blob: 3a3d7aaa3c5421e73ddbacc2c6ca40a471b01975 [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
Varun Wadekarc6a11f62017-05-25 18:04:48 -070018#define GIC400_NUM_SPIS U(480)
19#define MAX_PPIS U(14)
20#define MAX_SGIS U(16)
Dan Handley930ee2e2014-04-17 17:48:52 +010021
Varun Wadekarc6a11f62017-05-25 18:04:48 -070022#define MIN_SGI_ID U(0)
23#define MIN_PPI_ID U(16)
24#define MIN_SPI_ID U(32)
Dan Handleyfb42b122014-06-20 09:43:15 +010025
Varun Wadekarc6a11f62017-05-25 18:04:48 -070026#define GRP0 U(0)
27#define GRP1 U(1)
28#define GIC_PRI_MASK U(0xff)
29#define GIC_HIGHEST_SEC_PRIORITY U(0)
30#define GIC_LOWEST_SEC_PRIORITY U(127)
31#define GIC_HIGHEST_NS_PRIORITY U(128)
32#define GIC_LOWEST_NS_PRIORITY U(254) /* 255 would disable an interrupt */
33#define GIC_SPURIOUS_INTERRUPT U(1023)
34#define GIC_TARGET_CPU_MASK U(0xff)
Dan Handley930ee2e2014-04-17 17:48:52 +010035
Varun Wadekarc6a11f62017-05-25 18:04:48 -070036#define ENABLE_GRP0 (U(1) << 0)
37#define ENABLE_GRP1 (U(1) << 1)
Dan Handley930ee2e2014-04-17 17:48:52 +010038
39/* Distributor interface definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070040#define GICD_CTLR U(0x0)
41#define GICD_TYPER U(0x4)
42#define GICD_IGROUPR U(0x80)
43#define GICD_ISENABLER U(0x100)
44#define GICD_ICENABLER U(0x180)
45#define GICD_ISPENDR U(0x200)
46#define GICD_ICPENDR U(0x280)
47#define GICD_ISACTIVER U(0x300)
48#define GICD_ICACTIVER U(0x380)
49#define GICD_IPRIORITYR U(0x400)
50#define GICD_ITARGETSR U(0x800)
51#define GICD_ICFGR U(0xC00)
52#define GICD_SGIR U(0xF00)
53#define GICD_CPENDSGIR U(0xF10)
54#define GICD_SPENDSGIR U(0xF20)
Dan Handley930ee2e2014-04-17 17:48:52 +010055
Varun Wadekarc6a11f62017-05-25 18:04:48 -070056#define IGROUPR_SHIFT U(5)
57#define ISENABLER_SHIFT U(5)
Dan Handley930ee2e2014-04-17 17:48:52 +010058#define ICENABLER_SHIFT ISENABLER_SHIFT
Varun Wadekarc6a11f62017-05-25 18:04:48 -070059#define ISPENDR_SHIFT U(5)
Dan Handley930ee2e2014-04-17 17:48:52 +010060#define ICPENDR_SHIFT ISPENDR_SHIFT
Varun Wadekarc6a11f62017-05-25 18:04:48 -070061#define ISACTIVER_SHIFT U(5)
Dan Handley930ee2e2014-04-17 17:48:52 +010062#define ICACTIVER_SHIFT ISACTIVER_SHIFT
Varun Wadekarc6a11f62017-05-25 18:04:48 -070063#define IPRIORITYR_SHIFT U(2)
64#define ITARGETSR_SHIFT U(2)
65#define ICFGR_SHIFT U(4)
66#define CPENDSGIR_SHIFT U(2)
Dan Handley930ee2e2014-04-17 17:48:52 +010067#define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
68
69/* GICD_TYPER bit definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070070#define IT_LINES_NO_MASK U(0x1f)
Dan Handley930ee2e2014-04-17 17:48:52 +010071
72/* Physical CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070073#define GICC_CTLR U(0x0)
74#define GICC_PMR U(0x4)
75#define GICC_BPR U(0x8)
76#define GICC_IAR U(0xC)
77#define GICC_EOIR U(0x10)
78#define GICC_RPR U(0x14)
79#define GICC_HPPIR U(0x18)
80#define GICC_AHPPIR U(0x28)
81#define GICC_IIDR U(0xFC)
82#define GICC_DIR U(0x1000)
Dan Handley930ee2e2014-04-17 17:48:52 +010083#define GICC_PRIODROP GICC_EOIR
84
Achin Gupta966b9522015-05-18 10:56:47 +010085/* Common CPU Interface definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070086#define INT_ID_MASK U(0x3ff)
Achin Gupta966b9522015-05-18 10:56:47 +010087
Dan Handley930ee2e2014-04-17 17:48:52 +010088/* GICC_CTLR bit definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070089#define EOI_MODE_NS (U(1) << 10)
90#define EOI_MODE_S (U(1) << 9)
91#define IRQ_BYP_DIS_GRP1 (U(1) << 8)
92#define FIQ_BYP_DIS_GRP1 (U(1) << 7)
93#define IRQ_BYP_DIS_GRP0 (U(1) << 6)
94#define FIQ_BYP_DIS_GRP0 (U(1) << 5)
95#define CBPR (U(1) << 4)
96#define FIQ_EN (U(1) << 3)
97#define ACK_CTL (U(1) << 2)
Dan Handley930ee2e2014-04-17 17:48:52 +010098
99/* GICC_IIDR bit masks and shifts */
Varun Wadekarc6a11f62017-05-25 18:04:48 -0700100#define GICC_IIDR_PID_SHIFT U(20)
101#define GICC_IIDR_ARCH_SHIFT U(16)
102#define GICC_IIDR_REV_SHIFT U(12)
103#define GICC_IIDR_IMP_SHIFT U(0)
Dan Handley930ee2e2014-04-17 17:48:52 +0100104
Varun Wadekarc6a11f62017-05-25 18:04:48 -0700105#define GICC_IIDR_PID_MASK U(0xfff)
106#define GICC_IIDR_ARCH_MASK U(0xf)
107#define GICC_IIDR_REV_MASK U(0xf)
108#define GICC_IIDR_IMP_MASK U(0xfff)
Dan Handley930ee2e2014-04-17 17:48:52 +0100109
110/* HYP view virtual CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -0700111#define GICH_CTL U(0x0)
112#define GICH_VTR U(0x4)
113#define GICH_ELRSR0 U(0x30)
114#define GICH_ELRSR1 U(0x34)
115#define GICH_APR0 U(0xF0)
116#define GICH_LR_BASE U(0x100)
Dan Handley930ee2e2014-04-17 17:48:52 +0100117
118/* Virtual CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -0700119#define GICV_CTL U(0x0)
120#define GICV_PRIMASK U(0x4)
121#define GICV_BP U(0x8)
122#define GICV_INTACK U(0xC)
123#define GICV_EOI U(0x10)
124#define GICV_RUNNINGPRI U(0x14)
125#define GICV_HIGHESTPEND U(0x18)
126#define GICV_DEACTIVATE U(0x1000)
Dan Handley930ee2e2014-04-17 17:48:52 +0100127
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__ */