Struct devices::VfioPciDevice
source · pub struct VfioPciDevice {Show 28 fields
device: Arc<VfioDevice>,
config: VfioPciConfig,
hotplug: bool,
hotplug_bus_number: Option<u8>,
preferred_address: PciAddress,
pci_address: Option<PciAddress>,
interrupt_evt: Option<IrqLevelEvent>,
acpi_notification_evt: Option<Event>,
mmio_regions: Vec<PciBarConfiguration>,
io_regions: Vec<PciBarConfiguration>,
pm_cap: Option<Arc<Mutex<VfioPmCap>>>,
msi_cap: Option<VfioMsiCap>,
msix_cap: Option<Arc<Mutex<VfioMsixCap>>>,
irq_type: Option<VfioIrqType>,
vm_memory_client: VmMemoryClient,
device_data: Option<DeviceData>,
pm_evt: Option<Event>,
is_in_low_power: Arc<Mutex<bool>>,
worker_thread: Option<WorkerThread<VfioPciWorker>>,
vm_socket_vm: Option<Tube>,
sysfs_path: PathBuf,
ext_caps: Vec<ExtCap>,
vcfg_shm_mmap: Option<MemoryMapping>,
mapped_mmio_bars: BTreeMap<PciBarIndex, (u64, Vec<VmMemoryRegionId>)>,
activated: bool,
acpi_notifier_val: Arc<Mutex<Vec<u32>>>,
gpe: Option<u32>,
base_class_code: PciClassCode,
}
Expand description
Implements the Vfio Pci device, then a pci device is added into vm
Fields§
§device: Arc<VfioDevice>
§config: VfioPciConfig
§hotplug: bool
§hotplug_bus_number: Option<u8>
§preferred_address: PciAddress
§pci_address: Option<PciAddress>
§interrupt_evt: Option<IrqLevelEvent>
§acpi_notification_evt: Option<Event>
§mmio_regions: Vec<PciBarConfiguration>
§io_regions: Vec<PciBarConfiguration>
§pm_cap: Option<Arc<Mutex<VfioPmCap>>>
§msi_cap: Option<VfioMsiCap>
§msix_cap: Option<Arc<Mutex<VfioMsixCap>>>
§irq_type: Option<VfioIrqType>
§vm_memory_client: VmMemoryClient
§device_data: Option<DeviceData>
§pm_evt: Option<Event>
§is_in_low_power: Arc<Mutex<bool>>
§worker_thread: Option<WorkerThread<VfioPciWorker>>
§vm_socket_vm: Option<Tube>
§sysfs_path: PathBuf
§ext_caps: Vec<ExtCap>
§vcfg_shm_mmap: Option<MemoryMapping>
§mapped_mmio_bars: BTreeMap<PciBarIndex, (u64, Vec<VmMemoryRegionId>)>
§activated: bool
§acpi_notifier_val: Arc<Mutex<Vec<u32>>>
§gpe: Option<u32>
§base_class_code: PciClassCode
Implementations§
source§impl VfioPciDevice
impl VfioPciDevice
sourcepub fn new(
sysfs_path: &Path,
device: VfioDevice,
hotplug: bool,
hotplug_bus_number: Option<u8>,
guest_address: Option<PciAddress>,
vfio_device_socket_msi: Tube,
vfio_device_socket_msix: Tube,
vm_memory_client: VmMemoryClient,
vfio_device_socket_vm: Tube
) -> Result<Self, PciDeviceError>
pub fn new( sysfs_path: &Path, device: VfioDevice, hotplug: bool, hotplug_bus_number: Option<u8>, guest_address: Option<PciAddress>, vfio_device_socket_msi: Tube, vfio_device_socket_msix: Tube, vm_memory_client: VmMemoryClient, vfio_device_socket_vm: Tube ) -> Result<Self, PciDeviceError>
Constructs a new Vfio Pci device for the give Vfio device
sourcepub fn pci_address(&self) -> Option<PciAddress>
pub fn pci_address(&self) -> Option<PciAddress>
Gets the pci address of the device, if one has already been allocated.
pub fn is_gfx(&self) -> bool
fn is_intel_gfx(&self) -> bool
fn enable_acpi_notification(&mut self) -> Result<(), PciDeviceError>
fn disable_acpi_notification(&mut self) -> Result<(), PciDeviceError>
fn test_acpi_notification(&mut self, val: u32) -> Result<(), PciDeviceError>
fn enable_intx(&mut self)
fn disable_intx(&mut self)
fn disable_irqs(&mut self)
fn enable_msi(&mut self)
fn disable_msi(&mut self)
fn enable_msix(&mut self)
fn disable_msix(&mut self)
fn msix_vectors_update(&self) -> Result<(), VfioError>
fn msix_vector_update(&self, index: usize, irqfd: Option<&Event>)
fn adjust_bar_mmap( &self, bar_mmaps: Vec<vfio_region_sparse_mmap_area>, remove_mmaps: &[AddressRange] ) -> Vec<vfio_region_sparse_mmap_area>
fn remove_bar_mmap_msix( &self, bar_index: PciBarIndex, bar_mmaps: Vec<vfio_region_sparse_mmap_area> ) -> Vec<vfio_region_sparse_mmap_area>
fn add_bar_mmap( &self, index: PciBarIndex, bar_addr: u64 ) -> Vec<VmMemoryRegionId>
fn remove_bar_mmap(&self, mmap_ids: &[VmMemoryRegionId])
fn disable_bars_mmap(&mut self)
fn commit_bars_mmap(&mut self)
fn close(&mut self)
fn start_work_thread(&mut self)
fn collect_bars(&mut self) -> Vec<PciBarConfiguration>
fn configure_barmem(&mut self, bar_info: &PciBarConfiguration, bar_addr: u64)
fn allocate_root_barmem( &mut self, mem_bars: &[PciBarConfiguration], resources: &mut SystemAllocator ) -> Result<Vec<BarRange>, PciDeviceError>
fn allocate_nonroot_barmem( &mut self, mem_bars: &mut [PciBarConfiguration], resources: &mut SystemAllocator ) -> Result<Vec<BarRange>, PciDeviceError>
sourcepub fn get_max_iova(&self) -> u64
pub fn get_max_iova(&self) -> u64
Return the supported iova max address of the Vfio Pci device
fn get_ext_cap_by_reg(&self, reg: u32) -> Option<ExtCap>
fn is_skipped_reg(&self, reg: u32) -> bool
Trait Implementations§
source§impl PciDevice for VfioPciDevice
impl PciDevice for VfioPciDevice
source§fn debug_label(&self) -> String
fn debug_label(&self) -> String
Returns a label suitable for debug output.
source§fn preferred_address(&self) -> Option<PciAddress>
fn preferred_address(&self) -> Option<PciAddress>
Preferred PCI address for this device, if any.
source§fn allocate_address(
&mut self,
resources: &mut SystemAllocator
) -> Result<PciAddress, PciDeviceError>
fn allocate_address( &mut self, resources: &mut SystemAllocator ) -> Result<PciAddress, PciDeviceError>
Allocate and return an unique bus, device and function number for this device.
May be called multiple times; on subsequent calls, the device should return the same
address it returned from the first call.
source§fn 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.
source§fn preferred_irq(&self) -> PreferredIrq
fn preferred_irq(&self) -> PreferredIrq
Preferred IRQ for this device.
The device may request a specific pin and IRQ number by returning a
Fixed
value.
If a device does not support INTx# interrupts at all, it should return None
.
Otherwise, an appropriate IRQ will be allocated automatically.
The device’s assign_irq
function will be called with its assigned IRQ either way.source§fn assign_irq(
&mut self,
irq_evt: IrqLevelEvent,
pin: PciInterruptPin,
irq_num: u32
)
fn assign_irq( &mut self, irq_evt: IrqLevelEvent, pin: PciInterruptPin, irq_num: u32 )
Assign a legacy PCI IRQ to this device.
The device may write to
irq_evt
to trigger an interrupt.
When irq_resample_evt
is signaled, the device should re-assert irq_evt
if necessary.source§fn allocate_io_bars(
&mut self,
resources: &mut SystemAllocator
) -> Result<Vec<BarRange>, PciDeviceError>
fn allocate_io_bars( &mut self, resources: &mut SystemAllocator ) -> Result<Vec<BarRange>, PciDeviceError>
Allocates the needed IO BAR space using the
allocate
function which takes a size and
returns an address. Returns a Vec of BarRange{addr, size, prefetchable}.source§fn allocate_device_bars(
&mut self,
resources: &mut SystemAllocator
) -> Result<Vec<BarRange>, PciDeviceError>
fn allocate_device_bars( &mut self, resources: &mut SystemAllocator ) -> Result<Vec<BarRange>, PciDeviceError>
Allocates the needed device BAR space. Returns a Vec of BarRange{addr, size, prefetchable}.
Unlike MMIO BARs (see allocate_io_bars), device BARs are not expected to incur VM exits Read more
source§fn get_bar_configuration(&self, bar_num: usize) -> Option<PciBarConfiguration>
fn get_bar_configuration(&self, bar_num: usize) -> Option<PciBarConfiguration>
Returns the configuration of a base address register, if present.
source§fn register_device_capabilities(&mut self) -> Result<(), PciDeviceError>
fn register_device_capabilities(&mut self) -> Result<(), PciDeviceError>
Register any capabilties specified by the device.
source§fn read_config_register(&self, reg_idx: usize) -> u32
fn read_config_register(&self, reg_idx: usize) -> u32
Reads from a PCI configuration register. Read more
source§fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8])
fn write_config_register(&mut self, reg_idx: usize, offset: u64, data: &[u8])
Writes to a PCI configuration register. Read more
source§fn read_virtual_config_register(&self, reg_idx: usize) -> u32
fn read_virtual_config_register(&self, reg_idx: usize) -> u32
Reads from a virtual config register. Read more
source§fn write_virtual_config_register(&mut self, reg_idx: usize, value: u32)
fn write_virtual_config_register(&mut self, reg_idx: usize, value: u32)
Writes to a virtual config register. Read more
source§fn read_bar(&mut self, bar_index: PciBarIndex, offset: u64, data: &mut [u8])
fn read_bar(&mut self, bar_index: PciBarIndex, offset: u64, data: &mut [u8])
Reads from a BAR region mapped in to the device. Read more
source§fn write_bar(&mut self, bar_index: PciBarIndex, offset: u64, data: &[u8])
fn write_bar(&mut self, bar_index: PciBarIndex, offset: u64, data: &[u8])
Writes to a BAR region mapped in to the device. Read more
source§fn destroy_device(&mut self)
fn destroy_device(&mut self)
Invoked when the device is destroyed
source§fn generate_acpi_methods(&mut self) -> (Vec<u8>, Option<(u32, MemoryMapping)>)
fn generate_acpi_methods(&mut self) -> (Vec<u8>, Option<(u32, MemoryMapping)>)
Construct customized acpi method, and return the AML code and
shared memory
fn set_gpe(&mut self, resources: &mut SystemAllocator) -> Option<u32>
source§fn get_vm_memory_client(&self) -> Option<&VmMemoryClient>
fn get_vm_memory_client(&self) -> Option<&VmMemoryClient>
Gets a reference to the API client for sending VmMemoryRequest. Any devices that uses
ioevents must provide this.
source§fn setup_pci_config_mapping(
&mut self,
_shmem: &SharedMemory,
_base: usize,
_len: usize
) -> Result<bool, Error>
fn setup_pci_config_mapping( &mut self, _shmem: &SharedMemory, _base: usize, _len: usize ) -> Result<bool, Error>
Provides a memory region to back MMIO access to the configuration
space. If the device can keep the memory region up to date, then it
should return Ok(true), after which no more calls to read_config_register
will be made. If support isn’t implemented, it should return Ok(false).
Otherwise, it should return an error (a failure here is not treated as
a fatal setup error). Read more
source§fn on_device_sandboxed(&mut self)
fn on_device_sandboxed(&mut self)
Invoked when the device is sandboxed.
fn generate_acpi(&mut self, sdts: Vec<SDT>) -> Option<Vec<SDT>>
source§fn get_removed_children_devices(&self) -> Vec<PciAddress>
fn get_removed_children_devices(&self) -> Vec<PciAddress>
Get the removed children devices under pci bridge
source§fn get_new_pci_bus(&self) -> Option<Arc<Mutex<PciBus>>>
fn get_new_pci_bus(&self) -> Option<Arc<Mutex<PciBus>>>
Get the pci bus generated by this pci device
source§fn configure_bridge_window(
&mut self,
_resources: &mut SystemAllocator,
_bar_ranges: &[BarRange]
) -> Result<Vec<BarRange>, Error>
fn configure_bridge_window( &mut self, _resources: &mut SystemAllocator, _bar_ranges: &[BarRange] ) -> Result<Vec<BarRange>, Error>
if device is a pci brdige, configure pci bridge window
source§fn set_subordinate_bus(&mut self, _bus_no: u8)
fn set_subordinate_bus(&mut self, _bus_no: u8)
if device is a pci bridge, configure subordinate bus number
source§fn supports_iommu(&self) -> bool
fn supports_iommu(&self) -> bool
Indicates whether the device supports IOMMU
source§fn set_iommu(&mut self, _iommu: IpcMemoryMapper) -> Result<()>
fn set_iommu(&mut self, _iommu: IpcMemoryMapper) -> Result<()>
Sets the IOMMU for the device if
supports_iommu()
fn as_virtio_pci_device(&self) -> Option<&VirtioPciDevice>
source§impl Suspendable for VfioPciDevice
impl Suspendable for VfioPciDevice
source§fn sleep(&mut self) -> Result<()>
fn sleep(&mut self) -> Result<()>
Stop all threads related to the device.
Sleep should be idempotent.
source§fn wake(&mut self) -> Result<()>
fn wake(&mut self) -> Result<()>
Create/Resume all threads related to the device.
Wake should be idempotent.
Auto Trait Implementations§
impl !RefUnwindSafe for VfioPciDevice
impl Send for VfioPciDevice
impl Sync for VfioPciDevice
impl Unpin for VfioPciDevice
impl !UnwindSafe for VfioPciDevice
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
source§impl<T> BusDevice for Twhere
T: PciDevice,
impl<T> BusDevice for Twhere
T: PciDevice,
source§fn debug_label(&self) -> String
fn debug_label(&self) -> String
Returns a label suitable for debug output.
source§fn device_id(&self) -> DeviceId
fn device_id(&self) -> DeviceId
Returns a unique id per device type suitable for metrics gathering.
source§fn read(&mut self, info: BusAccessInfo, data: &mut [u8])
fn read(&mut self, info: BusAccessInfo, data: &mut [u8])
Reads at
offset
from this devicesource§fn write(&mut self, info: BusAccessInfo, data: &[u8])
fn write(&mut self, info: BusAccessInfo, data: &[u8])
Writes at
offset
into this devicesource§fn config_register_write(
&mut self,
reg_idx: usize,
offset: u64,
data: &[u8]
) -> ConfigWriteResult
fn config_register_write( &mut self, reg_idx: usize, offset: u64, data: &[u8] ) -> ConfigWriteResult
Sets a register in the configuration space. Only used by PCI. Read more
source§fn config_register_read(&self, reg_idx: usize) -> u32
fn config_register_read(&self, reg_idx: usize) -> u32
Gets a register from the configuration space. Only used by PCI. Read more
source§fn init_pci_config_mapping(
&mut self,
shmem: &SharedMemory,
base: usize,
len: usize
) -> bool
fn init_pci_config_mapping( &mut self, shmem: &SharedMemory, base: usize, len: usize ) -> bool
Provides a memory region to back MMIO access to the configuration
space. If the device can keep the memory region up to date, then it
should return true, after which no more calls to config_register_read
will be made. Otherwise the device should return false. Read more
source§fn virtual_config_register_write(&mut self, reg_idx: usize, value: u32)
fn virtual_config_register_write(&mut self, reg_idx: usize, value: u32)
Sets a register in the virtual config space. Only used by PCI. Read more
source§fn virtual_config_register_read(&self, reg_idx: usize) -> u32
fn virtual_config_register_read(&self, reg_idx: usize) -> u32
Gets a register from the virtual config space. Only used by PCI. Read more
source§fn on_sandboxed(&mut self)
fn on_sandboxed(&mut self)
Invoked when the device is sandboxed.
source§fn get_ranges(&self) -> Vec<(BusRange, BusType)>
fn get_ranges(&self) -> Vec<(BusRange, BusType)>
Gets a list of all ranges registered by this BusDevice.
source§fn destroy_device(&mut self)
fn destroy_device(&mut self)
Invoked when the device is destroyed
source§impl<T> BusDeviceObj for Twhere
T: 'static + PciDevice,
impl<T> BusDeviceObj for Twhere
T: 'static + PciDevice,
fn as_pci_device(&self) -> Option<&dyn PciDevice>
fn as_pci_device_mut(&mut self) -> Option<&mut dyn PciDevice>
fn into_pci_device(self: Box<T>) -> Option<Box<dyn PciDevice>>
fn as_platform_device(&self) -> Option<&VfioPlatformDevice>
fn as_platform_device_mut(&mut self) -> Option<&mut VfioPlatformDevice>
fn into_platform_device(self: Box<Self>) -> Option<Box<VfioPlatformDevice>>
fn as_virtio_mmio_device(&self) -> Option<&VirtioMmioDevice>
fn as_virtio_mmio_device_mut(&mut self) -> Option<&mut VirtioMmioDevice>
fn into_virtio_mmio_device(self: Box<Self>) -> Option<Box<VirtioMmioDevice>>
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait>
(where Trait: Downcast
) to Box<dyn Any>
. Box<dyn Any>
can
then be further downcast
into Box<ConcreteType>
where ConcreteType
implements Trait
.§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait>
(where Trait: Downcast
) to Rc<Any>
. Rc<Any>
can then be
further downcast
into Rc<ConcreteType>
where ConcreteType
implements Trait
.§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &Any
’s vtable from &Trait
’s.§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.