pci, vmm: Pass PCI BDF to vfio and vfio_user

On AArch64, PCI BDF is used for devId in MSI-X routing entry.

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao 2022-01-18 19:52:56 +08:00 committed by Bo Chen
parent cf68f03ab6
commit 1db7718589
3 changed files with 21 additions and 6 deletions

View File

@ -5,7 +5,7 @@
use crate::{
msi_num_enabled_vectors, BarReprogrammingParams, MsiConfig, MsixCap, MsixConfig,
PciBarConfiguration, PciBarRegionType, PciCapabilityId, PciClassCode, PciConfiguration,
PciBarConfiguration, PciBarRegionType, PciBdf, PciCapabilityId, PciClassCode, PciConfiguration,
PciDevice, PciDeviceError, PciHeaderType, PciSubclass, MSIX_TABLE_ENTRY_SIZE,
};
use byteorder::{ByteOrder, LittleEndian};
@ -557,6 +557,7 @@ impl VfioCommon {
cap: u8,
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
vfio_wrapper: &dyn Vfio,
bdf: PciBdf,
) {
let msg_ctl = vfio_wrapper.read_config_word((cap + 2).into());
@ -577,7 +578,11 @@ impl VfioCommon {
})
.unwrap();
let msix_config = MsixConfig::new(msix_cap.table_size(), interrupt_source_group.clone(), 0);
let msix_config = MsixConfig::new(
msix_cap.table_size(),
interrupt_source_group.clone(),
bdf.into(),
);
self.interrupt.msix = Some(VfioMsix {
bar: msix_config,
@ -615,6 +620,7 @@ impl VfioCommon {
&mut self,
interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
vfio_wrapper: &dyn Vfio,
bdf: PciBdf,
) {
let mut cap_next = vfio_wrapper.read_config_byte(PCI_CONFIG_CAPABILITY_OFFSET);
@ -636,7 +642,12 @@ impl VfioCommon {
if irq_info.count > 0 {
// Parse capability only if the VFIO device
// supports MSI-X.
self.parse_msix_capabilities(cap_next, interrupt_manager, vfio_wrapper);
self.parse_msix_capabilities(
cap_next,
interrupt_manager,
vfio_wrapper,
bdf,
);
}
}
}
@ -968,6 +979,7 @@ impl VfioPciDevice {
msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>,
iommu_attached: bool,
bdf: PciBdf,
) -> Result<Self, VfioPciError> {
let device = Arc::new(device);
device.reset();
@ -997,7 +1009,7 @@ impl VfioPciDevice {
},
};
common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper);
common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper, bdf);
common.initialize_legacy_interrupt(legacy_interrupt_group, &vfio_wrapper)?;
let vfio_pci_device = VfioPciDevice {

View File

@ -6,7 +6,7 @@
use crate::vfio::{Interrupt, Vfio, VfioCommon, VfioError};
use crate::{BarReprogrammingParams, PciBarRegionType, VfioPciError};
use crate::{
PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
PciBdf, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
};
use hypervisor::HypervisorVmError;
use std::any::Any;
@ -67,6 +67,7 @@ impl VfioUserPciDevice {
client: Arc<Mutex<Client>>,
msi_interrupt_manager: &Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>,
bdf: PciBdf,
) -> Result<Self, VfioUserPciDeviceError> {
// This is used for the BAR and capabilities only
let configuration = PciConfiguration::new(
@ -104,7 +105,7 @@ impl VfioUserPciDevice {
},
};
common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper);
common.parse_capabilities(msi_interrupt_manager, &vfio_wrapper, bdf);
common
.initialize_legacy_interrupt(legacy_interrupt_group, &vfio_wrapper)
.map_err(VfioUserPciDeviceError::InitializeLegacyInterrupts)?;

View File

@ -3025,6 +3025,7 @@ impl DeviceManager {
&self.msi_interrupt_manager,
legacy_interrupt_group,
device_cfg.iommu,
pci_device_bdf,
)
.map_err(DeviceManagerError::VfioPciCreate)?;
@ -3171,6 +3172,7 @@ impl DeviceManager {
client.clone(),
&self.msi_interrupt_manager,
legacy_interrupt_group,
pci_device_bdf,
)
.map_err(DeviceManagerError::VfioUserCreate)?;