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 This function dumps the ACPI table to a file.
38 @param [in] Ptr Pointer to the ACPI table data.
39 @param [in] Length The length of the ACPI table.
42 @retval FALSE Failure.
52 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
53 SHELL_FILE_HANDLE DumpFileHandle
;
55 SELECTED_ACPI_TABLE
*SelectedTable
;
57 DumpFileHandle
= NULL
;
58 TransferBytes
= Length
;
59 GetSelectedAcpiTable (&SelectedTable
);
63 sizeof (FileNameBuffer
),
69 Status
= ShellOpenFileByName (
72 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
75 if (EFI_ERROR (Status
)) {
80 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
81 gShellAcpiViewHiiHandle
,
87 Print (L
"Dumping ACPI table to : %s ... ", FileNameBuffer
);
89 Status
= ShellWriteFile (
94 if (EFI_ERROR (Status
)) {
95 Print (L
"ERROR: Failed to dump table to binary file.\n");
101 ShellCloseFile (&DumpFileHandle
);
102 return (Length
== TransferBytes
);
106 This function processes the table reporting options for the ACPI table.
108 @param [in] Signature The ACPI table Signature.
109 @param [in] TablePtr Pointer to the ACPI table data.
110 @param [in] Length The length fo the ACPI table.
112 @retval Returns TRUE if the ACPI table should be traced.
115 ProcessTableReportOptions (
116 IN CONST UINT32 Signature
,
117 IN CONST UINT8
* TablePtr
,
118 IN CONST UINT32 Length
121 UINTN OriginalAttribute
;
125 SELECTED_ACPI_TABLE
*SelectedTable
;
128 // set local variables to suppress incorrect compiler/analyzer warnings
130 OriginalAttribute
= 0;
131 SignaturePtr
= (UINT8
*)(UINTN
)&Signature
;
133 HighLight
= GetColourHighlighting ();
134 GetSelectedAcpiTable (&SelectedTable
);
136 switch (GetReportOption ()) {
141 if (Signature
== SelectedTable
->Type
) {
143 SelectedTable
->Found
= TRUE
;
146 case ReportTableList
:
147 if (mTableCount
== 0) {
149 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
150 gST
->ConOut
->SetAttribute (
152 EFI_TEXT_ATTR(EFI_CYAN
,
153 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
156 Print (L
"\nInstalled Table(s):\n");
158 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
162 L
"\t%4d. %c%c%c%c\n",
170 case ReportDumpBinFile
:
171 if (Signature
== SelectedTable
->Type
) {
172 SelectedTable
->Found
= TRUE
;
173 DumpAcpiTableToFile (TablePtr
, Length
);
177 // We should never be here.
178 // This case is only present to prevent compiler warning.
184 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
185 gST
->ConOut
->SetAttribute (
187 EFI_TEXT_ATTR(EFI_LIGHTBLUE
,
188 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4))
192 L
"\n\n --------------- %c%c%c%c Table --------------- \n\n",
199 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);
209 This function iterates the configuration table entries in the
210 system table, retrieves the RSDP pointer and starts parsing the ACPI tables.
212 @param [in] SystemTable Pointer to the EFI system table.
214 @retval Returns EFI_NOT_FOUND if the RSDP pointer is not found.
215 Returns EFI_UNSUPPORTED if the RSDP version is less than 2.
216 Returns EFI_SUCCESS if successful.
221 IN EFI_SYSTEM_TABLE
* SystemTable
226 EFI_CONFIGURATION_TABLE
* EfiConfigurationTable
;
227 BOOLEAN FoundAcpiTable
;
228 UINTN OriginalAttribute
;
229 UINTN PrintAttribute
;
230 EREPORT_OPTION ReportOption
;
234 PARSE_ACPI_TABLE_PROC RsdpParserProc
;
236 SELECTED_ACPI_TABLE
*SelectedTable
;
239 // set local variables to suppress incorrect compiler/analyzer warnings
241 EfiConfigurationTable
= NULL
;
242 OriginalAttribute
= 0;
244 // Reset Table counts
248 // Reset The error/warning counters
250 ResetWarningCount ();
252 // Retrieve the user selection of ACPI table to process
253 GetSelectedAcpiTable (&SelectedTable
);
255 // Search the table for an entry that matches the ACPI Table Guid
256 FoundAcpiTable
= FALSE
;
257 for (Index
= 0; Index
< SystemTable
->NumberOfTableEntries
; Index
++) {
258 if (CompareGuid (&gEfiAcpiTableGuid
,
259 &(SystemTable
->ConfigurationTable
[Index
].VendorGuid
))) {
260 EfiConfigurationTable
= &SystemTable
->ConfigurationTable
[Index
];
261 FoundAcpiTable
= TRUE
;
266 if (FoundAcpiTable
) {
267 RsdpPtr
= (UINT8
*)EfiConfigurationTable
->VendorTable
;
269 // The RSDP revision is 1 byte starting at offset 15
270 RsdpRevision
= *(RsdpPtr
+ RSDP_REVISION_OFFSET
);
272 if (RsdpRevision
< 2) {
274 L
"ERROR: RSDP version less than 2 is not supported.\n"
276 return EFI_UNSUPPORTED
;
279 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
280 if (GetMandatoryTableValidate ()) {
281 ArmSbbrResetTableCounts ();
285 // The RSDP length is 4 bytes starting at offset 20
286 RsdpLength
= *(UINT32
*)(RsdpPtr
+ RSDP_LENGTH_OFFSET
);
288 Trace
= ProcessTableReportOptions (RSDP_TABLE_INFO
, RsdpPtr
, RsdpLength
);
290 Status
= GetParser (RSDP_TABLE_INFO
, &RsdpParserProc
);
291 if (EFI_ERROR (Status
)) {
293 L
"ERROR: No registered parser found for RSDP.\n"
306 IncrementErrorCount ();
308 L
"ERROR: Failed to find ACPI Table Guid in System Configuration Table.\n"
310 return EFI_NOT_FOUND
;
313 #if defined(MDE_CPU_ARM) || defined (MDE_CPU_AARCH64)
314 if (GetMandatoryTableValidate ()) {
315 ArmSbbrReqsValidate ((ARM_SBBR_VERSION
)GetMandatoryTableSpec ());
319 ReportOption
= GetReportOption ();
320 if (ReportTableList
!= ReportOption
) {
321 if (((ReportSelected
== ReportOption
) ||
322 (ReportDumpBinFile
== ReportOption
)) &&
323 (!SelectedTable
->Found
)) {
324 Print (L
"\nRequested ACPI Table not found.\n");
325 } else if (GetConsistencyChecking () &&
326 (ReportDumpBinFile
!= ReportOption
)) {
327 OriginalAttribute
= gST
->ConOut
->Mode
->Attribute
;
329 Print (L
"\nTable Statistics:\n");
331 if (GetColourHighlighting ()) {
332 PrintAttribute
= (GetErrorCount () > 0) ?
335 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
338 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
340 Print (L
"\t%d Error(s)\n", GetErrorCount ());
342 if (GetColourHighlighting ()) {
343 PrintAttribute
= (GetWarningCount () > 0) ?
346 ((OriginalAttribute
&(BIT4
|BIT5
|BIT6
))>>4)
350 gST
->ConOut
->SetAttribute (gST
->ConOut
, PrintAttribute
);
352 Print (L
"\t%d Warning(s)\n", GetWarningCount ());
354 if (GetColourHighlighting ()) {
355 gST
->ConOut
->SetAttribute (gST
->ConOut
, OriginalAttribute
);