pub struct VirtQueue<H: Hal, const SIZE: usize> { /* private fields */ }Expand description
The mechanism for bulk data transport on virtio devices.
Each device can have zero or more virtqueues.
SIZE: The size of the queue. This is both the number of descriptors, and the number of slots in the available and used rings. It must be a power of 2 and fit in au16.
Implementations§
Source§impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE>
impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE>
Sourcepub fn new<T: Transport>(
transport: &mut T,
idx: u16,
indirect: bool,
event_idx: bool,
) -> Result<Self>
pub fn new<T: Transport>( transport: &mut T, idx: u16, indirect: bool, event_idx: bool, ) -> Result<Self>
Creates a new VirtQueue.
indirect: Whether to use indirect descriptors. This should be set if theVIRTIO_F_INDIRECT_DESCfeature has been negotiated with the device.event_idx: Whether to use theused_eventandavail_eventfields for notification suppression. This should be set if theVIRTIO_F_EVENT_IDXfeature has been negotiated with the device.
Sourcepub unsafe fn add<'a, 'b>(
&mut self,
inputs: &'a [&'b [u8]],
outputs: &'a mut [&'b mut [u8]],
) -> Result<u16>
pub unsafe fn add<'a, 'b>( &mut self, inputs: &'a [&'b [u8]], outputs: &'a mut [&'b mut [u8]], ) -> Result<u16>
Add buffers to the virtqueue, return a token.
The buffers must not be empty.
Ref: linux virtio_ring.c virtqueue_add
§Safety
The input and output buffers must remain valid and not be accessed until a call to
pop_used with the returned token succeeds.
Sourcepub fn add_notify_wait_pop<'a>(
&mut self,
inputs: &'a [&'a [u8]],
outputs: &'a mut [&'a mut [u8]],
transport: &mut impl Transport,
) -> Result<u32>
pub fn add_notify_wait_pop<'a>( &mut self, inputs: &'a [&'a [u8]], outputs: &'a mut [&'a mut [u8]], transport: &mut impl Transport, ) -> Result<u32>
Add the given buffers to the virtqueue, notifies the device, blocks until the device uses them, then pops them.
This assumes that the device isn’t processing any other buffers at the same time.
The buffers must not be empty.
Sourcepub fn set_dev_notify(&mut self, enable: bool)
pub fn set_dev_notify(&mut self, enable: bool)
Advise the device whether used buffer notifications are needed.
See Virtio v1.1 2.6.7 Used Buffer Notification Suppression
Sourcepub fn should_notify(&self) -> bool
pub fn should_notify(&self) -> bool
Returns whether the driver should notify the device after adding a new buffer to the virtqueue.
This will be false if the device has suppressed notifications.
Sourcepub fn peek_used(&self) -> Option<u16>
pub fn peek_used(&self) -> Option<u16>
Returns the descriptor index (a.k.a. token) of the next used element without popping it, or
None if the used ring is empty.
Sourcepub fn available_desc(&self) -> usize
pub fn available_desc(&self) -> usize
Returns the number of free descriptors.
Sourcepub unsafe fn pop_used<'a>(
&mut self,
token: u16,
inputs: &'a [&'a [u8]],
outputs: &'a mut [&'a mut [u8]],
) -> Result<u32>
pub unsafe fn pop_used<'a>( &mut self, token: u16, inputs: &'a [&'a [u8]], outputs: &'a mut [&'a mut [u8]], ) -> Result<u32>
If the given token is next on the device used queue, pops it and returns the total buffer length which was used (written) by the device.
Ref: linux virtio_ring.c virtqueue_get_buf_ctx
§Safety
The buffers in inputs and outputs must match the set of buffers originally added to the
queue by add when it returned the token being passed in here.