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