Trait dbs_device::DeviceIo
source · [−]pub trait DeviceIo: Send + Sync {
fn as_any(&self) -> &dyn Any;
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
Provided Methods
sourcefn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8])
fn read(&self, base: IoAddress, offset: IoAddress, data: &mut [u8])
Read from the MMIO address base + offset
into data
.
sourcefn write(&self, base: IoAddress, offset: IoAddress, data: &[u8])
fn write(&self, base: IoAddress, offset: IoAddress, data: &[u8])
Write from data
to the MMIO address base + offset
.
sourcefn 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
.
sourcefn 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
.
sourcefn get_assigned_resources(&self) -> DeviceResources
fn get_assigned_resources(&self) -> DeviceResources
Get resources assigned to the device.
sourcefn 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.