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