dsmthdat.c revision 197104
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 118193341Sjkim#include <contrib/dev/acpica/include/acpi.h> 119193341Sjkim#include <contrib/dev/acpica/include/accommon.h> 120193341Sjkim#include <contrib/dev/acpica/include/acdispat.h> 121193341Sjkim#include <contrib/dev/acpica/include/acnamesp.h> 122193341Sjkim#include <contrib/dev/acpica/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 551197104Sjkim /* 552197104Sjkim * No error message for this case, will be trapped again later to 553197104Sjkim * detect and ignore cases of Store(LocalX,LocalX) 554197104Sjkim */ 55567754Smsmith return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL); 55699679Siwasaki 55799679Siwasaki default: 558193267Sjkim 559193267Sjkim ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: %X", Type)); 56099679Siwasaki return_ACPI_STATUS (AE_AML_INTERNAL); 56167754Smsmith } 56267754Smsmith } 56367754Smsmith 56467754Smsmith /* 56587031Smsmith * The Index points to an initialized and valid object. 56667754Smsmith * Return an additional reference to the object 56767754Smsmith */ 56867754Smsmith *DestDesc = Object; 56977424Smsmith AcpiUtAddReference (Object); 57067754Smsmith 57167754Smsmith return_ACPI_STATUS (AE_OK); 57267754Smsmith} 57367754Smsmith 57467754Smsmith 57567754Smsmith/******************************************************************************* 57667754Smsmith * 57767754Smsmith * FUNCTION: AcpiDsMethodDataDeleteValue 57867754Smsmith * 579193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 580193267Sjkim * ACPI_REFCLASS_ARG 58167754Smsmith * Index - Which localVar or argument to delete 58271867Smsmith * WalkState - Current walk state object 58367754Smsmith * 58499679Siwasaki * RETURN: None 58567754Smsmith * 586151937Sjkim * DESCRIPTION: Delete the entry at Opcode:Index. Inserts 58767754Smsmith * a null into the stack slot after the object is deleted. 58867754Smsmith * 58967754Smsmith ******************************************************************************/ 59067754Smsmith 591151937Sjkimstatic void 59267754SmsmithAcpiDsMethodDataDeleteValue ( 593193267Sjkim UINT8 Type, 59467754Smsmith UINT32 Index, 59567754Smsmith ACPI_WALK_STATE *WalkState) 59667754Smsmith{ 59767754Smsmith ACPI_STATUS Status; 59887031Smsmith ACPI_NAMESPACE_NODE *Node; 59967754Smsmith ACPI_OPERAND_OBJECT *Object; 60067754Smsmith 60167754Smsmith 602167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue); 60367754Smsmith 60467754Smsmith 60587031Smsmith /* Get the namespace node for the arg/local */ 60667754Smsmith 607193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 60867754Smsmith if (ACPI_FAILURE (Status)) 60967754Smsmith { 61099679Siwasaki return_VOID; 61167754Smsmith } 61267754Smsmith 61387031Smsmith /* Get the associated object */ 61467754Smsmith 61587031Smsmith Object = AcpiNsGetAttachedObject (Node); 61667754Smsmith 61767754Smsmith /* 61867754Smsmith * Undefine the Arg or Local by setting its descriptor 61967754Smsmith * pointer to NULL. Locals/Args can contain both 62067754Smsmith * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs 62167754Smsmith */ 62287031Smsmith Node->Object = NULL; 62367754Smsmith 62467754Smsmith if ((Object) && 62599679Siwasaki (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND)) 62667754Smsmith { 62767754Smsmith /* 62887031Smsmith * There is a valid object. 62967754Smsmith * Decrement the reference count by one to balance the 63087031Smsmith * increment when the object was stored. 63167754Smsmith */ 63277424Smsmith AcpiUtRemoveReference (Object); 63367754Smsmith } 63467754Smsmith 63599679Siwasaki return_VOID; 63667754Smsmith} 63767754Smsmith 63867754Smsmith 63967754Smsmith/******************************************************************************* 64067754Smsmith * 64177424Smsmith * FUNCTION: AcpiDsStoreObjectToLocal 64267754Smsmith * 643193267Sjkim * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or 644193267Sjkim * ACPI_REFCLASS_ARG 645151937Sjkim * Index - Which Local or Arg to set 64687031Smsmith * ObjDesc - Value to be stored 64771867Smsmith * WalkState - Current walk state 64867754Smsmith * 64967754Smsmith * RETURN: Status 65067754Smsmith * 65187031Smsmith * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed 65267754Smsmith * as the new value for the Arg or Local and the reference count 65387031Smsmith * for ObjDesc is incremented. 65467754Smsmith * 65567754Smsmith ******************************************************************************/ 65667754Smsmith 65767754SmsmithACPI_STATUS 65877424SmsmithAcpiDsStoreObjectToLocal ( 659193267Sjkim UINT8 Type, 66067754Smsmith UINT32 Index, 66187031Smsmith ACPI_OPERAND_OBJECT *ObjDesc, 66267754Smsmith ACPI_WALK_STATE *WalkState) 66367754Smsmith{ 66467754Smsmith ACPI_STATUS Status; 66587031Smsmith ACPI_NAMESPACE_NODE *Node; 66687031Smsmith ACPI_OPERAND_OBJECT *CurrentObjDesc; 667123315Snjl ACPI_OPERAND_OBJECT *NewObjDesc; 66867754Smsmith 66967754Smsmith 670167802Sjkim ACPI_FUNCTION_TRACE (DsStoreObjectToLocal); 671193267Sjkim ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%d Obj=%p\n", 672193267Sjkim Type, Index, ObjDesc)); 67367754Smsmith 67467754Smsmith /* Parameter validation */ 67567754Smsmith 67687031Smsmith if (!ObjDesc) 67767754Smsmith { 67867754Smsmith return_ACPI_STATUS (AE_BAD_PARAMETER); 67967754Smsmith } 68067754Smsmith 68187031Smsmith /* Get the namespace node for the arg/local */ 68267754Smsmith 683193267Sjkim Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node); 68467754Smsmith if (ACPI_FAILURE (Status)) 68567754Smsmith { 68687031Smsmith return_ACPI_STATUS (Status); 68767754Smsmith } 68867754Smsmith 68987031Smsmith CurrentObjDesc = AcpiNsGetAttachedObject (Node); 69087031Smsmith if (CurrentObjDesc == ObjDesc) 69167754Smsmith { 692114237Snjl ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n", 693114237Snjl ObjDesc)); 69487031Smsmith return_ACPI_STATUS (Status); 69567754Smsmith } 69667754Smsmith 69767754Smsmith /* 698123315Snjl * If the reference count on the object is more than one, we must 699126372Snjl * take a copy of the object before we store. A reference count 700126372Snjl * of exactly 1 means that the object was just created during the 701126372Snjl * evaluation of an expression, and we can safely use it since it 702126372Snjl * is not used anywhere else. 703123315Snjl */ 704123315Snjl NewObjDesc = ObjDesc; 705126372Snjl if (ObjDesc->Common.ReferenceCount > 1) 706123315Snjl { 707123315Snjl Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState); 708123315Snjl if (ACPI_FAILURE (Status)) 709123315Snjl { 710123315Snjl return_ACPI_STATUS (Status); 711123315Snjl } 712123315Snjl } 713123315Snjl 714123315Snjl /* 71567754Smsmith * If there is an object already in this slot, we either 71667754Smsmith * have to delete it, or if this is an argument and there 71767754Smsmith * is an object reference stored there, we have to do 71867754Smsmith * an indirect store! 71967754Smsmith */ 72087031Smsmith if (CurrentObjDesc) 72167754Smsmith { 72267754Smsmith /* 72367754Smsmith * Check for an indirect store if an argument 72467754Smsmith * contains an object reference (stored as an Node). 72567754Smsmith * We don't allow this automatic dereferencing for 72667754Smsmith * locals, since a store to a local should overwrite 72767754Smsmith * anything there, including an object reference. 72867754Smsmith * 72967754Smsmith * If both Arg0 and Local0 contain RefOf (Local4): 73067754Smsmith * 73167754Smsmith * Store (1, Arg0) - Causes indirect store to local4 73267754Smsmith * Store (1, Local0) - Stores 1 in local0, overwriting 73367754Smsmith * the reference to local4 73467754Smsmith * Store (1, DeRefof (Local0)) - Causes indirect store to local4 73567754Smsmith * 73667754Smsmith * Weird, but true. 73767754Smsmith */ 738193267Sjkim if (Type == ACPI_REFCLASS_ARG) 73967754Smsmith { 740114237Snjl /* 741151937Sjkim * If we have a valid reference object that came from RefOf(), 742151937Sjkim * do the indirect store 743102550Siwasaki */ 744151937Sjkim if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) && 745151937Sjkim (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) && 746193267Sjkim (CurrentObjDesc->Reference.Class == ACPI_REFCLASS_REFOF)) 747102550Siwasaki { 748102550Siwasaki ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, 749123315Snjl "Arg (%p) is an ObjRef(Node), storing in node %p\n", 750123315Snjl NewObjDesc, CurrentObjDesc)); 75167754Smsmith 752102550Siwasaki /* 753128212Snjl * Store this object to the Node (perform the indirect store) 754128212Snjl * NOTE: No implicit conversion is performed, as per the ACPI 755128212Snjl * specification rules on storing to Locals/Args. 756102550Siwasaki */ 757123315Snjl Status = AcpiExStoreObjectToNode (NewObjDesc, 758128212Snjl CurrentObjDesc->Reference.Object, WalkState, 759128212Snjl ACPI_NO_IMPLICIT_CONVERSION); 760123315Snjl 761123315Snjl /* Remove local reference if we copied the object above */ 762123315Snjl 763123315Snjl if (NewObjDesc != ObjDesc) 764123315Snjl { 765123315Snjl AcpiUtRemoveReference (NewObjDesc); 766123315Snjl } 767102550Siwasaki return_ACPI_STATUS (Status); 768102550Siwasaki } 76967754Smsmith } 77067754Smsmith 771193267Sjkim /* Delete the existing object before storing the new one */ 772193267Sjkim 773193267Sjkim AcpiDsMethodDataDeleteValue (Type, Index, WalkState); 77467754Smsmith } 77567754Smsmith 77667754Smsmith /* 777123315Snjl * Install the Obj descriptor (*NewObjDesc) into 77867754Smsmith * the descriptor for the Arg or Local. 77967754Smsmith * (increments the object reference count by one) 78067754Smsmith */ 781193267Sjkim Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState); 782123315Snjl 783123315Snjl /* Remove local reference if we copied the object above */ 784123315Snjl 785123315Snjl if (NewObjDesc != ObjDesc) 786123315Snjl { 787123315Snjl AcpiUtRemoveReference (NewObjDesc); 788123315Snjl } 789123315Snjl 79067754Smsmith return_ACPI_STATUS (Status); 79167754Smsmith} 79267754Smsmith 79387031Smsmith 794151937Sjkim#ifdef ACPI_OBSOLETE_FUNCTIONS 795151937Sjkim/******************************************************************************* 796151937Sjkim * 797151937Sjkim * FUNCTION: AcpiDsMethodDataGetType 798151937Sjkim * 799151937Sjkim * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP 800151937Sjkim * Index - Which Local or Arg whose type to get 801151937Sjkim * WalkState - Current walk state object 802151937Sjkim * 803151937Sjkim * RETURN: Data type of current value of the selected Arg or Local 804151937Sjkim * 805151937Sjkim * DESCRIPTION: Get the type of the object stored in the Local or Arg 806151937Sjkim * 807151937Sjkim ******************************************************************************/ 808151937Sjkim 809151937SjkimACPI_OBJECT_TYPE 810151937SjkimAcpiDsMethodDataGetType ( 811151937Sjkim UINT16 Opcode, 812151937Sjkim UINT32 Index, 813151937Sjkim ACPI_WALK_STATE *WalkState) 814151937Sjkim{ 815151937Sjkim ACPI_STATUS Status; 816151937Sjkim ACPI_NAMESPACE_NODE *Node; 817151937Sjkim ACPI_OPERAND_OBJECT *Object; 818151937Sjkim 819151937Sjkim 820167802Sjkim ACPI_FUNCTION_TRACE (DsMethodDataGetType); 821151937Sjkim 822151937Sjkim 823151937Sjkim /* Get the namespace node for the arg/local */ 824151937Sjkim 825151937Sjkim Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node); 826151937Sjkim if (ACPI_FAILURE (Status)) 827151937Sjkim { 828151937Sjkim return_VALUE ((ACPI_TYPE_NOT_FOUND)); 829151937Sjkim } 830151937Sjkim 831151937Sjkim /* Get the object */ 832151937Sjkim 833151937Sjkim Object = AcpiNsGetAttachedObject (Node); 834151937Sjkim if (!Object) 835151937Sjkim { 836151937Sjkim /* Uninitialized local/arg, return TYPE_ANY */ 837151937Sjkim 838151937Sjkim return_VALUE (ACPI_TYPE_ANY); 839151937Sjkim } 840151937Sjkim 841151937Sjkim /* Get the object type */ 842151937Sjkim 843193267Sjkim return_VALUE (Object->Type); 844151937Sjkim} 845151937Sjkim#endif 846151937Sjkim 847151937Sjkim 848