1 /******************************************************************************
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2004, R. Byron Moore
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
45 #include <acpi/acpi.h>
46 #include <acpi/acparser.h>
47 #include <acpi/acinterp.h>
48 #include <acpi/acevents.h>
49 #include <acpi/amlcode.h>
52 #define _COMPONENT ACPI_EXECUTER
53 ACPI_MODULE_NAME ("exoparg2")
57 * Naming convention for AML interpreter execution routines.
59 * The routines that begin execution of AML opcodes are named with a common
60 * convention based upon the number of arguments, the number of target operands,
61 * and whether or not a value is returned:
63 * AcpiExOpcode_xA_yT_zR
67 * xA - ARGUMENTS: The number of arguments (input operands) that are
68 * required for this opcode type (1 through 6 args).
69 * yT - TARGETS: The number of targets (output operands) that are required
70 * for this opcode type (0, 1, or 2 targets).
71 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
72 * as the function return (0 or 1).
74 * The AcpiExOpcode* functions are called via the Dispatcher component with
75 * fully resolved operands.
79 /*******************************************************************************
81 * FUNCTION: acpi_ex_opcode_2A_0T_0R
83 * PARAMETERS: walk_state - Current walk state
87 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
90 * ALLOCATION: Deletes both operands
92 ******************************************************************************/
95 acpi_ex_opcode_2A_0T_0R (
96 struct acpi_walk_state *walk_state)
98 union acpi_operand_object **operand = &walk_state->operands[0];
99 struct acpi_namespace_node *node;
100 acpi_status status = AE_OK;
103 ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_0T_0R",
104 acpi_ps_get_opcode_name (walk_state->opcode));
107 /* Examine the opcode */
109 switch (walk_state->opcode) {
110 case AML_NOTIFY_OP: /* Notify (notify_object, notify_value) */
112 /* The first operand is a namespace node */
114 node = (struct acpi_namespace_node *) operand[0];
116 /* Notifies allowed on this object? */
118 if (!acpi_ev_is_notify_object (node)) {
119 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unexpected notify object type [%s]\n",
120 acpi_ut_get_type_name (node->type)));
122 status = AE_AML_OPERAND_TYPE;
127 * Dispatch the notify to the appropriate handler
128 * NOTE: the request is queued for execution after this method
129 * completes. The notify handlers are NOT invoked synchronously
130 * from this thread -- because handlers may in turn run other
133 status = acpi_ev_queue_notify_request (node,
134 (u32) operand[1]->integer.value);
140 ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_0T_0R: Unknown opcode %X\n",
141 walk_state->opcode));
142 status = AE_AML_BAD_OPCODE;
145 return_ACPI_STATUS (status);
149 /*******************************************************************************
151 * FUNCTION: acpi_ex_opcode_2A_2T_1R
153 * PARAMETERS: walk_state - Current walk state
157 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
158 * and one implicit return value.
160 ******************************************************************************/
163 acpi_ex_opcode_2A_2T_1R (
164 struct acpi_walk_state *walk_state)
166 union acpi_operand_object **operand = &walk_state->operands[0];
167 union acpi_operand_object *return_desc1 = NULL;
168 union acpi_operand_object *return_desc2 = NULL;
172 ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_2T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
178 switch (walk_state->opcode) {
179 case AML_DIVIDE_OP: /* Divide (Dividend, Divisor, remainder_result quotient_result) */
181 return_desc1 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
183 status = AE_NO_MEMORY;
187 return_desc2 = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
189 status = AE_NO_MEMORY;
193 /* Quotient to return_desc1, remainder to return_desc2 */
195 status = acpi_ut_divide (&operand[0]->integer.value, &operand[1]->integer.value,
196 &return_desc1->integer.value, &return_desc2->integer.value);
197 if (ACPI_FAILURE (status)) {
205 ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_2T_1R: Unknown opcode %X\n",
206 walk_state->opcode));
207 status = AE_AML_BAD_OPCODE;
212 /* Store the results to the target reference operands */
214 status = acpi_ex_store (return_desc2, operand[2], walk_state);
215 if (ACPI_FAILURE (status)) {
219 status = acpi_ex_store (return_desc1, operand[3], walk_state);
220 if (ACPI_FAILURE (status)) {
224 /* Return the remainder */
226 walk_state->result_obj = return_desc1;
231 * Since the remainder is not returned indirectly, remove a reference to
232 * it. Only the quotient is returned indirectly.
234 acpi_ut_remove_reference (return_desc2);
236 if (ACPI_FAILURE (status)) {
237 /* Delete the return object */
239 acpi_ut_remove_reference (return_desc1);
242 return_ACPI_STATUS (status);
246 /*******************************************************************************
248 * FUNCTION: acpi_ex_opcode_2A_1T_1R
250 * PARAMETERS: walk_state - Current walk state
254 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
257 ******************************************************************************/
260 acpi_ex_opcode_2A_1T_1R (
261 struct acpi_walk_state *walk_state)
263 union acpi_operand_object **operand = &walk_state->operands[0];
264 union acpi_operand_object *return_desc = NULL;
265 union acpi_operand_object *temp_desc = NULL;
267 acpi_status status = AE_OK;
271 ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_1T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
277 if (walk_state->op_info->flags & AML_MATH) {
278 /* All simple math opcodes (add, etc.) */
280 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
282 status = AE_NO_MEMORY;
286 return_desc->integer.value = acpi_ex_do_math_op (walk_state->opcode,
287 operand[0]->integer.value,
288 operand[1]->integer.value);
289 goto store_result_to_target;
293 switch (walk_state->opcode) {
294 case AML_MOD_OP: /* Mod (Dividend, Divisor, remainder_result (ACPI 2.0) */
296 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
298 status = AE_NO_MEMORY;
302 /* return_desc will contain the remainder */
304 status = acpi_ut_divide (&operand[0]->integer.value, &operand[1]->integer.value,
305 NULL, &return_desc->integer.value);
309 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
312 * Convert the second operand if necessary. The first operand
313 * determines the type of the second operand, (See the Data Types
314 * section of the ACPI specification.) Both object types are
315 * guaranteed to be either Integer/String/Buffer by the operand
316 * resolution mechanism above.
318 switch (ACPI_GET_OBJECT_TYPE (operand[0])) {
319 case ACPI_TYPE_INTEGER:
320 status = acpi_ex_convert_to_integer (operand[1], &temp_desc, walk_state);
323 case ACPI_TYPE_STRING:
324 status = acpi_ex_convert_to_string (operand[1], &temp_desc, 16, ACPI_UINT32_MAX, walk_state);
327 case ACPI_TYPE_BUFFER:
328 status = acpi_ex_convert_to_buffer (operand[1], &temp_desc, walk_state);
332 ACPI_REPORT_ERROR (("Concat - invalid obj type: %X\n",
333 ACPI_GET_OBJECT_TYPE (operand[0])));
334 status = AE_AML_INTERNAL;
337 if (ACPI_FAILURE (status)) {
342 * Both operands are now known to be the same object type
343 * (Both are Integer, String, or Buffer), and we can now perform the
346 status = acpi_ex_do_concatenate (operand[0], temp_desc, &return_desc, walk_state);
347 if (temp_desc != operand[1]) {
348 acpi_ut_remove_reference (temp_desc);
353 case AML_TO_STRING_OP: /* to_string (Buffer, Length, Result) (ACPI 2.0) */
356 * Input object is guaranteed to be a buffer at this point (it may have
357 * been converted.) Copy the raw buffer data to a new object of type String.
360 /* Get the length of the new string */
363 if (operand[1]->integer.value == 0) {
364 /* Handle optional length value */
366 operand[1]->integer.value = ACPI_INTEGER_MAX;
369 while ((length < operand[0]->buffer.length) &&
370 (length < operand[1]->integer.value) &&
371 (operand[0]->buffer.pointer[length])) {
375 if (length > ACPI_MAX_STRING_CONVERSION) {
376 status = AE_AML_STRING_LIMIT;
380 /* Create the internal return object */
382 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_STRING);
384 status = AE_NO_MEMORY;
388 /* Allocate a new string buffer (Length + 1 for null terminator) */
390 return_desc->string.pointer = ACPI_MEM_CALLOCATE (length + 1);
391 if (!return_desc->string.pointer) {
392 status = AE_NO_MEMORY;
396 /* Copy the raw buffer data with no transform */
398 ACPI_MEMCPY (return_desc->string.pointer, operand[0]->buffer.pointer, length);
400 /* Set the string length */
402 return_desc->string.length = (u32) length;
406 case AML_CONCAT_RES_OP: /* concatenate_res_template (Buffer, Buffer, Result) (ACPI 2.0) */
408 status = acpi_ex_concat_template (operand[0], operand[1], &return_desc, walk_state);
412 case AML_INDEX_OP: /* Index (Source Index Result) */
414 /* Create the internal return object */
416 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_LOCAL_REFERENCE);
418 status = AE_NO_MEMORY;
422 index = (u32) operand[1]->integer.value;
425 * At this point, the Source operand is either a Package or a Buffer
427 if (ACPI_GET_OBJECT_TYPE (operand[0]) == ACPI_TYPE_PACKAGE) {
428 /* Object to be indexed is a Package */
430 if (index >= operand[0]->package.count) {
431 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index value (%X) beyond package end (%X)\n",
432 index, operand[0]->package.count));
433 status = AE_AML_PACKAGE_LIMIT;
437 return_desc->reference.target_type = ACPI_TYPE_PACKAGE;
438 return_desc->reference.object = operand[0];
439 return_desc->reference.where = &operand[0]->package.elements [index];
442 /* Object to be indexed is a Buffer */
444 if (index >= operand[0]->buffer.length) {
445 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Index value (%X) beyond end of buffer (%X)\n",
446 index, operand[0]->buffer.length));
447 status = AE_AML_BUFFER_LIMIT;
451 return_desc->reference.target_type = ACPI_TYPE_BUFFER_FIELD;
452 return_desc->reference.object = operand[0];
455 /* Complete the Index reference object */
457 return_desc->reference.opcode = AML_INDEX_OP;
458 return_desc->reference.offset = index;
460 /* Store the reference to the Target */
462 status = acpi_ex_store (return_desc, operand[2], walk_state);
464 /* Return the reference */
466 walk_state->result_obj = return_desc;
472 ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_1T_1R: Unknown opcode %X\n",
473 walk_state->opcode));
474 status = AE_AML_BAD_OPCODE;
479 store_result_to_target:
481 if (ACPI_SUCCESS (status)) {
483 * Store the result of the operation (which is now in return_desc) into
484 * the Target descriptor.
486 status = acpi_ex_store (return_desc, operand[2], walk_state);
487 if (ACPI_FAILURE (status)) {
491 if (!walk_state->result_obj) {
492 walk_state->result_obj = return_desc;
499 /* Delete return object on error */
501 if (ACPI_FAILURE (status)) {
502 acpi_ut_remove_reference (return_desc);
505 return_ACPI_STATUS (status);
509 /*******************************************************************************
511 * FUNCTION: acpi_ex_opcode_2A_0T_1R
513 * PARAMETERS: walk_state - Current walk state
517 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
519 ******************************************************************************/
522 acpi_ex_opcode_2A_0T_1R (
523 struct acpi_walk_state *walk_state)
525 union acpi_operand_object **operand = &walk_state->operands[0];
526 union acpi_operand_object *return_desc = NULL;
527 acpi_status status = AE_OK;
528 u8 logical_result = FALSE;
531 ACPI_FUNCTION_TRACE_STR ("ex_opcode_2A_0T_1R", acpi_ps_get_opcode_name (walk_state->opcode));
534 /* Create the internal return object */
536 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
538 status = AE_NO_MEMORY;
545 if (walk_state->op_info->flags & AML_LOGICAL) /* logical_op (Operand0, Operand1) */ {
546 logical_result = acpi_ex_do_logical_op (walk_state->opcode,
547 operand[0]->integer.value,
548 operand[1]->integer.value);
549 goto store_logical_result;
553 switch (walk_state->opcode) {
554 case AML_ACQUIRE_OP: /* Acquire (mutex_object, Timeout) */
556 status = acpi_ex_acquire_mutex (operand[1], operand[0], walk_state);
557 if (status == AE_TIME) {
558 logical_result = TRUE; /* TRUE = Acquire timed out */
564 case AML_WAIT_OP: /* Wait (event_object, Timeout) */
566 status = acpi_ex_system_wait_event (operand[1], operand[0]);
567 if (status == AE_TIME) {
568 logical_result = TRUE; /* TRUE, Wait timed out */
576 ACPI_REPORT_ERROR (("acpi_ex_opcode_2A_0T_1R: Unknown opcode %X\n",
577 walk_state->opcode));
578 status = AE_AML_BAD_OPCODE;
583 store_logical_result:
585 * Set return value to according to logical_result. logical TRUE (all ones)
586 * Default is FALSE (zero)
588 if (logical_result) {
589 return_desc->integer.value = ACPI_INTEGER_MAX;
592 walk_state->result_obj = return_desc;
597 /* Delete return object on error */
599 if (ACPI_FAILURE (status)) {
600 acpi_ut_remove_reference (return_desc);
603 return_ACPI_STATUS (status);