pub struct Virtqueue<'a, R: Copy> { /* private fields */ }
Expand description
A virtqueue of a virtio device.
R
is used to store device-specific per-request data (like the request header or status byte)
in memory shared with the device and is copied on completion. Don’t put things there that the
device doesn’t have to access, in the interest of both security and performance.
Implementations§
Source§impl<'a, R: Copy> Virtqueue<'a, R>
impl<'a, R: Copy> Virtqueue<'a, R>
Sourcepub fn new(
iova_translator: Box<dyn IovaTranslator>,
buf: &'a mut [u8],
queue_size: u16,
features: VirtioFeatureFlags,
) -> Result<Self, Error>
pub fn new( iova_translator: Box<dyn IovaTranslator>, buf: &'a mut [u8], queue_size: u16, features: VirtioFeatureFlags, ) -> Result<Self, Error>
Creates a new virtqueue in the passed memory buffer.
buf
has to be memory that is visible for the device. It is used to store all descriptors,
rings and device-specific per-request data for the queue.
Sourcepub fn queue_size(&self) -> u16
pub fn queue_size(&self) -> u16
Returns the number of entries in each of the descriptor table and rings.
Sourcepub fn layout(&self) -> &VirtqueueLayout
pub fn layout(&self) -> &VirtqueueLayout
Returns the virtqueue memory layout.
Sourcepub fn desc_table_ptr(&self) -> *const u8
pub fn desc_table_ptr(&self) -> *const u8
Returns a raw pointer to the start of the descriptor table.
Sourcepub fn driver_area_ptr(&self) -> *const u8
pub fn driver_area_ptr(&self) -> *const u8
Returns a raw pointer to the start of the driver area.
Sourcepub fn device_area_ptr(&self) -> *const u8
pub fn device_area_ptr(&self) -> *const u8
Returns a raw pointer to the start of the device area.
Sourcepub fn add_request<F>(&mut self, prepare: F) -> Result<u16, Error>
pub fn add_request<F>(&mut self, prepare: F) -> Result<u16, Error>
Enqueues a new request.
prepare
is a function or closure that gets a reference to the device-specific per-request
data in its final location in the virtqueue memory and a FnMut to add virtio descriptors to
the request. It can set up the per-request data as necessary and must add all descriptors
needed for the request.
The parameters of the FnMut it received are the iovec
describing the buffer to be added
and a boolean from_dev
that is true
if this buffer is written by the device and false
if it is read by the device.
Sourcepub fn completions(&mut self) -> VirtqueueIter<'_, 'a, R> ⓘ
pub fn completions(&mut self) -> VirtqueueIter<'_, 'a, R> ⓘ
Returns an iterator that returns all completed requests.