Trait dbs_device::DeviceIo
source · [−]pub trait DeviceIo: Send + Sync {
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.
Provided methods
Read from the MMIO address base + offset
into data
.
Write from data
to the MMIO address base + offset
.
fn pio_read(&self, base: PioAddress, offset: PioAddress, data: &mut [u8])
fn pio_read(&self, base: PioAddress, offset: PioAddress, data: &mut [u8])
Read from port base + offset
into data
.
fn pio_write(&self, base: PioAddress, offset: PioAddress, data: &[u8])
fn pio_write(&self, base: PioAddress, offset: PioAddress, data: &[u8])
Write from data
to the port base + offset
.
fn get_assigned_resources(&self) -> DeviceResources
fn get_assigned_resources(&self) -> DeviceResources
Get resources assigned to the device.
fn get_trapped_io_resources(&self) -> DeviceResources
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.