Skip to main content

VirtQueue

Struct VirtQueue 

Source
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 a u16.

Implementations§

Source§

impl<H: Hal, const SIZE: usize> VirtQueue<H, SIZE>

Source

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 the VIRTIO_F_INDIRECT_DESC feature has been negotiated with the device.
  • event_idx: Whether to use the used_event and avail_event fields for notification suppression. This should be set if the VIRTIO_F_EVENT_IDX feature has been negotiated with the device.
Source

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.

Source

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.

Source

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

Source

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.

Source

pub fn can_pop(&self) -> bool

Returns whether there is a used element that can be popped.

Source

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.

Source

pub fn available_desc(&self) -> usize

Returns the number of free descriptors.

Source

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.

Trait Implementations§

Source§

impl<H: Debug + Hal, const SIZE: usize> Debug for VirtQueue<H, SIZE>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<H: Hal, const SIZE: usize> Send for VirtQueue<H, SIZE>

Source§

impl<H: Hal, const SIZE: usize> Sync for VirtQueue<H, SIZE>

Auto Trait Implementations§

§

impl<H, const SIZE: usize> Freeze for VirtQueue<H, SIZE>

§

impl<H, const SIZE: usize> RefUnwindSafe for VirtQueue<H, SIZE>
where H: RefUnwindSafe,

§

impl<H, const SIZE: usize> Unpin for VirtQueue<H, SIZE>
where H: Unpin,

§

impl<H, const SIZE: usize> UnsafeUnpin for VirtQueue<H, SIZE>

§

impl<H, const SIZE: usize> UnwindSafe for VirtQueue<H, SIZE>
where H: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.