2000-10-28 05:01:06 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Module Name: psscope - Parser scope stack management routines
|
|
|
|
*
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2011-01-13 16:12:34 +00:00
|
|
|
/*
|
2013-01-17 21:32:03 +00:00
|
|
|
* Copyright (C) 2000 - 2013, Intel Corp.
|
2000-12-21 06:56:46 +00:00
|
|
|
* All rights reserved.
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
2011-01-13 16:12:34 +00:00
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification.
|
|
|
|
* 2. Redistributions in binary form must reproduce at minimum a disclaimer
|
|
|
|
* substantially similar to the "NO WARRANTY" disclaimer below
|
|
|
|
* ("Disclaimer") and any redistribution must be conditioned upon
|
|
|
|
* including a substantially similar Disclaimer requirement for further
|
|
|
|
* binary redistribution.
|
|
|
|
* 3. Neither the names of the above-listed copyright holders nor the names
|
|
|
|
* of any contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* Alternatively, this software may be distributed under the terms of the
|
|
|
|
* GNU General Public License ("GPL") version 2 as published by the Free
|
|
|
|
* Software Foundation.
|
|
|
|
*
|
|
|
|
* NO WARRANTY
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
|
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
|
* HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
|
|
|
|
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
|
|
|
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGES.
|
|
|
|
*/
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acpi.h"
|
2009-06-01 21:02:40 +00:00
|
|
|
#include "accommon.h"
|
2009-06-01 19:24:26 +00:00
|
|
|
#include "acparser.h"
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
#define _COMPONENT ACPI_PARSER
|
2002-02-23 05:10:40 +00:00
|
|
|
ACPI_MODULE_NAME ("psscope")
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsGetParentScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
*
|
|
|
|
* RETURN: Pointer to an Op object
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Get parent of current op being parsed
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_PARSE_OBJECT *
|
|
|
|
AcpiPsGetParentScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
return (ParserState->Scope->ParseScope.Op);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsHasCompletedScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
*
|
|
|
|
* RETURN: Boolean, TRUE = scope completed.
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Is parsing of current argument complete? Determined by
|
|
|
|
* 1) AML pointer is at or beyond the end of the scope
|
|
|
|
* 2) The scope argument count has reached zero.
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
BOOLEAN
|
|
|
|
AcpiPsHasCompletedScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
|
|
|
|
return ((BOOLEAN)
|
|
|
|
((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||
|
|
|
|
!ParserState->Scope->ParseScope.ArgCount)));
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsInitScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
* Root - the Root Node of this new scope
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Allocate and init a new scope object
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiPsInitScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState,
|
|
|
|
ACPI_PARSE_OBJECT *RootOp)
|
|
|
|
{
|
|
|
|
ACPI_GENERIC_STATE *Scope;
|
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
Scope = AcpiUtCreateGenericState ();
|
2000-10-28 05:01:06 +00:00
|
|
|
if (!Scope)
|
|
|
|
{
|
|
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
|
|
|
}
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;
|
|
|
|
Scope->ParseScope.Op = RootOp;
|
|
|
|
Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;
|
|
|
|
Scope->ParseScope.ArgEnd = ParserState->AmlEnd;
|
|
|
|
Scope->ParseScope.PkgEnd = ParserState->AmlEnd;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ParserState->Scope = Scope;
|
|
|
|
ParserState->StartOp = RootOp;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
return_ACPI_STATUS (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsPushScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
* Op - Current op to be pushed
|
|
|
|
* RemainingArgs - List of args remaining
|
|
|
|
* ArgCount - Fixed or variable number of args
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Push current op to begin parsing its argument
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
ACPI_STATUS
|
|
|
|
AcpiPsPushScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState,
|
|
|
|
ACPI_PARSE_OBJECT *Op,
|
|
|
|
UINT32 RemainingArgs,
|
|
|
|
UINT32 ArgCount)
|
|
|
|
{
|
|
|
|
ACPI_GENERIC_STATE *Scope;
|
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
Scope = AcpiUtCreateGenericState ();
|
2000-10-28 05:01:06 +00:00
|
|
|
if (!Scope)
|
|
|
|
{
|
2001-11-28 04:29:40 +00:00
|
|
|
return_ACPI_STATUS (AE_NO_MEMORY);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;
|
|
|
|
Scope->ParseScope.Op = Op;
|
|
|
|
Scope->ParseScope.ArgList = RemainingArgs;
|
2005-11-01 22:11:18 +00:00
|
|
|
Scope->ParseScope.ArgCount = ArgCount;
|
2007-03-22 17:24:05 +00:00
|
|
|
Scope->ParseScope.PkgEnd = ParserState->PkgEnd;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/* Push onto scope stack */
|
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
AcpiUtPushGenericState (&ParserState->Scope, Scope);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
if (ArgCount == ACPI_VAR_ARGS)
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Multiple arguments */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
Scope->ParseScope.ArgEnd = ParserState->PkgEnd;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Single argument */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2002-02-23 05:10:40 +00:00
|
|
|
Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return_ACPI_STATUS (AE_OK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsPopScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
* Op - Where the popped op is returned
|
|
|
|
* ArgList - Where the popped "next argument" is
|
|
|
|
* returned
|
|
|
|
* ArgCount - Count of objects in ArgList
|
|
|
|
*
|
|
|
|
* RETURN: Status
|
|
|
|
*
|
|
|
|
* DESCRIPTION: Return to parsing a previous op
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
AcpiPsPopScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState,
|
|
|
|
ACPI_PARSE_OBJECT **Op,
|
|
|
|
UINT32 *ArgList,
|
|
|
|
UINT32 *ArgCount)
|
|
|
|
{
|
|
|
|
ACPI_GENERIC_STATE *Scope = ParserState->Scope;
|
|
|
|
|
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE (PsPopScope);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2001-09-07 01:22:25 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
/* Only pop the scope if there is in fact a next scope */
|
|
|
|
|
2000-10-28 05:01:06 +00:00
|
|
|
if (Scope->Common.Next)
|
|
|
|
{
|
2001-05-29 19:52:40 +00:00
|
|
|
Scope = AcpiUtPopGenericState (&ParserState->Scope);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
/* Return to parsing previous op */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
*Op = Scope->ParseScope.Op;
|
|
|
|
*ArgList = Scope->ParseScope.ArgList;
|
|
|
|
*ArgCount = Scope->ParseScope.ArgCount;
|
|
|
|
ParserState->PkgEnd = Scope->ParseScope.PkgEnd;
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
/* All done with this scope state structure */
|
|
|
|
|
2001-05-29 19:52:40 +00:00
|
|
|
AcpiUtDeleteGenericState (Scope);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-22 17:24:05 +00:00
|
|
|
/* Empty parse stack, prepare to fetch next opcode */
|
2000-10-28 05:01:06 +00:00
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
*Op = NULL;
|
|
|
|
*ArgList = 0;
|
|
|
|
*ArgCount = 0;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
2005-11-01 22:11:18 +00:00
|
|
|
ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,
|
|
|
|
"Popped Op %p Args %X\n", *Op, *ArgCount));
|
2000-10-28 05:01:06 +00:00
|
|
|
return_VOID;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/*******************************************************************************
|
|
|
|
*
|
|
|
|
* FUNCTION: AcpiPsCleanupScope
|
|
|
|
*
|
|
|
|
* PARAMETERS: ParserState - Current parser state object
|
|
|
|
*
|
2005-11-01 22:11:18 +00:00
|
|
|
* RETURN: None
|
2000-10-28 05:01:06 +00:00
|
|
|
*
|
|
|
|
* DESCRIPTION: Destroy available list, remaining stack levels, and return
|
|
|
|
* root scope
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
void
|
|
|
|
AcpiPsCleanupScope (
|
|
|
|
ACPI_PARSE_STATE *ParserState)
|
|
|
|
{
|
|
|
|
ACPI_GENERIC_STATE *Scope;
|
|
|
|
|
2004-03-18 17:42:14 +00:00
|
|
|
|
2007-03-22 17:24:05 +00:00
|
|
|
ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);
|
2000-10-28 05:01:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
if (!ParserState)
|
|
|
|
{
|
2004-03-18 17:42:14 +00:00
|
|
|
return_VOID;
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Delete anything on the scope stack */
|
|
|
|
|
|
|
|
while (ParserState->Scope)
|
|
|
|
{
|
2001-05-29 19:52:40 +00:00
|
|
|
Scope = AcpiUtPopGenericState (&ParserState->Scope);
|
|
|
|
AcpiUtDeleteGenericState (Scope);
|
2000-10-28 05:01:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return_VOID;
|
|
|
|
}
|