pub struct AvailableRing<T: GuestMemoryAccessor + Clone> {
pub base_addr: GuestPhysAddr,
pub size: u16,
pub last_avail_idx: u16,
/* private fields */
}Expand description
Available ring management structure.
This structure provides a high-level interface for managing the VirtIO available ring in guest memory. It wraps the guest memory accessor and provides methods to read/write various parts of the available ring:
- The header (VirtQueueAvail structure)
- The ring array of descriptor indices
- The used_event field (if VIRTIO_F_EVENT_IDX is negotiated)
Relationship with VirtQueueAvail:
- VirtQueueAvail defines the memory layout of the available ring header
- AvailableRing uses VirtQueueAvail to access the header in guest memory
- AvailableRing manages the entire available ring structure, not just the header
Memory Layout:
base_addr -> +-------------------+
| VirtQueueAvail | (flags + idx)
+-------------------+
| ring[0] | (descriptor index)
| ring[1] |
| ... |
| ring[queue_size-1]|
+-------------------+
| used_event | (optional, if event_idx enabled)
+-------------------+Fields§
§base_addr: GuestPhysAddrBase address of the available ring
size: u16Queue size
last_avail_idx: u16Last seen available index
Implementations§
Source§impl<T: GuestMemoryAccessor + Clone> AvailableRing<T>
impl<T: GuestMemoryAccessor + Clone> AvailableRing<T>
Sourcepub fn new(base_addr: GuestPhysAddr, size: u16, accessor: Arc<T>) -> Self
pub fn new(base_addr: GuestPhysAddr, size: u16, accessor: Arc<T>) -> Self
Create a new available ring
Sourcepub fn header_addr(&self) -> GuestPhysAddr
pub fn header_addr(&self) -> GuestPhysAddr
Get the address of the available ring header
Sourcepub fn ring_addr(&self) -> GuestPhysAddr
pub fn ring_addr(&self) -> GuestPhysAddr
Get the address of the ring array
Sourcepub fn ring_entry_addr(&self, index: u16) -> Option<GuestPhysAddr>
pub fn ring_entry_addr(&self, index: u16) -> Option<GuestPhysAddr>
Get the address of a specific ring entry
Sourcepub fn used_event_addr(&self) -> GuestPhysAddr
pub fn used_event_addr(&self) -> GuestPhysAddr
Get the address of the used event field (if event_idx is enabled)
Sourcepub fn total_size(&self) -> usize
pub fn total_size(&self) -> usize
Calculate the total size of the available ring
Sourcepub fn has_new_avail(&self, current_idx: u16) -> bool
pub fn has_new_avail(&self, current_idx: u16) -> bool
Check if there are new available descriptors
Sourcepub fn update_last_avail_idx(&mut self, idx: u16)
pub fn update_last_avail_idx(&mut self, idx: u16)
Update the last seen available index
Sourcepub fn read_avail_header(&self) -> VirtioResult<VirtQueueAvail>
pub fn read_avail_header(&self) -> VirtioResult<VirtQueueAvail>
Read the available ring header
Sourcepub fn write_avail_header(&self, header: &VirtQueueAvail) -> VirtioResult<()>
pub fn write_avail_header(&self, header: &VirtQueueAvail) -> VirtioResult<()>
Write the available ring header
Sourcepub fn read_avail_idx(&self) -> VirtioResult<u16>
pub fn read_avail_idx(&self) -> VirtioResult<u16>
Read the current available index from guest memory
Sourcepub fn get_avail_idx(&self) -> VirtioResult<u16>
pub fn get_avail_idx(&self) -> VirtioResult<u16>
Get the available index for external access
Sourcepub fn read_avail_ring_entry(&self, ring_index: u16) -> VirtioResult<u16>
pub fn read_avail_ring_entry(&self, ring_index: u16) -> VirtioResult<u16>
Read a descriptor index from the available ring
Sourcepub fn write_avail_ring_entry(
&self,
ring_index: u16,
desc_index: u16,
) -> VirtioResult<()>
pub fn write_avail_ring_entry( &self, ring_index: u16, desc_index: u16, ) -> VirtioResult<()>
Write a descriptor index to the available ring
Sourcepub fn get_available_count(&self) -> VirtioResult<u16>
pub fn get_available_count(&self) -> VirtioResult<u16>
Get the number of available descriptors since last check
Sourcepub fn interrupts_suppressed(&self) -> VirtioResult<bool>
pub fn interrupts_suppressed(&self) -> VirtioResult<bool>
Check if interrupts are suppressed
Sourcepub fn set_interrupt_suppression(&self, suppress: bool) -> VirtioResult<()>
pub fn set_interrupt_suppression(&self, suppress: bool) -> VirtioResult<()>
Set interrupt suppression
Sourcepub fn read_used_event(&self) -> VirtioResult<u16>
pub fn read_used_event(&self) -> VirtioResult<u16>
Read the used event field (for event_idx feature)
Sourcepub fn write_used_event(&self, event: u16) -> VirtioResult<()>
pub fn write_used_event(&self, event: u16) -> VirtioResult<()>
Write the used event field (for event_idx feature)
Trait Implementations§
Source§impl<T: Clone + GuestMemoryAccessor + Clone> Clone for AvailableRing<T>
impl<T: Clone + GuestMemoryAccessor + Clone> Clone for AvailableRing<T>
Source§fn clone(&self) -> AvailableRing<T>
fn clone(&self) -> AvailableRing<T>
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more