Skip to contentSkip to conversation

nvic: set pending status for not active interrupts

PATCH Superseded [email protected] 2 participants 6 messages Oct 18, 2016 – Oct 31, 2016

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 nvic: set pending status for not active interrupts

From: Marcin Krzeminski <[email protected]>

According to ARM DUI 0552A 4.2.10. NVIC set pending status also for disabled interrupts. This patch adds possibility to emulate this in Qemu.

---
Changes for v2:
- add a dedicated unction for nvic
- update complete_irq

 hw/intc/arm_gic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c +25 -2
index b30cc91..72e4c01 100644
@@ -156,6 +156,21 @@ static void gic_set_irq_11mpcore(GICState *s, int irq, int level,
     }
 }
 
+static void gic_set_irq_nvic(GICState *s, int irq, int level,
+                                 int cm, int target)
+{
+    if (level) {
+        GIC_SET_LEVEL(irq, cm);
+        if (GIC_TEST_EDGE_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)
+                || !GIC_TEST_ACTIVE(irq, cm)) {
+            DPRINTF("Set %d pending mask %x\n", irq, target);
+            GIC_SET_PENDING(irq, target);
+        }
+    } else {
+        GIC_CLEAR_LEVEL(irq, cm);
+    }
+}
+
 static void gic_set_irq_generic(GICState *s, int irq, int level,
                                 int cm, int target)
 {
@@ -201,8 +216,10 @@ static void gic_set_irq(void *opaque, int irq, int level)
         return;
     }
 
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         gic_set_irq_11mpcore(s, irq, level, cm, target);
+    } else if (s->revision == REV_NVIC) {
+        gic_set_irq_nvic(s, irq, level, cm, target);
     } else {
         gic_set_irq_generic(s, irq, level, cm, target);
     }
@@ -568,7 +585,7 @@ void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs)
         return; /* No active IRQ.  */
     }
 
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         /* Mark level triggered interrupts as pending if they are still
            raised.  */
         if (!GIC_TEST_EDGE_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm)
@@ -576,6 +593,12 @@ void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs)
             DPRINTF("Set %d pending mask %x\n", irq, cm);
             GIC_SET_PENDING(irq, cm);
         }
+    } else if (s->revision == REV_NVIC) {
+        if (GIC_TEST_ENABLED(irq, cm) && GIC_TEST_LEVEL(irq, cm)
+            && (GIC_TARGET(irq) & cm) != 0) {
+            DPRINTF("Set nvic %d pending mask %x\n", irq, cm);
+            GIC_SET_PENDING(irq, cm);
+        }
     }
 
     group = gic_has_groups(s) && GIC_TEST_GROUP(irq, cm);
Signature · 1 line
2.7.4
#1 lore raw
Quoted 7 lines · On 18 October 2016 at 07:14, <[email protected]> wrote:

From: Marcin Krzeminski <[email protected]>

According to ARM DUI 0552A 4.2.10. NVIC set pending status also for disabled interrupts. This patch adds possibility to emulate this in Qemu.

Thanks for rolling a v2. Unfortunately I think we don't have the logic quite right yet...

Quoted 15 lines

---
Changes for v2:
- add a dedicated unction for nvic
- update complete_irq

 hw/intc/arm_gic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c +0 -0
index b30cc91..72e4c01 100644
@@ -156,6 +156,21 @@ static void gic_set_irq_11mpcore(GICState *s, int irq, int level,
     }
 }
 

hw/intc/arm_gic.c static void gic_set_irq_11mpcore(GICState *s, int irq, int level, · line 168

Quoted 10 lines
hw/intc/arm_gic.c +10 -0
+static void gic_set_irq_nvic(GICState *s, int irq, int level,
+                                 int cm, int target)
+{
+    if (level) {
+        GIC_SET_LEVEL(irq, cm);
+        if (GIC_TEST_EDGE_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)
+                || !GIC_TEST_ACTIVE(irq, cm)) {
+            DPRINTF("Set %d pending mask %x\n", irq, target);
+            GIC_SET_PENDING(irq, target);
+        }

Why is GIC_TEST_ENABLED() in this condition, when the idea is that we don't care about the enabled status for whether we can pend the interrupt?

I think this should actually just always do
GIC_SET_PENDING(irq, target)
whenever level is high

because:
(1) pending status can be set for disabled interrupts
(2) edge-triggered IRQs definitely always re-pend on rising edge
(3) I think level-triggered IRQs do too (it's a bit less clear in the docs, but DUI0552A 4.2.9 says we pend on a rising edge and doesn't say that applies only to edge triggered IRQs)

I don't have any real hardware to hand to test against, though.

Quoted 30 lines
hw/intc/arm_gic.c +9 -2
+    } else {
+        GIC_CLEAR_LEVEL(irq, cm);
+    }
+}
+
 static void gic_set_irq_generic(GICState *s, int irq, int level,
                                 int cm, int target)
 {
@@ -201,8 +216,10 @@ static void gic_set_irq(void *opaque, int irq, int level)
         return;
     }
 
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         gic_set_irq_11mpcore(s, irq, level, cm, target);
+    } else if (s->revision == REV_NVIC) {
+        gic_set_irq_nvic(s, irq, level, cm, target);
     } else {
         gic_set_irq_generic(s, irq, level, cm, target);
     }
