exoparg1.c 26.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7 8

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

/*
L
Len Brown 已提交
9
 * Copyright (C) 2000 - 2008, Intel Corp.
L
Linus Torvalds 已提交
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>
L
Len Brown 已提交
46 47 48 49 50 51
#include "accommon.h"
#include "acparser.h"
#include "acdispat.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
L
Linus Torvalds 已提交
52 53

#define _COMPONENT          ACPI_EXECUTER
L
Len Brown 已提交
54
ACPI_MODULE_NAME("exoparg1")
L
Linus Torvalds 已提交
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
 *
 ******************************************************************************/
L
Len Brown 已提交
88
acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
89
{
L
Len Brown 已提交
90 91
	acpi_status status = AE_OK;
	union acpi_operand_object *return_desc = NULL;
L
Linus Torvalds 已提交
92

B
Bob Moore 已提交
93
	ACPI_FUNCTION_TRACE_STR(ex_opcode_0A_0T_1R,
L
Len Brown 已提交
94
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
95 96 97 98

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
L
Len Brown 已提交
99
	case AML_TIMER_OP:	/*  Timer () */
L
Linus Torvalds 已提交
100 101 102

		/* Create a return object of type Integer */

103 104
		return_desc =
		    acpi_ut_create_integer_object(acpi_os_get_timer());
L
Linus Torvalds 已提交
105 106 107 108 109 110
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

L
Len Brown 已提交
111
	default:		/*  Unknown opcode  */
L
Linus Torvalds 已提交
112

B
Bob Moore 已提交
113 114
		ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
			    walk_state->opcode));
L
Linus Torvalds 已提交
115 116 117 118
		status = AE_AML_BAD_OPCODE;
		break;
	}

L
Len Brown 已提交
119
      cleanup:
L
Linus Torvalds 已提交
120 121 122

	/* Delete return object on error */

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

		walk_state->result_obj = return_desc;
	}
L
Linus Torvalds 已提交
131

L
Len Brown 已提交
132
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
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
 *
 ******************************************************************************/

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

B
Bob Moore 已提交
153
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_0R,
L
Len Brown 已提交
154
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
155 156 157 158

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
L
Len Brown 已提交
159
	case AML_RELEASE_OP:	/*  Release (mutex_object) */
L
Linus Torvalds 已提交
160

L
Len Brown 已提交
161
		status = acpi_ex_release_mutex(operand[0], walk_state);
L
Linus Torvalds 已提交
162 163
		break;

L
Len Brown 已提交
164
	case AML_RESET_OP:	/*  Reset (event_object) */
L
Linus Torvalds 已提交
165

L
Len Brown 已提交
166
		status = acpi_ex_system_reset_event(operand[0]);
L
Linus Torvalds 已提交
167 168
		break;

L
Len Brown 已提交
169
	case AML_SIGNAL_OP:	/*  Signal (event_object) */
L
Linus Torvalds 已提交
170

L
Len Brown 已提交
171
		status = acpi_ex_system_signal_event(operand[0]);
L
Linus Torvalds 已提交
172 173
		break;

L
Len Brown 已提交
174
	case AML_SLEEP_OP:	/*  Sleep (msec_time) */
L
Linus Torvalds 已提交
175

L
Len Brown 已提交
176
		status = acpi_ex_system_do_suspend(operand[0]->integer.value);
L
Linus Torvalds 已提交
177 178
		break;

L
Len Brown 已提交
179
	case AML_STALL_OP:	/*  Stall (usec_time) */
L
Linus Torvalds 已提交
180

L
Len Brown 已提交
181 182
		status =
		    acpi_ex_system_do_stall((u32) operand[0]->integer.value);
L
Linus Torvalds 已提交
183 184
		break;

L
Len Brown 已提交
185
	case AML_UNLOAD_OP:	/*  Unload (Handle) */
L
Linus Torvalds 已提交
186

