1 /******************************************************************************
3 * Module Name: nsparse - namespace interface to AML parser
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2016, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
53 #define _COMPONENT ACPI_NAMESPACE
54 ACPI_MODULE_NAME ("nsparse")
57 /*******************************************************************************
59 * FUNCTION: NsExecuteTable
61 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
62 * StartNode - Where to enter the table into the namespace
66 * DESCRIPTION: Load ACPI/AML table by executing the entire table as a
69 ******************************************************************************/
74 ACPI_NAMESPACE_NODE *StartNode)
77 ACPI_TABLE_HEADER *Table;
78 ACPI_OWNER_ID OwnerId;
79 ACPI_EVALUATE_INFO *Info = NULL;
82 ACPI_OPERAND_OBJECT *MethodObj = NULL;
85 ACPI_FUNCTION_TRACE (NsExecuteTable);
88 Status = AcpiGetTableByIndex (TableIndex, &Table);
89 if (ACPI_FAILURE (Status))
91 return_ACPI_STATUS (Status);
94 /* Table must consist of at least a complete header */
96 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
98 return_ACPI_STATUS (AE_BAD_HEADER);
101 AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
102 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
104 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
105 if (ACPI_FAILURE (Status))
107 return_ACPI_STATUS (Status);
110 /* Create, initialize, and link a new temporary method object */
112 MethodObj = AcpiUtCreateInternalObject (ACPI_TYPE_METHOD);
115 return_ACPI_STATUS (AE_NO_MEMORY);
118 /* Allocate the evaluation information block */
120 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
123 Status = AE_NO_MEMORY;
127 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
128 "Create table code block: %p\n", MethodObj));
130 MethodObj->Method.AmlStart = AmlStart;
131 MethodObj->Method.AmlLength = AmlLength;
132 MethodObj->Method.OwnerId = OwnerId;
133 MethodObj->Method.InfoFlags |= ACPI_METHOD_MODULE_LEVEL;
135 Info->PassNumber = ACPI_IMODE_EXECUTE;
136 Info->Node = StartNode;
137 Info->ObjDesc = MethodObj;
138 Info->NodeFlags = Info->Node->Flags;
139 Info->FullPathname = AcpiNsGetNormalizedPathname (Info->Node, TRUE);
140 if (!Info->FullPathname)
142 Status = AE_NO_MEMORY;
146 Status = AcpiPsExecuteTable (Info);
151 ACPI_FREE (Info->FullPathname);
152 Info->FullPathname = NULL;
155 AcpiUtRemoveReference (MethodObj);
156 return_ACPI_STATUS (Status);
160 /*******************************************************************************
162 * FUNCTION: NsOneCompleteParse
164 * PARAMETERS: PassNumber - 1 or 2
165 * TableDesc - The table to be parsed.
169 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
171 ******************************************************************************/
174 AcpiNsOneCompleteParse (
177 ACPI_NAMESPACE_NODE *StartNode)
179 ACPI_PARSE_OBJECT *ParseRoot;
183 ACPI_WALK_STATE *WalkState;
184 ACPI_TABLE_HEADER *Table;
185 ACPI_OWNER_ID OwnerId;
188 ACPI_FUNCTION_TRACE (NsOneCompleteParse);
191 Status = AcpiGetTableByIndex (TableIndex, &Table);
192 if (ACPI_FAILURE (Status))
194 return_ACPI_STATUS (Status);
197 /* Table must consist of at least a complete header */
199 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
201 return_ACPI_STATUS (AE_BAD_HEADER);
204 AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
205 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
207 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
208 if (ACPI_FAILURE (Status))
210 return_ACPI_STATUS (Status);
213 /* Create and init a Root Node */
215 ParseRoot = AcpiPsCreateScopeOp (AmlStart);
218 return_ACPI_STATUS (AE_NO_MEMORY);
221 /* Create and initialize a new walk state */
223 WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
226 AcpiPsFreeOp (ParseRoot);
227 return_ACPI_STATUS (AE_NO_MEMORY);
230 Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
231 AmlStart, AmlLength, NULL, (UINT8) PassNumber);
232 if (ACPI_FAILURE (Status))
234 AcpiDsDeleteWalkState (WalkState);
238 /* Found OSDT table, enable the namespace override feature */
240 if (ACPI_COMPARE_NAME(Table->Signature, ACPI_SIG_OSDT) &&
241 PassNumber == ACPI_IMODE_LOAD_PASS1)
243 WalkState->NamespaceOverride = TRUE;
246 /* StartNode is the default location to load the table */
248 if (StartNode && StartNode != AcpiGbl_RootNode)
250 Status = AcpiDsScopeStackPush (
251 StartNode, ACPI_TYPE_METHOD, WalkState);
252 if (ACPI_FAILURE (Status))
254 AcpiDsDeleteWalkState (WalkState);
261 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
262 "*PARSE* pass %u parse\n", PassNumber));
263 AcpiExEnterInterpreter ();
264 Status = AcpiPsParseAml (WalkState);
265 AcpiExExitInterpreter ();
268 AcpiPsDeleteParseTree (ParseRoot);
269 return_ACPI_STATUS (Status);
273 /*******************************************************************************
275 * FUNCTION: AcpiNsParseTable
277 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
278 * StartNode - Where to enter the table into the namespace
282 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
284 ******************************************************************************/
289 ACPI_NAMESPACE_NODE *StartNode)
294 ACPI_FUNCTION_TRACE (NsParseTable);
297 if (AcpiGbl_ParseTableAsTermList)
299 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start load pass\n"));
301 Status = AcpiNsExecuteTable (TableIndex, StartNode);
302 if (ACPI_FAILURE (Status))
304 return_ACPI_STATUS (Status);
312 * In this pass, we load most of the namespace. Control methods
313 * are not parsed until later. A parse tree is not created.
314 * Instead, each Parser Op subtree is deleted when it is finished.
315 * This saves a great deal of memory, and allows a small cache of
316 * parse objects to service the entire parse. The second pass of
317 * the parse then performs another complete parse of the AML.
319 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
321 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
322 TableIndex, StartNode);
323 if (ACPI_FAILURE (Status))
325 return_ACPI_STATUS (Status);
331 * In this pass, we resolve forward references and other things
332 * that could not be completed during the first pass.
333 * Another complete parse of the AML is performed, but the
334 * overhead of this is compensated for by the fact that the
335 * parse objects are all cached.
337 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
338 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
339 TableIndex, StartNode);
340 if (ACPI_FAILURE (Status))
342 return_ACPI_STATUS (Status);
346 return_ACPI_STATUS (Status);