vmm: device_manager: Add an IOAPIC 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 12:02:37 +01:00 committed by Sebastien Boeuf
parent ce1765c8af
commit 5087f633f6

View File

@ -413,25 +413,6 @@ impl DeviceManager {
let io_bus = devices::Bus::new();
let mmio_bus = devices::Bus::new();
let ioapic = if userspace_ioapic {
// Create IOAPIC
let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new(
vm_info.vm_fd.clone(),
APIC_START,
)));
mmio_bus
.insert(ioapic.clone(), IOAPIC_START.0, IOAPIC_SIZE)
.map_err(DeviceManagerError::BusError)?;
Some(ioapic)
} else {
None
};
let interrupt_info = InterruptInfo {
_msi_capable,
ioapic: &ioapic,
};
let mut virtio_devices: Vec<(Box<dyn vm_virtio::VirtioDevice>, bool)> = Vec::new();
let mut mmap_regions = Vec::new();
@ -449,6 +430,12 @@ impl DeviceManager {
vm_fd: vm_info.vm_fd.clone(),
});
let ioapic = DeviceManager::make_ioapic(vm_info, &address_manager, userspace_ioapic)?;
let interrupt_info = InterruptInfo {
_msi_capable,
ioapic: &ioapic,
};
let console = DeviceManager::make_console_device(
vm_info,
&address_manager,
@ -602,6 +589,30 @@ impl DeviceManager {
})
}
fn make_ioapic(
vm_info: &VmInfo,
address_manager: &Arc<AddressManager>,
userspace_ioapic: bool,
) -> DeviceManagerResult<Option<Arc<Mutex<ioapic::Ioapic>>>> {
let ioapic = if userspace_ioapic {
// Create IOAPIC
let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new(
vm_info.vm_fd.clone(),
APIC_START,
)));
address_manager
.mmio_bus
.insert(ioapic.clone(), IOAPIC_START.0, IOAPIC_SIZE)
.map_err(DeviceManagerError::BusError)?;
Some(ioapic)
} else {
None
};
Ok(ioapic)
}
#[allow(unused_variables)]
fn add_acpi_device(
address_manager: &Arc<AddressManager>,