From: Wu Fei <[email protected]>

Add an iommu_ops field to RISCVIOMMUState and use it when
registering the IOMMU on a PCI bus, falling back to the default
riscv_iommu_ops when unset. This lets callers install custom PCI
IOMMU ops without changing existing behaviour.

Signed-off-by: Wu Fei <[email protected]>
Signed-off-by: Gong Shuai <[email protected]>
---
 hw/riscv/riscv-iommu.c | 5 ++++-
 hw/riscv/riscv-iommu.h | 3 +++
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/hw/riscv/riscv-iommu.c b/hw/riscv/riscv-iommu.c
index 0e6970773a..6381986265 100644
--- a/hw/riscv/riscv-iommu.c
+++ b/hw/riscv/riscv-iommu.c
@@ -3007,7 +3007,10 @@ void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, 
PCIBus *bus,
         RISCVIOMMUState *last = (RISCVIOMMUState *)bus->iommu_opaque;
         QLIST_INSERT_AFTER(last, iommu, iommus);
     } else if (!bus->iommu_ops && !bus->iommu_opaque) {
-        pci_setup_iommu(bus, &riscv_iommu_ops, iommu);
+        if (!iommu->iommu_ops) {
+            iommu->iommu_ops = &riscv_iommu_ops;
+        }
+        pci_setup_iommu(bus, iommu->iommu_ops, iommu);
     } else {
         error_setg(errp, "can't register secondary IOMMU for PCI bus #%d",
             pci_bus_num(bus));
diff --git a/hw/riscv/riscv-iommu.h b/hw/riscv/riscv-iommu.h
index 403d10b321..cf2904c118 100644
--- a/hw/riscv/riscv-iommu.h
+++ b/hw/riscv/riscv-iommu.h
@@ -24,6 +24,7 @@
 #include "system/dma.h"
 #include "hw/riscv/iommu.h"
 #include "hw/riscv/riscv-iommu-bits.h"
+#include "hw/pci/pci.h"
 
 typedef enum riscv_iommu_igs_modes riscv_iommu_igs_mode;
 
@@ -97,6 +98,8 @@ struct RISCVIOMMUState {
     /* HPM event counters */
     GHashTable *hpm_event_ctr_map; /* Mapping of events to counters */
     uint8_t hpm_cntrs;
+
+    const PCIIOMMUOps *iommu_ops;
 };
 
 void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus,
-- 
2.53.0


Reply via email to