pub trait VirtioDevice: AsAny + Send {
Show 22 methods
// Required methods
fn avail_features(&self) -> u64;
fn acked_features(&self) -> u64;
fn set_acked_features(&mut self, acked_features: u64);
fn const_device_type() -> u32
where Self: Sized;
fn device_type(&self) -> u32;
fn queues(&self) -> &[Queue];
fn queues_mut(&mut self) -> &mut [Queue];
fn queue_events(&self) -> &[EventFd];
fn interrupt_trigger(&self) -> &dyn VirtioInterrupt;
fn read_config(&self, offset: u64, data: &mut [u8]);
fn write_config(&mut self, offset: u64, data: &[u8]);
fn activate(
&mut self,
mem: GuestMemoryMmap,
interrupt: Arc<dyn VirtioInterrupt>,
) -> Result<(), ActivateError>;
fn is_activated(&self) -> bool;
// Provided methods
fn has_feature(&self, feature: u64) -> bool { ... }
fn interrupt_status(&self) -> Arc<AtomicU32> { ... }
fn avail_features_by_page(&self, page: u32) -> u32 { ... }
fn ack_features_by_page(&mut self, page: u32, value: u32) { ... }
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)> { ... }
fn mark_queue_memory_dirty(
&mut self,
mem: &GuestMemoryMmap,
) -> Result<(), QueueError> { ... }
fn kick(&mut self) { ... }
fn as_cow_file_engine(&self) -> Option<&CowFileEngine> { ... }
fn nyx_handle_queue_event(&mut self, _queue_index: u16) { ... }
}Expand description
Trait for virtio devices to be driven by a virtio transport.
The lifecycle of a virtio device is to be moved to a virtio transport, which will then query the device. The virtio devices needs to create queues, events and event fds for interrupts and expose them to the transport via get_queues/get_queue_events/get_interrupt/get_interrupt_status fns.
Required Methods§
Sourcefn avail_features(&self) -> u64
fn avail_features(&self) -> u64
Get the available features offered by device.
Sourcefn acked_features(&self) -> u64
fn acked_features(&self) -> u64
Get acknowledged features of the driver.
Sourcefn set_acked_features(&mut self, acked_features: u64)
fn set_acked_features(&mut self, acked_features: u64)
Set acknowledged features of the driver. This function must maintain the following invariant:
- self.avail_features() & self.acked_features() = self.get_acked_features()
Sourcefn const_device_type() -> u32where
Self: Sized,
fn const_device_type() -> u32where
Self: Sized,
The virtio device type (as a constant of the struct).
Sourcefn device_type(&self) -> u32
fn device_type(&self) -> u32
The virtio device type.
It should be the same as returned by Self::const_device_type().
Sourcefn queues_mut(&mut self) -> &mut [Queue]
fn queues_mut(&mut self) -> &mut [Queue]
Returns a mutable reference to the device queues.
Sourcefn queue_events(&self) -> &[EventFd]
fn queue_events(&self) -> &[EventFd]
Returns the device queues event fds.
fn interrupt_trigger(&self) -> &dyn VirtioInterrupt
Sourcefn read_config(&self, offset: u64, data: &mut [u8])
fn read_config(&self, offset: u64, data: &mut [u8])
Reads this device configuration space at offset.
Sourcefn write_config(&mut self, offset: u64, data: &[u8])
fn write_config(&mut self, offset: u64, data: &[u8])
Writes to this device configuration space at offset.
Sourcefn activate(
&mut self,
mem: GuestMemoryMmap,
interrupt: Arc<dyn VirtioInterrupt>,
) -> Result<(), ActivateError>
fn activate( &mut self, mem: GuestMemoryMmap, interrupt: Arc<dyn VirtioInterrupt>, ) -> Result<(), ActivateError>
Performs the formal activation for a device, which can be verified also with is_activated.
Sourcefn is_activated(&self) -> bool
fn is_activated(&self) -> bool
Checks if the resources of this device are activated.
Provided Methods§
Sourcefn has_feature(&self, feature: u64) -> bool
fn has_feature(&self, feature: u64) -> bool
Check if virtio device has negotiated given feature.
Sourcefn interrupt_status(&self) -> Arc<AtomicU32>
fn interrupt_status(&self) -> Arc<AtomicU32>
Returns the current device interrupt status.
Sourcefn avail_features_by_page(&self, page: u32) -> u32
fn avail_features_by_page(&self, page: u32) -> u32
The set of feature bits shifted by page * 32.
Sourcefn ack_features_by_page(&mut self, page: u32, value: u32)
fn ack_features_by_page(&mut self, page: u32, value: u32)
Acknowledges that this set of features should be enabled.
Sourcefn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)>
fn reset(&mut self) -> Option<(Arc<dyn VirtioInterrupt>, Vec<EventFd>)>
Optionally deactivates this device and returns ownership of the guest memory map, interrupt event, and queue events.
Sourcefn mark_queue_memory_dirty(
&mut self,
mem: &GuestMemoryMmap,
) -> Result<(), QueueError>
fn mark_queue_memory_dirty( &mut self, mem: &GuestMemoryMmap, ) -> Result<(), QueueError>
Mark pages used by queues as dirty.
Sourcefn as_cow_file_engine(&self) -> Option<&CowFileEngine>
fn as_cow_file_engine(&self) -> Option<&CowFileEngine>
Returns a COW file engine if the device exposes one (NYX extension).
Sourcefn nyx_handle_queue_event(&mut self, _queue_index: u16)
fn nyx_handle_queue_event(&mut self, _queue_index: u16)
Handle a queue notification from an MMIO write (NYX extension).