Zephyr API Documentation 4.1.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
gic.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2019 Stephanos Ioannidis <root@stephanos.io>
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
16#ifndef ZEPHYR_INCLUDE_DRIVERS_GIC_H_
17#define ZEPHYR_INCLUDE_DRIVERS_GIC_H_
18
19/*
20 * GIC Register Interface Base Addresses
21 */
22
23#define GIC_DIST_BASE DT_REG_ADDR_BY_IDX(DT_INST(0, arm_gic), 0)
24#define GIC_CPU_BASE DT_REG_ADDR_BY_IDX(DT_INST(0, arm_gic), 1)
25
26/*
27 * GIC Distributor Interface
28 */
29
30/*
31 * 0x000 Distributor Control Register
32 * v1 ICDDCR
33 * v2/v3 GICD_CTLR
34 */
35#define GICD_CTLR (GIC_DIST_BASE + 0x0)
36
37/*
38 * 0x004 Interrupt Controller Type Register
39 * v1 ICDICTR
40 * v2/v3 GICD_TYPER
41 */
42#define GICD_TYPER (GIC_DIST_BASE + 0x4)
43
44/*
45 * 0x008 Distributor Implementer Identification Register
46 * v1 ICDIIDR
47 * v2/v3 GICD_IIDR
48 */
49#define GICD_IIDR (GIC_DIST_BASE + 0x8)
50
51/*
52 * 0x080 Interrupt Group Registers
53 * v1 ICDISRn
54 * v2/v3 GICD_IGROUPRn
55 */
56#define GICD_IGROUPRn (GIC_DIST_BASE + 0x80)
57
58/*
59 * 0x1000 Interrupt Group Registers for Extended SPI Range
60 * v3.1 GICD_IGROUPRnE
61 */
62#define GICD_IGROUPRnE (GIC_DIST_BASE + 0x1000)
63
64/*
65 * 0x100 Interrupt Set-Enable Registers
66 * v1 ICDISERn
67 * v2/v3 GICD_ISENABLERn
68 */
69#define GICD_ISENABLERn (GIC_DIST_BASE + 0x100)
70
71/*
72 * 0x1200 Interrupt Set-Enable Registers for Extended SPI Range
73 * v3.1 GICD_ISENABLERnE
74 */
75#define GICD_ISENABLERnE (GIC_DIST_BASE + 0x1200)
76
77/*
78 * 0x180 Interrupt Clear-Enable Registers
79 * v1 ICDICERn
80 * v2/v3 GICD_ICENABLERn
81 */
82#define GICD_ICENABLERn (GIC_DIST_BASE + 0x180)
83
84/*
85 * 0x1400 Interrupt Clear-Enable Registers for Extended SPI Range
86 * v3.1 GICD_ICENABLERnE
87 */
88#define GICD_ICENABLERnE (GIC_DIST_BASE + 0x1400)
89
90/*
91 * 0x200 Interrupt Set-Pending Registers
92 * v1 ICDISPRn
93 * v2/v3 GICD_ISPENDRn
94 */
95#define GICD_ISPENDRn (GIC_DIST_BASE + 0x200)
96
97/*
98 * 1600 Interrupt Set-Pending Registers for Extended SPI Range
99 * v3.1 GICD_ISPENDRnE
100 */
101#define GICD_ISPENDRnE (GIC_DIST_BASE + 0x1600)
102
103/*
104 * 0x280 Interrupt Clear-Pending Registers
105 * v1 ICDICPRn
106 * v2/v3 GICD_ICPENDRn
107 */
108#define GICD_ICPENDRn (GIC_DIST_BASE + 0x280)
109
110/*
111 * 0x1800 Interrupt Clear-Pending Registers for Extended SPI Range
112 * v3.1 GICD_ICPENDRnE
113 */
114#define GICD_ICPENDRnE (GIC_DIST_BASE + 0x1800)
115
116/*
117 * 0x300 Interrupt Set-Active Registers
118 * v1 ICDABRn
119 * v2/v3 GICD_ISACTIVERn
120 */
121#define GICD_ISACTIVERn (GIC_DIST_BASE + 0x300)
122
123/*
124 * 0x1A00 Interrupt Set-Active Registers for Extended SPI Range
125 * v3.1 GICD_ISACTIVERnE
126 */
127#define GICD_ISACTIVERnE (GIC_DIST_BASE + 0x1A00)
128
129#if CONFIG_GIC_VER >= 2
130/*
131 * 0x380 Interrupt Clear-Active Registers
132 * v2/v3 GICD_ICACTIVERn
133 */
134#define GICD_ICACTIVERn (GIC_DIST_BASE + 0x380)
135
136/*
137 * 0x1C00 Interrupt Clear-Active Registers for Extended SPI Range
138 * v3.1 GICD_ICACTIVERnE
139 */
140#define GICD_ICACTIVERnE (GIC_DIST_BASE + 0x1C00)
141#endif
142
143/*
144 * 0x400 Interrupt Priority Registers
145 * v1 ICDIPRn
146 * v2/v3 GICD_IPRIORITYRn
147 */
148#define GICD_IPRIORITYRn (GIC_DIST_BASE + 0x400)
149
150/*
151 * 0x2000 Interrupt Priority Registers for Extended SPI Range
152 * v3.1 GICD_IPRIORITYRnE
153 */
154#define GICD_IPRIORITYRnE (GIC_DIST_BASE + 0x2000)
155
156/*
157 * 0x800 Interrupt Processor Targets Registers
158 * v1 ICDIPTRn
159 * v2/v3 GICD_ITARGETSRn
160 */
161#define GICD_ITARGETSRn (GIC_DIST_BASE + 0x800)
162
163/*
164 * 0xC00 Interrupt Configuration Registers
165 * v1 ICDICRn
166 * v2/v3 GICD_ICFGRn
167 */
168#define GICD_ICFGRn (GIC_DIST_BASE + 0xc00)
169
170/*
171 * 0x3000 Interrupt Configuration Registers for Extended SPI Range
172 * v3.1 GICD_ICFGRnE
173 */
174#define GICD_ICFGRnE (GIC_DIST_BASE + 0x3000)
175
176/*
177 * 0xF00 Software Generated Interrupt Register
178 * v1 ICDSGIR
179 * v2/v3 GICD_SGIR
180 */
181#define GICD_SGIR (GIC_DIST_BASE + 0xf00)
182
183/*
184 * GIC CPU Interface
185 */
186
187#if CONFIG_GIC_VER <= 2
188
189/*
190 * 0x0000 CPU Interface Control Register
191 * v1 ICCICR
192 * v2/v3 GICC_CTLR
193 */
194#define GICC_CTLR (GIC_CPU_BASE + 0x0)
195
196/*
197 * 0x0004 Interrupt Priority Mask Register
198 * v1 ICCPMR
199 * v2/v3 GICC_PMR
200 */
201#define GICC_PMR (GIC_CPU_BASE + 0x4)
202
203/*
204 * 0x0008 Binary Point Register
205 * v1 ICCBPR
206 * v2/v3 GICC_BPR
207 */
208#define GICC_BPR (GIC_CPU_BASE + 0x8)
209
210/*
211 * 0x000C Interrupt Acknowledge Register
212 * v1 ICCIAR
213 * v2/v3 GICC_IAR
214 */
215#define GICC_IAR (GIC_CPU_BASE + 0xc)
216
217/*
218 * 0x0010 End of Interrupt Register
219 * v1 ICCEOIR
220 * v2/v3 GICC_EOIR
221 */
222#define GICC_EOIR (GIC_CPU_BASE + 0x10)
223
224/*
225 * Helper Constants
226 */
227
228/* GICC_CTLR */
229#define GICC_CTLR_ENABLEGRP0 BIT(0)
230#define GICC_CTLR_ENABLEGRP1 BIT(1)
231
232#define GICC_CTLR_ENABLE_MASK (GICC_CTLR_ENABLEGRP0 | GICC_CTLR_ENABLEGRP1)
233
234#if defined(CONFIG_GIC_V2)
235
236#define GICC_CTLR_FIQBYPDISGRP0 BIT(5)
237#define GICC_CTLR_IRQBYPDISGRP0 BIT(6)
238#define GICC_CTLR_FIQBYPDISGRP1 BIT(7)
239#define GICC_CTLR_IRQBYPDISGRP1 BIT(8)
240
241#define GICC_CTLR_BYPASS_MASK \
242 (GICC_CTLR_FIQBYPDISGRP0 | GICC_CTLR_IRQBYPDISGRP1 | GICC_CTLR_FIQBYPDISGRP1 | \
243 GICC_CTLR_IRQBYPDISGRP1)
244
245#endif /* CONFIG_GIC_V2 */
246
247/* GICD_SGIR */
248#define GICD_SGIR_TGTFILT(x) ((x) << 24)
249#define GICD_SGIR_TGTFILT_CPULIST GICD_SGIR_TGTFILT(0b00)
250#define GICD_SGIR_TGTFILT_ALLBUTREQ GICD_SGIR_TGTFILT(0b01)
251#define GICD_SGIR_TGTFILT_REQONLY GICD_SGIR_TGTFILT(0b10)
252
253#define GICD_SGIR_CPULIST(x) ((x) << 16)
254#define GICD_SGIR_CPULIST_CPU(n) GICD_SGIR_CPULIST(BIT(n))
255#define GICD_SGIR_CPULIST_MASK 0xff
256
257#define GICD_SGIR_NSATT BIT(15)
258
259#define GICD_SGIR_SGIINTID(x) (x)
260
261#endif /* CONFIG_GIC_VER <= 2 */
262
263/* GICD_ICFGR */
264#define GICD_ICFGR_MASK BIT_MASK(2)
265#define GICD_ICFGR_TYPE BIT(1)
266
267/* GICD_TYPER.ITLinesNumber 0:4 */
268#define GICD_TYPER_ITLINESNUM_MASK 0x1f
269
270/* GICD_TYPER.ESPI [8] */
271#define GICD_TYPER_ESPI_MASK BIT(8)
272
273/* GICD_TYPER.IDbits */
274#define GICD_TYPER_IDBITS(typer) ((((typer) >> 19) & 0x1f) + 1)
275
276/*
277 * Common Helper Constants
278 */
279#define GIC_SGI_INT_BASE 0
280#define GIC_PPI_INT_BASE 16
281
282#define GIC_IS_SGI(intid) (((intid) >= GIC_SGI_INT_BASE) && ((intid) < GIC_PPI_INT_BASE))
283
284#define GIC_SPI_INT_BASE 32
285
286#define GIC_SPI_MAX_INTID 1019
287
288#define GIC_IS_SPI(intid) (((intid) >= GIC_SPI_INT_BASE) && ((intid) <= GIC_SPI_MAX_INTID))
289
290#define GIC_NUM_INTR_PER_REG 32
291
292#define GIC_NUM_CFG_PER_REG 16
293
294#define GIC_NUM_PRI_PER_REG 4
295
296/* GIC idle priority : value '0xff' will allow all interrupts */
297#define GIC_IDLE_PRIO 0xff
298
299/* Priority levels 0:255 */
300#define GIC_PRI_MASK 0xff
301
302/*
303 * '0xa0'is used to initialize each interrupt default priority.
304 * This is an arbitrary value in current context.
305 * Any value '0x80' to '0xff' will work for both NS and S state.
306 * The values of individual interrupt and default has to be chosen
307 * carefully if PMR and BPR based nesting and preemption has to be done.
308 */
309#define GIC_INT_DEF_PRI_X4 0xa0a0a0a0
310
311/* GIC special interrupt id */
312#define GIC_INTID_SPURIOUS 1023
313
314/* Fixme: update from platform specific define or dt */
315#define GIC_NUM_CPU_IF CONFIG_MP_MAX_NUM_CPUS
316
317#ifndef _ASMLANGUAGE
318
319#include <zephyr/types.h>
320#include <zephyr/device.h>
321
322/*
323 * GIC Driver Interface Functions
324 */
325
331void arm_gic_irq_enable(unsigned int irq);
332
338void arm_gic_irq_disable(unsigned int irq);
339
346bool arm_gic_irq_is_enabled(unsigned int irq);
347
354bool arm_gic_irq_is_pending(unsigned int irq);
355
361void arm_gic_irq_set_pending(unsigned int irq);
362
368void arm_gic_irq_clear_pending(unsigned int irq);
369
377void arm_gic_irq_set_priority(unsigned int irq, unsigned int prio, unsigned int flags);
378
384unsigned int arm_gic_get_active(void);
385
391void arm_gic_eoi(unsigned int irq);
392
393#ifdef CONFIG_SMP
398#endif
399
408void gic_raise_sgi(unsigned int sgi_id, uint64_t target_aff, uint16_t target_list);
409
410#endif /* !_ASMLANGUAGE */
411
412#endif /* ZEPHYR_INCLUDE_DRIVERS_GIC_H_ */
void gic_raise_sgi(unsigned int sgi_id, uint64_t target_aff, uint16_t target_list)
raise SGI to target cores
void arm_gic_irq_clear_pending(unsigned int irq)
Clear the pending irq.
void arm_gic_secondary_init(void)
Initialize GIC of secondary cores.
void arm_gic_irq_disable(unsigned int irq)
Disable interrupt.
void arm_gic_eoi(unsigned int irq)
Signal end-of-interrupt.
void arm_gic_irq_enable(unsigned int irq)
Enable interrupt.
void arm_gic_irq_set_pending(unsigned int irq)
Set interrupt as pending.
bool arm_gic_irq_is_enabled(unsigned int irq)
Check if an interrupt is enabled.
bool arm_gic_irq_is_pending(unsigned int irq)
Check if an interrupt is pending.
void arm_gic_irq_set_priority(unsigned int irq, unsigned int prio, unsigned int flags)
Set interrupt priority.
unsigned int arm_gic_get_active(void)
Get active interrupt ID.
flags
Definition parser.h:97
__UINT64_TYPE__ uint64_t
Definition stdint.h:91
__UINT16_TYPE__ uint16_t
Definition stdint.h:89