Path: blob/main/sys/contrib/dev/acpica/components/dispatcher/dswstate.c
48521 views
/******************************************************************************1*2* Module Name: dswstate - Dispatcher parse tree walk 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>154#include <contrib/dev/acpica/include/acdispat.h>155#include <contrib/dev/acpica/include/acnamesp.h>156157#define _COMPONENT ACPI_DISPATCHER158ACPI_MODULE_NAME ("dswstate")159160/* Local prototypes */161162static ACPI_STATUS163AcpiDsResultStackPush (164ACPI_WALK_STATE *WalkState);165166static ACPI_STATUS167AcpiDsResultStackPop (168ACPI_WALK_STATE *WalkState);169170171/*******************************************************************************172*173* FUNCTION: AcpiDsResultPop174*175* PARAMETERS: Object - Where to return the popped object176* WalkState - Current Walk state177*178* RETURN: Status179*180* DESCRIPTION: Pop an object off the top of this walk's result stack181*182******************************************************************************/183184ACPI_STATUS185AcpiDsResultPop (186ACPI_OPERAND_OBJECT **Object,187ACPI_WALK_STATE *WalkState)188{189UINT32 Index;190ACPI_GENERIC_STATE *State;191ACPI_STATUS Status;192193194ACPI_FUNCTION_NAME (DsResultPop);195196197State = WalkState->Results;198199/* Incorrect state of result stack */200201if (State && !WalkState->ResultCount)202{203ACPI_ERROR ((AE_INFO, "No results on result stack"));204return (AE_AML_INTERNAL);205}206207if (!State && WalkState->ResultCount)208{209ACPI_ERROR ((AE_INFO, "No result state for result stack"));210return (AE_AML_INTERNAL);211}212213/* Empty result stack */214215if (!State)216{217ACPI_ERROR ((AE_INFO, "Result stack is empty! State=%p", WalkState));218return (AE_AML_NO_RETURN_VALUE);219}220221/* Return object of the top element and clean that top element result stack */222223WalkState->ResultCount--;224Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;225226*Object = State->Results.ObjDesc [Index];227if (!*Object)228{229ACPI_ERROR ((AE_INFO, "No result objects on result stack, State=%p",230WalkState));231return (AE_AML_NO_RETURN_VALUE);232}233234State->Results.ObjDesc [Index] = NULL;235if (Index == 0)236{237Status = AcpiDsResultStackPop (WalkState);238if (ACPI_FAILURE (Status))239{240return (Status);241}242}243244ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,245"Obj=%p [%s] Index=%X State=%p Num=%X\n", *Object,246AcpiUtGetObjectTypeName (*Object),247Index, WalkState, WalkState->ResultCount));248249return (AE_OK);250}251252253/*******************************************************************************254*255* FUNCTION: AcpiDsResultPush256*257* PARAMETERS: Object - Where to return the popped object258* WalkState - Current Walk state259*260* RETURN: Status261*262* DESCRIPTION: Push an object onto the current result stack263*264******************************************************************************/265266ACPI_STATUS267AcpiDsResultPush (268ACPI_OPERAND_OBJECT *Object,269ACPI_WALK_STATE *WalkState)270{271ACPI_GENERIC_STATE *State;272ACPI_STATUS Status;273UINT32 Index;274275276ACPI_FUNCTION_NAME (DsResultPush);277278279if (WalkState->ResultCount > WalkState->ResultSize)280{281ACPI_ERROR ((AE_INFO, "Result stack is full"));282return (AE_AML_INTERNAL);283}284else if (WalkState->ResultCount == WalkState->ResultSize)285{286/* Extend the result stack */287288Status = AcpiDsResultStackPush (WalkState);289if (ACPI_FAILURE (Status))290{291ACPI_ERROR ((AE_INFO, "Failed to extend the result stack"));292return (Status);293}294}295296if (!(WalkState->ResultCount < WalkState->ResultSize))297{298ACPI_ERROR ((AE_INFO, "No free elements in result stack"));299return (AE_AML_INTERNAL);300}301302State = WalkState->Results;303if (!State)304{305ACPI_ERROR ((AE_INFO, "No result stack frame during push"));306return (AE_AML_INTERNAL);307}308309if (!Object)310{311ACPI_ERROR ((AE_INFO,312"Null Object! State=%p Num=%u",313WalkState, WalkState->ResultCount));314return (AE_BAD_PARAMETER);315}316317/* Assign the address of object to the top free element of result stack */318319Index = (UINT32) WalkState->ResultCount % ACPI_RESULTS_FRAME_OBJ_NUM;320State->Results.ObjDesc [Index] = Object;321WalkState->ResultCount++;322323ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p Num=%X Cur=%X\n",324Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),325WalkState, WalkState->ResultCount, WalkState->CurrentResult));326327return (AE_OK);328}329330331/*******************************************************************************332*333* FUNCTION: AcpiDsResultStackPush334*335* PARAMETERS: WalkState - Current Walk state336*337* RETURN: Status338*339* DESCRIPTION: Push an object onto the WalkState result stack340*341******************************************************************************/342343static ACPI_STATUS344AcpiDsResultStackPush (345ACPI_WALK_STATE *WalkState)346{347ACPI_GENERIC_STATE *State;348349350ACPI_FUNCTION_NAME (DsResultStackPush);351352353/* Check for stack overflow */354355if (((UINT32) WalkState->ResultSize + ACPI_RESULTS_FRAME_OBJ_NUM) >356ACPI_RESULTS_OBJ_NUM_MAX)357{358ACPI_ERROR ((AE_INFO, "Result stack overflow: State=%p Num=%u",359WalkState, WalkState->ResultSize));360return (AE_STACK_OVERFLOW);361}362363State = AcpiUtCreateGenericState ();364if (!State)365{366return (AE_NO_MEMORY);367}368369State->Common.DescriptorType = ACPI_DESC_TYPE_STATE_RESULT;370AcpiUtPushGenericState (&WalkState->Results, State);371372/* Increase the length of the result stack by the length of frame */373374WalkState->ResultSize += ACPI_RESULTS_FRAME_OBJ_NUM;375376ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Results=%p State=%p\n",377State, WalkState));378379return (AE_OK);380}381382383/*******************************************************************************384*385* FUNCTION: AcpiDsResultStackPop386*387* PARAMETERS: WalkState - Current Walk state388*389* RETURN: Status390*391* DESCRIPTION: Pop an object off of the WalkState result stack392*393******************************************************************************/394395static ACPI_STATUS396AcpiDsResultStackPop (397ACPI_WALK_STATE *WalkState)398{399ACPI_GENERIC_STATE *State;400401402ACPI_FUNCTION_NAME (DsResultStackPop);403404405/* Check for stack underflow */406407if (WalkState->Results == NULL)408{409ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,410"Result stack underflow - State=%p\n", WalkState));411return (AE_AML_NO_OPERAND);412}413414if (WalkState->ResultSize < ACPI_RESULTS_FRAME_OBJ_NUM)415{416ACPI_ERROR ((AE_INFO, "Insufficient result stack size"));417return (AE_AML_INTERNAL);418}419420State = AcpiUtPopGenericState (&WalkState->Results);421AcpiUtDeleteGenericState (State);422423/* Decrease the length of result stack by the length of frame */424425WalkState->ResultSize -= ACPI_RESULTS_FRAME_OBJ_NUM;426427ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,428"Result=%p RemainingResults=%X State=%p\n",429State, WalkState->ResultCount, WalkState));430431return (AE_OK);432}433434435/*******************************************************************************436*437* FUNCTION: AcpiDsObjStackPush438*439* PARAMETERS: Object - Object to push440* WalkState - Current Walk state441*442* RETURN: Status443*444* DESCRIPTION: Push an object onto this walk's object/operand stack445*446******************************************************************************/447448ACPI_STATUS449AcpiDsObjStackPush (450void *Object,451ACPI_WALK_STATE *WalkState)452{453ACPI_FUNCTION_NAME (DsObjStackPush);454455456/* Check for stack overflow */457458if (WalkState->NumOperands >= ACPI_OBJ_NUM_OPERANDS)459{460ACPI_ERROR ((AE_INFO,461"Object stack overflow! Obj=%p State=%p #Ops=%u",462Object, WalkState, WalkState->NumOperands));463return (AE_STACK_OVERFLOW);464}465466/* Put the object onto the stack */467468WalkState->Operands [WalkState->OperandIndex] = Object;469WalkState->NumOperands++;470471/* For the usual order of filling the operand stack */472473WalkState->OperandIndex++;474475ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p [%s] State=%p #Ops=%X\n",476Object, AcpiUtGetObjectTypeName ((ACPI_OPERAND_OBJECT *) Object),477WalkState, WalkState->NumOperands));478479return (AE_OK);480}481482483/*******************************************************************************484*485* FUNCTION: AcpiDsObjStackPop486*487* PARAMETERS: PopCount - Number of objects/entries to pop488* WalkState - Current Walk state489*490* RETURN: Status491*492* DESCRIPTION: Pop this walk's object stack. Objects on the stack are NOT493* deleted by this routine.494*495******************************************************************************/496497ACPI_STATUS498AcpiDsObjStackPop (499UINT32 PopCount,500ACPI_WALK_STATE *WalkState)501{502UINT32 i;503504505ACPI_FUNCTION_NAME (DsObjStackPop);506507508for (i = 0; i < PopCount; i++)509{510/* Check for stack underflow */511512if (WalkState->NumOperands == 0)513{514ACPI_ERROR ((AE_INFO,515"Object stack underflow! Count=%X State=%p #Ops=%u",516PopCount, WalkState, WalkState->NumOperands));517return (AE_STACK_UNDERFLOW);518}519520/* Just set the stack entry to null */521522WalkState->NumOperands--;523WalkState->Operands [WalkState->NumOperands] = NULL;524}525526ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%u\n",527PopCount, WalkState, WalkState->NumOperands));528529return (AE_OK);530}531532533/*******************************************************************************534*535* FUNCTION: AcpiDsObjStackPopAndDelete536*537* PARAMETERS: PopCount - Number of objects/entries to pop538* WalkState - Current Walk state539*540* RETURN: Status541*542* DESCRIPTION: Pop this walk's object stack and delete each object that is543* popped off.544*545******************************************************************************/546547void548AcpiDsObjStackPopAndDelete (549UINT32 PopCount,550ACPI_WALK_STATE *WalkState)551{552INT32 i;553ACPI_OPERAND_OBJECT *ObjDesc;554555556ACPI_FUNCTION_NAME (DsObjStackPopAndDelete);557558559if (PopCount == 0)560{561return;562}563564for (i = (INT32) PopCount - 1; i >= 0; i--)565{566if (WalkState->NumOperands == 0)567{568return;569}570571/* Pop the stack and delete an object if present in this stack entry */572573WalkState->NumOperands--;574ObjDesc = WalkState->Operands [i];575if (ObjDesc)576{577AcpiUtRemoveReference (WalkState->Operands [i]);578WalkState->Operands [i] = NULL;579}580}581582ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Count=%X State=%p #Ops=%X\n",583PopCount, WalkState, WalkState->NumOperands));584}585586587/*******************************************************************************588*589* FUNCTION: AcpiDsGetCurrentWalkState590*591* PARAMETERS: Thread - Get current active state for this Thread592*593* RETURN: Pointer to the current walk state594*595* DESCRIPTION: Get the walk state that is at the head of the list (the "current"596* walk state.)597*598******************************************************************************/599600ACPI_WALK_STATE *601AcpiDsGetCurrentWalkState (602ACPI_THREAD_STATE *Thread)603{604ACPI_FUNCTION_NAME (DsGetCurrentWalkState);605606607if (!Thread)608{609return (NULL);610}611612ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Current WalkState %p\n",613Thread->WalkStateList));614615return (Thread->WalkStateList);616}617618619/*******************************************************************************620*621* FUNCTION: AcpiDsPushWalkState622*623* PARAMETERS: WalkState - State to push624* Thread - Thread state object625*626* RETURN: None627*628* DESCRIPTION: Place the Thread state at the head of the state list629*630******************************************************************************/631632void633AcpiDsPushWalkState (634ACPI_WALK_STATE *WalkState,635ACPI_THREAD_STATE *Thread)636{637ACPI_FUNCTION_TRACE (DsPushWalkState);638639640WalkState->Next = Thread->WalkStateList;641Thread->WalkStateList = WalkState;642643return_VOID;644}645646647/*******************************************************************************648*649* FUNCTION: AcpiDsPopWalkState650*651* PARAMETERS: Thread - Current thread state652*653* RETURN: A WalkState object popped from the thread's stack654*655* DESCRIPTION: Remove and return the walkstate object that is at the head of656* the walk stack for the given walk list. NULL indicates that657* the list is empty.658*659******************************************************************************/660661ACPI_WALK_STATE *662AcpiDsPopWalkState (663ACPI_THREAD_STATE *Thread)664{665ACPI_WALK_STATE *WalkState;666667668ACPI_FUNCTION_TRACE (DsPopWalkState);669670671WalkState = Thread->WalkStateList;672673if (WalkState)674{675/* Next walk state becomes the current walk state */676677Thread->WalkStateList = WalkState->Next;678679/*680* Don't clear the NEXT field, this serves as an indicator681* that there is a parent WALK STATE682* Do Not: WalkState->Next = NULL;683*/684}685686return_PTR (WalkState);687}688689690/*******************************************************************************691*692* FUNCTION: AcpiDsCreateWalkState693*694* PARAMETERS: OwnerId - ID for object creation695* Origin - Starting point for this walk696* MethodDesc - Method object697* Thread - Current thread state698*699* RETURN: Pointer to the new walk state.700*701* DESCRIPTION: Allocate and initialize a new walk state. The current walk702* state is set to this new state.703*704******************************************************************************/705706ACPI_WALK_STATE *707AcpiDsCreateWalkState (708ACPI_OWNER_ID OwnerId,709ACPI_PARSE_OBJECT *Origin,710ACPI_OPERAND_OBJECT *MethodDesc,711ACPI_THREAD_STATE *Thread)712{713ACPI_WALK_STATE *WalkState;714715716ACPI_FUNCTION_TRACE (DsCreateWalkState);717718719WalkState = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_WALK_STATE));720if (!WalkState)721{722return_PTR (NULL);723}724725WalkState->DescriptorType = ACPI_DESC_TYPE_WALK;726WalkState->MethodDesc = MethodDesc;727WalkState->OwnerId = OwnerId;728WalkState->Origin = Origin;729WalkState->Thread = Thread;730731WalkState->ParserState.StartOp = Origin;732733/* Init the method args/local */734735#ifndef ACPI_CONSTANT_EVAL_ONLY736AcpiDsMethodDataInit (WalkState);737#endif738739/* Put the new state at the head of the walk list */740741if (Thread)742{743AcpiDsPushWalkState (WalkState, Thread);744}745746return_PTR (WalkState);747}748749750/*******************************************************************************751*752* FUNCTION: AcpiDsInitAmlWalk753*754* PARAMETERS: WalkState - New state to be initialized755* Op - Current parse op756* MethodNode - Control method NS node, if any757* AmlStart - Start of AML758* AmlLength - Length of AML759* Info - Method info block (params, etc.)760* PassNumber - 1, 2, or 3761*762* RETURN: Status763*764* DESCRIPTION: Initialize a walk state for a pass 1 or 2 parse tree walk765*766******************************************************************************/767768ACPI_STATUS769AcpiDsInitAmlWalk (770ACPI_WALK_STATE *WalkState,771ACPI_PARSE_OBJECT *Op,772ACPI_NAMESPACE_NODE *MethodNode,773UINT8 *AmlStart,774UINT32 AmlLength,775ACPI_EVALUATE_INFO *Info,776UINT8 PassNumber)777{778ACPI_STATUS Status;779ACPI_PARSE_STATE *ParserState = &WalkState->ParserState;780ACPI_PARSE_OBJECT *ExtraOp;781782783ACPI_FUNCTION_TRACE (DsInitAmlWalk);784785786WalkState->ParserState.Aml =787WalkState->ParserState.AmlStart =788WalkState->ParserState.AmlEnd =789WalkState->ParserState.PkgEnd = AmlStart;790/* Avoid undefined behavior: applying zero offset to null pointer */791if (AmlLength != 0) {792WalkState->ParserState.AmlEnd += AmlLength;793WalkState->ParserState.PkgEnd += AmlLength;794}795796/* The NextOp of the NextWalk will be the beginning of the method */797798WalkState->NextOp = NULL;799WalkState->PassNumber = PassNumber;800801if (Info)802{803WalkState->Params = Info->Parameters;804WalkState->CallerReturnDesc = &Info->ReturnObject;805}806807Status = AcpiPsInitScope (&WalkState->ParserState, Op);808if (ACPI_FAILURE (Status))809{810return_ACPI_STATUS (Status);811}812813if (MethodNode)814{815WalkState->ParserState.StartNode = MethodNode;816WalkState->WalkType = ACPI_WALK_METHOD;817WalkState->MethodNode = MethodNode;818WalkState->MethodDesc = AcpiNsGetAttachedObject (MethodNode);819820/* Push start scope on scope stack and make it current */821822Status = AcpiDsScopeStackPush (823MethodNode, ACPI_TYPE_METHOD, WalkState);824if (ACPI_FAILURE (Status))825{826return_ACPI_STATUS (Status);827}828829/* Init the method arguments */830831Status = AcpiDsMethodDataInitArgs (WalkState->Params,832ACPI_METHOD_NUM_ARGS, WalkState);833if (ACPI_FAILURE (Status))834{835return_ACPI_STATUS (Status);836}837}838else839{840/*841* Setup the current scope.842* Find a Named Op that has a namespace node associated with it.843* search upwards from this Op. Current scope is the first844* Op with a namespace node.845*/846ExtraOp = ParserState->StartOp;847while (ExtraOp && !ExtraOp->Common.Node)848{849ExtraOp = ExtraOp->Common.Parent;850}851852if (!ExtraOp)853{854ParserState->StartNode = NULL;855}856else857{858ParserState->StartNode = ExtraOp->Common.Node;859}860861if (ParserState->StartNode)862{863/* Push start scope on scope stack and make it current */864865Status = AcpiDsScopeStackPush (ParserState->StartNode,866ParserState->StartNode->Type, WalkState);867if (ACPI_FAILURE (Status))868{869return_ACPI_STATUS (Status);870}871}872}873874Status = AcpiDsInitCallbacks (WalkState, PassNumber);875return_ACPI_STATUS (Status);876}877878879/*******************************************************************************880*881* FUNCTION: AcpiDsDeleteWalkState882*883* PARAMETERS: WalkState - State to delete884*885* RETURN: Status886*887* DESCRIPTION: Delete a walk state including all internal data structures888*889******************************************************************************/890891void892AcpiDsDeleteWalkState (893ACPI_WALK_STATE *WalkState)894{895ACPI_GENERIC_STATE *State;896897898ACPI_FUNCTION_TRACE_PTR (DsDeleteWalkState, WalkState);899900901if (!WalkState)902{903return_VOID;904}905906if (WalkState->DescriptorType != ACPI_DESC_TYPE_WALK)907{908ACPI_ERROR ((AE_INFO, "%p is not a valid walk state",909WalkState));910return_VOID;911}912913/* There should not be any open scopes */914915if (WalkState->ParserState.Scope)916{917ACPI_ERROR ((AE_INFO, "%p walk still has a scope list",918WalkState));919AcpiPsCleanupScope (&WalkState->ParserState);920}921922/* Always must free any linked control states */923924while (WalkState->ControlState)925{926State = WalkState->ControlState;927WalkState->ControlState = State->Common.Next;928929AcpiUtDeleteGenericState (State);930}931932/* Always must free any linked parse states */933934while (WalkState->ScopeInfo)935{936State = WalkState->ScopeInfo;937WalkState->ScopeInfo = State->Common.Next;938939AcpiUtDeleteGenericState (State);940}941942/* Always must free any stacked result states */943944while (WalkState->Results)945{946State = WalkState->Results;947WalkState->Results = State->Common.Next;948949AcpiUtDeleteGenericState (State);950}951952ACPI_FREE (WalkState);953return_VOID;954}955956957