From 17057a0dd93b8a5f7a03a83bf88c26153afcec18 Mon Sep 17 00:00:00 2001 From: Michael Zhao Date: Wed, 3 Jun 2020 16:59:35 +0800 Subject: [PATCH] vmm: Fix build errors with "pci" feature on AArch64 Signed-off-by: Michael Zhao --- pci/src/bus.rs | 5 ++++- pci/src/vfio.rs | 4 ++-- vmm/src/device_manager.rs | 44 ++++++++++++++++++++++++--------------- 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/pci/src/bus.rs b/pci/src/bus.rs index 09423b90a..0685afbe1 100644 --- a/pci/src/bus.rs +++ b/pci/src/bus.rs @@ -110,16 +110,19 @@ impl PciBus { pub fn register_mapping( &self, dev: Arc>, - io_bus: &devices::Bus, + #[cfg(target_arch = "x86_64")] io_bus: &devices::Bus, mmio_bus: &devices::Bus, bars: Vec<(GuestAddress, GuestUsize, PciBarRegionType)>, ) -> Result<()> { for (address, size, type_) in bars { match type_ { PciBarRegionType::IORegion => { + #[cfg(target_arch = "x86_64")] io_bus .insert(dev.clone(), address.raw_value(), size) .map_err(PciRootError::PioInsert)?; + #[cfg(target_arch = "aarch64")] + error!("I/O region is not supported"); } PciBarRegionType::Memory32BitRegion | PciBarRegionType::Memory64BitRegion => { mmio_bus diff --git a/pci/src/vfio.rs b/pci/src/vfio.rs index 3d2cd9842..23fa8eb25 100644 --- a/pci/src/vfio.rs +++ b/pci/src/vfio.rs @@ -762,7 +762,7 @@ impl PciDevice for VfioPciDevice { .ok_or_else(|| PciDeviceError::IoAllocationFailed(region_size))?; } #[cfg(target_arch = "aarch64")] - unimplemented!(); + unimplemented!() } else { if is_64bit_bar { // 64 bits Memory BAR @@ -875,7 +875,7 @@ impl PciDevice for VfioPciDevice { #[cfg(target_arch = "x86_64")] allocator.free_io_addresses(region.start, region.length); #[cfg(target_arch = "aarch64")] - unimplemented!(); + error!("I/O region is not supported"); } PciBarRegionType::Memory32BitRegion => { allocator.free_mmio_hole_addresses(region.start, region.length); diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index bdf1c293c..3a33d7c61 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -87,7 +87,7 @@ use vm_migration::{ use vm_virtio::{VirtioDeviceType, VirtioIommuRemapping}; use vmm_sys_util::eventfd::EventFd; -#[cfg(feature = "mmio_support")] +#[cfg(any(feature = "mmio_support", target_arch = "aarch64"))] const MMIO_LEN: u64 = 0x1000; #[cfg(feature = "pci_support")] @@ -454,24 +454,33 @@ impl DeviceRelocation for AddressManager { ) -> std::result::Result<(), std::io::Error> { match region_type { PciBarRegionType::IORegion => { - // Update system allocator - self.allocator - .lock() - .unwrap() - .free_io_addresses(GuestAddress(old_base), len as GuestUsize); + #[cfg(target_arch = "x86_64")] + { + // Update system allocator + self.allocator + .lock() + .unwrap() + .free_io_addresses(GuestAddress(old_base), len as GuestUsize); - self.allocator - .lock() - .unwrap() - .allocate_io_addresses(Some(GuestAddress(new_base)), len as GuestUsize, None) - .ok_or_else(|| { - io::Error::new(io::ErrorKind::Other, "failed allocating new IO range") - })?; + self.allocator + .lock() + .unwrap() + .allocate_io_addresses( + Some(GuestAddress(new_base)), + len as GuestUsize, + None, + ) + .ok_or_else(|| { + io::Error::new(io::ErrorKind::Other, "failed allocating new IO range") + })?; - // Update PIO bus - self.io_bus - .update_range(old_base, len, new_base, len) - .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + // Update PIO bus + self.io_bus + .update_range(old_base, len, new_base, len) + .map_err(|e| io::Error::new(io::ErrorKind::Other, e))?; + } + #[cfg(target_arch = "aarch64")] + error!("I/O region is not supported"); } PciBarRegionType::Memory32BitRegion | PciBarRegionType::Memory64BitRegion => { // Update system allocator @@ -2457,6 +2466,7 @@ impl DeviceManager { pci.register_mapping( vfio_pci_device, + #[cfg(target_arch = "x86_64")] self.address_manager.io_bus.as_ref(), self.address_manager.mmio_bus.as_ref(), bars,