1 /*******************************************************************************
3 * Module Name: dsmthdat - control method arguments and local variables
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2016, 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 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_DISPATCHER
51 ACPI_MODULE_NAME("dsmthdat")
53 /* Local prototypes */
55 acpi_ds_method_data_delete_value(u8 type
,
56 u32 index
, struct acpi_walk_state
*walk_state
);
59 acpi_ds_method_data_set_value(u8 type
,
61 union acpi_operand_object
*object
,
62 struct acpi_walk_state
*walk_state
);
64 #ifdef ACPI_OBSOLETE_FUNCTIONS
66 acpi_ds_method_data_get_type(u16 opcode
,
67 u32 index
, struct acpi_walk_state
*walk_state
);
70 /*******************************************************************************
72 * FUNCTION: acpi_ds_method_data_init
74 * PARAMETERS: walk_state - Current walk state object
78 * DESCRIPTION: Initialize the data structures that hold the method's arguments
79 * and locals. The data struct is an array of namespace nodes for
80 * each - this allows ref_of and de_ref_of to work properly for these
83 * NOTES: walk_state fields are initialized to zero by the
84 * ACPI_ALLOCATE_ZEROED().
86 * A pseudo-Namespace Node is assigned to each argument and local
87 * so that ref_of() can return a pointer to the Node.
89 ******************************************************************************/
91 void acpi_ds_method_data_init(struct acpi_walk_state
*walk_state
)
95 ACPI_FUNCTION_TRACE(ds_method_data_init
);
97 /* Init the method arguments */
99 for (i
= 0; i
< ACPI_METHOD_NUM_ARGS
; i
++) {
100 ACPI_MOVE_32_TO_32(&walk_state
->arguments
[i
].name
,
103 walk_state
->arguments
[i
].name
.integer
|= (i
<< 24);
104 walk_state
->arguments
[i
].descriptor_type
= ACPI_DESC_TYPE_NAMED
;
105 walk_state
->arguments
[i
].type
= ACPI_TYPE_ANY
;
106 walk_state
->arguments
[i
].flags
= ANOBJ_METHOD_ARG
;
109 /* Init the method locals */
111 for (i
= 0; i
< ACPI_METHOD_NUM_LOCALS
; i
++) {
112 ACPI_MOVE_32_TO_32(&walk_state
->local_variables
[i
].name
,
115 walk_state
->local_variables
[i
].name
.integer
|= (i
<< 24);
116 walk_state
->local_variables
[i
].descriptor_type
=
117 ACPI_DESC_TYPE_NAMED
;
118 walk_state
->local_variables
[i
].type
= ACPI_TYPE_ANY
;
119 walk_state
->local_variables
[i
].flags
= ANOBJ_METHOD_LOCAL
;
125 /*******************************************************************************
127 * FUNCTION: acpi_ds_method_data_delete_all
129 * PARAMETERS: walk_state - Current walk state object
133 * DESCRIPTION: Delete method locals and arguments. Arguments are only
134 * deleted if this method was called from another method.
136 ******************************************************************************/
138 void acpi_ds_method_data_delete_all(struct acpi_walk_state
*walk_state
)
142 ACPI_FUNCTION_TRACE(ds_method_data_delete_all
);
144 /* Detach the locals */
146 for (index
= 0; index
< ACPI_METHOD_NUM_LOCALS
; index
++) {
147 if (walk_state
->local_variables
[index
].object
) {
148 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Deleting Local%u=%p\n",
150 walk_state
->local_variables
[index
].
153 /* Detach object (if present) and remove a reference */
155 acpi_ns_detach_object(&walk_state
->
156 local_variables
[index
]);
160 /* Detach the arguments */
162 for (index
= 0; index
< ACPI_METHOD_NUM_ARGS
; index
++) {
163 if (walk_state
->arguments
[index
].object
) {
164 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Deleting Arg%u=%p\n",
166 walk_state
->arguments
[index
].object
));
168 /* Detach object (if present) and remove a reference */
170 acpi_ns_detach_object(&walk_state
->arguments
[index
]);
177 /*******************************************************************************
179 * FUNCTION: acpi_ds_method_data_init_args
181 * PARAMETERS: *params - Pointer to a parameter list for the method
182 * max_param_count - The arg count for this method
183 * walk_state - Current walk state object
187 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
188 * of ACPI operand objects, either null terminated or whose length
189 * is defined by max_param_count.
191 ******************************************************************************/
194 acpi_ds_method_data_init_args(union acpi_operand_object
**params
,
196 struct acpi_walk_state
*walk_state
)
201 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args
, params
);
204 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
205 "No parameter list passed to method\n"));
206 return_ACPI_STATUS(AE_OK
);
209 /* Copy passed parameters into the new method stack frame */
211 while ((index
< ACPI_METHOD_NUM_ARGS
) &&
212 (index
< max_param_count
) && params
[index
]) {
215 * Store the argument in the method/walk descriptor.
216 * Do not copy the arg in order to implement call by reference
219 acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG
, index
,
220 params
[index
], walk_state
);
221 if (ACPI_FAILURE(status
)) {
222 return_ACPI_STATUS(status
);
228 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "%u args passed to method\n", index
));
229 return_ACPI_STATUS(AE_OK
);
232 /*******************************************************************************
234 * FUNCTION: acpi_ds_method_data_get_node
236 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
238 * index - Which Local or Arg whose type to get
239 * walk_state - Current walk state object
240 * node - Where the node is returned.
242 * RETURN: Status and node
244 * DESCRIPTION: Get the Node associated with a local or arg.
246 ******************************************************************************/
249 acpi_ds_method_data_get_node(u8 type
,
251 struct acpi_walk_state
*walk_state
,
252 struct acpi_namespace_node
**node
)
254 ACPI_FUNCTION_TRACE(ds_method_data_get_node
);
257 * Method Locals and Arguments are supported
260 case ACPI_REFCLASS_LOCAL
:
262 if (index
> ACPI_METHOD_MAX_LOCAL
) {
264 "Local index %u is invalid (max %u)",
265 index
, ACPI_METHOD_MAX_LOCAL
));
266 return_ACPI_STATUS(AE_AML_INVALID_INDEX
);
269 /* Return a pointer to the pseudo-node */
271 *node
= &walk_state
->local_variables
[index
];
274 case ACPI_REFCLASS_ARG
:
276 if (index
> ACPI_METHOD_MAX_ARG
) {
278 "Arg index %u is invalid (max %u)",
279 index
, ACPI_METHOD_MAX_ARG
));
280 return_ACPI_STATUS(AE_AML_INVALID_INDEX
);
283 /* Return a pointer to the pseudo-node */
285 *node
= &walk_state
->arguments
[index
];
290 ACPI_ERROR((AE_INFO
, "Type %u is invalid", type
));
291 return_ACPI_STATUS(AE_TYPE
);
294 return_ACPI_STATUS(AE_OK
);
297 /*******************************************************************************
299 * FUNCTION: acpi_ds_method_data_set_value
301 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
303 * index - Which Local or Arg to get
304 * object - Object to be inserted into the stack entry
305 * walk_state - Current walk state object
309 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
310 * Note: There is no "implicit conversion" for locals.
312 ******************************************************************************/
315 acpi_ds_method_data_set_value(u8 type
,
317 union acpi_operand_object
*object
,
318 struct acpi_walk_state
*walk_state
)
321 struct acpi_namespace_node
*node
;
323 ACPI_FUNCTION_TRACE(ds_method_data_set_value
);
325 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
326 "NewObj %p Type %2.2X, Refs=%u [%s]\n", object
,
327 type
, object
->common
.reference_count
,
328 acpi_ut_get_type_name(object
->common
.type
)));
330 /* Get the namespace node for the arg/local */
332 status
= acpi_ds_method_data_get_node(type
, index
, walk_state
, &node
);
333 if (ACPI_FAILURE(status
)) {
334 return_ACPI_STATUS(status
);
338 * Increment ref count so object can't be deleted while installed.
339 * NOTE: We do not copy the object in order to preserve the call by
340 * reference semantics of ACPI Control Method invocation.
341 * (See ACPI Specification 2.0C)
343 acpi_ut_add_reference(object
);
345 /* Install the object */
347 node
->object
= object
;
348 return_ACPI_STATUS(status
);
351 /*******************************************************************************
353 * FUNCTION: acpi_ds_method_data_get_value
355 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
357 * index - Which localVar or argument to get
358 * walk_state - Current walk state object
359 * dest_desc - Where Arg or Local value is returned
363 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
364 * Used only in acpi_ex_resolve_to_value().
366 ******************************************************************************/
369 acpi_ds_method_data_get_value(u8 type
,
371 struct acpi_walk_state
*walk_state
,
372 union acpi_operand_object
**dest_desc
)
375 struct acpi_namespace_node
*node
;
376 union acpi_operand_object
*object
;
378 ACPI_FUNCTION_TRACE(ds_method_data_get_value
);
380 /* Validate the object descriptor */
383 ACPI_ERROR((AE_INFO
, "Null object descriptor pointer"));
384 return_ACPI_STATUS(AE_BAD_PARAMETER
);
387 /* Get the namespace node for the arg/local */
389 status
= acpi_ds_method_data_get_node(type
, index
, walk_state
, &node
);
390 if (ACPI_FAILURE(status
)) {
391 return_ACPI_STATUS(status
);
394 /* Get the object from the node */
396 object
= node
->object
;
398 /* Examine the returned object, it must be valid. */
402 * Index points to uninitialized object.
403 * This means that either 1) The expected argument was
404 * not passed to the method, or 2) A local variable
405 * was referenced by the method (via the ASL)
406 * before it was initialized. Either case is an error.
409 /* If slack enabled, init the local_x/arg_x to an Integer of value zero */
411 if (acpi_gbl_enable_interpreter_slack
) {
412 object
= acpi_ut_create_integer_object((u64
) 0);
414 return_ACPI_STATUS(AE_NO_MEMORY
);
417 node
->object
= object
;
420 /* Otherwise, return the error */
424 case ACPI_REFCLASS_ARG
:
427 "Uninitialized Arg[%u] at node %p",
430 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG
);
432 case ACPI_REFCLASS_LOCAL
:
434 * No error message for this case, will be trapped again later to
435 * detect and ignore cases of Store(local_x,local_x)
437 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL
);
442 "Not a Arg/Local opcode: 0x%X",
444 return_ACPI_STATUS(AE_AML_INTERNAL
);
449 * The Index points to an initialized and valid object.
450 * Return an additional reference to the object
453 acpi_ut_add_reference(object
);
455 return_ACPI_STATUS(AE_OK
);
458 /*******************************************************************************
460 * FUNCTION: acpi_ds_method_data_delete_value
462 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
464 * index - Which localVar or argument to delete
465 * walk_state - Current walk state object
469 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
470 * a null into the stack slot after the object is deleted.
472 ******************************************************************************/
475 acpi_ds_method_data_delete_value(u8 type
,
476 u32 index
, struct acpi_walk_state
*walk_state
)
479 struct acpi_namespace_node
*node
;
480 union acpi_operand_object
*object
;
482 ACPI_FUNCTION_TRACE(ds_method_data_delete_value
);
484 /* Get the namespace node for the arg/local */
486 status
= acpi_ds_method_data_get_node(type
, index
, walk_state
, &node
);
487 if (ACPI_FAILURE(status
)) {
491 /* Get the associated object */
493 object
= acpi_ns_get_attached_object(node
);
496 * Undefine the Arg or Local by setting its descriptor
497 * pointer to NULL. Locals/Args can contain both
498 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
503 (ACPI_GET_DESCRIPTOR_TYPE(object
) == ACPI_DESC_TYPE_OPERAND
)) {
505 * There is a valid object.
506 * Decrement the reference count by one to balance the
507 * increment when the object was stored.
509 acpi_ut_remove_reference(object
);
515 /*******************************************************************************
517 * FUNCTION: acpi_ds_store_object_to_local
519 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
521 * index - Which Local or Arg to set
522 * obj_desc - Value to be stored
523 * walk_state - Current walk state
527 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
528 * as the new value for the Arg or Local and the reference count
529 * for obj_desc is incremented.
531 ******************************************************************************/
534 acpi_ds_store_object_to_local(u8 type
,
536 union acpi_operand_object
*obj_desc
,
537 struct acpi_walk_state
*walk_state
)
540 struct acpi_namespace_node
*node
;
541 union acpi_operand_object
*current_obj_desc
;
542 union acpi_operand_object
*new_obj_desc
;
544 ACPI_FUNCTION_TRACE(ds_store_object_to_local
);
545 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Type=%2.2X Index=%u Obj=%p\n",
546 type
, index
, obj_desc
));
548 /* Parameter validation */
551 return_ACPI_STATUS(AE_BAD_PARAMETER
);
554 /* Get the namespace node for the arg/local */
556 status
= acpi_ds_method_data_get_node(type
, index
, walk_state
, &node
);
557 if (ACPI_FAILURE(status
)) {
558 return_ACPI_STATUS(status
);
561 current_obj_desc
= acpi_ns_get_attached_object(node
);
562 if (current_obj_desc
== obj_desc
) {
563 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
, "Obj=%p already installed!\n",
565 return_ACPI_STATUS(status
);
569 * If the reference count on the object is more than one, we must
570 * take a copy of the object before we store. A reference count
571 * of exactly 1 means that the object was just created during the
572 * evaluation of an expression, and we can safely use it since it
573 * is not used anywhere else.
575 new_obj_desc
= obj_desc
;
576 if (obj_desc
->common
.reference_count
> 1) {
578 acpi_ut_copy_iobject_to_iobject(obj_desc
, &new_obj_desc
,
580 if (ACPI_FAILURE(status
)) {
581 return_ACPI_STATUS(status
);
586 * If there is an object already in this slot, we either
587 * have to delete it, or if this is an argument and there
588 * is an object reference stored there, we have to do
591 if (current_obj_desc
) {
593 * Check for an indirect store if an argument
594 * contains an object reference (stored as an Node).
595 * We don't allow this automatic dereferencing for
596 * locals, since a store to a local should overwrite
597 * anything there, including an object reference.
599 * If both Arg0 and Local0 contain ref_of (Local4):
601 * Store (1, Arg0) - Causes indirect store to local4
602 * Store (1, Local0) - Stores 1 in local0, overwriting
603 * the reference to local4
604 * Store (1, de_refof (Local0)) - Causes indirect store to local4
608 if (type
== ACPI_REFCLASS_ARG
) {
610 * If we have a valid reference object that came from ref_of(),
611 * do the indirect store
613 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc
) ==
614 ACPI_DESC_TYPE_OPERAND
) &&
615 (current_obj_desc
->common
.type
==
616 ACPI_TYPE_LOCAL_REFERENCE
) &&
617 (current_obj_desc
->reference
.class ==
618 ACPI_REFCLASS_REFOF
)) {
619 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
620 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
625 * Store this object to the Node (perform the indirect store)
626 * NOTE: No implicit conversion is performed, as per the ACPI
627 * specification rules on storing to Locals/Args.
630 acpi_ex_store_object_to_node(new_obj_desc
,
635 ACPI_NO_IMPLICIT_CONVERSION
);
637 /* Remove local reference if we copied the object above */
639 if (new_obj_desc
!= obj_desc
) {
640 acpi_ut_remove_reference(new_obj_desc
);
643 return_ACPI_STATUS(status
);
647 /* Delete the existing object before storing the new one */
649 acpi_ds_method_data_delete_value(type
, index
, walk_state
);
653 * Install the Obj descriptor (*new_obj_desc) into
654 * the descriptor for the Arg or Local.
655 * (increments the object reference count by one)
658 acpi_ds_method_data_set_value(type
, index
, new_obj_desc
,
661 /* Remove local reference if we copied the object above */
663 if (new_obj_desc
!= obj_desc
) {
664 acpi_ut_remove_reference(new_obj_desc
);
667 return_ACPI_STATUS(status
);
670 #ifdef ACPI_OBSOLETE_FUNCTIONS
671 /*******************************************************************************
673 * FUNCTION: acpi_ds_method_data_get_type
675 * PARAMETERS: opcode - Either AML_LOCAL_OP or AML_ARG_OP
676 * index - Which Local or Arg whose type to get
677 * walk_state - Current walk state object
679 * RETURN: Data type of current value of the selected Arg or Local
681 * DESCRIPTION: Get the type of the object stored in the Local or Arg
683 ******************************************************************************/
686 acpi_ds_method_data_get_type(u16 opcode
,
687 u32 index
, struct acpi_walk_state
*walk_state
)
690 struct acpi_namespace_node
*node
;
691 union acpi_operand_object
*object
;
693 ACPI_FUNCTION_TRACE(ds_method_data_get_type
);
695 /* Get the namespace node for the arg/local */
697 status
= acpi_ds_method_data_get_node(opcode
, index
, walk_state
, &node
);
698 if (ACPI_FAILURE(status
)) {
699 return_VALUE((ACPI_TYPE_NOT_FOUND
));
704 object
= acpi_ns_get_attached_object(node
);
707 /* Uninitialized local/arg, return TYPE_ANY */
709 return_VALUE(ACPI_TYPE_ANY
);
712 /* Get the object type */
714 return_VALUE(object
->type
);