exoparg1.c 26.9 KB
Newer Older
L
Linus Torvalds 已提交
1 2 3 4 5 6 7
/******************************************************************************
 *
 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
 *
 *****************************************************************************/

/*
8
 * Copyright (C) 2000 - 2012, 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 49 50
#include "accommon.h"
#include "acparser.h"
#include "acdispat.h"
#include "acinterp.h"
#include "amlcode.h"
#include "acnamesp.h"
L
Linus Torvalds 已提交
51 52

#define _COMPONENT          ACPI_EXECUTER
L
Len Brown 已提交
53
ACPI_MODULE_NAME("exoparg1")
L
Linus Torvalds 已提交
54 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

/*!
 * 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 已提交
87
acpi_status acpi_ex_opcode_0A_0T_1R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
88
{
L
Len Brown 已提交
89 90
	acpi_status status = AE_OK;
	union acpi_operand_object *return_desc = NULL;
L
Linus Torvalds 已提交
91

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

	/* Examine the AML opcode */

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

		/* Create a return object of type Integer */

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

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

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

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

	/* Delete return object on error */

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

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

L
Len Brown 已提交
131
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
}

/*******************************************************************************
 *
 * 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 已提交
147
acpi_status acpi_ex_opcode_1A_0T_0R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
148
{
L
Len Brown 已提交
149 150
	union acpi_operand_object **operand = &walk_state->operands[0];
	acpi_status status = AE_OK;
L
Linus Torvalds 已提交
151

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

	/* Examine the AML opcode */

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

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

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

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

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

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

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

175
		status = acpi_ex_system_do_sleep(operand[0]->integer.value);
L
Linus Torvalds 已提交
176 177
		break;

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

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

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

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

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

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

L
Len Brown 已提交
197
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
198 199 200 201 202 203 204 205 206 207 208 209 210 211 212
}

/*******************************************************************************
 *
 * 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 已提交
213
acpi_status acpi_ex_opcode_1A_1T_0R(struct acpi_walk_state *walk_state)
L
Linus Torvalds 已提交
214
{
L
Len Brown 已提交
215 216
	acpi_status status = AE_OK;
	union acpi_operand_object **operand = &walk_state->operands[0];
L
Linus Torvalds 已提交
217

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

	/* Examine the AML opcode */

	switch (walk_state->opcode) {
	case AML_LOAD_OP:

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

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

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

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

L
Len Brown 已提交
239
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254
}

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

B
Bob Moore 已提交
266
	ACPI_FUNCTION_TRACE_STR(ex_opcode_1A_1T_1R,
L
Len Brown 已提交
267
				acpi_ps_get_opcode_name(walk_state->opcode));
L
Linus Torvalds 已提交
268 269 270 271 272 273 274 275 276 277 278 279 280

	/* 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 已提交
281
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
L
Linus Torvalds 已提交
282 283 284 285 286 287
		if (!return_desc) {
			status = AE_NO_MEMORY;
			goto cleanup;
		}

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

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

L
Len Brown 已提交
293
		case AML_FIND_SET_LEFT_BIT_OP:	/* find_set_left_bit (Operand, Result) */
L
Linus Torvalds 已提交
294 295 296 297 298 299 300 301

			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 已提交
302
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
L
Linus Torvalds 已提交
303 304 305 306 307 308
				return_desc->integer.value >>= 1;
			}

			return_desc->integer.value = temp32;
			break;

L
Len Brown 已提交
309
		case AML_FIND_SET_RIGHT_BIT_OP:	/* find_set_right_bit (Operand, Result) */
L
Linus Torvalds 已提交
310 311 312 313 314 315 316 317

			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 已提交
318
			     temp32 < ACPI_INTEGER_BIT_SIZE; ++temp32) {
L
Linus Torvalds 已提交
319 320 321 322 323
				return_desc->integer.value <<= 1;
			}

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

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

L
Len Brown 已提交
329
		case AML_FROM_BCD_OP:	/* from_bcd (BCDValue, Result) */
