psscope.c revision 193251
1193323Sed/****************************************************************************** 2193323Sed * 3193323Sed * Module Name: psscope - Parser scope stack management routines 4193323Sed * $Revision: 1.47 $ 5193323Sed * 6193323Sed *****************************************************************************/ 7193323Sed 8193323Sed/****************************************************************************** 9193323Sed * 10193323Sed * 1. Copyright Notice 11193323Sed * 12193323Sed * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp. 13193323Sed * All rights reserved. 14193323Sed * 15193323Sed * 2. License 16223017Sdim * 17203954Srdivacky * 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 19198090Srdivacky * you this software, covering your right to use that party's intellectual 20205218Srdivacky * property rights. 21205218Srdivacky * 22205218Srdivacky * 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 24218893Sdim * irrevocable, perpetual, worldwide license under Intel's copyrights in the 25193323Sed * base code distributed originally by Intel ("Original Intel Code") to copy, 26198090Srdivacky * make derivatives, distribute, use and display any portion of the Covered 27203954Srdivacky * Code in any form, with the right to sublicense such rights; and 28218893Sdim * 29203954Srdivacky * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 30198090Srdivacky * 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, 32203954Srdivacky * offer to sell, and import the Covered Code and derivative works thereof 33193323Sed * solely to the minimum extent necessary to exercise the above copyright 34202375Srdivacky * license, and in no event shall the patent license extend to any additions 35198090Srdivacky * to or modifications of the Original Intel Code. No other license or right 36193323Sed * is granted directly or by implication, estoppel or otherwise; 37193323Sed * 38193323Sed * The above copyright and patent license is granted only if the following 39193323Sed * conditions are met: 40193323Sed * 41193323Sed * 3. Conditions 42198953Srdivacky * 43198953Srdivacky * 3.1. Redistribution of Source with Rights to Further Distribute Source. 44198953Srdivacky * Redistribution of source code of any substantial portion of the Covered 45198953Srdivacky * Code or modification with rights to further distribute source must include 46199989Srdivacky * the above Copyright Notice, the above License, this list of Conditions, 47199989Srdivacky * and the following Disclaimer and Export Compliance provision. In addition, 48202878Srdivacky * Licensee must cause all Covered Code to which Licensee contributes to 49202878Srdivacky * contain a file documenting the changes Licensee made to create that Covered 50198953Srdivacky * Code and the date of any change. Licensee must include in that file the 51198953Srdivacky * documentation of any changes made by any predecessor Licensee. Licensee 52198953Srdivacky * must include a prominent statement that the modification is derived, 53198953Srdivacky * directly or indirectly, from Original Intel Code. 54198953Srdivacky * 55198953Srdivacky * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 56207618Srdivacky * Redistribution of source code of any substantial portion of the Covered 57207618Srdivacky * Code or modification without rights to further distribute source must 58207618Srdivacky * include the following Disclaimer and Export Compliance provision in the 59198953Srdivacky * documentation and/or other materials provided with distribution. In 60198953Srdivacky * addition, Licensee may not authorize further sublicense of source of any 61198953Srdivacky * portion of the Covered Code, and must include terms to the effect that the 62198953Srdivacky * license from Licensee to its licensee is limited to the intellectual 63198953Srdivacky * property embodied in the software Licensee provides to its licensee, and 64198953Srdivacky * not to intellectual property embodied in modifications its licensee may 65193323Sed * make. 66193323Sed * 67193323Sed * 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 70193323Sed * provision in the documentation and/or other materials provided with the 71208599Srdivacky * distribution. 72208599Srdivacky * 73208599Srdivacky * 3.4. Intel retains all right, title, and interest in and to the Original 74208599Srdivacky * Intel Code. 75208599Srdivacky * 76208599Srdivacky * 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 78193323Sed * other dealings in products derived from or relating to the Covered Code 79193323Sed * without prior written authorization from Intel. 80193323Sed * 81203954Srdivacky * 4. Disclaimer and Export Compliance 82203954Srdivacky * 83203954Srdivacky * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 84202375Srdivacky * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 85203954Srdivacky * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 86203954Srdivacky * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 87203954Srdivacky * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 88203954Srdivacky * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 89203954Srdivacky * PARTICULAR PURPOSE. 90203954Srdivacky * 91212904Sdim * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 92203954Srdivacky * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 93203954Srdivacky * 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 96198090Srdivacky * 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. 99198090Srdivacky * 100193323Sed * 4.3. Licensee shall not export, either directly or indirectly, any of this 101198090Srdivacky * software or system incorporating such software without first obtaining any 102205218Srdivacky * required license or other approval from the U. S. Department of Commerce or 103205218Srdivacky * any other agency or department of the United States Government. In the 104198090Srdivacky * event Licensee exports any such software from the United States or 105198090Srdivacky * re-exports any such software from a foreign destination, Licensee shall 106198090Srdivacky * ensure that the distribution and export/re-export of the software is in 107201360Srdivacky * compliance with all laws, regulations, orders, or other restrictions of the 108201360Srdivacky * U.S. Export Administration Regulations. Licensee agrees that neither it nor 109205218Srdivacky * any of its subsidiaries will export/re-export any technical data, process, 110201360Srdivacky * software, or service, directly or indirectly, to any country for which the 111201360Srdivacky * United States government or any agency thereof requires an export license, 112198090Srdivacky * other governmental approval, or letter of assurance, without first obtaining 113201360Srdivacky * such license, approval or letter. 114205218Srdivacky * 115201360Srdivacky *****************************************************************************/ 116201360Srdivacky 117198090Srdivacky 118203954Srdivacky#include "acpi.h" 119203954Srdivacky#include "acparser.h" 120203954Srdivacky 121204642Srdivacky#define _COMPONENT ACPI_PARSER 122204642Srdivacky ACPI_MODULE_NAME ("psscope") 123193323Sed 124205218Srdivacky 125205218Srdivacky/******************************************************************************* 126203954Srdivacky * 127205218Srdivacky * FUNCTION: AcpiPsGetParentScope 128193323Sed * 129221345Sdim * PARAMETERS: ParserState - Current parser state object 130221345Sdim * 131221345Sdim * RETURN: Pointer to an Op object 132205218Srdivacky * 133203954Srdivacky * DESCRIPTION: Get parent of current op being parsed 134203954Srdivacky * 135193323Sed ******************************************************************************/ 136203954Srdivacky 137203954SrdivackyACPI_PARSE_OBJECT * 138203954SrdivackyAcpiPsGetParentScope ( 139221345Sdim ACPI_PARSE_STATE *ParserState) 140208599Srdivacky{ 141208599Srdivacky 142208599Srdivacky return (ParserState->Scope->ParseScope.Op); 143218893Sdim} 144218893Sdim 145208599Srdivacky 146218893Sdim/******************************************************************************* 147218893Sdim * 148208599Srdivacky * FUNCTION: AcpiPsHasCompletedScope 149218893Sdim * 150218893Sdim * PARAMETERS: ParserState - Current parser state object 151218893Sdim * 152221345Sdim * RETURN: Boolean, TRUE = scope completed. 153218893Sdim * 154218893Sdim * DESCRIPTION: Is parsing of current argument complete? Determined by 155218893Sdim * 1) AML pointer is at or beyond the end of the scope 156218893Sdim * 2) The scope argument count has reached zero. 157193323Sed * 158193323Sed ******************************************************************************/ 159203954Srdivacky 160203954SrdivackyBOOLEAN 161203954SrdivackyAcpiPsHasCompletedScope ( 162203954Srdivacky ACPI_PARSE_STATE *ParserState) 163205218Srdivacky{ 164205218Srdivacky 165203954Srdivacky return ((BOOLEAN) 166208599Srdivacky ((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd || 167208599Srdivacky !ParserState->Scope->ParseScope.ArgCount))); 168208599Srdivacky} 169218893Sdim 170218893Sdim 171218893Sdim/******************************************************************************* 172203954Srdivacky * 173203954Srdivacky * FUNCTION: AcpiPsInitScope 174203954Srdivacky * 175203954Srdivacky * PARAMETERS: ParserState - Current parser state object 176203954Srdivacky * Root - the Root Node of this new scope 177203954Srdivacky * 178203954Srdivacky * RETURN: Status 179203954Srdivacky * 180208599Srdivacky * DESCRIPTION: Allocate and init a new scope object 181208599Srdivacky * 182208599Srdivacky ******************************************************************************/ 183208599Srdivacky 184205218SrdivackyACPI_STATUS 185206274SrdivackyAcpiPsInitScope ( 186203954Srdivacky ACPI_PARSE_STATE *ParserState, 187198090Srdivacky ACPI_PARSE_OBJECT *RootOp) 188212904Sdim{ 189205218Srdivacky ACPI_GENERIC_STATE *Scope; 190205218Srdivacky 191212904Sdim 192203954Srdivacky ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp); 193212904Sdim 194201360Srdivacky 195201360Srdivacky Scope = AcpiUtCreateGenericState (); 196198090Srdivacky if (!Scope) 197203954Srdivacky { 198193323Sed return_ACPI_STATUS (AE_NO_MEMORY); 199193323Sed } 200193323Sed 201203954Srdivacky Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE; 202193323Sed Scope->ParseScope.Op = RootOp; 203193323Sed Scope->ParseScope.ArgCount = ACPI_VAR_ARGS; 204193323Sed Scope->ParseScope.ArgEnd = ParserState->AmlEnd; 205193323Sed Scope->ParseScope.PkgEnd = ParserState->AmlEnd; 206193323Sed 207193323Sed ParserState->Scope = Scope; 208204642Srdivacky ParserState->StartOp = RootOp; 209204642Srdivacky 210201360Srdivacky return_ACPI_STATUS (AE_OK); 211201360Srdivacky} 212212904Sdim 213193323Sed 214205218Srdivacky/******************************************************************************* 215205218Srdivacky * 216193323Sed * FUNCTION: AcpiPsPushScope 217193323Sed * 218198090Srdivacky * PARAMETERS: ParserState - Current parser state object 219193323Sed * Op - Current op to be pushed 220193323Sed * RemainingArgs - List of args remaining 221193323Sed * ArgCount - Fixed or variable number of args 222193323Sed * 223193323Sed * RETURN: Status 224212904Sdim * 225212904Sdim * DESCRIPTION: Push current op to begin parsing its argument 226212904Sdim * 227212904Sdim ******************************************************************************/ 228212904Sdim 229212904SdimACPI_STATUS 230212904SdimAcpiPsPushScope ( 231221345Sdim ACPI_PARSE_STATE *ParserState, 232212904Sdim ACPI_PARSE_OBJECT *Op, 233212904Sdim UINT32 RemainingArgs, 234212904Sdim UINT32 ArgCount) 235212904Sdim{ 236212904Sdim ACPI_GENERIC_STATE *Scope; 237221345Sdim 238221345Sdim 239221345Sdim ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op); 240221345Sdim 241221345Sdim 242221345Sdim Scope = AcpiUtCreateGenericState (); 243221345Sdim if (!Scope) 244221345Sdim { 245221345Sdim return_ACPI_STATUS (AE_NO_MEMORY); 246221345Sdim } 247221345Sdim 248221345Sdim Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE; 249221345Sdim Scope->ParseScope.Op = Op; 250221345Sdim Scope->ParseScope.ArgList = RemainingArgs; 251221345Sdim Scope->ParseScope.ArgCount = ArgCount; 252221345Sdim Scope->ParseScope.PkgEnd = ParserState->PkgEnd; 253221345Sdim 254221345Sdim /* Push onto scope stack */ 255221345Sdim 256221345Sdim AcpiUtPushGenericState (&ParserState->Scope, Scope); 257221345Sdim 258221345Sdim if (ArgCount == ACPI_VAR_ARGS) 259221345Sdim { 260221345Sdim /* Multiple arguments */ 261221345Sdim 262221345Sdim Scope->ParseScope.ArgEnd = ParserState->PkgEnd; 263221345Sdim } 264221345Sdim else 265212904Sdim { 266212904Sdim /* Single argument */ 267212904Sdim 268212904Sdim Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR); 269212904Sdim } 270212904Sdim 271205218Srdivacky return_ACPI_STATUS (AE_OK); 272204792Srdivacky} 273204792Srdivacky 274204792Srdivacky 275204792Srdivacky/******************************************************************************* 276193323Sed * 277212904Sdim * FUNCTION: AcpiPsPopScope 278193323Sed * 279202375Srdivacky * PARAMETERS: ParserState - Current parser state object 280193323Sed * Op - Where the popped op is returned 281193323Sed * ArgList - Where the popped "next argument" is 282218893Sdim * returned 283193323Sed * ArgCount - Count of objects in ArgList 284193323Sed * 285193323Sed * RETURN: Status 286193323Sed * 287193323Sed * DESCRIPTION: Return to parsing a previous op 288193323Sed * 289204642Srdivacky ******************************************************************************/ 290205218Srdivacky 291205218Srdivackyvoid 292193323SedAcpiPsPopScope ( 293193323Sed ACPI_PARSE_STATE *ParserState, 294218893Sdim ACPI_PARSE_OBJECT **Op, 295223017Sdim UINT32 *ArgList, 296223017Sdim UINT32 *ArgCount) 297223017Sdim{ 298223017Sdim ACPI_GENERIC_STATE *Scope = ParserState->Scope; 299223017Sdim 300218893Sdim 301204642Srdivacky ACPI_FUNCTION_TRACE (PsPopScope); 302204642Srdivacky 303204642Srdivacky 304204642Srdivacky /* Only pop the scope if there is in fact a next scope */ 305204642Srdivacky 306193323Sed if (Scope->Common.Next) 307198953Srdivacky { 308193323Sed Scope = AcpiUtPopGenericState (&ParserState->Scope); 309193323Sed 310202375Srdivacky /* Return to parsing previous op */ 311193323Sed 312193323Sed *Op = Scope->ParseScope.Op; 313212904Sdim *ArgList = Scope->ParseScope.ArgList; 314212904Sdim *ArgCount = Scope->ParseScope.ArgCount; 315212904Sdim ParserState->PkgEnd = Scope->ParseScope.PkgEnd; 316212904Sdim 317212904Sdim /* All done with this scope state structure */ 318193323Sed 319193323Sed AcpiUtDeleteGenericState (Scope); 320205218Srdivacky } 321198090Srdivacky else 322198090Srdivacky { 323202375Srdivacky /* Empty parse stack, prepare to fetch next opcode */ 324202375Srdivacky 325202375Srdivacky *Op = NULL; 326202375Srdivacky *ArgList = 0; 327202375Srdivacky *ArgCount = 0; 328202375Srdivacky } 329212904Sdim 330218893Sdim ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, 331221345Sdim "Popped Op %p Args %X\n", *Op, *ArgCount)); 332223017Sdim return_VOID; 333212904Sdim} 334198090Srdivacky 335198090Srdivacky 336193323Sed/******************************************************************************* 337212904Sdim * 338212904Sdim * FUNCTION: AcpiPsCleanupScope 339212904Sdim * 340198090Srdivacky * PARAMETERS: ParserState - Current parser state object 341198090Srdivacky * 342193323Sed * RETURN: None 343198953Srdivacky * 344193323Sed * DESCRIPTION: Destroy available list, remaining stack levels, and return 345193323Sed * root scope 346193323Sed * 347193323Sed ******************************************************************************/ 348212904Sdim 349212904Sdimvoid 350193323SedAcpiPsCleanupScope ( 351193323Sed ACPI_PARSE_STATE *ParserState) 352193323Sed{ 353202375Srdivacky ACPI_GENERIC_STATE *Scope; 354193323Sed 355204642Srdivacky 356204642Srdivacky ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState); 357204642Srdivacky 358204642Srdivacky 359204642Srdivacky if (!ParserState) 360193323Sed { 361212904Sdim return_VOID; 362205218Srdivacky } 363205218Srdivacky 364218893Sdim /* Delete anything on the scope stack */ 365218893Sdim 366205218Srdivacky while (ParserState->Scope) 367205218Srdivacky { 368193323Sed Scope = AcpiUtPopGenericState (&ParserState->Scope); 369198090Srdivacky AcpiUtDeleteGenericState (Scope); 370198090Srdivacky } 371198090Srdivacky 372193323Sed return_VOID; 373193323Sed} 374193323Sed 375193323Sed