dsmthdat.c 21.1 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/*******************************************************************************
 *
 * Module Name: dsmthdat - control method arguments and local variables
 *
 ******************************************************************************/

/*
8
 * Copyright (C) 2000 - 2010, Intel Corp.
L
Linus Torvalds 已提交
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions, and the following disclaimer,
 *    without modification.
 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
 *    substantially similar to the "NO WARRANTY" disclaimer below
 *    ("Disclaimer") and any redistribution must be conditioned upon
 *    including a substantially similar Disclaimer requirement for further
 *    binary redistribution.
 * 3. Neither the names of the above-listed copyright holders nor the names
 *    of any contributors may be used to endorse or promote products derived
 *    from this software without specific prior written permission.
 *
 * Alternatively, this software may be distributed under the terms of the
 * GNU General Public License ("GPL") version 2 as published by the Free
 * Software Foundation.
 *
 * NO WARRANTY
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGES.
 */

#include <acpi/acpi.h>
L
Len Brown 已提交
45 46 47 48
#include "accommon.h"
#include "acdispat.h"
#include "acnamesp.h"
#include "acinterp.h"
L
Linus Torvalds 已提交
49 50

#define _COMPONENT          ACPI_DISPATCHER
L
Len Brown 已提交
51
ACPI_MODULE_NAME("dsmthdat")
L
Linus Torvalds 已提交
52

R
Robert Moore 已提交
53 54
/* Local prototypes */
static void
55
acpi_ds_method_data_delete_value(u8 type,
L
Len Brown 已提交
56
				 u32 index, struct acpi_walk_state *walk_state);
R
Robert Moore 已提交
57 58

static acpi_status
59
acpi_ds_method_data_set_value(u8 type,
L
Len Brown 已提交
60 61 62
			      u32 index,
			      union acpi_operand_object *object,
			      struct acpi_walk_state *walk_state);
R
Robert Moore 已提交
63 64 65

#ifdef ACPI_OBSOLETE_FUNCTIONS
acpi_object_type
L
Len Brown 已提交
66 67
acpi_ds_method_data_get_type(u16 opcode,
			     u32 index, struct acpi_walk_state *walk_state);
R
Robert Moore 已提交
68 69
#endif

L
Linus Torvalds 已提交
70 71 72 73 74 75 76 77 78
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_init
 *
 * PARAMETERS:  walk_state          - Current walk state object
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initialize the data structures that hold the method's arguments
R
Robert Moore 已提交
79 80
 *              and locals.  The data struct is an array of namespace nodes for
 *              each - this allows ref_of and de_ref_of to work properly for these
L
Linus Torvalds 已提交
81 82 83
 *              special data types.
 *
 * NOTES:       walk_state fields are initialized to zero by the
B
Bob Moore 已提交
84
 *              ACPI_ALLOCATE_ZEROED().
L
Linus Torvalds 已提交
85 86 87 88 89 90
 *
 *              A pseudo-Namespace Node is assigned to each argument and local
 *              so that ref_of() can return a pointer to the Node.
 *
 ******************************************************************************/

L
Len Brown 已提交
91
void acpi_ds_method_data_init(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
92
{
L
Len Brown 已提交
93
	u32 i;
L
Linus Torvalds 已提交
94

B
Bob Moore 已提交
95
	ACPI_FUNCTION_TRACE(ds_method_data_init);
L
Linus Torvalds 已提交
96 97 98 99

	/* Init the method arguments */

	for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
L
Len Brown 已提交
100
		ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name,
L
Linus Torvalds 已提交
101 102
				   NAMEOF_ARG_NTE);
		walk_state->arguments[i].name.integer |= (i << 24);
B
Bob Moore 已提交
103
		walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED;
L
Len Brown 已提交
104
		walk_state->arguments[i].type = ACPI_TYPE_ANY;
B
Bob Moore 已提交
105 106
		walk_state->arguments[i].flags =
		    ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
L
Linus Torvalds 已提交
107 108 109 110 111
	}

	/* Init the method locals */

	for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
L
Len Brown 已提交
112
		ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name,
L
Linus Torvalds 已提交
113 114 115
				   NAMEOF_LOCAL_NTE);

		walk_state->local_variables[i].name.integer |= (i << 24);
B
Bob Moore 已提交
116
		walk_state->local_variables[i].descriptor_type =
L
Len Brown 已提交
117 118
		    ACPI_DESC_TYPE_NAMED;
		walk_state->local_variables[i].type = ACPI_TYPE_ANY;
