]>
Commit | Line | Data |
---|---|---|
a6eaba4d | 1 | /** @file\r |
ee4dc24f RN |
2 | ACPI parser\r |
3 | \r | |
10bf6c40 | 4 | Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.\r |
56ba3746 | 5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r |
ee4dc24f RN |
6 | **/\r |
7 | \r | |
8 | #include <Uefi.h>\r | |
9 | #include <Library/UefiLib.h>\r | |
10 | #include <Library/UefiBootServicesTableLib.h>\r | |
11 | #include "AcpiParser.h"\r | |
12 | #include "AcpiView.h"\r | |
e18ac66d | 13 | #include "AcpiViewConfig.h"\r |
ee4dc24f RN |
14 | \r |
15 | STATIC UINT32 gIndent;\r | |
16 | STATIC UINT32 mTableErrorCount;\r | |
17 | STATIC UINT32 mTableWarningCount;\r | |
18 | \r | |
f75c7478 DB |
19 | STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;\r |
20 | \r | |
21 | /**\r | |
22 | An ACPI_PARSER array describing the ACPI header.\r | |
23 | **/\r | |
24 | STATIC CONST ACPI_PARSER AcpiHeaderParser[] = {\r | |
25 | PARSE_ACPI_HEADER (&AcpiHdrInfo)\r | |
26 | };\r | |
27 | \r | |
a6eaba4d DB |
28 | /**\r |
29 | This function resets the ACPI table error counter to Zero.\r | |
30 | **/\r | |
ee4dc24f RN |
31 | VOID\r |
32 | ResetErrorCount (\r | |
33 | VOID\r | |
34 | )\r | |
35 | {\r | |
36 | mTableErrorCount = 0;\r | |
37 | }\r | |
38 | \r | |
a6eaba4d DB |
39 | /**\r |
40 | This function returns the ACPI table error count.\r | |
ee4dc24f RN |
41 | \r |
42 | @retval Returns the count of errors detected in the ACPI tables.\r | |
a6eaba4d | 43 | **/\r |
ee4dc24f RN |
44 | UINT32\r |
45 | GetErrorCount (\r | |
46 | VOID\r | |
47 | )\r | |
48 | {\r | |
49 | return mTableErrorCount;\r | |
50 | }\r | |
51 | \r | |
a6eaba4d DB |
52 | /**\r |
53 | This function resets the ACPI table warning counter to Zero.\r | |
54 | **/\r | |
ee4dc24f RN |
55 | VOID\r |
56 | ResetWarningCount (\r | |
57 | VOID\r | |
58 | )\r | |
59 | {\r | |
60 | mTableWarningCount = 0;\r | |
61 | }\r | |
62 | \r | |
a6eaba4d DB |
63 | /**\r |
64 | This function returns the ACPI table warning count.\r | |
ee4dc24f RN |
65 | \r |
66 | @retval Returns the count of warning detected in the ACPI tables.\r | |
a6eaba4d | 67 | **/\r |
ee4dc24f RN |
68 | UINT32\r |
69 | GetWarningCount (\r | |
70 | VOID\r | |
71 | )\r | |
72 | {\r | |
73 | return mTableWarningCount;\r | |
74 | }\r | |
75 | \r | |
a6eaba4d DB |
76 | /**\r |
77 | This function increments the ACPI table error counter.\r | |
78 | **/\r | |
ee4dc24f RN |
79 | VOID\r |
80 | EFIAPI\r | |
81 | IncrementErrorCount (\r | |
82 | VOID\r | |
83 | )\r | |
84 | {\r | |
85 | mTableErrorCount++;\r | |
86 | }\r | |
87 | \r | |
a6eaba4d DB |
88 | /**\r |
89 | This function increments the ACPI table warning counter.\r | |
90 | **/\r | |
ee4dc24f RN |
91 | VOID\r |
92 | EFIAPI\r | |
93 | IncrementWarningCount (\r | |
94 | VOID\r | |
95 | )\r | |
96 | {\r | |
97 | mTableWarningCount++;\r | |
98 | }\r | |
99 | \r | |
a6eaba4d DB |
100 | /**\r |
101 | This function verifies the ACPI table checksum.\r | |
ee4dc24f RN |
102 | \r |
103 | This function verifies the checksum for the ACPI table and optionally\r | |
104 | prints the status.\r | |
105 | \r | |
106 | @param [in] Log If TRUE log the status of the checksum.\r | |
107 | @param [in] Ptr Pointer to the start of the table buffer.\r | |
108 | @param [in] Length The length of the buffer.\r | |
109 | \r | |
110 | @retval TRUE The checksum is OK.\r | |
111 | @retval FALSE The checksum failed.\r | |
a6eaba4d | 112 | **/\r |
ee4dc24f RN |
113 | BOOLEAN\r |
114 | EFIAPI\r | |
115 | VerifyChecksum (\r | |
116 | IN BOOLEAN Log,\r | |
117 | IN UINT8* Ptr,\r | |
118 | IN UINT32 Length\r | |
119 | )\r | |
120 | {\r | |
f75c7478 DB |
121 | UINTN ByteCount;\r |
122 | UINT8 Checksum;\r | |
ee4dc24f RN |
123 | UINTN OriginalAttribute;\r |
124 | \r | |
0154e02d SZ |
125 | //\r |
126 | // set local variables to suppress incorrect compiler/analyzer warnings\r | |
127 | //\r | |
128 | OriginalAttribute = 0;\r | |
f75c7478 DB |
129 | ByteCount = 0;\r |
130 | Checksum = 0;\r | |
131 | \r | |
ee4dc24f RN |
132 | while (ByteCount < Length) {\r |
133 | Checksum += *(Ptr++);\r | |
134 | ByteCount++;\r | |
135 | }\r | |
136 | \r | |
137 | if (Log) {\r | |
138 | OriginalAttribute = gST->ConOut->Mode->Attribute;\r | |
139 | if (Checksum == 0) {\r | |
140 | if (GetColourHighlighting ()) {\r | |
141 | gST->ConOut->SetAttribute (\r | |
142 | gST->ConOut,\r | |
143 | EFI_TEXT_ATTR (EFI_GREEN,\r | |
144 | ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))\r | |
145 | );\r | |
146 | }\r | |
5a119220 | 147 | Print (L"Table Checksum : OK\n\n");\r |
ee4dc24f RN |
148 | } else {\r |
149 | IncrementErrorCount ();\r | |
150 | if (GetColourHighlighting ()) {\r | |
151 | gST->ConOut->SetAttribute (\r | |
152 | gST->ConOut,\r | |
153 | EFI_TEXT_ATTR (EFI_RED,\r | |
154 | ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))\r | |
155 | );\r | |
156 | }\r | |
5a119220 | 157 | Print (L"Table Checksum : FAILED (0x%X)\n\n", Checksum);\r |
ee4dc24f RN |
158 | }\r |
159 | if (GetColourHighlighting ()) {\r | |
160 | gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);\r | |
161 | }\r | |
162 | }\r | |
163 | \r | |
164 | return (Checksum == 0);\r | |
165 | }\r | |
166 | \r | |
a6eaba4d DB |
167 | /**\r |
168 | This function performs a raw data dump of the ACPI table.\r | |
ee4dc24f RN |
169 | \r |
170 | @param [in] Ptr Pointer to the start of the table buffer.\r | |
171 | @param [in] Length The length of the buffer.\r | |
a6eaba4d | 172 | **/\r |
ee4dc24f RN |
173 | VOID\r |
174 | EFIAPI\r | |
175 | DumpRaw (\r | |
176 | IN UINT8* Ptr,\r | |
177 | IN UINT32 Length\r | |
178 | )\r | |
179 | {\r | |
f75c7478 | 180 | UINTN ByteCount;\r |
ee4dc24f | 181 | UINTN PartLineChars;\r |
f75c7478 | 182 | UINTN AsciiBufferIndex;\r |
ee4dc24f RN |
183 | CHAR8 AsciiBuffer[17];\r |
184 | \r | |
f75c7478 DB |
185 | ByteCount = 0;\r |
186 | AsciiBufferIndex = 0;\r | |
187 | \r | |
ee4dc24f RN |
188 | Print (L"Address : 0x%p\n", Ptr);\r |
189 | Print (L"Length : %d\n", Length);\r | |
190 | \r | |
191 | while (ByteCount < Length) {\r | |
192 | if ((ByteCount & 0x0F) == 0) {\r | |
193 | AsciiBuffer[AsciiBufferIndex] = '\0';\r | |
194 | Print (L" %a\n%08X : ", AsciiBuffer, ByteCount);\r | |
195 | AsciiBufferIndex = 0;\r | |
196 | } else if ((ByteCount & 0x07) == 0) {\r | |
197 | Print (L"- ");\r | |
198 | }\r | |
199 | \r | |
200 | if ((*Ptr >= ' ') && (*Ptr < 0x7F)) {\r | |
201 | AsciiBuffer[AsciiBufferIndex++] = *Ptr;\r | |
202 | } else {\r | |
203 | AsciiBuffer[AsciiBufferIndex++] = '.';\r | |
204 | }\r | |
205 | \r | |
206 | Print (L"%02X ", *Ptr++);\r | |
207 | \r | |
208 | ByteCount++;\r | |
209 | }\r | |
210 | \r | |
211 | // Justify the final line using spaces before printing\r | |
212 | // the ASCII data.\r | |
213 | PartLineChars = (Length & 0x0F);\r | |
214 | if (PartLineChars != 0) {\r | |
215 | PartLineChars = 48 - (PartLineChars * 3);\r | |
216 | if ((Length & 0x0F) <= 8) {\r | |
217 | PartLineChars += 2;\r | |
218 | }\r | |
219 | while (PartLineChars > 0) {\r | |
220 | Print (L" ");\r | |
221 | PartLineChars--;\r | |
222 | }\r | |
223 | }\r | |
224 | \r | |
225 | // Print ASCII data for the final line.\r | |
226 | AsciiBuffer[AsciiBufferIndex] = '\0';\r | |
5a119220 | 227 | Print (L" %a\n\n", AsciiBuffer);\r |
ee4dc24f RN |
228 | }\r |
229 | \r | |
a6eaba4d DB |
230 | /**\r |
231 | This function traces 1 byte of data as specified in the format string.\r | |
ee4dc24f RN |
232 | \r |
233 | @param [in] Format The format string for tracing the data.\r | |
234 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 235 | **/\r |
ee4dc24f RN |
236 | VOID\r |
237 | EFIAPI\r | |
238 | DumpUint8 (\r | |
239 | IN CONST CHAR16* Format,\r | |
240 | IN UINT8* Ptr\r | |
241 | )\r | |
242 | {\r | |
243 | Print (Format, *Ptr);\r | |
244 | }\r | |
245 | \r | |
a6eaba4d DB |
246 | /**\r |
247 | This function traces 2 bytes of data as specified in the format string.\r | |
ee4dc24f RN |
248 | \r |
249 | @param [in] Format The format string for tracing the data.\r | |
250 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 251 | **/\r |
ee4dc24f RN |
252 | VOID\r |
253 | EFIAPI\r | |
254 | DumpUint16 (\r | |
255 | IN CONST CHAR16* Format,\r | |
256 | IN UINT8* Ptr\r | |
257 | )\r | |
258 | {\r | |
259 | Print (Format, *(UINT16*)Ptr);\r | |
260 | }\r | |
261 | \r | |
a6eaba4d DB |
262 | /**\r |
263 | This function traces 4 bytes of data as specified in the format string.\r | |
ee4dc24f RN |
264 | \r |
265 | @param [in] Format The format string for tracing the data.\r | |
266 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 267 | **/\r |
ee4dc24f RN |
268 | VOID\r |
269 | EFIAPI\r | |
270 | DumpUint32 (\r | |
271 | IN CONST CHAR16* Format,\r | |
272 | IN UINT8* Ptr\r | |
273 | )\r | |
274 | {\r | |
275 | Print (Format, *(UINT32*)Ptr);\r | |
276 | }\r | |
277 | \r | |
a6eaba4d DB |
278 | /**\r |
279 | This function traces 8 bytes of data as specified by the format string.\r | |
ee4dc24f RN |
280 | \r |
281 | @param [in] Format The format string for tracing the data.\r | |
282 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 283 | **/\r |
ee4dc24f RN |
284 | VOID\r |
285 | EFIAPI\r | |
286 | DumpUint64 (\r | |
287 | IN CONST CHAR16* Format,\r | |
288 | IN UINT8* Ptr\r | |
289 | )\r | |
290 | {\r | |
291 | // Some fields are not aligned and this causes alignment faults\r | |
292 | // on ARM platforms if the compiler generates LDRD instructions.\r | |
293 | // Perform word access so that LDRD instructions are not generated.\r | |
f75c7478 DB |
294 | UINT64 Val;\r |
295 | \r | |
296 | Val = *(UINT32*)(Ptr + sizeof (UINT32));\r | |
297 | \r | |
5726bdd9 | 298 | Val = LShiftU64(Val,32);\r |
81038d50 | 299 | Val |= (UINT64)*(UINT32*)Ptr;\r |
ee4dc24f RN |
300 | \r |
301 | Print (Format, Val);\r | |
302 | }\r | |
303 | \r | |
a6eaba4d DB |
304 | /**\r |
305 | This function traces 3 characters which can be optionally\r | |
306 | formated using the format string if specified.\r | |
ee4dc24f RN |
307 | \r |
308 | If no format string is specified the Format must be NULL.\r | |
309 | \r | |
310 | @param [in] Format Optional format string for tracing the data.\r | |
311 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 312 | **/\r |
ee4dc24f RN |
313 | VOID\r |
314 | EFIAPI\r | |
315 | Dump3Chars (\r | |
316 | IN CONST CHAR16* Format OPTIONAL,\r | |
317 | IN UINT8* Ptr\r | |
318 | )\r | |
319 | {\r | |
320 | Print (\r | |
321 | (Format != NULL) ? Format : L"%c%c%c",\r | |
322 | Ptr[0],\r | |
323 | Ptr[1],\r | |
324 | Ptr[2]\r | |
325 | );\r | |
326 | }\r | |
327 | \r | |
a6eaba4d DB |
328 | /**\r |
329 | This function traces 4 characters which can be optionally\r | |
330 | formated using the format string if specified.\r | |
ee4dc24f RN |
331 | \r |
332 | If no format string is specified the Format must be NULL.\r | |
333 | \r | |
334 | @param [in] Format Optional format string for tracing the data.\r | |
335 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 336 | **/\r |
ee4dc24f RN |
337 | VOID\r |
338 | EFIAPI\r | |
339 | Dump4Chars (\r | |
340 | IN CONST CHAR16* Format OPTIONAL,\r | |
341 | IN UINT8* Ptr\r | |
342 | )\r | |
343 | {\r | |
344 | Print (\r | |
345 | (Format != NULL) ? Format : L"%c%c%c%c",\r | |
346 | Ptr[0],\r | |
347 | Ptr[1],\r | |
348 | Ptr[2],\r | |
349 | Ptr[3]\r | |
350 | );\r | |
351 | }\r | |
352 | \r | |
a6eaba4d DB |
353 | /**\r |
354 | This function traces 6 characters which can be optionally\r | |
355 | formated using the format string if specified.\r | |
ee4dc24f RN |
356 | \r |
357 | If no format string is specified the Format must be NULL.\r | |
358 | \r | |
359 | @param [in] Format Optional format string for tracing the data.\r | |
360 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 361 | **/\r |
ee4dc24f RN |
362 | VOID\r |
363 | EFIAPI\r | |
364 | Dump6Chars (\r | |
365 | IN CONST CHAR16* Format OPTIONAL,\r | |
366 | IN UINT8* Ptr\r | |
367 | )\r | |
368 | {\r | |
369 | Print (\r | |
370 | (Format != NULL) ? Format : L"%c%c%c%c%c%c",\r | |
371 | Ptr[0],\r | |
372 | Ptr[1],\r | |
373 | Ptr[2],\r | |
374 | Ptr[3],\r | |
375 | Ptr[4],\r | |
376 | Ptr[5]\r | |
377 | );\r | |
378 | }\r | |
379 | \r | |
a6eaba4d DB |
380 | /**\r |
381 | This function traces 8 characters which can be optionally\r | |
382 | formated using the format string if specified.\r | |
ee4dc24f RN |
383 | \r |
384 | If no format string is specified the Format must be NULL.\r | |
385 | \r | |
386 | @param [in] Format Optional format string for tracing the data.\r | |
387 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 388 | **/\r |
ee4dc24f RN |
389 | VOID\r |
390 | EFIAPI\r | |
391 | Dump8Chars (\r | |
392 | IN CONST CHAR16* Format OPTIONAL,\r | |
393 | IN UINT8* Ptr\r | |
394 | )\r | |
395 | {\r | |
396 | Print (\r | |
397 | (Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c",\r | |
398 | Ptr[0],\r | |
399 | Ptr[1],\r | |
400 | Ptr[2],\r | |
401 | Ptr[3],\r | |
402 | Ptr[4],\r | |
403 | Ptr[5],\r | |
404 | Ptr[6],\r | |
405 | Ptr[7]\r | |
406 | );\r | |
407 | }\r | |
408 | \r | |
710ff749 KK |
409 | /**\r |
410 | This function traces 12 characters which can be optionally\r | |
411 | formated using the format string if specified.\r | |
412 | \r | |
413 | If no format string is specified the Format must be NULL.\r | |
414 | \r | |
415 | @param [in] Format Optional format string for tracing the data.\r | |
416 | @param [in] Ptr Pointer to the start of the buffer.\r | |
417 | **/\r | |
418 | VOID\r | |
419 | EFIAPI\r | |
420 | Dump12Chars (\r | |
421 | IN CONST CHAR16* Format OPTIONAL,\r | |
422 | IN UINT8* Ptr\r | |
423 | )\r | |
424 | {\r | |
425 | Print (\r | |
426 | (Format != NULL) ? Format : L"%c%c%c%c%c%c%c%c%c%c%c%c",\r | |
427 | Ptr[0],\r | |
428 | Ptr[1],\r | |
429 | Ptr[2],\r | |
430 | Ptr[3],\r | |
431 | Ptr[4],\r | |
432 | Ptr[5],\r | |
433 | Ptr[6],\r | |
434 | Ptr[7],\r | |
435 | Ptr[8],\r | |
436 | Ptr[9],\r | |
437 | Ptr[10],\r | |
438 | Ptr[11]\r | |
439 | );\r | |
440 | }\r | |
441 | \r | |
a6eaba4d DB |
442 | /**\r |
443 | This function indents and prints the ACPI table Field Name.\r | |
ee4dc24f RN |
444 | \r |
445 | @param [in] Indent Number of spaces to add to the global table indent.\r | |
446 | The global table indent is 0 by default; however\r | |
447 | this value is updated on entry to the ParseAcpi()\r | |
448 | by adding the indent value provided to ParseAcpi()\r | |
449 | and restored back on exit.\r | |
450 | Therefore the total indent in the output is\r | |
451 | dependent on from where this function is called.\r | |
452 | @param [in] FieldName Pointer to the Field Name.\r | |
a6eaba4d | 453 | **/\r |
ee4dc24f RN |
454 | VOID\r |
455 | EFIAPI\r | |
456 | PrintFieldName (\r | |
457 | IN UINT32 Indent,\r | |
458 | IN CONST CHAR16* FieldName\r | |
459 | )\r | |
460 | {\r | |
461 | Print (\r | |
462 | L"%*a%-*s : ",\r | |
463 | gIndent + Indent,\r | |
464 | "",\r | |
465 | (OUTPUT_FIELD_COLUMN_WIDTH - gIndent - Indent),\r | |
466 | FieldName\r | |
467 | );\r | |
468 | }\r | |
469 | \r | |
a6eaba4d DB |
470 | /**\r |
471 | This function is used to parse an ACPI table buffer.\r | |
ee4dc24f RN |
472 | \r |
473 | The ACPI table buffer is parsed using the ACPI table parser information\r | |
474 | specified by a pointer to an array of ACPI_PARSER elements. This parser\r | |
475 | function iterates through each item on the ACPI_PARSER array and logs the\r | |
476 | ACPI table fields.\r | |
477 | \r | |
478 | This function can optionally be used to parse ACPI tables and fetch specific\r | |
479 | field values. The ItemPtr member of the ACPI_PARSER structure (where used)\r | |
480 | is updated by this parser function to point to the selected field data\r | |
481 | (e.g. useful for variable length nested fields).\r | |
482 | \r | |
483 | @param [in] Trace Trace the ACPI fields TRUE else only parse the\r | |
484 | table.\r | |
485 | @param [in] Indent Number of spaces to indent the output.\r | |
486 | @param [in] AsciiName Optional pointer to an ASCII string that describes\r | |
487 | the table being parsed.\r | |
488 | @param [in] Ptr Pointer to the start of the buffer.\r | |
489 | @param [in] Length Length of the buffer pointed by Ptr.\r | |
490 | @param [in] Parser Pointer to an array of ACPI_PARSER structure that\r | |
491 | describes the table being parsed.\r | |
492 | @param [in] ParserItems Number of items in the ACPI_PARSER array.\r | |
493 | \r | |
494 | @retval Number of bytes parsed.\r | |
a6eaba4d | 495 | **/\r |
ee4dc24f RN |
496 | UINT32\r |
497 | EFIAPI\r | |
498 | ParseAcpi (\r | |
499 | IN BOOLEAN Trace,\r | |
500 | IN UINT32 Indent,\r | |
501 | IN CONST CHAR8* AsciiName OPTIONAL,\r | |
502 | IN UINT8* Ptr,\r | |
503 | IN UINT32 Length,\r | |
504 | IN CONST ACPI_PARSER* Parser,\r | |
505 | IN UINT32 ParserItems\r | |
506 | )\r | |
507 | {\r | |
508 | UINT32 Index;\r | |
f75c7478 DB |
509 | UINT32 Offset;\r |
510 | BOOLEAN HighLight;\r | |
ed874680 | 511 | UINTN OriginalAttribute;\r |
f75c7478 | 512 | \r |
0154e02d SZ |
513 | //\r |
514 | // set local variables to suppress incorrect compiler/analyzer warnings\r | |
515 | //\r | |
516 | OriginalAttribute = 0;\r | |
f75c7478 | 517 | Offset = 0;\r |
ee4dc24f RN |
518 | \r |
519 | // Increment the Indent\r | |
520 | gIndent += Indent;\r | |
521 | \r | |
522 | if (Trace && (AsciiName != NULL)){\r | |
f75c7478 | 523 | HighLight = GetColourHighlighting ();\r |
ee4dc24f RN |
524 | \r |
525 | if (HighLight) {\r | |
526 | OriginalAttribute = gST->ConOut->Mode->Attribute;\r | |
527 | gST->ConOut->SetAttribute (\r | |
528 | gST->ConOut,\r | |
529 | EFI_TEXT_ATTR(EFI_YELLOW,\r | |
530 | ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4))\r | |
531 | );\r | |
532 | }\r | |
533 | Print (\r | |
534 | L"%*a%-*a :\n",\r | |
535 | gIndent,\r | |
536 | "",\r | |
537 | (OUTPUT_FIELD_COLUMN_WIDTH - gIndent),\r | |
538 | AsciiName\r | |
539 | );\r | |
540 | if (HighLight) {\r | |
541 | gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);\r | |
542 | }\r | |
543 | }\r | |
544 | \r | |
545 | for (Index = 0; Index < ParserItems; Index++) {\r | |
546 | if ((Offset + Parser[Index].Length) > Length) {\r | |
5bd326c5 KK |
547 | \r |
548 | // For fields outside the buffer length provided, reset any pointers\r | |
549 | // which were supposed to be updated by this function call\r | |
550 | if (Parser[Index].ItemPtr != NULL) {\r | |
551 | *Parser[Index].ItemPtr = NULL;\r | |
552 | }\r | |
553 | \r | |
ee4dc24f | 554 | // We don't parse past the end of the max length specified\r |
5bd326c5 | 555 | continue;\r |
ee4dc24f RN |
556 | }\r |
557 | \r | |
f73843d5 KK |
558 | if (GetConsistencyChecking () &&\r |
559 | (Offset != Parser[Index].Offset)) {\r | |
ee4dc24f RN |
560 | IncrementErrorCount ();\r |
561 | Print (\r | |
562 | L"\nERROR: %a: Offset Mismatch for %s\n"\r | |
e6f958d1 | 563 | L"CurrentOffset = %d FieldOffset = %d\n",\r |
ee4dc24f RN |
564 | AsciiName,\r |
565 | Parser[Index].NameStr,\r | |
566 | Offset,\r | |
567 | Parser[Index].Offset\r | |
568 | );\r | |
569 | }\r | |
570 | \r | |
571 | if (Trace) {\r | |
572 | // if there is a Formatter function let the function handle\r | |
573 | // the printing else if a Format is specified in the table use\r | |
574 | // the Format for printing\r | |
575 | PrintFieldName (2, Parser[Index].NameStr);\r | |
576 | if (Parser[Index].PrintFormatter != NULL) {\r | |
577 | Parser[Index].PrintFormatter (Parser[Index].Format, Ptr);\r | |
578 | } else if (Parser[Index].Format != NULL) {\r | |
579 | switch (Parser[Index].Length) {\r | |
580 | case 1:\r | |
581 | DumpUint8 (Parser[Index].Format, Ptr);\r | |
582 | break;\r | |
583 | case 2:\r | |
584 | DumpUint16 (Parser[Index].Format, Ptr);\r | |
585 | break;\r | |
586 | case 4:\r | |
587 | DumpUint32 (Parser[Index].Format, Ptr);\r | |
588 | break;\r | |
589 | case 8:\r | |
590 | DumpUint64 (Parser[Index].Format, Ptr);\r | |
591 | break;\r | |
592 | default:\r | |
593 | Print (\r | |
594 | L"\nERROR: %a: CANNOT PARSE THIS FIELD, Field Length = %d\n",\r | |
595 | AsciiName,\r | |
596 | Parser[Index].Length\r | |
597 | );\r | |
598 | } // switch\r | |
856cf5ab SM |
599 | }\r |
600 | // Validating only makes sense if we are tracing\r | |
601 | // the parsed table entries, to report by table name.\r | |
602 | if (GetConsistencyChecking () &&\r | |
603 | (Parser[Index].FieldValidator != NULL)) {\r | |
604 | Parser[Index].FieldValidator (Ptr, Parser[Index].Context);\r | |
ee4dc24f RN |
605 | }\r |
606 | Print (L"\n");\r | |
607 | } // if (Trace)\r | |
608 | \r | |
609 | if (Parser[Index].ItemPtr != NULL) {\r | |
610 | *Parser[Index].ItemPtr = (VOID*)Ptr;\r | |
611 | }\r | |
612 | \r | |
613 | Ptr += Parser[Index].Length;\r | |
614 | Offset += Parser[Index].Length;\r | |
615 | } // for\r | |
616 | \r | |
617 | // Decrement the Indent\r | |
618 | gIndent -= Indent;\r | |
619 | return Offset;\r | |
620 | }\r | |
621 | \r | |
a6eaba4d DB |
622 | /**\r |
623 | An array describing the ACPI Generic Address Structure.\r | |
ee4dc24f RN |
624 | The GasParser array is used by the ParseAcpi function to parse and/or trace\r |
625 | the GAS structure.\r | |
a6eaba4d | 626 | **/\r |
ee4dc24f RN |
627 | STATIC CONST ACPI_PARSER GasParser[] = {\r |
628 | {L"Address Space ID", 1, 0, L"0x%x", NULL, NULL, NULL, NULL},\r | |
629 | {L"Register Bit Width", 1, 1, L"0x%x", NULL, NULL, NULL, NULL},\r | |
630 | {L"Register Bit Offset", 1, 2, L"0x%x", NULL, NULL, NULL, NULL},\r | |
10bf6c40 | 631 | {L"Access Size", 1, 3, L"0x%x", NULL, NULL, NULL, NULL},\r |
ee4dc24f RN |
632 | {L"Address", 8, 4, L"0x%lx", NULL, NULL, NULL, NULL}\r |
633 | };\r | |
634 | \r | |
a6eaba4d DB |
635 | /**\r |
636 | This function indents and traces the GAS structure as described by the GasParser.\r | |
ee4dc24f RN |
637 | \r |
638 | @param [in] Ptr Pointer to the start of the buffer.\r | |
639 | @param [in] Indent Number of spaces to indent the output.\r | |
58cc0ffe KK |
640 | @param [in] Length Length of the GAS structure buffer.\r |
641 | \r | |
642 | @retval Number of bytes parsed.\r | |
a6eaba4d | 643 | **/\r |
58cc0ffe | 644 | UINT32\r |
ee4dc24f RN |
645 | EFIAPI\r |
646 | DumpGasStruct (\r | |
647 | IN UINT8* Ptr,\r | |
58cc0ffe KK |
648 | IN UINT32 Indent,\r |
649 | IN UINT32 Length\r | |
ee4dc24f RN |
650 | )\r |
651 | {\r | |
652 | Print (L"\n");\r | |
58cc0ffe KK |
653 | return ParseAcpi (\r |
654 | TRUE,\r | |
655 | Indent,\r | |
656 | NULL,\r | |
657 | Ptr,\r | |
658 | Length,\r | |
659 | PARSER_PARAMS (GasParser)\r | |
660 | );\r | |
ee4dc24f RN |
661 | }\r |
662 | \r | |
a6eaba4d DB |
663 | /**\r |
664 | This function traces the GAS structure as described by the GasParser.\r | |
ee4dc24f RN |
665 | \r |
666 | @param [in] Format Optional format string for tracing the data.\r | |
667 | @param [in] Ptr Pointer to the start of the buffer.\r | |
a6eaba4d | 668 | **/\r |
ee4dc24f RN |
669 | VOID\r |
670 | EFIAPI\r | |
671 | DumpGas (\r | |
672 | IN CONST CHAR16* Format OPTIONAL,\r | |
673 | IN UINT8* Ptr\r | |
674 | )\r | |
675 | {\r | |
0b9026a8 | 676 | DumpGasStruct (Ptr, 2, sizeof (EFI_ACPI_6_3_GENERIC_ADDRESS_STRUCTURE));\r |
ee4dc24f RN |
677 | }\r |
678 | \r | |
a6eaba4d DB |
679 | /**\r |
680 | This function traces the ACPI header as described by the AcpiHeaderParser.\r | |
ee4dc24f RN |
681 | \r |
682 | @param [in] Ptr Pointer to the start of the buffer.\r | |
683 | \r | |
684 | @retval Number of bytes parsed.\r | |
a6eaba4d | 685 | **/\r |
ee4dc24f RN |
686 | UINT32\r |
687 | EFIAPI\r | |
688 | DumpAcpiHeader (\r | |
689 | IN UINT8* Ptr\r | |
690 | )\r | |
691 | {\r | |
ee4dc24f RN |
692 | return ParseAcpi (\r |
693 | TRUE,\r | |
694 | 0,\r | |
695 | "ACPI Table Header",\r | |
696 | Ptr,\r | |
0b9026a8 | 697 | sizeof (EFI_ACPI_DESCRIPTION_HEADER),\r |
ee4dc24f RN |
698 | PARSER_PARAMS (AcpiHeaderParser)\r |
699 | );\r | |
700 | }\r | |
701 | \r | |
a6eaba4d DB |
702 | /**\r |
703 | This function parses the ACPI header as described by the AcpiHeaderParser.\r | |
ee4dc24f RN |
704 | \r |
705 | This function optionally returns the signature, length and revision of the\r | |
706 | ACPI table.\r | |
707 | \r | |
708 | @param [in] Ptr Pointer to the start of the buffer.\r | |
709 | @param [out] Signature Gets location of the ACPI table signature.\r | |
710 | @param [out] Length Gets location of the length of the ACPI table.\r | |
711 | @param [out] Revision Gets location of the revision of the ACPI table.\r | |
712 | \r | |
713 | @retval Number of bytes parsed.\r | |
a6eaba4d | 714 | **/\r |
ee4dc24f RN |
715 | UINT32\r |
716 | EFIAPI\r | |
717 | ParseAcpiHeader (\r | |
718 | IN UINT8* Ptr,\r | |
719 | OUT CONST UINT32** Signature,\r | |
720 | OUT CONST UINT32** Length,\r | |
721 | OUT CONST UINT8** Revision\r | |
722 | )\r | |
723 | {\r | |
724 | UINT32 BytesParsed;\r | |
ee4dc24f RN |
725 | \r |
726 | BytesParsed = ParseAcpi (\r | |
727 | FALSE,\r | |
728 | 0,\r | |
729 | NULL,\r | |
730 | Ptr,\r | |
0b9026a8 | 731 | sizeof (EFI_ACPI_DESCRIPTION_HEADER),\r |
ee4dc24f RN |
732 | PARSER_PARAMS (AcpiHeaderParser)\r |
733 | );\r | |
734 | \r | |
735 | *Signature = AcpiHdrInfo.Signature;\r | |
736 | *Length = AcpiHdrInfo.Length;\r | |
737 | *Revision = AcpiHdrInfo.Revision;\r | |
738 | \r | |
739 | return BytesParsed;\r | |
740 | }\r |