exoparg1.c 26.9 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2 3 4 5 6 7 8

/******************************************************************************
 *
 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
 *
 *****************************************************************************/

/*
9
 * Copyright (C) 2000 - 2011, Intel Corp.
Linus Torvalds's avatar
Linus Torvalds committed
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 45
 * 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>
Len Brown's avatar
Len Brown committed
46 47 48 49 50 51
#include "accommon.h"
#include "acparser.h"
#include "acdispat.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
Linus Torvalds's avatar
Linus Torvalds committed
52 53

#define _COMPONENT          ACPI_EXECUTER
Len Brown's avatar
Len Brown committed
54
ACPI_MODULE_NAME("exoparg1")
Linus Torvalds's avatar
Linus Torvalds committed
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87

/*!
 * Naming convention for AML interpreter execution routines.
 *
 * The routines that begin execution of AML opcodes are named with a common
 * convention based upon the number of arguments, the number of target operands,
 * and whether or not a value is returned:
 *
 *      AcpiExOpcode_xA_yT_zR
 *
 * Where:
 *
 * xA - ARGUMENTS:    The number of arguments (input operands) that are
 *                    required for this opcode type (0 through 6 args).
 * yT - TARGETS:      The number of targets (output operands) that are required
 *                    for this opcode type (0, 1, or 2 targets).
 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
 *                    as the function return (0 or 1).
 *
 * The AcpiExOpcode* functions are called via the Dispatcher component with
 * fully resolved operands.
!*/
/*******************************************************************************
 *
 * FUNCTION:    acpi_ex_opcode_0A_0T_1R
 *
 * PARAMETERS:  walk_state          - Current state (contains AML opcode)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute operator with no operands, one return value
 *
 ******************************************************************************/
