⚠️ VeridianOS Kernel Documentation - This is low-level kernel code. All functions are unsafe unless explicitly marked otherwise. no_std

VirtQueue

Struct VirtQueue 

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

A split virtqueue managing descriptors, available ring, and used ring.

Owns the physical memory backing all three structures. The physical page frame number (PFN) is communicated to the device so it can DMA directly.

Implementations§

Source§

impl VirtQueue

Source

pub fn new(size: u16) -> Result<Self, KernelError>

Allocate and initialize a new virtqueue.

Allocates physically contiguous memory for the descriptor table, available ring, and used ring. The memory is zeroed and the free descriptor list is linked.

size is typically read from the device via QUEUE_SIZE register and should be a power of 2. If size is 0 or exceeds our compiled maximum, we clamp to DEFAULT_QUEUE_SIZE.

Source

pub fn pfn(&self) -> u32

Get the physical page frame number for the QUEUE_ADDRESS register.

Source

pub fn phys_desc(&self) -> u64

Physical addresses for mmio transports (virtio-mmio expects 64-bit phys)

Source

pub fn phys_avail(&self) -> u64

Source

pub fn phys_used(&self) -> u64

Source

pub fn size(&self) -> u16

Get the queue size.

Source

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

Allocate a single free descriptor, returning its index.

Returns None if all descriptors are in use.

Source

pub fn free_desc(&mut self, idx: u16)

Return a descriptor to the free list.

Source

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

Free a chain of descriptors linked via NEXT flags, starting at head.

Source

pub unsafe fn write_desc( &mut self, idx: u16, phys_addr: u64, len: u32, flags: u16, next: u16, )

Write a descriptor’s fields.

§Safety

idx must be a valid descriptor index (< queue size). phys_addr must point to a valid guest physical buffer of at least len bytes that will remain valid until the device returns the descriptor via the used ring.

Source

pub fn push_avail(&mut self, desc_head: u16)

Push a descriptor chain head onto the available ring and advance the available index.

The caller must call kick() (via the transport) after one or more push_avail() calls to notify the device.

Source

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

Poll the used ring for a completed buffer.

Returns Some((chain_head_index, bytes_written)) if the device has returned a buffer, or None if no new completions are available.

The caller should free the returned descriptor chain via free_chain().

Source

pub fn has_used(&self) -> bool

Check if any completions are pending without consuming them.

Trait Implementations§

Source§

impl Drop for VirtQueue

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl Send for VirtQueue

Source§

impl Sync for VirtQueue

Auto Trait Implementations§

§

impl Freeze for VirtQueue

§

impl RefUnwindSafe for VirtQueue

§

impl Unpin for VirtQueue

§

impl UnwindSafe for VirtQueue

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = Infallible

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

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

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.