]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/Parsers/Madt/MadtParser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / Parsers / Madt / MadtParser.c
1 /** @file
2 MADT table parser
3
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
9
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.
12
13 @par Reference(s):
14 - ACPI 6.2 Specification - Errata A, September 2017
15 **/
16
17 #include <IndustryStandard/Acpi.h>
18 #include <Library/UefiLib.h>
19 #include "AcpiParser.h"
20 #include "AcpiTableParser.h"
21
22 // Local Variables
23 STATIC CONST UINT8* MadtInterruptControllerType;
24 STATIC CONST UINT8* MadtInterruptControllerLength;
25 STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
26
27 /**
28 This function validates the System Vector Base in the GICD.
29
30 @param [in] Ptr Pointer to the start of the field data.
31 @param [in] Context Pointer to context specific information e.g. this
32 could be a pointer to the ACPI table header.
33 **/
34 STATIC
35 VOID
36 EFIAPI
37 ValidateGICDSystemVectorBase (
38 IN UINT8* Ptr,
39 IN VOID* Context
40 );
41
42 /**
43 An ACPI_PARSER array describing the GICC Interrupt Controller Structure.
44 **/
45 STATIC CONST ACPI_PARSER GicCParser[] = {
46 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
47 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
48 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
49
50 {L"CPU Interface Number", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
51 {L"ACPI Processor UID", 4, 8, L"0x%x", NULL, NULL, NULL, NULL},
52 {L"Flags", 4, 12, L"0x%x", NULL, NULL, NULL, NULL},
53 {L"Parking Protocol Version", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
54
55 {L"Performance Interrupt GSIV", 4, 20, L"0x%x", NULL, NULL, NULL, NULL},
56 {L"Parked Address", 8, 24, L"0x%lx", NULL, NULL, NULL, NULL},
57 {L"Physical Base Address", 8, 32, L"0x%lx", NULL, NULL, NULL, NULL},
58 {L"GICV", 8, 40, L"0x%lx", NULL, NULL, NULL, NULL},
59 {L"GICH", 8, 48, L"0x%lx", NULL, NULL, NULL, NULL},
60 {L"VGIC Maintenance interrupt", 4, 56, L"0x%x", NULL, NULL, NULL, NULL},
61 {L"GICR Base Address", 8, 60, L"0x%lx", NULL, NULL, NULL, NULL},
62 {L"MPIDR", 8, 68, L"0x%lx", NULL, NULL, NULL, NULL},
63 {L"Processor Power Efficiency Class", 1, 76, L"0x%x", NULL, NULL, NULL,
64 NULL},
65 {L"Reserved", 3, 77, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
66 };
67
68 /**
69 An ACPI_PARSER array describing the GICD Interrupt Controller Structure.
70 **/
71 STATIC CONST ACPI_PARSER GicDParser[] = {
72 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
73 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
74 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
75
76 {L"GIC ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
77 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
78 {L"System Vector Base", 4, 16, L"0x%x", NULL, NULL,
79 ValidateGICDSystemVectorBase, NULL},
80 {L"GIC Version", 1, 20, L"%d", NULL, NULL, NULL, NULL},
81 {L"Reserved", 3, 21, L"%x %x %x", Dump3Chars, NULL, NULL, NULL}
82 };
83
84 /**
85 An ACPI_PARSER array describing the MSI Frame Interrupt Controller Structure.
86 **/
87 STATIC CONST ACPI_PARSER GicMSIFrameParser[] = {
88 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
89 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
90 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
91
92 {L"MSI Frame ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
93 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
94 {L"Flags", 4, 16, L"0x%x", NULL, NULL, NULL, NULL},
95
96 {L"SPI Count", 2, 20, L"%d", NULL, NULL, NULL, NULL},
97 {L"SPI Base", 2, 22, L"0x%x", NULL, NULL, NULL, NULL}
98 };
99
100 /**
101 An ACPI_PARSER array describing the GICR Interrupt Controller Structure.
102 **/
103 STATIC CONST ACPI_PARSER GicRParser[] = {
104 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
105 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
106 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
107
108 {L"Discovery Range Base Address", 8, 4, L"0x%lx", NULL, NULL, NULL,
109 NULL},
110 {L"Discovery Range Length", 4, 12, L"0x%x", NULL, NULL, NULL, NULL}
111 };
112
113 /**
114 An ACPI_PARSER array describing the GIC ITS Interrupt Controller Structure.
115 **/
116 STATIC CONST ACPI_PARSER GicITSParser[] = {
117 {L"Type", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},
118 {L"Length", 1, 1, L"%d", NULL, NULL, NULL, NULL},
119 {L"Reserved", 2, 2, L"0x%x", NULL, NULL, NULL, NULL},
120
121 {L"GIC ITS ID", 4, 4, L"0x%x", NULL, NULL, NULL, NULL},
122 {L"Physical Base Address", 8, 8, L"0x%lx", NULL, NULL, NULL, NULL},
123 {L"Reserved", 4, 16, L"0x%x", NULL, NULL, NULL, NULL}
124 };
125
126 /**
127 An ACPI_PARSER array describing the ACPI MADT Table.
128 **/
129 STATIC CONST ACPI_PARSER MadtParser[] = {
130 PARSE_ACPI_HEADER (&AcpiHdrInfo),
131 {L"Local Interrupt Controller Address", 4, 36, L"0x%x", NULL, NULL, NULL,
132 NULL},
133 {L"Flags", 4, 40, L"0x%x", NULL, NULL, NULL, NULL}
134 };
135
136 /**
137 An ACPI_PARSER array describing the MADT Interrupt Controller Structure Header Structure.
138 **/
139 STATIC CONST ACPI_PARSER MadtInterruptControllerHeaderParser[] = {
140 {NULL, 1, 0, NULL, NULL, (VOID**)&MadtInterruptControllerType, NULL, NULL},
141 {L"Length", 1, 1, NULL, NULL, (VOID**)&MadtInterruptControllerLength, NULL,
142 NULL},
143 {L"Reserved", 2, 2, NULL, NULL, NULL, NULL, NULL}
144 };
145
146 /**
147 This function validates the System Vector Base in the GICD.
148
149 @param [in] Ptr Pointer to the start of the field data.
150 @param [in] Context Pointer to context specific information e.g. this
151 could be a pointer to the ACPI table header.
152 **/
153 STATIC
154 VOID
155 EFIAPI
156 ValidateGICDSystemVectorBase (
157 IN UINT8* Ptr,
158 IN VOID* Context
159 )
160 {
161 if (*(UINT32*)Ptr != 0) {
162 IncrementErrorCount ();
163 Print (
164 L"\nERROR: System Vector Base must be zero."
165 );
166 }
167 }
168
169 /**
170 This function parses the ACPI MADT table.
171 When trace is enabled this function parses the MADT table and
172 traces the ACPI table fields.
173
174 This function currently parses the following Interrupt Controller
175 Structures:
176 - GICC
177 - GICD
178 - GIC MSI Frame
179 - GICR
180 - GIC ITS
181
182 This function also performs validation of the ACPI table fields.
183
184 @param [in] Trace If TRUE, trace the ACPI fields.
185 @param [in] Ptr Pointer to the start of the buffer.
186 @param [in] AcpiTableLength Length of the ACPI table.
187 @param [in] AcpiTableRevision Revision of the ACPI table.
188 **/
189 VOID
190 EFIAPI
191 ParseAcpiMadt (
192 IN BOOLEAN Trace,
193 IN UINT8* Ptr,
194 IN UINT32 AcpiTableLength,
195 IN UINT8 AcpiTableRevision
196 )
197 {
198 UINT32 Offset;
199 UINT8* InterruptContollerPtr;
200 UINT32 GICDCount = 0;
201
202 if (!Trace) {
203 return;
204 }
205
206 Offset = ParseAcpi (
207 TRUE,
208 0,
209 "MADT",
210 Ptr,
211 AcpiTableLength,
212 PARSER_PARAMS (MadtParser)
213 );
214 InterruptContollerPtr = Ptr + Offset;
215
216 while (Offset < AcpiTableLength) {
217 // Parse Interrupt Controller Structure to obtain Length.
218 ParseAcpi (
219 FALSE,
220 0,
221 NULL,
222 InterruptContollerPtr,
223 2, // Length is 1 byte at offset 1
224 PARSER_PARAMS (MadtInterruptControllerHeaderParser)
225 );
226
227 if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
228 (*MadtInterruptControllerLength < 4)) {
229 IncrementErrorCount ();
230 Print (
231 L"ERROR: Invalid Interrupt Controller Length,"
232 " Type = %d, Length = %d\n",
233 *MadtInterruptControllerType,
234 *MadtInterruptControllerLength
235 );
236 break;
237 }
238
239 switch (*MadtInterruptControllerType) {
240 case EFI_ACPI_6_2_GIC: {
241 ParseAcpi (
242 TRUE,
243 2,
244 "GICC",
245 InterruptContollerPtr,
246 *MadtInterruptControllerLength,
247 PARSER_PARAMS (GicCParser)
248 );
249 break;
250 }
251
252 case EFI_ACPI_6_2_GICD: {
253 if (++GICDCount > 1) {
254 IncrementErrorCount ();
255 Print (
256 L"ERROR: Only one GICD must be present,"
257 " GICDCount = %d\n",
258 GICDCount
259 );
260 }
261 ParseAcpi (
262 TRUE,
263 2,
264 "GICD",
265 InterruptContollerPtr,
266 *MadtInterruptControllerLength,
267 PARSER_PARAMS (GicDParser)
268 );
269 break;
270 }
271
272 case EFI_ACPI_6_2_GIC_MSI_FRAME: {
273 ParseAcpi (
274 TRUE,
275 2,
276 "GIC MSI Frame",
277 InterruptContollerPtr,
278 *MadtInterruptControllerLength,
279 PARSER_PARAMS (GicMSIFrameParser)
280 );
281 break;
282 }
283
284 case EFI_ACPI_6_2_GICR: {
285 ParseAcpi (
286 TRUE,
287 2,
288 "GICR",
289 InterruptContollerPtr,
290 *MadtInterruptControllerLength,
291 PARSER_PARAMS (GicRParser)
292 );
293 break;
294 }
295
296 case EFI_ACPI_6_2_GIC_ITS: {
297 ParseAcpi (
298 TRUE,
299 2,
300 "GIC ITS",
301 InterruptContollerPtr,
302 *MadtInterruptControllerLength,
303 PARSER_PARAMS (GicITSParser)
304 );
305 break;
306 }
307
308 default: {
309 IncrementErrorCount ();
310 Print (
311 L"ERROR: Unknown Interrupt Controller Structure,"
312 " Type = %d, Length = %d\n",
313 *MadtInterruptControllerType,
314 *MadtInterruptControllerLength
315 );
316 }
317 } // switch
318
319 InterruptContollerPtr += *MadtInterruptControllerLength;
320 Offset += *MadtInterruptControllerLength;
321 } // while
322 }