mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-02 01:45:21 +00:00
vmm: device_manager: Add a legacy devices creation routine
In order to reduce the DeviceManager's new() complexity, we can move the legacy devices creation code into its own routine. Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
4b469b98cf
commit
cfca2759fc
@ -432,33 +432,6 @@ impl DeviceManager {
|
||||
ioapic: &ioapic,
|
||||
};
|
||||
|
||||
// Add a shutdown device (i8042)
|
||||
let i8042 = Arc::new(Mutex::new(devices::legacy::I8042Device::new(
|
||||
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||
)));
|
||||
|
||||
allocator
|
||||
.allocate_io_addresses(Some(GuestAddress(0x61)), 0x4, None)
|
||||
.ok_or(DeviceManagerError::AllocateIOPort)?;
|
||||
|
||||
io_bus
|
||||
.insert(i8042.clone(), 0x61, 0x4)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
#[cfg(feature = "cmos")]
|
||||
{
|
||||
use vm_memory::GuestMemory;
|
||||
let mem_size = vm_info.memory.as_ref().read().unwrap().end_addr().0 + 1;
|
||||
let mem_below_4g = std::cmp::min(arch::layout::MEM_32BIT_RESERVED_START.0, mem_size);
|
||||
let mem_above_4g = mem_size.saturating_sub(arch::layout::RAM_64BIT_START.0);
|
||||
|
||||
let cmos = Arc::new(Mutex::new(devices::legacy::Cmos::new(
|
||||
mem_below_4g,
|
||||
mem_above_4g,
|
||||
)));
|
||||
io_bus
|
||||
.insert(cmos.clone(), 0x70, 0x2)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
}
|
||||
#[cfg(feature = "acpi")]
|
||||
{
|
||||
let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new(
|
||||
@ -506,6 +479,12 @@ impl DeviceManager {
|
||||
&mut mmap_regions,
|
||||
)?);
|
||||
|
||||
DeviceManager::add_legacy_devices(
|
||||
vm_info,
|
||||
&address_manager,
|
||||
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||
)?;
|
||||
|
||||
if cfg!(feature = "pci_support") {
|
||||
#[cfg(feature = "pci_support")]
|
||||
{
|
||||
@ -633,6 +612,40 @@ impl DeviceManager {
|
||||
})
|
||||
}
|
||||
|
||||
fn add_legacy_devices(
|
||||
_vm_info: &VmInfo,
|
||||
address_manager: &Arc<AddressManager>,
|
||||
reset_evt: EventFd,
|
||||
) -> DeviceManagerResult<()> {
|
||||
// Add a shutdown device (i8042)
|
||||
let i8042 = Arc::new(Mutex::new(devices::legacy::I8042Device::new(reset_evt)));
|
||||
|
||||
address_manager
|
||||
.io_bus
|
||||
.insert(i8042.clone(), 0x61, 0x4)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
#[cfg(feature = "cmos")]
|
||||
{
|
||||
// Add a CMOS emulated device
|
||||
use vm_memory::GuestMemory;
|
||||
let mem_size = _vm_info.memory.as_ref().read().unwrap().end_addr().0 + 1;
|
||||
let mem_below_4g = std::cmp::min(arch::layout::MEM_32BIT_RESERVED_START.0, mem_size);
|
||||
let mem_above_4g = mem_size.saturating_sub(arch::layout::RAM_64BIT_START.0);
|
||||
|
||||
let cmos = Arc::new(Mutex::new(devices::legacy::Cmos::new(
|
||||
mem_below_4g,
|
||||
mem_above_4g,
|
||||
)));
|
||||
|
||||
address_manager
|
||||
.io_bus
|
||||
.insert(cmos.clone(), 0x70, 0x2)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn make_console_device(
|
||||
vm_info: &VmInfo,
|
||||
address_manager: &Arc<AddressManager>,
|
||||
|
Loading…
x
Reference in New Issue
Block a user