blob: 7959bb78f4f9f38d2cdf67301b96c8f35f26affa [file] [log] [blame]
Sandrine Bailleux27866d82013-10-25 15:33:39 +01001/*
Dan Handleye83b0ca2014-01-14 18:17:09 +00002 * Copyright (c) 2013-2014, ARM Limited and Contributors. All rights reserved.
Sandrine Bailleux27866d82013-10-25 15:33:39 +01003 *
dp-armfa3cf0b2017-05-03 09:38:09 +01004 * SPDX-License-Identifier: BSD-3-Clause
Sandrine Bailleux27866d82013-10-25 15:33:39 +01005 */
6
7#ifndef __GIC_V2_H__
8#define __GIC_V2_H__
9
Soby Mathew3ddc9722015-10-26 14:32:09 +000010/******************************************************************************
11 * THIS DRIVER IS DEPRECATED. For GICv2 systems, use the driver in gicv2.h
12 * and for GICv3 systems, use the driver in gicv3.h.
13 *****************************************************************************/
14#if ERROR_DEPRECATED
15#error " The legacy ARM GIC driver is deprecated."
16#endif
Dan Handley930ee2e2014-04-17 17:48:52 +010017
18#define GIC400_NUM_SPIS 480
19#define MAX_PPIS 14
20#define MAX_SGIS 16
21
Dan Handleyfb42b122014-06-20 09:43:15 +010022#define MIN_SGI_ID 0
23#define MIN_PPI_ID 16
24#define MIN_SPI_ID 32
25
Dan Handley930ee2e2014-04-17 17:48:52 +010026#define GRP0 0
27#define GRP1 1
28#define GIC_PRI_MASK 0xff
29#define GIC_HIGHEST_SEC_PRIORITY 0
30#define GIC_LOWEST_SEC_PRIORITY 127
31#define GIC_HIGHEST_NS_PRIORITY 128
32#define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */
Achin Gupta02d36282014-05-04 19:02:52 +010033#define GIC_SPURIOUS_INTERRUPT 1023
Juan Castillo82312952014-10-20 12:27:28 +010034#define GIC_TARGET_CPU_MASK 0xff
Dan Handley930ee2e2014-04-17 17:48:52 +010035
36#define ENABLE_GRP0 (1 << 0)
37#define ENABLE_GRP1 (1 << 1)
38
39/* Distributor interface definitions */
40#define GICD_CTLR 0x0
41#define GICD_TYPER 0x4
42#define GICD_IGROUPR 0x80
43#define GICD_ISENABLER 0x100
44#define GICD_ICENABLER 0x180
45#define GICD_ISPENDR 0x200
46#define GICD_ICPENDR 0x280
47#define GICD_ISACTIVER 0x300
48#define GICD_ICACTIVER 0x380
49#define GICD_IPRIORITYR 0x400
50#define GICD_ITARGETSR 0x800
51#define GICD_ICFGR 0xC00
52#define GICD_SGIR 0xF00
53#define GICD_CPENDSGIR 0xF10
54#define GICD_SPENDSGIR 0xF20
55
56#define IGROUPR_SHIFT 5
57#define ISENABLER_SHIFT 5
58#define ICENABLER_SHIFT ISENABLER_SHIFT
59#define ISPENDR_SHIFT 5
60#define ICPENDR_SHIFT ISPENDR_SHIFT
61#define ISACTIVER_SHIFT 5
62#define ICACTIVER_SHIFT ISACTIVER_SHIFT
63#define IPRIORITYR_SHIFT 2
64#define ITARGETSR_SHIFT 2
65#define ICFGR_SHIFT 4
66#define CPENDSGIR_SHIFT 2
67#define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
68
69/* GICD_TYPER bit definitions */
70#define IT_LINES_NO_MASK 0x1f
71
72/* Physical CPU Interface registers */
73#define GICC_CTLR 0x0
74#define GICC_PMR 0x4
75#define GICC_BPR 0x8
76#define GICC_IAR 0xC
77#define GICC_EOIR 0x10
78#define GICC_RPR 0x14
79#define GICC_HPPIR 0x18
Achin Gupta02d36282014-05-04 19:02:52 +010080#define GICC_AHPPIR 0x28
Dan Handley930ee2e2014-04-17 17:48:52 +010081#define GICC_IIDR 0xFC
82#define GICC_DIR 0x1000
83#define GICC_PRIODROP GICC_EOIR
84
Achin Gupta966b9522015-05-18 10:56:47 +010085/* Common CPU Interface definitions */
86#define INT_ID_MASK 0x3ff
87
Dan Handley930ee2e2014-04-17 17:48:52 +010088/* GICC_CTLR bit definitions */
89#define EOI_MODE_NS (1 << 10)
90#define EOI_MODE_S (1 << 9)
91#define IRQ_BYP_DIS_GRP1 (1 << 8)
92#define FIQ_BYP_DIS_GRP1 (1 << 7)
93#define IRQ_BYP_DIS_GRP0 (1 << 6)
94#define FIQ_BYP_DIS_GRP0 (1 << 5)
95#define CBPR (1 << 4)
96#define FIQ_EN (1 << 3)
97#define ACK_CTL (1 << 2)
98
99/* GICC_IIDR bit masks and shifts */
100#define GICC_IIDR_PID_SHIFT 20
101#define GICC_IIDR_ARCH_SHIFT 16
102#define GICC_IIDR_REV_SHIFT 12
103#define GICC_IIDR_IMP_SHIFT 0
104
105#define GICC_IIDR_PID_MASK 0xfff
106#define GICC_IIDR_ARCH_MASK 0xf
107#define GICC_IIDR_REV_MASK 0xf
108#define GICC_IIDR_IMP_MASK 0xfff
109
110/* HYP view virtual CPU Interface registers */
111#define GICH_CTL 0x0
112#define GICH_VTR 0x4
113#define GICH_ELRSR0 0x30
114#define GICH_ELRSR1 0x34
115#define GICH_APR0 0xF0
116#define GICH_LR_BASE 0x100
117
118/* Virtual CPU Interface registers */
119#define GICV_CTL 0x0
120#define GICV_PRIMASK 0x4
121#define GICV_BP 0x8
122#define GICV_INTACK 0xC
123#define GICV_EOI 0x10
124#define GICV_RUNNINGPRI 0x14
125#define GICV_HIGHESTPEND 0x18
126#define GICV_DEACTIVATE 0x1000
127
128#ifndef __ASSEMBLY__
129
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100130#include <mmio.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +0100131#include <stdint.h>
Dan Handley930ee2e2014-04-17 17:48:52 +0100132
133/*******************************************************************************
134 * GIC Distributor function prototypes
135 ******************************************************************************/
136
Juan Castillo7f1f0622014-09-09 09:49:23 +0100137unsigned int gicd_read_igroupr(uintptr_t, unsigned int);
138unsigned int gicd_read_isenabler(uintptr_t, unsigned int);
139unsigned int gicd_read_icenabler(uintptr_t, unsigned int);
140unsigned int gicd_read_ispendr(uintptr_t, unsigned int);
141unsigned int gicd_read_icpendr(uintptr_t, unsigned int);
142unsigned int gicd_read_isactiver(uintptr_t, unsigned int);
143unsigned int gicd_read_icactiver(uintptr_t, unsigned int);
144unsigned int gicd_read_ipriorityr(uintptr_t, unsigned int);
145unsigned int gicd_read_itargetsr(uintptr_t, unsigned int);
146unsigned int gicd_read_icfgr(uintptr_t, unsigned int);
147unsigned int gicd_read_cpendsgir(uintptr_t, unsigned int);
148unsigned int gicd_read_spendsgir(uintptr_t, unsigned int);
149void gicd_write_igroupr(uintptr_t, unsigned int, unsigned int);
150void gicd_write_isenabler(uintptr_t, unsigned int, unsigned int);
151void gicd_write_icenabler(uintptr_t, unsigned int, unsigned int);
152void gicd_write_ispendr(uintptr_t, unsigned int, unsigned int);
153void gicd_write_icpendr(uintptr_t, unsigned int, unsigned int);
154void gicd_write_isactiver(uintptr_t, unsigned int, unsigned int);
155void gicd_write_icactiver(uintptr_t, unsigned int, unsigned int);
156void gicd_write_ipriorityr(uintptr_t, unsigned int, unsigned int);
157void gicd_write_itargetsr(uintptr_t, unsigned int, unsigned int);
158void gicd_write_icfgr(uintptr_t, unsigned int, unsigned int);
159void gicd_write_cpendsgir(uintptr_t, unsigned int, unsigned int);
160void gicd_write_spendsgir(uintptr_t, unsigned int, unsigned int);
161unsigned int gicd_get_igroupr(uintptr_t, unsigned int);
162void gicd_set_igroupr(uintptr_t, unsigned int);
163void gicd_clr_igroupr(uintptr_t, unsigned int);
164void gicd_set_isenabler(uintptr_t, unsigned int);
165void gicd_set_icenabler(uintptr_t, unsigned int);
166void gicd_set_ispendr(uintptr_t, unsigned int);
167void gicd_set_icpendr(uintptr_t, unsigned int);
168void gicd_set_isactiver(uintptr_t, unsigned int);
169void gicd_set_icactiver(uintptr_t, unsigned int);
170void gicd_set_ipriorityr(uintptr_t, unsigned int, unsigned int);
171void gicd_set_itargetsr(uintptr_t, unsigned int, unsigned int);
Dan Handley930ee2e2014-04-17 17:48:52 +0100172
173
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100174/*******************************************************************************
175 * GIC Distributor interface accessors for reading entire registers
176 ******************************************************************************/
177
Juan Castillo7f1f0622014-09-09 09:49:23 +0100178static inline unsigned int gicd_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100179{
180 return mmio_read_32(base + GICD_CTLR);
181}
182
Juan Castillo7f1f0622014-09-09 09:49:23 +0100183static inline unsigned int gicd_read_typer(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100184{
185 return mmio_read_32(base + GICD_TYPER);
186}
187
Juan Castillo7f1f0622014-09-09 09:49:23 +0100188static inline unsigned int gicd_read_sgir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100189{
190 return mmio_read_32(base + GICD_SGIR);
191}
192
193
194/*******************************************************************************
195 * GIC Distributor interface accessors for writing entire registers
196 ******************************************************************************/
197
Juan Castillo7f1f0622014-09-09 09:49:23 +0100198static inline void gicd_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100199{
200 mmio_write_32(base + GICD_CTLR, val);
201}
202
Juan Castillo7f1f0622014-09-09 09:49:23 +0100203static inline void gicd_write_sgir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100204{
205 mmio_write_32(base + GICD_SGIR, val);
206}
207
208
209/*******************************************************************************
210 * GIC CPU interface accessors for reading entire registers
211 ******************************************************************************/
212
Juan Castillo7f1f0622014-09-09 09:49:23 +0100213static inline unsigned int gicc_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100214{
215 return mmio_read_32(base + GICC_CTLR);
216}
217
Juan Castillo7f1f0622014-09-09 09:49:23 +0100218static inline unsigned int gicc_read_pmr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100219{
220 return mmio_read_32(base + GICC_PMR);
221}
222
Juan Castillo7f1f0622014-09-09 09:49:23 +0100223static inline unsigned int gicc_read_BPR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100224{
225 return mmio_read_32(base + GICC_BPR);
226}
227
Juan Castillo7f1f0622014-09-09 09:49:23 +0100228static inline unsigned int gicc_read_IAR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100229{
230 return mmio_read_32(base + GICC_IAR);
231}
232
Juan Castillo7f1f0622014-09-09 09:49:23 +0100233static inline unsigned int gicc_read_EOIR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100234{
235 return mmio_read_32(base + GICC_EOIR);
236}
237
Juan Castillo7f1f0622014-09-09 09:49:23 +0100238static inline unsigned int gicc_read_hppir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100239{
240 return mmio_read_32(base + GICC_HPPIR);
241}
242
Juan Castillo7f1f0622014-09-09 09:49:23 +0100243static inline unsigned int gicc_read_ahppir(uintptr_t base)
Achin Gupta02d36282014-05-04 19:02:52 +0100244{
245 return mmio_read_32(base + GICC_AHPPIR);
246}
247
Juan Castillo7f1f0622014-09-09 09:49:23 +0100248static inline unsigned int gicc_read_dir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100249{
250 return mmio_read_32(base + GICC_DIR);
251}
252
Juan Castillo7f1f0622014-09-09 09:49:23 +0100253static inline unsigned int gicc_read_iidr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100254{
255 return mmio_read_32(base + GICC_IIDR);
256}
257
258
259/*******************************************************************************
260 * GIC CPU interface accessors for writing entire registers
261 ******************************************************************************/
262
Juan Castillo7f1f0622014-09-09 09:49:23 +0100263static inline void gicc_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100264{
265 mmio_write_32(base + GICC_CTLR, val);
266}
267
Juan Castillo7f1f0622014-09-09 09:49:23 +0100268static inline void gicc_write_pmr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100269{
270 mmio_write_32(base + GICC_PMR, val);
271}
272
Juan Castillo7f1f0622014-09-09 09:49:23 +0100273static inline void gicc_write_BPR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100274{
275 mmio_write_32(base + GICC_BPR, val);
276}
277
278
Juan Castillo7f1f0622014-09-09 09:49:23 +0100279static inline void gicc_write_IAR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100280{
281 mmio_write_32(base + GICC_IAR, val);
282}
283
Juan Castillo7f1f0622014-09-09 09:49:23 +0100284static inline void gicc_write_EOIR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100285{
286 mmio_write_32(base + GICC_EOIR, val);
287}
288
Juan Castillo7f1f0622014-09-09 09:49:23 +0100289static inline void gicc_write_hppir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100290{
291 mmio_write_32(base + GICC_HPPIR, val);
292}
293
Juan Castillo7f1f0622014-09-09 09:49:23 +0100294static inline void gicc_write_dir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100295{
296 mmio_write_32(base + GICC_DIR, val);
297}
298
Achin Gupta191e86e2014-05-09 10:03:15 +0100299/*******************************************************************************
300 * Prototype of function to map an interrupt type to the interrupt line used to
301 * signal it.
302 ******************************************************************************/
303uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type);
304
Dan Handley930ee2e2014-04-17 17:48:52 +0100305#endif /*__ASSEMBLY__*/
306
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100307#endif /* __GIC_V2_H__ */