dsmthdat.c revision 193267
167754Smsmith/******************************************************************************* 267754Smsmith * 367754Smsmith * Module Name: dsmthdat - control method arguments and local variables 467754Smsmith * 567754Smsmith ******************************************************************************/ 667754Smsmith 767754Smsmith/****************************************************************************** 867754Smsmith * 967754Smsmith * 1. Copyright Notice 1067754Smsmith * 11193267Sjkim * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp. 1270243Smsmith * All rights reserved. 1367754Smsmith * 1467754Smsmith * 2. License 1567754Smsmith * 1667754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property 1767754Smsmith * rights. You may have additional license terms from the party that provided 1867754Smsmith * you this software, covering your right to use that party's intellectual 1967754Smsmith * property rights. 2067754Smsmith * 2167754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a 2267754Smsmith * copy of the source code appearing in this file ("Covered Code") an 2367754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the 2467754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy, 2567754Smsmith * make derivatives, distribute, use and display any portion of the Covered 2667754Smsmith * Code in any form, with the right to sublicense such rights; and 2767754Smsmith * 2867754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent 2967754Smsmith * license (with the right to sublicense), under only those claims of Intel 3067754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell, 3167754Smsmith * offer to sell, and import the Covered Code and derivative works thereof 3267754Smsmith * solely to the minimum extent necessary to exercise the above copyright 3367754Smsmith * license, and in no event shall the patent license extend to any additions 3467754Smsmith * to or modifications of the Original Intel Code. No other license or right 3567754Smsmith * is granted directly or by implication, estoppel or otherwise; 3667754Smsmith * 3767754Smsmith * The above copyright and patent license is granted only if the following 3867754Smsmith * conditions are met: 3967754Smsmith * 4067754Smsmith * 3. Conditions 4167754Smsmith * 4267754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source. 4367754Smsmith * Redistribution of source code of any substantial portion of the Covered 4467754Smsmith * Code or modification with rights to further distribute source must include 4567754Smsmith * the above Copyright Notice, the above License, this list of Conditions, 4667754Smsmith * and the following Disclaimer and Export Compliance provision. In addition, 4767754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to 4867754Smsmith * contain a file documenting the changes Licensee made to create that Covered 4967754Smsmith * Code and the date of any change. Licensee must include in that file the 5067754Smsmith * documentation of any changes made by any predecessor Licensee. Licensee 5167754Smsmith * must include a prominent statement that the modification is derived, 5267754Smsmith * directly or indirectly, from Original Intel Code. 5367754Smsmith * 5467754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source. 5567754Smsmith * Redistribution of source code of any substantial portion of the Covered 5667754Smsmith * Code or modification without rights to further distribute source must 5767754Smsmith * include the following Disclaimer and Export Compliance provision in the 5867754Smsmith * documentation and/or other materials provided with distribution. In 5967754Smsmith * addition, Licensee may not authorize further sublicense of source of any 6067754Smsmith * portion of the Covered Code, and must include terms to the effect that the 6167754Smsmith * license from Licensee to its licensee is limited to the intellectual 6267754Smsmith * property embodied in the software Licensee provides to its licensee, and 6367754Smsmith * not to intellectual property embodied in modifications its licensee may 6467754Smsmith * make. 6567754Smsmith * 6667754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any 6767754Smsmith * substantial portion of the Covered Code or modification must reproduce the 6867754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance 6967754Smsmith * provision in the documentation and/or other materials provided with the 7067754Smsmith * distribution. 7167754Smsmith * 7267754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original 7367754Smsmith * Intel Code. 7467754Smsmith * 7567754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by 7667754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or 7767754Smsmith * other dealings in products derived from or relating to the Covered Code 7867754Smsmith * without prior written authorization from Intel. 7967754Smsmith * 8067754Smsmith * 4. Disclaimer and Export Compliance 8167754Smsmith * 8267754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED 8367754Smsmith * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE 8467754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE, 8567754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY 8667754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY 8767754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A 8867754Smsmith * PARTICULAR PURPOSE. 8967754Smsmith * 9067754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES 9167754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR 9267754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT, 9367754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY 9467754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL 9567754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS 9667754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY 9767754Smsmith * LIMITED REMEDY. 9867754Smsmith * 9967754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this 10067754Smsmith * software or system incorporating such software without first obtaining any 10167754Smsmith * required license or other approval from the U. S. Department of Commerce or 10267754Smsmith * any other agency or department of the United States Government. In the 10367754Smsmith * event Licensee exports any such software from the United States or 10467754Smsmith * re-exports any such software from a foreign destination, Licensee shall 10567754Smsmith * ensure that the distribution and export/re-export of the software is in 10667754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the 10767754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor 10867754Smsmith * any of its subsidiaries will export/re-export any technical data, process, 10967754Smsmith * software, or service, directly or indirectly, to any country for which the 11067754Smsmith * United States government or any agency thereof requires an export license, 11167754Smsmith * other governmental approval, or letter of assurance, without first obtaining 11267754Smsmith * such license, approval or letter. 11367754Smsmith * 11467754Smsmith *****************************************************************************/ 11567754Smsmith 11667754Smsmith#define __DSMTHDAT_C__ 11767754Smsmith 118193251Sjkim#include "acpi.h" 119193267Sjkim#include "accommon.h" 120193251Sjkim#include "acdispat.h" 121193251Sjkim#include "acnamesp.h" 122193251Sjkim#include "acinterp.h" 12367754Smsmith 12467754Smsmith 12577424Smsmith#define _COMPONENT ACPI_DISPATCHER 12691116Smsmith ACPI_MODULE_NAME ("dsmthdat") 12767754Smsmith 128151937Sjkim/* Local prototypes */ 12967754Smsmith 130151937Sjkimstatic void 131151937SjkimAcpiDsMethodDataDeleteValue ( 132193267Sjkim UINT8 Type, 133151937Sjkim UINT32 Index, 134151937Sjkim ACPI_WALK_STATE *WalkState); 135151937Sjkim 136151937Sjkimstatic ACPI_STATUS 137151937SjkimAcpiDsMethodDataSetValue ( 138193267Sjkim UINT8 Type, 139151937Sjkim UINT32 Index, 140151937Sjkim ACPI_OPERAND_OBJECT *Object, 141151937Sjkim ACPI_WALK_STATE *WalkState); 142151937Sjkim 143151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 144151937SjkimACPI_OBJECT_TYPE 145151937SjkimAcpiDsMethodDataGetType ( 146151937Sjkim UINT16 Opcode, 147151937Sjkim UINT32 Index, 148151937Sjkim ACPI_WALK_STATE *WalkState); 149151937Sjkim#endif 150151937Sjkim 151151937Sjkim 15267754Smsmith/******************************************************************************* 15367754Smsmith * 15467754Smsmith * FUNCTION: AcpiDsMethodDataInit 15567754Smsmith * 15671867Smsmith * PARAMETERS: WalkState - Current walk state object 15767754Smsmith * 15867754Smsmith * RETURN: Status 15967754Smsmith * 16067754Smsmith * DESCRIPTION: Initialize the data structures that hold the method's arguments 161151937Sjkim * and locals. The data struct is an array of namespace nodes for 162151937Sjkim * each - this allows RefOf and DeRefOf to work properly for these 16367754Smsmith * special data types. 16467754Smsmith * 16587031Smsmith * NOTES: WalkState fields are initialized to zero by the 166167802Sjkim * ACPI_ALLOCATE_ZEROED(). 16787031Smsmith * 16887031Smsmith * A pseudo-Namespace Node is assigned to each argument and local 16987031Smsmith * so that RefOf() can return a pointer to the Node. 17087031Smsmith * 17167754Smsmith ******************************************************************************/ 17267754Smsmith 17399679Siwasakivoid 17467754SmsmithAcpiDsMethodDataInit ( 17567754Smsmith ACPI_WALK_STATE *WalkState) 17667754Smsmith{ 17767754Smsmith UINT32 i; 17867754Smsmith 17967754Smsmith 180167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataInit); 18167754Smsmith 18267754Smsmith 18367754Smsmith /* Init the method arguments */ 18467754Smsmith 185114237Snjl for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) 18667754Smsmith { 187167802Sjkim ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, NAMEOF_ARG_NTE); 18899146Siwasaki WalkState->Arguments[i].Name.Integer |= (i << 24); 189167802Sjkim WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED; 190167802Sjkim WalkState->Arguments[i].Type = ACPI_TYPE_ANY; 191167802Sjkim WalkState->Arguments[i].Flags = 192167802Sjkim ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG; 19367754Smsmith } 19467754Smsmith 19567754Smsmith /* Init the method locals */ 19667754Smsmith 197114237Snjl for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) 19867754Smsmith { 199167802Sjkim ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, NAMEOF_LOCAL_NTE); 20067754Smsmith 20199146Siwasaki WalkState->LocalVariables[i].Name.Integer |= (i << 24); 202167802Sjkim WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED; 203167802Sjkim WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY; 204167802Sjkim WalkState->LocalVariables[i].Flags = 205167802Sjkim ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL; 20667754Smsmith } 20767754Smsmith 20899679Siwasaki return_VOID; 20967754Smsmith} 21067754Smsmith 21167754Smsmith 21267754Smsmith/******************************************************************************* 21367754Smsmith * 21467754Smsmith * FUNCTION: AcpiDsMethodDataDeleteAll 21567754Smsmith * 21671867Smsmith * PARAMETERS: WalkState - Current walk state object 21767754Smsmith * 21899679Siwasaki * RETURN: None 21967754Smsmith * 22067754Smsmith * DESCRIPTION: Delete method locals and arguments. Arguments are only 22167754Smsmith * deleted if this method was called from another method. 22267754Smsmith * 22367754Smsmith ******************************************************************************/ 22467754Smsmith 22599679Siwasakivoid 22667754SmsmithAcpiDsMethodDataDeleteAll ( 22767754Smsmith ACPI_WALK_STATE *WalkState) 22867754Smsmith{ 22967754Smsmith UINT32 Index; 23067754Smsmith 23167754Smsmith 232167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll); 23367754Smsmith 23467754Smsmith 23587031Smsmith /* Detach the locals */ 23667754Smsmith 237114237Snjl for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++) 23867754Smsmith { 23987031Smsmith if (WalkState->LocalVariables[Index].Object) 24067754Smsmith { 24187031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n", 24287031Smsmith Index, WalkState->LocalVariables[Index].Object)); 24367754Smsmith 24487031Smsmith /* Detach object (if present) and remove a reference */ 24567754Smsmith 24687031Smsmith AcpiNsDetachObject (&WalkState->LocalVariables[Index]); 24799679Siwasaki } 24867754Smsmith } 24967754Smsmith 25087031Smsmith /* Detach the arguments */ 25167754Smsmith 252114237Snjl for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++) 25367754Smsmith { 25487031Smsmith if (WalkState->Arguments[Index].Object) 25567754Smsmith { 25687031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n", 25787031Smsmith Index, WalkState->Arguments[Index].Object)); 25867754Smsmith 25987031Smsmith /* Detach object (if present) and remove a reference */ 26067754Smsmith 26187031Smsmith AcpiNsDetachObject (&WalkState->Arguments[Index]); 26267754Smsmith } 26367754Smsmith } 26467754Smsmith 26599679Siwasaki return_VOID; 26667754Smsmith} 26767754Smsmith 26867754Smsmith 26967754Smsmith/******************************************************************************* 27067754Smsmith * 27167754Smsmith * FUNCTION: AcpiDsMethodDataInitArgs 27267754Smsmith * 27371867Smsmith * PARAMETERS: *Params - Pointer to a parameter list for the method 27471867Smsmith * MaxParamCount - The arg count for this method 27571867Smsmith * WalkState - Current walk state object 27667754Smsmith * 27767754Smsmith * RETURN: Status 27867754Smsmith * 27987031Smsmith * DESCRIPTION: Initialize arguments for a method. The parameter list is a list 28087031Smsmith * of ACPI operand objects, either null terminated or whose length 28187031Smsmith * is defined by MaxParamCount. 28267754Smsmith * 28367754Smsmith ******************************************************************************/ 28467754Smsmith 28567754SmsmithACPI_STATUS 28667754SmsmithAcpiDsMethodDataInitArgs ( 28767754Smsmith ACPI_OPERAND_OBJECT **Params, 28867754Smsmith UINT32 MaxParamCount, 28967754Smsmith ACPI_WALK_STATE *WalkState) 29067754Smsmith{ 29167754Smsmith ACPI_STATUS Status; 29287031Smsmith UINT32 Index = 0; 29367754Smsmith 29467754Smsmith 295167802Sjkim ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params); 29667754Smsmith 29767754Smsmith 29867754Smsmith if (!Params) 29967754Smsmith { 30082367Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n")); 30167754Smsmith return_ACPI_STATUS (AE_OK); 30267754Smsmith } 30367754Smsmith 304151937Sjkim /* Copy passed parameters into the new method stack frame */ 30567754Smsmith 306151937Sjkim while ((Index < ACPI_METHOD_NUM_ARGS) && 307151937Sjkim (Index < MaxParamCount) && 308151937Sjkim Params[Index]) 30967754Smsmith { 31087031Smsmith /* 31187031Smsmith * A valid parameter. 312126372Snjl * Store the argument in the method/walk descriptor. 313126372Snjl * Do not copy the arg in order to implement call by reference 31487031Smsmith */ 315193267Sjkim Status = AcpiDsMethodDataSetValue (ACPI_REFCLASS_ARG, Index, 316151937Sjkim Params[Index], WalkState); 31787031Smsmith if (ACPI_FAILURE (Status)) 31867754Smsmith { 31987031Smsmith return_ACPI_STATUS (Status); 32067754Smsmith } 32167754Smsmith 32287031Smsmith Index++; 32367754Smsmith } 32467754Smsmith 32587031Smsmith ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index)); 32667754Smsmith return_ACPI_STATUS (AE_OK); 32767754Smsmith} 32867754Smsmith 32967754Smsmith 33067754Smsmith/******************************************************************************* 33167754Smsmith * 33287031Smsmith * FUNCTION: AcpiDsMethodDataGetNode 33367754Smsmith * 334193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 335193267Sjkim * ACPI_REFCLASS_ARG 336151937Sjkim * Index - Which Local or Arg whose type to get 33771867Smsmith * WalkState - Current walk state object 338151937Sjkim * Node - Where the node is returned. 33967754Smsmith * 340151937Sjkim * RETURN: Status and node 34167754Smsmith * 342151937Sjkim * DESCRIPTION: Get the Node associated with a local or arg. 343151937Sjkim * 34467754Smsmith ******************************************************************************/ 34567754Smsmith 34667754SmsmithACPI_STATUS 34787031SmsmithAcpiDsMethodDataGetNode ( 348193267Sjkim UINT8 Type, 34967754Smsmith UINT32 Index, 35067754Smsmith ACPI_WALK_STATE *WalkState, 35187031Smsmith ACPI_NAMESPACE_NODE **Node) 35267754Smsmith{ 353167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataGetNode); 35467754Smsmith 35567754Smsmith 35667754Smsmith /* 35787031Smsmith * Method Locals and Arguments are supported 35867754Smsmith */ 359193267Sjkim switch (Type) 36067754Smsmith { 361193267Sjkim case ACPI_REFCLASS_LOCAL: 36267754Smsmith 363114237Snjl if (Index > ACPI_METHOD_MAX_LOCAL) 36467754Smsmith { 365167802Sjkim ACPI_ERROR ((AE_INFO, 366167802Sjkim "Local index %d is invalid (max %d)", 367114237Snjl Index, ACPI_METHOD_MAX_LOCAL)); 36887031Smsmith return_ACPI_STATUS (AE_AML_INVALID_INDEX); 36967754Smsmith } 37067754Smsmith 37187031Smsmith /* Return a pointer to the pseudo-node */ 37287031Smsmith 37387031Smsmith *Node = &WalkState->LocalVariables[Index]; 37467754Smsmith break; 37567754Smsmith 376193267Sjkim case ACPI_REFCLASS_ARG: 37767754Smsmith 378114237Snjl if (Index > ACPI_METHOD_MAX_ARG) 37967754Smsmith { 380167802Sjkim ACPI_ERROR ((AE_INFO, 381167802Sjkim "Arg index %d is invalid (max %d)", 382114237Snjl Index, ACPI_METHOD_MAX_ARG)); 38387031Smsmith return_ACPI_STATUS (AE_AML_INVALID_INDEX); 38467754Smsmith } 38567754Smsmith 38687031Smsmith /* Return a pointer to the pseudo-node */ 38787031Smsmith 38887031Smsmith *Node = &WalkState->Arguments[Index]; 38967754Smsmith break; 39067754Smsmith 39167754Smsmith default: 392193267Sjkim ACPI_ERROR ((AE_INFO, "Type %d is invalid", Type)); 393193267Sjkim return_ACPI_STATUS (AE_TYPE); 39467754Smsmith } 39567754Smsmith 39667754Smsmith return_ACPI_STATUS (AE_OK); 39767754Smsmith} 39867754Smsmith 39967754Smsmith 40067754Smsmith/******************************************************************************* 40167754Smsmith * 40287031Smsmith * FUNCTION: AcpiDsMethodDataSetValue 40367754Smsmith * 404193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 405193267Sjkim * ACPI_REFCLASS_ARG 406151937Sjkim * Index - Which Local or Arg to get 40767754Smsmith * Object - Object to be inserted into the stack entry 40871867Smsmith * WalkState - Current walk state object 40967754Smsmith * 41067754Smsmith * RETURN: Status 41167754Smsmith * 41277424Smsmith * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index. 413114237Snjl * Note: There is no "implicit conversion" for locals. 41467754Smsmith * 41567754Smsmith ******************************************************************************/ 41667754Smsmith 417151937Sjkimstatic ACPI_STATUS 41887031SmsmithAcpiDsMethodDataSetValue ( 419193267Sjkim UINT8 Type, 42067754Smsmith UINT32 Index, 42167754Smsmith ACPI_OPERAND_OBJECT *Object, 42267754Smsmith ACPI_WALK_STATE *WalkState) 42367754Smsmith{ 42467754Smsmith ACPI_STATUS Status; 42587031Smsmith ACPI_NAMESPACE_NODE *Node; 42667754Smsmith 42767754Smsmith 428167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataSetValue); 42967754Smsmith 43083174Smsmith 431114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 432193267Sjkim "NewObj %p Type %2.2X, Refs=%d [%s]\n", Object, 433193267Sjkim Type, Object->Common.ReferenceCount, 434114237Snjl AcpiUtGetTypeName (Object->Common.Type))); 435114237Snjl 43687031Smsmith /* Get the namespace node for the arg/local */ 43767754Smsmith 438193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 43967754Smsmith if (ACPI_FAILURE (Status)) 44067754Smsmith { 44167754Smsmith return_ACPI_STATUS (Status); 44267754Smsmith } 44367754Smsmith 444123315Snjl /* 445122945Snjl * Increment ref count so object can't be deleted while installed. 446122945Snjl * NOTE: We do not copy the object in order to preserve the call by 447122945Snjl * reference semantics of ACPI Control Method invocation. 448122945Snjl * (See ACPI Specification 2.0C) 449114237Snjl */ 450122945Snjl AcpiUtAddReference (Object); 45167754Smsmith 452114237Snjl /* Install the object */ 453114237Snjl 454122945Snjl Node->Object = Object; 455114237Snjl return_ACPI_STATUS (Status); 45667754Smsmith} 45767754Smsmith 45867754Smsmith 45967754Smsmith/******************************************************************************* 46067754Smsmith * 46167754Smsmith * FUNCTION: AcpiDsMethodDataGetValue 46267754Smsmith * 463193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 464193267Sjkim * ACPI_REFCLASS_ARG 46567754Smsmith * Index - Which localVar or argument to get 46671867Smsmith * WalkState - Current walk state object 467151937Sjkim * DestDesc - Where Arg or Local value is returned 46867754Smsmith * 46967754Smsmith * RETURN: Status 47067754Smsmith * 471151937Sjkim * DESCRIPTION: Retrieve value of selected Arg or Local for this method 47277424Smsmith * Used only in AcpiExResolveToValue(). 47367754Smsmith * 47467754Smsmith ******************************************************************************/ 47567754Smsmith 47667754SmsmithACPI_STATUS 47767754SmsmithAcpiDsMethodDataGetValue ( 478193267Sjkim UINT8 Type, 47967754Smsmith UINT32 Index, 48067754Smsmith ACPI_WALK_STATE *WalkState, 48167754Smsmith ACPI_OPERAND_OBJECT **DestDesc) 48267754Smsmith{ 48367754Smsmith ACPI_STATUS Status; 48487031Smsmith ACPI_NAMESPACE_NODE *Node; 48567754Smsmith ACPI_OPERAND_OBJECT *Object; 48667754Smsmith 48767754Smsmith 488167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataGetValue); 48967754Smsmith 49067754Smsmith 49167754Smsmith /* Validate the object descriptor */ 49267754Smsmith 49367754Smsmith if (!DestDesc) 49467754Smsmith { 495167802Sjkim ACPI_ERROR ((AE_INFO, "Null object descriptor pointer")); 49667754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 49767754Smsmith } 49867754Smsmith 49987031Smsmith /* Get the namespace node for the arg/local */ 50067754Smsmith 501193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 50267754Smsmith if (ACPI_FAILURE (Status)) 50367754Smsmith { 50467754Smsmith return_ACPI_STATUS (Status); 50567754Smsmith } 50667754Smsmith 50787031Smsmith /* Get the object from the node */ 50867754Smsmith 50987031Smsmith Object = Node->Object; 51067754Smsmith 51167754Smsmith /* Examine the returned object, it must be valid. */ 51267754Smsmith 51367754Smsmith if (!Object) 51467754Smsmith { 51567754Smsmith /* 51687031Smsmith * Index points to uninitialized object. 51767754Smsmith * This means that either 1) The expected argument was 51867754Smsmith * not passed to the method, or 2) A local variable 51967754Smsmith * was referenced by the method (via the ASL) 52067754Smsmith * before it was initialized. Either case is an error. 52167754Smsmith */ 522138287Smarks 523138287Smarks /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */ 524138287Smarks 525138287Smarks if (AcpiGbl_EnableInterpreterSlack) 52667754Smsmith { 527138287Smarks Object = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER); 528138287Smarks if (!Object) 529138287Smarks { 530138287Smarks return_ACPI_STATUS (AE_NO_MEMORY); 531138287Smarks } 532138287Smarks 533138287Smarks Object->Integer.Value = 0; 534138287Smarks Node->Object = Object; 535138287Smarks } 536138287Smarks 537138287Smarks /* Otherwise, return the error */ 538138287Smarks 539193267Sjkim else switch (Type) 540138287Smarks { 541193267Sjkim case ACPI_REFCLASS_ARG: 54271867Smsmith 543167802Sjkim ACPI_ERROR ((AE_INFO, 544167802Sjkim "Uninitialized Arg[%d] at node %p", 54587031Smsmith Index, Node)); 54671867Smsmith 54767754Smsmith return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG); 54867754Smsmith 549193267Sjkim case ACPI_REFCLASS_LOCAL: 55071867Smsmith 551167802Sjkim ACPI_ERROR ((AE_INFO, 552193267Sjkim "Uninitialized Local[%d] at node %p", Index, Node)); 55371867Smsmith 55467754Smsmith return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 55599679Siwasaki 55699679Siwasaki default: 557193267Sjkim 558193267Sjkim ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: %X", Type)); 55999679Siwasaki return_ACPI_STATUS (AE_AML_INTERNAL); 56067754Smsmith } 56167754Smsmith } 56267754Smsmith 56367754Smsmith /* 56487031Smsmith * The Index points to an initialized and valid object. 56567754Smsmith * Return an additional reference to the object 56667754Smsmith */ 56767754Smsmith *DestDesc = Object; 56877424Smsmith AcpiUtAddReference (Object); 56967754Smsmith 57067754Smsmith return_ACPI_STATUS (AE_OK); 57167754Smsmith} 57267754Smsmith 57367754Smsmith 57467754Smsmith/******************************************************************************* 57567754Smsmith * 57667754Smsmith * FUNCTION: AcpiDsMethodDataDeleteValue 57767754Smsmith * 578193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 579193267Sjkim * ACPI_REFCLASS_ARG 58067754Smsmith * Index - Which localVar or argument to delete 58171867Smsmith * WalkState - Current walk state object 58267754Smsmith * 58399679Siwasaki * RETURN: None 58467754Smsmith * 585151937Sjkim * DESCRIPTION: Delete the entry at Opcode:Index. Inserts 58667754Smsmith * a null into the stack slot after the object is deleted. 58767754Smsmith * 58867754Smsmith ******************************************************************************/ 58967754Smsmith 590151937Sjkimstatic void 59167754SmsmithAcpiDsMethodDataDeleteValue ( 592193267Sjkim UINT8 Type, 59367754Smsmith UINT32 Index, 59467754Smsmith ACPI_WALK_STATE *WalkState) 59567754Smsmith{ 59667754Smsmith ACPI_STATUS Status; 59787031Smsmith ACPI_NAMESPACE_NODE *Node; 59867754Smsmith ACPI_OPERAND_OBJECT *Object; 59967754Smsmith 60067754Smsmith 601167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue); 60267754Smsmith 60367754Smsmith 60487031Smsmith /* Get the namespace node for the arg/local */ 60567754Smsmith 606193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 60767754Smsmith if (ACPI_FAILURE (Status)) 60867754Smsmith { 60999679Siwasaki return_VOID; 61067754Smsmith } 61167754Smsmith 61287031Smsmith /* Get the associated object */ 61367754Smsmith 61487031Smsmith Object = AcpiNsGetAttachedObject (Node); 61567754Smsmith 61667754Smsmith /* 61767754Smsmith * Undefine the Arg or Local by setting its descriptor 61867754Smsmith * pointer to NULL. Locals/Args can contain both 61967754Smsmith * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs 62067754Smsmith */ 62187031Smsmith Node->Object = NULL; 62267754Smsmith 62367754Smsmith if ((Object) && 62499679Siwasaki (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND)) 62567754Smsmith { 62667754Smsmith /* 62787031Smsmith * There is a valid object. 62867754Smsmith * Decrement the reference count by one to balance the 62987031Smsmith * increment when the object was stored. 63067754Smsmith */ 63177424Smsmith AcpiUtRemoveReference (Object); 63267754Smsmith } 63367754Smsmith 63499679Siwasaki return_VOID; 63567754Smsmith} 63667754Smsmith 63767754Smsmith 63867754Smsmith/******************************************************************************* 63967754Smsmith * 64077424Smsmith * FUNCTION: AcpiDsStoreObjectToLocal 64167754Smsmith * 642193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 643193267Sjkim * ACPI_REFCLASS_ARG 644151937Sjkim * Index - Which Local or Arg to set 64587031Smsmith * ObjDesc - Value to be stored 64671867Smsmith * WalkState - Current walk state 64767754Smsmith * 64867754Smsmith * RETURN: Status 64967754Smsmith * 65087031Smsmith * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed 65167754Smsmith * as the new value for the Arg or Local and the reference count 65287031Smsmith * for ObjDesc is incremented. 65367754Smsmith * 65467754Smsmith ******************************************************************************/ 65567754Smsmith 65667754SmsmithACPI_STATUS 65777424SmsmithAcpiDsStoreObjectToLocal ( 658193267Sjkim UINT8 Type, 65967754Smsmith UINT32 Index, 66087031Smsmith ACPI_OPERAND_OBJECT *ObjDesc, 66167754Smsmith ACPI_WALK_STATE *WalkState) 66267754Smsmith{ 66367754Smsmith ACPI_STATUS Status; 66487031Smsmith ACPI_NAMESPACE_NODE *Node; 66587031Smsmith ACPI_OPERAND_OBJECT *CurrentObjDesc; 666123315Snjl ACPI_OPERAND_OBJECT *NewObjDesc; 66767754Smsmith 66867754Smsmith 669167802Sjkim ACPI_FUNCTION_TRACE (DsStoreObjectToLocal); 670193267Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%d Obj=%p\n", 671193267Sjkim Type, Index, ObjDesc)); 67267754Smsmith 67367754Smsmith /* Parameter validation */ 67467754Smsmith 67587031Smsmith if (!ObjDesc) 67667754Smsmith { 67767754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 67867754Smsmith } 67967754Smsmith 68087031Smsmith /* Get the namespace node for the arg/local */ 68167754Smsmith 682193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 68367754Smsmith if (ACPI_FAILURE (Status)) 68467754Smsmith { 68587031Smsmith return_ACPI_STATUS (Status); 68667754Smsmith } 68767754Smsmith 68887031Smsmith CurrentObjDesc = AcpiNsGetAttachedObject (Node); 68987031Smsmith if (CurrentObjDesc == ObjDesc) 69067754Smsmith { 691114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", 692114237Snjl ObjDesc)); 69387031Smsmith return_ACPI_STATUS (Status); 69467754Smsmith } 69567754Smsmith 69667754Smsmith /* 697123315Snjl * If the reference count on the object is more than one, we must 698126372Snjl * take a copy of the object before we store. A reference count 699126372Snjl * of exactly 1 means that the object was just created during the 700126372Snjl * evaluation of an expression, and we can safely use it since it 701126372Snjl * is not used anywhere else. 702123315Snjl */ 703123315Snjl NewObjDesc = ObjDesc; 704126372Snjl if (ObjDesc->Common.ReferenceCount > 1) 705123315Snjl { 706123315Snjl Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState); 707123315Snjl if (ACPI_FAILURE (Status)) 708123315Snjl { 709123315Snjl return_ACPI_STATUS (Status); 710123315Snjl } 711123315Snjl } 712123315Snjl 713123315Snjl /* 71467754Smsmith * If there is an object already in this slot, we either 71567754Smsmith * have to delete it, or if this is an argument and there 71667754Smsmith * is an object reference stored there, we have to do 71767754Smsmith * an indirect store! 71867754Smsmith */ 71987031Smsmith if (CurrentObjDesc) 72067754Smsmith { 72167754Smsmith /* 72267754Smsmith * Check for an indirect store if an argument 72367754Smsmith * contains an object reference (stored as an Node). 72467754Smsmith * We don't allow this automatic dereferencing for 72567754Smsmith * locals, since a store to a local should overwrite 72667754Smsmith * anything there, including an object reference. 72767754Smsmith * 72867754Smsmith * If both Arg0 and Local0 contain RefOf (Local4): 72967754Smsmith * 73067754Smsmith * Store (1, Arg0) - Causes indirect store to local4 73167754Smsmith * Store (1, Local0) - Stores 1 in local0, overwriting 73267754Smsmith * the reference to local4 73367754Smsmith * Store (1, DeRefof (Local0)) - Causes indirect store to local4 73467754Smsmith * 73567754Smsmith * Weird, but true. 73667754Smsmith */ 737193267Sjkim if (Type == ACPI_REFCLASS_ARG) 73867754Smsmith { 739114237Snjl /* 740151937Sjkim * If we have a valid reference object that came from RefOf(), 741151937Sjkim * do the indirect store 742102550Siwasaki */ 743151937Sjkim if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) && 744151937Sjkim (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) && 745193267Sjkim (CurrentObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)) 746102550Siwasaki { 747102550Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 748123315Snjl "Arg (%p) is an ObjRef(Node), storing in node %p\n", 749123315Snjl NewObjDesc, CurrentObjDesc)); 75067754Smsmith 751102550Siwasaki /* 752128212Snjl * Store this object to the Node (perform the indirect store) 753128212Snjl * NOTE: No implicit conversion is performed, as per the ACPI 754128212Snjl * specification rules on storing to Locals/Args. 755102550Siwasaki */ 756123315Snjl Status = AcpiExStoreObjectToNode (NewObjDesc, 757128212Snjl CurrentObjDesc->Reference.Object, WalkState, 758128212Snjl ACPI_NO_IMPLICIT_CONVERSION); 759123315Snjl 760123315Snjl /* Remove local reference if we copied the object above */ 761123315Snjl 762123315Snjl if (NewObjDesc != ObjDesc) 763123315Snjl { 764123315Snjl AcpiUtRemoveReference (NewObjDesc); 765123315Snjl } 766102550Siwasaki return_ACPI_STATUS (Status); 767102550Siwasaki } 76867754Smsmith } 76967754Smsmith 770193267Sjkim /* Delete the existing object before storing the new one */ 771193267Sjkim 772193267Sjkim AcpiDsMethodDataDeleteValue (Type, Index, WalkState); 77367754Smsmith } 77467754Smsmith 77567754Smsmith /* 776123315Snjl * Install the Obj descriptor (*NewObjDesc) into 77767754Smsmith * the descriptor for the Arg or Local. 77867754Smsmith * (increments the object reference count by one) 77967754Smsmith */ 780193267Sjkim Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState); 781123315Snjl 782123315Snjl /* Remove local reference if we copied the object above */ 783123315Snjl 784123315Snjl if (NewObjDesc != ObjDesc) 785123315Snjl { 786123315Snjl AcpiUtRemoveReference (NewObjDesc); 787123315Snjl } 788123315Snjl 78967754Smsmith return_ACPI_STATUS (Status); 79067754Smsmith} 79167754Smsmith 79287031Smsmith 793151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 794151937Sjkim/******************************************************************************* 795151937Sjkim * 796151937Sjkim * FUNCTION: AcpiDsMethodDataGetType 797151937Sjkim * 798151937Sjkim * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 799151937Sjkim * Index - Which Local or Arg whose type to get 800151937Sjkim * WalkState - Current walk state object 801151937Sjkim * 802151937Sjkim * RETURN: Data type of current value of the selected Arg or Local 803151937Sjkim * 804151937Sjkim * DESCRIPTION: Get the type of the object stored in the Local or Arg 805151937Sjkim * 806151937Sjkim ******************************************************************************/ 807151937Sjkim 808151937SjkimACPI_OBJECT_TYPE 809151937SjkimAcpiDsMethodDataGetType ( 810151937Sjkim UINT16 Opcode, 811151937Sjkim UINT32 Index, 812151937Sjkim ACPI_WALK_STATE *WalkState) 813151937Sjkim{ 814151937Sjkim ACPI_STATUS Status; 815151937Sjkim ACPI_NAMESPACE_NODE *Node; 816151937Sjkim ACPI_OPERAND_OBJECT *Object; 817151937Sjkim 818151937Sjkim 819167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataGetType); 820151937Sjkim 821151937Sjkim 822151937Sjkim /* Get the namespace node for the arg/local */ 823151937Sjkim 824151937Sjkim Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 825151937Sjkim if (ACPI_FAILURE (Status)) 826151937Sjkim { 827151937Sjkim return_VALUE ((ACPI_TYPE_NOT_FOUND)); 828151937Sjkim } 829151937Sjkim 830151937Sjkim /* Get the object */ 831151937Sjkim 832151937Sjkim Object = AcpiNsGetAttachedObject (Node); 833151937Sjkim if (!Object) 834151937Sjkim { 835151937Sjkim /* Uninitialized local/arg, return TYPE_ANY */ 836151937Sjkim 837151937Sjkim return_VALUE (ACPI_TYPE_ANY); 838151937Sjkim } 839151937Sjkim 840151937Sjkim /* Get the object type */ 841151937Sjkim 842193267Sjkim return_VALUE (Object->Type); 843151937Sjkim} 844151937Sjkim#endif 845151937Sjkim 846151937Sjkim 847