pub struct Virtqueue {Show 13 fields
queue_size: u16,
_ring_area: PhysFrame,
desc_area: u64,
avail_area: u64,
used_area: u64,
desc_ptr: *mut VirtqDesc,
avail_ptr: *mut VirtqAvail,
avail_ring_ptr: *mut u16,
used_ptr: *mut VirtqUsed,
used_ring_ptr: *mut VirtqUsedElem,
free_descriptors: Vec<u16>,
last_used_idx: u16,
next_avail_idx: u16,
}Expand description
A VirtIO virtqueue
This structure manages the split virtqueue format as described in VirtIO spec section 2.6 (Split Virtqueues).
Fields§
§queue_size: u16Queue size (must be power of 2)
_ring_area: PhysFrameContiguous legacy vring allocation backing desc+avail+used
desc_area: u64Physical address of descriptor table
avail_area: u64Physical address of available ring
used_area: u64Physical address of used ring
desc_ptr: *mut VirtqDescVirtual address of descriptor table
avail_ptr: *mut VirtqAvailVirtual address of available ring
avail_ring_ptr: *mut u16Virtual address of available ring entries
used_ptr: *mut VirtqUsedVirtual address of used ring
used_ring_ptr: *mut VirtqUsedElemVirtual address of used ring entries
free_descriptors: Vec<u16>Free descriptor list (indices of free descriptors)
last_used_idx: u16Last seen used index
next_avail_idx: u16Next available index
Implementations§
Source§impl Virtqueue
impl Virtqueue
fn align_up(value: usize, align: usize) -> usize
Sourcepub unsafe fn new(queue_size: u16) -> Result<Self, &'static str>
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.
Sourcepub fn avail_area(&self) -> u64
pub fn avail_area(&self) -> u64
Get the physical address of the available ring
Sourcepub fn queue_size(&self) -> usize
pub fn queue_size(&self) -> usize
Get the queue size (number of descriptors)
Sourcepub fn alloc_descriptor(&mut self) -> Option<u16>
pub fn alloc_descriptor(&mut self) -> Option<u16>
Allocate a descriptor chain
Returns the head descriptor index
Sourcepub fn free_descriptor(&mut self, head: u16)
pub fn free_descriptor(&mut self, head: u16)
Free a descriptor chain
Walks the chain following NEXT flags and frees all descriptors
Sourcepub fn add_buffer(
&mut self,
buffers: &[(u64, u32, bool)],
) -> Result<u16, &'static str>
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)
Sourcepub fn used_indices(&self) -> (u16, u16)
pub fn used_indices(&self) -> (u16, u16)
Return a snapshot of (device_used_idx, driver_last_used_idx) for diagnostics.
Sourcepub fn get_used(&mut self) -> Option<(u16, u32)>
pub fn get_used(&mut self) -> Option<(u16, u32)>
Get the next used buffer
Returns (descriptor_index, length_written)
Sourcepub fn should_notify(&self) -> bool
pub fn should_notify(&self) -> bool
Notify the device (should write to queue_notify register)
Trait Implementations§
Auto Trait Implementations§
impl !Sync for Virtqueue
impl Freeze for Virtqueue
impl RefUnwindSafe for Virtqueue
impl Unpin for Virtqueue
impl UnsafeUnpin for Virtqueue
impl UnwindSafe for Virtqueue
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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