From: Wang Yechao <[email protected]>

On DT system, add the "iommu-map" property for pcie bus, so the kernel
can build the dependency between iommu and devices, to avoid the
incorrect removal order.

Signed-off-by: Wang Yechao <[email protected]>
---
 hw/riscv/virt.c         | 8 ++++++++
 include/hw/riscv/virt.h | 1 +
 2 files changed, 9 insertions(+)

diff --git a/hw/riscv/virt.c b/hw/riscv/virt.c
index ce64eaaef7..0ce16f13c2 100644
--- a/hw/riscv/virt.c
+++ b/hw/riscv/virt.c
@@ -904,6 +904,13 @@ static void create_fdt_pcie(RISCVVirtState *s,
                                iommu_sys_phandle, 0, 0xffff);
     }

+    if (s->pci_iommu_bdf) {
+        qemu_fdt_setprop_cells(ms->fdt, name, "iommu-map",
+                               0, s->pci_iommu_phandle, 0, s->pci_iommu_bdf,
+                               s->pci_iommu_bdf + 1, s->pci_iommu_phandle,
+                               s->pci_iommu_bdf + 1, 0xffff - 
s->pci_iommu_bdf);
+    }
+
     create_pcie_irq_map(s, ms->fdt, name, irq_pcie_phandle);
 }

@@ -1117,6 +1124,7 @@ static void create_fdt_iommu(RISCVVirtState *s, uint16_t 
bdf)
                            0, iommu_phandle, 0, bdf,
                            bdf + 1, iommu_phandle, bdf + 1, 0xffff - bdf);
     s->pci_iommu_bdf = bdf;
+    s->pci_iommu_phandle = iommu_phandle;
 }

 static void finalize_fdt(RISCVVirtState *s)
diff --git a/include/hw/riscv/virt.h b/include/hw/riscv/virt.h
index 18a2a323a3..25c563cf8f 100644
--- a/include/hw/riscv/virt.h
+++ b/include/hw/riscv/virt.h
@@ -64,6 +64,7 @@ struct RISCVVirtState {
     struct GPEXHost *gpex_host;
     OnOffAuto iommu_sys;
     uint16_t pci_iommu_bdf;
+    uint32_t pci_iommu_phandle;
 };

 enum {
-- 
2.27.0

Reply via email to