>-----Original Message----- >From: Eric Auger <eric.au...@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.au...@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