]>
Commit | Line | Data |
---|---|---|
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 |
24 | STATIC 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 |
41 | EFI_STATUS\r |
42 | EFIAPI\r | |
43 | RegisterParser (\r | |
44 | IN UINT32 Signature,\r | |
45 | IN PARSE_ACPI_TABLE_PROC ParserProc\r | |
46 | )\r | |
47 | {\r | |
f75c7478 | 48 | UINT32 Index;\r |
ee4dc24f RN |
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 | |
f75c7478 DB |
55 | for (Index = 0;\r |
56 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r | |
57 | Index++)\r | |
ee4dc24f | 58 | {\r |
f75c7478 DB |
59 | if (Signature == mTableParserList[Index].Signature) {\r |
60 | if (mTableParserList[Index].Parser != NULL) {\r | |
ee4dc24f RN |
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 | |
f75c7478 DB |
67 | for (Index = 0;\r |
68 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r | |
69 | Index++)\r | |
ee4dc24f | 70 | {\r |
f75c7478 DB |
71 | if (mTableParserList[Index].Signature == ACPI_PARSER_SIGNATURE_NULL) {\r |
72 | mTableParserList[Index].Signature = Signature;\r | |
73 | mTableParserList[Index].Parser = ParserProc;\r | |
ee4dc24f RN |
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 |
93 | EFI_STATUS\r |
94 | EFIAPI\r | |
95 | DeregisterParser (\r | |
96 | IN UINT32 Signature\r | |
97 | )\r | |
98 | {\r | |
f75c7478 | 99 | UINT32 Index;\r |
ee4dc24f RN |
100 | \r |
101 | if (Signature == ACPI_PARSER_SIGNATURE_NULL) {\r | |
102 | return EFI_INVALID_PARAMETER;\r | |
103 | }\r | |
104 | \r | |
f75c7478 DB |
105 | for (Index = 0;\r |
106 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r | |
107 | Index++)\r | |
ee4dc24f | 108 | {\r |
f75c7478 DB |
109 | if (Signature == mTableParserList[Index].Signature) {\r |
110 | mTableParserList[Index].Signature = ACPI_PARSER_SIGNATURE_NULL;\r | |
111 | mTableParserList[Index].Parser = NULL;\r | |
ee4dc24f RN |
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 |
133 | EFI_STATUS\r |
134 | EFIAPI\r | |
135 | GetParser (\r | |
136 | IN UINT32 Signature,\r | |
137 | OUT PARSE_ACPI_TABLE_PROC * ParserProc\r | |
138 | )\r | |
139 | {\r | |
f75c7478 | 140 | UINT32 Index;\r |
ee4dc24f RN |
141 | \r |
142 | if ((ParserProc == NULL) || (Signature == ACPI_PARSER_SIGNATURE_NULL)) {\r | |
143 | return EFI_INVALID_PARAMETER;\r | |
144 | }\r | |
145 | \r | |
f75c7478 DB |
146 | for (Index = 0;\r |
147 | Index < (sizeof (mTableParserList) / sizeof (mTableParserList[0]));\r | |
148 | Index++)\r | |
ee4dc24f | 149 | {\r |
f75c7478 DB |
150 | if (Signature == mTableParserList[Index].Signature) {\r |
151 | *ParserProc = mTableParserList[Index].Parser;\r | |
ee4dc24f RN |
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 |
174 | VOID\r |
175 | EFIAPI\r | |
176 | ProcessAcpiTable (\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 |