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