xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/executer/exoparg2.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: exoparg2 - AML execution - opcodes with 2 arguments
40174267aSFredrik Holmqvist  *
50174267aSFredrik Holmqvist  *****************************************************************************/
60174267aSFredrik Holmqvist 
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist  *
90174267aSFredrik Holmqvist  * 1. Copyright Notice
100174267aSFredrik Holmqvist  *
11*6dde014fSPulkoMandy  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist  * All rights reserved.
130174267aSFredrik Holmqvist  *
140174267aSFredrik Holmqvist  * 2. License
150174267aSFredrik Holmqvist  *
160174267aSFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist  * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist  * property rights.
200174267aSFredrik Holmqvist  *
210174267aSFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist  *
280174267aSFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist  * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist  *
370174267aSFredrik Holmqvist  * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist  * conditions are met:
390174267aSFredrik Holmqvist  *
400174267aSFredrik Holmqvist  * 3. Conditions
410174267aSFredrik Holmqvist  *
420174267aSFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist  * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist  * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist  * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist  *
540174267aSFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist  * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist  * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist  * make.
650174267aSFredrik Holmqvist  *
660174267aSFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist  * distribution.
710174267aSFredrik Holmqvist  *
720174267aSFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist  * Intel Code.
740174267aSFredrik Holmqvist  *
750174267aSFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist  * without prior written authorization from Intel.
790174267aSFredrik Holmqvist  *
800174267aSFredrik Holmqvist  * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist  *
820174267aSFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist  * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist  *
900174267aSFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist  * LIMITED REMEDY.
980174267aSFredrik Holmqvist  *
990174267aSFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist  * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist  * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist  * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist  * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist  * such license, approval or letter.
1130174267aSFredrik Holmqvist  *
114ff2e2f81SFredrik Holmqvist  *****************************************************************************
115ff2e2f81SFredrik Holmqvist  *
116ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist  * following license:
118ff2e2f81SFredrik Holmqvist  *
119ff2e2f81SFredrik Holmqvist  * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist  * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist  * are met:
122ff2e2f81SFredrik Holmqvist  * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist  *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist  *    without modification.
125ff2e2f81SFredrik Holmqvist  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist  *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist  *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist  *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist  *    binary redistribution.
130ff2e2f81SFredrik Holmqvist  * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist  *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist  *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist  *
134ff2e2f81SFredrik Holmqvist  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist  *
146ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist  * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist  * Software Foundation.
149ff2e2f81SFredrik Holmqvist  *
1500174267aSFredrik Holmqvist  *****************************************************************************/
1510174267aSFredrik Holmqvist 
1520174267aSFredrik Holmqvist #include "acpi.h"
1530174267aSFredrik Holmqvist #include "accommon.h"
1540174267aSFredrik Holmqvist #include "acparser.h"
1550174267aSFredrik Holmqvist #include "acinterp.h"
1560174267aSFredrik Holmqvist #include "acevents.h"
1570174267aSFredrik Holmqvist #include "amlcode.h"
1580174267aSFredrik Holmqvist 
1590174267aSFredrik Holmqvist 
1600174267aSFredrik Holmqvist #define _COMPONENT          ACPI_EXECUTER
1610174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("exoparg2")
1620174267aSFredrik Holmqvist 
1630174267aSFredrik Holmqvist 
1640174267aSFredrik Holmqvist /*!
1650174267aSFredrik Holmqvist  * Naming convention for AML interpreter execution routines.
1660174267aSFredrik Holmqvist  *
1670174267aSFredrik Holmqvist  * The routines that begin execution of AML opcodes are named with a common
1680174267aSFredrik Holmqvist  * convention based upon the number of arguments, the number of target operands,
1690174267aSFredrik Holmqvist  * and whether or not a value is returned:
1700174267aSFredrik Holmqvist  *
1710174267aSFredrik Holmqvist  *      AcpiExOpcode_xA_yT_zR
1720174267aSFredrik Holmqvist  *
1730174267aSFredrik Holmqvist  * Where:
1740174267aSFredrik Holmqvist  *
1750174267aSFredrik Holmqvist  * xA - ARGUMENTS:    The number of arguments (input operands) that are
1760174267aSFredrik Holmqvist  *                    required for this opcode type (1 through 6 args).
1770174267aSFredrik Holmqvist  * yT - TARGETS:      The number of targets (output operands) that are required
1780174267aSFredrik Holmqvist  *                    for this opcode type (0, 1, or 2 targets).
1790174267aSFredrik Holmqvist  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
1800174267aSFredrik Holmqvist  *                    as the function return (0 or 1).
1810174267aSFredrik Holmqvist  *
1820174267aSFredrik Holmqvist  * The AcpiExOpcode* functions are called via the Dispatcher component with
1830174267aSFredrik Holmqvist  * fully resolved operands.
1840174267aSFredrik Holmqvist !*/
1850174267aSFredrik Holmqvist 
1860174267aSFredrik Holmqvist 
1870174267aSFredrik Holmqvist /*******************************************************************************
1880174267aSFredrik Holmqvist  *
1890174267aSFredrik Holmqvist  * FUNCTION:    AcpiExOpcode_2A_0T_0R
1900174267aSFredrik Holmqvist  *
1910174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current walk state
1920174267aSFredrik Holmqvist  *
1930174267aSFredrik Holmqvist  * RETURN:      Status
1940174267aSFredrik Holmqvist  *
1950174267aSFredrik Holmqvist  * DESCRIPTION: Execute opcode with two arguments, no target, and no return
1960174267aSFredrik Holmqvist  *              value.
1970174267aSFredrik Holmqvist  *
1980174267aSFredrik Holmqvist  * ALLOCATION:  Deletes both operands
1990174267aSFredrik Holmqvist  *
2000174267aSFredrik Holmqvist  ******************************************************************************/
2010174267aSFredrik Holmqvist 
2020174267aSFredrik Holmqvist ACPI_STATUS
AcpiExOpcode_2A_0T_0R(ACPI_WALK_STATE * WalkState)2030174267aSFredrik Holmqvist AcpiExOpcode_2A_0T_0R (
2040174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
2050174267aSFredrik Holmqvist {
2060174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
2070174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *Node;
2080174267aSFredrik Holmqvist     UINT32                  Value;
2090174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
2100174267aSFredrik Holmqvist 
2110174267aSFredrik Holmqvist 
2120174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_0R,
2130174267aSFredrik Holmqvist             AcpiPsGetOpcodeName (WalkState->Opcode));
2140174267aSFredrik Holmqvist 
2150174267aSFredrik Holmqvist 
2160174267aSFredrik Holmqvist     /* Examine the opcode */
2170174267aSFredrik Holmqvist 
2180174267aSFredrik Holmqvist     switch (WalkState->Opcode)
2190174267aSFredrik Holmqvist     {
2200174267aSFredrik Holmqvist     case AML_NOTIFY_OP:         /* Notify (NotifyObject, NotifyValue) */
2210174267aSFredrik Holmqvist 
2220174267aSFredrik Holmqvist         /* The first operand is a namespace node */
2230174267aSFredrik Holmqvist 
2240174267aSFredrik Holmqvist         Node = (ACPI_NAMESPACE_NODE *) Operand[0];
2250174267aSFredrik Holmqvist 
2260174267aSFredrik Holmqvist         /* Second value is the notify value */
2270174267aSFredrik Holmqvist 
2280174267aSFredrik Holmqvist         Value = (UINT32) Operand[1]->Integer.Value;
2290174267aSFredrik Holmqvist 
2300174267aSFredrik Holmqvist         /* Are notifies allowed on this object? */
2310174267aSFredrik Holmqvist 
2320174267aSFredrik Holmqvist         if (!AcpiEvIsNotifyObject (Node))
2330174267aSFredrik Holmqvist         {
2340174267aSFredrik Holmqvist             ACPI_ERROR ((AE_INFO,
2350174267aSFredrik Holmqvist                 "Unexpected notify object type [%s]",
2360174267aSFredrik Holmqvist                 AcpiUtGetTypeName (Node->Type)));
2370174267aSFredrik Holmqvist 
2380174267aSFredrik Holmqvist             Status = AE_AML_OPERAND_TYPE;
2390174267aSFredrik Holmqvist             break;
2400174267aSFredrik Holmqvist         }
2410174267aSFredrik Holmqvist 
2420174267aSFredrik Holmqvist         /*
2430174267aSFredrik Holmqvist          * Dispatch the notify to the appropriate handler
2440174267aSFredrik Holmqvist          * NOTE: the request is queued for execution after this method
2450174267aSFredrik Holmqvist          * completes. The notify handlers are NOT invoked synchronously
2460174267aSFredrik Holmqvist          * from this thread -- because handlers may in turn run other
2470174267aSFredrik Holmqvist          * control methods.
2480174267aSFredrik Holmqvist          */
2490174267aSFredrik Holmqvist         Status = AcpiEvQueueNotifyRequest (Node, Value);
2500174267aSFredrik Holmqvist         break;
2510174267aSFredrik Holmqvist 
2520174267aSFredrik Holmqvist     default:
2530174267aSFredrik Holmqvist 
2540174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
2550174267aSFredrik Holmqvist             WalkState->Opcode));
2560174267aSFredrik Holmqvist         Status = AE_AML_BAD_OPCODE;
2570174267aSFredrik Holmqvist     }
2580174267aSFredrik Holmqvist 
2590174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
2600174267aSFredrik Holmqvist }
2610174267aSFredrik Holmqvist 
2620174267aSFredrik Holmqvist 
2630174267aSFredrik Holmqvist /*******************************************************************************
2640174267aSFredrik Holmqvist  *
2650174267aSFredrik Holmqvist  * FUNCTION:    AcpiExOpcode_2A_2T_1R
2660174267aSFredrik Holmqvist  *
2670174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current walk state
2680174267aSFredrik Holmqvist  *
2690174267aSFredrik Holmqvist  * RETURN:      Status
2700174267aSFredrik Holmqvist  *
2710174267aSFredrik Holmqvist  * DESCRIPTION: Execute a dyadic operator (2 operands) with 2 output targets
2720174267aSFredrik Holmqvist  *              and one implicit return value.
2730174267aSFredrik Holmqvist  *
2740174267aSFredrik Holmqvist  ******************************************************************************/
2750174267aSFredrik Holmqvist 
2760174267aSFredrik Holmqvist ACPI_STATUS
AcpiExOpcode_2A_2T_1R(ACPI_WALK_STATE * WalkState)2770174267aSFredrik Holmqvist AcpiExOpcode_2A_2T_1R (
2780174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
2790174267aSFredrik Holmqvist {
2800174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
2810174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ReturnDesc1 = NULL;
2820174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ReturnDesc2 = NULL;
2830174267aSFredrik Holmqvist     ACPI_STATUS             Status;
2840174267aSFredrik Holmqvist 
2850174267aSFredrik Holmqvist 
2860174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_2T_1R,
2870174267aSFredrik Holmqvist         AcpiPsGetOpcodeName (WalkState->Opcode));
2880174267aSFredrik Holmqvist 
2890174267aSFredrik Holmqvist 
2900174267aSFredrik Holmqvist     /* Execute the opcode */
2910174267aSFredrik Holmqvist 
2920174267aSFredrik Holmqvist     switch (WalkState->Opcode)
2930174267aSFredrik Holmqvist     {
2940174267aSFredrik Holmqvist     case AML_DIVIDE_OP:
2950174267aSFredrik Holmqvist 
2960174267aSFredrik Holmqvist         /* Divide (Dividend, Divisor, RemainderResult QuotientResult) */
2970174267aSFredrik Holmqvist 
2980174267aSFredrik Holmqvist         ReturnDesc1 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
2990174267aSFredrik Holmqvist         if (!ReturnDesc1)
3000174267aSFredrik Holmqvist         {
3010174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
3020174267aSFredrik Holmqvist             goto Cleanup;
3030174267aSFredrik Holmqvist         }
3040174267aSFredrik Holmqvist 
3050174267aSFredrik Holmqvist         ReturnDesc2 = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
3060174267aSFredrik Holmqvist         if (!ReturnDesc2)
3070174267aSFredrik Holmqvist         {
3080174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
3090174267aSFredrik Holmqvist             goto Cleanup;
3100174267aSFredrik Holmqvist         }
3110174267aSFredrik Holmqvist 
3120174267aSFredrik Holmqvist         /* Quotient to ReturnDesc1, remainder to ReturnDesc2 */
3130174267aSFredrik Holmqvist 
314b64e8511SFredrik Holmqvist         Status = AcpiUtDivide (
315b64e8511SFredrik Holmqvist             Operand[0]->Integer.Value,
3160174267aSFredrik Holmqvist             Operand[1]->Integer.Value,
3170174267aSFredrik Holmqvist             &ReturnDesc1->Integer.Value,
3180174267aSFredrik Holmqvist             &ReturnDesc2->Integer.Value);
3190174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
3200174267aSFredrik Holmqvist         {
3210174267aSFredrik Holmqvist             goto Cleanup;
3220174267aSFredrik Holmqvist         }
3230174267aSFredrik Holmqvist         break;
3240174267aSFredrik Holmqvist 
3250174267aSFredrik Holmqvist     default:
3260174267aSFredrik Holmqvist 
3270174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
3280174267aSFredrik Holmqvist             WalkState->Opcode));
329b64e8511SFredrik Holmqvist 
3300174267aSFredrik Holmqvist         Status = AE_AML_BAD_OPCODE;
3310174267aSFredrik Holmqvist         goto Cleanup;
3320174267aSFredrik Holmqvist     }
3330174267aSFredrik Holmqvist 
3340174267aSFredrik Holmqvist     /* Store the results to the target reference operands */
3350174267aSFredrik Holmqvist 
3360174267aSFredrik Holmqvist     Status = AcpiExStore (ReturnDesc2, Operand[2], WalkState);
3370174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3380174267aSFredrik Holmqvist     {
3390174267aSFredrik Holmqvist         goto Cleanup;
3400174267aSFredrik Holmqvist     }
3410174267aSFredrik Holmqvist 
3420174267aSFredrik Holmqvist     Status = AcpiExStore (ReturnDesc1, Operand[3], WalkState);
3430174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3440174267aSFredrik Holmqvist     {
3450174267aSFredrik Holmqvist         goto Cleanup;
3460174267aSFredrik Holmqvist     }
3470174267aSFredrik Holmqvist 
3480174267aSFredrik Holmqvist Cleanup:
3490174267aSFredrik Holmqvist     /*
3500174267aSFredrik Holmqvist      * Since the remainder is not returned indirectly, remove a reference to
3510174267aSFredrik Holmqvist      * it. Only the quotient is returned indirectly.
3520174267aSFredrik Holmqvist      */
3530174267aSFredrik Holmqvist     AcpiUtRemoveReference (ReturnDesc2);
3540174267aSFredrik Holmqvist 
3550174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3560174267aSFredrik Holmqvist     {
3570174267aSFredrik Holmqvist         /* Delete the return object */
3580174267aSFredrik Holmqvist 
3590174267aSFredrik Holmqvist         AcpiUtRemoveReference (ReturnDesc1);
3600174267aSFredrik Holmqvist     }
3610174267aSFredrik Holmqvist 
3620174267aSFredrik Holmqvist     /* Save return object (the remainder) on success */
3630174267aSFredrik Holmqvist 
3640174267aSFredrik Holmqvist     else
3650174267aSFredrik Holmqvist     {
3660174267aSFredrik Holmqvist         WalkState->ResultObj = ReturnDesc1;
3670174267aSFredrik Holmqvist     }
3680174267aSFredrik Holmqvist 
3690174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
3700174267aSFredrik Holmqvist }
3710174267aSFredrik Holmqvist 
3720174267aSFredrik Holmqvist 
3730174267aSFredrik Holmqvist /*******************************************************************************
3740174267aSFredrik Holmqvist  *
3750174267aSFredrik Holmqvist  * FUNCTION:    AcpiExOpcode_2A_1T_1R
3760174267aSFredrik Holmqvist  *
3770174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current walk state
3780174267aSFredrik Holmqvist  *
3790174267aSFredrik Holmqvist  * RETURN:      Status
3800174267aSFredrik Holmqvist  *
3810174267aSFredrik Holmqvist  * DESCRIPTION: Execute opcode with two arguments, one target, and a return
3820174267aSFredrik Holmqvist  *              value.
3830174267aSFredrik Holmqvist  *
3840174267aSFredrik Holmqvist  ******************************************************************************/
3850174267aSFredrik Holmqvist 
3860174267aSFredrik Holmqvist ACPI_STATUS
AcpiExOpcode_2A_1T_1R(ACPI_WALK_STATE * WalkState)3870174267aSFredrik Holmqvist AcpiExOpcode_2A_1T_1R (
3880174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
3890174267aSFredrik Holmqvist {
3900174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
3910174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
3920174267aSFredrik Holmqvist     UINT64                  Index;
3930174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
394c70258b7SJérôme Duval     ACPI_SIZE               Length = 0;
3950174267aSFredrik Holmqvist 
3960174267aSFredrik Holmqvist 
3970174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_1T_1R,
3980174267aSFredrik Holmqvist         AcpiPsGetOpcodeName (WalkState->Opcode));
3990174267aSFredrik Holmqvist 
4000174267aSFredrik Holmqvist 
4010174267aSFredrik Holmqvist     /* Execute the opcode */
4020174267aSFredrik Holmqvist 
4030174267aSFredrik Holmqvist     if (WalkState->OpInfo->Flags & AML_MATH)
4040174267aSFredrik Holmqvist     {
4050174267aSFredrik Holmqvist         /* All simple math opcodes (add, etc.) */
4060174267aSFredrik Holmqvist 
4070174267aSFredrik Holmqvist         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
4080174267aSFredrik Holmqvist         if (!ReturnDesc)
4090174267aSFredrik Holmqvist         {
4100174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
4110174267aSFredrik Holmqvist             goto Cleanup;
4120174267aSFredrik Holmqvist         }
4130174267aSFredrik Holmqvist 
414b64e8511SFredrik Holmqvist         ReturnDesc->Integer.Value = AcpiExDoMathOp (
415b64e8511SFredrik Holmqvist             WalkState->Opcode,
4160174267aSFredrik Holmqvist             Operand[0]->Integer.Value,
4170174267aSFredrik Holmqvist             Operand[1]->Integer.Value);
4180174267aSFredrik Holmqvist         goto StoreResultToTarget;
4190174267aSFredrik Holmqvist     }
4200174267aSFredrik Holmqvist 
4210174267aSFredrik Holmqvist     switch (WalkState->Opcode)
4220174267aSFredrik Holmqvist     {
4230174267aSFredrik Holmqvist     case AML_MOD_OP: /* Mod (Dividend, Divisor, RemainderResult (ACPI 2.0) */
4240174267aSFredrik Holmqvist 
4250174267aSFredrik Holmqvist         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
4260174267aSFredrik Holmqvist         if (!ReturnDesc)
4270174267aSFredrik Holmqvist         {
4280174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
4290174267aSFredrik Holmqvist             goto Cleanup;
4300174267aSFredrik Holmqvist         }
4310174267aSFredrik Holmqvist 
4320174267aSFredrik Holmqvist         /* ReturnDesc will contain the remainder */
4330174267aSFredrik Holmqvist 
434b64e8511SFredrik Holmqvist         Status = AcpiUtDivide (
435b64e8511SFredrik Holmqvist             Operand[0]->Integer.Value,
4360174267aSFredrik Holmqvist             Operand[1]->Integer.Value,
4370174267aSFredrik Holmqvist             NULL,
4380174267aSFredrik Holmqvist             &ReturnDesc->Integer.Value);
4390174267aSFredrik Holmqvist         break;
4400174267aSFredrik Holmqvist 
441ff2e2f81SFredrik Holmqvist     case AML_CONCATENATE_OP: /* Concatenate (Data1, Data2, Result) */
4420174267aSFredrik Holmqvist 
443b64e8511SFredrik Holmqvist         Status = AcpiExDoConcatenate (
444b64e8511SFredrik Holmqvist             Operand[0], Operand[1], &ReturnDesc, WalkState);
4450174267aSFredrik Holmqvist         break;
4460174267aSFredrik Holmqvist 
4470174267aSFredrik Holmqvist     case AML_TO_STRING_OP: /* ToString (Buffer, Length, Result) (ACPI 2.0) */
4480174267aSFredrik Holmqvist         /*
4490174267aSFredrik Holmqvist          * Input object is guaranteed to be a buffer at this point (it may have
4500174267aSFredrik Holmqvist          * been converted.)  Copy the raw buffer data to a new object of
4510174267aSFredrik Holmqvist          * type String.
4520174267aSFredrik Holmqvist          */
4530174267aSFredrik Holmqvist 
4540174267aSFredrik Holmqvist         /*
4550174267aSFredrik Holmqvist          * Get the length of the new string. It is the smallest of:
4560174267aSFredrik Holmqvist          * 1) Length of the input buffer
4570174267aSFredrik Holmqvist          * 2) Max length as specified in the ToString operator
4580174267aSFredrik Holmqvist          * 3) Length of input buffer up to a zero byte (null terminator)
4590174267aSFredrik Holmqvist          *
4600174267aSFredrik Holmqvist          * NOTE: A length of zero is ok, and will create a zero-length, null
4610174267aSFredrik Holmqvist          *       terminated string.
4620174267aSFredrik Holmqvist          */
46308c9948cSFredrik Holmqvist         while ((Length < Operand[0]->Buffer.Length) &&  /* Length of input buffer */
46408c9948cSFredrik Holmqvist                (Length < Operand[1]->Integer.Value) &&  /* Length operand */
46508c9948cSFredrik Holmqvist                (Operand[0]->Buffer.Pointer[Length]))    /* Null terminator */
4660174267aSFredrik Holmqvist         {
4670174267aSFredrik Holmqvist             Length++;
4680174267aSFredrik Holmqvist         }
4690174267aSFredrik Holmqvist 
4700174267aSFredrik Holmqvist         /* Allocate a new string object */
4710174267aSFredrik Holmqvist 
4720174267aSFredrik Holmqvist         ReturnDesc = AcpiUtCreateStringObject (Length);
4730174267aSFredrik Holmqvist         if (!ReturnDesc)
4740174267aSFredrik Holmqvist         {
4750174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
4760174267aSFredrik Holmqvist             goto Cleanup;
4770174267aSFredrik Holmqvist         }
4780174267aSFredrik Holmqvist 
4790174267aSFredrik Holmqvist         /*
4800174267aSFredrik Holmqvist          * Copy the raw buffer data with no transform.
4810174267aSFredrik Holmqvist          * (NULL terminated already)
4820174267aSFredrik Holmqvist          */
483e226d1d0SFredrik Holmqvist         memcpy (ReturnDesc->String.Pointer,
4840174267aSFredrik Holmqvist             Operand[0]->Buffer.Pointer, Length);
4850174267aSFredrik Holmqvist         break;
4860174267aSFredrik Holmqvist 
487ff2e2f81SFredrik Holmqvist     case AML_CONCATENATE_TEMPLATE_OP:
4880174267aSFredrik Holmqvist 
4890174267aSFredrik Holmqvist         /* ConcatenateResTemplate (Buffer, Buffer, Result) (ACPI 2.0) */
4900174267aSFredrik Holmqvist 
491b64e8511SFredrik Holmqvist         Status = AcpiExConcatTemplate (
492b64e8511SFredrik Holmqvist             Operand[0], Operand[1], &ReturnDesc, WalkState);
4930174267aSFredrik Holmqvist         break;
4940174267aSFredrik Holmqvist 
4950174267aSFredrik Holmqvist     case AML_INDEX_OP:              /* Index (Source Index Result) */
4960174267aSFredrik Holmqvist 
4970174267aSFredrik Holmqvist         /* Create the internal return object */
4980174267aSFredrik Holmqvist 
4990174267aSFredrik Holmqvist         ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
5000174267aSFredrik Holmqvist         if (!ReturnDesc)
5010174267aSFredrik Holmqvist         {
5020174267aSFredrik Holmqvist             Status = AE_NO_MEMORY;
5030174267aSFredrik Holmqvist             goto Cleanup;
5040174267aSFredrik Holmqvist         }
5050174267aSFredrik Holmqvist 
5060174267aSFredrik Holmqvist         /* Initialize the Index reference object */
5070174267aSFredrik Holmqvist 
5080174267aSFredrik Holmqvist         Index = Operand[1]->Integer.Value;
5090174267aSFredrik Holmqvist         ReturnDesc->Reference.Value = (UINT32) Index;
5100174267aSFredrik Holmqvist         ReturnDesc->Reference.Class = ACPI_REFCLASS_INDEX;
5110174267aSFredrik Holmqvist 
5120174267aSFredrik Holmqvist         /*
5130174267aSFredrik Holmqvist          * At this point, the Source operand is a String, Buffer, or Package.
5140174267aSFredrik Holmqvist          * Verify that the index is within range.
5150174267aSFredrik Holmqvist          */
5160174267aSFredrik Holmqvist         switch ((Operand[0])->Common.Type)
5170174267aSFredrik Holmqvist         {
5180174267aSFredrik Holmqvist         case ACPI_TYPE_STRING:
5190174267aSFredrik Holmqvist 
5200174267aSFredrik Holmqvist             if (Index >= Operand[0]->String.Length)
5210174267aSFredrik Holmqvist             {
522c70258b7SJérôme Duval                 Length = Operand[0]->String.Length;
5230174267aSFredrik Holmqvist                 Status = AE_AML_STRING_LIMIT;
5240174267aSFredrik Holmqvist             }
5250174267aSFredrik Holmqvist 
5260174267aSFredrik Holmqvist             ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
527e226d1d0SFredrik Holmqvist             ReturnDesc->Reference.IndexPointer =
528e226d1d0SFredrik Holmqvist                 &(Operand[0]->Buffer.Pointer [Index]);
5290174267aSFredrik Holmqvist             break;
5300174267aSFredrik Holmqvist 
5310174267aSFredrik Holmqvist         case ACPI_TYPE_BUFFER:
5320174267aSFredrik Holmqvist 
5330174267aSFredrik Holmqvist             if (Index >= Operand[0]->Buffer.Length)
5340174267aSFredrik Holmqvist             {
535c70258b7SJérôme Duval                 Length = Operand[0]->Buffer.Length;
5360174267aSFredrik Holmqvist                 Status = AE_AML_BUFFER_LIMIT;
5370174267aSFredrik Holmqvist             }
5380174267aSFredrik Holmqvist 
5390174267aSFredrik Holmqvist             ReturnDesc->Reference.TargetType = ACPI_TYPE_BUFFER_FIELD;
540e226d1d0SFredrik Holmqvist             ReturnDesc->Reference.IndexPointer =
541e226d1d0SFredrik Holmqvist                 &(Operand[0]->Buffer.Pointer [Index]);
5420174267aSFredrik Holmqvist             break;
5430174267aSFredrik Holmqvist 
5440174267aSFredrik Holmqvist         case ACPI_TYPE_PACKAGE:
5450174267aSFredrik Holmqvist 
5460174267aSFredrik Holmqvist             if (Index >= Operand[0]->Package.Count)
5470174267aSFredrik Holmqvist             {
548c70258b7SJérôme Duval                 Length = Operand[0]->Package.Count;
5490174267aSFredrik Holmqvist                 Status = AE_AML_PACKAGE_LIMIT;
5500174267aSFredrik Holmqvist             }
5510174267aSFredrik Holmqvist 
5520174267aSFredrik Holmqvist             ReturnDesc->Reference.TargetType = ACPI_TYPE_PACKAGE;
553e226d1d0SFredrik Holmqvist             ReturnDesc->Reference.Where =
554e226d1d0SFredrik Holmqvist                 &Operand[0]->Package.Elements [Index];
5550174267aSFredrik Holmqvist             break;
5560174267aSFredrik Holmqvist 
5570174267aSFredrik Holmqvist         default:
5580174267aSFredrik Holmqvist 
559ff2e2f81SFredrik Holmqvist             ACPI_ERROR ((AE_INFO,
560ff2e2f81SFredrik Holmqvist                 "Invalid object type: %X", (Operand[0])->Common.Type));
5610174267aSFredrik Holmqvist             Status = AE_AML_INTERNAL;
5620174267aSFredrik Holmqvist             goto Cleanup;
5630174267aSFredrik Holmqvist         }
5640174267aSFredrik Holmqvist 
5650174267aSFredrik Holmqvist         /* Failure means that the Index was beyond the end of the object */
5660174267aSFredrik Holmqvist 
5670174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
5680174267aSFredrik Holmqvist         {
5690ffed378SFredrik Holmqvist             ACPI_BIOS_EXCEPTION ((AE_INFO, Status,
570c70258b7SJérôme Duval                 "Index (0x%X%8.8X) is beyond end of object (length 0x%X)",
571c70258b7SJérôme Duval                 ACPI_FORMAT_UINT64 (Index), (UINT32) Length));
5720174267aSFredrik Holmqvist             goto Cleanup;
5730174267aSFredrik Holmqvist         }
5740174267aSFredrik Holmqvist 
5750174267aSFredrik Holmqvist         /*
5760174267aSFredrik Holmqvist          * Save the target object and add a reference to it for the life
5770174267aSFredrik Holmqvist          * of the index
5780174267aSFredrik Holmqvist          */
5790174267aSFredrik Holmqvist         ReturnDesc->Reference.Object = Operand[0];
5800174267aSFredrik Holmqvist         AcpiUtAddReference (Operand[0]);
5810174267aSFredrik Holmqvist 
5820174267aSFredrik Holmqvist         /* Store the reference to the Target */
5830174267aSFredrik Holmqvist 
5840174267aSFredrik Holmqvist         Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
5850174267aSFredrik Holmqvist 
5860174267aSFredrik Holmqvist         /* Return the reference */
5870174267aSFredrik Holmqvist 
5880174267aSFredrik Holmqvist         WalkState->ResultObj = ReturnDesc;
5890174267aSFredrik Holmqvist         goto Cleanup;
5900174267aSFredrik Holmqvist 
5910174267aSFredrik Holmqvist     default:
5920174267aSFredrik Holmqvist 
5930174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
5940174267aSFredrik Holmqvist             WalkState->Opcode));
5950174267aSFredrik Holmqvist         Status = AE_AML_BAD_OPCODE;
5960174267aSFredrik Holmqvist         break;
5970174267aSFredrik Holmqvist     }
5980174267aSFredrik Holmqvist 
5990174267aSFredrik Holmqvist 
6000174267aSFredrik Holmqvist StoreResultToTarget:
6010174267aSFredrik Holmqvist 
6020174267aSFredrik Holmqvist     if (ACPI_SUCCESS (Status))
6030174267aSFredrik Holmqvist     {
6040174267aSFredrik Holmqvist         /*
6050174267aSFredrik Holmqvist          * Store the result of the operation (which is now in ReturnDesc) into
6060174267aSFredrik Holmqvist          * the Target descriptor.
6070174267aSFredrik Holmqvist          */
6080174267aSFredrik Holmqvist         Status = AcpiExStore (ReturnDesc, Operand[2], WalkState);
6090174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
6100174267aSFredrik Holmqvist         {
6110174267aSFredrik Holmqvist             goto Cleanup;
6120174267aSFredrik Holmqvist         }
6130174267aSFredrik Holmqvist 
6140174267aSFredrik Holmqvist         if (!WalkState->ResultObj)
6150174267aSFredrik Holmqvist         {
6160174267aSFredrik Holmqvist             WalkState->ResultObj = ReturnDesc;
6170174267aSFredrik Holmqvist         }
6180174267aSFredrik Holmqvist     }
6190174267aSFredrik Holmqvist 
6200174267aSFredrik Holmqvist 
6210174267aSFredrik Holmqvist Cleanup:
6220174267aSFredrik Holmqvist 
6230174267aSFredrik Holmqvist     /* Delete return object on error */
6240174267aSFredrik Holmqvist 
6250174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
6260174267aSFredrik Holmqvist     {
6270174267aSFredrik Holmqvist         AcpiUtRemoveReference (ReturnDesc);
6280174267aSFredrik Holmqvist         WalkState->ResultObj = NULL;
6290174267aSFredrik Holmqvist     }
6300174267aSFredrik Holmqvist 
6310174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
6320174267aSFredrik Holmqvist }
6330174267aSFredrik Holmqvist 
6340174267aSFredrik Holmqvist 
6350174267aSFredrik Holmqvist /*******************************************************************************
6360174267aSFredrik Holmqvist  *
6370174267aSFredrik Holmqvist  * FUNCTION:    AcpiExOpcode_2A_0T_1R
6380174267aSFredrik Holmqvist  *
6390174267aSFredrik Holmqvist  * PARAMETERS:  WalkState           - Current walk state
6400174267aSFredrik Holmqvist  *
6410174267aSFredrik Holmqvist  * RETURN:      Status
6420174267aSFredrik Holmqvist  *
6430174267aSFredrik Holmqvist  * DESCRIPTION: Execute opcode with 2 arguments, no target, and a return value
6440174267aSFredrik Holmqvist  *
6450174267aSFredrik Holmqvist  ******************************************************************************/
6460174267aSFredrik Holmqvist 
6470174267aSFredrik Holmqvist ACPI_STATUS
AcpiExOpcode_2A_0T_1R(ACPI_WALK_STATE * WalkState)6480174267aSFredrik Holmqvist AcpiExOpcode_2A_0T_1R (
6490174267aSFredrik Holmqvist     ACPI_WALK_STATE         *WalkState)
6500174267aSFredrik Holmqvist {
6510174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
6520174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
6530174267aSFredrik Holmqvist     ACPI_STATUS             Status = AE_OK;
6540174267aSFredrik Holmqvist     BOOLEAN                 LogicalResult = FALSE;
6550174267aSFredrik Holmqvist 
6560174267aSFredrik Holmqvist 
6570174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE_STR (ExOpcode_2A_0T_1R,
6580174267aSFredrik Holmqvist         AcpiPsGetOpcodeName (WalkState->Opcode));
6590174267aSFredrik Holmqvist 
6600174267aSFredrik Holmqvist 
6610174267aSFredrik Holmqvist     /* Create the internal return object */
6620174267aSFredrik Holmqvist 
6630174267aSFredrik Holmqvist     ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
6640174267aSFredrik Holmqvist     if (!ReturnDesc)
6650174267aSFredrik Holmqvist     {
6660174267aSFredrik Holmqvist         Status = AE_NO_MEMORY;
6670174267aSFredrik Holmqvist         goto Cleanup;
6680174267aSFredrik Holmqvist     }
6690174267aSFredrik Holmqvist 
6700174267aSFredrik Holmqvist     /* Execute the Opcode */
6710174267aSFredrik Holmqvist 
6720174267aSFredrik Holmqvist     if (WalkState->OpInfo->Flags & AML_LOGICAL_NUMERIC)
6730174267aSFredrik Holmqvist     {
6740174267aSFredrik Holmqvist         /* LogicalOp  (Operand0, Operand1) */
6750174267aSFredrik Holmqvist 
6760174267aSFredrik Holmqvist         Status = AcpiExDoLogicalNumericOp (WalkState->Opcode,
6770174267aSFredrik Holmqvist             Operand[0]->Integer.Value, Operand[1]->Integer.Value,
6780174267aSFredrik Holmqvist             &LogicalResult);
6790174267aSFredrik Holmqvist         goto StoreLogicalResult;
6800174267aSFredrik Holmqvist     }
6810174267aSFredrik Holmqvist     else if (WalkState->OpInfo->Flags & AML_LOGICAL)
6820174267aSFredrik Holmqvist     {
6830174267aSFredrik Holmqvist         /* LogicalOp  (Operand0, Operand1) */
6840174267aSFredrik Holmqvist 
6850174267aSFredrik Holmqvist         Status = AcpiExDoLogicalOp (WalkState->Opcode, Operand[0],
6860174267aSFredrik Holmqvist             Operand[1], &LogicalResult);
6870174267aSFredrik Holmqvist         goto StoreLogicalResult;
6880174267aSFredrik Holmqvist     }
6890174267aSFredrik Holmqvist 
6900174267aSFredrik Holmqvist     switch (WalkState->Opcode)
6910174267aSFredrik Holmqvist     {
6920174267aSFredrik Holmqvist     case AML_ACQUIRE_OP:            /* Acquire (MutexObject, Timeout) */
6930174267aSFredrik Holmqvist 
6940174267aSFredrik Holmqvist         Status = AcpiExAcquireMutex (Operand[1], Operand[0], WalkState);
6950174267aSFredrik Holmqvist         if (Status == AE_TIME)
6960174267aSFredrik Holmqvist         {
6970174267aSFredrik Holmqvist             LogicalResult = TRUE;       /* TRUE = Acquire timed out */
6980174267aSFredrik Holmqvist             Status = AE_OK;
6990174267aSFredrik Holmqvist         }
7000174267aSFredrik Holmqvist         break;
7010174267aSFredrik Holmqvist 
7020174267aSFredrik Holmqvist 
7030174267aSFredrik Holmqvist     case AML_WAIT_OP:               /* Wait (EventObject, Timeout) */
7040174267aSFredrik Holmqvist 
7050174267aSFredrik Holmqvist         Status = AcpiExSystemWaitEvent (Operand[1], Operand[0]);
7060174267aSFredrik Holmqvist         if (Status == AE_TIME)
7070174267aSFredrik Holmqvist         {
7080174267aSFredrik Holmqvist             LogicalResult = TRUE;       /* TRUE, Wait timed out */
7090174267aSFredrik Holmqvist             Status = AE_OK;
7100174267aSFredrik Holmqvist         }
7110174267aSFredrik Holmqvist         break;
7120174267aSFredrik Holmqvist 
7130174267aSFredrik Holmqvist     default:
7140174267aSFredrik Holmqvist 
7150174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
7160174267aSFredrik Holmqvist             WalkState->Opcode));
717b64e8511SFredrik Holmqvist 
7180174267aSFredrik Holmqvist         Status = AE_AML_BAD_OPCODE;
7190174267aSFredrik Holmqvist         goto Cleanup;
7200174267aSFredrik Holmqvist     }
7210174267aSFredrik Holmqvist 
7220174267aSFredrik Holmqvist 
7230174267aSFredrik Holmqvist StoreLogicalResult:
7240174267aSFredrik Holmqvist     /*
7250174267aSFredrik Holmqvist      * Set return value to according to LogicalResult. logical TRUE (all ones)
7260174267aSFredrik Holmqvist      * Default is FALSE (zero)
7270174267aSFredrik Holmqvist      */
7280174267aSFredrik Holmqvist     if (LogicalResult)
7290174267aSFredrik Holmqvist     {
7300174267aSFredrik Holmqvist         ReturnDesc->Integer.Value = ACPI_UINT64_MAX;
7310174267aSFredrik Holmqvist     }
7320174267aSFredrik Holmqvist 
7330174267aSFredrik Holmqvist Cleanup:
7340174267aSFredrik Holmqvist 
7350174267aSFredrik Holmqvist     /* Delete return object on error */
7360174267aSFredrik Holmqvist 
7370174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
7380174267aSFredrik Holmqvist     {
7390174267aSFredrik Holmqvist         AcpiUtRemoveReference (ReturnDesc);
7400174267aSFredrik Holmqvist     }
7410174267aSFredrik Holmqvist 
7420174267aSFredrik Holmqvist     /* Save return object on success */
7430174267aSFredrik Holmqvist 
7440174267aSFredrik Holmqvist     else
7450174267aSFredrik Holmqvist     {
7460174267aSFredrik Holmqvist         WalkState->ResultObj = ReturnDesc;
7470174267aSFredrik Holmqvist     }
7480174267aSFredrik Holmqvist 
7490174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
7500174267aSFredrik Holmqvist }
751