L
Len Brown 已提交
187
		status = acpi_ex_unload_table(operand[0]);
L
Linus Torvalds 已提交
188 189
		break;

L
Len Brown 已提交
190
	default:		/*  Unknown opcode  */
L
Linus Torvalds 已提交
191

B
Bob Moore 已提交
192 193
		ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
			    walk_state->opcode));
L
Linus Torvalds 已提交
194 195 196 197
		status = AE_AML_BAD_OPCODE;
		break;
	}

L
Len Brown 已提交
198
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
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.
 *
 ******************************************************************************/

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

B
Bob Moore 已提交
219
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_0R,
L
Len Brown 已提交
220
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
221 222 223 224 225 226

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
	case AML_LOAD_OP:

L
Len Brown 已提交
227
		status = acpi_ex_load_op(operand[0], operand[1], walk_state);
L
Linus Torvalds 已提交
228 229
		break;

L
Len Brown 已提交
230
	default:		/* Unknown opcode */
L
Linus Torvalds 已提交
231

B
Bob Moore 已提交
232 233
		ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
			    walk_state->opcode));
L
Linus Torvalds 已提交
234 235 236 237
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

L
Len Brown 已提交
238
      cleanup:
L
Linus Torvalds 已提交
239

L
Len Brown 已提交
240
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
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.
 *
 ******************************************************************************/

L
Len Brown 已提交
256
acpi_status acpi_ex_opcode_1A_1T_1R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
257
{
L
Len Brown 已提交
258 259 260 261 262 263 264 265 266
	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;
	acpi_integer power_of_ten;
	acpi_integer digit;

B
Bob Moore 已提交
267
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
L
Len Brown 已提交
268
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
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 */

L
Len Brown 已提交
282
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
L
Linus Torvalds 已提交
283 284 285 286 287 288
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

		switch (walk_state->opcode) {
L
Len Brown 已提交
289
		case AML_BIT_NOT_OP:	/* Not (Operand, Result)  */
L
Linus Torvalds 已提交
290 291 292 293

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

L
Len Brown 已提交
294
		case AML_FIND_SET_LEFT_BIT_OP:	/* find_set_left_bit (Operand, Result) */
L
Linus Torvalds 已提交
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 &&
L
Len Brown 已提交
303
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
L
Linus Torvalds 已提交
304 305 306 307 308 309
				return_desc->integer.value >>= 1;
			}

			return_desc->integer.value = temp32;
			break;

L
Len Brown 已提交
310
		case AML_FIND_SET_RIGHT_BIT_OP:	/* find_set_right_bit (Operand, Result) */
L
Linus Torvalds 已提交
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 &&
L
Len Brown 已提交
319
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
L
Linus Torvalds 已提交
320 321 322 323 324
				return_desc->integer.value <<= 1;
			}

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

B
Bob Moore 已提交
325 326 327
			return_desc->integer.value =
			    temp32 ==
			    0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - temp32;
L
Linus Torvalds 已提交
328 329
			break;

L
Len Brown 已提交
330
		case AML_FROM_BCD_OP:	/* from_bcd (BCDValue, Result) */
L
Linus Torvalds 已提交
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) */

L
Len Brown 已提交
343 344 345
			for (i = 0;
			     (i < acpi_gbl_integer_nybble_width) && (digit > 0);
			     i++) {
B
Bob Moore 已提交
346

L
Linus Torvalds 已提交
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) {
B
Bob Moore 已提交
354 355 356
					ACPI_ERROR((AE_INFO,
						    "BCD digit too large (not decimal): 0x%X",
						    temp32));
L
Linus Torvalds 已提交
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 */

L
Len Brown 已提交
364 365
				return_desc->integer.value +=
				    (((acpi_integer) temp32) * power_of_ten);
L
Linus Torvalds 已提交
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;

L
Len Brown 已提交
377
		case AML_TO_BCD_OP:	/* to_bcd (Operand, Result) */
L
Linus Torvalds 已提交
378 379 380 381 382 383

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

			/* Each BCD digit is one nybble wide */

L
Len Brown 已提交
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);
L
Linus Torvalds 已提交
389

