1 /******************************************************************************
2 *
3 * Module Name: nsparse - namespace interface to AML parser
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2014, Intel Corp.
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acnamesp.h"
47 #include "acparser.h"
48 #include "acdispat.h"
49 #include "actables.h"
50
51
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nsparse")
54
55
56 /*******************************************************************************
57 *
58 * FUNCTION: NsOneCompleteParse
59 *
60 * PARAMETERS: PassNumber - 1 or 2
61 * TableDesc - The table to be parsed.
62 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Perform one complete parse of an ACPI/AML table.
66 *
67 ******************************************************************************/
68
69 ACPI_STATUS
AcpiNsOneCompleteParse(UINT32 PassNumber,UINT32 TableIndex,ACPI_NAMESPACE_NODE * StartNode)70 AcpiNsOneCompleteParse (
71 UINT32 PassNumber,
72 UINT32 TableIndex,
73 ACPI_NAMESPACE_NODE *StartNode)
74 {
75 ACPI_PARSE_OBJECT *ParseRoot;
76 ACPI_STATUS Status;
77 UINT32 AmlLength;
78 UINT8 *AmlStart;
79 ACPI_WALK_STATE *WalkState;
80 ACPI_TABLE_HEADER *Table;
81 ACPI_OWNER_ID OwnerId;
82
83
84 ACPI_FUNCTION_TRACE (NsOneCompleteParse);
85
86
87 Status = AcpiTbGetOwnerId (TableIndex, &OwnerId);
88 if (ACPI_FAILURE (Status))
89 {
90 return_ACPI_STATUS (Status);
91 }
92
93 /* Create and init a Root Node */
94
95 ParseRoot = AcpiPsCreateScopeOp ();
96 if (!ParseRoot)
97 {
98 return_ACPI_STATUS (AE_NO_MEMORY);
99 }
100
101 /* Create and initialize a new walk state */
102
103 WalkState = AcpiDsCreateWalkState (OwnerId, NULL, NULL, NULL);
104 if (!WalkState)
105 {
106 AcpiPsFreeOp (ParseRoot);
107 return_ACPI_STATUS (AE_NO_MEMORY);
108 }
109
110 Status = AcpiGetTableByIndex (TableIndex, &Table);
111 if (ACPI_FAILURE (Status))
112 {
113 AcpiDsDeleteWalkState (WalkState);
114 AcpiPsFreeOp (ParseRoot);
115 return_ACPI_STATUS (Status);
116 }
117
118 /* Table must consist of at least a complete header */
119
120 if (Table->Length < sizeof (ACPI_TABLE_HEADER))
121 {
122 Status = AE_BAD_HEADER;
123 }
124 else
125 {
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);
130 }
131
132 if (ACPI_FAILURE (Status))
133 {
134 AcpiDsDeleteWalkState (WalkState);
135 goto Cleanup;
136 }
137
138 /* StartNode is the default location to load the table */
139
140 if (StartNode && StartNode != AcpiGbl_RootNode)
141 {
142 Status = AcpiDsScopeStackPush (StartNode, ACPI_TYPE_METHOD, WalkState);
143 if (ACPI_FAILURE (Status))
144 {
145 AcpiDsDeleteWalkState (WalkState);
146 goto Cleanup;
147 }
148 }
149
150 /* Parse the AML */
151
152 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "*PARSE* pass %u parse\n", PassNumber));
153 Status = AcpiPsParseAml (WalkState);
154
155 Cleanup:
156 AcpiPsDeleteParseTree (ParseRoot);
157 return_ACPI_STATUS (Status);
158 }
159
160
161 /*******************************************************************************
162 *
163 * FUNCTION: AcpiNsParseTable
164 *
165 * PARAMETERS: TableDesc - An ACPI table descriptor for table to parse
166 * StartNode - Where to enter the table into the namespace
167 *
168 * RETURN: Status
169 *
170 * DESCRIPTION: Parse AML within an ACPI table and return a tree of ops
171 *
172 ******************************************************************************/
173
174 ACPI_STATUS
AcpiNsParseTable(UINT32 TableIndex,ACPI_NAMESPACE_NODE * StartNode)175 AcpiNsParseTable (
176 UINT32 TableIndex,
177 ACPI_NAMESPACE_NODE *StartNode)
178 {
179 ACPI_STATUS Status;
180
181
182 ACPI_FUNCTION_TRACE (NsParseTable);
183
184
185 /*
186 * AML Parse, pass 1
187 *
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.
194 */
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))
199 {
200 return_ACPI_STATUS (Status);
201 }
202
203 /*
204 * AML Parse, pass 2
205 *
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.
211 */
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))
216 {
217 return_ACPI_STATUS (Status);
218 }
219
220 return_ACPI_STATUS (Status);
221 }
222