1 /******************************************************************************
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, Intel Corp.
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 #define __EXOPARG2_C__
47 #include <contrib/dev/acpica/include/acpi.h>
48 #include <contrib/dev/acpica/include/accommon.h>
49 #include <contrib/dev/acpica/include/acparser.h>
50 #include <contrib/dev/acpica/include/acinterp.h>
51 #include <contrib/dev/acpica/include/acevents.h>
52 #include <contrib/dev/acpica/include/amlcode.h>
55 #define _COMPONENT ACPI_EXECUTER
56 ACPI_MODULE_NAME ("exoparg2")
60 * Naming convention for AML interpreter execution routines.
62 * The routines that begin execution of AML opcodes are named with a common
63 * convention based upon the number of arguments, the number of target operands,
64 * and whether or not a value is returned:
66 * AcpiExOpcode_xA_yT_zR
70 * xA - ARGUMENTS: The number of arguments (input operands) that are
71 * required for this opcode type (1 through 6 args).
72 * yT - TARGETS: The number of targets (output operands) that are required
73 * for this opcode type (0, 1, or 2 targets).
74 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
75 * as the function return (0 or 1).
77 * The AcpiExOpcode* functions are called via the Dispatcher component with
78 * fully resolved operands.
82 /*******************************************************************************
84 * FUNCTION: AcpiExOpcode_2A_0T_0R
86 * PARAMETERS: WalkState - Current walk state
90 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
93 * ALLOCATION: Deletes both operands
95 ******************************************************************************/
98 AcpiExOpcode_2A_0T_0R (
99 ACPI_WALK_STATE *WalkState)
101 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
102 ACPI_NAMESPACE_NODE *Node;
104 ACPI_STATUS Status = AE_OK;
107 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
108 AcpiPsGetOpcodeName (WalkState->Opcode));
111 /* Examine the opcode */
113 switch (WalkState->Opcode)
115 case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
117 /* The first operand is a namespace node */
119 Node = (ACPI_NAMESPACE_NODE *) Operand[0];
121 /* Second value is the notify value */
123 Value = (UINT32) Operand[1]->Integer.Value;
125 /* Are notifies allowed on this object? */
127 if (!AcpiEvIsNotifyObject (Node))
129 ACPI_ERROR ((AE_INFO,
130 "Unexpected notify object type [%s]",
131 AcpiUtGetTypeName (Node->Type)));
133 Status = AE_AML_OPERAND_TYPE;
138 * Dispatch the notify to the appropriate handler
139 * NOTE: the request is queued for execution after this method
140 * completes. The notify handlers are NOT invoked synchronously
141 * from this thread -- because handlers may in turn run other
144 Status = AcpiEvQueueNotifyRequest (Node, Value);
150 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
152 Status = AE_AML_BAD_OPCODE;
155 return_ACPI_STATUS (Status);
159 /*******************************************************************************
161 * FUNCTION: AcpiExOpcode_2A_2T_1R
163 * PARAMETERS: WalkState - Current walk state
167 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
168 * and one implicit return value.
170 ******************************************************************************/
173 AcpiExOpcode_2A_2T_1R (
174 ACPI_WALK_STATE *WalkState)
176 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
177 ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
178 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
182 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
183 AcpiPsGetOpcodeName (WalkState->Opcode));
186 /* Execute the opcode */
188 switch (WalkState->Opcode)
192 /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
194 ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
197 Status = AE_NO_MEMORY;
201 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
204 Status = AE_NO_MEMORY;
208 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
210 Status = AcpiUtDivide (Operand[0]->Integer.Value,
211 Operand[1]->Integer.Value,
212 &ReturnDesc1->Integer.Value,
213 &ReturnDesc2->Integer.Value);
214 if (ACPI_FAILURE (Status))
223 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
225 Status = AE_AML_BAD_OPCODE;
229 /* Store the results to the target reference operands */
231 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
232 if (ACPI_FAILURE (Status))
237 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
238 if (ACPI_FAILURE (Status))
245 * Since the remainder is not returned indirectly, remove a reference to
246 * it. Only the quotient is returned indirectly.
248 AcpiUtRemoveReference (ReturnDesc2);
250 if (ACPI_FAILURE (Status))
252 /* Delete the return object */
254 AcpiUtRemoveReference (ReturnDesc1);
257 /* Save return object (the remainder) on success */
261 WalkState->ResultObj = ReturnDesc1;
264 return_ACPI_STATUS (Status);
268 /*******************************************************************************
270 * FUNCTION: AcpiExOpcode_2A_1T_1R
272 * PARAMETERS: WalkState - Current walk state
276 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
279 ******************************************************************************/
282 AcpiExOpcode_2A_1T_1R (
283 ACPI_WALK_STATE *WalkState)
285 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
286 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
288 ACPI_STATUS Status = AE_OK;
292 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
293 AcpiPsGetOpcodeName (WalkState->Opcode));
296 /* Execute the opcode */
298 if (WalkState->OpInfo->Flags & AML_MATH)
300 /* All simple math opcodes (add, etc.) */
302 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
305 Status = AE_NO_MEMORY;
309 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
310 Operand[0]->Integer.Value,
311 Operand[1]->Integer.Value);
312 goto StoreResultToTarget;
315 switch (WalkState->Opcode)
317 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
319 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
322 Status = AE_NO_MEMORY;
326 /* ReturnDesc will contain the remainder */
328 Status = AcpiUtDivide (Operand[0]->Integer.Value,
329 Operand[1]->Integer.Value,
331 &ReturnDesc->Integer.Value);
335 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
337 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
338 &ReturnDesc, WalkState);
342 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
345 * Input object is guaranteed to be a buffer at this point (it may have
346 * been converted.) Copy the raw buffer data to a new object of
351 * Get the length of the new string. It is the smallest of:
352 * 1) Length of the input buffer
353 * 2) Max length as specified in the ToString operator
354 * 3) Length of input buffer up to a zero byte (null terminator)
356 * NOTE: A length of zero is ok, and will create a zero-length, null
360 while ((Length < Operand[0]->Buffer.Length) &&
361 (Length < Operand[1]->Integer.Value) &&
362 (Operand[0]->Buffer.Pointer[Length]))
367 /* Allocate a new string object */
369 ReturnDesc = AcpiUtCreateStringObject (Length);
372 Status = AE_NO_MEMORY;
377 * Copy the raw buffer data with no transform.
378 * (NULL terminated already)
380 ACPI_MEMCPY (ReturnDesc->String.Pointer,
381 Operand[0]->Buffer.Pointer, Length);
385 case AML_CONCAT_RES_OP:
387 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
389 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
390 &ReturnDesc, WalkState);
394 case AML_INDEX_OP: /* Index (Source Index Result) */
396 /* Create the internal return object */
398 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
401 Status = AE_NO_MEMORY;
405 /* Initialize the Index reference object */
407 Index = Operand[1]->Integer.Value;
408 ReturnDesc->Reference.Value = (UINT32) Index;
409 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
412 * At this point, the Source operand is a String, Buffer, or Package.
413 * Verify that the index is within range.
415 switch ((Operand[0])->Common.Type)
417 case ACPI_TYPE_STRING:
419 if (Index >= Operand[0]->String.Length)
421 Status = AE_AML_STRING_LIMIT;
424 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
427 case ACPI_TYPE_BUFFER:
429 if (Index >= Operand[0]->Buffer.Length)
431 Status = AE_AML_BUFFER_LIMIT;
434 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
437 case ACPI_TYPE_PACKAGE:
439 if (Index >= Operand[0]->Package.Count)
441 Status = AE_AML_PACKAGE_LIMIT;
444 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
445 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
450 Status = AE_AML_INTERNAL;
454 /* Failure means that the Index was beyond the end of the object */
456 if (ACPI_FAILURE (Status))
458 ACPI_EXCEPTION ((AE_INFO, Status,
459 "Index (0x%8.8X%8.8X) is beyond end of object",
460 ACPI_FORMAT_UINT64 (Index)));
465 * Save the target object and add a reference to it for the life
468 ReturnDesc->Reference.Object = Operand[0];
469 AcpiUtAddReference (Operand[0]);
471 /* Store the reference to the Target */
473 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
475 /* Return the reference */
477 WalkState->ResultObj = ReturnDesc;
483 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
485 Status = AE_AML_BAD_OPCODE;
492 if (ACPI_SUCCESS (Status))
495 * Store the result of the operation (which is now in ReturnDesc) into
496 * the Target descriptor.
498 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
499 if (ACPI_FAILURE (Status))
504 if (!WalkState->ResultObj)
506 WalkState->ResultObj = ReturnDesc;
513 /* Delete return object on error */
515 if (ACPI_FAILURE (Status))
517 AcpiUtRemoveReference (ReturnDesc);
518 WalkState->ResultObj = NULL;
521 return_ACPI_STATUS (Status);
525 /*******************************************************************************
527 * FUNCTION: AcpiExOpcode_2A_0T_1R
529 * PARAMETERS: WalkState - Current walk state
533 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
535 ******************************************************************************/
538 AcpiExOpcode_2A_0T_1R (
539 ACPI_WALK_STATE *WalkState)
541 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
542 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
543 ACPI_STATUS Status = AE_OK;
544 BOOLEAN LogicalResult = FALSE;
547 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
548 AcpiPsGetOpcodeName (WalkState->Opcode));
551 /* Create the internal return object */
553 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
556 Status = AE_NO_MEMORY;
560 /* Execute the Opcode */
562 if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
564 /* LogicalOp (Operand0, Operand1) */
566 Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
567 Operand[0]->Integer.Value, Operand[1]->Integer.Value,
569 goto StoreLogicalResult;
571 else if (WalkState->OpInfo->Flags & AML_LOGICAL)
573 /* LogicalOp (Operand0, Operand1) */
575 Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
576 Operand[1], &LogicalResult);
577 goto StoreLogicalResult;
580 switch (WalkState->Opcode)
582 case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
584 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
585 if (Status == AE_TIME)
587 LogicalResult = TRUE; /* TRUE = Acquire timed out */
593 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
595 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
596 if (Status == AE_TIME)
598 LogicalResult = TRUE; /* TRUE, Wait timed out */
606 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
608 Status = AE_AML_BAD_OPCODE;
615 * Set return value to according to LogicalResult. logical TRUE (all ones)
616 * Default is FALSE (zero)
620 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
625 /* Delete return object on error */
627 if (ACPI_FAILURE (Status))
629 AcpiUtRemoveReference (ReturnDesc);
632 /* Save return object on success */
636 WalkState->ResultObj = ReturnDesc;
639 return_ACPI_STATUS (Status);