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 "UefiShellAcpiViewCommandLib.h"
25 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
26 #include "Arm/SbbrValidator.h"
29 EFI_HII_HANDLE gShellAcpiViewHiiHandle
= NULL
;
32 STATIC UINT32 mSelectedAcpiTable
;
33 STATIC CONST CHAR16
* mSelectedAcpiTableName
;
34 STATIC BOOLEAN mSelectedAcpiTableFound
;
35 STATIC EREPORT_OPTION mReportType
;
36 STATIC UINT32 mTableCount
;
37 STATIC UINT32 mBinTableCount
;
38 STATIC BOOLEAN mConsistencyCheck
;
39 STATIC BOOLEAN mColourHighlighting
;
40 STATIC BOOLEAN mMandatoryTableValidate
;
41 STATIC UINTN mMandatoryTableSpec
;
44 An array of acpiview command line parameters.
46 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
57 This function returns the colour highlighting status.
59 @retval TRUE if colour highlighting is enabled.
62 GetColourHighlighting (
66 return mColourHighlighting
;
70 This function sets the colour highlighting status.
72 @param Highlight The Highlight status.
76 SetColourHighlighting (
80 mColourHighlighting
= Highlight
;
84 This function returns the consistency checking status.
86 @retval TRUE if consistency checking is enabled.
89 GetConsistencyChecking (
93 return mConsistencyCheck
;
97 This function sets the consistency checking status.
99 @param ConsistencyChecking The consistency checking status.
103 SetConsistencyChecking (
104 BOOLEAN ConsistencyChecking
107 mConsistencyCheck
= ConsistencyChecking
;
111 This function returns the ACPI table requirements validation flag.
113 @retval TRUE if check for mandatory table presence should be performed.
116 GetMandatoryTableValidate (
120 return mMandatoryTableValidate
;
124 This function sets the ACPI table requirements validation flag.
126 @param Validate Enable/Disable ACPI table requirements validation.
129 SetMandatoryTableValidate (
133 mMandatoryTableValidate
= Validate
;
137 This function returns the identifier of specification to validate ACPI table
138 requirements against.
140 @return ID of specification listing mandatory tables.
143 GetMandatoryTableSpec (
147 return mMandatoryTableSpec
;
151 This function sets the identifier of specification to validate ACPI table
152 requirements against.
154 @param Spec ID of specification listing mandatory tables.
157 SetMandatoryTableSpec (
161 mMandatoryTableSpec
= Spec
;
165 This function returns the report options.
167 @retval Returns the report option.
179 This function returns the selected ACPI table.
181 @retval Returns signature of the selected ACPI table.
185 GetSelectedAcpiTable (
189 return mSelectedAcpiTable
;
193 This function dumps the ACPI table to a file.
195 @param [in] Ptr Pointer to the ACPI table data.
196 @param [in] Length The length of the ACPI table.
198 @retval TRUE Success.
199 @retval FALSE Failure.
203 DumpAcpiTableToFile (
205 IN CONST UINTN Length
209 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
210 SHELL_FILE_HANDLE DumpFileHandle
;
213 DumpFileHandle
= NULL
;
214 TransferBytes
= Length
;
218 sizeof (FileNameBuffer
),
220 mSelectedAcpiTableName
,
224 Status
= ShellOpenFileByName (
227 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
230 if (EFI_ERROR (Status
)) {
235 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
236 gShellAcpiViewHiiHandle
,
242 Print (L
"Dumping ACPI table to : %s ... ", FileNameBuffer
);
244 Status
= ShellWriteFile (
249 if (EFI_ERROR (Status
)) {
250 Print (L
"ERROR: Failed to dump table to binary file.\n");
256 ShellCloseFile (&DumpFileHandle
);
257 return (Length
== TransferBytes
);
261 This function processes the table reporting options for the ACPI table.
263 @param [in] Signature The ACPI table Signature.
264 @param [in] TablePtr Pointer to the ACPI table data.
265 @param [in] Length The length fo the ACPI table.
267 @retval Returns TRUE if the ACPI table should be traced.
270 ProcessTableReportOptions (
271 IN CONST UINT32 Signature
,
272 IN CONST UINT8
* TablePtr
,
273 IN CONST UINT32 Length
276 UINTN OriginalAttribute
;
282 // set local variables to suppress incorrect compiler/analyzer warnings
284 OriginalAttribute
= 0;
285 SignaturePtr
= (UINT8
*)(UINTN
)&Signature
;
287 HighLight
= GetColourHighlighting ();
289 switch (GetReportOption ()) {
294 if (Signature
== GetSelectedAcpiTable ()) {
296 mSelectedAcpiTableFound
= TRUE
;
299 case ReportTableList
:
300 if (mTableCount
== 0) {
302 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
303 gST
->ConOut
->SetAttribute (
305 EFI_TEXT_ATTR(EFI_CYAN
,
306 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
309 Print (L
"\nInstalled Table(s):\n");
311 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
315 L
"\t%4d. %c%c%c%c\n",
323 case ReportDumpBinFile
:
324 if (Signature
== GetSelectedAcpiTable ()) {
325 mSelectedAcpiTableFound
= TRUE
;
326 DumpAcpiTableToFile (TablePtr
, Length
);
330 // We should never be here.
331 // This case is only present to prevent compiler warning.
337 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
338 gST
->ConOut
->SetAttribute (
340 EFI_TEXT_ATTR(EFI_LIGHTBLUE
,
341 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
345 L
"\n\n --------------- %c%c%c%c Table --------------- \n\n",
352 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
360 This function converts a string to ACPI table signature.
362 @param [in] Str Pointer to the string to be converted to the
363 ACPI table signature.
365 @retval The ACPI table signature.
369 ConvertStrToAcpiSignature (
376 ZeroMem (Ptr
, sizeof (Ptr
));
379 // Convert to Upper case and convert to ASCII
380 while ((Index
< 4) && (Str
[Index
] != 0)) {
381 if (Str
[Index
] >= L
'a' && Str
[Index
] <= L
'z') {
382 Ptr
[Index
] = (CHAR8
)(Str
[Index
] - (L
'a' - L
'A'));
384 Ptr
[Index
] = (CHAR8
)Str
[Index
];
388 return *(UINT32
*)Ptr
;
392 This function iterates the configuration table entries in the
393 system table, retrieves the RSDP pointer and starts parsing the ACPI tables.
395 @param [in] SystemTable Pointer to the EFI system table.
397 @retval Returns EFI_NOT_FOUND if the RSDP pointer is not found.
398 Returns EFI_UNSUPPORTED if the RSDP version is less than 2.
399 Returns EFI_SUCCESS if successful.
405 IN EFI_SYSTEM_TABLE
* SystemTable
410 EFI_CONFIGURATION_TABLE
* EfiConfigurationTable
;
411 BOOLEAN FoundAcpiTable
;
412 UINTN OriginalAttribute
;
413 UINTN PrintAttribute
;
414 EREPORT_OPTION ReportOption
;
418 PARSE_ACPI_TABLE_PROC RsdpParserProc
;
422 // set local variables to suppress incorrect compiler/analyzer warnings
424 EfiConfigurationTable
= NULL
;
425 OriginalAttribute
= 0;
427 // Search the table for an entry that matches the ACPI Table Guid
428 FoundAcpiTable
= FALSE
;
429 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
430 if (CompareGuid (&gEfiAcpiTableGuid
,
431 &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
432 EfiConfigurationTable
= &SystemTable
->ConfigurationTable
[Index
];
433 FoundAcpiTable
= TRUE
;
438 if (FoundAcpiTable
) {
439 RsdpPtr
= (UINT8
*)EfiConfigurationTable
->VendorTable
;
441 // The RSDP revision is 1 byte starting at offset 15
442 RsdpRevision
= *(RsdpPtr
+ RSDP_REVISION_OFFSET
);
444 if (RsdpRevision
< 2) {
446 L
"ERROR: RSDP version less than 2 is not supported.\n"
448 return EFI_UNSUPPORTED
;
451 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
452 if (GetMandatoryTableValidate ()) {
453 ArmSbbrResetTableCounts ();
457 // The RSDP length is 4 bytes starting at offset 20
458 RsdpLength
= *(UINT32
*)(RsdpPtr
+ RSDP_LENGTH_OFFSET
);
460 Trace
= ProcessTableReportOptions (RSDP_TABLE_INFO
, RsdpPtr
, RsdpLength
);
462 Status
= GetParser (RSDP_TABLE_INFO
, &RsdpParserProc
);
463 if (EFI_ERROR (Status
)) {
465 L
"ERROR: No registered parser found for RSDP.\n"
478 IncrementErrorCount ();
480 L
"ERROR: Failed to find ACPI Table Guid in System Configuration Table.\n"
482 return EFI_NOT_FOUND
;
485 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
486 if (GetMandatoryTableValidate ()) {
487 ArmSbbrReqsValidate ((ARM_SBBR_VERSION
)GetMandatoryTableSpec ());
491 ReportOption
= GetReportOption ();
492 if (ReportTableList
!= ReportOption
) {
493 if (((ReportSelected
== ReportOption
) ||
494 (ReportDumpBinFile
== ReportOption
)) &&
495 (!mSelectedAcpiTableFound
)) {
496 Print (L
"\nRequested ACPI Table not found.\n");
497 } else if (GetConsistencyChecking () &&
498 (ReportDumpBinFile
!= ReportOption
)) {
499 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
501 Print (L
"\nTable Statistics:\n");
503 if (GetColourHighlighting ()) {
504 PrintAttribute
= (GetErrorCount () > 0) ?
507 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
510 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
512 Print (L
"\t%d Error(s)\n", GetErrorCount ());
514 if (GetColourHighlighting ()) {
515 PrintAttribute
= (GetWarningCount () > 0) ?
518 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
522 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
524 Print (L
"\t%d Warning(s)\n", GetWarningCount ());
526 if (GetColourHighlighting ()) {
527 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
535 Function for 'acpiview' command.
537 @param[in] ImageHandle Handle to the Image (NULL if Internal).
538 @param[in] SystemTable Pointer to the System Table (NULL if Internal).
542 ShellCommandRunAcpiView (
543 IN EFI_HANDLE ImageHandle
,
544 IN EFI_SYSTEM_TABLE
* SystemTable
548 SHELL_STATUS ShellStatus
;
550 CHAR16
* ProblemParam
;
551 SHELL_FILE_HANDLE TmpDumpFileHandle
;
552 CONST CHAR16
* MandatoryTableSpecStr
;
555 mReportType
= ReportAll
;
558 mSelectedAcpiTable
= 0;
559 mSelectedAcpiTableName
= NULL
;
560 mSelectedAcpiTableFound
= FALSE
;
561 mConsistencyCheck
= TRUE
;
562 mMandatoryTableValidate
= FALSE
;
563 mMandatoryTableSpec
= 0;
565 ShellStatus
= SHELL_SUCCESS
;
567 TmpDumpFileHandle
= NULL
;
569 // Reset The error/warning counters
571 ResetWarningCount ();
573 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
574 if (EFI_ERROR (Status
)) {
575 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
580 STRING_TOKEN (STR_GEN_PROBLEM
),
581 gShellAcpiViewHiiHandle
,
585 FreePool (ProblemParam
);
587 Print (L
"acpiview: Error processing input parameter(s)\n");
589 ShellStatus
= SHELL_INVALID_PARAMETER
;
591 if (ShellCommandLineGetCount (Package
) > 1) {
596 STRING_TOKEN (STR_GEN_TOO_MANY
),
597 gShellAcpiViewHiiHandle
,
600 ShellStatus
= SHELL_INVALID_PARAMETER
;
601 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
606 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
607 gShellAcpiViewHiiHandle
,
610 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
611 ShellCommandLineGetValue (Package
, L
"-s") == NULL
) {
616 STRING_TOKEN (STR_GEN_NO_VALUE
),
617 gShellAcpiViewHiiHandle
,
621 ShellStatus
= SHELL_INVALID_PARAMETER
;
622 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
623 ShellCommandLineGetValue (Package
, L
"-r") == NULL
) {
628 STRING_TOKEN (STR_GEN_NO_VALUE
),
629 gShellAcpiViewHiiHandle
,
633 ShellStatus
= SHELL_INVALID_PARAMETER
;
634 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
635 ShellCommandLineGetFlag (Package
, L
"-l"))) {
640 STRING_TOKEN (STR_GEN_TOO_MANY
),
641 gShellAcpiViewHiiHandle
,
644 ShellStatus
= SHELL_INVALID_PARAMETER
;
645 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
646 !ShellCommandLineGetFlag (Package
, L
"-s")) {
651 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
652 gShellAcpiViewHiiHandle
,
657 ShellStatus
= SHELL_INVALID_PARAMETER
;
659 // Turn on colour highlighting if requested
660 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
662 // Surpress consistency checking if requested
663 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
665 // Evaluate the parameters for mandatory ACPI table presence checks
666 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
667 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
669 if (MandatoryTableSpecStr
!= NULL
) {
670 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
673 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
674 mReportType
= ReportTableList
;
676 mSelectedAcpiTableName
= ShellCommandLineGetValue (Package
, L
"-s");
677 if (mSelectedAcpiTableName
!= NULL
) {
678 mSelectedAcpiTable
= (UINT32
)ConvertStrToAcpiSignature (
679 mSelectedAcpiTableName
681 mReportType
= ReportSelected
;
683 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
684 // Create a temporary file to check if the media is writable.
685 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
686 mReportType
= ReportDumpBinFile
;
690 sizeof (FileNameBuffer
),
692 mSelectedAcpiTableName
,
696 Status
= ShellOpenFileByName (
699 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
700 EFI_FILE_MODE_CREATE
,
704 if (EFI_ERROR (Status
)) {
705 ShellStatus
= SHELL_INVALID_PARAMETER
;
706 TmpDumpFileHandle
= NULL
;
711 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
712 gShellAcpiViewHiiHandle
,
717 // Delete Temporary file.
718 ShellDeleteFile (&TmpDumpFileHandle
);
723 // Parse ACPI Table information
724 Status
= AcpiView (SystemTable
);
725 if (EFI_ERROR (Status
)) {
726 ShellStatus
= SHELL_NOT_FOUND
;
732 if (Package
!= NULL
) {
733 ShellCommandLineFreeVarList (Package
);