pub struct Driver<'a> { /* private fields */ }
Expand description
Representation of driver owned data.
Provides methods for safely querying, using appropriate memory barriers, items published by the driver.
Contents of this struct
are not expected to be being modified in parallel by a driver in a
guest, but as there is no way to guarantee guest behavior it is designed under the assumption of
parallel modifications by a malicious guest.
Implementations§
Source§impl<'a> Driver<'a>
impl<'a> Driver<'a>
Sourcepub const fn avail_len_for_queue_size(queue_size: u16) -> usize
pub const fn avail_len_for_queue_size(queue_size: u16) -> usize
How many bytes the avail ring should be for the given queue_size
.
Provides an easy way to calculate the correct size of the range for passing to new
Sourcepub fn new<'b: 'a, 'c: 'a>(
desc: DeviceRange<'b>,
avail: DeviceRange<'c>,
) -> Option<Self>
pub fn new<'b: 'a, 'c: 'a>( desc: DeviceRange<'b>, avail: DeviceRange<'c>, ) -> Option<Self>
Construct a Driver
using the provided memory for descriptor and available rings.
Provided ranges must be correctly sized and aligned to represent the same power of two
queue size, otherwise a None
is returned.
Sourcepub fn get_avail(&self, next_index: u16) -> Option<u16>
pub fn get_avail(&self, next_index: u16) -> Option<u16>
Query if a descriptor chain has been published with the given index.
If a chain has been published by the driver then returns the index of the first descriptor
in the chain. Otherwise returns a None
.
Sourcepub fn get_desc(&self, index: u16) -> Option<Desc>
pub fn get_desc(&self, index: u16) -> Option<Desc>
Request a descriptor by index.
Returns a none if the requested index is not within the range of the ring. Beyond this check this method has no way to validate if the requested descriptor is valid and it is the responsibility of the caller to know this.
Sourcepub fn needs_notification(
&self,
feature_event_idx: bool,
submitted: u16,
) -> bool
pub fn needs_notification( &self, feature_event_idx: bool, submitted: u16, ) -> bool
Determines if the driver has requested a notification for the given descriptor submission.
Queries the information published by the driver to determine whether or not it would like a
notification for the given submitted
descriptor by the Device
. As the Driver
holds
no host state whether the VIRTIO_F_EVENT_IDX
feature was negotiated must be passed in.
Sourcepub fn queue_size(&self) -> u16
pub fn queue_size(&self) -> u16
Returns the size of the descriptor and available rings.
The descriptor and available rings are, by definition, the same size. This is just returning
the size that was calculated during new