blob: 594ce49918a6ce21882bc4a0a01190bc3edfc512 [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 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * Redistributions of source code must retain the above copyright notice, this
8 * list of conditions and the following disclaimer.
9 *
10 * Redistributions in binary form must reproduce the above copyright notice,
11 * this list of conditions and the following disclaimer in the documentation
12 * and/or other materials provided with the distribution.
13 *
14 * Neither the name of ARM nor the names of its contributors may be used
15 * to endorse or promote products derived from this software without specific
16 * prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
22 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28 * POSSIBILITY OF SUCH DAMAGE.
29 */
30
31#ifndef __GIC_V2_H__
32#define __GIC_V2_H__
33
Soby Mathew3ddc9722015-10-26 14:32:09 +000034/******************************************************************************
35 * THIS DRIVER IS DEPRECATED. For GICv2 systems, use the driver in gicv2.h
36 * and for GICv3 systems, use the driver in gicv3.h.
37 *****************************************************************************/
38#if ERROR_DEPRECATED
39#error " The legacy ARM GIC driver is deprecated."
40#endif
Dan Handley930ee2e2014-04-17 17:48:52 +010041
42#define GIC400_NUM_SPIS 480
43#define MAX_PPIS 14
44#define MAX_SGIS 16
45
Dan Handleyfb42b122014-06-20 09:43:15 +010046#define MIN_SGI_ID 0
47#define MIN_PPI_ID 16
48#define MIN_SPI_ID 32
49
Dan Handley930ee2e2014-04-17 17:48:52 +010050#define GRP0 0
51#define GRP1 1
52#define GIC_PRI_MASK 0xff
53#define GIC_HIGHEST_SEC_PRIORITY 0
54#define GIC_LOWEST_SEC_PRIORITY 127
55#define GIC_HIGHEST_NS_PRIORITY 128
56#define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */
Achin Gupta02d36282014-05-04 19:02:52 +010057#define GIC_SPURIOUS_INTERRUPT 1023
Juan Castillo82312952014-10-20 12:27:28 +010058#define GIC_TARGET_CPU_MASK 0xff
Dan Handley930ee2e2014-04-17 17:48:52 +010059
60#define ENABLE_GRP0 (1 << 0)
61#define ENABLE_GRP1 (1 << 1)
62
63/* Distributor interface definitions */
64#define GICD_CTLR 0x0
65#define GICD_TYPER 0x4
66#define GICD_IGROUPR 0x80
67#define GICD_ISENABLER 0x100
68#define GICD_ICENABLER 0x180
69#define GICD_ISPENDR 0x200
70#define GICD_ICPENDR 0x280
71#define GICD_ISACTIVER 0x300
72#define GICD_ICACTIVER 0x380
73#define GICD_IPRIORITYR 0x400
74#define GICD_ITARGETSR 0x800
75#define GICD_ICFGR 0xC00
76#define GICD_SGIR 0xF00
77#define GICD_CPENDSGIR 0xF10
78#define GICD_SPENDSGIR 0xF20
79
80#define IGROUPR_SHIFT 5
81#define ISENABLER_SHIFT 5
82#define ICENABLER_SHIFT ISENABLER_SHIFT
83#define ISPENDR_SHIFT 5
84#define ICPENDR_SHIFT ISPENDR_SHIFT
85#define ISACTIVER_SHIFT 5
86#define ICACTIVER_SHIFT ISACTIVER_SHIFT
87#define IPRIORITYR_SHIFT 2
88#define ITARGETSR_SHIFT 2
89#define ICFGR_SHIFT 4
90#define CPENDSGIR_SHIFT 2
91#define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
92
93/* GICD_TYPER bit definitions */
94#define IT_LINES_NO_MASK 0x1f
95
96/* Physical CPU Interface registers */
97#define GICC_CTLR 0x0
98#define GICC_PMR 0x4
99#define GICC_BPR 0x8
100#define GICC_IAR 0xC
101#define GICC_EOIR 0x10
102#define GICC_RPR 0x14
103#define GICC_HPPIR 0x18
Achin Gupta02d36282014-05-04 19:02:52 +0100104#define GICC_AHPPIR 0x28
Dan Handley930ee2e2014-04-17 17:48:52 +0100105#define GICC_IIDR 0xFC
106#define GICC_DIR 0x1000
107#define GICC_PRIODROP GICC_EOIR
108
Achin Gupta966b9522015-05-18 10:56:47 +0100109/* Common CPU Interface definitions */
110#define INT_ID_MASK 0x3ff
111
Dan Handley930ee2e2014-04-17 17:48:52 +0100112/* GICC_CTLR bit definitions */
113#define EOI_MODE_NS (1 << 10)
114#define EOI_MODE_S (1 << 9)
115#define IRQ_BYP_DIS_GRP1 (1 << 8)
116#define FIQ_BYP_DIS_GRP1 (1 << 7)
117#define IRQ_BYP_DIS_GRP0 (1 << 6)
118#define FIQ_BYP_DIS_GRP0 (1 << 5)
119#define CBPR (1 << 4)
120#define FIQ_EN (1 << 3)
121#define ACK_CTL (1 << 2)
122
123/* GICC_IIDR bit masks and shifts */
124#define GICC_IIDR_PID_SHIFT 20
125#define GICC_IIDR_ARCH_SHIFT 16
126#define GICC_IIDR_REV_SHIFT 12
127#define GICC_IIDR_IMP_SHIFT 0
128
129#define GICC_IIDR_PID_MASK 0xfff
130#define GICC_IIDR_ARCH_MASK 0xf
131#define GICC_IIDR_REV_MASK 0xf
132#define GICC_IIDR_IMP_MASK 0xfff
133
134/* HYP view virtual CPU Interface registers */
135#define GICH_CTL 0x0
136#define GICH_VTR 0x4
137#define GICH_ELRSR0 0x30
138#define GICH_ELRSR1 0x34
139#define GICH_APR0 0xF0
140#define GICH_LR_BASE 0x100
141
142/* Virtual CPU Interface registers */
143#define GICV_CTL 0x0
144#define GICV_PRIMASK 0x4
145#define GICV_BP 0x8
146#define GICV_INTACK 0xC
147#define GICV_EOI 0x10
148#define GICV_RUNNINGPRI 0x14
149#define GICV_HIGHESTPEND 0x18
150#define GICV_DEACTIVATE 0x1000
151
152#ifndef __ASSEMBLY__
153
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100154#include <mmio.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +0100155#include <stdint.h>
Dan Handley930ee2e2014-04-17 17:48:52 +0100156
157/*******************************************************************************
158 * GIC Distributor function prototypes
159 ******************************************************************************/
160
Juan Castillo7f1f0622014-09-09 09:49:23 +0100161unsigned int gicd_read_igroupr(uintptr_t, unsigned int);
162unsigned int gicd_read_isenabler(uintptr_t, unsigned int);
163unsigned int gicd_read_icenabler(uintptr_t, unsigned int);
164unsigned int gicd_read_ispendr(uintptr_t, unsigned int);
165unsigned int gicd_read_icpendr(uintptr_t, unsigned int);
166unsigned int gicd_read_isactiver(uintptr_t, unsigned int);
167unsigned int gicd_read_icactiver(uintptr_t, unsigned int);
168unsigned int gicd_read_ipriorityr(uintptr_t, unsigned int);
169unsigned int gicd_read_itargetsr(uintptr_t, unsigned int);
170unsigned int gicd_read_icfgr(uintptr_t, unsigned int);
171unsigned int gicd_read_cpendsgir(uintptr_t, unsigned int);
172unsigned int gicd_read_spendsgir(uintptr_t, unsigned int);
173void gicd_write_igroupr(uintptr_t, unsigned int, unsigned int);
174void gicd_write_isenabler(uintptr_t, unsigned int, unsigned int);
175void gicd_write_icenabler(uintptr_t, unsigned int, unsigned int);
176void gicd_write_ispendr(uintptr_t, unsigned int, unsigned int);
177void gicd_write_icpendr(uintptr_t, unsigned int, unsigned int);
178void gicd_write_isactiver(uintptr_t, unsigned int, unsigned int);
179void gicd_write_icactiver(uintptr_t, unsigned int, unsigned int);
180void gicd_write_ipriorityr(uintptr_t, unsigned int, unsigned int);
181void gicd_write_itargetsr(uintptr_t, unsigned int, unsigned int);
182void gicd_write_icfgr(uintptr_t, unsigned int, unsigned int);
183void gicd_write_cpendsgir(uintptr_t, unsigned int, unsigned int);
184void gicd_write_spendsgir(uintptr_t, unsigned int, unsigned int);
185unsigned int gicd_get_igroupr(uintptr_t, unsigned int);
186void gicd_set_igroupr(uintptr_t, unsigned int);
187void gicd_clr_igroupr(uintptr_t, unsigned int);
188void gicd_set_isenabler(uintptr_t, unsigned int);
189void gicd_set_icenabler(uintptr_t, unsigned int);
190void gicd_set_ispendr(uintptr_t, unsigned int);
191void gicd_set_icpendr(uintptr_t, unsigned int);
192void gicd_set_isactiver(uintptr_t, unsigned int);
193void gicd_set_icactiver(uintptr_t, unsigned int);
194void gicd_set_ipriorityr(uintptr_t, unsigned int, unsigned int);
195void gicd_set_itargetsr(uintptr_t, unsigned int, unsigned int);
Dan Handley930ee2e2014-04-17 17:48:52 +0100196
197
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100198/*******************************************************************************
199 * GIC Distributor interface accessors for reading entire registers
200 ******************************************************************************/
201
Juan Castillo7f1f0622014-09-09 09:49:23 +0100202static inline unsigned int gicd_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100203{
204 return mmio_read_32(base + GICD_CTLR);
205}
206
Juan Castillo7f1f0622014-09-09 09:49:23 +0100207static inline unsigned int gicd_read_typer(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100208{
209 return mmio_read_32(base + GICD_TYPER);
210}
211
Juan Castillo7f1f0622014-09-09 09:49:23 +0100212static inline unsigned int gicd_read_sgir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100213{
214 return mmio_read_32(base + GICD_SGIR);
215}
216
217
218/*******************************************************************************
219 * GIC Distributor interface accessors for writing entire registers
220 ******************************************************************************/
221
Juan Castillo7f1f0622014-09-09 09:49:23 +0100222static inline void gicd_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100223{
224 mmio_write_32(base + GICD_CTLR, val);
225}
226
Juan Castillo7f1f0622014-09-09 09:49:23 +0100227static inline void gicd_write_sgir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100228{
229 mmio_write_32(base + GICD_SGIR, val);
230}
231
232
233/*******************************************************************************
234 * GIC CPU interface accessors for reading entire registers
235 ******************************************************************************/
236
Juan Castillo7f1f0622014-09-09 09:49:23 +0100237static inline unsigned int gicc_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100238{
239 return mmio_read_32(base + GICC_CTLR);
240}
241
Juan Castillo7f1f0622014-09-09 09:49:23 +0100242static inline unsigned int gicc_read_pmr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100243{
244 return mmio_read_32(base + GICC_PMR);
245}
246
Juan Castillo7f1f0622014-09-09 09:49:23 +0100247static inline unsigned int gicc_read_BPR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100248{
249 return mmio_read_32(base + GICC_BPR);
250}
251
Juan Castillo7f1f0622014-09-09 09:49:23 +0100252static inline unsigned int gicc_read_IAR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100253{
254 return mmio_read_32(base + GICC_IAR);
255}
256
Juan Castillo7f1f0622014-09-09 09:49:23 +0100257static inline unsigned int gicc_read_EOIR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100258{
259 return mmio_read_32(base + GICC_EOIR);
260}
261
Juan Castillo7f1f0622014-09-09 09:49:23 +0100262static inline unsigned int gicc_read_hppir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100263{
264 return mmio_read_32(base + GICC_HPPIR);
265}
266
Juan Castillo7f1f0622014-09-09 09:49:23 +0100267static inline unsigned int gicc_read_ahppir(uintptr_t base)
Achin Gupta02d36282014-05-04 19:02:52 +0100268{
269 return mmio_read_32(base + GICC_AHPPIR);
270}
271
Juan Castillo7f1f0622014-09-09 09:49:23 +0100272static inline unsigned int gicc_read_dir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100273{
274 return mmio_read_32(base + GICC_DIR);
275}
276
Juan Castillo7f1f0622014-09-09 09:49:23 +0100277static inline unsigned int gicc_read_iidr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100278{
279 return mmio_read_32(base + GICC_IIDR);
280}
281
282
283/*******************************************************************************
284 * GIC CPU interface accessors for writing entire registers
285 ******************************************************************************/
286
Juan Castillo7f1f0622014-09-09 09:49:23 +0100287static inline void gicc_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100288{
289 mmio_write_32(base + GICC_CTLR, val);
290}
291
Juan Castillo7f1f0622014-09-09 09:49:23 +0100292static inline void gicc_write_pmr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100293{
294 mmio_write_32(base + GICC_PMR, val);
295}
296
Juan Castillo7f1f0622014-09-09 09:49:23 +0100297static inline void gicc_write_BPR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100298{
299 mmio_write_32(base + GICC_BPR, val);
300}
301
302
Juan Castillo7f1f0622014-09-09 09:49:23 +0100303static inline void gicc_write_IAR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100304{
305 mmio_write_32(base + GICC_IAR, val);
306}
307
Juan Castillo7f1f0622014-09-09 09:49:23 +0100308static inline void gicc_write_EOIR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100309{
310 mmio_write_32(base + GICC_EOIR, val);
311}
312
Juan Castillo7f1f0622014-09-09 09:49:23 +0100313static inline void gicc_write_hppir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100314{
315 mmio_write_32(base + GICC_HPPIR, val);
316}
317
Juan Castillo7f1f0622014-09-09 09:49:23 +0100318static inline void gicc_write_dir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100319{
320 mmio_write_32(base + GICC_DIR, val);
321}
322
Achin Gupta191e86e2014-05-09 10:03:15 +0100323/*******************************************************************************
324 * Prototype of function to map an interrupt type to the interrupt line used to
325 * signal it.
326 ******************************************************************************/
327uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type);
328
Dan Handley930ee2e2014-04-17 17:48:52 +0100329#endif /*__ASSEMBLY__*/
330
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100331#endif /* __GIC_V2_H__ */