Skip to main content

Virtqueue

Struct Virtqueue 

Source
pub struct Virtqueue { /* private fields */ }
Expand description

A VirtIO virtqueue

This structure manages the split virtqueue format as described in VirtIO spec section 2.6 (Split Virtqueues).

Implementations§

Source§

impl Virtqueue

Source

pub unsafe fn new(queue_size: u16) -> Result<Self, &'static str>

Create a new virtqueue with the specified size

§Safety

The caller must ensure that the allocated memory is properly mapped and accessible.

Source

pub fn desc_area(&self) -> u64

Get the physical address of the descriptor table

Source

pub fn avail_area(&self) -> u64

Get the physical address of the available ring

Source

pub fn used_area(&self) -> u64

Get the physical address of the used ring

Source

pub fn size(&self) -> u16

Get the queue size

Source

pub fn alloc_descriptor(&mut self) -> Option<u16>

Allocate a descriptor chain

Returns the head descriptor index

Source

pub fn free_descriptor(&mut self, head: u16)

Free a descriptor chain

Walks the chain following NEXT flags and frees all descriptors

Source

pub fn add_buffer( &mut self, buffers: &[(u64, u32, bool)], ) -> Result<u16, &'static str>

Add a buffer to the virtqueue

Returns the descriptor index (token) that can be used to track completion

§Arguments
  • buffers: A list of (physical_address, length, is_write_only)
Source

pub fn has_used(&self) -> bool

Check if there are any used buffers

Source

pub fn get_used(&mut self) -> Option<(u16, u32)>

Get the next used buffer

Returns (descriptor_index, length_written)

Source

pub fn should_notify(&self) -> bool

Notify the device (should write to queue_notify register)

Trait Implementations§

Auto Trait Implementations§

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
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.