[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PULL 12/42] hw/pci: Introduce helper function pci_device_get_iommu_bus_
From: |
Cédric Le Goater |
Subject: |
[PULL 12/42] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn() |
Date: |
Mon, 24 Jun 2024 23:24:26 +0200 |
From: Zhenzhong Duan <zhenzhong.duan@intel.com>
Extract out pci_device_get_iommu_bus_devfn() from
pci_device_iommu_address_space() to facilitate
implementation of pci_device_[set|unset]_iommu_device()
in following patch.
No functional change intended.
Signed-off-by: Yi Liu <yi.l.liu@intel.com>
Signed-off-by: Yi Sun <yi.y.sun@linux.intel.com>
Signed-off-by: Nicolin Chen <nicolinc@nvidia.com>
Signed-off-by: Zhenzhong Duan <zhenzhong.duan@intel.com>
Reviewed-by: Eric Auger <eric.auger@redhat.com>
Reviewed-by: Michael S. Tsirkin <mst@redhat.com>
---
hw/pci/pci.c | 48 +++++++++++++++++++++++++++++++++++++++++++++---
1 file changed, 45 insertions(+), 3 deletions(-)
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index
324c1302d25f89c716d2fff06b3cd59471881a4f..02a4bb2af63feabd954ce23e9b02dd931c81ae9a
100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2648,11 +2648,27 @@ static void pci_device_class_base_init(ObjectClass
*klass, void *data)
}
}
-AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
+/*
+ * Get IOMMU root bus, aliased bus and devfn of a PCI device
+ *
+ * IOMMU root bus is needed by all call sites to call into iommu_ops.
+ * For call sites which don't need aliased BDF, passing NULL to
+ * aliased_[bus|devfn] is allowed.
+ *
+ * @piommu_bus: return root #PCIBus backed by an IOMMU for the PCI device.
+ *
+ * @aliased_bus: return aliased #PCIBus of the PCI device, optional.
+ *
+ * @aliased_devfn: return aliased devfn of the PCI device, optional.
+ */
+static void pci_device_get_iommu_bus_devfn(PCIDevice *dev,
+ PCIBus **piommu_bus,
+ PCIBus **aliased_bus,
+ int *aliased_devfn)
{
PCIBus *bus = pci_get_bus(dev);
PCIBus *iommu_bus = bus;
- uint8_t devfn = dev->devfn;
+ int devfn = dev->devfn;
while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) {
PCIBus *parent_bus = pci_get_bus(iommu_bus->parent_dev);
@@ -2693,7 +2709,33 @@ AddressSpace *pci_device_iommu_address_space(PCIDevice
*dev)
iommu_bus = parent_bus;
}
- if (!pci_bus_bypass_iommu(bus) && iommu_bus->iommu_ops) {
+
+ assert(0 <= devfn && devfn < PCI_DEVFN_MAX);
+ assert(iommu_bus);
+
+ if (pci_bus_bypass_iommu(bus) || !iommu_bus->iommu_ops) {
+ iommu_bus = NULL;
+ }
+
+ *piommu_bus = iommu_bus;
+
+ if (aliased_bus) {
+ *aliased_bus = bus;
+ }
+
+ if (aliased_devfn) {
+ *aliased_devfn = devfn;
+ }
+}
+
+AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
+{
+ PCIBus *bus;
+ PCIBus *iommu_bus;
+ int devfn;
+
+ pci_device_get_iommu_bus_devfn(dev, &iommu_bus, &bus, &devfn);
+ if (iommu_bus) {
return iommu_bus->iommu_ops->get_address_space(bus,
iommu_bus->iommu_opaque, devfn);
}
--
2.45.2
- [PULL 02/42] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps, (continued)
- [PULL 02/42] backends/host_iommu_device: Introduce HostIOMMUDeviceCaps, Cédric Le Goater, 2024/06/24
- [PULL 04/42] backends/iommufd: Introduce TYPE_HOST_IOMMU_DEVICE_IOMMUFD[_VFIO] devices, Cédric Le Goater, 2024/06/24
- [PULL 03/42] vfio/container: Introduce TYPE_HOST_IOMMU_DEVICE_LEGACY_VFIO device, Cédric Le Goater, 2024/06/24
- [PULL 05/42] range: Introduce range_get_last_bit(), Cédric Le Goater, 2024/06/24
- [PULL 06/42] vfio/container: Implement HostIOMMUDeviceClass::realize() handler, Cédric Le Goater, 2024/06/24
- [PULL 07/42] backends/iommufd: Introduce helper function iommufd_backend_get_device_info(), Cédric Le Goater, 2024/06/24
- [PULL 08/42] vfio/iommufd: Implement HostIOMMUDeviceClass::realize() handler, Cédric Le Goater, 2024/06/24
- [PULL 09/42] vfio/container: Implement HostIOMMUDeviceClass::get_cap() handler, Cédric Le Goater, 2024/06/24
- [PULL 10/42] backends/iommufd: Implement HostIOMMUDeviceClass::get_cap() handler, Cédric Le Goater, 2024/06/24
- [PULL 11/42] vfio: Create host IOMMU device instance, Cédric Le Goater, 2024/06/24
- [PULL 12/42] hw/pci: Introduce helper function pci_device_get_iommu_bus_devfn(),
Cédric Le Goater <=
- [PULL 13/42] hw/pci: Introduce pci_device_[set|unset]_iommu_device(), Cédric Le Goater, 2024/06/24
- [PULL 14/42] vfio/pci: Pass HostIOMMUDevice to vIOMMU, Cédric Le Goater, 2024/06/24
- [PULL 15/42] intel_iommu: Extract out vtd_cap_init() to initialize cap/ecap, Cédric Le Goater, 2024/06/24
- [PULL 16/42] intel_iommu: Implement [set|unset]_iommu_device() callbacks, Cédric Le Goater, 2024/06/24
- [PULL 17/42] intel_iommu: Check compatibility with host IOMMU capabilities, Cédric Le Goater, 2024/06/24
- [PULL 18/42] HostIOMMUDevice: Store the VFIO/VDPA agent, Cédric Le Goater, 2024/06/24
- [PULL 19/42] virtio-iommu: Implement set|unset]_iommu_device() callbacks, Cédric Le Goater, 2024/06/24
- [PULL 20/42] HostIOMMUDevice: Introduce get_iova_ranges callback, Cédric Le Goater, 2024/06/24
- [PULL 21/42] HostIOMMUDevice: Store the aliased bus and devfn, Cédric Le Goater, 2024/06/24
- [PULL 22/42] virtio-iommu: Compute host reserved regions, Cédric Le Goater, 2024/06/24