xref: /freebsd/sys/contrib/dev/acpica/components/executer/exoparg1.c (revision 722b16673c40aedf280895f2f2f676bb494518d7)
1a159c266SJung-uk Kim /******************************************************************************
2a159c266SJung-uk Kim  *
3a159c266SJung-uk Kim  * Module Name: exoparg1 - AML execution - opcodes with 1 argument
4a159c266SJung-uk Kim  *
5a159c266SJung-uk Kim  *****************************************************************************/
6a159c266SJung-uk Kim 
70d84335fSJung-uk Kim /******************************************************************************
80d84335fSJung-uk Kim  *
90d84335fSJung-uk Kim  * 1. Copyright Notice
100d84335fSJung-uk Kim  *
11*722b1667SJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2023, Intel Corp.
12a159c266SJung-uk Kim  * All rights reserved.
13a159c266SJung-uk Kim  *
140d84335fSJung-uk Kim  * 2. License
150d84335fSJung-uk Kim  *
160d84335fSJung-uk Kim  * 2.1. This is your license from Intel Corp. under its intellectual property
170d84335fSJung-uk Kim  * rights. You may have additional license terms from the party that provided
180d84335fSJung-uk Kim  * you this software, covering your right to use that party's intellectual
190d84335fSJung-uk Kim  * property rights.
200d84335fSJung-uk Kim  *
210d84335fSJung-uk Kim  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220d84335fSJung-uk Kim  * copy of the source code appearing in this file ("Covered Code") an
230d84335fSJung-uk Kim  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240d84335fSJung-uk Kim  * base code distributed originally by Intel ("Original Intel Code") to copy,
250d84335fSJung-uk Kim  * make derivatives, distribute, use and display any portion of the Covered
260d84335fSJung-uk Kim  * Code in any form, with the right to sublicense such rights; and
270d84335fSJung-uk Kim  *
280d84335fSJung-uk Kim  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290d84335fSJung-uk Kim  * license (with the right to sublicense), under only those claims of Intel
300d84335fSJung-uk Kim  * patents that are infringed by the Original Intel Code, to make, use, sell,
310d84335fSJung-uk Kim  * offer to sell, and import the Covered Code and derivative works thereof
320d84335fSJung-uk Kim  * solely to the minimum extent necessary to exercise the above copyright
330d84335fSJung-uk Kim  * license, and in no event shall the patent license extend to any additions
340d84335fSJung-uk Kim  * to or modifications of the Original Intel Code. No other license or right
350d84335fSJung-uk Kim  * is granted directly or by implication, estoppel or otherwise;
360d84335fSJung-uk Kim  *
370d84335fSJung-uk Kim  * The above copyright and patent license is granted only if the following
380d84335fSJung-uk Kim  * conditions are met:
390d84335fSJung-uk Kim  *
400d84335fSJung-uk Kim  * 3. Conditions
410d84335fSJung-uk Kim  *
420d84335fSJung-uk Kim  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
440d84335fSJung-uk Kim  * Code or modification with rights to further distribute source must include
450d84335fSJung-uk Kim  * the above Copyright Notice, the above License, this list of Conditions,
460d84335fSJung-uk Kim  * and the following Disclaimer and Export Compliance provision. In addition,
470d84335fSJung-uk Kim  * Licensee must cause all Covered Code to which Licensee contributes to
480d84335fSJung-uk Kim  * contain a file documenting the changes Licensee made to create that Covered
490d84335fSJung-uk Kim  * Code and the date of any change. Licensee must include in that file the
500d84335fSJung-uk Kim  * documentation of any changes made by any predecessor Licensee. Licensee
510d84335fSJung-uk Kim  * must include a prominent statement that the modification is derived,
520d84335fSJung-uk Kim  * directly or indirectly, from Original Intel Code.
530d84335fSJung-uk Kim  *
540d84335fSJung-uk Kim  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550d84335fSJung-uk Kim  * Redistribution of source code of any substantial portion of the Covered
560d84335fSJung-uk Kim  * Code or modification without rights to further distribute source must
570d84335fSJung-uk Kim  * include the following Disclaimer and Export Compliance provision in the
580d84335fSJung-uk Kim  * documentation and/or other materials provided with distribution. In
590d84335fSJung-uk Kim  * addition, Licensee may not authorize further sublicense of source of any
600d84335fSJung-uk Kim  * portion of the Covered Code, and must include terms to the effect that the
610d84335fSJung-uk Kim  * license from Licensee to its licensee is limited to the intellectual
620d84335fSJung-uk Kim  * property embodied in the software Licensee provides to its licensee, and
630d84335fSJung-uk Kim  * not to intellectual property embodied in modifications its licensee may
640d84335fSJung-uk Kim  * make.
650d84335fSJung-uk Kim  *
660d84335fSJung-uk Kim  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670d84335fSJung-uk Kim  * substantial portion of the Covered Code or modification must reproduce the
680d84335fSJung-uk Kim  * above Copyright Notice, and the following Disclaimer and Export Compliance
690d84335fSJung-uk Kim  * provision in the documentation and/or other materials provided with the
700d84335fSJung-uk Kim  * distribution.
710d84335fSJung-uk Kim  *
720d84335fSJung-uk Kim  * 3.4. Intel retains all right, title, and interest in and to the Original
730d84335fSJung-uk Kim  * Intel Code.
740d84335fSJung-uk Kim  *
750d84335fSJung-uk Kim  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760d84335fSJung-uk Kim  * Intel shall be used in advertising or otherwise to promote the sale, use or
770d84335fSJung-uk Kim  * other dealings in products derived from or relating to the Covered Code
780d84335fSJung-uk Kim  * without prior written authorization from Intel.
790d84335fSJung-uk Kim  *
800d84335fSJung-uk Kim  * 4. Disclaimer and Export Compliance
810d84335fSJung-uk Kim  *
820d84335fSJung-uk Kim  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830d84335fSJung-uk Kim  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840d84335fSJung-uk Kim  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850d84335fSJung-uk Kim  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860d84335fSJung-uk Kim  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870d84335fSJung-uk Kim  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880d84335fSJung-uk Kim  * PARTICULAR PURPOSE.
890d84335fSJung-uk Kim  *
900d84335fSJung-uk Kim  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910d84335fSJung-uk Kim  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920d84335fSJung-uk Kim  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930d84335fSJung-uk Kim  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940d84335fSJung-uk Kim  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950d84335fSJung-uk Kim  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960d84335fSJung-uk Kim  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970d84335fSJung-uk Kim  * LIMITED REMEDY.
980d84335fSJung-uk Kim  *
990d84335fSJung-uk Kim  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000d84335fSJung-uk Kim  * software or system incorporating such software without first obtaining any
1010d84335fSJung-uk Kim  * required license or other approval from the U. S. Department of Commerce or
1020d84335fSJung-uk Kim  * any other agency or department of the United States Government. In the
1030d84335fSJung-uk Kim  * event Licensee exports any such software from the United States or
1040d84335fSJung-uk Kim  * re-exports any such software from a foreign destination, Licensee shall
1050d84335fSJung-uk Kim  * ensure that the distribution and export/re-export of the software is in
1060d84335fSJung-uk Kim  * compliance with all laws, regulations, orders, or other restrictions of the
1070d84335fSJung-uk Kim  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080d84335fSJung-uk Kim  * any of its subsidiaries will export/re-export any technical data, process,
1090d84335fSJung-uk Kim  * software, or service, directly or indirectly, to any country for which the
1100d84335fSJung-uk Kim  * United States government or any agency thereof requires an export license,
1110d84335fSJung-uk Kim  * other governmental approval, or letter of assurance, without first obtaining
1120d84335fSJung-uk Kim  * such license, approval or letter.
1130d84335fSJung-uk Kim  *
1140d84335fSJung-uk Kim  *****************************************************************************
1150d84335fSJung-uk Kim  *
1160d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
1170d84335fSJung-uk Kim  * following license:
1180d84335fSJung-uk Kim  *
119a159c266SJung-uk Kim  * Redistribution and use in source and binary forms, with or without
120a159c266SJung-uk Kim  * modification, are permitted provided that the following conditions
121a159c266SJung-uk Kim  * are met:
122a159c266SJung-uk Kim  * 1. Redistributions of source code must retain the above copyright
123a159c266SJung-uk Kim  *    notice, this list of conditions, and the following disclaimer,
124a159c266SJung-uk Kim  *    without modification.
125a159c266SJung-uk Kim  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126a159c266SJung-uk Kim  *    substantially similar to the "NO WARRANTY" disclaimer below
127a159c266SJung-uk Kim  *    ("Disclaimer") and any redistribution must be conditioned upon
128a159c266SJung-uk Kim  *    including a substantially similar Disclaimer requirement for further
129a159c266SJung-uk Kim  *    binary redistribution.
130a159c266SJung-uk Kim  * 3. Neither the names of the above-listed copyright holders nor the names
131a159c266SJung-uk Kim  *    of any contributors may be used to endorse or promote products derived
132a159c266SJung-uk Kim  *    from this software without specific prior written permission.
133a159c266SJung-uk Kim  *
1340d84335fSJung-uk Kim  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1350d84335fSJung-uk Kim  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1360d84335fSJung-uk Kim  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1370d84335fSJung-uk Kim  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1380d84335fSJung-uk Kim  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
1390d84335fSJung-uk Kim  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
1400d84335fSJung-uk Kim  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
1410d84335fSJung-uk Kim  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
1420d84335fSJung-uk Kim  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
1430d84335fSJung-uk Kim  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
1440d84335fSJung-uk Kim  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1450d84335fSJung-uk Kim  *
1460d84335fSJung-uk Kim  * Alternatively, you may choose to be licensed under the terms of the
147a159c266SJung-uk Kim  * GNU General Public License ("GPL") version 2 as published by the Free
148a159c266SJung-uk Kim  * Software Foundation.
149a159c266SJung-uk Kim  *
1500d84335fSJung-uk Kim  *****************************************************************************/
151a159c266SJung-uk Kim 
152a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acpi.h>
153a159c266SJung-uk Kim #include <contrib/dev/acpica/include/accommon.h>
154a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acparser.h>
155a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acdispat.h>
156a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acinterp.h>
157a159c266SJung-uk Kim #include <contrib/dev/acpica/include/amlcode.h>
158a159c266SJung-uk Kim #include <contrib/dev/acpica/include/acnamesp.h>
159a159c266SJung-uk Kim 
160a159c266SJung-uk Kim 
161a159c266SJung-uk Kim #define _COMPONENT          ACPI_EXECUTER
162a159c266SJung-uk Kim         ACPI_MODULE_NAME    ("exoparg1")
163a159c266SJung-uk Kim 
164a159c266SJung-uk Kim 
165a159c266SJung-uk Kim /*!
166a159c266SJung-uk Kim  * Naming convention for AML interpreter execution routines.
167a159c266SJung-uk Kim  *
168a159c266SJung-uk Kim  * The routines that begin execution of AML opcodes are named with a common
169a159c266SJung-uk Kim  * convention based upon the number of arguments, the number of target operands,
170a159c266SJung-uk Kim  * and whether or not a value is returned:
171a159c266SJung-uk Kim  *
172a159c266SJung-uk Kim  *      AcpiExOpcode_xA_yT_zR
173a159c266SJung-uk Kim  *
174a159c266SJung-uk Kim  * Where:
175a159c266SJung-uk Kim  *
176a159c266SJung-uk Kim  * xA - ARGUMENTS:    The number of arguments (input operands) that are
177a159c266SJung-uk Kim  *                    required for this opcode type (0 through 6 args).
178a159c266SJung-uk Kim  * yT - TARGETS:      The number of targets (output operands) that are required
179a159c266SJung-uk Kim  *                    for this opcode type (0, 1, or 2 targets).
180a159c266SJung-uk Kim  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
181a159c266SJung-uk Kim  *                    as the function return (0 or 1).
182a159c266SJung-uk Kim  *
183a159c266SJung-uk Kim  * The AcpiExOpcode* functions are called via the Dispatcher component with
184a159c266SJung-uk Kim  * fully resolved operands.
185a159c266SJung-uk Kim !*/
186a159c266SJung-uk Kim 
187a159c266SJung-uk Kim /*******************************************************************************
188a159c266SJung-uk Kim  *
189a159c266SJung-uk Kim  * FUNCTION:    AcpiExOpcode_0A_0T_1R
190a159c266SJung-uk Kim  *
191a159c266SJung-uk Kim  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
192a159c266SJung-uk Kim  *
193a159c266SJung-uk Kim  * RETURN:      Status
194a159c266SJung-uk Kim  *
195a159c266SJung-uk Kim  * DESCRIPTION: Execute operator with no operands, one return value
196a159c266SJung-uk Kim  *
197a159c266SJung-uk Kim  ******************************************************************************/
198a159c266SJung-uk Kim 
199a159c266SJung-uk Kim ACPI_STATUS
AcpiExOpcode_0A_0T_1R(ACPI_WALK_STATE * WalkState)200a159c266SJung-uk Kim AcpiExOpcode_0A_0T_1R (
201a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
202a159c266SJung-uk Kim {
203a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
204a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
205a159c266SJung-uk Kim 
206a159c266SJung-uk Kim 
207a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE_STR (ExOpcode_0A_0T_1R,
208a159c266SJung-uk Kim         AcpiPsGetOpcodeName (WalkState->Opcode));
209a159c266SJung-uk Kim 
210a159c266SJung-uk Kim 
211a159c266SJung-uk Kim     /* Examine the AML opcode */
212a159c266SJung-uk Kim 
213a159c266SJung-uk Kim     switch (WalkState->Opcode)
214a159c266SJung-uk Kim     {
215a159c266SJung-uk Kim     case AML_TIMER_OP:      /*  Timer () */
216a159c266SJung-uk Kim 
217a159c266SJung-uk Kim         /* Create a return object of type Integer */
218a159c266SJung-uk Kim 
219a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateIntegerObject (AcpiOsGetTimer ());
220a159c266SJung-uk Kim         if (!ReturnDesc)
221a159c266SJung-uk Kim         {
222a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
223a159c266SJung-uk Kim             goto Cleanup;
224a159c266SJung-uk Kim         }
225a159c266SJung-uk Kim         break;
226a159c266SJung-uk Kim 
227a159c266SJung-uk Kim     default:                /*  Unknown opcode  */
228a159c266SJung-uk Kim 
229a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
230a159c266SJung-uk Kim             WalkState->Opcode));
231a159c266SJung-uk Kim         Status = AE_AML_BAD_OPCODE;
232a159c266SJung-uk Kim         break;
233a159c266SJung-uk Kim     }
234a159c266SJung-uk Kim 
235a159c266SJung-uk Kim Cleanup:
236a159c266SJung-uk Kim 
237a159c266SJung-uk Kim     /* Delete return object on error */
238a159c266SJung-uk Kim 
239a159c266SJung-uk Kim     if ((ACPI_FAILURE (Status)) || WalkState->ResultObj)
240a159c266SJung-uk Kim     {
241a159c266SJung-uk Kim         AcpiUtRemoveReference (ReturnDesc);
242a159c266SJung-uk Kim         WalkState->ResultObj = NULL;
243a159c266SJung-uk Kim     }
244a159c266SJung-uk Kim     else
245a159c266SJung-uk Kim     {
246a159c266SJung-uk Kim         /* Save the return value */
247a159c266SJung-uk Kim 
248a159c266SJung-uk Kim         WalkState->ResultObj = ReturnDesc;
249a159c266SJung-uk Kim     }
250a159c266SJung-uk Kim 
251a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
252a159c266SJung-uk Kim }
253a159c266SJung-uk Kim 
254a159c266SJung-uk Kim 
255a159c266SJung-uk Kim /*******************************************************************************
256a159c266SJung-uk Kim  *
257a159c266SJung-uk Kim  * FUNCTION:    AcpiExOpcode_1A_0T_0R
258a159c266SJung-uk Kim  *
259a159c266SJung-uk Kim  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
260a159c266SJung-uk Kim  *
261a159c266SJung-uk Kim  * RETURN:      Status
262a159c266SJung-uk Kim  *
263a159c266SJung-uk Kim  * DESCRIPTION: Execute Type 1 monadic operator with numeric operand on
264a159c266SJung-uk Kim  *              object stack
265a159c266SJung-uk Kim  *
266a159c266SJung-uk Kim  ******************************************************************************/
267a159c266SJung-uk Kim 
268a159c266SJung-uk Kim ACPI_STATUS
AcpiExOpcode_1A_0T_0R(ACPI_WALK_STATE * WalkState)269a159c266SJung-uk Kim AcpiExOpcode_1A_0T_0R (
270a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
271a159c266SJung-uk Kim {
272a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
273a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
274a159c266SJung-uk Kim 
275a159c266SJung-uk Kim 
276a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_0R,
277a159c266SJung-uk Kim         AcpiPsGetOpcodeName (WalkState->Opcode));
278a159c266SJung-uk Kim 
279a159c266SJung-uk Kim 
280a159c266SJung-uk Kim     /* Examine the AML opcode */
281a159c266SJung-uk Kim 
282a159c266SJung-uk Kim     switch (WalkState->Opcode)
283a159c266SJung-uk Kim     {
284a159c266SJung-uk Kim     case AML_RELEASE_OP:    /*  Release (MutexObject) */
285a159c266SJung-uk Kim 
286a159c266SJung-uk Kim         Status = AcpiExReleaseMutex (Operand[0], WalkState);
287a159c266SJung-uk Kim         break;
288a159c266SJung-uk Kim 
289a159c266SJung-uk Kim     case AML_RESET_OP:      /*  Reset (EventObject) */
290a159c266SJung-uk Kim 
291a159c266SJung-uk Kim         Status = AcpiExSystemResetEvent (Operand[0]);
292a159c266SJung-uk Kim         break;
293a159c266SJung-uk Kim 
294a159c266SJung-uk Kim     case AML_SIGNAL_OP:     /*  Signal (EventObject) */
295a159c266SJung-uk Kim 
296a159c266SJung-uk Kim         Status = AcpiExSystemSignalEvent (Operand[0]);
297a159c266SJung-uk Kim         break;
298a159c266SJung-uk Kim 
299a159c266SJung-uk Kim     case AML_SLEEP_OP:      /*  Sleep (MsecTime) */
300a159c266SJung-uk Kim 
301a159c266SJung-uk Kim         Status = AcpiExSystemDoSleep (Operand[0]->Integer.Value);
302a159c266SJung-uk Kim         break;
303a159c266SJung-uk Kim 
304a159c266SJung-uk Kim     case AML_STALL_OP:      /*  Stall (UsecTime) */
305a159c266SJung-uk Kim 
306a159c266SJung-uk Kim         Status = AcpiExSystemDoStall ((UINT32) Operand[0]->Integer.Value);
307a159c266SJung-uk Kim         break;
308a159c266SJung-uk Kim 
309a159c266SJung-uk Kim     case AML_UNLOAD_OP:     /*  Unload (Handle) */
310a159c266SJung-uk Kim 
311a159c266SJung-uk Kim         Status = AcpiExUnloadTable (Operand[0]);
312a159c266SJung-uk Kim         break;
313a159c266SJung-uk Kim 
314a159c266SJung-uk Kim     default:                /*  Unknown opcode  */
315a159c266SJung-uk Kim 
316a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
317a159c266SJung-uk Kim             WalkState->Opcode));
318a159c266SJung-uk Kim         Status = AE_AML_BAD_OPCODE;
319a159c266SJung-uk Kim         break;
320a159c266SJung-uk Kim     }
321a159c266SJung-uk Kim 
322a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
323a159c266SJung-uk Kim }
324a159c266SJung-uk Kim 
325a159c266SJung-uk Kim 
326ab71bbb7SJung-uk Kim #ifdef _OBSOLETE_CODE /* Was originally used for Load() operator */
327a159c266SJung-uk Kim /*******************************************************************************
328a159c266SJung-uk Kim  *
329a159c266SJung-uk Kim  * FUNCTION:    AcpiExOpcode_1A_1T_0R
330a159c266SJung-uk Kim  *
331a159c266SJung-uk Kim  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
332a159c266SJung-uk Kim  *
333a159c266SJung-uk Kim  * RETURN:      Status
334a159c266SJung-uk Kim  *
335a159c266SJung-uk Kim  * DESCRIPTION: Execute opcode with one argument, one target, and no
336a159c266SJung-uk Kim  *              return value.
337a159c266SJung-uk Kim  *
338a159c266SJung-uk Kim  ******************************************************************************/
339a159c266SJung-uk Kim 
340a159c266SJung-uk Kim ACPI_STATUS
AcpiExOpcode_1A_1T_0R(ACPI_WALK_STATE * WalkState)341a159c266SJung-uk Kim AcpiExOpcode_1A_1T_0R (
342a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
343a159c266SJung-uk Kim {
344a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
345a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
346a159c266SJung-uk Kim 
347a159c266SJung-uk Kim 
348a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_0R,
349a159c266SJung-uk Kim         AcpiPsGetOpcodeName (WalkState->Opcode));
350a159c266SJung-uk Kim 
351a159c266SJung-uk Kim 
352a159c266SJung-uk Kim     /* Examine the AML opcode */
353a159c266SJung-uk Kim 
354a159c266SJung-uk Kim     switch (WalkState->Opcode)
355a159c266SJung-uk Kim     {
356ab71bbb7SJung-uk Kim #ifdef _OBSOLETE_CODE
357a159c266SJung-uk Kim     case AML_LOAD_OP:
358a159c266SJung-uk Kim 
359a159c266SJung-uk Kim         Status = AcpiExLoadOp (Operand[0], Operand[1], WalkState);
360a159c266SJung-uk Kim         break;
361ab71bbb7SJung-uk Kim #endif
362a159c266SJung-uk Kim 
363a159c266SJung-uk Kim     default:                        /* Unknown opcode */
364a159c266SJung-uk Kim 
365a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
366a159c266SJung-uk Kim             WalkState->Opcode));
367a159c266SJung-uk Kim         Status = AE_AML_BAD_OPCODE;
368a159c266SJung-uk Kim         goto Cleanup;
369a159c266SJung-uk Kim     }
370a159c266SJung-uk Kim 
371a159c266SJung-uk Kim 
372a159c266SJung-uk Kim Cleanup:
373a159c266SJung-uk Kim 
374a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
375a159c266SJung-uk Kim }
376ab71bbb7SJung-uk Kim #endif
377a159c266SJung-uk Kim 
378a159c266SJung-uk Kim /*******************************************************************************
379a159c266SJung-uk Kim  *
380a159c266SJung-uk Kim  * FUNCTION:    AcpiExOpcode_1A_1T_1R
381a159c266SJung-uk Kim  *
382a159c266SJung-uk Kim  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
383a159c266SJung-uk Kim  *
384a159c266SJung-uk Kim  * RETURN:      Status
385a159c266SJung-uk Kim  *
386a159c266SJung-uk Kim  * DESCRIPTION: Execute opcode with one argument, one target, and a
387a159c266SJung-uk Kim  *              return value.
388ab71bbb7SJung-uk Kim  *              January 2022: Added Load operator, with new ACPI 6.4
389ab71bbb7SJung-uk Kim  *              semantics.
390a159c266SJung-uk Kim  *
391a159c266SJung-uk Kim  ******************************************************************************/
392a159c266SJung-uk Kim 
393a159c266SJung-uk Kim ACPI_STATUS
AcpiExOpcode_1A_1T_1R(ACPI_WALK_STATE * WalkState)394a159c266SJung-uk Kim AcpiExOpcode_1A_1T_1R (
395a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
396a159c266SJung-uk Kim {
397a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
398a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
399a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
400a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ReturnDesc2 = NULL;
401a159c266SJung-uk Kim     UINT32                  Temp32;
402a159c266SJung-uk Kim     UINT32                  i;
403a159c266SJung-uk Kim     UINT64                  PowerOfTen;
404a159c266SJung-uk Kim     UINT64                  Digit;
405a159c266SJung-uk Kim 
406a159c266SJung-uk Kim 
407a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_1T_1R,
408a159c266SJung-uk Kim         AcpiPsGetOpcodeName (WalkState->Opcode));
409a159c266SJung-uk Kim 
410a159c266SJung-uk Kim 
411a159c266SJung-uk Kim     /* Examine the AML opcode */
412a159c266SJung-uk Kim 
413a159c266SJung-uk Kim     switch (WalkState->Opcode)
414a159c266SJung-uk Kim     {
415a159c266SJung-uk Kim     case AML_BIT_NOT_OP:
416a159c266SJung-uk Kim     case AML_FIND_SET_LEFT_BIT_OP:
417a159c266SJung-uk Kim     case AML_FIND_SET_RIGHT_BIT_OP:
418a159c266SJung-uk Kim     case AML_FROM_BCD_OP:
419ab71bbb7SJung-uk Kim     case AML_LOAD_OP:
420a159c266SJung-uk Kim     case AML_TO_BCD_OP:
4210d84335fSJung-uk Kim     case AML_CONDITIONAL_REF_OF_OP:
422a159c266SJung-uk Kim 
423a159c266SJung-uk Kim         /* Create a return object of type Integer for these opcodes */
424a159c266SJung-uk Kim 
425a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
426a159c266SJung-uk Kim         if (!ReturnDesc)
427a159c266SJung-uk Kim         {
428a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
429a159c266SJung-uk Kim             goto Cleanup;
430a159c266SJung-uk Kim         }
431a159c266SJung-uk Kim 
432a159c266SJung-uk Kim         switch (WalkState->Opcode)
433a159c266SJung-uk Kim         {
434a159c266SJung-uk Kim         case AML_BIT_NOT_OP:            /* Not (Operand, Result)  */
435a159c266SJung-uk Kim 
436a159c266SJung-uk Kim             ReturnDesc->Integer.Value = ~Operand[0]->Integer.Value;
437a159c266SJung-uk Kim             break;
438a159c266SJung-uk Kim 
439a159c266SJung-uk Kim         case AML_FIND_SET_LEFT_BIT_OP:  /* FindSetLeftBit (Operand, Result) */
440a159c266SJung-uk Kim 
441a159c266SJung-uk Kim             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
442a159c266SJung-uk Kim 
443a159c266SJung-uk Kim             /*
444a159c266SJung-uk Kim              * Acpi specification describes Integer type as a little
445a159c266SJung-uk Kim              * endian unsigned value, so this boundary condition is valid.
446a159c266SJung-uk Kim              */
447a159c266SJung-uk Kim             for (Temp32 = 0; ReturnDesc->Integer.Value &&
448a159c266SJung-uk Kim                     Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
449a159c266SJung-uk Kim             {
450a159c266SJung-uk Kim                 ReturnDesc->Integer.Value >>= 1;
451a159c266SJung-uk Kim             }
452a159c266SJung-uk Kim 
453a159c266SJung-uk Kim             ReturnDesc->Integer.Value = Temp32;
454a159c266SJung-uk Kim             break;
455a159c266SJung-uk Kim 
456a159c266SJung-uk Kim         case AML_FIND_SET_RIGHT_BIT_OP: /* FindSetRightBit (Operand, Result) */
457a159c266SJung-uk Kim 
458a159c266SJung-uk Kim             ReturnDesc->Integer.Value = Operand[0]->Integer.Value;
459a159c266SJung-uk Kim 
460a159c266SJung-uk Kim             /*
461a159c266SJung-uk Kim              * The Acpi specification describes Integer type as a little
462a159c266SJung-uk Kim              * endian unsigned value, so this boundary condition is valid.
463a159c266SJung-uk Kim              */
464a159c266SJung-uk Kim             for (Temp32 = 0; ReturnDesc->Integer.Value &&
465a159c266SJung-uk Kim                      Temp32 < ACPI_INTEGER_BIT_SIZE; ++Temp32)
466a159c266SJung-uk Kim             {
467a159c266SJung-uk Kim                 ReturnDesc->Integer.Value <<= 1;
468a159c266SJung-uk Kim             }
469a159c266SJung-uk Kim 
470a159c266SJung-uk Kim             /* Since the bit position is one-based, subtract from 33 (65) */
471a159c266SJung-uk Kim 
472a159c266SJung-uk Kim             ReturnDesc->Integer.Value =
473a159c266SJung-uk Kim                 Temp32 == 0 ? 0 : (ACPI_INTEGER_BIT_SIZE + 1) - Temp32;
474a159c266SJung-uk Kim             break;
475a159c266SJung-uk Kim 
476a159c266SJung-uk Kim         case AML_FROM_BCD_OP:           /* FromBcd (BCDValue, Result)  */
477a159c266SJung-uk Kim             /*
478a159c266SJung-uk Kim              * The 64-bit ACPI integer can hold 16 4-bit BCD characters
479a159c266SJung-uk Kim              * (if table is 32-bit, integer can hold 8 BCD characters)
480a159c266SJung-uk Kim              * Convert each 4-bit BCD value
481a159c266SJung-uk Kim              */
482a159c266SJung-uk Kim             PowerOfTen = 1;
483a159c266SJung-uk Kim             ReturnDesc->Integer.Value = 0;
484a159c266SJung-uk Kim             Digit = Operand[0]->Integer.Value;
485a159c266SJung-uk Kim 
486a159c266SJung-uk Kim             /* Convert each BCD digit (each is one nybble wide) */
487a159c266SJung-uk Kim 
488a159c266SJung-uk Kim             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
489a159c266SJung-uk Kim             {
490a159c266SJung-uk Kim                 /* Get the least significant 4-bit BCD digit */
491a159c266SJung-uk Kim 
492a159c266SJung-uk Kim                 Temp32 = ((UINT32) Digit) & 0xF;
493a159c266SJung-uk Kim 
494a159c266SJung-uk Kim                 /* Check the range of the digit */
495a159c266SJung-uk Kim 
496a159c266SJung-uk Kim                 if (Temp32 > 9)
497a159c266SJung-uk Kim                 {
498a159c266SJung-uk Kim                     ACPI_ERROR ((AE_INFO,
499a159c266SJung-uk Kim                         "BCD digit too large (not decimal): 0x%X",
500a159c266SJung-uk Kim                         Temp32));
501a159c266SJung-uk Kim 
502a159c266SJung-uk Kim                     Status = AE_AML_NUMERIC_OVERFLOW;
503a159c266SJung-uk Kim                     goto Cleanup;
504a159c266SJung-uk Kim                 }
505a159c266SJung-uk Kim 
506a159c266SJung-uk Kim                 /* Sum the digit into the result with the current power of 10 */
507a159c266SJung-uk Kim 
508a159c266SJung-uk Kim                 ReturnDesc->Integer.Value +=
509a159c266SJung-uk Kim                     (((UINT64) Temp32) * PowerOfTen);
510a159c266SJung-uk Kim 
511a159c266SJung-uk Kim                 /* Shift to next BCD digit */
512a159c266SJung-uk Kim 
513a159c266SJung-uk Kim                 Digit >>= 4;
514a159c266SJung-uk Kim 
515a159c266SJung-uk Kim                 /* Next power of 10 */
516a159c266SJung-uk Kim 
517a159c266SJung-uk Kim                 PowerOfTen *= 10;
518a159c266SJung-uk Kim             }
519a159c266SJung-uk Kim             break;
520a159c266SJung-uk Kim 
521ab71bbb7SJung-uk Kim         case AML_LOAD_OP:               /* Result1 = Load (Operand[0], Result1) */
522ab71bbb7SJung-uk Kim 
523ab71bbb7SJung-uk Kim             ReturnDesc->Integer.Value = 0;
524ab71bbb7SJung-uk Kim             Status = AcpiExLoadOp (Operand[0], ReturnDesc, WalkState);
525ab71bbb7SJung-uk Kim             if (ACPI_SUCCESS (Status))
526ab71bbb7SJung-uk Kim             {
527ab71bbb7SJung-uk Kim                 /* Return -1 (non-zero) indicates success */
528ab71bbb7SJung-uk Kim 
529ab71bbb7SJung-uk Kim                 ReturnDesc->Integer.Value = 0xFFFFFFFFFFFFFFFF;
530ab71bbb7SJung-uk Kim             }
531ab71bbb7SJung-uk Kim             break;
532ab71bbb7SJung-uk Kim 
533a159c266SJung-uk Kim         case AML_TO_BCD_OP:             /* ToBcd (Operand, Result)  */
534a159c266SJung-uk Kim 
535a159c266SJung-uk Kim             ReturnDesc->Integer.Value = 0;
536a159c266SJung-uk Kim             Digit = Operand[0]->Integer.Value;
537a159c266SJung-uk Kim 
538a159c266SJung-uk Kim             /* Each BCD digit is one nybble wide */
539a159c266SJung-uk Kim 
540a159c266SJung-uk Kim             for (i = 0; (i < AcpiGbl_IntegerNybbleWidth) && (Digit > 0); i++)
541a159c266SJung-uk Kim             {
542a159c266SJung-uk Kim                 (void) AcpiUtShortDivide (Digit, 10, &Digit, &Temp32);
543a159c266SJung-uk Kim 
544a159c266SJung-uk Kim                 /*
545a159c266SJung-uk Kim                  * Insert the BCD digit that resides in the
546a159c266SJung-uk Kim                  * remainder from above
547a159c266SJung-uk Kim                  */
548a159c266SJung-uk Kim                 ReturnDesc->Integer.Value |=
549a159c266SJung-uk Kim                     (((UINT64) Temp32) << ACPI_MUL_4 (i));
550a159c266SJung-uk Kim             }
551a159c266SJung-uk Kim 
552a159c266SJung-uk Kim             /* Overflow if there is any data left in Digit */
553a159c266SJung-uk Kim 
554a159c266SJung-uk Kim             if (Digit > 0)
555a159c266SJung-uk Kim             {
556a159c266SJung-uk Kim                 ACPI_ERROR ((AE_INFO,
557a159c266SJung-uk Kim                     "Integer too large to convert to BCD: 0x%8.8X%8.8X",
558a159c266SJung-uk Kim                     ACPI_FORMAT_UINT64 (Operand[0]->Integer.Value)));
559a159c266SJung-uk Kim                 Status = AE_AML_NUMERIC_OVERFLOW;
560a159c266SJung-uk Kim                 goto Cleanup;
561a159c266SJung-uk Kim             }
562a159c266SJung-uk Kim             break;
563a159c266SJung-uk Kim 
5640d84335fSJung-uk Kim         case AML_CONDITIONAL_REF_OF_OP:     /* CondRefOf (SourceObject, Result)  */
565a159c266SJung-uk Kim             /*
566a159c266SJung-uk Kim              * This op is a little strange because the internal return value is
567a159c266SJung-uk Kim              * different than the return value stored in the result descriptor
568a159c266SJung-uk Kim              * (There are really two return values)
569a159c266SJung-uk Kim              */
570a159c266SJung-uk Kim             if ((ACPI_NAMESPACE_NODE *) Operand[0] == AcpiGbl_RootNode)
571a159c266SJung-uk Kim             {
572a159c266SJung-uk Kim                 /*
573a159c266SJung-uk Kim                  * This means that the object does not exist in the namespace,
574a159c266SJung-uk Kim                  * return FALSE
575a159c266SJung-uk Kim                  */
576a159c266SJung-uk Kim                 ReturnDesc->Integer.Value = 0;
577a159c266SJung-uk Kim                 goto Cleanup;
578a159c266SJung-uk Kim             }
579a159c266SJung-uk Kim 
580a159c266SJung-uk Kim             /* Get the object reference, store it, and remove our reference */
581a159c266SJung-uk Kim 
582a159c266SJung-uk Kim             Status = AcpiExGetObjectReference (Operand[0],
583a159c266SJung-uk Kim                 &ReturnDesc2, WalkState);
584a159c266SJung-uk Kim             if (ACPI_FAILURE (Status))
585a159c266SJung-uk Kim             {
586a159c266SJung-uk Kim                 goto Cleanup;
587a159c266SJung-uk Kim             }
588a159c266SJung-uk Kim 
589a159c266SJung-uk Kim             Status = AcpiExStore (ReturnDesc2, Operand[1], WalkState);
590a159c266SJung-uk Kim             AcpiUtRemoveReference (ReturnDesc2);
591a159c266SJung-uk Kim 
592a159c266SJung-uk Kim             /* The object exists in the namespace, return TRUE */
593a159c266SJung-uk Kim 
594a159c266SJung-uk Kim             ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
595a159c266SJung-uk Kim             goto Cleanup;
596a159c266SJung-uk Kim 
597a159c266SJung-uk Kim 
598a159c266SJung-uk Kim         default:
599a9d8d09cSJung-uk Kim 
600a159c266SJung-uk Kim             /* No other opcodes get here */
601a9d8d09cSJung-uk Kim 
602a159c266SJung-uk Kim             break;
603a159c266SJung-uk Kim         }
604a159c266SJung-uk Kim         break;
605a159c266SJung-uk Kim 
606a159c266SJung-uk Kim     case AML_STORE_OP:              /* Store (Source, Target) */
607a159c266SJung-uk Kim         /*
608a159c266SJung-uk Kim          * A store operand is typically a number, string, buffer or lvalue
609a159c266SJung-uk Kim          * Be careful about deleting the source object,
610a159c266SJung-uk Kim          * since the object itself may have been stored.
611a159c266SJung-uk Kim          */
612a159c266SJung-uk Kim         Status = AcpiExStore (Operand[0], Operand[1], WalkState);
613a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
614a159c266SJung-uk Kim         {
615a159c266SJung-uk Kim             return_ACPI_STATUS (Status);
616a159c266SJung-uk Kim         }
617a159c266SJung-uk Kim 
618a159c266SJung-uk Kim         /* It is possible that the Store already produced a return object */
619a159c266SJung-uk Kim 
620a159c266SJung-uk Kim         if (!WalkState->ResultObj)
621a159c266SJung-uk Kim         {
622a159c266SJung-uk Kim             /*
623a159c266SJung-uk Kim              * Normally, we would remove a reference on the Operand[0]
624a159c266SJung-uk Kim              * parameter; But since it is being used as the internal return
625a159c266SJung-uk Kim              * object (meaning we would normally increment it), the two
626a159c266SJung-uk Kim              * cancel out, and we simply don't do anything.
627a159c266SJung-uk Kim              */
628a159c266SJung-uk Kim             WalkState->ResultObj = Operand[0];
629a159c266SJung-uk Kim             WalkState->Operands[0] = NULL;  /* Prevent deletion */
630a159c266SJung-uk Kim         }
631a159c266SJung-uk Kim         return_ACPI_STATUS (Status);
632a159c266SJung-uk Kim 
633a159c266SJung-uk Kim     /*
634a159c266SJung-uk Kim      * ACPI 2.0 Opcodes
635a159c266SJung-uk Kim      */
6360d84335fSJung-uk Kim     case AML_COPY_OBJECT_OP:        /* CopyObject (Source, Target) */
637a159c266SJung-uk Kim 
638f8146b88SJung-uk Kim         Status = AcpiUtCopyIobjectToIobject (
639f8146b88SJung-uk Kim             Operand[0], &ReturnDesc, WalkState);
640a159c266SJung-uk Kim         break;
641a159c266SJung-uk Kim 
6420d84335fSJung-uk Kim     case AML_TO_DECIMAL_STRING_OP:  /* ToDecimalString (Data, Result) */
643a159c266SJung-uk Kim 
644f8146b88SJung-uk Kim         Status = AcpiExConvertToString (
645f8146b88SJung-uk Kim             Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_DECIMAL);
646a159c266SJung-uk Kim         if (ReturnDesc == Operand[0])
647a159c266SJung-uk Kim         {
648a159c266SJung-uk Kim             /* No conversion performed, add ref to handle return value */
649f8146b88SJung-uk Kim 
650a159c266SJung-uk Kim             AcpiUtAddReference (ReturnDesc);
651a159c266SJung-uk Kim         }
652a159c266SJung-uk Kim         break;
653a159c266SJung-uk Kim 
6540d84335fSJung-uk Kim     case AML_TO_HEX_STRING_OP:      /* ToHexString (Data, Result) */
655a159c266SJung-uk Kim 
656f8146b88SJung-uk Kim         Status = AcpiExConvertToString (
657f8146b88SJung-uk Kim             Operand[0], &ReturnDesc, ACPI_EXPLICIT_CONVERT_HEX);
658a159c266SJung-uk Kim         if (ReturnDesc == Operand[0])
659a159c266SJung-uk Kim         {
660a159c266SJung-uk Kim             /* No conversion performed, add ref to handle return value */
661f8146b88SJung-uk Kim 
662a159c266SJung-uk Kim             AcpiUtAddReference (ReturnDesc);
663a159c266SJung-uk Kim         }
664a159c266SJung-uk Kim         break;
665a159c266SJung-uk Kim 
666a159c266SJung-uk Kim     case AML_TO_BUFFER_OP:          /* ToBuffer (Data, Result) */
667a159c266SJung-uk Kim 
668a159c266SJung-uk Kim         Status = AcpiExConvertToBuffer (Operand[0], &ReturnDesc);
669a159c266SJung-uk Kim         if (ReturnDesc == Operand[0])
670a159c266SJung-uk Kim         {
671a159c266SJung-uk Kim             /* No conversion performed, add ref to handle return value */
672f8146b88SJung-uk Kim 
673a159c266SJung-uk Kim             AcpiUtAddReference (ReturnDesc);
674a159c266SJung-uk Kim         }
675a159c266SJung-uk Kim         break;
676a159c266SJung-uk Kim 
677a159c266SJung-uk Kim     case AML_TO_INTEGER_OP:         /* ToInteger (Data, Result) */
678a159c266SJung-uk Kim 
679493deb39SJung-uk Kim         /* Perform "explicit" conversion */
680493deb39SJung-uk Kim 
681493deb39SJung-uk Kim         Status = AcpiExConvertToInteger (Operand[0], &ReturnDesc, 0);
682a159c266SJung-uk Kim         if (ReturnDesc == Operand[0])
683a159c266SJung-uk Kim         {
684a159c266SJung-uk Kim             /* No conversion performed, add ref to handle return value */
685f8146b88SJung-uk Kim 
686a159c266SJung-uk Kim             AcpiUtAddReference (ReturnDesc);
687a159c266SJung-uk Kim         }
688a159c266SJung-uk Kim         break;
689a159c266SJung-uk Kim 
690a159c266SJung-uk Kim     case AML_SHIFT_LEFT_BIT_OP:     /* ShiftLeftBit (Source, BitNum)  */
691a159c266SJung-uk Kim     case AML_SHIFT_RIGHT_BIT_OP:    /* ShiftRightBit (Source, BitNum) */
692a159c266SJung-uk Kim 
693a159c266SJung-uk Kim         /* These are two obsolete opcodes */
694a159c266SJung-uk Kim 
695a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO,
696a159c266SJung-uk Kim             "%s is obsolete and not implemented",
697a159c266SJung-uk Kim             AcpiPsGetOpcodeName (WalkState->Opcode)));
698a159c266SJung-uk Kim         Status = AE_SUPPORT;
699a159c266SJung-uk Kim         goto Cleanup;
700a159c266SJung-uk Kim 
701a159c266SJung-uk Kim     default:                        /* Unknown opcode */
702a159c266SJung-uk Kim 
703a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
704a159c266SJung-uk Kim             WalkState->Opcode));
705a159c266SJung-uk Kim         Status = AE_AML_BAD_OPCODE;
706a159c266SJung-uk Kim         goto Cleanup;
707a159c266SJung-uk Kim     }
708a159c266SJung-uk Kim 
709a159c266SJung-uk Kim     if (ACPI_SUCCESS (Status))
710a159c266SJung-uk Kim     {
711a159c266SJung-uk Kim         /* Store the return value computed above into the target object */
712a159c266SJung-uk Kim 
713a159c266SJung-uk Kim         Status = AcpiExStore (ReturnDesc, Operand[1], WalkState);
714a159c266SJung-uk Kim     }
715a159c266SJung-uk Kim 
716a159c266SJung-uk Kim 
717a159c266SJung-uk Kim Cleanup:
718a159c266SJung-uk Kim 
719a159c266SJung-uk Kim     /* Delete return object on error */
720a159c266SJung-uk Kim 
721a159c266SJung-uk Kim     if (ACPI_FAILURE (Status))
722a159c266SJung-uk Kim     {
723a159c266SJung-uk Kim         AcpiUtRemoveReference (ReturnDesc);
724a159c266SJung-uk Kim     }
725a159c266SJung-uk Kim 
726a159c266SJung-uk Kim     /* Save return object on success */
727a159c266SJung-uk Kim 
728a159c266SJung-uk Kim     else if (!WalkState->ResultObj)
729a159c266SJung-uk Kim     {
730a159c266SJung-uk Kim         WalkState->ResultObj = ReturnDesc;
731a159c266SJung-uk Kim     }
732a159c266SJung-uk Kim 
733a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
734a159c266SJung-uk Kim }
735a159c266SJung-uk Kim 
736a159c266SJung-uk Kim 
737a159c266SJung-uk Kim /*******************************************************************************
738a159c266SJung-uk Kim  *
739a159c266SJung-uk Kim  * FUNCTION:    AcpiExOpcode_1A_0T_1R
740a159c266SJung-uk Kim  *
741a159c266SJung-uk Kim  * PARAMETERS:  WalkState           - Current state (contains AML opcode)
742a159c266SJung-uk Kim  *
743a159c266SJung-uk Kim  * RETURN:      Status
744a159c266SJung-uk Kim  *
745a159c266SJung-uk Kim  * DESCRIPTION: Execute opcode with one argument, no target, and a return value
746a159c266SJung-uk Kim  *
747a159c266SJung-uk Kim  ******************************************************************************/
748a159c266SJung-uk Kim 
749a159c266SJung-uk Kim ACPI_STATUS
AcpiExOpcode_1A_0T_1R(ACPI_WALK_STATE * WalkState)750a159c266SJung-uk Kim AcpiExOpcode_1A_0T_1R (
751a159c266SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
752a159c266SJung-uk Kim {
753a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
754a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *TempDesc;
755a159c266SJung-uk Kim     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
756a159c266SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
757a159c266SJung-uk Kim     UINT32                  Type;
758a159c266SJung-uk Kim     UINT64                  Value;
759a159c266SJung-uk Kim 
760a159c266SJung-uk Kim 
761a159c266SJung-uk Kim     ACPI_FUNCTION_TRACE_STR (ExOpcode_1A_0T_1R,
762a159c266SJung-uk Kim         AcpiPsGetOpcodeName (WalkState->Opcode));
763a159c266SJung-uk Kim 
764a159c266SJung-uk Kim 
765a159c266SJung-uk Kim     /* Examine the AML opcode */
766a159c266SJung-uk Kim 
767a159c266SJung-uk Kim     switch (WalkState->Opcode)
768a159c266SJung-uk Kim     {
7690d84335fSJung-uk Kim     case AML_LOGICAL_NOT_OP:        /* LNot (Operand) */
770a159c266SJung-uk Kim 
771a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) 0);
772a159c266SJung-uk Kim         if (!ReturnDesc)
773a159c266SJung-uk Kim         {
774a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
775a159c266SJung-uk Kim             goto Cleanup;
776a159c266SJung-uk Kim         }
777a159c266SJung-uk Kim 
778a159c266SJung-uk Kim         /*
779a159c266SJung-uk Kim          * Set result to ONES (TRUE) if Value == 0. Note:
780a159c266SJung-uk Kim          * ReturnDesc->Integer.Value is initially == 0 (FALSE) from above.
781a159c266SJung-uk Kim          */
782a159c266SJung-uk Kim         if (!Operand[0]->Integer.Value)
783a159c266SJung-uk Kim         {
784a159c266SJung-uk Kim             ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
785a159c266SJung-uk Kim         }
786a159c266SJung-uk Kim         break;
787a159c266SJung-uk Kim 
788a159c266SJung-uk Kim     case AML_DECREMENT_OP:          /* Decrement (Operand)  */
789a159c266SJung-uk Kim     case AML_INCREMENT_OP:          /* Increment (Operand)  */
790a159c266SJung-uk Kim         /*
791a159c266SJung-uk Kim          * Create a new integer. Can't just get the base integer and
792a159c266SJung-uk Kim          * increment it because it may be an Arg or Field.
793a159c266SJung-uk Kim          */
794a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
795a159c266SJung-uk Kim         if (!ReturnDesc)
796a159c266SJung-uk Kim         {
797a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
798a159c266SJung-uk Kim             goto Cleanup;
799a159c266SJung-uk Kim         }
800a159c266SJung-uk Kim 
801a159c266SJung-uk Kim         /*
802a159c266SJung-uk Kim          * Since we are expecting a Reference operand, it can be either a
803a159c266SJung-uk Kim          * NS Node or an internal object.
804a159c266SJung-uk Kim          */
805a159c266SJung-uk Kim         TempDesc = Operand[0];
806a159c266SJung-uk Kim         if (ACPI_GET_DESCRIPTOR_TYPE (TempDesc) == ACPI_DESC_TYPE_OPERAND)
807a159c266SJung-uk Kim         {
808a159c266SJung-uk Kim             /* Internal reference object - prevent deletion */
809a159c266SJung-uk Kim 
810a159c266SJung-uk Kim             AcpiUtAddReference (TempDesc);
811a159c266SJung-uk Kim         }
812a159c266SJung-uk Kim 
813a159c266SJung-uk Kim         /*
814a159c266SJung-uk Kim          * Convert the Reference operand to an Integer (This removes a
815a159c266SJung-uk Kim          * reference on the Operand[0] object)
816a159c266SJung-uk Kim          *
817a159c266SJung-uk Kim          * NOTE:  We use LNOT_OP here in order to force resolution of the
818a159c266SJung-uk Kim          * reference operand to an actual integer.
819a159c266SJung-uk Kim          */
8200d84335fSJung-uk Kim         Status = AcpiExResolveOperands (AML_LOGICAL_NOT_OP,
8210d84335fSJung-uk Kim             &TempDesc, WalkState);
822a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
823a159c266SJung-uk Kim         {
824a159c266SJung-uk Kim             ACPI_EXCEPTION ((AE_INFO, Status,
825a159c266SJung-uk Kim                 "While resolving operands for [%s]",
826a159c266SJung-uk Kim                 AcpiPsGetOpcodeName (WalkState->Opcode)));
827a159c266SJung-uk Kim 
828a159c266SJung-uk Kim             goto Cleanup;
829a159c266SJung-uk Kim         }
830a159c266SJung-uk Kim 
831a159c266SJung-uk Kim         /*
832a159c266SJung-uk Kim          * TempDesc is now guaranteed to be an Integer object --
833a159c266SJung-uk Kim          * Perform the actual increment or decrement
834a159c266SJung-uk Kim          */
835a159c266SJung-uk Kim         if (WalkState->Opcode == AML_INCREMENT_OP)
836a159c266SJung-uk Kim         {
837a159c266SJung-uk Kim             ReturnDesc->Integer.Value = TempDesc->Integer.Value + 1;
838a159c266SJung-uk Kim         }
839a159c266SJung-uk Kim         else
840a159c266SJung-uk Kim         {
841a159c266SJung-uk Kim             ReturnDesc->Integer.Value = TempDesc->Integer.Value - 1;
842a159c266SJung-uk Kim         }
843a159c266SJung-uk Kim 
844a159c266SJung-uk Kim         /* Finished with this Integer object */
845a159c266SJung-uk Kim 
846a159c266SJung-uk Kim         AcpiUtRemoveReference (TempDesc);
847a159c266SJung-uk Kim 
848a159c266SJung-uk Kim         /*
849a159c266SJung-uk Kim          * Store the result back (indirectly) through the original
850a159c266SJung-uk Kim          * Reference object
851a159c266SJung-uk Kim          */
852a159c266SJung-uk Kim         Status = AcpiExStore (ReturnDesc, Operand[0], WalkState);
853a159c266SJung-uk Kim         break;
854a159c266SJung-uk Kim 
855f8146b88SJung-uk Kim     case AML_OBJECT_TYPE_OP:            /* ObjectType (SourceObject) */
856a159c266SJung-uk Kim         /*
857a159c266SJung-uk Kim          * Note: The operand is not resolved at this point because we want to
858a159c266SJung-uk Kim          * get the associated object, not its value. For example, we don't
859a159c266SJung-uk Kim          * want to resolve a FieldUnit to its value, we want the actual
860a159c266SJung-uk Kim          * FieldUnit object.
861a159c266SJung-uk Kim          */
862a159c266SJung-uk Kim 
863a159c266SJung-uk Kim         /* Get the type of the base object */
864a159c266SJung-uk Kim 
865a159c266SJung-uk Kim         Status = AcpiExResolveMultiple (WalkState, Operand[0], &Type, NULL);
866a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
867a159c266SJung-uk Kim         {
868a159c266SJung-uk Kim             goto Cleanup;
869a159c266SJung-uk Kim         }
870a159c266SJung-uk Kim 
871a159c266SJung-uk Kim         /* Allocate a descriptor to hold the type. */
872a159c266SJung-uk Kim 
873a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateIntegerObject ((UINT64) Type);
874a159c266SJung-uk Kim         if (!ReturnDesc)
875a159c266SJung-uk Kim         {
876a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
877a159c266SJung-uk Kim             goto Cleanup;
878a159c266SJung-uk Kim         }
879a159c266SJung-uk Kim         break;
880a159c266SJung-uk Kim 
881a159c266SJung-uk Kim     case AML_SIZE_OF_OP:            /* SizeOf (SourceObject)  */
882a159c266SJung-uk Kim         /*
883a159c266SJung-uk Kim          * Note: The operand is not resolved at this point because we want to
884a159c266SJung-uk Kim          * get the associated object, not its value.
885a159c266SJung-uk Kim          */
886a159c266SJung-uk Kim 
887a159c266SJung-uk Kim         /* Get the base object */
888a159c266SJung-uk Kim 
889f8146b88SJung-uk Kim         Status = AcpiExResolveMultiple (
890f8146b88SJung-uk Kim             WalkState, Operand[0], &Type, &TempDesc);
891a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
892a159c266SJung-uk Kim         {
893a159c266SJung-uk Kim             goto Cleanup;
894a159c266SJung-uk Kim         }
895a159c266SJung-uk Kim 
896a159c266SJung-uk Kim         /*
897a159c266SJung-uk Kim          * The type of the base object must be integer, buffer, string, or
898a159c266SJung-uk Kim          * package. All others are not supported.
899a159c266SJung-uk Kim          *
900a159c266SJung-uk Kim          * NOTE: Integer is not specifically supported by the ACPI spec,
901a159c266SJung-uk Kim          * but is supported implicitly via implicit operand conversion.
902a159c266SJung-uk Kim          * rather than bother with conversion, we just use the byte width
903a159c266SJung-uk Kim          * global (4 or 8 bytes).
904a159c266SJung-uk Kim          */
905a159c266SJung-uk Kim         switch (Type)
906a159c266SJung-uk Kim         {
907a159c266SJung-uk Kim         case ACPI_TYPE_INTEGER:
908a9d8d09cSJung-uk Kim 
909a159c266SJung-uk Kim             Value = AcpiGbl_IntegerByteWidth;
910a159c266SJung-uk Kim             break;
911a159c266SJung-uk Kim 
912a159c266SJung-uk Kim         case ACPI_TYPE_STRING:
913a9d8d09cSJung-uk Kim 
914a159c266SJung-uk Kim             Value = TempDesc->String.Length;
915a159c266SJung-uk Kim             break;
916a159c266SJung-uk Kim 
917a159c266SJung-uk Kim         case ACPI_TYPE_BUFFER:
918a159c266SJung-uk Kim 
919a159c266SJung-uk Kim             /* Buffer arguments may not be evaluated at this point */
920a159c266SJung-uk Kim 
921a159c266SJung-uk Kim             Status = AcpiDsGetBufferArguments (TempDesc);
922a159c266SJung-uk Kim             Value = TempDesc->Buffer.Length;
923a159c266SJung-uk Kim             break;
924a159c266SJung-uk Kim 
925a159c266SJung-uk Kim         case ACPI_TYPE_PACKAGE:
926a159c266SJung-uk Kim 
927a159c266SJung-uk Kim             /* Package arguments may not be evaluated at this point */
928a159c266SJung-uk Kim 
929a159c266SJung-uk Kim             Status = AcpiDsGetPackageArguments (TempDesc);
930a159c266SJung-uk Kim             Value = TempDesc->Package.Count;
931a159c266SJung-uk Kim             break;
932a159c266SJung-uk Kim 
933a159c266SJung-uk Kim         default:
934a9d8d09cSJung-uk Kim 
935a159c266SJung-uk Kim             ACPI_ERROR ((AE_INFO,
936f8146b88SJung-uk Kim                 "Operand must be Buffer/Integer/String/Package"
937f8146b88SJung-uk Kim                 " - found type %s",
938a159c266SJung-uk Kim                 AcpiUtGetTypeName (Type)));
939f8146b88SJung-uk Kim 
940a159c266SJung-uk Kim             Status = AE_AML_OPERAND_TYPE;
941a159c266SJung-uk Kim             goto Cleanup;
942a159c266SJung-uk Kim         }
943a159c266SJung-uk Kim 
944a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
945a159c266SJung-uk Kim         {
946a159c266SJung-uk Kim             goto Cleanup;
947a159c266SJung-uk Kim         }
948a159c266SJung-uk Kim 
949a159c266SJung-uk Kim         /*
950a159c266SJung-uk Kim          * Now that we have the size of the object, create a result
951a159c266SJung-uk Kim          * object to hold the value
952a159c266SJung-uk Kim          */
953a159c266SJung-uk Kim         ReturnDesc = AcpiUtCreateIntegerObject (Value);
954a159c266SJung-uk Kim         if (!ReturnDesc)
955a159c266SJung-uk Kim         {
956a159c266SJung-uk Kim             Status = AE_NO_MEMORY;
957a159c266SJung-uk Kim             goto Cleanup;
958a159c266SJung-uk Kim         }
959a159c266SJung-uk Kim         break;
960a159c266SJung-uk Kim 
961a159c266SJung-uk Kim 
962a159c266SJung-uk Kim     case AML_REF_OF_OP:             /* RefOf (SourceObject) */
963a159c266SJung-uk Kim 
964f8146b88SJung-uk Kim         Status = AcpiExGetObjectReference (
965f8146b88SJung-uk Kim             Operand[0], &ReturnDesc, WalkState);
966a159c266SJung-uk Kim         if (ACPI_FAILURE (Status))
967a159c266SJung-uk Kim         {
968a159c266SJung-uk Kim             goto Cleanup;
969a159c266SJung-uk Kim         }
970a159c266SJung-uk Kim         break;
971a159c266SJung-uk Kim 
972a159c266SJung-uk Kim 
973a159c266SJung-uk Kim     case AML_DEREF_OF_OP:           /* DerefOf (ObjReference | String) */
974a159c266SJung-uk Kim 
975a159c266SJung-uk Kim         /* Check for a method local or argument, or standalone String */
976a159c266SJung-uk Kim 
977a159c266SJung-uk Kim         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
978a159c266SJung-uk Kim         {
979a159c266SJung-uk Kim             TempDesc = AcpiNsGetAttachedObject (
980a159c266SJung-uk Kim                 (ACPI_NAMESPACE_NODE *) Operand[0]);
981a159c266SJung-uk Kim             if (TempDesc &&
982a159c266SJung-uk Kim                  ((TempDesc->Common.Type == ACPI_TYPE_STRING) ||
983a159c266SJung-uk Kim                   (TempDesc->Common.Type == ACPI_TYPE_LOCAL_REFERENCE)))
984a159c266SJung-uk Kim             {
985a159c266SJung-uk Kim                 Operand[0] = TempDesc;
986a159c266SJung-uk Kim                 AcpiUtAddReference (TempDesc);
987a159c266SJung-uk Kim             }
988a159c266SJung-uk Kim             else
989a159c266SJung-uk Kim             {
990a159c266SJung-uk Kim                 Status = AE_AML_OPERAND_TYPE;
991a159c266SJung-uk Kim                 goto Cleanup;
992a159c266SJung-uk Kim             }
993a159c266SJung-uk Kim         }
994a159c266SJung-uk Kim         else
995a159c266SJung-uk Kim         {
996a159c266SJung-uk Kim             switch ((Operand[0])->Common.Type)
997a159c266SJung-uk Kim             {
998a159c266SJung-uk Kim             case ACPI_TYPE_LOCAL_REFERENCE:
999a159c266SJung-uk Kim                 /*
1000a159c266SJung-uk Kim                  * This is a DerefOf (LocalX | ArgX)
1001a159c266SJung-uk Kim                  *
1002a159c266SJung-uk Kim                  * Must resolve/dereference the local/arg reference first
1003a159c266SJung-uk Kim                  */
1004a159c266SJung-uk Kim                 switch (Operand[0]->Reference.Class)
1005a159c266SJung-uk Kim                 {
1006a159c266SJung-uk Kim                 case ACPI_REFCLASS_LOCAL:
1007a159c266SJung-uk Kim                 case ACPI_REFCLASS_ARG:
1008a159c266SJung-uk Kim 
1009a159c266SJung-uk Kim                     /* Set Operand[0] to the value of the local/arg */
1010a159c266SJung-uk Kim 
1011a159c266SJung-uk Kim                     Status = AcpiDsMethodDataGetValue (
1012a159c266SJung-uk Kim                         Operand[0]->Reference.Class,
1013a159c266SJung-uk Kim                         Operand[0]->Reference.Value,
1014a159c266SJung-uk Kim                         WalkState, &TempDesc);
1015a159c266SJung-uk Kim                     if (ACPI_FAILURE (Status))
1016a159c266SJung-uk Kim                     {
1017a159c266SJung-uk Kim                         goto Cleanup;
1018a159c266SJung-uk Kim                     }
1019a159c266SJung-uk Kim 
1020a159c266SJung-uk Kim                     /*
1021a159c266SJung-uk Kim                      * Delete our reference to the input object and
1022a159c266SJung-uk Kim                      * point to the object just retrieved
1023a159c266SJung-uk Kim                      */
1024a159c266SJung-uk Kim                     AcpiUtRemoveReference (Operand[0]);
1025a159c266SJung-uk Kim                     Operand[0] = TempDesc;
1026a159c266SJung-uk Kim                     break;
1027a159c266SJung-uk Kim 
1028a159c266SJung-uk Kim                 case ACPI_REFCLASS_REFOF:
1029a159c266SJung-uk Kim 
1030a159c266SJung-uk Kim                     /* Get the object to which the reference refers */
1031a159c266SJung-uk Kim 
1032a159c266SJung-uk Kim                     TempDesc = Operand[0]->Reference.Object;
1033a159c266SJung-uk Kim                     AcpiUtRemoveReference (Operand[0]);
1034a159c266SJung-uk Kim                     Operand[0] = TempDesc;
1035a159c266SJung-uk Kim                     break;
1036a159c266SJung-uk Kim 
1037a159c266SJung-uk Kim                 default:
1038a159c266SJung-uk Kim 
1039a159c266SJung-uk Kim                     /* Must be an Index op - handled below */
1040a159c266SJung-uk Kim                     break;
1041a159c266SJung-uk Kim                 }
1042a159c266SJung-uk Kim                 break;
1043a159c266SJung-uk Kim 
1044a159c266SJung-uk Kim             case ACPI_TYPE_STRING:
1045a9d8d09cSJung-uk Kim 
1046a159c266SJung-uk Kim                 break;
1047a159c266SJung-uk Kim 
1048a159c266SJung-uk Kim             default:
1049a9d8d09cSJung-uk Kim 
1050a159c266SJung-uk Kim                 Status = AE_AML_OPERAND_TYPE;
1051a159c266SJung-uk Kim                 goto Cleanup;
1052a159c266SJung-uk Kim             }
1053a159c266SJung-uk Kim         }
1054a159c266SJung-uk Kim 
1055a159c266SJung-uk Kim         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) != ACPI_DESC_TYPE_NAMED)
1056a159c266SJung-uk Kim         {
1057a159c266SJung-uk Kim             if ((Operand[0])->Common.Type == ACPI_TYPE_STRING)
1058a159c266SJung-uk Kim             {
1059a159c266SJung-uk Kim                 /*
1060a159c266SJung-uk Kim                  * This is a DerefOf (String). The string is a reference
1061a159c266SJung-uk Kim                  * to a named ACPI object.
1062a159c266SJung-uk Kim                  *
1063a159c266SJung-uk Kim                  * 1) Find the owning Node
1064a159c266SJung-uk Kim                  * 2) Dereference the node to an actual object. Could be a
1065a159c266SJung-uk Kim                  *    Field, so we need to resolve the node to a value.
1066a159c266SJung-uk Kim                  */
1067493deb39SJung-uk Kim                 Status = AcpiNsGetNodeUnlocked (WalkState->ScopeInfo->Scope.Node,
1068a159c266SJung-uk Kim                     Operand[0]->String.Pointer,
1069a159c266SJung-uk Kim                     ACPI_NS_SEARCH_PARENT,
1070a159c266SJung-uk Kim                     ACPI_CAST_INDIRECT_PTR (
1071a159c266SJung-uk Kim                         ACPI_NAMESPACE_NODE, &ReturnDesc));
1072a159c266SJung-uk Kim                 if (ACPI_FAILURE (Status))
1073a159c266SJung-uk Kim                 {
1074a159c266SJung-uk Kim                     goto Cleanup;
1075a159c266SJung-uk Kim                 }
1076a159c266SJung-uk Kim 
1077a159c266SJung-uk Kim                 Status = AcpiExResolveNodeToValue (
1078a159c266SJung-uk Kim                     ACPI_CAST_INDIRECT_PTR (
1079a159c266SJung-uk Kim                         ACPI_NAMESPACE_NODE, &ReturnDesc),
1080a159c266SJung-uk Kim                     WalkState);
1081a159c266SJung-uk Kim                 goto Cleanup;
1082a159c266SJung-uk Kim             }
1083a159c266SJung-uk Kim         }
1084a159c266SJung-uk Kim 
1085a159c266SJung-uk Kim         /* Operand[0] may have changed from the code above */
1086a159c266SJung-uk Kim 
1087a159c266SJung-uk Kim         if (ACPI_GET_DESCRIPTOR_TYPE (Operand[0]) == ACPI_DESC_TYPE_NAMED)
1088a159c266SJung-uk Kim         {
1089a159c266SJung-uk Kim             /*
1090a159c266SJung-uk Kim              * This is a DerefOf (ObjectReference)
1091a159c266SJung-uk Kim              * Get the actual object from the Node (This is the dereference).
1092a159c266SJung-uk Kim              * This case may only happen when a LocalX or ArgX is
1093af051161SJung-uk Kim              * dereferenced above, or for references to device and
1094af051161SJung-uk Kim              * thermal objects.
1095a159c266SJung-uk Kim              */
1096af051161SJung-uk Kim             switch (((ACPI_NAMESPACE_NODE *) Operand[0])->Type)
1097af051161SJung-uk Kim             {
1098af051161SJung-uk Kim             case ACPI_TYPE_DEVICE:
1099af051161SJung-uk Kim             case ACPI_TYPE_THERMAL:
1100af051161SJung-uk Kim 
1101af051161SJung-uk Kim                 /* These types have no node subobject, return the NS node */
1102af051161SJung-uk Kim 
1103af051161SJung-uk Kim                 ReturnDesc = Operand[0];
1104af051161SJung-uk Kim                 break;
1105af051161SJung-uk Kim 
1106af051161SJung-uk Kim             default:
1107af051161SJung-uk Kim                 /* For most types, get the object attached to the node */
1108af051161SJung-uk Kim 
1109a159c266SJung-uk Kim                 ReturnDesc = AcpiNsGetAttachedObject (
1110a159c266SJung-uk Kim                     (ACPI_NAMESPACE_NODE *) Operand[0]);
1111a159c266SJung-uk Kim                 AcpiUtAddReference (ReturnDesc);
1112af051161SJung-uk Kim                 break;
1113af051161SJung-uk Kim             }
1114a159c266SJung-uk Kim         }
1115a159c266SJung-uk Kim         else
1116a159c266SJung-uk Kim         {
1117a159c266SJung-uk Kim             /*
1118a159c266SJung-uk Kim              * This must be a reference object produced by either the
1119a159c266SJung-uk Kim              * Index() or RefOf() operator
1120a159c266SJung-uk Kim              */
1121a159c266SJung-uk Kim             switch (Operand[0]->Reference.Class)
1122a159c266SJung-uk Kim             {
1123a159c266SJung-uk Kim             case ACPI_REFCLASS_INDEX:
1124a159c266SJung-uk Kim                 /*
1125a159c266SJung-uk Kim                  * The target type for the Index operator must be
1126a159c266SJung-uk Kim                  * either a Buffer or a Package
1127a159c266SJung-uk Kim                  */
1128a159c266SJung-uk Kim                 switch (Operand[0]->Reference.TargetType)
1129a159c266SJung-uk Kim                 {
1130a159c266SJung-uk Kim                 case ACPI_TYPE_BUFFER_FIELD:
1131a159c266SJung-uk Kim 
1132a159c266SJung-uk Kim                     TempDesc = Operand[0]->Reference.Object;
1133a159c266SJung-uk Kim 
1134a159c266SJung-uk Kim                     /*
1135a159c266SJung-uk Kim                      * Create a new object that contains one element of the
1136a159c266SJung-uk Kim                      * buffer -- the element pointed to by the index.
1137a159c266SJung-uk Kim                      *
1138a159c266SJung-uk Kim                      * NOTE: index into a buffer is NOT a pointer to a
1139a159c266SJung-uk Kim                      * sub-buffer of the main buffer, it is only a pointer to a
1140a159c266SJung-uk Kim                      * single element (byte) of the buffer!
1141a159c266SJung-uk Kim                      *
1142a159c266SJung-uk Kim                      * Since we are returning the value of the buffer at the
1143a159c266SJung-uk Kim                      * indexed location, we don't need to add an additional
1144a159c266SJung-uk Kim                      * reference to the buffer itself.
1145a159c266SJung-uk Kim                      */
1146a159c266SJung-uk Kim                     ReturnDesc = AcpiUtCreateIntegerObject ((UINT64)
1147a159c266SJung-uk Kim                         TempDesc->Buffer.Pointer[Operand[0]->Reference.Value]);
1148a159c266SJung-uk Kim                     if (!ReturnDesc)
1149a159c266SJung-uk Kim                     {
1150a159c266SJung-uk Kim                         Status = AE_NO_MEMORY;
1151a159c266SJung-uk Kim                         goto Cleanup;
1152a159c266SJung-uk Kim                     }
1153a159c266SJung-uk Kim                     break;
1154a159c266SJung-uk Kim 
1155a159c266SJung-uk Kim                 case ACPI_TYPE_PACKAGE:
1156a159c266SJung-uk Kim                     /*
1157a159c266SJung-uk Kim                      * Return the referenced element of the package. We must
1158a159c266SJung-uk Kim                      * add another reference to the referenced object, however.
1159a159c266SJung-uk Kim                      */
1160a159c266SJung-uk Kim                     ReturnDesc = *(Operand[0]->Reference.Where);
1161bf6fac21SJung-uk Kim                     if (!ReturnDesc)
1162a159c266SJung-uk Kim                     {
1163bf6fac21SJung-uk Kim                         /*
1164bf6fac21SJung-uk Kim                          * Element is NULL, do not allow the dereference.
1165bf6fac21SJung-uk Kim                          * This provides compatibility with other ACPI
1166bf6fac21SJung-uk Kim                          * implementations.
1167bf6fac21SJung-uk Kim                          */
1168bf6fac21SJung-uk Kim                         return_ACPI_STATUS (AE_AML_UNINITIALIZED_ELEMENT);
1169a159c266SJung-uk Kim                     }
1170bf6fac21SJung-uk Kim 
1171bf6fac21SJung-uk Kim                     AcpiUtAddReference (ReturnDesc);
1172a159c266SJung-uk Kim                     break;
1173a159c266SJung-uk Kim 
1174a159c266SJung-uk Kim                 default:
1175a159c266SJung-uk Kim 
1176a159c266SJung-uk Kim                     ACPI_ERROR ((AE_INFO,
1177a159c266SJung-uk Kim                         "Unknown Index TargetType 0x%X in reference object %p",
1178a159c266SJung-uk Kim                         Operand[0]->Reference.TargetType, Operand[0]));
1179f8146b88SJung-uk Kim 
1180a159c266SJung-uk Kim                     Status = AE_AML_OPERAND_TYPE;
1181a159c266SJung-uk Kim                     goto Cleanup;
1182a159c266SJung-uk Kim                 }
1183a159c266SJung-uk Kim                 break;
1184a159c266SJung-uk Kim 
1185a159c266SJung-uk Kim             case ACPI_REFCLASS_REFOF:
1186a159c266SJung-uk Kim 
1187a159c266SJung-uk Kim                 ReturnDesc = Operand[0]->Reference.Object;
1188a159c266SJung-uk Kim 
1189a159c266SJung-uk Kim                 if (ACPI_GET_DESCRIPTOR_TYPE (ReturnDesc) ==
1190a159c266SJung-uk Kim                     ACPI_DESC_TYPE_NAMED)
1191a159c266SJung-uk Kim                 {
1192a159c266SJung-uk Kim                     ReturnDesc = AcpiNsGetAttachedObject (
1193a159c266SJung-uk Kim                         (ACPI_NAMESPACE_NODE *) ReturnDesc);
1194bf6fac21SJung-uk Kim                     if (!ReturnDesc)
1195bf6fac21SJung-uk Kim                     {
1196bf6fac21SJung-uk Kim                         break;
1197a159c266SJung-uk Kim                     }
1198a159c266SJung-uk Kim 
1199bf6fac21SJung-uk Kim                    /*
1200bf6fac21SJung-uk Kim                     * June 2013:
1201bf6fac21SJung-uk Kim                     * BufferFields/FieldUnits require additional resolution
1202bf6fac21SJung-uk Kim                     */
1203bf6fac21SJung-uk Kim                     switch (ReturnDesc->Common.Type)
1204bf6fac21SJung-uk Kim                     {
1205bf6fac21SJung-uk Kim                     case ACPI_TYPE_BUFFER_FIELD:
1206bf6fac21SJung-uk Kim                     case ACPI_TYPE_LOCAL_REGION_FIELD:
1207bf6fac21SJung-uk Kim                     case ACPI_TYPE_LOCAL_BANK_FIELD:
1208bf6fac21SJung-uk Kim                     case ACPI_TYPE_LOCAL_INDEX_FIELD:
1209bf6fac21SJung-uk Kim 
1210f8146b88SJung-uk Kim                         Status = AcpiExReadDataFromField (
1211f8146b88SJung-uk Kim                             WalkState, ReturnDesc, &TempDesc);
1212bf6fac21SJung-uk Kim                         if (ACPI_FAILURE (Status))
1213bf6fac21SJung-uk Kim                         {
1214ab71bbb7SJung-uk Kim                             return_ACPI_STATUS (Status);
1215bf6fac21SJung-uk Kim                         }
1216bf6fac21SJung-uk Kim 
1217bf6fac21SJung-uk Kim                         ReturnDesc = TempDesc;
1218bf6fac21SJung-uk Kim                         break;
1219bf6fac21SJung-uk Kim 
1220bf6fac21SJung-uk Kim                     default:
1221bf6fac21SJung-uk Kim 
1222bf6fac21SJung-uk Kim                         /* Add another reference to the object */
1223a159c266SJung-uk Kim 
1224a159c266SJung-uk Kim                         AcpiUtAddReference (ReturnDesc);
1225a159c266SJung-uk Kim                         break;
1226bf6fac21SJung-uk Kim                     }
1227bf6fac21SJung-uk Kim                 }
1228bf6fac21SJung-uk Kim                 break;
1229a159c266SJung-uk Kim 
1230a159c266SJung-uk Kim             default:
1231a9d8d09cSJung-uk Kim 
1232a159c266SJung-uk Kim                 ACPI_ERROR ((AE_INFO,
1233a159c266SJung-uk Kim                     "Unknown class in reference(%p) - 0x%2.2X",
1234a159c266SJung-uk Kim                     Operand[0], Operand[0]->Reference.Class));
1235a159c266SJung-uk Kim 
1236a159c266SJung-uk Kim                 Status = AE_TYPE;
1237a159c266SJung-uk Kim                 goto Cleanup;
1238a159c266SJung-uk Kim             }
1239a159c266SJung-uk Kim         }
1240a159c266SJung-uk Kim         break;
1241a159c266SJung-uk Kim 
1242a159c266SJung-uk Kim     default:
1243a159c266SJung-uk Kim 
1244a159c266SJung-uk Kim         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
1245a159c266SJung-uk Kim             WalkState->Opcode));
1246f8146b88SJung-uk Kim 
1247a159c266SJung-uk Kim         Status = AE_AML_BAD_OPCODE;
1248a159c266SJung-uk Kim         goto Cleanup;
1249a159c266SJung-uk Kim     }
1250a159c266SJung-uk Kim 
1251a159c266SJung-uk Kim 
1252a159c266SJung-uk Kim Cleanup:
1253a159c266SJung-uk Kim 
1254a159c266SJung-uk Kim     /* Delete return object on error */
1255a159c266SJung-uk Kim 
1256a159c266SJung-uk Kim     if (ACPI_FAILURE (Status))
1257a159c266SJung-uk Kim     {
1258a159c266SJung-uk Kim         AcpiUtRemoveReference (ReturnDesc);
1259a159c266SJung-uk Kim     }
1260a159c266SJung-uk Kim 
1261a159c266SJung-uk Kim     /* Save return object on success */
1262a159c266SJung-uk Kim 
1263a159c266SJung-uk Kim     else
1264a159c266SJung-uk Kim     {
1265a159c266SJung-uk Kim         WalkState->ResultObj = ReturnDesc;
1266a159c266SJung-uk Kim     }
1267a159c266SJung-uk Kim 
1268a159c266SJung-uk Kim     return_ACPI_STATUS (Status);
1269a159c266SJung-uk Kim }
1270