vmm: Remove hardcoded zero PCI segment id

Replace the hardcoded zero PCI segment id when adding devices to the bus
and extend the DeviceTree to hold the PCI segment id.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2021-10-07 18:07:13 +01:00
parent b8b0dab1ae
commit d33d254921
2 changed files with 73 additions and 48 deletions

View File

@@ -16,6 +16,7 @@ pub struct DeviceNode {
pub children: Vec<String>,
#[serde(skip)]
pub migratable: Option<Arc<Mutex<dyn Migratable>>>,
pub pci_segment_id: Option<u16>,
pub pci_bdf: Option<u32>,
#[serde(skip)]
pub pci_device_handle: Option<PciDeviceHandle>,
@@ -31,6 +32,7 @@ impl DeviceNode {
migratable,
pci_bdf: None,
pci_device_handle: None,
pci_segment_id: None,
}
}
}
@@ -79,17 +81,22 @@ impl DeviceTree {
pub fn pci_devices(&self) -> Vec<&DeviceNode> {
self.0
.values()
.filter(|v| v.pci_bdf.is_some() && v.pci_device_handle.is_some())
.filter(|v| {
v.pci_bdf.is_some() && v.pci_segment_id.is_some() && v.pci_device_handle.is_some()
})
.collect()
}
pub fn remove_node_by_pci_bdf(&mut self, pci_bdf: u32) -> Option<DeviceNode> {
pub fn remove_node_by_pci_bdf(
&mut self,
pci_segment_id: u16,
pci_bdf: u32,
) -> Option<DeviceNode> {
let mut id = None;
for (k, v) in self.0.iter() {
if let Some(bdf) = v.pci_bdf {
if bdf == pci_bdf {
id = Some(k.clone());
break;
}
if v.pci_segment_id == Some(pci_segment_id) && v.pci_bdf == Some(pci_bdf) {
id = Some(k.clone());
break;
}
}