]> 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;
201
202 GICDCount = 0;
203
204 if (!Trace) {
205 return;
206 }
207
208 Offset = ParseAcpi (
209 TRUE,
210 0,
211 "MADT",
212 Ptr,
213 AcpiTableLength,
214 PARSER_PARAMS (MadtParser)
215 );
216 InterruptContollerPtr = Ptr + Offset;
217
218 while (Offset < AcpiTableLength) {
219 // Parse Interrupt Controller Structure to obtain Length.
220 ParseAcpi (
221 FALSE,
222 0,
223 NULL,
224 InterruptContollerPtr,
225 2, // Length is 1 byte at offset 1
226 PARSER_PARAMS (MadtInterruptControllerHeaderParser)
227 );
228
229 if (((Offset + (*MadtInterruptControllerLength)) > AcpiTableLength) ||
230 (*MadtInterruptControllerLength < 4)) {
231 IncrementErrorCount ();
232 Print (
233 L"ERROR: Invalid Interrupt Controller Length,"
234 " Type = %d, Length = %d\n",
235 *MadtInterruptControllerType,
236 *MadtInterruptControllerLength
237 );
238 break;
239 }
240
241 switch (*MadtInterruptControllerType) {
242 case EFI_ACPI_6_2_GIC: {
243 ParseAcpi (
244 TRUE,
245 2,
246 "GICC",
247 InterruptContollerPtr,
248 *MadtInterruptControllerLength,
249 PARSER_PARAMS (GicCParser)
250 );
251 break;
252 }
253
254 case EFI_ACPI_6_2_GICD: {
255 if (++GICDCount > 1) {
256 IncrementErrorCount ();
257 Print (
258 L"ERROR: Only one GICD must be present,"
259 " GICDCount = %d\n",
260 GICDCount
261 );
262 }
263 ParseAcpi (
264 TRUE,
265 2,
266 "GICD",
267 InterruptContollerPtr,
268 *MadtInterruptControllerLength,
269 PARSER_PARAMS (GicDParser)
270 );
271 break;
272 }
273
274 case EFI_ACPI_6_2_GIC_MSI_FRAME: {
275 ParseAcpi (
276 TRUE,
277 2,
278 "GIC MSI Frame",
279 InterruptContollerPtr,
280 *MadtInterruptControllerLength,
281 PARSER_PARAMS (GicMSIFrameParser)
282 );
283 break;
284 }
285
286 case EFI_ACPI_6_2_GICR: {
287 ParseAcpi (
288 TRUE,
289 2,
290 "GICR",
291 InterruptContollerPtr,
292 *MadtInterruptControllerLength,
293 PARSER_PARAMS (GicRParser)
294 );
295 break;
296 }
297
298 case EFI_ACPI_6_2_GIC_ITS: {
299 ParseAcpi (
300 TRUE,
301 2,
302 "GIC ITS",
303 InterruptContollerPtr,
304 *MadtInterruptControllerLength,
305 PARSER_PARAMS (GicITSParser)
306 );
307 break;
308 }
309
310 default: {
311 IncrementErrorCount ();
312 Print (
313 L"ERROR: Unknown Interrupt Controller Structure,"
314 " Type = %d, Length = %d\n",
315 *MadtInterruptControllerType,
316 *MadtInterruptControllerLength
317 );
318 }
319 } // switch
320
321 InterruptContollerPtr += *MadtInterruptControllerLength;
322 Offset += *MadtInterruptControllerLength;
323 } // while
324 }