Len Brown's avatar
Len Brown committed
88
acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
89
{
Len Brown's avatar
Len Brown committed
90 91
	acpi_status status = AE_OK;
	union acpi_operand_object *return_desc = NULL;
Linus Torvalds's avatar
Linus Torvalds committed
92

Bob Moore's avatar
Bob Moore committed
93
	ACPI_FUNCTION_TRACE_STR(ex_opcode_0A_0T_1R,
Len Brown's avatar
Len Brown committed
94
				acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
95 96 97 98

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
Len Brown's avatar
Len Brown committed
99
	case AML_TIMER_OP:	/*  Timer () */
Linus Torvalds's avatar
Linus Torvalds committed
100 101 102

		/* Create a return object of type Integer */

103 104
		return_desc =
		    acpi_ut_create_integer_object(acpi_os_get_timer());
Linus Torvalds's avatar
Linus Torvalds committed
105 106 107 108 109 110
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

Len Brown's avatar
Len Brown committed
111
	default:		/*  Unknown opcode  */
Linus Torvalds's avatar
Linus Torvalds committed
112

113
		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Moore's avatar
Bob Moore committed
114
			    walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
115 116 117 118
		status = AE_AML_BAD_OPCODE;
		break;
	}

Len Brown's avatar
Len Brown committed
119
      cleanup:
Linus Torvalds's avatar
Linus Torvalds committed
120 121 122

	/* Delete return object on error */

Len Brown's avatar
Len Brown committed
123 124
	if ((ACPI_FAILURE(status)) || walk_state->result_obj) {
		acpi_ut_remove_reference(return_desc);
125
		walk_state->result_obj = NULL;
Len Brown's avatar
Len Brown committed
126
	} else {
127 128 129 130
		/* Save the return value */

		walk_state->result_obj = return_desc;
	}
Linus Torvalds's avatar
Linus Torvalds committed
131

Len Brown's avatar
Len Brown committed
132
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ex_opcode_1A_0T_0R
 *
 * PARAMETERS:  walk_state          - Current state (contains AML opcode)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
 *              object stack
 *
 ******************************************************************************/

Len Brown's avatar
Len Brown committed
148
acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
149
{
Len Brown's avatar
Len Brown committed
150 151
	union acpi_operand_object **operand = &walk_state->operands[0];
	acpi_status status = AE_OK;
Linus Torvalds's avatar
Linus Torvalds committed
152

Bob Moore's avatar
Bob Moore committed
153
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_0R,
Len Brown's avatar
Len Brown committed
154
				acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
155 156 157 158

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
Len Brown's avatar
Len Brown committed
159
	case AML_RELEASE_OP:	/*  Release (mutex_object) */
Linus Torvalds's avatar
Linus Torvalds committed
160

Len Brown's avatar
Len Brown committed
161
		status = acpi_ex_release_mutex(operand[0], walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
162 163
		break;

Len Brown's avatar
Len Brown committed
164
	case AML_RESET_OP:	/*  Reset (event_object) */
Linus Torvalds's avatar
Linus Torvalds committed
165

Len Brown's avatar
Len Brown committed
166
		status = acpi_ex_system_reset_event(operand[0]);
Linus Torvalds's avatar
Linus Torvalds committed
167 168
		break;

Len Brown's avatar
Len Brown committed
169
	case AML_SIGNAL_OP:	/*  Signal (event_object) */
Linus Torvalds's avatar
Linus Torvalds committed
170

Len Brown's avatar
Len Brown committed
171
		status = acpi_ex_system_signal_event(operand[0]);
Linus Torvalds's avatar
Linus Torvalds committed
172 173
		break;

Len Brown's avatar
Len Brown committed
174
	case AML_SLEEP_OP:	/*  Sleep (msec_time) */
Linus Torvalds's avatar
Linus Torvalds committed
175

176
		status = acpi_ex_system_do_sleep(operand[0]->integer.value);
Linus Torvalds's avatar
Linus Torvalds committed
177 178
		break;

Len Brown's avatar
Len Brown committed
179
	case AML_STALL_OP:	/*  Stall (usec_time) */
Linus Torvalds's avatar
Linus Torvalds committed
180

Len Brown's avatar
Len Brown committed
181 182
		status =
		    acpi_ex_system_do_stall((u32) operand[0]->integer.value);
Linus Torvalds's avatar
Linus Torvalds committed
183 184
		break;

Len Brown's avatar
Len Brown committed
185
	case AML_UNLOAD_OP:	/*  Unload (Handle) */
Linus Torvalds's avatar
Linus Torvalds committed
186

Len Brown's avatar
Len Brown committed
187
		status = acpi_ex_unload_table(operand[0]);
Linus Torvalds's avatar
Linus Torvalds committed
188 189
		break;

Len Brown's avatar
Len Brown committed
190
	default:		/*  Unknown opcode  */
Linus Torvalds's avatar
Linus Torvalds committed
191

192
		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Moore's avatar
Bob Moore committed
193
			    walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
194 195 196 197
		status = AE_AML_BAD_OPCODE;
		break;
	}

Len Brown's avatar
Len Brown committed
198
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ex_opcode_1A_1T_0R
 *
 * PARAMETERS:  walk_state          - Current state (contains AML opcode)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute opcode with one argument, one target, and no
 *              return value.
 *
 ******************************************************************************/

Len Brown's avatar
Len Brown committed
214
acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
215
{
Len Brown's avatar
Len Brown committed
216 217
	acpi_status status = AE_OK;
	union acpi_operand_object **operand = &walk_state->operands[0];
Linus Torvalds's avatar
Linus Torvalds committed
218

Bob Moore's avatar
Bob Moore committed
219
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_0R,
Len Brown's avatar
Len Brown committed
220
				acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
221 222 223 224 225 226

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
	case AML_LOAD_OP:

Len Brown's avatar
Len Brown committed
227
		status = acpi_ex_load_op(operand[0], operand[1], walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
228 229
		break;

Len Brown's avatar
Len Brown committed
230
	default:		/* Unknown opcode */
Linus Torvalds's avatar
Linus Torvalds committed
231

232
		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Moore's avatar
Bob Moore committed
233
			    walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
234 235 236 237
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

Len Brown's avatar
Len Brown committed
238
      cleanup:
Linus Torvalds's avatar
Linus Torvalds committed
239

Len Brown's avatar
Len Brown committed
240
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ex_opcode_1A_1T_1R
 *
 * PARAMETERS:  walk_state          - Current state (contains AML opcode)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute opcode with one argument, one target, and a
 *              return value.
 *
 ******************************************************************************/

Len Brown's avatar
Len Brown committed
256
acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
257
{
Len Brown's avatar
Len Brown committed
258 259 260 261 262 263
	acpi_status status = AE_OK;
	union acpi_operand_object **operand = &walk_state->operands[0];
	union acpi_operand_object *return_desc = NULL;
	union acpi_operand_object *return_desc2 = NULL;
	u32 temp32;
	u32 i;
264 265
	u64 power_of_ten;
	u64 digit;
Len Brown's avatar
Len Brown committed
266

Bob Moore's avatar
Bob Moore committed
267
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
Len Brown's avatar
Len Brown committed
268
				acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
269 270 271 272 273 274 275 276 277 278 279 280 281

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
	case AML_BIT_NOT_OP:
	case AML_FIND_SET_LEFT_BIT_OP:
	case AML_FIND_SET_RIGHT_BIT_OP:
	case AML_FROM_BCD_OP:
	case AML_TO_BCD_OP:
	case AML_COND_REF_OF_OP:

		/* Create a return object of type Integer for these opcodes */

Len Brown's avatar
Len Brown committed
282
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds's avatar
Linus Torvalds committed
283 284 285 286 287 288
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

		switch (walk_state->opcode) {
Len Brown's avatar
Len Brown committed
289
		case AML_BIT_NOT_OP:	/* Not (Operand, Result)  */
Linus Torvalds's avatar
Linus Torvalds committed
290 291 292 293

			return_desc->integer.value = ~operand[0]->integer.value;
			break;

Len Brown's avatar
Len Brown committed
294
		case AML_FIND_SET_LEFT_BIT_OP:	/* find_set_left_bit (Operand, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
295 296 297 298 299 300 301 302

			return_desc->integer.value = operand[0]->integer.value;

			/*
			 * Acpi specification describes Integer type as a little
			 * endian unsigned value, so this boundary condition is valid.
			 */
			for (temp32 = 0; return_desc->integer.value &&
Len Brown's avatar
Len Brown committed
303
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
Linus Torvalds's avatar
Linus Torvalds committed
304 305 306 307 308 309
				return_desc->integer.value >>= 1;
			}

			return_desc->integer.value = temp32;
			break;

Len Brown's avatar
Len Brown committed
310
		case AML_FIND_SET_RIGHT_BIT_OP:	/* find_set_right_bit (Operand, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
311 312 313 314 315 316 317 318

			return_desc->integer.value = operand[0]->integer.value;

			/*
			 * The Acpi specification describes Integer type as a little
			 * endian unsigned value, so this boundary condition is valid.
			 */
			for (temp32 = 0; return_desc->integer.value &&
Len Brown's avatar
Len Brown committed
319
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
Linus Torvalds's avatar
Linus Torvalds committed
320 321 322 323 324
				return_desc->integer.value <<= 1;
			}

			/* Since the bit position is one-based, subtract from 33 (65) */

Bob Moore's avatar
Bob Moore committed
325 326 327
			return_desc->integer.value =
			    temp32 ==
			    0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
Linus Torvalds's avatar
Linus Torvalds committed
328 329
			break;

Len Brown's avatar
Len Brown committed
330
		case AML_FROM_BCD_OP:	/* from_bcd (BCDValue, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
331 332 333 334 335 336 337 338 339 340 341 342

			/*
			 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
			 * (if table is 32-bit, integer can hold 8 BCD characters)
			 * Convert each 4-bit BCD value
			 */
			power_of_ten = 1;
			return_desc->integer.value = 0;
			digit = operand[0]->integer.value;

			/* Convert each BCD digit (each is one nybble wide) */

Len Brown's avatar
Len Brown committed
343 344 345
			for (i = 0;
			     (i < acpi_gbl_integer_nybble_width) && (digit > 0);
			     i++) {
Bob Moore's avatar
Bob Moore committed
346

Linus Torvalds's avatar
Linus Torvalds committed
347 348 349 350 351 352 353
				/* Get the least significant 4-bit BCD digit */

				temp32 = ((u32) digit) & 0xF;

				/* Check the range of the digit */

				if (temp32 > 9) {
Bob Moore's avatar
Bob Moore committed
354 355 356
					ACPI_ERROR((AE_INFO,
						    "BCD digit too large (not decimal): 0x%X",
						    temp32));
Linus Torvalds's avatar
Linus Torvalds committed
357 358 359 360 361 362 363

					status = AE_AML_NUMERIC_OVERFLOW;
					goto cleanup;
				}

				/* Sum the digit into the result with the current power of 10 */

Len Brown's avatar
Len Brown committed
364
				return_desc->integer.value +=
365
				    (((u64) temp32) * power_of_ten);
Linus Torvalds's avatar
Linus Torvalds committed
366 367 368 369 370 371 372 373 374 375 376

				/* Shift to next BCD digit */

				digit >>= 4;

				/* Next power of 10 */

				power_of_ten *= 10;
			}
			break;

Len Brown's avatar
Len Brown committed
377
		case AML_TO_BCD_OP:	/* to_bcd (Operand, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
378 379 380 381 382 383

			return_desc->integer.value = 0;
			digit = operand[0]->integer.value;

			/* Each BCD digit is one nybble wide */

Len Brown's avatar
Len Brown committed
384 385 386 387 388
			for (i = 0;
			     (i < acpi_gbl_integer_nybble_width) && (digit > 0);
			     i++) {
				(void)acpi_ut_short_divide(digit, 10, &digit,
							   &temp32);
Linus Torvalds's avatar
Linus Torvalds committed
389

390 391 392 393
				/*
				 * Insert the BCD digit that resides in the
				 * remainder from above
				 */
Len Brown's avatar
Len Brown committed
394
				return_desc->integer.value |=
395
				    (((u64) temp32) << ACPI_MUL_4(i));
Linus Torvalds's avatar
Linus Torvalds committed
396 397 398 399 400
			}

			/* Overflow if there is any data left in Digit */

			if (digit > 0) {
Bob Moore's avatar
Bob Moore committed
401
				ACPI_ERROR((AE_INFO,
402
					    "Integer too large to convert to BCD: 0x%8.8X%8.8X",
Bob Moore's avatar
Bob Moore committed
403 404
					    ACPI_FORMAT_UINT64(operand[0]->
							       integer.value)));
Linus Torvalds's avatar
Linus Torvalds committed
405 406 407 408 409
				status = AE_AML_NUMERIC_OVERFLOW;
				goto cleanup;
			}
			break;

Len Brown's avatar
Len Brown committed
410
		case AML_COND_REF_OF_OP:	/* cond_ref_of (source_object, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
411 412 413 414 415 416

			/*
			 * This op is a little strange because the internal return value is
			 * different than the return value stored in the result descriptor
			 * (There are really two return values)
			 */
Len Brown's avatar
Len Brown committed
417 418
			if ((struct acpi_namespace_node *)operand[0] ==
			    acpi_gbl_root_node) {
Linus Torvalds's avatar
Linus Torvalds committed
419 420 421 422 423 424 425 426 427 428
				/*
				 * This means that the object does not exist in the namespace,
				 * return FALSE
				 */
				return_desc->integer.value = 0;
				goto cleanup;
			}

			/* Get the object reference, store it, and remove our reference */

Len Brown's avatar
Len Brown committed
429 430 431 432
			status = acpi_ex_get_object_reference(operand[0],
							      &return_desc2,
							      walk_state);
			if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
433 434 435
				goto cleanup;
			}

Len Brown's avatar
Len Brown committed
436 437 438
			status =
			    acpi_ex_store(return_desc2, operand[1], walk_state);
			acpi_ut_remove_reference(return_desc2);
Linus Torvalds's avatar
Linus Torvalds committed
439 440 441

			/* The object exists in the namespace, return TRUE */

442
			return_desc->integer.value = ACPI_UINT64_MAX;
Linus Torvalds's avatar
Linus Torvalds committed
443 444 445 446 447 448 449 450
			goto cleanup;

		default:
			/* No other opcodes get here */
			break;
		}
		break;

Len Brown's avatar
Len Brown committed
451
	case AML_STORE_OP:	/* Store (Source, Target) */
Linus Torvalds's avatar
Linus Torvalds committed
452 453 454 455 456 457

		/*
		 * A store operand is typically a number, string, buffer or lvalue
		 * Be careful about deleting the source object,
		 * since the object itself may have been stored.
		 */
Len Brown's avatar
Len Brown committed
458 459 460
		status = acpi_ex_store(operand[0], operand[1], walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
461 462 463 464 465 466
		}

		/* It is possible that the Store already produced a return object */

		if (!walk_state->result_obj) {
			/*
467 468 469 470
			 * Normally, we would remove a reference on the Operand[0]
			 * parameter; But since it is being used as the internal return
			 * object (meaning we would normally increment it), the two
			 * cancel out, and we simply don't do anything.
Linus Torvalds's avatar
Linus Torvalds committed
471 472
			 */
			walk_state->result_obj = operand[0];
Len Brown's avatar
Len Brown committed
473
			walk_state->operands[0] = NULL;	/* Prevent deletion */
Linus Torvalds's avatar
Linus Torvalds committed
474
		}
Len Brown's avatar
Len Brown committed
475
		return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
476

Len Brown's avatar
Len Brown committed
477 478 479 480
		/*
		 * ACPI 2.0 Opcodes
		 */
	case AML_COPY_OP:	/* Copy (Source, Target) */
Linus Torvalds's avatar
Linus Torvalds committed
481

Len Brown's avatar
Len Brown committed
482 483 484
		status =
		    acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
						    walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
485 486
		break;

Len Brown's avatar
Len Brown committed
487
	case AML_TO_DECSTRING_OP:	/* to_decimal_string (Data, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
488

Len Brown's avatar
Len Brown committed
489 490
		status = acpi_ex_convert_to_string(operand[0], &return_desc,
						   ACPI_EXPLICIT_CONVERT_DECIMAL);
Linus Torvalds's avatar
Linus Torvalds committed
491
		if (return_desc == operand[0]) {
Bob Moore's avatar
Bob Moore committed
492

Linus Torvalds's avatar
Linus Torvalds committed
493
			/* No conversion performed, add ref to handle return value */
Len Brown's avatar
Len Brown committed
494
			acpi_ut_add_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
495 496 497
		}
		break;

Len Brown's avatar
Len Brown committed
498
	case AML_TO_HEXSTRING_OP:	/* to_hex_string (Data, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
499

Len Brown's avatar
Len Brown committed
500 501
		status = acpi_ex_convert_to_string(operand[0], &return_desc,
						   ACPI_EXPLICIT_CONVERT_HEX);
Linus Torvalds's avatar
Linus Torvalds committed
502
		if (return_desc == operand[0]) {
Bob Moore's avatar
Bob Moore committed
503

Linus Torvalds's avatar
Linus Torvalds committed
504
			/* No conversion performed, add ref to handle return value */
Len Brown's avatar
Len Brown committed
505
			acpi_ut_add_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
506 507 508
		}
		break;

Len Brown's avatar
Len Brown committed
509
	case AML_TO_BUFFER_OP:	/* to_buffer (Data, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
510

Len Brown's avatar
Len Brown committed
511
		status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
512
		if (return_desc == operand[0]) {
Bob Moore's avatar
Bob Moore committed
513

Linus Torvalds's avatar
Linus Torvalds committed
514
			/* No conversion performed, add ref to handle return value */
Len Brown's avatar
Len Brown committed
515
			acpi_ut_add_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
516 517 518
		}
		break;

Len Brown's avatar
Len Brown committed
519
	case AML_TO_INTEGER_OP:	/* to_integer (Data, Result) */
Linus Torvalds's avatar
Linus Torvalds committed
520

Len Brown's avatar
Len Brown committed
521 522
		status = acpi_ex_convert_to_integer(operand[0], &return_desc,
						    ACPI_ANY_BASE);
Linus Torvalds's avatar
Linus Torvalds committed
523
		if (return_desc == operand[0]) {
Bob Moore's avatar
Bob Moore committed
524

Linus Torvalds's avatar
Linus Torvalds committed
525
			/* No conversion performed, add ref to handle return value */
Len Brown's avatar
Len Brown committed
526
			acpi_ut_add_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
527 528 529
		}
		break;

Len Brown's avatar
Len Brown committed
530 531
	case AML_SHIFT_LEFT_BIT_OP:	/* shift_left_bit (Source, bit_num) */
	case AML_SHIFT_RIGHT_BIT_OP:	/* shift_right_bit (Source, bit_num) */
Linus Torvalds's avatar
Linus Torvalds committed
532

533 534
		/* These are two obsolete opcodes */

Bob Moore's avatar
Bob Moore committed
535 536 537
		ACPI_ERROR((AE_INFO,
			    "%s is obsolete and not implemented",
			    acpi_ps_get_opcode_name(walk_state->opcode)));
Linus Torvalds's avatar
Linus Torvalds committed
538 539 540
		status = AE_SUPPORT;
		goto cleanup;

Len Brown's avatar
Len Brown committed
541
	default:		/* Unknown opcode */
Linus Torvalds's avatar
Linus Torvalds committed
542

543
		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Moore's avatar
Bob Moore committed
544
			    walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
545 546 547 548
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

Len Brown's avatar
Len Brown committed
549
	if (ACPI_SUCCESS(status)) {
Bob Moore's avatar
Bob Moore committed
550

551 552
		/* Store the return value computed above into the target object */

Len Brown's avatar
Len Brown committed
553
		status = acpi_ex_store(return_desc, operand[1], walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
554 555
	}

Len Brown's avatar
Len Brown committed
556
      cleanup:
Linus Torvalds's avatar
Linus Torvalds committed
557 558 559

	/* Delete return object on error */

Len Brown's avatar
Len Brown committed
560 561
	if (ACPI_FAILURE(status)) {
		acpi_ut_remove_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
562 563
	}

Bob Moore's avatar
Bob Moore committed
564 565 566 567 568 569
	/* Save return object on success */

	else if (!walk_state->result_obj) {
		walk_state->result_obj = return_desc;
	}

Len Brown's avatar
Len Brown committed
570
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
571 572 573 574 575 576 577 578 579 580 581 582 583 584
}

/*******************************************************************************
 *
 * FUNCTION:    acpi_ex_opcode_1A_0T_1R
 *
 * PARAMETERS:  walk_state          - Current state (contains AML opcode)
 *
 * RETURN:      Status
 *
 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
 *
 ******************************************************************************/

Len Brown's avatar
Len Brown committed
585
acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
Linus Torvalds's avatar
Linus Torvalds committed
586
{
Len Brown's avatar
Len Brown committed
587 588 589 590 591
	union acpi_operand_object **operand = &walk_state->operands[0];
	union acpi_operand_object *temp_desc;
	union acpi_operand_object *return_desc = NULL;
	acpi_status status = AE_OK;
	u32 type;
592
	u64 value;
Linus Torvalds's avatar
Linus Torvalds committed
593

Bob Moore's avatar
Bob Moore committed
594
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
Len Brown's avatar
Len Brown committed
595
				acpi_ps_get_opcode_name(walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
596 597 598 599

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
Len Brown's avatar
Len Brown committed
600
	case AML_LNOT_OP:	/* LNot (Operand) */
Linus Torvalds's avatar
Linus Torvalds committed
601

602
		return_desc = acpi_ut_create_integer_object((u64) 0);
Linus Torvalds's avatar
Linus Torvalds committed
603 604 605 606 607 608 609 610 611 612
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

		/*
		 * Set result to ONES (TRUE) if Value == 0.  Note:
		 * return_desc->Integer.Value is initially == 0 (FALSE) from above.
		 */
		if (!operand[0]->integer.value) {
613
			return_desc->integer.value = ACPI_UINT64_MAX;
Linus Torvalds's avatar
Linus Torvalds committed
614 615 616
		}
		break;

Len Brown's avatar
Len Brown committed
617 618
	case AML_DECREMENT_OP:	/* Decrement (Operand)  */
	case AML_INCREMENT_OP:	/* Increment (Operand)  */
Linus Torvalds's avatar
Linus Torvalds committed
619 620 621 622 623

		/*
		 * Create a new integer.  Can't just get the base integer and
		 * increment it because it may be an Arg or Field.
		 */
Len Brown's avatar
Len Brown committed
624
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds's avatar
Linus Torvalds committed
625 626 627 628 629 630 631 632 633 634
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

		/*
		 * Since we are expecting a Reference operand, it can be either a
		 * NS Node or an internal object.
		 */
		temp_desc = operand[0];
Len Brown's avatar
Len Brown committed
635 636
		if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
		    ACPI_DESC_TYPE_OPERAND) {
Bob Moore's avatar
Bob Moore committed
637

Linus Torvalds's avatar
Linus Torvalds committed
638 639
			/* Internal reference object - prevent deletion */

Len Brown's avatar
Len Brown committed
640
			acpi_ut_add_reference(temp_desc);
Linus Torvalds's avatar
Linus Torvalds committed
641 642 643 644 645 646 647 648 649
		}

		/*
		 * Convert the Reference operand to an Integer (This removes a
		 * reference on the Operand[0] object)
		 *
		 * NOTE:  We use LNOT_OP here in order to force resolution of the
		 * reference operand to an actual integer.
		 */
Len Brown's avatar
Len Brown committed
650 651 652 653
		status =
		    acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
					     walk_state);
		if (ACPI_FAILURE(status)) {
Bob Moore's avatar
Bob Moore committed
654 655 656 657
			ACPI_EXCEPTION((AE_INFO, status,
					"While resolving operands for [%s]",
					acpi_ps_get_opcode_name(walk_state->
								opcode)));
Linus Torvalds's avatar
Linus Torvalds committed
658 659 660 661 662 663 664 665 666

			goto cleanup;
		}

		/*
		 * temp_desc is now guaranteed to be an Integer object --
		 * Perform the actual increment or decrement
		 */
		if (walk_state->opcode == AML_INCREMENT_OP) {
Len Brown's avatar
Len Brown committed
667 668 669 670 671
			return_desc->integer.value =
			    temp_desc->integer.value + 1;
		} else {
			return_desc->integer.value =
			    temp_desc->integer.value - 1;
Linus Torvalds's avatar
Linus Torvalds committed
672 673 674 675
		}

		/* Finished with this Integer object */

Len Brown's avatar
Len Brown committed
676
		acpi_ut_remove_reference(temp_desc);
Linus Torvalds's avatar
Linus Torvalds committed
677 678 679 680 681

		/*
		 * Store the result back (indirectly) through the original
		 * Reference object
		 */
Len Brown's avatar
Len Brown committed
682
		status = acpi_ex_store(return_desc, operand[0], walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
683 684
		break;

Len Brown's avatar
Len Brown committed
685
	case AML_TYPE_OP:	/* object_type (source_object) */
Linus Torvalds's avatar
Linus Torvalds committed
686 687 688

		/*
		 * Note: The operand is not resolved at this point because we want to
689 690 691
		 * get the associated object, not its value.  For example, we don't
		 * want to resolve a field_unit to its value, we want the actual
		 * field_unit object.
Linus Torvalds's avatar
Linus Torvalds committed
692 693 694 695
		 */

		/* Get the type of the base object */

Len Brown's avatar
Len Brown committed
696 697 698 699
		status =
		    acpi_ex_resolve_multiple(walk_state, operand[0], &type,
					     NULL);
		if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
700 701
			goto cleanup;
		}
Bob Moore's avatar
Bob Moore committed
702

Linus Torvalds's avatar
Linus Torvalds committed
703 704
		/* Allocate a descriptor to hold the type. */

705
		return_desc = acpi_ut_create_integer_object((u64) type);
Linus Torvalds's avatar
Linus Torvalds committed
706 707 708 709 710 711
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

Len Brown's avatar
Len Brown committed
712
	case AML_SIZE_OF_OP:	/* size_of (source_object) */
Linus Torvalds's avatar
Linus Torvalds committed
713 714 715 716 717 718 719 720

		/*
		 * Note: The operand is not resolved at this point because we want to
		 * get the associated object, not its value.
		 */

		/* Get the base object */

Len Brown's avatar
Len Brown committed
721 722 723 724
		status = acpi_ex_resolve_multiple(walk_state,
						  operand[0], &type,
						  &temp_desc);
		if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745
			goto cleanup;
		}

		/*
		 * The type of the base object must be integer, buffer, string, or
		 * package.  All others are not supported.
		 *
		 * NOTE: Integer is not specifically supported by the ACPI spec,
		 * but is supported implicitly via implicit operand conversion.
		 * rather than bother with conversion, we just use the byte width
		 * global (4 or 8 bytes).
		 */
		switch (type) {
		case ACPI_TYPE_INTEGER:
			value = acpi_gbl_integer_byte_width;
			break;

		case ACPI_TYPE_STRING:
			value = temp_desc->string.length;
			break;

746 747 748 749 750 751 752 753
		case ACPI_TYPE_BUFFER:

			/* Buffer arguments may not be evaluated at this point */

			status = acpi_ds_get_buffer_arguments(temp_desc);
			value = temp_desc->buffer.length;
			break;

Linus Torvalds's avatar
Linus Torvalds committed
754
		case ACPI_TYPE_PACKAGE:
755 756 757 758

			/* Package arguments may not be evaluated at this point */

			status = acpi_ds_get_package_arguments(temp_desc);
Linus Torvalds's avatar
Linus Torvalds committed
759 760 761 762
			value = temp_desc->package.count;
			break;

		default:
Bob Moore's avatar
Bob Moore committed
763
			ACPI_ERROR((AE_INFO,
764
				    "Operand must be Buffer/Integer/String/Package - found type %s",
Bob Moore's avatar
Bob Moore committed
765
				    acpi_ut_get_type_name(type)));
Linus Torvalds's avatar
Linus Torvalds committed
766 767 768 769
			status = AE_AML_OPERAND_TYPE;
			goto cleanup;
		}

