167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: dswscope - Scope stack manipulation
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7217365Sjkim/*
8306536Sjkim * Copyright (C) 2000 - 2016, Intel Corp.
970243Smsmith * All rights reserved.
1067754Smsmith *
11217365Sjkim * Redistribution and use in source and binary forms, with or without
12217365Sjkim * modification, are permitted provided that the following conditions
13217365Sjkim * are met:
14217365Sjkim * 1. Redistributions of source code must retain the above copyright
15217365Sjkim *    notice, this list of conditions, and the following disclaimer,
16217365Sjkim *    without modification.
17217365Sjkim * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18217365Sjkim *    substantially similar to the "NO WARRANTY" disclaimer below
19217365Sjkim *    ("Disclaimer") and any redistribution must be conditioned upon
20217365Sjkim *    including a substantially similar Disclaimer requirement for further
21217365Sjkim *    binary redistribution.
22217365Sjkim * 3. Neither the names of the above-listed copyright holders nor the names
23217365Sjkim *    of any contributors may be used to endorse or promote products derived
24217365Sjkim *    from this software without specific prior written permission.
2567754Smsmith *
26217365Sjkim * Alternatively, this software may be distributed under the terms of the
27217365Sjkim * GNU General Public License ("GPL") version 2 as published by the Free
28217365Sjkim * Software Foundation.
2967754Smsmith *
30217365Sjkim * NO WARRANTY
31217365Sjkim * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32217365Sjkim * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33217365Sjkim * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34217365Sjkim * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35217365Sjkim * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36217365Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37217365Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38217365Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39217365Sjkim * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40217365Sjkim * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41217365Sjkim * POSSIBILITY OF SUCH DAMAGES.
42217365Sjkim */
4367754Smsmith
44193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
45193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
46193341Sjkim#include <contrib/dev/acpica/include/acdispat.h>
4767754Smsmith
4867754Smsmith
4977424Smsmith#define _COMPONENT          ACPI_DISPATCHER
5091116Smsmith        ACPI_MODULE_NAME    ("dswscope")
5167754Smsmith
5267754Smsmith
5367754Smsmith/****************************************************************************
5467754Smsmith *
5567754Smsmith * FUNCTION:    AcpiDsScopeStackClear
5667754Smsmith *
57151937Sjkim * PARAMETERS:  WalkState       - Current state
5867754Smsmith *
59151937Sjkim * RETURN:      None
60151937Sjkim *
6167754Smsmith * DESCRIPTION: Pop (and free) everything on the scope stack except the
6267754Smsmith *              root scope object (which remains at the stack top.)
6367754Smsmith *
6467754Smsmith ***************************************************************************/
6567754Smsmith
6667754Smsmithvoid
6767754SmsmithAcpiDsScopeStackClear (
6867754Smsmith    ACPI_WALK_STATE         *WalkState)
6967754Smsmith{
7067754Smsmith    ACPI_GENERIC_STATE      *ScopeInfo;
7167754Smsmith
72167802Sjkim    ACPI_FUNCTION_NAME (DsScopeStackClear);
7367754Smsmith
7482367Smsmith
7567754Smsmith    while (WalkState->ScopeInfo)
7667754Smsmith    {
7767754Smsmith        /* Pop a scope off the stack */
7867754Smsmith
7967754Smsmith        ScopeInfo = WalkState->ScopeInfo;
8067754Smsmith        WalkState->ScopeInfo = ScopeInfo->Scope.Next;
8167754Smsmith
8282367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
83151937Sjkim            "Popped object type (%s)\n",
84151937Sjkim            AcpiUtGetTypeName (ScopeInfo->Common.Value)));
85306536Sjkim
8677424Smsmith        AcpiUtDeleteGenericState (ScopeInfo);
8767754Smsmith    }
8867754Smsmith}
8967754Smsmith
9067754Smsmith
9167754Smsmith/****************************************************************************
9267754Smsmith *
9367754Smsmith * FUNCTION:    AcpiDsScopeStackPush
9467754Smsmith *
95151937Sjkim * PARAMETERS:  Node            - Name to be made current
96151937Sjkim *              Type            - Type of frame being pushed
97151937Sjkim *              WalkState       - Current state
9867754Smsmith *
99151937Sjkim * RETURN:      Status
100151937Sjkim *
10167754Smsmith * DESCRIPTION: Push the current scope on the scope stack, and make the
10267754Smsmith *              passed Node current.
10367754Smsmith *
10467754Smsmith ***************************************************************************/
10567754Smsmith
10667754SmsmithACPI_STATUS
10767754SmsmithAcpiDsScopeStackPush (
10867754Smsmith    ACPI_NAMESPACE_NODE     *Node,
10991116Smsmith    ACPI_OBJECT_TYPE        Type,
11067754Smsmith    ACPI_WALK_STATE         *WalkState)
11167754Smsmith{
11267754Smsmith    ACPI_GENERIC_STATE      *ScopeInfo;
113107325Siwasaki    ACPI_GENERIC_STATE      *OldScopeInfo;
11467754Smsmith
11567754Smsmith
116167802Sjkim    ACPI_FUNCTION_TRACE (DsScopeStackPush);
11767754Smsmith
11867754Smsmith
11967754Smsmith    if (!Node)
12067754Smsmith    {
12183174Smsmith        /* Invalid scope   */
12267754Smsmith
123167802Sjkim        ACPI_ERROR ((AE_INFO, "Null scope parameter"));
12467754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
12567754Smsmith    }
12667754Smsmith
12767754Smsmith    /* Make sure object type is valid */
12867754Smsmith
129107325Siwasaki    if (!AcpiUtValidObjectType (Type))
13067754Smsmith    {
131167802Sjkim        ACPI_WARNING ((AE_INFO,
132167802Sjkim            "Invalid object type: 0x%X", Type));
13367754Smsmith    }
13467754Smsmith
13567754Smsmith    /* Allocate a new scope object */
13667754Smsmith
13777424Smsmith    ScopeInfo = AcpiUtCreateGenericState ();
13867754Smsmith    if (!ScopeInfo)
13967754Smsmith    {
14067754Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
14167754Smsmith    }
14267754Smsmith
14367754Smsmith    /* Init new scope object */
14467754Smsmith
145167802Sjkim    ScopeInfo->Common.DescriptorType = ACPI_DESC_TYPE_STATE_WSCOPE;
146167802Sjkim    ScopeInfo->Scope.Node = Node;
147167802Sjkim    ScopeInfo->Common.Value = (UINT16) Type;
14867754Smsmith
149107325Siwasaki    WalkState->ScopeDepth++;
150107325Siwasaki
151107325Siwasaki    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
152107325Siwasaki        "[%.2d] Pushed scope ", (UINT32) WalkState->ScopeDepth));
153107325Siwasaki
154107325Siwasaki    OldScopeInfo = WalkState->ScopeInfo;
155107325Siwasaki    if (OldScopeInfo)
156107325Siwasaki    {
157107325Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
158123315Snjl            "[%4.4s] (%s)",
159123315Snjl            AcpiUtGetNodeName (OldScopeInfo->Scope.Node),
160107325Siwasaki            AcpiUtGetTypeName (OldScopeInfo->Common.Value)));
161107325Siwasaki    }
162107325Siwasaki    else
163107325Siwasaki    {
164107325Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
165123315Snjl            "[\\___] (%s)", "ROOT"));
166107325Siwasaki    }
167107325Siwasaki
168107325Siwasaki    ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
169107325Siwasaki        ", New scope -> [%4.4s] (%s)\n",
170123315Snjl        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
171107325Siwasaki        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
172107325Siwasaki
17367754Smsmith    /* Push new scope object onto stack */
17467754Smsmith
17577424Smsmith    AcpiUtPushGenericState (&WalkState->ScopeInfo, ScopeInfo);
17667754Smsmith    return_ACPI_STATUS (AE_OK);
17767754Smsmith}
17867754Smsmith
17967754Smsmith
18067754Smsmith/****************************************************************************
18167754Smsmith *
18267754Smsmith * FUNCTION:    AcpiDsScopeStackPop
18367754Smsmith *
184151937Sjkim * PARAMETERS:  WalkState       - Current state
18567754Smsmith *
186151937Sjkim * RETURN:      Status
18767754Smsmith *
188151937Sjkim * DESCRIPTION: Pop the scope stack once.
18967754Smsmith *
19067754Smsmith ***************************************************************************/
19167754Smsmith
19267754SmsmithACPI_STATUS
19367754SmsmithAcpiDsScopeStackPop (
19467754Smsmith    ACPI_WALK_STATE         *WalkState)
19567754Smsmith{
19667754Smsmith    ACPI_GENERIC_STATE      *ScopeInfo;
197107325Siwasaki    ACPI_GENERIC_STATE      *NewScopeInfo;
19867754Smsmith
19967754Smsmith
200167802Sjkim    ACPI_FUNCTION_TRACE (DsScopeStackPop);
20167754Smsmith
20283174Smsmith
20367754Smsmith    /*
20467754Smsmith     * Pop scope info object off the stack.
20567754Smsmith     */
20677424Smsmith    ScopeInfo = AcpiUtPopGenericState (&WalkState->ScopeInfo);
20767754Smsmith    if (!ScopeInfo)
20867754Smsmith    {
20967754Smsmith        return_ACPI_STATUS (AE_STACK_UNDERFLOW);
21067754Smsmith    }
21167754Smsmith
212107325Siwasaki    WalkState->ScopeDepth--;
213107325Siwasaki
21482367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
215123315Snjl        "[%.2d] Popped scope [%4.4s] (%s), New scope -> ",
216107325Siwasaki        (UINT32) WalkState->ScopeDepth,
217123315Snjl        AcpiUtGetNodeName (ScopeInfo->Scope.Node),
218107325Siwasaki        AcpiUtGetTypeName (ScopeInfo->Common.Value)));
21967754Smsmith
220107325Siwasaki    NewScopeInfo = WalkState->ScopeInfo;
221107325Siwasaki    if (NewScopeInfo)
222107325Siwasaki    {
223107325Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
224107325Siwasaki            "[%4.4s] (%s)\n",
225123315Snjl            AcpiUtGetNodeName (NewScopeInfo->Scope.Node),
226107325Siwasaki            AcpiUtGetTypeName (NewScopeInfo->Common.Value)));
227107325Siwasaki    }
228107325Siwasaki    else
229107325Siwasaki    {
230107325Siwasaki        ACPI_DEBUG_PRINT_RAW ((ACPI_DB_EXEC,
231107325Siwasaki            "[\\___] (ROOT)\n"));
232107325Siwasaki    }
233107325Siwasaki
23477424Smsmith    AcpiUtDeleteGenericState (ScopeInfo);
23567754Smsmith    return_ACPI_STATUS (AE_OK);
23667754Smsmith}
237