Trait VirtioDevice

Source
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§

Source

fn get_base_addr(&self) -> usize

Source

fn get_virtqueue_count(&self) -> usize

Source

fn get_virtqueue(&self, queue_idx: usize) -> &VirtQueue<'_>

Provided Methods§

Source

fn init(&mut self) -> Result<(), &'static str>

Initialize the device

This method performs the standard VirtIO initialization sequence:

  1. Reset the device
  2. Acknowledge the device
  3. Set driver status
  4. Negotiate features
  5. Set up virtqueues
  6. Set driver OK status
Source

fn reset(&mut self)

Reset the device by writing 0 to the Status register

Source

fn acknowledge(&mut self)

Set ACKNOWLEDGE status bit

Source

fn driver(&mut self)

Set DRIVER status bit

Source

fn driver_ok(&mut self)

Set DRIVER_OK status bit

Source

fn set_failed(&mut self)

Set FAILED status bit

Source

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

Source

fn get_supported_features(&self, device_features: u32) -> u32

Get device features supported by this driver

This method can be overridden by specific device implementations to select which features to support.

§Arguments
  • device_features - The features offered by the device
§Returns

The features supported by the driver

Source

fn setup_queue(&mut self, queue_idx: usize) -> bool

Set up a virtqueue

This method configures a virtqueue by setting the queue selection, size, alignment, and ready status.

§Arguments
  • queue_idx - The index of the queue to set up
§Returns

Returns true if queue setup was successful, false otherwise

Source

fn read_config<T: Sized>(&self, offset: usize) -> T

Read device-specific configuration

This method reads configuration data from the device-specific configuration space.

§Arguments
  • offset - The offset within the configuration space
§Returns

The configuration value of type T

Source

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 space
  • value - The value to write
Source

fn get_device_info(&self) -> (u32, u32)

Get device and vendor IDs

§Returns

A tuple containing (device_id, vendor_id)

Source

fn get_interrupt_status(&self) -> u32

Get interrupt status

§Returns

The interrupt status register value

Source

fn process_interrupts(&mut self) -> u32

Process interrupts (polling method)

This method checks for interrupts and acknowledges them.

§Returns

The interrupt status before acknowledgment

Source

fn memory_barrier(&self)

Memory barrier for ensuring memory operations ordering

Source

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

Source

fn read32_register(&self, register: Register) -> u32

Read a 32-bit value from a device register

§Arguments
  • register - The register to read from
§Returns

The 32-bit value read from the register

Source

fn write32_register(&self, register: Register, value: u32)

Write a 32-bit value to a device register

§Arguments
  • register - The register to write to
  • value - The 32-bit value to write
Source

fn read64_register(&self, register: Register) -> u64

Read a 64-bit value from a device register

§Arguments
  • register - The register to read from
§Returns

The 64-bit value read from the register

Source

fn write64_register(&self, register: Register, value: u64)

Write a 64-bit value to a device register

§Arguments
  • register - The register to write to
  • value - 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.

Implementors§