1 /*******************************************************************************
3 * Module Name: dsmthdat - control method arguments and local variables
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2014, 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.
51 #define _COMPONENT ACPI_DISPATCHER
52 ACPI_MODULE_NAME ("dsmthdat")
54 /* Local prototypes */
57 AcpiDsMethodDataDeleteValue (
60 ACPI_WALK_STATE *WalkState);
63 AcpiDsMethodDataSetValue (
66 ACPI_OPERAND_OBJECT *Object,
67 ACPI_WALK_STATE *WalkState);
69 #ifdef ACPI_OBSOLETE_FUNCTIONS
71 AcpiDsMethodDataGetType (
74 ACPI_WALK_STATE *WalkState);
78 /*******************************************************************************
80 * FUNCTION: AcpiDsMethodDataInit
82 * PARAMETERS: WalkState - Current walk state object
86 * DESCRIPTION: Initialize the data structures that hold the method's arguments
87 * and locals. The data struct is an array of namespace nodes for
88 * each - this allows RefOf and DeRefOf to work properly for these
91 * NOTES: WalkState fields are initialized to zero by the
92 * ACPI_ALLOCATE_ZEROED().
94 * A pseudo-Namespace Node is assigned to each argument and local
95 * so that RefOf() can return a pointer to the Node.
97 ******************************************************************************/
100 AcpiDsMethodDataInit (
101 ACPI_WALK_STATE *WalkState)
106 ACPI_FUNCTION_TRACE (DsMethodDataInit);
109 /* Init the method arguments */
111 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
113 ACPI_MOVE_32_TO_32 (&WalkState->Arguments[i].Name, NAMEOF_ARG_NTE);
114 WalkState->Arguments[i].Name.Integer |= (i << 24);
115 WalkState->Arguments[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
116 WalkState->Arguments[i].Type = ACPI_TYPE_ANY;
117 WalkState->Arguments[i].Flags = ANOBJ_METHOD_ARG;
120 /* Init the method locals */
122 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++)
124 ACPI_MOVE_32_TO_32 (&WalkState->LocalVariables[i].Name, NAMEOF_LOCAL_NTE);
126 WalkState->LocalVariables[i].Name.Integer |= (i << 24);
127 WalkState->LocalVariables[i].DescriptorType = ACPI_DESC_TYPE_NAMED;
128 WalkState->LocalVariables[i].Type = ACPI_TYPE_ANY;
129 WalkState->LocalVariables[i].Flags = ANOBJ_METHOD_LOCAL;
136 /*******************************************************************************
138 * FUNCTION: AcpiDsMethodDataDeleteAll
140 * PARAMETERS: WalkState - Current walk state object
144 * DESCRIPTION: Delete method locals and arguments. Arguments are only
145 * deleted if this method was called from another method.
147 ******************************************************************************/
150 AcpiDsMethodDataDeleteAll (
151 ACPI_WALK_STATE *WalkState)
156 ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll);
159 /* Detach the locals */
161 for (Index = 0; Index < ACPI_METHOD_NUM_LOCALS; Index++)
163 if (WalkState->LocalVariables[Index].Object)
165 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
166 Index, WalkState->LocalVariables[Index].Object));
168 /* Detach object (if present) and remove a reference */
170 AcpiNsDetachObject (&WalkState->LocalVariables[Index]);
174 /* Detach the arguments */
176 for (Index = 0; Index < ACPI_METHOD_NUM_ARGS; Index++)
178 if (WalkState->Arguments[Index].Object)
180 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
181 Index, WalkState->Arguments[Index].Object));
183 /* Detach object (if present) and remove a reference */
185 AcpiNsDetachObject (&WalkState->Arguments[Index]);
193 /*******************************************************************************
195 * FUNCTION: AcpiDsMethodDataInitArgs
197 * PARAMETERS: *Params - Pointer to a parameter list for the method
198 * MaxParamCount - The arg count for this method
199 * WalkState - Current walk state object
203 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
204 * of ACPI operand objects, either null terminated or whose length
205 * is defined by MaxParamCount.
207 ******************************************************************************/
210 AcpiDsMethodDataInitArgs (
211 ACPI_OPERAND_OBJECT **Params,
212 UINT32 MaxParamCount,
213 ACPI_WALK_STATE *WalkState)
219 ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs, Params);
224 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "No param list passed to method\n"));
225 return_ACPI_STATUS (AE_OK);
228 /* Copy passed parameters into the new method stack frame */
230 while ((Index < ACPI_METHOD_NUM_ARGS) &&
231 (Index < MaxParamCount) &&
236 * Store the argument in the method/walk descriptor.
237 * Do not copy the arg in order to implement call by reference
239 Status = AcpiDsMethodDataSetValue (ACPI_REFCLASS_ARG, Index,
240 Params[Index], WalkState);
241 if (ACPI_FAILURE (Status))
243 return_ACPI_STATUS (Status);
249 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%u args passed to method\n", Index));
250 return_ACPI_STATUS (AE_OK);
254 /*******************************************************************************
256 * FUNCTION: AcpiDsMethodDataGetNode
258 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
260 * Index - Which Local or Arg whose type to get
261 * WalkState - Current walk state object
262 * Node - Where the node is returned.
264 * RETURN: Status and node
266 * DESCRIPTION: Get the Node associated with a local or arg.
268 ******************************************************************************/
271 AcpiDsMethodDataGetNode (
274 ACPI_WALK_STATE *WalkState,
275 ACPI_NAMESPACE_NODE **Node)
277 ACPI_FUNCTION_TRACE (DsMethodDataGetNode);
281 * Method Locals and Arguments are supported
285 case ACPI_REFCLASS_LOCAL:
287 if (Index > ACPI_METHOD_MAX_LOCAL)
289 ACPI_ERROR ((AE_INFO,
290 "Local index %u is invalid (max %u)",
291 Index, ACPI_METHOD_MAX_LOCAL));
292 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
295 /* Return a pointer to the pseudo-node */
297 *Node = &WalkState->LocalVariables[Index];
300 case ACPI_REFCLASS_ARG:
302 if (Index > ACPI_METHOD_MAX_ARG)
304 ACPI_ERROR ((AE_INFO,
305 "Arg index %u is invalid (max %u)",
306 Index, ACPI_METHOD_MAX_ARG));
307 return_ACPI_STATUS (AE_AML_INVALID_INDEX);
310 /* Return a pointer to the pseudo-node */
312 *Node = &WalkState->Arguments[Index];
317 ACPI_ERROR ((AE_INFO, "Type %u is invalid", Type));
318 return_ACPI_STATUS (AE_TYPE);
321 return_ACPI_STATUS (AE_OK);
325 /*******************************************************************************
327 * FUNCTION: AcpiDsMethodDataSetValue
329 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
331 * Index - Which Local or Arg to get
332 * Object - Object to be inserted into the stack entry
333 * WalkState - Current walk state object
337 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
338 * Note: There is no "implicit conversion" for locals.
340 ******************************************************************************/
343 AcpiDsMethodDataSetValue (
346 ACPI_OPERAND_OBJECT *Object,
347 ACPI_WALK_STATE *WalkState)
350 ACPI_NAMESPACE_NODE *Node;
353 ACPI_FUNCTION_TRACE (DsMethodDataSetValue);
356 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
357 "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object,
358 Type, Object->Common.ReferenceCount,
359 AcpiUtGetTypeName (Object->Common.Type)));
361 /* Get the namespace node for the arg/local */
363 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
364 if (ACPI_FAILURE (Status))
366 return_ACPI_STATUS (Status);
370 * Increment ref count so object can't be deleted while installed.
371 * NOTE: We do not copy the object in order to preserve the call by
372 * reference semantics of ACPI Control Method invocation.
373 * (See ACPI Specification 2.0C)
375 AcpiUtAddReference (Object);
377 /* Install the object */
379 Node->Object = Object;
380 return_ACPI_STATUS (Status);
384 /*******************************************************************************
386 * FUNCTION: AcpiDsMethodDataGetValue
388 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
390 * Index - Which localVar or argument to get
391 * WalkState - Current walk state object
392 * DestDesc - Where Arg or Local value is returned
396 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
397 * Used only in AcpiExResolveToValue().
399 ******************************************************************************/
402 AcpiDsMethodDataGetValue (
405 ACPI_WALK_STATE *WalkState,
406 ACPI_OPERAND_OBJECT **DestDesc)
409 ACPI_NAMESPACE_NODE *Node;
410 ACPI_OPERAND_OBJECT *Object;
413 ACPI_FUNCTION_TRACE (DsMethodDataGetValue);
416 /* Validate the object descriptor */
420 ACPI_ERROR ((AE_INFO, "Null object descriptor pointer"));
421 return_ACPI_STATUS (AE_BAD_PARAMETER);
424 /* Get the namespace node for the arg/local */
426 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
427 if (ACPI_FAILURE (Status))
429 return_ACPI_STATUS (Status);
432 /* Get the object from the node */
434 Object = Node->Object;
436 /* Examine the returned object, it must be valid. */
441 * Index points to uninitialized object.
442 * This means that either 1) The expected argument was
443 * not passed to the method, or 2) A local variable
444 * was referenced by the method (via the ASL)
445 * before it was initialized. Either case is an error.
448 /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
450 if (AcpiGbl_EnableInterpreterSlack)
452 Object = AcpiUtCreateIntegerObject ((UINT64) 0);
455 return_ACPI_STATUS (AE_NO_MEMORY);
458 Node->Object = Object;
461 /* Otherwise, return the error */
465 case ACPI_REFCLASS_ARG:
467 ACPI_ERROR ((AE_INFO,
468 "Uninitialized Arg[%u] at node %p",
471 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG);
473 case ACPI_REFCLASS_LOCAL:
475 * No error message for this case, will be trapped again later to
476 * detect and ignore cases of Store(LocalX,LocalX)
478 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL);
482 ACPI_ERROR ((AE_INFO, "Not a Arg/Local opcode: 0x%X", Type));
483 return_ACPI_STATUS (AE_AML_INTERNAL);
488 * The Index points to an initialized and valid object.
489 * Return an additional reference to the object
492 AcpiUtAddReference (Object);
494 return_ACPI_STATUS (AE_OK);
498 /*******************************************************************************
500 * FUNCTION: AcpiDsMethodDataDeleteValue
502 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
504 * Index - Which localVar or argument to delete
505 * WalkState - Current walk state object
509 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
510 * a null into the stack slot after the object is deleted.
512 ******************************************************************************/
515 AcpiDsMethodDataDeleteValue (
518 ACPI_WALK_STATE *WalkState)
521 ACPI_NAMESPACE_NODE *Node;
522 ACPI_OPERAND_OBJECT *Object;
525 ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue);
528 /* Get the namespace node for the arg/local */
530 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
531 if (ACPI_FAILURE (Status))
536 /* Get the associated object */
538 Object = AcpiNsGetAttachedObject (Node);
541 * Undefine the Arg or Local by setting its descriptor
542 * pointer to NULL. Locals/Args can contain both
543 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
548 (ACPI_GET_DESCRIPTOR_TYPE (Object) == ACPI_DESC_TYPE_OPERAND))
551 * There is a valid object.
552 * Decrement the reference count by one to balance the
553 * increment when the object was stored.
555 AcpiUtRemoveReference (Object);
562 /*******************************************************************************
564 * FUNCTION: AcpiDsStoreObjectToLocal
566 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
568 * Index - Which Local or Arg to set
569 * ObjDesc - Value to be stored
570 * WalkState - Current walk state
574 * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
575 * as the new value for the Arg or Local and the reference count
576 * for ObjDesc is incremented.
578 ******************************************************************************/
581 AcpiDsStoreObjectToLocal (
584 ACPI_OPERAND_OBJECT *ObjDesc,
585 ACPI_WALK_STATE *WalkState)
588 ACPI_NAMESPACE_NODE *Node;
589 ACPI_OPERAND_OBJECT *CurrentObjDesc;
590 ACPI_OPERAND_OBJECT *NewObjDesc;
593 ACPI_FUNCTION_TRACE (DsStoreObjectToLocal);
594 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
595 Type, Index, ObjDesc));
597 /* Parameter validation */
601 return_ACPI_STATUS (AE_BAD_PARAMETER);
604 /* Get the namespace node for the arg/local */
606 Status = AcpiDsMethodDataGetNode (Type, Index, WalkState, &Node);
607 if (ACPI_FAILURE (Status))
609 return_ACPI_STATUS (Status);
612 CurrentObjDesc = AcpiNsGetAttachedObject (Node);
613 if (CurrentObjDesc == ObjDesc)
615 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Obj=%p already installed!\n",
617 return_ACPI_STATUS (Status);
621 * If the reference count on the object is more than one, we must
622 * take a copy of the object before we store. A reference count
623 * of exactly 1 means that the object was just created during the
624 * evaluation of an expression, and we can safely use it since it
625 * is not used anywhere else.
627 NewObjDesc = ObjDesc;
628 if (ObjDesc->Common.ReferenceCount > 1)
630 Status = AcpiUtCopyIobjectToIobject (ObjDesc, &NewObjDesc, WalkState);
631 if (ACPI_FAILURE (Status))
633 return_ACPI_STATUS (Status);
638 * If there is an object already in this slot, we either
639 * have to delete it, or if this is an argument and there
640 * is an object reference stored there, we have to do
646 * Check for an indirect store if an argument
647 * contains an object reference (stored as an Node).
648 * We don't allow this automatic dereferencing for
649 * locals, since a store to a local should overwrite
650 * anything there, including an object reference.
652 * If both Arg0 and Local0 contain RefOf (Local4):
654 * Store (1, Arg0) - Causes indirect store to local4
655 * Store (1, Local0) - Stores 1 in local0, overwriting
656 * the reference to local4
657 * Store (1, DeRefof (Local0)) - Causes indirect store to local4
661 if (Type == ACPI_REFCLASS_ARG)
664 * If we have a valid reference object that came from RefOf(),
665 * do the indirect store
667 if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc) == ACPI_DESC_TYPE_OPERAND) &&
668 (CurrentObjDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE) &&
669 (CurrentObjDesc->Reference.Class == ACPI_REFCLASS_REFOF))
671 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
672 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
673 NewObjDesc, CurrentObjDesc));
676 * Store this object to the Node (perform the indirect store)
677 * NOTE: No implicit conversion is performed, as per the ACPI
678 * specification rules on storing to Locals/Args.
680 Status = AcpiExStoreObjectToNode (NewObjDesc,
681 CurrentObjDesc->Reference.Object, WalkState,
682 ACPI_NO_IMPLICIT_CONVERSION);
684 /* Remove local reference if we copied the object above */
686 if (NewObjDesc != ObjDesc)
688 AcpiUtRemoveReference (NewObjDesc);
690 return_ACPI_STATUS (Status);
694 /* Delete the existing object before storing the new one */
696 AcpiDsMethodDataDeleteValue (Type, Index, WalkState);
700 * Install the Obj descriptor (*NewObjDesc) into
701 * the descriptor for the Arg or Local.
702 * (increments the object reference count by one)
704 Status = AcpiDsMethodDataSetValue (Type, Index, NewObjDesc, WalkState);
706 /* Remove local reference if we copied the object above */
708 if (NewObjDesc != ObjDesc)
710 AcpiUtRemoveReference (NewObjDesc);
713 return_ACPI_STATUS (Status);
717 #ifdef ACPI_OBSOLETE_FUNCTIONS
718 /*******************************************************************************
720 * FUNCTION: AcpiDsMethodDataGetType
722 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
723 * Index - Which Local or Arg whose type to get
724 * WalkState - Current walk state object
726 * RETURN: Data type of current value of the selected Arg or Local
728 * DESCRIPTION: Get the type of the object stored in the Local or Arg
730 ******************************************************************************/
733 AcpiDsMethodDataGetType (
736 ACPI_WALK_STATE *WalkState)
739 ACPI_NAMESPACE_NODE *Node;
740 ACPI_OPERAND_OBJECT *Object;
743 ACPI_FUNCTION_TRACE (DsMethodDataGetType);
746 /* Get the namespace node for the arg/local */
748 Status = AcpiDsMethodDataGetNode (Opcode, Index, WalkState, &Node);
749 if (ACPI_FAILURE (Status))
751 return_VALUE ((ACPI_TYPE_NOT_FOUND));
756 Object = AcpiNsGetAttachedObject (Node);
759 /* Uninitialized local/arg, return TYPE_ANY */
761 return_VALUE (ACPI_TYPE_ANY);
764 /* Get the object type */
766 return_VALUE (Object->Type);