From ce1765c8af033bfa7d08a7bf27ac6b560f06d435 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Mon, 18 Nov 2019 11:55:04 +0100 Subject: [PATCH] vmm: device_manager: Add an ACPI device creation routine In order to reduce the DeviceManager's new() complexity, we can move the ACPI device creation code into its own routine. Signed-off-by: Samuel Ortiz --- vmm/src/device_manager.rs | 45 ++++++++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 17 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index fecf80548..8be83b89a 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -403,7 +403,7 @@ pub struct DeviceManager { impl DeviceManager { pub fn new( vm_info: &VmInfo, - mut allocator: SystemAllocator, + allocator: SystemAllocator, _msi_capable: bool, userspace_ioapic: bool, mut mem_slots: u32, @@ -432,22 +432,6 @@ impl DeviceManager { ioapic: &ioapic, }; - #[cfg(feature = "acpi")] - { - let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new( - _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?, - reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?, - ))); - - allocator - .allocate_io_addresses(Some(GuestAddress(0x3c0)), 0x4, None) - .ok_or(DeviceManagerError::AllocateIOPort)?; - - io_bus - .insert(acpi_device.clone(), 0x3c0, 0x4) - .map_err(DeviceManagerError::BusError)?; - } - let mut virtio_devices: Vec<(Box, bool)> = Vec::new(); let mut mmap_regions = Vec::new(); @@ -485,6 +469,12 @@ impl DeviceManager { reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?, )?; + DeviceManager::add_acpi_device( + &address_manager, + reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?, + _exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?, + )?; + if cfg!(feature = "pci_support") { #[cfg(feature = "pci_support")] { @@ -612,6 +602,27 @@ impl DeviceManager { }) } + #[allow(unused_variables)] + fn add_acpi_device( + address_manager: &Arc, + reset_evt: EventFd, + exit_evt: EventFd, + ) -> DeviceManagerResult<()> { + #[cfg(feature = "acpi")] + { + let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new( + exit_evt, reset_evt, + ))); + + address_manager + .io_bus + .insert(acpi_device.clone(), 0x3c0, 0x4) + .map_err(DeviceManagerError::BusError)?; + } + + Ok(()) + } + fn add_legacy_devices( _vm_info: &VmInfo, address_manager: &Arc,