From 0b8318a2bef78a0686f4c9415cd24eb2ecd3653c Mon Sep 17 00:00:00 2001 From: Xiong Zhang Date: Fri, 20 Aug 2021 13:33:38 +0800 Subject: [PATCH] Linux: Change root_config from PciConfigArch to PciRoot Since PciRoot has been modified into Arc>, 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 Tested-by: kokoro Commit-Queue: Junichi Uekawa --- aarch64/src/lib.rs | 5 +++-- arch/src/lib.rs | 6 +++--- devices/src/pci/pci_root.rs | 8 -------- x86_64/src/lib.rs | 6 +++--- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/aarch64/src/lib.rs b/aarch64/src/lib.rs index c3a159d62c..1cb8af0419 100644 --- a/aarch64/src/lib.rs +++ b/aarch64/src/lib.rs @@ -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(), }) } diff --git a/arch/src/lib.rs b/arch/src/lib.rs index 571f436e9c..79e88f4d98 100644 --- a/arch/src/lib.rs +++ b/arch/src/lib.rs @@ -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 { pub gdb: Option<(u32, Tube)>, /// Devices to be notified before the system resumes from the S3 suspended state. pub resume_notify_devices: Vec>>, - pub root_config: Arc>, + pub root_config: Arc>, pub hotplug_bus: Vec>>, } diff --git a/devices/src/pci/pci_root.rs b/devices/src/pci/pci_root.rs index a3c2f6c1de..623a9f83ab 100644 --- a/devices/src/pci/pci_root.rs +++ b/devices/src/pci/pci_root.rs @@ -326,10 +326,6 @@ impl PciConfigIo { }; self.config_address = (self.config_address & !mask) | value; } - - pub fn add_device(&mut self, address: PciAddress, device: Arc>) { - 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>) { - self.pci_root.lock().add_device(address, device) - } } impl BusDevice for PciConfigMmio { diff --git a/x86_64/src/lib.rs b/x86_64/src/lib.rs index bdc031cc54..bcf0fca925 100644 --- a/x86_64/src/lib.rs +++ b/x86_64/src/lib.rs @@ -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(), }) }