[RFC 2/7] hw/pci: Introduce pci_device_iommu_bus

Eric Auger posted 7 patches 10 months, 2 weeks ago
Maintainers: "Michael S. Tsirkin" <mst@redhat.com>, Marcel Apfelbaum <marcel.apfelbaum@gmail.com>, Alex Williamson <alex.williamson@redhat.com>, "Cédric Le Goater" <clg@redhat.com>, Eric Auger <eric.auger@redhat.com>, Paolo Bonzini <pbonzini@redhat.com>, Peter Xu <peterx@redhat.com>, David Hildenbrand <david@redhat.com>, "Philippe Mathieu-Daudé" <philmd@linaro.org>
There is a newer version of this series
[RFC 2/7] hw/pci: Introduce pci_device_iommu_bus
Posted by Eric Auger 10 months, 2 weeks ago
This helper will allow subsequent patches to retrieve the IOMMU bus
and call its associated PCIIOMMUOps callbacks.

Signed-off-by: Eric Auger <eric.auger@redhat.com>
---
 include/hw/pci/pci.h |  1 +
 hw/pci/pci.c         | 16 ++++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
index 63c018b35a..649b327f9f 100644
--- a/include/hw/pci/pci.h
+++ b/include/hw/pci/pci.h
@@ -403,6 +403,7 @@ typedef struct PCIIOMMUOps {
 } PCIIOMMUOps;
 
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);
+PCIBus *pci_device_iommu_bus(PCIDevice *dev);
 
 /**
  * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus
diff --git a/hw/pci/pci.c b/hw/pci/pci.c
index 76080af580..5bf07662fe 100644
--- a/hw/pci/pci.c
+++ b/hw/pci/pci.c
@@ -2672,6 +2672,22 @@ static void pci_device_class_base_init(ObjectClass *klass, void *data)
     }
 }
 
+PCIBus *pci_device_iommu_bus(PCIDevice *dev)
+{
+    PCIBus *bus = pci_get_bus(dev);
+    PCIBus *iommu_bus = bus;
+
+    while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus->parent_dev) {
+        PCIBus *parent_bus = pci_get_bus(iommu_bus->parent_dev);
+
+        iommu_bus = parent_bus;
+    }
+    if (pci_bus_bypass_iommu(bus)) {
+        return NULL;
+    }
+    return iommu_bus;
+}
+
 AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
 {
     PCIBus *bus = pci_get_bus(dev);
-- 
2.41.0
RE: [RFC 2/7] hw/pci: Introduce pci_device_iommu_bus
Posted by Duan, Zhenzhong 10 months, 1 week ago

>-----Original Message-----
>From: Eric Auger <eric.auger@redhat.com>
>Subject: [RFC 2/7] hw/pci: Introduce pci_device_iommu_bus
>
>This helper will allow subsequent patches to retrieve the IOMMU bus
>and call its associated PCIIOMMUOps callbacks.
>
>Signed-off-by: Eric Auger <eric.auger@redhat.com>
>---
> include/hw/pci/pci.h |  1 +
> hw/pci/pci.c         | 16 ++++++++++++++++
> 2 files changed, 17 insertions(+)
>
>diff --git a/include/hw/pci/pci.h b/include/hw/pci/pci.h
>index 63c018b35a..649b327f9f 100644
>--- a/include/hw/pci/pci.h
>+++ b/include/hw/pci/pci.h
>@@ -403,6 +403,7 @@ typedef struct PCIIOMMUOps {
> } PCIIOMMUOps;
>
> AddressSpace *pci_device_iommu_address_space(PCIDevice *dev);
>+PCIBus *pci_device_iommu_bus(PCIDevice *dev);
>
> /**
>  * pci_setup_iommu: Initialize specific IOMMU handlers for a PCIBus
>diff --git a/hw/pci/pci.c b/hw/pci/pci.c
>index 76080af580..5bf07662fe 100644
>--- a/hw/pci/pci.c
>+++ b/hw/pci/pci.c
>@@ -2672,6 +2672,22 @@ static void
>pci_device_class_base_init(ObjectClass *klass, void *data)
>     }
> }
>
>+PCIBus *pci_device_iommu_bus(PCIDevice *dev)
>+{
>+    PCIBus *bus = pci_get_bus(dev);
>+    PCIBus *iommu_bus = bus;
>+
>+    while (iommu_bus && !iommu_bus->iommu_ops && iommu_bus-
>>parent_dev) {
>+        PCIBus *parent_bus = pci_get_bus(iommu_bus->parent_dev);
>+
>+        iommu_bus = parent_bus;

Variable parent_bus can be removed.

>+    }
>+    if (pci_bus_bypass_iommu(bus)) {
>+        return NULL;
>+    }
>+    return iommu_bus;
>+}
>+
> AddressSpace *pci_device_iommu_address_space(PCIDevice *dev)
> {
>     PCIBus *bus = pci_get_bus(dev);
>--
>2.41.0