3 Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
4 SPDX-License-Identifier: BSD-2-Clause-Patent
7 - Sbbr or SBBR - Server Base Boot Requirements
10 - Arm Server Base Boot Requirements 1.2, September 2019
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 "AcpiParser.h"
21 #include "AcpiTableParser.h"
23 #include "AcpiViewConfig.h"
24 #include "UefiShellAcpiViewCommandLib.h"
26 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
27 #include "Arm/SbbrValidator.h"
30 EFI_HII_HANDLE gShellAcpiViewHiiHandle
= NULL
;
32 STATIC UINT32 mTableCount
;
33 STATIC UINT32 mBinTableCount
;
36 An array of acpiview command line parameters.
38 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
49 This function dumps the ACPI table to a file.
51 @param [in] Ptr Pointer to the ACPI table data.
52 @param [in] Length The length of the ACPI table.
55 @retval FALSE Failure.
65 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
66 SHELL_FILE_HANDLE DumpFileHandle
;
68 SELECTED_ACPI_TABLE
*SelectedTable
;
70 DumpFileHandle
= NULL
;
71 TransferBytes
= Length
;
72 GetSelectedAcpiTable (&SelectedTable
);
76 sizeof (FileNameBuffer
),
82 Status
= ShellOpenFileByName (
85 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
88 if (EFI_ERROR (Status
)) {
93 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
94 gShellAcpiViewHiiHandle
,
100 Print (L
"Dumping ACPI table to : %s ... ", FileNameBuffer
);
102 Status
= ShellWriteFile (
107 if (EFI_ERROR (Status
)) {
108 Print (L
"ERROR: Failed to dump table to binary file.\n");
114 ShellCloseFile (&DumpFileHandle
);
115 return (Length
== TransferBytes
);
119 This function processes the table reporting options for the ACPI table.
121 @param [in] Signature The ACPI table Signature.
122 @param [in] TablePtr Pointer to the ACPI table data.
123 @param [in] Length The length fo the ACPI table.
125 @retval Returns TRUE if the ACPI table should be traced.
128 ProcessTableReportOptions (
129 IN CONST UINT32 Signature
,
130 IN CONST UINT8
* TablePtr
,
131 IN CONST UINT32 Length
134 UINTN OriginalAttribute
;
138 SELECTED_ACPI_TABLE
*SelectedTable
;
141 // set local variables to suppress incorrect compiler/analyzer warnings
143 OriginalAttribute
= 0;
144 SignaturePtr
= (UINT8
*)(UINTN
)&Signature
;
146 HighLight
= GetColourHighlighting ();
147 GetSelectedAcpiTable (&SelectedTable
);
149 switch (GetReportOption ()) {
154 if (Signature
== SelectedTable
->Type
) {
156 SelectedTable
->Found
= TRUE
;
159 case ReportTableList
:
160 if (mTableCount
== 0) {
162 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
163 gST
->ConOut
->SetAttribute (
165 EFI_TEXT_ATTR(EFI_CYAN
,
166 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
169 Print (L
"\nInstalled Table(s):\n");
171 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
175 L
"\t%4d. %c%c%c%c\n",
183 case ReportDumpBinFile
:
184 if (Signature
== SelectedTable
->Type
) {
185 SelectedTable
->Found
= TRUE
;
186 DumpAcpiTableToFile (TablePtr
, Length
);
190 // We should never be here.
191 // This case is only present to prevent compiler warning.
197 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
198 gST
->ConOut
->SetAttribute (
200 EFI_TEXT_ATTR(EFI_LIGHTBLUE
,
201 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
205 L
"\n\n --------------- %c%c%c%c Table --------------- \n\n",
212 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
222 This function iterates the configuration table entries in the
223 system table, retrieves the RSDP pointer and starts parsing the ACPI tables.
225 @param [in] SystemTable Pointer to the EFI system table.
227 @retval Returns EFI_NOT_FOUND if the RSDP pointer is not found.
228 Returns EFI_UNSUPPORTED if the RSDP version is less than 2.
229 Returns EFI_SUCCESS if successful.
235 IN EFI_SYSTEM_TABLE
* SystemTable
240 EFI_CONFIGURATION_TABLE
* EfiConfigurationTable
;
241 BOOLEAN FoundAcpiTable
;
242 UINTN OriginalAttribute
;
243 UINTN PrintAttribute
;
244 EREPORT_OPTION ReportOption
;
248 PARSE_ACPI_TABLE_PROC RsdpParserProc
;
250 SELECTED_ACPI_TABLE
*SelectedTable
;
253 // set local variables to suppress incorrect compiler/analyzer warnings
255 EfiConfigurationTable
= NULL
;
256 OriginalAttribute
= 0;
258 // Reset The error/warning counters
260 ResetWarningCount ();
262 // Retrieve the user selection of ACPI table to process
263 GetSelectedAcpiTable (&SelectedTable
);
265 // Search the table for an entry that matches the ACPI Table Guid
266 FoundAcpiTable
= FALSE
;
267 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
268 if (CompareGuid (&gEfiAcpiTableGuid
,
269 &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
270 EfiConfigurationTable
= &SystemTable
->ConfigurationTable
[Index
];
271 FoundAcpiTable
= TRUE
;
276 if (FoundAcpiTable
) {
277 RsdpPtr
= (UINT8
*)EfiConfigurationTable
->VendorTable
;
279 // The RSDP revision is 1 byte starting at offset 15
280 RsdpRevision
= *(RsdpPtr
+ RSDP_REVISION_OFFSET
);
282 if (RsdpRevision
< 2) {
284 L
"ERROR: RSDP version less than 2 is not supported.\n"
286 return EFI_UNSUPPORTED
;
289 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
290 if (GetMandatoryTableValidate ()) {
291 ArmSbbrResetTableCounts ();
295 // The RSDP length is 4 bytes starting at offset 20
296 RsdpLength
= *(UINT32
*)(RsdpPtr
+ RSDP_LENGTH_OFFSET
);
298 Trace
= ProcessTableReportOptions (RSDP_TABLE_INFO
, RsdpPtr
, RsdpLength
);
300 Status
= GetParser (RSDP_TABLE_INFO
, &RsdpParserProc
);
301 if (EFI_ERROR (Status
)) {
303 L
"ERROR: No registered parser found for RSDP.\n"
316 IncrementErrorCount ();
318 L
"ERROR: Failed to find ACPI Table Guid in System Configuration Table.\n"
320 return EFI_NOT_FOUND
;
323 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
324 if (GetMandatoryTableValidate ()) {
325 ArmSbbrReqsValidate ((ARM_SBBR_VERSION
)GetMandatoryTableSpec ());
329 ReportOption
= GetReportOption ();
330 if (ReportTableList
!= ReportOption
) {
331 if (((ReportSelected
== ReportOption
) ||
332 (ReportDumpBinFile
== ReportOption
)) &&
333 (!SelectedTable
->Found
)) {
334 Print (L
"\nRequested ACPI Table not found.\n");
335 } else if (GetConsistencyChecking () &&
336 (ReportDumpBinFile
!= ReportOption
)) {
337 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
339 Print (L
"\nTable Statistics:\n");
341 if (GetColourHighlighting ()) {
342 PrintAttribute
= (GetErrorCount () > 0) ?
345 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
348 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
350 Print (L
"\t%d Error(s)\n", GetErrorCount ());
352 if (GetColourHighlighting ()) {
353 PrintAttribute
= (GetWarningCount () > 0) ?
356 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
360 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
362 Print (L
"\t%d Warning(s)\n", GetWarningCount ());
364 if (GetColourHighlighting ()) {
365 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
373 Function for 'acpiview' command.
375 @param[in] ImageHandle Handle to the Image (NULL if Internal).
376 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
380 ShellCommandRunAcpiView (
381 IN EFI_HANDLE ImageHandle
,
382 IN EFI_SYSTEM_TABLE
* SystemTable
386 SHELL_STATUS ShellStatus
;
388 CHAR16
* ProblemParam
;
389 SHELL_FILE_HANDLE TmpDumpFileHandle
;
390 CONST CHAR16
* MandatoryTableSpecStr
;
391 CONST CHAR16
*SelectedTableName
;
396 AcpiConfigSetDefaults ();
398 ShellStatus
= SHELL_SUCCESS
;
400 TmpDumpFileHandle
= NULL
;
402 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
403 if (EFI_ERROR (Status
)) {
404 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
409 STRING_TOKEN (STR_GEN_PROBLEM
),
410 gShellAcpiViewHiiHandle
,
414 FreePool (ProblemParam
);
416 Print (L
"acpiview: Error processing input parameter(s)\n");
418 ShellStatus
= SHELL_INVALID_PARAMETER
;
420 if (ShellCommandLineGetCount (Package
) > 1) {
425 STRING_TOKEN (STR_GEN_TOO_MANY
),
426 gShellAcpiViewHiiHandle
,
429 ShellStatus
= SHELL_INVALID_PARAMETER
;
430 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
435 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
436 gShellAcpiViewHiiHandle
,
439 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
440 ShellCommandLineGetValue (Package
, L
"-s") == NULL
) {
445 STRING_TOKEN (STR_GEN_NO_VALUE
),
446 gShellAcpiViewHiiHandle
,
450 ShellStatus
= SHELL_INVALID_PARAMETER
;
451 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
452 ShellCommandLineGetValue (Package
, L
"-r") == NULL
) {
457 STRING_TOKEN (STR_GEN_NO_VALUE
),
458 gShellAcpiViewHiiHandle
,
462 ShellStatus
= SHELL_INVALID_PARAMETER
;
463 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
464 ShellCommandLineGetFlag (Package
, L
"-l"))) {
469 STRING_TOKEN (STR_GEN_TOO_MANY
),
470 gShellAcpiViewHiiHandle
,
473 ShellStatus
= SHELL_INVALID_PARAMETER
;
474 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
475 !ShellCommandLineGetFlag (Package
, L
"-s")) {
480 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
481 gShellAcpiViewHiiHandle
,
486 ShellStatus
= SHELL_INVALID_PARAMETER
;
488 // Turn on colour highlighting if requested
489 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
491 // Surpress consistency checking if requested
492 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
494 // Evaluate the parameters for mandatory ACPI table presence checks
495 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
496 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
498 if (MandatoryTableSpecStr
!= NULL
) {
499 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
502 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
503 SetReportOption (ReportTableList
);
505 SelectedTableName
= ShellCommandLineGetValue (Package
, L
"-s");
506 if (SelectedTableName
!= NULL
) {
507 SelectAcpiTable (SelectedTableName
);
508 SetReportOption (ReportSelected
);
510 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
511 // Create a temporary file to check if the media is writable.
512 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
513 SetReportOption (ReportDumpBinFile
);
517 sizeof (FileNameBuffer
),
523 Status
= ShellOpenFileByName (
526 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
527 EFI_FILE_MODE_CREATE
,
531 if (EFI_ERROR (Status
)) {
532 ShellStatus
= SHELL_INVALID_PARAMETER
;
533 TmpDumpFileHandle
= NULL
;
538 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
539 gShellAcpiViewHiiHandle
,
544 // Delete Temporary file.
545 ShellDeleteFile (&TmpDumpFileHandle
);
550 // Parse ACPI Table information
551 Status
= AcpiView (SystemTable
);
552 if (EFI_ERROR (Status
)) {
553 ShellStatus
= SHELL_NOT_FOUND
;
559 if (Package
!= NULL
) {
560 ShellCommandLineFreeVarList (Package
);