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,