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