1 /*******************************************************************************
3 * Module Name: dsmthdat - control method arguments and local variables
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #define __DSMTHDAT_C__
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acdispat.h>
49 #include <contrib/dev/acpica/include/acnamesp.h>
50 #include <contrib/dev/acpica/include/acinterp.h>
53 #define _COMPONENT ACPI_DISPATCHER
54 ACPI_MODULE_NAME ("dsmthdat")
56 /* Local prototypes */
59 AcpiDsMethodDataDeleteValue (
62 ACPI_WALK_STATE *WalkState);
65 AcpiDsMethodDataSetValue (
68 ACPI_OPERAND_OBJECT *Object,
69 ACPI_WALK_STATE *WalkState);
71 #ifdef ACPI_OBSOLETE_FUNCTIONS
73 AcpiDsMethodDataGetType (
76 ACPI_WALK_STATE *WalkState);
80 /*******************************************************************************
82 * FUNCTION: AcpiDsMethodDataInit
84 * PARAMETERS: WalkState - Current walk state object
88 * DESCRIPTION: Initialize the data structures that hold the method's arguments
89 * and locals. The data struct is an array of namespace nodes for
90 * each - this allows RefOf and DeRefOf to work properly for these
93 * NOTES: WalkState fields are initialized to zero by the
94 * ACPI_ALLOCATE_ZEROED().
96 * A pseudo-Namespace Node is assigned to each argument and local
97 * so that RefOf() can return a pointer to the Node.
99 ******************************************************************************/
102 AcpiDsMethodDataInit (
103 ACPI_WALK_STATE *WalkState)
108 ACPI_FUNCTION_TRACE (DsMethodDataInit);
111 /* Init the method arguments */
113 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
115 ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, NAMEOF_ARG_NTE);
116 WalkState->Arguments[i].Name.Integer |= (i << 24);
117 WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
118 WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
119 WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
122 /* Init the method locals */
124 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
126 ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, NAMEOF_LOCAL_NTE);
128 WalkState->LocalVariables[i].Name.Integer |= (i << 24);
129 WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
130 WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
131 WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
138 /*******************************************************************************
140 * FUNCTION: AcpiDsMethodDataDeleteAll
142 * PARAMETERS: WalkState - Current walk state object
146 * DESCRIPTION: Delete method locals and arguments. Arguments are only
147 * deleted if this method was called from another method.
149 ******************************************************************************/
152 AcpiDsMethodDataDeleteAll (
153 ACPI_WALK_STATE *WalkState)
158 ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
161 /* Detach the locals */
163 for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
165 if (WalkState->LocalVariables[Index].Object)
167 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
168 Index, WalkState->LocalVariables[Index].Object));
170 /* Detach object (if present) and remove a reference */
172 AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
176 /* Detach the arguments */
178 for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
180 if (WalkState->Arguments[Index].Object)
182 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
183 Index, WalkState->Arguments[Index].Object));
185 /* Detach object (if present) and remove a reference */
187 AcpiNsDetachObject (&WalkState->Arguments[Index]);
195 /*******************************************************************************
197 * FUNCTION: AcpiDsMethodDataInitArgs
199 * PARAMETERS: *Params - Pointer to a parameter list for the method
200 * MaxParamCount - The arg count for this method
201 * WalkState - Current walk state object
205 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
206 * of ACPI operand objects, either null terminated or whose length
207 * is defined by MaxParamCount.
209 ******************************************************************************/
212 AcpiDsMethodDataInitArgs (
213 ACPI_OPERAND_OBJECT **Params,
214 UINT32 MaxParamCount,
215 ACPI_WALK_STATE *WalkState)
221 ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
226 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
227 return_ACPI_STATUS (AE_OK);
230 /* Copy passed parameters into the new method stack frame */
232 while ((Index < ACPI_METHOD_NUM_ARGS) &&
233 (Index < MaxParamCount) &&
238 * Store the argument in the method/walk descriptor.
239 * Do not copy the arg in order to implement call by reference
241 Status = AcpiDsMethodDataSetValue (ACPI_REFCLASS_ARG, Index,
242 Params[Index], WalkState);
243 if (ACPI_FAILURE (Status))
245 return_ACPI_STATUS (Status);
251 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
252 return_ACPI_STATUS (AE_OK);
256 /*******************************************************************************
258 * FUNCTION: AcpiDsMethodDataGetNode
260 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
262 * Index - Which Local or Arg whose type to get
263 * WalkState - Current walk state object
264 * Node - Where the node is returned.
266 * RETURN: Status and node
268 * DESCRIPTION: Get the Node associated with a local or arg.
270 ******************************************************************************/
273 AcpiDsMethodDataGetNode (
276 ACPI_WALK_STATE *WalkState,
277 ACPI_NAMESPACE_NODE **Node)
279 ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
283 * Method Locals and Arguments are supported
287 case ACPI_REFCLASS_LOCAL:
289 if (Index > ACPI_METHOD_MAX_LOCAL)
291 ACPI_ERROR ((AE_INFO,
292 "Local index %u is invalid (max %u)",
293 Index, ACPI_METHOD_MAX_LOCAL));
294 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
297 /* Return a pointer to the pseudo-node */
299 *Node = &WalkState->LocalVariables[Index];
302 case ACPI_REFCLASS_ARG:
304 if (Index > ACPI_METHOD_MAX_ARG)
306 ACPI_ERROR ((AE_INFO,
307 "Arg index %u is invalid (max %u)",
308 Index, ACPI_METHOD_MAX_ARG));
309 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
312 /* Return a pointer to the pseudo-node */
314 *Node = &WalkState->Arguments[Index];
318 ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
319 return_ACPI_STATUS (AE_TYPE);
322 return_ACPI_STATUS (AE_OK);
326 /*******************************************************************************
328 * FUNCTION: AcpiDsMethodDataSetValue
330 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
332 * Index - Which Local or Arg to get
333 * Object - Object to be inserted into the stack entry
334 * WalkState - Current walk state object
338 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
339 * Note: There is no "implicit conversion" for locals.
341 ******************************************************************************/
344 AcpiDsMethodDataSetValue (
347 ACPI_OPERAND_OBJECT *Object,
348 ACPI_WALK_STATE *WalkState)
351 ACPI_NAMESPACE_NODE *Node;
354 ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
357 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
358 "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
359 Type, Object->Common.ReferenceCount,
360 AcpiUtGetTypeName (Object->Common.Type)));
362 /* Get the namespace node for the arg/local */
364 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
365 if (ACPI_FAILURE (Status))
367 return_ACPI_STATUS (Status);
371 * Increment ref count so object can't be deleted while installed.
372 * NOTE: We do not copy the object in order to preserve the call by
373 * reference semantics of ACPI Control Method invocation.
374 * (See ACPI Specification 2.0C)
376 AcpiUtAddReference (Object);
378 /* Install the object */
380 Node->Object = Object;
381 return_ACPI_STATUS (Status);
385 /*******************************************************************************
387 * FUNCTION: AcpiDsMethodDataGetValue
389 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
391 * Index - Which localVar or argument to get
392 * WalkState - Current walk state object
393 * DestDesc - Where Arg or Local value is returned
397 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
398 * Used only in AcpiExResolveToValue().
400 ******************************************************************************/
403 AcpiDsMethodDataGetValue (
406 ACPI_WALK_STATE *WalkState,
407 ACPI_OPERAND_OBJECT **DestDesc)
410 ACPI_NAMESPACE_NODE *Node;
411 ACPI_OPERAND_OBJECT *Object;
414 ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
417 /* Validate the object descriptor */
421 ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
422 return_ACPI_STATUS (AE_BAD_PARAMETER);
425 /* Get the namespace node for the arg/local */
427 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
428 if (ACPI_FAILURE (Status))
430 return_ACPI_STATUS (Status);
433 /* Get the object from the node */
435 Object = Node->Object;
437 /* Examine the returned object, it must be valid. */
442 * Index points to uninitialized object.
443 * This means that either 1) The expected argument was
444 * not passed to the method, or 2) A local variable
445 * was referenced by the method (via the ASL)
446 * before it was initialized. Either case is an error.
449 /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
451 if (AcpiGbl_EnableInterpreterSlack)
453 Object = AcpiUtCreateIntegerObject ((UINT64) 0);
456 return_ACPI_STATUS (AE_NO_MEMORY);
459 Node->Object = Object;
462 /* Otherwise, return the error */
466 case ACPI_REFCLASS_ARG:
468 ACPI_ERROR ((AE_INFO,
469 "Uninitialized Arg[%u] at node %p",
472 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
474 case ACPI_REFCLASS_LOCAL:
477 * No error message for this case, will be trapped again later to
478 * detect and ignore cases of Store(LocalX,LocalX)
480 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
484 ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
485 return_ACPI_STATUS (AE_AML_INTERNAL);
490 * The Index points to an initialized and valid object.
491 * Return an additional reference to the object
494 AcpiUtAddReference (Object);
496 return_ACPI_STATUS (AE_OK);
500 /*******************************************************************************
502 * FUNCTION: AcpiDsMethodDataDeleteValue
504 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
506 * Index - Which localVar or argument to delete
507 * WalkState - Current walk state object
511 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
512 * a null into the stack slot after the object is deleted.
514 ******************************************************************************/
517 AcpiDsMethodDataDeleteValue (
520 ACPI_WALK_STATE *WalkState)
523 ACPI_NAMESPACE_NODE *Node;
524 ACPI_OPERAND_OBJECT *Object;
527 ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
530 /* Get the namespace node for the arg/local */
532 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
533 if (ACPI_FAILURE (Status))
538 /* Get the associated object */
540 Object = AcpiNsGetAttachedObject (Node);
543 * Undefine the Arg or Local by setting its descriptor
544 * pointer to NULL. Locals/Args can contain both
545 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
550 (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
553 * There is a valid object.
554 * Decrement the reference count by one to balance the
555 * increment when the object was stored.
557 AcpiUtRemoveReference (Object);
564 /*******************************************************************************
566 * FUNCTION: AcpiDsStoreObjectToLocal
568 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
570 * Index - Which Local or Arg to set
571 * ObjDesc - Value to be stored
572 * WalkState - Current walk state
576 * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
577 * as the new value for the Arg or Local and the reference count
578 * for ObjDesc is incremented.
580 ******************************************************************************/
583 AcpiDsStoreObjectToLocal (
586 ACPI_OPERAND_OBJECT *ObjDesc,
587 ACPI_WALK_STATE *WalkState)
590 ACPI_NAMESPACE_NODE *Node;
591 ACPI_OPERAND_OBJECT *CurrentObjDesc;
592 ACPI_OPERAND_OBJECT *NewObjDesc;
595 ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
596 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
597 Type, Index, ObjDesc));
599 /* Parameter validation */
603 return_ACPI_STATUS (AE_BAD_PARAMETER);
606 /* Get the namespace node for the arg/local */
608 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
609 if (ACPI_FAILURE (Status))
611 return_ACPI_STATUS (Status);
614 CurrentObjDesc = AcpiNsGetAttachedObject (Node);
615 if (CurrentObjDesc == ObjDesc)
617 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
619 return_ACPI_STATUS (Status);
623 * If the reference count on the object is more than one, we must
624 * take a copy of the object before we store. A reference count
625 * of exactly 1 means that the object was just created during the
626 * evaluation of an expression, and we can safely use it since it
627 * is not used anywhere else.
629 NewObjDesc = ObjDesc;
630 if (ObjDesc->Common.ReferenceCount > 1)
632 Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState);
633 if (ACPI_FAILURE (Status))
635 return_ACPI_STATUS (Status);
640 * If there is an object already in this slot, we either
641 * have to delete it, or if this is an argument and there
642 * is an object reference stored there, we have to do
648 * Check for an indirect store if an argument
649 * contains an object reference (stored as an Node).
650 * We don't allow this automatic dereferencing for
651 * locals, since a store to a local should overwrite
652 * anything there, including an object reference.
654 * If both Arg0 and Local0 contain RefOf (Local4):
656 * Store (1, Arg0) - Causes indirect store to local4
657 * Store (1, Local0) - Stores 1 in local0, overwriting
658 * the reference to local4
659 * Store (1, DeRefof (Local0)) - Causes indirect store to local4
663 if (Type == ACPI_REFCLASS_ARG)
666 * If we have a valid reference object that came from RefOf(),
667 * do the indirect store
669 if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
670 (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
671 (CurrentObjDesc->Reference.Class == ACPI_REFCLASS_REFOF))
673 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
674 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
675 NewObjDesc, CurrentObjDesc));
678 * Store this object to the Node (perform the indirect store)
679 * NOTE: No implicit conversion is performed, as per the ACPI
680 * specification rules on storing to Locals/Args.
682 Status = AcpiExStoreObjectToNode (NewObjDesc,
683 CurrentObjDesc->Reference.Object, WalkState,
684 ACPI_NO_IMPLICIT_CONVERSION);
686 /* Remove local reference if we copied the object above */
688 if (NewObjDesc != ObjDesc)
690 AcpiUtRemoveReference (NewObjDesc);
692 return_ACPI_STATUS (Status);
696 /* Delete the existing object before storing the new one */
698 AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
702 * Install the Obj descriptor (*NewObjDesc) into
703 * the descriptor for the Arg or Local.
704 * (increments the object reference count by one)
706 Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
708 /* Remove local reference if we copied the object above */
710 if (NewObjDesc != ObjDesc)
712 AcpiUtRemoveReference (NewObjDesc);
715 return_ACPI_STATUS (Status);
719 #ifdef ACPI_OBSOLETE_FUNCTIONS
720 /*******************************************************************************
722 * FUNCTION: AcpiDsMethodDataGetType
724 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
725 * Index - Which Local or Arg whose type to get
726 * WalkState - Current walk state object
728 * RETURN: Data type of current value of the selected Arg or Local
730 * DESCRIPTION: Get the type of the object stored in the Local or Arg
732 ******************************************************************************/
735 AcpiDsMethodDataGetType (
738 ACPI_WALK_STATE *WalkState)
741 ACPI_NAMESPACE_NODE *Node;
742 ACPI_OPERAND_OBJECT *Object;
745 ACPI_FUNCTION_TRACE (DsMethodDataGetType);
748 /* Get the namespace node for the arg/local */
750 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
751 if (ACPI_FAILURE (Status))
753 return_VALUE ((ACPI_TYPE_NOT_FOUND));
758 Object = AcpiNsGetAttachedObject (Node);
761 /* Uninitialized local/arg, return TYPE_ANY */
763 return_VALUE (ACPI_TYPE_ANY);
766 /* Get the object type */
768 return_VALUE (Object->Type);