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