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 <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-11-18 11:55:04 +01:00 committed by Sebastien Boeuf
parent cfca2759fc
commit ce1765c8af

View File

@ -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<dyn vm_virtio::VirtioDevice>, 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<AddressManager>,
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<AddressManager>,