167754Smsmith/****************************************************************************** 267754Smsmith * 367754Smsmith * Module Name: psscope - Parser scope stack management routines 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/acparser.h> 4767754Smsmith 4877424Smsmith#define _COMPONENT ACPI_PARSER 4991116Smsmith ACPI_MODULE_NAME ("psscope") 5067754Smsmith 5167754Smsmith 5267754Smsmith/******************************************************************************* 5367754Smsmith * 5467754Smsmith * FUNCTION: AcpiPsGetParentScope 5567754Smsmith * 5667754Smsmith * PARAMETERS: ParserState - Current parser state object 5767754Smsmith * 5867754Smsmith * RETURN: Pointer to an Op object 5967754Smsmith * 6067754Smsmith * DESCRIPTION: Get parent of current op being parsed 6167754Smsmith * 6267754Smsmith ******************************************************************************/ 6367754Smsmith 6467754SmsmithACPI_PARSE_OBJECT * 6567754SmsmithAcpiPsGetParentScope ( 6667754Smsmith ACPI_PARSE_STATE *ParserState) 6767754Smsmith{ 68151937Sjkim 6967754Smsmith return (ParserState->Scope->ParseScope.Op); 7067754Smsmith} 7167754Smsmith 7267754Smsmith 7367754Smsmith/******************************************************************************* 7467754Smsmith * 7567754Smsmith * FUNCTION: AcpiPsHasCompletedScope 7667754Smsmith * 7767754Smsmith * PARAMETERS: ParserState - Current parser state object 7867754Smsmith * 7967754Smsmith * RETURN: Boolean, TRUE = scope completed. 8067754Smsmith * 8167754Smsmith * DESCRIPTION: Is parsing of current argument complete? Determined by 8267754Smsmith * 1) AML pointer is at or beyond the end of the scope 8367754Smsmith * 2) The scope argument count has reached zero. 8467754Smsmith * 8567754Smsmith ******************************************************************************/ 8667754Smsmith 8767754SmsmithBOOLEAN 8867754SmsmithAcpiPsHasCompletedScope ( 8967754Smsmith ACPI_PARSE_STATE *ParserState) 9067754Smsmith{ 91151937Sjkim 92151937Sjkim return ((BOOLEAN) 93151937Sjkim ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd || 94151937Sjkim !ParserState->Scope->ParseScope.ArgCount))); 9567754Smsmith} 9667754Smsmith 9767754Smsmith 9867754Smsmith/******************************************************************************* 9967754Smsmith * 10067754Smsmith * FUNCTION: AcpiPsInitScope 10167754Smsmith * 10267754Smsmith * PARAMETERS: ParserState - Current parser state object 10367754Smsmith * Root - the Root Node of this new scope 10467754Smsmith * 10567754Smsmith * RETURN: Status 10667754Smsmith * 10767754Smsmith * DESCRIPTION: Allocate and init a new scope object 10867754Smsmith * 10967754Smsmith ******************************************************************************/ 11067754Smsmith 11167754SmsmithACPI_STATUS 11267754SmsmithAcpiPsInitScope ( 11367754Smsmith ACPI_PARSE_STATE *ParserState, 11467754Smsmith ACPI_PARSE_OBJECT *RootOp) 11567754Smsmith{ 11667754Smsmith ACPI_GENERIC_STATE *Scope; 11767754Smsmith 11867754Smsmith 119167802Sjkim ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp); 12067754Smsmith 12167754Smsmith 12277424Smsmith Scope = AcpiUtCreateGenericState (); 12367754Smsmith if (!Scope) 12467754Smsmith { 12567754Smsmith return_ACPI_STATUS (AE_NO_MEMORY); 12667754Smsmith } 12767754Smsmith 128167802Sjkim Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE; 129167802Sjkim Scope->ParseScope.Op = RootOp; 130167802Sjkim Scope->ParseScope.ArgCount = ACPI_VAR_ARGS; 131167802Sjkim Scope->ParseScope.ArgEnd = ParserState->AmlEnd; 132167802Sjkim Scope->ParseScope.PkgEnd = ParserState->AmlEnd; 13367754Smsmith 134167802Sjkim ParserState->Scope = Scope; 135167802Sjkim ParserState->StartOp = RootOp; 13667754Smsmith 13767754Smsmith return_ACPI_STATUS (AE_OK); 13867754Smsmith} 13967754Smsmith 14067754Smsmith 14167754Smsmith/******************************************************************************* 14267754Smsmith * 14367754Smsmith * FUNCTION: AcpiPsPushScope 14467754Smsmith * 14567754Smsmith * PARAMETERS: ParserState - Current parser state object 14667754Smsmith * Op - Current op to be pushed 14767754Smsmith * RemainingArgs - List of args remaining 14867754Smsmith * ArgCount - Fixed or variable number of args 14967754Smsmith * 15067754Smsmith * RETURN: Status 15167754Smsmith * 15267754Smsmith * DESCRIPTION: Push current op to begin parsing its argument 15367754Smsmith * 15467754Smsmith ******************************************************************************/ 15567754Smsmith 15667754SmsmithACPI_STATUS 15767754SmsmithAcpiPsPushScope ( 15867754Smsmith ACPI_PARSE_STATE *ParserState, 15967754Smsmith ACPI_PARSE_OBJECT *Op, 16067754Smsmith UINT32 RemainingArgs, 16167754Smsmith UINT32 ArgCount) 16267754Smsmith{ 16367754Smsmith ACPI_GENERIC_STATE *Scope; 16467754Smsmith 16567754Smsmith 166167802Sjkim ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op); 16767754Smsmith 16867754Smsmith 16977424Smsmith Scope = AcpiUtCreateGenericState (); 17067754Smsmith if (!Scope) 17167754Smsmith { 17287031Smsmith return_ACPI_STATUS (AE_NO_MEMORY); 17367754Smsmith } 17467754Smsmith 175167802Sjkim Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE; 176167802Sjkim Scope->ParseScope.Op = Op; 177167802Sjkim Scope->ParseScope.ArgList = RemainingArgs; 178151937Sjkim Scope->ParseScope.ArgCount = ArgCount; 179167802Sjkim Scope->ParseScope.PkgEnd = ParserState->PkgEnd; 18067754Smsmith 18167754Smsmith /* Push onto scope stack */ 18267754Smsmith 18377424Smsmith AcpiUtPushGenericState (&ParserState->Scope, Scope); 18467754Smsmith 18567754Smsmith if (ArgCount == ACPI_VAR_ARGS) 18667754Smsmith { 187151937Sjkim /* Multiple arguments */ 18867754Smsmith 18967754Smsmith Scope->ParseScope.ArgEnd = ParserState->PkgEnd; 19067754Smsmith } 19167754Smsmith else 19267754Smsmith { 193151937Sjkim /* Single argument */ 19467754Smsmith 19591116Smsmith Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR); 19667754Smsmith } 19767754Smsmith 19867754Smsmith return_ACPI_STATUS (AE_OK); 19967754Smsmith} 20067754Smsmith 20167754Smsmith 20267754Smsmith/******************************************************************************* 20367754Smsmith * 20467754Smsmith * FUNCTION: AcpiPsPopScope 20567754Smsmith * 20667754Smsmith * PARAMETERS: ParserState - Current parser state object 20767754Smsmith * Op - Where the popped op is returned 20867754Smsmith * ArgList - Where the popped "next argument" is 20967754Smsmith * returned 21067754Smsmith * ArgCount - Count of objects in ArgList 21167754Smsmith * 21267754Smsmith * RETURN: Status 21367754Smsmith * 21467754Smsmith * DESCRIPTION: Return to parsing a previous op 21567754Smsmith * 21667754Smsmith ******************************************************************************/ 21767754Smsmith 21867754Smsmithvoid 21967754SmsmithAcpiPsPopScope ( 22067754Smsmith ACPI_PARSE_STATE *ParserState, 22167754Smsmith ACPI_PARSE_OBJECT **Op, 22267754Smsmith UINT32 *ArgList, 22367754Smsmith UINT32 *ArgCount) 22467754Smsmith{ 22567754Smsmith ACPI_GENERIC_STATE *Scope = ParserState->Scope; 22667754Smsmith 22767754Smsmith 228167802Sjkim ACPI_FUNCTION_TRACE (PsPopScope); 22967754Smsmith 23083174Smsmith 231151937Sjkim /* Only pop the scope if there is in fact a next scope */ 232151937Sjkim 23367754Smsmith if (Scope->Common.Next) 23467754Smsmith { 23577424Smsmith Scope = AcpiUtPopGenericState (&ParserState->Scope); 23667754Smsmith 237167802Sjkim /* Return to parsing previous op */ 23867754Smsmith 239306536Sjkim *Op = Scope->ParseScope.Op; 240306536Sjkim *ArgList = Scope->ParseScope.ArgList; 241306536Sjkim *ArgCount = Scope->ParseScope.ArgCount; 242151937Sjkim ParserState->PkgEnd = Scope->ParseScope.PkgEnd; 24367754Smsmith 24467754Smsmith /* All done with this scope state structure */ 24567754Smsmith 24677424Smsmith AcpiUtDeleteGenericState (Scope); 24767754Smsmith } 24867754Smsmith else 24967754Smsmith { 250167802Sjkim /* Empty parse stack, prepare to fetch next opcode */ 25167754Smsmith 252306536Sjkim *Op = NULL; 253306536Sjkim *ArgList = 0; 254151937Sjkim *ArgCount = 0; 25567754Smsmith } 25667754Smsmith 257151937Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 258151937Sjkim "Popped Op %p Args %X\n", *Op, *ArgCount)); 25967754Smsmith return_VOID; 26067754Smsmith} 26167754Smsmith 26267754Smsmith 26367754Smsmith/******************************************************************************* 26467754Smsmith * 26567754Smsmith * FUNCTION: AcpiPsCleanupScope 26667754Smsmith * 26767754Smsmith * PARAMETERS: ParserState - Current parser state object 26867754Smsmith * 269151937Sjkim * RETURN: None 27067754Smsmith * 27167754Smsmith * DESCRIPTION: Destroy available list, remaining stack levels, and return 27267754Smsmith * root scope 27367754Smsmith * 27467754Smsmith ******************************************************************************/ 27567754Smsmith 27667754Smsmithvoid 27767754SmsmithAcpiPsCleanupScope ( 27867754Smsmith ACPI_PARSE_STATE *ParserState) 27967754Smsmith{ 28067754Smsmith ACPI_GENERIC_STATE *Scope; 28167754Smsmith 282127175Snjl 283167802Sjkim ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState); 28467754Smsmith 28567754Smsmith 28667754Smsmith if (!ParserState) 28767754Smsmith { 288127175Snjl return_VOID; 28967754Smsmith } 29067754Smsmith 29167754Smsmith /* Delete anything on the scope stack */ 29267754Smsmith 29367754Smsmith while (ParserState->Scope) 29467754Smsmith { 29577424Smsmith Scope = AcpiUtPopGenericState (&ParserState->Scope); 29677424Smsmith AcpiUtDeleteGenericState (Scope); 29767754Smsmith } 29867754Smsmith 29967754Smsmith return_VOID; 30067754Smsmith} 301