Trait VirtioTransport

Source
pub trait VirtioTransport<C: ByteValued, R: Copy>: Send + Sync {
    // Required methods
    fn max_queues(&self) -> Option<usize>;
    fn max_mem_regions(&self) -> u64;
    fn mem_region_alignment(&self) -> usize;
    fn alloc_queue_mem(
        &mut self,
        layout: &VirtqueueLayout,
    ) -> Result<&mut [u8], Error>;
    fn map_mem_region(
        &mut self,
        addr: usize,
        len: usize,
        fd: RawFd,
        fd_offset: i64,
    ) -> Result<Iova, Error>;
    fn unmap_mem_region(&mut self, addr: usize, len: usize) -> Result<(), Error>;
    fn iova_translator(&self) -> Box<dyn IovaTranslator>;
    fn setup_queues(&mut self, queues: &[Virtqueue<'_, R>]) -> Result<(), Error>;
    fn get_features(&self) -> u64;
    fn get_config(&self) -> Result<C, Error>;
    fn get_submission_notifier(
        &self,
        queue_idx: usize,
    ) -> Box<dyn QueueNotifier>;
    fn get_completion_fd(&self, queue_idx: usize) -> Arc<EventFd>;
}
Expand description

An interface to the virtio transport/bus of a device

Type parameters:

  • C represents the device configuration space, as returned by VirtioTransport::get_config;
  • R has the same meaning as in Virtqueue, and is used to store device-specific per-request data.

Required Methods§

Source

fn max_queues(&self) -> Option<usize>

Returns the maximum number of queues supported by the device if the transport is able to get this information.

Source

fn max_mem_regions(&self) -> u64

Returns the maximum number of memory regions supported by the transport.

Source

fn mem_region_alignment(&self) -> usize

Returns the alignment requirement in bytes of the memory region

Source

fn alloc_queue_mem( &mut self, layout: &VirtqueueLayout, ) -> Result<&mut [u8], Error>

Allocates or maps the memory to store the virtqueues in.

This memory must be accessible by the device and is also used for additional per-request metadata (such as request headers) that is created internally by the driver and must be visible for the device.

Source

fn map_mem_region( &mut self, addr: usize, len: usize, fd: RawFd, fd_offset: i64, ) -> Result<Iova, Error>

Maps a memory region with the transport.

Returns the IOVA corresponding to the start of the memory region.

Requests to the device may only refer to memory that is in a mapped memory region.

Source

fn unmap_mem_region(&mut self, addr: usize, len: usize) -> Result<(), Error>

Unmaps a memory region from the transport.

Note that mapped regions are implicitly unmapped when the transport is dropped.

Source

fn iova_translator(&self) -> Box<dyn IovaTranslator>

Returns a value that can translate process addresses into IOVAs.

Source

fn setup_queues(&mut self, queues: &[Virtqueue<'_, R>]) -> Result<(), Error>

Initialises and enables the passed queues on the transport level.

Source

fn get_features(&self) -> u64

Returns the negotiated virtio feature flags.

Source

fn get_config(&self) -> Result<C, Error>

Queries the device configuration.

Source

fn get_submission_notifier(&self, queue_idx: usize) -> Box<dyn QueueNotifier>

Returns a QueueNotifier that can be used to notify the device of new requests in the queue.

Source

fn get_completion_fd(&self, queue_idx: usize) -> Arc<EventFd>

Returns an EventFd that can be read to be notified of request completions in the queue.

Implementors§