]> git.proxmox.com Git - mirror_edk2.git/blob - ShellPkg/Library/UefiShellAcpiViewCommandLib/AcpiTableParser.c
501967c4dde680809c56e5d79ed744a1013a69e1
[mirror_edk2.git] / ShellPkg / Library / UefiShellAcpiViewCommandLib / AcpiTableParser.c
1 /** @file
2 ACPI table parser
3
4 Copyright (c) 2016 - 2020, ARM Limited. All rights reserved.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6 **/
7
8 #include <Uefi.h>
9 #include <IndustryStandard/Acpi.h>
10 #include <Library/UefiLib.h>
11 #include "AcpiParser.h"
12 #include "AcpiTableParser.h"
13 #include "AcpiView.h"
14
15 /**
16 A list of registered ACPI table parsers.
17 **/
18 STATIC ACPI_TABLE_PARSER mTableParserList[MAX_ACPI_TABLE_PARSERS];
19
20 /**
21 Register the ACPI table Parser
22
23 This function registers the ACPI table parser.
24
25 @param [in] Signature The ACPI table signature.
26 @param [in] ParserProc The ACPI table parser.
27
28 @retval EFI_SUCCESS The parser is registered.
29 @retval EFI_INVALID_PARAMETER A parameter is invalid.
30 @retval EFI_ALREADY_STARTED The parser for the Table
31 was already registered.
32 @retval EFI_OUT_OF_RESOURCES No space to register the
33 parser.
34 **/
35 EFI_STATUS
36 EFIAPI
37 RegisterParser (
38 IN UINT32 Signature,
39 IN PARSE_ACPI_TABLE_PROC ParserProc
40 )
41 {
42 UINT32 Index;
43
44 if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
45 return EFI_INVALID_PARAMETER;
46 }
47
48 // Search if a parser is already installed
49 for (Index = 0;
50 Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
51 Index++)
52 {
53 if (Signature == mTableParserList[Index].Signature) {
54 if (mTableParserList[Index].Parser != NULL) {
55 return EFI_ALREADY_STARTED;
56 }
57 }
58 }
59
60 // Find the first free slot and register the parser
61 for (Index = 0;
62 Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
63 Index++)
64 {
65 if (mTableParserList[Index].Signature == ACPI_PARSER_SIGNATURE_NULL) {
66 mTableParserList[Index].Signature = Signature;
67 mTableParserList[Index].Parser = ParserProc;
68 return EFI_SUCCESS;
69 }
70 }
71
72 // No free slot found
73 return EFI_OUT_OF_RESOURCES;
74 }
75
76 /**
77 Deregister the ACPI table Parser
78
79 This function deregisters the ACPI table parser.
80
81 @param [in] Signature The ACPI table signature.
82
83 @retval EFI_SUCCESS The parser was deregistered.
84 @retval EFI_INVALID_PARAMETER A parameter is invalid.
85 @retval EFI_NOT_FOUND A registered parser was not found.
86 **/
87 EFI_STATUS
88 EFIAPI
89 DeregisterParser (
90 IN UINT32 Signature
91 )
92 {
93 UINT32 Index;
94
95 if (Signature == ACPI_PARSER_SIGNATURE_NULL) {
96 return EFI_INVALID_PARAMETER;
97 }
98
99 for (Index = 0;
100 Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
101 Index++)
102 {
103 if (Signature == mTableParserList[Index].Signature) {
104 mTableParserList[Index].Signature = ACPI_PARSER_SIGNATURE_NULL;
105 mTableParserList[Index].Parser = NULL;
106 return EFI_SUCCESS;
107 }
108 }
109
110 // No matching registered parser found.
111 return EFI_NOT_FOUND;
112 }
113
114 /**
115 Get the ACPI table Parser
116
117 This function returns the ACPI table parser proc from the list of
118 registered parsers.
119
120 @param [in] Signature The ACPI table signature.
121 @param [out] ParserProc Pointer to a ACPI table parser proc.
122
123 @retval EFI_SUCCESS The parser was returned successfully.
124 @retval EFI_INVALID_PARAMETER A parameter is invalid.
125 @retval EFI_NOT_FOUND A registered parser was not found.
126 **/
127 EFI_STATUS
128 EFIAPI
129 GetParser (
130 IN UINT32 Signature,
131 OUT PARSE_ACPI_TABLE_PROC * ParserProc
132 )
133 {
134 UINT32 Index;
135
136 if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {
137 return EFI_INVALID_PARAMETER;
138 }
139
140 for (Index = 0;
141 Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));
142 Index++)
143 {
144 if (Signature == mTableParserList[Index].Signature) {
145 *ParserProc = mTableParserList[Index].Parser;
146 return EFI_SUCCESS;
147 }
148 }
149
150 // No matching registered parser found.
151 return EFI_NOT_FOUND;
152 }
153
154 /**
155 This function processes the ACPI tables.
156 This function calls ProcessTableReportOptions() to list the ACPI
157 tables, perform binary dump of the tables and determine if the
158 ACPI fields should be traced.
159
160 This function also invokes the parser for the ACPI tables.
161
162 This function also performs a RAW dump of the ACPI table including
163 the unknown/unparsed ACPI tables and validates the checksum.
164
165 @param [in] Ptr Pointer to the start of the ACPI
166 table data buffer.
167 **/
168 VOID
169 EFIAPI
170 ProcessAcpiTable (
171 IN UINT8* Ptr
172 )
173 {
174 EFI_STATUS Status;
175 BOOLEAN Trace;
176 CONST UINT32* AcpiTableSignature;
177 CONST UINT32* AcpiTableLength;
178 CONST UINT8* AcpiTableRevision;
179 CONST UINT8* SignaturePtr;
180 PARSE_ACPI_TABLE_PROC ParserProc;
181
182 ParseAcpiHeader (
183 Ptr,
184 &AcpiTableSignature,
185 &AcpiTableLength,
186 &AcpiTableRevision
187 );
188
189 Trace = ProcessTableReportOptions (
190 *AcpiTableSignature,
191 Ptr,
192 *AcpiTableLength
193 );
194
195 if (Trace) {
196 DumpRaw (Ptr, *AcpiTableLength);
197
198 // Do not process the ACPI table any further if the table length read
199 // is invalid. The ACPI table should at least contain the table header.
200 if (*AcpiTableLength < sizeof (EFI_ACPI_DESCRIPTION_HEADER)) {
201 SignaturePtr = (CONST UINT8*)AcpiTableSignature;
202 IncrementErrorCount ();
203 Print (
204 L"ERROR: Invalid %c%c%c%c table length. Length = %d\n",
205 SignaturePtr[0],
206 SignaturePtr[1],
207 SignaturePtr[2],
208 SignaturePtr[3],
209 *AcpiTableLength
210 );
211 return;
212 }
213
214 if (GetConsistencyChecking ()) {
215 VerifyChecksum (TRUE, Ptr, *AcpiTableLength);
216 }
217 }
218
219 Status = GetParser (*AcpiTableSignature, &ParserProc);
220 if (EFI_ERROR (Status)) {
221 // No registered parser found, do default handling.
222 if (Trace) {
223 DumpAcpiHeader (Ptr);
224 }
225 return;
226 }
227
228 ParserProc (
229 Trace,
230 Ptr,
231 *AcpiTableLength,
232 *AcpiTableRevision
233 );
234 }