R
Robert Moore 已提交
390 391 392 393
				/*
				 * Insert the BCD digit that resides in the
				 * remainder from above
				 */
L
Len Brown 已提交
394 395
				return_desc->integer.value |=
				    (((acpi_integer) temp32) << ACPI_MUL_4(i));
L
Linus Torvalds 已提交
396 397 398 399 400
			}

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

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

L
Len Brown 已提交
410
		case AML_COND_REF_OF_OP:	/* cond_ref_of (source_object, Result) */
L
Linus Torvalds 已提交
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)
			 */
L
Len Brown 已提交
417 418
			if ((struct acpi_namespace_node *)operand[0] ==
			    acpi_gbl_root_node) {
L
Linus Torvalds 已提交
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 */

L
Len Brown 已提交
429 430 431 432
			status = acpi_ex_get_object_reference(operand[0],
							      &return_desc2,
							      walk_state);
			if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
433 434 435
				goto cleanup;
			}

L
Len Brown 已提交
436 437 438
			status =
			    acpi_ex_store(return_desc2, operand[1], walk_state);
			acpi_ut_remove_reference(return_desc2);
L
Linus Torvalds 已提交
439 440 441 442 443 444 445 446 447 448 449 450

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

			return_desc->integer.value = ACPI_INTEGER_MAX;
			goto cleanup;

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

L
Len Brown 已提交
451
	case AML_STORE_OP:	/* Store (Source, Target) */
L
Linus Torvalds 已提交
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.
		 */
L
Len Brown 已提交
458 459 460
		status = acpi_ex_store(operand[0], operand[1], walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
461 462 463 464 465 466
		}

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

		if (!walk_state->result_obj) {
			/*
R
Robert Moore 已提交
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.
L
Linus Torvalds 已提交
471 472
			 */
			walk_state->result_obj = operand[0];
L
Len Brown 已提交
473
			walk_state->operands[0] = NULL;	/* Prevent deletion */
L
Linus Torvalds 已提交
474
		}
L
Len Brown 已提交
475
		return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
476

L
Len Brown 已提交
477 478 479 480
		/*
		 * ACPI 2.0 Opcodes
		 */
	case AML_COPY_OP:	/* Copy (Source, Target) */
L
Linus Torvalds 已提交
481

L
Len Brown 已提交
482 483 484
		status =
		    acpi_ut_copy_iobject_to_iobject(operand[0], &return_desc,
						    walk_state);
L
Linus Torvalds 已提交
485 486
		break;

L
Len Brown 已提交
487
	case AML_TO_DECSTRING_OP:	/* to_decimal_string (Data, Result) */
L
Linus Torvalds 已提交
488

L
Len Brown 已提交
489 490
		status = acpi_ex_convert_to_string(operand[0], &return_desc,
						   ACPI_EXPLICIT_CONVERT_DECIMAL);
L
Linus Torvalds 已提交
491
		if (return_desc == operand[0]) {
B
Bob Moore 已提交
492

L
Linus Torvalds 已提交
493
			/* No conversion performed, add ref to handle return value */
L
Len Brown 已提交
494
			acpi_ut_add_reference(return_desc);
L
Linus Torvalds 已提交
495 496 497
		}
		break;

L
Len Brown 已提交
498
	case AML_TO_HEXSTRING_OP:	/* to_hex_string (Data, Result) */
L
Linus Torvalds 已提交
499

L
Len Brown 已提交
500 501
		status = acpi_ex_convert_to_string(operand[0], &return_desc,
						   ACPI_EXPLICIT_CONVERT_HEX);
