@@ -2644,7 +2644,13 @@ void riscv_iommu_pci_setup_iommu(RISCVIOMMUState *iommu, PCIBus *bus,
static int riscv_iommu_memory_region_index(IOMMUMemoryRegion *iommu_mr,
MemTxAttrs attrs)
{
- return attrs.unspecified ? RISCV_IOMMU_NOPROCID : (int)attrs.pid;
+ RISCVIOMMUSpace *as = container_of(iommu_mr, RISCVIOMMUSpace, iova_mr);
+
+ /* Requesters must attach its device ID. */
+ g_assert(attrs.unspecified == 0);
+
+ as->devid = attrs.requester_id;
+ return attrs.pid;
}
static int riscv_iommu_memory_region_index_len(IOMMUMemoryRegion *iommu_mr)
The bus number of a PCIe endpoint may change after PCIe re-enumeration, potentially causing the device ID stored in RISCVIOMMUSpace to become outdated. This can lead to an incorrect Device Directory Table walk. This commit ensures that the IOMMU dynamically retrieves the latest device IDs from the memory attributes of the requester devices, ensuring accuracy. Signed-off-by: Jason Chien <jason.chien@sifive.com> --- hw/riscv/riscv-iommu.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)