Skip to main content

MmioOps

Trait MmioOps 

Source
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§

Source

unsafe fn read_u8(src: *const u8) -> u8

Perform an 8-bit MMIO read.

§Safety

src must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn read_u16(src: *const u16) -> u16

Perform a 16-bit MMIO read.

§Safety

src must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn read_u32(src: *const u32) -> u32

Perform a 32-bit MMIO read.

§Safety

src must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn read_u64(src: *const u64) -> u64

Perform a 64-bit MMIO read.

§Safety

src must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn write_u8(dst: *mut u8, value: u8)

Perform an 8-bit MMIO write.

§Safety

dst must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn write_u16(dst: *mut u16, value: u16)

Perform a 16-bit MMIO write.

§Safety

dst must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn write_u32(dst: *mut u32, value: u32)

Perform a 32-bit MMIO write.

§Safety

dst must be a valid, aligned pointer to MMIO address space.

Source

unsafe fn write_u64(dst: *mut u64, value: u64)

Perform a 64-bit MMIO write.

§Safety

dst must be a valid, aligned pointer to MMIO address space.

Provided Methods§

Source

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.

Source

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.

Source

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.

Source

unsafe fn write<T: Immutable + IntoBytes>(ptr: NonNull<T>, value: T)

Performs an MMIO write of the given value.

§Safety

ptr must be valid to perform an MMIO write to.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§