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