770 771 772 773
		if (ACPI_FAILURE(status)) {
			goto cleanup;
		}

Linus Torvalds's avatar
Linus Torvalds committed
774 775 776 777
		/*
		 * Now that we have the size of the object, create a result
		 * object to hold the value
		 */
778
		return_desc = acpi_ut_create_integer_object(value);
Linus Torvalds's avatar
Linus Torvalds committed
779 780 781 782 783 784
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

Len Brown's avatar
Len Brown committed
785
	case AML_REF_OF_OP:	/* ref_of (source_object) */
Linus Torvalds's avatar
Linus Torvalds committed
786

Len Brown's avatar
Len Brown committed
787 788 789 790
		status =
		    acpi_ex_get_object_reference(operand[0], &return_desc,
						 walk_state);
		if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
791 792 793 794
			goto cleanup;
		}
		break;

Len Brown's avatar
Len Brown committed
795
	case AML_DEREF_OF_OP:	/* deref_of (obj_reference | String) */
Linus Torvalds's avatar
Linus Torvalds committed
796 797 798

		/* Check for a method local or argument, or standalone String */

Bob Moore's avatar
Bob Moore committed
799
		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
Len Brown's avatar
Len Brown committed
800
		    ACPI_DESC_TYPE_NAMED) {
Bob Moore's avatar
Bob Moore committed
801 802 803 804 805
			temp_desc =
			    acpi_ns_get_attached_object((struct
							 acpi_namespace_node *)
							operand[0]);
			if (temp_desc
806 807 808
			    && ((temp_desc->common.type == ACPI_TYPE_STRING)
				|| (temp_desc->common.type ==
				    ACPI_TYPE_LOCAL_REFERENCE))) {
Bob Moore's avatar
Bob Moore committed
809 810 811 812 813 814 815
				operand[0] = temp_desc;
				acpi_ut_add_reference(temp_desc);
			} else {
				status = AE_AML_OPERAND_TYPE;
				goto cleanup;
			}
		} else {
816
			switch ((operand[0])->common.type) {
Linus Torvalds's avatar
Linus Torvalds committed
817 818 819 820 821 822
			case ACPI_TYPE_LOCAL_REFERENCE:
				/*
				 * This is a deref_of (local_x | arg_x)
				 *
				 * Must resolve/dereference the local/arg reference first
				 */
823 824 825
				switch (operand[0]->reference.class) {
				case ACPI_REFCLASS_LOCAL:
				case ACPI_REFCLASS_ARG:
Linus Torvalds's avatar
Linus Torvalds committed
826 827 828

					/* Set Operand[0] to the value of the local/arg */

Len Brown's avatar
Len Brown committed
829 830
					status =
					    acpi_ds_method_data_get_value
831 832
					    (operand[0]->reference.class,
					     operand[0]->reference.value,
Len Brown's avatar
Len Brown committed
833 834
					     walk_state, &temp_desc);
					if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
835 836 837 838 839 840 841
						goto cleanup;
					}

					/*
					 * Delete our reference to the input object and
					 * point to the object just retrieved
					 */
Len Brown's avatar
Len Brown committed
842
					acpi_ut_remove_reference(operand[0]);
Linus Torvalds's avatar
Linus Torvalds committed
843 844 845
					operand[0] = temp_desc;
					break;

846
				case ACPI_REFCLASS_REFOF:
Linus Torvalds's avatar
Linus Torvalds committed
847 848 849

					/* Get the object to which the reference refers */

Len Brown's avatar
Len Brown committed
850 851 852
					temp_desc =
					    operand[0]->reference.object;
					acpi_ut_remove_reference(operand[0]);
Linus Torvalds's avatar
Linus Torvalds committed
853 854 855 856 857 858 859 860 861 862 863
					operand[0] = temp_desc;
					break;

				default:

					/* Must be an Index op - handled below */
					break;
				}
				break;

			case ACPI_TYPE_STRING:
Bob Moore's avatar
Bob Moore committed
864
				break;
Linus Torvalds's avatar
Linus Torvalds committed
865

Bob Moore's avatar
Bob Moore committed
866 867 868 869 870 871 872 873
			default:
				status = AE_AML_OPERAND_TYPE;
				goto cleanup;
			}
		}

		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
		    ACPI_DESC_TYPE_NAMED) {
874
			if ((operand[0])->common.type == ACPI_TYPE_STRING) {
Linus Torvalds's avatar
Linus Torvalds committed
875
				/*
876 877
				 * This is a deref_of (String). The string is a reference
				 * to a named ACPI object.
Linus Torvalds's avatar
Linus Torvalds committed
878 879
				 *
				 * 1) Find the owning Node
Bob Moore's avatar
Bob Moore committed
880
				 * 2) Dereference the node to an actual object. Could be a
881
				 *    Field, so we need to resolve the node to a value.
Linus Torvalds's avatar
Linus Torvalds committed
882
				 */
Len Brown's avatar
Len Brown committed
883
				status =
Bob Moore's avatar
Bob Moore committed
884 885 886 887 888 889 890 891
				    acpi_ns_get_node(walk_state->scope_info->
						     scope.node,
						     operand[0]->string.pointer,
						     ACPI_NS_SEARCH_PARENT,
						     ACPI_CAST_INDIRECT_PTR
						     (struct
						      acpi_namespace_node,
						      &return_desc));
Len Brown's avatar
Len Brown committed
892
				if (ACPI_FAILURE(status)) {
Linus Torvalds's avatar
Linus Torvalds committed
893 894 895
					goto cleanup;
				}

Len Brown's avatar
Len Brown committed
896 897 898 899 900
				status =
				    acpi_ex_resolve_node_to_value
				    (ACPI_CAST_INDIRECT_PTR
				     (struct acpi_namespace_node, &return_desc),
				     walk_state);
Linus Torvalds's avatar
Linus Torvalds committed
901 902 903 904 905 906
				goto cleanup;
			}
		}

		/* Operand[0] may have changed from the code above */

