Home | History | Annotate | Line # | Download | only in compiler
aslxref.c revision 1.1
      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  christos  * Copyright (C) 2000 - 2013, 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 
     45  1.1  christos #include "aslcompiler.h"
     46  1.1  christos #include "aslcompiler.y.h"
     47  1.1  christos #include "acparser.h"
     48  1.1  christos #include "amlcode.h"
     49  1.1  christos #include "acnamesp.h"
     50  1.1  christos #include "acdispat.h"
     51  1.1  christos 
     52  1.1  christos 
     53  1.1  christos #define _COMPONENT          ACPI_COMPILER
     54  1.1  christos         ACPI_MODULE_NAME    ("aslxref")
     55  1.1  christos 
     56  1.1  christos /* Local prototypes */
     57  1.1  christos 
     58  1.1  christos static ACPI_STATUS
     59  1.1  christos XfNamespaceLocateBegin (
     60  1.1  christos     ACPI_PARSE_OBJECT       *Op,
     61  1.1  christos     UINT32                  Level,
     62  1.1  christos     void                    *Context);
     63  1.1  christos 
     64  1.1  christos static ACPI_STATUS
     65  1.1  christos XfNamespaceLocateEnd (
     66  1.1  christos     ACPI_PARSE_OBJECT       *Op,
     67  1.1  christos     UINT32                  Level,
     68  1.1  christos     void                    *Context);
     69  1.1  christos 
     70  1.1  christos static BOOLEAN
     71  1.1  christos XfObjectExists (
     72  1.1  christos     char                    *Name);
     73  1.1  christos 
     74  1.1  christos static ACPI_STATUS
     75  1.1  christos XfCompareOneNamespaceObject (
     76  1.1  christos     ACPI_HANDLE             ObjHandle,
     77  1.1  christos     UINT32                  Level,
     78  1.1  christos     void                    *Context,
     79  1.1  christos     void                    **ReturnValue);
     80  1.1  christos 
     81  1.1  christos static void
     82  1.1  christos XfCheckFieldRange (
     83  1.1  christos     ACPI_PARSE_OBJECT       *Op,
     84  1.1  christos     UINT32                  RegionBitLength,
     85  1.1  christos     UINT32                  FieldBitOffset,
     86  1.1  christos     UINT32                  FieldBitLength,
     87  1.1  christos     UINT32                  AccessBitWidth);
     88  1.1  christos 
     89  1.1  christos 
     90  1.1  christos /*******************************************************************************
     91  1.1  christos  *
     92  1.1  christos  * FUNCTION:    XfCrossReferenceNamespace
     93  1.1  christos  *
     94  1.1  christos  * PARAMETERS:  None
     95  1.1  christos  *
     96  1.1  christos  * RETURN:      Status
     97  1.1  christos  *
     98  1.1  christos  * DESCRIPTION: Perform a cross reference check of the parse tree against the
     99  1.1  christos  *              namespace. Every named referenced within the parse tree
    100  1.1  christos  *              should be get resolved with a namespace lookup. If not, the
    101  1.1  christos  *              original reference in the ASL code is invalid -- i.e., refers
    102  1.1  christos  *              to a non-existent object.
    103  1.1  christos  *
    104  1.1  christos  * NOTE:  The ASL "External" operator causes the name to be inserted into the
    105  1.1  christos  *        namespace so that references to the external name will be resolved
    106  1.1  christos  *        correctly here.
    107  1.1  christos  *
    108  1.1  christos  ******************************************************************************/
    109  1.1  christos 
    110  1.1  christos ACPI_STATUS
    111  1.1  christos XfCrossReferenceNamespace (
    112  1.1  christos     void)
    113  1.1  christos {
    114  1.1  christos     ACPI_WALK_STATE         *WalkState;
    115  1.1  christos 
    116  1.1  christos 
    117  1.1  christos     DbgPrint (ASL_DEBUG_OUTPUT, "\nCross referencing namespace\n\n");
    118  1.1  christos 
    119  1.1  christos     /*
    120  1.1  christos      * Create a new walk state for use when looking up names
    121  1.1  christos      * within the namespace (Passed as context to the callbacks)
    122  1.1  christos      */
    123  1.1  christos     WalkState = AcpiDsCreateWalkState (0, NULL, NULL, NULL);
    124  1.1  christos     if (!WalkState)
    125  1.1  christos     {
    126  1.1  christos         return (AE_NO_MEMORY);
    127  1.1  christos     }
    128  1.1  christos 
    129  1.1  christos     /* Walk the entire parse tree */
    130  1.1  christos 
    131  1.1  christos     TrWalkParseTree (RootNode, ASL_WALK_VISIT_TWICE, XfNamespaceLocateBegin,
    132  1.1  christos                         XfNamespaceLocateEnd, WalkState);
    133  1.1  christos     return (AE_OK);
    134  1.1  christos }
    135  1.1  christos 
    136  1.1  christos 
    137  1.1  christos /*******************************************************************************
    138  1.1  christos  *
    139  1.1  christos  * FUNCTION:    XfObjectExists
    140  1.1  christos  *
    141  1.1  christos  * PARAMETERS:  Name            - 4 char ACPI name
    142  1.1  christos  *
    143  1.1  christos  * RETURN:      TRUE if name exists in namespace
    144  1.1  christos  *
    145  1.1  christos  * DESCRIPTION: Walk the namespace to find an object
    146  1.1  christos  *
    147  1.1  christos  ******************************************************************************/
    148  1.1  christos 
    149  1.1  christos static BOOLEAN
    150  1.1  christos XfObjectExists (
    151  1.1  christos     char                    *Name)
    152  1.1  christos {
    153  1.1  christos     ACPI_STATUS             Status;
    154  1.1  christos 
    155  1.1  christos 
    156  1.1  christos     /* Walk entire namespace from the supplied root */
    157  1.1  christos 
    158  1.1  christos     Status = AcpiNsWalkNamespace (ACPI_TYPE_ANY, ACPI_ROOT_OBJECT,
    159  1.1  christos                 ACPI_UINT32_MAX, FALSE, XfCompareOneNamespaceObject, NULL,
    160  1.1  christos                 Name, NULL);
    161  1.1  christos     if (Status == AE_CTRL_TRUE)
    162  1.1  christos     {
    163  1.1  christos         /* At least one instance of the name was found */
    164  1.1  christos 
    165  1.1  christos         return (TRUE);
    166  1.1  christos     }
    167  1.1  christos 
    168  1.1  christos     return (FALSE);
    169  1.1  christos }
    170  1.1  christos 
    171  1.1  christos 
    172  1.1  christos /*******************************************************************************
    173  1.1  christos  *
    174  1.1  christos  * FUNCTION:    XfCompareOneNamespaceObject
    175  1.1  christos  *
    176  1.1  christos  * PARAMETERS:  ACPI_WALK_CALLBACK
    177  1.1  christos  *
    178  1.1  christos  * RETURN:      Status
    179  1.1  christos  *
    180  1.1  christos  * DESCRIPTION: Compare name of one object.
    181  1.1  christos  *
    182  1.1  christos  ******************************************************************************/
    183  1.1  christos 
    184  1.1  christos static ACPI_STATUS
    185  1.1  christos XfCompareOneNamespaceObject (
    186  1.1  christos     ACPI_HANDLE             ObjHandle,
    187  1.1  christos     UINT32                  Level,
    188  1.1  christos     void                    *Context,
    189  1.1  christos     void                    **ReturnValue)
    190  1.1  christos {
    191  1.1  christos     ACPI_NAMESPACE_NODE     *Node = (ACPI_NAMESPACE_NODE *) ObjHandle;
    192  1.1  christos 
    193  1.1  christos 
    194  1.1  christos     /* Simply check the name */
    195  1.1  christos 
    196  1.1  christos     if (*((UINT32 *) (Context)) == Node->Name.Integer)
    197  1.1  christos     {
    198  1.1  christos         /* Abort walk if we found one instance */
    199  1.1  christos 
    200  1.1  christos         return (AE_CTRL_TRUE);
    201  1.1  christos     }
    202  1.1  christos 
    203  1.1  christos     return (AE_OK);
    204  1.1  christos }
    205  1.1  christos 
    206  1.1  christos 
    207  1.1  christos /*******************************************************************************
    208  1.1  christos  *
    209  1.1  christos  * FUNCTION:    XfCheckFieldRange
    210  1.1  christos  *
    211  1.1  christos  * PARAMETERS:  RegionBitLength     - Length of entire parent region
    212  1.1  christos  *              FieldBitOffset      - Start of the field unit (within region)
    213  1.1  christos  *              FieldBitLength      - Entire length of field unit
    214  1.1  christos  *              AccessBitWidth      - Access width of the field unit
    215  1.1  christos  *
    216  1.1  christos  * RETURN:      None
    217  1.1  christos  *
    218  1.1  christos  * DESCRIPTION: Check one field unit to make sure it fits in the parent
    219  1.1  christos  *              op region.
    220  1.1  christos  *
    221  1.1  christos  * Note: AccessBitWidth must be either 8,16,32, or 64
    222  1.1  christos  *
    223  1.1  christos  ******************************************************************************/
    224  1.1  christos 
    225  1.1  christos static void
    226  1.1  christos XfCheckFieldRange (
    227  1.1  christos     ACPI_PARSE_OBJECT       *Op,
    228  1.1  christos     UINT32                  RegionBitLength,
    229  1.1  christos     UINT32                  FieldBitOffset,
    230  1.1  christos     UINT32                  FieldBitLength,
    231  1.1  christos     UINT32                  AccessBitWidth)
    232  1.1  christos {
    233  1.1  christos     UINT32                  FieldEndBitOffset;
    234  1.1  christos 
    235  1.1  christos 
    236  1.1  christos     /*
    237  1.1  christos      * Check each field unit against the region size. The entire
    238  1.1  christos      * field unit (start offset plus length) must fit within the
    239  1.1  christos      * region.
    240  1.1  christos      */
    241  1.1  christos     FieldEndBitOffset = FieldBitOffset + FieldBitLength;
    242  1.1  christos 
    243  1.1  christos     if (FieldEndBitOffset > RegionBitLength)
    244  1.1  christos     {
    245  1.1  christos         /* Field definition itself is beyond the end-of-region */
    246  1.1  christos 
    247  1.1  christos         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_OFFSET, Op, NULL);
    248  1.1  christos         return;
    249  1.1  christos     }
    250  1.1  christos 
    251  1.1  christos     /*
    252  1.1  christos      * Now check that the field plus AccessWidth doesn't go beyond
    253  1.1  christos      * the end-of-region. Assumes AccessBitWidth is a power of 2
    254  1.1  christos      */
    255  1.1  christos     FieldEndBitOffset = ACPI_ROUND_UP (FieldEndBitOffset, AccessBitWidth);
    256  1.1  christos 
    257  1.1  christos     if (FieldEndBitOffset > RegionBitLength)
    258  1.1  christos     {
    259  1.1  christos         /* Field definition combined with the access is beyond EOR */
    260  1.1  christos 
    261  1.1  christos         AslError (ASL_ERROR, ASL_MSG_FIELD_UNIT_ACCESS_WIDTH, Op, NULL);
    262  1.1  christos     }
    263  1.1  christos }
    264  1.1  christos 
    265  1.1  christos /*******************************************************************************
    266  1.1  christos  *
    267  1.1  christos  * FUNCTION:    XfNamespaceLocateBegin
    268  1.1  christos  *
    269  1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
    270  1.1  christos  *
    271  1.1  christos  * RETURN:      Status
    272  1.1  christos  *
    273  1.1  christos  * DESCRIPTION: Descending callback used during cross-reference. For named
    274  1.1  christos  *              object references, attempt to locate the name in the
    275  1.1  christos  *              namespace.
    276  1.1  christos  *
    277  1.1  christos  * NOTE: ASL references to named fields within resource descriptors are
    278  1.1  christos  *       resolved to integer values here. Therefore, this step is an
    279  1.1  christos  *       important part of the code generation. We don't know that the
    280  1.1  christos  *       name refers to a resource descriptor until now.
    281  1.1  christos  *
    282  1.1  christos  ******************************************************************************/
    283  1.1  christos 
    284  1.1  christos static ACPI_STATUS
    285  1.1  christos XfNamespaceLocateBegin (
    286  1.1  christos     ACPI_PARSE_OBJECT       *Op,
    287  1.1  christos     UINT32                  Level,
    288  1.1  christos     void                    *Context)
    289  1.1  christos {
    290  1.1  christos     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
    291  1.1  christos     ACPI_NAMESPACE_NODE     *Node;
    292  1.1  christos     ACPI_STATUS             Status;
    293  1.1  christos     ACPI_OBJECT_TYPE        ObjectType;
    294  1.1  christos     char                    *Path;
    295  1.1  christos     UINT8                   PassedArgs;
    296  1.1  christos     ACPI_PARSE_OBJECT       *NextOp;
    297  1.1  christos     ACPI_PARSE_OBJECT       *OwningOp;
    298  1.1  christos     ACPI_PARSE_OBJECT       *SpaceIdOp;
    299  1.1  christos     UINT32                  MinimumLength;
    300  1.1  christos     UINT32                  Offset;
    301  1.1  christos     UINT32                  FieldBitLength;
    302  1.1  christos     UINT32                  TagBitLength;
    303  1.1  christos     UINT8                   Message = 0;
    304  1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    305  1.1  christos     UINT32                  Flags;
    306  1.1  christos 
    307  1.1  christos 
    308  1.1  christos     ACPI_FUNCTION_TRACE_PTR (XfNamespaceLocateBegin, Op);
    309  1.1  christos 
    310  1.1  christos     /*
    311  1.1  christos      * If this node is the actual declaration of a name
    312  1.1  christos      * [such as the XXXX name in "Method (XXXX)"],
    313  1.1  christos      * we are not interested in it here. We only care about names that are
    314  1.1  christos      * references to other objects within the namespace and the parent objects
    315  1.1  christos      * of name declarations
    316  1.1  christos      */
    317  1.1  christos     if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
    318  1.1  christos     {
    319  1.1  christos         return_ACPI_STATUS (AE_OK);
    320  1.1  christos     }
    321  1.1  christos 
    322  1.1  christos     /* We are only interested in opcodes that have an associated name */
    323  1.1  christos 
    324  1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    325  1.1  christos 
    326  1.1  christos     if ((!(OpInfo->Flags & AML_NAMED)) &&
    327  1.1  christos         (!(OpInfo->Flags & AML_CREATE)) &&
    328  1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_NAMESTRING) &&
    329  1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_NAMESEG)    &&
    330  1.1  christos         (Op->Asl.ParseOpcode != PARSEOP_METHODCALL))
    331  1.1  christos     {
    332  1.1  christos         return_ACPI_STATUS (AE_OK);
    333  1.1  christos     }
    334  1.1  christos 
    335  1.1  christos     /*
    336  1.1  christos      * One special case: CondRefOf operator - we don't care if the name exists
    337  1.1  christos      * or not at this point, just ignore it, the point of the operator is to
    338  1.1  christos      * determine if the name exists at runtime.
    339  1.1  christos      */
    340  1.1  christos     if ((Op->Asl.Parent) &&
    341  1.1  christos         (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF))
    342  1.1  christos     {
    343  1.1  christos         return_ACPI_STATUS (AE_OK);
    344  1.1  christos     }
    345  1.1  christos 
    346  1.1  christos     /*
    347  1.1  christos      * We must enable the "search-to-root" for single NameSegs, but
    348  1.1  christos      * we have to be very careful about opening up scopes
    349  1.1  christos      */
    350  1.1  christos     Flags = ACPI_NS_SEARCH_PARENT;
    351  1.1  christos     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
    352  1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
    353  1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
    354  1.1  christos     {
    355  1.1  christos         /*
    356  1.1  christos          * These are name references, do not push the scope stack
    357  1.1  christos          * for them.
    358  1.1  christos          */
    359  1.1  christos         Flags |= ACPI_NS_DONT_OPEN_SCOPE;
    360  1.1  christos     }
    361  1.1  christos 
    362  1.1  christos     /* Get the NamePath from the appropriate place */
    363  1.1  christos 
    364  1.1  christos     if (OpInfo->Flags & AML_NAMED)
    365  1.1  christos     {
    366  1.1  christos         /* For nearly all NAMED operators, the name reference is the first child */
    367  1.1  christos 
    368  1.1  christos         Path = Op->Asl.Child->Asl.Value.String;
    369  1.1  christos         if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
    370  1.1  christos         {
    371  1.1  christos             /*
    372  1.1  christos              * ALIAS is the only oddball opcode, the name declaration
    373  1.1  christos              * (alias name) is the second operand
    374  1.1  christos              */
    375  1.1  christos             Path = Op->Asl.Child->Asl.Next->Asl.Value.String;
    376  1.1  christos         }
    377  1.1  christos     }
    378  1.1  christos     else if (OpInfo->Flags & AML_CREATE)
    379  1.1  christos     {
    380  1.1  christos         /* Name must appear as the last parameter */
    381  1.1  christos 
    382  1.1  christos         NextOp = Op->Asl.Child;
    383  1.1  christos         while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
    384  1.1  christos         {
    385  1.1  christos             NextOp = NextOp->Asl.Next;
    386  1.1  christos         }
    387  1.1  christos         Path = NextOp->Asl.Value.String;
    388  1.1  christos     }
    389  1.1  christos     else
    390  1.1  christos     {
    391  1.1  christos         Path = Op->Asl.Value.String;
    392  1.1  christos     }
    393  1.1  christos 
    394  1.1  christos     ObjectType = AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode);
    395  1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    396  1.1  christos         "Type=%s\n", AcpiUtGetTypeName (ObjectType)));
    397  1.1  christos 
    398  1.1  christos     /*
    399  1.1  christos      * Lookup the name in the namespace. Name must exist at this point, or it
    400  1.1  christos      * is an invalid reference.
    401  1.1  christos      *
    402  1.1  christos      * The namespace is also used as a lookup table for references to resource
    403  1.1  christos      * descriptors and the fields within them.
    404  1.1  christos      */
    405  1.1  christos     Gbl_NsLookupCount++;
    406  1.1  christos 
    407  1.1  christos     Status = AcpiNsLookup (WalkState->ScopeInfo, Path, ObjectType,
    408  1.1  christos                 ACPI_IMODE_EXECUTE, Flags, WalkState, &(Node));
    409  1.1  christos     if (ACPI_FAILURE (Status))
    410  1.1  christos     {
    411  1.1  christos         if (Status == AE_NOT_FOUND)
    412  1.1  christos         {
    413  1.1  christos             /*
    414  1.1  christos              * We didn't find the name reference by path -- we can qualify this
    415  1.1  christos              * a little better before we print an error message
    416  1.1  christos              */
    417  1.1  christos             if (strlen (Path) == ACPI_NAME_SIZE)
    418  1.1  christos             {
    419  1.1  christos                 /* A simple, one-segment ACPI name */
    420  1.1  christos 
    421  1.1  christos                 if (XfObjectExists (Path))
    422  1.1  christos                 {
    423  1.1  christos                     /*
    424  1.1  christos                      * There exists such a name, but we couldn't get to it
    425  1.1  christos                      * from this scope
    426  1.1  christos                      */
    427  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_REACHABLE, Op,
    428  1.1  christos                         Op->Asl.ExternalName);
    429  1.1  christos                 }
    430  1.1  christos                 else
    431  1.1  christos                 {
    432  1.1  christos                     /* The name doesn't exist, period */
    433  1.1  christos 
    434  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST,
    435  1.1  christos                         Op, Op->Asl.ExternalName);
    436  1.1  christos                 }
    437  1.1  christos             }
    438  1.1  christos             else
    439  1.1  christos             {
    440  1.1  christos                 /* Check for a fully qualified path */
    441  1.1  christos 
    442  1.1  christos                 if (Path[0] == AML_ROOT_PREFIX)
    443  1.1  christos                 {
    444  1.1  christos                     /* Gave full path, the object does not exist */
    445  1.1  christos 
    446  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_EXIST, Op,
    447  1.1  christos                         Op->Asl.ExternalName);
    448  1.1  christos                 }
    449  1.1  christos                 else
    450  1.1  christos                 {
    451  1.1  christos                     /*
    452  1.1  christos                      * We can't tell whether it doesn't exist or just
    453  1.1  christos                      * can't be reached.
    454  1.1  christos                      */
    455  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_NOT_FOUND, Op,
    456  1.1  christos                         Op->Asl.ExternalName);
    457  1.1  christos                 }
    458  1.1  christos             }
    459  1.1  christos 
    460  1.1  christos             Status = AE_OK;
    461  1.1  christos         }
    462  1.1  christos 
    463  1.1  christos         return_ACPI_STATUS (Status);
    464  1.1  christos     }
    465  1.1  christos 
    466  1.1  christos     /* Check for a reference vs. name declaration */
    467  1.1  christos 
    468  1.1  christos     if (!(OpInfo->Flags & AML_NAMED) &&
    469  1.1  christos         !(OpInfo->Flags & AML_CREATE))
    470  1.1  christos     {
    471  1.1  christos         /* This node has been referenced, mark it for reference check */
    472  1.1  christos 
    473  1.1  christos         Node->Flags |= ANOBJ_IS_REFERENCED;
    474  1.1  christos     }
    475  1.1  christos 
    476  1.1  christos     /* Attempt to optimize the NamePath */
    477  1.1  christos 
    478  1.1  christos     OptOptimizeNamePath (Op, OpInfo->Flags, WalkState, Path, Node);
    479  1.1  christos 
    480  1.1  christos     /*
    481  1.1  christos      * 1) Dereference an alias (A name reference that is an alias)
    482  1.1  christos      *    Aliases are not nested, the alias always points to the final object
    483  1.1  christos      */
    484  1.1  christos     if ((Op->Asl.ParseOpcode != PARSEOP_ALIAS) &&
    485  1.1  christos         (Node->Type == ACPI_TYPE_LOCAL_ALIAS))
    486  1.1  christos     {
    487  1.1  christos         /* This node points back to the original PARSEOP_ALIAS */
    488  1.1  christos 
    489  1.1  christos         NextOp = Node->Op;
    490  1.1  christos 
    491  1.1  christos         /* The first child is the alias target op */
    492  1.1  christos 
    493  1.1  christos         NextOp = NextOp->Asl.Child;
    494  1.1  christos 
    495  1.1  christos         /* That in turn points back to original target alias node */
    496  1.1  christos 
    497  1.1  christos         if (NextOp->Asl.Node)
    498  1.1  christos         {
    499  1.1  christos             Node = NextOp->Asl.Node;
    500  1.1  christos         }
    501  1.1  christos 
    502  1.1  christos         /* Else - forward reference to alias, will be resolved later */
    503  1.1  christos     }
    504  1.1  christos 
    505  1.1  christos     /* 2) Check for a reference to a resource descriptor */
    506  1.1  christos 
    507  1.1  christos     if ((Node->Type == ACPI_TYPE_LOCAL_RESOURCE_FIELD) ||
    508  1.1  christos         (Node->Type == ACPI_TYPE_LOCAL_RESOURCE))
    509  1.1  christos     {
    510  1.1  christos         /*
    511  1.1  christos          * This was a reference to a field within a resource descriptor.
    512  1.1  christos          * Extract the associated field offset (either a bit or byte
    513  1.1  christos          * offset depending on the field type) and change the named
    514  1.1  christos          * reference into an integer for AML code generation
    515  1.1  christos          */
    516  1.1  christos         Offset = Node->Value;
    517  1.1  christos         TagBitLength = Node->Length;
    518  1.1  christos 
    519  1.1  christos         /*
    520  1.1  christos          * If a field is being created, generate the length (in bits) of
    521  1.1  christos          * the field. Note: Opcodes other than CreateXxxField and Index
    522  1.1  christos          * can come through here. For other opcodes, we just need to
    523  1.1  christos          * convert the resource tag reference to an integer offset.
    524  1.1  christos          */
    525  1.1  christos         switch (Op->Asl.Parent->Asl.AmlOpcode)
    526  1.1  christos         {
    527  1.1  christos         case AML_CREATE_FIELD_OP: /* Variable "Length" field, in bits */
    528  1.1  christos             /*
    529  1.1  christos              * We know the length operand is an integer constant because
    530  1.1  christos              * we know that it contains a reference to a resource
    531  1.1  christos              * descriptor tag.
    532  1.1  christos              */
    533  1.1  christos             FieldBitLength = (UINT32) Op->Asl.Next->Asl.Value.Integer;
    534  1.1  christos             break;
    535  1.1  christos 
    536  1.1  christos         case AML_CREATE_BIT_FIELD_OP:
    537  1.1  christos 
    538  1.1  christos             FieldBitLength = 1;
    539  1.1  christos             break;
    540  1.1  christos 
    541  1.1  christos         case AML_CREATE_BYTE_FIELD_OP:
    542  1.1  christos         case AML_INDEX_OP:
    543  1.1  christos 
    544  1.1  christos             FieldBitLength = 8;
    545  1.1  christos             break;
    546  1.1  christos 
    547  1.1  christos         case AML_CREATE_WORD_FIELD_OP:
    548  1.1  christos 
    549  1.1  christos             FieldBitLength = 16;
    550  1.1  christos             break;
    551  1.1  christos 
    552  1.1  christos         case AML_CREATE_DWORD_FIELD_OP:
    553  1.1  christos 
    554  1.1  christos             FieldBitLength = 32;
    555  1.1  christos             break;
    556  1.1  christos 
    557  1.1  christos         case AML_CREATE_QWORD_FIELD_OP:
    558  1.1  christos 
    559  1.1  christos             FieldBitLength = 64;
    560  1.1  christos             break;
    561  1.1  christos 
    562  1.1  christos         default:
    563  1.1  christos 
    564  1.1  christos             FieldBitLength = 0;
    565  1.1  christos             break;
    566  1.1  christos         }
    567  1.1  christos 
    568  1.1  christos         /* Check the field length against the length of the resource tag */
    569  1.1  christos 
    570  1.1  christos         if (FieldBitLength)
    571  1.1  christos         {
    572  1.1  christos             if (TagBitLength < FieldBitLength)
    573  1.1  christos             {
    574  1.1  christos                 Message = ASL_MSG_TAG_SMALLER;
    575  1.1  christos             }
    576  1.1  christos             else if (TagBitLength > FieldBitLength)
    577  1.1  christos             {
    578  1.1  christos                 Message = ASL_MSG_TAG_LARGER;
    579  1.1  christos             }
    580  1.1  christos 
    581  1.1  christos             if (Message)
    582  1.1  christos             {
    583  1.1  christos                 sprintf (MsgBuffer, "Size mismatch, Tag: %u bit%s, Field: %u bit%s",
    584  1.1  christos                     TagBitLength, (TagBitLength > 1) ? "s" : "",
    585  1.1  christos                     FieldBitLength, (FieldBitLength > 1) ? "s" : "");
    586  1.1  christos 
    587  1.1  christos                 AslError (ASL_WARNING, Message, Op, MsgBuffer);
    588  1.1  christos             }
    589  1.1  christos         }
    590  1.1  christos 
    591  1.1  christos         /* Convert the BitOffset to a ByteOffset for certain opcodes */
    592  1.1  christos 
    593  1.1  christos         switch (Op->Asl.Parent->Asl.AmlOpcode)
    594  1.1  christos         {
    595  1.1  christos         case AML_CREATE_BYTE_FIELD_OP:
    596  1.1  christos         case AML_CREATE_WORD_FIELD_OP:
    597  1.1  christos         case AML_CREATE_DWORD_FIELD_OP:
    598  1.1  christos         case AML_CREATE_QWORD_FIELD_OP:
    599  1.1  christos         case AML_INDEX_OP:
    600  1.1  christos 
    601  1.1  christos             Offset = ACPI_DIV_8 (Offset);
    602  1.1  christos             break;
    603  1.1  christos 
    604  1.1  christos         default:
    605  1.1  christos 
    606  1.1  christos             break;
    607  1.1  christos         }
    608  1.1  christos 
    609  1.1  christos         /* Now convert this node to an integer whose value is the field offset */
    610  1.1  christos 
    611  1.1  christos         Op->Asl.AmlLength = 0;
    612  1.1  christos         Op->Asl.ParseOpcode = PARSEOP_INTEGER;
    613  1.1  christos         Op->Asl.Value.Integer = (UINT64) Offset;
    614  1.1  christos         Op->Asl.CompileFlags |= NODE_IS_RESOURCE_FIELD;
    615  1.1  christos 
    616  1.1  christos         OpcGenerateAmlOpcode (Op);
    617  1.1  christos     }
    618  1.1  christos 
    619  1.1  christos     /* 3) Check for a method invocation */
    620  1.1  christos 
    621  1.1  christos     else if ((((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) || (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)) &&
    622  1.1  christos                 (Node->Type == ACPI_TYPE_METHOD) &&
    623  1.1  christos                 (Op->Asl.Parent) &&
    624  1.1  christos                 (Op->Asl.Parent->Asl.ParseOpcode != PARSEOP_METHOD))   ||
    625  1.1  christos 
    626  1.1  christos                 (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
    627  1.1  christos     {
    628  1.1  christos         /*
    629  1.1  christos          * A reference to a method within one of these opcodes is not an
    630  1.1  christos          * invocation of the method, it is simply a reference to the method.
    631  1.1  christos          */
    632  1.1  christos         if ((Op->Asl.Parent) &&
    633  1.1  christos            ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_REFOF)      ||
    634  1.1  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_DEREFOF)    ||
    635  1.1  christos             (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_OBJECTTYPE)))
    636  1.1  christos         {
    637  1.1  christos             return_ACPI_STATUS (AE_OK);
    638  1.1  christos         }
    639  1.1  christos         /*
    640  1.1  christos          * There are two types of method invocation:
    641  1.1  christos          * 1) Invocation with arguments -- the parser recognizes this
    642  1.1  christos          *    as a METHODCALL.
    643  1.1  christos          * 2) Invocation with no arguments --the parser cannot determine that
    644  1.1  christos          *    this is a method invocation, therefore we have to figure it out
    645  1.1  christos          *    here.
    646  1.1  christos          */
    647  1.1  christos         if (Node->Type != ACPI_TYPE_METHOD)
    648  1.1  christos         {
    649  1.1  christos             sprintf (MsgBuffer, "%s is a %s",
    650  1.1  christos                     Op->Asl.ExternalName, AcpiUtGetTypeName (Node->Type));
    651  1.1  christos 
    652  1.1  christos             AslError (ASL_ERROR, ASL_MSG_NOT_METHOD, Op, MsgBuffer);
    653  1.1  christos             return_ACPI_STATUS (AE_OK);
    654  1.1  christos         }
    655  1.1  christos 
    656  1.1  christos         /* Save the method node in the caller's op */
    657  1.1  christos 
    658  1.1  christos         Op->Asl.Node = Node;
    659  1.1  christos         if (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_CONDREFOF)
    660  1.1  christos         {
    661  1.1  christos             return_ACPI_STATUS (AE_OK);
    662  1.1  christos         }
    663  1.1  christos 
    664  1.1  christos         /*
    665  1.1  christos          * This is a method invocation, with or without arguments.
    666  1.1  christos          * Count the number of arguments, each appears as a child
    667  1.1  christos          * under the parent node
    668  1.1  christos          */
    669  1.1  christos         Op->Asl.ParseOpcode = PARSEOP_METHODCALL;
    670  1.1  christos         UtSetParseOpName (Op);
    671  1.1  christos 
    672  1.1  christos         PassedArgs = 0;
    673  1.1  christos         NextOp     = Op->Asl.Child;
    674  1.1  christos 
    675  1.1  christos         while (NextOp)
    676  1.1  christos         {
    677  1.1  christos             PassedArgs++;
    678  1.1  christos             NextOp = NextOp->Asl.Next;
    679  1.1  christos         }
    680  1.1  christos 
    681  1.1  christos         if (Node->Value != ASL_EXTERNAL_METHOD)
    682  1.1  christos         {
    683  1.1  christos             /*
    684  1.1  christos              * Check the parsed arguments with the number expected by the
    685  1.1  christos              * method declaration itself
    686  1.1  christos              */
    687  1.1  christos             if (PassedArgs != Node->Value)
    688  1.1  christos             {
    689  1.1  christos                 sprintf (MsgBuffer, "%s requires %u", Op->Asl.ExternalName,
    690  1.1  christos                             Node->Value);
    691  1.1  christos 
    692  1.1  christos                 if (PassedArgs < Node->Value)
    693  1.1  christos                 {
    694  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_LO, Op, MsgBuffer);
    695  1.1  christos                 }
    696  1.1  christos                 else
    697  1.1  christos                 {
    698  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_ARG_COUNT_HI, Op, MsgBuffer);
    699  1.1  christos                 }
    700  1.1  christos             }
    701  1.1  christos         }
    702  1.1  christos     }
    703  1.1  christos 
    704  1.1  christos     /* 4) Check for an ASL Field definition */
    705  1.1  christos 
    706  1.1  christos     else if ((Op->Asl.Parent) &&
    707  1.1  christos             ((Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_FIELD)     ||
    708  1.1  christos              (Op->Asl.Parent->Asl.ParseOpcode == PARSEOP_BANKFIELD)))
    709  1.1  christos     {
    710  1.1  christos         /*
    711  1.1  christos          * Offset checking for fields. If the parent operation region has a
    712  1.1  christos          * constant length (known at compile time), we can check fields
    713  1.1  christos          * defined in that region against the region length. This will catch
    714  1.1  christos          * fields and field units that cannot possibly fit within the region.
    715  1.1  christos          *
    716  1.1  christos          * Note: Index fields do not directly reference an operation region,
    717  1.1  christos          * thus they are not included in this check.
    718  1.1  christos          */
    719  1.1  christos         if (Op == Op->Asl.Parent->Asl.Child)
    720  1.1  christos         {
    721  1.1  christos             /*
    722  1.1  christos              * This is the first child of the field node, which is
    723  1.1  christos              * the name of the region. Get the parse node for the
    724  1.1  christos              * region -- which contains the length of the region.
    725  1.1  christos              */
    726  1.1  christos             OwningOp = Node->Op;
    727  1.1  christos             Op->Asl.Parent->Asl.ExtraValue =
    728  1.1  christos                 ACPI_MUL_8 ((UINT32) OwningOp->Asl.Value.Integer);
    729  1.1  christos 
    730  1.1  christos             /* Examine the field access width */
    731  1.1  christos 
    732  1.1  christos             switch ((UINT8) Op->Asl.Parent->Asl.Value.Integer)
    733  1.1  christos             {
    734  1.1  christos             case AML_FIELD_ACCESS_ANY:
    735  1.1  christos             case AML_FIELD_ACCESS_BYTE:
    736  1.1  christos             case AML_FIELD_ACCESS_BUFFER:
    737  1.1  christos             default:
    738  1.1  christos 
    739  1.1  christos                 MinimumLength = 1;
    740  1.1  christos                 break;
    741  1.1  christos 
    742  1.1  christos             case AML_FIELD_ACCESS_WORD:
    743  1.1  christos 
    744  1.1  christos                 MinimumLength = 2;
    745  1.1  christos                 break;
    746  1.1  christos 
    747  1.1  christos             case AML_FIELD_ACCESS_DWORD:
    748  1.1  christos 
    749  1.1  christos                 MinimumLength = 4;
    750  1.1  christos                 break;
    751  1.1  christos 
    752  1.1  christos             case AML_FIELD_ACCESS_QWORD:
    753  1.1  christos 
    754  1.1  christos                 MinimumLength = 8;
    755  1.1  christos                 break;
    756  1.1  christos             }
    757  1.1  christos 
    758  1.1  christos             /*
    759  1.1  christos              * Is the region at least as big as the access width?
    760  1.1  christos              * Note: DataTableRegions have 0 length
    761  1.1  christos              */
    762  1.1  christos             if (((UINT32) OwningOp->Asl.Value.Integer) &&
    763  1.1  christos                 ((UINT32) OwningOp->Asl.Value.Integer < MinimumLength))
    764  1.1  christos             {
    765  1.1  christos                 AslError (ASL_ERROR, ASL_MSG_FIELD_ACCESS_WIDTH, Op, NULL);
    766  1.1  christos             }
    767  1.1  christos 
    768  1.1  christos             /*
    769  1.1  christos              * Check EC/CMOS/SMBUS fields to make sure that the correct
    770  1.1  christos              * access type is used (BYTE for EC/CMOS, BUFFER for SMBUS)
    771  1.1  christos              */
    772  1.1  christos             SpaceIdOp = OwningOp->Asl.Child->Asl.Next;
    773  1.1  christos             switch ((UINT32) SpaceIdOp->Asl.Value.Integer)
    774  1.1  christos             {
    775  1.1  christos             case ACPI_ADR_SPACE_EC:
    776  1.1  christos             case ACPI_ADR_SPACE_CMOS:
    777  1.1  christos             case ACPI_ADR_SPACE_GPIO:
    778  1.1  christos 
    779  1.1  christos                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BYTE)
    780  1.1  christos                 {
    781  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_REGION_BYTE_ACCESS, Op, NULL);
    782  1.1  christos                 }
    783  1.1  christos                 break;
    784  1.1  christos 
    785  1.1  christos             case ACPI_ADR_SPACE_SMBUS:
    786  1.1  christos             case ACPI_ADR_SPACE_IPMI:
    787  1.1  christos             case ACPI_ADR_SPACE_GSBUS:
    788  1.1  christos 
    789  1.1  christos                 if ((UINT8) Op->Asl.Parent->Asl.Value.Integer != AML_FIELD_ACCESS_BUFFER)
    790  1.1  christos                 {
    791  1.1  christos                     AslError (ASL_ERROR, ASL_MSG_REGION_BUFFER_ACCESS, Op, NULL);
    792  1.1  christos                 }
    793  1.1  christos                 break;
    794  1.1  christos 
    795  1.1  christos             default:
    796  1.1  christos 
    797  1.1  christos                 /* Nothing to do for other address spaces */
    798  1.1  christos 
    799  1.1  christos                 break;
    800  1.1  christos             }
    801  1.1  christos         }
    802  1.1  christos         else
    803  1.1  christos         {
    804  1.1  christos             /*
    805  1.1  christos              * This is one element of the field list. Check to make sure
    806  1.1  christos              * that it does not go beyond the end of the parent operation region.
    807  1.1  christos              *
    808  1.1  christos              * In the code below:
    809  1.1  christos              *    Op->Asl.Parent->Asl.ExtraValue      - Region Length (bits)
    810  1.1  christos              *    Op->Asl.ExtraValue                  - Field start offset (bits)
    811  1.1  christos              *    Op->Asl.Child->Asl.Value.Integer32  - Field length (bits)
    812  1.1  christos              *    Op->Asl.Child->Asl.ExtraValue       - Field access width (bits)
    813  1.1  christos              */
    814  1.1  christos             if (Op->Asl.Parent->Asl.ExtraValue && Op->Asl.Child)
    815  1.1  christos             {
    816  1.1  christos                 XfCheckFieldRange (Op,
    817  1.1  christos                             Op->Asl.Parent->Asl.ExtraValue,
    818  1.1  christos                             Op->Asl.ExtraValue,
    819  1.1  christos                             (UINT32) Op->Asl.Child->Asl.Value.Integer,
    820  1.1  christos                             Op->Asl.Child->Asl.ExtraValue);
    821  1.1  christos             }
    822  1.1  christos         }
    823  1.1  christos     }
    824  1.1  christos 
    825  1.1  christos     Op->Asl.Node = Node;
    826  1.1  christos     return_ACPI_STATUS (Status);
    827  1.1  christos }
    828  1.1  christos 
    829  1.1  christos 
    830  1.1  christos /*******************************************************************************
    831  1.1  christos  *
    832  1.1  christos  * FUNCTION:    XfNamespaceLocateEnd
    833  1.1  christos  *
    834  1.1  christos  * PARAMETERS:  ASL_WALK_CALLBACK
    835  1.1  christos  *
    836  1.1  christos  * RETURN:      Status
    837  1.1  christos  *
    838  1.1  christos  * DESCRIPTION: Ascending callback used during cross reference. We only
    839  1.1  christos  *              need to worry about scope management here.
    840  1.1  christos  *
    841  1.1  christos  ******************************************************************************/
    842  1.1  christos 
    843  1.1  christos static ACPI_STATUS
    844  1.1  christos XfNamespaceLocateEnd (
    845  1.1  christos     ACPI_PARSE_OBJECT       *Op,
    846  1.1  christos     UINT32                  Level,
    847  1.1  christos     void                    *Context)
    848  1.1  christos {
    849  1.1  christos     ACPI_WALK_STATE         *WalkState = (ACPI_WALK_STATE *) Context;
    850  1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    851  1.1  christos 
    852  1.1  christos 
    853  1.1  christos     ACPI_FUNCTION_TRACE (XfNamespaceLocateEnd);
    854  1.1  christos 
    855  1.1  christos 
    856  1.1  christos     /* We are only interested in opcodes that have an associated name */
    857  1.1  christos 
    858  1.1  christos     OpInfo = AcpiPsGetOpcodeInfo (Op->Asl.AmlOpcode);
    859  1.1  christos     if (!(OpInfo->Flags & AML_NAMED))
    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     /* Not interested in name references, we did not open a scope for them */
    865  1.1  christos 
    866  1.1  christos     if ((Op->Asl.ParseOpcode == PARSEOP_NAMESTRING) ||
    867  1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_NAMESEG)    ||
    868  1.1  christos         (Op->Asl.ParseOpcode == PARSEOP_METHODCALL))
    869  1.1  christos     {
    870  1.1  christos         return_ACPI_STATUS (AE_OK);
    871  1.1  christos     }
    872  1.1  christos 
    873  1.1  christos     /* Pop the scope stack if necessary */
    874  1.1  christos 
    875  1.1  christos     if (AcpiNsOpensScope (AslMapNamedOpcodeToDataType (Op->Asl.AmlOpcode)))
    876  1.1  christos     {
    877  1.1  christos 
    878  1.1  christos         ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH,
    879  1.1  christos             "%s: Popping scope for Op %p\n",
    880  1.1  christos             AcpiUtGetTypeName (OpInfo->ObjectType), Op));
    881  1.1  christos 
    882  1.1  christos         (void) AcpiDsScopeStackPop (WalkState);
    883  1.1  christos     }
    884  1.1  christos 
    885  1.1  christos     return_ACPI_STATUS (AE_OK);
    886  1.1  christos }
    887