nsparse.c revision 1.1.1.10 1 1.1 jruoho /******************************************************************************
2 1.1 jruoho *
3 1.1 jruoho * Module Name: nsparse - namespace interface to AML parser
4 1.1 jruoho *
5 1.1 jruoho *****************************************************************************/
6 1.1 jruoho
7 1.1.1.2 jruoho /*
8 1.1.1.10 christos * Copyright (C) 2000 - 2018, Intel Corp.
9 1.1 jruoho * All rights reserved.
10 1.1 jruoho *
11 1.1.1.2 jruoho * Redistribution and use in source and binary forms, with or without
12 1.1.1.2 jruoho * modification, are permitted provided that the following conditions
13 1.1.1.2 jruoho * are met:
14 1.1.1.2 jruoho * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2 jruoho * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2 jruoho * without modification.
17 1.1.1.2 jruoho * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2 jruoho * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2 jruoho * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2 jruoho * including a substantially similar Disclaimer requirement for further
21 1.1.1.2 jruoho * binary redistribution.
22 1.1.1.2 jruoho * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2 jruoho * of any contributors may be used to endorse or promote products derived
24 1.1.1.2 jruoho * from this software without specific prior written permission.
25 1.1.1.2 jruoho *
26 1.1.1.2 jruoho * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2 jruoho * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2 jruoho * Software Foundation.
29 1.1.1.2 jruoho *
30 1.1.1.2 jruoho * NO WARRANTY
31 1.1.1.2 jruoho * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2 jruoho * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2 jruoho * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2 jruoho * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2 jruoho * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2 jruoho * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2 jruoho * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2 jruoho * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2 jruoho * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2 jruoho * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2 jruoho * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2 jruoho */
43 1.1 jruoho
44 1.1 jruoho #include "acpi.h"
45 1.1 jruoho #include "accommon.h"
46 1.1 jruoho #include "acnamesp.h"
47 1.1 jruoho #include "acparser.h"
48 1.1 jruoho #include "acdispat.h"
49 1.1 jruoho #include "actables.h"
50 1.1.1.8 christos #include "acinterp.h"
51 1.1 jruoho
52 1.1 jruoho
53 1.1 jruoho #define _COMPONENT ACPI_NAMESPACE
54 1.1 jruoho ACPI_MODULE_NAME ("nsparse")
55 1.1 jruoho
56 1.1 jruoho
57 1.1 jruoho /*******************************************************************************
58 1.1 jruoho *
59 1.1.1.8 christos * FUNCTION: NsExecuteTable
60 1.1.1.8 christos *
61 1.1.1.8 christos * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
62 1.1.1.8 christos * StartNode - Where to enter the table into the namespace
63 1.1.1.8 christos *
64 1.1.1.8 christos * RETURN: Status
65 1.1.1.8 christos *
66 1.1.1.10 christos * DESCRIPTION: Load ACPI/AML table by executing the entire table as a single
67 1.1.1.10 christos * large control method.
68 1.1.1.10 christos *
69 1.1.1.10 christos * NOTE: The point of this is to execute any module-level code in-place
70 1.1.1.10 christos * as the table is parsed. Some AML code depends on this behavior.
71 1.1.1.10 christos *
72 1.1.1.10 christos * It is a run-time option at this time, but will eventually become
73 1.1.1.10 christos * the default.
74 1.1.1.10 christos *
75 1.1.1.10 christos * Note: This causes the table to only have a single-pass parse.
76 1.1.1.10 christos * However, this is compatible with other ACPI implementations.
77 1.1.1.8 christos *
78 1.1.1.8 christos ******************************************************************************/
79 1.1.1.8 christos
80 1.1.1.8 christos ACPI_STATUS
81 1.1.1.8 christos AcpiNsExecuteTable (
82 1.1.1.8 christos UINT32 TableIndex,
83 1.1.1.8 christos ACPI_NAMESPACE_NODE *StartNode)
84 1.1.1.8 christos {
85 1.1.1.8 christos ACPI_STATUS Status;
86 1.1.1.8 christos ACPI_TABLE_HEADER *Table;
87 1.1.1.8 christos ACPI_OWNER_ID OwnerId;
88 1.1.1.8 christos ACPI_EVALUATE_INFO *Info = NULL;
89 1.1.1.8 christos UINT32 AmlLength;
90 1.1.1.8 christos UINT8 *AmlStart;
91 1.1.1.8 christos ACPI_OPERAND_OBJECT *MethodObj = NULL;
92 1.1.1.8 christos
93 1.1.1.8 christos
94 1.1.1.8 christos ACPI_FUNCTION_TRACE (NsExecuteTable);
95 1.1.1.8 christos
96 1.1.1.8 christos
97 1.1.1.8 christos Status = AcpiGetTableByIndex (TableIndex, &Table);
98 1.1.1.8 christos if (ACPI_FAILURE (Status))
99 1.1.1.8 christos {
100 1.1.1.8 christos return_ACPI_STATUS (Status);
101 1.1.1.8 christos }
102 1.1.1.8 christos
103 1.1.1.8 christos /* Table must consist of at least a complete header */
104 1.1.1.8 christos
105 1.1.1.8 christos if (Table->Length < sizeof (ACPI_TABLE_HEADER))
106 1.1.1.8 christos {
107 1.1.1.8 christos return_ACPI_STATUS (AE_BAD_HEADER);
108 1.1.1.8 christos }
109 1.1.1.8 christos
110 1.1.1.8 christos AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
111 1.1.1.8 christos AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
112 1.1.1.8 christos
113 1.1.1.8 christos Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
114 1.1.1.8 christos if (ACPI_FAILURE (Status))
115 1.1.1.8 christos {
116 1.1.1.8 christos return_ACPI_STATUS (Status);
117 1.1.1.8 christos }
118 1.1.1.8 christos
119 1.1.1.8 christos /* Create, initialize, and link a new temporary method object */
120 1.1.1.8 christos
121 1.1.1.8 christos MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
122 1.1.1.8 christos if (!MethodObj)
123 1.1.1.8 christos {
124 1.1.1.8 christos return_ACPI_STATUS (AE_NO_MEMORY);
125 1.1.1.8 christos }
126 1.1.1.8 christos
127 1.1.1.8 christos /* Allocate the evaluation information block */
128 1.1.1.8 christos
129 1.1.1.8 christos Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
130 1.1.1.8 christos if (!Info)
131 1.1.1.8 christos {
132 1.1.1.8 christos Status = AE_NO_MEMORY;
133 1.1.1.8 christos goto Cleanup;
134 1.1.1.8 christos }
135 1.1.1.8 christos
136 1.1.1.10 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
137 1.1.1.10 christos "%s: Create table pseudo-method for [%4.4s] @%p, method %p\n",
138 1.1.1.10 christos ACPI_GET_FUNCTION_NAME, Table->Signature, Table, MethodObj));
139 1.1.1.8 christos
140 1.1.1.8 christos MethodObj->Method.AmlStart = AmlStart;
141 1.1.1.8 christos MethodObj->Method.AmlLength = AmlLength;
142 1.1.1.8 christos MethodObj->Method.OwnerId = OwnerId;
143 1.1.1.8 christos MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
144 1.1.1.8 christos
145 1.1.1.8 christos Info->PassNumber = ACPI_IMODE_EXECUTE;
146 1.1.1.8 christos Info->Node = StartNode;
147 1.1.1.8 christos Info->ObjDesc = MethodObj;
148 1.1.1.8 christos Info->NodeFlags = Info->Node->Flags;
149 1.1.1.8 christos Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
150 1.1.1.8 christos if (!Info->FullPathname)
151 1.1.1.8 christos {
152 1.1.1.8 christos Status = AE_NO_MEMORY;
153 1.1.1.8 christos goto Cleanup;
154 1.1.1.8 christos }
155 1.1.1.8 christos
156 1.1.1.8 christos Status = AcpiPsExecuteTable (Info);
157 1.1.1.8 christos
158 1.1.1.8 christos Cleanup:
159 1.1.1.8 christos if (Info)
160 1.1.1.8 christos {
161 1.1.1.8 christos ACPI_FREE (Info->FullPathname);
162 1.1.1.8 christos Info->FullPathname = NULL;
163 1.1.1.8 christos }
164 1.1.1.8 christos ACPI_FREE (Info);
165 1.1.1.8 christos AcpiUtRemoveReference (MethodObj);
166 1.1.1.8 christos return_ACPI_STATUS (Status);
167 1.1.1.8 christos }
168 1.1.1.8 christos
169 1.1.1.8 christos
170 1.1.1.8 christos /*******************************************************************************
171 1.1.1.8 christos *
172 1.1 jruoho * FUNCTION: NsOneCompleteParse
173 1.1 jruoho *
174 1.1 jruoho * PARAMETERS: PassNumber - 1 or 2
175 1.1 jruoho * TableDesc - The table to be parsed.
176 1.1 jruoho *
177 1.1 jruoho * RETURN: Status
178 1.1 jruoho *
179 1.1 jruoho * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
180 1.1 jruoho *
181 1.1 jruoho ******************************************************************************/
182 1.1 jruoho
183 1.1 jruoho ACPI_STATUS
184 1.1 jruoho AcpiNsOneCompleteParse (
185 1.1 jruoho UINT32 PassNumber,
186 1.1 jruoho UINT32 TableIndex,
187 1.1 jruoho ACPI_NAMESPACE_NODE *StartNode)
188 1.1 jruoho {
189 1.1 jruoho ACPI_PARSE_OBJECT *ParseRoot;
190 1.1 jruoho ACPI_STATUS Status;
191 1.1 jruoho UINT32 AmlLength;
192 1.1 jruoho UINT8 *AmlStart;
193 1.1 jruoho ACPI_WALK_STATE *WalkState;
194 1.1 jruoho ACPI_TABLE_HEADER *Table;
195 1.1 jruoho ACPI_OWNER_ID OwnerId;
196 1.1 jruoho
197 1.1 jruoho
198 1.1 jruoho ACPI_FUNCTION_TRACE (NsOneCompleteParse);
199 1.1 jruoho
200 1.1 jruoho
201 1.1.1.6 christos Status = AcpiGetTableByIndex (TableIndex, &Table);
202 1.1.1.6 christos if (ACPI_FAILURE (Status))
203 1.1.1.6 christos {
204 1.1.1.6 christos return_ACPI_STATUS (Status);
205 1.1.1.6 christos }
206 1.1.1.6 christos
207 1.1.1.6 christos /* Table must consist of at least a complete header */
208 1.1.1.6 christos
209 1.1.1.6 christos if (Table->Length < sizeof (ACPI_TABLE_HEADER))
210 1.1.1.6 christos {
211 1.1.1.6 christos return_ACPI_STATUS (AE_BAD_HEADER);
212 1.1.1.6 christos }
213 1.1.1.6 christos
214 1.1.1.6 christos AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
215 1.1.1.6 christos AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
216 1.1.1.6 christos
217 1.1 jruoho Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
218 1.1 jruoho if (ACPI_FAILURE (Status))
219 1.1 jruoho {
220 1.1 jruoho return_ACPI_STATUS (Status);
221 1.1 jruoho }
222 1.1 jruoho
223 1.1 jruoho /* Create and init a Root Node */
224 1.1 jruoho
225 1.1.1.6 christos ParseRoot = AcpiPsCreateScopeOp (AmlStart);
226 1.1 jruoho if (!ParseRoot)
227 1.1 jruoho {
228 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
229 1.1 jruoho }
230 1.1 jruoho
231 1.1 jruoho /* Create and initialize a new walk state */
232 1.1 jruoho
233 1.1 jruoho WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
234 1.1 jruoho if (!WalkState)
235 1.1 jruoho {
236 1.1 jruoho AcpiPsFreeOp (ParseRoot);
237 1.1 jruoho return_ACPI_STATUS (AE_NO_MEMORY);
238 1.1 jruoho }
239 1.1 jruoho
240 1.1.1.6 christos Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
241 1.1.1.7 christos AmlStart, AmlLength, NULL, (UINT8) PassNumber);
242 1.1 jruoho if (ACPI_FAILURE (Status))
243 1.1 jruoho {
244 1.1 jruoho AcpiDsDeleteWalkState (WalkState);
245 1.1.1.6 christos goto Cleanup;
246 1.1 jruoho }
247 1.1 jruoho
248 1.1.1.6 christos /* Found OSDT table, enable the namespace override feature */
249 1.1 jruoho
250 1.1.1.6 christos if (ACPI_COMPARE_NAME(Table->Signature, ACPI_SIG_OSDT) &&
251 1.1.1.6 christos PassNumber == ACPI_IMODE_LOAD_PASS1)
252 1.1 jruoho {
253 1.1.1.6 christos WalkState->NamespaceOverride = TRUE;
254 1.1 jruoho }
255 1.1 jruoho
256 1.1 jruoho /* StartNode is the default location to load the table */
257 1.1 jruoho
258 1.1 jruoho if (StartNode && StartNode != AcpiGbl_RootNode)
259 1.1 jruoho {
260 1.1.1.7 christos Status = AcpiDsScopeStackPush (
261 1.1.1.7 christos StartNode, ACPI_TYPE_METHOD, WalkState);
262 1.1 jruoho if (ACPI_FAILURE (Status))
263 1.1 jruoho {
264 1.1 jruoho AcpiDsDeleteWalkState (WalkState);
265 1.1 jruoho goto Cleanup;
266 1.1 jruoho }
267 1.1 jruoho }
268 1.1 jruoho
269 1.1 jruoho /* Parse the AML */
270 1.1 jruoho
271 1.1.1.7 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
272 1.1.1.7 christos "*PARSE* pass %u parse\n", PassNumber));
273 1.1.1.8 christos AcpiExEnterInterpreter ();
274 1.1 jruoho Status = AcpiPsParseAml (WalkState);
275 1.1.1.8 christos AcpiExExitInterpreter ();
276 1.1 jruoho
277 1.1 jruoho Cleanup:
278 1.1 jruoho AcpiPsDeleteParseTree (ParseRoot);
279 1.1 jruoho return_ACPI_STATUS (Status);
280 1.1 jruoho }
281 1.1 jruoho
282 1.1 jruoho
283 1.1 jruoho /*******************************************************************************
284 1.1 jruoho *
285 1.1 jruoho * FUNCTION: AcpiNsParseTable
286 1.1 jruoho *
287 1.1 jruoho * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
288 1.1 jruoho * StartNode - Where to enter the table into the namespace
289 1.1 jruoho *
290 1.1 jruoho * RETURN: Status
291 1.1 jruoho *
292 1.1 jruoho * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
293 1.1 jruoho *
294 1.1 jruoho ******************************************************************************/
295 1.1 jruoho
296 1.1 jruoho ACPI_STATUS
297 1.1 jruoho AcpiNsParseTable (
298 1.1 jruoho UINT32 TableIndex,
299 1.1 jruoho ACPI_NAMESPACE_NODE *StartNode)
300 1.1 jruoho {
301 1.1 jruoho ACPI_STATUS Status;
302 1.1 jruoho
303 1.1 jruoho
304 1.1 jruoho ACPI_FUNCTION_TRACE (NsParseTable);
305 1.1 jruoho
306 1.1 jruoho
307 1.1.1.10 christos if (AcpiGbl_ExecuteTablesAsMethods)
308 1.1 jruoho {
309 1.1.1.10 christos /*
310 1.1.1.10 christos * This case executes the AML table as one large control method.
311 1.1.1.10 christos * The point of this is to execute any module-level code in-place
312 1.1.1.10 christos * as the table is parsed. Some AML code depends on this behavior.
313 1.1.1.10 christos *
314 1.1.1.10 christos * It is a run-time option at this time, but will eventually become
315 1.1.1.10 christos * the default.
316 1.1.1.10 christos *
317 1.1.1.10 christos * Note: This causes the table to only have a single-pass parse.
318 1.1.1.10 christos * However, this is compatible with other ACPI implementations.
319 1.1.1.10 christos */
320 1.1.1.10 christos ACPI_DEBUG_PRINT_RAW ((ACPI_DB_PARSE,
321 1.1.1.10 christos "%s: **** Start table execution pass\n", ACPI_GET_FUNCTION_NAME));
322 1.1 jruoho
323 1.1.1.8 christos Status = AcpiNsExecuteTable (TableIndex, StartNode);
324 1.1.1.8 christos if (ACPI_FAILURE (Status))
325 1.1.1.8 christos {
326 1.1.1.8 christos return_ACPI_STATUS (Status);
327 1.1.1.8 christos }
328 1.1.1.8 christos }
329 1.1.1.8 christos else
330 1.1 jruoho {
331 1.1.1.8 christos /*
332 1.1.1.8 christos * AML Parse, pass 1
333 1.1.1.8 christos *
334 1.1.1.8 christos * In this pass, we load most of the namespace. Control methods
335 1.1.1.8 christos * are not parsed until later. A parse tree is not created.
336 1.1.1.8 christos * Instead, each Parser Op subtree is deleted when it is finished.
337 1.1.1.8 christos * This saves a great deal of memory, and allows a small cache of
338 1.1.1.8 christos * parse objects to service the entire parse. The second pass of
339 1.1.1.8 christos * the parse then performs another complete parse of the AML.
340 1.1.1.8 christos */
341 1.1.1.8 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
342 1.1.1.8 christos
343 1.1.1.8 christos Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
344 1.1.1.8 christos TableIndex, StartNode);
345 1.1.1.8 christos if (ACPI_FAILURE (Status))
346 1.1.1.8 christos {
347 1.1.1.8 christos return_ACPI_STATUS (Status);
348 1.1.1.8 christos }
349 1.1.1.8 christos
350 1.1.1.8 christos /*
351 1.1.1.8 christos * AML Parse, pass 2
352 1.1.1.8 christos *
353 1.1.1.8 christos * In this pass, we resolve forward references and other things
354 1.1.1.8 christos * that could not be completed during the first pass.
355 1.1.1.8 christos * Another complete parse of the AML is performed, but the
356 1.1.1.8 christos * overhead of this is compensated for by the fact that the
357 1.1.1.8 christos * parse objects are all cached.
358 1.1.1.8 christos */
359 1.1.1.8 christos ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
360 1.1.1.8 christos Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
361 1.1.1.8 christos TableIndex, StartNode);
362 1.1.1.8 christos if (ACPI_FAILURE (Status))
363 1.1.1.8 christos {
364 1.1.1.8 christos return_ACPI_STATUS (Status);
365 1.1.1.8 christos }
366 1.1 jruoho }
367 1.1 jruoho
368 1.1 jruoho return_ACPI_STATUS (Status);
369 1.1 jruoho }
370