2 /******************************************************************************
4 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
7 *****************************************************************************/
9 /******************************************************************************
13 * Some or all of this work - Copyright (c) 1999 - 2005, Intel Corp.
14 * All rights reserved.
18 * 2.1. This is your license from Intel Corp. under its intellectual property
19 * rights. You may have additional license terms from the party that provided
20 * you this software, covering your right to use that party's intellectual
23 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
24 * copy of the source code appearing in this file ("Covered Code") an
25 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
26 * base code distributed originally by Intel ("Original Intel Code") to copy,
27 * make derivatives, distribute, use and display any portion of the Covered
28 * Code in any form, with the right to sublicense such rights; and
30 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
31 * license (with the right to sublicense), under only those claims of Intel
32 * patents that are infringed by the Original Intel Code, to make, use, sell,
33 * offer to sell, and import the Covered Code and derivative works thereof
34 * solely to the minimum extent necessary to exercise the above copyright
35 * license, and in no event shall the patent license extend to any additions
36 * to or modifications of the Original Intel Code. No other license or right
37 * is granted directly or by implication, estoppel or otherwise;
39 * The above copyright and patent license is granted only if the following
44 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
45 * Redistribution of source code of any substantial portion of the Covered
46 * Code or modification with rights to further distribute source must include
47 * the above Copyright Notice, the above License, this list of Conditions,
48 * and the following Disclaimer and Export Compliance provision. In addition,
49 * Licensee must cause all Covered Code to which Licensee contributes to
50 * contain a file documenting the changes Licensee made to create that Covered
51 * Code and the date of any change. Licensee must include in that file the
52 * documentation of any changes made by any predecessor Licensee. Licensee
53 * must include a prominent statement that the modification is derived,
54 * directly or indirectly, from Original Intel Code.
56 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
57 * Redistribution of source code of any substantial portion of the Covered
58 * Code or modification without rights to further distribute source must
59 * include the following Disclaimer and Export Compliance provision in the
60 * documentation and/or other materials provided with distribution. In
61 * addition, Licensee may not authorize further sublicense of source of any
62 * portion of the Covered Code, and must include terms to the effect that the
63 * license from Licensee to its licensee is limited to the intellectual
64 * property embodied in the software Licensee provides to its licensee, and
65 * not to intellectual property embodied in modifications its licensee may
68 * 3.3. Redistribution of Executable. Redistribution in executable form of any
69 * substantial portion of the Covered Code or modification must reproduce the
70 * above Copyright Notice, and the following Disclaimer and Export Compliance
71 * provision in the documentation and/or other materials provided with the
74 * 3.4. Intel retains all right, title, and interest in and to the Original
77 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
78 * Intel shall be used in advertising or otherwise to promote the sale, use or
79 * other dealings in products derived from or relating to the Covered Code
80 * without prior written authorization from Intel.
82 * 4. Disclaimer and Export Compliance
84 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
85 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
86 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
87 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
88 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
89 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
92 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
93 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
94 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
95 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
96 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
97 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
98 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
101 * 4.3. Licensee shall not export, either directly or indirectly, any of this
102 * software or system incorporating such software without first obtaining any
103 * required license or other approval from the U. S. Department of Commerce or
104 * any other agency or department of the United States Government. In the
105 * event Licensee exports any such software from the United States or
106 * re-exports any such software from a foreign destination, Licensee shall
107 * ensure that the distribution and export/re-export of the software is in
108 * compliance with all laws, regulations, orders, or other restrictions of the
109 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
110 * any of its subsidiaries will export/re-export any technical data, process,
111 * software, or service, directly or indirectly, to any country for which the
112 * United States government or any agency thereof requires an export license,
113 * other governmental approval, or letter of assurance, without first obtaining
114 * such license, approval or letter.
116 *****************************************************************************/
118 #define __EXOPARG1_C__
120 #include <contrib/dev/acpica/acpi.h>
121 #include <contrib/dev/acpica/acparser.h>
122 #include <contrib/dev/acpica/acdispat.h>
123 #include <contrib/dev/acpica/acinterp.h>
124 #include <contrib/dev/acpica/amlcode.h>
125 #include <contrib/dev/acpica/acnamesp.h>
128 #define _COMPONENT ACPI_EXECUTER
129 ACPI_MODULE_NAME ("exoparg1")
133 * Naming convention for AML interpreter execution routines.
135 * The routines that begin execution of AML opcodes are named with a common
136 * convention based upon the number of arguments, the number of target operands,
137 * and whether or not a value is returned:
139 * AcpiExOpcode_xA_yT_zR
143 * xA - ARGUMENTS: The number of arguments (input operands) that are
144 * required for this opcode type (0 through 6 args).
145 * yT - TARGETS: The number of targets (output operands) that are required
146 * for this opcode type (0, 1, or 2 targets).
147 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
148 * as the function return (0 or 1).
150 * The AcpiExOpcode* functions are called via the Dispatcher component with
151 * fully resolved operands.
154 /*******************************************************************************
156 * FUNCTION: AcpiExOpcode_0A_0T_1R
158 * PARAMETERS: WalkState - Current state (contains AML opcode)
162 * DESCRIPTION: Execute operator with no operands, one return value
164 ******************************************************************************/
167 AcpiExOpcode_0A_0T_1R (
168 ACPI_WALK_STATE *WalkState)
170 ACPI_STATUS Status = AE_OK;
171 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
174 ACPI_FUNCTION_TRACE_STR ("ExOpcode_0A_0T_1R",
175 AcpiPsGetOpcodeName (WalkState->Opcode));
178 /* Examine the AML opcode */
180 switch (WalkState->Opcode)
182 case AML_TIMER_OP: /* Timer () */
184 /* Create a return object of type Integer */
186 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
189 Status = AE_NO_MEMORY;
192 #if ACPI_MACHINE_WIDTH != 16
193 ReturnDesc->Integer.Value = AcpiOsGetTimer ();
197 default: /* Unknown opcode */
199 ACPI_REPORT_ERROR (("AcpiExOpcode_0A_0T_1R: Unknown opcode %X\n",
201 Status = AE_AML_BAD_OPCODE;
207 /* Delete return object on error */
209 if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
211 AcpiUtRemoveReference (ReturnDesc);
215 /* Save the return value */
217 WalkState->ResultObj = ReturnDesc;
220 return_ACPI_STATUS (Status);
224 /*******************************************************************************
226 * FUNCTION: AcpiExOpcode_1A_0T_0R
228 * PARAMETERS: WalkState - Current state (contains AML opcode)
232 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
235 ******************************************************************************/
238 AcpiExOpcode_1A_0T_0R (
239 ACPI_WALK_STATE *WalkState)
241 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
242 ACPI_STATUS Status = AE_OK;
245 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_0R",
246 AcpiPsGetOpcodeName (WalkState->Opcode));
249 /* Examine the AML opcode */
251 switch (WalkState->Opcode)
253 case AML_RELEASE_OP: /* Release (MutexObject) */
255 Status = AcpiExReleaseMutex (Operand[0], WalkState);
259 case AML_RESET_OP: /* Reset (EventObject) */
261 Status = AcpiExSystemResetEvent (Operand[0]);
265 case AML_SIGNAL_OP: /* Signal (EventObject) */
267 Status = AcpiExSystemSignalEvent (Operand[0]);
271 case AML_SLEEP_OP: /* Sleep (MsecTime) */
273 Status = AcpiExSystemDoSuspend (Operand[0]->Integer.Value);
277 case AML_STALL_OP: /* Stall (UsecTime) */
279 Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
283 case AML_UNLOAD_OP: /* Unload (Handle) */
285 Status = AcpiExUnloadTable (Operand[0]);
289 default: /* Unknown opcode */
291 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_0R: Unknown opcode %X\n",
293 Status = AE_AML_BAD_OPCODE;
297 return_ACPI_STATUS (Status);
301 /*******************************************************************************
303 * FUNCTION: AcpiExOpcode_1A_1T_0R
305 * PARAMETERS: WalkState - Current state (contains AML opcode)
309 * DESCRIPTION: Execute opcode with one argument, one target, and no
312 ******************************************************************************/
315 AcpiExOpcode_1A_1T_0R (
316 ACPI_WALK_STATE *WalkState)
318 ACPI_STATUS Status = AE_OK;
319 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
322 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_0R",
323 AcpiPsGetOpcodeName (WalkState->Opcode));
326 /* Examine the AML opcode */
328 switch (WalkState->Opcode)
332 Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
335 default: /* Unknown opcode */
337 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_0R: Unknown opcode %X\n",
339 Status = AE_AML_BAD_OPCODE;
346 return_ACPI_STATUS (Status);
350 /*******************************************************************************
352 * FUNCTION: AcpiExOpcode_1A_1T_1R
354 * PARAMETERS: WalkState - Current state (contains AML opcode)
358 * DESCRIPTION: Execute opcode with one argument, one target, and a
361 ******************************************************************************/
364 AcpiExOpcode_1A_1T_1R (
365 ACPI_WALK_STATE *WalkState)
367 ACPI_STATUS Status = AE_OK;
368 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
369 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
370 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
373 ACPI_INTEGER PowerOfTen;
377 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_1T_1R",
378 AcpiPsGetOpcodeName (WalkState->Opcode));
381 /* Examine the AML opcode */
383 switch (WalkState->Opcode)
386 case AML_FIND_SET_LEFT_BIT_OP:
387 case AML_FIND_SET_RIGHT_BIT_OP:
388 case AML_FROM_BCD_OP:
390 case AML_COND_REF_OF_OP:
392 /* Create a return object of type Integer for these opcodes */
394 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
397 Status = AE_NO_MEMORY;
401 switch (WalkState->Opcode)
403 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
405 ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
409 case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
411 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
414 * Acpi specification describes Integer type as a little
415 * endian unsigned value, so this boundary condition is valid.
417 for (Temp32 = 0; ReturnDesc->Integer.Value &&
418 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
420 ReturnDesc->Integer.Value >>= 1;
423 ReturnDesc->Integer.Value = Temp32;
427 case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
429 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
432 * The Acpi specification describes Integer type as a little
433 * endian unsigned value, so this boundary condition is valid.
435 for (Temp32 = 0; ReturnDesc->Integer.Value &&
436 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
438 ReturnDesc->Integer.Value <<= 1;
441 /* Since the bit position is one-based, subtract from 33 (65) */
443 ReturnDesc->Integer.Value = Temp32 == 0 ? 0 :
444 (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
448 case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
451 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
452 * (if table is 32-bit, integer can hold 8 BCD characters)
453 * Convert each 4-bit BCD value
456 ReturnDesc->Integer.Value = 0;
457 Digit = Operand[0]->Integer.Value;
459 /* Convert each BCD digit (each is one nybble wide) */
461 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
463 /* Get the least significant 4-bit BCD digit */
465 Temp32 = ((UINT32) Digit) & 0xF;
467 /* Check the range of the digit */
471 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
472 "BCD digit too large (not decimal): 0x%X\n",
475 Status = AE_AML_NUMERIC_OVERFLOW;
479 /* Sum the digit into the result with the current power of 10 */
481 ReturnDesc->Integer.Value += (((ACPI_INTEGER) Temp32) *
484 /* Shift to next BCD digit */
488 /* Next power of 10 */
495 case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
497 ReturnDesc->Integer.Value = 0;
498 Digit = Operand[0]->Integer.Value;
500 /* Each BCD digit is one nybble wide */
502 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
504 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
507 * Insert the BCD digit that resides in the
508 * remainder from above
510 ReturnDesc->Integer.Value |= (((ACPI_INTEGER) Temp32) <<
514 /* Overflow if there is any data left in Digit */
518 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
519 "Integer too large to convert to BCD: %8.8X%8.8X\n",
520 ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
521 Status = AE_AML_NUMERIC_OVERFLOW;
527 case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
530 * This op is a little strange because the internal return value is
531 * different than the return value stored in the result descriptor
532 * (There are really two return values)
534 if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
537 * This means that the object does not exist in the namespace,
540 ReturnDesc->Integer.Value = 0;
544 /* Get the object reference, store it, and remove our reference */
546 Status = AcpiExGetObjectReference (Operand[0],
547 &ReturnDesc2, WalkState);
548 if (ACPI_FAILURE (Status))
553 Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
554 AcpiUtRemoveReference (ReturnDesc2);
556 /* The object exists in the namespace, return TRUE */
558 ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
563 /* No other opcodes get here */
569 case AML_STORE_OP: /* Store (Source, Target) */
572 * A store operand is typically a number, string, buffer or lvalue
573 * Be careful about deleting the source object,
574 * since the object itself may have been stored.
576 Status = AcpiExStore (Operand[0], Operand[1], WalkState);
577 if (ACPI_FAILURE (Status))
579 return_ACPI_STATUS (Status);
582 /* It is possible that the Store already produced a return object */
584 if (!WalkState->ResultObj)
587 * Normally, we would remove a reference on the Operand[0]
588 * parameter; But since it is being used as the internal return
589 * object (meaning we would normally increment it), the two
590 * cancel out, and we simply don't do anything.
592 WalkState->ResultObj = Operand[0];
593 WalkState->Operands[0] = NULL; /* Prevent deletion */
595 return_ACPI_STATUS (Status);
601 case AML_COPY_OP: /* Copy (Source, Target) */
603 Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc,
608 case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
610 Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
611 ACPI_EXPLICIT_CONVERT_DECIMAL);
612 if (ReturnDesc == Operand[0])
614 /* No conversion performed, add ref to handle return value */
615 AcpiUtAddReference (ReturnDesc);
620 case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
622 Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
623 ACPI_EXPLICIT_CONVERT_HEX);
624 if (ReturnDesc == Operand[0])
626 /* No conversion performed, add ref to handle return value */
627 AcpiUtAddReference (ReturnDesc);
632 case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
634 Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
635 if (ReturnDesc == Operand[0])
637 /* No conversion performed, add ref to handle return value */
638 AcpiUtAddReference (ReturnDesc);
643 case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
645 Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc,
647 if (ReturnDesc == Operand[0])
649 /* No conversion performed, add ref to handle return value */
650 AcpiUtAddReference (ReturnDesc);
655 case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
656 case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
658 /* These are two obsolete opcodes */
660 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
661 "%s is obsolete and not implemented\n",
662 AcpiPsGetOpcodeName (WalkState->Opcode)));
667 default: /* Unknown opcode */
669 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_1T_1R: Unknown opcode %X\n",
671 Status = AE_AML_BAD_OPCODE;
675 if (ACPI_SUCCESS (Status))
677 /* Store the return value computed above into the target object */
679 Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
685 if (!WalkState->ResultObj)
687 WalkState->ResultObj = ReturnDesc;
690 /* Delete return object on error */
692 if (ACPI_FAILURE (Status))
694 AcpiUtRemoveReference (ReturnDesc);
697 return_ACPI_STATUS (Status);
701 /*******************************************************************************
703 * FUNCTION: AcpiExOpcode_1A_0T_1R
705 * PARAMETERS: WalkState - Current state (contains AML opcode)
709 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
711 ******************************************************************************/
714 AcpiExOpcode_1A_0T_1R (
715 ACPI_WALK_STATE *WalkState)
717 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
718 ACPI_OPERAND_OBJECT *TempDesc;
719 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
720 ACPI_STATUS Status = AE_OK;
725 ACPI_FUNCTION_TRACE_STR ("ExOpcode_1A_0T_1R",
726 AcpiPsGetOpcodeName (WalkState->Opcode));
729 /* Examine the AML opcode */
731 switch (WalkState->Opcode)
733 case AML_LNOT_OP: /* LNot (Operand) */
735 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
738 Status = AE_NO_MEMORY;
743 * Set result to ONES (TRUE) if Value == 0. Note:
744 * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
746 if (!Operand[0]->Integer.Value)
748 ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
753 case AML_DECREMENT_OP: /* Decrement (Operand) */
754 case AML_INCREMENT_OP: /* Increment (Operand) */
757 * Create a new integer. Can't just get the base integer and
758 * increment it because it may be an Arg or Field.
760 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
763 Status = AE_NO_MEMORY;
768 * Since we are expecting a Reference operand, it can be either a
769 * NS Node or an internal object.
771 TempDesc = Operand[0];
772 if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
774 /* Internal reference object - prevent deletion */
776 AcpiUtAddReference (TempDesc);
780 * Convert the Reference operand to an Integer (This removes a
781 * reference on the Operand[0] object)
783 * NOTE: We use LNOT_OP here in order to force resolution of the
784 * reference operand to an actual integer.
786 Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
787 if (ACPI_FAILURE (Status))
789 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s: bad operand(s) %s\n",
790 AcpiPsGetOpcodeName (WalkState->Opcode),
791 AcpiFormatException(Status)));
797 * TempDesc is now guaranteed to be an Integer object --
798 * Perform the actual increment or decrement
800 if (WalkState->Opcode == AML_INCREMENT_OP)
802 ReturnDesc->Integer.Value = TempDesc->Integer.Value +1;
806 ReturnDesc->Integer.Value = TempDesc->Integer.Value -1;
809 /* Finished with this Integer object */
811 AcpiUtRemoveReference (TempDesc);
814 * Store the result back (indirectly) through the original
817 Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
821 case AML_TYPE_OP: /* ObjectType (SourceObject) */
824 * Note: The operand is not resolved at this point because we want to
825 * get the associated object, not its value. For example, we don't
826 * want to resolve a FieldUnit to its value, we want the actual
830 /* Get the type of the base object */
832 Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
833 if (ACPI_FAILURE (Status))
837 /* Allocate a descriptor to hold the type. */
839 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
842 Status = AE_NO_MEMORY;
846 ReturnDesc->Integer.Value = Type;
850 case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
853 * Note: The operand is not resolved at this point because we want to
854 * get the associated object, not its value.
857 /* Get the base object */
859 Status = AcpiExResolveMultiple (WalkState,
860 Operand[0], &Type, &TempDesc);
861 if (ACPI_FAILURE (Status))
867 * The type of the base object must be integer, buffer, string, or
868 * package. All others are not supported.
870 * NOTE: Integer is not specifically supported by the ACPI spec,
871 * but is supported implicitly via implicit operand conversion.
872 * rather than bother with conversion, we just use the byte width
873 * global (4 or 8 bytes).
877 case ACPI_TYPE_INTEGER:
878 Value = AcpiGbl_IntegerByteWidth;
881 case ACPI_TYPE_BUFFER:
882 Value = TempDesc->Buffer.Length;
885 case ACPI_TYPE_STRING:
886 Value = TempDesc->String.Length;
889 case ACPI_TYPE_PACKAGE:
890 Value = TempDesc->Package.Count;
894 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
895 "SizeOf - Operand is not Buf/Int/Str/Pkg - found type %s\n",
896 AcpiUtGetTypeName (Type)));
897 Status = AE_AML_OPERAND_TYPE;
902 * Now that we have the size of the object, create a result
903 * object to hold the value
905 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
908 Status = AE_NO_MEMORY;
912 ReturnDesc->Integer.Value = Value;
916 case AML_REF_OF_OP: /* RefOf (SourceObject) */
918 Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
919 if (ACPI_FAILURE (Status))
926 case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
928 /* Check for a method local or argument, or standalone String */
930 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
932 switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
934 case ACPI_TYPE_LOCAL_REFERENCE:
936 * This is a DerefOf (LocalX | ArgX)
938 * Must resolve/dereference the local/arg reference first
940 switch (Operand[0]->Reference.Opcode)
945 /* Set Operand[0] to the value of the local/arg */
947 Status = AcpiDsMethodDataGetValue (
948 Operand[0]->Reference.Opcode,
949 Operand[0]->Reference.Offset,
950 WalkState, &TempDesc);
951 if (ACPI_FAILURE (Status))
957 * Delete our reference to the input object and
958 * point to the object just retrieved
960 AcpiUtRemoveReference (Operand[0]);
961 Operand[0] = TempDesc;
966 /* Get the object to which the reference refers */
968 TempDesc = Operand[0]->Reference.Object;
969 AcpiUtRemoveReference (Operand[0]);
970 Operand[0] = TempDesc;
975 /* Must be an Index op - handled below */
981 case ACPI_TYPE_STRING:
984 * This is a DerefOf (String). The string is a reference
985 * to a named ACPI object.
987 * 1) Find the owning Node
988 * 2) Dereference the node to an actual object. Could be a
989 * Field, so we need to resolve the node to a value.
991 Status = AcpiNsGetNodeByPath (Operand[0]->String.Pointer,
992 WalkState->ScopeInfo->Scope.Node,
993 ACPI_NS_SEARCH_PARENT,
994 ACPI_CAST_INDIRECT_PTR (
995 ACPI_NAMESPACE_NODE, &ReturnDesc));
996 if (ACPI_FAILURE (Status))
1001 Status = AcpiExResolveNodeToValue (
1002 ACPI_CAST_INDIRECT_PTR (
1003 ACPI_NAMESPACE_NODE, &ReturnDesc),
1010 Status = AE_AML_OPERAND_TYPE;
1015 /* Operand[0] may have changed from the code above */
1017 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1020 * This is a DerefOf (ObjectReference)
1021 * Get the actual object from the Node (This is the dereference).
1022 * This case may only happen when a LocalX or ArgX is
1023 * dereferenced above.
1025 ReturnDesc = AcpiNsGetAttachedObject (
1026 (ACPI_NAMESPACE_NODE *) Operand[0]);
1027 AcpiUtAddReference (ReturnDesc);
1032 * This must be a reference object produced by either the
1033 * Index() or RefOf() operator
1035 switch (Operand[0]->Reference.Opcode)
1040 * The target type for the Index operator must be
1041 * either a Buffer or a Package
1043 switch (Operand[0]->Reference.TargetType)
1045 case ACPI_TYPE_BUFFER_FIELD:
1047 TempDesc = Operand[0]->Reference.Object;
1050 * Create a new object that contains one element of the
1051 * buffer -- the element pointed to by the index.
1053 * NOTE: index into a buffer is NOT a pointer to a
1054 * sub-buffer of the main buffer, it is only a pointer to a
1055 * single element (byte) of the buffer!
1057 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
1060 Status = AE_NO_MEMORY;
1065 * Since we are returning the value of the buffer at the
1066 * indexed location, we don't need to add an additional
1067 * reference to the buffer itself.
1069 ReturnDesc->Integer.Value =
1070 TempDesc->Buffer.Pointer[Operand[0]->Reference.Offset];
1074 case ACPI_TYPE_PACKAGE:
1077 * Return the referenced element of the package. We must
1078 * add another reference to the referenced object, however.
1080 ReturnDesc = *(Operand[0]->Reference.Where);
1083 AcpiUtAddReference (ReturnDesc);
1091 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1092 "Unknown Index TargetType %X in obj %p\n",
1093 Operand[0]->Reference.TargetType, Operand[0]));
1094 Status = AE_AML_OPERAND_TYPE;
1102 ReturnDesc = Operand[0]->Reference.Object;
1104 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1105 ACPI_DESC_TYPE_NAMED)
1108 ReturnDesc = AcpiNsGetAttachedObject (
1109 (ACPI_NAMESPACE_NODE *) ReturnDesc);
1112 /* Add another reference to the object! */
1114 AcpiUtAddReference (ReturnDesc);
1119 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
1120 "Unknown opcode in ref(%p) - %X\n",
1121 Operand[0], Operand[0]->Reference.Opcode));
1132 ACPI_REPORT_ERROR (("AcpiExOpcode_1A_0T_1R: Unknown opcode %X\n",
1133 WalkState->Opcode));
1134 Status = AE_AML_BAD_OPCODE;
1141 /* Delete return object on error */
1143 if (ACPI_FAILURE (Status))
1145 AcpiUtRemoveReference (ReturnDesc);
1148 WalkState->ResultObj = ReturnDesc;
1149 return_ACPI_STATUS (Status);