Trait DeviceIo

Source
pub trait DeviceIo: Send + Sync {
    // Required method
    fn as_any(&self) -> &dyn Any;

    // Provided methods
    fn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8]) { ... }
    fn write(&self, base: IoAddress, offset: IoAddress, data: &[u8]) { ... }
    fn pio_read(&self, base: PioAddress, offset: PioAddress, data: &mut [u8]) { ... }
    fn pio_write(&self, base: PioAddress, offset: PioAddress, data: &[u8]) { ... }
    fn get_assigned_resources(&self) -> DeviceResources { ... }
    fn get_trapped_io_resources(&self) -> DeviceResources { ... }
}
Expand description

Trait for device to handle trapped MMIO/PIO access requests with interior mutability for high performance.

Any device which needs to trap MMIO/PIO access requests should implement the DeviceIo or DeviceIoMut trait and register itself to the IoManager with those trapped IO address ranges. When the guest access those trapped address ranges, the access request will be routed to the registered callbacks.

The DeviceIo trait adopts the interior mutability pattern so we can get a real concurrent multiple threads handling. For device backend drivers not focusing on high performance, the Mutex<T: DeviceIoMut> adapter may be used to simplify the implementation.

Required Methods§

Source

fn as_any(&self) -> &dyn Any

Used to downcast to the specific type.

Provided Methods§

Source

fn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8])

Read from the MMIO address base + offset into data.

Source

fn write(&self, base: IoAddress, offset: IoAddress, data: &[u8])

Write from data to the MMIO address base + offset.

Source

fn pio_read(&self, base: PioAddress, offset: PioAddress, data: &mut [u8])

Read from port base + offset into data.

Source

fn pio_write(&self, base: PioAddress, offset: PioAddress, data: &[u8])

Write from data to the port base + offset.

Source

fn get_assigned_resources(&self) -> DeviceResources

Get resources assigned to the device.

Source

fn get_trapped_io_resources(&self) -> DeviceResources

Get the trapped IO address ranges for the device.

Only MMIO/PIO address ranges in the resource list will be handled, other resources will be ignored. So the device does not need to filter out non-MMIO/PIO resources.

Implementations on Foreign Types§

Source§

impl<T: DeviceIoMut + Send + 'static> DeviceIo for Mutex<T>

Source§

fn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8])

Source§

fn write(&self, base: IoAddress, offset: IoAddress, data: &[u8])

Source§

fn pio_read(&self, base: PioAddress, offset: PioAddress, data: &mut [u8])

Source§

fn pio_write(&self, base: PioAddress, offset: PioAddress, data: &[u8])

Source§

fn get_assigned_resources(&self) -> DeviceResources

Source§

fn get_trapped_io_resources(&self) -> DeviceResources

Source§

fn as_any(&self) -> &dyn Any

Implementors§