@@ -568,7 +585,7 @@ void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs)
         return; /* No active IRQ.  */
     }
 
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         /* Mark level triggered interrupts as pending if they are still
            raised.  */
         if (!GIC_TEST_EDGE_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm)

hw/intc/arm_gic.c void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs) · line 601

Quoted 9 lines
hw/intc/arm_gic.c +6 -0
@@ -576,6 +593,12 @@ void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs)
             DPRINTF("Set %d pending mask %x\n", irq, cm);
             GIC_SET_PENDING(irq, cm);
         }
+    } else if (s->revision == REV_NVIC) {
+        if (GIC_TEST_ENABLED(irq, cm) && GIC_TEST_LEVEL(irq, cm)
+            && (GIC_TARGET(irq) & cm) != 0) {
+            DPRINTF("Set nvic %d pending mask %x\n", irq, cm);
+            GIC_SET_PENDING(irq, cm);
+        }

Similarly, I think this should just be

    if (GIC_TEST_LEVEL(irq, cm) {
        GIC_SET_PENDING(irq, cm);
    }

because:
(1) for the NVIC there is only one CPU and GIC_TARGET(irq) always indicates that IRQs target it
(2) we don't care whether the interrupt is enabled when deciding whether it should be pended
(3) we don't care whether the interrupt is level-triggered or edge-triggered for deciding whether to re-pend it
(see statement R_XVWM in the v8M ARM ARM DDI0553A.c)

Quoted 5 lines
hw/intc/arm_gic.c +0 -1
     }
 
     group = gic_has_groups(s) && GIC_TEST_GROUP(irq, cm);
--

2.7.4

thanks
-- PMM

#2 lore raw

Peter,

Quoted 12 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Monday, October 24, 2016 5:26 PM
To: Krzeminski, Marcin (Nokia - PL/Wroclaw) <[email protected]>
Cc: QEMU Developers <[email protected]>; qemu-arm <qemu- [email protected]>; [email protected]
Subject: Re: [v2] nvic: set pending status for not active interrupts

Quoted 2 lines · On 18 October 2016 at 07:14, <[email protected]> wrote:

From: Marcin Krzeminski <[email protected]>

Quoted 9 lines
Quoted 5 lines

According to ARM DUI 0552A 4.2.10. NVIC set pending status also for disabled interrupts. This patch adds possibility to emulate this in Qemu.

Thanks for rolling a v2. Unfortunately I think we don't have the logic quite right yet...

Yeap, I separated it but not update to work only with NVIC.

Quoted 41 lines

hw/intc/arm_gic.c static void gic_set_irq_11mpcore(GICState *s, int

Quoted 12 lines

---
Changes for v2:
- add a dedicated unction for nvic
- update complete_irq

 hw/intc/arm_gic.c | 27 +++++++++++++++++++++++++--
 1 file changed, 25 insertions(+), 2 deletions(-)
hw/intc/arm_gic.c index renamed from hw/intc/arm_gic.c +0 -0

b30cc91..72e4c01 100644

hw/intc/arm_gic.c +0 -0
@@ -156,6 +156,21 @@ static void gic_set_irq_11mpcore(GICState *s, int

irq, int level,

hw/intc/arm_gic.c static void gic_set_irq_11mpcore(GICState *s, int irq, int level, · line 168

Quoted 12 lines
hw/intc/arm_gic.c +9 -0
     }
 }
 
+static void gic_set_irq_nvic(GICState *s, int irq, int level,
+                                 int cm, int target) {
+    if (level) {
+        GIC_SET_LEVEL(irq, cm);
+        if (GIC_TEST_EDGE_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)
+                || !GIC_TEST_ACTIVE(irq, cm)) {
+            DPRINTF("Set %d pending mask %x\n", irq, target);
+            GIC_SET_PENDING(irq, target);
+        }

Why is GIC_TEST_ENABLED() in this condition, when the idea is that we don't care about the enabled status for whether we can pend the interrupt?

I think this should actually just always do
GIC_SET_PENDING(irq, target)
whenever level is high

because:
(1) pending status can be set for disabled interrupts
(2) edge-triggered IRQs definitely always re-pend on rising edge
(3) I think level-triggered IRQs do too (it's a bit less clear in the docs, but DUI0552A 4.2.9 says we pend on a rising edge and doesn't say that applies only to edge triggered IRQs)

Quoted 2 lines

I don't have any real hardware to hand to test against, though.

Yes, it works exactly as you're saying (checked on HW), if level is still high after exit interrupt handler, interrupt is re-pend.

Quoted 46 lines

hw/intc/arm_gic.c void gic_complete_irq(GICState *s, int cpu, int irq,

Quoted 20 lines
hw/intc/arm_gic.c +6 -0
+    } else {
+        GIC_CLEAR_LEVEL(irq, cm);
+    }
+}
+
 static void gic_set_irq_generic(GICState *s, int irq, int level,
                                 int cm, int target)  { @@ -201,8
+216,10 @@ static void gic_set_irq(void *opaque, int irq, int level)
         return;
     }
hw/intc/arm_gic.c +3 -1
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         gic_set_irq_11mpcore(s, irq, level, cm, target);
+    } else if (s->revision == REV_NVIC) {
+        gic_set_irq_nvic(s, irq, level, cm, target);
     } else {
         gic_set_irq_generic(s, irq, level, cm, target);
     }
@@ -568,7 +585,7 @@ void gic_complete_irq(GICState *s, int cpu, int irq,

MemTxAttrs attrs)

hw/intc/arm_gic.c void gic_complete_irq(GICState *s, int cpu, int irq,

Quoted 9 lines
hw/intc/arm_gic.c +1 -1
         return; /* No active IRQ.  */
     }
 
-    if (s->revision == REV_11MPCORE || s->revision == REV_NVIC) {
+    if (s->revision == REV_11MPCORE) {
         /* Mark level triggered interrupts as pending if they are still
            raised.  */
         if (!GIC_TEST_EDGE_TRIGGER(irq) && GIC_TEST_ENABLED(irq, cm)
@@ -576,6 +593,12 @@ void gic_complete_irq(GICState *s, int cpu, int irq,

MemTxAttrs attrs)

hw/intc/arm_gic.c void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs) · line 601

Quoted 9 lines
hw/intc/arm_gic.c +6 -0
             DPRINTF("Set %d pending mask %x\n", irq, cm);
             GIC_SET_PENDING(irq, cm);
         }
+    } else if (s->revision == REV_NVIC) {
+        if (GIC_TEST_ENABLED(irq, cm) && GIC_TEST_LEVEL(irq, cm)
+            && (GIC_TARGET(irq) & cm) != 0) {
+            DPRINTF("Set nvic %d pending mask %x\n", irq, cm);
+            GIC_SET_PENDING(irq, cm);
+        }

Similarly, I think this should just be

    if (GIC_TEST_LEVEL(irq, cm) {
        GIC_SET_PENDING(irq, cm);
    }
Quoted 9 lines

because:
(1) for the NVIC there is only one CPU and GIC_TARGET(irq) always indicates
that IRQs target it
(2) we don't care whether the interrupt is enabled when deciding whether
it should be pended
(3) we don't care whether the interrupt is level-triggered or edge-triggered
for deciding whether to re-pend it (see statement R_XVWM in the v8M ARM ARM DDI0553A.c)

Same as above. I'll send v3.

Thanks,
Marcin

Quoted 8 lines
Quoted 5 lines
hw/intc/arm_gic.c +0 -1
     }
 
     group = gic_has_groups(s) && GIC_TEST_GROUP(irq, cm);
--

2.7.4

thanks
-- PMM

#3 lore raw
Quoted 29 lines · Marcin (Nokia - PL/Wroclaw)

Peter,

Quoted 27 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]

hw/intc/arm_gic.c static void gic_set_irq_11mpcore(GICState *s, int irq, int level, · line 168

Quoted 9 lines
hw/intc/arm_gic.c +9 -0
+static void gic_set_irq_nvic(GICState *s, int irq, int level,
+                                 int cm, int target) {
+    if (level) {
+        GIC_SET_LEVEL(irq, cm);
+        if (GIC_TEST_EDGE_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)
+                || !GIC_TEST_ACTIVE(irq, cm)) {
+            DPRINTF("Set %d pending mask %x\n", irq, target);
+            GIC_SET_PENDING(irq, target);
+        }

Why is GIC_TEST_ENABLED() in this condition, when the idea is that we don't care about the enabled status for whether we can pend the interrupt?

I think this should actually just always do
GIC_SET_PENDING(irq, target)
whenever level is high

because:
(1) pending status can be set for disabled interrupts
(2) edge-triggered IRQs definitely always re-pend on rising edge
(3) I think level-triggered IRQs do too (it's a bit less clear in the docs, but DUI0552A 4.2.9 says we pend on a rising edge and doesn't say that applies only to edge triggered IRQs)

Quoted 4 lines
Quoted 2 lines

I don't have any real hardware to hand to test against, though.

Yes, it works exactly as you're saying (checked on HW), if level is still high after exit interrupt handler, interrupt is re-pend.

"after exiting interrupt handler" is the wrong condition to check. You need to:
* cause the interrupt line to be set
* enter the interrupt handler as a result (int becomes active)
* cause the interrupt line to be lowered (while in the handler)
* cause the interrupt line to be set again (still in the handler)
* check the interrupt pending state (still in the handler)

If you only check the pending state after exiting the handler, then you can't tell whether it was pended on the rising edge while active, or for the "re-pend if high when we leave the interrupt handler". We know the hardware does the latter, it's the former we're unsure about.

thanks
-- PMM

#4 lore raw
Quoted 48 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]
Sent: Monday, October 31, 2016 11:15 AM
To: Krzeminski, Marcin (Nokia - PL/Wroclaw) <[email protected]>
Cc: QEMU Developers <[email protected]>; qemu-arm <qemu- [email protected]>; [email protected]
Subject: Re: [v2] nvic: set pending status for not active interrupts

Quoted 16 lines · Marcin (Nokia - PL/Wroclaw)

Peter,

Quoted 14 lines

-----Original Message-----
From: Peter Maydell [mailto:[email protected]]

hw/intc/arm_gic.c static void gic_set_irq_11mpcore(GICState *s, int irq, int level, · line 168

Quoted 9 lines
hw/intc/arm_gic.c +9 -0
+static void gic_set_irq_nvic(GICState *s, int irq, int level,
+                                 int cm, int target) {
+    if (level) {
+        GIC_SET_LEVEL(irq, cm);
+        if (GIC_TEST_EDGE_TRIGGER(irq) || GIC_TEST_ENABLED(irq, cm)
+                || !GIC_TEST_ACTIVE(irq, cm)) {
+            DPRINTF("Set %d pending mask %x\n", irq, target);
+            GIC_SET_PENDING(irq, target);
+        }

Why is GIC_TEST_ENABLED() in this condition, when the idea is that we don't care about the enabled status for whether we can pend the

interrupt?

Quoted 13 lines
Quoted 13 lines

I think this should actually just always do
GIC_SET_PENDING(irq, target)
whenever level is high

because:
(1) pending status can be set for disabled interrupts
(2) edge-triggered IRQs definitely always re-pend on rising edge
(3) I think level-triggered IRQs do too (it's a bit less clear in the docs, but DUI0552A 4.2.9 says we pend on a rising edge and doesn't say that applies only to edge triggered IRQs)

Quoted 4 lines
Quoted 2 lines

I don't have any real hardware to hand to test against, though.

Yes, it works exactly as you're saying (checked on HW), if level is still high after exit interrupt handler, interrupt is re-pend.

Quoted 8 lines

"after exiting interrupt handler" is the wrong condition to check. You need to:
* cause the interrupt line to be set
* enter the interrupt handler as a result (int becomes active)
* cause the interrupt line to be lowered (while in the handler)
* cause the interrupt line to be set again (still in the handler)
* check the interrupt pending state (still in the handler)

I performed this test, and when we are in interrupt handler (constantly pooling pending bit) interrupt is re-pend just after line is set again. V3 behaves in the same way.

Thanks,
Marcin

Quoted 7 lines

If you only check the pending state after exiting the handler, then you can't tell whether it was pended on the rising edge while active, or for the "re- pend if high when we leave the interrupt handler". We know the hardware does the latter, it's the former we're unsure about.

thanks
-- PMM

#5 lore raw
Quoted 11 lines · Marcin (Nokia - PL/Wroclaw)
Quoted 8 lines

"after exiting interrupt handler" is the wrong condition to check. You need to:
* cause the interrupt line to be set
* enter the interrupt handler as a result (int becomes active)
* cause the interrupt line to be lowered (while in the handler)
* cause the interrupt line to be set again (still in the handler)
* check the interrupt pending state (still in the handler)

I performed this test, and when we are in interrupt handler (constantly pooling pending bit) interrupt is re-pend just after line is set again. V3 behaves in the same way.

Great -- thanks for checking.

-- PMM