B
Bob Moore 已提交
119 120
		walk_state->local_variables[i].flags =
		    ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
L
Linus Torvalds 已提交
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138
	}

	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_delete_all
 *
 * PARAMETERS:  walk_state          - Current walk state object
 *
 * RETURN:      None
 *
 * DESCRIPTION: Delete method locals and arguments.  Arguments are only
 *              deleted if this method was called from another method.
 *
 ******************************************************************************/

L
Len Brown 已提交
139
void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
140
{
L
Len Brown 已提交
141
	u32 index;
L
Linus Torvalds 已提交
142

B
Bob Moore 已提交
143
	ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
L
Linus Torvalds 已提交
144 145 146 147 148

	/* Detach the locals */

	for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
		if (walk_state->local_variables[index].object) {
L
Len Brown 已提交
149 150 151 152
			ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
					  index,
					  walk_state->local_variables[index].
					  object));
L
Linus Torvalds 已提交
153 154 155

			/* Detach object (if present) and remove a reference */

L
Len Brown 已提交
156 157
			acpi_ns_detach_object(&walk_state->
					      local_variables[index]);
L
Linus Torvalds 已提交
158 159 160 161 162 163 164
		}
	}

	/* Detach the arguments */

	for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
		if (walk_state->arguments[index].object) {
L
Len Brown 已提交
165 166 167
			ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
					  index,
					  walk_state->arguments[index].object));
L
Linus Torvalds 已提交
168 169 170

			/* Detach object (if present) and remove a reference */

L
Len Brown 已提交
171
			acpi_ns_detach_object(&walk_state->arguments[index]);
L
Linus Torvalds 已提交
172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194
		}
	}

	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_init_args
 *
 * PARAMETERS:  *Params         - Pointer to a parameter list for the method
 *              max_param_count - The arg count for this method
 *              walk_state      - Current walk state object
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Initialize arguments for a method.  The parameter list is a list
 *              of ACPI operand objects, either null terminated or whose length
 *              is defined by max_param_count.
 *
 ******************************************************************************/

acpi_status
L
Len Brown 已提交
195 196 197
acpi_ds_method_data_init_args(union acpi_operand_object **params,
			      u32 max_param_count,
			      struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
198
{
L
Len Brown 已提交
199 200
	acpi_status status;
	u32 index = 0;
L
Linus Torvalds 已提交
201

B
Bob Moore 已提交
202
	ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
L
Linus Torvalds 已提交
203 204

	if (!params) {
L
Len Brown 已提交
205 206 207
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
				  "No param list passed to method\n"));
		return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
208 209
	}

R
Robert Moore 已提交
210
	/* Copy passed parameters into the new method stack frame */
L
Linus Torvalds 已提交
211

R
Robert Moore 已提交
212
	while ((index < ACPI_METHOD_NUM_ARGS) &&
L
Len Brown 已提交
213
	       (index < max_param_count) && params[index]) {
L
Linus Torvalds 已提交
214 215 216 217 218
		/*
		 * A valid parameter.
		 * Store the argument in the method/walk descriptor.
		 * Do not copy the arg in order to implement call by reference
		 */
219
		status = acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
L
Len Brown 已提交
220 221 222 223
						       params[index],
						       walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
224 225 226 227 228
		}

		index++;
	}

L
Len Brown 已提交
229 230
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%d args passed to method\n", index));
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
231 232 233 234 235 236
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_get_node
 *
237 238
 * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
 *                                    ACPI_REFCLASS_ARG
R
Robert Moore 已提交
239
 *              Index               - Which Local or Arg whose type to get
L
Linus Torvalds 已提交
240
 *              walk_state          - Current walk state object
R
Robert Moore 已提交
241
 *              Node                - Where the node is returned.
L
Linus Torvalds 已提交
242
 *
R
Robert Moore 已提交
243 244 245
 * RETURN:      Status and node
 *
 * DESCRIPTION: Get the Node associated with a local or arg.
L
Linus Torvalds 已提交
246 247 248 249
 *
 ******************************************************************************/

acpi_status
250
acpi_ds_method_data_get_node(u8 type,
L
Len Brown 已提交
251 252 253
			     u32 index,
			     struct acpi_walk_state *walk_state,
			     struct acpi_namespace_node **node)
