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