vmm: Extract PCI related state from DeviceManager

Move the PCI related state from the DeviceManager struct to a PciSegment
struct inside the DeviceManager. This is in preparation for multiple
segment support. Currently this state is just the bus itself, the MMIO
and PIO config devices and hotplug related state.

The main change that this required is using the Arc<Mutex<PciBus>> in
the device addition logic in order to ensure that
the bus could be created earlier.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2021-10-04 15:33:29 +01:00
parent 9aadbbe6d9
commit 0eb78ab177
2 changed files with 205 additions and 214 deletions

View File

@@ -188,25 +188,20 @@ impl PciBus {
}
}
#[derive(Default)]
pub struct PciConfigIo {
/// Config space register.
config_address: u32,
pci_bus: Option<Arc<Mutex<PciBus>>>,
pci_bus: Arc<Mutex<PciBus>>,
}
impl PciConfigIo {
pub fn new() -> Self {
pub fn new(pci_bus: Arc<Mutex<PciBus>>) -> Self {
PciConfigIo {
config_address: 0,
pci_bus: None,
pci_bus,
}
}
pub fn set_bus(&mut self, pci_bus: Arc<Mutex<PciBus>>) {
self.pci_bus = Some(pci_bus)
}
pub fn config_space_read(&self) -> u32 {
let enabled = (self.config_address & 0x8000_0000) != 0;
if !enabled {
@@ -228,7 +223,6 @@ impl PciConfigIo {
self.pci_bus
.as_ref()
.unwrap()
.lock()
.unwrap()
.devices
@@ -256,7 +250,7 @@ impl PciConfigIo {
return None;
}
let pci_bus = self.pci_bus.as_ref().unwrap().lock().unwrap();
let pci_bus = self.pci_bus.as_ref().lock().unwrap();
if let Some(d) = pci_bus.devices.get(&(device as u32)) {
let mut device = d.lock().unwrap();