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