nsparse.c revision 1.1.1.2.2.2 1 1.1.1.2.2.2 bouyer /******************************************************************************
2 1.1.1.2.2.2 bouyer *
3 1.1.1.2.2.2 bouyer * Module Name: nsparse - namespace interface to AML parser
4 1.1.1.2.2.2 bouyer *
5 1.1.1.2.2.2 bouyer *****************************************************************************/
6 1.1.1.2.2.2 bouyer
7 1.1.1.2.2.2 bouyer /*
8 1.1.1.2.2.2 bouyer * Copyright (C) 2000 - 2011, Intel Corp.
9 1.1.1.2.2.2 bouyer * All rights reserved.
10 1.1.1.2.2.2 bouyer *
11 1.1.1.2.2.2 bouyer * Redistribution and use in source and binary forms, with or without
12 1.1.1.2.2.2 bouyer * modification, are permitted provided that the following conditions
13 1.1.1.2.2.2 bouyer * are met:
14 1.1.1.2.2.2 bouyer * 1. Redistributions of source code must retain the above copyright
15 1.1.1.2.2.2 bouyer * notice, this list of conditions, and the following disclaimer,
16 1.1.1.2.2.2 bouyer * without modification.
17 1.1.1.2.2.2 bouyer * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 1.1.1.2.2.2 bouyer * substantially similar to the "NO WARRANTY" disclaimer below
19 1.1.1.2.2.2 bouyer * ("Disclaimer") and any redistribution must be conditioned upon
20 1.1.1.2.2.2 bouyer * including a substantially similar Disclaimer requirement for further
21 1.1.1.2.2.2 bouyer * binary redistribution.
22 1.1.1.2.2.2 bouyer * 3. Neither the names of the above-listed copyright holders nor the names
23 1.1.1.2.2.2 bouyer * of any contributors may be used to endorse or promote products derived
24 1.1.1.2.2.2 bouyer * from this software without specific prior written permission.
25 1.1.1.2.2.2 bouyer *
26 1.1.1.2.2.2 bouyer * Alternatively, this software may be distributed under the terms of the
27 1.1.1.2.2.2 bouyer * GNU General Public License ("GPL") version 2 as published by the Free
28 1.1.1.2.2.2 bouyer * Software Foundation.
29 1.1.1.2.2.2 bouyer *
30 1.1.1.2.2.2 bouyer * NO WARRANTY
31 1.1.1.2.2.2 bouyer * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 1.1.1.2.2.2 bouyer * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 1.1.1.2.2.2 bouyer * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 1.1.1.2.2.2 bouyer * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 1.1.1.2.2.2 bouyer * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 1.1.1.2.2.2 bouyer * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 1.1.1.2.2.2 bouyer * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 1.1.1.2.2.2 bouyer * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 1.1.1.2.2.2 bouyer * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 1.1.1.2.2.2 bouyer * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 1.1.1.2.2.2 bouyer * POSSIBILITY OF SUCH DAMAGES.
42 1.1.1.2.2.2 bouyer */
43 1.1.1.2.2.2 bouyer
44 1.1.1.2.2.2 bouyer #define __NSPARSE_C__
45 1.1.1.2.2.2 bouyer
46 1.1.1.2.2.2 bouyer #include "acpi.h"
47 1.1.1.2.2.2 bouyer #include "accommon.h"
48 1.1.1.2.2.2 bouyer #include "acnamesp.h"
49 1.1.1.2.2.2 bouyer #include "acparser.h"
50 1.1.1.2.2.2 bouyer #include "acdispat.h"
51 1.1.1.2.2.2 bouyer #include "actables.h"
52 1.1.1.2.2.2 bouyer
53 1.1.1.2.2.2 bouyer
54 1.1.1.2.2.2 bouyer #define _COMPONENT ACPI_NAMESPACE
55 1.1.1.2.2.2 bouyer ACPI_MODULE_NAME ("nsparse")
56 1.1.1.2.2.2 bouyer
57 1.1.1.2.2.2 bouyer
58 1.1.1.2.2.2 bouyer /*******************************************************************************
59 1.1.1.2.2.2 bouyer *
60 1.1.1.2.2.2 bouyer * FUNCTION: NsOneCompleteParse
61 1.1.1.2.2.2 bouyer *
62 1.1.1.2.2.2 bouyer * PARAMETERS: PassNumber - 1 or 2
63 1.1.1.2.2.2 bouyer * TableDesc - The table to be parsed.
64 1.1.1.2.2.2 bouyer *
65 1.1.1.2.2.2 bouyer * RETURN: Status
66 1.1.1.2.2.2 bouyer *
67 1.1.1.2.2.2 bouyer * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
68 1.1.1.2.2.2 bouyer *
69 1.1.1.2.2.2 bouyer ******************************************************************************/
70 1.1.1.2.2.2 bouyer
71 1.1.1.2.2.2 bouyer ACPI_STATUS
72 1.1.1.2.2.2 bouyer AcpiNsOneCompleteParse (
73 1.1.1.2.2.2 bouyer UINT32 PassNumber,
74 1.1.1.2.2.2 bouyer UINT32 TableIndex,
75 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *StartNode)
76 1.1.1.2.2.2 bouyer {
77 1.1.1.2.2.2 bouyer ACPI_PARSE_OBJECT *ParseRoot;
78 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
79 1.1.1.2.2.2 bouyer UINT32 AmlLength;
80 1.1.1.2.2.2 bouyer UINT8 *AmlStart;
81 1.1.1.2.2.2 bouyer ACPI_WALK_STATE *WalkState;
82 1.1.1.2.2.2 bouyer ACPI_TABLE_HEADER *Table;
83 1.1.1.2.2.2 bouyer ACPI_OWNER_ID OwnerId;
84 1.1.1.2.2.2 bouyer
85 1.1.1.2.2.2 bouyer
86 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (NsOneCompleteParse);
87 1.1.1.2.2.2 bouyer
88 1.1.1.2.2.2 bouyer
89 1.1.1.2.2.2 bouyer Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
90 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
91 1.1.1.2.2.2 bouyer {
92 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
93 1.1.1.2.2.2 bouyer }
94 1.1.1.2.2.2 bouyer
95 1.1.1.2.2.2 bouyer /* Create and init a Root Node */
96 1.1.1.2.2.2 bouyer
97 1.1.1.2.2.2 bouyer ParseRoot = AcpiPsCreateScopeOp ();
98 1.1.1.2.2.2 bouyer if (!ParseRoot)
99 1.1.1.2.2.2 bouyer {
100 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
101 1.1.1.2.2.2 bouyer }
102 1.1.1.2.2.2 bouyer
103 1.1.1.2.2.2 bouyer /* Create and initialize a new walk state */
104 1.1.1.2.2.2 bouyer
105 1.1.1.2.2.2 bouyer WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
106 1.1.1.2.2.2 bouyer if (!WalkState)
107 1.1.1.2.2.2 bouyer {
108 1.1.1.2.2.2 bouyer AcpiPsFreeOp (ParseRoot);
109 1.1.1.2.2.2 bouyer return_ACPI_STATUS (AE_NO_MEMORY);
110 1.1.1.2.2.2 bouyer }
111 1.1.1.2.2.2 bouyer
112 1.1.1.2.2.2 bouyer Status = AcpiGetTableByIndex (TableIndex, &Table);
113 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
114 1.1.1.2.2.2 bouyer {
115 1.1.1.2.2.2 bouyer AcpiDsDeleteWalkState (WalkState);
116 1.1.1.2.2.2 bouyer AcpiPsFreeOp (ParseRoot);
117 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
118 1.1.1.2.2.2 bouyer }
119 1.1.1.2.2.2 bouyer
120 1.1.1.2.2.2 bouyer /* Table must consist of at least a complete header */
121 1.1.1.2.2.2 bouyer
122 1.1.1.2.2.2 bouyer if (Table->Length < sizeof (ACPI_TABLE_HEADER))
123 1.1.1.2.2.2 bouyer {
124 1.1.1.2.2.2 bouyer Status = AE_BAD_HEADER;
125 1.1.1.2.2.2 bouyer }
126 1.1.1.2.2.2 bouyer else
127 1.1.1.2.2.2 bouyer {
128 1.1.1.2.2.2 bouyer AmlStart = (UINT8 *) Table + sizeof (ACPI_TABLE_HEADER);
129 1.1.1.2.2.2 bouyer AmlLength = Table->Length - sizeof (ACPI_TABLE_HEADER);
130 1.1.1.2.2.2 bouyer Status = AcpiDsInitAmlWalk (WalkState, ParseRoot, NULL,
131 1.1.1.2.2.2 bouyer AmlStart, AmlLength, NULL, (UINT8) PassNumber);
132 1.1.1.2.2.2 bouyer }
133 1.1.1.2.2.2 bouyer
134 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
135 1.1.1.2.2.2 bouyer {
136 1.1.1.2.2.2 bouyer AcpiDsDeleteWalkState (WalkState);
137 1.1.1.2.2.2 bouyer goto Cleanup;
138 1.1.1.2.2.2 bouyer }
139 1.1.1.2.2.2 bouyer
140 1.1.1.2.2.2 bouyer /* StartNode is the default location to load the table */
141 1.1.1.2.2.2 bouyer
142 1.1.1.2.2.2 bouyer if (StartNode && StartNode != AcpiGbl_RootNode)
143 1.1.1.2.2.2 bouyer {
144 1.1.1.2.2.2 bouyer Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
145 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
146 1.1.1.2.2.2 bouyer {
147 1.1.1.2.2.2 bouyer AcpiDsDeleteWalkState (WalkState);
148 1.1.1.2.2.2 bouyer goto Cleanup;
149 1.1.1.2.2.2 bouyer }
150 1.1.1.2.2.2 bouyer }
151 1.1.1.2.2.2 bouyer
152 1.1.1.2.2.2 bouyer /* Parse the AML */
153 1.1.1.2.2.2 bouyer
154 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber));
155 1.1.1.2.2.2 bouyer Status = AcpiPsParseAml (WalkState);
156 1.1.1.2.2.2 bouyer
157 1.1.1.2.2.2 bouyer Cleanup:
158 1.1.1.2.2.2 bouyer AcpiPsDeleteParseTree (ParseRoot);
159 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
160 1.1.1.2.2.2 bouyer }
161 1.1.1.2.2.2 bouyer
162 1.1.1.2.2.2 bouyer
163 1.1.1.2.2.2 bouyer /*******************************************************************************
164 1.1.1.2.2.2 bouyer *
165 1.1.1.2.2.2 bouyer * FUNCTION: AcpiNsParseTable
166 1.1.1.2.2.2 bouyer *
167 1.1.1.2.2.2 bouyer * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
168 1.1.1.2.2.2 bouyer * StartNode - Where to enter the table into the namespace
169 1.1.1.2.2.2 bouyer *
170 1.1.1.2.2.2 bouyer * RETURN: Status
171 1.1.1.2.2.2 bouyer *
172 1.1.1.2.2.2 bouyer * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
173 1.1.1.2.2.2 bouyer *
174 1.1.1.2.2.2 bouyer ******************************************************************************/
175 1.1.1.2.2.2 bouyer
176 1.1.1.2.2.2 bouyer ACPI_STATUS
177 1.1.1.2.2.2 bouyer AcpiNsParseTable (
178 1.1.1.2.2.2 bouyer UINT32 TableIndex,
179 1.1.1.2.2.2 bouyer ACPI_NAMESPACE_NODE *StartNode)
180 1.1.1.2.2.2 bouyer {
181 1.1.1.2.2.2 bouyer ACPI_STATUS Status;
182 1.1.1.2.2.2 bouyer
183 1.1.1.2.2.2 bouyer
184 1.1.1.2.2.2 bouyer ACPI_FUNCTION_TRACE (NsParseTable);
185 1.1.1.2.2.2 bouyer
186 1.1.1.2.2.2 bouyer
187 1.1.1.2.2.2 bouyer /*
188 1.1.1.2.2.2 bouyer * AML Parse, pass 1
189 1.1.1.2.2.2 bouyer *
190 1.1.1.2.2.2 bouyer * In this pass, we load most of the namespace. Control methods
191 1.1.1.2.2.2 bouyer * are not parsed until later. A parse tree is not created. Instead,
192 1.1.1.2.2.2 bouyer * each Parser Op subtree is deleted when it is finished. This saves
193 1.1.1.2.2.2 bouyer * a great deal of memory, and allows a small cache of parse objects
194 1.1.1.2.2.2 bouyer * to service the entire parse. The second pass of the parse then
195 1.1.1.2.2.2 bouyer * performs another complete parse of the AML.
196 1.1.1.2.2.2 bouyer */
197 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 1\n"));
198 1.1.1.2.2.2 bouyer Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS1,
199 1.1.1.2.2.2 bouyer TableIndex, StartNode);
200 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
201 1.1.1.2.2.2 bouyer {
202 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
203 1.1.1.2.2.2 bouyer }
204 1.1.1.2.2.2 bouyer
205 1.1.1.2.2.2 bouyer /*
206 1.1.1.2.2.2 bouyer * AML Parse, pass 2
207 1.1.1.2.2.2 bouyer *
208 1.1.1.2.2.2 bouyer * In this pass, we resolve forward references and other things
209 1.1.1.2.2.2 bouyer * that could not be completed during the first pass.
210 1.1.1.2.2.2 bouyer * Another complete parse of the AML is performed, but the
211 1.1.1.2.2.2 bouyer * overhead of this is compensated for by the fact that the
212 1.1.1.2.2.2 bouyer * parse objects are all cached.
213 1.1.1.2.2.2 bouyer */
214 1.1.1.2.2.2 bouyer ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "**** Start pass 2\n"));
215 1.1.1.2.2.2 bouyer Status = AcpiNsOneCompleteParse (ACPI_IMODE_LOAD_PASS2,
216 1.1.1.2.2.2 bouyer TableIndex, StartNode);
217 1.1.1.2.2.2 bouyer if (ACPI_FAILURE (Status))
218 1.1.1.2.2.2 bouyer {
219 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
220 1.1.1.2.2.2 bouyer }
221 1.1.1.2.2.2 bouyer
222 1.1.1.2.2.2 bouyer return_ACPI_STATUS (Status);
223 1.1.1.2.2.2 bouyer }
224 1.1.1.2.2.2 bouyer
225 1.1.1.2.2.2 bouyer
226