1 /*******************************************************************************
3 * Module Name: dsmthdat - control method arguments and local variables
6 ******************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2003, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
116 /* $DragonFly: src/sys/contrib/dev/acpica/Attic/dsmthdat.c,v 1.1 2003/09/24 03:32:15 drhodus Exp $ */
118 #define __DSMTHDAT_C__
121 #include "acdispat.h"
123 #include "acnamesp.h"
124 #include "acinterp.h"
127 #define _COMPONENT ACPI_DISPATCHER
128 ACPI_MODULE_NAME ("dsmthdat")
131 /*******************************************************************************
133 * FUNCTION: AcpiDsMethodDataInit
135 * PARAMETERS: WalkState - Current walk state object
139 * DESCRIPTION: Initialize the data structures that hold the method's arguments
140 * and locals. The data struct is an array of NTEs for each.
141 * This allows RefOf and DeRefOf to work properly for these
142 * special data types.
144 * NOTES: WalkState fields are initialized to zero by the
145 * ACPI_MEM_CALLOCATE().
147 * A pseudo-Namespace Node is assigned to each argument and local
148 * so that RefOf() can return a pointer to the Node.
150 ******************************************************************************/
153 AcpiDsMethodDataInit (
154 ACPI_WALK_STATE *WalkState)
159 ACPI_FUNCTION_TRACE ("DsMethodDataInit");
162 /* Init the method arguments */
164 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
166 ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->Arguments[i].Name,
168 WalkState->Arguments[i].Name.Integer |= (i << 24);
169 WalkState->Arguments[i].Descriptor = ACPI_DESC_TYPE_NAMED;
170 WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
171 WalkState->Arguments[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
174 /* Init the method locals */
176 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
178 ACPI_MOVE_UNALIGNED32_TO_32 (&WalkState->LocalVariables[i].Name,
181 WalkState->LocalVariables[i].Name.Integer |= (i << 24);
182 WalkState->LocalVariables[i].Descriptor = ACPI_DESC_TYPE_NAMED;
183 WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
184 WalkState->LocalVariables[i].Flags = ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
191 /*******************************************************************************
193 * FUNCTION: AcpiDsMethodDataDeleteAll
195 * PARAMETERS: WalkState - Current walk state object
199 * DESCRIPTION: Delete method locals and arguments. Arguments are only
200 * deleted if this method was called from another method.
202 ******************************************************************************/
205 AcpiDsMethodDataDeleteAll (
206 ACPI_WALK_STATE *WalkState)
211 ACPI_FUNCTION_TRACE ("DsMethodDataDeleteAll");
214 /* Detach the locals */
216 for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
218 if (WalkState->LocalVariables[Index].Object)
220 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
221 Index, WalkState->LocalVariables[Index].Object));
223 /* Detach object (if present) and remove a reference */
225 AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
229 /* Detach the arguments */
231 for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
233 if (WalkState->Arguments[Index].Object)
235 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
236 Index, WalkState->Arguments[Index].Object));
238 /* Detach object (if present) and remove a reference */
240 AcpiNsDetachObject (&WalkState->Arguments[Index]);
248 /*******************************************************************************
250 * FUNCTION: AcpiDsMethodDataInitArgs
252 * PARAMETERS: *Params - Pointer to a parameter list for the method
253 * MaxParamCount - The arg count for this method
254 * WalkState - Current walk state object
258 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
259 * of ACPI operand objects, either null terminated or whose length
260 * is defined by MaxParamCount.
262 ******************************************************************************/
265 AcpiDsMethodDataInitArgs (
266 ACPI_OPERAND_OBJECT **Params,
267 UINT32 MaxParamCount,
268 ACPI_WALK_STATE *WalkState)
274 ACPI_FUNCTION_TRACE_PTR ("DsMethodDataInitArgs", Params);
279 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
280 return_ACPI_STATUS (AE_OK);
283 /* Copy passed parameters into the new method stack frame */
285 while ((Index < ACPI_METHOD_NUM_ARGS) && (Index < MaxParamCount) && Params[Index])
289 * Store the argument in the method/walk descriptor
291 Status = AcpiDsStoreObjectToLocal (AML_ARG_OP, Index, Params[Index],
293 if (ACPI_FAILURE (Status))
295 return_ACPI_STATUS (Status);
301 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%d args passed to method\n", Index));
302 return_ACPI_STATUS (AE_OK);
306 /*******************************************************************************
308 * FUNCTION: AcpiDsMethodDataGetNode
310 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
311 * Index - Which localVar or argument whose type
313 * WalkState - Current walk state object
315 * RETURN: Get the Node associated with a local or arg.
317 ******************************************************************************/
320 AcpiDsMethodDataGetNode (
323 ACPI_WALK_STATE *WalkState,
324 ACPI_NAMESPACE_NODE **Node)
326 ACPI_FUNCTION_TRACE ("DsMethodDataGetNode");
330 * Method Locals and Arguments are supported
336 if (Index > ACPI_METHOD_MAX_LOCAL)
338 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Local index %d is invalid (max %d)\n",
339 Index, ACPI_METHOD_MAX_LOCAL));
340 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
343 /* Return a pointer to the pseudo-node */
345 *Node = &WalkState->LocalVariables[Index];
350 if (Index > ACPI_METHOD_MAX_ARG)
352 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Arg index %d is invalid (max %d)\n",
353 Index, ACPI_METHOD_MAX_ARG));
354 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
357 /* Return a pointer to the pseudo-node */
359 *Node = &WalkState->Arguments[Index];
363 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Opcode %d is invalid\n", Opcode));
364 return_ACPI_STATUS (AE_AML_BAD_OPCODE);
367 return_ACPI_STATUS (AE_OK);
371 /*******************************************************************************
373 * FUNCTION: AcpiDsMethodDataSetValue
375 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
376 * Index - Which localVar or argument to get
377 * Object - Object to be inserted into the stack entry
378 * WalkState - Current walk state object
382 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
383 * Note: There is no "implicit conversion" for locals.
385 ******************************************************************************/
388 AcpiDsMethodDataSetValue (
391 ACPI_OPERAND_OBJECT *Object,
392 ACPI_WALK_STATE *WalkState)
395 ACPI_NAMESPACE_NODE *Node;
396 ACPI_OPERAND_OBJECT *NewDesc = Object;
399 ACPI_FUNCTION_TRACE ("DsMethodDataSetValue");
402 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
403 "obj %p op %X, ref count = %d [%s]\n", Object,
404 Opcode, Object->Common.ReferenceCount,
405 AcpiUtGetTypeName (Object->Common.Type)));
407 /* Get the namespace node for the arg/local */
409 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
410 if (ACPI_FAILURE (Status))
412 return_ACPI_STATUS (Status);
416 * If the object has just been created and is not attached to anything,
417 * (the reference count is 1), then we can just store it directly into
418 * the arg/local. Otherwise, we must copy it.
420 if (Object->Common.ReferenceCount > 1)
422 Status = AcpiUtCopyIobjectToIobject (Object, &NewDesc, WalkState);
423 if (ACPI_FAILURE (Status))
425 return_ACPI_STATUS (Status);
428 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Object Copied %p, new %p\n",
433 /* Increment ref count so object can't be deleted while installed */
435 AcpiUtAddReference (NewDesc);
438 /* Install the object */
440 Node->Object = NewDesc;
441 return_ACPI_STATUS (Status);
445 /*******************************************************************************
447 * FUNCTION: AcpiDsMethodDataGetType
449 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
450 * Index - Which localVar or argument whose type
452 * WalkState - Current walk state object
454 * RETURN: Data type of current value of the selected Arg or Local
456 ******************************************************************************/
459 AcpiDsMethodDataGetType (
462 ACPI_WALK_STATE *WalkState)
465 ACPI_NAMESPACE_NODE *Node;
466 ACPI_OPERAND_OBJECT *Object;
469 ACPI_FUNCTION_TRACE ("DsMethodDataGetType");
472 /* Get the namespace node for the arg/local */
474 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
475 if (ACPI_FAILURE (Status))
477 return_VALUE ((ACPI_TYPE_NOT_FOUND));
482 Object = AcpiNsGetAttachedObject (Node);
485 /* Uninitialized local/arg, return TYPE_ANY */
487 return_VALUE (ACPI_TYPE_ANY);
490 /* Get the object type */
492 return_VALUE (ACPI_GET_OBJECT_TYPE (Object));
496 /*******************************************************************************
498 * FUNCTION: AcpiDsMethodDataGetValue
500 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
501 * Index - Which localVar or argument to get
502 * WalkState - Current walk state object
503 * *DestDesc - Ptr to Descriptor into which selected Arg
504 * or Local value should be copied
508 * DESCRIPTION: Retrieve value of selected Arg or Local from the method frame
509 * at the current top of the method stack.
510 * Used only in AcpiExResolveToValue().
512 ******************************************************************************/
515 AcpiDsMethodDataGetValue (
518 ACPI_WALK_STATE *WalkState,
519 ACPI_OPERAND_OBJECT **DestDesc)
522 ACPI_NAMESPACE_NODE *Node;
523 ACPI_OPERAND_OBJECT *Object;
526 ACPI_FUNCTION_TRACE ("DsMethodDataGetValue");
529 /* Validate the object descriptor */
533 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Null object descriptor pointer\n"));
534 return_ACPI_STATUS (AE_BAD_PARAMETER);
537 /* Get the namespace node for the arg/local */
539 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
540 if (ACPI_FAILURE (Status))
542 return_ACPI_STATUS (Status);
545 /* Get the object from the node */
547 Object = Node->Object;
549 /* Examine the returned object, it must be valid. */
554 * Index points to uninitialized object.
555 * This means that either 1) The expected argument was
556 * not passed to the method, or 2) A local variable
557 * was referenced by the method (via the ASL)
558 * before it was initialized. Either case is an error.
564 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Arg[%d] at node %p\n",
567 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
571 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Uninitialized Local[%d] at node %p\n",
574 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
577 return_ACPI_STATUS (AE_AML_INTERNAL);
582 * The Index points to an initialized and valid object.
583 * Return an additional reference to the object
586 AcpiUtAddReference (Object);
588 return_ACPI_STATUS (AE_OK);
592 /*******************************************************************************
594 * FUNCTION: AcpiDsMethodDataDeleteValue
596 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
597 * Index - Which localVar or argument to delete
598 * WalkState - Current walk state object
602 * DESCRIPTION: Delete the entry at Opcode:Index on the method stack. Inserts
603 * a null into the stack slot after the object is deleted.
605 ******************************************************************************/
608 AcpiDsMethodDataDeleteValue (
611 ACPI_WALK_STATE *WalkState)
614 ACPI_NAMESPACE_NODE *Node;
615 ACPI_OPERAND_OBJECT *Object;
618 ACPI_FUNCTION_TRACE ("DsMethodDataDeleteValue");
621 /* Get the namespace node for the arg/local */
623 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
624 if (ACPI_FAILURE (Status))
629 /* Get the associated object */
631 Object = AcpiNsGetAttachedObject (Node);
634 * Undefine the Arg or Local by setting its descriptor
635 * pointer to NULL. Locals/Args can contain both
636 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
641 (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
644 * There is a valid object.
645 * Decrement the reference count by one to balance the
646 * increment when the object was stored.
648 AcpiUtRemoveReference (Object);
655 /*******************************************************************************
657 * FUNCTION: AcpiDsStoreObjectToLocal
659 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
660 * Index - Which localVar or argument to set
661 * ObjDesc - Value to be stored
662 * WalkState - Current walk state
666 * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
667 * as the new value for the Arg or Local and the reference count
668 * for ObjDesc is incremented.
670 ******************************************************************************/
673 AcpiDsStoreObjectToLocal (
676 ACPI_OPERAND_OBJECT *ObjDesc,
677 ACPI_WALK_STATE *WalkState)
680 ACPI_NAMESPACE_NODE *Node;
681 ACPI_OPERAND_OBJECT *CurrentObjDesc;
684 ACPI_FUNCTION_TRACE ("DsStoreObjectToLocal");
685 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Opcode=%d Idx=%d Obj=%p\n",
686 Opcode, Index, ObjDesc));
689 /* Parameter validation */
693 return_ACPI_STATUS (AE_BAD_PARAMETER);
696 /* Get the namespace node for the arg/local */
698 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
699 if (ACPI_FAILURE (Status))
701 return_ACPI_STATUS (Status);
704 CurrentObjDesc = AcpiNsGetAttachedObject (Node);
705 if (CurrentObjDesc == ObjDesc)
707 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
709 return_ACPI_STATUS (Status);
713 * If there is an object already in this slot, we either
714 * have to delete it, or if this is an argument and there
715 * is an object reference stored there, we have to do
721 * Check for an indirect store if an argument
722 * contains an object reference (stored as an Node).
723 * We don't allow this automatic dereferencing for
724 * locals, since a store to a local should overwrite
725 * anything there, including an object reference.
727 * If both Arg0 and Local0 contain RefOf (Local4):
729 * Store (1, Arg0) - Causes indirect store to local4
730 * Store (1, Local0) - Stores 1 in local0, overwriting
731 * the reference to local4
732 * Store (1, DeRefof (Local0)) - Causes indirect store to local4
736 if (Opcode == AML_ARG_OP)
739 * Make sure that the object is the correct type. This may be overkill, but
740 * it is here because references were NS nodes in the past. Now they are
741 * operand objects of type Reference.
743 if (ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) != ACPI_DESC_TYPE_OPERAND)
745 ACPI_REPORT_ERROR (("Invalid descriptor type while storing to method arg: %X\n",
746 CurrentObjDesc->Common.Type));
747 return_ACPI_STATUS (AE_AML_INTERNAL);
751 * If we have a valid reference object that came from RefOf(), do the
754 if ((CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
755 (CurrentObjDesc->Reference.Opcode == AML_REF_OF_OP))
757 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
758 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
759 ObjDesc, CurrentObjDesc));
762 * Store this object to the Node
763 * (perform the indirect store)
765 Status = AcpiExStoreObjectToNode (ObjDesc,
766 CurrentObjDesc->Reference.Object, WalkState);
767 return_ACPI_STATUS (Status);
772 * Delete the existing object
773 * before storing the new one
775 AcpiDsMethodDataDeleteValue (Opcode, Index, WalkState);
779 * Install the ObjStack descriptor (*ObjDesc) into
780 * the descriptor for the Arg or Local.
781 * Install the new object in the stack entry
782 * (increments the object reference count by one)
784 Status = AcpiDsMethodDataSetValue (Opcode, Index, ObjDesc, WalkState);
785 return_ACPI_STATUS (Status);