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