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
impl VirtQueue
Sourcepub fn new(size: u16) -> Result<Self, KernelError>
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.
Sourcepub fn phys_desc(&self) -> u64
pub fn phys_desc(&self) -> u64
Physical addresses for mmio transports (virtio-mmio expects 64-bit phys)
pub fn phys_avail(&self) -> u64
pub fn phys_used(&self) -> u64
Sourcepub fn alloc_desc(&mut self) -> Option<u16>
pub fn alloc_desc(&mut self) -> Option<u16>
Allocate a single free descriptor, returning its index.
Returns None if all descriptors are in use.
Sourcepub fn free_chain(&mut self, head: u16)
pub fn free_chain(&mut self, head: u16)
Free a chain of descriptors linked via NEXT flags, starting at head.
Sourcepub unsafe fn write_desc(
&mut self,
idx: u16,
phys_addr: u64,
len: u32,
flags: u16,
next: u16,
)
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.
Sourcepub fn push_avail(&mut self, desc_head: u16)
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.