pub struct DriverRing<M, const N: usize, const R: usize> { /* private fields */ }Expand description
The driver’s half of one split virtqueue in shared memory.
N bounds the queue’s size and R a chain’s regions; both are storage
the value carries inline, so the queue allocates nothing. One owner:
every operation takes &mut self, and there is no lock.
§What the driver trusts
Nothing the device wrote, and nothing it can write. The descriptor table
is never read back: the free list, each chain’s links and its room are
kept here, so a device that rewrites a descriptor changes nothing the
driver does. A used entry is checked before it is believed — the head
must be a chain the device holds, the length no more than the chain’s
writable bytes, and the used index no further ahead than chains are
outstanding. A device that fails any of them has stopped being a device:
the queue refuses every operation from then on
(DriverRingError::UsedIndex, DriverRingError::UsedEntry) until it
is reset, which is also what the driver owes the
device.
The profile is the protocol’s: direct descriptors only, no indirect tables, no event indices, and the two suppression flags.
Implementations§
Source§impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> DriverRing<M, N, R>
impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> DriverRing<M, N, R>
Sourcepub fn new(
memory: M,
max_size: QueueSize,
max_chain_descriptors: u16,
) -> Option<Self>
pub fn new( memory: M, max_size: QueueSize, max_chain_descriptors: u16, ) -> Option<Self>
A queue in memory of at most max_size descriptors whose chains
are at most max_chain_descriptors long. Unconfigured: the driver
configures a size, says where the parts
are (set_addresses) and makes it ready.
None when the limits do not fit: a queue no larger than N, and a
chain of two descriptors at least, no longer than R or the queue.
Sourcepub fn set_addresses(
&mut self,
addresses: RingAddresses,
) -> Result<(), QueueError<DriverRingError>>
pub fn set_addresses( &mut self, addresses: RingAddresses, ) -> Result<(), QueueError<DriverRingError>>
Where the queue’s parts are. Taken while the queue is not ready and the device holds nothing, and checked when the queue is made ready.
Sourcepub const fn addresses(&self) -> RingAddresses
pub const fn addresses(&self) -> RingAddresses
The addresses the queue was given: what the transport is told.
Sourcepub const fn outstanding(&self) -> u16
pub const fn outstanding(&self) -> u16
Chains the device holds: published and not yet taken back.
Sourcepub const fn free_descriptors(&self) -> u16
pub const fn free_descriptors(&self) -> u16
Descriptors no chain holds.
Trait Implementations§
Source§impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> DriverQueue for DriverRing<M, N, R>
impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> DriverQueue for DriverRing<M, N, R>
Source§type Chain = DriverChain<M, R>
type Chain = DriverChain<M, R>
Source§type Reclaimed = ReclaimedChains<M, N, R>
type Reclaimed = ReclaimedChains<M, N, R>
Source§type Error = DriverRingError
type Error = DriverRingError
Source§fn publish(
&mut self,
chain: Self::Chain,
) -> Result<PublishedChain, PublishError<Self::Chain, Self::Error>>
fn publish( &mut self, chain: Self::Chain, ) -> Result<PublishedChain, PublishError<Self::Chain, Self::Error>>
Source§fn pop_used(
&mut self,
) -> Result<Option<UsedChain<Self::Chain>>, QueueError<Self::Error>>
fn pop_used( &mut self, ) -> Result<Option<UsedChain<Self::Chain>>, QueueError<Self::Error>>
Source§fn disable_used_notifications(&mut self) -> Result<(), QueueError<Self::Error>>
fn disable_used_notifications(&mut self) -> Result<(), QueueError<Self::Error>>
Source§fn enable_used_notifications(
&mut self,
) -> Result<NotificationRecheck, QueueError<Self::Error>>
fn enable_used_notifications( &mut self, ) -> Result<NotificationRecheck, QueueError<Self::Error>>
Source§impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> QueueControl for DriverRing<M, N, R>
impl<M: SharedMemory + Clone + Debug, const N: usize, const R: usize> QueueControl for DriverRing<M, N, R>
Source§fn set_ready(&mut self, ready: bool) -> Result<(), QueueError<Self::Error>>
fn set_ready(&mut self, ready: bool) -> Result<(), QueueError<Self::Error>>
Making the queue ready checks the layout. The first time after it was sized or placed it also clears both rings’ headers, because the memory may have held a queue before: do that before the transport is told the queue is live, while the memory is still only the driver’s. A queue made not ready and ready again is a pause, and resumes where it was.