AcpiTableParser.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. /** @file
  2. ACPI table parser
  3. Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
  4. SPDX-License-Identifier: BSD-2-Clause-Patent
  5. @par Glossary:
  6. - Sbbr or SBBR - Server Base Boot Requirements
  7. @par Reference(s):
  8. - Arm Server Base Boot Requirements 1.2, September 2019
  9. **/
  10. #include <Uefi.h>
  11. #include <IndustryStandard/Acpi.h>
  12. #include <Library/UefiLib.h>
  13. #include "AcpiParser.h"
  14. #include "AcpiTableParser.h"
  15. #include "AcpiView.h"
  16. #include "AcpiViewConfig.h"
  17. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  18. #include "Arm/SbbrValidator.h"
  19. #endif
  20. /**
  21. A list of registered ACPI table parsers.
  22. **/
  23. STATIC ACPI_TABLE_PARSER mTableParserList[MAX_ACPI_TABLE_PARSERS];
  24. /**
  25. Register the ACPI table Parser
  26. This function registers the ACPI table parser.
  27. @param [in] Signature The ACPI table signature.
  28. @param [in] ParserProc The ACPI table parser.
  29. @retval EFI_SUCCESS The parser is registered.
  30. @retval EFI_INVALID_PARAMETER A parameter is invalid.
  31. @retval EFI_ALREADY_STARTED The parser for the Table
  32. was already registered.
  33. @retval EFI_OUT_OF_RESOURCES No space to register the
  34. parser.
  35. **/
  36. EFI_STATUS
  37. EFIAPI
  38. RegisterParser (
  39. IN UINT32 Signature,
  40. IN PARSE_ACPI_TABLE_PROC ParserProc
  41. )
  42. {
  43. UINT32 Index;
  44. if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
  45. return EFI_INVALID_PARAMETER;
  46. }
  47. // Search if a parser is already installed
  48. for (Index = 0;
  49. Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
  50. Index++)
  51. {
  52. if (Signature == mTableParserList[Index].Signature) {
  53. if (mTableParserList[Index].Parser != NULL) {
  54. return EFI_ALREADY_STARTED;
  55. }
  56. }
  57. }
  58. // Find the first free slot and register the parser
  59. for (Index = 0;
  60. Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
  61. Index++)
  62. {
  63. if (mTableParserList[Index].Signature == ACPI_PARSER_SIGNATURE_NULL) {
  64. mTableParserList[Index].Signature = Signature;
  65. mTableParserList[Index].Parser = ParserProc;
  66. return EFI_SUCCESS;
  67. }
  68. }
  69. // No free slot found
  70. return EFI_OUT_OF_RESOURCES;
  71. }
  72. /**
  73. Deregister the ACPI table Parser
  74. This function deregisters the ACPI table parser.
  75. @param [in] Signature The ACPI table signature.
  76. @retval EFI_SUCCESS The parser was deregistered.
  77. @retval EFI_INVALID_PARAMETER A parameter is invalid.
  78. @retval EFI_NOT_FOUND A registered parser was not found.
  79. **/
  80. EFI_STATUS
  81. EFIAPI
  82. DeregisterParser (
  83. IN UINT32 Signature
  84. )
  85. {
  86. UINT32 Index;
  87. if (Signature == ACPI_PARSER_SIGNATURE_NULL) {
  88. return EFI_INVALID_PARAMETER;
  89. }
  90. for (Index = 0;
  91. Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
  92. Index++)
  93. {
  94. if (Signature == mTableParserList[Index].Signature) {
  95. mTableParserList[Index].Signature = ACPI_PARSER_SIGNATURE_NULL;
  96. mTableParserList[Index].Parser = NULL;
  97. return EFI_SUCCESS;
  98. }
  99. }
  100. // No matching registered parser found.
  101. return EFI_NOT_FOUND;
  102. }
  103. /**
  104. Get the ACPI table Parser
  105. This function returns the ACPI table parser proc from the list of
  106. registered parsers.
  107. @param [in] Signature The ACPI table signature.
  108. @param [out] ParserProc Pointer to a ACPI table parser proc.
  109. @retval EFI_SUCCESS The parser was returned successfully.
  110. @retval EFI_INVALID_PARAMETER A parameter is invalid.
  111. @retval EFI_NOT_FOUND A registered parser was not found.
  112. **/
  113. EFI_STATUS
  114. EFIAPI
  115. GetParser (
  116. IN UINT32 Signature,
  117. OUT PARSE_ACPI_TABLE_PROC *ParserProc
  118. )
  119. {
  120. UINT32 Index;
  121. if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
  122. return EFI_INVALID_PARAMETER;
  123. }
  124. for (Index = 0;
  125. Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
  126. Index++)
  127. {
  128. if (Signature == mTableParserList[Index].Signature) {
  129. *ParserProc = mTableParserList[Index].Parser;
  130. return EFI_SUCCESS;
  131. }
  132. }
  133. // No matching registered parser found.
  134. return EFI_NOT_FOUND;
  135. }
  136. /**
  137. This function processes the ACPI tables.
  138. This function calls ProcessTableReportOptions() to list the ACPI
  139. tables, perform binary dump of the tables and determine if the
  140. ACPI fields should be traced.
  141. This function also invokes the parser for the ACPI tables.
  142. This function also performs a RAW dump of the ACPI table including
  143. the unknown/unparsed ACPI tables and validates the checksum.
  144. @param [in] Ptr Pointer to the start of the ACPI
  145. table data buffer.
  146. **/
  147. VOID
  148. EFIAPI
  149. ProcessAcpiTable (
  150. IN UINT8 *Ptr
  151. )
  152. {
  153. EFI_STATUS Status;
  154. BOOLEAN Trace;
  155. CONST UINT32 *AcpiTableSignature;
  156. CONST UINT32 *AcpiTableLength;
  157. CONST UINT8 *AcpiTableRevision;
  158. CONST UINT8 *SignaturePtr;
  159. PARSE_ACPI_TABLE_PROC ParserProc;
  160. ParseAcpiHeader (
  161. Ptr,
  162. &AcpiTableSignature,
  163. &AcpiTableLength,
  164. &AcpiTableRevision
  165. );
  166. Trace = ProcessTableReportOptions (
  167. *AcpiTableSignature,
  168. Ptr,
  169. *AcpiTableLength
  170. );
  171. if (Trace) {
  172. DumpRaw (Ptr, *AcpiTableLength);
  173. // Do not process the ACPI table any further if the table length read
  174. // is invalid. The ACPI table should at least contain the table header.
  175. if (*AcpiTableLength < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
  176. SignaturePtr = (CONST UINT8 *)AcpiTableSignature;
  177. IncrementErrorCount ();
  178. Print (
  179. L"ERROR: Invalid %c%c%c%c table length. Length = %d\n",
  180. SignaturePtr[0],
  181. SignaturePtr[1],
  182. SignaturePtr[2],
  183. SignaturePtr[3],
  184. *AcpiTableLength
  185. );
  186. return;
  187. }
  188. if (GetConsistencyChecking ()) {
  189. VerifyChecksum (TRUE, Ptr, *AcpiTableLength);
  190. }
  191. }
  192. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  193. if (GetMandatoryTableValidate ()) {
  194. ArmSbbrIncrementTableCount (*AcpiTableSignature);
  195. }
  196. #endif
  197. Status = GetParser (*AcpiTableSignature, &ParserProc);
  198. if (EFI_ERROR (Status)) {
  199. // No registered parser found, do default handling.
  200. if (Trace) {
  201. DumpAcpiHeader (Ptr);
  202. }
  203. return;
  204. }
  205. ParserProc (
  206. Trace,
  207. Ptr,
  208. *AcpiTableLength,
  209. *AcpiTableRevision
  210. );
  211. }