]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
ShellPkg: acpiview: Add -r parameter for table requirements validation
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / UefiShellAcpiViewCommandLib.c
1 /** @file
2 Main file for 'acpiview' Shell command function.
3
4 Copyright (c) 2016 - 2019, ARM Limited. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7
8 #include <Guid/ShellLibHiiGuid.h>
9 #include <IndustryStandard/Acpi.h>
10 #include <Library/HiiLib.h>
11 #include <Library/ShellCommandLib.h>
12 #include <Library/UefiLib.h>
13 #include <Library/UefiBootServicesTableLib.h>
14 #include <Uefi.h>
15 #include "AcpiParser.h"
16 #include "AcpiTableParser.h"
17 #include "AcpiView.h"
18 #include "UefiShellAcpiViewCommandLib.h"
19
20 CONST CHAR16 gShellAcpiViewFileName[] = L"ShellCommand";
21
22 /**
23 A list of available table parsers.
24 */
25 STATIC
26 CONST
27 ACPI_TABLE_PARSER ParserList[] = {
28 {EFI_ACPI_6_2_BOOT_GRAPHICS_RESOURCE_TABLE_SIGNATURE, ParseAcpiBgrt},
29 {EFI_ACPI_6_2_DEBUG_PORT_2_TABLE_SIGNATURE, ParseAcpiDbg2},
30 {EFI_ACPI_6_2_DIFFERENTIATED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE,
31 ParseAcpiDsdt},
32 {EFI_ACPI_6_3_FIRMWARE_ACPI_CONTROL_STRUCTURE_SIGNATURE, ParseAcpiFacs},
33 {EFI_ACPI_6_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiFadt},
34 {EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiGtdt},
35 {EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE, ParseAcpiIort},
36 {EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiMadt},
37 {EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
38 ParseAcpiMcfg},
39 {EFI_ACPI_6_2_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE,
40 ParseAcpiPptt},
41 {RSDP_TABLE_INFO, ParseAcpiRsdp},
42 {EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE, ParseAcpiSlit},
43 {EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, ParseAcpiSpcr},
44 {EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE, ParseAcpiSrat},
45 {EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiSsdt},
46 {EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiXsdt}
47 };
48
49 /**
50 This function registers all the available table parsers.
51
52 @retval EFI_SUCCESS The parser is registered.
53 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
54 was already registered.
55 @retval EFI_INVALID_PARAMETER A parameter is invalid.
56 @retval EFI_OUT_OF_RESOURCES No space to register the
57 parser.
58 **/
59 EFI_STATUS
60 RegisterAllParsers (
61 )
62 {
63 EFI_STATUS Status;
64 UINTN Count;
65
66 Status = EFI_SUCCESS;
67 Count = sizeof (ParserList) / sizeof (ParserList[0]);
68
69 while (Count-- != 0) {
70 Status = RegisterParser (
71 ParserList[Count].Signature,
72 ParserList[Count].Parser
73 );
74 if (EFI_ERROR (Status)) {
75 return Status;
76 }
77 }
78 return Status;
79 }
80
81 /**
82 Return the file name of the help text file if not using HII.
83
84 @return The string pointer to the file name.
85 **/
86 CONST CHAR16*
87 EFIAPI
88 ShellCommandGetManFileNameAcpiView (
89 VOID
90 )
91 {
92 return gShellAcpiViewFileName;
93 }
94
95 /**
96 Constructor for the Shell AcpiView Command library.
97
98 Install the handlers for acpiview UEFI Shell command.
99
100 @param ImageHandle The image handle of the process.
101 @param SystemTable The EFI System Table pointer.
102
103 @retval EFI_SUCCESS The Shell command handlers were installed
104 successfully.
105 @retval EFI_DEVICE_ERROR Hii package failed to install.
106 **/
107 EFI_STATUS
108 EFIAPI
109 UefiShellAcpiViewCommandLibConstructor (
110 IN EFI_HANDLE ImageHandle,
111 IN EFI_SYSTEM_TABLE *SystemTable
112 )
113 {
114 EFI_STATUS Status;
115 gShellAcpiViewHiiHandle = NULL;
116
117 // Check Shell Profile Debug1 bit of the profiles mask
118 if ((PcdGet8 (PcdShellProfileMask) & BIT1) == 0) {
119 return EFI_SUCCESS;
120 }
121
122 Status = RegisterAllParsers ();
123 if (EFI_ERROR (Status)) {
124 Print (L"acpiview: Error failed to register parser.\n");
125 return Status;
126 }
127
128 gShellAcpiViewHiiHandle = HiiAddPackages (
129 &gShellAcpiViewHiiGuid,
130 gImageHandle,
131 UefiShellAcpiViewCommandLibStrings,
132 NULL
133 );
134 if (gShellAcpiViewHiiHandle == NULL) {
135 return EFI_DEVICE_ERROR;
136 }
137 // Install our Shell command handler
138 ShellCommandRegisterCommandName (
139 L"acpiview",
140 ShellCommandRunAcpiView,
141 ShellCommandGetManFileNameAcpiView,
142 0,
143 L"acpiview",
144 TRUE,
145 gShellAcpiViewHiiHandle,
146 STRING_TOKEN (STR_GET_HELP_ACPIVIEW)
147 );
148
149 return EFI_SUCCESS;
150 }
151
152 /**
153 Destructor for the library. free any resources.
154
155 @param ImageHandle The image handle of the process.
156 @param SystemTable The EFI System Table pointer.
157 **/
158 EFI_STATUS
159 EFIAPI
160 UefiShellAcpiViewCommandLibDestructor (
161 IN EFI_HANDLE ImageHandle,
162 IN EFI_SYSTEM_TABLE *SystemTable
163 )
164 {
165 if (gShellAcpiViewHiiHandle != NULL) {
166 HiiRemovePackages (gShellAcpiViewHiiHandle);
167 }
168 return EFI_SUCCESS;
169 }