2 Main file for 'acpiview' Shell command function.
4 Copyright (c) 2022, NVIDIA CORPORATION. All rights reserved.
5 Copyright (c) 2016 - 2021, Arm Limited. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include <Guid/ShellLibHiiGuid.h>
10 #include <IndustryStandard/Acpi.h>
11 #include <IndustryStandard/ArmErrorSourceTable.h>
13 #include <Library/BaseMemoryLib.h>
14 #include <Library/HiiLib.h>
15 #include <Library/MemoryAllocationLib.h>
16 #include <Library/PrintLib.h>
17 #include <Library/ShellCommandLib.h>
18 #include <Library/ShellLib.h>
19 #include <Library/UefiBootServicesTableLib.h>
20 #include <Library/UefiLib.h>
21 #include <Library/AcpiViewCommandLib.h>
24 #include "AcpiParser.h"
25 #include "AcpiTableParser.h"
27 #include "AcpiViewConfig.h"
29 CONST CHAR16 gShellAcpiViewFileName
[] = L
"ShellCommand";
30 EFI_HII_HANDLE gShellAcpiViewHiiHandle
= NULL
;
33 An array of acpiview command line parameters.
35 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
46 A list of available table parsers.
50 ACPI_TABLE_PARSER ParserList
[] = {
51 { EFI_ACPI_6_3_ARM_ERROR_SOURCE_TABLE_SIGNATURE
, ParseAcpiAest
},
52 { EFI_ACPI_6_4_ARM_PERFORMANCE_MONITORING_UNIT_TABLE_SIGNATURE
, ParseAcpiApmt
},
53 { EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
, ParseAcpiBgrt
},
54 { EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE
, ParseAcpiDbg2
},
55 { EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
,
57 { EFI_ACPI_6_4_ERROR_RECORD_SERIALIZATION_TABLE_SIGNATURE
, ParseAcpiErst
},
58 { EFI_ACPI_6_3_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
, ParseAcpiFacs
},
59 { EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiFadt
},
60 { EFI_ACPI_6_4_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiGtdt
},
61 { EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE
, ParseAcpiHmat
},
62 { EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE
, ParseAcpiIort
},
63 { EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiMadt
},
64 { EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
66 { EFI_ACPI_6_4_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE
,
68 { EFI_ACPI_6_4_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
,
70 { RSDP_TABLE_INFO
, ParseAcpiRsdp
},
71 { EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE
, ParseAcpiSlit
},
72 { EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE
, ParseAcpiSpcr
},
73 { EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE
, ParseAcpiSrat
},
74 { EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiSsdt
},
75 { EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiXsdt
}
79 This function registers all the available table parsers.
81 @retval EFI_SUCCESS The parser is registered.
82 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
83 was already registered.
84 @retval EFI_INVALID_PARAMETER A parameter is invalid.
85 @retval EFI_OUT_OF_RESOURCES No space to register the
96 Count
= sizeof (ParserList
) / sizeof (ParserList
[0]);
98 while (Count
-- != 0) {
99 Status
= RegisterParser (
100 ParserList
[Count
].Signature
,
101 ParserList
[Count
].Parser
103 if (EFI_ERROR (Status
)) {
112 Dump a buffer to a file. Print error message if a file cannot be created.
114 @param[in] FileName The filename that shall be created to contain the buffer.
115 @param[in] Buffer Pointer to buffer that shall be dumped.
116 @param[in] BufferSize The size of buffer to be dumped in bytes.
118 @return The number of bytes that were written
122 ShellDumpBufferToFile (
123 IN CONST CHAR16
*FileNameBuffer
,
124 IN CONST VOID
*Buffer
,
125 IN CONST UINTN BufferSize
129 SHELL_FILE_HANDLE DumpFileHandle
;
132 Status
= ShellOpenFileByName (
135 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
139 if (EFI_ERROR (Status
)) {
144 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
145 gShellAcpiViewHiiHandle
,
151 TransferBytes
= BufferSize
;
152 Status
= ShellWriteFile (
158 if (EFI_ERROR (Status
)) {
159 Print (L
"ERROR: Failed to write binary file.\n");
165 ShellCloseFile (&DumpFileHandle
);
166 return TransferBytes
;
170 Return the file name of the help text file if not using HII.
172 @return The string pointer to the file name.
176 ShellCommandGetManFileNameAcpiView (
180 return gShellAcpiViewFileName
;
184 Function for 'acpiview' command.
186 @param[in] ImageHandle Handle to the Image (NULL if internal).
187 @param[in] SystemTable Pointer to the System Table (NULL if internal).
189 @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed
190 @retval SHELL_NOT_FOUND The command failed
191 @retval SHELL_SUCCESS The command was successful
195 ShellCommandRunAcpiView (
196 IN EFI_HANDLE ImageHandle
,
197 IN EFI_SYSTEM_TABLE
*SystemTable
201 SHELL_STATUS ShellStatus
;
203 CHAR16
*ProblemParam
;
204 SHELL_FILE_HANDLE TmpDumpFileHandle
;
205 CONST CHAR16
*MandatoryTableSpecStr
;
206 CONST CHAR16
*SelectedTableName
;
208 // Set configuration defaults
209 AcpiConfigSetDefaults ();
211 ShellStatus
= SHELL_SUCCESS
;
213 TmpDumpFileHandle
= NULL
;
215 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
216 if (EFI_ERROR (Status
)) {
217 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
222 STRING_TOKEN (STR_GEN_PROBLEM
),
223 gShellAcpiViewHiiHandle
,
227 FreePool (ProblemParam
);
229 Print (L
"acpiview: Error processing input parameter(s)\n");
232 ShellStatus
= SHELL_INVALID_PARAMETER
;
234 if (ShellCommandLineGetCount (Package
) > 1) {
239 STRING_TOKEN (STR_GEN_TOO_MANY
),
240 gShellAcpiViewHiiHandle
,
243 ShellStatus
= SHELL_INVALID_PARAMETER
;
244 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
249 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
250 gShellAcpiViewHiiHandle
,
253 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
254 (ShellCommandLineGetValue (Package
, L
"-s") == NULL
))
260 STRING_TOKEN (STR_GEN_NO_VALUE
),
261 gShellAcpiViewHiiHandle
,
265 ShellStatus
= SHELL_INVALID_PARAMETER
;
266 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
267 (ShellCommandLineGetValue (Package
, L
"-r") == NULL
))
273 STRING_TOKEN (STR_GEN_NO_VALUE
),
274 gShellAcpiViewHiiHandle
,
278 ShellStatus
= SHELL_INVALID_PARAMETER
;
279 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
280 ShellCommandLineGetFlag (Package
, L
"-l")))
286 STRING_TOKEN (STR_GEN_TOO_MANY
),
287 gShellAcpiViewHiiHandle
,
290 ShellStatus
= SHELL_INVALID_PARAMETER
;
291 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
292 !ShellCommandLineGetFlag (Package
, L
"-s"))
298 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
299 gShellAcpiViewHiiHandle
,
304 ShellStatus
= SHELL_INVALID_PARAMETER
;
306 // Turn on colour highlighting if requested
307 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
309 // Surpress consistency checking if requested
310 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
312 // Evaluate the parameters for mandatory ACPI table presence checks
313 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
314 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
316 if (MandatoryTableSpecStr
!= NULL
) {
317 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
320 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
321 SetReportOption (ReportTableList
);
323 SelectedTableName
= ShellCommandLineGetValue (Package
, L
"-s");
324 if (SelectedTableName
!= NULL
) {
325 SelectAcpiTable (SelectedTableName
);
326 SetReportOption (ReportSelected
);
328 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
329 // Create a temporary file to check if the media is writable.
330 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
331 SetReportOption (ReportDumpBinFile
);
335 sizeof (FileNameBuffer
),
340 Status
= ShellOpenFileByName (
343 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
344 EFI_FILE_MODE_CREATE
,
348 if (EFI_ERROR (Status
)) {
349 ShellStatus
= SHELL_INVALID_PARAMETER
;
350 TmpDumpFileHandle
= NULL
;
355 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
356 gShellAcpiViewHiiHandle
,
362 // Delete Temporary file.
363 ShellDeleteFile (&TmpDumpFileHandle
);
368 // Parse ACPI Table information
369 Status
= AcpiView (SystemTable
);
370 if (EFI_ERROR (Status
)) {
371 ShellStatus
= SHELL_NOT_FOUND
;
377 if (Package
!= NULL
) {
378 ShellCommandLineFreeVarList (Package
);
385 Constructor for the Shell AcpiView Command library.
387 Install the handlers for acpiview UEFI Shell command.
389 @param ImageHandle The image handle of the process.
390 @param SystemTable The EFI System Table pointer.
392 @retval EFI_SUCCESS The Shell command handlers were installed
394 @retval EFI_DEVICE_ERROR Hii package failed to install.
398 UefiShellAcpiViewCommandLibConstructor (
399 IN EFI_HANDLE ImageHandle
,
400 IN EFI_SYSTEM_TABLE
*SystemTable
405 gShellAcpiViewHiiHandle
= NULL
;
407 // Check Shell Profile Debug1 bit of the profiles mask
408 if ((PcdGet8 (PcdShellProfileMask
) & BIT1
) == 0) {
412 Status
= RegisterAllParsers ();
413 if (EFI_ERROR (Status
)) {
414 Print (L
"acpiview: Error failed to register parser.\n");
418 gShellAcpiViewHiiHandle
= HiiAddPackages (
419 &gShellAcpiViewHiiGuid
,
421 UefiShellAcpiViewCommandLibStrings
,
424 if (gShellAcpiViewHiiHandle
== NULL
) {
425 return EFI_DEVICE_ERROR
;
428 // Install our Shell command handler
429 ShellCommandRegisterCommandName (
431 ShellCommandRunAcpiView
,
432 ShellCommandGetManFileNameAcpiView
,
436 gShellAcpiViewHiiHandle
,
437 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
)
444 Destructor for the library. free any resources.
446 @param ImageHandle The image handle of the process.
447 @param SystemTable The EFI System Table pointer.
451 UefiShellAcpiViewCommandLibDestructor (
452 IN EFI_HANDLE ImageHandle
,
453 IN EFI_SYSTEM_TABLE
*SystemTable
456 if (gShellAcpiViewHiiHandle
!= NULL
) {
457 HiiRemovePackages (gShellAcpiViewHiiHandle
);