Home | History | Annotate | Line # | Download | only in executer
exmisc.c revision 1.1.1.3
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3      1.1    jruoho  * Module Name: exmisc - ACPI AML (p-code) execution - specific opcodes
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.3  christos  * Copyright (C) 2000 - 2013, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #define __EXMISC_C__
     45      1.1    jruoho 
     46      1.1    jruoho #include "acpi.h"
     47      1.1    jruoho #include "accommon.h"
     48      1.1    jruoho #include "acinterp.h"
     49      1.1    jruoho #include "amlcode.h"
     50      1.1    jruoho #include "amlresrc.h"
     51      1.1    jruoho 
     52      1.1    jruoho 
     53      1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     54      1.1    jruoho         ACPI_MODULE_NAME    ("exmisc")
     55      1.1    jruoho 
     56      1.1    jruoho 
     57      1.1    jruoho /*******************************************************************************
     58      1.1    jruoho  *
     59      1.1    jruoho  * FUNCTION:    AcpiExGetObjectReference
     60      1.1    jruoho  *
     61      1.1    jruoho  * PARAMETERS:  ObjDesc             - Create a reference to this object
     62      1.1    jruoho  *              ReturnDesc          - Where to store the reference
     63      1.1    jruoho  *              WalkState           - Current state
     64      1.1    jruoho  *
     65      1.1    jruoho  * RETURN:      Status
     66      1.1    jruoho  *
     67      1.1    jruoho  * DESCRIPTION: Obtain and return a "reference" to the target object
     68      1.1    jruoho  *              Common code for the RefOfOp and the CondRefOfOp.
     69      1.1    jruoho  *
     70      1.1    jruoho  ******************************************************************************/
     71      1.1    jruoho 
     72      1.1    jruoho ACPI_STATUS
     73      1.1    jruoho AcpiExGetObjectReference (
     74      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc,
     75      1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnDesc,
     76      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
     77      1.1    jruoho {
     78      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReferenceObj;
     79      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReferencedObj;
     80      1.1    jruoho 
     81      1.1    jruoho 
     82      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (ExGetObjectReference, ObjDesc);
     83      1.1    jruoho 
     84      1.1    jruoho 
     85      1.1    jruoho     *ReturnDesc = NULL;
     86      1.1    jruoho 
     87      1.1    jruoho     switch (ACPI_GET_DESCRIPTOR_TYPE (ObjDesc))
     88      1.1    jruoho     {
     89      1.1    jruoho     case ACPI_DESC_TYPE_OPERAND:
     90      1.1    jruoho 
     91      1.1    jruoho         if (ObjDesc->Common.Type != ACPI_TYPE_LOCAL_REFERENCE)
     92      1.1    jruoho         {
     93      1.1    jruoho             return_ACPI_STATUS (AE_AML_OPERAND_TYPE);
     94      1.1    jruoho         }
     95      1.1    jruoho 
     96      1.1    jruoho         /*
     97      1.1    jruoho          * Must be a reference to a Local or Arg
     98      1.1    jruoho          */
     99      1.1    jruoho         switch (ObjDesc->Reference.Class)
    100      1.1    jruoho         {
    101      1.1    jruoho         case ACPI_REFCLASS_LOCAL:
    102      1.1    jruoho         case ACPI_REFCLASS_ARG:
    103      1.1    jruoho         case ACPI_REFCLASS_DEBUG:
    104      1.1    jruoho 
    105      1.1    jruoho             /* The referenced object is the pseudo-node for the local/arg */
    106      1.1    jruoho 
    107      1.1    jruoho             ReferencedObj = ObjDesc->Reference.Object;
    108      1.1    jruoho             break;
    109      1.1    jruoho 
    110      1.1    jruoho         default:
    111      1.1    jruoho 
    112      1.1    jruoho             ACPI_ERROR ((AE_INFO, "Unknown Reference Class 0x%2.2X",
    113      1.1    jruoho                 ObjDesc->Reference.Class));
    114      1.1    jruoho             return_ACPI_STATUS (AE_AML_INTERNAL);
    115      1.1    jruoho         }
    116      1.1    jruoho         break;
    117      1.1    jruoho 
    118      1.1    jruoho     case ACPI_DESC_TYPE_NAMED:
    119      1.1    jruoho         /*
    120      1.1    jruoho          * A named reference that has already been resolved to a Node
    121      1.1    jruoho          */
    122      1.1    jruoho         ReferencedObj = ObjDesc;
    123      1.1    jruoho         break;
    124      1.1    jruoho 
    125      1.1    jruoho     default:
    126      1.1    jruoho 
    127      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid descriptor type 0x%X",
    128      1.1    jruoho             ACPI_GET_DESCRIPTOR_TYPE (ObjDesc)));
    129      1.1    jruoho         return_ACPI_STATUS (AE_TYPE);
    130      1.1    jruoho     }
    131      1.1    jruoho 
    132      1.1    jruoho 
    133      1.1    jruoho     /* Create a new reference object */
    134      1.1    jruoho 
    135      1.1    jruoho     ReferenceObj = AcpiUtCreateInternalObject (ACPI_TYPE_LOCAL_REFERENCE);
    136      1.1    jruoho     if (!ReferenceObj)
    137      1.1    jruoho     {
    138      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    139      1.1    jruoho     }
    140      1.1    jruoho 
    141      1.1    jruoho     ReferenceObj->Reference.Class = ACPI_REFCLASS_REFOF;
    142      1.1    jruoho     ReferenceObj->Reference.Object = ReferencedObj;
    143      1.1    jruoho     *ReturnDesc = ReferenceObj;
    144      1.1    jruoho 
    145      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
    146      1.1    jruoho         "Object %p Type [%s], returning Reference %p\n",
    147      1.1    jruoho         ObjDesc, AcpiUtGetObjectTypeName (ObjDesc), *ReturnDesc));
    148      1.1    jruoho 
    149      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    150      1.1    jruoho }
    151      1.1    jruoho 
    152      1.1    jruoho 
    153      1.1    jruoho /*******************************************************************************
    154      1.1    jruoho  *
    155      1.1    jruoho  * FUNCTION:    AcpiExConcatTemplate
    156      1.1    jruoho  *
    157      1.1    jruoho  * PARAMETERS:  Operand0            - First source object
    158      1.1    jruoho  *              Operand1            - Second source object
    159      1.1    jruoho  *              ActualReturnDesc    - Where to place the return object
    160      1.1    jruoho  *              WalkState           - Current walk state
    161      1.1    jruoho  *
    162      1.1    jruoho  * RETURN:      Status
    163      1.1    jruoho  *
    164      1.1    jruoho  * DESCRIPTION: Concatenate two resource templates
    165      1.1    jruoho  *
    166      1.1    jruoho  ******************************************************************************/
    167      1.1    jruoho 
    168      1.1    jruoho ACPI_STATUS
    169      1.1    jruoho AcpiExConcatTemplate (
    170      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    171      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    172      1.1    jruoho     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
    173      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    174      1.1    jruoho {
    175      1.1    jruoho     ACPI_STATUS             Status;
    176      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc;
    177      1.1    jruoho     UINT8                   *NewBuf;
    178      1.1    jruoho     UINT8                   *EndTag;
    179      1.1    jruoho     ACPI_SIZE               Length0;
    180      1.1    jruoho     ACPI_SIZE               Length1;
    181      1.1    jruoho     ACPI_SIZE               NewLength;
    182      1.1    jruoho 
    183      1.1    jruoho 
    184      1.1    jruoho     ACPI_FUNCTION_TRACE (ExConcatTemplate);
    185      1.1    jruoho 
    186      1.1    jruoho 
    187      1.1    jruoho     /*
    188      1.1    jruoho      * Find the EndTag descriptor in each resource template.
    189      1.1    jruoho      * Note1: returned pointers point TO the EndTag, not past it.
    190      1.1    jruoho      * Note2: zero-length buffers are allowed; treated like one EndTag
    191      1.1    jruoho      */
    192      1.1    jruoho 
    193      1.1    jruoho     /* Get the length of the first resource template */
    194      1.1    jruoho 
    195      1.1    jruoho     Status = AcpiUtGetResourceEndTag (Operand0, &EndTag);
    196      1.1    jruoho     if (ACPI_FAILURE (Status))
    197      1.1    jruoho     {
    198      1.1    jruoho         return_ACPI_STATUS (Status);
    199      1.1    jruoho     }
    200      1.1    jruoho 
    201      1.1    jruoho     Length0 = ACPI_PTR_DIFF (EndTag, Operand0->Buffer.Pointer);
    202      1.1    jruoho 
    203      1.1    jruoho     /* Get the length of the second resource template */
    204      1.1    jruoho 
    205      1.1    jruoho     Status = AcpiUtGetResourceEndTag (Operand1, &EndTag);
    206      1.1    jruoho     if (ACPI_FAILURE (Status))
    207      1.1    jruoho     {
    208      1.1    jruoho         return_ACPI_STATUS (Status);
    209      1.1    jruoho     }
    210      1.1    jruoho 
    211      1.1    jruoho     Length1 = ACPI_PTR_DIFF (EndTag, Operand1->Buffer.Pointer);
    212      1.1    jruoho 
    213      1.1    jruoho     /* Combine both lengths, minimum size will be 2 for EndTag */
    214      1.1    jruoho 
    215      1.1    jruoho     NewLength = Length0 + Length1 + sizeof (AML_RESOURCE_END_TAG);
    216      1.1    jruoho 
    217      1.1    jruoho     /* Create a new buffer object for the result (with one EndTag) */
    218      1.1    jruoho 
    219      1.1    jruoho     ReturnDesc = AcpiUtCreateBufferObject (NewLength);
    220      1.1    jruoho     if (!ReturnDesc)
    221      1.1    jruoho     {
    222      1.1    jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    223      1.1    jruoho     }
    224      1.1    jruoho 
    225      1.1    jruoho     /*
    226      1.1    jruoho      * Copy the templates to the new buffer, 0 first, then 1 follows. One
    227      1.1    jruoho      * EndTag descriptor is copied from Operand1.
    228      1.1    jruoho      */
    229      1.1    jruoho     NewBuf = ReturnDesc->Buffer.Pointer;
    230      1.1    jruoho     ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer, Length0);
    231      1.1    jruoho     ACPI_MEMCPY (NewBuf + Length0, Operand1->Buffer.Pointer, Length1);
    232      1.1    jruoho 
    233      1.1    jruoho     /* Insert EndTag and set the checksum to zero, means "ignore checksum" */
    234      1.1    jruoho 
    235      1.1    jruoho     NewBuf[NewLength - 1] = 0;
    236      1.1    jruoho     NewBuf[NewLength - 2] = ACPI_RESOURCE_NAME_END_TAG | 1;
    237      1.1    jruoho 
    238      1.1    jruoho     /* Return the completed resource template */
    239      1.1    jruoho 
    240      1.1    jruoho     *ActualReturnDesc = ReturnDesc;
    241      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    242      1.1    jruoho }
    243      1.1    jruoho 
    244      1.1    jruoho 
    245      1.1    jruoho /*******************************************************************************
    246      1.1    jruoho  *
    247      1.1    jruoho  * FUNCTION:    AcpiExDoConcatenate
    248      1.1    jruoho  *
    249      1.1    jruoho  * PARAMETERS:  Operand0            - First source object
    250      1.1    jruoho  *              Operand1            - Second source object
    251      1.1    jruoho  *              ActualReturnDesc    - Where to place the return object
    252      1.1    jruoho  *              WalkState           - Current walk state
    253      1.1    jruoho  *
    254      1.1    jruoho  * RETURN:      Status
    255      1.1    jruoho  *
    256      1.1    jruoho  * DESCRIPTION: Concatenate two objects OF THE SAME TYPE.
    257      1.1    jruoho  *
    258      1.1    jruoho  ******************************************************************************/
    259      1.1    jruoho 
    260      1.1    jruoho ACPI_STATUS
    261      1.1    jruoho AcpiExDoConcatenate (
    262      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    263      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    264      1.1    jruoho     ACPI_OPERAND_OBJECT     **ActualReturnDesc,
    265      1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    266      1.1    jruoho {
    267      1.1    jruoho     ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
    268      1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc;
    269      1.1    jruoho     char                    *NewBuf;
    270      1.1    jruoho     ACPI_STATUS             Status;
    271      1.1    jruoho 
    272      1.1    jruoho 
    273      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoConcatenate);
    274      1.1    jruoho 
    275      1.1    jruoho 
    276      1.1    jruoho     /*
    277  1.1.1.3  christos      * Convert the second operand if necessary. The first operand
    278      1.1    jruoho      * determines the type of the second operand, (See the Data Types
    279      1.1    jruoho      * section of the ACPI specification.)  Both object types are
    280      1.1    jruoho      * guaranteed to be either Integer/String/Buffer by the operand
    281      1.1    jruoho      * resolution mechanism.
    282      1.1    jruoho      */
    283      1.1    jruoho     switch (Operand0->Common.Type)
    284      1.1    jruoho     {
    285      1.1    jruoho     case ACPI_TYPE_INTEGER:
    286  1.1.1.3  christos 
    287      1.1    jruoho         Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
    288      1.1    jruoho         break;
    289      1.1    jruoho 
    290      1.1    jruoho     case ACPI_TYPE_STRING:
    291  1.1.1.3  christos 
    292      1.1    jruoho         Status = AcpiExConvertToString (Operand1, &LocalOperand1,
    293      1.1    jruoho                     ACPI_IMPLICIT_CONVERT_HEX);
    294      1.1    jruoho         break;
    295      1.1    jruoho 
    296      1.1    jruoho     case ACPI_TYPE_BUFFER:
    297  1.1.1.3  christos 
    298      1.1    jruoho         Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
    299      1.1    jruoho         break;
    300      1.1    jruoho 
    301      1.1    jruoho     default:
    302  1.1.1.3  christos 
    303      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    304      1.1    jruoho             Operand0->Common.Type));
    305      1.1    jruoho         Status = AE_AML_INTERNAL;
    306      1.1    jruoho     }
    307      1.1    jruoho 
    308      1.1    jruoho     if (ACPI_FAILURE (Status))
    309      1.1    jruoho     {
    310      1.1    jruoho         goto Cleanup;
    311      1.1    jruoho     }
    312      1.1    jruoho 
    313      1.1    jruoho     /*
    314      1.1    jruoho      * Both operands are now known to be the same object type
    315      1.1    jruoho      * (Both are Integer, String, or Buffer), and we can now perform the
    316      1.1    jruoho      * concatenation.
    317      1.1    jruoho      */
    318      1.1    jruoho 
    319      1.1    jruoho     /*
    320      1.1    jruoho      * There are three cases to handle:
    321      1.1    jruoho      *
    322      1.1    jruoho      * 1) Two Integers concatenated to produce a new Buffer
    323      1.1    jruoho      * 2) Two Strings concatenated to produce a new String
    324      1.1    jruoho      * 3) Two Buffers concatenated to produce a new Buffer
    325      1.1    jruoho      */
    326      1.1    jruoho     switch (Operand0->Common.Type)
    327      1.1    jruoho     {
    328      1.1    jruoho     case ACPI_TYPE_INTEGER:
    329      1.1    jruoho 
    330      1.1    jruoho         /* Result of two Integers is a Buffer */
    331      1.1    jruoho         /* Need enough buffer space for two integers */
    332      1.1    jruoho 
    333      1.1    jruoho         ReturnDesc = AcpiUtCreateBufferObject ((ACPI_SIZE)
    334      1.1    jruoho                             ACPI_MUL_2 (AcpiGbl_IntegerByteWidth));
    335      1.1    jruoho         if (!ReturnDesc)
    336      1.1    jruoho         {
    337      1.1    jruoho             Status = AE_NO_MEMORY;
    338      1.1    jruoho             goto Cleanup;
    339      1.1    jruoho         }
    340      1.1    jruoho 
    341      1.1    jruoho         NewBuf = (char *) ReturnDesc->Buffer.Pointer;
    342      1.1    jruoho 
    343      1.1    jruoho         /* Copy the first integer, LSB first */
    344      1.1    jruoho 
    345      1.1    jruoho         ACPI_MEMCPY (NewBuf, &Operand0->Integer.Value,
    346      1.1    jruoho                         AcpiGbl_IntegerByteWidth);
    347      1.1    jruoho 
    348      1.1    jruoho         /* Copy the second integer (LSB first) after the first */
    349      1.1    jruoho 
    350      1.1    jruoho         ACPI_MEMCPY (NewBuf + AcpiGbl_IntegerByteWidth,
    351      1.1    jruoho                         &LocalOperand1->Integer.Value,
    352      1.1    jruoho                         AcpiGbl_IntegerByteWidth);
    353      1.1    jruoho         break;
    354      1.1    jruoho 
    355      1.1    jruoho     case ACPI_TYPE_STRING:
    356      1.1    jruoho 
    357      1.1    jruoho         /* Result of two Strings is a String */
    358      1.1    jruoho 
    359      1.1    jruoho         ReturnDesc = AcpiUtCreateStringObject (
    360      1.1    jruoho                         ((ACPI_SIZE) Operand0->String.Length +
    361      1.1    jruoho                         LocalOperand1->String.Length));
    362      1.1    jruoho         if (!ReturnDesc)
    363      1.1    jruoho         {
    364      1.1    jruoho             Status = AE_NO_MEMORY;
    365      1.1    jruoho             goto Cleanup;
    366      1.1    jruoho         }
    367      1.1    jruoho 
    368      1.1    jruoho         NewBuf = ReturnDesc->String.Pointer;
    369      1.1    jruoho 
    370      1.1    jruoho         /* Concatenate the strings */
    371      1.1    jruoho 
    372      1.1    jruoho         ACPI_STRCPY (NewBuf, Operand0->String.Pointer);
    373      1.1    jruoho         ACPI_STRCPY (NewBuf + Operand0->String.Length,
    374      1.1    jruoho                         LocalOperand1->String.Pointer);
    375      1.1    jruoho         break;
    376      1.1    jruoho 
    377      1.1    jruoho     case ACPI_TYPE_BUFFER:
    378      1.1    jruoho 
    379      1.1    jruoho         /* Result of two Buffers is a Buffer */
    380      1.1    jruoho 
    381      1.1    jruoho         ReturnDesc = AcpiUtCreateBufferObject (
    382      1.1    jruoho                         ((ACPI_SIZE) Operand0->Buffer.Length +
    383      1.1    jruoho                         LocalOperand1->Buffer.Length));
    384      1.1    jruoho         if (!ReturnDesc)
    385      1.1    jruoho         {
    386      1.1    jruoho             Status = AE_NO_MEMORY;
    387      1.1    jruoho             goto Cleanup;
    388      1.1    jruoho         }
    389      1.1    jruoho 
    390      1.1    jruoho         NewBuf = (char *) ReturnDesc->Buffer.Pointer;
    391      1.1    jruoho 
    392      1.1    jruoho         /* Concatenate the buffers */
    393      1.1    jruoho 
    394      1.1    jruoho         ACPI_MEMCPY (NewBuf, Operand0->Buffer.Pointer,
    395      1.1    jruoho                         Operand0->Buffer.Length);
    396      1.1    jruoho         ACPI_MEMCPY (NewBuf + Operand0->Buffer.Length,
    397      1.1    jruoho                         LocalOperand1->Buffer.Pointer,
    398      1.1    jruoho                         LocalOperand1->Buffer.Length);
    399      1.1    jruoho         break;
    400      1.1    jruoho 
    401      1.1    jruoho     default:
    402      1.1    jruoho 
    403      1.1    jruoho         /* Invalid object type, should not happen here */
    404      1.1    jruoho 
    405      1.1    jruoho         ACPI_ERROR ((AE_INFO, "Invalid object type: 0x%X",
    406      1.1    jruoho             Operand0->Common.Type));
    407      1.1    jruoho         Status =AE_AML_INTERNAL;
    408      1.1    jruoho         goto Cleanup;
    409      1.1    jruoho     }
    410      1.1    jruoho 
    411      1.1    jruoho     *ActualReturnDesc = ReturnDesc;
    412      1.1    jruoho 
    413      1.1    jruoho Cleanup:
    414      1.1    jruoho     if (LocalOperand1 != Operand1)
    415      1.1    jruoho     {
    416      1.1    jruoho         AcpiUtRemoveReference (LocalOperand1);
    417      1.1    jruoho     }
    418      1.1    jruoho     return_ACPI_STATUS (Status);
    419      1.1    jruoho }
    420      1.1    jruoho 
    421      1.1    jruoho 
    422      1.1    jruoho /*******************************************************************************
    423      1.1    jruoho  *
    424      1.1    jruoho  * FUNCTION:    AcpiExDoMathOp
    425      1.1    jruoho  *
    426      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    427      1.1    jruoho  *              Integer0            - Integer operand #0
    428      1.1    jruoho  *              Integer1            - Integer operand #1
    429      1.1    jruoho  *
    430      1.1    jruoho  * RETURN:      Integer result of the operation
    431      1.1    jruoho  *
    432      1.1    jruoho  * DESCRIPTION: Execute a math AML opcode. The purpose of having all of the
    433      1.1    jruoho  *              math functions here is to prevent a lot of pointer dereferencing
    434      1.1    jruoho  *              to obtain the operands.
    435      1.1    jruoho  *
    436      1.1    jruoho  ******************************************************************************/
    437      1.1    jruoho 
    438      1.1    jruoho UINT64
    439      1.1    jruoho AcpiExDoMathOp (
    440      1.1    jruoho     UINT16                  Opcode,
    441      1.1    jruoho     UINT64                  Integer0,
    442      1.1    jruoho     UINT64                  Integer1)
    443      1.1    jruoho {
    444      1.1    jruoho 
    445      1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    446      1.1    jruoho 
    447      1.1    jruoho 
    448      1.1    jruoho     switch (Opcode)
    449      1.1    jruoho     {
    450      1.1    jruoho     case AML_ADD_OP:                /* Add (Integer0, Integer1, Result) */
    451      1.1    jruoho 
    452      1.1    jruoho         return (Integer0 + Integer1);
    453      1.1    jruoho 
    454      1.1    jruoho     case AML_BIT_AND_OP:            /* And (Integer0, Integer1, Result) */
    455      1.1    jruoho 
    456      1.1    jruoho         return (Integer0 & Integer1);
    457      1.1    jruoho 
    458      1.1    jruoho     case AML_BIT_NAND_OP:           /* NAnd (Integer0, Integer1, Result) */
    459      1.1    jruoho 
    460      1.1    jruoho         return (~(Integer0 & Integer1));
    461      1.1    jruoho 
    462      1.1    jruoho     case AML_BIT_OR_OP:             /* Or (Integer0, Integer1, Result) */
    463      1.1    jruoho 
    464      1.1    jruoho         return (Integer0 | Integer1);
    465      1.1    jruoho 
    466      1.1    jruoho     case AML_BIT_NOR_OP:            /* NOr (Integer0, Integer1, Result) */
    467      1.1    jruoho 
    468      1.1    jruoho         return (~(Integer0 | Integer1));
    469      1.1    jruoho 
    470      1.1    jruoho     case AML_BIT_XOR_OP:            /* XOr (Integer0, Integer1, Result) */
    471      1.1    jruoho 
    472      1.1    jruoho         return (Integer0 ^ Integer1);
    473      1.1    jruoho 
    474      1.1    jruoho     case AML_MULTIPLY_OP:           /* Multiply (Integer0, Integer1, Result) */
    475      1.1    jruoho 
    476      1.1    jruoho         return (Integer0 * Integer1);
    477      1.1    jruoho 
    478      1.1    jruoho     case AML_SHIFT_LEFT_OP:         /* ShiftLeft (Operand, ShiftCount, Result)*/
    479      1.1    jruoho 
    480      1.1    jruoho         /*
    481      1.1    jruoho          * We need to check if the shiftcount is larger than the integer bit
    482      1.1    jruoho          * width since the behavior of this is not well-defined in the C language.
    483      1.1    jruoho          */
    484      1.1    jruoho         if (Integer1 >= AcpiGbl_IntegerBitWidth)
    485      1.1    jruoho         {
    486      1.1    jruoho             return (0);
    487      1.1    jruoho         }
    488      1.1    jruoho         return (Integer0 << Integer1);
    489      1.1    jruoho 
    490      1.1    jruoho     case AML_SHIFT_RIGHT_OP:        /* ShiftRight (Operand, ShiftCount, Result) */
    491      1.1    jruoho 
    492      1.1    jruoho         /*
    493      1.1    jruoho          * We need to check if the shiftcount is larger than the integer bit
    494      1.1    jruoho          * width since the behavior of this is not well-defined in the C language.
    495      1.1    jruoho          */
    496      1.1    jruoho         if (Integer1 >= AcpiGbl_IntegerBitWidth)
    497      1.1    jruoho         {
    498      1.1    jruoho             return (0);
    499      1.1    jruoho         }
    500      1.1    jruoho         return (Integer0 >> Integer1);
    501      1.1    jruoho 
    502      1.1    jruoho     case AML_SUBTRACT_OP:           /* Subtract (Integer0, Integer1, Result) */
    503      1.1    jruoho 
    504      1.1    jruoho         return (Integer0 - Integer1);
    505      1.1    jruoho 
    506      1.1    jruoho     default:
    507      1.1    jruoho 
    508      1.1    jruoho         return (0);
    509      1.1    jruoho     }
    510      1.1    jruoho }
    511      1.1    jruoho 
    512      1.1    jruoho 
    513      1.1    jruoho /*******************************************************************************
    514      1.1    jruoho  *
    515      1.1    jruoho  * FUNCTION:    AcpiExDoLogicalNumericOp
    516      1.1    jruoho  *
    517      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    518      1.1    jruoho  *              Integer0            - Integer operand #0
    519      1.1    jruoho  *              Integer1            - Integer operand #1
    520      1.1    jruoho  *              LogicalResult       - TRUE/FALSE result of the operation
    521      1.1    jruoho  *
    522      1.1    jruoho  * RETURN:      Status
    523      1.1    jruoho  *
    524      1.1    jruoho  * DESCRIPTION: Execute a logical "Numeric" AML opcode. For these Numeric
    525      1.1    jruoho  *              operators (LAnd and LOr), both operands must be integers.
    526      1.1    jruoho  *
    527      1.1    jruoho  *              Note: cleanest machine code seems to be produced by the code
    528      1.1    jruoho  *              below, rather than using statements of the form:
    529      1.1    jruoho  *                  Result = (Integer0 && Integer1);
    530      1.1    jruoho  *
    531      1.1    jruoho  ******************************************************************************/
    532      1.1    jruoho 
    533      1.1    jruoho ACPI_STATUS
    534      1.1    jruoho AcpiExDoLogicalNumericOp (
    535      1.1    jruoho     UINT16                  Opcode,
    536      1.1    jruoho     UINT64                  Integer0,
    537      1.1    jruoho     UINT64                  Integer1,
    538      1.1    jruoho     BOOLEAN                 *LogicalResult)
    539      1.1    jruoho {
    540      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    541      1.1    jruoho     BOOLEAN                 LocalResult = FALSE;
    542      1.1    jruoho 
    543      1.1    jruoho 
    544      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoLogicalNumericOp);
    545      1.1    jruoho 
    546      1.1    jruoho 
    547      1.1    jruoho     switch (Opcode)
    548      1.1    jruoho     {
    549      1.1    jruoho     case AML_LAND_OP:               /* LAnd (Integer0, Integer1) */
    550      1.1    jruoho 
    551      1.1    jruoho         if (Integer0 && Integer1)
    552      1.1    jruoho         {
    553      1.1    jruoho             LocalResult = TRUE;
    554      1.1    jruoho         }
    555      1.1    jruoho         break;
    556      1.1    jruoho 
    557      1.1    jruoho     case AML_LOR_OP:                /* LOr (Integer0, Integer1) */
    558      1.1    jruoho 
    559      1.1    jruoho         if (Integer0 || Integer1)
    560      1.1    jruoho         {
    561      1.1    jruoho             LocalResult = TRUE;
    562      1.1    jruoho         }
    563      1.1    jruoho         break;
    564      1.1    jruoho 
    565      1.1    jruoho     default:
    566  1.1.1.3  christos 
    567      1.1    jruoho         Status = AE_AML_INTERNAL;
    568      1.1    jruoho         break;
    569      1.1    jruoho     }
    570      1.1    jruoho 
    571      1.1    jruoho     /* Return the logical result and status */
    572      1.1    jruoho 
    573      1.1    jruoho     *LogicalResult = LocalResult;
    574      1.1    jruoho     return_ACPI_STATUS (Status);
    575      1.1    jruoho }
    576      1.1    jruoho 
    577      1.1    jruoho 
    578      1.1    jruoho /*******************************************************************************
    579      1.1    jruoho  *
    580      1.1    jruoho  * FUNCTION:    AcpiExDoLogicalOp
    581      1.1    jruoho  *
    582      1.1    jruoho  * PARAMETERS:  Opcode              - AML opcode
    583      1.1    jruoho  *              Operand0            - operand #0
    584      1.1    jruoho  *              Operand1            - operand #1
    585      1.1    jruoho  *              LogicalResult       - TRUE/FALSE result of the operation
    586      1.1    jruoho  *
    587      1.1    jruoho  * RETURN:      Status
    588      1.1    jruoho  *
    589      1.1    jruoho  * DESCRIPTION: Execute a logical AML opcode. The purpose of having all of the
    590      1.1    jruoho  *              functions here is to prevent a lot of pointer dereferencing
    591      1.1    jruoho  *              to obtain the operands and to simplify the generation of the
    592      1.1    jruoho  *              logical value. For the Numeric operators (LAnd and LOr), both
    593      1.1    jruoho  *              operands must be integers. For the other logical operators,
    594      1.1    jruoho  *              operands can be any combination of Integer/String/Buffer. The
    595      1.1    jruoho  *              first operand determines the type to which the second operand
    596      1.1    jruoho  *              will be converted.
    597      1.1    jruoho  *
    598      1.1    jruoho  *              Note: cleanest machine code seems to be produced by the code
    599      1.1    jruoho  *              below, rather than using statements of the form:
    600      1.1    jruoho  *                  Result = (Operand0 == Operand1);
    601      1.1    jruoho  *
    602      1.1    jruoho  ******************************************************************************/
    603      1.1    jruoho 
    604      1.1    jruoho ACPI_STATUS
    605      1.1    jruoho AcpiExDoLogicalOp (
    606      1.1    jruoho     UINT16                  Opcode,
    607      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand0,
    608      1.1    jruoho     ACPI_OPERAND_OBJECT     *Operand1,
    609      1.1    jruoho     BOOLEAN                 *LogicalResult)
    610      1.1    jruoho {
    611      1.1    jruoho     ACPI_OPERAND_OBJECT     *LocalOperand1 = Operand1;
    612      1.1    jruoho     UINT64                  Integer0;
    613      1.1    jruoho     UINT64                  Integer1;
    614      1.1    jruoho     UINT32                  Length0;
    615      1.1    jruoho     UINT32                  Length1;
    616      1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    617      1.1    jruoho     BOOLEAN                 LocalResult = FALSE;
    618      1.1    jruoho     int                     Compare;
    619      1.1    jruoho 
    620      1.1    jruoho 
    621      1.1    jruoho     ACPI_FUNCTION_TRACE (ExDoLogicalOp);
    622      1.1    jruoho 
    623      1.1    jruoho 
    624      1.1    jruoho     /*
    625  1.1.1.3  christos      * Convert the second operand if necessary. The first operand
    626      1.1    jruoho      * determines the type of the second operand, (See the Data Types
    627      1.1    jruoho      * section of the ACPI 3.0+ specification.)  Both object types are
    628      1.1    jruoho      * guaranteed to be either Integer/String/Buffer by the operand
    629      1.1    jruoho      * resolution mechanism.
    630      1.1    jruoho      */
    631      1.1    jruoho     switch (Operand0->Common.Type)
    632      1.1    jruoho     {
    633      1.1    jruoho     case ACPI_TYPE_INTEGER:
    634  1.1.1.3  christos 
    635      1.1    jruoho         Status = AcpiExConvertToInteger (Operand1, &LocalOperand1, 16);
    636      1.1    jruoho         break;
    637      1.1    jruoho 
    638      1.1    jruoho     case ACPI_TYPE_STRING:
    639  1.1.1.3  christos 
    640      1.1    jruoho         Status = AcpiExConvertToString (Operand1, &LocalOperand1,
    641      1.1    jruoho                     ACPI_IMPLICIT_CONVERT_HEX);
    642      1.1    jruoho         break;
    643      1.1    jruoho 
    644      1.1    jruoho     case ACPI_TYPE_BUFFER:
    645  1.1.1.3  christos 
    646      1.1    jruoho         Status = AcpiExConvertToBuffer (Operand1, &LocalOperand1);
    647      1.1    jruoho         break;
    648      1.1    jruoho 
    649      1.1    jruoho     default:
    650  1.1.1.3  christos 
    651      1.1    jruoho         Status = AE_AML_INTERNAL;
    652      1.1    jruoho         break;
    653      1.1    jruoho     }
    654      1.1    jruoho 
    655      1.1    jruoho     if (ACPI_FAILURE (Status))
    656      1.1    jruoho     {
    657      1.1    jruoho         goto Cleanup;
    658      1.1    jruoho     }
    659      1.1    jruoho 
    660      1.1    jruoho     /*
    661      1.1    jruoho      * Two cases: 1) Both Integers, 2) Both Strings or Buffers
    662      1.1    jruoho      */
    663      1.1    jruoho     if (Operand0->Common.Type == ACPI_TYPE_INTEGER)
    664      1.1    jruoho     {
    665      1.1    jruoho         /*
    666      1.1    jruoho          * 1) Both operands are of type integer
    667      1.1    jruoho          *    Note: LocalOperand1 may have changed above
    668      1.1    jruoho          */
    669      1.1    jruoho         Integer0 = Operand0->Integer.Value;
    670      1.1    jruoho         Integer1 = LocalOperand1->Integer.Value;
    671      1.1    jruoho 
    672      1.1    jruoho         switch (Opcode)
    673      1.1    jruoho         {
    674      1.1    jruoho         case AML_LEQUAL_OP:             /* LEqual (Operand0, Operand1) */
    675      1.1    jruoho 
    676      1.1    jruoho             if (Integer0 == Integer1)
    677      1.1    jruoho             {
    678      1.1    jruoho                 LocalResult = TRUE;
    679      1.1    jruoho             }
    680      1.1    jruoho             break;
    681      1.1    jruoho 
    682      1.1    jruoho         case AML_LGREATER_OP:           /* LGreater (Operand0, Operand1) */
    683      1.1    jruoho 
    684      1.1    jruoho             if (Integer0 > Integer1)
    685      1.1    jruoho             {
    686      1.1    jruoho                 LocalResult = TRUE;
    687      1.1    jruoho             }
    688      1.1    jruoho             break;
    689      1.1    jruoho 
    690      1.1    jruoho         case AML_LLESS_OP:              /* LLess (Operand0, Operand1) */
    691      1.1    jruoho 
    692      1.1    jruoho             if (Integer0 < Integer1)
    693      1.1    jruoho             {
    694      1.1    jruoho                 LocalResult = TRUE;
    695      1.1    jruoho             }
    696      1.1    jruoho             break;
    697      1.1    jruoho 
    698      1.1    jruoho         default:
    699  1.1.1.3  christos 
    700      1.1    jruoho             Status = AE_AML_INTERNAL;
    701      1.1    jruoho             break;
    702      1.1    jruoho         }
    703      1.1    jruoho     }
    704      1.1    jruoho     else
    705      1.1    jruoho     {
    706      1.1    jruoho         /*
    707      1.1    jruoho          * 2) Both operands are Strings or both are Buffers
    708      1.1    jruoho          *    Note: Code below takes advantage of common Buffer/String
    709      1.1    jruoho          *          object fields. LocalOperand1 may have changed above. Use
    710      1.1    jruoho          *          memcmp to handle nulls in buffers.
    711      1.1    jruoho          */
    712      1.1    jruoho         Length0 = Operand0->Buffer.Length;
    713      1.1    jruoho         Length1 = LocalOperand1->Buffer.Length;
    714      1.1    jruoho 
    715      1.1    jruoho         /* Lexicographic compare: compare the data bytes */
    716      1.1    jruoho 
    717      1.1    jruoho         Compare = ACPI_MEMCMP (Operand0->Buffer.Pointer,
    718      1.1    jruoho                     LocalOperand1->Buffer.Pointer,
    719      1.1    jruoho                     (Length0 > Length1) ? Length1 : Length0);
    720      1.1    jruoho 
    721      1.1    jruoho         switch (Opcode)
    722      1.1    jruoho         {
    723      1.1    jruoho         case AML_LEQUAL_OP:             /* LEqual (Operand0, Operand1) */
    724      1.1    jruoho 
    725      1.1    jruoho             /* Length and all bytes must be equal */
    726      1.1    jruoho 
    727      1.1    jruoho             if ((Length0 == Length1) &&
    728      1.1    jruoho                 (Compare == 0))
    729      1.1    jruoho             {
    730      1.1    jruoho                 /* Length and all bytes match ==> TRUE */
    731      1.1    jruoho 
    732      1.1    jruoho                 LocalResult = TRUE;
    733      1.1    jruoho             }
    734      1.1    jruoho             break;
    735      1.1    jruoho 
    736      1.1    jruoho         case AML_LGREATER_OP:           /* LGreater (Operand0, Operand1) */
    737      1.1    jruoho 
    738      1.1    jruoho             if (Compare > 0)
    739      1.1    jruoho             {
    740      1.1    jruoho                 LocalResult = TRUE;
    741      1.1    jruoho                 goto Cleanup;   /* TRUE */
    742      1.1    jruoho             }
    743      1.1    jruoho             if (Compare < 0)
    744      1.1    jruoho             {
    745      1.1    jruoho                 goto Cleanup;   /* FALSE */
    746      1.1    jruoho             }
    747      1.1    jruoho 
    748      1.1    jruoho             /* Bytes match (to shortest length), compare lengths */
    749      1.1    jruoho 
    750      1.1    jruoho             if (Length0 > Length1)
    751      1.1    jruoho             {
    752      1.1    jruoho                 LocalResult = TRUE;
    753      1.1    jruoho             }
    754      1.1    jruoho             break;
    755      1.1    jruoho 
    756      1.1    jruoho         case AML_LLESS_OP:              /* LLess (Operand0, Operand1) */
    757      1.1    jruoho 
    758      1.1    jruoho             if (Compare > 0)
    759      1.1    jruoho             {
    760      1.1    jruoho                 goto Cleanup;   /* FALSE */
    761      1.1    jruoho             }
    762      1.1    jruoho             if (Compare < 0)
    763      1.1    jruoho             {
    764      1.1    jruoho                 LocalResult = TRUE;
    765      1.1    jruoho                 goto Cleanup;   /* TRUE */
    766      1.1    jruoho             }
    767      1.1    jruoho 
    768      1.1    jruoho             /* Bytes match (to shortest length), compare lengths */
    769      1.1    jruoho 
    770      1.1    jruoho             if (Length0 < Length1)
    771      1.1    jruoho             {
    772      1.1    jruoho                 LocalResult = TRUE;
    773      1.1    jruoho             }
    774      1.1    jruoho             break;
    775      1.1    jruoho 
    776      1.1    jruoho         default:
    777  1.1.1.3  christos 
    778      1.1    jruoho             Status = AE_AML_INTERNAL;
    779      1.1    jruoho             break;
    780      1.1    jruoho         }
    781      1.1    jruoho     }
    782      1.1    jruoho 
    783      1.1    jruoho Cleanup:
    784      1.1    jruoho 
    785      1.1    jruoho     /* New object was created if implicit conversion performed - delete */
    786      1.1    jruoho 
    787      1.1    jruoho     if (LocalOperand1 != Operand1)
    788      1.1    jruoho     {
    789      1.1    jruoho         AcpiUtRemoveReference (LocalOperand1);
    790      1.1    jruoho     }
    791      1.1    jruoho 
    792      1.1    jruoho     /* Return the logical result and status */
    793      1.1    jruoho 
    794      1.1    jruoho     *LogicalResult = LocalResult;
    795      1.1    jruoho     return_ACPI_STATUS (Status);
    796      1.1    jruoho }
    797