L
Linus Torvalds 已提交
330 331 332 333 334 335 336 337 338 339 340 341

			/*
			 * 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 已提交
342 343 344
			for (i = 0;
			     (i < acpi_gbl_integer_nybble_width) && (digit > 0);
			     i++) {
B
Bob Moore 已提交
345

L
Linus Torvalds 已提交
346 347 348 349 350 351 352
				/* Get the least significant 4-bit BCD digit */

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

				/* Check the range of the digit */

				if (temp32 > 9) {
B
Bob Moore 已提交
353 354 355
					ACPI_ERROR((AE_INFO,
						    "BCD digit too large (not decimal): 0x%X",
						    temp32));
L
Linus Torvalds 已提交
356 357 358 359 360 361 362

					status = AE_AML_NUMERIC_OVERFLOW;
					goto cleanup;
				}

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

L
Len Brown 已提交
363
				return_desc->integer.value +=
364
				    (((u64) temp32) * power_of_ten);
L
Linus Torvalds 已提交
365 366 367 368 369 370 371 372 373 374 375

				/* Shift to next BCD digit */

				digit >>= 4;

				/* Next power of 10 */

				power_of_ten *= 10;
			}
			break;

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

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

			/* Each BCD digit is one nybble wide */

L
Len Brown 已提交
383 384 385 386 387
			for (i = 0;
			     (i < acpi_gbl_integer_nybble_width) && (digit > 0);
			     i++) {
				(void)acpi_ut_short_divide(digit, 10, &digit,
							   &temp32);
L
Linus Torvalds 已提交
388

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

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

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

L
Len Brown 已提交
409
		case AML_COND_REF_OF_OP:	/* cond_ref_of (source_object, Result) */
L
Linus Torvalds 已提交
410 411 412 413 414 415

			/*
			 * 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 已提交
416 417
			if ((struct acpi_namespace_node *)operand[0] ==
			    acpi_gbl_root_node) {
L
Linus Torvalds 已提交
418 419 420 421 422 423 424 425 426 427
				/*
				 * 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 已提交
428 429 430 431
			status = acpi_ex_get_object_reference(operand[0],
							      &return_desc2,
							      walk_state);
			if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
432 433 434
				goto cleanup;
			}

L
Len Brown 已提交
435 436 437
			status =
			    acpi_ex_store(return_desc2, operand[1], walk_state);
			acpi_ut_remove_reference(return_desc2);
L
Linus Torvalds 已提交
438 439 440

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

441
			return_desc->integer.value = ACPI_UINT64_MAX;
L
Linus Torvalds 已提交
442 443 444 445 446 447 448 449
			goto cleanup;

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

L
Len Brown 已提交
450
	case AML_STORE_OP:	/* Store (Source, Target) */
L
Linus Torvalds 已提交
451 452 453 454 455 456

		/*
		 * 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 已提交
457 458 459
		status = acpi_ex_store(operand[0], operand[1], walk_state);
		if (ACPI_FAILURE(status)) {
			return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
460 461 462 463 464 465
		}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

L
Len Brown 已提交
529 530
	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 已提交
531

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

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

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

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

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

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

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

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

	/* Delete return object on error */

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

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

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

L
Len Brown 已提交
569
	return_ACPI_STATUS(status);
L
Linus Torvalds 已提交
570 571 572 573 574 575 576 577 578 579 580 581 582 583
}

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

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

	/* Examine the AML opcode */

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

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

L
Len Brown 已提交
616 617
	case AML_DECREMENT_OP:	/* Decrement (Operand)  */
	case AML_INCREMENT_OP:	/* Increment (Operand)  */
L
Linus Torvalds 已提交
618 619 620 621 622

		/*
		 * 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 已提交
623
		return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
L
Linus Torvalds 已提交
624 625 626 627 628 629 630 631 632 633
		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 已提交
634 635
		if (ACPI_GET_DESCRIPTOR_TYPE(temp_desc) ==
		    ACPI_DESC_TYPE_OPERAND) {
B
Bob Moore 已提交
636

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

L
Len Brown 已提交
639
			acpi_ut_add_reference(temp_desc);
L
Linus Torvalds 已提交
640 641 642 643 644 645 646 647 648
		}

		/*
		 * 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 已提交
649 650 651 652
		status =
		    acpi_ex_resolve_operands(AML_LNOT_OP, &temp_desc,
					     walk_state);
		if (ACPI_FAILURE(status)) {
B
Bob Moore 已提交
653 654 655 656
			ACPI_EXCEPTION((AE_INFO, status,
					"While resolving operands for [%s]",
					acpi_ps_get_opcode_name(walk_state->
								opcode)));
L
Linus Torvalds 已提交
657 658 659 660 661 662 663 664 665

			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 已提交
666 667 668 669 670
			return_desc->integer.value =
			    temp_desc->integer.value + 1;
		} else {
			return_desc->integer.value =
			    temp_desc->integer.value - 1;
L
Linus Torvalds 已提交
671 672 673 674
		}

		/* Finished with this Integer object */

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

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

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

		/*
		 * Note: The operand is not resolved at this point because we want to
R
Robert Moore 已提交
688 689 690
		 * 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 已提交
691 692 693 694
		 */

		/* Get the type of the base object */

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

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

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

