Skip to contentSkip to conversation

*** SUBJECT HERE ***

PATCH Superseded lanxiaoyun 2 participants 3 messages Jul 25 – Jul 27 SiFive drivers

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
author
#1 lore raw

PATCH 1/1 hw/intc: resample level IRQ on PLIC completion

In reply to lanxiaoyun

From: lanxiaoyun1 <[email protected]>

When an interrupt completion message is received, if the interrupt is level-triggered and still asserted, forward a new interrupt request to the PLIC core.

This updates the SiFive PLIC IRQ handling so completion rechecks the current source level and reasserts pending state when the input remains high, matching the RISC-V PLIC specification.

---
 hw/intc/sifive_plic.c         | 4 +++-
 include/hw/intc/sifive_plic.h | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
hw/intc/sifive_plic.c +3 -1
index 9c84ff06a9..43f235e329 100644
@@ -246,6 +246,7 @@ static void sifive_plic_write(void *opaque, hwaddr addr, uint64_t value,
         } else if (contextid == 4) {
             if (value < plic->num_sources) {
                 sifive_plic_set_claimed(plic, value, false);
+                sifive_plic_set_pending(plic, value, !!plic->source[value]);
                 sifive_plic_update(plic);
             }
         } else {
@@ -276,6 +277,7 @@ static void sifive_plic_reset(DeviceState *dev)
     int i;
 
     memset(s->source_priority, 0, sizeof(uint32_t) * s->num_sources);
+    memset(s->source, 0, sizeof(uint32_t) * s->num_sources);
     memset(s->target_priority, 0, sizeof(uint32_t) * s->num_addrs);
     memset(s->pending, 0, sizeof(uint32_t) * s->bitfield_words);
     memset(s->claimed, 0, sizeof(uint32_t) * s->bitfield_words);
@@ -353,7 +355,7 @@ static void parse_hart_config(SiFivePLICState *plic)
 static void sifive_plic_irq_request(void *opaque, int irq, int level)
 {
     SiFivePLICState *s = opaque;
-
+    s->source[irq] = !!level;
     if (level > 0) {
         sifive_plic_set_pending(s, irq, true);
         sifive_plic_update(s);
include/hw/intc/sifive_plic.h +1 -0
index 32973dbf28..627a418ba1 100644
@@ -54,6 +54,7 @@ struct SiFivePLICState {
     uint32_t num_enables;
     PLICAddr *addr_config;
     uint32_t *source_priority;
+    uint32_t *source;
     uint32_t *target_priority;
     uint32_t *pending;
     uint32_t *claimed;
Signature · 1 line
2.43.0

lanxiaoyun

author
#0 lore raw

cover *** SUBJECT HERE ***

From: lanxiaoyun1 <[email protected]>

*** BLURB HERE ***

lanxiaoyun1 (1):
hw/intc: resample level IRQ on PLIC completion

 hw/intc/sifive_plic.c         | 4 +++-
 include/hw/intc/sifive_plic.h | 1 +
 2 files changed, 4 insertions(+), 1 deletion(-)
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH v1 1/1] hw/intc: resample level IRQ on PLIC completion

In reply to lanxiaoyun

Hi,

Quoted 50 lines · lanxiaoyun

From: lanxiaoyun1 <[email protected]>

When an interrupt completion message is received, if the interrupt is level-triggered and still asserted, forward a new interrupt request to the PLIC core.

This updates the SiFive PLIC IRQ handling so completion rechecks the current source level and reasserts pending state when the input remains high, matching the RISC-V PLIC specification.

---
  hw/intc/sifive_plic.c         | 4 +++-
  include/hw/intc/sifive_plic.h | 1 +
  2 files changed, 4 insertions(+), 1 deletion(-)
hw/intc/sifive_plic.c +3 -1
index 9c84ff06a9..43f235e329 100644
@@ -246,6 +246,7 @@ static void sifive_plic_write(void *opaque, hwaddr addr, uint64_t value,
          } else if (contextid == 4) {
              if (value < plic->num_sources) {
                  sifive_plic_set_claimed(plic, value, false);
+                sifive_plic_set_pending(plic, value, !!plic->source[value]);
                  sifive_plic_update(plic);
              }
          } else {
@@ -276,6 +277,7 @@ static void sifive_plic_reset(DeviceState *dev)
      int i;
 
      memset(s->source_priority, 0, sizeof(uint32_t) * s->num_sources);
+    memset(s->source, 0, sizeof(uint32_t) * s->num_sources);
      memset(s->target_priority, 0, sizeof(uint32_t) * s->num_addrs);
      memset(s->pending, 0, sizeof(uint32_t) * s->bitfield_words);
      memset(s->claimed, 0, sizeof(uint32_t) * s->bitfield_words);
@@ -353,7 +355,7 @@ static void parse_hart_config(SiFivePLICState *plic)
  static void sifive_plic_irq_request(void *opaque, int irq, int level)
  {
      SiFivePLICState *s = opaque;
-
+    s->source[irq] = !!level;
      if (level > 0) {
          sifive_plic_set_pending(s, irq, true);
          sifive_plic_update(s);
include/hw/intc/sifive_plic.h +0 -0
index 32973dbf28..627a418ba1 100644

include/hw/intc/sifive_plic.h struct SiFivePLICState { · line 60

Quoted 7 lines
include/hw/intc/sifive_plic.h +1 -0
@@ -54,6 +54,7 @@ struct SiFivePLICState {
      uint32_t num_enables;
      PLICAddr *addr_config;
      uint32_t *source_priority;
+    uint32_t *source;
      uint32_t *target_priority;
      uint32_t *pending;
      uint32_t *claimed;

Where is this array initialized?