1 /*******************************************************************************
3 * Module Name: dsmthdat - control method arguments and local variables
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2017, 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
,
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
,
129 WalkState
->LocalVariables
[i
].Name
.Integer
|= (i
<< 24);
130 WalkState
->LocalVariables
[i
].DescriptorType
= ACPI_DESC_TYPE_NAMED
;
131 WalkState
->LocalVariables
[i
].Type
= ACPI_TYPE_ANY
;
132 WalkState
->LocalVariables
[i
].Flags
= ANOBJ_METHOD_LOCAL
;
139 /*******************************************************************************
141 * FUNCTION: AcpiDsMethodDataDeleteAll
143 * PARAMETERS: WalkState - Current walk state object
147 * DESCRIPTION: Delete method locals and arguments. Arguments are only
148 * deleted if this method was called from another method.
150 ******************************************************************************/
153 AcpiDsMethodDataDeleteAll (
154 ACPI_WALK_STATE
*WalkState
)
159 ACPI_FUNCTION_TRACE (DsMethodDataDeleteAll
);
162 /* Detach the locals */
164 for (Index
= 0; Index
< ACPI_METHOD_NUM_LOCALS
; Index
++)
166 if (WalkState
->LocalVariables
[Index
].Object
)
168 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Deleting Local%u=%p\n",
169 Index
, WalkState
->LocalVariables
[Index
].Object
));
171 /* Detach object (if present) and remove a reference */
173 AcpiNsDetachObject (&WalkState
->LocalVariables
[Index
]);
177 /* Detach the arguments */
179 for (Index
= 0; Index
< ACPI_METHOD_NUM_ARGS
; Index
++)
181 if (WalkState
->Arguments
[Index
].Object
)
183 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Deleting Arg%u=%p\n",
184 Index
, WalkState
->Arguments
[Index
].Object
));
186 /* Detach object (if present) and remove a reference */
188 AcpiNsDetachObject (&WalkState
->Arguments
[Index
]);
196 /*******************************************************************************
198 * FUNCTION: AcpiDsMethodDataInitArgs
200 * PARAMETERS: *Params - Pointer to a parameter list for the method
201 * MaxParamCount - The arg count for this method
202 * WalkState - Current walk state object
206 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
207 * of ACPI operand objects, either null terminated or whose length
208 * is defined by MaxParamCount.
210 ******************************************************************************/
213 AcpiDsMethodDataInitArgs (
214 ACPI_OPERAND_OBJECT
**Params
,
215 UINT32 MaxParamCount
,
216 ACPI_WALK_STATE
*WalkState
)
222 ACPI_FUNCTION_TRACE_PTR (DsMethodDataInitArgs
, Params
);
227 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
228 "No parameter list passed to method\n"));
229 return_ACPI_STATUS (AE_OK
);
232 /* Copy passed parameters into the new method stack frame */
234 while ((Index
< ACPI_METHOD_NUM_ARGS
) &&
235 (Index
< MaxParamCount
) &&
240 * Store the argument in the method/walk descriptor.
241 * Do not copy the arg in order to implement call by reference
243 Status
= AcpiDsMethodDataSetValue (
244 ACPI_REFCLASS_ARG
, Index
, Params
[Index
], WalkState
);
245 if (ACPI_FAILURE (Status
))
247 return_ACPI_STATUS (Status
);
253 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "%u args passed to method\n", Index
));
254 return_ACPI_STATUS (AE_OK
);
258 /*******************************************************************************
260 * FUNCTION: AcpiDsMethodDataGetNode
262 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
264 * Index - Which Local or Arg whose type to get
265 * WalkState - Current walk state object
266 * Node - Where the node is returned.
268 * RETURN: Status and node
270 * DESCRIPTION: Get the Node associated with a local or arg.
272 ******************************************************************************/
275 AcpiDsMethodDataGetNode (
278 ACPI_WALK_STATE
*WalkState
,
279 ACPI_NAMESPACE_NODE
**Node
)
281 ACPI_FUNCTION_TRACE (DsMethodDataGetNode
);
285 * Method Locals and Arguments are supported
289 case ACPI_REFCLASS_LOCAL
:
291 if (Index
> ACPI_METHOD_MAX_LOCAL
)
293 ACPI_ERROR ((AE_INFO
,
294 "Local index %u is invalid (max %u)",
295 Index
, ACPI_METHOD_MAX_LOCAL
));
296 return_ACPI_STATUS (AE_AML_INVALID_INDEX
);
299 /* Return a pointer to the pseudo-node */
301 *Node
= &WalkState
->LocalVariables
[Index
];
304 case ACPI_REFCLASS_ARG
:
306 if (Index
> ACPI_METHOD_MAX_ARG
)
308 ACPI_ERROR ((AE_INFO
,
309 "Arg index %u is invalid (max %u)",
310 Index
, ACPI_METHOD_MAX_ARG
));
311 return_ACPI_STATUS (AE_AML_INVALID_INDEX
);
314 /* Return a pointer to the pseudo-node */
316 *Node
= &WalkState
->Arguments
[Index
];
321 ACPI_ERROR ((AE_INFO
, "Type %u is invalid", Type
));
322 return_ACPI_STATUS (AE_TYPE
);
325 return_ACPI_STATUS (AE_OK
);
329 /*******************************************************************************
331 * FUNCTION: AcpiDsMethodDataSetValue
333 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
335 * Index - Which Local or Arg to get
336 * Object - Object to be inserted into the stack entry
337 * WalkState - Current walk state object
341 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
342 * Note: There is no "implicit conversion" for locals.
344 ******************************************************************************/
347 AcpiDsMethodDataSetValue (
350 ACPI_OPERAND_OBJECT
*Object
,
351 ACPI_WALK_STATE
*WalkState
)
354 ACPI_NAMESPACE_NODE
*Node
;
357 ACPI_FUNCTION_TRACE (DsMethodDataSetValue
);
360 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
361 "NewObj %p Type %2.2X, Refs=%u [%s]\n", Object
,
362 Type
, Object
->Common
.ReferenceCount
,
363 AcpiUtGetTypeName (Object
->Common
.Type
)));
365 /* Get the namespace node for the arg/local */
367 Status
= AcpiDsMethodDataGetNode (Type
, Index
, WalkState
, &Node
);
368 if (ACPI_FAILURE (Status
))
370 return_ACPI_STATUS (Status
);
374 * Increment ref count so object can't be deleted while installed.
375 * NOTE: We do not copy the object in order to preserve the call by
376 * reference semantics of ACPI Control Method invocation.
377 * (See ACPI Specification 2.0C)
379 AcpiUtAddReference (Object
);
381 /* Install the object */
383 Node
->Object
= Object
;
384 return_ACPI_STATUS (Status
);
388 /*******************************************************************************
390 * FUNCTION: AcpiDsMethodDataGetValue
392 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
394 * Index - Which localVar or argument to get
395 * WalkState - Current walk state object
396 * DestDesc - Where Arg or Local value is returned
400 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
401 * Used only in AcpiExResolveToValue().
403 ******************************************************************************/
406 AcpiDsMethodDataGetValue (
409 ACPI_WALK_STATE
*WalkState
,
410 ACPI_OPERAND_OBJECT
**DestDesc
)
413 ACPI_NAMESPACE_NODE
*Node
;
414 ACPI_OPERAND_OBJECT
*Object
;
417 ACPI_FUNCTION_TRACE (DsMethodDataGetValue
);
420 /* Validate the object descriptor */
424 ACPI_ERROR ((AE_INFO
, "Null object descriptor pointer"));
425 return_ACPI_STATUS (AE_BAD_PARAMETER
);
428 /* Get the namespace node for the arg/local */
430 Status
= AcpiDsMethodDataGetNode (Type
, Index
, WalkState
, &Node
);
431 if (ACPI_FAILURE (Status
))
433 return_ACPI_STATUS (Status
);
436 /* Get the object from the node */
438 Object
= Node
->Object
;
440 /* Examine the returned object, it must be valid. */
445 * Index points to uninitialized object.
446 * This means that either 1) The expected argument was
447 * not passed to the method, or 2) A local variable
448 * was referenced by the method (via the ASL)
449 * before it was initialized. Either case is an error.
452 /* If slack enabled, init the LocalX/ArgX to an Integer of value zero */
454 if (AcpiGbl_EnableInterpreterSlack
)
456 Object
= AcpiUtCreateIntegerObject ((UINT64
) 0);
459 return_ACPI_STATUS (AE_NO_MEMORY
);
462 Node
->Object
= Object
;
465 /* Otherwise, return the error */
469 case ACPI_REFCLASS_ARG
:
471 ACPI_ERROR ((AE_INFO
,
472 "Uninitialized Arg[%u] at node %p",
475 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ARG
);
477 case ACPI_REFCLASS_LOCAL
:
479 * No error message for this case, will be trapped again later to
480 * detect and ignore cases of Store(LocalX,LocalX)
482 return_ACPI_STATUS (AE_AML_UNINITIALIZED_LOCAL
);
486 ACPI_ERROR ((AE_INFO
, "Not a Arg/Local opcode: 0x%X", Type
));
487 return_ACPI_STATUS (AE_AML_INTERNAL
);
492 * The Index points to an initialized and valid object.
493 * Return an additional reference to the object
496 AcpiUtAddReference (Object
);
498 return_ACPI_STATUS (AE_OK
);
502 /*******************************************************************************
504 * FUNCTION: AcpiDsMethodDataDeleteValue
506 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
508 * Index - Which localVar or argument to delete
509 * WalkState - Current walk state object
513 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
514 * a null into the stack slot after the object is deleted.
516 ******************************************************************************/
519 AcpiDsMethodDataDeleteValue (
522 ACPI_WALK_STATE
*WalkState
)
525 ACPI_NAMESPACE_NODE
*Node
;
526 ACPI_OPERAND_OBJECT
*Object
;
529 ACPI_FUNCTION_TRACE (DsMethodDataDeleteValue
);
532 /* Get the namespace node for the arg/local */
534 Status
= AcpiDsMethodDataGetNode (Type
, Index
, WalkState
, &Node
);
535 if (ACPI_FAILURE (Status
))
540 /* Get the associated object */
542 Object
= AcpiNsGetAttachedObject (Node
);
545 * Undefine the Arg or Local by setting its descriptor
546 * pointer to NULL. Locals/Args can contain both
547 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
552 (ACPI_GET_DESCRIPTOR_TYPE (Object
) == ACPI_DESC_TYPE_OPERAND
))
555 * There is a valid object.
556 * Decrement the reference count by one to balance the
557 * increment when the object was stored.
559 AcpiUtRemoveReference (Object
);
566 /*******************************************************************************
568 * FUNCTION: AcpiDsStoreObjectToLocal
570 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
572 * Index - Which Local or Arg to set
573 * ObjDesc - Value to be stored
574 * WalkState - Current walk state
578 * DESCRIPTION: Store a value in an Arg or Local. The ObjDesc is installed
579 * as the new value for the Arg or Local and the reference count
580 * for ObjDesc is incremented.
582 ******************************************************************************/
585 AcpiDsStoreObjectToLocal (
588 ACPI_OPERAND_OBJECT
*ObjDesc
,
589 ACPI_WALK_STATE
*WalkState
)
592 ACPI_NAMESPACE_NODE
*Node
;
593 ACPI_OPERAND_OBJECT
*CurrentObjDesc
;
594 ACPI_OPERAND_OBJECT
*NewObjDesc
;
597 ACPI_FUNCTION_TRACE (DsStoreObjectToLocal
);
598 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Type=%2.2X Index=%u Obj=%p\n",
599 Type
, Index
, ObjDesc
));
601 /* Parameter validation */
605 return_ACPI_STATUS (AE_BAD_PARAMETER
);
608 /* Get the namespace node for the arg/local */
610 Status
= AcpiDsMethodDataGetNode (Type
, Index
, WalkState
, &Node
);
611 if (ACPI_FAILURE (Status
))
613 return_ACPI_STATUS (Status
);
616 CurrentObjDesc
= AcpiNsGetAttachedObject (Node
);
617 if (CurrentObjDesc
== ObjDesc
)
619 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "Obj=%p already installed!\n",
621 return_ACPI_STATUS (Status
);
625 * If the reference count on the object is more than one, we must
626 * take a copy of the object before we store. A reference count
627 * of exactly 1 means that the object was just created during the
628 * evaluation of an expression, and we can safely use it since it
629 * is not used anywhere else.
631 NewObjDesc
= ObjDesc
;
632 if (ObjDesc
->Common
.ReferenceCount
> 1)
634 Status
= AcpiUtCopyIobjectToIobject (
635 ObjDesc
, &NewObjDesc
, WalkState
);
636 if (ACPI_FAILURE (Status
))
638 return_ACPI_STATUS (Status
);
643 * If there is an object already in this slot, we either
644 * have to delete it, or if this is an argument and there
645 * is an object reference stored there, we have to do
651 * Check for an indirect store if an argument
652 * contains an object reference (stored as an Node).
653 * We don't allow this automatic dereferencing for
654 * locals, since a store to a local should overwrite
655 * anything there, including an object reference.
657 * If both Arg0 and Local0 contain RefOf (Local4):
659 * Store (1, Arg0) - Causes indirect store to local4
660 * Store (1, Local0) - Stores 1 in local0, overwriting
661 * the reference to local4
662 * Store (1, DeRefof (Local0)) - Causes indirect store to local4
666 if (Type
== ACPI_REFCLASS_ARG
)
669 * If we have a valid reference object that came from RefOf(),
670 * do the indirect store
672 if ((ACPI_GET_DESCRIPTOR_TYPE (CurrentObjDesc
) ==
673 ACPI_DESC_TYPE_OPERAND
) &&
674 (CurrentObjDesc
->Common
.Type
==
675 ACPI_TYPE_LOCAL_REFERENCE
) &&
676 (CurrentObjDesc
->Reference
.Class
==
677 ACPI_REFCLASS_REFOF
))
679 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
680 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
681 NewObjDesc
, CurrentObjDesc
));
684 * Store this object to the Node (perform the indirect store)
685 * NOTE: No implicit conversion is performed, as per the ACPI
686 * specification rules on storing to Locals/Args.
688 Status
= AcpiExStoreObjectToNode (NewObjDesc
,
689 CurrentObjDesc
->Reference
.Object
, WalkState
,
690 ACPI_NO_IMPLICIT_CONVERSION
);
692 /* Remove local reference if we copied the object above */
694 if (NewObjDesc
!= ObjDesc
)
696 AcpiUtRemoveReference (NewObjDesc
);
699 return_ACPI_STATUS (Status
);
703 /* Delete the existing object before storing the new one */
705 AcpiDsMethodDataDeleteValue (Type
, Index
, WalkState
);
709 * Install the Obj descriptor (*NewObjDesc) into
710 * the descriptor for the Arg or Local.
711 * (increments the object reference count by one)
713 Status
= AcpiDsMethodDataSetValue (Type
, Index
, NewObjDesc
, WalkState
);
715 /* Remove local reference if we copied the object above */
717 if (NewObjDesc
!= ObjDesc
)
719 AcpiUtRemoveReference (NewObjDesc
);
722 return_ACPI_STATUS (Status
);
726 #ifdef ACPI_OBSOLETE_FUNCTIONS
727 /*******************************************************************************
729 * FUNCTION: AcpiDsMethodDataGetType
731 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
732 * Index - Which Local or Arg whose type to get
733 * WalkState - Current walk state object
735 * RETURN: Data type of current value of the selected Arg or Local
737 * DESCRIPTION: Get the type of the object stored in the Local or Arg
739 ******************************************************************************/
742 AcpiDsMethodDataGetType (
745 ACPI_WALK_STATE
*WalkState
)
748 ACPI_NAMESPACE_NODE
*Node
;
749 ACPI_OPERAND_OBJECT
*Object
;
752 ACPI_FUNCTION_TRACE (DsMethodDataGetType
);
755 /* Get the namespace node for the arg/local */
757 Status
= AcpiDsMethodDataGetNode (Opcode
, Index
, WalkState
, &Node
);
758 if (ACPI_FAILURE (Status
))
760 return_VALUE ((ACPI_TYPE_NOT_FOUND
));
765 Object
= AcpiNsGetAttachedObject (Node
);
768 /* Uninitialized local/arg, return TYPE_ANY */
770 return_VALUE (ACPI_TYPE_ANY
);
773 /* Get the object type */
775 return_VALUE (Object
->Type
);