static void gic_complete_irq(gic_state * s, int irq) { int update = 0; DPRINTF("EOI %d\n", irq); if (s->running_irq == 1023) return; /* No active IRQ. */ if (irq != 1023) { /* Mark level triggered interrupts as pending if they are still raised. */ if (!GIC_TEST_TRIGGER(irq) && GIC_TEST_ENABLED(irq) && GIC_TEST_LEVEL(irq)) { GIC_SET_PENDING(irq); update = 1; } } if (irq != s->running_irq) { /* Complete an IRQ that is not currently running. */ int tmp = s->running_irq; while (s->last_active[tmp] != 1023) { if (s->last_active[tmp] == irq) { s->last_active[tmp] = s->last_active[irq]; break; } tmp = s->last_active[tmp]; } if (update) { gic_update(s); } } else { /* Complete the current running IRQ. */ gic_set_running_irq(s, s->last_active[s->running_irq]); } }
static void gic_dist_writew(void *opaque, target_phys_addr_t offset, uint32_t value) { gic_state *s = (gic_state *)opaque; if (offset - s->base == 0xf00) { GIC_SET_PENDING(value & 0x3ff); gic_update(s); return; } gic_dist_writeb(opaque, offset, value & 0xff); gic_dist_writeb(opaque, offset + 1, value >> 8); }
static void translate_pending(GICState *s, int irq, int cpu, uint32_t *field, bool to_kernel) { int cm = (irq < GIC_INTERNAL) ? (1 << cpu) : ALL_CPU_MASK; if (to_kernel) { *field = gic_test_pending(s, irq, cm); } else { if (*field & 1) { GIC_SET_PENDING(irq, cm); /* TODO: Capture is level-line is held high in the kernel */ } } }
static void gic_set_irq(void *opaque, int irq, int level) { gic_state *s = (gic_state *)opaque; /* The first external input line is internal interrupt 32. */ irq += 32; if (level == GIC_TEST_LEVEL(irq)) return; if (level) { GIC_SET_LEVEL(irq); if (GIC_TEST_TRIGGER(irq) || GIC_TEST_ENABLED(irq)) { DPRINTF("Set %d pending\n", irq); GIC_SET_PENDING(irq); } } else { GIC_CLEAR_LEVEL(irq); } gic_update(s); }
static void gic_dist_writeb(void *opaque, target_phys_addr_t offset, uint32_t value) { gic_state *s = (gic_state *)opaque; int irq; int i; offset -= s->base + 0x1000; if (offset < 0x100) { if (offset == 0) { s->enabled = (value & 1); DPRINTF("Distribution %sabled\n", s->enabled ? "En" : "Dis"); } else if (offset < 4) { /* ignored. */ } else { goto bad_reg; } } else if (offset < 0x180) { /* Interrupt Set Enable. */ irq = (offset - 0x100) * 8; if (irq >= GIC_NIRQ) goto bad_reg; for (i = 0; i < 8; i++) { if (value & (1 << i)) { if (!GIC_TEST_ENABLED(irq + i)) DPRINTF("Enabled IRQ %d\n", irq + i); GIC_SET_ENABLED(irq + i); /* If a raised level triggered IRQ enabled then mark is as pending. */ if (GIC_TEST_LEVEL(irq + i) && !GIC_TEST_TRIGGER(irq + i)) GIC_SET_PENDING(irq + i); } } } else if (offset < 0x200) { /* Interrupt Clear Enable. */ irq = (offset - 0x180) * 8; if (irq >= GIC_NIRQ) goto bad_reg; for (i = 0; i < 8; i++) { if (value & (1 << i)) { if (GIC_TEST_ENABLED(irq + i)) DPRINTF("Disabled IRQ %d\n", irq + i); GIC_CLEAR_ENABLED(irq + i); } } } else if (offset < 0x280) { /* Interrupt Set Pending. */ irq = (offset - 0x200) * 8; if (irq >= GIC_NIRQ) goto bad_reg; for (i = 0; i < 8; i++) { if (value & (1 << i)) { GIC_SET_PENDING(irq + i); } } } else if (offset < 0x300) { /* Interrupt Clear Pending. */ irq = (offset - 0x280) * 8; if (irq >= GIC_NIRQ) goto bad_reg; for (i = 0; i < 8; i++) { if (value & (1 << i)) { GIC_CLEAR_PENDING(irq + i); } } } else if (offset < 0x400) { /* Interrupt Active. */ goto bad_reg; } else if (offset < 0x800) { /* Interrupt Priority. */ irq = offset - 0x400; if (irq >= GIC_NIRQ) goto bad_reg; s->priority[irq] = value; } else if (offset < 0xc00) { /* Interrupt CPU Target. */ irq = offset - 0x800; if (irq >= GIC_NIRQ) goto bad_reg; s->irq_target[irq] = value; } else if (offset < 0xf00) { /* Interrupt Configuration. */ irq = (offset - 0xc00) * 4; if (irq >= GIC_NIRQ) goto bad_reg; for (i = 0; i < 4; i++) { if (value & (1 << (i * 2))) { GIC_SET_MODEL(irq + i); } else { GIC_CLEAR_MODEL(irq + i); } if (value & (2 << (i * 2))) { GIC_SET_TRIGGER(irq + i); } else { GIC_CLEAR_TRIGGER(irq + i); } } } else { /* 0xf00 is only handled for word writes. */ goto bad_reg; } gic_update(s); return; bad_reg: cpu_abort (cpu_single_env, "gic_dist_writeb: Bad offset %x\n", offset); }