Len Brown's avatar
Len Brown committed
907 908
		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
		    ACPI_DESC_TYPE_NAMED) {
Linus Torvalds's avatar
Linus Torvalds committed
909 910 911
			/*
			 * This is a deref_of (object_reference)
			 * Get the actual object from the Node (This is the dereference).
912 913
			 * This case may only happen when a local_x or arg_x is
			 * dereferenced above.
Linus Torvalds's avatar
Linus Torvalds committed
914
			 */
Len Brown's avatar
Len Brown committed
915 916 917 918 919 920
			return_desc = acpi_ns_get_attached_object((struct
								   acpi_namespace_node
								   *)
								  operand[0]);
			acpi_ut_add_reference(return_desc);
		} else {
Linus Torvalds's avatar
Linus Torvalds committed
921
			/*
922 923
			 * This must be a reference object produced by either the
			 * Index() or ref_of() operator
Linus Torvalds's avatar
Linus Torvalds committed
924
			 */
925 926
			switch (operand[0]->reference.class) {
			case ACPI_REFCLASS_INDEX:
Linus Torvalds's avatar
Linus Torvalds committed
927 928 929 930 931 932 933 934

				/*
				 * The target type for the Index operator must be
				 * either a Buffer or a Package
				 */
				switch (operand[0]->reference.target_type) {
				case ACPI_TYPE_BUFFER_FIELD:

Len Brown's avatar
Len Brown committed
935 936
					temp_desc =
					    operand[0]->reference.object;
Linus Torvalds's avatar
Linus Torvalds committed
937 938 939 940 941 942 943 944

					/*
					 * Create a new object that contains one element of the
					 * buffer -- the element pointed to by the index.
					 *
					 * NOTE: index into a buffer is NOT a pointer to a
					 * sub-buffer of the main buffer, it is only a pointer to a
					 * single element (byte) of the buffer!
945 946 947 948
					 *
					 * Since we are returning the value of the buffer at the
					 * indexed location, we don't need to add an additional
					 * reference to the buffer itself.
Linus Torvalds's avatar
Linus Torvalds committed
949
					 */
Len Brown's avatar
Len Brown committed
950
					return_desc =
951 952 953 954 955 956 957 958
					    acpi_ut_create_integer_object((u64)
									  temp_desc->
									  buffer.
									  pointer
									  [operand
									   [0]->
									   reference.
									   value]);
Linus Torvalds's avatar
Linus Torvalds committed
959 960 961 962 963 964 965 966 967
					if (!return_desc) {
						status = AE_NO_MEMORY;
						goto cleanup;
					}
					break;

				case ACPI_TYPE_PACKAGE:

					/*
968 969
					 * Return the referenced element of the package.  We must
					 * add another reference to the referenced object, however.
Linus Torvalds's avatar
Linus Torvalds committed
970
					 */
Len Brown's avatar
Len Brown committed
971 972
					return_desc =
					    *(operand[0]->reference.where);
973
					if (return_desc) {
Len Brown's avatar
Len Brown committed
974 975
						acpi_ut_add_reference
						    (return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
976 977 978 979 980
					}
					break;

				default:

Bob Moore's avatar
Bob Moore committed
981
					ACPI_ERROR((AE_INFO,
982
						    "Unknown Index TargetType 0x%X in reference object %p",
Bob Moore's avatar
Bob Moore committed
983 984
						    operand[0]->reference.
						    target_type, operand[0]));
Linus Torvalds's avatar
Linus Torvalds committed
985 986 987 988 989
					status = AE_AML_OPERAND_TYPE;
					goto cleanup;
				}
				break;

990
			case ACPI_REFCLASS_REFOF:
Linus Torvalds's avatar
Linus Torvalds committed
991 992 993

				return_desc = operand[0]->reference.object;

Len Brown's avatar
Len Brown committed
994 995 996 997 998 999 1000
				if (ACPI_GET_DESCRIPTOR_TYPE(return_desc) ==
				    ACPI_DESC_TYPE_NAMED) {
					return_desc =
					    acpi_ns_get_attached_object((struct
									 acpi_namespace_node
									 *)
									return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
1001 1002 1003 1004
				}

				/* Add another reference to the object! */

Len Brown's avatar
Len Brown committed
1005
				acpi_ut_add_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
1006 1007 1008
				break;

			default:
Bob Moore's avatar
Bob Moore committed
1009
				ACPI_ERROR((AE_INFO,
1010
					    "Unknown class in reference(%p) - 0x%2.2X",
Bob Moore's avatar
Bob Moore committed
1011
					    operand[0],
1012
					    operand[0]->reference.class));
Linus Torvalds's avatar
Linus Torvalds committed
1013 1014 1015 1016 1017 1018 1019 1020 1021

				status = AE_TYPE;
				goto cleanup;
			}
		}
		break;

	default:

1022
		ACPI_ERROR((AE_INFO, "Unknown AML opcode 0x%X",
Bob Moore's avatar
Bob Moore committed
1023
			    walk_state->opcode));
Linus Torvalds's avatar
Linus Torvalds committed
1024 1025 1026 1027
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

Len Brown's avatar
Len Brown committed
1028
      cleanup:
Linus Torvalds's avatar
Linus Torvalds committed
1029 1030 1031

	/* Delete return object on error */

Len Brown's avatar
Len Brown committed
1032 1033
	if (ACPI_FAILURE(status)) {
		acpi_ut_remove_reference(return_desc);
Linus Torvalds's avatar
Linus Torvalds committed
1034 1035
	}

Bob Moore's avatar
Bob Moore committed
1036 1037 1038 1039 1040 1041
	/* Save return object on success */

	else {
		walk_state->result_obj = return_desc;
	}

Len Brown's avatar
Len Brown committed
1042
	return_ACPI_STATUS(status);
Linus Torvalds's avatar
Linus Torvalds committed
1043
}