2 Main file for 'acpiview' Shell command function.
4 Copyright (c) 2016 - 2020, Arm Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
8 #include <Guid/ShellLibHiiGuid.h>
9 #include <IndustryStandard/Acpi.h>
10 #include <IndustryStandard/ArmErrorSourceTable.h>
12 #include <Library/BaseMemoryLib.h>
13 #include <Library/HiiLib.h>
14 #include <Library/MemoryAllocationLib.h>
15 #include <Library/PrintLib.h>
16 #include <Library/ShellCommandLib.h>
17 #include <Library/ShellLib.h>
18 #include <Library/UefiBootServicesTableLib.h>
19 #include <Library/UefiLib.h>
20 #include <Library/AcpiViewCommandLib.h>
23 #include "AcpiParser.h"
24 #include "AcpiTableParser.h"
26 #include "AcpiViewConfig.h"
28 CONST CHAR16 gShellAcpiViewFileName
[] = L
"ShellCommand";
29 EFI_HII_HANDLE gShellAcpiViewHiiHandle
= NULL
;
32 An array of acpiview command line parameters.
34 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
45 A list of available table parsers.
49 ACPI_TABLE_PARSER ParserList
[] = {
50 {EFI_ACPI_6_3_ARM_ERROR_SOURCE_TABLE_SIGNATURE
, ParseAcpiAest
},
51 {EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
, ParseAcpiBgrt
},
52 {EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE
, ParseAcpiDbg2
},
53 {EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
,
55 {EFI_ACPI_6_3_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
, ParseAcpiFacs
},
56 {EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiFadt
},
57 {EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiGtdt
},
58 {EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE
, ParseAcpiIort
},
59 {EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiMadt
},
60 {EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
62 {EFI_ACPI_6_2_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE
,
64 {EFI_ACPI_6_2_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
,
66 {RSDP_TABLE_INFO
, ParseAcpiRsdp
},
67 {EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE
, ParseAcpiSlit
},
68 {EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE
, ParseAcpiSpcr
},
69 {EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE
, ParseAcpiSrat
},
70 {EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiSsdt
},
71 {EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiXsdt
}
75 This function registers all the available table parsers.
77 @retval EFI_SUCCESS The parser is registered.
78 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
79 was already registered.
80 @retval EFI_INVALID_PARAMETER A parameter is invalid.
81 @retval EFI_OUT_OF_RESOURCES No space to register the
92 Count
= sizeof (ParserList
) / sizeof (ParserList
[0]);
94 while (Count
-- != 0) {
95 Status
= RegisterParser (
96 ParserList
[Count
].Signature
,
97 ParserList
[Count
].Parser
99 if (EFI_ERROR (Status
)) {
107 Dump a buffer to a file. Print error message if a file cannot be created.
109 @param[in] FileName The filename that shall be created to contain the buffer.
110 @param[in] Buffer Pointer to buffer that shall be dumped.
111 @param[in] BufferSize The size of buffer to be dumped in bytes.
113 @return The number of bytes that were written
117 ShellDumpBufferToFile (
118 IN CONST CHAR16
* FileNameBuffer
,
119 IN CONST VOID
* Buffer
,
120 IN CONST UINTN BufferSize
124 SHELL_FILE_HANDLE DumpFileHandle
;
127 Status
= ShellOpenFileByName (
130 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
134 if (EFI_ERROR (Status
)) {
139 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
140 gShellAcpiViewHiiHandle
,
146 TransferBytes
= BufferSize
;
147 Status
= ShellWriteFile (
153 if (EFI_ERROR (Status
)) {
154 Print (L
"ERROR: Failed to write binary file.\n");
160 ShellCloseFile (&DumpFileHandle
);
161 return TransferBytes
;
165 Return the file name of the help text file if not using HII.
167 @return The string pointer to the file name.
171 ShellCommandGetManFileNameAcpiView (
175 return gShellAcpiViewFileName
;
179 Function for 'acpiview' command.
181 @param[in] ImageHandle Handle to the Image (NULL if internal).
182 @param[in] SystemTable Pointer to the System Table (NULL if internal).
184 @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed
185 @retval SHELL_NOT_FOUND The command failed
186 @retval SHELL_SUCCESS The command was successful
190 ShellCommandRunAcpiView (
191 IN EFI_HANDLE ImageHandle
,
192 IN EFI_SYSTEM_TABLE
* SystemTable
196 SHELL_STATUS ShellStatus
;
198 CHAR16
* ProblemParam
;
199 SHELL_FILE_HANDLE TmpDumpFileHandle
;
200 CONST CHAR16
* MandatoryTableSpecStr
;
201 CONST CHAR16
* SelectedTableName
;
203 // Set configuration defaults
204 AcpiConfigSetDefaults ();
206 ShellStatus
= SHELL_SUCCESS
;
208 TmpDumpFileHandle
= NULL
;
210 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
211 if (EFI_ERROR (Status
)) {
212 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
217 STRING_TOKEN (STR_GEN_PROBLEM
),
218 gShellAcpiViewHiiHandle
,
222 FreePool (ProblemParam
);
224 Print (L
"acpiview: Error processing input parameter(s)\n");
226 ShellStatus
= SHELL_INVALID_PARAMETER
;
228 if (ShellCommandLineGetCount (Package
) > 1) {
233 STRING_TOKEN (STR_GEN_TOO_MANY
),
234 gShellAcpiViewHiiHandle
,
237 ShellStatus
= SHELL_INVALID_PARAMETER
;
238 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
243 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
244 gShellAcpiViewHiiHandle
,
247 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
248 ShellCommandLineGetValue (Package
, L
"-s") == NULL
) {
253 STRING_TOKEN (STR_GEN_NO_VALUE
),
254 gShellAcpiViewHiiHandle
,
258 ShellStatus
= SHELL_INVALID_PARAMETER
;
259 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
260 ShellCommandLineGetValue (Package
, L
"-r") == NULL
) {
265 STRING_TOKEN (STR_GEN_NO_VALUE
),
266 gShellAcpiViewHiiHandle
,
270 ShellStatus
= SHELL_INVALID_PARAMETER
;
271 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
272 ShellCommandLineGetFlag (Package
, L
"-l"))) {
277 STRING_TOKEN (STR_GEN_TOO_MANY
),
278 gShellAcpiViewHiiHandle
,
281 ShellStatus
= SHELL_INVALID_PARAMETER
;
282 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
283 !ShellCommandLineGetFlag (Package
, L
"-s")) {
288 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
289 gShellAcpiViewHiiHandle
,
294 ShellStatus
= SHELL_INVALID_PARAMETER
;
296 // Turn on colour highlighting if requested
297 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
299 // Surpress consistency checking if requested
300 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
302 // Evaluate the parameters for mandatory ACPI table presence checks
303 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
304 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
306 if (MandatoryTableSpecStr
!= NULL
) {
307 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
310 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
311 SetReportOption (ReportTableList
);
313 SelectedTableName
= ShellCommandLineGetValue (Package
, L
"-s");
314 if (SelectedTableName
!= NULL
) {
315 SelectAcpiTable (SelectedTableName
);
316 SetReportOption (ReportSelected
);
318 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
319 // Create a temporary file to check if the media is writable.
320 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
321 SetReportOption (ReportDumpBinFile
);
325 sizeof (FileNameBuffer
),
330 Status
= ShellOpenFileByName (
333 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
334 EFI_FILE_MODE_CREATE
,
338 if (EFI_ERROR (Status
)) {
339 ShellStatus
= SHELL_INVALID_PARAMETER
;
340 TmpDumpFileHandle
= NULL
;
345 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
346 gShellAcpiViewHiiHandle
,
351 // Delete Temporary file.
352 ShellDeleteFile (&TmpDumpFileHandle
);
357 // Parse ACPI Table information
358 Status
= AcpiView (SystemTable
);
359 if (EFI_ERROR (Status
)) {
360 ShellStatus
= SHELL_NOT_FOUND
;
366 if (Package
!= NULL
) {
367 ShellCommandLineFreeVarList (Package
);
373 Constructor for the Shell AcpiView Command library.
375 Install the handlers for acpiview UEFI Shell command.
377 @param ImageHandle The image handle of the process.
378 @param SystemTable The EFI System Table pointer.
380 @retval EFI_SUCCESS The Shell command handlers were installed
382 @retval EFI_DEVICE_ERROR Hii package failed to install.
386 UefiShellAcpiViewCommandLibConstructor (
387 IN EFI_HANDLE ImageHandle
,
388 IN EFI_SYSTEM_TABLE
*SystemTable
392 gShellAcpiViewHiiHandle
= NULL
;
394 // Check Shell Profile Debug1 bit of the profiles mask
395 if ((PcdGet8 (PcdShellProfileMask
) & BIT1
) == 0) {
399 Status
= RegisterAllParsers ();
400 if (EFI_ERROR (Status
)) {
401 Print (L
"acpiview: Error failed to register parser.\n");
405 gShellAcpiViewHiiHandle
= HiiAddPackages (
406 &gShellAcpiViewHiiGuid
,
408 UefiShellAcpiViewCommandLibStrings
,
411 if (gShellAcpiViewHiiHandle
== NULL
) {
412 return EFI_DEVICE_ERROR
;
414 // Install our Shell command handler
415 ShellCommandRegisterCommandName (
417 ShellCommandRunAcpiView
,
418 ShellCommandGetManFileNameAcpiView
,
422 gShellAcpiViewHiiHandle
,
423 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
)
430 Destructor for the library. free any resources.
432 @param ImageHandle The image handle of the process.
433 @param SystemTable The EFI System Table pointer.
437 UefiShellAcpiViewCommandLibDestructor (
438 IN EFI_HANDLE ImageHandle
,
439 IN EFI_SYSTEM_TABLE
*SystemTable
442 if (gShellAcpiViewHiiHandle
!= NULL
) {
443 HiiRemovePackages (gShellAcpiViewHiiHandle
);