mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 11:35:46 +00:00
vmm: device_manager: Remove pci_id_list
Introduces a tuple holding both information needed by pci_id_list and pci_devices. Changes pci_devices to be a BTreeMap of this new tuple. Now that pci_devices holds the information needed from pci_id_list, pci_id_list is no longer needed. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
305e095d15
commit
fbd624d816
@ -894,11 +894,8 @@ pub struct DeviceManager {
|
|||||||
// Bitmap of PCI devices to hotunplug.
|
// Bitmap of PCI devices to hotunplug.
|
||||||
pci_devices_down: u32,
|
pci_devices_down: u32,
|
||||||
|
|
||||||
// Hashmap of PCI b/d/f to their corresponding device's name.
|
// BTreeMap of PCI b/d/f to their corresponding MetaPciDevice.
|
||||||
pci_id_list: HashMap<u32, String>,
|
pci_devices: BTreeMap<u32, (String, Arc<dyn Any + Send + Sync>)>,
|
||||||
|
|
||||||
// Hashmap of PCI b/d/f to their corresponding Arc<Mutex<dyn PciDevice>>.
|
|
||||||
pci_devices: HashMap<u32, Arc<dyn Any + Send + Sync>>,
|
|
||||||
|
|
||||||
// BTreeMap of PCI b/d/f to their allocated IRQ.
|
// BTreeMap of PCI b/d/f to their allocated IRQ.
|
||||||
pci_device_irqs: BTreeMap<u32, u32>,
|
pci_device_irqs: BTreeMap<u32, u32>,
|
||||||
@ -1004,8 +1001,7 @@ impl DeviceManager {
|
|||||||
iommu_device: None,
|
iommu_device: None,
|
||||||
pci_devices_up: 0,
|
pci_devices_up: 0,
|
||||||
pci_devices_down: 0,
|
pci_devices_down: 0,
|
||||||
pci_id_list: HashMap::new(),
|
pci_devices: BTreeMap::new(),
|
||||||
pci_devices: HashMap::new(),
|
|
||||||
pci_device_irqs: BTreeMap::new(),
|
pci_device_irqs: BTreeMap::new(),
|
||||||
device_tree,
|
device_tree,
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
@ -2942,7 +2938,8 @@ impl DeviceManager {
|
|||||||
.add_device(bdf, pci_device)
|
.add_device(bdf, pci_device)
|
||||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||||
|
|
||||||
self.pci_devices.insert(bdf, any_device);
|
self.pci_devices
|
||||||
|
.insert(bdf, (device_id.clone(), any_device));
|
||||||
self.bus_devices.push(Arc::clone(&bus_device));
|
self.bus_devices.push(Arc::clone(&bus_device));
|
||||||
|
|
||||||
pci_bus
|
pci_bus
|
||||||
@ -2955,7 +2952,6 @@ impl DeviceManager {
|
|||||||
)
|
)
|
||||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||||
|
|
||||||
self.pci_id_list.insert(bdf, device_id);
|
|
||||||
Ok(bars)
|
Ok(bars)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3167,8 +3163,9 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Take care of updating the memory for VFIO PCI devices.
|
// Take care of updating the memory for VFIO PCI devices.
|
||||||
for (_, any_device) in self.pci_devices.iter() {
|
for (_, (_, any_device)) in self.pci_devices.iter() {
|
||||||
if let Ok(vfio_pci_device) = Arc::clone(any_device).downcast::<Mutex<VfioPciDevice>>() {
|
if let Ok(vfio_pci_device) = Arc::clone(&any_device).downcast::<Mutex<VfioPciDevice>>()
|
||||||
|
{
|
||||||
vfio_pci_device
|
vfio_pci_device
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -3186,9 +3183,9 @@ impl DeviceManager {
|
|||||||
|
|
||||||
pub fn activate_virtio_devices(&self) -> DeviceManagerResult<()> {
|
pub fn activate_virtio_devices(&self) -> DeviceManagerResult<()> {
|
||||||
// Find virtio pci devices and activate any pending ones
|
// Find virtio pci devices and activate any pending ones
|
||||||
for (_, any_device) in self.pci_devices.iter() {
|
for (_, (_, any_device)) in self.pci_devices.iter() {
|
||||||
if let Ok(virtio_pci_device) =
|
if let Ok(virtio_pci_device) =
|
||||||
Arc::clone(any_device).downcast::<Mutex<VirtioPciDevice>>()
|
Arc::clone(&any_device).downcast::<Mutex<VirtioPciDevice>>()
|
||||||
{
|
{
|
||||||
virtio_pci_device.lock().unwrap().maybe_activate();
|
virtio_pci_device.lock().unwrap().maybe_activate();
|
||||||
}
|
}
|
||||||
@ -3247,32 +3244,28 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
|
pub fn remove_device(&mut self, id: String) -> DeviceManagerResult<()> {
|
||||||
for (pci_device_bdf, pci_device_name) in self.pci_id_list.iter() {
|
for (pci_device_bdf, (device_id, any_device)) in self.pci_devices.iter() {
|
||||||
if *pci_device_name == id {
|
if *device_id == id {
|
||||||
if let Some(any_device) = self.pci_devices.get(pci_device_bdf) {
|
if let Ok(virtio_pci_device) =
|
||||||
if let Ok(virtio_pci_device) =
|
Arc::clone(&any_device).downcast::<Mutex<VirtioPciDevice>>()
|
||||||
Arc::clone(any_device).downcast::<Mutex<VirtioPciDevice>>()
|
{
|
||||||
{
|
let device_type = VirtioDeviceType::from(
|
||||||
let device_type = VirtioDeviceType::from(
|
virtio_pci_device
|
||||||
virtio_pci_device
|
.lock()
|
||||||
.lock()
|
.unwrap()
|
||||||
.unwrap()
|
.virtio_device()
|
||||||
.virtio_device()
|
.lock()
|
||||||
.lock()
|
.unwrap()
|
||||||
.unwrap()
|
.device_type(),
|
||||||
.device_type(),
|
);
|
||||||
);
|
match device_type {
|
||||||
match device_type {
|
VirtioDeviceType::TYPE_NET
|
||||||
VirtioDeviceType::TYPE_NET
|
| VirtioDeviceType::TYPE_BLOCK
|
||||||
| VirtioDeviceType::TYPE_BLOCK
|
| VirtioDeviceType::TYPE_PMEM
|
||||||
| VirtioDeviceType::TYPE_PMEM
|
| VirtioDeviceType::TYPE_FS
|
||||||
| VirtioDeviceType::TYPE_FS
|
| VirtioDeviceType::TYPE_VSOCK => {}
|
||||||
| VirtioDeviceType::TYPE_VSOCK => {}
|
_ => return Err(DeviceManagerError::RemovalNotAllowed(device_type)),
|
||||||
_ => return Err(DeviceManagerError::RemovalNotAllowed(device_type)),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
|
||||||
return Err(DeviceManagerError::UnknownPciBdf(*pci_device_bdf));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the PCID bitmap
|
// Update the PCID bitmap
|
||||||
@ -3304,17 +3297,13 @@ impl DeviceManager {
|
|||||||
// Convert the device ID into the corresponding b/d/f.
|
// Convert the device ID into the corresponding b/d/f.
|
||||||
let pci_device_bdf = (device_id as u32) << 3;
|
let pci_device_bdf = (device_id as u32) << 3;
|
||||||
|
|
||||||
// Find the device name corresponding to the PCI b/d/f while removing
|
|
||||||
// the device entry.
|
|
||||||
self.pci_id_list.remove(&pci_device_bdf);
|
|
||||||
|
|
||||||
// Give the PCI device ID back to the PCI bus.
|
// Give the PCI device ID back to the PCI bus.
|
||||||
pci.lock()
|
pci.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.put_device_id(device_id as usize)
|
.put_device_id(device_id as usize)
|
||||||
.map_err(DeviceManagerError::PutPciDeviceId)?;
|
.map_err(DeviceManagerError::PutPciDeviceId)?;
|
||||||
|
|
||||||
if let Some(any_device) = self.pci_devices.remove(&pci_device_bdf) {
|
if let Some((_, any_device)) = self.pci_devices.remove(&pci_device_bdf) {
|
||||||
let (pci_device, bus_device, virtio_device) = if let Ok(vfio_pci_device) =
|
let (pci_device, bus_device, virtio_device) = if let Ok(vfio_pci_device) =
|
||||||
any_device.clone().downcast::<Mutex<VfioPciDevice>>()
|
any_device.clone().downcast::<Mutex<VfioPciDevice>>()
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user