1 /******************************************************************************
3 * Module Name: nsparse - namespace interface to AML parser
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsparse")
56 /*******************************************************************************
58 * FUNCTION: NsOneCompleteParse
60 * PARAMETERS: PassNumber - 1 or 2
61 * TableDesc - The table to be parsed.
65 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
67 ******************************************************************************/
70 AcpiNsOneCompleteParse (
73 ACPI_NAMESPACE_NODE *StartNode)
75 ACPI_PARSE_OBJECT *ParseRoot;
79 ACPI_WALK_STATE *WalkState;
80 ACPI_TABLE_HEADER *Table;
81 ACPI_OWNER_ID OwnerId;
84 ACPI_FUNCTION_TRACE (NsOneCompleteParse);
87 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
88 if (ACPI_FAILURE (Status))
90 return_ACPI_STATUS (Status);
93 /* Create and init a Root Node */
95 ParseRoot = AcpiPsCreateScopeOp ();
98 return_ACPI_STATUS (AE_NO_MEMORY);
101 /* Create and initialize a new walk state */
103 WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
106 AcpiPsFreeOp (ParseRoot);
107 return_ACPI_STATUS (AE_NO_MEMORY);
110 Status = AcpiGetTableByIndex (TableIndex, &Table);
111 if (ACPI_FAILURE (Status))
113 AcpiDsDeleteWalkState (WalkState);
114 AcpiPsFreeOp (ParseRoot);
115 return_ACPI_STATUS (Status);
118 /* Table must consist of at least a complete header */
120 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
122 Status = AE_BAD_HEADER;
126 AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
127 AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
128 Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
129 AmlStart, AmlLength, NULL, (UINT8) PassNumber);
132 if (ACPI_FAILURE (Status))
134 AcpiDsDeleteWalkState (WalkState);
138 /* StartNode is the default location to load the table */
140 if (StartNode && StartNode != AcpiGbl_RootNode)
142 Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
143 if (ACPI_FAILURE (Status))
145 AcpiDsDeleteWalkState (WalkState);
152 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber));
153 Status = AcpiPsParseAml (WalkState);
156 AcpiPsDeleteParseTree (ParseRoot);
157 return_ACPI_STATUS (Status);
161 /*******************************************************************************
163 * FUNCTION: AcpiNsParseTable
165 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
166 * StartNode - Where to enter the table into the namespace
170 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
172 ******************************************************************************/
177 ACPI_NAMESPACE_NODE *StartNode)
182 ACPI_FUNCTION_TRACE (NsParseTable);
188 * In this pass, we load most of the namespace. Control methods
189 * are not parsed until later. A parse tree is not created. Instead,
190 * each Parser Op subtree is deleted when it is finished. This saves
191 * a great deal of memory, and allows a small cache of parse objects
192 * to service the entire parse. The second pass of the parse then
193 * performs another complete parse of the AML.
195 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
196 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
197 TableIndex, StartNode);
198 if (ACPI_FAILURE (Status))
200 return_ACPI_STATUS (Status);
206 * In this pass, we resolve forward references and other things
207 * that could not be completed during the first pass.
208 * Another complete parse of the AML is performed, but the
209 * overhead of this is compensated for by the fact that the
210 * parse objects are all cached.
212 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
213 Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
214 TableIndex, StartNode);
215 if (ACPI_FAILURE (Status))
217 return_ACPI_STATUS (Status);
220 return_ACPI_STATUS (Status);