dswscope.c revision 69746
1272343Sngie/******************************************************************************
2272343Sngie *
3272343Sngie * Module Name: dswscope - Scope stack manipulation
4272343Sngie *              $Revision: 40 $
5272343Sngie *
6272343Sngie *****************************************************************************/
7272343Sngie
8272343Sngie/******************************************************************************
9272343Sngie *
10272343Sngie * 1. Copyright Notice
11272343Sngie *
12272343Sngie * Some or all of this work - Copyright (c) 1999, Intel Corp.  All rights
13272343Sngie * reserved.
14272343Sngie *
15272343Sngie * 2. License
16272343Sngie *
17272343Sngie * 2.1. This is your license from Intel Corp. under its intellectual property
18272343Sngie * rights.  You may have additional license terms from the party that provided
19272343Sngie * you this software, covering your right to use that party's intellectual
20272343Sngie * property rights.
21272343Sngie *
22272343Sngie * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23272343Sngie * copy of the source code appearing in this file ("Covered Code") an
24272343Sngie * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25272343Sngie * base code distributed originally by Intel ("Original Intel Code") to copy,
26272343Sngie * make derivatives, distribute, use and display any portion of the Covered
27272343Sngie * Code in any form, with the right to sublicense such rights; and
28272343Sngie *
29272343Sngie * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30272343Sngie * license (with the right to sublicense), under only those claims of Intel
31272343Sngie * patents that are infringed by the Original Intel Code, to make, use, sell,
32272343Sngie * offer to sell, and import the Covered Code and derivative works thereof
33272343Sngie * solely to the minimum extent necessary to exercise the above copyright
34272343Sngie * license, and in no event shall the patent license extend to any additions
35272343Sngie * to or modifications of the Original Intel Code.  No other license or right
36272343Sngie * is granted directly or by implication, estoppel or otherwise;
37272343Sngie *
38272343Sngie * The above copyright and patent license is granted only if the following
39272343Sngie * conditions are met:
40272343Sngie *
41272343Sngie * 3. Conditions
42272343Sngie *
43272343Sngie * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44272343Sngie * Redistribution of source code of any substantial portion of the Covered
45272343Sngie * Code or modification with rights to further distribute source must include
46272343Sngie * the above Copyright Notice, the above License, this list of Conditions,
47272343Sngie * and the following Disclaimer and Export Compliance provision.  In addition,
48272343Sngie * Licensee must cause all Covered Code to which Licensee contributes to
49272343Sngie * contain a file documenting the changes Licensee made to create that Covered
50272343Sngie * Code and the date of any change.  Licensee must include in that file the
51272343Sngie * documentation of any changes made by any predecessor Licensee.  Licensee
52272343Sngie * must include a prominent statement that the modification is derived,
53272343Sngie * directly or indirectly, from Original Intel Code.
54272343Sngie *
55272343Sngie * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56272343Sngie * Redistribution of source code of any substantial portion of the Covered
57272343Sngie * Code or modification without rights to further distribute source must
58272343Sngie * include the following Disclaimer and Export Compliance provision in the
59272343Sngie * documentation and/or other materials provided with distribution.  In
60272343Sngie * addition, Licensee may not authorize further sublicense of source of any
61272343Sngie * portion of the Covered Code, and must include terms to the effect that the
62272343Sngie * license from Licensee to its licensee is limited to the intellectual
63272343Sngie * property embodied in the software Licensee provides to its licensee, and
64272343Sngie * not to intellectual property embodied in modifications its licensee may
65272343Sngie * make.
66272343Sngie *
67272343Sngie * 3.3. Redistribution of Executable. Redistribution in executable form of any
68272343Sngie * substantial portion of the Covered Code or modification must reproduce the
69272343Sngie * above Copyright Notice, and the following Disclaimer and Export Compliance
70272343Sngie * provision in the documentation and/or other materials provided with the
71272343Sngie * distribution.
72272343Sngie *
73272343Sngie * 3.4. Intel retains all right, title, and interest in and to the Original
74272343Sngie * Intel Code.
75272343Sngie *
76272343Sngie * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77272343Sngie * Intel shall be used in advertising or otherwise to promote the sale, use or
78272343Sngie * other dealings in products derived from or relating to the Covered Code
79272343Sngie * without prior written authorization from Intel.
80272343Sngie *
81272343Sngie * 4. Disclaimer and Export Compliance
82272343Sngie *
83272343Sngie * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84272343Sngie * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85272343Sngie * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
86272343Sngie * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
87272343Sngie * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
88272343Sngie * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
89272343Sngie * PARTICULAR PURPOSE.
90272343Sngie *
91272343Sngie * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92272343Sngie * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93272343Sngie * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94272343Sngie * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95272343Sngie * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96272343Sngie * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
97272343Sngie * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
98272343Sngie * LIMITED REMEDY.
99272343Sngie *
100272343Sngie * 4.3. Licensee shall not export, either directly or indirectly, any of this
101272343Sngie * software or system incorporating such software without first obtaining any
102272343Sngie * required license or other approval from the U. S. Department of Commerce or
103272343Sngie * any other agency or department of the United States Government.  In the
104272343Sngie * event Licensee exports any such software from the United States or
105272343Sngie * re-exports any such software from a foreign destination, Licensee shall
106272343Sngie * ensure that the distribution and export/re-export of the software is in
107272343Sngie * compliance with all laws, regulations, orders, or other restrictions of the
108272343Sngie * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109272343Sngie * any of its subsidiaries will export/re-export any technical data, process,
110272343Sngie * software, or service, directly or indirectly, to any country for which the
111272343Sngie * United States government or any agency thereof requires an export license,
112272343Sngie * other governmental approval, or letter of assurance, without first obtaining
113272343Sngie * such license, approval or letter.
114272343Sngie *
115272343Sngie *****************************************************************************/
116272343Sngie
117272343Sngie#define __DSWSCOPE_C__
118272343Sngie
119272343Sngie#include "acpi.h"
120272343Sngie#include "acinterp.h"
121272343Sngie#include "acdispat.h"
122272343Sngie
123272343Sngie
124272343Sngie#define _COMPONENT          NAMESPACE
125272343Sngie        MODULE_NAME         ("dswscope")
126272343Sngie
127272343Sngie
128272343Sngie#define STACK_POP(head) head
129272343Sngie
130272343Sngie
131272343Sngie/****************************************************************************
132272343Sngie *
133272343Sngie * FUNCTION:    AcpiDsScopeStackClear
134272343Sngie *
135272343Sngie * PARAMETERS:  None
136272343Sngie *
137272343Sngie * DESCRIPTION: Pop (and free) everything on the scope stack except the
138272343Sngie *              root scope object (which remains at the stack top.)
139272343Sngie *
140272343Sngie ***************************************************************************/
141272343Sngie
142272343Sngievoid
143272343SngieAcpiDsScopeStackClear (
144272343Sngie    ACPI_WALK_STATE         *WalkState)
145272343Sngie{
146272343Sngie    ACPI_GENERIC_STATE      *ScopeInfo;
147272343Sngie
148272343Sngie
149272343Sngie    while (WalkState->ScopeInfo)
150272343Sngie    {
151272343Sngie        /* Pop a scope off the stack */
152272343Sngie
153272343Sngie        ScopeInfo = WalkState->ScopeInfo;
154272343Sngie        WalkState->ScopeInfo = ScopeInfo->Scope.Next;
155272343Sngie
156272343Sngie        DEBUG_PRINT (TRACE_EXEC,
157272343Sngie            ("Popped object type %X\n", ScopeInfo->Common.Value));
158272343Sngie        AcpiCmDeleteGenericState (ScopeInfo);
159272343Sngie    }
160272343Sngie}
161272343Sngie
162272343Sngie
163272343Sngie/****************************************************************************
164272343Sngie *
165272343Sngie * FUNCTION:    AcpiDsScopeStackPush
166272343Sngie *
167272343Sngie * PARAMETERS:  *Node,              - Name to be made current
168272343Sngie *              Type,               - Type of frame being pushed
169272343Sngie *
170272343Sngie * DESCRIPTION: Push the current scope on the scope stack, and make the
171272343Sngie *              passed Node current.
172272343Sngie *
173272343Sngie ***************************************************************************/
174272343Sngie
175272343SngieACPI_STATUS
176272343SngieAcpiDsScopeStackPush (
177    ACPI_NAMESPACE_NODE     *Node,
178    OBJECT_TYPE_INTERNAL    Type,
179    ACPI_WALK_STATE         *WalkState)
180{
181    ACPI_GENERIC_STATE      *ScopeInfo;
182
183
184    FUNCTION_TRACE ("DsScopeStackPush");
185
186
187    if (!Node)
188    {
189        /*  invalid scope   */
190
191        REPORT_ERROR (("DsScopeStackPush: null scope passed\n"));
192        return_ACPI_STATUS (AE_BAD_PARAMETER);
193    }
194
195    /* Make sure object type is valid */
196
197    if (!AcpiAmlValidateObjectType (Type))
198    {
199        REPORT_WARNING (("DsScopeStackPush: type code out of range\n"));
200    }
201
202
203    /* Allocate a new scope object */
204
205    ScopeInfo = AcpiCmCreateGenericState ();
206    if (!ScopeInfo)
207    {
208        return_ACPI_STATUS (AE_NO_MEMORY);
209    }
210
211    /* Init new scope object */
212
213    ScopeInfo->Scope.Node  = Node;
214    ScopeInfo->Common.Value = (UINT16) Type;
215
216    /* Push new scope object onto stack */
217
218    AcpiCmPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
219
220    return_ACPI_STATUS (AE_OK);
221}
222
223
224/****************************************************************************
225 *
226 * FUNCTION:    AcpiDsScopeStackPop
227 *
228 * PARAMETERS:  Type                - The type of frame to be found
229 *
230 * DESCRIPTION: Pop the scope stack until a frame of the requested type
231 *              is found.
232 *
233 * RETURN:      Count of frames popped.  If no frame of the requested type
234 *              was found, the count is returned as a negative number and
235 *              the scope stack is emptied (which sets the current scope
236 *              to the root).  If the scope stack was empty at entry, the
237 *              function is a no-op and returns 0.
238 *
239 ***************************************************************************/
240
241ACPI_STATUS
242AcpiDsScopeStackPop (
243    ACPI_WALK_STATE         *WalkState)
244{
245    ACPI_GENERIC_STATE      *ScopeInfo;
246
247
248    FUNCTION_TRACE ("DsScopeStackPop");
249
250    /*
251     * Pop scope info object off the stack.
252     */
253
254    ScopeInfo = AcpiCmPopGenericState (&WalkState->ScopeInfo);
255    if (!ScopeInfo)
256    {
257        return_ACPI_STATUS (AE_STACK_UNDERFLOW);
258    }
259
260    DEBUG_PRINT (TRACE_EXEC,
261        ("Popped object type %X\n", ScopeInfo->Common.Value));
262
263    AcpiCmDeleteGenericState (ScopeInfo);
264
265    return_ACPI_STATUS (AE_OK);
266}
267
268
269