[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [RFC PATCH v3 06/10] arm_gic: Keep track of GICD_CPENDR and
From: |
Christoffer Dall |
Subject: |
[Qemu-devel] [RFC PATCH v3 06/10] arm_gic: Keep track of GICD_CPENDR and GICD_SPENDR |
Date: |
Mon, 18 Nov 2013 22:18:12 -0800 |
If software writes to the ISPENDR and sets the pending state of a
level-triggered interrupt, the falling edge of the hardware input must
not clear the pending state. Conversely, if software writes to the
ICPENDR, the pending state of a level-triggered interrupt should only be
cleared if the hardware input is not asserted.
This requires an extra state variable to keep track of software writes.
Signed-off-by: Christoffer Dall <address@hidden>
---
hw/intc/arm_gic.c | 20 +++++++++++++++++---
hw/intc/arm_gic_common.c | 5 +++--
hw/intc/gic_internal.h | 3 +++
include/hw/intc/arm_gic_common.h | 1 +
4 files changed, 24 insertions(+), 5 deletions(-)
diff --git a/hw/intc/arm_gic.c b/hw/intc/arm_gic.c
index 5736b95..9811161 100644
--- a/hw/intc/arm_gic.c
+++ b/hw/intc/arm_gic.c
@@ -119,6 +119,12 @@ static void gic_clear_pending(GICState *s, int irq, int
cm, uint8_t src)
GIC_CLEAR_PENDING(irq, cm);
}
} else {
+ /* If a level-triggered interrupt has been set to pending through the
+ * GICD_SPENDR, then a falling edge does not clear the pending state.
+ */
+ if (GIC_TEST_SW_PENDING(irq, cm))
+ return;
+
GIC_CLEAR_PENDING(irq, cm);
}
}
@@ -189,8 +195,9 @@ uint32_t gic_acknowledge_irq(GICState *s, int cpu)
s->last_active[new_irq][cpu] = s->running_irq[cpu];
/* Clear pending flags for both level and edge triggered interrupts.
Level triggered IRQs will be reasserted once they become inactive. */
- gic_clear_pending(s, new_irq, GIC_TEST_MODEL(new_irq) ? ALL_CPU_MASK : cm,
- GIC_SGI_SRC(new_irq, cpu));
+ cm = GIC_TEST_MODEL(new_irq) ? ALL_CPU_MASK : cm;
+ GIC_CLEAR_SW_PENDING(new_irq, cm);
+ gic_clear_pending(s, new_irq, cm, GIC_SGI_SRC(new_irq, cpu));
gic_set_running_irq(s, cpu, new_irq);
DPRINTF("ACK %d\n", new_irq);
return new_irq;
@@ -454,16 +461,23 @@ static void gic_dist_writeb(void *opaque, hwaddr offset,
for (i = 0; i < 8; i++, irq++) {
if (irq >= GIC_NR_SGIS && value & (1 << i)) {
GIC_SET_PENDING(irq, GIC_TARGET(irq));
+ if (!GIC_TEST_EDGE_TRIGGER(irq)) {
+ GIC_SET_SW_PENDING(irq, GIC_TARGET(irq));
+ }
}
}
} else if (offset < 0x300) {
+ int cm = (1 << cpu);
/* Interrupt Clear Pending. */
irq = (offset - 0x280) * 8 + GIC_BASE_IRQ;
if (irq >= s->num_irq)
goto bad_reg;
for (i = 0; i < 8; i++, irq++) {
if (irq >= GIC_NR_SGIS && value & (1 << i)) {
- gic_clear_pending(s, irq, 1 << cpu, 0);
+ GIC_CLEAR_SW_PENDING(irq, cm);
+ if (GIC_TEST_EDGE_TRIGGER(irq) || !GIC_TEST_LEVEL(irq, cm)) {
+ GIC_CLEAR_PENDING(irq, cm);
+ }
}
}
} else if (offset < 0x400) {
diff --git a/hw/intc/arm_gic_common.c b/hw/intc/arm_gic_common.c
index 41ddc9b..65e3dc8 100644
--- a/hw/intc/arm_gic_common.c
+++ b/hw/intc/arm_gic_common.c
@@ -43,11 +43,12 @@ static int gic_post_load(void *opaque, int version_id)
static const VMStateDescription vmstate_gic_irq_state = {
.name = "arm_gic_irq_state",
- .version_id = 1,
- .minimum_version_id = 1,
+ .version_id = 2,
+ .minimum_version_id = 2,
.fields = (VMStateField[]) {
VMSTATE_UINT8(enabled, gic_irq_state),
VMSTATE_UINT8(pending, gic_irq_state),
+ VMSTATE_UINT8(sw_pending, gic_irq_state),
VMSTATE_UINT8(active, gic_irq_state),
VMSTATE_UINT8(level, gic_irq_state),
VMSTATE_BOOL(model, gic_irq_state),
diff --git a/hw/intc/gic_internal.h b/hw/intc/gic_internal.h
index 5471749..b04cb50 100644
--- a/hw/intc/gic_internal.h
+++ b/hw/intc/gic_internal.h
@@ -35,6 +35,9 @@
#define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm)
#define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm)
#define GIC_TEST_PENDING(irq, cm) ((s->irq_state[irq].pending & (cm)) != 0)
+#define GIC_SET_SW_PENDING(irq, cm) (s->irq_state[irq].sw_pending |= (cm))
+#define GIC_CLEAR_SW_PENDING(irq, cm) (s->irq_state[irq].sw_pending &= ~(cm))
+#define GIC_TEST_SW_PENDING(irq, cm) ((s->irq_state[irq].sw_pending & (cm)) !=
0)
#define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
#define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
#define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
diff --git a/include/hw/intc/arm_gic_common.h b/include/hw/intc/arm_gic_common.h
index 120d6b2..2d6c23f 100644
--- a/include/hw/intc/arm_gic_common.h
+++ b/include/hw/intc/arm_gic_common.h
@@ -35,6 +35,7 @@ typedef struct gic_irq_state {
/* The enable bits are only banked for per-cpu interrupts. */
uint8_t enabled;
uint8_t pending;
+ uint8_t sw_pending; /* keep track of GICD_ISPENDR and GICD_ICPENDR writes
*/
uint8_t active;
uint8_t level;
bool model; /* 0 = N:N, 1 = 1:N */
--
1.8.4.3
- [Qemu-devel] [RFC PATCH v3 01/10] hw: arm_gic: Fix gic_set_irq handling, (continued)
- [Qemu-devel] [RFC PATCH v3 01/10] hw: arm_gic: Fix gic_set_irq handling, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 02/10] hw: arm_gic: Introduce gic_set_priority function, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 03/10] hw: arm_gic: Keep track of SGI sources, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 04/10] arm_gic: Support setting/getting binary point reg, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 05/10] arm_gic: Rename GIC_X_TRIGGER to GIC_X_EDGE_TRIGGER, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 06/10] arm_gic: Keep track of GICD_CPENDR and GICD_SPENDR,
Christoffer Dall <=
- [Qemu-devel] [RFC PATCH v3 07/10] arm_gic: Fix gic_acknowledge_irq pending bit clear, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 08/10] vmstate: Add uint32 2D-array support, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 09/10] arm_gic: Add GICC_APRn state to the GICState, Christoffer Dall, 2013/11/19
- [Qemu-devel] [RFC PATCH v3 10/10] hw: arm_gic_kvm: Add KVM VGIC save/restore logic, Christoffer Dall, 2013/11/19