csu: restore crt1.o symlink
[minix.git] / drivers / acpi / executer / exoparg2.c
blob6df45ea8abac7663e2b22f53f236a5c1c8d99fff
1 /******************************************************************************
3 * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
5 *****************************************************************************/
7 /******************************************************************************
9 * 1. Copyright Notice
11 * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
12 * All rights reserved.
14 * 2. License
16 * 2.1. This is your license from Intel Corp. under its intellectual property
17 * rights. You may have additional license terms from the party that provided
18 * you this software, covering your right to use that party's intellectual
19 * property rights.
21 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22 * copy of the source code appearing in this file ("Covered Code") an
23 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24 * base code distributed originally by Intel ("Original Intel Code") to copy,
25 * make derivatives, distribute, use and display any portion of the Covered
26 * Code in any form, with the right to sublicense such rights; and
28 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29 * license (with the right to sublicense), under only those claims of Intel
30 * patents that are infringed by the Original Intel Code, to make, use, sell,
31 * offer to sell, and import the Covered Code and derivative works thereof
32 * solely to the minimum extent necessary to exercise the above copyright
33 * license, and in no event shall the patent license extend to any additions
34 * to or modifications of the Original Intel Code. No other license or right
35 * is granted directly or by implication, estoppel or otherwise;
37 * The above copyright and patent license is granted only if the following
38 * conditions are met:
40 * 3. Conditions
42 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43 * Redistribution of source code of any substantial portion of the Covered
44 * Code or modification with rights to further distribute source must include
45 * the above Copyright Notice, the above License, this list of Conditions,
46 * and the following Disclaimer and Export Compliance provision. In addition,
47 * Licensee must cause all Covered Code to which Licensee contributes to
48 * contain a file documenting the changes Licensee made to create that Covered
49 * Code and the date of any change. Licensee must include in that file the
50 * documentation of any changes made by any predecessor Licensee. Licensee
51 * must include a prominent statement that the modification is derived,
52 * directly or indirectly, from Original Intel Code.
54 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55 * Redistribution of source code of any substantial portion of the Covered
56 * Code or modification without rights to further distribute source must
57 * include the following Disclaimer and Export Compliance provision in the
58 * documentation and/or other materials provided with distribution. In
59 * addition, Licensee may not authorize further sublicense of source of any
60 * portion of the Covered Code, and must include terms to the effect that the
61 * license from Licensee to its licensee is limited to the intellectual
62 * property embodied in the software Licensee provides to its licensee, and
63 * not to intellectual property embodied in modifications its licensee may
64 * make.
66 * 3.3. Redistribution of Executable. Redistribution in executable form of any
67 * substantial portion of the Covered Code or modification must reproduce the
68 * above Copyright Notice, and the following Disclaimer and Export Compliance
69 * provision in the documentation and/or other materials provided with the
70 * distribution.
72 * 3.4. Intel retains all right, title, and interest in and to the Original
73 * Intel Code.
75 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76 * Intel shall be used in advertising or otherwise to promote the sale, use or
77 * other dealings in products derived from or relating to the Covered Code
78 * without prior written authorization from Intel.
80 * 4. Disclaimer and Export Compliance
82 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88 * PARTICULAR PURPOSE.
90 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97 * LIMITED REMEDY.
99 * 4.3. Licensee shall not export, either directly or indirectly, any of this
100 * software or system incorporating such software without first obtaining any
101 * required license or other approval from the U. S. Department of Commerce or
102 * any other agency or department of the United States Government. In the
103 * event Licensee exports any such software from the United States or
104 * re-exports any such software from a foreign destination, Licensee shall
105 * ensure that the distribution and export/re-export of the software is in
106 * compliance with all laws, regulations, orders, or other restrictions of the
107 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108 * any of its subsidiaries will export/re-export any technical data, process,
109 * software, or service, directly or indirectly, to any country for which the
110 * United States government or any agency thereof requires an export license,
111 * other governmental approval, or letter of assurance, without first obtaining
112 * such license, approval or letter.
114 *****************************************************************************/
117 #define __EXOPARG2_C__
119 #include "acpi.h"
120 #include "accommon.h"
121 #include "acparser.h"
122 #include "acinterp.h"
123 #include "acevents.h"
124 #include "amlcode.h"
127 #define _COMPONENT ACPI_EXECUTER
128 ACPI_MODULE_NAME ("exoparg2")
132 * Naming convention for AML interpreter execution routines.
134 * The routines that begin execution of AML opcodes are named with a common
135 * convention based upon the number of arguments, the number of target operands,
136 * and whether or not a value is returned:
138 * AcpiExOpcode_xA_yT_zR
140 * Where:
142 * xA - ARGUMENTS: The number of arguments (input operands) that are
143 * required for this opcode type (1 through 6 args).
144 * yT - TARGETS: The number of targets (output operands) that are required
145 * for this opcode type (0, 1, or 2 targets).
146 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
147 * as the function return (0 or 1).
149 * The AcpiExOpcode* functions are called via the Dispatcher component with
150 * fully resolved operands.
154 /*******************************************************************************
156 * FUNCTION: AcpiExOpcode_2A_0T_0R
158 * PARAMETERS: WalkState - Current walk state
160 * RETURN: Status
162 * DESCRIPTION: Execute opcode with two arguments, no target, and no return
163 * value.
165 * ALLOCATION: Deletes both operands
167 ******************************************************************************/
169 ACPI_STATUS
170 AcpiExOpcode_2A_0T_0R (
171 ACPI_WALK_STATE *WalkState)
173 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
174 ACPI_NAMESPACE_NODE *Node;
175 UINT32 Value;
176 ACPI_STATUS Status = AE_OK;
179 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
180 AcpiPsGetOpcodeName (WalkState->Opcode));
183 /* Examine the opcode */
185 switch (WalkState->Opcode)
187 case AML_NOTIFY_OP: /* Notify (NotifyObject, NotifyValue) */
189 /* The first operand is a namespace node */
191 Node = (ACPI_NAMESPACE_NODE *) Operand[0];
193 /* Second value is the notify value */
195 Value = (UINT32) Operand[1]->Integer.Value;
197 /* Are notifies allowed on this object? */
199 if (!AcpiEvIsNotifyObject (Node))
201 ACPI_ERROR ((AE_INFO,
202 "Unexpected notify object type [%s]",
203 AcpiUtGetTypeName (Node->Type)));
205 Status = AE_AML_OPERAND_TYPE;
206 break;
210 * Dispatch the notify to the appropriate handler
211 * NOTE: the request is queued for execution after this method
212 * completes. The notify handlers are NOT invoked synchronously
213 * from this thread -- because handlers may in turn run other
214 * control methods.
216 Status = AcpiEvQueueNotifyRequest (Node, Value);
217 break;
220 default:
222 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
223 WalkState->Opcode));
224 Status = AE_AML_BAD_OPCODE;
227 return_ACPI_STATUS (Status);
231 /*******************************************************************************
233 * FUNCTION: AcpiExOpcode_2A_2T_1R
235 * PARAMETERS: WalkState - Current walk state
237 * RETURN: Status
239 * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
240 * and one implicit return value.
242 ******************************************************************************/
244 ACPI_STATUS
245 AcpiExOpcode_2A_2T_1R (
246 ACPI_WALK_STATE *WalkState)
248 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
249 ACPI_OPERAND_OBJECT *ReturnDesc1 = NULL;
250 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
251 ACPI_STATUS Status;
254 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
255 AcpiPsGetOpcodeName (WalkState->Opcode));
258 /* Execute the opcode */
260 switch (WalkState->Opcode)
262 case AML_DIVIDE_OP:
264 /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
266 ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
267 if (!ReturnDesc1)
269 Status = AE_NO_MEMORY;
270 goto Cleanup;
273 ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
274 if (!ReturnDesc2)
276 Status = AE_NO_MEMORY;
277 goto Cleanup;
280 /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
282 Status = AcpiUtDivide (Operand[0]->Integer.Value,
283 Operand[1]->Integer.Value,
284 &ReturnDesc1->Integer.Value,
285 &ReturnDesc2->Integer.Value);
286 if (ACPI_FAILURE (Status))
288 goto Cleanup;
290 break;
293 default:
295 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
296 WalkState->Opcode));
297 Status = AE_AML_BAD_OPCODE;
298 goto Cleanup;
301 /* Store the results to the target reference operands */
303 Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
304 if (ACPI_FAILURE (Status))
306 goto Cleanup;
309 Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
310 if (ACPI_FAILURE (Status))
312 goto Cleanup;
315 Cleanup:
317 * Since the remainder is not returned indirectly, remove a reference to
318 * it. Only the quotient is returned indirectly.
320 AcpiUtRemoveReference (ReturnDesc2);
322 if (ACPI_FAILURE (Status))
324 /* Delete the return object */
326 AcpiUtRemoveReference (ReturnDesc1);
329 /* Save return object (the remainder) on success */
331 else
333 WalkState->ResultObj = ReturnDesc1;
336 return_ACPI_STATUS (Status);
340 /*******************************************************************************
342 * FUNCTION: AcpiExOpcode_2A_1T_1R
344 * PARAMETERS: WalkState - Current walk state
346 * RETURN: Status
348 * DESCRIPTION: Execute opcode with two arguments, one target, and a return
349 * value.
351 ******************************************************************************/
353 ACPI_STATUS
354 AcpiExOpcode_2A_1T_1R (
355 ACPI_WALK_STATE *WalkState)
357 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
358 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
359 UINT64 Index;
360 ACPI_STATUS Status = AE_OK;
361 ACPI_SIZE Length;
364 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
365 AcpiPsGetOpcodeName (WalkState->Opcode));
368 /* Execute the opcode */
370 if (WalkState->OpInfo->Flags & AML_MATH)
372 /* All simple math opcodes (add, etc.) */
374 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
375 if (!ReturnDesc)
377 Status = AE_NO_MEMORY;
378 goto Cleanup;
381 ReturnDesc->Integer.Value = AcpiExDoMathOp (WalkState->Opcode,
382 Operand[0]->Integer.Value,
383 Operand[1]->Integer.Value);
384 goto StoreResultToTarget;
387 switch (WalkState->Opcode)
389 case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
391 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
392 if (!ReturnDesc)
394 Status = AE_NO_MEMORY;
395 goto Cleanup;
398 /* ReturnDesc will contain the remainder */
400 Status = AcpiUtDivide (Operand[0]->Integer.Value,
401 Operand[1]->Integer.Value,
402 NULL,
403 &ReturnDesc->Integer.Value);
404 break;
407 case AML_CONCAT_OP: /* Concatenate (Data1, Data2, Result) */
409 Status = AcpiExDoConcatenate (Operand[0], Operand[1],
410 &ReturnDesc, WalkState);
411 break;
414 case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
417 * Input object is guaranteed to be a buffer at this point (it may have
418 * been converted.) Copy the raw buffer data to a new object of
419 * type String.
423 * Get the length of the new string. It is the smallest of:
424 * 1) Length of the input buffer
425 * 2) Max length as specified in the ToString operator
426 * 3) Length of input buffer up to a zero byte (null terminator)
428 * NOTE: A length of zero is ok, and will create a zero-length, null
429 * terminated string.
431 Length = 0;
432 while ((Length < Operand[0]->Buffer.Length) &&
433 (Length < Operand[1]->Integer.Value) &&
434 (Operand[0]->Buffer.Pointer[Length]))
436 Length++;
439 /* Allocate a new string object */
441 ReturnDesc = AcpiUtCreateStringObject (Length);
442 if (!ReturnDesc)
444 Status = AE_NO_MEMORY;
445 goto Cleanup;
449 * Copy the raw buffer data with no transform.
450 * (NULL terminated already)
452 ACPI_MEMCPY (ReturnDesc->String.Pointer,
453 Operand[0]->Buffer.Pointer, Length);
454 break;
457 case AML_CONCAT_RES_OP:
459 /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
461 Status = AcpiExConcatTemplate (Operand[0], Operand[1],
462 &ReturnDesc, WalkState);
463 break;
466 case AML_INDEX_OP: /* Index (Source Index Result) */
468 /* Create the internal return object */
470 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
471 if (!ReturnDesc)
473 Status = AE_NO_MEMORY;
474 goto Cleanup;
477 /* Initialize the Index reference object */
479 Index = Operand[1]->Integer.Value;
480 ReturnDesc->Reference.Value = (UINT32) Index;
481 ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
484 * At this point, the Source operand is a String, Buffer, or Package.
485 * Verify that the index is within range.
487 switch ((Operand[0])->Common.Type)
489 case ACPI_TYPE_STRING:
491 if (Index >= Operand[0]->String.Length)
493 Status = AE_AML_STRING_LIMIT;
496 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
497 break;
499 case ACPI_TYPE_BUFFER:
501 if (Index >= Operand[0]->Buffer.Length)
503 Status = AE_AML_BUFFER_LIMIT;
506 ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
507 break;
509 case ACPI_TYPE_PACKAGE:
511 if (Index >= Operand[0]->Package.Count)
513 Status = AE_AML_PACKAGE_LIMIT;
516 ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
517 ReturnDesc->Reference.Where = &Operand[0]->Package.Elements [Index];
518 break;
520 default:
522 Status = AE_AML_INTERNAL;
523 goto Cleanup;
526 /* Failure means that the Index was beyond the end of the object */
528 if (ACPI_FAILURE (Status))
530 ACPI_EXCEPTION ((AE_INFO, Status,
531 "Index (0x%8.8X%8.8X) is beyond end of object",
532 ACPI_FORMAT_UINT64 (Index)));
533 goto Cleanup;
537 * Save the target object and add a reference to it for the life
538 * of the index
540 ReturnDesc->Reference.Object = Operand[0];
541 AcpiUtAddReference (Operand[0]);
543 /* Store the reference to the Target */
545 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
547 /* Return the reference */
549 WalkState->ResultObj = ReturnDesc;
550 goto Cleanup;
553 default:
555 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
556 WalkState->Opcode));
557 Status = AE_AML_BAD_OPCODE;
558 break;
562 StoreResultToTarget:
564 if (ACPI_SUCCESS (Status))
567 * Store the result of the operation (which is now in ReturnDesc) into
568 * the Target descriptor.
570 Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
571 if (ACPI_FAILURE (Status))
573 goto Cleanup;
576 if (!WalkState->ResultObj)
578 WalkState->ResultObj = ReturnDesc;
583 Cleanup:
585 /* Delete return object on error */
587 if (ACPI_FAILURE (Status))
589 AcpiUtRemoveReference (ReturnDesc);
590 WalkState->ResultObj = NULL;
593 return_ACPI_STATUS (Status);
597 /*******************************************************************************
599 * FUNCTION: AcpiExOpcode_2A_0T_1R
601 * PARAMETERS: WalkState - Current walk state
603 * RETURN: Status
605 * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
607 ******************************************************************************/
609 ACPI_STATUS
610 AcpiExOpcode_2A_0T_1R (
611 ACPI_WALK_STATE *WalkState)
613 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
614 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
615 ACPI_STATUS Status = AE_OK;
616 BOOLEAN LogicalResult = FALSE;
619 ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
620 AcpiPsGetOpcodeName (WalkState->Opcode));
623 /* Create the internal return object */
625 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
626 if (!ReturnDesc)
628 Status = AE_NO_MEMORY;
629 goto Cleanup;
632 /* Execute the Opcode */
634 if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
636 /* LogicalOp (Operand0, Operand1) */
638 Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
639 Operand[0]->Integer.Value, Operand[1]->Integer.Value,
640 &LogicalResult);
641 goto StoreLogicalResult;
643 else if (WalkState->OpInfo->Flags & AML_LOGICAL)
645 /* LogicalOp (Operand0, Operand1) */
647 Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
648 Operand[1], &LogicalResult);
649 goto StoreLogicalResult;
652 switch (WalkState->Opcode)
654 case AML_ACQUIRE_OP: /* Acquire (MutexObject, Timeout) */
656 Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
657 if (Status == AE_TIME)
659 LogicalResult = TRUE; /* TRUE = Acquire timed out */
660 Status = AE_OK;
662 break;
665 case AML_WAIT_OP: /* Wait (EventObject, Timeout) */
667 Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
668 if (Status == AE_TIME)
670 LogicalResult = TRUE; /* TRUE, Wait timed out */
671 Status = AE_OK;
673 break;
676 default:
678 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
679 WalkState->Opcode));
680 Status = AE_AML_BAD_OPCODE;
681 goto Cleanup;
685 StoreLogicalResult:
687 * Set return value to according to LogicalResult. logical TRUE (all ones)
688 * Default is FALSE (zero)
690 if (LogicalResult)
692 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
695 Cleanup:
697 /* Delete return object on error */
699 if (ACPI_FAILURE (Status))
701 AcpiUtRemoveReference (ReturnDesc);
704 /* Save return object on success */
706 else
708 WalkState->ResultObj = ReturnDesc;
711 return_ACPI_STATUS (Status);