3 * Copyright (c) 2011-2014, 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.
16 #include <Library/ArmGicLib.h>
17 #include <Library/DebugLib.h>
18 #include <Library/IoLib.h>
20 #include "GicV2/ArmGicV2Lib.h"
24 ArmGicGetInterfaceIdentification (
25 IN INTN GicInterruptInterfaceBase
28 // Read the GIC Identification Register
29 return MmioRead32 (GicInterruptInterfaceBase
+ ARM_GIC_ICCIIDR
);
34 ArmGicGetMaxNumInterrupts (
35 IN INTN GicDistributorBase
38 return 32 * ((MmioRead32 (GicDistributorBase
+ ARM_GIC_ICDICTR
) & 0x1F) + 1);
44 IN INTN GicDistributorBase
,
45 IN INTN TargetListFilter
,
46 IN INTN CPUTargetList
,
50 MmioWrite32 (GicDistributorBase
+ ARM_GIC_ICDSGIR
, ((TargetListFilter
& 0x3) << 24) | ((CPUTargetList
& 0xFF) << 16) | SgiId
);
54 * Acknowledge and return the value of the Interrupt Acknowledge Register
56 * InterruptId is returned separately from the register value because in
57 * the GICv2 the register value contains the CpuId and InterruptId while
58 * in the GICv3 the register value is only the InterruptId.
60 * @param GicInterruptInterfaceBase Base Address of the GIC CPU Interface
61 * @param InterruptId InterruptId read from the Interrupt Acknowledge Register
63 * @retval value returned by the Interrupt Acknowledge Register
68 ArmGicAcknowledgeInterrupt (
69 IN UINTN GicInterruptInterfaceBase
,
70 OUT UINTN
*InterruptId
75 Value
= ArmGicV2AcknowledgeInterrupt (GicInterruptInterfaceBase
);
77 // InterruptId is required for the caller to know if a valid or spurious
78 // interrupt has been read
79 ASSERT (InterruptId
!= NULL
);
81 if (InterruptId
!= NULL
) {
82 *InterruptId
= Value
& ARM_GIC_ICCIAR_ACKINTID
;
90 ArmGicEndOfInterrupt (
91 IN UINTN GicInterruptInterfaceBase
,
95 ArmGicV2EndOfInterrupt (GicInterruptInterfaceBase
, Source
);
100 ArmGicEnableInterrupt (
101 IN UINTN GicDistributorBase
,
108 // Calculate enable register offset and bit position
109 RegOffset
= Source
/ 32;
110 RegShift
= Source
% 32;
112 // Write set-enable register
113 MmioWrite32 (GicDistributorBase
+ ARM_GIC_ICDISER
+ (4 * RegOffset
), 1 << RegShift
);
118 ArmGicDisableInterrupt (
119 IN UINTN GicDistributorBase
,
126 // Calculate enable register offset and bit position
127 RegOffset
= Source
/ 32;
128 RegShift
= Source
% 32;
130 // Write clear-enable register
131 MmioWrite32 (GicDistributorBase
+ ARM_GIC_ICDICER
+ (4 * RegOffset
), 1 << RegShift
);
136 ArmGicIsInterruptEnabled (
137 IN UINTN GicDistributorBase
,
144 // Calculate enable register offset and bit position
145 RegOffset
= Source
/ 32;
146 RegShift
= Source
% 32;
148 return ((MmioRead32 (GicDistributorBase
+ ARM_GIC_ICDISER
+ (4 * RegOffset
)) & (1 << RegShift
)) != 0);
153 ArmGicDisableDistributor (
154 IN INTN GicDistributorBase
157 // Disable Gic Distributor
158 MmioWrite32 (GicDistributorBase
+ ARM_GIC_ICDDCR
, 0x0);
163 ArmGicEnableInterruptInterface (
164 IN INTN GicInterruptInterfaceBase
167 return ArmGicV2EnableInterruptInterface (GicInterruptInterfaceBase
);
172 ArmGicDisableInterruptInterface (
173 IN INTN GicInterruptInterfaceBase
176 return ArmGicV2DisableInterruptInterface (GicInterruptInterfaceBase
);