Home | History | Annotate | Line # | Download | only in executer
exoparg6.c revision 1.1.1.4.2.1
      1          1.1    jruoho /******************************************************************************
      2          1.1    jruoho  *
      3          1.1    jruoho  * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
      4          1.1    jruoho  *
      5          1.1    jruoho  *****************************************************************************/
      6          1.1    jruoho 
      7      1.1.1.2    jruoho /*
      8  1.1.1.4.2.1     skrll  * 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 "acparser.h"
     48          1.1    jruoho #include "amlcode.h"
     49          1.1    jruoho 
     50          1.1    jruoho 
     51          1.1    jruoho #define _COMPONENT          ACPI_EXECUTER
     52          1.1    jruoho         ACPI_MODULE_NAME    ("exoparg6")
     53          1.1    jruoho 
     54          1.1    jruoho 
     55          1.1    jruoho /*!
     56          1.1    jruoho  * Naming convention for AML interpreter execution routines.
     57          1.1    jruoho  *
     58          1.1    jruoho  * The routines that begin execution of AML opcodes are named with a common
     59          1.1    jruoho  * convention based upon the number of arguments, the number of target operands,
     60          1.1    jruoho  * and whether or not a value is returned:
     61          1.1    jruoho  *
     62          1.1    jruoho  *      AcpiExOpcode_xA_yT_zR
     63          1.1    jruoho  *
     64          1.1    jruoho  * Where:
     65          1.1    jruoho  *
     66          1.1    jruoho  * xA - ARGUMENTS:    The number of arguments (input operands) that are
     67          1.1    jruoho  *                    required for this opcode type (1 through 6 args).
     68          1.1    jruoho  * yT - TARGETS:      The number of targets (output operands) that are required
     69          1.1    jruoho  *                    for this opcode type (0, 1, or 2 targets).
     70          1.1    jruoho  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
     71          1.1    jruoho  *                    as the function return (0 or 1).
     72          1.1    jruoho  *
     73          1.1    jruoho  * The AcpiExOpcode* functions are called via the Dispatcher component with
     74          1.1    jruoho  * fully resolved operands.
     75          1.1    jruoho !*/
     76          1.1    jruoho 
     77          1.1    jruoho /* Local prototypes */
     78          1.1    jruoho 
     79          1.1    jruoho static BOOLEAN
     80          1.1    jruoho AcpiExDoMatch (
     81          1.1    jruoho     UINT32                  MatchOp,
     82          1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageObj,
     83          1.1    jruoho     ACPI_OPERAND_OBJECT     *MatchObj);
     84          1.1    jruoho 
     85          1.1    jruoho 
     86          1.1    jruoho /*******************************************************************************
     87          1.1    jruoho  *
     88          1.1    jruoho  * FUNCTION:    AcpiExDoMatch
     89          1.1    jruoho  *
     90          1.1    jruoho  * PARAMETERS:  MatchOp         - The AML match operand
     91          1.1    jruoho  *              PackageObj      - Object from the target package
     92          1.1    jruoho  *              MatchObj        - Object to be matched
     93          1.1    jruoho  *
     94          1.1    jruoho  * RETURN:      TRUE if the match is successful, FALSE otherwise
     95          1.1    jruoho  *
     96          1.1    jruoho  * DESCRIPTION: Implements the low-level match for the ASL Match operator.
     97          1.1    jruoho  *              Package elements will be implicitly converted to the type of
     98          1.1    jruoho  *              the match object (Integer/Buffer/String).
     99          1.1    jruoho  *
    100          1.1    jruoho  ******************************************************************************/
    101          1.1    jruoho 
    102          1.1    jruoho static BOOLEAN
    103          1.1    jruoho AcpiExDoMatch (
    104          1.1    jruoho     UINT32                  MatchOp,
    105          1.1    jruoho     ACPI_OPERAND_OBJECT     *PackageObj,
    106          1.1    jruoho     ACPI_OPERAND_OBJECT     *MatchObj)
    107          1.1    jruoho {
    108          1.1    jruoho     BOOLEAN                 LogicalResult = TRUE;
    109          1.1    jruoho     ACPI_STATUS             Status;
    110          1.1    jruoho 
    111          1.1    jruoho 
    112          1.1    jruoho     /*
    113          1.1    jruoho      * Note: Since the PackageObj/MatchObj ordering is opposite to that of
    114          1.1    jruoho      * the standard logical operators, we have to reverse them when we call
    115          1.1    jruoho      * DoLogicalOp in order to make the implicit conversion rules work
    116          1.1    jruoho      * correctly. However, this means we have to flip the entire equation
    117          1.1    jruoho      * also. A bit ugly perhaps, but overall, better than fussing the
    118          1.1    jruoho      * parameters around at runtime, over and over again.
    119          1.1    jruoho      *
    120          1.1    jruoho      * Below, P[i] refers to the package element, M refers to the Match object.
    121          1.1    jruoho      */
    122          1.1    jruoho     switch (MatchOp)
    123          1.1    jruoho     {
    124          1.1    jruoho     case MATCH_MTR:
    125          1.1    jruoho 
    126          1.1    jruoho         /* Always true */
    127          1.1    jruoho 
    128          1.1    jruoho         break;
    129          1.1    jruoho 
    130          1.1    jruoho     case MATCH_MEQ:
    131          1.1    jruoho         /*
    132          1.1    jruoho          * True if equal: (P[i] == M)
    133          1.1    jruoho          * Change to:     (M == P[i])
    134          1.1    jruoho          */
    135          1.1    jruoho         Status = AcpiExDoLogicalOp (AML_LEQUAL_OP, MatchObj, PackageObj,
    136          1.1    jruoho                     &LogicalResult);
    137          1.1    jruoho         if (ACPI_FAILURE (Status))
    138          1.1    jruoho         {
    139          1.1    jruoho             return (FALSE);
    140          1.1    jruoho         }
    141          1.1    jruoho         break;
    142          1.1    jruoho 
    143          1.1    jruoho     case MATCH_MLE:
    144          1.1    jruoho         /*
    145          1.1    jruoho          * True if less than or equal: (P[i] <= M) (P[i] NotGreater than M)
    146          1.1    jruoho          * Change to:                  (M >= P[i]) (M NotLess than P[i])
    147          1.1    jruoho          */
    148          1.1    jruoho         Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
    149          1.1    jruoho                     &LogicalResult);
    150          1.1    jruoho         if (ACPI_FAILURE (Status))
    151          1.1    jruoho         {
    152          1.1    jruoho             return (FALSE);
    153          1.1    jruoho         }
    154          1.1    jruoho         LogicalResult = (BOOLEAN) !LogicalResult;
    155          1.1    jruoho         break;
    156          1.1    jruoho 
    157          1.1    jruoho     case MATCH_MLT:
    158          1.1    jruoho         /*
    159          1.1    jruoho          * True if less than: (P[i] < M)
    160          1.1    jruoho          * Change to:         (M > P[i])
    161          1.1    jruoho          */
    162          1.1    jruoho         Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
    163          1.1    jruoho                     &LogicalResult);
    164          1.1    jruoho         if (ACPI_FAILURE (Status))
    165          1.1    jruoho         {
    166          1.1    jruoho             return (FALSE);
    167          1.1    jruoho         }
    168          1.1    jruoho         break;
    169          1.1    jruoho 
    170          1.1    jruoho     case MATCH_MGE:
    171          1.1    jruoho         /*
    172          1.1    jruoho          * True if greater than or equal: (P[i] >= M) (P[i] NotLess than M)
    173          1.1    jruoho          * Change to:                     (M <= P[i]) (M NotGreater than P[i])
    174          1.1    jruoho          */
    175          1.1    jruoho         Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
    176          1.1    jruoho                     &LogicalResult);
    177          1.1    jruoho         if (ACPI_FAILURE (Status))
    178          1.1    jruoho         {
    179          1.1    jruoho             return (FALSE);
    180          1.1    jruoho         }
    181          1.1    jruoho         LogicalResult = (BOOLEAN)!LogicalResult;
    182          1.1    jruoho         break;
    183          1.1    jruoho 
    184          1.1    jruoho     case MATCH_MGT:
    185          1.1    jruoho         /*
    186          1.1    jruoho          * True if greater than: (P[i] > M)
    187          1.1    jruoho          * Change to:            (M < P[i])
    188          1.1    jruoho          */
    189          1.1    jruoho         Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
    190          1.1    jruoho                     &LogicalResult);
    191          1.1    jruoho         if (ACPI_FAILURE (Status))
    192          1.1    jruoho         {
    193          1.1    jruoho             return (FALSE);
    194          1.1    jruoho         }
    195          1.1    jruoho         break;
    196          1.1    jruoho 
    197          1.1    jruoho     default:
    198          1.1    jruoho 
    199          1.1    jruoho         /* Undefined */
    200          1.1    jruoho 
    201          1.1    jruoho         return (FALSE);
    202          1.1    jruoho     }
    203          1.1    jruoho 
    204      1.1.1.3  christos     return (LogicalResult);
    205          1.1    jruoho }
    206          1.1    jruoho 
    207          1.1    jruoho 
    208          1.1    jruoho /*******************************************************************************
    209          1.1    jruoho  *
    210          1.1    jruoho  * FUNCTION:    AcpiExOpcode_6A_0T_1R
    211          1.1    jruoho  *
    212          1.1    jruoho  * PARAMETERS:  WalkState           - Current walk state
    213          1.1    jruoho  *
    214          1.1    jruoho  * RETURN:      Status
    215          1.1    jruoho  *
    216          1.1    jruoho  * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
    217          1.1    jruoho  *
    218          1.1    jruoho  ******************************************************************************/
    219          1.1    jruoho 
    220          1.1    jruoho ACPI_STATUS
    221          1.1    jruoho AcpiExOpcode_6A_0T_1R (
    222          1.1    jruoho     ACPI_WALK_STATE         *WalkState)
    223          1.1    jruoho {
    224          1.1    jruoho     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
    225          1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
    226          1.1    jruoho     ACPI_STATUS             Status = AE_OK;
    227          1.1    jruoho     UINT64                  Index;
    228          1.1    jruoho     ACPI_OPERAND_OBJECT     *ThisElement;
    229          1.1    jruoho 
    230          1.1    jruoho 
    231          1.1    jruoho     ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R,
    232          1.1    jruoho         AcpiPsGetOpcodeName (WalkState->Opcode));
    233          1.1    jruoho 
    234          1.1    jruoho 
    235          1.1    jruoho     switch (WalkState->Opcode)
    236          1.1    jruoho     {
    237          1.1    jruoho     case AML_MATCH_OP:
    238          1.1    jruoho         /*
    239          1.1    jruoho          * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2],
    240          1.1    jruoho          *                      MatchOp2[3], MatchObj2[4], StartIndex[5])
    241          1.1    jruoho          */
    242          1.1    jruoho 
    243          1.1    jruoho         /* Validate both Match Term Operators (MTR, MEQ, etc.) */
    244          1.1    jruoho 
    245          1.1    jruoho         if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) ||
    246          1.1    jruoho             (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR))
    247          1.1    jruoho         {
    248          1.1    jruoho             ACPI_ERROR ((AE_INFO, "Match operator out of range"));
    249          1.1    jruoho             Status = AE_AML_OPERAND_VALUE;
    250          1.1    jruoho             goto Cleanup;
    251          1.1    jruoho         }
    252          1.1    jruoho 
    253          1.1    jruoho         /* Get the package StartIndex, validate against the package length */
    254          1.1    jruoho 
    255          1.1    jruoho         Index = Operand[5]->Integer.Value;
    256          1.1    jruoho         if (Index >= Operand[0]->Package.Count)
    257          1.1    jruoho         {
    258          1.1    jruoho             ACPI_ERROR ((AE_INFO,
    259          1.1    jruoho                 "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
    260          1.1    jruoho                 ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count));
    261          1.1    jruoho             Status = AE_AML_PACKAGE_LIMIT;
    262          1.1    jruoho             goto Cleanup;
    263          1.1    jruoho         }
    264          1.1    jruoho 
    265          1.1    jruoho         /* Create an integer for the return value */
    266          1.1    jruoho         /* Default return value is ACPI_UINT64_MAX if no match found */
    267          1.1    jruoho 
    268          1.1    jruoho         ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX);
    269          1.1    jruoho         if (!ReturnDesc)
    270          1.1    jruoho         {
    271          1.1    jruoho             Status = AE_NO_MEMORY;
    272          1.1    jruoho             goto Cleanup;
    273          1.1    jruoho 
    274          1.1    jruoho         }
    275          1.1    jruoho 
    276          1.1    jruoho         /*
    277          1.1    jruoho          * Examine each element until a match is found. Both match conditions
    278          1.1    jruoho          * must be satisfied for a match to occur. Within the loop,
    279          1.1    jruoho          * "continue" signifies that the current element does not match
    280          1.1    jruoho          * and the next should be examined.
    281          1.1    jruoho          *
    282          1.1    jruoho          * Upon finding a match, the loop will terminate via "break" at
    283      1.1.1.3  christos          * the bottom. If it terminates "normally", MatchValue will be
    284          1.1    jruoho          * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
    285          1.1    jruoho          * match was found.
    286          1.1    jruoho          */
    287          1.1    jruoho         for ( ; Index < Operand[0]->Package.Count; Index++)
    288          1.1    jruoho         {
    289          1.1    jruoho             /* Get the current package element */
    290          1.1    jruoho 
    291          1.1    jruoho             ThisElement = Operand[0]->Package.Elements[Index];
    292          1.1    jruoho 
    293          1.1    jruoho             /* Treat any uninitialized (NULL) elements as non-matching */
    294          1.1    jruoho 
    295          1.1    jruoho             if (!ThisElement)
    296          1.1    jruoho             {
    297          1.1    jruoho                 continue;
    298          1.1    jruoho             }
    299          1.1    jruoho 
    300          1.1    jruoho             /*
    301          1.1    jruoho              * Both match conditions must be satisfied. Execution of a continue
    302          1.1    jruoho              * (proceed to next iteration of enclosing for loop) signifies a
    303          1.1    jruoho              * non-match.
    304          1.1    jruoho              */
    305          1.1    jruoho             if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value,
    306          1.1    jruoho                                 ThisElement, Operand[2]))
    307          1.1    jruoho             {
    308          1.1    jruoho                 continue;
    309          1.1    jruoho             }
    310          1.1    jruoho 
    311          1.1    jruoho             if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value,
    312          1.1    jruoho                                 ThisElement, Operand[4]))
    313          1.1    jruoho             {
    314          1.1    jruoho                 continue;
    315          1.1    jruoho             }
    316          1.1    jruoho 
    317          1.1    jruoho             /* Match found: Index is the return value */
    318          1.1    jruoho 
    319          1.1    jruoho             ReturnDesc->Integer.Value = Index;
    320          1.1    jruoho             break;
    321          1.1    jruoho         }
    322          1.1    jruoho         break;
    323          1.1    jruoho 
    324          1.1    jruoho     case AML_LOAD_TABLE_OP:
    325          1.1    jruoho 
    326          1.1    jruoho         Status = AcpiExLoadTableOp (WalkState, &ReturnDesc);
    327          1.1    jruoho         break;
    328          1.1    jruoho 
    329          1.1    jruoho     default:
    330          1.1    jruoho 
    331          1.1    jruoho         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
    332          1.1    jruoho             WalkState->Opcode));
    333          1.1    jruoho         Status = AE_AML_BAD_OPCODE;
    334          1.1    jruoho         goto Cleanup;
    335          1.1    jruoho     }
    336          1.1    jruoho 
    337          1.1    jruoho 
    338          1.1    jruoho Cleanup:
    339          1.1    jruoho 
    340          1.1    jruoho     /* Delete return object on error */
    341          1.1    jruoho 
    342          1.1    jruoho     if (ACPI_FAILURE (Status))
    343          1.1    jruoho     {
    344          1.1    jruoho         AcpiUtRemoveReference (ReturnDesc);
    345          1.1    jruoho     }
    346          1.1    jruoho 
    347          1.1    jruoho     /* Save return object on success */
    348          1.1    jruoho 
    349          1.1    jruoho     else
    350          1.1    jruoho     {
    351          1.1    jruoho         WalkState->ResultObj = ReturnDesc;
    352          1.1    jruoho     }
    353          1.1    jruoho 
    354          1.1    jruoho     return_ACPI_STATUS (Status);
    355          1.1    jruoho }
    356