[ACPICA] Update to version 20190108. CORE-15593
[reactos.git] / drivers / bus / acpi / acpica / parser / psscope.c
1 /******************************************************************************
2 *
3 * Module Name: psscope - Parser scope stack management routines
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2019, 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 "acparser.h"
47
48 #define _COMPONENT ACPI_PARSER
49 ACPI_MODULE_NAME ("psscope")
50
51
52 /*******************************************************************************
53 *
54 * FUNCTION: AcpiPsGetParentScope
55 *
56 * PARAMETERS: ParserState - Current parser state object
57 *
58 * RETURN: Pointer to an Op object
59 *
60 * DESCRIPTION: Get parent of current op being parsed
61 *
62 ******************************************************************************/
63
64 ACPI_PARSE_OBJECT *
65 AcpiPsGetParentScope (
66 ACPI_PARSE_STATE *ParserState)
67 {
68
69 return (ParserState->Scope->ParseScope.Op);
70 }
71
72
73 /*******************************************************************************
74 *
75 * FUNCTION: AcpiPsHasCompletedScope
76 *
77 * PARAMETERS: ParserState - Current parser state object
78 *
79 * RETURN: Boolean, TRUE = scope completed.
80 *
81 * DESCRIPTION: Is parsing of current argument complete? Determined by
82 * 1) AML pointer is at or beyond the end of the scope
83 * 2) The scope argument count has reached zero.
84 *
85 ******************************************************************************/
86
87 BOOLEAN
88 AcpiPsHasCompletedScope (
89 ACPI_PARSE_STATE *ParserState)
90 {
91
92 return ((BOOLEAN)
93 ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
94 !ParserState->Scope->ParseScope.ArgCount)));
95 }
96
97
98 /*******************************************************************************
99 *
100 * FUNCTION: AcpiPsInitScope
101 *
102 * PARAMETERS: ParserState - Current parser state object
103 * Root - the Root Node of this new scope
104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: Allocate and init a new scope object
108 *
109 ******************************************************************************/
110
111 ACPI_STATUS
112 AcpiPsInitScope (
113 ACPI_PARSE_STATE *ParserState,
114 ACPI_PARSE_OBJECT *RootOp)
115 {
116 ACPI_GENERIC_STATE *Scope;
117
118
119 ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
120
121
122 Scope = AcpiUtCreateGenericState ();
123 if (!Scope)
124 {
125 return_ACPI_STATUS (AE_NO_MEMORY);
126 }
127
128 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
129 Scope->ParseScope.Op = RootOp;
130 Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
131 Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
132 Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
133
134 ParserState->Scope = Scope;
135 ParserState->StartOp = RootOp;
136
137 return_ACPI_STATUS (AE_OK);
138 }
139
140
141 /*******************************************************************************
142 *
143 * FUNCTION: AcpiPsPushScope
144 *
145 * PARAMETERS: ParserState - Current parser state object
146 * Op - Current op to be pushed
147 * RemainingArgs - List of args remaining
148 * ArgCount - Fixed or variable number of args
149 *
150 * RETURN: Status
151 *
152 * DESCRIPTION: Push current op to begin parsing its argument
153 *
154 ******************************************************************************/
155
156 ACPI_STATUS
157 AcpiPsPushScope (
158 ACPI_PARSE_STATE *ParserState,
159 ACPI_PARSE_OBJECT *Op,
160 UINT32 RemainingArgs,
161 UINT32 ArgCount)
162 {
163 ACPI_GENERIC_STATE *Scope;
164
165
166 ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
167
168
169 Scope = AcpiUtCreateGenericState ();
170 if (!Scope)
171 {
172 return_ACPI_STATUS (AE_NO_MEMORY);
173 }
174
175 Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
176 Scope->ParseScope.Op = Op;
177 Scope->ParseScope.ArgList = RemainingArgs;
178 Scope->ParseScope.ArgCount = ArgCount;
179 Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
180
181 /* Push onto scope stack */
182
183 AcpiUtPushGenericState (&ParserState->Scope, Scope);
184
185 if (ArgCount == ACPI_VAR_ARGS)
186 {
187 /* Multiple arguments */
188
189 Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
190 }
191 else
192 {
193 /* Single argument */
194
195 Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
196 }
197
198 return_ACPI_STATUS (AE_OK);
199 }
200
201
202 /*******************************************************************************
203 *
204 * FUNCTION: AcpiPsPopScope
205 *
206 * PARAMETERS: ParserState - Current parser state object
207 * Op - Where the popped op is returned
208 * ArgList - Where the popped "next argument" is
209 * returned
210 * ArgCount - Count of objects in ArgList
211 *
212 * RETURN: Status
213 *
214 * DESCRIPTION: Return to parsing a previous op
215 *
216 ******************************************************************************/
217
218 void
219 AcpiPsPopScope (
220 ACPI_PARSE_STATE *ParserState,
221 ACPI_PARSE_OBJECT **Op,
222 UINT32 *ArgList,
223 UINT32 *ArgCount)
224 {
225 ACPI_GENERIC_STATE *Scope = ParserState->Scope;
226
227
228 ACPI_FUNCTION_TRACE (PsPopScope);
229
230
231 /* Only pop the scope if there is in fact a next scope */
232
233 if (Scope->Common.Next)
234 {
235 Scope = AcpiUtPopGenericState (&ParserState->Scope);
236
237 /* Return to parsing previous op */
238
239 *Op = Scope->ParseScope.Op;
240 *ArgList = Scope->ParseScope.ArgList;
241 *ArgCount = Scope->ParseScope.ArgCount;
242 ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
243
244 /* All done with this scope state structure */
245
246 AcpiUtDeleteGenericState (Scope);
247 }
248 else
249 {
250 /* Empty parse stack, prepare to fetch next opcode */
251
252 *Op = NULL;
253 *ArgList = 0;
254 *ArgCount = 0;
255 }
256
257 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
258 "Popped Op %p Args %X\n", *Op, *ArgCount));
259 return_VOID;
260 }
261
262
263 /*******************************************************************************
264 *
265 * FUNCTION: AcpiPsCleanupScope
266 *
267 * PARAMETERS: ParserState - Current parser state object
268 *
269 * RETURN: None
270 *
271 * DESCRIPTION: Destroy available list, remaining stack levels, and return
272 * root scope
273 *
274 ******************************************************************************/
275
276 void
277 AcpiPsCleanupScope (
278 ACPI_PARSE_STATE *ParserState)
279 {
280 ACPI_GENERIC_STATE *Scope;
281
282
283 ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
284
285
286 if (!ParserState)
287 {
288 return_VOID;
289 }
290
291 /* Delete anything on the scope stack */
292
293 while (ParserState->Scope)
294 {
295 Scope = AcpiUtPopGenericState (&ParserState->Scope);
296 AcpiUtDeleteGenericState (Scope);
297 }
298
299 return_VOID;
300 }