3 * Copyright (c) 2011-2015, ARM Limited. All rights reserved.
5 * This program and the accompanying materials
6 * are licensed and made available under the terms and conditions of the BSD License
7 * which accompanies this distribution. The full text of the license may be found at
8 * http://opensource.org/licenses/bsd-license.php
10 * THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
18 #include <Library/ArmGicArchLib.h>
23 #define ARM_GIC_ICDDCR 0x000 // Distributor Control Register
24 #define ARM_GIC_ICDICTR 0x004 // Interrupt Controller Type Register
25 #define ARM_GIC_ICDIIDR 0x008 // Implementer Identification Register
27 // Each reg base below repeats for Number of interrupts / 4 (see GIC spec)
28 #define ARM_GIC_ICDISR 0x080 // Interrupt Security Registers
29 #define ARM_GIC_ICDISER 0x100 // Interrupt Set-Enable Registers
30 #define ARM_GIC_ICDICER 0x180 // Interrupt Clear-Enable Registers
31 #define ARM_GIC_ICDSPR 0x200 // Interrupt Set-Pending Registers
32 #define ARM_GIC_ICDICPR 0x280 // Interrupt Clear-Pending Registers
33 #define ARM_GIC_ICDABR 0x300 // Active Bit Registers
35 // Each reg base below repeats for Number of interrupts / 4
36 #define ARM_GIC_ICDIPR 0x400 // Interrupt Priority Registers
38 // Each reg base below repeats for Number of interrupts
39 #define ARM_GIC_ICDIPTR 0x800 // Interrupt Processor Target Registers
40 #define ARM_GIC_ICDICFR 0xC00 // Interrupt Configuration Registers
42 #define ARM_GIC_ICDPPISR 0xD00 // PPI Status register
45 #define ARM_GIC_ICDSGIR 0xF00 // Software Generated Interrupt Register
47 // GICv3 specific registers
48 #define ARM_GICD_IROUTER 0x6100 // Interrupt Routing Registers
50 // the Affinity Routing Enable (ARE) bit in GICD_CTLR
51 #define ARM_GIC_ICDDCR_ARE (1 << 4)
57 #define ARM_GICR_CTLR_FRAME_SIZE SIZE_64KB
58 #define ARM_GICR_SGI_PPI_FRAME_SIZE SIZE_64KB
60 // GIC Redistributor Control frame
61 #define ARM_GICR_TYPER 0x0008 // Redistributor Type Register
63 // GIC SGI & PPI Redistributor frame
64 #define ARM_GICR_ISENABLER 0x0100 // Interrupt Set-Enable Registers
65 #define ARM_GICR_ICENABLER 0x0180 // Interrupt Clear-Enable Registers
70 #define ARM_GIC_ICCICR 0x00 // CPU Interface Control Register
71 #define ARM_GIC_ICCPMR 0x04 // Interrupt Priority Mask Register
72 #define ARM_GIC_ICCBPR 0x08 // Binary Point Register
73 #define ARM_GIC_ICCIAR 0x0C // Interrupt Acknowledge Register
74 #define ARM_GIC_ICCEIOR 0x10 // End Of Interrupt Register
75 #define ARM_GIC_ICCRPR 0x14 // Running Priority Register
76 #define ARM_GIC_ICCPIR 0x18 // Highest Pending Interrupt Register
77 #define ARM_GIC_ICCABPR 0x1C // Aliased Binary Point Register
78 #define ARM_GIC_ICCIIDR 0xFC // Identification Register
80 #define ARM_GIC_ICDSGIR_FILTER_TARGETLIST 0x0
81 #define ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE 0x1
82 #define ARM_GIC_ICDSGIR_FILTER_ITSELF 0x2
84 // Bit-masks to configure the CPU Interface Control register
85 #define ARM_GIC_ICCICR_ENABLE_SECURE 0x01
86 #define ARM_GIC_ICCICR_ENABLE_NS 0x02
87 #define ARM_GIC_ICCICR_ACK_CTL 0x04
88 #define ARM_GIC_ICCICR_SIGNAL_SECURE_TO_FIQ 0x08
89 #define ARM_GIC_ICCICR_USE_SBPR 0x10
91 // Bit Mask for GICC_IIDR
92 #define ARM_GIC_ICCIIDR_GET_PRODUCT_ID(IccIidr) (((IccIidr) >> 20) & 0xFFF)
93 #define ARM_GIC_ICCIIDR_GET_ARCH_VERSION(IccIidr) (((IccIidr) >> 16) & 0xF)
94 #define ARM_GIC_ICCIIDR_GET_REVISION(IccIidr) (((IccIidr) >> 12) & 0xF)
95 #define ARM_GIC_ICCIIDR_GET_IMPLEMENTER(IccIidr) ((IccIidr) & 0xFFF)
98 #define ARM_GIC_ICCIAR_ACKINTID 0x3FF
102 ArmGicGetInterfaceIdentification (
103 IN INTN GicInterruptInterfaceBase
107 // GIC Secure interfaces
111 ArmGicSetupNonSecure (
113 IN INTN GicDistributorBase
,
114 IN INTN GicInterruptInterfaceBase
119 ArmGicSetSecureInterrupts (
120 IN UINTN GicDistributorBase
,
121 IN UINTN
* GicSecureInterruptMask
,
122 IN UINTN GicSecureInterruptMaskSize
127 ArmGicEnableInterruptInterface (
128 IN INTN GicInterruptInterfaceBase
133 ArmGicDisableInterruptInterface (
134 IN INTN GicInterruptInterfaceBase
139 ArmGicEnableDistributor (
140 IN INTN GicDistributorBase
145 ArmGicDisableDistributor (
146 IN INTN GicDistributorBase
151 ArmGicGetMaxNumInterrupts (
152 IN INTN GicDistributorBase
158 IN INTN GicDistributorBase
,
159 IN INTN TargetListFilter
,
160 IN INTN CPUTargetList
,
165 * Acknowledge and return the value of the Interrupt Acknowledge Register
167 * InterruptId is returned separately from the register value because in
168 * the GICv2 the register value contains the CpuId and InterruptId while
169 * in the GICv3 the register value is only the InterruptId.
171 * @param GicInterruptInterfaceBase Base Address of the GIC CPU Interface
172 * @param InterruptId InterruptId read from the Interrupt Acknowledge Register
174 * @retval value returned by the Interrupt Acknowledge Register
179 ArmGicAcknowledgeInterrupt (
180 IN UINTN GicInterruptInterfaceBase
,
181 OUT UINTN
*InterruptId
186 ArmGicEndOfInterrupt (
187 IN UINTN GicInterruptInterfaceBase
,
193 ArmGicSetPriorityMask (
194 IN INTN GicInterruptInterfaceBase
,
200 ArmGicEnableInterrupt (
201 IN UINTN GicDistributorBase
,
202 IN UINTN GicRedistributorBase
,
208 ArmGicDisableInterrupt (
209 IN UINTN GicDistributorBase
,
210 IN UINTN GicRedistributorBase
,
216 ArmGicIsInterruptEnabled (
217 IN UINTN GicDistributorBase
,
218 IN UINTN GicRedistributorBase
,
223 // GIC revision 2 specific declarations
226 // Interrupts from 1020 to 1023 are considered as special interrupts (eg: spurious interrupts)
227 #define ARM_GIC_IS_SPECIAL_INTERRUPTS(Interrupt) (((Interrupt) >= 1020) && ((Interrupt) <= 1023))
231 ArmGicV2SetupNonSecure (
233 IN INTN GicDistributorBase
,
234 IN INTN GicInterruptInterfaceBase
239 ArmGicV2EnableInterruptInterface (
240 IN INTN GicInterruptInterfaceBase
245 ArmGicV2DisableInterruptInterface (
246 IN INTN GicInterruptInterfaceBase
251 ArmGicV2AcknowledgeInterrupt (
252 IN UINTN GicInterruptInterfaceBase
257 ArmGicV2EndOfInterrupt (
258 IN UINTN GicInterruptInterfaceBase
,
263 // GIC revision 3 specific declarations
266 #define ICC_SRE_EL2_SRE (1 << 0)
268 #define ARM_GICD_IROUTER_IRM BIT31
272 ArmGicV3GetControlSystemRegisterEnable (
278 ArmGicV3SetControlSystemRegisterEnable (
279 IN UINT32 ControlSystemRegisterEnable
284 ArmGicV3EnableInterruptInterface (
290 ArmGicV3DisableInterruptInterface (
296 ArmGicV3AcknowledgeInterrupt (
302 ArmGicV3EndOfInterrupt (
307 ArmGicV3SetBinaryPointer (
312 ArmGicV3SetPriorityMask (