18#define GIC_V3_REDISTRIBUTOR_GRANULARITY (ARM_GICR_CTLR_FRAME_SIZE \
19 + ARM_GICR_SGI_PPI_FRAME_SIZE)
23#define GIC_V4_REDISTRIBUTOR_GRANULARITY (GIC_V3_REDISTRIBUTOR_GRANULARITY \
24 + ARM_GICR_SGI_VLPI_FRAME_SIZE \
25 + ARM_GICR_SGI_RESERVED_FRAME_SIZE)
27#define ISENABLER_ADDRESS(base, offset) ((base) +\
28 ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ISENABLER + 4 * (offset))
30#define ICENABLER_ADDRESS(base, offset) ((base) +\
31 ARM_GICR_CTLR_FRAME_SIZE + ARM_GICR_ICENABLER + 4 * (offset))
33#define IPRIORITY_ADDRESS(base, offset) ((base) +\
34 ARM_GICR_CTLR_FRAME_SIZE + ARM_GIC_ICDIPR + 4 * (offset))
46 return Source >= 32 && Source < 1020;
61 IN ARM_GIC_ARCH_REVISION Revision
67 UINTN GicCpuRedistributorBase;
70 MpId = ArmReadMpidr ();
74 CpuAffinity = (MpId & (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2)) |
75 ((MpId & ARM_CORE_AFF3) >> 8);
77 if (Revision < ARM_GIC_ARCH_REVISION_3) {
82 GicCpuRedistributorBase = GicRedistributorBase;
85 TypeRegister =
MmioRead64 (GicCpuRedistributorBase + ARM_GICR_TYPER);
86 Affinity = ARM_GICR_TYPER_GET_AFFINITY (TypeRegister);
87 if (Affinity == CpuAffinity) {
88 return GicCpuRedistributorBase;
97 GicCpuRedistributorBase += (((ARM_GICR_TYPER_VLPIS & TypeRegister) != 0)
98 ? GIC_V4_REDISTRIBUTOR_GRANULARITY
99 : GIC_V3_REDISTRIBUTOR_GRANULARITY);
100 }
while ((TypeRegister & ARM_GICR_TYPER_LAST) == 0);
117 IN UINTN GicInterruptInterfaceBase
121 return MmioRead32 (GicInterruptInterfaceBase + ARM_GIC_ICCIIDR);
126ArmGicGetMaxNumInterrupts (
132 ItLines =
MmioRead32 (GicDistributorBase + ARM_GIC_ICDICTR) & 0x1F;
137 return (ItLines == 0x1f) ? 1020 : 32 * (ItLines + 1);
144 IN UINT8 TargetListFilter,
145 IN UINT8 CPUTargetList,
150 GicDistributorBase + ARM_GIC_ICDSGIR,
151 ((TargetListFilter & 0x3) << 24) |
152 ((CPUTargetList & 0xFF) << 16) |
173ArmGicAcknowledgeInterrupt (
174 IN UINTN GicInterruptInterfaceBase,
180 ARM_GIC_ARCH_REVISION Revision;
182 ASSERT (InterruptId !=
NULL);
183 Revision = ArmGicGetSupportedArchRevision ();
184 if (Revision == ARM_GIC_ARCH_REVISION_2) {
185 Value = ArmGicV2AcknowledgeInterrupt (GicInterruptInterfaceBase);
186 IntId = Value & ARM_GIC_ICCIAR_ACKINTID;
187 }
else if (Revision == ARM_GIC_ARCH_REVISION_3) {
188 Value = ArmGicV3AcknowledgeInterrupt ();
197 if (InterruptId !=
NULL) {
200 *InterruptId = IntId;
208ArmGicEndOfInterrupt (
209 IN UINTN GicInterruptInterfaceBase,
213 ARM_GIC_ARCH_REVISION Revision;
215 Revision = ArmGicGetSupportedArchRevision ();
216 if (Revision == ARM_GIC_ARCH_REVISION_2) {
217 ArmGicV2EndOfInterrupt (GicInterruptInterfaceBase, Source);
218 }
else if (Revision == ARM_GIC_ARCH_REVISION_3) {
219 ArmGicV3EndOfInterrupt (Source);
227ArmGicSetInterruptPriority (
236 ARM_GIC_ARCH_REVISION Revision;
237 UINTN GicCpuRedistributorBase;
240 RegOffset = (UINT32)(Source / 4);
241 RegShift = (UINT8)((Source % 4) * 8);
243 Revision = ArmGicGetSupportedArchRevision ();
244 if ((Revision == ARM_GIC_ARCH_REVISION_2) ||
249 GicDistributorBase + ARM_GIC_ICDIPR + (4 * RegOffset),
255 GicRedistributorBase,
258 if (GicCpuRedistributorBase == 0) {
263 IPRIORITY_ADDRESS (GicCpuRedistributorBase, RegOffset),
272ArmGicEnableInterrupt (
280 ARM_GIC_ARCH_REVISION Revision;
281 UINTN GicCpuRedistributorBase;
284 RegOffset = (UINT32)(Source / 32);
285 RegShift = (UINT8)(Source % 32);
287 Revision = ArmGicGetSupportedArchRevision ();
288 if ((Revision == ARM_GIC_ARCH_REVISION_2) ||
294 GicDistributorBase + ARM_GIC_ICDISER + (4 * RegOffset),
299 GicRedistributorBase,
302 if (GicCpuRedistributorBase == 0) {
309 ISENABLER_ADDRESS (GicCpuRedistributorBase, RegOffset),
317ArmGicDisableInterrupt (
325 ARM_GIC_ARCH_REVISION Revision;
326 UINTN GicCpuRedistributorBase;
329 RegOffset = (UINT32)(Source / 32);
330 RegShift = (UINT8)(Source % 32);
332 Revision = ArmGicGetSupportedArchRevision ();
333 if ((Revision == ARM_GIC_ARCH_REVISION_2) ||
339 GicDistributorBase + ARM_GIC_ICDICER + (4 * RegOffset),
344 GicRedistributorBase,
347 if (GicCpuRedistributorBase == 0) {
353 ICENABLER_ADDRESS (GicCpuRedistributorBase, RegOffset),
361ArmGicIsInterruptEnabled (
369 ARM_GIC_ARCH_REVISION Revision;
370 UINTN GicCpuRedistributorBase;
374 RegOffset = (UINT32)(Source / 32);
375 RegShift = (UINT8)(Source % 32);
377 Revision = ArmGicGetSupportedArchRevision ();
378 if ((Revision == ARM_GIC_ARCH_REVISION_2) ||
383 GicDistributorBase + ARM_GIC_ICDISER + (4 * RegOffset)
387 GicRedistributorBase,
390 if (GicCpuRedistributorBase == 0) {
396 ISENABLER_ADDRESS (GicCpuRedistributorBase, RegOffset)
400 return ((Interrupts & (1 << RegShift)) != 0);
405ArmGicDisableDistributor (
410 MmioWrite32 (GicDistributorBase + ARM_GIC_ICDDCR, 0x0);
415ArmGicEnableInterruptInterface (
416 IN UINTN GicInterruptInterfaceBase
419 ARM_GIC_ARCH_REVISION Revision;
421 Revision = ArmGicGetSupportedArchRevision ();
422 if (Revision == ARM_GIC_ARCH_REVISION_2) {
423 ArmGicV2EnableInterruptInterface (GicInterruptInterfaceBase);
424 }
else if (Revision == ARM_GIC_ARCH_REVISION_3) {
425 ArmGicV3EnableInterruptInterface ();
433ArmGicDisableInterruptInterface (
434 IN UINTN GicInterruptInterfaceBase
437 ARM_GIC_ARCH_REVISION Revision;
439 Revision = ArmGicGetSupportedArchRevision ();
440 if (Revision == ARM_GIC_ARCH_REVISION_2) {
441 ArmGicV2DisableInterruptInterface (GicInterruptInterfaceBase);
442 }
else if (Revision == ARM_GIC_ARCH_REVISION_3) {
443 ArmGicV3DisableInterruptInterface ();
UINT32 EFIAPI ArmGicGetInterfaceIdentification(IN UINTN GicInterruptInterfaceBase)
STATIC UINTN GicGetCpuRedistributorBase(IN UINTN GicRedistributorBase, IN ARM_GIC_ARCH_REVISION Revision)
STATIC BOOLEAN SourceIsSpi(IN UINTN Source)
UINT64 EFIAPI MmioRead64(IN UINTN Address)
UINT32 EFIAPI MmioRead32(IN UINTN Address)
UINT32 EFIAPI MmioAndThenOr32(IN UINTN Address, IN UINT32 AndData, IN UINT32 OrData)
UINT32 EFIAPI MmioWrite32(IN UINTN Address, IN UINT32 Value)
#define ASSERT_EFI_ERROR(StatusParameter)
#define FeaturePcdGet(TokenName)