Path: blob/main/sys/contrib/dev/acpica/components/parser/psscope.c
48524 views
/******************************************************************************1*2* Module Name: psscope - Parser scope stack management routines3*4*****************************************************************************/56/******************************************************************************7*8* 1. Copyright Notice9*10* Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.11* All rights reserved.12*13* 2. License14*15* 2.1. This is your license from Intel Corp. under its intellectual property16* rights. You may have additional license terms from the party that provided17* you this software, covering your right to use that party's intellectual18* property rights.19*20* 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a21* copy of the source code appearing in this file ("Covered Code") an22* irrevocable, perpetual, worldwide license under Intel's copyrights in the23* base code distributed originally by Intel ("Original Intel Code") to copy,24* make derivatives, distribute, use and display any portion of the Covered25* Code in any form, with the right to sublicense such rights; and26*27* 2.3. Intel grants Licensee a non-exclusive and non-transferable patent28* license (with the right to sublicense), under only those claims of Intel29* patents that are infringed by the Original Intel Code, to make, use, sell,30* offer to sell, and import the Covered Code and derivative works thereof31* solely to the minimum extent necessary to exercise the above copyright32* license, and in no event shall the patent license extend to any additions33* to or modifications of the Original Intel Code. No other license or right34* is granted directly or by implication, estoppel or otherwise;35*36* The above copyright and patent license is granted only if the following37* conditions are met:38*39* 3. Conditions40*41* 3.1. Redistribution of Source with Rights to Further Distribute Source.42* Redistribution of source code of any substantial portion of the Covered43* Code or modification with rights to further distribute source must include44* the above Copyright Notice, the above License, this list of Conditions,45* and the following Disclaimer and Export Compliance provision. In addition,46* Licensee must cause all Covered Code to which Licensee contributes to47* contain a file documenting the changes Licensee made to create that Covered48* Code and the date of any change. Licensee must include in that file the49* documentation of any changes made by any predecessor Licensee. Licensee50* must include a prominent statement that the modification is derived,51* directly or indirectly, from Original Intel Code.52*53* 3.2. Redistribution of Source with no Rights to Further Distribute Source.54* Redistribution of source code of any substantial portion of the Covered55* Code or modification without rights to further distribute source must56* include the following Disclaimer and Export Compliance provision in the57* documentation and/or other materials provided with distribution. In58* addition, Licensee may not authorize further sublicense of source of any59* portion of the Covered Code, and must include terms to the effect that the60* license from Licensee to its licensee is limited to the intellectual61* property embodied in the software Licensee provides to its licensee, and62* not to intellectual property embodied in modifications its licensee may63* make.64*65* 3.3. Redistribution of Executable. Redistribution in executable form of any66* substantial portion of the Covered Code or modification must reproduce the67* above Copyright Notice, and the following Disclaimer and Export Compliance68* provision in the documentation and/or other materials provided with the69* distribution.70*71* 3.4. Intel retains all right, title, and interest in and to the Original72* Intel Code.73*74* 3.5. Neither the name Intel nor any other trademark owned or controlled by75* Intel shall be used in advertising or otherwise to promote the sale, use or76* other dealings in products derived from or relating to the Covered Code77* without prior written authorization from Intel.78*79* 4. Disclaimer and Export Compliance80*81* 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED82* HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE83* IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,84* INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY85* UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY86* IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A87* PARTICULAR PURPOSE.88*89* 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES90* OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR91* COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,92* SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY93* CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL94* HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS95* SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY96* LIMITED REMEDY.97*98* 4.3. Licensee shall not export, either directly or indirectly, any of this99* software or system incorporating such software without first obtaining any100* required license or other approval from the U. S. Department of Commerce or101* any other agency or department of the United States Government. In the102* event Licensee exports any such software from the United States or103* re-exports any such software from a foreign destination, Licensee shall104* ensure that the distribution and export/re-export of the software is in105* compliance with all laws, regulations, orders, or other restrictions of the106* U.S. Export Administration Regulations. Licensee agrees that neither it nor107* any of its subsidiaries will export/re-export any technical data, process,108* software, or service, directly or indirectly, to any country for which the109* United States government or any agency thereof requires an export license,110* other governmental approval, or letter of assurance, without first obtaining111* such license, approval or letter.112*113*****************************************************************************114*115* Alternatively, you may choose to be licensed under the terms of the116* following license:117*118* Redistribution and use in source and binary forms, with or without119* modification, are permitted provided that the following conditions120* are met:121* 1. Redistributions of source code must retain the above copyright122* notice, this list of conditions, and the following disclaimer,123* without modification.124* 2. Redistributions in binary form must reproduce at minimum a disclaimer125* substantially similar to the "NO WARRANTY" disclaimer below126* ("Disclaimer") and any redistribution must be conditioned upon127* including a substantially similar Disclaimer requirement for further128* binary redistribution.129* 3. Neither the names of the above-listed copyright holders nor the names130* of any contributors may be used to endorse or promote products derived131* from this software without specific prior written permission.132*133* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS134* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT135* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR136* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT137* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,138* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT139* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,140* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY141* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT142* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE143* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.144*145* Alternatively, you may choose to be licensed under the terms of the146* GNU General Public License ("GPL") version 2 as published by the Free147* Software Foundation.148*149*****************************************************************************/150151#include <contrib/dev/acpica/include/acpi.h>152#include <contrib/dev/acpica/include/accommon.h>153#include <contrib/dev/acpica/include/acparser.h>154155#define _COMPONENT ACPI_PARSER156ACPI_MODULE_NAME ("psscope")157158159/*******************************************************************************160*161* FUNCTION: AcpiPsGetParentScope162*163* PARAMETERS: ParserState - Current parser state object164*165* RETURN: Pointer to an Op object166*167* DESCRIPTION: Get parent of current op being parsed168*169******************************************************************************/170171ACPI_PARSE_OBJECT *172AcpiPsGetParentScope (173ACPI_PARSE_STATE *ParserState)174{175176return (ParserState->Scope->ParseScope.Op);177}178179180/*******************************************************************************181*182* FUNCTION: AcpiPsHasCompletedScope183*184* PARAMETERS: ParserState - Current parser state object185*186* RETURN: Boolean, TRUE = scope completed.187*188* DESCRIPTION: Is parsing of current argument complete? Determined by189* 1) AML pointer is at or beyond the end of the scope190* 2) The scope argument count has reached zero.191*192******************************************************************************/193194BOOLEAN195AcpiPsHasCompletedScope (196ACPI_PARSE_STATE *ParserState)197{198199return ((BOOLEAN)200((ParserState->Aml >= ParserState->Scope->ParseScope.ArgEnd ||201!ParserState->Scope->ParseScope.ArgCount)));202}203204205/*******************************************************************************206*207* FUNCTION: AcpiPsInitScope208*209* PARAMETERS: ParserState - Current parser state object210* Root - the Root Node of this new scope211*212* RETURN: Status213*214* DESCRIPTION: Allocate and init a new scope object215*216******************************************************************************/217218ACPI_STATUS219AcpiPsInitScope (220ACPI_PARSE_STATE *ParserState,221ACPI_PARSE_OBJECT *RootOp)222{223ACPI_GENERIC_STATE *Scope;224225226ACPI_FUNCTION_TRACE_PTR (PsInitScope, RootOp);227228229Scope = AcpiUtCreateGenericState ();230if (!Scope)231{232return_ACPI_STATUS (AE_NO_MEMORY);233}234235Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RPSCOPE;236Scope->ParseScope.Op = RootOp;237Scope->ParseScope.ArgCount = ACPI_VAR_ARGS;238Scope->ParseScope.ArgEnd = ParserState->AmlEnd;239Scope->ParseScope.PkgEnd = ParserState->AmlEnd;240241ParserState->Scope = Scope;242ParserState->StartOp = RootOp;243244return_ACPI_STATUS (AE_OK);245}246247248/*******************************************************************************249*250* FUNCTION: AcpiPsPushScope251*252* PARAMETERS: ParserState - Current parser state object253* Op - Current op to be pushed254* RemainingArgs - List of args remaining255* ArgCount - Fixed or variable number of args256*257* RETURN: Status258*259* DESCRIPTION: Push current op to begin parsing its argument260*261******************************************************************************/262263ACPI_STATUS264AcpiPsPushScope (265ACPI_PARSE_STATE *ParserState,266ACPI_PARSE_OBJECT *Op,267UINT32 RemainingArgs,268UINT32 ArgCount)269{270ACPI_GENERIC_STATE *Scope;271272273ACPI_FUNCTION_TRACE_PTR (PsPushScope, Op);274275276Scope = AcpiUtCreateGenericState ();277if (!Scope)278{279return_ACPI_STATUS (AE_NO_MEMORY);280}281282Scope->Common.DescriptorType = ACPI_DESC_TYPE_STATE_PSCOPE;283Scope->ParseScope.Op = Op;284Scope->ParseScope.ArgList = RemainingArgs;285Scope->ParseScope.ArgCount = ArgCount;286Scope->ParseScope.PkgEnd = ParserState->PkgEnd;287288/* Push onto scope stack */289290AcpiUtPushGenericState (&ParserState->Scope, Scope);291292if (ArgCount == ACPI_VAR_ARGS)293{294/* Multiple arguments */295296Scope->ParseScope.ArgEnd = ParserState->PkgEnd;297}298else299{300/* Single argument */301302Scope->ParseScope.ArgEnd = ACPI_TO_POINTER (ACPI_MAX_PTR);303}304305return_ACPI_STATUS (AE_OK);306}307308309/*******************************************************************************310*311* FUNCTION: AcpiPsPopScope312*313* PARAMETERS: ParserState - Current parser state object314* Op - Where the popped op is returned315* ArgList - Where the popped "next argument" is316* returned317* ArgCount - Count of objects in ArgList318*319* RETURN: Status320*321* DESCRIPTION: Return to parsing a previous op322*323******************************************************************************/324325void326AcpiPsPopScope (327ACPI_PARSE_STATE *ParserState,328ACPI_PARSE_OBJECT **Op,329UINT32 *ArgList,330UINT32 *ArgCount)331{332ACPI_GENERIC_STATE *Scope = ParserState->Scope;333334335ACPI_FUNCTION_TRACE (PsPopScope);336337338/* Only pop the scope if there is in fact a next scope */339340if (Scope->Common.Next)341{342Scope = AcpiUtPopGenericState (&ParserState->Scope);343344/* Return to parsing previous op */345346*Op = Scope->ParseScope.Op;347*ArgList = Scope->ParseScope.ArgList;348*ArgCount = Scope->ParseScope.ArgCount;349ParserState->PkgEnd = Scope->ParseScope.PkgEnd;350351/* All done with this scope state structure */352353AcpiUtDeleteGenericState (Scope);354}355else356{357/* Empty parse stack, prepare to fetch next opcode */358359*Op = NULL;360*ArgList = 0;361*ArgCount = 0;362}363364ACPI_DEBUG_PRINT ((ACPI_DB_PARSE,365"Popped Op %p Args %X\n", *Op, *ArgCount));366return_VOID;367}368369370/*******************************************************************************371*372* FUNCTION: AcpiPsCleanupScope373*374* PARAMETERS: ParserState - Current parser state object375*376* RETURN: None377*378* DESCRIPTION: Destroy available list, remaining stack levels, and return379* root scope380*381******************************************************************************/382383void384AcpiPsCleanupScope (385ACPI_PARSE_STATE *ParserState)386{387ACPI_GENERIC_STATE *Scope;388389390ACPI_FUNCTION_TRACE_PTR (PsCleanupScope, ParserState);391392393if (!ParserState)394{395return_VOID;396}397398/* Delete anything on the scope stack */399400while (ParserState->Scope)401{402Scope = AcpiUtPopGenericState (&ParserState->Scope);403AcpiUtDeleteGenericState (Scope);404}405406return_VOID;407}408409410