]> git.proxmox.com Git - mirror_edk2.git/blame - ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
ShellPkg/UefiShellAcpiViewCommandLib: Fix ECC issues
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / AcpiTableParser.c
CommitLineData
a6eaba4d 1/** @file\r
ee4dc24f
RN
2 ACPI table parser\r
3\r
4 Copyright (c) 2016 - 2018, ARM Limited. All rights reserved.\r
5 This program and the accompanying materials\r
6 are licensed and made available under the terms and conditions of the BSD License\r
7 which accompanies this distribution. The full text of the license may be found at\r
8 http://opensource.org/licenses/bsd-license.php\r
9\r
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12**/\r
13\r
14#include <Uefi.h>\r
15#include <IndustryStandard/Acpi.h>\r
16#include <Library/UefiLib.h>\r
17#include "AcpiParser.h"\r
18#include "AcpiTableParser.h"\r
19#include "AcpiView.h"\r
20\r
a6eaba4d
DB
21/**\r
22 A list of registered ACPI table parsers.\r
23**/\r
ee4dc24f
RN
24STATIC ACPI_TABLE_PARSER mTableParserList[MAX_ACPI_TABLE_PARSERS];\r
25\r
a6eaba4d
DB
26/**\r
27 Register the ACPI table Parser\r
ee4dc24f
RN
28\r
29 This function registers the ACPI table parser.\r
30\r
31 @param [in] Signature The ACPI table signature.\r
32 @param [in] ParserProc The ACPI table parser.\r
33\r
34 @retval EFI_SUCCESS The parser is registered.\r
35 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
36 @retval EFI_ALREADY_STARTED The parser for the Table\r
37 was already registered.\r
38 @retval EFI_OUT_OF_RESOURCES No space to register the\r
39 parser.\r
a6eaba4d 40**/\r
ee4dc24f
RN
41EFI_STATUS\r
42EFIAPI\r
43RegisterParser (\r
44 IN UINT32 Signature,\r
45 IN PARSE_ACPI_TABLE_PROC ParserProc\r
46 )\r
47{\r
48 UINT32 index;\r
49\r
50 if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {\r
51 return EFI_INVALID_PARAMETER;\r
52 }\r
53\r
54 // Search if a parser is already installed\r
55 for (index = 0;\r
56 index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r
57 index++)\r
58 {\r
59 if (Signature == mTableParserList[index].Signature) {\r
60 if (mTableParserList[index].Parser != NULL) {\r
61 return EFI_ALREADY_STARTED;\r
62 }\r
63 }\r
64 }\r
65\r
66 // Find the first free slot and register the parser\r
67 for (index = 0;\r
68 index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r
69 index++)\r
70 {\r
71 if (mTableParserList[index].Signature == ACPI_PARSER_SIGNATURE_NULL) {\r
72 mTableParserList[index].Signature = Signature;\r
73 mTableParserList[index].Parser = ParserProc;\r
74 return EFI_SUCCESS;\r
75 }\r
76 }\r
77\r
78 // No free slot found\r
79 return EFI_OUT_OF_RESOURCES;\r
80}\r
81\r
a6eaba4d
DB
82/**\r
83 Deregister the ACPI table Parser\r
ee4dc24f
RN
84\r
85 This function deregisters the ACPI table parser.\r
86\r
87 @param [in] Signature The ACPI table signature.\r
88\r
89 @retval EFI_SUCCESS The parser was deregistered.\r
90 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
91 @retval EFI_NOT_FOUND A registered parser was not found.\r
a6eaba4d 92**/\r
ee4dc24f
RN
93EFI_STATUS\r
94EFIAPI\r
95DeregisterParser (\r
96 IN UINT32 Signature\r
97 )\r
98{\r
99 UINT32 index;\r
100\r
101 if (Signature == ACPI_PARSER_SIGNATURE_NULL) {\r
102 return EFI_INVALID_PARAMETER;\r
103 }\r
104\r
105 for (index = 0;\r
106 index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r
107 index++)\r
108 {\r
109 if (Signature == mTableParserList[index].Signature) {\r
110 mTableParserList[index].Signature = ACPI_PARSER_SIGNATURE_NULL;\r
111 mTableParserList[index].Parser = NULL;\r
112 return EFI_SUCCESS;\r
113 }\r
114 }\r
115\r
116 // No matching registered parser found.\r
117 return EFI_NOT_FOUND;\r
118}\r
119\r
a6eaba4d
DB
120/**\r
121 Get the ACPI table Parser\r
ee4dc24f
RN
122\r
123 This function returns the ACPI table parser proc from the list of\r
124 registered parsers.\r
125\r
126 @param [in] Signature The ACPI table signature.\r
127 @param [out] ParserProc Pointer to a ACPI table parser proc.\r
128\r
129 @retval EFI_SUCCESS The parser was returned successfully.\r
130 @retval EFI_INVALID_PARAMETER A parameter is invalid.\r
131 @retval EFI_NOT_FOUND A registered parser was not found.\r
a6eaba4d 132**/\r
ee4dc24f
RN
133EFI_STATUS\r
134EFIAPI\r
135GetParser (\r
136 IN UINT32 Signature,\r
137 OUT PARSE_ACPI_TABLE_PROC * ParserProc\r
138 )\r
139{\r
140 UINT32 index;\r
141\r
142 if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {\r
143 return EFI_INVALID_PARAMETER;\r
144 }\r
145\r
146 for (index = 0;\r
147 index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r
148 index++)\r
149 {\r
150 if (Signature == mTableParserList[index].Signature) {\r
151 *ParserProc = mTableParserList[index].Parser;\r
152 return EFI_SUCCESS;\r
153 }\r
154 }\r
155\r
156 // No matching registered parser found.\r
157 return EFI_NOT_FOUND;\r
158}\r
159\r
a6eaba4d
DB
160/**\r
161 This function processes the ACPI tables.\r
ee4dc24f
RN
162 This function calls ProcessTableReportOptions() to list the ACPI\r
163 tables, perform binary dump of the tables and determine if the\r
164 ACPI fields should be traced.\r
165\r
166 This function also invokes the parser for the ACPI tables.\r
167\r
168 This function also performs a RAW dump of the ACPI table including\r
169 the unknown/unparsed ACPI tables and validates the checksum.\r
170\r
171 @param [in] Ptr Pointer to the start of the ACPI\r
172 table data buffer.\r
a6eaba4d 173**/\r
ee4dc24f
RN
174VOID\r
175EFIAPI\r
176ProcessAcpiTable (\r
177 IN UINT8* Ptr\r
178 )\r
179{\r
180 EFI_STATUS Status;\r
181 BOOLEAN Trace;\r
182 CONST UINT32* AcpiTableSignature;\r
183 CONST UINT32* AcpiTableLength;\r
184 CONST UINT8* AcpiTableRevision;\r
185 PARSE_ACPI_TABLE_PROC ParserProc;\r
186\r
187 ParseAcpiHeader (\r
188 Ptr,\r
189 &AcpiTableSignature,\r
190 &AcpiTableLength,\r
191 &AcpiTableRevision\r
192 );\r
193\r
194 Trace = ProcessTableReportOptions (\r
195 *AcpiTableSignature,\r
196 Ptr,\r
197 *AcpiTableLength\r
198 );\r
199\r
200 if (Trace) {\r
201 DumpRaw (Ptr, *AcpiTableLength);\r
202 VerifyChecksum (TRUE, Ptr, *AcpiTableLength);\r
203 }\r
204\r
205 Status = GetParser (*AcpiTableSignature, &ParserProc);\r
206 if (EFI_ERROR (Status)) {\r
207 // No registered parser found, do default handling.\r
208 if (Trace) {\r
209 DumpAcpiHeader (Ptr);\r
210 }\r
211 return;\r
212 }\r
213\r
214 ParserProc (\r
215 Trace,\r
216 Ptr,\r
217 *AcpiTableLength,\r
218 *AcpiTableRevision\r
219 );\r
220}\r