]> git.proxmox.com Git - mirror_edk2.git/blob - ArmPkg/Include/Library/ArmGicLib.h
7bcfc001115b9fd82bbf262bbc893c74cc813b81
[mirror_edk2.git] / ArmPkg / Include / Library / ArmGicLib.h
1 /** @file
2 *
3 * Copyright (c) 2011-2018, ARM Limited. All rights reserved.
4 *
5 * SPDX-License-Identifier: BSD-2-Clause-Patent
6 *
7 **/
8
9 #ifndef __ARMGIC_H
10 #define __ARMGIC_H
11
12 #include <Library/ArmGicArchLib.h>
13
14 // GIC Distributor
15 #define ARM_GIC_ICDDCR 0x000 // Distributor Control Register
16 #define ARM_GIC_ICDICTR 0x004 // Interrupt Controller Type Register
17 #define ARM_GIC_ICDIIDR 0x008 // Implementer Identification Register
18
19 // Each reg base below repeats for Number of interrupts / 4 (see GIC spec)
20 #define ARM_GIC_ICDISR 0x080 // Interrupt Security Registers
21 #define ARM_GIC_ICDISER 0x100 // Interrupt Set-Enable Registers
22 #define ARM_GIC_ICDICER 0x180 // Interrupt Clear-Enable Registers
23 #define ARM_GIC_ICDSPR 0x200 // Interrupt Set-Pending Registers
24 #define ARM_GIC_ICDICPR 0x280 // Interrupt Clear-Pending Registers
25 #define ARM_GIC_ICDABR 0x300 // Active Bit Registers
26
27 // Each reg base below repeats for Number of interrupts / 4
28 #define ARM_GIC_ICDIPR 0x400 // Interrupt Priority Registers
29
30 // Each reg base below repeats for Number of interrupts
31 #define ARM_GIC_ICDIPTR 0x800 // Interrupt Processor Target Registers
32 #define ARM_GIC_ICDICFR 0xC00 // Interrupt Configuration Registers
33
34 #define ARM_GIC_ICDPPISR 0xD00 // PPI Status register
35
36 // just one of these
37 #define ARM_GIC_ICDSGIR 0xF00 // Software Generated Interrupt Register
38
39 // GICv3 specific registers
40 #define ARM_GICD_IROUTER 0x6100 // Interrupt Routing Registers
41
42 // GICD_CTLR bits
43 #define ARM_GIC_ICDDCR_ARE (1 << 4) // Affinity Routing Enable (ARE)
44 #define ARM_GIC_ICDDCR_DS (1 << 6) // Disable Security (DS)
45
46 // GICD_ICDICFR bits
47 #define ARM_GIC_ICDICFR_WIDTH 32 // ICDICFR is a 32 bit register
48 #define ARM_GIC_ICDICFR_BYTES (ARM_GIC_ICDICFR_WIDTH / 8)
49 #define ARM_GIC_ICDICFR_F_WIDTH 2 // Each F field is 2 bits
50 #define ARM_GIC_ICDICFR_F_STRIDE 16 // (32/2) F fields per register
51 #define ARM_GIC_ICDICFR_F_CONFIG1_BIT 1 // Bit number within F field
52 #define ARM_GIC_ICDICFR_LEVEL_TRIGGERED 0x0 // Level triggered interrupt
53 #define ARM_GIC_ICDICFR_EDGE_TRIGGERED 0x1 // Edge triggered interrupt
54
55
56 // GIC Redistributor
57 #define ARM_GICR_CTLR_FRAME_SIZE SIZE_64KB
58 #define ARM_GICR_SGI_PPI_FRAME_SIZE SIZE_64KB
59 #define ARM_GICR_SGI_VLPI_FRAME_SIZE SIZE_64KB
60 #define ARM_GICR_SGI_RESERVED_FRAME_SIZE SIZE_64KB
61
62 // GIC Redistributor Control frame
63 #define ARM_GICR_TYPER 0x0008 // Redistributor Type Register
64
65 // GIC Redistributor TYPER bit assignments
66 #define ARM_GICR_TYPER_PLPIS (1 << 0) // Physical LPIs
67 #define ARM_GICR_TYPER_VLPIS (1 << 1) // Virtual LPIs
68 #define ARM_GICR_TYPER_DIRECTLPI (1 << 3) // Direct LPIs
69 #define ARM_GICR_TYPER_LAST (1 << 4) // Last Redistributor in series
70 #define ARM_GICR_TYPER_DPGS (1 << 5) // Disable Processor Group
71 // Selection Support
72 #define ARM_GICR_TYPER_PROCNO (0xFFFF << 8) // Processor Number
73 #define ARM_GICR_TYPER_COMMONLPIAFF (0x3 << 24) // Common LPI Affinity
74 #define ARM_GICR_TYPER_AFFINITY (0xFFFFFFFFULL << 32) // Redistributor Affinity
75
76 #define ARM_GICR_TYPER_GET_AFFINITY(TypeReg) (((TypeReg) & \
77 ARM_GICR_TYPER_AFFINITY) >> 32)
78
79 // GIC SGI & PPI Redistributor frame
80 #define ARM_GICR_ISENABLER 0x0100 // Interrupt Set-Enable Registers
81 #define ARM_GICR_ICENABLER 0x0180 // Interrupt Clear-Enable Registers
82
83 // GIC Cpu interface
84 #define ARM_GIC_ICCICR 0x00 // CPU Interface Control Register
85 #define ARM_GIC_ICCPMR 0x04 // Interrupt Priority Mask Register
86 #define ARM_GIC_ICCBPR 0x08 // Binary Point Register
87 #define ARM_GIC_ICCIAR 0x0C // Interrupt Acknowledge Register
88 #define ARM_GIC_ICCEIOR 0x10 // End Of Interrupt Register
89 #define ARM_GIC_ICCRPR 0x14 // Running Priority Register
90 #define ARM_GIC_ICCPIR 0x18 // Highest Pending Interrupt Register
91 #define ARM_GIC_ICCABPR 0x1C // Aliased Binary Point Register
92 #define ARM_GIC_ICCIIDR 0xFC // Identification Register
93
94 #define ARM_GIC_ICDSGIR_FILTER_TARGETLIST 0x0
95 #define ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE 0x1
96 #define ARM_GIC_ICDSGIR_FILTER_ITSELF 0x2
97
98 // Bit-masks to configure the CPU Interface Control register
99 #define ARM_GIC_ICCICR_ENABLE_SECURE 0x01
100 #define ARM_GIC_ICCICR_ENABLE_NS 0x02
101 #define ARM_GIC_ICCICR_ACK_CTL 0x04
102 #define ARM_GIC_ICCICR_SIGNAL_SECURE_TO_FIQ 0x08
103 #define ARM_GIC_ICCICR_USE_SBPR 0x10
104
105 // Bit Mask for GICC_IIDR
106 #define ARM_GIC_ICCIIDR_GET_PRODUCT_ID(IccIidr) (((IccIidr) >> 20) & 0xFFF)
107 #define ARM_GIC_ICCIIDR_GET_ARCH_VERSION(IccIidr) (((IccIidr) >> 16) & 0xF)
108 #define ARM_GIC_ICCIIDR_GET_REVISION(IccIidr) (((IccIidr) >> 12) & 0xF)
109 #define ARM_GIC_ICCIIDR_GET_IMPLEMENTER(IccIidr) ((IccIidr) & 0xFFF)
110
111 // Bit Mask for
112 #define ARM_GIC_ICCIAR_ACKINTID 0x3FF
113
114 UINTN
115 EFIAPI
116 ArmGicGetInterfaceIdentification (
117 IN INTN GicInterruptInterfaceBase
118 );
119
120 // GIC Secure interfaces
121 VOID
122 EFIAPI
123 ArmGicSetupNonSecure (
124 IN UINTN MpId,
125 IN INTN GicDistributorBase,
126 IN INTN GicInterruptInterfaceBase
127 );
128
129 VOID
130 EFIAPI
131 ArmGicSetSecureInterrupts (
132 IN UINTN GicDistributorBase,
133 IN UINTN* GicSecureInterruptMask,
134 IN UINTN GicSecureInterruptMaskSize
135 );
136
137 VOID
138 EFIAPI
139 ArmGicEnableInterruptInterface (
140 IN INTN GicInterruptInterfaceBase
141 );
142
143 VOID
144 EFIAPI
145 ArmGicDisableInterruptInterface (
146 IN INTN GicInterruptInterfaceBase
147 );
148
149 VOID
150 EFIAPI
151 ArmGicEnableDistributor (
152 IN INTN GicDistributorBase
153 );
154
155 VOID
156 EFIAPI
157 ArmGicDisableDistributor (
158 IN INTN GicDistributorBase
159 );
160
161 UINTN
162 EFIAPI
163 ArmGicGetMaxNumInterrupts (
164 IN INTN GicDistributorBase
165 );
166
167 VOID
168 EFIAPI
169 ArmGicSendSgiTo (
170 IN INTN GicDistributorBase,
171 IN INTN TargetListFilter,
172 IN INTN CPUTargetList,
173 IN INTN SgiId
174 );
175
176 /*
177 * Acknowledge and return the value of the Interrupt Acknowledge Register
178 *
179 * InterruptId is returned separately from the register value because in
180 * the GICv2 the register value contains the CpuId and InterruptId while
181 * in the GICv3 the register value is only the InterruptId.
182 *
183 * @param GicInterruptInterfaceBase Base Address of the GIC CPU Interface
184 * @param InterruptId InterruptId read from the Interrupt
185 * Acknowledge Register
186 *
187 * @retval value returned by the Interrupt Acknowledge Register
188 *
189 */
190 UINTN
191 EFIAPI
192 ArmGicAcknowledgeInterrupt (
193 IN UINTN GicInterruptInterfaceBase,
194 OUT UINTN *InterruptId
195 );
196
197 VOID
198 EFIAPI
199 ArmGicEndOfInterrupt (
200 IN UINTN GicInterruptInterfaceBase,
201 IN UINTN Source
202 );
203
204 UINTN
205 EFIAPI
206 ArmGicSetPriorityMask (
207 IN INTN GicInterruptInterfaceBase,
208 IN INTN PriorityMask
209 );
210
211 VOID
212 EFIAPI
213 ArmGicSetInterruptPriority (
214 IN UINTN GicDistributorBase,
215 IN UINTN GicRedistributorBase,
216 IN UINTN Source,
217 IN UINTN Priority
218 );
219
220 VOID
221 EFIAPI
222 ArmGicEnableInterrupt (
223 IN UINTN GicDistributorBase,
224 IN UINTN GicRedistributorBase,
225 IN UINTN Source
226 );
227
228 VOID
229 EFIAPI
230 ArmGicDisableInterrupt (
231 IN UINTN GicDistributorBase,
232 IN UINTN GicRedistributorBase,
233 IN UINTN Source
234 );
235
236 BOOLEAN
237 EFIAPI
238 ArmGicIsInterruptEnabled (
239 IN UINTN GicDistributorBase,
240 IN UINTN GicRedistributorBase,
241 IN UINTN Source
242 );
243
244 // GIC revision 2 specific declarations
245
246 // Interrupts from 1020 to 1023 are considered as special interrupts
247 // (eg: spurious interrupts)
248 #define ARM_GIC_IS_SPECIAL_INTERRUPTS(Interrupt) \
249 (((Interrupt) >= 1020) && ((Interrupt) <= 1023))
250
251 VOID
252 EFIAPI
253 ArmGicV2SetupNonSecure (
254 IN UINTN MpId,
255 IN INTN GicDistributorBase,
256 IN INTN GicInterruptInterfaceBase
257 );
258
259 VOID
260 EFIAPI
261 ArmGicV2EnableInterruptInterface (
262 IN INTN GicInterruptInterfaceBase
263 );
264
265 VOID
266 EFIAPI
267 ArmGicV2DisableInterruptInterface (
268 IN INTN GicInterruptInterfaceBase
269 );
270
271 UINTN
272 EFIAPI
273 ArmGicV2AcknowledgeInterrupt (
274 IN UINTN GicInterruptInterfaceBase
275 );
276
277 VOID
278 EFIAPI
279 ArmGicV2EndOfInterrupt (
280 IN UINTN GicInterruptInterfaceBase,
281 IN UINTN Source
282 );
283
284 // GIC revision 3 specific declarations
285
286 #define ICC_SRE_EL2_SRE (1 << 0)
287
288 #define ARM_GICD_IROUTER_IRM BIT31
289
290 UINT32
291 EFIAPI
292 ArmGicV3GetControlSystemRegisterEnable (
293 VOID
294 );
295
296 VOID
297 EFIAPI
298 ArmGicV3SetControlSystemRegisterEnable (
299 IN UINT32 ControlSystemRegisterEnable
300 );
301
302 VOID
303 EFIAPI
304 ArmGicV3EnableInterruptInterface (
305 VOID
306 );
307
308 VOID
309 EFIAPI
310 ArmGicV3DisableInterruptInterface (
311 VOID
312 );
313
314 UINTN
315 EFIAPI
316 ArmGicV3AcknowledgeInterrupt (
317 VOID
318 );
319
320 VOID
321 EFIAPI
322 ArmGicV3EndOfInterrupt (
323 IN UINTN Source
324 );
325
326 VOID
327 ArmGicV3SetBinaryPointer (
328 IN UINTN BinaryPoint
329 );
330
331 VOID
332 ArmGicV3SetPriorityMask (
333 IN UINTN Priority
334 );
335
336 #endif