blob: 258b898120de5028593324ad9de987eb48cc638f [file] [log] [blame]
Sandrine Bailleux27866d82013-10-25 15:33:39 +01001/*
Jeenu Viswambharan723dce02017-09-22 08:59:59 +01002 * Copyright (c) 2013-2017, 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
Jeenu Viswambharan723dce02017-09-22 08:59:59 +010010/* The macros required here are additional to those in gic_common.h. */
11#include <gic_common.h>
12
Soby Mathew3ddc9722015-10-26 14:32:09 +000013/******************************************************************************
14 * THIS DRIVER IS DEPRECATED. For GICv2 systems, use the driver in gicv2.h
15 * and for GICv3 systems, use the driver in gicv3.h.
16 *****************************************************************************/
17#if ERROR_DEPRECATED
18#error " The legacy ARM GIC driver is deprecated."
19#endif
Dan Handley930ee2e2014-04-17 17:48:52 +010020
Varun Wadekarc6a11f62017-05-25 18:04:48 -070021#define GIC400_NUM_SPIS U(480)
22#define MAX_PPIS U(14)
23#define MAX_SGIS U(16)
Dan Handley930ee2e2014-04-17 17:48:52 +010024
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)
Varun Wadekarc6a11f62017-05-25 18:04:48 -070028#define GIC_TARGET_CPU_MASK U(0xff)
Dan Handley930ee2e2014-04-17 17:48:52 +010029
Varun Wadekarc6a11f62017-05-25 18:04:48 -070030#define ENABLE_GRP0 (U(1) << 0)
31#define ENABLE_GRP1 (U(1) << 1)
Dan Handley930ee2e2014-04-17 17:48:52 +010032
33/* Distributor interface definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070034#define GICD_ITARGETSR U(0x800)
Varun Wadekarc6a11f62017-05-25 18:04:48 -070035#define GICD_SGIR U(0xF00)
36#define GICD_CPENDSGIR U(0xF10)
37#define GICD_SPENDSGIR U(0xF20)
Dan Handley930ee2e2014-04-17 17:48:52 +010038
Varun Wadekarc6a11f62017-05-25 18:04:48 -070039#define CPENDSGIR_SHIFT U(2)
Dan Handley930ee2e2014-04-17 17:48:52 +010040#define SPENDSGIR_SHIFT CPENDSGIR_SHIFT
41
42/* GICD_TYPER bit definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070043#define IT_LINES_NO_MASK U(0x1f)
Dan Handley930ee2e2014-04-17 17:48:52 +010044
45/* Physical CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070046#define GICC_CTLR U(0x0)
47#define GICC_PMR U(0x4)
48#define GICC_BPR U(0x8)
49#define GICC_IAR U(0xC)
50#define GICC_EOIR U(0x10)
51#define GICC_RPR U(0x14)
52#define GICC_HPPIR U(0x18)
53#define GICC_AHPPIR U(0x28)
54#define GICC_IIDR U(0xFC)
55#define GICC_DIR U(0x1000)
Dan Handley930ee2e2014-04-17 17:48:52 +010056#define GICC_PRIODROP GICC_EOIR
57
Achin Gupta966b9522015-05-18 10:56:47 +010058/* Common CPU Interface definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070059#define INT_ID_MASK U(0x3ff)
Achin Gupta966b9522015-05-18 10:56:47 +010060
Dan Handley930ee2e2014-04-17 17:48:52 +010061/* GICC_CTLR bit definitions */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070062#define EOI_MODE_NS (U(1) << 10)
63#define EOI_MODE_S (U(1) << 9)
64#define IRQ_BYP_DIS_GRP1 (U(1) << 8)
65#define FIQ_BYP_DIS_GRP1 (U(1) << 7)
66#define IRQ_BYP_DIS_GRP0 (U(1) << 6)
67#define FIQ_BYP_DIS_GRP0 (U(1) << 5)
68#define CBPR (U(1) << 4)
69#define FIQ_EN (U(1) << 3)
70#define ACK_CTL (U(1) << 2)
Dan Handley930ee2e2014-04-17 17:48:52 +010071
72/* GICC_IIDR bit masks and shifts */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070073#define GICC_IIDR_PID_SHIFT U(20)
74#define GICC_IIDR_ARCH_SHIFT U(16)
75#define GICC_IIDR_REV_SHIFT U(12)
76#define GICC_IIDR_IMP_SHIFT U(0)
Dan Handley930ee2e2014-04-17 17:48:52 +010077
Varun Wadekarc6a11f62017-05-25 18:04:48 -070078#define GICC_IIDR_PID_MASK U(0xfff)
79#define GICC_IIDR_ARCH_MASK U(0xf)
80#define GICC_IIDR_REV_MASK U(0xf)
81#define GICC_IIDR_IMP_MASK U(0xfff)
Dan Handley930ee2e2014-04-17 17:48:52 +010082
83/* HYP view virtual CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070084#define GICH_CTL U(0x0)
85#define GICH_VTR U(0x4)
86#define GICH_ELRSR0 U(0x30)
87#define GICH_ELRSR1 U(0x34)
88#define GICH_APR0 U(0xF0)
89#define GICH_LR_BASE U(0x100)
Dan Handley930ee2e2014-04-17 17:48:52 +010090
91/* Virtual CPU Interface registers */
Varun Wadekarc6a11f62017-05-25 18:04:48 -070092#define GICV_CTL U(0x0)
93#define GICV_PRIMASK U(0x4)
94#define GICV_BP U(0x8)
95#define GICV_INTACK U(0xC)
96#define GICV_EOI U(0x10)
97#define GICV_RUNNINGPRI U(0x14)
98#define GICV_HIGHESTPEND U(0x18)
99#define GICV_DEACTIVATE U(0x1000)
Dan Handley930ee2e2014-04-17 17:48:52 +0100100
101#ifndef __ASSEMBLY__
102
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100103#include <mmio.h>
Juan Castillo7f1f0622014-09-09 09:49:23 +0100104#include <stdint.h>
Dan Handley930ee2e2014-04-17 17:48:52 +0100105
106/*******************************************************************************
107 * GIC Distributor function prototypes
108 ******************************************************************************/
109
Juan Castillo7f1f0622014-09-09 09:49:23 +0100110unsigned int gicd_read_igroupr(uintptr_t, unsigned int);
111unsigned int gicd_read_isenabler(uintptr_t, unsigned int);
112unsigned int gicd_read_icenabler(uintptr_t, unsigned int);
113unsigned int gicd_read_ispendr(uintptr_t, unsigned int);
114unsigned int gicd_read_icpendr(uintptr_t, unsigned int);
115unsigned int gicd_read_isactiver(uintptr_t, unsigned int);
116unsigned int gicd_read_icactiver(uintptr_t, unsigned int);
117unsigned int gicd_read_ipriorityr(uintptr_t, unsigned int);
118unsigned int gicd_read_itargetsr(uintptr_t, unsigned int);
119unsigned int gicd_read_icfgr(uintptr_t, unsigned int);
120unsigned int gicd_read_cpendsgir(uintptr_t, unsigned int);
121unsigned int gicd_read_spendsgir(uintptr_t, unsigned int);
122void gicd_write_igroupr(uintptr_t, unsigned int, unsigned int);
123void gicd_write_isenabler(uintptr_t, unsigned int, unsigned int);
124void gicd_write_icenabler(uintptr_t, unsigned int, unsigned int);
125void gicd_write_ispendr(uintptr_t, unsigned int, unsigned int);
126void gicd_write_icpendr(uintptr_t, unsigned int, unsigned int);
127void gicd_write_isactiver(uintptr_t, unsigned int, unsigned int);
128void gicd_write_icactiver(uintptr_t, unsigned int, unsigned int);
129void gicd_write_ipriorityr(uintptr_t, unsigned int, unsigned int);
130void gicd_write_itargetsr(uintptr_t, unsigned int, unsigned int);
131void gicd_write_icfgr(uintptr_t, unsigned int, unsigned int);
132void gicd_write_cpendsgir(uintptr_t, unsigned int, unsigned int);
133void gicd_write_spendsgir(uintptr_t, unsigned int, unsigned int);
134unsigned int gicd_get_igroupr(uintptr_t, unsigned int);
135void gicd_set_igroupr(uintptr_t, unsigned int);
136void gicd_clr_igroupr(uintptr_t, unsigned int);
137void gicd_set_isenabler(uintptr_t, unsigned int);
138void gicd_set_icenabler(uintptr_t, unsigned int);
139void gicd_set_ispendr(uintptr_t, unsigned int);
140void gicd_set_icpendr(uintptr_t, unsigned int);
141void gicd_set_isactiver(uintptr_t, unsigned int);
142void gicd_set_icactiver(uintptr_t, unsigned int);
143void gicd_set_ipriorityr(uintptr_t, unsigned int, unsigned int);
144void gicd_set_itargetsr(uintptr_t, unsigned int, unsigned int);
Dan Handley930ee2e2014-04-17 17:48:52 +0100145
146
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100147/*******************************************************************************
148 * GIC Distributor interface accessors for reading entire registers
149 ******************************************************************************/
150
Juan Castillo7f1f0622014-09-09 09:49:23 +0100151static inline unsigned int gicd_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100152{
153 return mmio_read_32(base + GICD_CTLR);
154}
155
Juan Castillo7f1f0622014-09-09 09:49:23 +0100156static inline unsigned int gicd_read_typer(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100157{
158 return mmio_read_32(base + GICD_TYPER);
159}
160
Juan Castillo7f1f0622014-09-09 09:49:23 +0100161static inline unsigned int gicd_read_sgir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100162{
163 return mmio_read_32(base + GICD_SGIR);
164}
165
166
167/*******************************************************************************
168 * GIC Distributor interface accessors for writing entire registers
169 ******************************************************************************/
170
Juan Castillo7f1f0622014-09-09 09:49:23 +0100171static inline void gicd_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100172{
173 mmio_write_32(base + GICD_CTLR, val);
174}
175
Juan Castillo7f1f0622014-09-09 09:49:23 +0100176static inline void gicd_write_sgir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100177{
178 mmio_write_32(base + GICD_SGIR, val);
179}
180
181
182/*******************************************************************************
183 * GIC CPU interface accessors for reading entire registers
184 ******************************************************************************/
185
Juan Castillo7f1f0622014-09-09 09:49:23 +0100186static inline unsigned int gicc_read_ctlr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100187{
188 return mmio_read_32(base + GICC_CTLR);
189}
190
Juan Castillo7f1f0622014-09-09 09:49:23 +0100191static inline unsigned int gicc_read_pmr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100192{
193 return mmio_read_32(base + GICC_PMR);
194}
195
Juan Castillo7f1f0622014-09-09 09:49:23 +0100196static inline unsigned int gicc_read_BPR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100197{
198 return mmio_read_32(base + GICC_BPR);
199}
200
Juan Castillo7f1f0622014-09-09 09:49:23 +0100201static inline unsigned int gicc_read_IAR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100202{
203 return mmio_read_32(base + GICC_IAR);
204}
205
Juan Castillo7f1f0622014-09-09 09:49:23 +0100206static inline unsigned int gicc_read_EOIR(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100207{
208 return mmio_read_32(base + GICC_EOIR);
209}
210
Juan Castillo7f1f0622014-09-09 09:49:23 +0100211static inline unsigned int gicc_read_hppir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100212{
213 return mmio_read_32(base + GICC_HPPIR);
214}
215
Juan Castillo7f1f0622014-09-09 09:49:23 +0100216static inline unsigned int gicc_read_ahppir(uintptr_t base)
Achin Gupta02d36282014-05-04 19:02:52 +0100217{
218 return mmio_read_32(base + GICC_AHPPIR);
219}
220
Juan Castillo7f1f0622014-09-09 09:49:23 +0100221static inline unsigned int gicc_read_dir(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100222{
223 return mmio_read_32(base + GICC_DIR);
224}
225
Juan Castillo7f1f0622014-09-09 09:49:23 +0100226static inline unsigned int gicc_read_iidr(uintptr_t base)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100227{
228 return mmio_read_32(base + GICC_IIDR);
229}
230
231
232/*******************************************************************************
233 * GIC CPU interface accessors for writing entire registers
234 ******************************************************************************/
235
Juan Castillo7f1f0622014-09-09 09:49:23 +0100236static inline void gicc_write_ctlr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100237{
238 mmio_write_32(base + GICC_CTLR, val);
239}
240
Juan Castillo7f1f0622014-09-09 09:49:23 +0100241static inline void gicc_write_pmr(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100242{
243 mmio_write_32(base + GICC_PMR, val);
244}
245
Juan Castillo7f1f0622014-09-09 09:49:23 +0100246static inline void gicc_write_BPR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100247{
248 mmio_write_32(base + GICC_BPR, val);
249}
250
251
Juan Castillo7f1f0622014-09-09 09:49:23 +0100252static inline void gicc_write_IAR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100253{
254 mmio_write_32(base + GICC_IAR, val);
255}
256
Juan Castillo7f1f0622014-09-09 09:49:23 +0100257static inline void gicc_write_EOIR(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100258{
259 mmio_write_32(base + GICC_EOIR, val);
260}
261
Juan Castillo7f1f0622014-09-09 09:49:23 +0100262static inline void gicc_write_hppir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100263{
264 mmio_write_32(base + GICC_HPPIR, val);
265}
266
Juan Castillo7f1f0622014-09-09 09:49:23 +0100267static inline void gicc_write_dir(uintptr_t base, unsigned int val)
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100268{
269 mmio_write_32(base + GICC_DIR, val);
270}
271
Achin Gupta191e86e2014-05-09 10:03:15 +0100272/*******************************************************************************
273 * Prototype of function to map an interrupt type to the interrupt line used to
274 * signal it.
275 ******************************************************************************/
276uint32_t gicv2_interrupt_type_to_line(uint32_t cpuif_base, uint32_t type);
277
Dan Handley930ee2e2014-04-17 17:48:52 +0100278#endif /*__ASSEMBLY__*/
279
Sandrine Bailleux27866d82013-10-25 15:33:39 +0100280#endif /* __GIC_V2_H__ */