mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Add devices to IO/MMIO bus closer to creation
This removes the register_devices() function with all that functionality spread across the places where the devices are created. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
committed by
Sebastien Boeuf
parent
0739c2c7fd
commit
4df5ebea12
+31
-53
@@ -275,13 +275,6 @@ pub struct DeviceManager {
|
|||||||
// Console abstraction
|
// Console abstraction
|
||||||
console: Arc<Console>,
|
console: Arc<Console>,
|
||||||
|
|
||||||
// i8042 device for i8042 reset
|
|
||||||
i8042: Arc<Mutex<devices::legacy::I8042Device>>,
|
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
|
||||||
// ACPI device for reboot/shutdwon
|
|
||||||
acpi_device: Arc<Mutex<devices::AcpiShutdownDevice>>,
|
|
||||||
|
|
||||||
// IOAPIC
|
// IOAPIC
|
||||||
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
||||||
|
|
||||||
@@ -312,9 +305,12 @@ impl DeviceManager {
|
|||||||
|
|
||||||
let ioapic = if userspace_ioapic {
|
let ioapic = if userspace_ioapic {
|
||||||
// Create IOAPIC
|
// Create IOAPIC
|
||||||
Some(Arc::new(Mutex::new(ioapic::Ioapic::new(
|
let ioapic = Arc::new(Mutex::new(ioapic::Ioapic::new(vm_info.vm_fd.clone())));
|
||||||
vm_info.vm_fd.clone(),
|
buses
|
||||||
))))
|
.mmio
|
||||||
|
.insert(ioapic.clone(), IOAPIC_RANGE_ADDR, IOAPIC_RANGE_SIZE)
|
||||||
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
|
Some(ioapic)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -347,10 +343,17 @@ impl DeviceManager {
|
|||||||
Box::new(KernelIoapicIrq::new(serial_evt))
|
Box::new(KernelIoapicIrq::new(serial_evt))
|
||||||
};
|
};
|
||||||
|
|
||||||
Some(Arc::new(Mutex::new(devices::legacy::Serial::new(
|
let serial = Arc::new(Mutex::new(devices::legacy::Serial::new(
|
||||||
interrupt,
|
interrupt,
|
||||||
serial_writer,
|
serial_writer,
|
||||||
))))
|
)));
|
||||||
|
|
||||||
|
buses
|
||||||
|
.io
|
||||||
|
.insert(serial.clone(), 0x3f8, 0x8)
|
||||||
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
|
|
||||||
|
Some(serial)
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
@@ -359,12 +362,22 @@ impl DeviceManager {
|
|||||||
let i8042 = Arc::new(Mutex::new(devices::legacy::I8042Device::new(
|
let i8042 = Arc::new(Mutex::new(devices::legacy::I8042Device::new(
|
||||||
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
)));
|
)));
|
||||||
|
buses
|
||||||
|
.io
|
||||||
|
.insert(i8042.clone(), 0x61, 0x4)
|
||||||
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new(
|
{
|
||||||
_exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
let acpi_device = Arc::new(Mutex::new(devices::AcpiShutdownDevice::new(
|
||||||
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
_exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
)));
|
reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
|
)));
|
||||||
|
buses
|
||||||
|
.io
|
||||||
|
.insert(acpi_device.clone(), 0x3c0, 0x4)
|
||||||
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
|
}
|
||||||
|
|
||||||
let mut virtio_devices: Vec<Box<dyn vm_virtio::VirtioDevice>> = Vec::new();
|
let mut virtio_devices: Vec<Box<dyn vm_virtio::VirtioDevice>> = Vec::new();
|
||||||
|
|
||||||
@@ -458,21 +471,14 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let mut dm = DeviceManager {
|
Ok(DeviceManager {
|
||||||
io_bus,
|
io_bus,
|
||||||
mmio_bus,
|
mmio_bus,
|
||||||
console,
|
console,
|
||||||
i8042,
|
|
||||||
#[cfg(feature = "acpi")]
|
|
||||||
acpi_device,
|
|
||||||
ioapic,
|
ioapic,
|
||||||
mmap_regions,
|
mmap_regions,
|
||||||
cmdline_additions,
|
cmdline_additions,
|
||||||
};
|
})
|
||||||
|
|
||||||
dm.register_devices()?;
|
|
||||||
|
|
||||||
Ok(dm)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn make_virtio_devices(
|
fn make_virtio_devices(
|
||||||
@@ -1021,34 +1027,6 @@ impl DeviceManager {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn register_devices(&mut self) -> DeviceManagerResult<()> {
|
|
||||||
if self.console.serial.is_some() {
|
|
||||||
// Insert serial device
|
|
||||||
self.io_bus
|
|
||||||
.insert(self.console.serial.as_ref().unwrap().clone(), 0x3f8, 0x8)
|
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Insert i8042 device
|
|
||||||
self.io_bus
|
|
||||||
.insert(self.i8042.clone(), 0x61, 0x4)
|
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
|
||||||
self.io_bus
|
|
||||||
.insert(self.acpi_device.clone(), 0x3c0, 0x4)
|
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
|
||||||
|
|
||||||
if let Some(ioapic) = &self.ioapic {
|
|
||||||
// Insert IOAPIC
|
|
||||||
self.mmio_bus
|
|
||||||
.insert(ioapic.clone(), IOAPIC_RANGE_ADDR, IOAPIC_RANGE_SIZE)
|
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn io_bus(&self) -> &devices::Bus {
|
pub fn io_bus(&self) -> &devices::Bus {
|
||||||
&self.io_bus
|
&self.io_bus
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user