1 /******************************************************************************
3 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5 *****************************************************************************/
7 /******************************************************************************
11 * Some or all of this work - Copyright (c) 1999 - 2020, Intel Corp.
12 * All rights reserved.
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
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
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
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
72 * 3.4. Intel retains all right, title, and interest in and to the Original
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
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
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 *****************************************************************************
116 * Alternatively, you may choose to be licensed under the terms of the
119 * Redistribution and use in source and binary forms, with or without
120 * modification, are permitted provided that the following conditions
122 * 1. Redistributions of source code must retain the above copyright
123 * notice, this list of conditions, and the following disclaimer,
124 * without modification.
125 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126 * substantially similar to the "NO WARRANTY" disclaimer below
127 * ("Disclaimer") and any redistribution must be conditioned upon
128 * including a substantially similar Disclaimer requirement for further
129 * binary redistribution.
130 * 3. Neither the names of the above-listed copyright holders nor the names
131 * of any contributors may be used to endorse or promote products derived
132 * from this software without specific prior written permission.
134 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
146 * Alternatively, you may choose to be licensed under the terms of the
147 * GNU General Public License ("GPL") version 2 as published by the Free
148 * Software Foundation.
150 *****************************************************************************/
152 #include <contrib/dev/acpica/include/acpi.h>
153 #include <contrib/dev/acpica/include/accommon.h>
154 #include <contrib/dev/acpica/include/acparser.h>
155 #include <contrib/dev/acpica/include/acdispat.h>
156 #include <contrib/dev/acpica/include/acinterp.h>
157 #include <contrib/dev/acpica/include/amlcode.h>
158 #include <contrib/dev/acpica/include/acnamesp.h>
161 #define _COMPONENT ACPI_EXECUTER
162 ACPI_MODULE_NAME ("exoparg1")
166 * Naming convention for AML interpreter execution routines.
168 * The routines that begin execution of AML opcodes are named with a common
169 * convention based upon the number of arguments, the number of target operands,
170 * and whether or not a value is returned:
172 * AcpiExOpcode_xA_yT_zR
176 * xA - ARGUMENTS: The number of arguments (input operands) that are
177 * required for this opcode type (0 through 6 args).
178 * yT - TARGETS: The number of targets (output operands) that are required
179 * for this opcode type (0, 1, or 2 targets).
180 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
181 * as the function return (0 or 1).
183 * The AcpiExOpcode* functions are called via the Dispatcher component with
184 * fully resolved operands.
187 /*******************************************************************************
189 * FUNCTION: AcpiExOpcode_0A_0T_1R
191 * PARAMETERS: WalkState - Current state (contains AML opcode)
195 * DESCRIPTION: Execute operator with no operands, one return value
197 ******************************************************************************/
200 AcpiExOpcode_0A_0T_1R (
201 ACPI_WALK_STATE *WalkState)
203 ACPI_STATUS Status = AE_OK;
204 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
207 ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
208 AcpiPsGetOpcodeName (WalkState->Opcode));
211 /* Examine the AML opcode */
213 switch (WalkState->Opcode)
215 case AML_TIMER_OP: /* Timer () */
217 /* Create a return object of type Integer */
219 ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
222 Status = AE_NO_MEMORY;
227 default: /* Unknown opcode */
229 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
231 Status = AE_AML_BAD_OPCODE;
237 /* Delete return object on error */
239 if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
241 AcpiUtRemoveReference (ReturnDesc);
242 WalkState->ResultObj = NULL;
246 /* Save the return value */
248 WalkState->ResultObj = ReturnDesc;
251 return_ACPI_STATUS (Status);
255 /*******************************************************************************
257 * FUNCTION: AcpiExOpcode_1A_0T_0R
259 * PARAMETERS: WalkState - Current state (contains AML opcode)
263 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
266 ******************************************************************************/
269 AcpiExOpcode_1A_0T_0R (
270 ACPI_WALK_STATE *WalkState)
272 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
273 ACPI_STATUS Status = AE_OK;
276 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
277 AcpiPsGetOpcodeName (WalkState->Opcode));
280 /* Examine the AML opcode */
282 switch (WalkState->Opcode)
284 case AML_RELEASE_OP: /* Release (MutexObject) */
286 Status = AcpiExReleaseMutex (Operand[0], WalkState);
289 case AML_RESET_OP: /* Reset (EventObject) */
291 Status = AcpiExSystemResetEvent (Operand[0]);
294 case AML_SIGNAL_OP: /* Signal (EventObject) */
296 Status = AcpiExSystemSignalEvent (Operand[0]);
299 case AML_SLEEP_OP: /* Sleep (MsecTime) */
301 Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
304 case AML_STALL_OP: /* Stall (UsecTime) */
306 Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
309 case AML_UNLOAD_OP: /* Unload (Handle) */
311 Status = AcpiExUnloadTable (Operand[0]);
314 default: /* Unknown opcode */
316 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
318 Status = AE_AML_BAD_OPCODE;
322 return_ACPI_STATUS (Status);
326 /*******************************************************************************
328 * FUNCTION: AcpiExOpcode_1A_1T_0R
330 * PARAMETERS: WalkState - Current state (contains AML opcode)
334 * DESCRIPTION: Execute opcode with one argument, one target, and no
337 ******************************************************************************/
340 AcpiExOpcode_1A_1T_0R (
341 ACPI_WALK_STATE *WalkState)
343 ACPI_STATUS Status = AE_OK;
344 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
347 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
348 AcpiPsGetOpcodeName (WalkState->Opcode));
351 /* Examine the AML opcode */
353 switch (WalkState->Opcode)
357 Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
360 default: /* Unknown opcode */
362 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
364 Status = AE_AML_BAD_OPCODE;
371 return_ACPI_STATUS (Status);
375 /*******************************************************************************
377 * FUNCTION: AcpiExOpcode_1A_1T_1R
379 * PARAMETERS: WalkState - Current state (contains AML opcode)
383 * DESCRIPTION: Execute opcode with one argument, one target, and a
386 ******************************************************************************/
389 AcpiExOpcode_1A_1T_1R (
390 ACPI_WALK_STATE *WalkState)
392 ACPI_STATUS Status = AE_OK;
393 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
394 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
395 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
402 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
403 AcpiPsGetOpcodeName (WalkState->Opcode));
406 /* Examine the AML opcode */
408 switch (WalkState->Opcode)
411 case AML_FIND_SET_LEFT_BIT_OP:
412 case AML_FIND_SET_RIGHT_BIT_OP:
413 case AML_FROM_BCD_OP:
415 case AML_CONDITIONAL_REF_OF_OP:
417 /* Create a return object of type Integer for these opcodes */
419 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
422 Status = AE_NO_MEMORY;
426 switch (WalkState->Opcode)
428 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
430 ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
433 case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
435 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
438 * Acpi specification describes Integer type as a little
439 * endian unsigned value, so this boundary condition is valid.
441 for (Temp32 = 0; ReturnDesc->Integer.Value &&
442 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
444 ReturnDesc->Integer.Value >>= 1;
447 ReturnDesc->Integer.Value = Temp32;
450 case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
452 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
455 * The Acpi specification describes Integer type as a little
456 * endian unsigned value, so this boundary condition is valid.
458 for (Temp32 = 0; ReturnDesc->Integer.Value &&
459 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
461 ReturnDesc->Integer.Value <<= 1;
464 /* Since the bit position is one-based, subtract from 33 (65) */
466 ReturnDesc->Integer.Value =
467 Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
470 case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
472 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
473 * (if table is 32-bit, integer can hold 8 BCD characters)
474 * Convert each 4-bit BCD value
477 ReturnDesc->Integer.Value = 0;
478 Digit = Operand[0]->Integer.Value;
480 /* Convert each BCD digit (each is one nybble wide) */
482 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
484 /* Get the least significant 4-bit BCD digit */
486 Temp32 = ((UINT32) Digit) & 0xF;
488 /* Check the range of the digit */
492 ACPI_ERROR ((AE_INFO,
493 "BCD digit too large (not decimal): 0x%X",
496 Status = AE_AML_NUMERIC_OVERFLOW;
500 /* Sum the digit into the result with the current power of 10 */
502 ReturnDesc->Integer.Value +=
503 (((UINT64) Temp32) * PowerOfTen);
505 /* Shift to next BCD digit */
509 /* Next power of 10 */
515 case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
517 ReturnDesc->Integer.Value = 0;
518 Digit = Operand[0]->Integer.Value;
520 /* Each BCD digit is one nybble wide */
522 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
524 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
527 * Insert the BCD digit that resides in the
528 * remainder from above
530 ReturnDesc->Integer.Value |=
531 (((UINT64) Temp32) << ACPI_MUL_4 (i));
534 /* Overflow if there is any data left in Digit */
538 ACPI_ERROR ((AE_INFO,
539 "Integer too large to convert to BCD: 0x%8.8X%8.8X",
540 ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
541 Status = AE_AML_NUMERIC_OVERFLOW;
546 case AML_CONDITIONAL_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
548 * This op is a little strange because the internal return value is
549 * different than the return value stored in the result descriptor
550 * (There are really two return values)
552 if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
555 * This means that the object does not exist in the namespace,
558 ReturnDesc->Integer.Value = 0;
562 /* Get the object reference, store it, and remove our reference */
564 Status = AcpiExGetObjectReference (Operand[0],
565 &ReturnDesc2, WalkState);
566 if (ACPI_FAILURE (Status))
571 Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
572 AcpiUtRemoveReference (ReturnDesc2);
574 /* The object exists in the namespace, return TRUE */
576 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
582 /* No other opcodes get here */
588 case AML_STORE_OP: /* Store (Source, Target) */
590 * A store operand is typically a number, string, buffer or lvalue
591 * Be careful about deleting the source object,
592 * since the object itself may have been stored.
594 Status = AcpiExStore (Operand[0], Operand[1], WalkState);
595 if (ACPI_FAILURE (Status))
597 return_ACPI_STATUS (Status);
600 /* It is possible that the Store already produced a return object */
602 if (!WalkState->ResultObj)
605 * Normally, we would remove a reference on the Operand[0]
606 * parameter; But since it is being used as the internal return
607 * object (meaning we would normally increment it), the two
608 * cancel out, and we simply don't do anything.
610 WalkState->ResultObj = Operand[0];
611 WalkState->Operands[0] = NULL; /* Prevent deletion */
613 return_ACPI_STATUS (Status);
618 case AML_COPY_OBJECT_OP: /* CopyObject (Source, Target) */
620 Status = AcpiUtCopyIobjectToIobject (
621 Operand[0], &ReturnDesc, WalkState);
624 case AML_TO_DECIMAL_STRING_OP: /* ToDecimalString (Data, Result) */
626 Status = AcpiExConvertToString (
627 Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
628 if (ReturnDesc == Operand[0])
630 /* No conversion performed, add ref to handle return value */
632 AcpiUtAddReference (ReturnDesc);
636 case AML_TO_HEX_STRING_OP: /* ToHexString (Data, Result) */
638 Status = AcpiExConvertToString (
639 Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
640 if (ReturnDesc == Operand[0])
642 /* No conversion performed, add ref to handle return value */
644 AcpiUtAddReference (ReturnDesc);
648 case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
650 Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
651 if (ReturnDesc == Operand[0])
653 /* No conversion performed, add ref to handle return value */
655 AcpiUtAddReference (ReturnDesc);
659 case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
661 /* Perform "explicit" conversion */
663 Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc, 0);
664 if (ReturnDesc == Operand[0])
666 /* No conversion performed, add ref to handle return value */
668 AcpiUtAddReference (ReturnDesc);
672 case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
673 case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
675 /* These are two obsolete opcodes */
677 ACPI_ERROR ((AE_INFO,
678 "%s is obsolete and not implemented",
679 AcpiPsGetOpcodeName (WalkState->Opcode)));
683 default: /* Unknown opcode */
685 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
687 Status = AE_AML_BAD_OPCODE;
691 if (ACPI_SUCCESS (Status))
693 /* Store the return value computed above into the target object */
695 Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
701 /* Delete return object on error */
703 if (ACPI_FAILURE (Status))
705 AcpiUtRemoveReference (ReturnDesc);
708 /* Save return object on success */
710 else if (!WalkState->ResultObj)
712 WalkState->ResultObj = ReturnDesc;
715 return_ACPI_STATUS (Status);
719 /*******************************************************************************
721 * FUNCTION: AcpiExOpcode_1A_0T_1R
723 * PARAMETERS: WalkState - Current state (contains AML opcode)
727 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
729 ******************************************************************************/
732 AcpiExOpcode_1A_0T_1R (
733 ACPI_WALK_STATE *WalkState)
735 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
736 ACPI_OPERAND_OBJECT *TempDesc;
737 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
738 ACPI_STATUS Status = AE_OK;
743 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
744 AcpiPsGetOpcodeName (WalkState->Opcode));
747 /* Examine the AML opcode */
749 switch (WalkState->Opcode)
751 case AML_LOGICAL_NOT_OP: /* LNot (Operand) */
753 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
756 Status = AE_NO_MEMORY;
761 * Set result to ONES (TRUE) if Value == 0. Note:
762 * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
764 if (!Operand[0]->Integer.Value)
766 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
770 case AML_DECREMENT_OP: /* Decrement (Operand) */
771 case AML_INCREMENT_OP: /* Increment (Operand) */
773 * Create a new integer. Can't just get the base integer and
774 * increment it because it may be an Arg or Field.
776 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
779 Status = AE_NO_MEMORY;
784 * Since we are expecting a Reference operand, it can be either a
785 * NS Node or an internal object.
787 TempDesc = Operand[0];
788 if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
790 /* Internal reference object - prevent deletion */
792 AcpiUtAddReference (TempDesc);
796 * Convert the Reference operand to an Integer (This removes a
797 * reference on the Operand[0] object)
799 * NOTE: We use LNOT_OP here in order to force resolution of the
800 * reference operand to an actual integer.
802 Status = AcpiExResolveOperands (AML_LOGICAL_NOT_OP,
803 &TempDesc, WalkState);
804 if (ACPI_FAILURE (Status))
806 ACPI_EXCEPTION ((AE_INFO, Status,
807 "While resolving operands for [%s]",
808 AcpiPsGetOpcodeName (WalkState->Opcode)));
814 * TempDesc is now guaranteed to be an Integer object --
815 * Perform the actual increment or decrement
817 if (WalkState->Opcode == AML_INCREMENT_OP)
819 ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
823 ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
826 /* Finished with this Integer object */
828 AcpiUtRemoveReference (TempDesc);
831 * Store the result back (indirectly) through the original
834 Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
837 case AML_OBJECT_TYPE_OP: /* ObjectType (SourceObject) */
839 * Note: The operand is not resolved at this point because we want to
840 * get the associated object, not its value. For example, we don't
841 * want to resolve a FieldUnit to its value, we want the actual
845 /* Get the type of the base object */
847 Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
848 if (ACPI_FAILURE (Status))
853 /* Allocate a descriptor to hold the type. */
855 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
858 Status = AE_NO_MEMORY;
863 case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
865 * Note: The operand is not resolved at this point because we want to
866 * get the associated object, not its value.
869 /* Get the base object */
871 Status = AcpiExResolveMultiple (
872 WalkState, Operand[0], &Type, &TempDesc);
873 if (ACPI_FAILURE (Status))
879 * The type of the base object must be integer, buffer, string, or
880 * package. All others are not supported.
882 * NOTE: Integer is not specifically supported by the ACPI spec,
883 * but is supported implicitly via implicit operand conversion.
884 * rather than bother with conversion, we just use the byte width
885 * global (4 or 8 bytes).
889 case ACPI_TYPE_INTEGER:
891 Value = AcpiGbl_IntegerByteWidth;
894 case ACPI_TYPE_STRING:
896 Value = TempDesc->String.Length;
899 case ACPI_TYPE_BUFFER:
901 /* Buffer arguments may not be evaluated at this point */
903 Status = AcpiDsGetBufferArguments (TempDesc);
904 Value = TempDesc->Buffer.Length;
907 case ACPI_TYPE_PACKAGE:
909 /* Package arguments may not be evaluated at this point */
911 Status = AcpiDsGetPackageArguments (TempDesc);
912 Value = TempDesc->Package.Count;
917 ACPI_ERROR ((AE_INFO,
918 "Operand must be Buffer/Integer/String/Package"
920 AcpiUtGetTypeName (Type)));
922 Status = AE_AML_OPERAND_TYPE;
926 if (ACPI_FAILURE (Status))
932 * Now that we have the size of the object, create a result
933 * object to hold the value
935 ReturnDesc = AcpiUtCreateIntegerObject (Value);
938 Status = AE_NO_MEMORY;
944 case AML_REF_OF_OP: /* RefOf (SourceObject) */
946 Status = AcpiExGetObjectReference (
947 Operand[0], &ReturnDesc, WalkState);
948 if (ACPI_FAILURE (Status))
955 case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
957 /* Check for a method local or argument, or standalone String */
959 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
961 TempDesc = AcpiNsGetAttachedObject (
962 (ACPI_NAMESPACE_NODE *) Operand[0]);
964 ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
965 (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
967 Operand[0] = TempDesc;
968 AcpiUtAddReference (TempDesc);
972 Status = AE_AML_OPERAND_TYPE;
978 switch ((Operand[0])->Common.Type)
980 case ACPI_TYPE_LOCAL_REFERENCE:
982 * This is a DerefOf (LocalX | ArgX)
984 * Must resolve/dereference the local/arg reference first
986 switch (Operand[0]->Reference.Class)
988 case ACPI_REFCLASS_LOCAL:
989 case ACPI_REFCLASS_ARG:
991 /* Set Operand[0] to the value of the local/arg */
993 Status = AcpiDsMethodDataGetValue (
994 Operand[0]->Reference.Class,
995 Operand[0]->Reference.Value,
996 WalkState, &TempDesc);
997 if (ACPI_FAILURE (Status))
1003 * Delete our reference to the input object and
1004 * point to the object just retrieved
1006 AcpiUtRemoveReference (Operand[0]);
1007 Operand[0] = TempDesc;
1010 case ACPI_REFCLASS_REFOF:
1012 /* Get the object to which the reference refers */
1014 TempDesc = Operand[0]->Reference.Object;
1015 AcpiUtRemoveReference (Operand[0]);
1016 Operand[0] = TempDesc;
1021 /* Must be an Index op - handled below */
1026 case ACPI_TYPE_STRING:
1032 Status = AE_AML_OPERAND_TYPE;
1037 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
1039 if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
1042 * This is a DerefOf (String). The string is a reference
1043 * to a named ACPI object.
1045 * 1) Find the owning Node
1046 * 2) Dereference the node to an actual object. Could be a
1047 * Field, so we need to resolve the node to a value.
1049 Status = AcpiNsGetNodeUnlocked (WalkState->ScopeInfo->Scope.Node,
1050 Operand[0]->String.Pointer,
1051 ACPI_NS_SEARCH_PARENT,
1052 ACPI_CAST_INDIRECT_PTR (
1053 ACPI_NAMESPACE_NODE, &ReturnDesc));
1054 if (ACPI_FAILURE (Status))
1059 Status = AcpiExResolveNodeToValue (
1060 ACPI_CAST_INDIRECT_PTR (
1061 ACPI_NAMESPACE_NODE, &ReturnDesc),
1067 /* Operand[0] may have changed from the code above */
1069 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1072 * This is a DerefOf (ObjectReference)
1073 * Get the actual object from the Node (This is the dereference).
1074 * This case may only happen when a LocalX or ArgX is
1075 * dereferenced above, or for references to device and
1078 switch (((ACPI_NAMESPACE_NODE *) Operand[0])->Type)
1080 case ACPI_TYPE_DEVICE:
1081 case ACPI_TYPE_THERMAL:
1083 /* These types have no node subobject, return the NS node */
1085 ReturnDesc = Operand[0];
1089 /* For most types, get the object attached to the node */
1091 ReturnDesc = AcpiNsGetAttachedObject (
1092 (ACPI_NAMESPACE_NODE *) Operand[0]);
1093 AcpiUtAddReference (ReturnDesc);
1100 * This must be a reference object produced by either the
1101 * Index() or RefOf() operator
1103 switch (Operand[0]->Reference.Class)
1105 case ACPI_REFCLASS_INDEX:
1107 * The target type for the Index operator must be
1108 * either a Buffer or a Package
1110 switch (Operand[0]->Reference.TargetType)
1112 case ACPI_TYPE_BUFFER_FIELD:
1114 TempDesc = Operand[0]->Reference.Object;
1117 * Create a new object that contains one element of the
1118 * buffer -- the element pointed to by the index.
1120 * NOTE: index into a buffer is NOT a pointer to a
1121 * sub-buffer of the main buffer, it is only a pointer to a
1122 * single element (byte) of the buffer!
1124 * Since we are returning the value of the buffer at the
1125 * indexed location, we don't need to add an additional
1126 * reference to the buffer itself.
1128 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
1129 TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
1132 Status = AE_NO_MEMORY;
1137 case ACPI_TYPE_PACKAGE:
1139 * Return the referenced element of the package. We must
1140 * add another reference to the referenced object, however.
1142 ReturnDesc = *(Operand[0]->Reference.Where);
1146 * Element is NULL, do not allow the dereference.
1147 * This provides compatibility with other ACPI
1150 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1153 AcpiUtAddReference (ReturnDesc);
1158 ACPI_ERROR ((AE_INFO,
1159 "Unknown Index TargetType 0x%X in reference object %p",
1160 Operand[0]->Reference.TargetType, Operand[0]));
1162 Status = AE_AML_OPERAND_TYPE;
1167 case ACPI_REFCLASS_REFOF:
1169 ReturnDesc = Operand[0]->Reference.Object;
1171 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1172 ACPI_DESC_TYPE_NAMED)
1174 ReturnDesc = AcpiNsGetAttachedObject (
1175 (ACPI_NAMESPACE_NODE *) ReturnDesc);
1183 * BufferFields/FieldUnits require additional resolution
1185 switch (ReturnDesc->Common.Type)
1187 case ACPI_TYPE_BUFFER_FIELD:
1188 case ACPI_TYPE_LOCAL_REGION_FIELD:
1189 case ACPI_TYPE_LOCAL_BANK_FIELD:
1190 case ACPI_TYPE_LOCAL_INDEX_FIELD:
1192 Status = AcpiExReadDataFromField (
1193 WalkState, ReturnDesc, &TempDesc);
1194 if (ACPI_FAILURE (Status))
1199 ReturnDesc = TempDesc;
1204 /* Add another reference to the object */
1206 AcpiUtAddReference (ReturnDesc);
1214 ACPI_ERROR ((AE_INFO,
1215 "Unknown class in reference(%p) - 0x%2.2X",
1216 Operand[0], Operand[0]->Reference.Class));
1226 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1227 WalkState->Opcode));
1229 Status = AE_AML_BAD_OPCODE;
1236 /* Delete return object on error */
1238 if (ACPI_FAILURE (Status))
1240 AcpiUtRemoveReference (ReturnDesc);
1243 /* Save return object on success */
1247 WalkState->ResultObj = ReturnDesc;
1250 return_ACPI_STATUS (Status);