XsdtParser.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. /** @file
  2. XSDT table parser
  3. Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Reference(s):
  6. - ACPI 6.2 Specification - Errata A, September 2017
  7. **/
  8. #include <IndustryStandard/Acpi.h>
  9. #include <Library/UefiLib.h>
  10. #include <Library/PrintLib.h>
  11. #include "AcpiParser.h"
  12. #include "AcpiTableParser.h"
  13. // Local variables
  14. STATIC ACPI_DESCRIPTION_HEADER_INFO AcpiHdrInfo;
  15. /** An ACPI_PARSER array describing the ACPI XSDT table.
  16. */
  17. STATIC CONST ACPI_PARSER XsdtParser[] = {
  18. PARSE_ACPI_HEADER (&AcpiHdrInfo)
  19. };
  20. /**
  21. Get the ACPI XSDT header info.
  22. **/
  23. CONST ACPI_DESCRIPTION_HEADER_INFO *
  24. EFIAPI
  25. GetAcpiXsdtHeaderInfo (
  26. VOID
  27. )
  28. {
  29. return &AcpiHdrInfo;
  30. }
  31. /**
  32. This function parses the ACPI XSDT table and optionally traces the ACPI table fields.
  33. This function also performs validation of the XSDT table.
  34. @param [in] Trace If TRUE, trace the ACPI fields.
  35. @param [in] Ptr Pointer to the start of the buffer.
  36. @param [in] AcpiTableLength Length of the ACPI table.
  37. @param [in] AcpiTableRevision Revision of the ACPI table.
  38. **/
  39. VOID
  40. EFIAPI
  41. ParseAcpiXsdt (
  42. IN BOOLEAN Trace,
  43. IN UINT8 *Ptr,
  44. IN UINT32 AcpiTableLength,
  45. IN UINT8 AcpiTableRevision
  46. )
  47. {
  48. UINT32 Offset;
  49. UINT32 TableOffset;
  50. UINT64 *TablePointer;
  51. UINTN EntryIndex;
  52. CHAR16 Buffer[32];
  53. Offset = ParseAcpi (
  54. Trace,
  55. 0,
  56. "XSDT",
  57. Ptr,
  58. AcpiTableLength,
  59. PARSER_PARAMS (XsdtParser)
  60. );
  61. TableOffset = Offset;
  62. if (Trace) {
  63. EntryIndex = 0;
  64. TablePointer = (UINT64 *)(Ptr + TableOffset);
  65. while (Offset < AcpiTableLength) {
  66. CONST UINT32 *Signature;
  67. CONST UINT32 *Length;
  68. CONST UINT8 *Revision;
  69. if ((UINT64 *)(UINTN)(*TablePointer) != NULL) {
  70. UINT8 *SignaturePtr;
  71. ParseAcpiHeader (
  72. (UINT8 *)(UINTN)(*TablePointer),
  73. &Signature,
  74. &Length,
  75. &Revision
  76. );
  77. SignaturePtr = (UINT8 *)Signature;
  78. UnicodeSPrint (
  79. Buffer,
  80. sizeof (Buffer),
  81. L"Entry[%d] - %c%c%c%c",
  82. EntryIndex++,
  83. SignaturePtr[0],
  84. SignaturePtr[1],
  85. SignaturePtr[2],
  86. SignaturePtr[3]
  87. );
  88. } else {
  89. UnicodeSPrint (
  90. Buffer,
  91. sizeof (Buffer),
  92. L"Entry[%d]",
  93. EntryIndex++
  94. );
  95. }
  96. PrintFieldName (2, Buffer);
  97. Print (L"0x%lx\n", *TablePointer);
  98. // Validate the table pointers are not NULL
  99. if ((UINT64 *)(UINTN)(*TablePointer) == NULL) {
  100. IncrementErrorCount ();
  101. Print (
  102. L"ERROR: Invalid table entry at 0x%lx, table address is 0x%lx\n",
  103. TablePointer,
  104. *TablePointer
  105. );
  106. }
  107. Offset += sizeof (UINT64);
  108. TablePointer++;
  109. } // while
  110. }
  111. // Process the tables
  112. Offset = TableOffset;
  113. TablePointer = (UINT64 *)(Ptr + TableOffset);
  114. while (Offset < AcpiTableLength) {
  115. if ((UINT64 *)(UINTN)(*TablePointer) != NULL) {
  116. ProcessAcpiTable ((UINT8 *)(UINTN)(*TablePointer));
  117. }
  118. Offset += sizeof (UINT64);
  119. TablePointer++;
  120. } // while
  121. }