1 /******************************************************************************
3 * Module Name: psscope - Parser scope stack management routines
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, 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.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acparser.h>
48 #define _COMPONENT ACPI_PARSER
49 ACPI_MODULE_NAME ("psscope")
52 /*******************************************************************************
54 * FUNCTION: AcpiPsGetParentScope
56 * PARAMETERS: ParserState - Current parser state object
58 * RETURN: Pointer to an Op object
60 * DESCRIPTION: Get parent of current op being parsed
62 ******************************************************************************/
65 AcpiPsGetParentScope (
66 ACPI_PARSE_STATE *ParserState)
69 return (ParserState->Scope->ParseScope.Op);
73 /*******************************************************************************
75 * FUNCTION: AcpiPsHasCompletedScope
77 * PARAMETERS: ParserState - Current parser state object
79 * RETURN: Boolean, TRUE = scope completed.
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.
85 ******************************************************************************/
88 AcpiPsHasCompletedScope (
89 ACPI_PARSE_STATE *ParserState)
93 ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
94 !ParserState->Scope->ParseScope.ArgCount)));
98 /*******************************************************************************
100 * FUNCTION: AcpiPsInitScope
102 * PARAMETERS: ParserState - Current parser state object
103 * Root - the Root Node of this new scope
107 * DESCRIPTION: Allocate and init a new scope object
109 ******************************************************************************/
113 ACPI_PARSE_STATE *ParserState,
114 ACPI_PARSE_OBJECT *RootOp)
116 ACPI_GENERIC_STATE *Scope;
119 ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
122 Scope = AcpiUtCreateGenericState ();
125 return_ACPI_STATUS (AE_NO_MEMORY);
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;
134 ParserState->Scope = Scope;
135 ParserState->StartOp = RootOp;
137 return_ACPI_STATUS (AE_OK);
141 /*******************************************************************************
143 * FUNCTION: AcpiPsPushScope
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
152 * DESCRIPTION: Push current op to begin parsing its argument
154 ******************************************************************************/
158 ACPI_PARSE_STATE *ParserState,
159 ACPI_PARSE_OBJECT *Op,
160 UINT32 RemainingArgs,
163 ACPI_GENERIC_STATE *Scope;
166 ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
169 Scope = AcpiUtCreateGenericState ();
172 return_ACPI_STATUS (AE_NO_MEMORY);
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;
181 /* Push onto scope stack */
183 AcpiUtPushGenericState (&ParserState->Scope, Scope);
185 if (ArgCount == ACPI_VAR_ARGS)
187 /* Multiple arguments */
189 Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
193 /* Single argument */
195 Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
198 return_ACPI_STATUS (AE_OK);
202 /*******************************************************************************
204 * FUNCTION: AcpiPsPopScope
206 * PARAMETERS: ParserState - Current parser state object
207 * Op - Where the popped op is returned
208 * ArgList - Where the popped "next argument" is
210 * ArgCount - Count of objects in ArgList
214 * DESCRIPTION: Return to parsing a previous op
216 ******************************************************************************/
220 ACPI_PARSE_STATE *ParserState,
221 ACPI_PARSE_OBJECT **Op,
225 ACPI_GENERIC_STATE *Scope = ParserState->Scope;
228 ACPI_FUNCTION_TRACE (PsPopScope);
231 /* Only pop the scope if there is in fact a next scope */
233 if (Scope->Common.Next)
235 Scope = AcpiUtPopGenericState (&ParserState->Scope);
237 /* Return to parsing previous op */
239 *Op = Scope->ParseScope.Op;
240 *ArgList = Scope->ParseScope.ArgList;
241 *ArgCount = Scope->ParseScope.ArgCount;
242 ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
244 /* All done with this scope state structure */
246 AcpiUtDeleteGenericState (Scope);
250 /* Empty parse stack, prepare to fetch next opcode */
257 ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
258 "Popped Op %p Args %X\n", *Op, *ArgCount));
263 /*******************************************************************************
265 * FUNCTION: AcpiPsCleanupScope
267 * PARAMETERS: ParserState - Current parser state object
271 * DESCRIPTION: Destroy available list, remaining stack levels, and return
274 ******************************************************************************/
278 ACPI_PARSE_STATE *ParserState)
280 ACPI_GENERIC_STATE *Scope;
283 ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
291 /* Delete anything on the scope stack */
293 while (ParserState->Scope)
295 Scope = AcpiUtPopGenericState (&ParserState->Scope);
296 AcpiUtDeleteGenericState (Scope);