[PATCH v1.1 2/7] iommu/riscv: Fix WSI mode IRQ number handling
Lv Zheng
lv.zheng at spacemit.com
Wed Jan 28 22:08:50 PST 2026
From: Jingyu Li <joey.li at spacemit.com>
In WSI mode, ICVEC doesn't exist, thus reading it returns 0, which
causes IOMMU driver to fail to find IRQ numbers from device tree
IRQ arrary. The issue is fixed by applying icvec indexes of WSI IRQs.
Signed-off-by: Jingyu Li <joey.li at spacemit.com>
Signed-off-by: Lv Zheng <lv.zheng at spacemit.com>
---
drivers/iommu/riscv/iommu.c | 25 ++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)
diff --git a/drivers/iommu/riscv/iommu.c b/drivers/iommu/riscv/iommu.c
index d9429097a2b5..26630979473b 100644
--- a/drivers/iommu/riscv/iommu.c
+++ b/drivers/iommu/riscv/iommu.c
@@ -1593,11 +1593,26 @@ static int riscv_iommu_init_check(struct riscv_iommu_device *iommu)
FIELD_PREP(RISCV_IOMMU_ICVEC_PMIV, 3 % iommu->irqs_count);
riscv_iommu_writeq(iommu, RISCV_IOMMU_REG_ICVEC, iommu->icvec);
iommu->icvec = riscv_iommu_readq(iommu, RISCV_IOMMU_REG_ICVEC);
- if (max(max(FIELD_GET(RISCV_IOMMU_ICVEC_CIV, iommu->icvec),
- FIELD_GET(RISCV_IOMMU_ICVEC_FIV, iommu->icvec)),
- max(FIELD_GET(RISCV_IOMMU_ICVEC_PIV, iommu->icvec),
- FIELD_GET(RISCV_IOMMU_ICVEC_PMIV, iommu->icvec))) >= iommu->irqs_count)
- return -EINVAL;
+ /*
+ * In WSI mode, ICVEC may read as zero. Only validate if using MSI.
+ * Check if FCTL.WSI is set to determine interrupt mode.
+ */
+ if (!(iommu->fctl & RISCV_IOMMU_FCTL_WSI)) {
+ if (max(max(FIELD_GET(RISCV_IOMMU_ICVEC_CIV, iommu->icvec),
+ FIELD_GET(RISCV_IOMMU_ICVEC_FIV, iommu->icvec)),
+ max(FIELD_GET(RISCV_IOMMU_ICVEC_PIV, iommu->icvec),
+ FIELD_GET(RISCV_IOMMU_ICVEC_PMIV, iommu->icvec))) >= iommu->irqs_count)
+ return -EINVAL;
+ } else {
+ /*
+ * WSI mode: ICVEC is not used. Set to identity mapping for
+ * riscv_iommu_queue_vec() to work correctly.
+ */
+ iommu->icvec = FIELD_PREP(RISCV_IOMMU_ICVEC_CIV, 0) |
+ FIELD_PREP(RISCV_IOMMU_ICVEC_FIV, 1) |
+ FIELD_PREP(RISCV_IOMMU_ICVEC_PIV, 2) |
+ FIELD_PREP(RISCV_IOMMU_ICVEC_PMIV, 3);
+ }
return 0;
}
--
2.43.0
This message and any attachment are confidential and may be privileged or otherwise protected from disclosure. If you are not an intended recipient of this message, please delete it and any attachment from your system and notify the sender immediately by reply e-mail. Unintended recipients should not use, copy, disclose or take any action based on this message or any information contained in this message. Emails cannot be guaranteed to be secure or error free as they can be intercepted, amended, lost or destroyed, and you should take full responsibility for security checking.
本邮件及其任何附件具有保密性质,并可能受其他保护或不允许被披露给第三方。如阁下误收到本邮件,敬请立即以回复电子邮件的方式通知发件人,并将本邮件及其任何附件从阁下系统中予以删除。如阁下并非本邮件写明之收件人,敬请切勿使用、复制、披露本邮件或其任何内容,亦请切勿依本邮件或其任何内容而采取任何行动。电子邮件无法保证是一种安全和不会出现任何差错的通信方式,可能会被拦截、修改、丢失或损坏,收件人需自行负责做好安全检查。
More information about the linux-riscv
mailing list