[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 09/10] rust: pl011: pull device-specific code out of MemoryRegion
From: |
Paolo Bonzini |
Subject: |
[PATCH 09/10] rust: pl011: pull device-specific code out of MemoryRegionOps callbacks |
Date: |
Fri, 17 Jan 2025 10:26:56 +0100 |
read() can now return a simple u64.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/hw/char/pl011/src/device.rs | 16 +++++++++-------
rust/hw/char/pl011/src/memory_ops.rs | 23 ++++-------------------
2 files changed, 13 insertions(+), 26 deletions(-)
diff --git a/rust/hw/char/pl011/src/device.rs b/rust/hw/char/pl011/src/device.rs
index 6ecbfb9ac84..af0f451deb2 100644
--- a/rust/hw/char/pl011/src/device.rs
+++ b/rust/hw/char/pl011/src/device.rs
@@ -171,7 +171,7 @@ impl PL011Registers {
pub(self) fn read(&mut self, offset: RegisterOffset) -> ControlFlow<u32,
u32> {
use RegisterOffset::*;
- std::ops::ControlFlow::Break(match offset {
+ ControlFlow::Break(match offset {
DR => {
self.flags.set_receive_fifo_full(false);
let c = self.read_fifo[self.read_pos];
@@ -530,22 +530,24 @@ fn post_init(&self) {
}
}
- #[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 {
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]))
+ u64::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.into(),
ControlFlow::Continue(value) => {
self.update();
- ControlFlow::Continue(value.into())
+ unsafe {
+ qemu_chr_fe_accept_input(&mut self.char_backend);
+ }
+ value.into()
},
}
}
diff --git a/rust/hw/char/pl011/src/memory_ops.rs
b/rust/hw/char/pl011/src/memory_ops.rs
index 8f66c8d492c..95b4df794e4 100644
--- a/rust/hw/char/pl011/src/memory_ops.rs
+++ b/rust/hw/char/pl011/src/memory_ops.rs
@@ -26,26 +26,11 @@
unsafe extern "C" fn pl011_read(opaque: *mut c_void, addr: hwaddr, size:
c_uint) -> u64 {
assert!(!opaque.is_null());
let mut state = unsafe {
NonNull::new_unchecked(opaque.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) {
- unsafe {
- assert!(!opaque.is_null());
- let mut state = NonNull::new_unchecked(opaque.cast::<PL011State>());
- state.as_mut().write(addr, data)
- }
+ assert!(!opaque.is_null());
+ let mut state = unsafe {
NonNull::new_unchecked(opaque.cast::<PL011State>()) };
+ unsafe { state.as_mut() }.write(addr, data);
}
--
2.47.1
- [PATCH 00/10] rust: pl011: correctly use interior mutability, Paolo Bonzini, 2025/01/17
- [PATCH 01/10] rust: pl011: remove unnecessary "extern crate", Paolo Bonzini, 2025/01/17
- [PATCH 02/10] rust: pl011: hide unnecessarily "pub" items from outside pl011::device, Paolo Bonzini, 2025/01/17
- [PATCH 03/10] rust: pl011: extract conversion to RegisterOffset, Paolo Bonzini, 2025/01/17
- [PATCH 04/10] rust: pl011: extract CharBackend receive logic into a separate function, Paolo Bonzini, 2025/01/17
- [PATCH 06/10] rust: pl011: extract PL011Registers, Paolo Bonzini, 2025/01/17
- [PATCH 05/10] rust: pl011: pull interrupt updates out of read/write ops, Paolo Bonzini, 2025/01/17
- [PATCH 07/10] rust: pl011: wrap registers with BqlRefCell, Paolo Bonzini, 2025/01/17
- [PATCH 10/10] rust: qdev: make reset take a shared reference, Paolo Bonzini, 2025/01/17
- [PATCH 08/10] rust: pl011: remove duplicate definitions, Paolo Bonzini, 2025/01/17
- [PATCH 09/10] rust: pl011: pull device-specific code out of MemoryRegionOps callbacks,
Paolo Bonzini <=