mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-02 19:45:46 +00:00
vmm: device_manager: Make add_pci_devices and add_mmio_devices methods
Modify these functions to take an &mut self and become methods on DeviceManager. This allows the removal of some in/out parameters and leads the way to further refactoring and simplification. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
3dbae423bb
commit
2987476e0a
@ -496,26 +496,6 @@ impl DeviceManager {
|
|||||||
_exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
_exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if cfg!(feature = "pci_support") {
|
|
||||||
DeviceManager::add_pci_devices(
|
|
||||||
vm_info,
|
|
||||||
&address_manager,
|
|
||||||
&memory_manager,
|
|
||||||
virtio_devices,
|
|
||||||
&interrupt_manager,
|
|
||||||
&mut migratable_devices,
|
|
||||||
)?;
|
|
||||||
} else if cfg!(feature = "mmio_support") {
|
|
||||||
DeviceManager::add_mmio_devices(
|
|
||||||
vm_info,
|
|
||||||
&address_manager,
|
|
||||||
virtio_devices,
|
|
||||||
&interrupt_manager,
|
|
||||||
&mut cmdline_additions,
|
|
||||||
&mut migratable_devices,
|
|
||||||
)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
let config = vm_info.vm_cfg.clone();
|
let config = vm_info.vm_cfg.clone();
|
||||||
|
|
||||||
@ -533,7 +513,7 @@ impl DeviceManager {
|
|||||||
.insert(_memory_manager.clone(), 0xa00, 0x18)
|
.insert(_memory_manager.clone(), 0xa00, 0x18)
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
|
|
||||||
Ok(DeviceManager {
|
let mut device_manager = DeviceManager {
|
||||||
address_manager,
|
address_manager,
|
||||||
console,
|
console,
|
||||||
ioapic: Some(ioapic),
|
ioapic: Some(ioapic),
|
||||||
@ -545,24 +525,30 @@ impl DeviceManager {
|
|||||||
config,
|
config,
|
||||||
migratable_devices,
|
migratable_devices,
|
||||||
_memory_manager,
|
_memory_manager,
|
||||||
})
|
};
|
||||||
|
|
||||||
|
if cfg!(feature = "pci_support") {
|
||||||
|
device_manager.add_pci_devices(vm_info, virtio_devices, &interrupt_manager)?;
|
||||||
|
} else if cfg!(feature = "mmio_support") {
|
||||||
|
device_manager.add_mmio_devices(vm_info, virtio_devices, &interrupt_manager)?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(device_manager)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(unused_variables)]
|
#[allow(unused_variables)]
|
||||||
fn add_pci_devices(
|
fn add_pci_devices(
|
||||||
|
&mut self,
|
||||||
vm_info: &VmInfo,
|
vm_info: &VmInfo,
|
||||||
address_manager: &Arc<AddressManager>,
|
|
||||||
memory_manager: &Arc<Mutex<MemoryManager>>,
|
|
||||||
virtio_devices: Vec<(Arc<Mutex<dyn vm_virtio::VirtioDevice>>, bool)>,
|
virtio_devices: Vec<(Arc<Mutex<dyn vm_virtio::VirtioDevice>>, bool)>,
|
||||||
interrupt_manager: &Arc<dyn InterruptManager>,
|
interrupt_manager: &Arc<dyn InterruptManager>,
|
||||||
migratable_devices: &mut Vec<Arc<Mutex<dyn Migratable>>>,
|
|
||||||
) -> DeviceManagerResult<()> {
|
) -> DeviceManagerResult<()> {
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
{
|
{
|
||||||
let pci_root = PciRoot::new(None);
|
let pci_root = PciRoot::new(None);
|
||||||
let mut pci_bus = PciBus::new(
|
let mut pci_bus = PciBus::new(
|
||||||
pci_root,
|
pci_root,
|
||||||
Arc::downgrade(&address_manager) as Weak<dyn DeviceRelocation>,
|
Arc::downgrade(&self.address_manager) as Weak<dyn DeviceRelocation>,
|
||||||
);
|
);
|
||||||
|
|
||||||
let (mut iommu_device, iommu_mapping) = if vm_info.vm_cfg.lock().unwrap().iommu {
|
let (mut iommu_device, iommu_mapping) = if vm_info.vm_cfg.lock().unwrap().iommu {
|
||||||
@ -585,11 +571,11 @@ impl DeviceManager {
|
|||||||
let virtio_iommu_attach_dev = DeviceManager::add_virtio_pci_device(
|
let virtio_iommu_attach_dev = DeviceManager::add_virtio_pci_device(
|
||||||
device,
|
device,
|
||||||
vm_info.memory,
|
vm_info.memory,
|
||||||
&address_manager,
|
&self.address_manager,
|
||||||
vm_info.vm_fd,
|
vm_info.vm_fd,
|
||||||
&mut pci_bus,
|
&mut pci_bus,
|
||||||
mapping,
|
mapping,
|
||||||
migratable_devices,
|
&mut self.migratable_devices,
|
||||||
interrupt_manager,
|
interrupt_manager,
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
@ -600,9 +586,9 @@ impl DeviceManager {
|
|||||||
|
|
||||||
let mut vfio_iommu_device_ids = DeviceManager::add_vfio_devices(
|
let mut vfio_iommu_device_ids = DeviceManager::add_vfio_devices(
|
||||||
vm_info,
|
vm_info,
|
||||||
&address_manager,
|
&self.address_manager,
|
||||||
&mut pci_bus,
|
&mut pci_bus,
|
||||||
memory_manager,
|
&self._memory_manager,
|
||||||
&mut iommu_device,
|
&mut iommu_device,
|
||||||
interrupt_manager,
|
interrupt_manager,
|
||||||
)?;
|
)?;
|
||||||
@ -618,23 +604,23 @@ impl DeviceManager {
|
|||||||
DeviceManager::add_virtio_pci_device(
|
DeviceManager::add_virtio_pci_device(
|
||||||
Arc::new(Mutex::new(iommu_device)),
|
Arc::new(Mutex::new(iommu_device)),
|
||||||
vm_info.memory,
|
vm_info.memory,
|
||||||
&address_manager,
|
&self.address_manager,
|
||||||
vm_info.vm_fd,
|
vm_info.vm_fd,
|
||||||
&mut pci_bus,
|
&mut pci_bus,
|
||||||
&None,
|
&None,
|
||||||
migratable_devices,
|
&mut self.migratable_devices,
|
||||||
interrupt_manager,
|
interrupt_manager,
|
||||||
)?;
|
)?;
|
||||||
}
|
}
|
||||||
|
|
||||||
let pci_bus = Arc::new(Mutex::new(pci_bus));
|
let pci_bus = Arc::new(Mutex::new(pci_bus));
|
||||||
let pci_config_io = Arc::new(Mutex::new(PciConfigIo::new(pci_bus.clone())));
|
let pci_config_io = Arc::new(Mutex::new(PciConfigIo::new(pci_bus.clone())));
|
||||||
address_manager
|
self.address_manager
|
||||||
.io_bus
|
.io_bus
|
||||||
.insert(pci_config_io, 0xcf8, 0x8)
|
.insert(pci_config_io, 0xcf8, 0x8)
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
let pci_config_mmio = Arc::new(Mutex::new(PciConfigMmio::new(pci_bus)));
|
let pci_config_mmio = Arc::new(Mutex::new(PciConfigMmio::new(pci_bus)));
|
||||||
address_manager
|
self.address_manager
|
||||||
.mmio_bus
|
.mmio_bus
|
||||||
.insert(
|
.insert(
|
||||||
pci_config_mmio,
|
pci_config_mmio,
|
||||||
@ -649,17 +635,16 @@ impl DeviceManager {
|
|||||||
|
|
||||||
#[allow(unused_variables, unused_mut)]
|
#[allow(unused_variables, unused_mut)]
|
||||||
fn add_mmio_devices(
|
fn add_mmio_devices(
|
||||||
|
&mut self,
|
||||||
vm_info: &VmInfo,
|
vm_info: &VmInfo,
|
||||||
address_manager: &Arc<AddressManager>,
|
|
||||||
virtio_devices: Vec<(Arc<Mutex<dyn vm_virtio::VirtioDevice>>, bool)>,
|
virtio_devices: Vec<(Arc<Mutex<dyn vm_virtio::VirtioDevice>>, bool)>,
|
||||||
interrupt_manager: &Arc<dyn InterruptManager>,
|
interrupt_manager: &Arc<dyn InterruptManager>,
|
||||||
mut cmdline_additions: &mut Vec<String>,
|
|
||||||
migratable_devices: &mut Vec<Arc<Mutex<dyn Migratable>>>,
|
|
||||||
) -> DeviceManagerResult<()> {
|
) -> DeviceManagerResult<()> {
|
||||||
#[cfg(feature = "mmio_support")]
|
#[cfg(feature = "mmio_support")]
|
||||||
{
|
{
|
||||||
for (device, _) in virtio_devices {
|
for (device, _) in virtio_devices {
|
||||||
let mmio_addr = address_manager
|
let mmio_addr = self
|
||||||
|
.address_manager
|
||||||
.allocator
|
.allocator
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -668,12 +653,12 @@ impl DeviceManager {
|
|||||||
DeviceManager::add_virtio_mmio_device(
|
DeviceManager::add_virtio_mmio_device(
|
||||||
device,
|
device,
|
||||||
vm_info.memory,
|
vm_info.memory,
|
||||||
&address_manager,
|
&self.address_manager,
|
||||||
vm_info.vm_fd,
|
vm_info.vm_fd,
|
||||||
interrupt_manager,
|
interrupt_manager,
|
||||||
addr,
|
addr,
|
||||||
&mut cmdline_additions,
|
&mut self.cmdline_additions,
|
||||||
migratable_devices,
|
&mut self.migratable_devices,
|
||||||
)?;
|
)?;
|
||||||
} else {
|
} else {
|
||||||
error!("Unable to allocate MMIO address!");
|
error!("Unable to allocate MMIO address!");
|
||||||
|
Loading…
Reference in New Issue
Block a user