Path: blob/main/sys/contrib/dev/acpica/common/adwalk.c
48375 views
/******************************************************************************1*2* Module Name: adwalk - Application-level disassembler parse tree walk 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/amlcode.h>155#include <contrib/dev/acpica/include/acdisasm.h>156#include <contrib/dev/acpica/include/acdispat.h>157#include <contrib/dev/acpica/include/acnamesp.h>158#include <contrib/dev/acpica/include/acapps.h>159160161#define _COMPONENT ACPI_TOOLS162ACPI_MODULE_NAME ("adwalk")163164/*165* aslmap - opcode mappings and reserved method names166*/167ACPI_OBJECT_TYPE168AslMapNamedOpcodeToDataType (169UINT16 Opcode);170171/* Local prototypes */172173static ACPI_STATUS174AcpiDmFindOrphanDescending (175ACPI_PARSE_OBJECT *Op,176UINT32 Level,177void *Context);178179static ACPI_STATUS180AcpiDmDumpDescending (181ACPI_PARSE_OBJECT *Op,182UINT32 Level,183void *Context);184185static ACPI_STATUS186AcpiDmXrefDescendingOp (187ACPI_PARSE_OBJECT *Op,188UINT32 Level,189void *Context);190191static ACPI_STATUS192AcpiDmCommonAscendingOp (193ACPI_PARSE_OBJECT *Op,194UINT32 Level,195void *Context);196197static ACPI_STATUS198AcpiDmLoadDescendingOp (199ACPI_PARSE_OBJECT *Op,200UINT32 Level,201void *Context);202203static UINT32204AcpiDmInspectPossibleArgs (205UINT32 CurrentOpArgCount,206UINT32 TargetCount,207ACPI_PARSE_OBJECT *Op);208209static ACPI_STATUS210AcpiDmCommonDescendingOp (211ACPI_PARSE_OBJECT *Op,212UINT32 Level,213void *Context);214215static ACPI_STATUS216AcpiDmProcessResourceDescriptors (217ACPI_PARSE_OBJECT *Op,218UINT32 Level,219void *Context);220221/*******************************************************************************222*223* FUNCTION: AcpiDmDumpTree224*225* PARAMETERS: Origin - Starting object226*227* RETURN: None228*229* DESCRIPTION: Parse tree walk to format and output the nodes230*231******************************************************************************/232233void234AcpiDmDumpTree (235ACPI_PARSE_OBJECT *Origin)236{237ACPI_OP_WALK_INFO Info;238239240if (!Origin)241{242return;243}244245AcpiOsPrintf ("/*\nAML Parse Tree\n\n");246Info.Flags = 0;247Info.Count = 0;248Info.Level = 0;249Info.WalkState = NULL;250251AcpiDmWalkParseTree (Origin, AcpiDmDumpDescending, NULL, &Info);252AcpiOsPrintf ("*/\n\n");253}254255256/*******************************************************************************257*258* FUNCTION: AcpiDmFindOrphanMethods259*260* PARAMETERS: Origin - Starting object261*262* RETURN: None263*264* DESCRIPTION: Parse tree walk to find "orphaned" method invocations -- methods265* that are not resolved in the namespace266*267******************************************************************************/268269void270AcpiDmFindOrphanMethods (271ACPI_PARSE_OBJECT *Origin)272{273ACPI_OP_WALK_INFO Info;274275276if (!Origin)277{278return;279}280281Info.Flags = 0;282Info.Level = 0;283Info.WalkState = NULL;284285AcpiDmWalkParseTree (Origin, AcpiDmFindOrphanDescending, NULL, &Info);286}287288289/*******************************************************************************290*291* FUNCTION: AcpiDmFinishNamespaceLoad292*293* PARAMETERS: ParseTreeRoot - Root of the parse tree294* NamespaceRoot - Root of the internal namespace295* OwnerId - OwnerId of the table to be disassembled296*297* RETURN: None298*299* DESCRIPTION: Load all namespace items that are created within control300* methods. Used before namespace cross reference301*302******************************************************************************/303304void305AcpiDmFinishNamespaceLoad (306ACPI_PARSE_OBJECT *ParseTreeRoot,307ACPI_NAMESPACE_NODE *NamespaceRoot,308ACPI_OWNER_ID OwnerId)309{310ACPI_STATUS Status;311ACPI_OP_WALK_INFO Info;312ACPI_WALK_STATE *WalkState;313314315if (!ParseTreeRoot)316{317return;318}319320/* Create and initialize a new walk state */321322WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);323if (!WalkState)324{325return;326}327328Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,329WalkState);330if (ACPI_FAILURE (Status))331{332return;333}334335Info.Flags = 0;336Info.Level = 0;337Info.WalkState = WalkState;338339AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmLoadDescendingOp,340AcpiDmCommonAscendingOp, &Info);341ACPI_FREE (WalkState);342}343344345/*******************************************************************************346*347* FUNCTION: AcpiDmCrossReferenceNamespace348*349* PARAMETERS: ParseTreeRoot - Root of the parse tree350* NamespaceRoot - Root of the internal namespace351* OwnerId - OwnerId of the table to be disassembled352*353* RETURN: None354*355* DESCRIPTION: Cross reference the namespace to create externals356*357******************************************************************************/358359void360AcpiDmCrossReferenceNamespace (361ACPI_PARSE_OBJECT *ParseTreeRoot,362ACPI_NAMESPACE_NODE *NamespaceRoot,363ACPI_OWNER_ID OwnerId)364{365ACPI_STATUS Status;366ACPI_OP_WALK_INFO Info;367ACPI_WALK_STATE *WalkState;368369370if (!ParseTreeRoot)371{372return;373}374375/* Create and initialize a new walk state */376377WalkState = AcpiDsCreateWalkState (OwnerId, ParseTreeRoot, NULL, NULL);378if (!WalkState)379{380return;381}382383Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,384WalkState);385if (ACPI_FAILURE (Status))386{387return;388}389390Info.Flags = 0;391Info.Level = 0;392Info.WalkState = WalkState;393394AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmXrefDescendingOp,395AcpiDmCommonAscendingOp, &Info);396ACPI_FREE (WalkState);397}398399400/*******************************************************************************401*402* FUNCTION: AcpiDmConvertParseObjects403*404* PARAMETERS: ParseTreeRoot - Root of the parse tree405* NamespaceRoot - Root of the internal namespace406*407* RETURN: None408*409* DESCRIPTION: Begin parse tree walk to perform conversions needed for410* disassembly. These include resource descriptors and switch/case411* operations.412*413******************************************************************************/414415void416AcpiDmConvertParseObjects (417ACPI_PARSE_OBJECT *ParseTreeRoot,418ACPI_NAMESPACE_NODE *NamespaceRoot)419{420ACPI_STATUS Status;421ACPI_OP_WALK_INFO Info;422ACPI_WALK_STATE *WalkState;423424425if (!ParseTreeRoot)426{427return;428}429430/* Create and initialize a new walk state */431432WalkState = AcpiDsCreateWalkState (0, ParseTreeRoot, NULL, NULL);433if (!WalkState)434{435return;436}437438Status = AcpiDsScopeStackPush (NamespaceRoot, NamespaceRoot->Type,439WalkState);440if (ACPI_FAILURE (Status))441{442ACPI_FREE (WalkState);443return;444}445446Info.Flags = 0;447Info.Level = 0;448Info.WalkState = WalkState;449450AcpiDmWalkParseTree (ParseTreeRoot, AcpiDmCommonDescendingOp,451AcpiDmCommonAscendingOp, &Info);452ACPI_FREE (WalkState);453454if (AcpiGbl_TempListHead) {455AcpiDmClearTempList();456}457458return;459}460461462/*******************************************************************************463*464* FUNCTION: AcpiDmDumpDescending465*466* PARAMETERS: ASL_WALK_CALLBACK467*468* RETURN: Status469*470* DESCRIPTION: Format and print contents of one parse Op.471*472******************************************************************************/473474static ACPI_STATUS475AcpiDmDumpDescending (476ACPI_PARSE_OBJECT *Op,477UINT32 Level,478void *Context)479{480ACPI_OP_WALK_INFO *Info = Context;481char *Path;482ACPI_STATUS Status;483484485if (!Op)486{487return (AE_OK);488}489490/* Most of the information (count, level, name) here */491492Info->Count++;493AcpiOsPrintf ("% 5d [%2.2d] ", Info->Count, Level);494AcpiDmIndent (Level);495AcpiOsPrintf ("%-28s", AcpiPsGetOpcodeName (Op->Common.AmlOpcode));496497/* Extra info is helpful */498499switch (Op->Common.AmlOpcode)500{501case AML_BYTE_OP:502503AcpiOsPrintf ("%2.2X", (UINT32) Op->Common.Value.Integer);504break;505506case AML_WORD_OP:507508AcpiOsPrintf ("%4.4X", (UINT32) Op->Common.Value.Integer);509break;510511case AML_DWORD_OP:512513AcpiOsPrintf ("%8.8X", (UINT32) Op->Common.Value.Integer);514break;515516case AML_QWORD_OP:517518AcpiOsPrintf ("%8.8X%8.8X", ACPI_FORMAT_UINT64 (Op->Common.Value.Integer));519break;520521case AML_INT_NAMEPATH_OP:522523if (Op->Common.Value.String)524{525Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, Op->Common.Value.String,526NULL, &Path);527if (ACPI_SUCCESS (Status))528{529AcpiOsPrintf ("%s %p", Path, Op->Common.Node);530ACPI_FREE (Path);531}532else533{534AcpiOsPrintf ("Could not externalize pathname for node [%4.4s]",535Op->Common.Node->Name.Ascii);536}537}538else539{540AcpiOsPrintf ("[NULL]");541}542break;543544case AML_NAME_OP:545case AML_METHOD_OP:546case AML_DEVICE_OP:547548AcpiOsPrintf ("%4.4s",549ACPI_CAST_PTR (char, &Op->Named.Name));550break;551552case AML_INT_NAMEDFIELD_OP:553554AcpiOsPrintf ("%4.4s Length: (bits) %8.8X%8.8X (bytes) %8.8X%8.8X",555ACPI_CAST_PTR (char, &Op->Named.Name),556ACPI_FORMAT_UINT64 (Op->Common.Value.Integer),557ACPI_FORMAT_UINT64 (Op->Common.Value.Integer / 8));558break;559560561default:562563break;564}565566AcpiOsPrintf ("\n");567return (AE_OK);568}569570571/*******************************************************************************572*573* FUNCTION: AcpiDmFindOrphanDescending574*575* PARAMETERS: ASL_WALK_CALLBACK576*577* RETURN: Status578*579* DESCRIPTION: Check namepath Ops for orphaned method invocations580*581* Note: Parts of this are experimental, under possible further development.582*583******************************************************************************/584585static ACPI_STATUS586AcpiDmFindOrphanDescending (587ACPI_PARSE_OBJECT *Op,588UINT32 Level,589void *Context)590{591const ACPI_OPCODE_INFO *OpInfo;592ACPI_PARSE_OBJECT *ChildOp;593ACPI_PARSE_OBJECT *NextOp;594ACPI_PARSE_OBJECT *ParentOp;595UINT32 ArgCount;596597598if (!Op)599{600return (AE_OK);601}602603#ifdef ACPI_UNDER_DEVELOPMENT604OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);605#endif606607switch (Op->Common.AmlOpcode)608{609#ifdef ACPI_UNDER_DEVELOPMENT610case AML_ADD_OP:611612ChildOp = Op->Common.Value.Arg;613if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&614!ChildOp->Common.Node)615{616AcpiNsExternalizeName (ACPI_UINT32_MAX, ChildOp->Common.Value.String,617NULL, &Path);618AcpiOsPrintf ("/* %-16s A-NAMEPATH: %s */\n",619Op->Common.AmlOpName, Path);620ACPI_FREE (Path);621622NextOp = Op->Common.Next;623if (!NextOp)624{625/* This NamePath has no args, assume it is an integer */626627AcpiDmAddOpToExternalList (ChildOp,628ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);629return (AE_OK);630}631632ArgCount = AcpiDmInspectPossibleArgs (3, 1, NextOp);633AcpiOsPrintf ("/* A-CHILDREN: %u Actual %u */\n",634ArgCount, AcpiDmCountChildren (Op));635636if (ArgCount < 1)637{638/* One Arg means this is just a Store(Name,Target) */639640AcpiDmAddOpToExternalList (ChildOp,641ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);642return (AE_OK);643}644645AcpiDmAddOpToExternalList (ChildOp,646ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);647}648break;649650#endif651652case AML_STORE_OP:653654ChildOp = Op->Common.Value.Arg;655if ((ChildOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&656!ChildOp->Common.Node)657{658NextOp = Op->Common.Next;659if (!NextOp)660{661/* This NamePath has no args, assume it is an integer */662663AcpiDmAddOpToExternalList (ChildOp,664ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);665return (AE_OK);666}667668ArgCount = AcpiDmInspectPossibleArgs (2, 1, NextOp);669if (ArgCount <= 1)670{671/* One Arg means this is just a Store(Name,Target) */672673AcpiDmAddOpToExternalList (ChildOp,674ChildOp->Common.Value.String, ACPI_TYPE_INTEGER, ArgCount, 0);675return (AE_OK);676}677678AcpiDmAddOpToExternalList (ChildOp,679ChildOp->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);680}681break;682683case AML_INT_NAMEPATH_OP:684685/* Must examine parent to see if this namepath is an argument */686687ParentOp = Op->Common.Parent;688OpInfo = AcpiPsGetOpcodeInfo (ParentOp->Common.AmlOpcode);689690if ((OpInfo->Class != AML_CLASS_EXECUTE) &&691(OpInfo->Class != AML_CLASS_CREATE) &&692(OpInfo->ObjectType != ACPI_TYPE_LOCAL_ALIAS) &&693(ParentOp->Common.AmlOpcode != AML_INT_METHODCALL_OP) &&694!Op->Common.Node)695{696ArgCount = AcpiDmInspectPossibleArgs (0, 0, Op);697698/*699* Check if namepath is a predicate for if/while or lone parameter to700* a return.701*/702if (ArgCount == 0)703{704if (((ParentOp->Common.AmlOpcode == AML_IF_OP) ||705(ParentOp->Common.AmlOpcode == AML_WHILE_OP) ||706(ParentOp->Common.AmlOpcode == AML_RETURN_OP)) &&707708/* And namepath is the first argument */709(ParentOp->Common.Value.Arg == Op))710{711AcpiDmAddOpToExternalList (Op,712Op->Common.Value.String, ACPI_TYPE_INTEGER, 0, 0);713break;714}715}716717/*718* This is a standalone namestring (not a parameter to another719* operator) - it *must* be a method invocation, nothing else is720* grammatically possible.721*/722AcpiDmAddOpToExternalList (Op,723Op->Common.Value.String, ACPI_TYPE_METHOD, ArgCount, 0);724}725break;726727default:728729break;730}731732return (AE_OK);733}734735736/*******************************************************************************737*738* FUNCTION: AcpiDmLoadDescendingOp739*740* PARAMETERS: ASL_WALK_CALLBACK741*742* RETURN: Status743*744* DESCRIPTION: Descending handler for namespace control method object load745*746******************************************************************************/747748static ACPI_STATUS749AcpiDmLoadDescendingOp (750ACPI_PARSE_OBJECT *Op,751UINT32 Level,752void *Context)753{754ACPI_OP_WALK_INFO *Info = Context;755const ACPI_OPCODE_INFO *OpInfo;756ACPI_WALK_STATE *WalkState;757ACPI_OBJECT_TYPE ObjectType;758ACPI_STATUS Status;759char *Path = NULL;760ACPI_PARSE_OBJECT *NextOp;761ACPI_NAMESPACE_NODE *Node;762char FieldPath[5];763BOOLEAN PreDefined = FALSE;764UINT8 PreDefineIndex = 0;765766767WalkState = Info->WalkState;768OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);769ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);770771/* Only interested in operators that create new names */772773if (!(OpInfo->Flags & AML_NAMED) &&774!(OpInfo->Flags & AML_CREATE))775{776goto Exit;777}778779/* Get the NamePath from the appropriate place */780781if (OpInfo->Flags & AML_NAMED)782{783/* For all named operators, get the new name */784785Path = Op->Named.Path;786787if (!Path && Op->Common.AmlOpcode == AML_INT_NAMEDFIELD_OP)788{789*ACPI_CAST_PTR (UINT32, &FieldPath[0]) = Op->Named.Name;790FieldPath[4] = 0;791Path = FieldPath;792}793}794else if (OpInfo->Flags & AML_CREATE)795{796/* New name is the last child */797798NextOp = Op->Common.Value.Arg;799800while (NextOp->Common.Next)801{802NextOp = NextOp->Common.Next;803}804805Path = NextOp->Common.Value.String;806}807808if (!Path)809{810goto Exit;811}812813/* Insert the name into the namespace */814815Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,816ACPI_IMODE_LOAD_PASS2, ACPI_NS_DONT_OPEN_SCOPE,817WalkState, &Node);818819Op->Common.Node = Node;820821if (ACPI_SUCCESS (Status))822{823/* Check if it's a predefined node */824825while (AcpiGbl_PreDefinedNames[PreDefineIndex].Name)826{827if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii,828AcpiGbl_PreDefinedNames[PreDefineIndex].Name))829{830PreDefined = TRUE;831break;832}833834PreDefineIndex++;835}836837/*838* Set node owner id if it satisfies all the following conditions:839* 1) Not a predefined node, _SB_ etc840* 2) Not the root node841* 3) Not a node created by Scope842*/843if (!PreDefined &&844(Node != AcpiGbl_RootNode) &&845(Op->Common.AmlOpcode != AML_SCOPE_OP))846{847Node->OwnerId = WalkState->OwnerId;848}849}850851852Exit:853854if (AcpiNsOpensScope (ObjectType))855{856if (Op->Common.Node)857{858Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,859WalkState);860if (ACPI_FAILURE (Status))861{862return (Status);863}864}865}866867return (AE_OK);868}869870871/*******************************************************************************872*873* FUNCTION: AcpiDmXrefDescendingOp874*875* PARAMETERS: ASL_WALK_CALLBACK876*877* RETURN: Status878*879* DESCRIPTION: Descending handler for namespace cross reference880*881******************************************************************************/882883static ACPI_STATUS884AcpiDmXrefDescendingOp (885ACPI_PARSE_OBJECT *Op,886UINT32 Level,887void *Context)888{889ACPI_OP_WALK_INFO *Info = Context;890const ACPI_OPCODE_INFO *OpInfo;891ACPI_WALK_STATE *WalkState;892ACPI_OBJECT_TYPE ObjectType;893ACPI_OBJECT_TYPE ObjectType2;894ACPI_STATUS Status;895char *Path = NULL;896ACPI_PARSE_OBJECT *NextOp;897ACPI_NAMESPACE_NODE *Node;898ACPI_OPERAND_OBJECT *Object;899UINT32 ParamCount = 0;900char *Pathname;901UINT16 Flags = 0;902903904WalkState = Info->WalkState;905OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);906ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);907908if ((!(OpInfo->Flags & AML_NAMED)) &&909(!(OpInfo->Flags & AML_CREATE)) &&910(Op->Common.AmlOpcode != AML_INT_NAMEPATH_OP) &&911(Op->Common.AmlOpcode != AML_NOTIFY_OP))912{913goto Exit;914}915916/* Get the NamePath from the appropriate place */917918if (OpInfo->Flags & AML_NAMED)919{920/*921* Only these two operators (Alias, Scope) refer to an existing922* name, it is the first argument923*/924if (Op->Common.AmlOpcode == AML_ALIAS_OP)925{926ObjectType = ACPI_TYPE_ANY;927928NextOp = Op->Common.Value.Arg;929NextOp = NextOp->Common.Value.Arg;930if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)931{932Path = NextOp->Common.Value.String;933}934}935else if (Op->Common.AmlOpcode == AML_SCOPE_OP ||936Op->Common.AmlOpcode == AML_EXTERNAL_OP)937{938Path = Op->Named.Path;939}940}941else if (OpInfo->Flags & AML_CREATE)942{943/* Referenced Buffer Name is the first child */944945ObjectType = ACPI_TYPE_BUFFER; /* Change from TYPE_BUFFER_FIELD */946947NextOp = Op->Common.Value.Arg;948if (NextOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP)949{950Path = NextOp->Common.Value.String;951}952}953else if (Op->Common.AmlOpcode == AML_NOTIFY_OP)954{955Path = Op->Common.Value.Arg->Asl.Value.String;956}957else958{959Path = Op->Common.Value.String;960}961962if (!Path)963{964goto Exit;965}966967/*968* Lookup the name in the namespace. Name must exist at this point, or it969* is an invalid reference.970*971* The namespace is also used as a lookup table for references to resource972* descriptors and the fields within them.973*/974Node = NULL;975Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ACPI_TYPE_ANY,976ACPI_IMODE_EXECUTE, ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,977WalkState, &Node);978979if (ACPI_SUCCESS (Status) && (Node->Flags & ANOBJ_IS_EXTERNAL))980{981/* Node was created by an External() statement */982983Status = AE_NOT_FOUND;984}985986if (ACPI_FAILURE (Status))987{988if (Status == AE_NOT_FOUND)989{990/*991* Add this symbol as an external declaration, except if the992* parent is a CondRefOf operator. For this operator, we do not993* need an external, nor do we want one, since this can cause994* disassembly problems if the symbol is actually a control995* method.996*/997if (!(Op->Asl.Parent &&998(Op->Asl.Parent->Asl.AmlOpcode == AML_CONDITIONAL_REF_OF_OP)))999{1000if (Node)1001{1002AcpiDmAddNodeToExternalList (Node,1003(UINT8) ObjectType, 7, Flags);1004}1005else1006{1007AcpiDmAddOpToExternalList (Op, Path,1008(UINT8) ObjectType, 7, Flags);1009}1010}1011}1012}10131014/*1015* Found the node, but check if it came from an external table.1016* Add it to external list. Note: Node->OwnerId == 0 indicates1017* one of the built-in ACPI Names (_OS_ etc.) which can safely1018* be ignored.1019*/1020else if (Node->OwnerId &&1021(WalkState->OwnerId != Node->OwnerId))1022{1023ObjectType2 = ObjectType;10241025Object = AcpiNsGetAttachedObject (Node);1026if (Object)1027{1028ObjectType2 = Object->Common.Type;1029if (ObjectType2 == ACPI_TYPE_METHOD)1030{1031ParamCount = Object->Method.ParamCount;1032}1033}10341035Pathname = AcpiNsGetExternalPathname (Node);1036if (!Pathname)1037{1038return (AE_NO_MEMORY);1039}10401041AcpiDmAddNodeToExternalList (Node, (UINT8) ObjectType2,1042ParamCount, ACPI_EXT_RESOLVED_REFERENCE);10431044ACPI_FREE (Pathname);1045Op->Common.Node = Node;1046}1047else1048{1049Op->Common.Node = Node;1050}105110521053Exit:1054/* Open new scope if necessary */10551056if (AcpiNsOpensScope (ObjectType))1057{1058if (Op->Common.Node)1059{1060Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,1061WalkState);1062if (ACPI_FAILURE (Status))1063{1064return (Status);1065}1066}1067}10681069return (AE_OK);1070}10711072/*******************************************************************************1073*1074* FUNCTION: AcpiDmCommonDescendingOp1075*1076* PARAMETERS: ASL_WALK_CALLBACK1077*1078* RETURN: ACPI_STATUS1079*1080* DESCRIPTION: Perform parse tree preprocessing before main disassembly walk.1081*1082******************************************************************************/10831084static ACPI_STATUS1085AcpiDmCommonDescendingOp (1086ACPI_PARSE_OBJECT *Op,1087UINT32 Level,1088void *Context)1089{1090ACPI_STATUS Status;109110921093/* Resource descriptor conversion */10941095Status = AcpiDmProcessResourceDescriptors (Op, Level, Context);1096if (ACPI_FAILURE (Status))1097{1098return (Status);1099}11001101/* Switch/Case conversion */11021103Status = AcpiDmProcessSwitch (Op);1104return (Status);1105}110611071108/*******************************************************************************1109*1110* FUNCTION: AcpiDmProcessResourceDescriptors1111*1112* PARAMETERS: ASL_WALK_CALLBACK1113*1114* RETURN: ACPI_STATUS1115*1116* DESCRIPTION: Convert fixed-offset references to resource descriptors to1117* symbolic references. Should only be called after namespace has1118* been cross referenced.1119*1120******************************************************************************/11211122static ACPI_STATUS1123AcpiDmProcessResourceDescriptors (1124ACPI_PARSE_OBJECT *Op,1125UINT32 Level,1126void *Context)1127{1128ACPI_OP_WALK_INFO *Info = Context;1129const ACPI_OPCODE_INFO *OpInfo;1130ACPI_WALK_STATE *WalkState;1131ACPI_OBJECT_TYPE ObjectType;1132ACPI_STATUS Status;113311341135WalkState = Info->WalkState;1136OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);11371138/* Open new scope if necessary */11391140ObjectType = OpInfo->ObjectType;1141if (AcpiNsOpensScope (ObjectType))1142{1143if (Op->Common.Node)1144{11451146Status = AcpiDsScopeStackPush (Op->Common.Node, ObjectType,1147WalkState);1148if (ACPI_FAILURE (Status))1149{1150return (Status);1151}1152}1153}11541155/*1156* Check if this operator contains a reference to a resource descriptor.1157* If so, convert the reference into a symbolic reference.1158*/1159AcpiDmCheckResourceReference (Op, WalkState);1160return (AE_OK);1161}11621163/*******************************************************************************1164*1165* FUNCTION: AcpiDmCommonAscendingOp1166*1167* PARAMETERS: ASL_WALK_CALLBACK1168*1169* RETURN: None1170*1171* DESCRIPTION: Ascending handler for combined parse/namespace walks. Closes1172* scope if necessary.1173*1174******************************************************************************/11751176static ACPI_STATUS1177AcpiDmCommonAscendingOp (1178ACPI_PARSE_OBJECT *Op,1179UINT32 Level,1180void *Context)1181{1182ACPI_OP_WALK_INFO *Info = Context;1183ACPI_OBJECT_TYPE ObjectType;118411851186/* Close scope if necessary */11871188ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);11891190if (AcpiNsOpensScope (ObjectType))1191{1192(void) AcpiDsScopeStackPop (Info->WalkState);1193}11941195return (AE_OK);1196}11971198/*******************************************************************************1199*1200* FUNCTION: AcpiDmInspectPossibleArgs1201*1202* PARAMETERS: CurrentOpArgCount - Which arg of the current op was the1203* possible method invocation found1204* TargetCount - Number of targets (0,1,2) for this op1205* Op - Parse op1206*1207* RETURN: Status1208*1209* DESCRIPTION: Examine following args and next ops for possible arguments1210* for an unrecognized method invocation.1211*1212******************************************************************************/12131214static UINT321215AcpiDmInspectPossibleArgs (1216UINT32 CurrentOpArgCount,1217UINT32 TargetCount,1218ACPI_PARSE_OBJECT *Op)1219{1220const ACPI_OPCODE_INFO *OpInfo;1221UINT32 i;1222UINT32 ArgumentCount = 0;1223ACPI_PARSE_OBJECT *NextOp;1224ACPI_PARSE_OBJECT *ExecuteOp;122512261227if (!Op)1228{1229return (0);1230}12311232/* Lookahead for the maximum number of possible arguments */12331234NextOp = Op->Common.Next;12351236for (i = 0; (i < ACPI_METHOD_NUM_ARGS) && NextOp; i++)1237{1238OpInfo = AcpiPsGetOpcodeInfo (NextOp->Common.AmlOpcode);12391240/* Any one of these operators is "very probably" not a method arg */12411242if ((NextOp->Common.AmlOpcode == AML_STORE_OP) ||1243(NextOp->Common.AmlOpcode == AML_NOTIFY_OP) ||1244(OpInfo->Class == AML_CLASS_CONTROL) ||1245(OpInfo->Class == AML_CLASS_CREATE) ||1246(OpInfo->Class == AML_CLASS_NAMED_OBJECT))1247{1248break;1249}12501251if (OpInfo->Class == AML_CLASS_EXECUTE)1252{1253/* Probable that this is method arg if there is no target */12541255ExecuteOp = NextOp->Common.Value.Arg;1256while (ExecuteOp)1257{1258if ((ExecuteOp->Common.AmlOpcode == AML_INT_NAMEPATH_OP) &&1259(ExecuteOp->Common.Value.Arg == NULL))1260{1261/* No target, could be a method arg */12621263break;1264}12651266if (NextOp->Common.AmlOpcode == AML_REF_OF_OP)1267{1268break;1269}12701271ExecuteOp = ExecuteOp->Common.Next;1272}12731274if (!ExecuteOp)1275{1276/* Has a target, not method arg */12771278return (ArgumentCount);1279}1280}12811282ArgumentCount++;1283NextOp = NextOp->Common.Next;1284}12851286return (ArgumentCount);1287}128812891290