pub trait VirtioDevice {
Show 23 methods
// Required methods
fn get_base_addr(&self) -> usize;
fn get_virtqueue_count(&self) -> usize;
fn get_virtqueue(&self, queue_idx: usize) -> &VirtQueue<'_>;
// Provided methods
fn init(&mut self) -> Result<(), &'static str> { ... }
fn reset(&mut self) { ... }
fn acknowledge(&mut self) { ... }
fn driver(&mut self) { ... }
fn driver_ok(&mut self) { ... }
fn set_failed(&mut self) { ... }
fn negotiate_features(&mut self) -> bool { ... }
fn get_supported_features(&self, device_features: u32) -> u32 { ... }
fn setup_queue(&mut self, queue_idx: usize) -> bool { ... }
fn read_config<T: Sized>(&self, offset: usize) -> T { ... }
fn write_config<T: Sized>(&self, offset: usize, value: T) { ... }
fn get_device_info(&self) -> (u32, u32) { ... }
fn get_interrupt_status(&self) -> u32 { ... }
fn process_interrupts(&mut self) -> u32 { ... }
fn memory_barrier(&self) { ... }
fn notify(&mut self, virtqueue_idx: usize) { ... }
fn read32_register(&self, register: Register) -> u32 { ... }
fn write32_register(&self, register: Register, value: u32) { ... }
fn read64_register(&self, register: Register) -> u64 { ... }
fn write64_register(&self, register: Register, value: u64) { ... }
}
Expand description
VirtioDevice trait
This trait defines the interface for VirtIO devices. It provides methods for initializing the device, accessing registers, and performing device operations according to the VirtIO specification.
Required Methods§
fn get_base_addr(&self) -> usize
fn get_virtqueue_count(&self) -> usize
fn get_virtqueue(&self, queue_idx: usize) -> &VirtQueue<'_>
Provided Methods§
Sourcefn init(&mut self) -> Result<(), &'static str>
fn init(&mut self) -> Result<(), &'static str>
Initialize the device
This method performs the standard VirtIO initialization sequence:
- Reset the device
- Acknowledge the device
- Set driver status
- Negotiate features
- Set up virtqueues
- Set driver OK status
Sourcefn acknowledge(&mut self)
fn acknowledge(&mut self)
Set ACKNOWLEDGE status bit
Sourcefn set_failed(&mut self)
fn set_failed(&mut self)
Set FAILED status bit
Sourcefn negotiate_features(&mut self) -> bool
fn negotiate_features(&mut self) -> bool
Negotiate device features
This method reads device features, selects supported features, sets driver features, and verifies features OK status.
§Returns
Returns true if feature negotiation was successful, false otherwise
Sourcefn get_supported_features(&self, device_features: u32) -> u32
fn get_supported_features(&self, device_features: u32) -> u32
Sourcefn setup_queue(&mut self, queue_idx: usize) -> bool
fn setup_queue(&mut self, queue_idx: usize) -> bool
Sourcefn read_config<T: Sized>(&self, offset: usize) -> T
fn read_config<T: Sized>(&self, offset: usize) -> T
Sourcefn write_config<T: Sized>(&self, offset: usize, value: T)
fn write_config<T: Sized>(&self, offset: usize, value: T)
Write device-specific configuration
This method writes configuration data to the device-specific configuration space.
§Arguments
offset
- The offset within the configuration spacevalue
- The value to write
Sourcefn get_device_info(&self) -> (u32, u32)
fn get_device_info(&self) -> (u32, u32)
Sourcefn get_interrupt_status(&self) -> u32
fn get_interrupt_status(&self) -> u32
Sourcefn process_interrupts(&mut self) -> u32
fn process_interrupts(&mut self) -> u32
Process interrupts (polling method)
This method checks for interrupts and acknowledges them.
§Returns
The interrupt status before acknowledgment
Sourcefn memory_barrier(&self)
fn memory_barrier(&self)
Memory barrier for ensuring memory operations ordering
Sourcefn notify(&mut self, virtqueue_idx: usize)
fn notify(&mut self, virtqueue_idx: usize)
Notify the device about new buffers in a specified virtqueue
This method notifies the device that new buffers are available in the specified virtqueue. It selects the queue using the QueueSel register and then writes to the QueueNotify register.
§Arguments
virtqueue_idx
- The index of the virtqueue to notify
§Panics
Panics if the virtqueue index is invalid
Sourcefn read32_register(&self, register: Register) -> u32
fn read32_register(&self, register: Register) -> u32
Sourcefn write32_register(&self, register: Register, value: u32)
fn write32_register(&self, register: Register, value: u32)
Write a 32-bit value to a device register
§Arguments
register
- The register to write tovalue
- The 32-bit value to write
Sourcefn read64_register(&self, register: Register) -> u64
fn read64_register(&self, register: Register) -> u64
Sourcefn write64_register(&self, register: Register, value: u64)
fn write64_register(&self, register: Register, value: u64)
Write a 64-bit value to a device register
§Arguments
register
- The register to write tovalue
- The 64-bit value to write
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.