psscope.c revision 87031
1193323Sed/****************************************************************************** 2193323Sed * 3193323Sed * Module Name: psscope - Parser scope stack management routines 4193323Sed * $Revision: 31 $ 5193323Sed * 6193323Sed *****************************************************************************/ 7193323Sed 8193323Sed/****************************************************************************** 9193323Sed * 10193323Sed * 1. Copyright Notice 11193323Sed * 12193323Sed * Some or all of this work - Copyright (c) 1999, 2000, 2001, Intel Corp. 13193323Sed * All rights reserved. 14193323Sed * 15193323Sed * 2. License 16193323Sed * 17198090Srdivacky * 2.1. This is your license from Intel Corp. under its intellectual property 18193323Sed * rights. You may have additional license terms from the party that provided 19218893Sdim * you this software, covering your right to use that party's intellectual 20193323Sed * property rights. 21198090Srdivacky * 22193323Sed * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 23193323Sed * copy of the source code appearing in this file ("Covered Code") an 24193323Sed * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25193323Sed * base code distributed originally by Intel ("Original Intel Code") to copy, 26193323Sed * make derivatives, distribute, use and display any portion of the Covered 27193323Sed * Code in any form, with the right to sublicense such rights; and 28193323Sed * 29193323Sed * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30193323Sed * license (with the right to sublicense), under only those claims of Intel 31193323Sed * patents that are infringed by the Original Intel Code, to make, use, sell, 32193323Sed * offer to sell, and import the Covered Code and derivative works thereof 33193323Sed * solely to the minimum extent necessary to exercise the above copyright 34193323Sed * license, and in no event shall the patent license extend to any additions 35193323Sed * to or modifications of the Original Intel Code. No other license or right 36218893Sdim * is granted directly or by implication, estoppel or otherwise; 37218893Sdim * 38218893Sdim * The above copyright and patent license is granted only if the following 39205218Srdivacky * conditions are met: 40198396Srdivacky * 41193323Sed * 3. Conditions 42193323Sed * 43193323Sed * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44193323Sed * Redistribution of source code of any substantial portion of the Covered 45193323Sed * Code or modification with rights to further distribute source must include 46193323Sed * the above Copyright Notice, the above License, this list of Conditions, 47193323Sed * and the following Disclaimer and Export Compliance provision. In addition, 48193323Sed * Licensee must cause all Covered Code to which Licensee contributes to 49193323Sed * contain a file documenting the changes Licensee made to create that Covered 50193323Sed * Code and the date of any change. Licensee must include in that file the 51193323Sed * documentation of any changes made by any predecessor Licensee. Licensee 52193323Sed * must include a prominent statement that the modification is derived, 53193323Sed * directly or indirectly, from Original Intel Code. 54193323Sed * 55193323Sed * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56193323Sed * Redistribution of source code of any substantial portion of the Covered 57193323Sed * Code or modification without rights to further distribute source must 58193323Sed * include the following Disclaimer and Export Compliance provision in the 59198090Srdivacky * documentation and/or other materials provided with distribution. In 60193323Sed * addition, Licensee may not authorize further sublicense of source of any 61193323Sed * portion of the Covered Code, and must include terms to the effect that the 62198090Srdivacky * license from Licensee to its licensee is limited to the intellectual 63193323Sed * property embodied in the software Licensee provides to its licensee, and 64193323Sed * not to intellectual property embodied in modifications its licensee may 65193323Sed * make. 66193323Sed * 67198090Srdivacky * 3.3. Redistribution of Executable. Redistribution in executable form of any 68193323Sed * substantial portion of the Covered Code or modification must reproduce the 69193323Sed * above Copyright Notice, and the following Disclaimer and Export Compliance 70198090Srdivacky * provision in the documentation and/or other materials provided with the 71193323Sed * distribution. 72198090Srdivacky * 73193323Sed * 3.4. Intel retains all right, title, and interest in and to the Original 74193323Sed * Intel Code. 75193323Sed * 76193323Sed * 3.5. Neither the name Intel nor any other trademark owned or controlled by 77193323Sed * Intel shall be used in advertising or otherwise to promote the sale, use or 78204642Srdivacky * other dealings in products derived from or relating to the Covered Code 79193323Sed * without prior written authorization from Intel. 80193323Sed * 81193323Sed * 4. Disclaimer and Export Compliance 82218893Sdim * 83193323Sed * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84193323Sed * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85193323Sed * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86193323Sed * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87218893Sdim * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88193323Sed * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89198090Srdivacky * PARTICULAR PURPOSE. 90193323Sed * 91193323Sed * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92193323Sed * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93204642Srdivacky * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 94193323Sed * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 95193323Sed * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 96193323Sed * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 97193323Sed * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 98193323Sed * LIMITED REMEDY. 99193323Sed * 100193323Sed * 4.3. Licensee shall not export, either directly or indirectly, any of this 101193323Sed * software or system incorporating such software without first obtaining any 102193323Sed * required license or other approval from the U. S. Department of Commerce or 103198396Srdivacky * any other agency or department of the United States Government. In the 104198892Srdivacky * event Licensee exports any such software from the United States or 105198892Srdivacky * re-exports any such software from a foreign destination, Licensee shall 106198892Srdivacky * ensure that the distribution and export/re-export of the software is in 107193323Sed * compliance with all laws, regulations, orders, or other restrictions of the 108198090Srdivacky * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109198090Srdivacky * any of its subsidiaries will export/re-export any technical data, process, 110193323Sed * software, or service, directly or indirectly, to any country for which the 111193323Sed * United States government or any agency thereof requires an export license, 112198090Srdivacky * other governmental approval, or letter of assurance, without first obtaining 113193323Sed * such license, approval or letter. 114193323Sed * 115193323Sed *****************************************************************************/ 116193323Sed 117198396Srdivacky 118198396Srdivacky#include "acpi.h" 119198396Srdivacky#include "acparser.h" 120198396Srdivacky 121198396Srdivacky#define _COMPONENT ACPI_PARSER 122198396Srdivacky MODULE_NAME ("psscope") 123199481Srdivacky 124199481Srdivacky 125198396Srdivacky/******************************************************************************* 126198396Srdivacky * 127193323Sed * FUNCTION: AcpiPsGetParentScope 128198396Srdivacky * 129198396Srdivacky * PARAMETERS: ParserState - Current parser state object 130198396Srdivacky * 131198396Srdivacky * RETURN: Pointer to an Op object 132193323Sed * 133193323Sed * DESCRIPTION: Get parent of current op being parsed 134193323Sed * 135193323Sed ******************************************************************************/ 136193323Sed 137193323SedACPI_PARSE_OBJECT * 138193323SedAcpiPsGetParentScope ( 139193323Sed ACPI_PARSE_STATE *ParserState) 140193323Sed{ 141193323Sed return (ParserState->Scope->ParseScope.Op); 142193323Sed} 143193323Sed 144193323Sed 145218893Sdim/******************************************************************************* 146218893Sdim * 147218893Sdim * FUNCTION: AcpiPsHasCompletedScope 148218893Sdim * 149218893Sdim * PARAMETERS: ParserState - Current parser state object 150218893Sdim * 151218893Sdim * RETURN: Boolean, TRUE = scope completed. 152218893Sdim * 153218893Sdim * DESCRIPTION: Is parsing of current argument complete? Determined by 154218893Sdim * 1) AML pointer is at or beyond the end of the scope 155218893Sdim * 2) The scope argument count has reached zero. 156218893Sdim * 157218893Sdim ******************************************************************************/ 158218893Sdim 159218893SdimBOOLEAN 160218893SdimAcpiPsHasCompletedScope ( 161218893Sdim ACPI_PARSE_STATE *ParserState) 162218893Sdim{ 163218893Sdim return ((BOOLEAN) ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd || 164218893Sdim !ParserState->Scope->ParseScope.ArgCount))); 165218893Sdim} 166218893Sdim 167218893Sdim 168218893Sdim/******************************************************************************* 169218893Sdim * 170218893Sdim * FUNCTION: AcpiPsInitScope 171218893Sdim * 172218893Sdim * PARAMETERS: ParserState - Current parser state object 173218893Sdim * Root - the Root Node of this new scope 174218893Sdim * 175218893Sdim * RETURN: Status 176218893Sdim * 177218893Sdim * DESCRIPTION: Allocate and init a new scope object 178218893Sdim * 179218893Sdim ******************************************************************************/ 180218893Sdim 181218893SdimACPI_STATUS 182218893SdimAcpiPsInitScope ( 183218893Sdim ACPI_PARSE_STATE *ParserState, 184218893Sdim ACPI_PARSE_OBJECT *RootOp) 185198090Srdivacky{ 186193323Sed ACPI_GENERIC_STATE *Scope; 187193323Sed 188193323Sed 189193323Sed FUNCTION_TRACE_PTR ("PsInitScope", RootOp); 190193323Sed 191193323Sed 192193323Sed Scope = AcpiUtCreateGenericState (); 193199481Srdivacky if (!Scope) 194199481Srdivacky { 195193323Sed return_ACPI_STATUS (AE_NO_MEMORY); 196199481Srdivacky } 197199481Srdivacky 198199481Srdivacky Scope->Common.DataType = ACPI_DESC_TYPE_STATE_RPSCOPE; 199199481Srdivacky Scope->ParseScope.Op = RootOp; 200199481Srdivacky Scope->ParseScope.ArgCount = ACPI_VAR_ARGS; 201199481Srdivacky Scope->ParseScope.ArgEnd = ParserState->AmlEnd; 202193323Sed Scope->ParseScope.PkgEnd = ParserState->AmlEnd; 203205218Srdivacky 204212904Sdim ParserState->Scope = Scope; 205212904Sdim ParserState->StartOp = RootOp; 206212904Sdim 207205218Srdivacky return_ACPI_STATUS (AE_OK); 208193323Sed} 209193323Sed 210193323Sed 211193323Sed/******************************************************************************* 212198090Srdivacky * 213198090Srdivacky * FUNCTION: AcpiPsPushScope 214193323Sed * 215205218Srdivacky * PARAMETERS: ParserState - Current parser state object 216205218Srdivacky * Op - Current op to be pushed 217205218Srdivacky * RemainingArgs - List of args remaining 218205218Srdivacky * ArgCount - Fixed or variable number of args 219218893Sdim * 220218893Sdim * RETURN: Status 221218893Sdim * 222218893Sdim * DESCRIPTION: Push current op to begin parsing its argument 223193323Sed * 224193323Sed ******************************************************************************/ 225193323Sed 226193323SedACPI_STATUS 227205218SrdivackyAcpiPsPushScope ( 228205218Srdivacky ACPI_PARSE_STATE *ParserState, 229205218Srdivacky ACPI_PARSE_OBJECT *Op, 230205218Srdivacky UINT32 RemainingArgs, 231205218Srdivacky UINT32 ArgCount) 232205218Srdivacky{ 233205218Srdivacky ACPI_GENERIC_STATE *Scope; 234205218Srdivacky 235205218Srdivacky 236205218Srdivacky FUNCTION_TRACE_PTR ("PsPushScope", Op); 237193323Sed 238193323Sed 239193323Sed Scope = AcpiUtCreateGenericState (); 240193323Sed if (!Scope) 241193323Sed { 242218893Sdim return_ACPI_STATUS (AE_NO_MEMORY); 243218893Sdim } 244193323Sed 245193323Sed 246193323Sed Scope->Common.DataType = ACPI_DESC_TYPE_STATE_PSCOPE; 247193323Sed Scope->ParseScope.Op = Op; 248193323Sed Scope->ParseScope.ArgList = RemainingArgs; 249193323Sed Scope->ParseScope.ArgCount = ArgCount; 250193323Sed Scope->ParseScope.PkgEnd = ParserState->PkgEnd; 251193323Sed 252193323Sed /* Push onto scope stack */ 253193323Sed 254193323Sed AcpiUtPushGenericState (&ParserState->Scope, Scope); 255193323Sed 256193323Sed 257193323Sed if (ArgCount == ACPI_VAR_ARGS) 258193323Sed { 259205218Srdivacky /* multiple arguments */ 260205218Srdivacky 261208599Srdivacky Scope->ParseScope.ArgEnd = ParserState->PkgEnd; 262205218Srdivacky } 263205218Srdivacky 264205218Srdivacky else 265205218Srdivacky { 266193323Sed /* single argument */ 267193323Sed 268198090Srdivacky Scope->ParseScope.ArgEnd = ACPI_MAX_AML; 269198090Srdivacky } 270198090Srdivacky 271198090Srdivacky return_ACPI_STATUS (AE_OK); 272198090Srdivacky} 273198090Srdivacky 274193323Sed 275198090Srdivacky/******************************************************************************* 276193323Sed * 277193323Sed * FUNCTION: AcpiPsPopScope 278218893Sdim * 279218893Sdim * PARAMETERS: ParserState - Current parser state object 280193323Sed * Op - Where the popped op is returned 281193323Sed * ArgList - Where the popped "next argument" is 282193323Sed * returned 283198090Srdivacky * ArgCount - Count of objects in ArgList 284193323Sed * 285193323Sed * RETURN: Status 286193323Sed * 287193323Sed * DESCRIPTION: Return to parsing a previous op 288193323Sed * 289218893Sdim ******************************************************************************/ 290218893Sdim 291193323Sedvoid 292193323SedAcpiPsPopScope ( 293198892Srdivacky ACPI_PARSE_STATE *ParserState, 294198090Srdivacky ACPI_PARSE_OBJECT **Op, 295193323Sed UINT32 *ArgList, 296193323Sed UINT32 *ArgCount) 297193323Sed{ 298193323Sed ACPI_GENERIC_STATE *Scope = ParserState->Scope; 299193323Sed 300193323Sed 301193323Sed FUNCTION_TRACE ("PsPopScope"); 302193323Sed 303206083Srdivacky 304206083Srdivacky /* 305206083Srdivacky * Only pop the scope if there is in fact a next scope 306206083Srdivacky */ 307206083Srdivacky if (Scope->Common.Next) 308206083Srdivacky { 309206083Srdivacky Scope = AcpiUtPopGenericState (&ParserState->Scope); 310206083Srdivacky 311206083Srdivacky /* return to parsing previous op */ 312218893Sdim 313218893Sdim *Op = Scope->ParseScope.Op; 314206083Srdivacky *ArgList = Scope->ParseScope.ArgList; 315206083Srdivacky *ArgCount = Scope->ParseScope.ArgCount; 316206083Srdivacky ParserState->PkgEnd = Scope->ParseScope.PkgEnd; 317206083Srdivacky 318218893Sdim /* All done with this scope state structure */ 319218893Sdim 320206083Srdivacky AcpiUtDeleteGenericState (Scope); 321206083Srdivacky } 322206083Srdivacky 323193323Sed else 324206083Srdivacky { 325206083Srdivacky /* empty parse stack, prepare to fetch next opcode */ 326206083Srdivacky 327206083Srdivacky *Op = NULL; 328206083Srdivacky *ArgList = 0; 329207618Srdivacky *ArgCount = 0; 330207618Srdivacky } 331206083Srdivacky 332206083Srdivacky 333193323Sed ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped Op %p Args %X\n", *Op, *ArgCount)); 334193323Sed return_VOID; 335193323Sed} 336193323Sed 337193323Sed 338206083Srdivacky/******************************************************************************* 339206083Srdivacky * 340206083Srdivacky * FUNCTION: AcpiPsCleanupScope 341206083Srdivacky * 342207618Srdivacky * PARAMETERS: ParserState - Current parser state object 343207618Srdivacky * 344198090Srdivacky * RETURN: Status 345206083Srdivacky * 346193323Sed * DESCRIPTION: Destroy available list, remaining stack levels, and return 347193323Sed * root scope 348193323Sed * 349193323Sed ******************************************************************************/ 350193323Sed 351193323Sedvoid 352193323SedAcpiPsCleanupScope ( 353193323Sed ACPI_PARSE_STATE *ParserState) 354193323Sed{ 355193323Sed ACPI_GENERIC_STATE *Scope; 356193323Sed 357193323Sed FUNCTION_TRACE_PTR ("PsCleanupScope", ParserState); 358193323Sed 359193323Sed 360193323Sed if (!ParserState) 361193323Sed { 362193323Sed return; 363193323Sed } 364193323Sed 365193323Sed 366193323Sed /* Delete anything on the scope stack */ 367193323Sed 368193323Sed while (ParserState->Scope) 369193323Sed { 370193323Sed Scope = AcpiUtPopGenericState (&ParserState->Scope); 371193323Sed AcpiUtDeleteGenericState (Scope); 372193323Sed } 373193323Sed 374193323Sed return_VOID; 375193323Sed} 376193323Sed 377193323Sed