2 Main file for 'acpiview' Shell command function.
4 Copyright (c) 2016 - 2021, 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_4_ARM_PERFORMANCE_MONITORING_UNIT_TABLE_SIGNATURE
, ParseAcpiApmt
},
52 { EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE
, ParseAcpiBgrt
},
53 { EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE
, ParseAcpiDbg2
},
54 { EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
,
56 { EFI_ACPI_6_3_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE
, ParseAcpiFacs
},
57 { EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiFadt
},
58 { EFI_ACPI_6_4_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiGtdt
},
59 { EFI_ACPI_6_4_HETEROGENEOUS_MEMORY_ATTRIBUTE_TABLE_SIGNATURE
, ParseAcpiHmat
},
60 { EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE
, ParseAcpiIort
},
61 { EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiMadt
},
62 { EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE
,
64 { EFI_ACPI_6_4_PLATFORM_COMMUNICATIONS_CHANNEL_TABLE_SIGNATURE
,
66 { EFI_ACPI_6_4_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE
,
68 { RSDP_TABLE_INFO
, ParseAcpiRsdp
},
69 { EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE
, ParseAcpiSlit
},
70 { EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE
, ParseAcpiSpcr
},
71 { EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE
, ParseAcpiSrat
},
72 { EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiSsdt
},
73 { EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE
, ParseAcpiXsdt
}
77 This function registers all the available table parsers.
79 @retval EFI_SUCCESS The parser is registered.
80 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
81 was already registered.
82 @retval EFI_INVALID_PARAMETER A parameter is invalid.
83 @retval EFI_OUT_OF_RESOURCES No space to register the
94 Count
= sizeof (ParserList
) / sizeof (ParserList
[0]);
96 while (Count
-- != 0) {
97 Status
= RegisterParser (
98 ParserList
[Count
].Signature
,
99 ParserList
[Count
].Parser
101 if (EFI_ERROR (Status
)) {
110 Dump a buffer to a file. Print error message if a file cannot be created.
112 @param[in] FileName The filename that shall be created to contain the buffer.
113 @param[in] Buffer Pointer to buffer that shall be dumped.
114 @param[in] BufferSize The size of buffer to be dumped in bytes.
116 @return The number of bytes that were written
120 ShellDumpBufferToFile (
121 IN CONST CHAR16
*FileNameBuffer
,
122 IN CONST VOID
*Buffer
,
123 IN CONST UINTN BufferSize
127 SHELL_FILE_HANDLE DumpFileHandle
;
130 Status
= ShellOpenFileByName (
133 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
| EFI_FILE_MODE_CREATE
,
137 if (EFI_ERROR (Status
)) {
142 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
143 gShellAcpiViewHiiHandle
,
149 TransferBytes
= BufferSize
;
150 Status
= ShellWriteFile (
156 if (EFI_ERROR (Status
)) {
157 Print (L
"ERROR: Failed to write binary file.\n");
163 ShellCloseFile (&DumpFileHandle
);
164 return TransferBytes
;
168 Return the file name of the help text file if not using HII.
170 @return The string pointer to the file name.
174 ShellCommandGetManFileNameAcpiView (
178 return gShellAcpiViewFileName
;
182 Function for 'acpiview' command.
184 @param[in] ImageHandle Handle to the Image (NULL if internal).
185 @param[in] SystemTable Pointer to the System Table (NULL if internal).
187 @retval SHELL_INVALID_PARAMETER The command line invocation could not be parsed
188 @retval SHELL_NOT_FOUND The command failed
189 @retval SHELL_SUCCESS The command was successful
193 ShellCommandRunAcpiView (
194 IN EFI_HANDLE ImageHandle
,
195 IN EFI_SYSTEM_TABLE
*SystemTable
199 SHELL_STATUS ShellStatus
;
201 CHAR16
*ProblemParam
;
202 SHELL_FILE_HANDLE TmpDumpFileHandle
;
203 CONST CHAR16
*MandatoryTableSpecStr
;
204 CONST CHAR16
*SelectedTableName
;
206 // Set configuration defaults
207 AcpiConfigSetDefaults ();
209 ShellStatus
= SHELL_SUCCESS
;
211 TmpDumpFileHandle
= NULL
;
213 Status
= ShellCommandLineParse (ParamList
, &Package
, &ProblemParam
, TRUE
);
214 if (EFI_ERROR (Status
)) {
215 if ((Status
== EFI_VOLUME_CORRUPTED
) && (ProblemParam
!= NULL
)) {
220 STRING_TOKEN (STR_GEN_PROBLEM
),
221 gShellAcpiViewHiiHandle
,
225 FreePool (ProblemParam
);
227 Print (L
"acpiview: Error processing input parameter(s)\n");
230 ShellStatus
= SHELL_INVALID_PARAMETER
;
232 if (ShellCommandLineGetCount (Package
) > 1) {
237 STRING_TOKEN (STR_GEN_TOO_MANY
),
238 gShellAcpiViewHiiHandle
,
241 ShellStatus
= SHELL_INVALID_PARAMETER
;
242 } else if (ShellCommandLineGetFlag (Package
, L
"-?")) {
247 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
),
248 gShellAcpiViewHiiHandle
,
251 } else if (ShellCommandLineGetFlag (Package
, L
"-s") &&
252 (ShellCommandLineGetValue (Package
, L
"-s") == NULL
))
258 STRING_TOKEN (STR_GEN_NO_VALUE
),
259 gShellAcpiViewHiiHandle
,
263 ShellStatus
= SHELL_INVALID_PARAMETER
;
264 } else if (ShellCommandLineGetFlag (Package
, L
"-r") &&
265 (ShellCommandLineGetValue (Package
, L
"-r") == NULL
))
271 STRING_TOKEN (STR_GEN_NO_VALUE
),
272 gShellAcpiViewHiiHandle
,
276 ShellStatus
= SHELL_INVALID_PARAMETER
;
277 } else if ((ShellCommandLineGetFlag (Package
, L
"-s") &&
278 ShellCommandLineGetFlag (Package
, L
"-l")))
284 STRING_TOKEN (STR_GEN_TOO_MANY
),
285 gShellAcpiViewHiiHandle
,
288 ShellStatus
= SHELL_INVALID_PARAMETER
;
289 } else if (ShellCommandLineGetFlag (Package
, L
"-d") &&
290 !ShellCommandLineGetFlag (Package
, L
"-s"))
296 STRING_TOKEN (STR_GEN_MISSING_OPTION
),
297 gShellAcpiViewHiiHandle
,
302 ShellStatus
= SHELL_INVALID_PARAMETER
;
304 // Turn on colour highlighting if requested
305 SetColourHighlighting (ShellCommandLineGetFlag (Package
, L
"-h"));
307 // Surpress consistency checking if requested
308 SetConsistencyChecking (!ShellCommandLineGetFlag (Package
, L
"-q"));
310 // Evaluate the parameters for mandatory ACPI table presence checks
311 SetMandatoryTableValidate (ShellCommandLineGetFlag (Package
, L
"-r"));
312 MandatoryTableSpecStr
= ShellCommandLineGetValue (Package
, L
"-r");
314 if (MandatoryTableSpecStr
!= NULL
) {
315 SetMandatoryTableSpec (ShellHexStrToUintn (MandatoryTableSpecStr
));
318 if (ShellCommandLineGetFlag (Package
, L
"-l")) {
319 SetReportOption (ReportTableList
);
321 SelectedTableName
= ShellCommandLineGetValue (Package
, L
"-s");
322 if (SelectedTableName
!= NULL
) {
323 SelectAcpiTable (SelectedTableName
);
324 SetReportOption (ReportSelected
);
326 if (ShellCommandLineGetFlag (Package
, L
"-d")) {
327 // Create a temporary file to check if the media is writable.
328 CHAR16 FileNameBuffer
[MAX_FILE_NAME_LEN
];
329 SetReportOption (ReportDumpBinFile
);
333 sizeof (FileNameBuffer
),
338 Status
= ShellOpenFileByName (
341 EFI_FILE_MODE_READ
| EFI_FILE_MODE_WRITE
|
342 EFI_FILE_MODE_CREATE
,
346 if (EFI_ERROR (Status
)) {
347 ShellStatus
= SHELL_INVALID_PARAMETER
;
348 TmpDumpFileHandle
= NULL
;
353 STRING_TOKEN (STR_GEN_READONLY_MEDIA
),
354 gShellAcpiViewHiiHandle
,
360 // Delete Temporary file.
361 ShellDeleteFile (&TmpDumpFileHandle
);
366 // Parse ACPI Table information
367 Status
= AcpiView (SystemTable
);
368 if (EFI_ERROR (Status
)) {
369 ShellStatus
= SHELL_NOT_FOUND
;
375 if (Package
!= NULL
) {
376 ShellCommandLineFreeVarList (Package
);
383 Constructor for the Shell AcpiView Command library.
385 Install the handlers for acpiview UEFI Shell command.
387 @param ImageHandle The image handle of the process.
388 @param SystemTable The EFI System Table pointer.
390 @retval EFI_SUCCESS The Shell command handlers were installed
392 @retval EFI_DEVICE_ERROR Hii package failed to install.
396 UefiShellAcpiViewCommandLibConstructor (
397 IN EFI_HANDLE ImageHandle
,
398 IN EFI_SYSTEM_TABLE
*SystemTable
403 gShellAcpiViewHiiHandle
= NULL
;
405 // Check Shell Profile Debug1 bit of the profiles mask
406 if ((PcdGet8 (PcdShellProfileMask
) & BIT1
) == 0) {
410 Status
= RegisterAllParsers ();
411 if (EFI_ERROR (Status
)) {
412 Print (L
"acpiview: Error failed to register parser.\n");
416 gShellAcpiViewHiiHandle
= HiiAddPackages (
417 &gShellAcpiViewHiiGuid
,
419 UefiShellAcpiViewCommandLibStrings
,
422 if (gShellAcpiViewHiiHandle
== NULL
) {
423 return EFI_DEVICE_ERROR
;
426 // Install our Shell command handler
427 ShellCommandRegisterCommandName (
429 ShellCommandRunAcpiView
,
430 ShellCommandGetManFileNameAcpiView
,
434 gShellAcpiViewHiiHandle
,
435 STRING_TOKEN (STR_GET_HELP_ACPIVIEW
)
442 Destructor for the library. free any resources.
444 @param ImageHandle The image handle of the process.
445 @param SystemTable The EFI System Table pointer.
449 UefiShellAcpiViewCommandLibDestructor (
450 IN EFI_HANDLE ImageHandle
,
451 IN EFI_SYSTEM_TABLE
*SystemTable
454 if (gShellAcpiViewHiiHandle
!= NULL
) {
455 HiiRemovePackages (gShellAcpiViewHiiHandle
);