L
Linus Torvalds 已提交
502
		if (return_desc == operand[0]) {
B
Bob Moore 已提交
503

L
Linus Torvalds 已提交
504
			/* No conversion performed, add ref to handle return value */
L
Len Brown 已提交
505
			acpi_ut_add_reference(return_desc);
L
Linus Torvalds 已提交
506 507 508
		}
		break;

L
Len Brown 已提交
509
	case AML_TO_BUFFER_OP:	/* to_buffer (Data, Result) */
L
Linus Torvalds 已提交
510

L
Len Brown 已提交
511
		status = acpi_ex_convert_to_buffer(operand[0], &return_desc);
L
Linus Torvalds 已提交
512
		if (return_desc == operand[0]) {
B
Bob Moore 已提交
513

L
Linus Torvalds 已提交
514
			/* No conversion performed, add ref to handle return value */
L
Len Brown 已提交
515
			acpi_ut_add_reference(return_desc);
L
Linus Torvalds 已提交
516 517 518
		}
		break;

L
Len Brown 已提交
519
	case AML_TO_INTEGER_OP:	/* to_integer (Data, Result) */
L
Linus Torvalds 已提交
520

L
Len Brown 已提交
521 522
		status = acpi_ex_convert_to_integer(operand[0], &return_desc,
						    ACPI_ANY_BASE);
L
Linus Torvalds 已提交
523
		if (return_desc == operand[0]) {
B
Bob Moore 已提交
524

L
Linus Torvalds 已提交
525
			/* No conversion performed, add ref to handle return value */
L
Len Brown 已提交
526
			acpi_ut_add_reference(return_desc);
L
Linus Torvalds 已提交
527 528 529
		}
		break;

L
Len Brown 已提交
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) */
L
Linus Torvalds 已提交
532

R
Robert Moore 已提交
533 534
		/* These are two obsolete opcodes */

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

L
Len Brown 已提交
541
	default:		/* Unknown opcode */
L
Linus Torvalds 已提交
542

B
Bob Moore 已提交
543 544
		ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
			    walk_state->opcode));
L
Linus Torvalds 已提交
545 546 547 548
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

L
Len Brown 已提交
549
	if (ACPI_SUCCESS(status)) {
B
Bob Moore 已提交
550

R
Robert Moore 已提交
551 552
		/* Store the return value computed above into the target object */

L
Len Brown 已提交
553
		status = acpi_ex_store(return_desc, operand[1], walk_state);
L
Linus Torvalds 已提交
554 555
	}

L
Len Brown 已提交
556
      cleanup:
L
Linus Torvalds 已提交
557 558 559

	/* Delete return object on error */

L
Len Brown 已提交
560 561
	if (ACPI_FAILURE(status)) {
		acpi_ut_remove_reference(return_desc);
L
Linus Torvalds 已提交
562 563
	}

B
Bob Moore 已提交
564 565 566 567 568 569
	/* Save return object on success */

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

L
Len Brown 已提交
570
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
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
 *
 ******************************************************************************/

L
Len Brown 已提交
585
acpi_status acpi_ex_opcode_1A_0T_1R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
586
{
L
Len Brown 已提交
587 588 589 590 591 592
	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;
	acpi_integer value;
L
Linus Torvalds 已提交
593

B
Bob Moore 已提交
594
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_0T_1R,
L
Len Brown 已提交
595
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
596 597 598 599

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
L
Len Brown 已提交
600
	case AML_LNOT_OP:	/* LNot (Operand) */
L
Linus Torvalds 已提交
601

602
		return_desc = acpi_ut_create_integer_object((u64) 0);
L
Linus Torvalds 已提交
603 604 605 606 607 608 609 610 611 612 613 614 615 616
		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) {
			return_desc->integer.value = ACPI_INTEGER_MAX;
		}
		break;

L
Len Brown 已提交
617 618
	case AML_DECREMENT_OP:	/* Decrement (Operand)  */
	case AML_INCREMENT_OP:	/* Increment (Operand)  */
