dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / uts / intel / io / acpica / executer / exoparg1.c
blob5a45bead06f92f8de4baa074a3ddacb03f0640ae
1 /******************************************************************************
3 * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2016, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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.
44 #include "acpi.h"
45 #include "accommon.h"
46 #include "acparser.h"
47 #include "acdispat.h"
48 #include "acinterp.h"
49 #include "amlcode.h"
50 #include "acnamesp.h"
53 #define _COMPONENT ACPI_EXECUTER
54 ACPI_MODULE_NAME ("exoparg1")
57 /*!
58 * Naming convention for AML interpreter execution routines.
60 * The routines that begin execution of AML opcodes are named with a common
61 * convention based upon the number of arguments, the number of target operands,
62 * and whether or not a value is returned:
64 * AcpiExOpcode_xA_yT_zR
66 * Where:
68 * xA - ARGUMENTS: The number of arguments (input operands) that are
69 * required for this opcode type (0 through 6 args).
70 * yT - TARGETS: The number of targets (output operands) that are required
71 * for this opcode type (0, 1, or 2 targets).
72 * zR - RETURN VALUE: Indicates whether this opcode type returns a value
73 * as the function return (0 or 1).
75 * The AcpiExOpcode* functions are called via the Dispatcher component with
76 * fully resolved operands.
77 !*/
79 /*******************************************************************************
81 * FUNCTION: AcpiExOpcode_0A_0T_1R
83 * PARAMETERS: WalkState - Current state (contains AML opcode)
85 * RETURN: Status
87 * DESCRIPTION: Execute operator with no operands, one return value
89 ******************************************************************************/
91 ACPI_STATUS
92 AcpiExOpcode_0A_0T_1R (
93 ACPI_WALK_STATE *WalkState)
95 ACPI_STATUS Status = AE_OK;
96 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
99 ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
100 AcpiPsGetOpcodeName (WalkState->Opcode));
103 /* Examine the AML opcode */
105 switch (WalkState->Opcode)
107 case AML_TIMER_OP: /* Timer () */
109 /* Create a return object of type Integer */
111 ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
112 if (!ReturnDesc)
114 Status = AE_NO_MEMORY;
115 goto Cleanup;
117 break;
119 default: /* Unknown opcode */
121 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
122 WalkState->Opcode));
123 Status = AE_AML_BAD_OPCODE;
124 break;
127 Cleanup:
129 /* Delete return object on error */
131 if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
133 AcpiUtRemoveReference (ReturnDesc);
134 WalkState->ResultObj = NULL;
136 else
138 /* Save the return value */
140 WalkState->ResultObj = ReturnDesc;
143 return_ACPI_STATUS (Status);
147 /*******************************************************************************
149 * FUNCTION: AcpiExOpcode_1A_0T_0R
151 * PARAMETERS: WalkState - Current state (contains AML opcode)
153 * RETURN: Status
155 * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
156 * object stack
158 ******************************************************************************/
160 ACPI_STATUS
161 AcpiExOpcode_1A_0T_0R (
162 ACPI_WALK_STATE *WalkState)
164 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
165 ACPI_STATUS Status = AE_OK;
168 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
169 AcpiPsGetOpcodeName (WalkState->Opcode));
172 /* Examine the AML opcode */
174 switch (WalkState->Opcode)
176 case AML_RELEASE_OP: /* Release (MutexObject) */
178 Status = AcpiExReleaseMutex (Operand[0], WalkState);
179 break;
181 case AML_RESET_OP: /* Reset (EventObject) */
183 Status = AcpiExSystemResetEvent (Operand[0]);
184 break;
186 case AML_SIGNAL_OP: /* Signal (EventObject) */
188 Status = AcpiExSystemSignalEvent (Operand[0]);
189 break;
191 case AML_SLEEP_OP: /* Sleep (MsecTime) */
193 Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
194 break;
196 case AML_STALL_OP: /* Stall (UsecTime) */
198 Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
199 break;
201 case AML_UNLOAD_OP: /* Unload (Handle) */
203 Status = AcpiExUnloadTable (Operand[0]);
204 break;
206 default: /* Unknown opcode */
208 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
209 WalkState->Opcode));
210 Status = AE_AML_BAD_OPCODE;
211 break;
214 return_ACPI_STATUS (Status);
218 /*******************************************************************************
220 * FUNCTION: AcpiExOpcode_1A_1T_0R
222 * PARAMETERS: WalkState - Current state (contains AML opcode)
224 * RETURN: Status
226 * DESCRIPTION: Execute opcode with one argument, one target, and no
227 * return value.
229 ******************************************************************************/
231 ACPI_STATUS
232 AcpiExOpcode_1A_1T_0R (
233 ACPI_WALK_STATE *WalkState)
235 ACPI_STATUS Status = AE_OK;
236 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
239 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
240 AcpiPsGetOpcodeName (WalkState->Opcode));
243 /* Examine the AML opcode */
245 switch (WalkState->Opcode)
247 case AML_LOAD_OP:
249 Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
250 break;
252 default: /* Unknown opcode */
254 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
255 WalkState->Opcode));
256 Status = AE_AML_BAD_OPCODE;
257 goto Cleanup;
261 Cleanup:
263 return_ACPI_STATUS (Status);
267 /*******************************************************************************
269 * FUNCTION: AcpiExOpcode_1A_1T_1R
271 * PARAMETERS: WalkState - Current state (contains AML opcode)
273 * RETURN: Status
275 * DESCRIPTION: Execute opcode with one argument, one target, and a
276 * return value.
278 ******************************************************************************/
280 ACPI_STATUS
281 AcpiExOpcode_1A_1T_1R (
282 ACPI_WALK_STATE *WalkState)
284 ACPI_STATUS Status = AE_OK;
285 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
286 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
287 ACPI_OPERAND_OBJECT *ReturnDesc2 = NULL;
288 UINT32 Temp32;
289 UINT32 i;
290 UINT64 PowerOfTen;
291 UINT64 Digit;
294 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
295 AcpiPsGetOpcodeName (WalkState->Opcode));
298 /* Examine the AML opcode */
300 switch (WalkState->Opcode)
302 case AML_BIT_NOT_OP:
303 case AML_FIND_SET_LEFT_BIT_OP:
304 case AML_FIND_SET_RIGHT_BIT_OP:
305 case AML_FROM_BCD_OP:
306 case AML_TO_BCD_OP:
307 case AML_COND_REF_OF_OP:
309 /* Create a return object of type Integer for these opcodes */
311 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
312 if (!ReturnDesc)
314 Status = AE_NO_MEMORY;
315 goto Cleanup;
318 switch (WalkState->Opcode)
320 case AML_BIT_NOT_OP: /* Not (Operand, Result) */
322 ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
323 break;
325 case AML_FIND_SET_LEFT_BIT_OP: /* FindSetLeftBit (Operand, Result) */
327 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
330 * Acpi specification describes Integer type as a little
331 * endian unsigned value, so this boundary condition is valid.
333 for (Temp32 = 0; ReturnDesc->Integer.Value &&
334 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
336 ReturnDesc->Integer.Value >>= 1;
339 ReturnDesc->Integer.Value = Temp32;
340 break;
342 case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
344 ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
347 * The Acpi specification describes Integer type as a little
348 * endian unsigned value, so this boundary condition is valid.
350 for (Temp32 = 0; ReturnDesc->Integer.Value &&
351 Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
353 ReturnDesc->Integer.Value <<= 1;
356 /* Since the bit position is one-based, subtract from 33 (65) */
358 ReturnDesc->Integer.Value =
359 Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
360 break;
362 case AML_FROM_BCD_OP: /* FromBcd (BCDValue, Result) */
364 * The 64-bit ACPI integer can hold 16 4-bit BCD characters
365 * (if table is 32-bit, integer can hold 8 BCD characters)
366 * Convert each 4-bit BCD value
368 PowerOfTen = 1;
369 ReturnDesc->Integer.Value = 0;
370 Digit = Operand[0]->Integer.Value;
372 /* Convert each BCD digit (each is one nybble wide) */
374 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
376 /* Get the least significant 4-bit BCD digit */
378 Temp32 = ((UINT32) Digit) & 0xF;
380 /* Check the range of the digit */
382 if (Temp32 > 9)
384 ACPI_ERROR ((AE_INFO,
385 "BCD digit too large (not decimal): 0x%X",
386 Temp32));
388 Status = AE_AML_NUMERIC_OVERFLOW;
389 goto Cleanup;
392 /* Sum the digit into the result with the current power of 10 */
394 ReturnDesc->Integer.Value +=
395 (((UINT64) Temp32) * PowerOfTen);
397 /* Shift to next BCD digit */
399 Digit >>= 4;
401 /* Next power of 10 */
403 PowerOfTen *= 10;
405 break;
407 case AML_TO_BCD_OP: /* ToBcd (Operand, Result) */
409 ReturnDesc->Integer.Value = 0;
410 Digit = Operand[0]->Integer.Value;
412 /* Each BCD digit is one nybble wide */
414 for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
416 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
419 * Insert the BCD digit that resides in the
420 * remainder from above
422 ReturnDesc->Integer.Value |=
423 (((UINT64) Temp32) << ACPI_MUL_4 (i));
426 /* Overflow if there is any data left in Digit */
428 if (Digit > 0)
430 ACPI_ERROR ((AE_INFO,
431 "Integer too large to convert to BCD: 0x%8.8X%8.8X",
432 ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
433 Status = AE_AML_NUMERIC_OVERFLOW;
434 goto Cleanup;
436 break;
438 case AML_COND_REF_OF_OP: /* CondRefOf (SourceObject, Result) */
440 * This op is a little strange because the internal return value is
441 * different than the return value stored in the result descriptor
442 * (There are really two return values)
444 if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
447 * This means that the object does not exist in the namespace,
448 * return FALSE
450 ReturnDesc->Integer.Value = 0;
451 goto Cleanup;
454 /* Get the object reference, store it, and remove our reference */
456 Status = AcpiExGetObjectReference (Operand[0],
457 &ReturnDesc2, WalkState);
458 if (ACPI_FAILURE (Status))
460 goto Cleanup;
463 Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
464 AcpiUtRemoveReference (ReturnDesc2);
466 /* The object exists in the namespace, return TRUE */
468 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
469 goto Cleanup;
472 default:
474 /* No other opcodes get here */
476 break;
478 break;
480 case AML_STORE_OP: /* Store (Source, Target) */
482 * A store operand is typically a number, string, buffer or lvalue
483 * Be careful about deleting the source object,
484 * since the object itself may have been stored.
486 Status = AcpiExStore (Operand[0], Operand[1], WalkState);
487 if (ACPI_FAILURE (Status))
489 return_ACPI_STATUS (Status);
492 /* It is possible that the Store already produced a return object */
494 if (!WalkState->ResultObj)
497 * Normally, we would remove a reference on the Operand[0]
498 * parameter; But since it is being used as the internal return
499 * object (meaning we would normally increment it), the two
500 * cancel out, and we simply don't do anything.
502 WalkState->ResultObj = Operand[0];
503 WalkState->Operands[0] = NULL; /* Prevent deletion */
505 return_ACPI_STATUS (Status);
508 * ACPI 2.0 Opcodes
510 case AML_COPY_OP: /* Copy (Source, Target) */
512 Status = AcpiUtCopyIobjectToIobject (
513 Operand[0], &ReturnDesc, WalkState);
514 break;
516 case AML_TO_DECSTRING_OP: /* ToDecimalString (Data, Result) */
518 Status = AcpiExConvertToString (
519 Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
520 if (ReturnDesc == Operand[0])
522 /* No conversion performed, add ref to handle return value */
524 AcpiUtAddReference (ReturnDesc);
526 break;
528 case AML_TO_HEXSTRING_OP: /* ToHexString (Data, Result) */
530 Status = AcpiExConvertToString (
531 Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
532 if (ReturnDesc == Operand[0])
534 /* No conversion performed, add ref to handle return value */
536 AcpiUtAddReference (ReturnDesc);
538 break;
540 case AML_TO_BUFFER_OP: /* ToBuffer (Data, Result) */
542 Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
543 if (ReturnDesc == Operand[0])
545 /* No conversion performed, add ref to handle return value */
547 AcpiUtAddReference (ReturnDesc);
549 break;
551 case AML_TO_INTEGER_OP: /* ToInteger (Data, Result) */
553 Status = AcpiExConvertToInteger (
554 Operand[0], &ReturnDesc, ACPI_ANY_BASE);
555 if (ReturnDesc == Operand[0])
557 /* No conversion performed, add ref to handle return value */
559 AcpiUtAddReference (ReturnDesc);
561 break;
563 case AML_SHIFT_LEFT_BIT_OP: /* ShiftLeftBit (Source, BitNum) */
564 case AML_SHIFT_RIGHT_BIT_OP: /* ShiftRightBit (Source, BitNum) */
566 /* These are two obsolete opcodes */
568 ACPI_ERROR ((AE_INFO,
569 "%s is obsolete and not implemented",
570 AcpiPsGetOpcodeName (WalkState->Opcode)));
571 Status = AE_SUPPORT;
572 goto Cleanup;
574 default: /* Unknown opcode */
576 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
577 WalkState->Opcode));
578 Status = AE_AML_BAD_OPCODE;
579 goto Cleanup;
582 if (ACPI_SUCCESS (Status))
584 /* Store the return value computed above into the target object */
586 Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
590 Cleanup:
592 /* Delete return object on error */
594 if (ACPI_FAILURE (Status))
596 AcpiUtRemoveReference (ReturnDesc);
599 /* Save return object on success */
601 else if (!WalkState->ResultObj)
603 WalkState->ResultObj = ReturnDesc;
606 return_ACPI_STATUS (Status);
610 /*******************************************************************************
612 * FUNCTION: AcpiExOpcode_1A_0T_1R
614 * PARAMETERS: WalkState - Current state (contains AML opcode)
616 * RETURN: Status
618 * DESCRIPTION: Execute opcode with one argument, no target, and a return value
620 ******************************************************************************/
622 ACPI_STATUS
623 AcpiExOpcode_1A_0T_1R (
624 ACPI_WALK_STATE *WalkState)
626 ACPI_OPERAND_OBJECT **Operand = &WalkState->Operands[0];
627 ACPI_OPERAND_OBJECT *TempDesc;
628 ACPI_OPERAND_OBJECT *ReturnDesc = NULL;
629 ACPI_STATUS Status = AE_OK;
630 UINT32 Type;
631 UINT64 Value;
634 ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
635 AcpiPsGetOpcodeName (WalkState->Opcode));
638 /* Examine the AML opcode */
640 switch (WalkState->Opcode)
642 case AML_LNOT_OP: /* LNot (Operand) */
644 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
645 if (!ReturnDesc)
647 Status = AE_NO_MEMORY;
648 goto Cleanup;
652 * Set result to ONES (TRUE) if Value == 0. Note:
653 * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
655 if (!Operand[0]->Integer.Value)
657 ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
659 break;
661 case AML_DECREMENT_OP: /* Decrement (Operand) */
662 case AML_INCREMENT_OP: /* Increment (Operand) */
664 * Create a new integer. Can't just get the base integer and
665 * increment it because it may be an Arg or Field.
667 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
668 if (!ReturnDesc)
670 Status = AE_NO_MEMORY;
671 goto Cleanup;
675 * Since we are expecting a Reference operand, it can be either a
676 * NS Node or an internal object.
678 TempDesc = Operand[0];
679 if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
681 /* Internal reference object - prevent deletion */
683 AcpiUtAddReference (TempDesc);
687 * Convert the Reference operand to an Integer (This removes a
688 * reference on the Operand[0] object)
690 * NOTE: We use LNOT_OP here in order to force resolution of the
691 * reference operand to an actual integer.
693 Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
694 if (ACPI_FAILURE (Status))
696 ACPI_EXCEPTION ((AE_INFO, Status,
697 "While resolving operands for [%s]",
698 AcpiPsGetOpcodeName (WalkState->Opcode)));
700 goto Cleanup;
704 * TempDesc is now guaranteed to be an Integer object --
705 * Perform the actual increment or decrement
707 if (WalkState->Opcode == AML_INCREMENT_OP)
709 ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
711 else
713 ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
716 /* Finished with this Integer object */
718 AcpiUtRemoveReference (TempDesc);
721 * Store the result back (indirectly) through the original
722 * Reference object
724 Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
725 break;
727 case AML_OBJECT_TYPE_OP: /* ObjectType (SourceObject) */
729 * Note: The operand is not resolved at this point because we want to
730 * get the associated object, not its value. For example, we don't
731 * want to resolve a FieldUnit to its value, we want the actual
732 * FieldUnit object.
735 /* Get the type of the base object */
737 Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
738 if (ACPI_FAILURE (Status))
740 goto Cleanup;
743 /* Allocate a descriptor to hold the type. */
745 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
746 if (!ReturnDesc)
748 Status = AE_NO_MEMORY;
749 goto Cleanup;
751 break;
753 case AML_SIZE_OF_OP: /* SizeOf (SourceObject) */
755 * Note: The operand is not resolved at this point because we want to
756 * get the associated object, not its value.
759 /* Get the base object */
761 Status = AcpiExResolveMultiple (
762 WalkState, Operand[0], &Type, &TempDesc);
763 if (ACPI_FAILURE (Status))
765 goto Cleanup;
769 * The type of the base object must be integer, buffer, string, or
770 * package. All others are not supported.
772 * NOTE: Integer is not specifically supported by the ACPI spec,
773 * but is supported implicitly via implicit operand conversion.
774 * rather than bother with conversion, we just use the byte width
775 * global (4 or 8 bytes).
777 switch (Type)
779 case ACPI_TYPE_INTEGER:
781 Value = AcpiGbl_IntegerByteWidth;
782 break;
784 case ACPI_TYPE_STRING:
786 Value = TempDesc->String.Length;
787 break;
789 case ACPI_TYPE_BUFFER:
791 /* Buffer arguments may not be evaluated at this point */
793 Status = AcpiDsGetBufferArguments (TempDesc);
794 Value = TempDesc->Buffer.Length;
795 break;
797 case ACPI_TYPE_PACKAGE:
799 /* Package arguments may not be evaluated at this point */
801 Status = AcpiDsGetPackageArguments (TempDesc);
802 Value = TempDesc->Package.Count;
803 break;
805 default:
807 ACPI_ERROR ((AE_INFO,
808 "Operand must be Buffer/Integer/String/Package"
809 " - found type %s",
810 AcpiUtGetTypeName (Type)));
812 Status = AE_AML_OPERAND_TYPE;
813 goto Cleanup;
816 if (ACPI_FAILURE (Status))
818 goto Cleanup;
822 * Now that we have the size of the object, create a result
823 * object to hold the value
825 ReturnDesc = AcpiUtCreateIntegerObject (Value);
826 if (!ReturnDesc)
828 Status = AE_NO_MEMORY;
829 goto Cleanup;
831 break;
834 case AML_REF_OF_OP: /* RefOf (SourceObject) */
836 Status = AcpiExGetObjectReference (
837 Operand[0], &ReturnDesc, WalkState);
838 if (ACPI_FAILURE (Status))
840 goto Cleanup;
842 break;
845 case AML_DEREF_OF_OP: /* DerefOf (ObjReference | String) */
847 /* Check for a method local or argument, or standalone String */
849 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
851 TempDesc = AcpiNsGetAttachedObject (
852 (ACPI_NAMESPACE_NODE *) Operand[0]);
853 if (TempDesc &&
854 ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
855 (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
857 Operand[0] = TempDesc;
858 AcpiUtAddReference (TempDesc);
860 else
862 Status = AE_AML_OPERAND_TYPE;
863 goto Cleanup;
866 else
868 switch ((Operand[0])->Common.Type)
870 case ACPI_TYPE_LOCAL_REFERENCE:
872 * This is a DerefOf (LocalX | ArgX)
874 * Must resolve/dereference the local/arg reference first
876 switch (Operand[0]->Reference.Class)
878 case ACPI_REFCLASS_LOCAL:
879 case ACPI_REFCLASS_ARG:
881 /* Set Operand[0] to the value of the local/arg */
883 Status = AcpiDsMethodDataGetValue (
884 Operand[0]->Reference.Class,
885 Operand[0]->Reference.Value,
886 WalkState, &TempDesc);
887 if (ACPI_FAILURE (Status))
889 goto Cleanup;
893 * Delete our reference to the input object and
894 * point to the object just retrieved
896 AcpiUtRemoveReference (Operand[0]);
897 Operand[0] = TempDesc;
898 break;
900 case ACPI_REFCLASS_REFOF:
902 /* Get the object to which the reference refers */
904 TempDesc = Operand[0]->Reference.Object;
905 AcpiUtRemoveReference (Operand[0]);
906 Operand[0] = TempDesc;
907 break;
909 default:
911 /* Must be an Index op - handled below */
912 break;
914 break;
916 case ACPI_TYPE_STRING:
918 break;
920 default:
922 Status = AE_AML_OPERAND_TYPE;
923 goto Cleanup;
927 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
929 if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
932 * This is a DerefOf (String). The string is a reference
933 * to a named ACPI object.
935 * 1) Find the owning Node
936 * 2) Dereference the node to an actual object. Could be a
937 * Field, so we need to resolve the node to a value.
939 Status = AcpiNsGetNode (WalkState->ScopeInfo->Scope.Node,
940 Operand[0]->String.Pointer,
941 ACPI_NS_SEARCH_PARENT,
942 ACPI_CAST_INDIRECT_PTR (
943 ACPI_NAMESPACE_NODE, &ReturnDesc));
944 if (ACPI_FAILURE (Status))
946 goto Cleanup;
949 Status = AcpiExResolveNodeToValue (
950 ACPI_CAST_INDIRECT_PTR (
951 ACPI_NAMESPACE_NODE, &ReturnDesc),
952 WalkState);
953 goto Cleanup;
957 /* Operand[0] may have changed from the code above */
959 if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
962 * This is a DerefOf (ObjectReference)
963 * Get the actual object from the Node (This is the dereference).
964 * This case may only happen when a LocalX or ArgX is
965 * dereferenced above.
967 ReturnDesc = AcpiNsGetAttachedObject (
968 (ACPI_NAMESPACE_NODE *) Operand[0]);
969 AcpiUtAddReference (ReturnDesc);
971 else
974 * This must be a reference object produced by either the
975 * Index() or RefOf() operator
977 switch (Operand[0]->Reference.Class)
979 case ACPI_REFCLASS_INDEX:
981 * The target type for the Index operator must be
982 * either a Buffer or a Package
984 switch (Operand[0]->Reference.TargetType)
986 case ACPI_TYPE_BUFFER_FIELD:
988 TempDesc = Operand[0]->Reference.Object;
991 * Create a new object that contains one element of the
992 * buffer -- the element pointed to by the index.
994 * NOTE: index into a buffer is NOT a pointer to a
995 * sub-buffer of the main buffer, it is only a pointer to a
996 * single element (byte) of the buffer!
998 * Since we are returning the value of the buffer at the
999 * indexed location, we don't need to add an additional
1000 * reference to the buffer itself.
1002 ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
1003 TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
1004 if (!ReturnDesc)
1006 Status = AE_NO_MEMORY;
1007 goto Cleanup;
1009 break;
1011 case ACPI_TYPE_PACKAGE:
1013 * Return the referenced element of the package. We must
1014 * add another reference to the referenced object, however.
1016 ReturnDesc = *(Operand[0]->Reference.Where);
1017 if (!ReturnDesc)
1020 * Element is NULL, do not allow the dereference.
1021 * This provides compatibility with other ACPI
1022 * implementations.
1024 return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1027 AcpiUtAddReference (ReturnDesc);
1028 break;
1030 default:
1032 ACPI_ERROR ((AE_INFO,
1033 "Unknown Index TargetType 0x%X in reference object %p",
1034 Operand[0]->Reference.TargetType, Operand[0]));
1036 Status = AE_AML_OPERAND_TYPE;
1037 goto Cleanup;
1039 break;
1041 case ACPI_REFCLASS_REFOF:
1043 ReturnDesc = Operand[0]->Reference.Object;
1045 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1046 ACPI_DESC_TYPE_NAMED)
1048 ReturnDesc = AcpiNsGetAttachedObject (
1049 (ACPI_NAMESPACE_NODE *) ReturnDesc);
1050 if (!ReturnDesc)
1052 break;
1056 * June 2013:
1057 * BufferFields/FieldUnits require additional resolution
1059 switch (ReturnDesc->Common.Type)
1061 case ACPI_TYPE_BUFFER_FIELD:
1062 case ACPI_TYPE_LOCAL_REGION_FIELD:
1063 case ACPI_TYPE_LOCAL_BANK_FIELD:
1064 case ACPI_TYPE_LOCAL_INDEX_FIELD:
1066 Status = AcpiExReadDataFromField (
1067 WalkState, ReturnDesc, &TempDesc);
1068 if (ACPI_FAILURE (Status))
1070 goto Cleanup;
1073 ReturnDesc = TempDesc;
1074 break;
1076 default:
1078 /* Add another reference to the object */
1080 AcpiUtAddReference (ReturnDesc);
1081 break;
1084 break;
1086 default:
1088 ACPI_ERROR ((AE_INFO,
1089 "Unknown class in reference(%p) - 0x%2.2X",
1090 Operand[0], Operand[0]->Reference.Class));
1092 Status = AE_TYPE;
1093 goto Cleanup;
1096 break;
1098 default:
1100 ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1101 WalkState->Opcode));
1103 Status = AE_AML_BAD_OPCODE;
1104 goto Cleanup;
1108 Cleanup:
1110 /* Delete return object on error */
1112 if (ACPI_FAILURE (Status))
1114 AcpiUtRemoveReference (ReturnDesc);
1117 /* Save return object on success */
1119 else
1121 WalkState->ResultObj = ReturnDesc;
1124 return_ACPI_STATUS (Status);