blob: e81967638a6efdf025b4e538c3f25c87be987396 [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
Dan Handley930ee2e2014-04-17 17:48:52 +010034
35#define GIC400_NUM_SPIS 480
36#define MAX_PPIS 14
37#define MAX_SGIS 16
38
39#define GRP0 0
40#define GRP1 1
41#define GIC_PRI_MASK 0xff
42#define GIC_HIGHEST_SEC_PRIORITY 0
43#define GIC_LOWEST_SEC_PRIORITY 127
44#define GIC_HIGHEST_NS_PRIORITY 128
45#define GIC_LOWEST_NS_PRIORITY 254 /* 255 would disable an interrupt */
Achin Gupta02d36282014-05-04 19:02:52 +010046#define GIC_SPURIOUS_INTERRUPT 1023
Dan Handley930ee2e2014-04-17 17:48:52 +010047
48#define ENABLE_GRP0 (1 << 0)
49#define ENABLE_GRP1 (1 << 1)
50
51/* Distributor interface definitions */
52#define GICD_CTLR 0x0
53#define GICD_TYPER 0x4
54#define GICD_IGROUPR 0x80
55#define GICD_ISENABLER 0x100
56#define GICD_ICENABLER 0x180
57#define GICD_ISPENDR 0x200
58#define GICD_ICPENDR 0x280
59#define GICD_ISACTIVER 0x300
60#define GICD_ICACTIVER 0x380
61#define GICD_IPRIORITYR 0x400
62#define GICD_ITARGETSR 0x800
63#define GICD_ICFGR 0xC00
64#define GICD_SGIR 0xF00
65#define GICD_CPENDSGIR 0xF10
66#define GICD_SPENDSGIR 0xF20
67
68#define IGROUPR_SHIFT 5
69#define ISENABLER_SHIFT 5
70#define ICENABLER_SHIFT ISENABLER_SHIFT
71#define ISPENDR_SHIFT 5
72#define ICPENDR_SHIFT ISPENDR_SHIFT
73#define ISACTIVER_SHIFT 5
74#define ICACTIVER_SHIFT ISACTIVER_SHIFT
75#define IPRIORITYR_SHIFT 2
76#define ITARGETSR_SHIFT 2
77#define ICFGR_SHIFT 4
78#define CPENDSGIR_SHIFT 2
79#define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
80
81/* GICD_TYPER bit definitions */
82#define IT_LINES_NO_MASK 0x1f
83
84/* Physical CPU Interface registers */
85#define GICC_CTLR 0x0
86#define GICC_PMR 0x4
87#define GICC_BPR 0x8
88#define GICC_IAR 0xC
89#define GICC_EOIR 0x10
90#define GICC_RPR 0x14
91#define GICC_HPPIR 0x18
Achin Gupta02d36282014-05-04 19:02:52 +010092#define GICC_AHPPIR 0x28
Dan Handley930ee2e2014-04-17 17:48:52 +010093#define GICC_IIDR 0xFC
94#define GICC_DIR 0x1000
95#define GICC_PRIODROP GICC_EOIR
96
97/* GICC_CTLR bit definitions */
98#define EOI_MODE_NS (1 << 10)
99#define EOI_MODE_S (1 << 9)
100#define IRQ_BYP_DIS_GRP1 (1 << 8)
101#define FIQ_BYP_DIS_GRP1 (1 << 7)
102#define IRQ_BYP_DIS_GRP0 (1 << 6)
103#define FIQ_BYP_DIS_GRP0 (1 << 5)
104#define CBPR (1 << 4)
105#define FIQ_EN (1 << 3)
106#define ACK_CTL (1 << 2)
107
108/* GICC_IIDR bit masks and shifts */
109#define GICC_IIDR_PID_SHIFT 20
110#define GICC_IIDR_ARCH_SHIFT 16
111#define GICC_IIDR_REV_SHIFT 12
112#define GICC_IIDR_IMP_SHIFT 0
113
114#define GICC_IIDR_PID_MASK 0xfff
115#define GICC_IIDR_ARCH_MASK 0xf
116#define GICC_IIDR_REV_MASK 0xf
117#define GICC_IIDR_IMP_MASK 0xfff
118
119/* HYP view virtual CPU Interface registers */
120#define GICH_CTL 0x0
121#define GICH_VTR 0x4
122#define GICH_ELRSR0 0x30
123#define GICH_ELRSR1 0x34
124#define GICH_APR0 0xF0
125#define GICH_LR_BASE 0x100
126
127/* Virtual CPU Interface registers */
128#define GICV_CTL 0x0
129#define GICV_PRIMASK 0x4
130#define GICV_BP 0x8
131#define GICV_INTACK 0xC
132#define GICV_EOI 0x10
133#define GICV_RUNNINGPRI 0x14
134#define GICV_HIGHESTPEND 0x18
135#define GICV_DEACTIVATE 0x1000
136
137#ifndef __ASSEMBLY__
138
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100139#include <mmio.h>
140
Dan Handley930ee2e2014-04-17 17:48:52 +0100141
142/*******************************************************************************
143 * GIC Distributor function prototypes
144 ******************************************************************************/
145
146extern unsigned int gicd_read_igroupr(unsigned int, unsigned int);
147extern unsigned int gicd_read_isenabler(unsigned int, unsigned int);
148extern unsigned int gicd_read_icenabler(unsigned int, unsigned int);
149extern unsigned int gicd_read_ispendr(unsigned int, unsigned int);
150extern unsigned int gicd_read_icpendr(unsigned int, unsigned int);
151extern unsigned int gicd_read_isactiver(unsigned int, unsigned int);
152extern unsigned int gicd_read_icactiver(unsigned int, unsigned int);
153extern unsigned int gicd_read_ipriorityr(unsigned int, unsigned int);
154extern unsigned int gicd_read_itargetsr(unsigned int, unsigned int);
155extern unsigned int gicd_read_icfgr(unsigned int, unsigned int);
156extern unsigned int gicd_read_cpendsgir(unsigned int, unsigned int);
157extern unsigned int gicd_read_spendsgir(unsigned int, unsigned int);
158extern void gicd_write_igroupr(unsigned int, unsigned int, unsigned int);
159extern void gicd_write_isenabler(unsigned int, unsigned int, unsigned int);
160extern void gicd_write_icenabler(unsigned int, unsigned int, unsigned int);
161extern void gicd_write_ispendr(unsigned int, unsigned int, unsigned int);
162extern void gicd_write_icpendr(unsigned int, unsigned int, unsigned int);
163extern void gicd_write_isactiver(unsigned int, unsigned int, unsigned int);
164extern void gicd_write_icactiver(unsigned int, unsigned int, unsigned int);
165extern void gicd_write_ipriorityr(unsigned int, unsigned int, unsigned int);
166extern void gicd_write_itargetsr(unsigned int, unsigned int, unsigned int);
167extern void gicd_write_icfgr(unsigned int, unsigned int, unsigned int);
168extern void gicd_write_cpendsgir(unsigned int, unsigned int, unsigned int);
169extern void gicd_write_spendsgir(unsigned int, unsigned int, unsigned int);
170extern unsigned int gicd_get_igroupr(unsigned int, unsigned int);
171extern void gicd_set_igroupr(unsigned int, unsigned int);
172extern void gicd_clr_igroupr(unsigned int, unsigned int);
173extern void gicd_set_isenabler(unsigned int, unsigned int);
174extern void gicd_set_icenabler(unsigned int, unsigned int);
175extern void gicd_set_ispendr(unsigned int, unsigned int);
176extern void gicd_set_icpendr(unsigned int, unsigned int);
177extern void gicd_set_isactiver(unsigned int, unsigned int);
178extern void gicd_set_icactiver(unsigned int, unsigned int);
179extern void gicd_set_ipriorityr(unsigned int, unsigned int, unsigned int);
180extern void gicd_set_itargetsr(unsigned int, unsigned int, unsigned int);
181
182
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100183/*******************************************************************************
184 * GIC Distributor interface accessors for reading entire registers
185 ******************************************************************************/
186
187static inline unsigned int gicd_read_ctlr(unsigned int base)
188{
189 return mmio_read_32(base + GICD_CTLR);
190}
191
192static inline unsigned int gicd_read_typer(unsigned int base)
193{
194 return mmio_read_32(base + GICD_TYPER);
195}
196
197static inline unsigned int gicd_read_sgir(unsigned int base)
198{
199 return mmio_read_32(base + GICD_SGIR);
200}
201
202
203/*******************************************************************************
204 * GIC Distributor interface accessors for writing entire registers
205 ******************************************************************************/
206
207static inline void gicd_write_ctlr(unsigned int base, unsigned int val)
208{
209 mmio_write_32(base + GICD_CTLR, val);
210}
211
212static inline void gicd_write_sgir(unsigned int base, unsigned int val)
213{
214 mmio_write_32(base + GICD_SGIR, val);
215}
216
217
218/*******************************************************************************
219 * GIC CPU interface accessors for reading entire registers
220 ******************************************************************************/
221
222static inline unsigned int gicc_read_ctlr(unsigned int base)
223{
224 return mmio_read_32(base + GICC_CTLR);
225}
226
227static inline unsigned int gicc_read_pmr(unsigned int base)
228{
229 return mmio_read_32(base + GICC_PMR);
230}
231
232static inline unsigned int gicc_read_BPR(unsigned int base)
233{
234 return mmio_read_32(base + GICC_BPR);
235}
236
237static inline unsigned int gicc_read_IAR(unsigned int base)
238{
239 return mmio_read_32(base + GICC_IAR);
240}
241
242static inline unsigned int gicc_read_EOIR(unsigned int base)
243{
244 return mmio_read_32(base + GICC_EOIR);
245}
246
247static inline unsigned int gicc_read_hppir(unsigned int base)
248{
249 return mmio_read_32(base + GICC_HPPIR);
250}
251
Achin Gupta02d36282014-05-04 19:02:52 +0100252static inline unsigned int gicc_read_ahppir(unsigned int base)
253{
254 return mmio_read_32(base + GICC_AHPPIR);
255}
256
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100257static inline unsigned int gicc_read_dir(unsigned int base)
258{
259 return mmio_read_32(base + GICC_DIR);
260}
261
262static inline unsigned int gicc_read_iidr(unsigned int base)
263{
264 return mmio_read_32(base + GICC_IIDR);
265}
266
267
268/*******************************************************************************
269 * GIC CPU interface accessors for writing entire registers
270 ******************************************************************************/
271
272static inline void gicc_write_ctlr(unsigned int base, unsigned int val)
273{
274 mmio_write_32(base + GICC_CTLR, val);
275}
276
277static inline void gicc_write_pmr(unsigned int base, unsigned int val)
278{
279 mmio_write_32(base + GICC_PMR, val);
280}
281
282static inline void gicc_write_BPR(unsigned int base, unsigned int val)
283{
284 mmio_write_32(base + GICC_BPR, val);
285}
286
287
288static inline void gicc_write_IAR(unsigned int base, unsigned int val)
289{
290 mmio_write_32(base + GICC_IAR, val);
291}
292
293static inline void gicc_write_EOIR(unsigned int base, unsigned int val)
294{
295 mmio_write_32(base + GICC_EOIR, val);
296}
297
298static inline void gicc_write_hppir(unsigned int base, unsigned int val)
299{
300 mmio_write_32(base + GICC_HPPIR, val);
301}
302
303static inline void gicc_write_dir(unsigned int base, unsigned int val)
304{
305 mmio_write_32(base + GICC_DIR, val);
306}
307
Achin Gupta191e86e2014-05-09 10:03:15 +0100308/*******************************************************************************
309 * Prototype of function to map an interrupt type to the interrupt line used to
310 * signal it.
311 ******************************************************************************/
312uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type);
313
Dan Handley930ee2e2014-04-17 17:48:52 +0100314#endif /*__ASSEMBLY__*/
315
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100316#endif /* __GIC_V2_H__ */