13#define ARM_GIC_DEFAULT_PRIORITY 0x80
36 IN HARDWARE_INTERRUPT_SOURCE Source
39 if (Source >= mGicNumInterrupts) {
41 return EFI_UNSUPPORTED;
44 ArmGicEnableInterrupt (mGicDistributorBase, mGicRedistributorsBase, Source);
64 IN HARDWARE_INTERRUPT_SOURCE Source
67 if (Source >= mGicNumInterrupts) {
69 return EFI_UNSUPPORTED;
72 ArmGicDisableInterrupt (mGicDistributorBase, mGicRedistributorsBase, Source);
93 IN HARDWARE_INTERRUPT_SOURCE Source,
94 IN BOOLEAN *InterruptState
97 if (Source >= mGicNumInterrupts) {
99 return EFI_UNSUPPORTED;
102 *InterruptState = ArmGicIsInterruptEnabled (
104 mGicRedistributorsBase,
127 IN HARDWARE_INTERRUPT_SOURCE Source
130 if (Source >= mGicNumInterrupts) {
132 return EFI_UNSUPPORTED;
135 ArmGicV3EndOfInterrupt (Source);
162 GicInterrupt = ArmGicV3AcknowledgeInterrupt ();
166 if ((GicInterrupt & ARM_GIC_ICCIAR_ACKINTID) >= mGicNumInterrupts) {
171 InterruptHandler = gRegisteredInterruptHandlers[GicInterrupt];
172 if (InterruptHandler !=
NULL) {
174 InterruptHandler (GicInterrupt, SystemContext);
176 DEBUG ((DEBUG_ERROR,
"Spurious GIC interrupt: 0x%x\n", (UINT32)GicInterrupt));
183 RegisterInterruptSource,
205 IN HARDWARE_INTERRUPT_SOURCE Source,
206 OUT EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE *TriggerType
213 Status = GicGetDistributorIcfgBaseAndBit (
219 if (EFI_ERROR (Status)) {
223 if ((
MmioRead32 (RegAddress) & (1 << Config1Bit)) == 0) {
224 *TriggerType = EFI_HARDWARE_INTERRUPT2_TRIGGER_LEVEL_HIGH;
226 *TriggerType = EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING;
247 IN HARDWARE_INTERRUPT_SOURCE Source,
248 IN EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE TriggerType
255 BOOLEAN SourceEnabled;
257 if ( (TriggerType != EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING)
258 && (TriggerType != EFI_HARDWARE_INTERRUPT2_TRIGGER_LEVEL_HIGH))
262 "Invalid interrupt trigger type: %d\n", \
266 return EFI_UNSUPPORTED;
269 Status = GicGetDistributorIcfgBaseAndBit (
275 if (EFI_ERROR (Status)) {
285 if (EFI_ERROR (Status)) {
289 Value = (TriggerType == EFI_HARDWARE_INTERRUPT2_TRIGGER_EDGE_RISING)
290 ? ARM_GIC_ICDICFR_EDGE_TRIGGERED
291 : ARM_GIC_ICDICFR_LEVEL_TRIGGERED;
304 ~(0x1 << Config1Bit),
347 for (Index = 0; Index < mGicNumInterrupts; Index++) {
352 ArmGicV3DisableInterruptInterface ();
355 ArmGicDisableDistributor (mGicDistributorBase);
384 mGicDistributorBase = (
UINTN)
PcdGet64 (PcdGicDistributorBase);
385 mGicRedistributorsBase =
PcdGet64 (PcdGicRedistributorsBase);
386 mGicNumInterrupts = ArmGicGetMaxNumInterrupts (mGicDistributorBase);
391 MmioOr32 (mGicDistributorBase + ARM_GIC_ICDDCR, ARM_GIC_ICDDCR_ARE);
394 for (Index = 0; Index < mGicNumInterrupts; Index++) {
398 ArmGicSetInterruptPriority (
400 mGicRedistributorsBase,
402 ARM_GIC_DEFAULT_PRIORITY
417 CpuTarget =
MmioRead32 (mGicDistributorBase + ARM_GIC_ICDIPTR);
421 if (CpuTarget != 0) {
423 for (Index = 8; Index < (mGicNumInterrupts / 4); Index++) {
425 mGicDistributorBase + ARM_GIC_ICDIPTR + (Index * 4),
431 MpId = ArmReadMpidr ();
433 (ARM_CORE_AFF0 | ARM_CORE_AFF1 | ARM_CORE_AFF2 | ARM_CORE_AFF3);
436 mGicDistributorBase + ARM_GIC_ICDDCR
437 ) & ARM_GIC_ICDDCR_DS) != 0)
447 mGicRedistributorsBase + ARM_GICR_CTLR_FRAME_SIZE + ARM_GIC_ICDISR,
451 for (Index = 32; Index < mGicNumInterrupts; Index += 32) {
453 mGicDistributorBase + ARM_GIC_ICDISR + Index / 8,
460 for (Index = 0; Index < (mGicNumInterrupts - 32); Index++) {
462 mGicDistributorBase + ARM_GICD_IROUTER + (Index * 8),
469 ArmGicV3SetBinaryPointer (0x7);
472 ArmGicV3SetPriorityMask (0xff);
475 ArmGicV3EnableInterruptInterface ();
478 ArmGicEnableDistributor (mGicDistributorBase);
480 Status = InstallAndRegisterInterruptService (
481 &gHardwareInterruptV3Protocol,
482 &gHardwareInterrupt2V3Protocol,
STATIC EFI_STATUS EFIAPI GicV3DisableInterruptSource(IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
STATIC VOID EFIAPI GicV3IrqInterruptHandler(IN EFI_EXCEPTION_TYPE InterruptType, IN EFI_SYSTEM_CONTEXT SystemContext)
VOID EFIAPI GicV3ExitBootServicesEvent(IN EFI_EVENT Event, IN VOID *Context)
STATIC EFI_STATUS EFIAPI GicV3GetInterruptSourceState(IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source, IN BOOLEAN *InterruptState)
STATIC EFI_STATUS EFIAPI GicV3EnableInterruptSource(IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
STATIC EFI_STATUS EFIAPI GicV3GetTriggerType(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source, OUT EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE *TriggerType)
STATIC EFI_STATUS EFIAPI GicV3SetTriggerType(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source, IN EFI_HARDWARE_INTERRUPT2_TRIGGER_TYPE TriggerType)
STATIC EFI_STATUS EFIAPI GicV3EndOfInterrupt(IN EFI_HARDWARE_INTERRUPT_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
EFI_STATUS GicV3DxeInitialize(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS(EFIAPI * HARDWARE_INTERRUPT2_DISABLE)(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
EFI_STATUS(EFIAPI * HARDWARE_INTERRUPT2_REGISTER)(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source, IN HARDWARE_INTERRUPT_HANDLER Handler)
EFI_STATUS(EFIAPI * HARDWARE_INTERRUPT2_END_OF_INTERRUPT)(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
EFI_STATUS(EFIAPI * HARDWARE_INTERRUPT2_ENABLE)(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source)
EFI_STATUS(EFIAPI * HARDWARE_INTERRUPT2_INTERRUPT_STATE)(IN EFI_HARDWARE_INTERRUPT2_PROTOCOL *This, IN HARDWARE_INTERRUPT_SOURCE Source, IN BOOLEAN *InterruptState)
VOID(EFIAPI * HARDWARE_INTERRUPT_HANDLER)(IN HARDWARE_INTERRUPT_SOURCE Source, IN EFI_SYSTEM_CONTEXT SystemContext)
UINT64 EFIAPI MmioWrite64(IN UINTN Address, IN UINT64 Value)
UINT32 EFIAPI MmioOr32(IN UINTN Address, IN UINT32 OrData)
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 DEBUG(Expression)
#define ASSERT_PROTOCOL_ALREADY_INSTALLED(Handle, Guid)
#define PcdGet64(TokenName)
#define FeaturePcdGet(TokenName)