Trait devices::virtio::VirtioDevice
source · pub trait VirtioDevice: Send {
Show 28 methods
// Required methods
fn keep_rds(&self) -> Vec<RawDescriptor>;
fn device_type(&self) -> DeviceType;
fn queue_max_sizes(&self) -> &[u16];
fn activate(
&mut self,
mem: GuestMemory,
interrupt: Interrupt,
queues: BTreeMap<usize, Queue>
) -> Result<()>;
// Provided methods
fn debug_label(&self) -> String { ... }
fn num_interrupts(&self) -> usize { ... }
fn features(&self) -> u64 { ... }
fn ack_features(&mut self, value: u64) { ... }
fn read_config(&self, offset: u64, data: &mut [u8]) { ... }
fn write_config(&mut self, offset: u64, data: &[u8]) { ... }
fn reset(&mut self) -> Result<()> { ... }
fn get_device_bars(
&mut self,
_address: PciAddress
) -> Vec<PciBarConfiguration> { ... }
fn get_device_caps(&self) -> Vec<Box<dyn PciCapability>> { ... }
fn on_device_sandboxed(&mut self) { ... }
fn control_notify(&self, _behavior: MsixStatus) { ... }
fn generate_acpi(
&mut self,
_pci_address: &Option<PciAddress>,
sdts: Vec<SDT>
) -> Option<Vec<SDT>> { ... }
fn pci_address(&self) -> Option<PciAddress> { ... }
fn transport_type(&self) -> VirtioTransportType { ... }
fn get_shared_memory_region(&self) -> Option<SharedMemoryRegion> { ... }
fn expose_shmem_descriptors_with_viommu(&self) -> bool { ... }
fn set_shared_memory_mapper(&mut self, _mapper: Box<dyn SharedMemoryMapper>) { ... }
fn set_shared_memory_region(&mut self, shmem_region: AddressRange) { ... }
fn get_shared_memory_prepare_type(&mut self) -> SharedMemoryPrepareType { ... }
fn virtio_sleep(&mut self) -> Result<Option<BTreeMap<usize, Queue>>> { ... }
fn virtio_wake(
&mut self,
_queues_state: Option<(GuestMemory, Interrupt, BTreeMap<usize, Queue>)>
) -> Result<()> { ... }
fn virtio_snapshot(&mut self) -> Result<Value> { ... }
fn virtio_restore(&mut self, _data: Value) -> Result<()> { ... }
fn bootorder_fw_cfg(&self, _pci_address: u8) -> Option<(Vec<u8>, usize)> { ... }
}
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. Once the guest driver has configured the device, VirtioDevice::activate
will be called
and all the events, memory, and queues for device operation will be moved into the device.
Optionally, a virtio device can implement device reset in which it returns said resources and
resets its internal.
Virtio device state machine
restore (inactive)
----------------------------------------------------
| |
| V
| ------------ --------------
------------- restore(active) | asleep | | asleep | // States in this row
|asleep(new)|---------------> | (active) | | (inactive) | // can be snapshotted
------------- ------------ --------------
^ | ^ | ^ |
| | | | | |
sleep wake sleep wake sleep wake
| | | | | |
| V | V | V
------------ activate ---------- reset ------------
| new | ---------------> | active | ------> | inactive |
------------ ---------- <------ ------------
activate
Required Methods§
sourcefn keep_rds(&self) -> Vec<RawDescriptor>
fn keep_rds(&self) -> Vec<RawDescriptor>
A vector of device-specific file descriptors that must be kept open after jailing. Must be called before the process is jailed.
sourcefn device_type(&self) -> DeviceType
fn device_type(&self) -> DeviceType
The virtio device type.
sourcefn queue_max_sizes(&self) -> &[u16]
fn queue_max_sizes(&self) -> &[u16]
The maximum size of each queue that this device supports.
Provided Methods§
sourcefn debug_label(&self) -> String
fn debug_label(&self) -> String
Returns a label suitable for debug output.
sourcefn num_interrupts(&self) -> usize
fn num_interrupts(&self) -> usize
The number of interrupts used by this device.
sourcefn features(&self) -> u64
fn features(&self) -> u64
The set of feature bits that this device supports in addition to the base features.
sourcefn ack_features(&mut self, value: u64)
fn ack_features(&mut self, value: u64)
Acknowledges that this set of features should be enabled.
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 reset(&mut self) -> Result<()>
fn reset(&mut self) -> Result<()>
Optionally deactivates this device. If the reset method is
not able to reset the virtio device, or the virtio device model doesn’t
implement the reset method, an Err
value is returned to indicate
the reset is not successful. Otherwise Ok(())
should be returned.
sourcefn get_device_bars(&mut self, _address: PciAddress) -> Vec<PciBarConfiguration>
fn get_device_bars(&mut self, _address: PciAddress) -> Vec<PciBarConfiguration>
Returns any additional BAR configuration required by the device.
sourcefn get_device_caps(&self) -> Vec<Box<dyn PciCapability>>
fn get_device_caps(&self) -> Vec<Box<dyn PciCapability>>
Returns any additional capabiltiies required by the device.
sourcefn on_device_sandboxed(&mut self)
fn on_device_sandboxed(&mut self)
Invoked when the device is sandboxed.
fn control_notify(&self, _behavior: MsixStatus)
fn generate_acpi( &mut self, _pci_address: &Option<PciAddress>, sdts: Vec<SDT> ) -> Option<Vec<SDT>>
sourcefn pci_address(&self) -> Option<PciAddress>
fn pci_address(&self) -> Option<PciAddress>
Returns the PCI address where the device will be allocated.
Returns None
if any address is good for the device.
sourcefn transport_type(&self) -> VirtioTransportType
fn transport_type(&self) -> VirtioTransportType
Returns the Virtio transport type: PCI (default for crosvm) or MMIO.
Returns the device’s shared memory region if present.
sourcefn expose_shmem_descriptors_with_viommu(&self) -> bool
fn expose_shmem_descriptors_with_viommu(&self) -> bool
If true, VFIO passthrough devices can access descriptors mapped into this region by mapping the corresponding addresses from this device’s PCI bar into their IO address space with virtio-iommu.
NOTE: Not all vm_control::VmMemorySource types are supported. NOTE: Not yet compatible with PrepareSharedMemoryRegion (aka fixed mapping).
Provides the trait object used to map files into the device’s shared memory region.
If get_shared_memory_region
returns Some
, then this will be called
before activate
.
Provides the guest address range of the shared memory region, if one is present. Will
be called before activate
.
Queries the implementation whether a single prepared hypervisor memory mapping with explicit caching type should be setup lazily on first mapping request, or whether to dynamically setup a hypervisor mapping with every request’s caching type.
sourcefn virtio_sleep(&mut self) -> Result<Option<BTreeMap<usize, Queue>>>
fn virtio_sleep(&mut self) -> Result<Option<BTreeMap<usize, Queue>>>
Pause all processing.
Gives up the queues so that a higher layer can potentially snapshot them. The
implementations should also drop the Interrupt
and queues Event
s that were given along
with the queues originally.
Unlike Suspendable::sleep
, this is not idempotent. Attempting to sleep while already
asleep is an error.
sourcefn virtio_wake(
&mut self,
_queues_state: Option<(GuestMemory, Interrupt, BTreeMap<usize, Queue>)>
) -> Result<()>
fn virtio_wake( &mut self, _queues_state: Option<(GuestMemory, Interrupt, BTreeMap<usize, Queue>)> ) -> Result<()>
Resume all processing.
If the device’s queues are active, then the queues and associated data will is included.
Unlike Suspendable::wake
, this is not idempotent. Attempting to wake while already awake
is an error.
sourcefn virtio_snapshot(&mut self) -> Result<Value>
fn virtio_snapshot(&mut self) -> Result<Value>
Snapshot current state. Device must be asleep.
sourcefn virtio_restore(&mut self, _data: Value) -> Result<()>
fn virtio_restore(&mut self, _data: Value) -> Result<()>
Restore device state from a snapshot. TODO(b/280607404): Vhost user will need fds passed to the device process.