xref: /openbmc/qemu/hw/intc/gic_internal.h (revision 39164c13)
1 /*
2  * ARM GIC support - internal interfaces
3  *
4  * Copyright (c) 2012 Linaro Limited
5  * Written by Peter Maydell
6  *
7  * This program is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 2 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License along
18  * with this program; if not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef QEMU_ARM_GIC_INTERNAL_H
22 #define QEMU_ARM_GIC_INTERNAL_H
23 
24 #include "hw/intc/arm_gic.h"
25 
26 #define ALL_CPU_MASK ((unsigned)(((1 << GIC_NCPU) - 1)))
27 
28 #define GIC_BASE_IRQ 0
29 
30 #define GIC_SET_ENABLED(irq, cm) s->irq_state[irq].enabled |= (cm)
31 #define GIC_CLEAR_ENABLED(irq, cm) s->irq_state[irq].enabled &= ~(cm)
32 #define GIC_TEST_ENABLED(irq, cm) ((s->irq_state[irq].enabled & (cm)) != 0)
33 #define GIC_SET_PENDING(irq, cm) s->irq_state[irq].pending |= (cm)
34 #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm)
35 #define GIC_SET_ACTIVE(irq, cm) s->irq_state[irq].active |= (cm)
36 #define GIC_CLEAR_ACTIVE(irq, cm) s->irq_state[irq].active &= ~(cm)
37 #define GIC_TEST_ACTIVE(irq, cm) ((s->irq_state[irq].active & (cm)) != 0)
38 #define GIC_SET_MODEL(irq) s->irq_state[irq].model = true
39 #define GIC_CLEAR_MODEL(irq) s->irq_state[irq].model = false
40 #define GIC_TEST_MODEL(irq) s->irq_state[irq].model
41 #define GIC_SET_LEVEL(irq, cm) s->irq_state[irq].level |= (cm)
42 #define GIC_CLEAR_LEVEL(irq, cm) s->irq_state[irq].level &= ~(cm)
43 #define GIC_TEST_LEVEL(irq, cm) ((s->irq_state[irq].level & (cm)) != 0)
44 #define GIC_SET_EDGE_TRIGGER(irq) s->irq_state[irq].edge_trigger = true
45 #define GIC_CLEAR_EDGE_TRIGGER(irq) s->irq_state[irq].edge_trigger = false
46 #define GIC_TEST_EDGE_TRIGGER(irq) (s->irq_state[irq].edge_trigger)
47 #define GIC_GET_PRIORITY(irq, cpu) (((irq) < GIC_INTERNAL) ?            \
48                                     s->priority1[irq][cpu] :            \
49                                     s->priority2[(irq) - GIC_INTERNAL])
50 #define GIC_TARGET(irq) s->irq_target[irq]
51 #define GIC_CLEAR_GROUP(irq, cm) (s->irq_state[irq].group &= ~(cm))
52 #define GIC_SET_GROUP(irq, cm) (s->irq_state[irq].group |= (cm))
53 #define GIC_TEST_GROUP(irq, cm) ((s->irq_state[irq].group & (cm)) != 0)
54 
55 #define GICD_CTLR_EN_GRP0 (1U << 0)
56 #define GICD_CTLR_EN_GRP1 (1U << 1)
57 
58 #define GICC_CTLR_EN_GRP0    (1U << 0)
59 #define GICC_CTLR_EN_GRP1    (1U << 1)
60 #define GICC_CTLR_ACK_CTL    (1U << 2)
61 #define GICC_CTLR_FIQ_EN     (1U << 3)
62 #define GICC_CTLR_CBPR       (1U << 4) /* GICv1: SBPR */
63 #define GICC_CTLR_EOIMODE    (1U << 9)
64 #define GICC_CTLR_EOIMODE_NS (1U << 10)
65 
66 /* Valid bits for GICC_CTLR for GICv1, v1 with security extensions,
67  * GICv2 and GICv2 with security extensions:
68  */
69 #define GICC_CTLR_V1_MASK    0x1
70 #define GICC_CTLR_V1_S_MASK  0x1f
71 #define GICC_CTLR_V2_MASK    0x21f
72 #define GICC_CTLR_V2_S_MASK  0x61f
73 
74 /* The special cases for the revision property: */
75 #define REV_11MPCORE 0
76 
77 void gic_set_pending_private(GICState *s, int cpu, int irq);
78 uint32_t gic_acknowledge_irq(GICState *s, int cpu, MemTxAttrs attrs);
79 void gic_complete_irq(GICState *s, int cpu, int irq, MemTxAttrs attrs);
80 void gic_update(GICState *s);
81 void gic_init_irqs_and_distributor(GICState *s);
82 void gic_set_priority(GICState *s, int cpu, int irq, uint8_t val,
83                       MemTxAttrs attrs);
84 
85 static inline bool gic_test_pending(GICState *s, int irq, int cm)
86 {
87     if (s->revision == REV_11MPCORE) {
88         return s->irq_state[irq].pending & cm;
89     } else {
90         /* Edge-triggered interrupts are marked pending on a rising edge, but
91          * level-triggered interrupts are either considered pending when the
92          * level is active or if software has explicitly written to
93          * GICD_ISPENDR to set the state pending.
94          */
95         return (s->irq_state[irq].pending & cm) ||
96             (!GIC_TEST_EDGE_TRIGGER(irq) && GIC_TEST_LEVEL(irq, cm));
97     }
98 }
99 
100 #endif /* QEMU_ARM_GIC_INTERNAL_H */
101