EVENTQ_BASE and EVENTQ_PROD can currently be modified while the event
queue is enabled. Ignore these writes while EVENTQEN is set, using the
model's synchronous enable and acknowledgement state.

Mask reserved EVENTQ_BASE bits and update the queue size when writing
its low half. Use the high-half mask for writes to EVENTQ_BASE + 4.

The model does not advertise MSI support. Make EVENTQ_IRQ_CFG0/1/2 read
as zero and ignore writes, including accesses to both halves of CFG0.

Fixes: fae4be38b35d ("hw/arm/smmuv3: Implement MMIO write operations")
Signed-off-by: Tao Tang <[email protected]>
Reviewed-by: Pierrick Bouvier <[email protected]>
---
 hw/arm/smmuv3.c | 49 ++++++++++++++++++++++++++++++++++++++-----------
 1 file changed, 38 insertions(+), 11 deletions(-)

diff --git a/hw/arm/smmuv3.c b/hw/arm/smmuv3.c
index e5f057113e1..138ca178a1a 100644
--- a/hw/arm/smmuv3.c
+++ b/hw/arm/smmuv3.c
@@ -1775,14 +1775,19 @@ static MemTxResult smmu_writell(SMMUv3State *s, hwaddr 
offset,
         }
         return MEMTX_OK;
     case A_EVENTQ_BASE:
-        bank->eventq.base = data;
+        if (smmuv3_eventq_enabled(s, reg_sec_sid)) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "EVENTQ_BASE write ignored: register is RO\n");
+            return MEMTX_OK;
+        }
+
+        bank->eventq.base = data & SMMU_QUEUE_BASE_RESERVED;
         bank->eventq.log2size = extract64(bank->eventq.base, 0, 5);
         if (bank->eventq.log2size > SMMU_EVENTQS) {
             bank->eventq.log2size = SMMU_EVENTQS;
         }
         return MEMTX_OK;
     case A_EVENTQ_IRQ_CFG0:
-        bank->eventq_irq_cfg0 = data;
         return MEMTX_OK;
     default:
         qemu_log_mask(LOG_UNIMP,
@@ -1927,6 +1932,13 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr 
offset,
         bank->cmdq.cons = data;
         break;
     case A_EVENTQ_BASE: /* 64b */
+        if (smmuv3_eventq_enabled(s, reg_sec_sid)) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "EVENTQ_BASE write ignored: register is RO\n");
+            return MEMTX_OK;
+        }
+
+        data &= SMMU_QUEUE_BASE_RESERVED;
         bank->eventq.base = deposit64(bank->eventq.base, 0, 32, data);
         bank->eventq.log2size = extract64(bank->eventq.base, 0, 5);
         if (bank->eventq.log2size > SMMU_EVENTQS) {
@@ -1934,26 +1946,32 @@ static MemTxResult smmu_writel(SMMUv3State *s, hwaddr 
offset,
         }
         break;
     case A_EVENTQ_BASE + 4:
+        if (smmuv3_eventq_enabled(s, reg_sec_sid)) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "EVENTQ_BASE + 4 write ignored: register is RO\n");
+            return MEMTX_OK;
+        }
+
+        data &= SMMU_QUEUE_BASE_RESERVED >> 32;
         bank->eventq.base = deposit64(bank->eventq.base, 32, 32, data);
         break;
     case A_EVENTQ_PROD:
+        if (smmuv3_eventq_enabled(s, reg_sec_sid)) {
+            qemu_log_mask(LOG_GUEST_ERROR,
+                          "EVENTQ_PROD write ignored: register is RO\n");
+            return MEMTX_OK;
+        }
+
         bank->eventq.prod = data;
         break;
     case A_EVENTQ_CONS:
         bank->eventq.cons = data;
         break;
-    case A_EVENTQ_IRQ_CFG0: /* 64b */
-        bank->eventq_irq_cfg0 = deposit64(bank->eventq_irq_cfg0, 0, 32, data);
-        break;
+    case A_EVENTQ_IRQ_CFG0:
     case A_EVENTQ_IRQ_CFG0 + 4:
-        bank->eventq_irq_cfg0 = deposit64(bank->eventq_irq_cfg0, 32, 32, data);
-        break;
     case A_EVENTQ_IRQ_CFG1:
-        bank->eventq_irq_cfg1 = data;
-        break;
     case A_EVENTQ_IRQ_CFG2:
-        bank->eventq_irq_cfg2 = data;
-        break;
+        return MEMTX_OK;
     default:
         qemu_log_mask(LOG_UNIMP,
                       "%s Unexpected 32-bit access to 0x%"PRIx64" (WI)\n",
@@ -2012,6 +2030,9 @@ static MemTxResult smmu_readll(SMMUv3State *s, hwaddr 
offset,
     case A_EVENTQ_BASE:
         *data = bank->eventq.base;
         return MEMTX_OK;
+    case A_EVENTQ_IRQ_CFG0:
+        *data = 0;
+        return MEMTX_OK;
     default:
         *data = 0;
         qemu_log_mask(LOG_UNIMP,
@@ -2107,6 +2128,12 @@ static MemTxResult smmu_readl(SMMUv3State *s, hwaddr 
offset,
     case A_EVENTQ_CONS:
         *data = bank->eventq.cons;
         return MEMTX_OK;
+    case A_EVENTQ_IRQ_CFG0:
+    case A_EVENTQ_IRQ_CFG0 + 4:
+    case A_EVENTQ_IRQ_CFG1:
+    case A_EVENTQ_IRQ_CFG2:
+        *data = 0;
+        return MEMTX_OK;
     default:
         *data = 0;
         qemu_log_mask(LOG_UNIMP,
-- 
2.34.1


Reply via email to