dsmthdat.c revision 138287
167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: dsmthdat - control method arguments and local variables 4138287Smarks * $Revision: 80 $ 567754Smsmith * 667754Smsmith ******************************************************************************/ 767754Smsmith 867754Smsmith/****************************************************************************** 967754Smsmith * 1067754Smsmith * 1. Copyright Notice 1167754Smsmith * 12126372Snjl * Some or all of this work - Copyright (c) 1999 - 2004, Intel Corp. 1370243Smsmith * All rights reserved. 1467754Smsmith * 1567754Smsmith * 2. License 1667754Smsmith * 1767754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1867754Smsmith * rights. You may have additional license terms from the party that provided 1967754Smsmith * you this software, covering your right to use that party's intellectual 2067754Smsmith * property rights. 2167754Smsmith * 2267754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2367754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2467754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2567754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2667754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2767754Smsmith * Code in any form, with the right to sublicense such rights; and 2867754Smsmith * 2967754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 3067754Smsmith * license (with the right to sublicense), under only those claims of Intel 3167754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3267754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3367754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3467754Smsmith * license, and in no event shall the patent license extend to any additions 3567754Smsmith * to or modifications of the Original Intel Code. No other license or right 3667754Smsmith * is granted directly or by implication, estoppel or otherwise; 3767754Smsmith * 3867754Smsmith * The above copyright and patent license is granted only if the following 3967754Smsmith * conditions are met: 4067754Smsmith * 4167754Smsmith * 3. Conditions 4267754Smsmith * 4367754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4467754Smsmith * Redistribution of source code of any substantial portion of the Covered 4567754Smsmith * Code or modification with rights to further distribute source must include 4667754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4767754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4867754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 4967754Smsmith * contain a file documenting the changes Licensee made to create that Covered 5067754Smsmith * Code and the date of any change. Licensee must include in that file the 5167754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5267754Smsmith * must include a prominent statement that the modification is derived, 5367754Smsmith * directly or indirectly, from Original Intel Code. 5467754Smsmith * 5567754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5667754Smsmith * Redistribution of source code of any substantial portion of the Covered 5767754Smsmith * Code or modification without rights to further distribute source must 5867754Smsmith * include the following Disclaimer and Export Compliance provision in the 5967754Smsmith * documentation and/or other materials provided with distribution. In 6067754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6167754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6267754Smsmith * license from Licensee to its licensee is limited to the intellectual 6367754Smsmith * property embodied in the software Licensee provides to its licensee, and 6467754Smsmith * not to intellectual property embodied in modifications its licensee may 6567754Smsmith * make. 6667754Smsmith * 6767754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6867754Smsmith * substantial portion of the Covered Code or modification must reproduce the 6967754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 7067754Smsmith * provision in the documentation and/or other materials provided with the 7167754Smsmith * distribution. 7267754Smsmith * 7367754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7467754Smsmith * Intel Code. 7567754Smsmith * 7667754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7767754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7867754Smsmith * other dealings in products derived from or relating to the Covered Code 7967754Smsmith * without prior written authorization from Intel. 8067754Smsmith * 8167754Smsmith * 4. Disclaimer and Export Compliance 8267754Smsmith * 8367754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8467754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8567754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8667754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8767754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8867754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8967754Smsmith * PARTICULAR PURPOSE. 9067754Smsmith * 9167754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9267754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9367754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9467754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9567754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9667754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9767754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9867754Smsmith * LIMITED REMEDY. 9967754Smsmith * 10067754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10167754Smsmith * software or system incorporating such software without first obtaining any 10267754Smsmith * required license or other approval from the U. S. Department of Commerce or 10367754Smsmith * any other agency or department of the United States Government. In the 10467754Smsmith * event Licensee exports any such software from the United States or 10567754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10667754Smsmith * ensure that the distribution and export/re-export of the software is in 10767754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10867754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10967754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 11067754Smsmith * software, or service, directly or indirectly, to any country for which the 11167754Smsmith * United States government or any agency thereof requires an export license, 11267754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11367754Smsmith * such license, approval or letter. 11467754Smsmith * 11567754Smsmith *****************************************************************************/ 11667754Smsmith 11767754Smsmith#define __DSMTHDAT_C__ 11867754Smsmith 11967754Smsmith#include "acpi.h" 12067754Smsmith#include "acdispat.h" 12167754Smsmith#include "amlcode.h" 12267754Smsmith#include "acnamesp.h" 123114237Snjl#include "acinterp.h" 12467754Smsmith 12567754Smsmith 12677424Smsmith#define _COMPONENT ACPI_DISPATCHER 12791116Smsmith ACPI_MODULE_NAME ("dsmthdat") 12867754Smsmith 12967754Smsmith 13067754Smsmith/******************************************************************************* 13167754Smsmith * 13267754Smsmith * FUNCTION: AcpiDsMethodDataInit 13367754Smsmith * 13471867Smsmith * PARAMETERS: WalkState - Current walk state object 13567754Smsmith * 13667754Smsmith * RETURN: Status 13767754Smsmith * 13867754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments 13967754Smsmith * and locals. The data struct is an array of NTEs for each. 14067754Smsmith * This allows RefOf and DeRefOf to work properly for these 14167754Smsmith * special data types. 14267754Smsmith * 14387031Smsmith * NOTES: WalkState fields are initialized to zero by the 14487031Smsmith * ACPI_MEM_CALLOCATE(). 14587031Smsmith * 14687031Smsmith * A pseudo-Namespace Node is assigned to each argument and local 14787031Smsmith * so that RefOf() can return a pointer to the Node. 14887031Smsmith * 14967754Smsmith ******************************************************************************/ 15067754Smsmith 15199679Siwasakivoid 15267754SmsmithAcpiDsMethodDataInit ( 15367754Smsmith ACPI_WALK_STATE *WalkState) 15467754Smsmith{ 15567754Smsmith UINT32 i; 15667754Smsmith 15767754Smsmith 15891116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataInit"); 15967754Smsmith 16067754Smsmith 16167754Smsmith /* Init the method arguments */ 16267754Smsmith 163114237Snjl for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) 16467754Smsmith { 165117521Snjl ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, 166117521Snjl NAMEOF_ARG_NTE); 16799146Siwasaki WalkState->Arguments[i].Name.Integer |= (i << 24); 16899146Siwasaki WalkState->Arguments[i].Descriptor = ACPI_DESC_TYPE_NAMED; 16999146Siwasaki WalkState->Arguments[i].Type = ACPI_TYPE_ANY; 17099146Siwasaki WalkState->Arguments[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 17167754Smsmith } 17267754Smsmith 17367754Smsmith /* Init the method locals */ 17467754Smsmith 175114237Snjl for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) 17667754Smsmith { 177117521Snjl ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, 178117521Snjl NAMEOF_LOCAL_NTE); 17967754Smsmith 18099146Siwasaki WalkState->LocalVariables[i].Name.Integer |= (i << 24); 18199146Siwasaki WalkState->LocalVariables[i].Descriptor = ACPI_DESC_TYPE_NAMED; 18299146Siwasaki WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY; 18399146Siwasaki WalkState->LocalVariables[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 18467754Smsmith } 18567754Smsmith 18699679Siwasaki return_VOID; 18767754Smsmith} 18867754Smsmith 18967754Smsmith 19067754Smsmith/******************************************************************************* 19167754Smsmith * 19267754Smsmith * FUNCTION: AcpiDsMethodDataDeleteAll 19367754Smsmith * 19471867Smsmith * PARAMETERS: WalkState - Current walk state object 19567754Smsmith * 19699679Siwasaki * RETURN: None 19767754Smsmith * 19867754Smsmith * DESCRIPTION: Delete method locals and arguments. Arguments are only 19967754Smsmith * deleted if this method was called from another method. 20067754Smsmith * 20167754Smsmith ******************************************************************************/ 20267754Smsmith 20399679Siwasakivoid 20467754SmsmithAcpiDsMethodDataDeleteAll ( 20567754Smsmith ACPI_WALK_STATE *WalkState) 20667754Smsmith{ 20767754Smsmith UINT32 Index; 20867754Smsmith 20967754Smsmith 21091116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll"); 21167754Smsmith 21267754Smsmith 21387031Smsmith /* Detach the locals */ 21467754Smsmith 215114237Snjl for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++) 21667754Smsmith { 21787031Smsmith if (WalkState->LocalVariables[Index].Object) 21867754Smsmith { 21987031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n", 22087031Smsmith Index, WalkState->LocalVariables[Index].Object)); 22167754Smsmith 22287031Smsmith /* Detach object (if present) and remove a reference */ 22367754Smsmith 22487031Smsmith AcpiNsDetachObject (&WalkState->LocalVariables[Index]); 22599679Siwasaki } 22667754Smsmith } 22767754Smsmith 22887031Smsmith /* Detach the arguments */ 22967754Smsmith 230114237Snjl for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++) 23167754Smsmith { 23287031Smsmith if (WalkState->Arguments[Index].Object) 23367754Smsmith { 23487031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n", 23587031Smsmith Index, WalkState->Arguments[Index].Object)); 23667754Smsmith 23787031Smsmith /* Detach object (if present) and remove a reference */ 23867754Smsmith 23987031Smsmith AcpiNsDetachObject (&WalkState->Arguments[Index]); 24067754Smsmith } 24167754Smsmith } 24267754Smsmith 24399679Siwasaki return_VOID; 24467754Smsmith} 24567754Smsmith 24667754Smsmith 24767754Smsmith/******************************************************************************* 24867754Smsmith * 24967754Smsmith * FUNCTION: AcpiDsMethodDataInitArgs 25067754Smsmith * 25171867Smsmith * PARAMETERS: *Params - Pointer to a parameter list for the method 25271867Smsmith * MaxParamCount - The arg count for this method 25371867Smsmith * WalkState - Current walk state object 25467754Smsmith * 25567754Smsmith * RETURN: Status 25667754Smsmith * 25787031Smsmith * DESCRIPTION: Initialize arguments for a method. The parameter list is a list 25887031Smsmith * of ACPI operand objects, either null terminated or whose length 25987031Smsmith * is defined by MaxParamCount. 26067754Smsmith * 26167754Smsmith ******************************************************************************/ 26267754Smsmith 26367754SmsmithACPI_STATUS 26467754SmsmithAcpiDsMethodDataInitArgs ( 26567754Smsmith ACPI_OPERAND_OBJECT **Params, 26667754Smsmith UINT32 MaxParamCount, 26767754Smsmith ACPI_WALK_STATE *WalkState) 26867754Smsmith{ 26967754Smsmith ACPI_STATUS Status; 27087031Smsmith UINT32 Index = 0; 27167754Smsmith 27267754Smsmith 27391116Smsmith ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params); 27467754Smsmith 27567754Smsmith 27667754Smsmith if (!Params) 27767754Smsmith { 27882367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n")); 27967754Smsmith return_ACPI_STATUS (AE_OK); 28067754Smsmith } 28167754Smsmith 28267754Smsmith /* Copy passed parameters into the new method stack frame */ 28367754Smsmith 284114237Snjl while ((Index < ACPI_METHOD_NUM_ARGS) && (Index < MaxParamCount) && Params[Index]) 28567754Smsmith { 28687031Smsmith /* 28787031Smsmith * A valid parameter. 288126372Snjl * Store the argument in the method/walk descriptor. 289126372Snjl * Do not copy the arg in order to implement call by reference 29087031Smsmith */ 291126372Snjl Status = AcpiDsMethodDataSetValue (AML_ARG_OP, Index, Params[Index], WalkState); 29287031Smsmith if (ACPI_FAILURE (Status)) 29367754Smsmith { 29487031Smsmith return_ACPI_STATUS (Status); 29567754Smsmith } 29667754Smsmith 29787031Smsmith Index++; 29867754Smsmith } 29967754Smsmith 30087031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index)); 30167754Smsmith return_ACPI_STATUS (AE_OK); 30267754Smsmith} 30367754Smsmith 30467754Smsmith 30567754Smsmith/******************************************************************************* 30667754Smsmith * 30787031Smsmith * FUNCTION: AcpiDsMethodDataGetNode 30867754Smsmith * 30977424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 31087031Smsmith * Index - Which localVar or argument whose type 31187031Smsmith * to get 31271867Smsmith * WalkState - Current walk state object 31367754Smsmith * 31487031Smsmith * RETURN: Get the Node associated with a local or arg. 31567754Smsmith * 31667754Smsmith ******************************************************************************/ 31767754Smsmith 31867754SmsmithACPI_STATUS 31987031SmsmithAcpiDsMethodDataGetNode ( 32077424Smsmith UINT16 Opcode, 32167754Smsmith UINT32 Index, 32267754Smsmith ACPI_WALK_STATE *WalkState, 32387031Smsmith ACPI_NAMESPACE_NODE **Node) 32467754Smsmith{ 32591116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataGetNode"); 32667754Smsmith 32767754Smsmith 32867754Smsmith /* 32987031Smsmith * Method Locals and Arguments are supported 33067754Smsmith */ 33177424Smsmith switch (Opcode) 33267754Smsmith { 33377424Smsmith case AML_LOCAL_OP: 33467754Smsmith 335114237Snjl if (Index > ACPI_METHOD_MAX_LOCAL) 33667754Smsmith { 33787031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n", 338114237Snjl Index, ACPI_METHOD_MAX_LOCAL)); 33987031Smsmith return_ACPI_STATUS (AE_AML_INVALID_INDEX); 34067754Smsmith } 34167754Smsmith 34287031Smsmith /* Return a pointer to the pseudo-node */ 34387031Smsmith 34487031Smsmith *Node = &WalkState->LocalVariables[Index]; 34567754Smsmith break; 34667754Smsmith 34777424Smsmith case AML_ARG_OP: 34867754Smsmith 349114237Snjl if (Index > ACPI_METHOD_MAX_ARG) 35067754Smsmith { 35182367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n", 352114237Snjl Index, ACPI_METHOD_MAX_ARG)); 35387031Smsmith return_ACPI_STATUS (AE_AML_INVALID_INDEX); 35467754Smsmith } 35567754Smsmith 35687031Smsmith /* Return a pointer to the pseudo-node */ 35787031Smsmith 35887031Smsmith *Node = &WalkState->Arguments[Index]; 35967754Smsmith break; 36067754Smsmith 36167754Smsmith default: 36282367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode)); 36387031Smsmith return_ACPI_STATUS (AE_AML_BAD_OPCODE); 36467754Smsmith } 36567754Smsmith 36667754Smsmith return_ACPI_STATUS (AE_OK); 36767754Smsmith} 36867754Smsmith 36967754Smsmith 37067754Smsmith/******************************************************************************* 37167754Smsmith * 37287031Smsmith * FUNCTION: AcpiDsMethodDataSetValue 37367754Smsmith * 37477424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 37567754Smsmith * Index - Which localVar or argument to get 37667754Smsmith * Object - Object to be inserted into the stack entry 37771867Smsmith * WalkState - Current walk state object 37867754Smsmith * 37967754Smsmith * RETURN: Status 38067754Smsmith * 38177424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index. 382114237Snjl * Note: There is no "implicit conversion" for locals. 38367754Smsmith * 38467754Smsmith ******************************************************************************/ 38567754Smsmith 38667754SmsmithACPI_STATUS 38787031SmsmithAcpiDsMethodDataSetValue ( 38877424Smsmith UINT16 Opcode, 38967754Smsmith UINT32 Index, 39067754Smsmith ACPI_OPERAND_OBJECT *Object, 39167754Smsmith ACPI_WALK_STATE *WalkState) 39267754Smsmith{ 39367754Smsmith ACPI_STATUS Status; 39487031Smsmith ACPI_NAMESPACE_NODE *Node; 39567754Smsmith 39667754Smsmith 39791116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataSetValue"); 39867754Smsmith 39983174Smsmith 400114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 401138287Smarks "NewObj %p Opcode %X, Refs=%d [%s]\n", Object, 402114237Snjl Opcode, Object->Common.ReferenceCount, 403114237Snjl AcpiUtGetTypeName (Object->Common.Type))); 404114237Snjl 40587031Smsmith /* Get the namespace node for the arg/local */ 40667754Smsmith 40787031Smsmith Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 40867754Smsmith if (ACPI_FAILURE (Status)) 40967754Smsmith { 41067754Smsmith return_ACPI_STATUS (Status); 41167754Smsmith } 41267754Smsmith 413123315Snjl /* 414122945Snjl * Increment ref count so object can't be deleted while installed. 415122945Snjl * NOTE: We do not copy the object in order to preserve the call by 416122945Snjl * reference semantics of ACPI Control Method invocation. 417122945Snjl * (See ACPI Specification 2.0C) 418114237Snjl */ 419122945Snjl AcpiUtAddReference (Object); 42067754Smsmith 421114237Snjl /* Install the object */ 422114237Snjl 423122945Snjl Node->Object = Object; 424114237Snjl return_ACPI_STATUS (Status); 42567754Smsmith} 42667754Smsmith 42767754Smsmith 42867754Smsmith/******************************************************************************* 42967754Smsmith * 43067754Smsmith * FUNCTION: AcpiDsMethodDataGetType 43167754Smsmith * 43277424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 43367754Smsmith * Index - Which localVar or argument whose type 43467754Smsmith * to get 43571867Smsmith * WalkState - Current walk state object 43667754Smsmith * 43787031Smsmith * RETURN: Data type of current value of the selected Arg or Local 43867754Smsmith * 43967754Smsmith ******************************************************************************/ 44067754Smsmith 44191116SmsmithACPI_OBJECT_TYPE 44267754SmsmithAcpiDsMethodDataGetType ( 44377424Smsmith UINT16 Opcode, 44467754Smsmith UINT32 Index, 44567754Smsmith ACPI_WALK_STATE *WalkState) 44667754Smsmith{ 44767754Smsmith ACPI_STATUS Status; 44887031Smsmith ACPI_NAMESPACE_NODE *Node; 44967754Smsmith ACPI_OPERAND_OBJECT *Object; 45067754Smsmith 45167754Smsmith 45291116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataGetType"); 45367754Smsmith 45467754Smsmith 45587031Smsmith /* Get the namespace node for the arg/local */ 45667754Smsmith 45787031Smsmith Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 45867754Smsmith if (ACPI_FAILURE (Status)) 45967754Smsmith { 46067754Smsmith return_VALUE ((ACPI_TYPE_NOT_FOUND)); 46167754Smsmith } 46267754Smsmith 46387031Smsmith /* Get the object */ 46467754Smsmith 46587031Smsmith Object = AcpiNsGetAttachedObject (Node); 46667754Smsmith if (!Object) 46767754Smsmith { 46887031Smsmith /* Uninitialized local/arg, return TYPE_ANY */ 46987031Smsmith 47067754Smsmith return_VALUE (ACPI_TYPE_ANY); 47167754Smsmith } 47267754Smsmith 47387031Smsmith /* Get the object type */ 47487031Smsmith 47599679Siwasaki return_VALUE (ACPI_GET_OBJECT_TYPE (Object)); 47667754Smsmith} 47767754Smsmith 47867754Smsmith 47967754Smsmith/******************************************************************************* 48067754Smsmith * 48167754Smsmith * FUNCTION: AcpiDsMethodDataGetValue 48267754Smsmith * 48377424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 48467754Smsmith * Index - Which localVar or argument to get 48571867Smsmith * WalkState - Current walk state object 48671867Smsmith * *DestDesc - Ptr to Descriptor into which selected Arg 48767754Smsmith * or Local value should be copied 48867754Smsmith * 48967754Smsmith * RETURN: Status 49067754Smsmith * 49167754Smsmith * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame 49267754Smsmith * at the current top of the method stack. 49377424Smsmith * Used only in AcpiExResolveToValue(). 49467754Smsmith * 49567754Smsmith ******************************************************************************/ 49667754Smsmith 49767754SmsmithACPI_STATUS 49867754SmsmithAcpiDsMethodDataGetValue ( 49977424Smsmith UINT16 Opcode, 50067754Smsmith UINT32 Index, 50167754Smsmith ACPI_WALK_STATE *WalkState, 50267754Smsmith ACPI_OPERAND_OBJECT **DestDesc) 50367754Smsmith{ 50467754Smsmith ACPI_STATUS Status; 50587031Smsmith ACPI_NAMESPACE_NODE *Node; 50667754Smsmith ACPI_OPERAND_OBJECT *Object; 50767754Smsmith 50867754Smsmith 50991116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataGetValue"); 51067754Smsmith 51167754Smsmith 51267754Smsmith /* Validate the object descriptor */ 51367754Smsmith 51467754Smsmith if (!DestDesc) 51567754Smsmith { 51682367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n")); 51767754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 51867754Smsmith } 51967754Smsmith 52087031Smsmith /* Get the namespace node for the arg/local */ 52167754Smsmith 52287031Smsmith Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 52367754Smsmith if (ACPI_FAILURE (Status)) 52467754Smsmith { 52567754Smsmith return_ACPI_STATUS (Status); 52667754Smsmith } 52767754Smsmith 52887031Smsmith /* Get the object from the node */ 52967754Smsmith 53087031Smsmith Object = Node->Object; 53167754Smsmith 53267754Smsmith /* Examine the returned object, it must be valid. */ 53367754Smsmith 53467754Smsmith if (!Object) 53567754Smsmith { 53667754Smsmith /* 53787031Smsmith * Index points to uninitialized object. 53867754Smsmith * This means that either 1) The expected argument was 53967754Smsmith * not passed to the method, or 2) A local variable 54067754Smsmith * was referenced by the method (via the ASL) 54167754Smsmith * before it was initialized. Either case is an error. 54267754Smsmith */ 543138287Smarks 544138287Smarks /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */ 545138287Smarks 546138287Smarks if (AcpiGbl_EnableInterpreterSlack) 54767754Smsmith { 548138287Smarks Object = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 549138287Smarks if (!Object) 550138287Smarks { 551138287Smarks return_ACPI_STATUS (AE_NO_MEMORY); 552138287Smarks } 553138287Smarks 554138287Smarks Object->Integer.Value = 0; 555138287Smarks Node->Object = Object; 556138287Smarks } 557138287Smarks 558138287Smarks /* Otherwise, return the error */ 559138287Smarks 560138287Smarks else switch (Opcode) 561138287Smarks { 56277424Smsmith case AML_ARG_OP: 56371867Smsmith 56487031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n", 56587031Smsmith Index, Node)); 56671867Smsmith 56767754Smsmith return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 56867754Smsmith 56977424Smsmith case AML_LOCAL_OP: 57071867Smsmith 57187031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n", 57287031Smsmith Index, Node)); 57371867Smsmith 57467754Smsmith return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 57599679Siwasaki 57699679Siwasaki default: 577126372Snjl ACPI_REPORT_ERROR (("Not Arg/Local opcode: %X\n", Opcode)); 57899679Siwasaki return_ACPI_STATUS (AE_AML_INTERNAL); 57967754Smsmith } 58067754Smsmith } 58167754Smsmith 58267754Smsmith /* 58387031Smsmith * The Index points to an initialized and valid object. 58467754Smsmith * Return an additional reference to the object 58567754Smsmith */ 58667754Smsmith *DestDesc = Object; 58777424Smsmith AcpiUtAddReference (Object); 58867754Smsmith 58967754Smsmith return_ACPI_STATUS (AE_OK); 59067754Smsmith} 59167754Smsmith 59267754Smsmith 59367754Smsmith/******************************************************************************* 59467754Smsmith * 59567754Smsmith * FUNCTION: AcpiDsMethodDataDeleteValue 59667754Smsmith * 59777424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 59867754Smsmith * Index - Which localVar or argument to delete 59971867Smsmith * WalkState - Current walk state object 60067754Smsmith * 60199679Siwasaki * RETURN: None 60267754Smsmith * 60377424Smsmith * DESCRIPTION: Delete the entry at Opcode:Index on the method stack. Inserts 60467754Smsmith * a null into the stack slot after the object is deleted. 60567754Smsmith * 60667754Smsmith ******************************************************************************/ 60767754Smsmith 60899679Siwasakivoid 60967754SmsmithAcpiDsMethodDataDeleteValue ( 61077424Smsmith UINT16 Opcode, 61167754Smsmith UINT32 Index, 61267754Smsmith ACPI_WALK_STATE *WalkState) 61367754Smsmith{ 61467754Smsmith ACPI_STATUS Status; 61587031Smsmith ACPI_NAMESPACE_NODE *Node; 61667754Smsmith ACPI_OPERAND_OBJECT *Object; 61767754Smsmith 61867754Smsmith 61991116Smsmith ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue"); 62067754Smsmith 62167754Smsmith 62287031Smsmith /* Get the namespace node for the arg/local */ 62367754Smsmith 62487031Smsmith Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 62567754Smsmith if (ACPI_FAILURE (Status)) 62667754Smsmith { 62799679Siwasaki return_VOID; 62867754Smsmith } 62967754Smsmith 63087031Smsmith /* Get the associated object */ 63167754Smsmith 63287031Smsmith Object = AcpiNsGetAttachedObject (Node); 63367754Smsmith 63467754Smsmith /* 63567754Smsmith * Undefine the Arg or Local by setting its descriptor 63667754Smsmith * pointer to NULL. Locals/Args can contain both 63767754Smsmith * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs 63867754Smsmith */ 63987031Smsmith Node->Object = NULL; 64067754Smsmith 64167754Smsmith if ((Object) && 64299679Siwasaki (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND)) 64367754Smsmith { 64467754Smsmith /* 64587031Smsmith * There is a valid object. 64667754Smsmith * Decrement the reference count by one to balance the 64787031Smsmith * increment when the object was stored. 64867754Smsmith */ 64977424Smsmith AcpiUtRemoveReference (Object); 65067754Smsmith } 65167754Smsmith 65299679Siwasaki return_VOID; 65367754Smsmith} 65467754Smsmith 65567754Smsmith 65667754Smsmith/******************************************************************************* 65767754Smsmith * 65877424Smsmith * FUNCTION: AcpiDsStoreObjectToLocal 65967754Smsmith * 66077424Smsmith * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 66167754Smsmith * Index - Which localVar or argument to set 66287031Smsmith * ObjDesc - Value to be stored 66371867Smsmith * WalkState - Current walk state 66467754Smsmith * 66567754Smsmith * RETURN: Status 66667754Smsmith * 66787031Smsmith * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed 66867754Smsmith * as the new value for the Arg or Local and the reference count 66987031Smsmith * for ObjDesc is incremented. 67067754Smsmith * 67167754Smsmith ******************************************************************************/ 67267754Smsmith 67367754SmsmithACPI_STATUS 67477424SmsmithAcpiDsStoreObjectToLocal ( 67577424Smsmith UINT16 Opcode, 67667754Smsmith UINT32 Index, 67787031Smsmith ACPI_OPERAND_OBJECT *ObjDesc, 67867754Smsmith ACPI_WALK_STATE *WalkState) 67967754Smsmith{ 68067754Smsmith ACPI_STATUS Status; 68187031Smsmith ACPI_NAMESPACE_NODE *Node; 68287031Smsmith ACPI_OPERAND_OBJECT *CurrentObjDesc; 683123315Snjl ACPI_OPERAND_OBJECT *NewObjDesc; 68467754Smsmith 68567754Smsmith 68691116Smsmith ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal"); 687138287Smarks ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%X Index=%d Obj=%p\n", 68887031Smsmith Opcode, Index, ObjDesc)); 68967754Smsmith 69067754Smsmith /* Parameter validation */ 69167754Smsmith 69287031Smsmith if (!ObjDesc) 69367754Smsmith { 69467754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 69567754Smsmith } 69667754Smsmith 69787031Smsmith /* Get the namespace node for the arg/local */ 69867754Smsmith 69987031Smsmith Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 70067754Smsmith if (ACPI_FAILURE (Status)) 70167754Smsmith { 70287031Smsmith return_ACPI_STATUS (Status); 70367754Smsmith } 70467754Smsmith 70587031Smsmith CurrentObjDesc = AcpiNsGetAttachedObject (Node); 70687031Smsmith if (CurrentObjDesc == ObjDesc) 70767754Smsmith { 708114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", 709114237Snjl ObjDesc)); 71087031Smsmith return_ACPI_STATUS (Status); 71167754Smsmith } 71267754Smsmith 71367754Smsmith /* 714123315Snjl * If the reference count on the object is more than one, we must 715126372Snjl * take a copy of the object before we store. A reference count 716126372Snjl * of exactly 1 means that the object was just created during the 717126372Snjl * evaluation of an expression, and we can safely use it since it 718126372Snjl * is not used anywhere else. 719123315Snjl */ 720123315Snjl NewObjDesc = ObjDesc; 721126372Snjl if (ObjDesc->Common.ReferenceCount > 1) 722123315Snjl { 723123315Snjl Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState); 724123315Snjl if (ACPI_FAILURE (Status)) 725123315Snjl { 726123315Snjl return_ACPI_STATUS (Status); 727123315Snjl } 728123315Snjl } 729123315Snjl 730123315Snjl /* 73167754Smsmith * If there is an object already in this slot, we either 73267754Smsmith * have to delete it, or if this is an argument and there 73367754Smsmith * is an object reference stored there, we have to do 73467754Smsmith * an indirect store! 73567754Smsmith */ 73687031Smsmith if (CurrentObjDesc) 73767754Smsmith { 73867754Smsmith /* 73967754Smsmith * Check for an indirect store if an argument 74067754Smsmith * contains an object reference (stored as an Node). 74167754Smsmith * We don't allow this automatic dereferencing for 74267754Smsmith * locals, since a store to a local should overwrite 74367754Smsmith * anything there, including an object reference. 74467754Smsmith * 74567754Smsmith * If both Arg0 and Local0 contain RefOf (Local4): 74667754Smsmith * 74767754Smsmith * Store (1, Arg0) - Causes indirect store to local4 74867754Smsmith * Store (1, Local0) - Stores 1 in local0, overwriting 74967754Smsmith * the reference to local4 75067754Smsmith * Store (1, DeRefof (Local0)) - Causes indirect store to local4 75167754Smsmith * 75267754Smsmith * Weird, but true. 75367754Smsmith */ 754102550Siwasaki if (Opcode == AML_ARG_OP) 75567754Smsmith { 756114237Snjl /* 757102550Siwasaki * Make sure that the object is the correct type. This may be overkill, but 758102550Siwasaki * it is here because references were NS nodes in the past. Now they are 759102550Siwasaki * operand objects of type Reference. 760102550Siwasaki */ 761102550Siwasaki if (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) != ACPI_DESC_TYPE_OPERAND) 762102550Siwasaki { 763123315Snjl ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: [%s]\n", 764123315Snjl AcpiUtGetDescriptorName (CurrentObjDesc))); 765102550Siwasaki return_ACPI_STATUS (AE_AML_INTERNAL); 766102550Siwasaki } 76767754Smsmith 768114237Snjl /* 769102550Siwasaki * If we have a valid reference object that came from RefOf(), do the 770102550Siwasaki * indirect store 771102550Siwasaki */ 772107325Siwasaki if ((CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) && 773102550Siwasaki (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP)) 774102550Siwasaki { 775102550Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 776123315Snjl "Arg (%p) is an ObjRef(Node), storing in node %p\n", 777123315Snjl NewObjDesc, CurrentObjDesc)); 77867754Smsmith 779102550Siwasaki /* 780128212Snjl * Store this object to the Node (perform the indirect store) 781128212Snjl * NOTE: No implicit conversion is performed, as per the ACPI 782128212Snjl * specification rules on storing to Locals/Args. 783102550Siwasaki */ 784123315Snjl Status = AcpiExStoreObjectToNode (NewObjDesc, 785128212Snjl CurrentObjDesc->Reference.Object, WalkState, 786128212Snjl ACPI_NO_IMPLICIT_CONVERSION); 787123315Snjl 788123315Snjl /* Remove local reference if we copied the object above */ 789123315Snjl 790123315Snjl if (NewObjDesc != ObjDesc) 791123315Snjl { 792123315Snjl AcpiUtRemoveReference (NewObjDesc); 793123315Snjl } 794102550Siwasaki return_ACPI_STATUS (Status); 795102550Siwasaki } 79667754Smsmith } 79767754Smsmith 79867754Smsmith /* 79971867Smsmith * Delete the existing object 80067754Smsmith * before storing the new one 80167754Smsmith */ 80277424Smsmith AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState); 80367754Smsmith } 80467754Smsmith 80567754Smsmith /* 806123315Snjl * Install the Obj descriptor (*NewObjDesc) into 80767754Smsmith * the descriptor for the Arg or Local. 80867754Smsmith * (increments the object reference count by one) 80967754Smsmith */ 810123315Snjl Status = AcpiDsMethodDataSetValue (Opcode, Index, NewObjDesc, WalkState); 811123315Snjl 812123315Snjl /* Remove local reference if we copied the object above */ 813123315Snjl 814123315Snjl if (NewObjDesc != ObjDesc) 815123315Snjl { 816123315Snjl AcpiUtRemoveReference (NewObjDesc); 817123315Snjl } 818123315Snjl 81967754Smsmith return_ACPI_STATUS (Status); 82067754Smsmith} 82167754Smsmith 82287031Smsmith 823