Home | History | Annotate | Line # | Download | only in compiler
aslxref.c revision 1.1.1.6
      1      1.1  christos /******************************************************************************
      2      1.1  christos  *
      3      1.1  christos  * Module Name: aslxref - Namespace cross-reference
      4      1.1  christos  *
      5      1.1  christos  *****************************************************************************/
      6      1.1  christos 
      7      1.1  christos /*
      8  1.1.1.5  christos  * Copyright (C) 2000 - 2016, Intel Corp.
      9      1.1  christos  * All rights reserved.
     10      1.1  christos  *
     11      1.1  christos  * Redistribution and use in source and binary forms, with or without
     12      1.1  christos  * modification, are permitted provided that the following conditions
     13      1.1  christos  * are met:
     14      1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15      1.1  christos  *    notice, this list of conditions, and the following disclaimer,
     16      1.1  christos  *    without modification.
     17      1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1  christos  *    including a substantially similar Disclaimer requirement for further
     21      1.1  christos  *    binary redistribution.
     22      1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1  christos  *    of any contributors may be used to endorse or promote products derived
     24      1.1  christos  *    from this software without specific prior written permission.
     25      1.1  christos  *
     26      1.1  christos  * Alternatively, this software may be distributed under the terms of the
     27      1.1  christos  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1  christos  * Software Foundation.
     29      1.1  christos  *
     30      1.1  christos  * NO WARRANTY
     31      1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1  christos  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1  christos  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1  christos  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1  christos  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1  christos  */
     43      1.1  christos 
     44      1.1  christos #include "aslcompiler.h"
     45      1.1  christos #include "aslcompiler.y.h"
     46      1.1  christos #include "acparser.h"
     47      1.1  christos #include "amlcode.h"
     48      1.1  christos #include "acnamesp.h"
     49      1.1  christos #include "acdispat.h"
     50      1.1  christos 
     51      1.1  christos 
     52      1.1  christos #define _COMPONENT          ACPI_COMPILER
     53      1.1  christos         ACPI_MODULE_NAME    ("aslxref")
     54      1.1  christos 
     55      1.1  christos /* Local prototypes */
     56      1.1  christos 
     57      1.1  christos static ACPI_STATUS
     58      1.1  christos XfNamespaceLocateBegin (
     59      1.1  christos     ACPI_PARSE_OBJECT       *Op,
     60      1.1  christos     UINT32                  Level,
     61      1.1  christos     void                    *Context);
     62      1.1  christos 
     63      1.1  christos static ACPI_STATUS
     64      1.1  christos XfNamespaceLocateEnd (
     65      1.1  christos     ACPI_PARSE_OBJECT       *Op,
     66      1.1  christos     UINT32                  Level,
     67      1.1  christos     void                    *Context);
     68      1.1  christos 
     69  1.1.1.4  christos static ACPI_PARSE_OBJECT *
     70  1.1.1.4  christos XfGetParentMethod (
     71  1.1.1.4  christos     ACPI_PARSE_OBJECT       *Op);
     72  1.1.1.4  christos 
     73      1.1  christos static BOOLEAN
     74      1.1  christos XfObjectExists (
     75      1.1  christos     char                    *Name);
     76      1.1  christos 
     77      1.1  christos static ACPI_STATUS
     78      1.1  christos XfCompareOneNamespaceObject (
     79      1.1  christos     ACPI_HANDLE             ObjHandle,
     80      1.1  christos     UINT32                  Level,
     81      1.1  christos     void                    *Context,
     82      1.1  christos     void                    **ReturnValue);
     83      1.1  christos 
     84      1.1  christos static void
     85      1.1  christos XfCheckFieldRange (
     86      1.1  christos     ACPI_PARSE_OBJECT       *Op,
     87      1.1  christos     UINT32                  RegionBitLength,
     88      1.1  christos     UINT32                  FieldBitOffset,
     89      1.1  christos     UINT32                  FieldBitLength,
     90      1.1  christos     UINT32                  AccessBitWidth);
     91      1.1  christos 
     92  1.1.1.2  christos #ifdef __UNDER_DEVELOPMENT
     93  1.1.1.2  christos static ACPI_PARSE_OBJECT *
     94  1.1.1.2  christos XfGetParentMethod (
     95  1.1.1.2  christos     ACPI_PARSE_OBJECT       *Op);
     96  1.1.1.2  christos 
     97  1.1.1.2  christos static void
     98  1.1.1.2  christos XfCheckIllegalReference (
     99  1.1.1.2  christos     ACPI_PARSE_OBJECT       *Op,
    100  1.1.1.2  christos     ACPI_NAMESPACE_NODE     *Node);
    101  1.1.1.2  christos 
    102  1.1.1.2  christos static BOOLEAN
    103  1.1.1.2  christos XfIsObjectParental (
    104  1.1.1.2  christos     ACPI_PARSE_OBJECT       *MethodOp1,
    105  1.1.1.2  christos     ACPI_PARSE_OBJECT       *MethodOp2);
    106  1.1.1.2  christos #endif
    107  1.1.1.2  christos 
    108      1.1  christos 
    109      1.1  christos /*******************************************************************************
    110      1.1  christos  *
    111      1.1  christos  * FUNCTION:    XfCrossReferenceNamespace
    112      1.1  christos  *
    113      1.1  christos  * PARAMETERS:  None
    114      1.1  christos  *
    115      1.1  christos  * RETURN:      Status
    116      1.1  christos  *
    117      1.1  christos  * DESCRIPTION: Perform a cross reference check of the parse tree against the
    118      1.1  christos  *              namespace. Every named referenced within the parse tree
    119      1.1  christos  *              should be get resolved with a namespace lookup. If not, the
    120      1.1  christos  *              original reference in the ASL code is invalid -- i.e., refers
    121      1.1  christos  *              to a non-existent object.
    122      1.1  christos  *
    123      1.1  christos  * NOTE:  The ASL "External" operator causes the name to be inserted into the
    124      1.1  christos  *        namespace so that references to the external name will be resolved
    125      1.1  christos  *        correctly here.
    126      1.1  christos  *
    127      1.1  christos  ******************************************************************************/
    128      1.1  christos 
    129      1.1  christos ACPI_STATUS
    130      1.1  christos XfCrossReferenceNamespace (
    131      1.1  christos     void)
    132      1.1  christos {
    133      1.1  christos     ACPI_WALK_STATE         *WalkState;
    134      1.1  christos 
    135      1.1  christos 
    136      1.1  christos     /*
    137      1.1  christos      * Create a new walk state for use when looking up names
    138      1.1  christos      * within the namespace (Passed as context to the callbacks)
    139      1.1  christos      */
    140      1.1  christos     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
    141      1.1  christos     if (!WalkState)
    142      1.1  christos     {
    143      1.1  christos         return (AE_NO_MEMORY);
    144      1.1  christos     }
    145      1.1  christos 
    146      1.1  christos     /* Walk the entire parse tree */
    147      1.1  christos 
    148  1.1.1.6  christos     TrWalkParseTree (Gbl_ParseTreeRoot, ASL_WALK_VISIT_TWICE,
    149  1.1.1.6  christos         XfNamespaceLocateBegin, XfNamespaceLocateEnd, WalkState);
    150  1.1.1.2  christos 
    151  1.1.1.2  christos     ACPI_FREE (WalkState);
    152      1.1  christos     return (AE_OK);
    153      1.1  christos }
    154      1.1  christos 
    155      1.1  christos 
    156      1.1  christos /*******************************************************************************
    157      1.1  christos  *
    158      1.1  christos  * FUNCTION:    XfObjectExists
    159      1.1  christos  *
    160      1.1  christos  * PARAMETERS:  Name            - 4 char ACPI name
    161      1.1  christos  *
    162      1.1  christos  * RETURN:      TRUE if name exists in namespace
    163      1.1  christos  *
    164      1.1  christos  * DESCRIPTION: Walk the namespace to find an object
    165      1.1  christos  *
    166      1.1  christos  ******************************************************************************/
    167      1.1  christos 
    168      1.1  christos static BOOLEAN
    169      1.1  christos XfObjectExists (
    170      1.1  christos     char                    *Name)
    171      1.1  christos {
    172      1.1  christos     ACPI_STATUS             Status;
    173      1.1  christos 
    174      1.1  christos 
    175      1.1  christos     /* Walk entire namespace from the supplied root */
    176      1.1  christos 
    177      1.1  christos     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    178  1.1.1.5  christos         ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
    179  1.1.1.5  christos         Name, NULL);
    180      1.1  christos     if (Status == AE_CTRL_TRUE)
    181      1.1  christos     {
    182      1.1  christos         /* At least one instance of the name was found */
    183      1.1  christos 
    184      1.1  christos         return (TRUE);
    185      1.1  christos     }
    186      1.1  christos 
    187      1.1  christos     return (FALSE);
    188      1.1  christos }
    189      1.1  christos 
    190      1.1  christos 
    191      1.1  christos /*******************************************************************************
    192      1.1  christos  *
    193      1.1  christos  * FUNCTION:    XfCompareOneNamespaceObject
    194      1.1  christos  *
    195      1.1  christos  * PARAMETERS:  ACPI_WALK_CALLBACK
    196      1.1  christos  *
    197      1.1  christos  * RETURN:      Status
    198      1.1  christos  *
    199      1.1  christos  * DESCRIPTION: Compare name of one object.
    200      1.1  christos  *
    201      1.1  christos  ******************************************************************************/
    202      1.1  christos 
    203      1.1  christos static ACPI_STATUS
    204      1.1  christos XfCompareOneNamespaceObject (
    205      1.1  christos     ACPI_HANDLE             ObjHandle,
    206      1.1  christos     UINT32                  Level,
    207      1.1  christos     void                    *Context,
    208      1.1  christos     void                    **ReturnValue)
    209      1.1  christos {
    210      1.1  christos     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    211      1.1  christos 
    212      1.1  christos 
    213      1.1  christos     /* Simply check the name */
    214      1.1  christos 
    215      1.1  christos     if (*((UINT32 *) (Context)) == Node->Name.Integer)
    216      1.1  christos     {
    217      1.1  christos         /* Abort walk if we found one instance */
    218      1.1  christos 
    219      1.1  christos         return (AE_CTRL_TRUE);
    220      1.1  christos     }
    221      1.1  christos 
    222      1.1  christos     return (AE_OK);
    223      1.1  christos }
    224      1.1  christos 
    225      1.1  christos 
    226      1.1  christos /*******************************************************************************
    227      1.1  christos  *
    228      1.1  christos  * FUNCTION:    XfCheckFieldRange
    229      1.1  christos  *
    230      1.1  christos  * PARAMETERS:  RegionBitLength     - Length of entire parent region
    231      1.1  christos  *              FieldBitOffset      - Start of the field unit (within region)
    232      1.1  christos  *              FieldBitLength      - Entire length of field unit
    233      1.1  christos  *              AccessBitWidth      - Access width of the field unit
    234      1.1  christos  *
    235      1.1  christos  * RETURN:      None
    236      1.1  christos  *
    237      1.1  christos  * DESCRIPTION: Check one field unit to make sure it fits in the parent
    238      1.1  christos  *              op region.
    239      1.1  christos  *
    240      1.1  christos  * Note: AccessBitWidth must be either 8,16,32, or 64
    241      1.1  christos  *
    242      1.1  christos  ******************************************************************************/
    243      1.1  christos 
    244      1.1  christos static void
    245      1.1  christos XfCheckFieldRange (
    246      1.1  christos     ACPI_PARSE_OBJECT       *Op,
    247      1.1  christos     UINT32                  RegionBitLength,
    248      1.1  christos     UINT32                  FieldBitOffset,
    249      1.1  christos     UINT32                  FieldBitLength,
    250      1.1  christos     UINT32                  AccessBitWidth)
    251      1.1  christos {
    252      1.1  christos     UINT32                  FieldEndBitOffset;
    253      1.1  christos 
    254      1.1  christos 
    255      1.1  christos     /*
    256      1.1  christos      * Check each field unit against the region size. The entire
    257      1.1  christos      * field unit (start offset plus length) must fit within the
    258      1.1  christos      * region.
    259      1.1  christos      */
    260      1.1  christos     FieldEndBitOffset = FieldBitOffset + FieldBitLength;
    261      1.1  christos 
    262      1.1  christos     if (FieldEndBitOffset > RegionBitLength)
    263      1.1  christos     {
    264      1.1  christos         /* Field definition itself is beyond the end-of-region */
    265      1.1  christos 
    266      1.1  christos         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
    267      1.1  christos         return;
    268      1.1  christos     }
    269      1.1  christos 
    270      1.1  christos     /*
    271      1.1  christos      * Now check that the field plus AccessWidth doesn't go beyond
    272      1.1  christos      * the end-of-region. Assumes AccessBitWidth is a power of 2
    273      1.1  christos      */
    274      1.1  christos     FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
    275      1.1  christos 
    276      1.1  christos     if (FieldEndBitOffset > RegionBitLength)
    277      1.1  christos     {
    278      1.1  christos         /* Field definition combined with the access is beyond EOR */
    279      1.1  christos 
    280      1.1  christos         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
    281      1.1  christos     }
    282      1.1  christos }
    283      1.1  christos 
    284  1.1.1.2  christos 
    285  1.1.1.2  christos /*******************************************************************************
    286  1.1.1.2  christos  *
    287  1.1.1.2  christos  * FUNCTION:    XfGetParentMethod
    288  1.1.1.2  christos  *
    289  1.1.1.4  christos  * PARAMETERS:  Op                      - Parse Op to be checked
    290  1.1.1.2  christos  *
    291  1.1.1.4  christos  * RETURN:      Control method Op if found. NULL otherwise
    292  1.1.1.2  christos  *
    293  1.1.1.4  christos  * DESCRIPTION: Find the control method parent of a parse op. Returns NULL if
    294  1.1.1.4  christos  *              the input Op is not within a control method.
    295  1.1.1.2  christos  *
    296  1.1.1.2  christos  ******************************************************************************/
    297  1.1.1.2  christos 
    298  1.1.1.2  christos static ACPI_PARSE_OBJECT *
    299  1.1.1.2  christos XfGetParentMethod (
    300  1.1.1.2  christos     ACPI_PARSE_OBJECT       *Op)
    301  1.1.1.2  christos {
    302  1.1.1.4  christos     ACPI_PARSE_OBJECT       *NextOp;
    303  1.1.1.2  christos 
    304  1.1.1.2  christos 
    305  1.1.1.4  christos     NextOp = Op->Asl.Parent;
    306  1.1.1.4  christos     while (NextOp)
    307  1.1.1.2  christos     {
    308  1.1.1.4  christos         if (NextOp->Asl.AmlOpcode == AML_METHOD_OP)
    309  1.1.1.2  christos         {
    310  1.1.1.4  christos             return (NextOp);
    311  1.1.1.2  christos         }
    312  1.1.1.2  christos 
    313  1.1.1.4  christos         NextOp = NextOp->Asl.Parent;
    314  1.1.1.2  christos     }
    315  1.1.1.2  christos 
    316  1.1.1.4  christos     return (NULL); /* No parent method found */
    317  1.1.1.2  christos }
    318  1.1.1.2  christos 
    319      1.1  christos /*******************************************************************************
    320      1.1  christos  *
    321      1.1  christos  * FUNCTION:    XfNamespaceLocateBegin
    322      1.1  christos  *
    323      1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
    324      1.1  christos  *
    325      1.1  christos  * RETURN:      Status
    326      1.1  christos  *
    327      1.1  christos  * DESCRIPTION: Descending callback used during cross-reference. For named
    328      1.1  christos  *              object references, attempt to locate the name in the
    329      1.1  christos  *              namespace.
    330      1.1  christos  *
    331      1.1  christos  * NOTE: ASL references to named fields within resource descriptors are
    332      1.1  christos  *       resolved to integer values here. Therefore, this step is an
    333      1.1  christos  *       important part of the code generation. We don't know that the
    334      1.1  christos  *       name refers to a resource descriptor until now.
    335      1.1  christos  *
    336      1.1  christos  ******************************************************************************/
    337      1.1  christos 
    338      1.1  christos static ACPI_STATUS
    339      1.1  christos XfNamespaceLocateBegin (
    340      1.1  christos     ACPI_PARSE_OBJECT       *Op,
    341      1.1  christos     UINT32                  Level,
    342      1.1  christos     void                    *Context)
    343      1.1  christos {
    344      1.1  christos     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
    345      1.1  christos     ACPI_NAMESPACE_NODE     *Node;
    346      1.1  christos     ACPI_STATUS             Status;
    347      1.1  christos     ACPI_OBJECT_TYPE        ObjectType;
    348      1.1  christos     char                    *Path;
    349      1.1  christos     UINT8                   PassedArgs;
    350      1.1  christos     ACPI_PARSE_OBJECT       *NextOp;
    351      1.1  christos     ACPI_PARSE_OBJECT       *OwningOp;
    352      1.1  christos     ACPI_PARSE_OBJECT       *SpaceIdOp;
    353      1.1  christos     UINT32                  MinimumLength;
    354      1.1  christos     UINT32                  Offset;
    355      1.1  christos     UINT32                  FieldBitLength;
    356      1.1  christos     UINT32                  TagBitLength;
    357      1.1  christos     UINT8                   Message = 0;
    358      1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    359      1.1  christos     UINT32                  Flags;
    360  1.1.1.4  christos     ASL_METHOD_LOCAL        *MethodLocals = NULL;
    361  1.1.1.4  christos     ASL_METHOD_LOCAL        *MethodArgs = NULL;
    362  1.1.1.4  christos     int                     RegisterNumber;
    363  1.1.1.4  christos     UINT32                  i;
    364      1.1  christos 
    365      1.1  christos 
    366      1.1  christos     ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
    367      1.1  christos 
    368  1.1.1.4  christos 
    369  1.1.1.4  christos     if ((Op->Asl.AmlOpcode == AML_METHOD_OP) && Op->Asl.Node)
    370  1.1.1.4  christos     {
    371  1.1.1.4  christos         Node = Op->Asl.Node;
    372  1.1.1.4  christos 
    373  1.1.1.4  christos         /* Support for method LocalX/ArgX analysis */
    374  1.1.1.4  christos 
    375  1.1.1.4  christos         if (!Node->MethodLocals)
    376  1.1.1.4  christos         {
    377  1.1.1.4  christos             /* Create local/arg info blocks */
    378  1.1.1.4  christos 
    379  1.1.1.4  christos             MethodLocals = UtLocalCalloc (
    380  1.1.1.4  christos                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_LOCALS);
    381  1.1.1.4  christos             Node->MethodLocals = MethodLocals;
    382  1.1.1.4  christos 
    383  1.1.1.4  christos             MethodArgs = UtLocalCalloc (
    384  1.1.1.4  christos                 sizeof (ASL_METHOD_LOCAL) * ACPI_METHOD_NUM_ARGS);
    385  1.1.1.4  christos             Node->MethodArgs = MethodArgs;
    386  1.1.1.4  christos 
    387  1.1.1.4  christos             /*
    388  1.1.1.4  christos              * Get the method argument count
    389  1.1.1.4  christos              * First, get the name node
    390  1.1.1.4  christos              */
    391  1.1.1.4  christos             NextOp = Op->Asl.Child;
    392  1.1.1.4  christos 
    393  1.1.1.4  christos             /* Get the NumArguments node */
    394  1.1.1.4  christos 
    395  1.1.1.4  christos             NextOp = NextOp->Asl.Next;
    396  1.1.1.4  christos             Node->ArgCount = (UINT8)
    397  1.1.1.4  christos                 (((UINT8) NextOp->Asl.Value.Integer) & 0x07);
    398  1.1.1.4  christos 
    399  1.1.1.4  christos             /* We will track all posible ArgXs */
    400  1.1.1.4  christos 
    401  1.1.1.4  christos             for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++)
    402  1.1.1.4  christos             {
    403  1.1.1.4  christos                 if (i < Node->ArgCount)
    404  1.1.1.4  christos                 {
    405  1.1.1.4  christos                     /* Real Args are always "initialized" */
    406  1.1.1.4  christos 
    407  1.1.1.4  christos                     MethodArgs[i].Flags = ASL_ARG_INITIALIZED;
    408  1.1.1.4  christos                 }
    409  1.1.1.4  christos                 else
    410  1.1.1.4  christos                 {
    411  1.1.1.4  christos                     /* Other ArgXs can be used as locals */
    412  1.1.1.4  christos 
    413  1.1.1.4  christos                     MethodArgs[i].Flags = ASL_ARG_IS_LOCAL;
    414  1.1.1.4  christos                 }
    415  1.1.1.4  christos 
    416  1.1.1.4  christos                 MethodArgs[i].Op = Op;
    417  1.1.1.4  christos             }
    418  1.1.1.4  christos         }
    419  1.1.1.4  christos     }
    420  1.1.1.4  christos 
    421      1.1  christos     /*
    422      1.1  christos      * If this node is the actual declaration of a name
    423      1.1  christos      * [such as the XXXX name in "Method (XXXX)"],
    424      1.1  christos      * we are not interested in it here. We only care about names that are
    425      1.1  christos      * references to other objects within the namespace and the parent objects
    426      1.1  christos      * of name declarations
    427      1.1  christos      */
    428      1.1  christos     if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
    429      1.1  christos     {
    430      1.1  christos         return_ACPI_STATUS (AE_OK);
    431      1.1  christos     }
    432      1.1  christos 
    433      1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    434      1.1  christos 
    435  1.1.1.4  christos     /* Check method LocalX variables */
    436  1.1.1.4  christos 
    437  1.1.1.4  christos     if (OpInfo->Type == AML_TYPE_LOCAL_VARIABLE)
    438  1.1.1.4  christos     {
    439  1.1.1.4  christos         /* Find parent method Op */
    440  1.1.1.4  christos 
    441  1.1.1.4  christos         NextOp = XfGetParentMethod (Op);
    442  1.1.1.4  christos         if (!NextOp)
    443  1.1.1.4  christos         {
    444  1.1.1.4  christos             return_ACPI_STATUS (AE_OK);
    445  1.1.1.4  christos         }
    446  1.1.1.4  christos 
    447  1.1.1.4  christos         /* Get method node */
    448  1.1.1.4  christos 
    449  1.1.1.4  christos         Node = NextOp->Asl.Node;
    450  1.1.1.4  christos 
    451  1.1.1.4  christos         RegisterNumber = Op->Asl.AmlOpcode & 0x0007; /* 0x60 through 0x67 */
    452  1.1.1.4  christos         MethodLocals = Node->MethodLocals;
    453  1.1.1.4  christos 
    454  1.1.1.4  christos         if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    455  1.1.1.4  christos         {
    456  1.1.1.4  christos             /* Local is being initialized */
    457  1.1.1.4  christos 
    458  1.1.1.4  christos             MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_INITIALIZED;
    459  1.1.1.4  christos             MethodLocals[RegisterNumber].Op = Op;
    460  1.1.1.4  christos 
    461  1.1.1.4  christos             return_ACPI_STATUS (AE_OK);
    462  1.1.1.4  christos         }
    463  1.1.1.4  christos 
    464  1.1.1.4  christos         /* Mark this Local as referenced */
    465  1.1.1.4  christos 
    466  1.1.1.4  christos         MethodLocals[RegisterNumber].Flags |= ASL_LOCAL_REFERENCED;
    467  1.1.1.4  christos         MethodLocals[RegisterNumber].Op = Op;
    468  1.1.1.4  christos 
    469  1.1.1.4  christos         return_ACPI_STATUS (AE_OK);
    470  1.1.1.4  christos     }
    471  1.1.1.4  christos 
    472  1.1.1.4  christos     /* Check method ArgX variables */
    473  1.1.1.4  christos 
    474  1.1.1.4  christos     if (OpInfo->Type == AML_TYPE_METHOD_ARGUMENT)
    475  1.1.1.4  christos     {
    476  1.1.1.4  christos         /* Find parent method Op */
    477  1.1.1.4  christos 
    478  1.1.1.4  christos         NextOp = XfGetParentMethod (Op);
    479  1.1.1.4  christos         if (!NextOp)
    480  1.1.1.4  christos         {
    481  1.1.1.4  christos             return_ACPI_STATUS (AE_OK);
    482  1.1.1.4  christos         }
    483  1.1.1.4  christos 
    484  1.1.1.4  christos         /* Get method node */
    485  1.1.1.4  christos 
    486  1.1.1.4  christos         Node = NextOp->Asl.Node;
    487  1.1.1.4  christos 
    488  1.1.1.4  christos         /* Get Arg # */
    489  1.1.1.4  christos 
    490  1.1.1.4  christos         RegisterNumber = Op->Asl.AmlOpcode - AML_ARG0; /* 0x68 through 0x6F */
    491  1.1.1.4  christos         MethodArgs = Node->MethodArgs;
    492  1.1.1.4  christos 
    493  1.1.1.4  christos         if (Op->Asl.CompileFlags & NODE_IS_TARGET)
    494  1.1.1.4  christos         {
    495  1.1.1.4  christos             /* Arg is being initialized */
    496  1.1.1.4  christos 
    497  1.1.1.4  christos             MethodArgs[RegisterNumber].Flags |= ASL_ARG_INITIALIZED;
    498  1.1.1.4  christos             MethodArgs[RegisterNumber].Op = Op;
    499  1.1.1.4  christos 
    500  1.1.1.4  christos             return_ACPI_STATUS (AE_OK);
    501  1.1.1.4  christos         }
    502  1.1.1.4  christos 
    503  1.1.1.4  christos         /* Mark this Arg as referenced */
    504  1.1.1.4  christos 
    505  1.1.1.4  christos         MethodArgs[RegisterNumber].Flags |= ASL_ARG_REFERENCED;
    506  1.1.1.4  christos         MethodArgs[RegisterNumber].Op = Op;
    507  1.1.1.4  christos 
    508  1.1.1.4  christos         return_ACPI_STATUS (AE_OK);
    509  1.1.1.4  christos     }
    510  1.1.1.4  christos 
    511  1.1.1.4  christos     /*
    512  1.1.1.4  christos      * After method ArgX and LocalX, we are only interested in opcodes
    513  1.1.1.4  christos      * that have an associated name
    514  1.1.1.4  christos      */
    515      1.1  christos     if ((!(OpInfo->Flags & AML_NAMED)) &&
    516      1.1  christos         (!(OpInfo->Flags & AML_CREATE)) &&
    517      1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
    518      1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
    519      1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
    520      1.1  christos     {
    521      1.1  christos         return_ACPI_STATUS (AE_OK);
    522      1.1  christos     }
    523      1.1  christos 
    524      1.1  christos     /*
    525      1.1  christos      * One special case: CondRefOf operator - we don't care if the name exists
    526      1.1  christos      * or not at this point, just ignore it, the point of the operator is to
    527      1.1  christos      * determine if the name exists at runtime.
    528      1.1  christos      */
    529      1.1  christos     if ((Op->Asl.Parent) &&
    530      1.1  christos         (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
    531      1.1  christos     {
    532      1.1  christos         return_ACPI_STATUS (AE_OK);
    533      1.1  christos     }
    534      1.1  christos 
    535      1.1  christos     /*
    536      1.1  christos      * We must enable the "search-to-root" for single NameSegs, but
    537      1.1  christos      * we have to be very careful about opening up scopes
    538      1.1  christos      */
    539      1.1  christos     Flags = ACPI_NS_SEARCH_PARENT;
    540      1.1  christos     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
    541      1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
    542      1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
    543      1.1  christos     {
    544      1.1  christos         /*
    545      1.1  christos          * These are name references, do not push the scope stack
    546      1.1  christos          * for them.
    547      1.1  christos          */
    548      1.1  christos         Flags |= ACPI_NS_DONT_OPEN_SCOPE;
    549      1.1  christos     }
    550      1.1  christos 
    551      1.1  christos     /* Get the NamePath from the appropriate place */
    552      1.1  christos 
    553      1.1  christos     if (OpInfo->Flags & AML_NAMED)
    554      1.1  christos     {
    555      1.1  christos         /* For nearly all NAMED operators, the name reference is the first child */
    556      1.1  christos 
    557      1.1  christos         Path = Op->Asl.Child->Asl.Value.String;
    558      1.1  christos         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
    559      1.1  christos         {
    560      1.1  christos             /*
    561      1.1  christos              * ALIAS is the only oddball opcode, the name declaration
    562      1.1  christos              * (alias name) is the second operand
    563      1.1  christos              */
    564      1.1  christos             Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
    565      1.1  christos         }
    566      1.1  christos     }
    567      1.1  christos     else if (OpInfo->Flags & AML_CREATE)
    568      1.1  christos     {
    569      1.1  christos         /* Name must appear as the last parameter */
    570      1.1  christos 
    571      1.1  christos         NextOp = Op->Asl.Child;
    572      1.1  christos         while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
    573      1.1  christos         {
    574      1.1  christos             NextOp = NextOp->Asl.Next;
    575      1.1  christos         }
    576  1.1.1.5  christos 
    577      1.1  christos         Path = NextOp->Asl.Value.String;
    578      1.1  christos     }
    579      1.1  christos     else
    580      1.1  christos     {
    581      1.1  christos         Path = Op->Asl.Value.String;
    582      1.1  christos     }
    583      1.1  christos 
    584      1.1  christos     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
    585      1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    586      1.1  christos         "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
    587      1.1  christos 
    588      1.1  christos     /*
    589      1.1  christos      * Lookup the name in the namespace. Name must exist at this point, or it
    590      1.1  christos      * is an invalid reference.
    591      1.1  christos      *
    592      1.1  christos      * The namespace is also used as a lookup table for references to resource
    593      1.1  christos      * descriptors and the fields within them.
    594      1.1  christos      */
    595      1.1  christos     Gbl_NsLookupCount++;
    596      1.1  christos 
    597      1.1  christos     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
    598  1.1.1.5  christos         ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
    599      1.1  christos     if (ACPI_FAILURE (Status))
    600      1.1  christos     {
    601      1.1  christos         if (Status == AE_NOT_FOUND)
    602      1.1  christos         {
    603      1.1  christos             /*
    604      1.1  christos              * We didn't find the name reference by path -- we can qualify this
    605      1.1  christos              * a little better before we print an error message
    606      1.1  christos              */
    607      1.1  christos             if (strlen (Path) == ACPI_NAME_SIZE)
    608      1.1  christos             {
    609      1.1  christos                 /* A simple, one-segment ACPI name */
    610      1.1  christos 
    611      1.1  christos                 if (XfObjectExists (Path))
    612      1.1  christos                 {
    613      1.1  christos                     /*
    614      1.1  christos                      * There exists such a name, but we couldn't get to it
    615      1.1  christos                      * from this scope
    616      1.1  christos                      */
    617      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
    618      1.1  christos                         Op->Asl.ExternalName);
    619      1.1  christos                 }
    620      1.1  christos                 else
    621      1.1  christos                 {
    622      1.1  christos                     /* The name doesn't exist, period */
    623      1.1  christos 
    624      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
    625      1.1  christos                         Op, Op->Asl.ExternalName);
    626      1.1  christos                 }
    627      1.1  christos             }
    628      1.1  christos             else
    629      1.1  christos             {
    630      1.1  christos                 /* Check for a fully qualified path */
    631      1.1  christos 
    632      1.1  christos                 if (Path[0] == AML_ROOT_PREFIX)
    633      1.1  christos                 {
    634      1.1  christos                     /* Gave full path, the object does not exist */
    635      1.1  christos 
    636      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
    637      1.1  christos                         Op->Asl.ExternalName);
    638      1.1  christos                 }
    639      1.1  christos                 else
    640      1.1  christos                 {
    641      1.1  christos                     /*
    642      1.1  christos                      * We can't tell whether it doesn't exist or just
    643      1.1  christos                      * can't be reached.
    644      1.1  christos                      */
    645      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
    646      1.1  christos                         Op->Asl.ExternalName);
    647      1.1  christos                 }
    648      1.1  christos             }
    649      1.1  christos 
    650      1.1  christos             Status = AE_OK;
    651      1.1  christos         }
    652      1.1  christos 
    653      1.1  christos         return_ACPI_STATUS (Status);
    654      1.1  christos     }
    655      1.1  christos 
    656      1.1  christos     /* Check for a reference vs. name declaration */
    657      1.1  christos 
    658      1.1  christos     if (!(OpInfo->Flags & AML_NAMED) &&
    659      1.1  christos         !(OpInfo->Flags & AML_CREATE))
    660      1.1  christos     {
    661      1.1  christos         /* This node has been referenced, mark it for reference check */
    662      1.1  christos 
    663      1.1  christos         Node->Flags |= ANOBJ_IS_REFERENCED;
    664  1.1.1.2  christos 
    665  1.1.1.2  christos #ifdef __UNDER_DEVELOPMENT
    666  1.1.1.2  christos 
    667  1.1.1.2  christos         /* Check for an illegal reference */
    668  1.1.1.2  christos 
    669  1.1.1.2  christos         XfCheckIllegalReference (Op, Node);
    670  1.1.1.2  christos #endif
    671      1.1  christos     }
    672      1.1  christos 
    673      1.1  christos     /* Attempt to optimize the NamePath */
    674      1.1  christos 
    675      1.1  christos     OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
    676      1.1  christos 
    677      1.1  christos     /*
    678      1.1  christos      * 1) Dereference an alias (A name reference that is an alias)
    679      1.1  christos      *    Aliases are not nested, the alias always points to the final object
    680      1.1  christos      */
    681      1.1  christos     if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
    682      1.1  christos         (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
    683      1.1  christos     {
    684      1.1  christos         /* This node points back to the original PARSEOP_ALIAS */
    685      1.1  christos 
    686      1.1  christos         NextOp = Node->Op;
    687      1.1  christos 
    688      1.1  christos         /* The first child is the alias target op */
    689      1.1  christos 
    690      1.1  christos         NextOp = NextOp->Asl.Child;
    691      1.1  christos 
    692      1.1  christos         /* That in turn points back to original target alias node */
    693      1.1  christos 
    694      1.1  christos         if (NextOp->Asl.Node)
    695      1.1  christos         {
    696      1.1  christos             Node = NextOp->Asl.Node;
    697      1.1  christos         }
    698      1.1  christos 
    699      1.1  christos         /* Else - forward reference to alias, will be resolved later */
    700      1.1  christos     }
    701      1.1  christos 
    702      1.1  christos     /* 2) Check for a reference to a resource descriptor */
    703      1.1  christos 
    704      1.1  christos     if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
    705      1.1  christos         (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
    706      1.1  christos     {
    707      1.1  christos         /*
    708      1.1  christos          * This was a reference to a field within a resource descriptor.
    709      1.1  christos          * Extract the associated field offset (either a bit or byte
    710      1.1  christos          * offset depending on the field type) and change the named
    711      1.1  christos          * reference into an integer for AML code generation
    712      1.1  christos          */
    713      1.1  christos         Offset = Node->Value;
    714      1.1  christos         TagBitLength = Node->Length;
    715      1.1  christos 
    716      1.1  christos         /*
    717      1.1  christos          * If a field is being created, generate the length (in bits) of
    718      1.1  christos          * the field. Note: Opcodes other than CreateXxxField and Index
    719      1.1  christos          * can come through here. For other opcodes, we just need to
    720      1.1  christos          * convert the resource tag reference to an integer offset.
    721      1.1  christos          */
    722      1.1  christos         switch (Op->Asl.Parent->Asl.AmlOpcode)
    723      1.1  christos         {
    724      1.1  christos         case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
    725      1.1  christos             /*
    726      1.1  christos              * We know the length operand is an integer constant because
    727      1.1  christos              * we know that it contains a reference to a resource
    728      1.1  christos              * descriptor tag.
    729      1.1  christos              */
    730      1.1  christos             FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
    731      1.1  christos             break;
    732      1.1  christos 
    733      1.1  christos         case AML_CREATE_BIT_FIELD_OP:
    734      1.1  christos 
    735      1.1  christos             FieldBitLength = 1;
    736      1.1  christos             break;
    737      1.1  christos 
    738      1.1  christos         case AML_CREATE_BYTE_FIELD_OP:
    739      1.1  christos         case AML_INDEX_OP:
    740      1.1  christos 
    741      1.1  christos             FieldBitLength = 8;
    742      1.1  christos             break;
    743      1.1  christos 
    744      1.1  christos         case AML_CREATE_WORD_FIELD_OP:
    745      1.1  christos 
    746      1.1  christos             FieldBitLength = 16;
    747      1.1  christos             break;
    748      1.1  christos 
    749      1.1  christos         case AML_CREATE_DWORD_FIELD_OP:
    750      1.1  christos 
    751      1.1  christos             FieldBitLength = 32;
    752      1.1  christos             break;
    753      1.1  christos 
    754      1.1  christos         case AML_CREATE_QWORD_FIELD_OP:
    755      1.1  christos 
    756      1.1  christos             FieldBitLength = 64;
    757      1.1  christos             break;
    758      1.1  christos 
    759      1.1  christos         default:
    760      1.1  christos 
    761      1.1  christos             FieldBitLength = 0;
    762      1.1  christos             break;
    763      1.1  christos         }
    764      1.1  christos 
    765      1.1  christos         /* Check the field length against the length of the resource tag */
    766      1.1  christos 
    767      1.1  christos         if (FieldBitLength)
    768      1.1  christos         {
    769      1.1  christos             if (TagBitLength < FieldBitLength)
    770      1.1  christos             {
    771      1.1  christos                 Message = ASL_MSG_TAG_SMALLER;
    772      1.1  christos             }
    773      1.1  christos             else if (TagBitLength > FieldBitLength)
    774      1.1  christos             {
    775      1.1  christos                 Message = ASL_MSG_TAG_LARGER;
    776      1.1  christos             }
    777      1.1  christos 
    778      1.1  christos             if (Message)
    779      1.1  christos             {
    780  1.1.1.5  christos                 sprintf (MsgBuffer,
    781  1.1.1.5  christos                     "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
    782      1.1  christos                     TagBitLength, (TagBitLength > 1) ? "s" : "",
    783      1.1  christos                     FieldBitLength, (FieldBitLength > 1) ? "s" : "");
    784      1.1  christos 
    785      1.1  christos                 AslError (ASL_WARNING, Message, Op, MsgBuffer);
    786      1.1  christos             }
    787      1.1  christos         }
    788      1.1  christos 
    789      1.1  christos         /* Convert the BitOffset to a ByteOffset for certain opcodes */
    790      1.1  christos 
    791      1.1  christos         switch (Op->Asl.Parent->Asl.AmlOpcode)
    792      1.1  christos         {
    793      1.1  christos         case AML_CREATE_BYTE_FIELD_OP:
    794      1.1  christos         case AML_CREATE_WORD_FIELD_OP:
    795      1.1  christos         case AML_CREATE_DWORD_FIELD_OP:
    796      1.1  christos         case AML_CREATE_QWORD_FIELD_OP:
    797      1.1  christos         case AML_INDEX_OP:
    798      1.1  christos 
    799      1.1  christos             Offset = ACPI_DIV_8 (Offset);
    800      1.1  christos             break;
    801      1.1  christos 
    802      1.1  christos         default:
    803      1.1  christos 
    804      1.1  christos             break;
    805      1.1  christos         }
    806      1.1  christos 
    807      1.1  christos         /* Now convert this node to an integer whose value is the field offset */
    808      1.1  christos 
    809      1.1  christos         Op->Asl.AmlLength = 0;
    810      1.1  christos         Op->Asl.ParseOpcode = PARSEOP_INTEGER;
    811      1.1  christos         Op->Asl.Value.Integer = (UINT64) Offset;
    812      1.1  christos         Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
    813      1.1  christos 
    814      1.1  christos         OpcGenerateAmlOpcode (Op);
    815      1.1  christos     }
    816      1.1  christos 
    817      1.1  christos     /* 3) Check for a method invocation */
    818      1.1  christos 
    819      1.1  christos     else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
    820      1.1  christos                 (Node->Type == ACPI_TYPE_METHOD) &&
    821      1.1  christos                 (Op->Asl.Parent) &&
    822      1.1  christos                 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD))   ||
    823      1.1  christos 
    824      1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
    825      1.1  christos     {
    826      1.1  christos         /*
    827      1.1  christos          * A reference to a method within one of these opcodes is not an
    828      1.1  christos          * invocation of the method, it is simply a reference to the method.
    829      1.1  christos          */
    830      1.1  christos         if ((Op->Asl.Parent) &&
    831      1.1  christos            ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF)      ||
    832      1.1  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF)    ||
    833  1.1.1.3  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_PACKAGE)    ||
    834  1.1.1.3  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_VAR_PACKAGE)||
    835      1.1  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
    836      1.1  christos         {
    837      1.1  christos             return_ACPI_STATUS (AE_OK);
    838      1.1  christos         }
    839      1.1  christos         /*
    840      1.1  christos          * There are two types of method invocation:
    841      1.1  christos          * 1) Invocation with arguments -- the parser recognizes this
    842      1.1  christos          *    as a METHODCALL.
    843      1.1  christos          * 2) Invocation with no arguments --the parser cannot determine that
    844      1.1  christos          *    this is a method invocation, therefore we have to figure it out
    845      1.1  christos          *    here.
    846      1.1  christos          */
    847      1.1  christos         if (Node->Type != ACPI_TYPE_METHOD)
    848      1.1  christos         {
    849      1.1  christos             sprintf (MsgBuffer, "%s is a %s",
    850  1.1.1.5  christos                 Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
    851      1.1  christos 
    852      1.1  christos             AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
    853      1.1  christos             return_ACPI_STATUS (AE_OK);
    854      1.1  christos         }
    855      1.1  christos 
    856      1.1  christos         /* Save the method node in the caller's op */
    857      1.1  christos 
    858      1.1  christos         Op->Asl.Node = Node;
    859      1.1  christos         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
    860      1.1  christos         {
    861      1.1  christos             return_ACPI_STATUS (AE_OK);
    862      1.1  christos         }
    863      1.1  christos 
    864      1.1  christos         /*
    865      1.1  christos          * This is a method invocation, with or without arguments.
    866      1.1  christos          * Count the number of arguments, each appears as a child
    867      1.1  christos          * under the parent node
    868      1.1  christos          */
    869      1.1  christos         Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
    870      1.1  christos         UtSetParseOpName (Op);
    871      1.1  christos 
    872      1.1  christos         PassedArgs = 0;
    873  1.1.1.5  christos         NextOp = Op->Asl.Child;
    874      1.1  christos 
    875      1.1  christos         while (NextOp)
    876      1.1  christos         {
    877      1.1  christos             PassedArgs++;
    878      1.1  christos             NextOp = NextOp->Asl.Next;
    879      1.1  christos         }
    880      1.1  christos 
    881  1.1.1.6  christos         if (Node->Value != ASL_EXTERNAL_METHOD &&
    882  1.1.1.6  christos             Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_EXTERNAL)
    883      1.1  christos         {
    884      1.1  christos             /*
    885      1.1  christos              * Check the parsed arguments with the number expected by the
    886      1.1  christos              * method declaration itself
    887      1.1  christos              */
    888      1.1  christos             if (PassedArgs != Node->Value)
    889      1.1  christos             {
    890      1.1  christos                 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
    891      1.1  christos                             Node->Value);
    892      1.1  christos 
    893      1.1  christos                 if (PassedArgs < Node->Value)
    894      1.1  christos                 {
    895      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
    896      1.1  christos                 }
    897      1.1  christos                 else
    898      1.1  christos                 {
    899      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
    900      1.1  christos                 }
    901      1.1  christos             }
    902      1.1  christos         }
    903      1.1  christos     }
    904      1.1  christos 
    905      1.1  christos     /* 4) Check for an ASL Field definition */
    906      1.1  christos 
    907      1.1  christos     else if ((Op->Asl.Parent) &&
    908      1.1  christos             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
    909      1.1  christos              (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
    910      1.1  christos     {
    911      1.1  christos         /*
    912      1.1  christos          * Offset checking for fields. If the parent operation region has a
    913      1.1  christos          * constant length (known at compile time), we can check fields
    914      1.1  christos          * defined in that region against the region length. This will catch
    915      1.1  christos          * fields and field units that cannot possibly fit within the region.
    916      1.1  christos          *
    917      1.1  christos          * Note: Index fields do not directly reference an operation region,
    918      1.1  christos          * thus they are not included in this check.
    919      1.1  christos          */
    920      1.1  christos         if (Op == Op->Asl.Parent->Asl.Child)
    921      1.1  christos         {
    922      1.1  christos             /*
    923      1.1  christos              * This is the first child of the field node, which is
    924      1.1  christos              * the name of the region. Get the parse node for the
    925      1.1  christos              * region -- which contains the length of the region.
    926      1.1  christos              */
    927      1.1  christos             OwningOp = Node->Op;
    928      1.1  christos             Op->Asl.Parent->Asl.ExtraValue =
    929      1.1  christos                 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
    930      1.1  christos 
    931      1.1  christos             /* Examine the field access width */
    932      1.1  christos 
    933      1.1  christos             switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
    934      1.1  christos             {
    935      1.1  christos             case AML_FIELD_ACCESS_ANY:
    936      1.1  christos             case AML_FIELD_ACCESS_BYTE:
    937      1.1  christos             case AML_FIELD_ACCESS_BUFFER:
    938      1.1  christos             default:
    939      1.1  christos 
    940      1.1  christos                 MinimumLength = 1;
    941      1.1  christos                 break;
    942      1.1  christos 
    943      1.1  christos             case AML_FIELD_ACCESS_WORD:
    944      1.1  christos 
    945      1.1  christos                 MinimumLength = 2;
    946      1.1  christos                 break;
    947      1.1  christos 
    948      1.1  christos             case AML_FIELD_ACCESS_DWORD:
    949      1.1  christos 
    950      1.1  christos                 MinimumLength = 4;
    951      1.1  christos                 break;
    952      1.1  christos 
    953      1.1  christos             case AML_FIELD_ACCESS_QWORD:
    954      1.1  christos 
    955      1.1  christos                 MinimumLength = 8;
    956      1.1  christos                 break;
    957      1.1  christos             }
    958      1.1  christos 
    959      1.1  christos             /*
    960      1.1  christos              * Is the region at least as big as the access width?
    961      1.1  christos              * Note: DataTableRegions have 0 length
    962      1.1  christos              */
    963      1.1  christos             if (((UINT32) OwningOp->Asl.Value.Integer) &&
    964      1.1  christos                 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
    965      1.1  christos             {
    966      1.1  christos                 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
    967      1.1  christos             }
    968      1.1  christos 
    969      1.1  christos             /*
    970      1.1  christos              * Check EC/CMOS/SMBUS fields to make sure that the correct
    971      1.1  christos              * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
    972      1.1  christos              */
    973      1.1  christos             SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
    974      1.1  christos             switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
    975      1.1  christos             {
    976      1.1  christos             case ACPI_ADR_SPACE_EC:
    977      1.1  christos             case ACPI_ADR_SPACE_CMOS:
    978      1.1  christos             case ACPI_ADR_SPACE_GPIO:
    979      1.1  christos 
    980  1.1.1.5  christos                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
    981  1.1.1.5  christos                     AML_FIELD_ACCESS_BYTE)
    982      1.1  christos                 {
    983      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
    984      1.1  christos                 }
    985      1.1  christos                 break;
    986      1.1  christos 
    987      1.1  christos             case ACPI_ADR_SPACE_SMBUS:
    988      1.1  christos             case ACPI_ADR_SPACE_IPMI:
    989      1.1  christos             case ACPI_ADR_SPACE_GSBUS:
    990      1.1  christos 
    991  1.1.1.5  christos                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer !=
    992  1.1.1.5  christos                     AML_FIELD_ACCESS_BUFFER)
    993      1.1  christos                 {
    994      1.1  christos                     AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
    995      1.1  christos                 }
    996      1.1  christos                 break;
    997      1.1  christos 
    998      1.1  christos             default:
    999      1.1  christos 
   1000      1.1  christos                 /* Nothing to do for other address spaces */
   1001      1.1  christos 
   1002      1.1  christos                 break;
   1003      1.1  christos             }
   1004      1.1  christos         }
   1005      1.1  christos         else
   1006      1.1  christos         {
   1007      1.1  christos             /*
   1008      1.1  christos              * This is one element of the field list. Check to make sure
   1009      1.1  christos              * that it does not go beyond the end of the parent operation region.
   1010      1.1  christos              *
   1011      1.1  christos              * In the code below:
   1012      1.1  christos              *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
   1013      1.1  christos              *    Op->Asl.ExtraValue                  - Field start offset (bits)
   1014      1.1  christos              *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
   1015      1.1  christos              *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
   1016      1.1  christos              */
   1017      1.1  christos             if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
   1018      1.1  christos             {
   1019      1.1  christos                 XfCheckFieldRange (Op,
   1020  1.1.1.5  christos                     Op->Asl.Parent->Asl.ExtraValue,
   1021  1.1.1.5  christos                     Op->Asl.ExtraValue,
   1022  1.1.1.5  christos                     (UINT32) Op->Asl.Child->Asl.Value.Integer,
   1023  1.1.1.5  christos                     Op->Asl.Child->Asl.ExtraValue);
   1024      1.1  christos             }
   1025      1.1  christos         }
   1026      1.1  christos     }
   1027      1.1  christos 
   1028  1.1.1.2  christos     /* 5) Check for a connection object */
   1029  1.1.1.2  christos #if 0
   1030  1.1.1.2  christos     else if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONNECTION)
   1031  1.1.1.2  christos     {
   1032  1.1.1.2  christos         return_ACPI_STATUS (Status);
   1033  1.1.1.2  christos     }
   1034  1.1.1.2  christos #endif
   1035  1.1.1.2  christos 
   1036      1.1  christos     Op->Asl.Node = Node;
   1037      1.1  christos     return_ACPI_STATUS (Status);
   1038      1.1  christos }
   1039      1.1  christos 
   1040      1.1  christos 
   1041      1.1  christos /*******************************************************************************
   1042      1.1  christos  *
   1043      1.1  christos  * FUNCTION:    XfNamespaceLocateEnd
   1044      1.1  christos  *
   1045      1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
   1046      1.1  christos  *
   1047      1.1  christos  * RETURN:      Status
   1048      1.1  christos  *
   1049      1.1  christos  * DESCRIPTION: Ascending callback used during cross reference. We only
   1050      1.1  christos  *              need to worry about scope management here.
   1051      1.1  christos  *
   1052      1.1  christos  ******************************************************************************/
   1053      1.1  christos 
   1054      1.1  christos static ACPI_STATUS
   1055      1.1  christos XfNamespaceLocateEnd (
   1056      1.1  christos     ACPI_PARSE_OBJECT       *Op,
   1057      1.1  christos     UINT32                  Level,
   1058      1.1  christos     void                    *Context)
   1059      1.1  christos {
   1060      1.1  christos     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
   1061      1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
   1062      1.1  christos 
   1063      1.1  christos 
   1064      1.1  christos     ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
   1065      1.1  christos 
   1066      1.1  christos 
   1067      1.1  christos     /* We are only interested in opcodes that have an associated name */
   1068      1.1  christos 
   1069      1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
   1070      1.1  christos     if (!(OpInfo->Flags & AML_NAMED))
   1071      1.1  christos     {
   1072      1.1  christos         return_ACPI_STATUS (AE_OK);
   1073      1.1  christos     }
   1074      1.1  christos 
   1075      1.1  christos     /* Not interested in name references, we did not open a scope for them */
   1076      1.1  christos 
   1077      1.1  christos     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
   1078      1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
   1079      1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
   1080      1.1  christos     {
   1081      1.1  christos         return_ACPI_STATUS (AE_OK);
   1082      1.1  christos     }
   1083      1.1  christos 
   1084      1.1  christos     /* Pop the scope stack if necessary */
   1085      1.1  christos 
   1086      1.1  christos     if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
   1087      1.1  christos     {
   1088      1.1  christos 
   1089      1.1  christos         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
   1090      1.1  christos             "%s: Popping scope for Op %p\n",
   1091      1.1  christos             AcpiUtGetTypeName (OpInfo->ObjectType), Op));
   1092      1.1  christos 
   1093      1.1  christos         (void) AcpiDsScopeStackPop (WalkState);
   1094      1.1  christos     }
   1095      1.1  christos 
   1096      1.1  christos     return_ACPI_STATUS (AE_OK);
   1097      1.1  christos }
   1098  1.1.1.4  christos 
   1099  1.1.1.4  christos 
   1100  1.1.1.4  christos #ifdef __UNDER_DEVELOPMENT
   1101  1.1.1.4  christos /*******************************************************************************
   1102  1.1.1.4  christos  *
   1103  1.1.1.4  christos  * FUNCTION:    XfIsObjectParental
   1104  1.1.1.4  christos  *
   1105  1.1.1.4  christos  * PARAMETERS:  ChildOp                 - Op to be checked
   1106  1.1.1.4  christos  *              PossibleParentOp        - Determine if this op is in the family
   1107  1.1.1.4  christos  *
   1108  1.1.1.4  christos  * RETURN:      TRUE if ChildOp is a descendent of PossibleParentOp
   1109  1.1.1.4  christos  *
   1110  1.1.1.4  christos  * DESCRIPTION: Determine if an Op is a descendent of another Op. Used to
   1111  1.1.1.4  christos  *              detect if a method is declared within another method.
   1112  1.1.1.4  christos  *
   1113  1.1.1.4  christos  ******************************************************************************/
   1114  1.1.1.4  christos 
   1115  1.1.1.4  christos static BOOLEAN
   1116  1.1.1.4  christos XfIsObjectParental (
   1117  1.1.1.4  christos     ACPI_PARSE_OBJECT       *ChildOp,
   1118  1.1.1.4  christos     ACPI_PARSE_OBJECT       *PossibleParentOp)
   1119  1.1.1.4  christos {
   1120  1.1.1.4  christos     ACPI_PARSE_OBJECT       *ParentOp;
   1121  1.1.1.4  christos 
   1122  1.1.1.4  christos 
   1123  1.1.1.4  christos     /* Search upwards through the tree for possible parent */
   1124  1.1.1.4  christos 
   1125  1.1.1.4  christos     ParentOp = ChildOp;
   1126  1.1.1.4  christos     while (ParentOp)
   1127  1.1.1.4  christos     {
   1128  1.1.1.4  christos         if (ParentOp == PossibleParentOp)
   1129  1.1.1.4  christos         {
   1130  1.1.1.4  christos             return (TRUE);
   1131  1.1.1.4  christos         }
   1132  1.1.1.4  christos 
   1133  1.1.1.4  christos         ParentOp = ParentOp->Asl.Parent;
   1134  1.1.1.4  christos     }
   1135  1.1.1.4  christos 
   1136  1.1.1.4  christos     return (FALSE);
   1137  1.1.1.4  christos }
   1138  1.1.1.4  christos 
   1139  1.1.1.4  christos 
   1140  1.1.1.4  christos /*******************************************************************************
   1141  1.1.1.4  christos  *
   1142  1.1.1.4  christos  * FUNCTION:    XfGetParentMethod
   1143  1.1.1.4  christos  *
   1144  1.1.1.4  christos  * PARAMETERS:  Op                      - Op to be checked
   1145  1.1.1.4  christos  *
   1146  1.1.1.4  christos  * RETURN:      Op for parent method. NULL if object is not within a method.
   1147  1.1.1.4  christos  *
   1148  1.1.1.4  christos  * DESCRIPTION: Determine if an object is within a control method. Used to
   1149  1.1.1.4  christos  *              implement special rules for named references from within a
   1150  1.1.1.4  christos  *              control method.
   1151  1.1.1.4  christos  *
   1152  1.1.1.4  christos  * NOTE: It would be better to have the parser set a flag in the Op if possible.
   1153  1.1.1.4  christos  *
   1154  1.1.1.4  christos  ******************************************************************************/
   1155  1.1.1.4  christos 
   1156  1.1.1.4  christos static ACPI_PARSE_OBJECT *
   1157  1.1.1.4  christos XfGetParentMethod (
   1158  1.1.1.4  christos     ACPI_PARSE_OBJECT       *Op)
   1159  1.1.1.4  christos {
   1160  1.1.1.4  christos     ACPI_PARSE_OBJECT       *ParentOp;
   1161  1.1.1.4  christos 
   1162  1.1.1.4  christos 
   1163  1.1.1.4  christos     if (!Op)
   1164  1.1.1.4  christos     {
   1165  1.1.1.4  christos         return (NULL);
   1166  1.1.1.4  christos     }
   1167  1.1.1.4  christos 
   1168  1.1.1.4  christos     if (Op->Asl.ParseOpcode == PARSEOP_METHOD)
   1169  1.1.1.4  christos     {
   1170  1.1.1.4  christos         return (NULL);
   1171  1.1.1.4  christos     }
   1172  1.1.1.4  christos 
   1173  1.1.1.4  christos     /* Walk upwards through the parse tree, up to the root if necessary */
   1174  1.1.1.4  christos 
   1175  1.1.1.4  christos     ParentOp = Op;
   1176  1.1.1.4  christos     while (ParentOp)
   1177  1.1.1.4  christos     {
   1178  1.1.1.4  christos         if (ParentOp->Asl.ParseOpcode == PARSEOP_METHOD)
   1179  1.1.1.4  christos         {
   1180  1.1.1.4  christos             return (ParentOp);
   1181  1.1.1.4  christos         }
   1182  1.1.1.4  christos 
   1183  1.1.1.4  christos         ParentOp = ParentOp->Asl.Parent;
   1184  1.1.1.4  christos     }
   1185  1.1.1.4  christos 
   1186  1.1.1.4  christos     /* Object is not within a method */
   1187  1.1.1.4  christos 
   1188  1.1.1.4  christos     return (NULL);
   1189  1.1.1.4  christos }
   1190  1.1.1.4  christos 
   1191  1.1.1.4  christos 
   1192  1.1.1.4  christos /*******************************************************************************
   1193  1.1.1.4  christos  *
   1194  1.1.1.4  christos  * FUNCTION:    XfCheckIllegalReference
   1195  1.1.1.4  christos  *
   1196  1.1.1.4  christos  * PARAMETERS:  Op                      - Op referring to the target
   1197  1.1.1.4  christos  *              TargetNode              - Target of the reference
   1198  1.1.1.4  christos  *
   1199  1.1.1.4  christos  * RETURN:      None. Emits error message for an illegal reference
   1200  1.1.1.4  christos  *
   1201  1.1.1.4  christos  * DESCRIPTION: Determine if a named reference is legal. A "named" reference
   1202  1.1.1.4  christos  *              is something like: Store(ABCD, ...), where ABCD is an AML
   1203  1.1.1.4  christos  *              Nameseg or Namepath.
   1204  1.1.1.4  christos  *
   1205  1.1.1.4  christos  * NOTE: Caller must ensure that the name Op is in fact a reference, and not
   1206  1.1.1.4  christos  *       an actual name declaration (creation of a named object).
   1207  1.1.1.4  christos  *
   1208  1.1.1.4  christos  ******************************************************************************/
   1209  1.1.1.4  christos 
   1210  1.1.1.4  christos static void
   1211  1.1.1.4  christos XfCheckIllegalReference (
   1212  1.1.1.4  christos     ACPI_PARSE_OBJECT       *Op,
   1213  1.1.1.4  christos     ACPI_NAMESPACE_NODE     *TargetNode)
   1214  1.1.1.4  christos {
   1215  1.1.1.4  christos     ACPI_PARSE_OBJECT       *MethodOp1;
   1216  1.1.1.4  christos     ACPI_PARSE_OBJECT       *MethodOp2;
   1217  1.1.1.4  christos     ACPI_PARSE_OBJECT       *TargetOp;
   1218  1.1.1.4  christos 
   1219  1.1.1.4  christos 
   1220  1.1.1.4  christos     /*
   1221  1.1.1.4  christos      * Check for an illegal reference to a named object:
   1222  1.1.1.4  christos      *
   1223  1.1.1.4  christos      * 1) References from one control method to another, non-parent
   1224  1.1.1.4  christos      *    method are not allowed, they will fail at runtime.
   1225  1.1.1.4  christos      *
   1226  1.1.1.4  christos      * 2) Forward references within a control method are not allowed.
   1227  1.1.1.4  christos      *    AML interpreters use a one-pass parse of control methods
   1228  1.1.1.4  christos      *    so these forward references will fail at runtime.
   1229  1.1.1.4  christos      */
   1230  1.1.1.4  christos     TargetOp = TargetNode->Op;
   1231  1.1.1.4  christos 
   1232  1.1.1.4  christos     MethodOp1 = XfGetParentMethod (Op);
   1233  1.1.1.4  christos     MethodOp2 = XfGetParentMethod (TargetOp);
   1234  1.1.1.4  christos 
   1235  1.1.1.4  christos     /* Are both objects within control method(s)? */
   1236  1.1.1.4  christos 
   1237  1.1.1.4  christos     if (!MethodOp1 || !MethodOp2)
   1238  1.1.1.4  christos     {
   1239  1.1.1.4  christos         return;
   1240  1.1.1.4  christos     }
   1241  1.1.1.4  christos 
   1242  1.1.1.4  christos     /* Objects not in the same method? */
   1243  1.1.1.4  christos 
   1244  1.1.1.4  christos     if (MethodOp1 != MethodOp2)
   1245  1.1.1.4  christos     {
   1246  1.1.1.4  christos         /*
   1247  1.1.1.4  christos          * 1) Cross-method named reference
   1248  1.1.1.4  christos          *
   1249  1.1.1.4  christos          * This is OK if and only if the target reference is within in a
   1250  1.1.1.4  christos          * method that is a parent of current method
   1251  1.1.1.4  christos          */
   1252  1.1.1.4  christos         if (!XfIsObjectParental (MethodOp1, MethodOp2))
   1253  1.1.1.4  christos         {
   1254  1.1.1.4  christos             AslError (ASL_ERROR, ASL_MSG_ILLEGAL_METHOD_REF, Op,
   1255  1.1.1.4  christos                 Op->Asl.ExternalName);
   1256  1.1.1.4  christos         }
   1257  1.1.1.4  christos     }
   1258  1.1.1.4  christos 
   1259  1.1.1.4  christos     /*
   1260  1.1.1.4  christos      * 2) Both reference and target are in the same method. Check if this is
   1261  1.1.1.4  christos      * an (illegal) forward reference by examining the exact source code
   1262  1.1.1.4  christos      * location of each (the referenced object and the object declaration).
   1263  1.1.1.4  christos      * This is a bit nasty, yet effective.
   1264  1.1.1.4  christos      */
   1265  1.1.1.4  christos     else if (Op->Asl.LogicalByteOffset < TargetOp->Asl.LogicalByteOffset)
   1266  1.1.1.4  christos     {
   1267  1.1.1.4  christos         AslError (ASL_ERROR, ASL_MSG_ILLEGAL_FORWARD_REF, Op,
   1268  1.1.1.4  christos             Op->Asl.ExternalName);
   1269  1.1.1.4  christos     }
   1270  1.1.1.4  christos 
   1271  1.1.1.4  christos }
   1272  1.1.1.4  christos #endif
   1273