]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
ShellPkg: acpiview: ACPI 6.3 update for MADT parser
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Madt / MadtParser.c
1 /** @file
2 MADT table parser
3
4 Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 @par Reference(s):
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
12 **/
13
14 #include <IndustryStandard/Acpi.h>
15 #include <Library/UefiLib.h>
16 #include "AcpiParser.h"
17 #include "AcpiTableParser.h"
18 #include "MadtParser.h"
19
20 // Local Variables
21 STATIC CONST UINT8* MadtInterruptControllerType;
22 STATIC CONST UINT8* MadtInterruptControllerLength;
23 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
24
25 /**
26 This function validates the System Vector Base in the GICD.
27
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.
31 **/
32 STATIC
33 VOID
34 EFIAPI
35 ValidateGICDSystemVectorBase (
36 IN UINT8* Ptr,
37 IN VOID* Context
38 );
39
40 /**
41 This function validates the SPE Overflow Interrupt in the GICC.
42
43 @param [in] Ptr Pointer to the start of the field data.
44 @param [in] Context Pointer to context specific information e.g. this
45 could be a pointer to the ACPI table header.
46 **/
47 STATIC
48 VOID
49 EFIAPI
50 ValidateSpeOverflowInterrupt (
51 IN UINT8* Ptr,
52 IN VOID* Context
53 );
54
55 /**
56 An ACPI_PARSER array describing the GICC Interrupt Controller Structure.
57 **/
58 STATIC CONST ACPI_PARSER GicCParser[] = {
59 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
60 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
61 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
62
63 {L"CPU Interface Number", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
64 {L"ACPI Processor UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
65 {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
66 {L"Parking Protocol Version", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
67
68 {L"Performance Interrupt GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
69 {L"Parked Address", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL},
70 {L"Physical Base Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL},
71 {L"GICV", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL},
72 {L"GICH", 8, 48, L"0x%lx", NULL, NULL, NULL, NULL},
73 {L"VGIC Maintenance interrupt", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
74 {L"GICR Base Address", 8, 60, L"0x%lx", NULL, NULL, NULL, NULL},
75 {L"MPIDR", 8, 68, L"0x%lx", NULL, NULL, NULL, NULL},
76 {L"Processor Power Efficiency Class", 1, 76, L"0x%x", NULL, NULL, NULL,
77 NULL},
78 {L"Reserved", 1, 77, L"0x%x", NULL, NULL, NULL, NULL},
79 {L"SPE overflow Interrupt", 2, 78, L"0x%x", NULL, NULL,
80 ValidateSpeOverflowInterrupt, NULL}
81 };
82
83 /**
84 An ACPI_PARSER array describing the GICD Interrupt Controller Structure.
85 **/
86 STATIC CONST ACPI_PARSER GicDParser[] = {
87 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
88 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
89 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
90
91 {L"GIC ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
92 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
93 {L"System Vector Base", 4, 16, L"0x%x", NULL, NULL,
94 ValidateGICDSystemVectorBase, NULL},
95 {L"GIC Version", 1, 20, L"%d", NULL, NULL, NULL, NULL},
96 {L"Reserved", 3, 21, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
97 };
98
99 /**
100 An ACPI_PARSER array describing the MSI Frame Interrupt Controller Structure.
101 **/
102 STATIC CONST ACPI_PARSER GicMSIFrameParser[] = {
103 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
104 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
105 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
106
107 {L"MSI Frame ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
108 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
109 {L"Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
110
111 {L"SPI Count", 2, 20, L"%d", NULL, NULL, NULL, NULL},
112 {L"SPI Base", 2, 22, L"0x%x", NULL, NULL, NULL, NULL}
113 };
114
115 /**
116 An ACPI_PARSER array describing the GICR Interrupt Controller Structure.
117 **/
118 STATIC CONST ACPI_PARSER GicRParser[] = {
119 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
120 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
121 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
122
123 {L"Discovery Range Base Address", 8, 4, L"0x%lx", NULL, NULL, NULL,
124 NULL},
125 {L"Discovery Range Length", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
126 };
127
128 /**
129 An ACPI_PARSER array describing the GIC ITS Interrupt Controller Structure.
130 **/
131 STATIC CONST ACPI_PARSER GicITSParser[] = {
132 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
133 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
134 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
135
136 {L"GIC ITS ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
137 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
138 {L"Reserved", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}
139 };
140
141 /**
142 An ACPI_PARSER array describing the ACPI MADT Table.
143 **/
144 STATIC CONST ACPI_PARSER MadtParser[] = {
145 PARSE_ACPI_HEADER (&AcpiHdrInfo),
146 {L"Local Interrupt Controller Address", 4, 36, L"0x%x", NULL, NULL, NULL,
147 NULL},
148 {L"Flags", 4, 40, L"0x%x", NULL, NULL, NULL, NULL}
149 };
150
151 /**
152 An ACPI_PARSER array describing the MADT Interrupt Controller Structure Header Structure.
153 **/
154 STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser[] = {
155 {NULL, 1, 0, NULL, NULL, (VOID**)&MadtInterruptControllerType, NULL, NULL},
156 {L"Length", 1, 1, NULL, NULL, (VOID**)&MadtInterruptControllerLength, NULL,
157 NULL},
158 {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
159 };
160
161 /**
162 This function validates the System Vector Base in the GICD.
163
164 @param [in] Ptr Pointer to the start of the field data.
165 @param [in] Context Pointer to context specific information e.g. this
166 could be a pointer to the ACPI table header.
167 **/
168 STATIC
169 VOID
170 EFIAPI
171 ValidateGICDSystemVectorBase (
172 IN UINT8* Ptr,
173 IN VOID* Context
174 )
175 {
176 if (*(UINT32*)Ptr != 0) {
177 IncrementErrorCount ();
178 Print (
179 L"\nERROR: System Vector Base must be zero."
180 );
181 }
182 }
183
184 /**
185 This function validates the SPE Overflow Interrupt in the GICC.
186
187 @param [in] Ptr Pointer to the start of the field data.
188 @param [in] Context Pointer to context specific information e.g. this
189 could be a pointer to the ACPI table header.
190 **/
191 STATIC
192 VOID
193 EFIAPI
194 ValidateSpeOverflowInterrupt (
195 IN UINT8* Ptr,
196 IN VOID* Context
197 )
198 {
199 UINT16 SpeOverflowInterrupt;
200
201 SpeOverflowInterrupt = *(UINT16*)Ptr;
202
203 // SPE not supported by this processor
204 if (SpeOverflowInterrupt == 0) {
205 return;
206 }
207
208 if ((SpeOverflowInterrupt < ARM_PPI_ID_MIN) ||
209 ((SpeOverflowInterrupt > ARM_PPI_ID_MAX) &&
210 (SpeOverflowInterrupt < ARM_PPI_ID_EXTENDED_MIN)) ||
211 (SpeOverflowInterrupt > ARM_PPI_ID_EXTENDED_MAX)) {
212 IncrementErrorCount ();
213 Print (
214 L"\nERROR: SPE Overflow Interrupt ID of %d is not in the allowed PPI ID "
215 L"ranges of %d-%d or %d-%d (for GICv3.1 or later).",
216 SpeOverflowInterrupt,
217 ARM_PPI_ID_MIN,
218 ARM_PPI_ID_MAX,
219 ARM_PPI_ID_EXTENDED_MIN,
220 ARM_PPI_ID_EXTENDED_MAX
221 );
222 } else if (SpeOverflowInterrupt != ARM_PPI_ID_PMBIRQ) {
223 IncrementWarningCount();
224 Print (
225 L"\nWARNING: SPE Overflow Interrupt ID of %d is not compliant with SBSA "
226 L"Level 3 PPI ID assignment: %d.",
227 SpeOverflowInterrupt,
228 ARM_PPI_ID_PMBIRQ
229 );
230 }
231 }
232
233 /**
234 This function parses the ACPI MADT table.
235 When trace is enabled this function parses the MADT table and
236 traces the ACPI table fields.
237
238 This function currently parses the following Interrupt Controller
239 Structures:
240 - GICC
241 - GICD
242 - GIC MSI Frame
243 - GICR
244 - GIC ITS
245
246 This function also performs validation of the ACPI table fields.
247
248 @param [in] Trace If TRUE, trace the ACPI fields.
249 @param [in] Ptr Pointer to the start of the buffer.
250 @param [in] AcpiTableLength Length of the ACPI table.
251 @param [in] AcpiTableRevision Revision of the ACPI table.
252 **/
253 VOID
254 EFIAPI
255 ParseAcpiMadt (
256 IN BOOLEAN Trace,
257 IN UINT8* Ptr,
258 IN UINT32 AcpiTableLength,
259 IN UINT8 AcpiTableRevision
260 )
261 {
262 UINT32 Offset;
263 UINT8* InterruptContollerPtr;
264 UINT32 GICDCount;
265
266 GICDCount = 0;
267
268 if (!Trace) {
269 return;
270 }
271
272 Offset = ParseAcpi (
273 TRUE,
274 0,
275 "MADT",
276 Ptr,
277 AcpiTableLength,
278 PARSER_PARAMS (MadtParser)
279 );
280 InterruptContollerPtr = Ptr + Offset;
281
282 while (Offset < AcpiTableLength) {
283 // Parse Interrupt Controller Structure to obtain Length.
284 ParseAcpi (
285 FALSE,
286 0,
287 NULL,
288 InterruptContollerPtr,
289 2, // Length is 1 byte at offset 1
290 PARSER_PARAMS (MadtInterruptControllerHeaderParser)
291 );
292
293 if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
294 (*MadtInterruptControllerLength < 4)) {
295 IncrementErrorCount ();
296 Print (
297 L"ERROR: Invalid Interrupt Controller Length,"
298 L" Type = %d, Length = %d\n",
299 *MadtInterruptControllerType,
300 *MadtInterruptControllerLength
301 );
302 break;
303 }
304
305 switch (*MadtInterruptControllerType) {
306 case EFI_ACPI_6_3_GIC: {
307 ParseAcpi (
308 TRUE,
309 2,
310 "GICC",
311 InterruptContollerPtr,
312 *MadtInterruptControllerLength,
313 PARSER_PARAMS (GicCParser)
314 );
315 break;
316 }
317
318 case EFI_ACPI_6_3_GICD: {
319 if (++GICDCount > 1) {
320 IncrementErrorCount ();
321 Print (
322 L"ERROR: Only one GICD must be present,"
323 L" GICDCount = %d\n",
324 GICDCount
325 );
326 }
327 ParseAcpi (
328 TRUE,
329 2,
330 "GICD",
331 InterruptContollerPtr,
332 *MadtInterruptControllerLength,
333 PARSER_PARAMS (GicDParser)
334 );
335 break;
336 }
337
338 case EFI_ACPI_6_3_GIC_MSI_FRAME: {
339 ParseAcpi (
340 TRUE,
341 2,
342 "GIC MSI Frame",
343 InterruptContollerPtr,
344 *MadtInterruptControllerLength,
345 PARSER_PARAMS (GicMSIFrameParser)
346 );
347 break;
348 }
349
350 case EFI_ACPI_6_3_GICR: {
351 ParseAcpi (
352 TRUE,
353 2,
354 "GICR",
355 InterruptContollerPtr,
356 *MadtInterruptControllerLength,
357 PARSER_PARAMS (GicRParser)
358 );
359 break;
360 }
361
362 case EFI_ACPI_6_3_GIC_ITS: {
363 ParseAcpi (
364 TRUE,
365 2,
366 "GIC ITS",
367 InterruptContollerPtr,
368 *MadtInterruptControllerLength,
369 PARSER_PARAMS (GicITSParser)
370 );
371 break;
372 }
373
374 default: {
375 IncrementErrorCount ();
376 Print (
377 L"ERROR: Unknown Interrupt Controller Structure,"
378 L" Type = %d, Length = %d\n",
379 *MadtInterruptControllerType,
380 *MadtInterruptControllerLength
381 );
382 }
383 } // switch
384
385 InterruptContollerPtr += *MadtInterruptControllerLength;
386 Offset += *MadtInterruptControllerLength;
387 } // while
388 }