4 Copyright (c) 2016 - 2018, 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.
14 - ACPI 6.2 Specification - Errata A, September 2017
17 #include <IndustryStandard/Acpi.h>
18 #include <Library/UefiLib.h>
19 #include "AcpiParser.h"
20 #include "AcpiTableParser.h"
23 STATIC CONST UINT8
* MadtInterruptControllerType
;
24 STATIC CONST UINT8
* MadtInterruptControllerLength
;
25 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo
;
27 // Forward declarations
31 ValidateGICDSystemVectorBase (
36 /** An ACPI_PARSER array describing the GICC Interrupt
39 STATIC CONST ACPI_PARSER GicCParser
[] = {
40 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
41 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
42 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
44 {L
"CPU Interface Number", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
45 {L
"ACPI Processor UID", 4, 8, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
46 {L
"Flags", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
47 {L
"Parking Protocol Version", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
49 {L
"Performance Interrupt GSIV", 4, 20, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
50 {L
"Parked Address", 8, 24, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
51 {L
"Physical Base Address", 8, 32, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
52 {L
"GICV", 8, 40, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
53 {L
"GICH", 8, 48, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
54 {L
"VGIC Maintenance interrupt", 4, 56, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
55 {L
"GICR Base Address", 8, 60, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
56 {L
"MPIDR", 8, 68, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
57 {L
"Processor Power Efficiency Class", 1, 76, L
"0x%x", NULL
, NULL
, NULL
,
59 {L
"Reserved", 3, 77, L
"%x %x %x", Dump3Chars
, NULL
, NULL
, NULL
}
62 /** An ACPI_PARSER array describing the GICD Interrupt
65 STATIC CONST ACPI_PARSER GicDParser
[] = {
66 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
67 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
68 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
70 {L
"GIC ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
71 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
72 {L
"System Vector Base", 4, 16, L
"0x%x", NULL
, NULL
,
73 ValidateGICDSystemVectorBase
, NULL
},
74 {L
"GIC Version", 1, 20, L
"%d", NULL
, NULL
, NULL
, NULL
},
75 {L
"Reserved", 3, 21, L
"%x %x %x", Dump3Chars
, NULL
, NULL
, NULL
}
78 /** An ACPI_PARSER array describing the MSI Frame Interrupt
81 STATIC CONST ACPI_PARSER GicMSIFrameParser
[] = {
82 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
83 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
84 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
86 {L
"MSI Frame ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
87 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
88 {L
"Flags", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
90 {L
"SPI Count", 2, 20, L
"%d", NULL
, NULL
, NULL
, NULL
},
91 {L
"SPI Base", 2, 22, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
94 /** An ACPI_PARSER array describing the GICR Interrupt
97 STATIC CONST ACPI_PARSER GicRParser
[] = {
98 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
99 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
100 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
102 {L
"Discovery Range Base Address", 8, 4, L
"0x%lx", NULL
, NULL
, NULL
,
104 {L
"Discovery Range Length", 4, 12, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
107 /** An ACPI_PARSER array describing the GIC ITS Interrupt
108 Controller Structure.
110 STATIC CONST ACPI_PARSER GicITSParser
[] = {
111 {L
"Type", 1, 0, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
112 {L
"Length", 1, 1, L
"%d", NULL
, NULL
, NULL
, NULL
},
113 {L
"Reserved", 2, 2, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
115 {L
"GIC ITS ID", 4, 4, L
"0x%x", NULL
, NULL
, NULL
, NULL
},
116 {L
"Physical Base Address", 8, 8, L
"0x%lx", NULL
, NULL
, NULL
, NULL
},
117 {L
"Reserved", 4, 16, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
120 /** An ACPI_PARSER array describing the ACPI MADT Table.
122 STATIC CONST ACPI_PARSER MadtParser
[] = {
123 PARSE_ACPI_HEADER (&AcpiHdrInfo
),
124 {L
"Local Interrupt Controller Address", 4, 36, L
"0x%x", NULL
, NULL
, NULL
,
126 {L
"Flags", 4, 40, L
"0x%x", NULL
, NULL
, NULL
, NULL
}
129 /** An ACPI_PARSER array describing the MADT Interrupt
130 Controller Structure Header Structure.
132 STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser
[] = {
133 {NULL
, 1, 0, NULL
, NULL
, (VOID
**)&MadtInterruptControllerType
, NULL
, NULL
},
134 {L
"Length", 1, 1, NULL
, NULL
, (VOID
**)&MadtInterruptControllerLength
, NULL
,
136 {L
"Reserved", 2, 2, NULL
, NULL
, NULL
, NULL
, NULL
}
139 /** This function validates the System Vector Base in the GICD.
141 @param [in] Ptr Pointer to the start of the field data.
142 @param [in] Context Pointer to context specific information e.g. this
143 could be a pointer to the ACPI table header.
148 ValidateGICDSystemVectorBase (
153 if (*(UINT32
*)Ptr
!= 0) {
154 IncrementErrorCount ();
156 L
"\nERROR: System Vector Base must be zero."
161 /** This function parses the ACPI MADT table.
162 When trace is enabled this function parses the MADT table and
163 traces the ACPI table fields.
165 This function currently parses the following Interrupt Controller
173 This function also performs validation of the ACPI table fields.
175 @param [in] Trace If TRUE, trace the ACPI fields.
176 @param [in] Ptr Pointer to the start of the buffer.
177 @param [in] AcpiTableLength Length of the ACPI table.
178 @param [in] AcpiTableRevision Revision of the ACPI table.
185 IN UINT32 AcpiTableLength
,
186 IN UINT8 AcpiTableRevision
190 UINT8
* InterruptContollerPtr
;
191 UINT32 GICDCount
= 0;
203 PARSER_PARAMS (MadtParser
)
205 InterruptContollerPtr
= Ptr
+ Offset
;
207 while (Offset
< AcpiTableLength
) {
208 // Parse Interrupt Controller Structure to obtain Length.
213 InterruptContollerPtr
,
214 2, // Length is 1 byte at offset 1
215 PARSER_PARAMS (MadtInterruptControllerHeaderParser
)
218 if (((Offset
+ (*MadtInterruptControllerLength
)) > AcpiTableLength
) ||
219 (*MadtInterruptControllerLength
< 4)) {
220 IncrementErrorCount ();
222 L
"ERROR: Invalid Interrupt Controller Length,"
223 " Type = %d, Length = %d\n",
224 *MadtInterruptControllerType
,
225 *MadtInterruptControllerLength
230 switch (*MadtInterruptControllerType
) {
231 case EFI_ACPI_6_2_GIC
: {
236 InterruptContollerPtr
,
237 *MadtInterruptControllerLength
,
238 PARSER_PARAMS (GicCParser
)
243 case EFI_ACPI_6_2_GICD
: {
244 if (++GICDCount
> 1) {
245 IncrementErrorCount ();
247 L
"ERROR: Only one GICD must be present,"
256 InterruptContollerPtr
,
257 *MadtInterruptControllerLength
,
258 PARSER_PARAMS (GicDParser
)
263 case EFI_ACPI_6_2_GIC_MSI_FRAME
: {
268 InterruptContollerPtr
,
269 *MadtInterruptControllerLength
,
270 PARSER_PARAMS (GicMSIFrameParser
)
275 case EFI_ACPI_6_2_GICR
: {
280 InterruptContollerPtr
,
281 *MadtInterruptControllerLength
,
282 PARSER_PARAMS (GicRParser
)
287 case EFI_ACPI_6_2_GIC_ITS
: {
292 InterruptContollerPtr
,
293 *MadtInterruptControllerLength
,
294 PARSER_PARAMS (GicITSParser
)
300 IncrementErrorCount ();
302 L
"ERROR: Unknown Interrupt Controller Structure,"
303 " Type = %d, Length = %d\n",
304 *MadtInterruptControllerType
,
305 *MadtInterruptControllerLength
310 InterruptContollerPtr
+= *MadtInterruptControllerLength
;
311 Offset
+= *MadtInterruptControllerLength
;