L
Linus Torvalds 已提交
254
{
B
Bob Moore 已提交
255
	ACPI_FUNCTION_TRACE(ds_method_data_get_node);
L
Linus Torvalds 已提交
256 257 258 259

	/*
	 * Method Locals and Arguments are supported
	 */
260 261
	switch (type) {
	case ACPI_REFCLASS_LOCAL:
L
Linus Torvalds 已提交
262 263

		if (index > ACPI_METHOD_MAX_LOCAL) {
B
Bob Moore 已提交
264 265 266
			ACPI_ERROR((AE_INFO,
				    "Local index %d is invalid (max %d)",
				    index, ACPI_METHOD_MAX_LOCAL));
L
Len Brown 已提交
267
			return_ACPI_STATUS(AE_AML_INVALID_INDEX);
L
Linus Torvalds 已提交
268 269 270 271 272 273 274
		}

		/* Return a pointer to the pseudo-node */

		*node = &walk_state->local_variables[index];
		break;

275
	case ACPI_REFCLASS_ARG:
L
Linus Torvalds 已提交
276 277

		if (index > ACPI_METHOD_MAX_ARG) {
B
Bob Moore 已提交
278 279 280
			ACPI_ERROR((AE_INFO,
				    "Arg index %d is invalid (max %d)",
				    index, ACPI_METHOD_MAX_ARG));
L
Len Brown 已提交
281
			return_ACPI_STATUS(AE_AML_INVALID_INDEX);
L
Linus Torvalds 已提交
282 283 284 285 286 287 288 289
		}

		/* Return a pointer to the pseudo-node */

		*node = &walk_state->arguments[index];
		break;

	default:
290 291
		ACPI_ERROR((AE_INFO, "Type %d is invalid", type));
		return_ACPI_STATUS(AE_TYPE);
L
Linus Torvalds 已提交
292 293
	}

L
Len Brown 已提交
294
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
295 296 297 298 299 300
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_set_value
 *
301 302
 * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
 *                                    ACPI_REFCLASS_ARG
R
Robert Moore 已提交
303
 *              Index               - Which Local or Arg to get
L
Linus Torvalds 已提交
304 305 306 307 308 309 310 311 312 313
 *              Object              - Object to be inserted into the stack entry
 *              walk_state          - Current walk state object
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
 *              Note: There is no "implicit conversion" for locals.
 *
 ******************************************************************************/

R
Robert Moore 已提交
314
static acpi_status
315
acpi_ds_method_data_set_value(u8 type,
L
Len Brown 已提交
316 317 318
			      u32 index,
			      union acpi_operand_object *object,
			      struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
319
{
L
Len Brown 已提交
320 321
	acpi_status status;
	struct acpi_namespace_node *node;
L
Linus Torvalds 已提交
322

B
Bob Moore 已提交
323
	ACPI_FUNCTION_TRACE(ds_method_data_set_value);
L
Linus Torvalds 已提交
324

L
Len Brown 已提交
325
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
326 327
			  "NewObj %p Type %2.2X, Refs=%d [%s]\n", object,
			  type, object->common.reference_count,
L
Len Brown 已提交
328
			  acpi_ut_get_type_name(object->common.type)));
L
Linus Torvalds 已提交
329 330 331

	/* Get the namespace node for the arg/local */

332
	status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
L
Len Brown 已提交
333 334
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
335 336 337 338 339 340
	}

	/*
	 * Increment ref count so object can't be deleted while installed.
	 * NOTE: We do not copy the object in order to preserve the call by
	 * reference semantics of ACPI Control Method invocation.
B
Bob Moore 已提交
341
	 * (See ACPI Specification 2.0_c)
L
Linus Torvalds 已提交
342
	 */
L
Len Brown 已提交
343
	acpi_ut_add_reference(object);
L
Linus Torvalds 已提交
344 345 346 347

	/* Install the object */

	node->object = object;
L
Len Brown 已提交
348
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
349 350 351 352 353 354
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_get_value
 *
355 356
 * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
 *                                    ACPI_REFCLASS_ARG
B
Bob Moore 已提交
357
 *              Index               - Which local_var or argument to get
L
Linus Torvalds 已提交
358
 *              walk_state          - Current walk state object
R
Robert Moore 已提交
359
 *              dest_desc           - Where Arg or Local value is returned
L
Linus Torvalds 已提交
360 361 362
 *
 * RETURN:      Status
 *
R
Robert Moore 已提交
363
 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
L
Linus Torvalds 已提交
364 365 366 367 368
 *              Used only in acpi_ex_resolve_to_value().
 *
 ******************************************************************************/

