]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/UefiShellAcpiViewCommandLib.c
ShellPkg: Display VENDOR_ID in ASCII when parsing PPTT
[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_2_FIXED_ACPI_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiFadt},
33 {EFI_ACPI_6_2_GENERIC_TIMER_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiGtdt},
34 {EFI_ACPI_6_2_IO_REMAPPING_TABLE_SIGNATURE, ParseAcpiIort},
35 {EFI_ACPI_6_2_MULTIPLE_APIC_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiMadt},
36 {EFI_ACPI_6_2_PCI_EXPRESS_MEMORY_MAPPED_CONFIGURATION_SPACE_BASE_ADDRESS_DESCRIPTION_TABLE_SIGNATURE,
37 ParseAcpiMcfg},
38 {EFI_ACPI_6_2_PROCESSOR_PROPERTIES_TOPOLOGY_TABLE_STRUCTURE_SIGNATURE,
39 ParseAcpiPptt},
40 {RSDP_TABLE_INFO, ParseAcpiRsdp},
41 {EFI_ACPI_6_2_SYSTEM_LOCALITY_INFORMATION_TABLE_SIGNATURE, ParseAcpiSlit},
42 {EFI_ACPI_6_2_SERIAL_PORT_CONSOLE_REDIRECTION_TABLE_SIGNATURE, ParseAcpiSpcr},
43 {EFI_ACPI_6_2_SYSTEM_RESOURCE_AFFINITY_TABLE_SIGNATURE, ParseAcpiSrat},
44 {EFI_ACPI_6_2_SECONDARY_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiSsdt},
45 {EFI_ACPI_6_2_EXTENDED_SYSTEM_DESCRIPTION_TABLE_SIGNATURE, ParseAcpiXsdt}
46 };
47
48 /**
49 This function registers all the available table parsers.
50
51 @retval EFI_SUCCESS The parser is registered.
52 @retval EFI_ALREADY_STARTED The parser for the ACPI Table
53 was already registered.
54 @retval EFI_INVALID_PARAMETER A parameter is invalid.
55 @retval EFI_OUT_OF_RESOURCES No space to register the
56 parser.
57 **/
58 EFI_STATUS
59 RegisterAllParsers (
60 )
61 {
62 EFI_STATUS Status;
63 UINTN Count;
64
65 Status = EFI_SUCCESS;
66 Count = sizeof (ParserList) / sizeof (ParserList[0]);
67
68 while (Count-- != 0) {
69 Status = RegisterParser (
70 ParserList[Count].Signature,
71 ParserList[Count].Parser
72 );
73 if (EFI_ERROR (Status)) {
74 return Status;
75 }
76 }
77 return Status;
78 }
79
80 /**
81 Return the file name of the help text file if not using HII.
82
83 @return The string pointer to the file name.
84 **/
85 CONST CHAR16*
86 EFIAPI
87 ShellCommandGetManFileNameAcpiView (
88 VOID
89 )
90 {
91 return gShellAcpiViewFileName;
92 }
93
94 /**
95 Constructor for the Shell AcpiView Command library.
96
97 Install the handlers for acpiview UEFI Shell command.
98
99 @param ImageHandle The image handle of the process.
100 @param SystemTable The EFI System Table pointer.
101
102 @retval EFI_SUCCESS The Shell command handlers were installed
103 successfully.
104 @retval EFI_DEVICE_ERROR Hii package failed to install.
105 **/
106 EFI_STATUS
107 EFIAPI
108 UefiShellAcpiViewCommandLibConstructor (
109 IN EFI_HANDLE ImageHandle,
110 IN EFI_SYSTEM_TABLE *SystemTable
111 )
112 {
113 EFI_STATUS Status;
114 gShellAcpiViewHiiHandle = NULL;
115
116 // Check Shell Profile Debug1 bit of the profiles mask
117 if ((PcdGet8 (PcdShellProfileMask) & BIT1) == 0) {
118 return EFI_SUCCESS;
119 }
120
121 Status = RegisterAllParsers ();
122 if (EFI_ERROR (Status)) {
123 Print (L"acpiview: Error failed to register parser.\n");
124 return Status;
125 }
126
127 gShellAcpiViewHiiHandle = HiiAddPackages (
128 &gShellAcpiViewHiiGuid,
129 gImageHandle,
130 UefiShellAcpiViewCommandLibStrings,
131 NULL
132 );
133 if (gShellAcpiViewHiiHandle == NULL) {
134 return EFI_DEVICE_ERROR;
135 }
136 // Install our Shell command handler
137 ShellCommandRegisterCommandName (
138 L"acpiview",
139 ShellCommandRunAcpiView,
140 ShellCommandGetManFileNameAcpiView,
141 0,
142 L"acpiview",
143 TRUE,
144 gShellAcpiViewHiiHandle,
145 STRING_TOKEN (STR_GET_HELP_ACPIVIEW)
146 );
147
148 return EFI_SUCCESS;
149 }
150
151 /**
152 Destructor for the library. free any resources.
153
154 @param ImageHandle The image handle of the process.
155 @param SystemTable The EFI System Table pointer.
156 **/
157 EFI_STATUS
158 EFIAPI
159 UefiShellAcpiViewCommandLibDestructor (
160 IN EFI_HANDLE ImageHandle,
161 IN EFI_SYSTEM_TABLE *SystemTable
162 )
163 {
164 if (gShellAcpiViewHiiHandle != NULL) {
165 HiiRemovePackages (gShellAcpiViewHiiHandle);
166 }
167 return EFI_SUCCESS;
168 }