psscope.c revision 217365
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: psscope - Parser scope stack management routines
467754Smsmith *
567754Smsmith *****************************************************************************/
667754Smsmith
7217365Sjkim/*
8217365Sjkim * Copyright (C) 2000 - 2011, 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
4467754Smsmith
45193341Sjkim#include <contrib/dev/acpica/include/acpi.h>
46193341Sjkim#include <contrib/dev/acpica/include/accommon.h>
47193341Sjkim#include <contrib/dev/acpica/include/acparser.h>
4867754Smsmith
4977424Smsmith#define _COMPONENT          ACPI_PARSER
5091116Smsmith        ACPI_MODULE_NAME    ("psscope")
5167754Smsmith
5267754Smsmith
5367754Smsmith/*******************************************************************************
5467754Smsmith *
5567754Smsmith * FUNCTION:    AcpiPsGetParentScope
5667754Smsmith *
5767754Smsmith * PARAMETERS:  ParserState         - Current parser state object
5867754Smsmith *
5967754Smsmith * RETURN:      Pointer to an Op object
6067754Smsmith *
6167754Smsmith * DESCRIPTION: Get parent of current op being parsed
6267754Smsmith *
6367754Smsmith ******************************************************************************/
6467754Smsmith
6567754SmsmithACPI_PARSE_OBJECT *
6667754SmsmithAcpiPsGetParentScope (
6767754Smsmith    ACPI_PARSE_STATE        *ParserState)
6867754Smsmith{
69151937Sjkim
7067754Smsmith    return (ParserState->Scope->ParseScope.Op);
7167754Smsmith}
7267754Smsmith
7367754Smsmith
7467754Smsmith/*******************************************************************************
7567754Smsmith *
7667754Smsmith * FUNCTION:    AcpiPsHasCompletedScope
7767754Smsmith *
7867754Smsmith * PARAMETERS:  ParserState         - Current parser state object
7967754Smsmith *
8067754Smsmith * RETURN:      Boolean, TRUE = scope completed.
8167754Smsmith *
8267754Smsmith * DESCRIPTION: Is parsing of current argument complete?  Determined by
8367754Smsmith *              1) AML pointer is at or beyond the end of the scope
8467754Smsmith *              2) The scope argument count has reached zero.
8567754Smsmith *
8667754Smsmith ******************************************************************************/
8767754Smsmith
8867754SmsmithBOOLEAN
8967754SmsmithAcpiPsHasCompletedScope (
9067754Smsmith    ACPI_PARSE_STATE        *ParserState)
9167754Smsmith{
92151937Sjkim
93151937Sjkim    return ((BOOLEAN)
94151937Sjkim            ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
95151937Sjkim             !ParserState->Scope->ParseScope.ArgCount)));
9667754Smsmith}
9767754Smsmith
9867754Smsmith
9967754Smsmith/*******************************************************************************
10067754Smsmith *
10167754Smsmith * FUNCTION:    AcpiPsInitScope
10267754Smsmith *
10367754Smsmith * PARAMETERS:  ParserState         - Current parser state object
10467754Smsmith *              Root                - the Root Node of this new scope
10567754Smsmith *
10667754Smsmith * RETURN:      Status
10767754Smsmith *
10867754Smsmith * DESCRIPTION: Allocate and init a new scope object
10967754Smsmith *
11067754Smsmith ******************************************************************************/
11167754Smsmith
11267754SmsmithACPI_STATUS
11367754SmsmithAcpiPsInitScope (
11467754Smsmith    ACPI_PARSE_STATE        *ParserState,
11567754Smsmith    ACPI_PARSE_OBJECT       *RootOp)
11667754Smsmith{
11767754Smsmith    ACPI_GENERIC_STATE      *Scope;
11867754Smsmith
11967754Smsmith
120167802Sjkim    ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
12167754Smsmith
12267754Smsmith
12377424Smsmith    Scope = AcpiUtCreateGenericState ();
12467754Smsmith    if (!Scope)
12567754Smsmith    {
12667754Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
12767754Smsmith    }
12867754Smsmith
129167802Sjkim    Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
130167802Sjkim    Scope->ParseScope.Op = RootOp;
131167802Sjkim    Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
132167802Sjkim    Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
133167802Sjkim    Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
13467754Smsmith
135167802Sjkim    ParserState->Scope = Scope;
136167802Sjkim    ParserState->StartOp = RootOp;
13767754Smsmith
13867754Smsmith    return_ACPI_STATUS (AE_OK);
13967754Smsmith}
14067754Smsmith
14167754Smsmith
14267754Smsmith/*******************************************************************************
14367754Smsmith *
14467754Smsmith * FUNCTION:    AcpiPsPushScope
14567754Smsmith *
14667754Smsmith * PARAMETERS:  ParserState         - Current parser state object
14767754Smsmith *              Op                  - Current op to be pushed
14867754Smsmith *              RemainingArgs       - List of args remaining
14967754Smsmith *              ArgCount            - Fixed or variable number of args
15067754Smsmith *
15167754Smsmith * RETURN:      Status
15267754Smsmith *
15367754Smsmith * DESCRIPTION: Push current op to begin parsing its argument
15467754Smsmith *
15567754Smsmith ******************************************************************************/
15667754Smsmith
15767754SmsmithACPI_STATUS
15867754SmsmithAcpiPsPushScope (
15967754Smsmith    ACPI_PARSE_STATE        *ParserState,
16067754Smsmith    ACPI_PARSE_OBJECT       *Op,
16167754Smsmith    UINT32                  RemainingArgs,
16267754Smsmith    UINT32                  ArgCount)
16367754Smsmith{
16467754Smsmith    ACPI_GENERIC_STATE      *Scope;
16567754Smsmith
16667754Smsmith
167167802Sjkim    ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
16867754Smsmith
16967754Smsmith
17077424Smsmith    Scope = AcpiUtCreateGenericState ();
17167754Smsmith    if (!Scope)
17267754Smsmith    {
17387031Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
17467754Smsmith    }
17567754Smsmith
176167802Sjkim    Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
177167802Sjkim    Scope->ParseScope.Op = Op;
178167802Sjkim    Scope->ParseScope.ArgList = RemainingArgs;
179151937Sjkim    Scope->ParseScope.ArgCount = ArgCount;
180167802Sjkim    Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
18167754Smsmith
18267754Smsmith    /* Push onto scope stack */
18367754Smsmith
18477424Smsmith    AcpiUtPushGenericState (&ParserState->Scope, Scope);
18567754Smsmith
18667754Smsmith    if (ArgCount == ACPI_VAR_ARGS)
18767754Smsmith    {
188151937Sjkim        /* Multiple arguments */
18967754Smsmith
19067754Smsmith        Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
19167754Smsmith    }
19267754Smsmith    else
19367754Smsmith    {
194151937Sjkim        /* Single argument */
19567754Smsmith
19691116Smsmith        Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
19767754Smsmith    }
19867754Smsmith
19967754Smsmith    return_ACPI_STATUS (AE_OK);
20067754Smsmith}
20167754Smsmith
20267754Smsmith
20367754Smsmith/*******************************************************************************
20467754Smsmith *
20567754Smsmith * FUNCTION:    AcpiPsPopScope
20667754Smsmith *
20767754Smsmith * PARAMETERS:  ParserState         - Current parser state object
20867754Smsmith *              Op                  - Where the popped op is returned
20967754Smsmith *              ArgList             - Where the popped "next argument" is
21067754Smsmith *                                    returned
21167754Smsmith *              ArgCount            - Count of objects in ArgList
21267754Smsmith *
21367754Smsmith * RETURN:      Status
21467754Smsmith *
21567754Smsmith * DESCRIPTION: Return to parsing a previous op
21667754Smsmith *
21767754Smsmith ******************************************************************************/
21867754Smsmith
21967754Smsmithvoid
22067754SmsmithAcpiPsPopScope (
22167754Smsmith    ACPI_PARSE_STATE        *ParserState,
22267754Smsmith    ACPI_PARSE_OBJECT       **Op,
22367754Smsmith    UINT32                  *ArgList,
22467754Smsmith    UINT32                  *ArgCount)
22567754Smsmith{
22667754Smsmith    ACPI_GENERIC_STATE      *Scope = ParserState->Scope;
22767754Smsmith
22867754Smsmith
229167802Sjkim    ACPI_FUNCTION_TRACE (PsPopScope);
23067754Smsmith
23183174Smsmith
232151937Sjkim    /* Only pop the scope if there is in fact a next scope */
233151937Sjkim
23467754Smsmith    if (Scope->Common.Next)
23567754Smsmith    {
23677424Smsmith        Scope = AcpiUtPopGenericState (&ParserState->Scope);
23767754Smsmith
238167802Sjkim        /* Return to parsing previous op */
23967754Smsmith
240151937Sjkim        *Op                 = Scope->ParseScope.Op;
241151937Sjkim        *ArgList            = Scope->ParseScope.ArgList;
242151937Sjkim        *ArgCount           = Scope->ParseScope.ArgCount;
243151937Sjkim        ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
24467754Smsmith
24567754Smsmith        /* All done with this scope state structure */
24667754Smsmith
24777424Smsmith        AcpiUtDeleteGenericState (Scope);
24867754Smsmith    }
24967754Smsmith    else
25067754Smsmith    {
251167802Sjkim        /* Empty parse stack, prepare to fetch next opcode */
25267754Smsmith
253151937Sjkim        *Op       = NULL;
254151937Sjkim        *ArgList  = 0;
255151937Sjkim        *ArgCount = 0;
25667754Smsmith    }
25767754Smsmith
258151937Sjkim    ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
259151937Sjkim        "Popped Op %p Args %X\n", *Op, *ArgCount));
26067754Smsmith    return_VOID;
26167754Smsmith}
26267754Smsmith
26367754Smsmith
26467754Smsmith/*******************************************************************************
26567754Smsmith *
26667754Smsmith * FUNCTION:    AcpiPsCleanupScope
26767754Smsmith *
26867754Smsmith * PARAMETERS:  ParserState         - Current parser state object
26967754Smsmith *
270151937Sjkim * RETURN:      None
27167754Smsmith *
27267754Smsmith * DESCRIPTION: Destroy available list, remaining stack levels, and return
27367754Smsmith *              root scope
27467754Smsmith *
27567754Smsmith ******************************************************************************/
27667754Smsmith
27767754Smsmithvoid
27867754SmsmithAcpiPsCleanupScope (
27967754Smsmith    ACPI_PARSE_STATE        *ParserState)
28067754Smsmith{
28167754Smsmith    ACPI_GENERIC_STATE      *Scope;
28267754Smsmith
283127175Snjl
284167802Sjkim    ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
28567754Smsmith
28667754Smsmith
28767754Smsmith    if (!ParserState)
28867754Smsmith    {
289127175Snjl        return_VOID;
29067754Smsmith    }
29167754Smsmith
29267754Smsmith    /* Delete anything on the scope stack */
29367754Smsmith
29467754Smsmith    while (ParserState->Scope)
29567754Smsmith    {
29677424Smsmith        Scope = AcpiUtPopGenericState (&ParserState->Scope);
29777424Smsmith        AcpiUtDeleteGenericState (Scope);
29867754Smsmith    }
29967754Smsmith
30067754Smsmith    return_VOID;
30167754Smsmith}
30267754Smsmith
303