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