mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-24 04:12:21 +00:00
vmm: device_manager: introduce add_passthrough_device
It calls add_vfio_device on KVM or returns an error when not running on KVM. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
821892419c
commit
d484a3383c
@ -369,6 +369,9 @@ pub enum DeviceManagerError {
|
|||||||
/// Missing PCI b/d/f from the DeviceNode.
|
/// Missing PCI b/d/f from the DeviceNode.
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
MissingDeviceNodePciBdf,
|
MissingDeviceNodePciBdf,
|
||||||
|
|
||||||
|
/// No support for device passthrough
|
||||||
|
NoDevicePassthroughSupport,
|
||||||
}
|
}
|
||||||
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
|
pub type DeviceManagerResult<T> = result::Result<T, DeviceManagerError>;
|
||||||
|
|
||||||
@ -2383,6 +2386,21 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
|
fn add_passthrough_device(
|
||||||
|
&mut self,
|
||||||
|
pci: &mut PciBus,
|
||||||
|
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||||
|
device_fd: &Arc<DeviceFd>,
|
||||||
|
device_cfg: &mut DeviceConfig,
|
||||||
|
) -> DeviceManagerResult<(u32, String)> {
|
||||||
|
#[cfg(feature = "kvm")]
|
||||||
|
return self.add_vfio_device(pci, interrupt_manager, device_fd, device_cfg);
|
||||||
|
|
||||||
|
#[cfg(not(feature = "kvm"))]
|
||||||
|
Err(DeviceManagerError::NoDevicePassthroughSupport)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "pci_support", feature = "kvm"))]
|
||||||
fn add_vfio_device(
|
fn add_vfio_device(
|
||||||
&mut self,
|
&mut self,
|
||||||
pci: &mut PciBus,
|
pci: &mut PciBus,
|
||||||
@ -2503,7 +2521,7 @@ impl DeviceManager {
|
|||||||
|
|
||||||
for device_cfg in device_list_cfg.iter_mut() {
|
for device_cfg in device_list_cfg.iter_mut() {
|
||||||
let (device_id, _) =
|
let (device_id, _) =
|
||||||
self.add_vfio_device(pci, interrupt_manager, &device_fd, device_cfg)?;
|
self.add_passthrough_device(pci, interrupt_manager, &device_fd, device_cfg)?;
|
||||||
if device_cfg.iommu && self.iommu_device.is_some() {
|
if device_cfg.iommu && self.iommu_device.is_some() {
|
||||||
iommu_attached_device_ids.push(device_id);
|
iommu_attached_device_ids.push(device_id);
|
||||||
}
|
}
|
||||||
@ -2934,7 +2952,7 @@ impl DeviceManager {
|
|||||||
device_fd
|
device_fd
|
||||||
};
|
};
|
||||||
|
|
||||||
let (device_id, device_name) = self.add_vfio_device(
|
let (device_id, device_name) = self.add_passthrough_device(
|
||||||
&mut pci.lock().unwrap(),
|
&mut pci.lock().unwrap(),
|
||||||
&interrupt_manager,
|
&interrupt_manager,
|
||||||
&device_fd,
|
&device_fd,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user