qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] riscv: plic: Honour source priorities
@ 2020-06-18 19:35 Jessica Clarke
  2020-06-18 20:00 ` no-reply
  2020-06-18 20:23 ` [PATCH v2] " Jessica Clarke
  0 siblings, 2 replies; 5+ messages in thread
From: Jessica Clarke @ 2020-06-18 19:35 UTC (permalink / raw)
  To: qemu-riscv
  Cc: Sagar Karandikar, Bastian Koppelmann, qemu-devel, Palmer Dabbelt,
	Alistair Francis, Jessica Clarke

The source priorities can be used to order sources with respect to other
sources, not just as a way to enable/disable them based off a threshold.
We must therefore always claim the highest-priority source, rather than
the first source we find.

Signed-off-by: Jessica Clarke <jrtc27@jrtc27.com>
---
 hw/riscv/sifive_plic.c | 19 ++++++++++++++-----
 1 file changed, 14 insertions(+), 5 deletions(-)

diff --git a/hw/riscv/sifive_plic.c b/hw/riscv/sifive_plic.c
index 4f216c5585..911e006095 100644
--- a/hw/riscv/sifive_plic.c
+++ b/hw/riscv/sifive_plic.c
@@ -166,6 +166,9 @@ static void sifive_plic_update(SiFivePLICState *plic)
 static uint32_t sifive_plic_claim(SiFivePLICState *plic, uint32_t addrid)
 {
     int i, j;
+    uint32_t max_irq = 0;
+    uint32_t max_prio = 0;
+
     for (i = 0; i < plic->bitfield_words; i++) {
         uint32_t pending_enabled_not_claimed =
             (plic->pending[i] & ~plic->claimed[i]) &
@@ -177,14 +180,20 @@ static uint32_t sifive_plic_claim(SiFivePLICState *plic, uint32_t addrid)
             int irq = (i << 5) + j;
             uint32_t prio = plic->source_priority[irq];
             int enabled = pending_enabled_not_claimed & (1 << j);
-            if (enabled && prio > plic->target_priority[addrid]) {
-                sifive_plic_set_pending(plic, irq, false);
-                sifive_plic_set_claimed(plic, irq, true);
-                return irq;
+            if (enabled && prio > plic->target_priority[addrid] &&
+                prio > max_prio)
+            {
+                max_irq = irq;
+                max_prio = prio;
             }
         }
     }
-    return 0;
+
+    if (max_irq) {
+        sifive_plic_set_pending(plic, max_irq, false);
+        sifive_plic_set_claimed(plic, max_irq, true);
+    }
+    return max_irq;
 }
 
 static uint64_t sifive_plic_read(void *opaque, hwaddr addr, unsigned size)
-- 
2.20.1



^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-06-19 21:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-06-18 19:35 [PATCH] riscv: plic: Honour source priorities Jessica Clarke
2020-06-18 20:00 ` no-reply
2020-06-18 20:23 ` [PATCH v2] " Jessica Clarke
2020-06-18 20:43   ` no-reply
2020-06-19 21:13   ` Alistair Francis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).