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
impl Virtqueue
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 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 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 Freeze for Virtqueue
impl RefUnwindSafe for Virtqueue
impl !Sync 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
Mutably borrows from an owned value. Read more
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>
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 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>
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