Path: blob/main/sys/contrib/dev/acpica/components/executer/exresolv.c
48521 views
/******************************************************************************1*2* Module Name: exresolv - AML Interpreter object resolution3*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/amlcode.h>154#include <contrib/dev/acpica/include/acdispat.h>155#include <contrib/dev/acpica/include/acinterp.h>156#include <contrib/dev/acpica/include/acnamesp.h>157158159#define _COMPONENT ACPI_EXECUTER160ACPI_MODULE_NAME ("exresolv")161162/* Local prototypes */163164static ACPI_STATUS165AcpiExResolveObjectToValue (166ACPI_OPERAND_OBJECT **StackPtr,167ACPI_WALK_STATE *WalkState);168169170/*******************************************************************************171*172* FUNCTION: AcpiExResolveToValue173*174* PARAMETERS: **StackPtr - Points to entry on ObjStack, which can175* be either an (ACPI_OPERAND_OBJECT *)176* or an ACPI_HANDLE.177* WalkState - Current method state178*179* RETURN: Status180*181* DESCRIPTION: Convert Reference objects to values182*183******************************************************************************/184185ACPI_STATUS186AcpiExResolveToValue (187ACPI_OPERAND_OBJECT **StackPtr,188ACPI_WALK_STATE *WalkState)189{190ACPI_STATUS Status;191192193ACPI_FUNCTION_TRACE_PTR (ExResolveToValue, StackPtr);194195196if (!StackPtr || !*StackPtr)197{198ACPI_ERROR ((AE_INFO, "Internal - null pointer"));199return_ACPI_STATUS (AE_AML_NO_OPERAND);200}201202/*203* The entity pointed to by the StackPtr can be either204* 1) A valid ACPI_OPERAND_OBJECT, or205* 2) A ACPI_NAMESPACE_NODE (NamedObj)206*/207if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_OPERAND)208{209Status = AcpiExResolveObjectToValue (StackPtr, WalkState);210if (ACPI_FAILURE (Status))211{212return_ACPI_STATUS (Status);213}214215if (!*StackPtr)216{217ACPI_ERROR ((AE_INFO, "Internal - null pointer"));218return_ACPI_STATUS (AE_AML_NO_OPERAND);219}220}221222/*223* Object on the stack may have changed if AcpiExResolveObjectToValue()224* was called (i.e., we can't use an _else_ here.)225*/226if (ACPI_GET_DESCRIPTOR_TYPE (*StackPtr) == ACPI_DESC_TYPE_NAMED)227{228Status = AcpiExResolveNodeToValue (229ACPI_CAST_INDIRECT_PTR (ACPI_NAMESPACE_NODE, StackPtr),230WalkState);231if (ACPI_FAILURE (Status))232{233return_ACPI_STATUS (Status);234}235}236237ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Resolved object %p\n", *StackPtr));238return_ACPI_STATUS (AE_OK);239}240241242/*******************************************************************************243*244* FUNCTION: AcpiExResolveObjectToValue245*246* PARAMETERS: StackPtr - Pointer to an internal object247* WalkState - Current method state248*249* RETURN: Status250*251* DESCRIPTION: Retrieve the value from an internal object. The Reference type252* uses the associated AML opcode to determine the value.253*254******************************************************************************/255256static ACPI_STATUS257AcpiExResolveObjectToValue (258ACPI_OPERAND_OBJECT **StackPtr,259ACPI_WALK_STATE *WalkState)260{261ACPI_STATUS Status = AE_OK;262ACPI_OPERAND_OBJECT *StackDesc;263ACPI_OPERAND_OBJECT *ObjDesc = NULL;264UINT8 RefType;265266267ACPI_FUNCTION_TRACE (ExResolveObjectToValue);268269270StackDesc = *StackPtr;271272/* This is an object of type ACPI_OPERAND_OBJECT */273274switch (StackDesc->Common.Type)275{276case ACPI_TYPE_LOCAL_REFERENCE:277278RefType = StackDesc->Reference.Class;279280switch (RefType)281{282case ACPI_REFCLASS_LOCAL:283case ACPI_REFCLASS_ARG:284/*285* Get the local from the method's state info286* Note: this increments the local's object reference count287*/288Status = AcpiDsMethodDataGetValue (RefType,289StackDesc->Reference.Value, WalkState, &ObjDesc);290if (ACPI_FAILURE (Status))291{292return_ACPI_STATUS (Status);293}294295ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[Arg/Local %X] ValueObj is %p\n",296StackDesc->Reference.Value, ObjDesc));297298/*299* Now we can delete the original Reference Object and300* replace it with the resolved value301*/302AcpiUtRemoveReference (StackDesc);303*StackPtr = ObjDesc;304break;305306case ACPI_REFCLASS_INDEX:307308switch (StackDesc->Reference.TargetType)309{310case ACPI_TYPE_BUFFER_FIELD:311312/* Just return - do not dereference */313break;314315case ACPI_TYPE_PACKAGE:316317/* If method call or CopyObject - do not dereference */318319if ((WalkState->Opcode == AML_INT_METHODCALL_OP) ||320(WalkState->Opcode == AML_COPY_OBJECT_OP))321{322break;323}324325/* Otherwise, dereference the PackageIndex to a package element */326327ObjDesc = *StackDesc->Reference.Where;328if (ObjDesc)329{330/*331* Valid object descriptor, copy pointer to return value332* (i.e., dereference the package index)333* Delete the ref object, increment the returned object334*/335AcpiUtAddReference (ObjDesc);336*StackPtr = ObjDesc;337}338else339{340/*341* A NULL object descriptor means an uninitialized element of342* the package, can't dereference it343*/344ACPI_ERROR ((AE_INFO,345"Attempt to dereference an Index to "346"NULL package element Idx=%p",347StackDesc));348Status = AE_AML_UNINITIALIZED_ELEMENT;349}350break;351352default:353354/* Invalid reference object */355356ACPI_ERROR ((AE_INFO,357"Unknown TargetType 0x%X in Index/Reference object %p",358StackDesc->Reference.TargetType, StackDesc));359Status = AE_AML_INTERNAL;360break;361}362break;363364case ACPI_REFCLASS_REFOF:365case ACPI_REFCLASS_DEBUG:366case ACPI_REFCLASS_TABLE:367368/* Just leave the object as-is, do not dereference */369370break;371372case ACPI_REFCLASS_NAME: /* Reference to a named object */373374/* Dereference the name */375376if ((StackDesc->Reference.Node->Type == ACPI_TYPE_DEVICE) ||377(StackDesc->Reference.Node->Type == ACPI_TYPE_THERMAL))378{379/* These node types do not have 'real' subobjects */380381*StackPtr = (void *) StackDesc->Reference.Node;382}383else384{385/* Get the object pointed to by the namespace node */386387*StackPtr = (StackDesc->Reference.Node)->Object;388AcpiUtAddReference (*StackPtr);389}390391AcpiUtRemoveReference (StackDesc);392break;393394default:395396ACPI_ERROR ((AE_INFO,397"Unknown Reference type 0x%X in %p",398RefType, StackDesc));399Status = AE_AML_INTERNAL;400break;401}402break;403404case ACPI_TYPE_BUFFER:405406Status = AcpiDsGetBufferArguments (StackDesc);407break;408409case ACPI_TYPE_PACKAGE:410411Status = AcpiDsGetPackageArguments (StackDesc);412break;413414case ACPI_TYPE_BUFFER_FIELD:415case ACPI_TYPE_LOCAL_REGION_FIELD:416case ACPI_TYPE_LOCAL_BANK_FIELD:417case ACPI_TYPE_LOCAL_INDEX_FIELD:418419ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,420"FieldRead SourceDesc=%p Type=%X\n",421StackDesc, StackDesc->Common.Type));422423Status = AcpiExReadDataFromField (WalkState, StackDesc, &ObjDesc);424425/* Remove a reference to the original operand, then override */426427AcpiUtRemoveReference (*StackPtr);428*StackPtr = (void *) ObjDesc;429break;430431default:432433break;434}435436return_ACPI_STATUS (Status);437}438439440/*******************************************************************************441*442* FUNCTION: AcpiExResolveMultiple443*444* PARAMETERS: WalkState - Current state (contains AML opcode)445* Operand - Starting point for resolution446* ReturnType - Where the object type is returned447* ReturnDesc - Where the resolved object is returned448*449* RETURN: Status450*451* DESCRIPTION: Return the base object and type. Traverse a reference list if452* necessary to get to the base object.453*454******************************************************************************/455456ACPI_STATUS457AcpiExResolveMultiple (458ACPI_WALK_STATE *WalkState,459ACPI_OPERAND_OBJECT *Operand,460ACPI_OBJECT_TYPE *ReturnType,461ACPI_OPERAND_OBJECT **ReturnDesc)462{463ACPI_OPERAND_OBJECT *ObjDesc = ACPI_CAST_PTR (void, Operand);464ACPI_NAMESPACE_NODE *Node = ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Operand);465ACPI_OBJECT_TYPE Type;466ACPI_STATUS Status;467468469ACPI_FUNCTION_TRACE (AcpiExResolveMultiple);470471472/* Operand can be either a namespace node or an operand descriptor */473474switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))475{476case ACPI_DESC_TYPE_OPERAND:477478Type = ObjDesc->Common.Type;479break;480481case ACPI_DESC_TYPE_NAMED:482483Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;484ObjDesc = AcpiNsGetAttachedObject (Node);485486/* If we had an Alias node, use the attached object for type info */487488if (Type == ACPI_TYPE_LOCAL_ALIAS)489{490Type = ((ACPI_NAMESPACE_NODE *) ObjDesc)->Type;491ObjDesc = AcpiNsGetAttachedObject (492(ACPI_NAMESPACE_NODE *) ObjDesc);493}494495switch (Type)496{497case ACPI_TYPE_DEVICE:498case ACPI_TYPE_THERMAL:499500/* These types have no attached subobject */501break;502503default:504505/* All other types require a subobject */506507if (!ObjDesc)508{509ACPI_ERROR ((AE_INFO,510"[%4.4s] Node is unresolved or uninitialized",511AcpiUtGetNodeName (Node)));512return_ACPI_STATUS (AE_AML_UNINITIALIZED_NODE);513}514break;515}516break;517518default:519return_ACPI_STATUS (AE_AML_OPERAND_TYPE);520}521522/* If type is anything other than a reference, we are done */523524if (Type != ACPI_TYPE_LOCAL_REFERENCE)525{526goto Exit;527}528529/*530* For reference objects created via the RefOf, Index, or Load/LoadTable531* operators, we need to get to the base object (as per the ACPI532* specification of the ObjectType and SizeOf operators). This means533* traversing the list of possibly many nested references.534*/535while (ObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)536{537switch (ObjDesc->Reference.Class)538{539case ACPI_REFCLASS_REFOF:540case ACPI_REFCLASS_NAME:541542/* Dereference the reference pointer */543544if (ObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)545{546Node = ObjDesc->Reference.Object;547}548else /* AML_INT_NAMEPATH_OP */549{550Node = ObjDesc->Reference.Node;551}552553/* All "References" point to a NS node */554555if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)556{557ACPI_ERROR ((AE_INFO,558"Not a namespace node %p [%s]",559Node, AcpiUtGetDescriptorName (Node)));560return_ACPI_STATUS (AE_AML_INTERNAL);561}562563/* Get the attached object */564565ObjDesc = AcpiNsGetAttachedObject (Node);566if (!ObjDesc)567{568/* No object, use the NS node type */569570Type = AcpiNsGetType (Node);571goto Exit;572}573574/* Check for circular references */575576if (ObjDesc == Operand)577{578return_ACPI_STATUS (AE_AML_CIRCULAR_REFERENCE);579}580break;581582case ACPI_REFCLASS_INDEX:583584/* Get the type of this reference (index into another object) */585586Type = ObjDesc->Reference.TargetType;587if (Type != ACPI_TYPE_PACKAGE)588{589goto Exit;590}591592/*593* The main object is a package, we want to get the type594* of the individual package element that is referenced by595* the index.596*597* This could of course in turn be another reference object.598*/599ObjDesc = *(ObjDesc->Reference.Where);600if (!ObjDesc)601{602/* NULL package elements are allowed */603604Type = 0; /* Uninitialized */605goto Exit;606}607break;608609case ACPI_REFCLASS_TABLE:610611Type = ACPI_TYPE_DDB_HANDLE;612goto Exit;613614case ACPI_REFCLASS_LOCAL:615case ACPI_REFCLASS_ARG:616617if (ReturnDesc)618{619Status = AcpiDsMethodDataGetValue (ObjDesc->Reference.Class,620ObjDesc->Reference.Value, WalkState, &ObjDesc);621if (ACPI_FAILURE (Status))622{623return_ACPI_STATUS (Status);624}625AcpiUtRemoveReference (ObjDesc);626}627else628{629Status = AcpiDsMethodDataGetNode (ObjDesc->Reference.Class,630ObjDesc->Reference.Value, WalkState, &Node);631if (ACPI_FAILURE (Status))632{633return_ACPI_STATUS (Status);634}635636ObjDesc = AcpiNsGetAttachedObject (Node);637if (!ObjDesc)638{639Type = ACPI_TYPE_ANY;640goto Exit;641}642}643break;644645case ACPI_REFCLASS_DEBUG:646647/* The Debug Object is of type "DebugObject" */648649Type = ACPI_TYPE_DEBUG_OBJECT;650goto Exit;651652default:653654ACPI_ERROR ((AE_INFO,655"Unknown Reference Class 0x%2.2X",656ObjDesc->Reference.Class));657return_ACPI_STATUS (AE_AML_INTERNAL);658}659}660661/*662* Now we are guaranteed to have an object that has not been created663* via the RefOf or Index operators.664*/665Type = ObjDesc->Common.Type;666667668Exit:669/* Convert internal types to external types */670671switch (Type)672{673case ACPI_TYPE_LOCAL_REGION_FIELD:674case ACPI_TYPE_LOCAL_BANK_FIELD:675case ACPI_TYPE_LOCAL_INDEX_FIELD:676677Type = ACPI_TYPE_FIELD_UNIT;678break;679680case ACPI_TYPE_LOCAL_SCOPE:681682/* Per ACPI Specification, Scope is untyped */683684Type = ACPI_TYPE_ANY;685break;686687default:688689/* No change to Type required */690691break;692}693694*ReturnType = Type;695if (ReturnDesc)696{697*ReturnDesc = ObjDesc;698}699return_ACPI_STATUS (AE_OK);700}701702703