L
Linus Torvalds 已提交
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.
		 */
L
Len Brown 已提交
624
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
L
Linus Torvalds 已提交
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];
L
Len Brown 已提交
635 636
		if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
		    ACPI_DESC_TYPE_OPERAND) {
B
Bob Moore 已提交
637

L
Linus Torvalds 已提交
638 639
			/* Internal reference object - prevent deletion */

L
Len Brown 已提交
640
			acpi_ut_add_reference(temp_desc);
L
Linus Torvalds 已提交
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.
		 */
L
Len Brown 已提交
650 651 652 653
		status =
		    acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
					     walk_state);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
654 655 656 657
			ACPI_EXCEPTION((AE_INFO, status,
					"While resolving operands for [%s]",
					acpi_ps_get_opcode_name(walk_state->
								opcode)));
L
Linus Torvalds 已提交
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) {
L
Len Brown 已提交
667 668 669 670 671
			return_desc->integer.value =
			    temp_desc->integer.value + 1;
		} else {
			return_desc->integer.value =
			    temp_desc->integer.value - 1;
L
Linus Torvalds 已提交
672 673 674 675
		}

		/* Finished with this Integer object */

L
Len Brown 已提交
676
		acpi_ut_remove_reference(temp_desc);
L
Linus Torvalds 已提交
677 678 679 680 681

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

L
Len Brown 已提交
685
	case AML_TYPE_OP:	/* object_type (source_object) */
L
Linus Torvalds 已提交
686 687 688

		/*
		 * Note: The operand is not resolved at this point because we want to
R
Robert Moore 已提交
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.
L
Linus Torvalds 已提交
692 693 694 695
		 */

		/* Get the type of the base object */

L
Len Brown 已提交
696 697 698 699
		status =
		    acpi_ex_resolve_multiple(walk_state, operand[0], &type,
					     NULL);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
700 701
			goto cleanup;
		}
B
Bob Moore 已提交
702

L
Linus Torvalds 已提交
703 704
		/* Allocate a descriptor to hold the type. */

705
		return_desc = acpi_ut_create_integer_object((u64) type);
L
Linus Torvalds 已提交
706 707 708 709 710 711
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

L
Len Brown 已提交
712
	case AML_SIZE_OF_OP:	/* size_of (source_object) */
L
Linus Torvalds 已提交
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 */

L
Len Brown 已提交
721 722 723 724
		status = acpi_ex_resolve_multiple(walk_state,
						  operand[0], &type,
						  &temp_desc);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
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;

L
Linus Torvalds 已提交
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);
L
Linus Torvalds 已提交
759 760 761 762
			value = temp_desc->package.count;
			break;

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

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

L
Linus Torvalds 已提交
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);
L
Linus Torvalds 已提交
779 780 781 782 783 784
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}
		break;

L
Len Brown 已提交
785
	case AML_REF_OF_OP:	/* ref_of (source_object) */
L
Linus Torvalds 已提交
786

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

L
Len Brown 已提交
795
	case AML_DEREF_OF_OP:	/* deref_of (obj_reference | String) */
L
Linus Torvalds 已提交
796 797 798

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

B
Bob Moore 已提交
799
		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
