pub trait Device:
Send
+ Sync
+ Any {
// Required methods
fn name(&self) -> &str;
fn resources(&self) -> &[Resource];
fn handle(&self, access: &BusAccess) -> Result<BusResponse, DeviceError>;
fn as_any(&self) -> &dyn Any;
// Provided methods
fn reset(&mut self) -> Result<(), DeviceError> { ... }
fn suspend(&mut self) -> Result<(), DeviceError> { ... }
fn resume(&mut self) -> Result<(), DeviceError> { ... }
}Expand description
The unified device trait.
Every emulated device (interrupt controller, UART, virtio-blk, …)
implements this trait. The device manager calls resources
at registration time for conflict detection and handle
on the hot path whenever a vCPU exit is dispatched to this device.
§Downcasting
Device extends Any so callers can downcast to a
concrete device type via as_any:
if let Some(vgic) = device.as_any().downcast_ref::<VGicD>() {
vgic.assign_irq(32, cpu_id, (0, 0, 0, cpu_id));
}Required Methods§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Returns a human-readable name for this device (used in logging and diagnostics).
Sourcefn resources(&self) -> &[Resource]
fn resources(&self) -> &[Resource]
Returns the resources (MMIO windows, port ranges, system registers) this device requires.
The returned slice is a stable snapshot computed at device construction time. Callers may read it on both the registration path and the hot path without allocation.
Sourcefn handle(&self, access: &BusAccess) -> Result<BusResponse, DeviceError>
fn handle(&self, access: &BusAccess) -> Result<BusResponse, DeviceError>
Handles a single bus access.
This is the hot-path entry point called from BusRouter::dispatch.
Provided Methods§
Sourcefn reset(&mut self) -> Result<(), DeviceError>
fn reset(&mut self) -> Result<(), DeviceError>
Resets the device to its power-on state.
Sourcefn suspend(&mut self) -> Result<(), DeviceError>
fn suspend(&mut self) -> Result<(), DeviceError>
Puts the device into a low-power or suspended state.
Sourcefn resume(&mut self) -> Result<(), DeviceError>
fn resume(&mut self) -> Result<(), DeviceError>
Restores the device from a suspended state.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".