acpi_status
369
acpi_ds_method_data_get_value(u8 type,
L
Len Brown 已提交
370 371 372
			      u32 index,
			      struct acpi_walk_state *walk_state,
			      union acpi_operand_object **dest_desc)
L
Linus Torvalds 已提交
373
{
L
Len Brown 已提交
374 375 376
	acpi_status status;
	struct acpi_namespace_node *node;
	union acpi_operand_object *object;
L
Linus Torvalds 已提交
377

B
Bob Moore 已提交
378
	ACPI_FUNCTION_TRACE(ds_method_data_get_value);
L
Linus Torvalds 已提交
379 380 381 382

	/* Validate the object descriptor */

	if (!dest_desc) {
B
Bob Moore 已提交
383
		ACPI_ERROR((AE_INFO, "Null object descriptor pointer"));
L
Len Brown 已提交
384
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
385 386 387 388
	}

	/* Get the namespace node for the arg/local */

389
	status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
L
Len Brown 已提交
390 391
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
	}

	/* Get the object from the node */

	object = node->object;

	/* Examine the returned object, it must be valid. */

	if (!object) {
		/*
		 * Index points to uninitialized object.
		 * This means that either 1) The expected argument was
		 * not passed to the method, or 2) A local variable
		 * was referenced by the method (via the ASL)
		 * before it was initialized.  Either case is an error.
		 */

		/* If slack enabled, init the local_x/arg_x to an Integer of value zero */

		if (acpi_gbl_enable_interpreter_slack) {
412
			object = acpi_ut_create_integer_object((u64) 0);
L
Linus Torvalds 已提交
413
			if (!object) {
L
Len Brown 已提交
414
				return_ACPI_STATUS(AE_NO_MEMORY);
L
Linus Torvalds 已提交
415 416 417 418 419 420 421
			}

			node->object = object;
		}

		/* Otherwise, return the error */

L
Len Brown 已提交
422
		else
423 424
			switch (type) {
			case ACPI_REFCLASS_ARG:
L
Linus Torvalds 已提交
425

B
Bob Moore 已提交
426 427 428
				ACPI_ERROR((AE_INFO,
					    "Uninitialized Arg[%d] at node %p",
					    index, node));
L
Linus Torvalds 已提交
429

L
Len Brown 已提交
430
				return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
L
Linus Torvalds 已提交
431

432
			case ACPI_REFCLASS_LOCAL:
L
Linus Torvalds 已提交
433

434 435 436 437
				/*
				 * No error message for this case, will be trapped again later to
				 * detect and ignore cases of Store(local_x,local_x)
				 */
L
Len Brown 已提交
438
				return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
L
Linus Torvalds 已提交
439

L
Len Brown 已提交
440
			default:
441

B
Bob Moore 已提交
442 443
				ACPI_ERROR((AE_INFO,
					    "Not a Arg/Local opcode: %X",
444
					    type));
L
Len Brown 已提交
445 446
				return_ACPI_STATUS(AE_AML_INTERNAL);
			}
L
Linus Torvalds 已提交
447 448 449 450 451 452 453
	}

	/*
	 * The Index points to an initialized and valid object.
	 * Return an additional reference to the object
	 */
	*dest_desc = object;
L
Len Brown 已提交
454
	acpi_ut_add_reference(object);
L
Linus Torvalds 已提交
455

L
Len Brown 已提交
456
	return_ACPI_STATUS(AE_OK);
L
Linus Torvalds 已提交
457 458 459 460 461 462
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_delete_value
 *
463 464
 * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
 *                                    ACPI_REFCLASS_ARG
B
Bob Moore 已提交
465
 *              Index               - Which local_var or argument to delete
L
Linus Torvalds 已提交
466 467 468 469
 *              walk_state          - Current walk state object
 *
 * RETURN:      None
 *
R
Robert Moore 已提交
470
 * DESCRIPTION: Delete the entry at Opcode:Index.  Inserts
L
Linus Torvalds 已提交
471 472 473 474
 *              a null into the stack slot after the object is deleted.
 *
 ******************************************************************************/