L
Len Brown 已提交
800
		    ACPI_DESC_TYPE_NAMED) {
B
Bob Moore 已提交
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))) {
B
Bob Moore 已提交
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) {
L
Linus Torvalds 已提交
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:
L
Linus Torvalds 已提交
826 827 828

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

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

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

846
				case ACPI_REFCLASS_REFOF:
L
Linus Torvalds 已提交
847 848 849

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

L
Len Brown 已提交
850 851 852
					temp_desc =
					    operand[0]->reference.object;
					acpi_ut_remove_reference(operand[0]);
L
Linus Torvalds 已提交
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:
B
Bob Moore 已提交
864
				break;
L
Linus Torvalds 已提交
865

B
Bob Moore 已提交
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) {
L
Linus Torvalds 已提交
875
				/*
R
Robert Moore 已提交
876 877
				 * This is a deref_of (String). The string is a reference
				 * to a named ACPI object.
L
Linus Torvalds 已提交
878 879
				 *
				 * 1) Find the owning Node
B
Bob Moore 已提交
880
				 * 2) Dereference the node to an actual object. Could be a
R
Robert Moore 已提交
881
				 *    Field, so we need to resolve the node to a value.
L
Linus Torvalds 已提交
882
				 */
L
Len Brown 已提交
883
				status =
B
Bob Moore 已提交
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));
L
Len Brown 已提交
892
				if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
893 894 895
					goto cleanup;
				}

L
Len Brown 已提交
896 897 898 899 900
				status =
				    acpi_ex_resolve_node_to_value
				    (ACPI_CAST_INDIRECT_PTR
				     (struct acpi_namespace_node, &return_desc),
				     walk_state);
L
Linus Torvalds 已提交
901 902 903 904 905 906
				goto cleanup;
			}
		}

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

L
Len Brown 已提交
907 908
		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) ==
		    ACPI_DESC_TYPE_NAMED) {
L
Linus Torvalds 已提交
909 910 911
			/*
			 * This is a deref_of (object_reference)
			 * Get the actual object from the Node (This is the dereference).
R
Robert Moore 已提交
912 913
			 * This case may only happen when a local_x or arg_x is
			 * dereferenced above.
L
Linus Torvalds 已提交
914
			 */
L
Len Brown 已提交
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 {
L
Linus Torvalds 已提交
921
			/*
R
Robert Moore 已提交
922 923
			 * This must be a reference object produced by either the
			 * Index() or ref_of() operator
L
Linus Torvalds 已提交
924
			 */
925 926
			switch (operand[0]->reference.class) {
			case ACPI_REFCLASS_INDEX:
L
Linus Torvalds 已提交
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:

L
Len Brown 已提交
935 936
					temp_desc =
					    operand[0]->reference.object;
L
Linus Torvalds 已提交
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.
L
Linus Torvalds 已提交
949
					 */
L
Len Brown 已提交
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]);
L
Linus Torvalds 已提交
959 960 961 962 963 964 965 966 967
					if (!return_desc) {
						status = AE_NO_MEMORY;
						goto cleanup;
					}
					break;

				case ACPI_TYPE_PACKAGE:

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

				default:

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

990
			case ACPI_REFCLASS_REFOF:
L
Linus Torvalds 已提交
991 992 993

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

L
Len Brown 已提交
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);
L
Linus Torvalds 已提交
1001 1002 1003 1004
				}

				/* Add another reference to the object! */

L
Len Brown 已提交
1005
				acpi_ut_add_reference(return_desc);
L
Linus Torvalds 已提交
1006 1007 1008
				break;

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

				status = AE_TYPE;
				goto cleanup;
			}
		}
		break;

	default:

B
Bob Moore 已提交
1022 1023
		ACPI_ERROR((AE_INFO, "Unknown AML opcode %X",
			    walk_state->opcode));
L
Linus Torvalds 已提交
1024 1025 1026 1027
		status = AE_AML_BAD_OPCODE;
		goto cleanup;
	}

L
Len Brown 已提交
1028
      cleanup:
L
Linus Torvalds 已提交
1029 1030 1031

	/* Delete return object on error */

L
Len Brown 已提交
1032 1033
	if (ACPI_FAILURE(status)) {
		acpi_ut_remove_reference(return_desc);
L
Linus Torvalds 已提交
1034 1035
	}

B
Bob Moore 已提交
1036 1037 1038 1039 1040 1041
	/* Save return object on success */

	else {
		walk_state->result_obj = return_desc;
	}

L
Len Brown 已提交
1042
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
1043
}