[PATCH] hw/riscv/virt: Add "iommu-map" property for pcie bus

wang.yechao255@zte.com.cn posted 1 patch 17 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/qemu tags/patchew/20260608143458400rOXqFmoA6o1tmlztJH2gE@zte.com.cn
Maintainers: Palmer Dabbelt <palmer@dabbelt.com>, Alistair Francis <alistair.francis@wdc.com>, Weiwei Li <liwei1518@gmail.com>, Daniel Henrique Barboza <daniel.barboza@oss.qualcomm.com>, Liu Zhiwei <zhiwei_liu@linux.alibaba.com>, Chao Liu <chao.liu.zevorn@gmail.com>
hw/riscv/virt.c         | 8 ++++++++
include/hw/riscv/virt.h | 1 +
2 files changed, 9 insertions(+)
[PATCH] hw/riscv/virt: Add "iommu-map" property for pcie bus
Posted by wang.yechao255@zte.com.cn 17 hours ago
From: Wang Yechao <wang.yechao255@zte.com.cn>

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 <wang.yechao255@zte.com.cn>
---
 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
Re: [PATCH] hw/riscv/virt: Add "iommu-map" property for pcie bus
Posted by wang.yechao255@zte.com.cn 12 hours ago
> 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.

Ignore this patch, cause this patch is incorrect. The "iommu-map" property is
already defined in create_fdt_iommu. 

The device is not removed before the IOMMU device because the BDF of the
device I configured is smaller than the BDF of the IOMMU device.

Thanks,
Yechao