Home | History | Annotate | Line # | Download | only in executer
exoparg6.c revision 1.1.1.2
      1      1.1  jruoho 
      2      1.1  jruoho /******************************************************************************
      3      1.1  jruoho  *
      4      1.1  jruoho  * Module Name: exoparg6 - AML execution - opcodes with 6 arguments
      5      1.1  jruoho  *
      6      1.1  jruoho  *****************************************************************************/
      7      1.1  jruoho 
      8  1.1.1.2  jruoho /*
      9  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, Intel Corp.
     10      1.1  jruoho  * All rights reserved.
     11      1.1  jruoho  *
     12  1.1.1.2  jruoho  * Redistribution and use in source and binary forms, with or without
     13  1.1.1.2  jruoho  * modification, are permitted provided that the following conditions
     14  1.1.1.2  jruoho  * are met:
     15  1.1.1.2  jruoho  * 1. Redistributions of source code must retain the above copyright
     16  1.1.1.2  jruoho  *    notice, this list of conditions, and the following disclaimer,
     17  1.1.1.2  jruoho  *    without modification.
     18  1.1.1.2  jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     19  1.1.1.2  jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     20  1.1.1.2  jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     21  1.1.1.2  jruoho  *    including a substantially similar Disclaimer requirement for further
     22  1.1.1.2  jruoho  *    binary redistribution.
     23  1.1.1.2  jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     24  1.1.1.2  jruoho  *    of any contributors may be used to endorse or promote products derived
     25  1.1.1.2  jruoho  *    from this software without specific prior written permission.
     26  1.1.1.2  jruoho  *
     27  1.1.1.2  jruoho  * Alternatively, this software may be distributed under the terms of the
     28  1.1.1.2  jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     29  1.1.1.2  jruoho  * Software Foundation.
     30  1.1.1.2  jruoho  *
     31  1.1.1.2  jruoho  * NO WARRANTY
     32  1.1.1.2  jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     33  1.1.1.2  jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     34  1.1.1.2  jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     35  1.1.1.2  jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     36  1.1.1.2  jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     37  1.1.1.2  jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     38  1.1.1.2  jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     39  1.1.1.2  jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     40  1.1.1.2  jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     41  1.1.1.2  jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     42  1.1.1.2  jruoho  * POSSIBILITY OF SUCH DAMAGES.
     43  1.1.1.2  jruoho  */
     44      1.1  jruoho 
     45      1.1  jruoho #define __EXOPARG6_C__
     46      1.1  jruoho 
     47      1.1  jruoho #include "acpi.h"
     48      1.1  jruoho #include "accommon.h"
     49      1.1  jruoho #include "acinterp.h"
     50      1.1  jruoho #include "acparser.h"
     51      1.1  jruoho #include "amlcode.h"
     52      1.1  jruoho 
     53      1.1  jruoho 
     54      1.1  jruoho #define _COMPONENT          ACPI_EXECUTER
     55      1.1  jruoho         ACPI_MODULE_NAME    ("exoparg6")
     56      1.1  jruoho 
     57      1.1  jruoho 
     58      1.1  jruoho /*!
     59      1.1  jruoho  * Naming convention for AML interpreter execution routines.
     60      1.1  jruoho  *
     61      1.1  jruoho  * The routines that begin execution of AML opcodes are named with a common
     62      1.1  jruoho  * convention based upon the number of arguments, the number of target operands,
     63      1.1  jruoho  * and whether or not a value is returned:
     64      1.1  jruoho  *
     65      1.1  jruoho  *      AcpiExOpcode_xA_yT_zR
     66      1.1  jruoho  *
     67      1.1  jruoho  * Where:
     68      1.1  jruoho  *
     69      1.1  jruoho  * xA - ARGUMENTS:    The number of arguments (input operands) that are
     70      1.1  jruoho  *                    required for this opcode type (1 through 6 args).
     71      1.1  jruoho  * yT - TARGETS:      The number of targets (output operands) that are required
     72      1.1  jruoho  *                    for this opcode type (0, 1, or 2 targets).
     73      1.1  jruoho  * zR - RETURN VALUE: Indicates whether this opcode type returns a value
     74      1.1  jruoho  *                    as the function return (0 or 1).
     75      1.1  jruoho  *
     76      1.1  jruoho  * The AcpiExOpcode* functions are called via the Dispatcher component with
     77      1.1  jruoho  * fully resolved operands.
     78      1.1  jruoho !*/
     79      1.1  jruoho 
     80      1.1  jruoho /* Local prototypes */
     81      1.1  jruoho 
     82      1.1  jruoho static BOOLEAN
     83      1.1  jruoho AcpiExDoMatch (
     84      1.1  jruoho     UINT32                  MatchOp,
     85      1.1  jruoho     ACPI_OPERAND_OBJECT     *PackageObj,
     86      1.1  jruoho     ACPI_OPERAND_OBJECT     *MatchObj);
     87      1.1  jruoho 
     88      1.1  jruoho 
     89      1.1  jruoho /*******************************************************************************
     90      1.1  jruoho  *
     91      1.1  jruoho  * FUNCTION:    AcpiExDoMatch
     92      1.1  jruoho  *
     93      1.1  jruoho  * PARAMETERS:  MatchOp         - The AML match operand
     94      1.1  jruoho  *              PackageObj      - Object from the target package
     95      1.1  jruoho  *              MatchObj        - Object to be matched
     96      1.1  jruoho  *
     97      1.1  jruoho  * RETURN:      TRUE if the match is successful, FALSE otherwise
     98      1.1  jruoho  *
     99      1.1  jruoho  * DESCRIPTION: Implements the low-level match for the ASL Match operator.
    100      1.1  jruoho  *              Package elements will be implicitly converted to the type of
    101      1.1  jruoho  *              the match object (Integer/Buffer/String).
    102      1.1  jruoho  *
    103      1.1  jruoho  ******************************************************************************/
    104      1.1  jruoho 
    105      1.1  jruoho static BOOLEAN
    106      1.1  jruoho AcpiExDoMatch (
    107      1.1  jruoho     UINT32                  MatchOp,
    108      1.1  jruoho     ACPI_OPERAND_OBJECT     *PackageObj,
    109      1.1  jruoho     ACPI_OPERAND_OBJECT     *MatchObj)
    110      1.1  jruoho {
    111      1.1  jruoho     BOOLEAN                 LogicalResult = TRUE;
    112      1.1  jruoho     ACPI_STATUS             Status;
    113      1.1  jruoho 
    114      1.1  jruoho 
    115      1.1  jruoho     /*
    116      1.1  jruoho      * Note: Since the PackageObj/MatchObj ordering is opposite to that of
    117      1.1  jruoho      * the standard logical operators, we have to reverse them when we call
    118      1.1  jruoho      * DoLogicalOp in order to make the implicit conversion rules work
    119      1.1  jruoho      * correctly. However, this means we have to flip the entire equation
    120      1.1  jruoho      * also. A bit ugly perhaps, but overall, better than fussing the
    121      1.1  jruoho      * parameters around at runtime, over and over again.
    122      1.1  jruoho      *
    123      1.1  jruoho      * Below, P[i] refers to the package element, M refers to the Match object.
    124      1.1  jruoho      */
    125      1.1  jruoho     switch (MatchOp)
    126      1.1  jruoho     {
    127      1.1  jruoho     case MATCH_MTR:
    128      1.1  jruoho 
    129      1.1  jruoho         /* Always true */
    130      1.1  jruoho 
    131      1.1  jruoho         break;
    132      1.1  jruoho 
    133      1.1  jruoho     case MATCH_MEQ:
    134      1.1  jruoho 
    135      1.1  jruoho         /*
    136      1.1  jruoho          * True if equal: (P[i] == M)
    137      1.1  jruoho          * Change to:     (M == P[i])
    138      1.1  jruoho          */
    139      1.1  jruoho         Status = AcpiExDoLogicalOp (AML_LEQUAL_OP, MatchObj, PackageObj,
    140      1.1  jruoho                     &LogicalResult);
    141      1.1  jruoho         if (ACPI_FAILURE (Status))
    142      1.1  jruoho         {
    143      1.1  jruoho             return (FALSE);
    144      1.1  jruoho         }
    145      1.1  jruoho         break;
    146      1.1  jruoho 
    147      1.1  jruoho     case MATCH_MLE:
    148      1.1  jruoho 
    149      1.1  jruoho         /*
    150      1.1  jruoho          * True if less than or equal: (P[i] <= M) (P[i] NotGreater than M)
    151      1.1  jruoho          * Change to:                  (M >= P[i]) (M NotLess than P[i])
    152      1.1  jruoho          */
    153      1.1  jruoho         Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
    154      1.1  jruoho                     &LogicalResult);
    155      1.1  jruoho         if (ACPI_FAILURE (Status))
    156      1.1  jruoho         {
    157      1.1  jruoho             return (FALSE);
    158      1.1  jruoho         }
    159      1.1  jruoho         LogicalResult = (BOOLEAN) !LogicalResult;
    160      1.1  jruoho         break;
    161      1.1  jruoho 
    162      1.1  jruoho     case MATCH_MLT:
    163      1.1  jruoho 
    164      1.1  jruoho         /*
    165      1.1  jruoho          * True if less than: (P[i] < M)
    166      1.1  jruoho          * Change to:         (M > P[i])
    167      1.1  jruoho          */
    168      1.1  jruoho         Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
    169      1.1  jruoho                     &LogicalResult);
    170      1.1  jruoho         if (ACPI_FAILURE (Status))
    171      1.1  jruoho         {
    172      1.1  jruoho             return (FALSE);
    173      1.1  jruoho         }
    174      1.1  jruoho         break;
    175      1.1  jruoho 
    176      1.1  jruoho     case MATCH_MGE:
    177      1.1  jruoho 
    178      1.1  jruoho         /*
    179      1.1  jruoho          * True if greater than or equal: (P[i] >= M) (P[i] NotLess than M)
    180      1.1  jruoho          * Change to:                     (M <= P[i]) (M NotGreater than P[i])
    181      1.1  jruoho          */
    182      1.1  jruoho         Status = AcpiExDoLogicalOp (AML_LGREATER_OP, MatchObj, PackageObj,
    183      1.1  jruoho                     &LogicalResult);
    184      1.1  jruoho         if (ACPI_FAILURE (Status))
    185      1.1  jruoho         {
    186      1.1  jruoho             return (FALSE);
    187      1.1  jruoho         }
    188      1.1  jruoho         LogicalResult = (BOOLEAN)!LogicalResult;
    189      1.1  jruoho         break;
    190      1.1  jruoho 
    191      1.1  jruoho     case MATCH_MGT:
    192      1.1  jruoho 
    193      1.1  jruoho         /*
    194      1.1  jruoho          * True if greater than: (P[i] > M)
    195      1.1  jruoho          * Change to:            (M < P[i])
    196      1.1  jruoho          */
    197      1.1  jruoho         Status = AcpiExDoLogicalOp (AML_LLESS_OP, MatchObj, PackageObj,
    198      1.1  jruoho                     &LogicalResult);
    199      1.1  jruoho         if (ACPI_FAILURE (Status))
    200      1.1  jruoho         {
    201      1.1  jruoho             return (FALSE);
    202      1.1  jruoho         }
    203      1.1  jruoho         break;
    204      1.1  jruoho 
    205      1.1  jruoho     default:
    206      1.1  jruoho 
    207      1.1  jruoho         /* Undefined */
    208      1.1  jruoho 
    209      1.1  jruoho         return (FALSE);
    210      1.1  jruoho     }
    211      1.1  jruoho 
    212      1.1  jruoho     return LogicalResult;
    213      1.1  jruoho }
    214      1.1  jruoho 
    215      1.1  jruoho 
    216      1.1  jruoho /*******************************************************************************
    217      1.1  jruoho  *
    218      1.1  jruoho  * FUNCTION:    AcpiExOpcode_6A_0T_1R
    219      1.1  jruoho  *
    220      1.1  jruoho  * PARAMETERS:  WalkState           - Current walk state
    221      1.1  jruoho  *
    222      1.1  jruoho  * RETURN:      Status
    223      1.1  jruoho  *
    224      1.1  jruoho  * DESCRIPTION: Execute opcode with 6 arguments, no target, and a return value
    225      1.1  jruoho  *
    226      1.1  jruoho  ******************************************************************************/
    227      1.1  jruoho 
    228      1.1  jruoho ACPI_STATUS
    229      1.1  jruoho AcpiExOpcode_6A_0T_1R (
    230      1.1  jruoho     ACPI_WALK_STATE         *WalkState)
    231      1.1  jruoho {
    232      1.1  jruoho     ACPI_OPERAND_OBJECT     **Operand = &WalkState->Operands[0];
    233      1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnDesc = NULL;
    234      1.1  jruoho     ACPI_STATUS             Status = AE_OK;
    235      1.1  jruoho     UINT64                  Index;
    236      1.1  jruoho     ACPI_OPERAND_OBJECT     *ThisElement;
    237      1.1  jruoho 
    238      1.1  jruoho 
    239      1.1  jruoho     ACPI_FUNCTION_TRACE_STR (ExOpcode_6A_0T_1R,
    240      1.1  jruoho         AcpiPsGetOpcodeName (WalkState->Opcode));
    241      1.1  jruoho 
    242      1.1  jruoho 
    243      1.1  jruoho     switch (WalkState->Opcode)
    244      1.1  jruoho     {
    245      1.1  jruoho     case AML_MATCH_OP:
    246      1.1  jruoho         /*
    247      1.1  jruoho          * Match (SearchPkg[0], MatchOp1[1], MatchObj1[2],
    248      1.1  jruoho          *                      MatchOp2[3], MatchObj2[4], StartIndex[5])
    249      1.1  jruoho          */
    250      1.1  jruoho 
    251      1.1  jruoho         /* Validate both Match Term Operators (MTR, MEQ, etc.) */
    252      1.1  jruoho 
    253      1.1  jruoho         if ((Operand[1]->Integer.Value > MAX_MATCH_OPERATOR) ||
    254      1.1  jruoho             (Operand[3]->Integer.Value > MAX_MATCH_OPERATOR))
    255      1.1  jruoho         {
    256      1.1  jruoho             ACPI_ERROR ((AE_INFO, "Match operator out of range"));
    257      1.1  jruoho             Status = AE_AML_OPERAND_VALUE;
    258      1.1  jruoho             goto Cleanup;
    259      1.1  jruoho         }
    260      1.1  jruoho 
    261      1.1  jruoho         /* Get the package StartIndex, validate against the package length */
    262      1.1  jruoho 
    263      1.1  jruoho         Index = Operand[5]->Integer.Value;
    264      1.1  jruoho         if (Index >= Operand[0]->Package.Count)
    265      1.1  jruoho         {
    266      1.1  jruoho             ACPI_ERROR ((AE_INFO,
    267      1.1  jruoho                 "Index (0x%8.8X%8.8X) beyond package end (0x%X)",
    268      1.1  jruoho                 ACPI_FORMAT_UINT64 (Index), Operand[0]->Package.Count));
    269      1.1  jruoho             Status = AE_AML_PACKAGE_LIMIT;
    270      1.1  jruoho             goto Cleanup;
    271      1.1  jruoho         }
    272      1.1  jruoho 
    273      1.1  jruoho         /* Create an integer for the return value */
    274      1.1  jruoho         /* Default return value is ACPI_UINT64_MAX if no match found */
    275      1.1  jruoho 
    276      1.1  jruoho         ReturnDesc = AcpiUtCreateIntegerObject (ACPI_UINT64_MAX);
    277      1.1  jruoho         if (!ReturnDesc)
    278      1.1  jruoho         {
    279      1.1  jruoho             Status = AE_NO_MEMORY;
    280      1.1  jruoho             goto Cleanup;
    281      1.1  jruoho 
    282      1.1  jruoho         }
    283      1.1  jruoho 
    284      1.1  jruoho         /*
    285      1.1  jruoho          * Examine each element until a match is found. Both match conditions
    286      1.1  jruoho          * must be satisfied for a match to occur. Within the loop,
    287      1.1  jruoho          * "continue" signifies that the current element does not match
    288      1.1  jruoho          * and the next should be examined.
    289      1.1  jruoho          *
    290      1.1  jruoho          * Upon finding a match, the loop will terminate via "break" at
    291      1.1  jruoho          * the bottom.  If it terminates "normally", MatchValue will be
    292      1.1  jruoho          * ACPI_UINT64_MAX (Ones) (its initial value) indicating that no
    293      1.1  jruoho          * match was found.
    294      1.1  jruoho          */
    295      1.1  jruoho         for ( ; Index < Operand[0]->Package.Count; Index++)
    296      1.1  jruoho         {
    297      1.1  jruoho             /* Get the current package element */
    298      1.1  jruoho 
    299      1.1  jruoho             ThisElement = Operand[0]->Package.Elements[Index];
    300      1.1  jruoho 
    301      1.1  jruoho             /* Treat any uninitialized (NULL) elements as non-matching */
    302      1.1  jruoho 
    303      1.1  jruoho             if (!ThisElement)
    304      1.1  jruoho             {
    305      1.1  jruoho                 continue;
    306      1.1  jruoho             }
    307      1.1  jruoho 
    308      1.1  jruoho             /*
    309      1.1  jruoho              * Both match conditions must be satisfied. Execution of a continue
    310      1.1  jruoho              * (proceed to next iteration of enclosing for loop) signifies a
    311      1.1  jruoho              * non-match.
    312      1.1  jruoho              */
    313      1.1  jruoho             if (!AcpiExDoMatch ((UINT32) Operand[1]->Integer.Value,
    314      1.1  jruoho                                 ThisElement, Operand[2]))
    315      1.1  jruoho             {
    316      1.1  jruoho                 continue;
    317      1.1  jruoho             }
    318      1.1  jruoho 
    319      1.1  jruoho             if (!AcpiExDoMatch ((UINT32) Operand[3]->Integer.Value,
    320      1.1  jruoho                                 ThisElement, Operand[4]))
    321      1.1  jruoho             {
    322      1.1  jruoho                 continue;
    323      1.1  jruoho             }
    324      1.1  jruoho 
    325      1.1  jruoho             /* Match found: Index is the return value */
    326      1.1  jruoho 
    327      1.1  jruoho             ReturnDesc->Integer.Value = Index;
    328      1.1  jruoho             break;
    329      1.1  jruoho         }
    330      1.1  jruoho         break;
    331      1.1  jruoho 
    332      1.1  jruoho 
    333      1.1  jruoho     case AML_LOAD_TABLE_OP:
    334      1.1  jruoho 
    335      1.1  jruoho         Status = AcpiExLoadTableOp (WalkState, &ReturnDesc);
    336      1.1  jruoho         break;
    337      1.1  jruoho 
    338      1.1  jruoho 
    339      1.1  jruoho     default:
    340      1.1  jruoho 
    341      1.1  jruoho         ACPI_ERROR ((AE_INFO, "Unknown AML opcode 0x%X",
    342      1.1  jruoho             WalkState->Opcode));
    343      1.1  jruoho         Status = AE_AML_BAD_OPCODE;
    344      1.1  jruoho         goto Cleanup;
    345      1.1  jruoho     }
    346      1.1  jruoho 
    347      1.1  jruoho 
    348      1.1  jruoho Cleanup:
    349      1.1  jruoho 
    350      1.1  jruoho     /* Delete return object on error */
    351      1.1  jruoho 
    352      1.1  jruoho     if (ACPI_FAILURE (Status))
    353      1.1  jruoho     {
    354      1.1  jruoho         AcpiUtRemoveReference (ReturnDesc);
    355      1.1  jruoho     }
    356      1.1  jruoho 
    357      1.1  jruoho     /* Save return object on success */
    358      1.1  jruoho 
    359      1.1  jruoho     else
    360      1.1  jruoho     {
    361      1.1  jruoho         WalkState->ResultObj = ReturnDesc;
    362      1.1  jruoho     }
    363      1.1  jruoho 
    364      1.1  jruoho     return_ACPI_STATUS (Status);
    365      1.1  jruoho }
    366