L
Len Brown 已提交
711
	case AML_SIZE_OF_OP:	/* size_of (source_object) */
L
Linus Torvalds 已提交
712 713 714 715 716 717 718 719

		/*
		 * 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 已提交
720 721 722 723
		status = acpi_ex_resolve_multiple(walk_state,
						  operand[0], &type,
						  &temp_desc);
		if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744
			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;

745 746 747 748 749 750 751 752
		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 已提交
753
		case ACPI_TYPE_PACKAGE:
754 755 756 757

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

			status = acpi_ds_get_package_arguments(temp_desc);
L
Linus Torvalds 已提交
758 759 760 761
			value = temp_desc->package.count;
			break;

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

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

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

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

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

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

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

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

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

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

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

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

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

L
Len Brown 已提交
849 850 851
					temp_desc =
					    operand[0]->reference.object;
					acpi_ut_remove_reference(operand[0]);
L
Linus Torvalds 已提交
852 853 854 855 856 857 858 859 860 861 862
					operand[0] = temp_desc;
					break;

				default:

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

			case ACPI_TYPE_STRING:
B
Bob Moore 已提交
863
				break;
L
Linus Torvalds 已提交
864

B
Bob Moore 已提交
865 866 867 868 869 870 871 872
			default:
				status = AE_AML_OPERAND_TYPE;
				goto cleanup;
			}
		}

		if (ACPI_GET_DESCRIPTOR_TYPE(operand[0]) !=
		    ACPI_DESC_TYPE_NAMED) {
873
			if ((operand[0])->common.type == ACPI_TYPE_STRING) {
L
Linus Torvalds 已提交
874
				/*
R
Robert Moore 已提交
875 876
				 * This is a deref_of (String). The string is a reference
				 * to a named ACPI object.
L
Linus Torvalds 已提交
877 878
				 *
				 * 1) Find the owning Node
B
Bob Moore 已提交
879
				 * 2) Dereference the node to an actual object. Could be a
R
Robert Moore 已提交
880
				 *    Field, so we need to resolve the node to a value.
L
Linus Torvalds 已提交
881
				 */
L
Len Brown 已提交
882
				status =
B
Bob Moore 已提交
883 884 885 886 887 888 889 890
				    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 已提交
891
				if (ACPI_FAILURE(status)) {
L
Linus Torvalds 已提交
892 893 894
					goto cleanup;
				}

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

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

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

				/*
				 * 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 已提交
934 935
					temp_desc =
					    operand[0]->reference.object;
L
Linus Torvalds 已提交
936 937 938 939 940 941 942 943

					/*
					 * 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!
944 945 946 947
					 *
					 * 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 已提交
948
					 */
L
Len Brown 已提交
949
					return_desc =
950 951 952 953 954 955 956 957
					    acpi_ut_create_integer_object((u64)
									  temp_desc->
									  buffer.
									  pointer
									  [operand
									   [0]->
									   reference.
									   value]);
L
Linus Torvalds 已提交
958 959 960 961 962 963 964 965 966
					if (!return_desc) {
						status = AE_NO_MEMORY;
						goto cleanup;
					}
					break;

				case ACPI_TYPE_PACKAGE:

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

				default:

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

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

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

L
Len Brown 已提交
993 994 995 996 997 998 999
				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 已提交
1000 1001 1002 1003
				}

				/* Add another reference to the object! */

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

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

				status = AE_TYPE;
				goto cleanup;
			}
		}
		break;

	default:

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

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

	/* Delete return object on error */

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

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

	else {
		walk_state->result_obj = return_desc;
	}

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