1 /******************************************************************************
2  *
3  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
4  *
5  *****************************************************************************/
6 
7 /******************************************************************************
8  *
9  * 1. Copyright Notice
10  *
11  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
12  * All rights reserved.
13  *
14  * 2. License
15  *
16  * 2.1. This is your license from Intel Corp. under its intellectual property
17  * rights. You may have additional license terms from the party that provided
18  * you this software, covering your right to use that party's intellectual
19  * property rights.
20  *
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
27  *
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;
36  *
37  * The above copyright and patent license is granted only if the following
38  * conditions are met:
39  *
40  * 3. Conditions
41  *
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.
53  *
54  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55  * Redistribution of source code of any substantial portion of the Covered
56  * Code or modification without rights to further distribute source must
57  * include the following Disclaimer and Export Compliance provision in the
58  * documentation and/or other materials provided with distribution. In
59  * addition, Licensee may not authorize further sublicense of source of any
60  * portion of the Covered Code, and must include terms to the effect that the
61  * license from Licensee to its licensee is limited to the intellectual
62  * property embodied in the software Licensee provides to its licensee, and
63  * not to intellectual property embodied in modifications its licensee may
64  * make.
65  *
66  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67  * substantial portion of the Covered Code or modification must reproduce the
68  * above Copyright Notice, and the following Disclaimer and Export Compliance
69  * provision in the documentation and/or other materials provided with the
70  * distribution.
71  *
72  * 3.4. Intel retains all right, title, and interest in and to the Original
73  * Intel Code.
74  *
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.
79  *
80  * 4. Disclaimer and Export Compliance
81  *
82  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88  * PARTICULAR PURPOSE.
89  *
90  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97  * LIMITED REMEDY.
98  *
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.
113  *
114  *****************************************************************************
115  *
116  * Alternatively, you may choose to be licensed under the terms of the
117  * following license:
118  *
119  * Redistribution and use in source and binary forms, with or without
120  * modification, are permitted provided that the following conditions
121  * are met:
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.
133  *
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.
145  *
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.
149  *
150  *****************************************************************************/
151 
152 #include "acpi.h"
153 #include "accommon.h"
154 #include "acparser.h"
155 #include "acdispat.h"
156 #include "acinterp.h"
157 #include "amlcode.h"
158 #include "acnamesp.h"
159 
160 
161 #define _COMPONENT          ACPI_EXECUTER
162         ACPI_MODULE_NAME    ("exoparg1")
163 
164 
165 /*!
166  * Naming convention for AML interpreter execution routines.
167  *
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:
171  *
172  *      AcpiExOpcode_xA_yT_zR
173  *
174  * Where:
175  *
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).
182  *
183  * The AcpiExOpcode* functions are called via the Dispatcher component with
184  * fully resolved operands.
185 !*/
186 
187 /*******************************************************************************
188  *
189  * FUNCTION:    AcpiExOpcode_0A_0T_1R
190  *
191  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
192  *
193  * RETURN:      Status
194  *
195  * DESCRIPTION: Execute operator with no operands, one return value
196  *
197  ******************************************************************************/
198 
199 ACPI_STATUS
AcpiExOpcode_0A_0T_1R(ACPI_WALK_STATE * WalkState)200 AcpiExOpcode_0A_0T_1R (
201     ACPI_WALK_STATE         *WalkState)
202 {
203     ACPI_STATUS             Status = AE_OK;
204     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
205 
206 
207     ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
208         AcpiPsGetOpcodeName (WalkState->Opcode));
209 
210 
211     /* Examine the AML opcode */
212 
213     switch (WalkState->Opcode)
214     {
215     case AML_TIMER_OP:      /*  Timer () */
216 
217         /* Create a return object of type Integer */
218 
219         ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
220         if (!ReturnDesc)
221         {
222             Status = AE_NO_MEMORY;
223             goto Cleanup;
224         }
225         break;
226 
227     default:                /*  Unknown opcode  */
228 
229         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
230             WalkState->Opcode));
231         Status = AE_AML_BAD_OPCODE;
232         break;
233     }
234 
235 Cleanup:
236 
237     /* Delete return object on error */
238 
239     if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
240     {
241         AcpiUtRemoveReference (ReturnDesc);
242         WalkState->ResultObj = NULL;
243     }
244     else
245     {
246         /* Save the return value */
247 
248         WalkState->ResultObj = ReturnDesc;
249     }
250 
251     return_ACPI_STATUS (Status);
252 }
253 
254 
255 /*******************************************************************************
256  *
257  * FUNCTION:    AcpiExOpcode_1A_0T_0R
258  *
259  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
260  *
261  * RETURN:      Status
262  *
263  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
264  *              object stack
265  *
266  ******************************************************************************/
267 
268 ACPI_STATUS
AcpiExOpcode_1A_0T_0R(ACPI_WALK_STATE * WalkState)269 AcpiExOpcode_1A_0T_0R (
270     ACPI_WALK_STATE         *WalkState)
271 {
272     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
273     ACPI_STATUS             Status = AE_OK;
274 
275 
276     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
277         AcpiPsGetOpcodeName (WalkState->Opcode));
278 
279 
280     /* Examine the AML opcode */
281 
282     switch (WalkState->Opcode)
283     {
284     case AML_RELEASE_OP:    /*  Release (MutexObject) */
285 
286         Status = AcpiExReleaseMutex (Operand[0], WalkState);
287         break;
288 
289     case AML_RESET_OP:      /*  Reset (EventObject) */
290 
291         Status = AcpiExSystemResetEvent (Operand[0]);
292         break;
293 
294     case AML_SIGNAL_OP:     /*  Signal (EventObject) */
295 
296         Status = AcpiExSystemSignalEvent (Operand[0]);
297         break;
298 
299     case AML_SLEEP_OP:      /*  Sleep (MsecTime) */
300 
301         Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
302         break;
303 
304     case AML_STALL_OP:      /*  Stall (UsecTime) */
305 
306         Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
307         break;
308 
309     case AML_UNLOAD_OP:     /*  Unload (Handle) */
310 
311         Status = AcpiExUnloadTable (Operand[0]);
312         break;
313 
314     default:                /*  Unknown opcode  */
315 
316         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
317             WalkState->Opcode));
318         Status = AE_AML_BAD_OPCODE;
319         break;
320     }
321 
322     return_ACPI_STATUS (Status);
323 }
324 
325 
326 /*******************************************************************************
327  *
328  * FUNCTION:    AcpiExOpcode_1A_1T_0R
329  *
330  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
331  *
332  * RETURN:      Status
333  *
334  * DESCRIPTION: Execute opcode with one argument, one target, and no
335  *              return value.
336  *
337  ******************************************************************************/
338 
339 ACPI_STATUS
AcpiExOpcode_1A_1T_0R(ACPI_WALK_STATE * WalkState)340 AcpiExOpcode_1A_1T_0R (
341     ACPI_WALK_STATE         *WalkState)
342 {
343     ACPI_STATUS             Status = AE_OK;
344     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
345 
346 
347     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
348         AcpiPsGetOpcodeName (WalkState->Opcode));
349 
350 
351     /* Examine the AML opcode */
352 
353     switch (WalkState->Opcode)
354     {
355     case AML_LOAD_OP:
356 
357         Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
358         break;
359 
360     default:                        /* Unknown opcode */
361 
362         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
363             WalkState->Opcode));
364         Status = AE_AML_BAD_OPCODE;
365         goto Cleanup;
366     }
367 
368 
369 Cleanup:
370 
371     return_ACPI_STATUS (Status);
372 }
373 
374 
375 /*******************************************************************************
376  *
377  * FUNCTION:    AcpiExOpcode_1A_1T_1R
378  *
379  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
380  *
381  * RETURN:      Status
382  *
383  * DESCRIPTION: Execute opcode with one argument, one target, and a
384  *              return value.
385  *
386  ******************************************************************************/
387 
388 ACPI_STATUS
AcpiExOpcode_1A_1T_1R(ACPI_WALK_STATE * WalkState)389 AcpiExOpcode_1A_1T_1R (
390     ACPI_WALK_STATE         *WalkState)
391 {
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;
396     UINT32                  Temp32;
397     UINT32                  i;
398     UINT64                  PowerOfTen;
399     UINT64                  Digit;
400 
401 
402     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
403         AcpiPsGetOpcodeName (WalkState->Opcode));
404 
405 
406     /* Examine the AML opcode */
407 
408     switch (WalkState->Opcode)
409     {
410     case AML_BIT_NOT_OP:
411     case AML_FIND_SET_LEFT_BIT_OP:
412     case AML_FIND_SET_RIGHT_BIT_OP:
413     case AML_FROM_BCD_OP:
414     case AML_TO_BCD_OP:
415     case AML_CONDITIONAL_REF_OF_OP:
416 
417         /* Create a return object of type Integer for these opcodes */
418 
419         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
420         if (!ReturnDesc)
421         {
422             Status = AE_NO_MEMORY;
423             goto Cleanup;
424         }
425 
426         switch (WalkState->Opcode)
427         {
428         case AML_BIT_NOT_OP:            /* Not (Operand, Result)  */
429 
430             ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
431             break;
432 
433         case AML_FIND_SET_LEFT_BIT_OP:  /* FindSetLeftBit (Operand, Result) */
434 
435             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
436 
437             /*
438              * Acpi specification describes Integer type as a little
439              * endian unsigned value, so this boundary condition is valid.
440              */
441             for (Temp32 = 0; ReturnDesc->Integer.Value &&
442                     Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
443             {
444                 ReturnDesc->Integer.Value >>= 1;
445             }
446 
447             ReturnDesc->Integer.Value = Temp32;
448             break;
449 
450         case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
451 
452             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
453 
454             /*
455              * The Acpi specification describes Integer type as a little
456              * endian unsigned value, so this boundary condition is valid.
457              */
458             for (Temp32 = 0; ReturnDesc->Integer.Value &&
459                      Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
460             {
461                 ReturnDesc->Integer.Value <<= 1;
462             }
463 
464             /* Since the bit position is one-based, subtract from 33 (65) */
465 
466             ReturnDesc->Integer.Value =
467                 Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
468             break;
469 
470         case AML_FROM_BCD_OP:           /* FromBcd (BCDValue, Result)  */
471             /*
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
475              */
476             PowerOfTen = 1;
477             ReturnDesc->Integer.Value = 0;
478             Digit = Operand[0]->Integer.Value;
479 
480             /* Convert each BCD digit (each is one nybble wide) */
481 
482             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
483             {
484                 /* Get the least significant 4-bit BCD digit */
485 
486                 Temp32 = ((UINT32) Digit) & 0xF;
487 
488                 /* Check the range of the digit */
489 
490                 if (Temp32 > 9)
491                 {
492                     ACPI_ERROR ((AE_INFO,
493                         "BCD digit too large (not decimal): 0x%X",
494                         Temp32));
495 
496                     Status = AE_AML_NUMERIC_OVERFLOW;
497                     goto Cleanup;
498                 }
499 
500                 /* Sum the digit into the result with the current power of 10 */
501 
502                 ReturnDesc->Integer.Value +=
503                     (((UINT64) Temp32) * PowerOfTen);
504 
505                 /* Shift to next BCD digit */
506 
507                 Digit >>= 4;
508 
509                 /* Next power of 10 */
510 
511                 PowerOfTen *= 10;
512             }
513             break;
514 
515         case AML_TO_BCD_OP:             /* ToBcd (Operand, Result)  */
516 
517             ReturnDesc->Integer.Value = 0;
518             Digit = Operand[0]->Integer.Value;
519 
520             /* Each BCD digit is one nybble wide */
521 
522             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
523             {
524                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
525 
526                 /*
527                  * Insert the BCD digit that resides in the
528                  * remainder from above
529                  */
530                 ReturnDesc->Integer.Value |=
531                     (((UINT64) Temp32) << ACPI_MUL_4 (i));
532             }
533 
534             /* Overflow if there is any data left in Digit */
535 
536             if (Digit > 0)
537             {
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;
542                 goto Cleanup;
543             }
544             break;
545 
546         case AML_CONDITIONAL_REF_OF_OP:     /* CondRefOf (SourceObject, Result)  */
547             /*
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)
551              */
552             if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
553             {
554                 /*
555                  * This means that the object does not exist in the namespace,
556                  * return FALSE
557                  */
558                 ReturnDesc->Integer.Value = 0;
559                 goto Cleanup;
560             }
561 
562             /* Get the object reference, store it, and remove our reference */
563 
564             Status = AcpiExGetObjectReference (Operand[0],
565                 &ReturnDesc2, WalkState);
566             if (ACPI_FAILURE (Status))
567             {
568                 goto Cleanup;
569             }
570 
571             Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
572             AcpiUtRemoveReference (ReturnDesc2);
573 
574             /* The object exists in the namespace, return TRUE */
575 
576             ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
577             goto Cleanup;
578 
579 
580         default:
581 
582             /* No other opcodes get here */
583 
584             break;
585         }
586         break;
587 
588     case AML_STORE_OP:              /* Store (Source, Target) */
589         /*
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.
593          */
594         Status = AcpiExStore (Operand[0], Operand[1], WalkState);
595         if (ACPI_FAILURE (Status))
596         {
597             return_ACPI_STATUS (Status);
598         }
599 
600         /* It is possible that the Store already produced a return object */
601 
602         if (!WalkState->ResultObj)
603         {
604             /*
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.
609              */
610             WalkState->ResultObj = Operand[0];
611             WalkState->Operands[0] = NULL;  /* Prevent deletion */
612         }
613         return_ACPI_STATUS (Status);
614 
615     /*
616      * ACPI 2.0 Opcodes
617      */
618     case AML_COPY_OBJECT_OP:        /* CopyObject (Source, Target) */
619 
620         Status = AcpiUtCopyIobjectToIobject (
621             Operand[0], &ReturnDesc, WalkState);
622         break;
623 
624     case AML_TO_DECIMAL_STRING_OP:  /* ToDecimalString (Data, Result) */
625 
626         Status = AcpiExConvertToString (
627             Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
628         if (ReturnDesc == Operand[0])
629         {
630             /* No conversion performed, add ref to handle return value */
631 
632             AcpiUtAddReference (ReturnDesc);
633         }
634         break;
635 
636     case AML_TO_HEX_STRING_OP:      /* ToHexString (Data, Result) */
637 
638         Status = AcpiExConvertToString (
639             Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
640         if (ReturnDesc == Operand[0])
641         {
642             /* No conversion performed, add ref to handle return value */
643 
644             AcpiUtAddReference (ReturnDesc);
645         }
646         break;
647 
648     case AML_TO_BUFFER_OP:          /* ToBuffer (Data, Result) */
649 
650         Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
651         if (ReturnDesc == Operand[0])
652         {
653             /* No conversion performed, add ref to handle return value */
654 
655             AcpiUtAddReference (ReturnDesc);
656         }
657         break;
658 
659     case AML_TO_INTEGER_OP:         /* ToInteger (Data, Result) */
660 
661         /* Perform "explicit" conversion */
662 
663         Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc, 0);
664         if (ReturnDesc == Operand[0])
665         {
666             /* No conversion performed, add ref to handle return value */
667 
668             AcpiUtAddReference (ReturnDesc);
669         }
670         break;
671 
672     case AML_SHIFT_LEFT_BIT_OP:     /* ShiftLeftBit (Source, BitNum)  */
673     case AML_SHIFT_RIGHT_BIT_OP:    /* ShiftRightBit (Source, BitNum) */
674 
675         /* These are two obsolete opcodes */
676 
677         ACPI_ERROR ((AE_INFO,
678             "%s is obsolete and not implemented",
679             AcpiPsGetOpcodeName (WalkState->Opcode)));
680         Status = AE_SUPPORT;
681         goto Cleanup;
682 
683     default:                        /* Unknown opcode */
684 
685         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
686             WalkState->Opcode));
687         Status = AE_AML_BAD_OPCODE;
688         goto Cleanup;
689     }
690 
691     if (ACPI_SUCCESS (Status))
692     {
693         /* Store the return value computed above into the target object */
694 
695         Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
696     }
697 
698 
699 Cleanup:
700 
701     /* Delete return object on error */
702 
703     if (ACPI_FAILURE (Status))
704     {
705         AcpiUtRemoveReference (ReturnDesc);
706     }
707 
708     /* Save return object on success */
709 
710     else if (!WalkState->ResultObj)
711     {
712         WalkState->ResultObj = ReturnDesc;
713     }
714 
715     return_ACPI_STATUS (Status);
716 }
717 
718 
719 /*******************************************************************************
720  *
721  * FUNCTION:    AcpiExOpcode_1A_0T_1R
722  *
723  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
724  *
725  * RETURN:      Status
726  *
727  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
728  *
729  ******************************************************************************/
730 
731 ACPI_STATUS
AcpiExOpcode_1A_0T_1R(ACPI_WALK_STATE * WalkState)732 AcpiExOpcode_1A_0T_1R (
733     ACPI_WALK_STATE         *WalkState)
734 {
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;
739     UINT32                  Type;
740     UINT64                  Value;
741 
742 
743     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
744         AcpiPsGetOpcodeName (WalkState->Opcode));
745 
746 
747     /* Examine the AML opcode */
748 
749     switch (WalkState->Opcode)
750     {
751     case AML_LOGICAL_NOT_OP:        /* LNot (Operand) */
752 
753         ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
754         if (!ReturnDesc)
755         {
756             Status = AE_NO_MEMORY;
757             goto Cleanup;
758         }
759 
760         /*
761          * Set result to ONES (TRUE) if Value == 0. Note:
762          * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
763          */
764         if (!Operand[0]->Integer.Value)
765         {
766             ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
767         }
768         break;
769 
770     case AML_DECREMENT_OP:          /* Decrement (Operand)  */
771     case AML_INCREMENT_OP:          /* Increment (Operand)  */
772         /*
773          * Create a new integer. Can't just get the base integer and
774          * increment it because it may be an Arg or Field.
775          */
776         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
777         if (!ReturnDesc)
778         {
779             Status = AE_NO_MEMORY;
780             goto Cleanup;
781         }
782 
783         /*
784          * Since we are expecting a Reference operand, it can be either a
785          * NS Node or an internal object.
786          */
787         TempDesc = Operand[0];
788         if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
789         {
790             /* Internal reference object - prevent deletion */
791 
792             AcpiUtAddReference (TempDesc);
793         }
794 
795         /*
796          * Convert the Reference operand to an Integer (This removes a
797          * reference on the Operand[0] object)
798          *
799          * NOTE:  We use LNOT_OP here in order to force resolution of the
800          * reference operand to an actual integer.
801          */
802         Status = AcpiExResolveOperands (AML_LOGICAL_NOT_OP,
803             &TempDesc, WalkState);
804         if (ACPI_FAILURE (Status))
805         {
806             ACPI_EXCEPTION ((AE_INFO, Status,
807                 "While resolving operands for [%s]",
808                 AcpiPsGetOpcodeName (WalkState->Opcode)));
809 
810             goto Cleanup;
811         }
812 
813         /*
814          * TempDesc is now guaranteed to be an Integer object --
815          * Perform the actual increment or decrement
816          */
817         if (WalkState->Opcode == AML_INCREMENT_OP)
818         {
819             ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
820         }
821         else
822         {
823             ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
824         }
825 
826         /* Finished with this Integer object */
827 
828         AcpiUtRemoveReference (TempDesc);
829 
830         /*
831          * Store the result back (indirectly) through the original
832          * Reference object
833          */
834         Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
835         break;
836 
837     case AML_OBJECT_TYPE_OP:            /* ObjectType (SourceObject) */
838         /*
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
842          * FieldUnit object.
843          */
844 
845         /* Get the type of the base object */
846 
847         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
848         if (ACPI_FAILURE (Status))
849         {
850             goto Cleanup;
851         }
852 
853         /* Allocate a descriptor to hold the type. */
854 
855         ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
856         if (!ReturnDesc)
857         {
858             Status = AE_NO_MEMORY;
859             goto Cleanup;
860         }
861         break;
862 
863     case AML_SIZE_OF_OP:            /* SizeOf (SourceObject)  */
864         /*
865          * Note: The operand is not resolved at this point because we want to
866          * get the associated object, not its value.
867          */
868 
869         /* Get the base object */
870 
871         Status = AcpiExResolveMultiple (
872             WalkState, Operand[0], &Type, &TempDesc);
873         if (ACPI_FAILURE (Status))
874         {
875             goto Cleanup;
876         }
877 
878         /*
879          * The type of the base object must be integer, buffer, string, or
880          * package. All others are not supported.
881          *
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).
886          */
887         switch (Type)
888         {
889         case ACPI_TYPE_INTEGER:
890 
891             Value = AcpiGbl_IntegerByteWidth;
892             break;
893 
894         case ACPI_TYPE_STRING:
895 
896             Value = TempDesc->String.Length;
897             break;
898 
899         case ACPI_TYPE_BUFFER:
900 
901             /* Buffer arguments may not be evaluated at this point */
902 
903             Status = AcpiDsGetBufferArguments (TempDesc);
904             Value = TempDesc->Buffer.Length;
905             break;
906 
907         case ACPI_TYPE_PACKAGE:
908 
909             /* Package arguments may not be evaluated at this point */
910 
911             Status = AcpiDsGetPackageArguments (TempDesc);
912             Value = TempDesc->Package.Count;
913             break;
914 
915         default:
916 
917             ACPI_ERROR ((AE_INFO,
918                 "Operand must be Buffer/Integer/String/Package"
919                 " - found type %s",
920                 AcpiUtGetTypeName (Type)));
921 
922             Status = AE_AML_OPERAND_TYPE;
923             goto Cleanup;
924         }
925 
926         if (ACPI_FAILURE (Status))
927         {
928             goto Cleanup;
929         }
930 
931         /*
932          * Now that we have the size of the object, create a result
933          * object to hold the value
934          */
935         ReturnDesc = AcpiUtCreateIntegerObject (Value);
936         if (!ReturnDesc)
937         {
938             Status = AE_NO_MEMORY;
939             goto Cleanup;
940         }
941         break;
942 
943 
944     case AML_REF_OF_OP:             /* RefOf (SourceObject) */
945 
946         Status = AcpiExGetObjectReference (
947             Operand[0], &ReturnDesc, WalkState);
948         if (ACPI_FAILURE (Status))
949         {
950             goto Cleanup;
951         }
952         break;
953 
954 
955     case AML_DEREF_OF_OP:           /* DerefOf (ObjReference | String) */
956 
957         /* Check for a method local or argument, or standalone String */
958 
959         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
960         {
961             TempDesc = AcpiNsGetAttachedObject (
962                 (ACPI_NAMESPACE_NODE *) Operand[0]);
963             if (TempDesc &&
964                  ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
965                   (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
966             {
967                 Operand[0] = TempDesc;
968                 AcpiUtAddReference (TempDesc);
969             }
970             else
971             {
972                 Status = AE_AML_OPERAND_TYPE;
973                 goto Cleanup;
974             }
975         }
976         else
977         {
978             switch ((Operand[0])->Common.Type)
979             {
980             case ACPI_TYPE_LOCAL_REFERENCE:
981                 /*
982                  * This is a DerefOf (LocalX | ArgX)
983                  *
984                  * Must resolve/dereference the local/arg reference first
985                  */
986                 switch (Operand[0]->Reference.Class)
987                 {
988                 case ACPI_REFCLASS_LOCAL:
989                 case ACPI_REFCLASS_ARG:
990 
991                     /* Set Operand[0] to the value of the local/arg */
992 
993                     Status = AcpiDsMethodDataGetValue (
994                         Operand[0]->Reference.Class,
995                         Operand[0]->Reference.Value,
996                         WalkState, &TempDesc);
997                     if (ACPI_FAILURE (Status))
998                     {
999                         goto Cleanup;
1000                     }
1001 
1002                     /*
1003                      * Delete our reference to the input object and
1004                      * point to the object just retrieved
1005                      */
1006                     AcpiUtRemoveReference (Operand[0]);
1007                     Operand[0] = TempDesc;
1008                     break;
1009 
1010                 case ACPI_REFCLASS_REFOF:
1011 
1012                     /* Get the object to which the reference refers */
1013 
1014                     TempDesc = Operand[0]->Reference.Object;
1015                     AcpiUtRemoveReference (Operand[0]);
1016                     Operand[0] = TempDesc;
1017                     break;
1018 
1019                 default:
1020 
1021                     /* Must be an Index op - handled below */
1022                     break;
1023                 }
1024                 break;
1025 
1026             case ACPI_TYPE_STRING:
1027 
1028                 break;
1029 
1030             default:
1031 
1032                 Status = AE_AML_OPERAND_TYPE;
1033                 goto Cleanup;
1034             }
1035         }
1036 
1037         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
1038         {
1039             if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
1040             {
1041                 /*
1042                  * This is a DerefOf (String). The string is a reference
1043                  * to a named ACPI object.
1044                  *
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.
1048                  */
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))
1055                 {
1056                     goto Cleanup;
1057                 }
1058 
1059                 Status = AcpiExResolveNodeToValue (
1060                     ACPI_CAST_INDIRECT_PTR (
1061                         ACPI_NAMESPACE_NODE, &ReturnDesc),
1062                     WalkState);
1063                 goto Cleanup;
1064             }
1065         }
1066 
1067         /* Operand[0] may have changed from the code above */
1068 
1069         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1070         {
1071             /*
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
1076              * thermal objects.
1077              */
1078             switch (((ACPI_NAMESPACE_NODE *) Operand[0])->Type)
1079             {
1080             case ACPI_TYPE_DEVICE:
1081             case ACPI_TYPE_THERMAL:
1082 
1083                 /* These types have no node subobject, return the NS node */
1084 
1085                 ReturnDesc = Operand[0];
1086                 break;
1087 
1088             default:
1089                 /* For most types, get the object attached to the node */
1090 
1091                 ReturnDesc = AcpiNsGetAttachedObject (
1092                     (ACPI_NAMESPACE_NODE *) Operand[0]);
1093                 AcpiUtAddReference (ReturnDesc);
1094                 break;
1095             }
1096         }
1097         else
1098         {
1099             /*
1100              * This must be a reference object produced by either the
1101              * Index() or RefOf() operator
1102              */
1103             switch (Operand[0]->Reference.Class)
1104             {
1105             case ACPI_REFCLASS_INDEX:
1106                 /*
1107                  * The target type for the Index operator must be
1108                  * either a Buffer or a Package
1109                  */
1110                 switch (Operand[0]->Reference.TargetType)
1111                 {
1112                 case ACPI_TYPE_BUFFER_FIELD:
1113 
1114                     TempDesc = Operand[0]->Reference.Object;
1115 
1116                     /*
1117                      * Create a new object that contains one element of the
1118                      * buffer -- the element pointed to by the index.
1119                      *
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!
1123                      *
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.
1127                      */
1128                     ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
1129                         TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
1130                     if (!ReturnDesc)
1131                     {
1132                         Status = AE_NO_MEMORY;
1133                         goto Cleanup;
1134                     }
1135                     break;
1136 
1137                 case ACPI_TYPE_PACKAGE:
1138                     /*
1139                      * Return the referenced element of the package. We must
1140                      * add another reference to the referenced object, however.
1141                      */
1142                     ReturnDesc = *(Operand[0]->Reference.Where);
1143                     if (!ReturnDesc)
1144                     {
1145                         /*
1146                          * Element is NULL, do not allow the dereference.
1147                          * This provides compatibility with other ACPI
1148                          * implementations.
1149                          */
1150                         return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1151                     }
1152 
1153                     AcpiUtAddReference (ReturnDesc);
1154                     break;
1155 
1156                 default:
1157 
1158                     ACPI_ERROR ((AE_INFO,
1159                         "Unknown Index TargetType 0x%X in reference object %p",
1160                         Operand[0]->Reference.TargetType, Operand[0]));
1161 
1162                     Status = AE_AML_OPERAND_TYPE;
1163                     goto Cleanup;
1164                 }
1165                 break;
1166 
1167             case ACPI_REFCLASS_REFOF:
1168 
1169                 ReturnDesc = Operand[0]->Reference.Object;
1170 
1171                 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1172                     ACPI_DESC_TYPE_NAMED)
1173                 {
1174                     ReturnDesc = AcpiNsGetAttachedObject (
1175                         (ACPI_NAMESPACE_NODE *) ReturnDesc);
1176                     if (!ReturnDesc)
1177                     {
1178                         break;
1179                     }
1180 
1181                    /*
1182                     * June 2013:
1183                     * BufferFields/FieldUnits require additional resolution
1184                     */
1185                     switch (ReturnDesc->Common.Type)
1186                     {
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:
1191 
1192                         Status = AcpiExReadDataFromField (
1193                             WalkState, ReturnDesc, &TempDesc);
1194                         if (ACPI_FAILURE (Status))
1195                         {
1196                             goto Cleanup;
1197                         }
1198 
1199                         ReturnDesc = TempDesc;
1200                         break;
1201 
1202                     default:
1203 
1204                         /* Add another reference to the object */
1205 
1206                         AcpiUtAddReference (ReturnDesc);
1207                         break;
1208                     }
1209                 }
1210                 break;
1211 
1212             default:
1213 
1214                 ACPI_ERROR ((AE_INFO,
1215                     "Unknown class in reference(%p) - 0x%2.2X",
1216                     Operand[0], Operand[0]->Reference.Class));
1217 
1218                 Status = AE_TYPE;
1219                 goto Cleanup;
1220             }
1221         }
1222         break;
1223 
1224     default:
1225 
1226         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1227             WalkState->Opcode));
1228 
1229         Status = AE_AML_BAD_OPCODE;
1230         goto Cleanup;
1231     }
1232 
1233 
1234 Cleanup:
1235 
1236     /* Delete return object on error */
1237 
1238     if (ACPI_FAILURE (Status))
1239     {
1240         AcpiUtRemoveReference (ReturnDesc);
1241     }
1242 
1243     /* Save return object on success */
1244 
1245     else
1246     {
1247         WalkState->ResultObj = ReturnDesc;
1248     }
1249 
1250     return_ACPI_STATUS (Status);
1251 }
1252