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 <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2020-04-29 12:02:54 +02:00
parent adf297066d
commit 9cb1e1cc6b

View File

@ -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<T> = result::Result<T, DeviceManagerError>;
@ -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<dyn InterruptManager<GroupConfig = LegacyIrqGroupConfig>>,
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)?;