4 Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 - ACPI 6.3 Specification - January 2019
9 - Arm Generic Interrupt Controller Architecture Specification,
10 GIC architecture version 3 and version 4, issue E
11 - Arm Server Base System Architecture 5.0
14 #include <IndustryStandard/Acpi.h>
15 #include <Library/UefiLib.h>
16 #include "AcpiParser.h"
17 #include "AcpiTableParser.h"
18 #include "MadtParser.h"
21 STATIC CONST UINT8
* MadtInterruptControllerType
;
22 STATIC CONST UINT8
* MadtInterruptControllerLength
;
23 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo
;
26 This function validates the System Vector Base in the GICD.
28 @param [in] Ptr Pointer to the start of the field data.
29 @param [in] Context Pointer to context specific information e.g. this
30 could be a pointer to the ACPI table header.
35 ValidateGICDSystemVectorBase (
40 if (*(UINT32
*)Ptr
!= 0) {
41 IncrementErrorCount ();
43 L
"\nERROR: System Vector Base must be zero."
49 This function validates the SPE Overflow Interrupt in the GICC.
51 @param [in] Ptr Pointer to the start of the field data.
52 @param [in] Context Pointer to context specific information e.g. this
53 could be a pointer to the ACPI table header.
58 ValidateSpeOverflowInterrupt (
63 UINT16 SpeOverflowInterrupt
;
65 SpeOverflowInterrupt
= *(UINT16
*)Ptr
;
67 // SPE not supported by this processor
68 if (SpeOverflowInterrupt
== 0) {
72 if ((SpeOverflowInterrupt
< ARM_PPI_ID_MIN
) ||
73 ((SpeOverflowInterrupt
> ARM_PPI_ID_MAX
) &&
74 (SpeOverflowInterrupt
< ARM_PPI_ID_EXTENDED_MIN
)) ||
75 (SpeOverflowInterrupt
> ARM_PPI_ID_EXTENDED_MAX
)) {
76 IncrementErrorCount ();
78 L
"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
79 L
"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
83 ARM_PPI_ID_EXTENDED_MIN
,
84 ARM_PPI_ID_EXTENDED_MAX
86 } else if (SpeOverflowInterrupt
!= ARM_PPI_ID_PMBIRQ
) {
87 IncrementWarningCount();
89 L
"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "
90 L
"Level 3 PPI ID assignment: %d.",
98 An ACPI_PARSER array describing the GICC Interrupt Controller Structure.
100 STATIC CONST ACPI_PARSER GicCParser
[] = {
101 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
102 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
103 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
105 {L
"CPU Interface Number", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
106 {L
"ACPI Processor UID", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
107 {L
"Flags", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
108 {L
"Parking Protocol Version", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
110 {L
"Performance Interrupt GSIV", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
111 {L
"Parked Address", 8, 24, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
112 {L
"Physical Base Address", 8, 32, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
113 {L
"GICV", 8, 40, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
114 {L
"GICH", 8, 48, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
115 {L
"VGIC Maintenance interrupt", 4, 56, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
116 {L
"GICR Base Address", 8, 60, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
117 {L
"MPIDR", 8, 68, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
118 {L
"Processor Power Efficiency Class", 1, 76, L
"0x%x", NULL
, NULL
, NULL
,
120 {L
"Reserved", 1, 77, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
121 {L
"SPE overflow Interrupt", 2, 78, L
"0x%x", NULL
, NULL
,
122 ValidateSpeOverflowInterrupt
, NULL
}
126 An ACPI_PARSER array describing the GICD Interrupt Controller Structure.
128 STATIC CONST ACPI_PARSER GicDParser
[] = {
129 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
130 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
131 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
133 {L
"GIC ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
134 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
135 {L
"System Vector Base", 4, 16, L
"0x%x", NULL
, NULL
,
136 ValidateGICDSystemVectorBase
, NULL
},
137 {L
"GIC Version", 1, 20, L
"%d", NULL
, NULL
, NULL
, NULL
},
138 {L
"Reserved", 3, 21, L
"%x %x %x", Dump3Chars
, NULL
, NULL
, NULL
}
142 An ACPI_PARSER array describing the MSI Frame Interrupt Controller Structure.
144 STATIC CONST ACPI_PARSER GicMSIFrameParser
[] = {
145 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
146 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
147 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
149 {L
"MSI Frame ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
150 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
151 {L
"Flags", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
153 {L
"SPI Count", 2, 20, L
"%d", NULL
, NULL
, NULL
, NULL
},
154 {L
"SPI Base", 2, 22, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
158 An ACPI_PARSER array describing the GICR Interrupt Controller Structure.
160 STATIC CONST ACPI_PARSER GicRParser
[] = {
161 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
162 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
163 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
165 {L
"Discovery Range Base Address", 8, 4, L
"0x%lx", NULL
, NULL
, NULL
,
167 {L
"Discovery Range Length", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
171 An ACPI_PARSER array describing the GIC ITS Interrupt Controller Structure.
173 STATIC CONST ACPI_PARSER GicITSParser
[] = {
174 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
175 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
176 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
178 {L
"GIC ITS ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
179 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
180 {L
"Reserved", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
184 An ACPI_PARSER array describing the ACPI MADT Table.
186 STATIC CONST ACPI_PARSER MadtParser
[] = {
187 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
188 {L
"Local Interrupt Controller Address", 4, 36, L
"0x%x", NULL
, NULL
, NULL
,
190 {L
"Flags", 4, 40, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
194 An ACPI_PARSER array describing the MADT Interrupt Controller Structure Header Structure.
196 STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser
[] = {
197 {NULL
, 1, 0, NULL
, NULL
, (VOID
**)&MadtInterruptControllerType
, NULL
, NULL
},
198 {L
"Length", 1, 1, NULL
, NULL
, (VOID
**)&MadtInterruptControllerLength
, NULL
,
200 {L
"Reserved", 2, 2, NULL
, NULL
, NULL
, NULL
, NULL
}
204 This function parses the ACPI MADT table.
205 When trace is enabled this function parses the MADT table and
206 traces the ACPI table fields.
208 This function currently parses the following Interrupt Controller
216 This function also performs validation of the ACPI table fields.
218 @param [in] Trace If TRUE, trace the ACPI fields.
219 @param [in] Ptr Pointer to the start of the buffer.
220 @param [in] AcpiTableLength Length of the ACPI table.
221 @param [in] AcpiTableRevision Revision of the ACPI table.
228 IN UINT32 AcpiTableLength
,
229 IN UINT8 AcpiTableRevision
233 UINT8
* InterruptContollerPtr
;
248 PARSER_PARAMS (MadtParser
)
250 InterruptContollerPtr
= Ptr
+ Offset
;
252 while (Offset
< AcpiTableLength
) {
253 // Parse Interrupt Controller Structure to obtain Length.
258 InterruptContollerPtr
,
259 AcpiTableLength
- Offset
,
260 PARSER_PARAMS (MadtInterruptControllerHeaderParser
)
263 // Check if the values used to control the parsing logic have been
264 // successfully read.
265 if ((MadtInterruptControllerType
== NULL
) ||
266 (MadtInterruptControllerLength
== NULL
)) {
267 IncrementErrorCount ();
269 L
"ERROR: Insufficient remaining table buffer length to read the " \
270 L
"Interrupt Controller Structure header. Length = %d.\n",
271 AcpiTableLength
- Offset
276 // Make sure forward progress is made.
277 if (*MadtInterruptControllerLength
< 2) {
278 IncrementErrorCount ();
280 L
"ERROR: Structure length is too small: " \
281 L
"MadtInterruptControllerLength = %d. " \
282 L
"MadtInterruptControllerType = %d. MADT parsing aborted.\n",
283 *MadtInterruptControllerLength
,
284 *MadtInterruptControllerType
289 // Make sure the MADT structure lies inside the table
290 if ((Offset
+ *MadtInterruptControllerLength
) > AcpiTableLength
) {
291 IncrementErrorCount ();
293 L
"ERROR: Invalid MADT structure length. " \
294 L
"MadtInterruptControllerLength = %d. " \
295 L
"RemainingTableBufferLength = %d. MADT parsing aborted.\n",
296 *MadtInterruptControllerLength
,
297 AcpiTableLength
- Offset
302 switch (*MadtInterruptControllerType
) {
303 case EFI_ACPI_6_3_GIC
: {
308 InterruptContollerPtr
,
309 *MadtInterruptControllerLength
,
310 PARSER_PARAMS (GicCParser
)
315 case EFI_ACPI_6_3_GICD
: {
316 if (++GICDCount
> 1) {
317 IncrementErrorCount ();
319 L
"ERROR: Only one GICD must be present,"
320 L
" GICDCount = %d\n",
328 InterruptContollerPtr
,
329 *MadtInterruptControllerLength
,
330 PARSER_PARAMS (GicDParser
)
335 case EFI_ACPI_6_3_GIC_MSI_FRAME
: {
340 InterruptContollerPtr
,
341 *MadtInterruptControllerLength
,
342 PARSER_PARAMS (GicMSIFrameParser
)
347 case EFI_ACPI_6_3_GICR
: {
352 InterruptContollerPtr
,
353 *MadtInterruptControllerLength
,
354 PARSER_PARAMS (GicRParser
)
359 case EFI_ACPI_6_3_GIC_ITS
: {
364 InterruptContollerPtr
,
365 *MadtInterruptControllerLength
,
366 PARSER_PARAMS (GicITSParser
)
372 IncrementErrorCount ();
374 L
"ERROR: Unknown Interrupt Controller Structure,"
375 L
" Type = %d, Length = %d\n",
376 *MadtInterruptControllerType
,
377 *MadtInterruptControllerLength
382 InterruptContollerPtr
+= *MadtInterruptControllerLength
;
383 Offset
+= *MadtInterruptControllerLength
;