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>
11 #include <Library/BaseMemoryLib.h>
12 #include <Library/HiiLib.h>
13 #include <Library/MemoryAllocationLib.h>
14 #include <Library/PrintLib.h>
15 #include <Library/ShellCommandLib.h>
16 #include <Library/ShellLib.h>
17 #include <Library/UefiBootServicesTableLib.h>
18 #include <Library/UefiLib.h>
21 #include "AcpiParser.h"
22 #include "AcpiTableParser.h"
24 #include "AcpiViewConfig.h"
25 #include "UefiShellAcpiViewCommandLib.h"
27 CONST CHAR16 gShellAcpiViewFileName
[] = L
"ShellCommand";
30 An array of acpiview command line parameters.
32 STATIC CONST SHELL_PARAM_ITEM ParamList
[] = {
43 A list of available table parsers.
47 ACPI_TABLE_PARSER ParserList
[] = {
48 {EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
, ParseAcpiBgrt
},
49 {EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE
, ParseAcpiDbg2
},
50 {EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
,
52 {EFI_ACPI_6_3_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
, ParseAcpiFacs
},
53 {EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiFadt
},
54 {EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiGtdt
},
55 {EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE
, ParseAcpiIort
},
56 {EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiMadt
},
57 {EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
59 {EFI_ACPI_6_2_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
,
61 {RSDP_TABLE_INFO
, ParseAcpiRsdp
},
62 {EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE
, ParseAcpiSlit
},
63 {EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE
, ParseAcpiSpcr
},
64 {EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE
, ParseAcpiSrat
},
65 {EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiSsdt
},
66 {EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiXsdt
}
70 This function registers all the available table parsers.
72 @retval EFI_SUCCESS The parser is registered.
73 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
74 was already registered.
75 @retval EFI_INVALID_PARAMETER A parameter is invalid.
76 @retval EFI_OUT_OF_RESOURCES No space to register the
87 Count
= sizeof (ParserList
) / sizeof (ParserList
[0]);
89 while (Count
-- != 0) {
90 Status
= RegisterParser (
91 ParserList
[Count
].Signature
,
92 ParserList
[Count
].Parser
94 if (EFI_ERROR (Status
)) {
102 Return the file name of the help text file if not using HII.
104 @return The string pointer to the file name.
108 ShellCommandGetManFileNameAcpiView (
112 return gShellAcpiViewFileName
;
116 Function for 'acpiview' command.
118 @param[in] ImageHandle Handle to the Image (NULL if internal).
119 @param[in] SystemTable Pointer to the System Table (NULL if internal).
121 @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed
122 @retval SHELL_NOT_FOUND The command failed
123 @retval SHELL_SUCCESS The command was successful
127 ShellCommandRunAcpiView (
128 IN EFI_HANDLE ImageHandle
,
129 IN EFI_SYSTEM_TABLE
* SystemTable
133 SHELL_STATUS ShellStatus
;
135 CHAR16
* ProblemParam
;
136 SHELL_FILE_HANDLE TmpDumpFileHandle
;
137 CONST CHAR16
* MandatoryTableSpecStr
;
138 CONST CHAR16
* SelectedTableName
;
140 // Set configuration defaults
141 AcpiConfigSetDefaults ();
143 ShellStatus
= SHELL_SUCCESS
;
145 TmpDumpFileHandle
= NULL
;
147 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
148 if (EFI_ERROR (Status
)) {
149 if (Status
== EFI_VOLUME_CORRUPTED
&& ProblemParam
!= NULL
) {
154 STRING_TOKEN (STR_GEN_PROBLEM
),
155 gShellAcpiViewHiiHandle
,
159 FreePool (ProblemParam
);
161 Print (L
"acpiview: Error processing input parameter(s)\n");
163 ShellStatus
= SHELL_INVALID_PARAMETER
;
165 if (ShellCommandLineGetCount (Package
) > 1) {
170 STRING_TOKEN (STR_GEN_TOO_MANY
),
171 gShellAcpiViewHiiHandle
,
174 ShellStatus
= SHELL_INVALID_PARAMETER
;
175 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
180 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
181 gShellAcpiViewHiiHandle
,
184 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
185 ShellCommandLineGetValue (Package
, L
"-s") == NULL
) {
190 STRING_TOKEN (STR_GEN_NO_VALUE
),
191 gShellAcpiViewHiiHandle
,
195 ShellStatus
= SHELL_INVALID_PARAMETER
;
196 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
197 ShellCommandLineGetValue (Package
, L
"-r") == NULL
) {
202 STRING_TOKEN (STR_GEN_NO_VALUE
),
203 gShellAcpiViewHiiHandle
,
207 ShellStatus
= SHELL_INVALID_PARAMETER
;
208 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
209 ShellCommandLineGetFlag (Package
, L
"-l"))) {
214 STRING_TOKEN (STR_GEN_TOO_MANY
),
215 gShellAcpiViewHiiHandle
,
218 ShellStatus
= SHELL_INVALID_PARAMETER
;
219 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
220 !ShellCommandLineGetFlag (Package
, L
"-s")) {
225 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
226 gShellAcpiViewHiiHandle
,
231 ShellStatus
= SHELL_INVALID_PARAMETER
;
233 // Turn on colour highlighting if requested
234 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
236 // Surpress consistency checking if requested
237 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
239 // Evaluate the parameters for mandatory ACPI table presence checks
240 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
241 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
243 if (MandatoryTableSpecStr
!= NULL
) {
244 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
247 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
248 SetReportOption (ReportTableList
);
250 SelectedTableName
= ShellCommandLineGetValue (Package
, L
"-s");
251 if (SelectedTableName
!= NULL
) {
252 SelectAcpiTable (SelectedTableName
);
253 SetReportOption (ReportSelected
);
255 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
256 // Create a temporary file to check if the media is writable.
257 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
258 SetReportOption (ReportDumpBinFile
);
262 sizeof (FileNameBuffer
),
267 Status
= ShellOpenFileByName (
270 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
271 EFI_FILE_MODE_CREATE
,
275 if (EFI_ERROR (Status
)) {
276 ShellStatus
= SHELL_INVALID_PARAMETER
;
277 TmpDumpFileHandle
= NULL
;
282 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
283 gShellAcpiViewHiiHandle
,
288 // Delete Temporary file.
289 ShellDeleteFile (&TmpDumpFileHandle
);
294 // Parse ACPI Table information
295 Status
= AcpiView (SystemTable
);
296 if (EFI_ERROR (Status
)) {
297 ShellStatus
= SHELL_NOT_FOUND
;
303 if (Package
!= NULL
) {
304 ShellCommandLineFreeVarList (Package
);
310 Constructor for the Shell AcpiView Command library.
312 Install the handlers for acpiview UEFI Shell command.
314 @param ImageHandle The image handle of the process.
315 @param SystemTable The EFI System Table pointer.
317 @retval EFI_SUCCESS The Shell command handlers were installed
319 @retval EFI_DEVICE_ERROR Hii package failed to install.
323 UefiShellAcpiViewCommandLibConstructor (
324 IN EFI_HANDLE ImageHandle
,
325 IN EFI_SYSTEM_TABLE
*SystemTable
329 gShellAcpiViewHiiHandle
= NULL
;
331 // Check Shell Profile Debug1 bit of the profiles mask
332 if ((PcdGet8 (PcdShellProfileMask
) & BIT1
) == 0) {
336 Status
= RegisterAllParsers ();
337 if (EFI_ERROR (Status
)) {
338 Print (L
"acpiview: Error failed to register parser.\n");
342 gShellAcpiViewHiiHandle
= HiiAddPackages (
343 &gShellAcpiViewHiiGuid
,
345 UefiShellAcpiViewCommandLibStrings
,
348 if (gShellAcpiViewHiiHandle
== NULL
) {
349 return EFI_DEVICE_ERROR
;
351 // Install our Shell command handler
352 ShellCommandRegisterCommandName (
354 ShellCommandRunAcpiView
,
355 ShellCommandGetManFileNameAcpiView
,
359 gShellAcpiViewHiiHandle
,
360 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
)
367 Destructor for the library. free any resources.
369 @param ImageHandle The image handle of the process.
370 @param SystemTable The EFI System Table pointer.
374 UefiShellAcpiViewCommandLibDestructor (
375 IN EFI_HANDLE ImageHandle
,
376 IN EFI_SYSTEM_TABLE
*SystemTable
379 if (gShellAcpiViewHiiHandle
!= NULL
) {
380 HiiRemovePackages (gShellAcpiViewHiiHandle
);