From 9cb1e1cc6b840f2eabd4654c1347591487f7c3ea Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Wed, 29 Apr 2020 12:02:54 +0200 Subject: [PATCH] vmm: Perform MMIO allocation from virtio-mmio device creation Instead of splitting the MMIO allocation and the device creation into separate functions for virtio-mmio devices, it's is easier to move everything into the same function as we'll be able to gather resources in the same place for the same device. These resources will be stored in the device tree in a follow up patch. Signed-off-by: Sebastien Boeuf --- vmm/src/device_manager.rs | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 3dfbe1239..59fbd3346 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -319,6 +319,9 @@ pub enum DeviceManagerError { /// Could not find the node in the device tree. MissingNode, + + /// Could not find a MMIO range. + MmioRangeAllocation, } pub type DeviceManagerResult = result::Result; @@ -933,17 +936,7 @@ impl DeviceManager { #[cfg(feature = "mmio_support")] { for (device, _, id) in virtio_devices { - let mmio_addr = self - .address_manager - .allocator - .lock() - .unwrap() - .allocate_mmio_addresses(None, MMIO_LEN, Some(MMIO_LEN)); - if let Some(addr) = mmio_addr { - self.add_virtio_mmio_device(id, device, interrupt_manager, addr)?; - } else { - error!("Unable to allocate MMIO address!"); - } + self.add_virtio_mmio_device(id, device, interrupt_manager)?; } } @@ -2133,7 +2126,6 @@ impl DeviceManager { virtio_device_id: String, virtio_device: VirtioDeviceArc, interrupt_manager: &Arc>, - mmio_base: GuestAddress, ) -> DeviceManagerResult<()> { let id = format!("{}-{}", VIRTIO_MMIO_DEVICE_NAME_PREFIX, virtio_device_id); @@ -2151,6 +2143,14 @@ impl DeviceManager { return Err(DeviceManagerError::MissingNode); } + let mmio_base = self + .address_manager + .allocator + .lock() + .unwrap() + .allocate_mmio_addresses(None, MMIO_LEN, Some(MMIO_LEN)) + .ok_or(DeviceManagerError::MmioRangeAllocation)?; + let memory = self.memory_manager.lock().unwrap().guest_memory(); let mut mmio_device = vm_virtio::transport::MmioDevice::new(id, memory, virtio_device) .map_err(DeviceManagerError::VirtioDevice)?;