Linux: Change root_config from PciConfigArch to PciRoot

Since PciRoot has been modified into Arc<Mutex<>>, RunnableLinuxVm->root_config
could be changed from PciConfigArch to PciRoot also, this could simplify code
and reduce two functions from PciConfigArch.

BUG=b:197877871
TEST=tools/presubmit

Change-Id: Ibc18587900d6f8259ac1d6f8fe7b3ea4fedad07e
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3305942
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Tested-by: kokoro <noreply+kokoro@google.com>
Commit-Queue: Junichi Uekawa <uekawa@chromium.org>
This commit is contained in:
Xiong Zhang 2021-08-20 13:33:38 +08:00 committed by Commit Bot
parent 41dc04fc82
commit 0b8318a2be
4 changed files with 9 additions and 16 deletions

View file

@ -393,8 +393,9 @@ impl arch::LinuxArch for AArch64 {
(devices::AARCH64_GIC_NR_IRQS - AARCH64_IRQ_BASE) as usize,
)
.map_err(Error::CreatePciRoot)?;
let pci_bus = Arc::new(Mutex::new(PciConfigMmio::new(Arc::new(Mutex::new(pci)), 8)));
let pci_root = Arc::new(Mutex::new(pci));
let pci_bus = Arc::new(Mutex::new(PciConfigMmio::new(pci_root.clone(), 8)));
let (platform_devices, _others): (Vec<_>, Vec<_>) = others
.into_iter()
.partition(|(dev, _)| dev.as_platform_device().is_some());
@ -500,7 +501,7 @@ impl arch::LinuxArch for AArch64 {
delay_rt: components.delay_rt,
bat_control: None,
resume_notify_devices: Vec::new(),
root_config: pci_bus,
root_config: pci_root,
hotplug_bus: Vec::new(),
})
}

View file

@ -37,12 +37,12 @@ use gdbstub_arch::x86::reg::X86_64CoreRegs as GdbStubRegs;
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
use {
devices::{IrqChipAArch64 as IrqChipArch, PciConfigMmio as RootConfigArch},
devices::IrqChipAArch64 as IrqChipArch,
hypervisor::{Hypervisor as HypervisorArch, VcpuAArch64 as VcpuArch, VmAArch64 as VmArch},
};
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
use {
devices::{IrqChipX86_64 as IrqChipArch, PciConfigIo as RootConfigArch},
devices::IrqChipX86_64 as IrqChipArch,
hypervisor::{HypervisorX86_64 as HypervisorArch, VcpuX86_64 as VcpuArch, VmX86_64 as VmArch},
};
@ -123,7 +123,7 @@ pub struct RunnableLinuxVm<V: VmArch, Vcpu: VcpuArch> {
pub gdb: Option<(u32, Tube)>,
/// Devices to be notified before the system resumes from the S3 suspended state.
pub resume_notify_devices: Vec<Arc<Mutex<dyn BusResumeDevice>>>,
pub root_config: Arc<Mutex<RootConfigArch>>,
pub root_config: Arc<Mutex<PciRoot>>,
pub hotplug_bus: Vec<Arc<Mutex<dyn HotPlugBus>>>,
}

View file

@ -326,10 +326,6 @@ impl PciConfigIo {
};
self.config_address = (self.config_address & !mask) | value;
}
pub fn add_device(&mut self, address: PciAddress, device: Arc<Mutex<dyn BusDevice>>) {
self.pci_root.lock().add_device(address, device)
}
}
const PCI_RESET_CPU_BIT: u8 = 1 << 2;
@ -405,10 +401,6 @@ impl PciConfigMmio {
.lock()
.config_space_write(address, register, offset, data)
}
pub fn add_device(&mut self, address: PciAddress, device: Arc<Mutex<dyn BusDevice>>) {
self.pci_root.lock().add_device(address, device)
}
}
impl BusDevice for PciConfigMmio {

View file

@ -437,9 +437,9 @@ impl arch::LinuxArch for X8664arch {
reset_evt.try_clone().map_err(Error::CloneEvent)?,
);
let pci_bus = Arc::new(Mutex::new(pci_cfg));
io_bus.insert(pci_bus.clone(), 0xcf8, 0x8).unwrap();
io_bus.insert(pci_bus, 0xcf8, 0x8).unwrap();
let pcie_cfg_mmio = Arc::new(Mutex::new(PciConfigMmio::new(pci, 12)));
let pcie_cfg_mmio = Arc::new(Mutex::new(PciConfigMmio::new(pci.clone(), 12)));
mmio_bus
.insert(pcie_cfg_mmio, PCIE_CFG_MMIO_START, PCIE_CFG_MMIO_SIZE)
.unwrap();
@ -584,7 +584,7 @@ impl arch::LinuxArch for X8664arch {
bat_control,
#[cfg(all(target_arch = "x86_64", feature = "gdb"))]
gdb: components.gdb,
root_config: pci_bus,
root_config: pci,
hotplug_bus: Vec::new(),
})
}