Skip to contentSkip to conversation

hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection

PATCH Applied [email protected] 4 participants 4 messages May 9 – May 19 RISC-V

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/riscv/riscv-iommu: Fix IOCOUNTINH.CY toggle detection

From: Fangyu Yu <[email protected]>

Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit rather than XORing whole register with boolean.

Fixes 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")
---
 hw/riscv/riscv-iommu-hpm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-hpm.c +2 -1
index e8d284ac8b..5bf80a8db9 100644
@@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
         s, RISCV_IOMMU_REG_IOCOUNTINH);
 
     /* We only need to process CY bit toggle. */
-    if (!(inhibit ^ prev_cy_inh)) {
+    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
+    if (cy_inh == prev_cy_inh) {
         return;
     }
 
Signature · 1 line
2.50.1
Reviewed-by on v1 1/1
#1 lore raw
Quoted 8 lines · On 5/9/2026 4:49 AM, [email protected] wrote:

From: Fangyu Yu <[email protected]>

Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit rather than XORing whole register with boolean.

Fixes 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")

---

Quoted 17 lines
  hw/riscv/riscv-iommu-hpm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-hpm.c +2 -1
index e8d284ac8b..5bf80a8db9 100644
@@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
          s, RISCV_IOMMU_REG_IOCOUNTINH);
 
      /* We only need to process CY bit toggle. */
-    if (!(inhibit ^ prev_cy_inh)) {
+    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
+    if (cy_inh == prev_cy_inh) {
          return;
      }
 
Reviewed-by on v1 1/1
#2 lore raw
In reply to [email protected]
Quoted 7 lines · On 5/9/2026 3:49 PM, [email protected] wrote:

From: Fangyu Yu <[email protected]>

Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit rather than XORing whole register with boolean.

Fixes 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")

Thanks,
Nutty

Quoted 18 lines
---
  hw/riscv/riscv-iommu-hpm.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-hpm.c +2 -1
index e8d284ac8b..5bf80a8db9 100644
@@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
          s, RISCV_IOMMU_REG_IOCOUNTINH);
 
      /* We only need to process CY bit toggle. */
-    if (!(inhibit ^ prev_cy_inh)) {
+    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
+    if (cy_inh == prev_cy_inh) {
          return;
      }
 
#3 lore raw
In reply to [email protected]
Quoted 8 lines · On Sat, May 9, 2026 at 5:57 PM <[email protected]> wrote:

From: Fangyu Yu <[email protected]>

Fix IOCOUNTINH.CY toggle detection by comparing normalized CY bit rather than XORing whole register with boolean.

Fixes 2cf2a6c027ba ("hw/riscv/riscv-iommu: add IOCOUNTINH mmio writes")

Thanks!

Applied to riscv-to-apply.next

Alistair

Quoted 22 lines
---
 hw/riscv/riscv-iommu-hpm.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
hw/riscv/riscv-iommu-hpm.c +2 -2
index e8d284ac8b..5bf80a8db9 100644
@@ -245,7 +245,8 @@ void riscv_iommu_process_iocntinh_cy(RISCVIOMMUState *s, bool prev_cy_inh)
         s, RISCV_IOMMU_REG_IOCOUNTINH);
 
     /* We only need to process CY bit toggle. */
-    if (!(inhibit ^ prev_cy_inh)) {
+    bool cy_inh = !!(inhibit & RISCV_IOMMU_IOCOUNTINH_CY);
+    if (cy_inh == prev_cy_inh) {
         return;
     }
 
--

2.50.1