Directly wrap the memory_region_enable_lockless_io() in
MemoryRegion::enable_lockless_io.

Although memory_region_enable_lockless_io() just sets 2 fields at C
side, it's not necessary to totally implement it at Rust side, instead,
simply wrap and reuse existing C interfaces.

This will save some effort when modifying the interface in the future
(changes are likely to occur, as there is a TODO in the C code).

Signed-off-by: Zhao Liu <[email protected]>
---
 rust/system/src/memory.rs | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/rust/system/src/memory.rs b/rust/system/src/memory.rs
index 4b3316bf767f..e4bfbed1febe 100644
--- a/rust/system/src/memory.rs
+++ b/rust/system/src/memory.rs
@@ -12,7 +12,9 @@
 use common::{callbacks::FnCall, uninit::MaybeUninitField, zeroable::Zeroable, 
Opaque};
 use qom::prelude::*;
 
-use crate::bindings::{self, device_endian, memory_region_init_io};
+use crate::bindings::{
+    self, device_endian, memory_region_enable_lockless_io, 
memory_region_init_io,
+};
 pub use crate::bindings::{hwaddr, MemTxAttrs};
 
 pub struct MemoryRegionOps<T>(
@@ -172,6 +174,17 @@ pub fn init_io<T: IsA<Object>>(
             );
         }
     }
+
+    /// Enable lockless (BQL free) acceess.
+    ///
+    /// Enable BQL-free access for devices that are well prepared to handle
+    /// locking during I/O themselves: either by doing fine grained locking or
+    /// by providing lock-free I/O schemes.
+    pub fn enable_lockless_io(&self) {
+        // SAFETY: MemoryRegion is wrapped by Opaque<>, it's safe to get a
+        // raw pointer as *mut MemoryRegion.
+        unsafe { memory_region_enable_lockless_io(self.as_mut_ptr()) }
+    }
 }
 
 unsafe impl ObjectType for MemoryRegion {
-- 
2.34.1


Reply via email to