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