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