AcpiView.c 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340
  1. /** @file
  2. Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
  3. SPDX-License-Identifier: BSD-2-Clause-Patent
  4. @par Glossary:
  5. - Sbbr or SBBR - Server Base Boot Requirements
  6. @par Reference(s):
  7. - Arm Server Base Boot Requirements 1.2, September 2019
  8. **/
  9. #include <Library/PrintLib.h>
  10. #include <Library/UefiLib.h>
  11. #include <Library/ShellLib.h>
  12. #include <Library/UefiBootServicesTableLib.h>
  13. #include <Library/BaseMemoryLib.h>
  14. #include <Library/DebugLib.h>
  15. #include <Library/MemoryAllocationLib.h>
  16. #include <Library/AcpiViewCommandLib.h>
  17. #include "AcpiParser.h"
  18. #include "AcpiTableParser.h"
  19. #include "AcpiView.h"
  20. #include "AcpiViewConfig.h"
  21. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  22. #include "Arm/SbbrValidator.h"
  23. #endif
  24. STATIC UINT32 mTableCount;
  25. STATIC UINT32 mBinTableCount;
  26. /**
  27. This function dumps the ACPI table to a file.
  28. @param [in] Ptr Pointer to the ACPI table data.
  29. @param [in] Length The length of the ACPI table.
  30. @retval TRUE Success.
  31. @retval FALSE Failure.
  32. **/
  33. STATIC
  34. BOOLEAN
  35. DumpAcpiTableToFile (
  36. IN CONST UINT8 *Ptr,
  37. IN CONST UINTN Length
  38. )
  39. {
  40. CHAR16 FileNameBuffer[MAX_FILE_NAME_LEN];
  41. UINTN TransferBytes;
  42. SELECTED_ACPI_TABLE *SelectedTable;
  43. GetSelectedAcpiTable (&SelectedTable);
  44. UnicodeSPrint (
  45. FileNameBuffer,
  46. sizeof (FileNameBuffer),
  47. L".\\%s%04d.bin",
  48. SelectedTable->Name,
  49. mBinTableCount++
  50. );
  51. Print (L"Dumping ACPI table to : %s ... ", FileNameBuffer);
  52. TransferBytes = ShellDumpBufferToFile (FileNameBuffer, Ptr, Length);
  53. return (Length == TransferBytes);
  54. }
  55. /**
  56. This function processes the table reporting options for the ACPI table.
  57. @param [in] Signature The ACPI table Signature.
  58. @param [in] TablePtr Pointer to the ACPI table data.
  59. @param [in] Length The length fo the ACPI table.
  60. @retval Returns TRUE if the ACPI table should be traced.
  61. **/
  62. BOOLEAN
  63. ProcessTableReportOptions (
  64. IN CONST UINT32 Signature,
  65. IN CONST UINT8 *TablePtr,
  66. IN CONST UINT32 Length
  67. )
  68. {
  69. UINTN OriginalAttribute;
  70. UINT8 *SignaturePtr;
  71. BOOLEAN Log;
  72. BOOLEAN HighLight;
  73. SELECTED_ACPI_TABLE *SelectedTable;
  74. //
  75. // set local variables to suppress incorrect compiler/analyzer warnings
  76. //
  77. OriginalAttribute = 0;
  78. SignaturePtr = (UINT8 *)(UINTN)&Signature;
  79. Log = FALSE;
  80. HighLight = GetColourHighlighting ();
  81. GetSelectedAcpiTable (&SelectedTable);
  82. switch (GetReportOption ()) {
  83. case ReportAll:
  84. Log = TRUE;
  85. break;
  86. case ReportSelected:
  87. if (Signature == SelectedTable->Type) {
  88. Log = TRUE;
  89. SelectedTable->Found = TRUE;
  90. }
  91. break;
  92. case ReportTableList:
  93. if (mTableCount == 0) {
  94. if (HighLight) {
  95. OriginalAttribute = gST->ConOut->Mode->Attribute;
  96. gST->ConOut->SetAttribute (
  97. gST->ConOut,
  98. EFI_TEXT_ATTR (
  99. EFI_CYAN,
  100. ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
  101. )
  102. );
  103. }
  104. Print (L"\nInstalled Table(s):\n");
  105. if (HighLight) {
  106. gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
  107. }
  108. }
  109. Print (
  110. L"\t%4d. %c%c%c%c\n",
  111. ++mTableCount,
  112. SignaturePtr[0],
  113. SignaturePtr[1],
  114. SignaturePtr[2],
  115. SignaturePtr[3]
  116. );
  117. break;
  118. case ReportDumpBinFile:
  119. if (Signature == SelectedTable->Type) {
  120. SelectedTable->Found = TRUE;
  121. DumpAcpiTableToFile (TablePtr, Length);
  122. }
  123. break;
  124. case ReportMax:
  125. // We should never be here.
  126. // This case is only present to prevent compiler warning.
  127. break;
  128. } // switch
  129. if (Log) {
  130. if (HighLight) {
  131. OriginalAttribute = gST->ConOut->Mode->Attribute;
  132. gST->ConOut->SetAttribute (
  133. gST->ConOut,
  134. EFI_TEXT_ATTR (
  135. EFI_LIGHTBLUE,
  136. ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
  137. )
  138. );
  139. }
  140. Print (
  141. L"\n\n --------------- %c%c%c%c Table --------------- \n\n",
  142. SignaturePtr[0],
  143. SignaturePtr[1],
  144. SignaturePtr[2],
  145. SignaturePtr[3]
  146. );
  147. if (HighLight) {
  148. gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
  149. }
  150. }
  151. return Log;
  152. }
  153. /**
  154. This function iterates the configuration table entries in the
  155. system table, retrieves the RSDP pointer and starts parsing the ACPI tables.
  156. @param [in] SystemTable Pointer to the EFI system table.
  157. @retval Returns EFI_NOT_FOUND if the RSDP pointer is not found.
  158. Returns EFI_UNSUPPORTED if the RSDP version is less than 2.
  159. Returns EFI_SUCCESS if successful.
  160. **/
  161. EFI_STATUS
  162. EFIAPI
  163. AcpiView (
  164. IN EFI_SYSTEM_TABLE *SystemTable
  165. )
  166. {
  167. EFI_STATUS Status;
  168. UINTN Index;
  169. EFI_CONFIGURATION_TABLE *EfiConfigurationTable;
  170. BOOLEAN FoundAcpiTable;
  171. UINTN OriginalAttribute;
  172. UINTN PrintAttribute;
  173. EREPORT_OPTION ReportOption;
  174. UINT8 *RsdpPtr;
  175. UINT32 RsdpLength;
  176. UINT8 RsdpRevision;
  177. PARSE_ACPI_TABLE_PROC RsdpParserProc;
  178. BOOLEAN Trace;
  179. SELECTED_ACPI_TABLE *SelectedTable;
  180. //
  181. // set local variables to suppress incorrect compiler/analyzer warnings
  182. //
  183. EfiConfigurationTable = NULL;
  184. OriginalAttribute = 0;
  185. // Reset Table counts
  186. mTableCount = 0;
  187. mBinTableCount = 0;
  188. // Reset The error/warning counters
  189. ResetErrorCount ();
  190. ResetWarningCount ();
  191. // Retrieve the user selection of ACPI table to process
  192. GetSelectedAcpiTable (&SelectedTable);
  193. // Search the table for an entry that matches the ACPI Table Guid
  194. FoundAcpiTable = FALSE;
  195. for (Index = 0; Index < SystemTable->NumberOfTableEntries; Index++) {
  196. if (CompareGuid (
  197. &gEfiAcpiTableGuid,
  198. &(SystemTable->ConfigurationTable[Index].VendorGuid)
  199. ))
  200. {
  201. EfiConfigurationTable = &SystemTable->ConfigurationTable[Index];
  202. FoundAcpiTable = TRUE;
  203. break;
  204. }
  205. }
  206. if (FoundAcpiTable) {
  207. RsdpPtr = (UINT8 *)EfiConfigurationTable->VendorTable;
  208. // The RSDP revision is 1 byte starting at offset 15
  209. RsdpRevision = *(RsdpPtr + RSDP_REVISION_OFFSET);
  210. if (RsdpRevision < 2) {
  211. Print (
  212. L"ERROR: RSDP version less than 2 is not supported.\n"
  213. );
  214. return EFI_UNSUPPORTED;
  215. }
  216. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  217. if (GetMandatoryTableValidate ()) {
  218. ArmSbbrResetTableCounts ();
  219. }
  220. #endif
  221. // The RSDP length is 4 bytes starting at offset 20
  222. RsdpLength = *(UINT32 *)(RsdpPtr + RSDP_LENGTH_OFFSET);
  223. Trace = ProcessTableReportOptions (RSDP_TABLE_INFO, RsdpPtr, RsdpLength);
  224. Status = GetParser (RSDP_TABLE_INFO, &RsdpParserProc);
  225. if (EFI_ERROR (Status)) {
  226. Print (
  227. L"ERROR: No registered parser found for RSDP.\n"
  228. );
  229. return Status;
  230. }
  231. RsdpParserProc (
  232. Trace,
  233. RsdpPtr,
  234. RsdpLength,
  235. RsdpRevision
  236. );
  237. } else {
  238. IncrementErrorCount ();
  239. Print (
  240. L"ERROR: Failed to find ACPI Table Guid in System Configuration Table.\n"
  241. );
  242. return EFI_NOT_FOUND;
  243. }
  244. #if defined (MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
  245. if (GetMandatoryTableValidate ()) {
  246. ArmSbbrReqsValidate ((ARM_SBBR_VERSION)GetMandatoryTableSpec ());
  247. }
  248. #endif
  249. ReportOption = GetReportOption ();
  250. if (ReportTableList != ReportOption) {
  251. if (((ReportSelected == ReportOption) ||
  252. (ReportDumpBinFile == ReportOption)) &&
  253. (!SelectedTable->Found))
  254. {
  255. Print (L"\nRequested ACPI Table not found.\n");
  256. } else if (GetConsistencyChecking () &&
  257. (ReportDumpBinFile != ReportOption))
  258. {
  259. OriginalAttribute = gST->ConOut->Mode->Attribute;
  260. Print (L"\nTable Statistics:\n");
  261. if (GetColourHighlighting ()) {
  262. PrintAttribute = (GetErrorCount () > 0) ?
  263. EFI_TEXT_ATTR (
  264. EFI_RED,
  265. ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
  266. ) :
  267. OriginalAttribute;
  268. gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute);
  269. }
  270. Print (L"\t%d Error(s)\n", GetErrorCount ());
  271. if (GetColourHighlighting ()) {
  272. PrintAttribute = (GetWarningCount () > 0) ?
  273. EFI_TEXT_ATTR (
  274. EFI_RED,
  275. ((OriginalAttribute&(BIT4|BIT5|BIT6))>>4)
  276. ) :
  277. OriginalAttribute;
  278. gST->ConOut->SetAttribute (gST->ConOut, PrintAttribute);
  279. }
  280. Print (L"\t%d Warning(s)\n", GetWarningCount ());
  281. if (GetColourHighlighting ()) {
  282. gST->ConOut->SetAttribute (gST->ConOut, OriginalAttribute);
  283. }
  284. }
  285. }
  286. return EFI_SUCCESS;
  287. }