diff options
author | Paolo Bonzini <pbonzini@redhat.com> | 2025-01-17 17:56:00 +0100 |
---|---|---|
committer | Paolo Bonzini <pbonzini@redhat.com> | 2025-01-28 17:58:09 +0100 |
commit | b3a29b3dc0d3f1e0f177b2be3edeb0d74c061b15 (patch) | |
tree | 161a75976636380f21de26a882db0408d07cb363 | |
parent | c44818a5fdbcca9a4e3474be70f8a2615e19922b (diff) | |
download | qemu-b3a29b3dc0d3f1e0f177b2be3edeb0d74c061b15.zip qemu-b3a29b3dc0d3f1e0f177b2be3edeb0d74c061b15.tar.gz qemu-b3a29b3dc0d3f1e0f177b2be3edeb0d74c061b15.tar.bz2 |
rust: pl011: pull device-specific code out of MemoryRegionOps callbacks
read() can now return a simple u64.
Reviewed-by: Zhao Liu <zhao1.liu@intel.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
-rw-r--r-- | rust/hw/char/pl011/src/device.rs | 23 | ||||
-rw-r--r-- | rust/hw/char/pl011/src/memory_ops.rs | 18 |
2 files changed, 15 insertions, 26 deletions
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs index 6c47d30..945200f 100644 --- a/rust/hw/char/pl011/src/device.rs +++ b/rust/hw/char/pl011/src/device.rs @@ -12,9 +12,10 @@ use std::{ use qemu_api::{ bindings::{ error_fatal, hwaddr, memory_region_init_io, qdev_init_clock_in, qdev_new, - qdev_prop_set_chr, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, qemu_chr_fe_write_all, - qemu_irq, sysbus_connect_irq, sysbus_mmio_map, sysbus_realize_and_unref, CharBackend, - Chardev, Clock, ClockEvent, MemoryRegion, QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, + qdev_prop_set_chr, qemu_chr_fe_accept_input, qemu_chr_fe_ioctl, qemu_chr_fe_set_handlers, + qemu_chr_fe_write_all, qemu_irq, sysbus_connect_irq, sysbus_mmio_map, + sysbus_realize_and_unref, CharBackend, Chardev, Clock, ClockEvent, MemoryRegion, + QEMUChrEvent, CHR_IOCTL_SERIAL_SET_BREAK, }, c_str, impl_vmstate_forward, irq::InterruptSource, @@ -528,30 +529,32 @@ impl PL011State { } } - #[allow(clippy::needless_pass_by_ref_mut)] - pub fn read(&mut self, offset: hwaddr, _size: u32) -> ControlFlow<u64, u64> { + pub fn read(&mut self, offset: hwaddr, _size: u32) -> u64 { let mut update_irq = false; let result = match RegisterOffset::try_from(offset) { Err(v) if (0x3f8..0x400).contains(&(v >> 2)) => { let device_id = self.get_class().device_id; - ControlFlow::Break(u64::from(device_id[(offset - 0xfe0) >> 2])) + u32::from(device_id[(offset - 0xfe0) >> 2]) } Err(_) => { // qemu_log_mask(LOG_GUEST_ERROR, "pl011_read: Bad offset 0x%x\n", (int)offset); - ControlFlow::Break(0) + 0 } Ok(field) => match self.regs.borrow_mut().read(field) { - ControlFlow::Break(value) => ControlFlow::Break(value.into()), + ControlFlow::Break(value) => value, ControlFlow::Continue(value) => { update_irq = true; - ControlFlow::Continue(value.into()) + value } }, }; if update_irq { self.update(); + unsafe { + qemu_chr_fe_accept_input(&mut self.char_backend); + } } - result + result.into() } pub fn write(&mut self, offset: hwaddr, value: u64) { diff --git a/rust/hw/char/pl011/src/memory_ops.rs b/rust/hw/char/pl011/src/memory_ops.rs index a286003..432d326 100644 --- a/rust/hw/char/pl011/src/memory_ops.rs +++ b/rust/hw/char/pl011/src/memory_ops.rs @@ -24,25 +24,11 @@ pub static PL011_OPS: MemoryRegionOps = MemoryRegionOps { }; unsafe extern "C" fn pl011_read(opaque: *mut c_void, addr: hwaddr, size: c_uint) -> u64 { - assert!(!opaque.is_null()); let mut state = NonNull::new(opaque).unwrap().cast::<PL011State>(); - let val = unsafe { state.as_mut().read(addr, size) }; - match val { - std::ops::ControlFlow::Break(val) => val, - std::ops::ControlFlow::Continue(val) => { - // SAFETY: self.char_backend is a valid CharBackend instance after it's been - // initialized in realize(). - let cb_ptr = unsafe { core::ptr::addr_of_mut!(state.as_mut().char_backend) }; - unsafe { - qemu_chr_fe_accept_input(cb_ptr); - } - - val - } - } + unsafe { state.as_mut() }.read(addr, size) } unsafe extern "C" fn pl011_write(opaque: *mut c_void, addr: hwaddr, data: u64, _size: c_uint) { let mut state = NonNull::new(opaque).unwrap().cast::<PL011State>(); - unsafe { state.as_mut().write(addr, data) } + unsafe { state.as_mut() }.write(addr, data); } |