i386/identcpu.c: Add VIA Nano support
[dragonfly.git] / sys / contrib / dev / acpica-unix-20061109 / interpreter / executer / exoparg1.c
1
2 /******************************************************************************
3  *
4  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
5  *              $Revision: 1.181 $
6  *
7  *****************************************************************************/
8
9 /******************************************************************************
10  *
11  * 1. Copyright Notice
12  *
13  * Some or all of this work - Copyright (c) 1999 - 2006, Intel Corp.
14  * All rights reserved.
15  *
16  * 2. License
17  *
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
21  * property rights.
22  *
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
29  *
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;
38  *
39  * The above copyright and patent license is granted only if the following
40  * conditions are met:
41  *
42  * 3. Conditions
43  *
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.
55  *
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
66  * make.
67  *
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
72  * distribution.
73  *
74  * 3.4. Intel retains all right, title, and interest in and to the Original
75  * Intel Code.
76  *
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.
81  *
82  * 4. Disclaimer and Export Compliance
83  *
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
90  * PARTICULAR PURPOSE.
91  *
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
99  * LIMITED REMEDY.
100  *
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.
115  *
116  *****************************************************************************/
117
118 #define __EXOPARG1_C__
119
120 #include "acpi.h"
121 #include "acparser.h"
122 #include "acdispat.h"
123 #include "acinterp.h"
124 #include "amlcode.h"
125 #include "acnamesp.h"
126
127
128 #define _COMPONENT          ACPI_EXECUTER
129         ACPI_MODULE_NAME    ("exoparg1")
130
131
132 /*!
133  * Naming convention for AML interpreter execution routines.
134  *
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:
138  *
139  *      AcpiExOpcode_xA_yT_zR
140  *
141  * Where:
142  *
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).
149  *
150  * The AcpiExOpcode* functions are called via the Dispatcher component with
151  * fully resolved operands.
152 !*/
153
154 /*******************************************************************************
155  *
156  * FUNCTION:    AcpiExOpcode_0A_0T_1R
157  *
158  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
159  *
160  * RETURN:      Status
161  *
162  * DESCRIPTION: Execute operator with no operands, one return value
163  *
164  ******************************************************************************/
165
166 ACPI_STATUS
167 AcpiExOpcode_0A_0T_1R (
168     ACPI_WALK_STATE         *WalkState)
169 {
170     ACPI_STATUS             Status = AE_OK;
171     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
172
173
174     ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
175         AcpiPsGetOpcodeName (WalkState->Opcode));
176
177
178     /* Examine the AML opcode */
179
180     switch (WalkState->Opcode)
181     {
182     case AML_TIMER_OP:      /*  Timer () */
183
184         /* Create a return object of type Integer */
185
186         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
187         if (!ReturnDesc)
188         {
189             Status = AE_NO_MEMORY;
190             goto Cleanup;
191         }
192 #if ACPI_MACHINE_WIDTH != 16
193         ReturnDesc->Integer.Value = AcpiOsGetTimer ();
194 #endif
195         break;
196
197     default:                /*  Unknown opcode  */
198
199         ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
200             WalkState->Opcode));
201         Status = AE_AML_BAD_OPCODE;
202         break;
203     }
204
205 Cleanup:
206
207     /* Delete return object on error */
208
209     if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
210     {
211         AcpiUtRemoveReference (ReturnDesc);
212     }
213     else
214     {
215         /* Save the return value */
216
217         WalkState->ResultObj = ReturnDesc;
218     }
219
220     return_ACPI_STATUS (Status);
221 }
222
223
224 /*******************************************************************************
225  *
226  * FUNCTION:    AcpiExOpcode_1A_0T_0R
227  *
228  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
229  *
230  * RETURN:      Status
231  *
232  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
233  *              object stack
234  *
235  ******************************************************************************/
236
237 ACPI_STATUS
238 AcpiExOpcode_1A_0T_0R (
239     ACPI_WALK_STATE         *WalkState)
240 {
241     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
242     ACPI_STATUS             Status = AE_OK;
243
244
245     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
246         AcpiPsGetOpcodeName (WalkState->Opcode));
247
248
249     /* Examine the AML opcode */
250
251     switch (WalkState->Opcode)
252     {
253     case AML_RELEASE_OP:    /*  Release (MutexObject) */
254
255         Status = AcpiExReleaseMutex (Operand[0], WalkState);
256         break;
257
258
259     case AML_RESET_OP:      /*  Reset (EventObject) */
260
261         Status = AcpiExSystemResetEvent (Operand[0]);
262         break;
263
264
265     case AML_SIGNAL_OP:     /*  Signal (EventObject) */
266
267         Status = AcpiExSystemSignalEvent (Operand[0]);
268         break;
269
270
271     case AML_SLEEP_OP:      /*  Sleep (MsecTime) */
272
273         Status = AcpiExSystemDoSuspend (Operand[0]->Integer.Value);
274         break;
275
276
277     case AML_STALL_OP:      /*  Stall (UsecTime) */
278
279         Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
280         break;
281
282
283     case AML_UNLOAD_OP:     /*  Unload (Handle) */
284
285         Status = AcpiExUnloadTable (Operand[0]);
286         break;
287
288
289     default:                /*  Unknown opcode  */
290
291         ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
292             WalkState->Opcode));
293         Status = AE_AML_BAD_OPCODE;
294         break;
295     }
296
297     return_ACPI_STATUS (Status);
298 }
299
300
301 /*******************************************************************************
302  *
303  * FUNCTION:    AcpiExOpcode_1A_1T_0R
304  *
305  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
306  *
307  * RETURN:      Status
308  *
309  * DESCRIPTION: Execute opcode with one argument, one target, and no
310  *              return value.
311  *
312  ******************************************************************************/
313
314 ACPI_STATUS
315 AcpiExOpcode_1A_1T_0R (
316     ACPI_WALK_STATE         *WalkState)
317 {
318     ACPI_STATUS             Status = AE_OK;
319     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
320
321
322     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
323         AcpiPsGetOpcodeName (WalkState->Opcode));
324
325
326     /* Examine the AML opcode */
327
328     switch (WalkState->Opcode)
329     {
330     case AML_LOAD_OP:
331
332         Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
333         break;
334
335     default:                        /* Unknown opcode */
336
337         ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
338             WalkState->Opcode));
339         Status = AE_AML_BAD_OPCODE;
340         goto Cleanup;
341     }
342
343
344 Cleanup:
345
346     return_ACPI_STATUS (Status);
347 }
348
349
350 /*******************************************************************************
351  *
352  * FUNCTION:    AcpiExOpcode_1A_1T_1R
353  *
354  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
355  *
356  * RETURN:      Status
357  *
358  * DESCRIPTION: Execute opcode with one argument, one target, and a
359  *              return value.
360  *
361  ******************************************************************************/
362
363 ACPI_STATUS
364 AcpiExOpcode_1A_1T_1R (
365     ACPI_WALK_STATE         *WalkState)
366 {
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;
371     UINT32                  Temp32;
372     UINT32                  i;
373     ACPI_INTEGER            PowerOfTen;
374     ACPI_INTEGER            Digit;
375
376
377     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
378         AcpiPsGetOpcodeName (WalkState->Opcode));
379
380
381     /* Examine the AML opcode */
382
383     switch (WalkState->Opcode)
384     {
385     case AML_BIT_NOT_OP:
386     case AML_FIND_SET_LEFT_BIT_OP:
387     case AML_FIND_SET_RIGHT_BIT_OP:
388     case AML_FROM_BCD_OP:
389     case AML_TO_BCD_OP:
390     case AML_COND_REF_OF_OP:
391
392         /* Create a return object of type Integer for these opcodes */
393
394         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
395         if (!ReturnDesc)
396         {
397             Status = AE_NO_MEMORY;
398             goto Cleanup;
399         }
400
401         switch (WalkState->Opcode)
402         {
403         case AML_BIT_NOT_OP:            /* Not (Operand, Result)  */
404
405             ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
406             break;
407
408
409         case AML_FIND_SET_LEFT_BIT_OP:  /* FindSetLeftBit (Operand, Result) */
410
411             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
412
413             /*
414              * Acpi specification describes Integer type as a little
415              * endian unsigned value, so this boundary condition is valid.
416              */
417             for (Temp32 = 0; ReturnDesc->Integer.Value &&
418                              Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
419             {
420                 ReturnDesc->Integer.Value >>= 1;
421             }
422
423             ReturnDesc->Integer.Value = Temp32;
424             break;
425
426
427         case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
428
429             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
430
431             /*
432              * The Acpi specification describes Integer type as a little
433              * endian unsigned value, so this boundary condition is valid.
434              */
435             for (Temp32 = 0; ReturnDesc->Integer.Value &&
436                              Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
437             {
438                 ReturnDesc->Integer.Value <<= 1;
439             }
440
441             /* Since the bit position is one-based, subtract from 33 (65) */
442
443             ReturnDesc->Integer.Value =
444                 Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
445             break;
446
447
448         case AML_FROM_BCD_OP:           /* FromBcd (BCDValue, Result)  */
449
450             /*
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
454              */
455             PowerOfTen = 1;
456             ReturnDesc->Integer.Value = 0;
457             Digit = Operand[0]->Integer.Value;
458
459             /* Convert each BCD digit (each is one nybble wide) */
460
461             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
462             {
463                 /* Get the least significant 4-bit BCD digit */
464
465                 Temp32 = ((UINT32) Digit) & 0xF;
466
467                 /* Check the range of the digit */
468
469                 if (Temp32 > 9)
470                 {
471                     ACPI_ERROR ((AE_INFO,
472                         "BCD digit too large (not decimal): 0x%X",
473                         Temp32));
474
475                     Status = AE_AML_NUMERIC_OVERFLOW;
476                     goto Cleanup;
477                 }
478
479                 /* Sum the digit into the result with the current power of 10 */
480
481                 ReturnDesc->Integer.Value +=
482                     (((ACPI_INTEGER) Temp32) * PowerOfTen);
483
484                 /* Shift to next BCD digit */
485
486                 Digit >>= 4;
487
488                 /* Next power of 10 */
489
490                 PowerOfTen *= 10;
491             }
492             break;
493
494
495         case AML_TO_BCD_OP:             /* ToBcd (Operand, Result)  */
496
497             ReturnDesc->Integer.Value = 0;
498             Digit = Operand[0]->Integer.Value;
499
500             /* Each BCD digit is one nybble wide */
501
502             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
503             {
504                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
505
506                 /*
507                  * Insert the BCD digit that resides in the
508                  * remainder from above
509                  */
510                 ReturnDesc->Integer.Value |=
511                     (((ACPI_INTEGER) Temp32) << ACPI_MUL_4 (i));
512             }
513
514             /* Overflow if there is any data left in Digit */
515
516             if (Digit > 0)
517             {
518                 ACPI_ERROR ((AE_INFO,
519                     "Integer too large to convert to BCD: %8.8X%8.8X",
520                     ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
521                 Status = AE_AML_NUMERIC_OVERFLOW;
522                 goto Cleanup;
523             }
524             break;
525
526
527         case AML_COND_REF_OF_OP:        /* CondRefOf (SourceObject, Result)  */
528
529             /*
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)
533              */
534             if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
535             {
536                 /*
537                  * This means that the object does not exist in the namespace,
538                  * return FALSE
539                  */
540                 ReturnDesc->Integer.Value = 0;
541                 goto Cleanup;
542             }
543
544             /* Get the object reference, store it, and remove our reference */
545
546             Status = AcpiExGetObjectReference (Operand[0],
547                         &ReturnDesc2, WalkState);
548             if (ACPI_FAILURE (Status))
549             {
550                 goto Cleanup;
551             }
552
553             Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
554             AcpiUtRemoveReference (ReturnDesc2);
555
556             /* The object exists in the namespace, return TRUE */
557
558             ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
559             goto Cleanup;
560
561
562         default:
563             /* No other opcodes get here */
564             break;
565         }
566         break;
567
568
569     case AML_STORE_OP:              /* Store (Source, Target) */
570
571         /*
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.
575          */
576         Status = AcpiExStore (Operand[0], Operand[1], WalkState);
577         if (ACPI_FAILURE (Status))
578         {
579             return_ACPI_STATUS (Status);
580         }
581
582         /* It is possible that the Store already produced a return object */
583
584         if (!WalkState->ResultObj)
585         {
586             /*
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.
591              */
592             WalkState->ResultObj = Operand[0];
593             WalkState->Operands[0] = NULL;  /* Prevent deletion */
594         }
595         return_ACPI_STATUS (Status);
596
597
598     /*
599      * ACPI 2.0 Opcodes
600      */
601     case AML_COPY_OP:               /* Copy (Source, Target) */
602
603         Status = AcpiUtCopyIobjectToIobject (Operand[0], &ReturnDesc,
604                     WalkState);
605         break;
606
607
608     case AML_TO_DECSTRING_OP:       /* ToDecimalString (Data, Result) */
609
610         Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
611                     ACPI_EXPLICIT_CONVERT_DECIMAL);
612         if (ReturnDesc == Operand[0])
613         {
614             /* No conversion performed, add ref to handle return value */
615             AcpiUtAddReference (ReturnDesc);
616         }
617         break;
618
619
620     case AML_TO_HEXSTRING_OP:       /* ToHexString (Data, Result) */
621
622         Status = AcpiExConvertToString (Operand[0], &ReturnDesc,
623                     ACPI_EXPLICIT_CONVERT_HEX);
624         if (ReturnDesc == Operand[0])
625         {
626             /* No conversion performed, add ref to handle return value */
627             AcpiUtAddReference (ReturnDesc);
628         }
629         break;
630
631
632     case AML_TO_BUFFER_OP:          /* ToBuffer (Data, Result) */
633
634         Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
635         if (ReturnDesc == Operand[0])
636         {
637             /* No conversion performed, add ref to handle return value */
638             AcpiUtAddReference (ReturnDesc);
639         }
640         break;
641
642
643     case AML_TO_INTEGER_OP:         /* ToInteger (Data, Result) */
644
645         Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc,
646                     ACPI_ANY_BASE);
647         if (ReturnDesc == Operand[0])
648         {
649             /* No conversion performed, add ref to handle return value */
650             AcpiUtAddReference (ReturnDesc);
651         }
652         break;
653
654
655     case AML_SHIFT_LEFT_BIT_OP:     /* ShiftLeftBit (Source, BitNum)  */
656     case AML_SHIFT_RIGHT_BIT_OP:    /* ShiftRightBit (Source, BitNum) */
657
658         /* These are two obsolete opcodes */
659
660         ACPI_ERROR ((AE_INFO,
661             "%s is obsolete and not implemented",
662             AcpiPsGetOpcodeName (WalkState->Opcode)));
663         Status = AE_SUPPORT;
664         goto Cleanup;
665
666
667     default:                        /* Unknown opcode */
668
669         ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
670             WalkState->Opcode));
671         Status = AE_AML_BAD_OPCODE;
672         goto Cleanup;
673     }
674
675     if (ACPI_SUCCESS (Status))
676     {
677         /* Store the return value computed above into the target object */
678
679         Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
680     }
681
682
683 Cleanup:
684
685     /* Delete return object on error */
686
687     if (ACPI_FAILURE (Status))
688     {
689         AcpiUtRemoveReference (ReturnDesc);
690     }
691
692     /* Save return object on success */
693
694     else if (!WalkState->ResultObj)
695     {
696         WalkState->ResultObj = ReturnDesc;
697     }
698
699     return_ACPI_STATUS (Status);
700 }
701
702
703 /*******************************************************************************
704  *
705  * FUNCTION:    AcpiExOpcode_1A_0T_1R
706  *
707  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
708  *
709  * RETURN:      Status
710  *
711  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
712  *
713  ******************************************************************************/
714
715 ACPI_STATUS
716 AcpiExOpcode_1A_0T_1R (
717     ACPI_WALK_STATE         *WalkState)
718 {
719     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
720     ACPI_OPERAND_OBJECT     *TempDesc;
721     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
722     ACPI_STATUS             Status = AE_OK;
723     UINT32                  Type;
724     ACPI_INTEGER            Value;
725
726
727     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
728         AcpiPsGetOpcodeName (WalkState->Opcode));
729
730
731     /* Examine the AML opcode */
732
733     switch (WalkState->Opcode)
734     {
735     case AML_LNOT_OP:               /* LNot (Operand) */
736
737         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
738         if (!ReturnDesc)
739         {
740             Status = AE_NO_MEMORY;
741             goto Cleanup;
742         }
743
744         /*
745          * Set result to ONES (TRUE) if Value == 0.  Note:
746          * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
747          */
748         if (!Operand[0]->Integer.Value)
749         {
750             ReturnDesc->Integer.Value = ACPI_INTEGER_MAX;
751         }
752         break;
753
754
755     case AML_DECREMENT_OP:          /* Decrement (Operand)  */
756     case AML_INCREMENT_OP:          /* Increment (Operand)  */
757
758         /*
759          * Create a new integer.  Can't just get the base integer and
760          * increment it because it may be an Arg or Field.
761          */
762         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
763         if (!ReturnDesc)
764         {
765             Status = AE_NO_MEMORY;
766             goto Cleanup;
767         }
768
769         /*
770          * Since we are expecting a Reference operand, it can be either a
771          * NS Node or an internal object.
772          */
773         TempDesc = Operand[0];
774         if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
775         {
776             /* Internal reference object - prevent deletion */
777
778             AcpiUtAddReference (TempDesc);
779         }
780
781         /*
782          * Convert the Reference operand to an Integer (This removes a
783          * reference on the Operand[0] object)
784          *
785          * NOTE:  We use LNOT_OP here in order to force resolution of the
786          * reference operand to an actual integer.
787          */
788         Status = AcpiExResolveOperands (AML_LNOT_OP, &TempDesc, WalkState);
789         if (ACPI_FAILURE (Status))
790         {
791             ACPI_EXCEPTION ((AE_INFO, Status,
792                 "While resolving operands for [%s]",
793                 AcpiPsGetOpcodeName (WalkState->Opcode)));
794
795             goto Cleanup;
796         }
797
798         /*
799          * TempDesc is now guaranteed to be an Integer object --
800          * Perform the actual increment or decrement
801          */
802         if (WalkState->Opcode == AML_INCREMENT_OP)
803         {
804             ReturnDesc->Integer.Value = TempDesc->Integer.Value +1;
805         }
806         else
807         {
808             ReturnDesc->Integer.Value = TempDesc->Integer.Value -1;
809         }
810
811         /* Finished with this Integer object */
812
813         AcpiUtRemoveReference (TempDesc);
814
815         /*
816          * Store the result back (indirectly) through the original
817          * Reference object
818          */
819         Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
820         break;
821
822
823     case AML_TYPE_OP:               /* ObjectType (SourceObject) */
824
825         /*
826          * Note: The operand is not resolved at this point because we want to
827          * get the associated object, not its value.  For example, we don't
828          * want to resolve a FieldUnit to its value, we want the actual
829          * FieldUnit object.
830          */
831
832         /* Get the type of the base object */
833
834         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
835         if (ACPI_FAILURE (Status))
836         {
837             goto Cleanup;
838         }
839
840         /* Allocate a descriptor to hold the type. */
841
842         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
843         if (!ReturnDesc)
844         {
845             Status = AE_NO_MEMORY;
846             goto Cleanup;
847         }
848
849         ReturnDesc->Integer.Value = Type;
850         break;
851
852
853     case AML_SIZE_OF_OP:            /* SizeOf (SourceObject)  */
854
855         /*
856          * Note: The operand is not resolved at this point because we want to
857          * get the associated object, not its value.
858          */
859
860         /* Get the base object */
861
862         Status = AcpiExResolveMultiple (WalkState,
863                     Operand[0], &Type, &TempDesc);
864         if (ACPI_FAILURE (Status))
865         {
866             goto Cleanup;
867         }
868
869         /*
870          * The type of the base object must be integer, buffer, string, or
871          * package.  All others are not supported.
872          *
873          * NOTE: Integer is not specifically supported by the ACPI spec,
874          * but is supported implicitly via implicit operand conversion.
875          * rather than bother with conversion, we just use the byte width
876          * global (4 or 8 bytes).
877          */
878         switch (Type)
879         {
880         case ACPI_TYPE_INTEGER:
881             Value = AcpiGbl_IntegerByteWidth;
882             break;
883
884         case ACPI_TYPE_BUFFER:
885             Value = TempDesc->Buffer.Length;
886             break;
887
888         case ACPI_TYPE_STRING:
889             Value = TempDesc->String.Length;
890             break;
891
892         case ACPI_TYPE_PACKAGE:
893             Value = TempDesc->Package.Count;
894             break;
895
896         default:
897             ACPI_ERROR ((AE_INFO,
898                 "Operand is not Buf/Int/Str/Pkg - found type %s",
899                 AcpiUtGetTypeName (Type)));
900             Status = AE_AML_OPERAND_TYPE;
901             goto Cleanup;
902         }
903
904         /*
905          * Now that we have the size of the object, create a result
906          * object to hold the value
907          */
908         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
909         if (!ReturnDesc)
910         {
911             Status = AE_NO_MEMORY;
912             goto Cleanup;
913         }
914
915         ReturnDesc->Integer.Value = Value;
916         break;
917
918
919     case AML_REF_OF_OP:             /* RefOf (SourceObject) */
920
921         Status = AcpiExGetObjectReference (Operand[0], &ReturnDesc, WalkState);
922         if (ACPI_FAILURE (Status))
923         {
924             goto Cleanup;
925         }
926         break;
927
928
929     case AML_DEREF_OF_OP:           /* DerefOf (ObjReference | String) */
930
931         /* Check for a method local or argument, or standalone String */
932
933         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
934         {
935             TempDesc = AcpiNsGetAttachedObject (
936                            (ACPI_NAMESPACE_NODE *) Operand[0]);
937             if (TempDesc &&
938                  ((ACPI_GET_OBJECT_TYPE (TempDesc) == ACPI_TYPE_STRING) ||
939                   (ACPI_GET_OBJECT_TYPE (TempDesc) == ACPI_TYPE_LOCAL_REFERENCE)))
940             {
941                 Operand[0] = TempDesc;
942                 AcpiUtAddReference (TempDesc);
943             }
944             else
945             {
946                 Status = AE_AML_OPERAND_TYPE;
947                 goto Cleanup;
948             }
949         }
950         else
951         {
952             switch (ACPI_GET_OBJECT_TYPE (Operand[0]))
953             {
954             case ACPI_TYPE_LOCAL_REFERENCE:
955                 /*
956                  * This is a DerefOf (LocalX | ArgX)
957                  *
958                  * Must resolve/dereference the local/arg reference first
959                  */
960                 switch (Operand[0]->Reference.Opcode)
961                 {
962                 case AML_LOCAL_OP:
963                 case AML_ARG_OP:
964
965                     /* Set Operand[0] to the value of the local/arg */
966
967                     Status = AcpiDsMethodDataGetValue (
968                                 Operand[0]->Reference.Opcode,
969                                 Operand[0]->Reference.Offset,
970                                 WalkState, &TempDesc);
971                     if (ACPI_FAILURE (Status))
972                     {
973                         goto Cleanup;
974                     }
975
976                     /*
977                      * Delete our reference to the input object and
978                      * point to the object just retrieved
979                      */
980                     AcpiUtRemoveReference (Operand[0]);
981                     Operand[0] = TempDesc;
982                     break;
983
984                 case AML_REF_OF_OP:
985
986                     /* Get the object to which the reference refers */
987
988                     TempDesc = Operand[0]->Reference.Object;
989                     AcpiUtRemoveReference (Operand[0]);
990                     Operand[0] = TempDesc;
991                     break;
992
993                 default:
994
995                     /* Must be an Index op - handled below */
996                     break;
997                 }
998                 break;
999
1000             case ACPI_TYPE_STRING:
1001                 break;
1002
1003             default:
1004                 Status = AE_AML_OPERAND_TYPE;
1005                 goto Cleanup;
1006             }
1007         }
1008
1009         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
1010         {
1011             if (ACPI_GET_OBJECT_TYPE (Operand[0]) == ACPI_TYPE_STRING)
1012             {
1013                 /*
1014                  * This is a DerefOf (String). The string is a reference
1015                  * to a named ACPI object.
1016                  *
1017                  * 1) Find the owning Node
1018                  * 2) Dereference the node to an actual object. Could be a
1019                  *    Field, so we need to resolve the node to a value.
1020                  */
1021                 Status = AcpiNsGetNode (WalkState->ScopeInfo->Scope.Node,
1022                             Operand[0]->String.Pointer,
1023                             ACPI_NS_SEARCH_PARENT,
1024                             ACPI_CAST_INDIRECT_PTR (
1025                                 ACPI_NAMESPACE_NODE, &ReturnDesc));
1026                 if (ACPI_FAILURE (Status))
1027                 {
1028                     goto Cleanup;
1029                 }
1030
1031                 Status = AcpiExResolveNodeToValue (
1032                             ACPI_CAST_INDIRECT_PTR (
1033                                 ACPI_NAMESPACE_NODE, &ReturnDesc),
1034                             WalkState);
1035                 goto Cleanup;
1036             }
1037         }
1038
1039         /* Operand[0] may have changed from the code above */
1040
1041         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1042         {
1043             /*
1044              * This is a DerefOf (ObjectReference)
1045              * Get the actual object from the Node (This is the dereference).
1046              * This case may only happen when a LocalX or ArgX is
1047              * dereferenced above.
1048              */
1049             ReturnDesc = AcpiNsGetAttachedObject (
1050                             (ACPI_NAMESPACE_NODE *) Operand[0]);
1051             AcpiUtAddReference (ReturnDesc);
1052         }
1053         else
1054         {
1055             /*
1056              * This must be a reference object produced by either the
1057              * Index() or RefOf() operator
1058              */
1059             switch (Operand[0]->Reference.Opcode)
1060             {
1061             case AML_INDEX_OP:
1062
1063                 /*
1064                  * The target type for the Index operator must be
1065                  * either a Buffer or a Package
1066                  */
1067                 switch (Operand[0]->Reference.TargetType)
1068                 {
1069                 case ACPI_TYPE_BUFFER_FIELD:
1070
1071                     TempDesc = Operand[0]->Reference.Object;
1072
1073                     /*
1074                      * Create a new object that contains one element of the
1075                      * buffer -- the element pointed to by the index.
1076                      *
1077                      * NOTE: index into a buffer is NOT a pointer to a
1078                      * sub-buffer of the main buffer, it is only a pointer to a
1079                      * single element (byte) of the buffer!
1080                      */
1081                     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
1082                     if (!ReturnDesc)
1083                     {
1084                         Status = AE_NO_MEMORY;
1085                         goto Cleanup;
1086                     }
1087
1088                     /*
1089                      * Since we are returning the value of the buffer at the
1090                      * indexed location, we don't need to add an additional
1091                      * reference to the buffer itself.
1092                      */
1093                     ReturnDesc->Integer.Value =
1094                         TempDesc->Buffer.Pointer[Operand[0]->Reference.Offset];
1095                     break;
1096
1097
1098                 case ACPI_TYPE_PACKAGE:
1099
1100                     /*
1101                      * Return the referenced element of the package.  We must
1102                      * add another reference to the referenced object, however.
1103                      */
1104                     ReturnDesc = *(Operand[0]->Reference.Where);
1105                     if (ReturnDesc)
1106                     {
1107                         AcpiUtAddReference (ReturnDesc);
1108                     }
1109                     break;
1110
1111
1112                 default:
1113
1114                     ACPI_ERROR ((AE_INFO,
1115                         "Unknown Index TargetType %X in obj %p",
1116                         Operand[0]->Reference.TargetType, Operand[0]));
1117                     Status = AE_AML_OPERAND_TYPE;
1118                     goto Cleanup;
1119                 }
1120                 break;
1121
1122
1123             case AML_REF_OF_OP:
1124
1125                 ReturnDesc = Operand[0]->Reference.Object;
1126
1127                 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1128                         ACPI_DESC_TYPE_NAMED)
1129                 {
1130                     ReturnDesc = AcpiNsGetAttachedObject (
1131                                     (ACPI_NAMESPACE_NODE *) ReturnDesc);
1132                 }
1133
1134                 /* Add another reference to the object! */
1135
1136                 AcpiUtAddReference (ReturnDesc);
1137                 break;
1138
1139
1140             default:
1141                 ACPI_ERROR ((AE_INFO,
1142                     "Unknown opcode in reference(%p) - %X",
1143                     Operand[0], Operand[0]->Reference.Opcode));
1144
1145                 Status = AE_TYPE;
1146                 goto Cleanup;
1147             }
1148         }
1149         break;
1150
1151
1152     default:
1153
1154         ACPI_ERROR ((AE_INFO, "Unknown AML opcode %X",
1155             WalkState->Opcode));
1156         Status = AE_AML_BAD_OPCODE;
1157         goto Cleanup;
1158     }
1159
1160
1161 Cleanup:
1162
1163     /* Delete return object on error */
1164
1165     if (ACPI_FAILURE (Status))
1166     {
1167         AcpiUtRemoveReference (ReturnDesc);
1168     }
1169
1170     /* Save return object on success */
1171
1172     else
1173     {
1174         WalkState->ResultObj = ReturnDesc;
1175     }
1176
1177     return_ACPI_STATUS (Status);
1178 }
1179