1 /******************************************************************************
3 * Module Name: nsparse - namespace interface to AML parser
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2013, 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.
54 #define _COMPONENT ACPI_NAMESPACE
55 ACPI_MODULE_NAME ("nsparse")
58 /*******************************************************************************
60 * FUNCTION: NsOneCompleteParse
62 * PARAMETERS: PassNumber - 1 or 2
63 * TableDesc - The table to be parsed.
67 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
69 ******************************************************************************/
72 AcpiNsOneCompleteParse (
75 ACPI_NAMESPACE_NODE
*StartNode
)
77 ACPI_PARSE_OBJECT
*ParseRoot
;
81 ACPI_WALK_STATE
*WalkState
;
82 ACPI_TABLE_HEADER
*Table
;
83 ACPI_OWNER_ID OwnerId
;
86 ACPI_FUNCTION_TRACE (NsOneCompleteParse
);
89 Status
= AcpiTbGetOwnerId (TableIndex
, &OwnerId
);
90 if (ACPI_FAILURE (Status
))
92 return_ACPI_STATUS (Status
);
95 /* Create and init a Root Node */
97 ParseRoot
= AcpiPsCreateScopeOp ();
100 return_ACPI_STATUS (AE_NO_MEMORY
);
103 /* Create and initialize a new walk state */
105 WalkState
= AcpiDsCreateWalkState (OwnerId
, NULL
, NULL
, NULL
);
108 AcpiPsFreeOp (ParseRoot
);
109 return_ACPI_STATUS (AE_NO_MEMORY
);
112 Status
= AcpiGetTableByIndex (TableIndex
, &Table
);
113 if (ACPI_FAILURE (Status
))
115 AcpiDsDeleteWalkState (WalkState
);
116 AcpiPsFreeOp (ParseRoot
);
117 return_ACPI_STATUS (Status
);
120 /* Table must consist of at least a complete header */
122 if (Table
->Length
< sizeof (ACPI_TABLE_HEADER
))
124 Status
= AE_BAD_HEADER
;
128 AmlStart
= (UINT8
*) Table
+ sizeof (ACPI_TABLE_HEADER
);
129 AmlLength
= Table
->Length
- sizeof (ACPI_TABLE_HEADER
);
130 Status
= AcpiDsInitAmlWalk (WalkState
, ParseRoot
, NULL
,
131 AmlStart
, AmlLength
, NULL
, (UINT8
) PassNumber
);
134 if (ACPI_FAILURE (Status
))
136 AcpiDsDeleteWalkState (WalkState
);
140 /* StartNode is the default location to load the table */
142 if (StartNode
&& StartNode
!= AcpiGbl_RootNode
)
144 Status
= AcpiDsScopeStackPush (StartNode
, ACPI_TYPE_METHOD
, WalkState
);
145 if (ACPI_FAILURE (Status
))
147 AcpiDsDeleteWalkState (WalkState
);
154 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "*PARSE* pass %u parse\n", PassNumber
));
155 Status
= AcpiPsParseAml (WalkState
);
158 AcpiPsDeleteParseTree (ParseRoot
);
159 return_ACPI_STATUS (Status
);
163 /*******************************************************************************
165 * FUNCTION: AcpiNsParseTable
167 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
168 * StartNode - Where to enter the table into the namespace
172 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
174 ******************************************************************************/
179 ACPI_NAMESPACE_NODE
*StartNode
)
184 ACPI_FUNCTION_TRACE (NsParseTable
);
190 * In this pass, we load most of the namespace. Control methods
191 * are not parsed until later. A parse tree is not created. Instead,
192 * each Parser Op subtree is deleted when it is finished. This saves
193 * a great deal of memory, and allows a small cache of parse objects
194 * to service the entire parse. The second pass of the parse then
195 * performs another complete parse of the AML.
197 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "**** Start pass 1\n"));
198 Status
= AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1
,
199 TableIndex
, StartNode
);
200 if (ACPI_FAILURE (Status
))
202 return_ACPI_STATUS (Status
);
208 * In this pass, we resolve forward references and other things
209 * that could not be completed during the first pass.
210 * Another complete parse of the AML is performed, but the
211 * overhead of this is compensated for by the fact that the
212 * parse objects are all cached.
214 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE
, "**** Start pass 2\n"));
215 Status
= AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2
,
216 TableIndex
, StartNode
);
217 if (ACPI_FAILURE (Status
))
219 return_ACPI_STATUS (Status
);
222 return_ACPI_STATUS (Status
);