rust: pl011: drop use of ControlFlow

It is a poor match for what the code is doing, anyway.

Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
This commit is contained in:
Paolo Bonzini 2025-01-17 18:13:30 +01:00
parent b3a29b3dc0
commit 20bcc96f45

View File

@ -5,7 +5,6 @@
use core::ptr::{addr_of, addr_of_mut, NonNull}; use core::ptr::{addr_of, addr_of_mut, NonNull};
use std::{ use std::{
ffi::CStr, ffi::CStr,
ops::ControlFlow,
os::raw::{c_int, c_void}, os::raw::{c_int, c_void},
}; };
@ -177,10 +176,11 @@ impl DeviceImpl for PL011State {
} }
impl PL011Registers { impl PL011Registers {
pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow<u32, u32> { pub(self) fn read(&mut self, offset: RegisterOffset) -> (bool, u32) {
use RegisterOffset::*; use RegisterOffset::*;
ControlFlow::Break(match offset { let mut update = false;
let result = match offset {
DR => { DR => {
self.flags.set_receive_fifo_full(false); self.flags.set_receive_fifo_full(false);
let c = self.read_fifo[self.read_pos]; let c = self.read_fifo[self.read_pos];
@ -196,8 +196,9 @@ impl PL011Registers {
} }
// Update error bits. // Update error bits.
self.receive_status_error_clear.set_from_data(c); self.receive_status_error_clear.set_from_data(c);
// Must call qemu_chr_fe_accept_input, so return Continue: // Must call qemu_chr_fe_accept_input
return ControlFlow::Continue(u32::from(c)); update = true;
u32::from(c)
} }
RSR => u32::from(self.receive_status_error_clear), RSR => u32::from(self.receive_status_error_clear),
FR => u32::from(self.flags), FR => u32::from(self.flags),
@ -216,7 +217,8 @@ impl PL011Registers {
0 0
} }
DMACR => self.dmacr, DMACR => self.dmacr,
}) };
(update, result)
} }
pub(self) fn write( pub(self) fn write(
@ -530,31 +532,26 @@ impl PL011State {
} }
pub fn read(&mut self, offset: hwaddr, _size: u32) -> u64 { pub fn read(&mut self, offset: hwaddr, _size: u32) -> u64 {
let mut update_irq = false; match RegisterOffset::try_from(offset) {
let result = match RegisterOffset::try_from(offset) {
Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => {
let device_id = self.get_class().device_id; let device_id = self.get_class().device_id;
u32::from(device_id[(offset - 0xfe0) >> 2]) u64::from(device_id[(offset - 0xfe0) >> 2])
} }
Err(_) => { Err(_) => {
// qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset);
0 0
} }
Ok(field) => match self.regs.borrow_mut().read(field) { Ok(field) => {
ControlFlow::Break(value) => value, let (update_irq, result) = self.regs.borrow_mut().read(field);
ControlFlow::Continue(value) => { if update_irq {
update_irq = true; self.update();
value unsafe {
qemu_chr_fe_accept_input(&mut self.char_backend);
}
} }
}, result.into()
};
if update_irq {
self.update();
unsafe {
qemu_chr_fe_accept_input(&mut self.char_backend);
} }
} }
result.into()
} }
pub fn write(&mut self, offset: hwaddr, value: u64) { pub fn write(&mut self, offset: hwaddr, value: u64) {