pub trait MmioOps {
// Required methods
unsafe fn read_u8(src: *const u8) -> u8;
unsafe fn read_u16(src: *const u16) -> u16;
unsafe fn read_u32(src: *const u32) -> u32;
unsafe fn read_u64(src: *const u64) -> u64;
unsafe fn write_u8(dst: *mut u8, value: u8);
unsafe fn write_u16(dst: *mut u16, value: u16);
unsafe fn write_u32(dst: *mut u32, value: u32);
unsafe fn write_u64(dst: *mut u64, value: u64);
// Provided methods
unsafe fn read<T: FromBytes + IntoBytes>(ptr: NonNull<T>) -> T { ... }
unsafe fn read_slice(ptr: NonNull<u8>, slice: &mut [u8]) { ... }
unsafe fn write_slice(ptr: NonNull<u8>, slice: &[u8]) { ... }
unsafe fn write<T: Immutable + IntoBytes>(ptr: NonNull<T>, value: T) { ... }
}Expand description
Trait for custom MMIO read/write implementations.
Per-size methods are used because MMIO access width matters at the hardware level (e.g. the GHCB protocol needs to know the exact access size for VMGEXIT calls).
The pointer is guaranteed to be properly aligned for its type and to point to valid MMIO address space.
Required Methods§
Provided Methods§
Sourceunsafe fn read<T: FromBytes + IntoBytes>(ptr: NonNull<T>) -> T
unsafe fn read<T: FromBytes + IntoBytes>(ptr: NonNull<T>) -> T
Performs an MMIO read and returns the value.
§Safety
The pointer must be valid to perform an MMIO read from.
Sourceunsafe fn read_slice(ptr: NonNull<u8>, slice: &mut [u8])
unsafe fn read_slice(ptr: NonNull<u8>, slice: &mut [u8])
Reads from MMIO by splitting into naturally-sized chunks.
§Safety
ptr must be valid for MMIO reads spanning slice.len() bytes.
Sourceunsafe fn write_slice(ptr: NonNull<u8>, slice: &[u8])
unsafe fn write_slice(ptr: NonNull<u8>, slice: &[u8])
Writes to MMIO by splitting into naturally-sized chunks.
§Safety
ptr must be valid for MMIO writes spanning slice.len() bytes.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".