pub struct UsedRing<T: GuestMemoryAccessor + Clone> {
pub base_addr: GuestPhysAddr,
pub size: u16,
pub used_idx: u16,
/* private fields */
}Expand description
Used ring management structure.
This structure provides a high-level interface for managing the VirtIO used ring in guest memory. It wraps the guest memory accessor and provides methods to read/write various parts of the used ring:
- The header (VirtQueueUsed structure)
- The ring array of used elements (VirtqUsedElem structures)
- The avail_event field (if VIRTIO_F_EVENT_IDX is negotiated)
Relationship with VirtQueueUsed and VirtqUsedElem:
- VirtQueueUsed defines the memory layout of the used ring header
- VirtqUsedElem defines the memory layout of each ring element
- UsedRing uses both structures to access the complete used ring in guest memory
- UsedRing manages the entire used ring structure and provides high-level operations
Memory Layout:
base_addr -> +-------------------+
| VirtQueueUsed | (flags + idx)
+-------------------+
| ring[0] | (VirtqUsedElem: id + len)
| ring[1] | (VirtqUsedElem: id + len)
| ... |
| ring[queue_size-1]| (VirtqUsedElem: id + len)
+-------------------+
| avail_event | (optional, if event_idx enabled)
+-------------------+Fields§
§base_addr: GuestPhysAddrBase address of the used ring
size: u16Queue size
used_idx: u16Current used index
Implementations§
Source§impl<T: GuestMemoryAccessor + Clone> UsedRing<T>
impl<T: GuestMemoryAccessor + Clone> UsedRing<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 used ring
Sourcepub fn header_addr(&self) -> GuestPhysAddr
pub fn header_addr(&self) -> GuestPhysAddr
Get the address of the used 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 avail_event_addr(&self) -> GuestPhysAddr
pub fn avail_event_addr(&self) -> GuestPhysAddr
Get the address of the available 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 used ring
Sourcepub fn add_used(&mut self, id: u32, len: u32) -> VirtioResult<()>
pub fn add_used(&mut self, id: u32, len: u32) -> VirtioResult<()>
Add a used element to the ring
Sourcepub fn write_used_idx(&self) -> VirtioResult<()>
pub fn write_used_idx(&self) -> VirtioResult<()>
Write the used index to the used ring header
Sourcepub fn read_used_header(&self) -> VirtioResult<VirtQueueUsed>
pub fn read_used_header(&self) -> VirtioResult<VirtQueueUsed>
Read the used ring header
Sourcepub fn write_used_header(&self, header: &VirtQueueUsed) -> VirtioResult<()>
pub fn write_used_header(&self, header: &VirtQueueUsed) -> VirtioResult<()>
Write the used ring header
Sourcepub fn get_used_idx(&self) -> u16
pub fn get_used_idx(&self) -> u16
Get the current used index
Sourcepub fn set_used_idx(&mut self, idx: u16)
pub fn set_used_idx(&mut self, idx: u16)
Set the used index
Sourcepub fn should_notify(&self) -> VirtioResult<bool>
pub fn should_notify(&self) -> VirtioResult<bool>
Check if notifications should be suppressed
Sourcepub fn set_notification(&self, suppress: bool) -> VirtioResult<()>
pub fn set_notification(&self, suppress: bool) -> VirtioResult<()>
Set notification suppression