R
Robert Moore 已提交
475
static void
476
acpi_ds_method_data_delete_value(u8 type,
L
Len Brown 已提交
477
				 u32 index, struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
478
{
L
Len Brown 已提交
479 480 481
	acpi_status status;
	struct acpi_namespace_node *node;
	union acpi_operand_object *object;
L
Linus Torvalds 已提交
482

B
Bob Moore 已提交
483
	ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
L
Linus Torvalds 已提交
484 485 486

	/* Get the namespace node for the arg/local */

487
	status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
L
Len Brown 已提交
488
	if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
489 490 491 492 493
		return_VOID;
	}

	/* Get the associated object */

L
Len Brown 已提交
494
	object = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
495 496 497 498 499 500 501 502 503

	/*
	 * Undefine the Arg or Local by setting its descriptor
	 * pointer to NULL. Locals/Args can contain both
	 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
	 */
	node->object = NULL;

	if ((object) &&
L
Len Brown 已提交
504
	    (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
L
Linus Torvalds 已提交
505 506 507 508 509
		/*
		 * There is a valid object.
		 * Decrement the reference count by one to balance the
		 * increment when the object was stored.
		 */
L
Len Brown 已提交
510
		acpi_ut_remove_reference(object);
L
Linus Torvalds 已提交
511 512 513 514 515 516 517 518 519
	}

	return_VOID;
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_store_object_to_local
 *
520 521
 * PARAMETERS:  Type                - Either ACPI_REFCLASS_LOCAL or
 *                                    ACPI_REFCLASS_ARG
R
Robert Moore 已提交
522
 *              Index               - Which Local or Arg to set
L
Linus Torvalds 已提交
523 524 525 526 527 528 529 530 531 532 533 534
 *              obj_desc            - Value to be stored
 *              walk_state          - Current walk state
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Store a value in an Arg or Local.  The obj_desc is installed
 *              as the new value for the Arg or Local and the reference count
 *              for obj_desc is incremented.
 *
 ******************************************************************************/

acpi_status
535
acpi_ds_store_object_to_local(u8 type,
L
Len Brown 已提交
536 537 538
			      u32 index,
			      union acpi_operand_object *obj_desc,
			      struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
539
{
L
Len Brown 已提交
540 541 542 543
	acpi_status status;
	struct acpi_namespace_node *node;
	union acpi_operand_object *current_obj_desc;
	union acpi_operand_object *new_obj_desc;
L
Linus Torvalds 已提交
544

B
Bob Moore 已提交
545
	ACPI_FUNCTION_TRACE(ds_store_object_to_local);
546 547
	ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%d Obj=%p\n",
			  type, index, obj_desc));
L
Linus Torvalds 已提交
548 549 550 551

	/* Parameter validation */

	if (!obj_desc) {
L
Len Brown 已提交
552
		return_ACPI_STATUS(AE_BAD_PARAMETER);
L
Linus Torvalds 已提交
553 554 555 556
	}

	/* Get the namespace node for the arg/local */

557
	status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
L
Len Brown 已提交
558 559
	if (ACPI_FAILURE(status)) {
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
560 561
	}

L
Len Brown 已提交
562
	current_obj_desc = acpi_ns_get_attached_object(node);
L
Linus Torvalds 已提交
563
	if (current_obj_desc == obj_desc) {
L
Len Brown 已提交
564 565 566
		ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
				  obj_desc));
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
567 568 569 570 571 572 573 574 575 576 577
	}

	/*
	 * If the reference count on the object is more than one, we must
	 * take a copy of the object before we store.  A reference count
	 * of exactly 1 means that the object was just created during the
	 * evaluation of an expression, and we can safely use it since it
	 * is not used anywhere else.
	 */
	new_obj_desc = obj_desc;
	if (obj_desc->common.reference_count > 1) {
L
Len Brown 已提交
578 579 580 581 582
		status =
		    acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
						    walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
		}
	}

	/*
	 * If there is an object already in this slot, we either
	 * have to delete it, or if this is an argument and there
	 * is an object reference stored there, we have to do
	 * an indirect store!
	 */
	if (current_obj_desc) {
		/*
		 * Check for an indirect store if an argument
		 * contains an object reference (stored as an Node).
		 * We don't allow this automatic dereferencing for
		 * locals, since a store to a local should overwrite
		 * anything there, including an object reference.
		 *
		 * If both Arg0 and Local0 contain ref_of (Local4):
		 *
		 * Store (1, Arg0)             - Causes indirect store to local4
		 * Store (1, Local0)           - Stores 1 in local0, overwriting
		 *                                  the reference to local4
		 * Store (1, de_refof (Local0)) - Causes indirect store to local4
		 *
		 * Weird, but true.
		 */
609
		if (type == ACPI_REFCLASS_ARG) {
L
Linus Torvalds 已提交
610
			/*
R
Robert Moore 已提交
611 612
			 * If we have a valid reference object that came from ref_of(),
			 * do the indirect store
L
Linus Torvalds 已提交
613
			 */
L
Len Brown 已提交
614 615 616 617
			if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
			     ACPI_DESC_TYPE_OPERAND)
			    && (current_obj_desc->common.type ==
				ACPI_TYPE_LOCAL_REFERENCE)
618 619
			    && (current_obj_desc->reference.class ==
				ACPI_REFCLASS_REFOF)) {
L
Len Brown 已提交
620
				ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
B
Bob Moore 已提交
621
						  "Arg (%p) is an ObjRef(Node), storing in node %p\n",
L
Len Brown 已提交
622 623
						  new_obj_desc,
						  current_obj_desc));
