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