3 * Copyright (c) 2011-2017, 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>
21 #define ARM_GIC_ICDDCR 0x000 // Distributor Control Register
22 #define ARM_GIC_ICDICTR 0x004 // Interrupt Controller Type Register
23 #define ARM_GIC_ICDIIDR 0x008 // Implementer Identification Register
25 // Each reg base below repeats for Number of interrupts / 4 (see GIC spec)
26 #define ARM_GIC_ICDISR 0x080 // Interrupt Security Registers
27 #define ARM_GIC_ICDISER 0x100 // Interrupt Set-Enable Registers
28 #define ARM_GIC_ICDICER 0x180 // Interrupt Clear-Enable Registers
29 #define ARM_GIC_ICDSPR 0x200 // Interrupt Set-Pending Registers
30 #define ARM_GIC_ICDICPR 0x280 // Interrupt Clear-Pending Registers
31 #define ARM_GIC_ICDABR 0x300 // Active Bit Registers
33 // Each reg base below repeats for Number of interrupts / 4
34 #define ARM_GIC_ICDIPR 0x400 // Interrupt Priority Registers
36 // Each reg base below repeats for Number of interrupts
37 #define ARM_GIC_ICDIPTR 0x800 // Interrupt Processor Target Registers
38 #define ARM_GIC_ICDICFR 0xC00 // Interrupt Configuration Registers
40 #define ARM_GIC_ICDPPISR 0xD00 // PPI Status register
43 #define ARM_GIC_ICDSGIR 0xF00 // Software Generated Interrupt Register
45 // GICv3 specific registers
46 #define ARM_GICD_IROUTER 0x6100 // Interrupt Routing Registers
49 #define ARM_GIC_ICDDCR_ARE (1 << 4) // Affinity Routing Enable (ARE)
50 #define ARM_GIC_ICDDCR_DS (1 << 6) // Disable Security (DS)
53 #define ARM_GIC_ICDICFR_WIDTH 32 // ICDICFR is a 32 bit register
54 #define ARM_GIC_ICDICFR_BYTES (ARM_GIC_ICDICFR_WIDTH / 8)
55 #define ARM_GIC_ICDICFR_F_WIDTH 2 // Each F field is 2 bits
56 #define ARM_GIC_ICDICFR_F_STRIDE 16 // (32/2) F fields per register
57 #define ARM_GIC_ICDICFR_F_CONFIG1_BIT 1 // Bit number within F field
58 #define ARM_GIC_ICDICFR_LEVEL_TRIGGERED 0x0 // Level triggered interrupt
59 #define ARM_GIC_ICDICFR_EDGE_TRIGGERED 0x1 // Edge triggered interrupt
63 #define ARM_GICR_CTLR_FRAME_SIZE SIZE_64KB
64 #define ARM_GICR_SGI_PPI_FRAME_SIZE SIZE_64KB
66 // GIC Redistributor Control frame
67 #define ARM_GICR_TYPER 0x0008 // Redistributor Type Register
69 // GIC SGI & PPI Redistributor frame
70 #define ARM_GICR_ISENABLER 0x0100 // Interrupt Set-Enable Registers
71 #define ARM_GICR_ICENABLER 0x0180 // Interrupt Clear-Enable Registers
74 #define ARM_GIC_ICCICR 0x00 // CPU Interface Control Register
75 #define ARM_GIC_ICCPMR 0x04 // Interrupt Priority Mask Register
76 #define ARM_GIC_ICCBPR 0x08 // Binary Point Register
77 #define ARM_GIC_ICCIAR 0x0C // Interrupt Acknowledge Register
78 #define ARM_GIC_ICCEIOR 0x10 // End Of Interrupt Register
79 #define ARM_GIC_ICCRPR 0x14 // Running Priority Register
80 #define ARM_GIC_ICCPIR 0x18 // Highest Pending Interrupt Register
81 #define ARM_GIC_ICCABPR 0x1C // Aliased Binary Point Register
82 #define ARM_GIC_ICCIIDR 0xFC // Identification Register
84 #define ARM_GIC_ICDSGIR_FILTER_TARGETLIST 0x0
85 #define ARM_GIC_ICDSGIR_FILTER_EVERYONEELSE 0x1
86 #define ARM_GIC_ICDSGIR_FILTER_ITSELF 0x2
88 // Bit-masks to configure the CPU Interface Control register
89 #define ARM_GIC_ICCICR_ENABLE_SECURE 0x01
90 #define ARM_GIC_ICCICR_ENABLE_NS 0x02
91 #define ARM_GIC_ICCICR_ACK_CTL 0x04
92 #define ARM_GIC_ICCICR_SIGNAL_SECURE_TO_FIQ 0x08
93 #define ARM_GIC_ICCICR_USE_SBPR 0x10
95 // Bit Mask for GICC_IIDR
96 #define ARM_GIC_ICCIIDR_GET_PRODUCT_ID(IccIidr) (((IccIidr) >> 20) & 0xFFF)
97 #define ARM_GIC_ICCIIDR_GET_ARCH_VERSION(IccIidr) (((IccIidr) >> 16) & 0xF)
98 #define ARM_GIC_ICCIIDR_GET_REVISION(IccIidr) (((IccIidr) >> 12) & 0xF)
99 #define ARM_GIC_ICCIIDR_GET_IMPLEMENTER(IccIidr) ((IccIidr) & 0xFFF)
102 #define ARM_GIC_ICCIAR_ACKINTID 0x3FF
106 ArmGicGetInterfaceIdentification (
107 IN INTN GicInterruptInterfaceBase
110 // GIC Secure interfaces
113 ArmGicSetupNonSecure (
115 IN INTN GicDistributorBase
,
116 IN INTN GicInterruptInterfaceBase
121 ArmGicSetSecureInterrupts (
122 IN UINTN GicDistributorBase
,
123 IN UINTN
* GicSecureInterruptMask
,
124 IN UINTN GicSecureInterruptMaskSize
129 ArmGicEnableInterruptInterface (
130 IN INTN GicInterruptInterfaceBase
135 ArmGicDisableInterruptInterface (
136 IN INTN GicInterruptInterfaceBase
141 ArmGicEnableDistributor (
142 IN INTN GicDistributorBase
147 ArmGicDisableDistributor (
148 IN INTN GicDistributorBase
153 ArmGicGetMaxNumInterrupts (
154 IN INTN GicDistributorBase
160 IN INTN GicDistributorBase
,
161 IN INTN TargetListFilter
,
162 IN INTN CPUTargetList
,
167 * Acknowledge and return the value of the Interrupt Acknowledge Register
169 * InterruptId is returned separately from the register value because in
170 * the GICv2 the register value contains the CpuId and InterruptId while
171 * in the GICv3 the register value is only the InterruptId.
173 * @param GicInterruptInterfaceBase Base Address of the GIC CPU Interface
174 * @param InterruptId InterruptId read from the Interrupt
175 * Acknowledge Register
177 * @retval value returned by the Interrupt Acknowledge Register
182 ArmGicAcknowledgeInterrupt (
183 IN UINTN GicInterruptInterfaceBase
,
184 OUT UINTN
*InterruptId
189 ArmGicEndOfInterrupt (
190 IN UINTN GicInterruptInterfaceBase
,
196 ArmGicSetPriorityMask (
197 IN INTN GicInterruptInterfaceBase
,
203 ArmGicEnableInterrupt (
204 IN UINTN GicDistributorBase
,
205 IN UINTN GicRedistributorBase
,
211 ArmGicDisableInterrupt (
212 IN UINTN GicDistributorBase
,
213 IN UINTN GicRedistributorBase
,
219 ArmGicIsInterruptEnabled (
220 IN UINTN GicDistributorBase
,
221 IN UINTN GicRedistributorBase
,
225 // GIC revision 2 specific declarations
227 // Interrupts from 1020 to 1023 are considered as special interrupts
228 // (eg: spurious interrupts)
229 #define ARM_GIC_IS_SPECIAL_INTERRUPTS(Interrupt) \
230 (((Interrupt) >= 1020) && ((Interrupt) <= 1023))
234 ArmGicV2SetupNonSecure (
236 IN INTN GicDistributorBase
,
237 IN INTN GicInterruptInterfaceBase
242 ArmGicV2EnableInterruptInterface (
243 IN INTN GicInterruptInterfaceBase
248 ArmGicV2DisableInterruptInterface (
249 IN INTN GicInterruptInterfaceBase
254 ArmGicV2AcknowledgeInterrupt (
255 IN UINTN GicInterruptInterfaceBase
260 ArmGicV2EndOfInterrupt (
261 IN UINTN GicInterruptInterfaceBase
,
265 // GIC revision 3 specific declarations
267 #define ICC_SRE_EL2_SRE (1 << 0)
269 #define ARM_GICD_IROUTER_IRM BIT31
273 ArmGicV3GetControlSystemRegisterEnable (
279 ArmGicV3SetControlSystemRegisterEnable (
280 IN UINT32 ControlSystemRegisterEnable
285 ArmGicV3EnableInterruptInterface (
291 ArmGicV3DisableInterruptInterface (
297 ArmGicV3AcknowledgeInterrupt (
303 ArmGicV3EndOfInterrupt (
308 ArmGicV3SetBinaryPointer (
313 ArmGicV3SetPriorityMask (