ACPICA: Clarify ACPI_FREE_BUFFER usage.
[deliverable/linux.git] / drivers / acpi / acpica / dsmthdat.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
3 * Module Name: dsmthdat - control method arguments and local variables
4 *
5 ******************************************************************************/
6
7/*
25f044e6 8 * Copyright (C) 2000 - 2013, Intel Corp.
1da177e4
LT
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
25 *
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.
29 *
30 * NO WARRANTY
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.
42 */
43
1da177e4 44#include <acpi/acpi.h>
e2f7a777
LB
45#include "accommon.h"
46#include "acdispat.h"
47#include "acnamesp.h"
48#include "acinterp.h"
1da177e4 49
1da177e4 50#define _COMPONENT ACPI_DISPATCHER
4be44fcd 51ACPI_MODULE_NAME("dsmthdat")
1da177e4 52
44f6c012 53/* Local prototypes */
44f6c012 54static void
1044f1f6 55acpi_ds_method_data_delete_value(u8 type,
4be44fcd 56 u32 index, struct acpi_walk_state *walk_state);
44f6c012
RM
57
58static acpi_status
1044f1f6 59acpi_ds_method_data_set_value(u8 type,
4be44fcd
LB
60 u32 index,
61 union acpi_operand_object *object,
62 struct acpi_walk_state *walk_state);
44f6c012
RM
63
64#ifdef ACPI_OBSOLETE_FUNCTIONS
65acpi_object_type
4be44fcd
LB
66acpi_ds_method_data_get_type(u16 opcode,
67 u32 index, struct acpi_walk_state *walk_state);
44f6c012
RM
68#endif
69
1da177e4
LT
70/*******************************************************************************
71 *
72 * FUNCTION: acpi_ds_method_data_init
73 *
74 * PARAMETERS: walk_state - Current walk state object
75 *
76 * RETURN: Status
77 *
78 * DESCRIPTION: Initialize the data structures that hold the method's arguments
73a3090a 79 * and locals. The data struct is an array of namespace nodes for
44f6c012 80 * each - this allows ref_of and de_ref_of to work properly for these
1da177e4
LT
81 * special data types.
82 *
83 * NOTES: walk_state fields are initialized to zero by the
8313524a 84 * ACPI_ALLOCATE_ZEROED().
1da177e4
LT
85 *
86 * A pseudo-Namespace Node is assigned to each argument and local
87 * so that ref_of() can return a pointer to the Node.
88 *
89 ******************************************************************************/
90
4be44fcd 91void acpi_ds_method_data_init(struct acpi_walk_state *walk_state)
1da177e4 92{
4be44fcd 93 u32 i;
1da177e4 94
b229cf92 95 ACPI_FUNCTION_TRACE(ds_method_data_init);
1da177e4
LT
96
97 /* Init the method arguments */
98
99 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
4be44fcd 100 ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name,
1da177e4
LT
101 NAMEOF_ARG_NTE);
102 walk_state->arguments[i].name.integer |= (i << 24);
61686124 103 walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED;
4be44fcd 104 walk_state->arguments[i].type = ACPI_TYPE_ANY;
c45b5c09 105 walk_state->arguments[i].flags = ANOBJ_METHOD_ARG;
1da177e4
LT
106 }
107
108 /* Init the method locals */
109
110 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
4be44fcd 111 ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name,
1da177e4
LT
112 NAMEOF_LOCAL_NTE);
113
114 walk_state->local_variables[i].name.integer |= (i << 24);
61686124 115 walk_state->local_variables[i].descriptor_type =
4be44fcd
LB
116 ACPI_DESC_TYPE_NAMED;
117 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
c45b5c09 118 walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL;
1da177e4
LT
119 }
120
121 return_VOID;
122}
123
1da177e4
LT
124/*******************************************************************************
125 *
126 * FUNCTION: acpi_ds_method_data_delete_all
127 *
128 * PARAMETERS: walk_state - Current walk state object
129 *
130 * RETURN: None
131 *
73a3090a 132 * DESCRIPTION: Delete method locals and arguments. Arguments are only
1da177e4
LT
133 * deleted if this method was called from another method.
134 *
135 ******************************************************************************/
136
4be44fcd 137void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
1da177e4 138{
4be44fcd 139 u32 index;
1da177e4 140
b229cf92 141 ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
1da177e4
LT
142
143 /* Detach the locals */
144
145 for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
146 if (walk_state->local_variables[index].object) {
b27d6597 147 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
4be44fcd
LB
148 index,
149 walk_state->local_variables[index].
150 object));
1da177e4
LT
151
152 /* Detach object (if present) and remove a reference */
153
4be44fcd
LB
154 acpi_ns_detach_object(&walk_state->
155 local_variables[index]);
1da177e4
LT
156 }
157 }
158
159 /* Detach the arguments */
160
161 for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
162 if (walk_state->arguments[index].object) {
b27d6597 163 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
4be44fcd
LB
164 index,
165 walk_state->arguments[index].object));
1da177e4
LT
166
167 /* Detach object (if present) and remove a reference */
168
4be44fcd 169 acpi_ns_detach_object(&walk_state->arguments[index]);
1da177e4
LT
170 }
171 }
172
173 return_VOID;
174}
175
1da177e4
LT
176/*******************************************************************************
177 *
178 * FUNCTION: acpi_ds_method_data_init_args
179 *
ba494bee 180 * PARAMETERS: *params - Pointer to a parameter list for the method
1da177e4
LT
181 * max_param_count - The arg count for this method
182 * walk_state - Current walk state object
183 *
184 * RETURN: Status
185 *
73a3090a 186 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
1da177e4
LT
187 * of ACPI operand objects, either null terminated or whose length
188 * is defined by max_param_count.
189 *
190 ******************************************************************************/
191
192acpi_status
4be44fcd
LB
193acpi_ds_method_data_init_args(union acpi_operand_object **params,
194 u32 max_param_count,
195 struct acpi_walk_state *walk_state)
1da177e4 196{
4be44fcd
LB
197 acpi_status status;
198 u32 index = 0;
1da177e4 199
b229cf92 200 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
1da177e4
LT
201
202 if (!params) {
4be44fcd
LB
203 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
204 "No param list passed to method\n"));
205 return_ACPI_STATUS(AE_OK);
1da177e4
LT
206 }
207
44f6c012 208 /* Copy passed parameters into the new method stack frame */
1da177e4 209
44f6c012 210 while ((index < ACPI_METHOD_NUM_ARGS) &&
4be44fcd 211 (index < max_param_count) && params[index]) {
1da177e4
LT
212 /*
213 * A valid parameter.
214 * Store the argument in the method/walk descriptor.
215 * Do not copy the arg in order to implement call by reference
216 */
1044f1f6 217 status = acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
4be44fcd
LB
218 params[index],
219 walk_state);
220 if (ACPI_FAILURE(status)) {
221 return_ACPI_STATUS(status);
1da177e4
LT
222 }
223
224 index++;
225 }
226
b27d6597 227 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index));
4be44fcd 228 return_ACPI_STATUS(AE_OK);
1da177e4
LT
229}
230
1da177e4
LT
231/*******************************************************************************
232 *
233 * FUNCTION: acpi_ds_method_data_get_node
234 *
ba494bee 235 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
1044f1f6 236 * ACPI_REFCLASS_ARG
ba494bee 237 * index - Which Local or Arg whose type to get
1da177e4 238 * walk_state - Current walk state object
ba494bee 239 * node - Where the node is returned.
1da177e4 240 *
44f6c012
RM
241 * RETURN: Status and node
242 *
243 * DESCRIPTION: Get the Node associated with a local or arg.
1da177e4
LT
244 *
245 ******************************************************************************/
246
247acpi_status
1044f1f6 248acpi_ds_method_data_get_node(u8 type,
4be44fcd
LB
249 u32 index,
250 struct acpi_walk_state *walk_state,
251 struct acpi_namespace_node **node)
1da177e4 252{
b229cf92 253 ACPI_FUNCTION_TRACE(ds_method_data_get_node);
1da177e4
LT
254
255 /*
256 * Method Locals and Arguments are supported
257 */
1044f1f6
BM
258 switch (type) {
259 case ACPI_REFCLASS_LOCAL:
1da177e4
LT
260
261 if (index > ACPI_METHOD_MAX_LOCAL) {
b8e4d893 262 ACPI_ERROR((AE_INFO,
f6a22b0b 263 "Local index %u is invalid (max %u)",
b8e4d893 264 index, ACPI_METHOD_MAX_LOCAL));
4be44fcd 265 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
1da177e4
LT
266 }
267
268 /* Return a pointer to the pseudo-node */
269
270 *node = &walk_state->local_variables[index];
271 break;
272
1044f1f6 273 case ACPI_REFCLASS_ARG:
1da177e4
LT
274
275 if (index > ACPI_METHOD_MAX_ARG) {
b8e4d893 276 ACPI_ERROR((AE_INFO,
f6a22b0b 277 "Arg index %u is invalid (max %u)",
b8e4d893 278 index, ACPI_METHOD_MAX_ARG));
4be44fcd 279 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
1da177e4
LT
280 }
281
282 /* Return a pointer to the pseudo-node */
283
284 *node = &walk_state->arguments[index];
285 break;
286
287 default:
1d1ea1b7 288
f6a22b0b 289 ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
1044f1f6 290 return_ACPI_STATUS(AE_TYPE);
1da177e4
LT
291 }
292
4be44fcd 293 return_ACPI_STATUS(AE_OK);
1da177e4
LT
294}
295
1da177e4
LT
296/*******************************************************************************
297 *
298 * FUNCTION: acpi_ds_method_data_set_value
299 *
ba494bee 300 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
1044f1f6 301 * ACPI_REFCLASS_ARG
ba494bee
BM
302 * index - Which Local or Arg to get
303 * object - Object to be inserted into the stack entry
1da177e4
LT
304 * walk_state - Current walk state object
305 *
306 * RETURN: Status
307 *
308 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
309 * Note: There is no "implicit conversion" for locals.
310 *
311 ******************************************************************************/
312
44f6c012 313static acpi_status
1044f1f6 314acpi_ds_method_data_set_value(u8 type,
4be44fcd
LB
315 u32 index,
316 union acpi_operand_object *object,
317 struct acpi_walk_state *walk_state)
1da177e4 318{
4be44fcd
LB
319 acpi_status status;
320 struct acpi_namespace_node *node;
1da177e4 321
b229cf92 322 ACPI_FUNCTION_TRACE(ds_method_data_set_value);
1da177e4 323
4be44fcd 324 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
b27d6597 325 "NewObj %p Type %2.2X, Refs=%u [%s]\n", object,
1044f1f6 326 type, object->common.reference_count,
4be44fcd 327 acpi_ut_get_type_name(object->common.type)));
1da177e4
LT
328
329 /* Get the namespace node for the arg/local */
330
1044f1f6 331 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
4be44fcd
LB
332 if (ACPI_FAILURE(status)) {
333 return_ACPI_STATUS(status);
1da177e4
LT
334 }
335
336 /*
337 * Increment ref count so object can't be deleted while installed.
338 * NOTE: We do not copy the object in order to preserve the call by
339 * reference semantics of ACPI Control Method invocation.
ba494bee 340 * (See ACPI Specification 2.0C)
1da177e4 341 */
4be44fcd 342 acpi_ut_add_reference(object);
1da177e4
LT
343
344 /* Install the object */
345
346 node->object = object;
4be44fcd 347 return_ACPI_STATUS(status);
1da177e4
LT
348}
349
1da177e4
LT
350/*******************************************************************************
351 *
352 * FUNCTION: acpi_ds_method_data_get_value
353 *
ba494bee 354 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
1044f1f6 355 * ACPI_REFCLASS_ARG
ba494bee 356 * index - Which localVar or argument to get
1da177e4 357 * walk_state - Current walk state object
44f6c012 358 * dest_desc - Where Arg or Local value is returned
1da177e4
LT
359 *
360 * RETURN: Status
361 *
44f6c012 362 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
1da177e4
LT
363 * Used only in acpi_ex_resolve_to_value().
364 *
365 ******************************************************************************/
366
367acpi_status
1044f1f6 368acpi_ds_method_data_get_value(u8 type,
4be44fcd
LB
369 u32 index,
370 struct acpi_walk_state *walk_state,
371 union acpi_operand_object **dest_desc)
1da177e4 372{
4be44fcd
LB
373 acpi_status status;
374 struct acpi_namespace_node *node;
375 union acpi_operand_object *object;
1da177e4 376
b229cf92 377 ACPI_FUNCTION_TRACE(ds_method_data_get_value);
1da177e4
LT
378
379 /* Validate the object descriptor */
380
381 if (!dest_desc) {
b8e4d893 382 ACPI_ERROR((AE_INFO, "Null object descriptor pointer"));
4be44fcd 383 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
384 }
385
386 /* Get the namespace node for the arg/local */
387
1044f1f6 388 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
4be44fcd
LB
389 if (ACPI_FAILURE(status)) {
390 return_ACPI_STATUS(status);
1da177e4
LT
391 }
392
393 /* Get the object from the node */
394
395 object = node->object;
396
397 /* Examine the returned object, it must be valid. */
398
399 if (!object) {
400 /*
401 * Index points to uninitialized object.
402 * This means that either 1) The expected argument was
403 * not passed to the method, or 2) A local variable
404 * was referenced by the method (via the ASL)
73a3090a 405 * before it was initialized. Either case is an error.
1da177e4
LT
406 */
407
408 /* If slack enabled, init the local_x/arg_x to an Integer of value zero */
409
410 if (acpi_gbl_enable_interpreter_slack) {
dc95a270 411 object = acpi_ut_create_integer_object((u64) 0);
1da177e4 412 if (!object) {
4be44fcd 413 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
414 }
415
1da177e4
LT
416 node->object = object;
417 }
418
419 /* Otherwise, return the error */
420
4be44fcd 421 else
1044f1f6
BM
422 switch (type) {
423 case ACPI_REFCLASS_ARG:
1da177e4 424
b8e4d893 425 ACPI_ERROR((AE_INFO,
f6a22b0b 426 "Uninitialized Arg[%u] at node %p",
b8e4d893 427 index, node));
1da177e4 428
4be44fcd 429 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
1da177e4 430
1044f1f6 431 case ACPI_REFCLASS_LOCAL:
e678902e
BM
432 /*
433 * No error message for this case, will be trapped again later to
434 * detect and ignore cases of Store(local_x,local_x)
435 */
4be44fcd 436 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
1da177e4 437
4be44fcd 438 default:
1044f1f6 439
b8e4d893 440 ACPI_ERROR((AE_INFO,
f6a22b0b 441 "Not a Arg/Local opcode: 0x%X",
1044f1f6 442 type));
4be44fcd
LB
443 return_ACPI_STATUS(AE_AML_INTERNAL);
444 }
1da177e4
LT
445 }
446
447 /*
448 * The Index points to an initialized and valid object.
449 * Return an additional reference to the object
450 */
451 *dest_desc = object;
4be44fcd 452 acpi_ut_add_reference(object);
1da177e4 453
4be44fcd 454 return_ACPI_STATUS(AE_OK);
1da177e4
LT
455}
456
1da177e4
LT
457/*******************************************************************************
458 *
459 * FUNCTION: acpi_ds_method_data_delete_value
460 *
ba494bee 461 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
1044f1f6 462 * ACPI_REFCLASS_ARG
ba494bee 463 * index - Which localVar or argument to delete
1da177e4
LT
464 * walk_state - Current walk state object
465 *
466 * RETURN: None
467 *
73a3090a 468 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
1da177e4
LT
469 * a null into the stack slot after the object is deleted.
470 *
471 ******************************************************************************/
472
44f6c012 473static void
1044f1f6 474acpi_ds_method_data_delete_value(u8 type,
4be44fcd 475 u32 index, struct acpi_walk_state *walk_state)
1da177e4 476{
4be44fcd
LB
477 acpi_status status;
478 struct acpi_namespace_node *node;
479 union acpi_operand_object *object;
1da177e4 480
b229cf92 481 ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
1da177e4
LT
482
483 /* Get the namespace node for the arg/local */
484
1044f1f6 485 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
4be44fcd 486 if (ACPI_FAILURE(status)) {
1da177e4
LT
487 return_VOID;
488 }
489
490 /* Get the associated object */
491
4be44fcd 492 object = acpi_ns_get_attached_object(node);
1da177e4
LT
493
494 /*
495 * Undefine the Arg or Local by setting its descriptor
496 * pointer to NULL. Locals/Args can contain both
497 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
498 */
499 node->object = NULL;
500
501 if ((object) &&
4be44fcd 502 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
1da177e4
LT
503 /*
504 * There is a valid object.
505 * Decrement the reference count by one to balance the
506 * increment when the object was stored.
507 */
4be44fcd 508 acpi_ut_remove_reference(object);
1da177e4
LT
509 }
510
511 return_VOID;
512}
513
1da177e4
LT
514/*******************************************************************************
515 *
516 * FUNCTION: acpi_ds_store_object_to_local
517 *
ba494bee 518 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
1044f1f6 519 * ACPI_REFCLASS_ARG
ba494bee 520 * index - Which Local or Arg to set
1da177e4
LT
521 * obj_desc - Value to be stored
522 * walk_state - Current walk state
523 *
524 * RETURN: Status
525 *
73a3090a 526 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
1da177e4
LT
527 * as the new value for the Arg or Local and the reference count
528 * for obj_desc is incremented.
529 *
530 ******************************************************************************/
531
532acpi_status
1044f1f6 533acpi_ds_store_object_to_local(u8 type,
4be44fcd
LB
534 u32 index,
535 union acpi_operand_object *obj_desc,
536 struct acpi_walk_state *walk_state)
1da177e4 537{
4be44fcd
LB
538 acpi_status status;
539 struct acpi_namespace_node *node;
540 union acpi_operand_object *current_obj_desc;
541 union acpi_operand_object *new_obj_desc;
1da177e4 542
b229cf92 543 ACPI_FUNCTION_TRACE(ds_store_object_to_local);
b27d6597 544 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
1044f1f6 545 type, index, obj_desc));
1da177e4
LT
546
547 /* Parameter validation */
548
549 if (!obj_desc) {
4be44fcd 550 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
551 }
552
553 /* Get the namespace node for the arg/local */
554
1044f1f6 555 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
4be44fcd
LB
556 if (ACPI_FAILURE(status)) {
557 return_ACPI_STATUS(status);
1da177e4
LT
558 }
559
4be44fcd 560 current_obj_desc = acpi_ns_get_attached_object(node);
1da177e4 561 if (current_obj_desc == obj_desc) {
4be44fcd
LB
562 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
563 obj_desc));
564 return_ACPI_STATUS(status);
1da177e4
LT
565 }
566
567 /*
568 * If the reference count on the object is more than one, we must
73a3090a 569 * take a copy of the object before we store. A reference count
1da177e4
LT
570 * of exactly 1 means that the object was just created during the
571 * evaluation of an expression, and we can safely use it since it
572 * is not used anywhere else.
573 */
574 new_obj_desc = obj_desc;
575 if (obj_desc->common.reference_count > 1) {
4be44fcd
LB
576 status =
577 acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
578 walk_state);
579 if (ACPI_FAILURE(status)) {
580 return_ACPI_STATUS(status);
1da177e4
LT
581 }
582 }
583
584 /*
585 * If there is an object already in this slot, we either
586 * have to delete it, or if this is an argument and there
587 * is an object reference stored there, we have to do
588 * an indirect store!
589 */
590 if (current_obj_desc) {
591 /*
592 * Check for an indirect store if an argument
593 * contains an object reference (stored as an Node).
594 * We don't allow this automatic dereferencing for
595 * locals, since a store to a local should overwrite
596 * anything there, including an object reference.
597 *
598 * If both Arg0 and Local0 contain ref_of (Local4):
599 *
600 * Store (1, Arg0) - Causes indirect store to local4
601 * Store (1, Local0) - Stores 1 in local0, overwriting
602 * the reference to local4
603 * Store (1, de_refof (Local0)) - Causes indirect store to local4
604 *
605 * Weird, but true.
606 */
1044f1f6 607 if (type == ACPI_REFCLASS_ARG) {
1da177e4 608 /*
44f6c012
RM
609 * If we have a valid reference object that came from ref_of(),
610 * do the indirect store
1da177e4 611 */
4be44fcd
LB
612 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
613 ACPI_DESC_TYPE_OPERAND)
614 && (current_obj_desc->common.type ==
615 ACPI_TYPE_LOCAL_REFERENCE)
1044f1f6
BM
616 && (current_obj_desc->reference.class ==
617 ACPI_REFCLASS_REFOF)) {
4be44fcd 618 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
b229cf92 619 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
4be44fcd
LB
620 new_obj_desc,
621 current_obj_desc));
1da177e4
LT
622
623 /*
624 * Store this object to the Node (perform the indirect store)
625 * NOTE: No implicit conversion is performed, as per the ACPI
626 * specification rules on storing to Locals/Args.
627 */
4be44fcd
LB
628 status =
629 acpi_ex_store_object_to_node(new_obj_desc,
630 current_obj_desc->
631 reference.
632 object,
633 walk_state,
634 ACPI_NO_IMPLICIT_CONVERSION);
1da177e4
LT
635
636 /* Remove local reference if we copied the object above */
637
638 if (new_obj_desc != obj_desc) {
4be44fcd 639 acpi_ut_remove_reference(new_obj_desc);
1da177e4 640 }
4be44fcd 641 return_ACPI_STATUS(status);
1da177e4
LT
642 }
643 }
644
1044f1f6
BM
645 /* Delete the existing object before storing the new one */
646
647 acpi_ds_method_data_delete_value(type, index, walk_state);
1da177e4
LT
648 }
649
650 /*
651 * Install the Obj descriptor (*new_obj_desc) into
652 * the descriptor for the Arg or Local.
653 * (increments the object reference count by one)
654 */
4be44fcd 655 status =
1044f1f6 656 acpi_ds_method_data_set_value(type, index, new_obj_desc,
4be44fcd 657 walk_state);
1da177e4
LT
658
659 /* Remove local reference if we copied the object above */
660
661 if (new_obj_desc != obj_desc) {
4be44fcd 662 acpi_ut_remove_reference(new_obj_desc);
1da177e4
LT
663 }
664
4be44fcd 665 return_ACPI_STATUS(status);
1da177e4
LT
666}
667
44f6c012
RM
668#ifdef ACPI_OBSOLETE_FUNCTIONS
669/*******************************************************************************
670 *
671 * FUNCTION: acpi_ds_method_data_get_type
672 *
ba494bee
BM
673 * PARAMETERS: opcode - Either AML_LOCAL_OP or AML_ARG_OP
674 * index - Which Local or Arg whose type to get
44f6c012
RM
675 * walk_state - Current walk state object
676 *
677 * RETURN: Data type of current value of the selected Arg or Local
678 *
679 * DESCRIPTION: Get the type of the object stored in the Local or Arg
680 *
681 ******************************************************************************/
682
683acpi_object_type
4be44fcd
LB
684acpi_ds_method_data_get_type(u16 opcode,
685 u32 index, struct acpi_walk_state *walk_state)
44f6c012 686{
4be44fcd
LB
687 acpi_status status;
688 struct acpi_namespace_node *node;
689 union acpi_operand_object *object;
44f6c012 690
b229cf92 691 ACPI_FUNCTION_TRACE(ds_method_data_get_type);
44f6c012
RM
692
693 /* Get the namespace node for the arg/local */
694
4be44fcd
LB
695 status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
696 if (ACPI_FAILURE(status)) {
697 return_VALUE((ACPI_TYPE_NOT_FOUND));
44f6c012
RM
698 }
699
700 /* Get the object */
701
4be44fcd 702 object = acpi_ns_get_attached_object(node);
44f6c012 703 if (!object) {
52fc0b02 704
44f6c012
RM
705 /* Uninitialized local/arg, return TYPE_ANY */
706
4be44fcd 707 return_VALUE(ACPI_TYPE_ANY);
44f6c012
RM
708 }
709
710 /* Get the object type */
711
3371c19c 712 return_VALUE(object->type);
44f6c012
RM
713}
714#endif
This page took 0.649279 seconds and 5 git commands to generate.