@@ -14,12 +14,23 @@ EFI_HANDLE gHardwareInterruptHandle = NULL;
14
14
// Notifications
15
15
EFI_EVENT EfiExitBootServicesEvent = (EFI_EVENT )NULL ;
16
16
17
- // Maximum Number of Interrupts
18
- UINTN mGicNumInterrupts = 0 ;
19
-
20
17
HARDWARE_INTERRUPT_HANDLER * gRegisteredInterruptHandlers = NULL ;
21
18
EFI_CPU_ARCH_PROTOCOL * gCpuArch ;
22
19
20
+ /**
21
+ *
22
+ * Return whether the Source interrupt index refers to an extended shared
23
+ * interrupt (ESPI)
24
+ */
25
+ STATIC
26
+ BOOLEAN
27
+ SourceIsEspi (
28
+ IN UINTN Source
29
+ )
30
+ {
31
+ return Source >= ARM_GIC_ARCH_EXT_SPI_MIN && Source <= ARM_GIC_ARCH_EXT_SPI_MAX ;
32
+ }
33
+
23
34
/**
24
35
Calculate GICD_ICFGRn base address and corresponding bit
25
36
field Int_config[1] of the GIC distributor register.
@@ -38,18 +49,25 @@ GicGetDistributorIcfgBaseAndBit (
38
49
OUT UINTN * Config1Bit
39
50
)
40
51
{
41
- UINTN RegIndex ;
42
- UINTN Field ;
52
+ UINTN RegIndex ;
53
+ UINTN Field ;
54
+ UINTN RegOffset ;
55
+ HARDWARE_INTERRUPT_SOURCE AdjustedSource ;
43
56
44
- if (Source >= mGicNumInterrupts ) {
45
- ASSERT (Source < mGicNumInterrupts );
57
+ if (! GicIsValidSource ( Source ) ) {
58
+ ASSERT (FALSE );
46
59
return EFI_UNSUPPORTED ;
47
60
}
48
61
49
- RegIndex = Source / ARM_GIC_ICDICFR_F_STRIDE ; // NOTE: truncation is significant
50
- Field = Source % ARM_GIC_ICDICFR_F_STRIDE ;
62
+ // Translate ESPI sources into the SPI range for indexing purposes.
63
+ AdjustedSource = Source & ~(ARM_GIC_ARCH_EXT_SPI_MIN );
64
+
65
+ RegOffset = (SourceIsEspi (Source )) ? ARM_GIC_ICDICFR_E : ARM_GIC_ICDICFR ;
66
+
67
+ RegIndex = AdjustedSource / ARM_GIC_ICDICFR_F_STRIDE ; // NOTE: truncation is significant
68
+ Field = AdjustedSource % ARM_GIC_ICDICFR_F_STRIDE ;
51
69
* RegAddress = (UINTN )PcdGet64 (PcdGicDistributorBase )
52
- + ARM_GIC_ICDICFR
70
+ + RegOffset
53
71
+ (ARM_GIC_ICDICFR_BYTES * RegIndex );
54
72
* Config1Bit = ((Field * ARM_GIC_ICDICFR_F_WIDTH )
55
73
+ ARM_GIC_ICDICFR_F_CONFIG1_BIT );
@@ -76,7 +94,7 @@ RegisterInterruptSource (
76
94
IN HARDWARE_INTERRUPT_HANDLER Handler
77
95
)
78
96
{
79
- if (Source >= mGicNumInterrupts ) {
97
+ if (! GicIsValidSource ( Source ) ) {
80
98
ASSERT (FALSE);
81
99
return EFI_UNSUPPORTED ;
82
100
}
@@ -107,9 +125,12 @@ InstallAndRegisterInterruptService (
107
125
IN EFI_EVENT_NOTIFY ExitBootServicesEvent
108
126
)
109
127
{
110
- EFI_STATUS Status ;
128
+ EFI_STATUS Status ;
129
+
130
+ UINTN NumIntids = GicGetGreatestIntid () + 1 ;
131
+
111
132
CONST UINTN RihArraySize =
112
- (sizeof (HARDWARE_INTERRUPT_HANDLER ) * mGicNumInterrupts );
133
+ (sizeof (HARDWARE_INTERRUPT_HANDLER ) * NumIntids );
113
134
114
135
// Initialize the array for the Interrupt Handlers
115
136
gRegisteredInterruptHandlers = AllocateZeroPool (RihArraySize );
0 commit comments