L
Linus Torvalds 已提交
624 625 626 627 628 629

				/*
				 * Store this object to the Node (perform the indirect store)
				 * NOTE: No implicit conversion is performed, as per the ACPI
				 * specification rules on storing to Locals/Args.
				 */
L
Len Brown 已提交
630 631 632 633 634 635 636
				status =
				    acpi_ex_store_object_to_node(new_obj_desc,
								 current_obj_desc->
								 reference.
								 object,
								 walk_state,
								 ACPI_NO_IMPLICIT_CONVERSION);
L
Linus Torvalds 已提交
637 638 639 640

				/* Remove local reference if we copied the object above */

				if (new_obj_desc != obj_desc) {
L
Len Brown 已提交
641
					acpi_ut_remove_reference(new_obj_desc);
L
Linus Torvalds 已提交
642
				}
L
Len Brown 已提交
643
				return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
644 645 646
			}
		}

647 648 649
		/* Delete the existing object before storing the new one */

		acpi_ds_method_data_delete_value(type, index, walk_state);
L
Linus Torvalds 已提交
650 651 652 653 654 655 656
	}

	/*
	 * Install the Obj descriptor (*new_obj_desc) into
	 * the descriptor for the Arg or Local.
	 * (increments the object reference count by one)
	 */
L
Len Brown 已提交
657
	status =
658
	    acpi_ds_method_data_set_value(type, index, new_obj_desc,
L
Len Brown 已提交
659
					  walk_state);
L
Linus Torvalds 已提交
660 661 662 663

	/* Remove local reference if we copied the object above */

	if (new_obj_desc != obj_desc) {
L
Len Brown 已提交
664
		acpi_ut_remove_reference(new_obj_desc);
L
Linus Torvalds 已提交
665 666
	}

L
Len Brown 已提交
667
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
668 669
}

R
Robert Moore 已提交
670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685
#ifdef ACPI_OBSOLETE_FUNCTIONS
/*******************************************************************************
 *
 * FUNCTION:    acpi_ds_method_data_get_type
 *
 * PARAMETERS:  Opcode              - Either AML_LOCAL_OP or AML_ARG_OP
 *              Index               - Which Local or Arg whose type to get
 *              walk_state          - Current walk state object
 *
 * RETURN:      Data type of current value of the selected Arg or Local
 *
 * DESCRIPTION: Get the type of the object stored in the Local or Arg
 *
 ******************************************************************************/

acpi_object_type
L
Len Brown 已提交
686 687
acpi_ds_method_data_get_type(u16 opcode,
			     u32 index, struct acpi_walk_state *walk_state)
R
Robert Moore 已提交
688
{
L
Len Brown 已提交
689 690 691
	acpi_status status;
	struct acpi_namespace_node *node;
	union acpi_operand_object *object;
R
Robert Moore 已提交
692

B
Bob Moore 已提交
693
	ACPI_FUNCTION_TRACE(ds_method_data_get_type);
R
Robert Moore 已提交
694 695 696

	/* Get the namespace node for the arg/local */

L
Len Brown 已提交
697 698 699
	status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
	if (ACPI_FAILURE(status)) {
		return_VALUE((ACPI_TYPE_NOT_FOUND));
R
Robert Moore 已提交
700 701 702 703
	}

	/* Get the object */

L
Len Brown 已提交
704
	object = acpi_ns_get_attached_object(node);
R
Robert Moore 已提交
705
	if (!object) {
B
Bob Moore 已提交
706

R
Robert Moore 已提交
707 708
		/* Uninitialized local/arg, return TYPE_ANY */

L
Len Brown 已提交
709
		return_VALUE(ACPI_TYPE_ANY);
R
Robert Moore 已提交
710 711 712 713
	}

	/* Get the object type */

714
	return_VALUE(object->type);
R
Robert Moore 已提交
715 716
}
#endif