mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
pci: Allow for registering IO and Memory BAR
This patch adds the support for both IO and Memory BARs by expecting the function allocate_bars() to identify the type of each BAR. Based on the type, register_mapping() insert the address range on the appropriate bus (PIO or MMIO). Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
@@ -414,6 +414,11 @@ impl Vcpu {
|
||||
}
|
||||
}
|
||||
|
||||
struct BusInfo<'a> {
|
||||
io: &'a mut devices::Bus,
|
||||
mmio: &'a mut devices::Bus,
|
||||
}
|
||||
|
||||
struct InterruptInfo<'a> {
|
||||
msi_capable: bool,
|
||||
ioapic: &'a Option<Arc<Mutex<ioapic::Ioapic>>>,
|
||||
@@ -488,9 +493,14 @@ impl DeviceManager {
|
||||
msi_capable: bool,
|
||||
userspace_ioapic: bool,
|
||||
) -> DeviceManagerResult<Self> {
|
||||
let io_bus = devices::Bus::new();
|
||||
let mut io_bus = devices::Bus::new();
|
||||
let mut mmio_bus = devices::Bus::new();
|
||||
|
||||
let mut buses = BusInfo {
|
||||
io: &mut io_bus,
|
||||
mmio: &mut mmio_bus,
|
||||
};
|
||||
|
||||
let ioapic = if userspace_ioapic {
|
||||
// Create IOAPIC
|
||||
Some(Arc::new(Mutex::new(ioapic::Ioapic::new(vm_fd.clone()))))
|
||||
@@ -578,7 +588,7 @@ impl DeviceManager {
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&mut buses,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
@@ -605,7 +615,7 @@ impl DeviceManager {
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&mut buses,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
@@ -622,7 +632,7 @@ impl DeviceManager {
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&mut buses,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
@@ -645,7 +655,7 @@ impl DeviceManager {
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&mut buses,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
@@ -710,7 +720,7 @@ impl DeviceManager {
|
||||
allocator,
|
||||
vm_fd,
|
||||
&mut pci,
|
||||
&mut mmio_bus,
|
||||
&mut buses,
|
||||
&interrupt_info,
|
||||
)?;
|
||||
}
|
||||
@@ -735,7 +745,7 @@ impl DeviceManager {
|
||||
allocator: &mut SystemAllocator,
|
||||
vm_fd: &Arc<VmFd>,
|
||||
pci: &mut PciConfigIo,
|
||||
mmio_bus: &mut devices::Bus,
|
||||
buses: &mut BusInfo,
|
||||
interrupt_info: &InterruptInfo,
|
||||
) -> DeviceManagerResult<()> {
|
||||
let msix_num = if interrupt_info.msi_capable {
|
||||
@@ -828,8 +838,13 @@ impl DeviceManager {
|
||||
pci.add_device(virtio_pci_device.clone())
|
||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||
|
||||
pci.register_mapping(virtio_pci_device.clone(), mmio_bus, bars)
|
||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||
pci.register_mapping(
|
||||
virtio_pci_device.clone(),
|
||||
&mut buses.io,
|
||||
&mut buses.mmio,
|
||||
bars,
|
||||
)
|
||||
.map_err(DeviceManagerError::AddPciDevice)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user