Home | History | Annotate | Line # | Download | only in compiler
aslopt.c revision 1.1.1.2.4.2
      1  1.1.1.2.4.2  rmind /******************************************************************************
      2  1.1.1.2.4.2  rmind  *
      3  1.1.1.2.4.2  rmind  * Module Name: aslopt- Compiler optimizations
      4  1.1.1.2.4.2  rmind  *
      5  1.1.1.2.4.2  rmind  *****************************************************************************/
      6  1.1.1.2.4.2  rmind 
      7  1.1.1.2.4.2  rmind /*
      8  1.1.1.2.4.2  rmind  * Copyright (C) 2000 - 2011, Intel Corp.
      9  1.1.1.2.4.2  rmind  * All rights reserved.
     10  1.1.1.2.4.2  rmind  *
     11  1.1.1.2.4.2  rmind  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2.4.2  rmind  * modification, are permitted provided that the following conditions
     13  1.1.1.2.4.2  rmind  * are met:
     14  1.1.1.2.4.2  rmind  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2.4.2  rmind  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2.4.2  rmind  *    without modification.
     17  1.1.1.2.4.2  rmind  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2.4.2  rmind  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2.4.2  rmind  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2.4.2  rmind  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2.4.2  rmind  *    binary redistribution.
     22  1.1.1.2.4.2  rmind  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2.4.2  rmind  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2.4.2  rmind  *    from this software without specific prior written permission.
     25  1.1.1.2.4.2  rmind  *
     26  1.1.1.2.4.2  rmind  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2.4.2  rmind  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2.4.2  rmind  * Software Foundation.
     29  1.1.1.2.4.2  rmind  *
     30  1.1.1.2.4.2  rmind  * NO WARRANTY
     31  1.1.1.2.4.2  rmind  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2.4.2  rmind  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2.4.2  rmind  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2.4.2  rmind  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2.4.2  rmind  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2.4.2  rmind  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2.4.2  rmind  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2.4.2  rmind  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2.4.2  rmind  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2.4.2  rmind  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2.4.2  rmind  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2.4.2  rmind  */
     43  1.1.1.2.4.2  rmind 
     44  1.1.1.2.4.2  rmind 
     45  1.1.1.2.4.2  rmind #include "aslcompiler.h"
     46  1.1.1.2.4.2  rmind #include "aslcompiler.y.h"
     47  1.1.1.2.4.2  rmind 
     48  1.1.1.2.4.2  rmind #include "acparser.h"
     49  1.1.1.2.4.2  rmind #include "amlcode.h"
     50  1.1.1.2.4.2  rmind #include "acnamesp.h"
     51  1.1.1.2.4.2  rmind 
     52  1.1.1.2.4.2  rmind 
     53  1.1.1.2.4.2  rmind #define _COMPONENT          ACPI_COMPILER
     54  1.1.1.2.4.2  rmind         ACPI_MODULE_NAME    ("aslopt")
     55  1.1.1.2.4.2  rmind 
     56  1.1.1.2.4.2  rmind 
     57  1.1.1.2.4.2  rmind static UINT32 OptTotal = 0;
     58  1.1.1.2.4.2  rmind 
     59  1.1.1.2.4.2  rmind /* Local prototypes */
     60  1.1.1.2.4.2  rmind 
     61  1.1.1.2.4.2  rmind static ACPI_STATUS
     62  1.1.1.2.4.2  rmind OptSearchToRoot (
     63  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
     64  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
     65  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
     66  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
     67  1.1.1.2.4.2  rmind     ACPI_BUFFER             *TargetPath,
     68  1.1.1.2.4.2  rmind     char                    **NewPath);
     69  1.1.1.2.4.2  rmind 
     70  1.1.1.2.4.2  rmind static ACPI_STATUS
     71  1.1.1.2.4.2  rmind OptBuildShortestPath (
     72  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
     73  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
     74  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
     75  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
     76  1.1.1.2.4.2  rmind     ACPI_BUFFER             *CurrentPath,
     77  1.1.1.2.4.2  rmind     ACPI_BUFFER             *TargetPath,
     78  1.1.1.2.4.2  rmind     ACPI_SIZE               AmlNameStringLength,
     79  1.1.1.2.4.2  rmind     UINT8                   IsDeclaration,
     80  1.1.1.2.4.2  rmind     char                    **ReturnNewPath);
     81  1.1.1.2.4.2  rmind 
     82  1.1.1.2.4.2  rmind static ACPI_STATUS
     83  1.1.1.2.4.2  rmind OptOptimizeNameDeclaration (
     84  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
     85  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
     86  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
     87  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
     88  1.1.1.2.4.2  rmind     char                    *AmlNameString,
     89  1.1.1.2.4.2  rmind     char                    **NewPath);
     90  1.1.1.2.4.2  rmind 
     91  1.1.1.2.4.2  rmind 
     92  1.1.1.2.4.2  rmind /*******************************************************************************
     93  1.1.1.2.4.2  rmind  *
     94  1.1.1.2.4.2  rmind  * FUNCTION:    OptSearchToRoot
     95  1.1.1.2.4.2  rmind  *
     96  1.1.1.2.4.2  rmind  * PARAMETERS:  Op                  - Current parser op
     97  1.1.1.2.4.2  rmind  *              WalkState           - Current state
     98  1.1.1.2.4.2  rmind  *              CurrentNode         - Where we are in the namespace
     99  1.1.1.2.4.2  rmind  *              TargetNode          - Node to which we are referring
    100  1.1.1.2.4.2  rmind  *              TargetPath          - External full path to the target node
    101  1.1.1.2.4.2  rmind  *              NewPath             - Where the optimized path is returned
    102  1.1.1.2.4.2  rmind  *
    103  1.1.1.2.4.2  rmind  * RETURN:      Status
    104  1.1.1.2.4.2  rmind  *
    105  1.1.1.2.4.2  rmind  * DESCRIPTION: Attempt to optimize a reference to a single 4-character ACPI
    106  1.1.1.2.4.2  rmind  *              name utilizing the search-to-root name resolution algorithm
    107  1.1.1.2.4.2  rmind  *              that is used by AML interpreters.
    108  1.1.1.2.4.2  rmind  *
    109  1.1.1.2.4.2  rmind  ******************************************************************************/
    110  1.1.1.2.4.2  rmind 
    111  1.1.1.2.4.2  rmind static ACPI_STATUS
    112  1.1.1.2.4.2  rmind OptSearchToRoot (
    113  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
    114  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
    115  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
    116  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
    117  1.1.1.2.4.2  rmind     ACPI_BUFFER             *TargetPath,
    118  1.1.1.2.4.2  rmind     char                    **NewPath)
    119  1.1.1.2.4.2  rmind {
    120  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    121  1.1.1.2.4.2  rmind     ACPI_GENERIC_STATE      ScopeInfo;
    122  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    123  1.1.1.2.4.2  rmind     char                    *Path;
    124  1.1.1.2.4.2  rmind 
    125  1.1.1.2.4.2  rmind 
    126  1.1.1.2.4.2  rmind     ACPI_FUNCTION_NAME (OptSearchToRoot);
    127  1.1.1.2.4.2  rmind 
    128  1.1.1.2.4.2  rmind 
    129  1.1.1.2.4.2  rmind     /*
    130  1.1.1.2.4.2  rmind      * Check if search-to-root can be utilized.  Use the last NameSeg of
    131  1.1.1.2.4.2  rmind      * the NamePath and 1) See if can be found and 2) If found, make
    132  1.1.1.2.4.2  rmind      * sure that it is the same node that we want.  If there is another
    133  1.1.1.2.4.2  rmind      * name in the search path before the one we want, the nodes will
    134  1.1.1.2.4.2  rmind      * not match, and we cannot use this optimization.
    135  1.1.1.2.4.2  rmind      */
    136  1.1.1.2.4.2  rmind     Path = &(((char *) TargetPath->Pointer)[TargetPath->Length -
    137  1.1.1.2.4.2  rmind                                             ACPI_NAME_SIZE]),
    138  1.1.1.2.4.2  rmind     ScopeInfo.Scope.Node = CurrentNode;
    139  1.1.1.2.4.2  rmind 
    140  1.1.1.2.4.2  rmind     /* Lookup the NameSeg using SEARCH_PARENT (search-to-root) */
    141  1.1.1.2.4.2  rmind 
    142  1.1.1.2.4.2  rmind     Status = AcpiNsLookup (&ScopeInfo, Path, ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
    143  1.1.1.2.4.2  rmind                     ACPI_NS_SEARCH_PARENT | ACPI_NS_DONT_OPEN_SCOPE,
    144  1.1.1.2.4.2  rmind                     WalkState, &(Node));
    145  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    146  1.1.1.2.4.2  rmind     {
    147  1.1.1.2.4.2  rmind         return (Status);
    148  1.1.1.2.4.2  rmind     }
    149  1.1.1.2.4.2  rmind 
    150  1.1.1.2.4.2  rmind     /*
    151  1.1.1.2.4.2  rmind      * We found the name, but we must check to make sure that the node
    152  1.1.1.2.4.2  rmind      * matches.  Otherwise, there is another identical name in the search
    153  1.1.1.2.4.2  rmind      * path that precludes the use of this optimization.
    154  1.1.1.2.4.2  rmind      */
    155  1.1.1.2.4.2  rmind     if (Node != TargetNode)
    156  1.1.1.2.4.2  rmind     {
    157  1.1.1.2.4.2  rmind         /*
    158  1.1.1.2.4.2  rmind          * This means that another object with the same name was found first,
    159  1.1.1.2.4.2  rmind          * and we cannot use this optimization.
    160  1.1.1.2.4.2  rmind          */
    161  1.1.1.2.4.2  rmind         return (AE_NOT_FOUND);
    162  1.1.1.2.4.2  rmind     }
    163  1.1.1.2.4.2  rmind 
    164  1.1.1.2.4.2  rmind     /* Found the node, we can use this optimization */
    165  1.1.1.2.4.2  rmind 
    166  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    167  1.1.1.2.4.2  rmind         "NAMESEG:   %-24s", Path));
    168  1.1.1.2.4.2  rmind 
    169  1.1.1.2.4.2  rmind     /* We must allocate a new string for the name (TargetPath gets deleted) */
    170  1.1.1.2.4.2  rmind 
    171  1.1.1.2.4.2  rmind     *NewPath = ACPI_ALLOCATE_ZEROED (ACPI_NAME_SIZE + 1);
    172  1.1.1.2.4.2  rmind     ACPI_STRCPY (*NewPath, Path);
    173  1.1.1.2.4.2  rmind 
    174  1.1.1.2.4.2  rmind     if (ACPI_STRNCMP (*NewPath, "_T_", 3))
    175  1.1.1.2.4.2  rmind     {
    176  1.1.1.2.4.2  rmind         AslError (ASL_OPTIMIZATION, ASL_MSG_SINGLE_NAME_OPTIMIZATION, Op,
    177  1.1.1.2.4.2  rmind                 *NewPath);
    178  1.1.1.2.4.2  rmind     }
    179  1.1.1.2.4.2  rmind 
    180  1.1.1.2.4.2  rmind     return (AE_OK);
    181  1.1.1.2.4.2  rmind }
    182  1.1.1.2.4.2  rmind 
    183  1.1.1.2.4.2  rmind 
    184  1.1.1.2.4.2  rmind /*******************************************************************************
    185  1.1.1.2.4.2  rmind  *
    186  1.1.1.2.4.2  rmind  * FUNCTION:    OptBuildShortestPath
    187  1.1.1.2.4.2  rmind  *
    188  1.1.1.2.4.2  rmind  * PARAMETERS:  Op                  - Current parser op
    189  1.1.1.2.4.2  rmind  *              WalkState           - Current state
    190  1.1.1.2.4.2  rmind  *              CurrentNode         - Where we are in the namespace
    191  1.1.1.2.4.2  rmind  *              TargetNode          - Node to which we are referring
    192  1.1.1.2.4.2  rmind  *              CurrentPath         - External full path to the current node
    193  1.1.1.2.4.2  rmind  *              TargetPath          - External full path to the target node
    194  1.1.1.2.4.2  rmind  *              AmlNameStringLength - Length of the original namepath
    195  1.1.1.2.4.2  rmind  *              IsDeclaration       - TRUE for declaration, FALSE for reference
    196  1.1.1.2.4.2  rmind  *              ReturnNewPath       - Where the optimized path is returned
    197  1.1.1.2.4.2  rmind  *
    198  1.1.1.2.4.2  rmind  * RETURN:      Status
    199  1.1.1.2.4.2  rmind  *
    200  1.1.1.2.4.2  rmind  * DESCRIPTION: Build an optimal NamePath using carats
    201  1.1.1.2.4.2  rmind  *
    202  1.1.1.2.4.2  rmind  ******************************************************************************/
    203  1.1.1.2.4.2  rmind 
    204  1.1.1.2.4.2  rmind static ACPI_STATUS
    205  1.1.1.2.4.2  rmind OptBuildShortestPath (
    206  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
    207  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
    208  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
    209  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
    210  1.1.1.2.4.2  rmind     ACPI_BUFFER             *CurrentPath,
    211  1.1.1.2.4.2  rmind     ACPI_BUFFER             *TargetPath,
    212  1.1.1.2.4.2  rmind     ACPI_SIZE               AmlNameStringLength,
    213  1.1.1.2.4.2  rmind     UINT8                   IsDeclaration,
    214  1.1.1.2.4.2  rmind     char                    **ReturnNewPath)
    215  1.1.1.2.4.2  rmind {
    216  1.1.1.2.4.2  rmind     UINT32                  NumCommonSegments;
    217  1.1.1.2.4.2  rmind     UINT32                  MaxCommonSegments;
    218  1.1.1.2.4.2  rmind     UINT32                  Index;
    219  1.1.1.2.4.2  rmind     UINT32                  NumCarats;
    220  1.1.1.2.4.2  rmind     UINT32                  i;
    221  1.1.1.2.4.2  rmind     char                    *NewPath;
    222  1.1.1.2.4.2  rmind     char                    *NewPathExternal;
    223  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    224  1.1.1.2.4.2  rmind     ACPI_GENERIC_STATE      ScopeInfo;
    225  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    226  1.1.1.2.4.2  rmind     BOOLEAN                 SubPath = FALSE;
    227  1.1.1.2.4.2  rmind 
    228  1.1.1.2.4.2  rmind 
    229  1.1.1.2.4.2  rmind     ACPI_FUNCTION_NAME (OptBuildShortestPath);
    230  1.1.1.2.4.2  rmind 
    231  1.1.1.2.4.2  rmind 
    232  1.1.1.2.4.2  rmind     ScopeInfo.Scope.Node = CurrentNode;
    233  1.1.1.2.4.2  rmind 
    234  1.1.1.2.4.2  rmind     /*
    235  1.1.1.2.4.2  rmind      * Determine the maximum number of NameSegs that the Target and Current paths
    236  1.1.1.2.4.2  rmind      * can possibly have in common.  (To optimize, we have to have at least 1)
    237  1.1.1.2.4.2  rmind      *
    238  1.1.1.2.4.2  rmind      * Note: The external NamePath string lengths are always a multiple of 5
    239  1.1.1.2.4.2  rmind      * (ACPI_NAME_SIZE + separator)
    240  1.1.1.2.4.2  rmind      */
    241  1.1.1.2.4.2  rmind     MaxCommonSegments = TargetPath->Length / ACPI_PATH_SEGMENT_LENGTH;
    242  1.1.1.2.4.2  rmind     if (CurrentPath->Length < TargetPath->Length)
    243  1.1.1.2.4.2  rmind     {
    244  1.1.1.2.4.2  rmind         MaxCommonSegments = CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH;
    245  1.1.1.2.4.2  rmind     }
    246  1.1.1.2.4.2  rmind 
    247  1.1.1.2.4.2  rmind     /*
    248  1.1.1.2.4.2  rmind      * Determine how many NameSegs the two paths have in common.
    249  1.1.1.2.4.2  rmind      * (Starting from the root)
    250  1.1.1.2.4.2  rmind      */
    251  1.1.1.2.4.2  rmind     for (NumCommonSegments = 0;
    252  1.1.1.2.4.2  rmind          NumCommonSegments < MaxCommonSegments;
    253  1.1.1.2.4.2  rmind          NumCommonSegments++)
    254  1.1.1.2.4.2  rmind     {
    255  1.1.1.2.4.2  rmind         /* Compare two single NameSegs */
    256  1.1.1.2.4.2  rmind 
    257  1.1.1.2.4.2  rmind         if (ACPI_STRNCMP (
    258  1.1.1.2.4.2  rmind             &((char *) TargetPath->Pointer)[(NumCommonSegments *
    259  1.1.1.2.4.2  rmind                                              ACPI_PATH_SEGMENT_LENGTH) + 1],
    260  1.1.1.2.4.2  rmind             &((char *) CurrentPath->Pointer)[(NumCommonSegments *
    261  1.1.1.2.4.2  rmind                                               ACPI_PATH_SEGMENT_LENGTH) + 1],
    262  1.1.1.2.4.2  rmind             ACPI_NAME_SIZE))
    263  1.1.1.2.4.2  rmind         {
    264  1.1.1.2.4.2  rmind             /* Mismatch */
    265  1.1.1.2.4.2  rmind 
    266  1.1.1.2.4.2  rmind             break;
    267  1.1.1.2.4.2  rmind         }
    268  1.1.1.2.4.2  rmind     }
    269  1.1.1.2.4.2  rmind 
    270  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " COMMON: %u",
    271  1.1.1.2.4.2  rmind         NumCommonSegments));
    272  1.1.1.2.4.2  rmind 
    273  1.1.1.2.4.2  rmind     /* There must be at least 1 common NameSeg in order to optimize */
    274  1.1.1.2.4.2  rmind 
    275  1.1.1.2.4.2  rmind     if (NumCommonSegments == 0)
    276  1.1.1.2.4.2  rmind     {
    277  1.1.1.2.4.2  rmind         return (AE_NOT_FOUND);
    278  1.1.1.2.4.2  rmind     }
    279  1.1.1.2.4.2  rmind 
    280  1.1.1.2.4.2  rmind     if (NumCommonSegments == MaxCommonSegments)
    281  1.1.1.2.4.2  rmind     {
    282  1.1.1.2.4.2  rmind         if (CurrentPath->Length == TargetPath->Length)
    283  1.1.1.2.4.2  rmind         {
    284  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SAME PATH"));
    285  1.1.1.2.4.2  rmind             return (AE_NOT_FOUND);
    286  1.1.1.2.4.2  rmind         }
    287  1.1.1.2.4.2  rmind         else
    288  1.1.1.2.4.2  rmind         {
    289  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " SUBPATH"));
    290  1.1.1.2.4.2  rmind             SubPath = TRUE;
    291  1.1.1.2.4.2  rmind         }
    292  1.1.1.2.4.2  rmind     }
    293  1.1.1.2.4.2  rmind 
    294  1.1.1.2.4.2  rmind     /* Determine how many prefix Carats are required */
    295  1.1.1.2.4.2  rmind 
    296  1.1.1.2.4.2  rmind     NumCarats = (CurrentPath->Length / ACPI_PATH_SEGMENT_LENGTH) -
    297  1.1.1.2.4.2  rmind                 NumCommonSegments;
    298  1.1.1.2.4.2  rmind 
    299  1.1.1.2.4.2  rmind     /*
    300  1.1.1.2.4.2  rmind      * Construct a new target string
    301  1.1.1.2.4.2  rmind      */
    302  1.1.1.2.4.2  rmind     NewPathExternal = ACPI_ALLOCATE_ZEROED (
    303  1.1.1.2.4.2  rmind         TargetPath->Length + NumCarats + 1);
    304  1.1.1.2.4.2  rmind 
    305  1.1.1.2.4.2  rmind     /* Insert the Carats into the Target string */
    306  1.1.1.2.4.2  rmind 
    307  1.1.1.2.4.2  rmind     for (i = 0; i < NumCarats; i++)
    308  1.1.1.2.4.2  rmind     {
    309  1.1.1.2.4.2  rmind         NewPathExternal[i] = '^';
    310  1.1.1.2.4.2  rmind     }
    311  1.1.1.2.4.2  rmind 
    312  1.1.1.2.4.2  rmind     /*
    313  1.1.1.2.4.2  rmind      * Copy only the necessary (optimal) segments from the original
    314  1.1.1.2.4.2  rmind      * target string
    315  1.1.1.2.4.2  rmind      */
    316  1.1.1.2.4.2  rmind     Index = (NumCommonSegments * ACPI_PATH_SEGMENT_LENGTH) + 1;
    317  1.1.1.2.4.2  rmind 
    318  1.1.1.2.4.2  rmind     /* Special handling for exact subpath in a name declaration */
    319  1.1.1.2.4.2  rmind 
    320  1.1.1.2.4.2  rmind     if (IsDeclaration && SubPath && (CurrentPath->Length > TargetPath->Length))
    321  1.1.1.2.4.2  rmind     {
    322  1.1.1.2.4.2  rmind         /*
    323  1.1.1.2.4.2  rmind          * The current path is longer than the target, and the target is a
    324  1.1.1.2.4.2  rmind          * subpath of the current path. We must include one more NameSeg of
    325  1.1.1.2.4.2  rmind          * the target path
    326  1.1.1.2.4.2  rmind          */
    327  1.1.1.2.4.2  rmind         Index -= ACPI_PATH_SEGMENT_LENGTH;
    328  1.1.1.2.4.2  rmind 
    329  1.1.1.2.4.2  rmind         /* Special handling for Scope() operator */
    330  1.1.1.2.4.2  rmind 
    331  1.1.1.2.4.2  rmind         if (Op->Asl.AmlOpcode == AML_SCOPE_OP)
    332  1.1.1.2.4.2  rmind         {
    333  1.1.1.2.4.2  rmind             NewPathExternal[i] = '^';
    334  1.1.1.2.4.2  rmind             i++;
    335  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "(EXTRA ^)"));
    336  1.1.1.2.4.2  rmind         }
    337  1.1.1.2.4.2  rmind     }
    338  1.1.1.2.4.2  rmind 
    339  1.1.1.2.4.2  rmind     /* Make sure we haven't gone off the end of the target path */
    340  1.1.1.2.4.2  rmind 
    341  1.1.1.2.4.2  rmind     if (Index > TargetPath->Length)
    342  1.1.1.2.4.2  rmind     {
    343  1.1.1.2.4.2  rmind         Index = TargetPath->Length;
    344  1.1.1.2.4.2  rmind     }
    345  1.1.1.2.4.2  rmind 
    346  1.1.1.2.4.2  rmind     ACPI_STRCPY (&NewPathExternal[i], &((char *) TargetPath->Pointer)[Index]);
    347  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " %-24s", NewPathExternal));
    348  1.1.1.2.4.2  rmind 
    349  1.1.1.2.4.2  rmind     /*
    350  1.1.1.2.4.2  rmind      * Internalize the new target string and check it against the original
    351  1.1.1.2.4.2  rmind      * string to make sure that this is in fact an optimization. If the
    352  1.1.1.2.4.2  rmind      * original string is already optimal, there is no point in continuing.
    353  1.1.1.2.4.2  rmind      */
    354  1.1.1.2.4.2  rmind     Status = AcpiNsInternalizeName (NewPathExternal, &NewPath);
    355  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    356  1.1.1.2.4.2  rmind     {
    357  1.1.1.2.4.2  rmind         AslCoreSubsystemError (Op, Status, "Internalizing new NamePath",
    358  1.1.1.2.4.2  rmind             ASL_NO_ABORT);
    359  1.1.1.2.4.2  rmind         ACPI_FREE (NewPathExternal);
    360  1.1.1.2.4.2  rmind         return (Status);
    361  1.1.1.2.4.2  rmind     }
    362  1.1.1.2.4.2  rmind 
    363  1.1.1.2.4.2  rmind     if (ACPI_STRLEN (NewPath) >= AmlNameStringLength)
    364  1.1.1.2.4.2  rmind     {
    365  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    366  1.1.1.2.4.2  rmind             " NOT SHORTER (New %u old %u)",
    367  1.1.1.2.4.2  rmind             (UINT32) ACPI_STRLEN (NewPath), (UINT32) AmlNameStringLength));
    368  1.1.1.2.4.2  rmind         ACPI_FREE (NewPathExternal);
    369  1.1.1.2.4.2  rmind         return (AE_NOT_FOUND);
    370  1.1.1.2.4.2  rmind     }
    371  1.1.1.2.4.2  rmind 
    372  1.1.1.2.4.2  rmind     /*
    373  1.1.1.2.4.2  rmind      * Check to make sure that the optimization finds the node we are
    374  1.1.1.2.4.2  rmind      * looking for.  This is simply a sanity check on the new
    375  1.1.1.2.4.2  rmind      * path that has been created.
    376  1.1.1.2.4.2  rmind      */
    377  1.1.1.2.4.2  rmind     Status = AcpiNsLookup (&ScopeInfo,  NewPath,
    378  1.1.1.2.4.2  rmind                     ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
    379  1.1.1.2.4.2  rmind                     ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
    380  1.1.1.2.4.2  rmind     if (ACPI_SUCCESS (Status))
    381  1.1.1.2.4.2  rmind     {
    382  1.1.1.2.4.2  rmind         /* Found the namepath, but make sure the node is correct */
    383  1.1.1.2.4.2  rmind 
    384  1.1.1.2.4.2  rmind         if (Node == TargetNode)
    385  1.1.1.2.4.2  rmind         {
    386  1.1.1.2.4.2  rmind             /* The lookup matched the node, accept this optimization */
    387  1.1.1.2.4.2  rmind 
    388  1.1.1.2.4.2  rmind             AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
    389  1.1.1.2.4.2  rmind                 Op, NewPathExternal);
    390  1.1.1.2.4.2  rmind             *ReturnNewPath = NewPath;
    391  1.1.1.2.4.2  rmind         }
    392  1.1.1.2.4.2  rmind         else
    393  1.1.1.2.4.2  rmind         {
    394  1.1.1.2.4.2  rmind             /* Node is not correct, do not use this optimization */
    395  1.1.1.2.4.2  rmind 
    396  1.1.1.2.4.2  rmind             Status = AE_NOT_FOUND;
    397  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** WRONG NODE"));
    398  1.1.1.2.4.2  rmind             AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
    399  1.1.1.2.4.2  rmind                 "Not using optimized name - found wrong node");
    400  1.1.1.2.4.2  rmind         }
    401  1.1.1.2.4.2  rmind     }
    402  1.1.1.2.4.2  rmind     else
    403  1.1.1.2.4.2  rmind     {
    404  1.1.1.2.4.2  rmind         /* The lookup failed, we obviously cannot use this optimization */
    405  1.1.1.2.4.2  rmind 
    406  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ***** NOT FOUND"));
    407  1.1.1.2.4.2  rmind         AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
    408  1.1.1.2.4.2  rmind             "Not using optimized name - did not find node");
    409  1.1.1.2.4.2  rmind     }
    410  1.1.1.2.4.2  rmind 
    411  1.1.1.2.4.2  rmind     ACPI_FREE (NewPathExternal);
    412  1.1.1.2.4.2  rmind     return (Status);
    413  1.1.1.2.4.2  rmind }
    414  1.1.1.2.4.2  rmind 
    415  1.1.1.2.4.2  rmind 
    416  1.1.1.2.4.2  rmind /*******************************************************************************
    417  1.1.1.2.4.2  rmind  *
    418  1.1.1.2.4.2  rmind  * FUNCTION:    OptOptimizeNameDeclaration
    419  1.1.1.2.4.2  rmind  *
    420  1.1.1.2.4.2  rmind  * PARAMETERS:  Op                  - Current parser op
    421  1.1.1.2.4.2  rmind  *              WalkState           - Current state
    422  1.1.1.2.4.2  rmind  *              CurrentNode         - Where we are in the namespace
    423  1.1.1.2.4.2  rmind  *              AmlNameString       - Unoptimized namepath
    424  1.1.1.2.4.2  rmind  *              NewPath             - Where the optimized path is returned
    425  1.1.1.2.4.2  rmind  *
    426  1.1.1.2.4.2  rmind  * RETURN:      Status. AE_OK If path is optimized
    427  1.1.1.2.4.2  rmind  *
    428  1.1.1.2.4.2  rmind  * DESCRIPTION: Perform a simple optimization of removing an extraneous
    429  1.1.1.2.4.2  rmind  *              backslash prefix if we are already at the root scope.
    430  1.1.1.2.4.2  rmind  *
    431  1.1.1.2.4.2  rmind  ******************************************************************************/
    432  1.1.1.2.4.2  rmind 
    433  1.1.1.2.4.2  rmind static ACPI_STATUS
    434  1.1.1.2.4.2  rmind OptOptimizeNameDeclaration (
    435  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
    436  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
    437  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode,
    438  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode,
    439  1.1.1.2.4.2  rmind     char                    *AmlNameString,
    440  1.1.1.2.4.2  rmind     char                    **NewPath)
    441  1.1.1.2.4.2  rmind {
    442  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    443  1.1.1.2.4.2  rmind     char                    *NewPathExternal;
    444  1.1.1.2.4.2  rmind     ACPI_GENERIC_STATE      ScopeInfo;
    445  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *Node;
    446  1.1.1.2.4.2  rmind 
    447  1.1.1.2.4.2  rmind 
    448  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (OptOptimizeNameDeclaration);
    449  1.1.1.2.4.2  rmind 
    450  1.1.1.2.4.2  rmind 
    451  1.1.1.2.4.2  rmind     if (((CurrentNode == AcpiGbl_RootNode) ||
    452  1.1.1.2.4.2  rmind         (Op->Common.Parent->Asl.ParseOpcode == PARSEOP_DEFINITIONBLOCK)) &&
    453  1.1.1.2.4.2  rmind             (AmlNameString[0] == '\\'))
    454  1.1.1.2.4.2  rmind     {
    455  1.1.1.2.4.2  rmind         /*
    456  1.1.1.2.4.2  rmind          * The current scope is the root, and the namepath has a root prefix
    457  1.1.1.2.4.2  rmind          * that is therefore extraneous.  Remove it.
    458  1.1.1.2.4.2  rmind          */
    459  1.1.1.2.4.2  rmind         *NewPath = &AmlNameString[1];
    460  1.1.1.2.4.2  rmind 
    461  1.1.1.2.4.2  rmind         /* Debug output */
    462  1.1.1.2.4.2  rmind 
    463  1.1.1.2.4.2  rmind         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, *NewPath,
    464  1.1.1.2.4.2  rmind                     NULL, &NewPathExternal);
    465  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    466  1.1.1.2.4.2  rmind         {
    467  1.1.1.2.4.2  rmind             AslCoreSubsystemError (Op, Status, "Externalizing NamePath",
    468  1.1.1.2.4.2  rmind                 ASL_NO_ABORT);
    469  1.1.1.2.4.2  rmind             return (Status);
    470  1.1.1.2.4.2  rmind         }
    471  1.1.1.2.4.2  rmind 
    472  1.1.1.2.4.2  rmind         /*
    473  1.1.1.2.4.2  rmind          * Check to make sure that the optimization finds the node we are
    474  1.1.1.2.4.2  rmind          * looking for.  This is simply a sanity check on the new
    475  1.1.1.2.4.2  rmind          * path that has been created.
    476  1.1.1.2.4.2  rmind          */
    477  1.1.1.2.4.2  rmind         ScopeInfo.Scope.Node = CurrentNode;
    478  1.1.1.2.4.2  rmind         Status = AcpiNsLookup (&ScopeInfo, *NewPath,
    479  1.1.1.2.4.2  rmind                         ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
    480  1.1.1.2.4.2  rmind                         ACPI_NS_DONT_OPEN_SCOPE, WalkState, &(Node));
    481  1.1.1.2.4.2  rmind         if (ACPI_SUCCESS (Status))
    482  1.1.1.2.4.2  rmind         {
    483  1.1.1.2.4.2  rmind             /* Found the namepath, but make sure the node is correct */
    484  1.1.1.2.4.2  rmind 
    485  1.1.1.2.4.2  rmind             if (Node == TargetNode)
    486  1.1.1.2.4.2  rmind             {
    487  1.1.1.2.4.2  rmind                 /* The lookup matched the node, accept this optimization */
    488  1.1.1.2.4.2  rmind 
    489  1.1.1.2.4.2  rmind                 AslError (ASL_OPTIMIZATION, ASL_MSG_NAME_OPTIMIZATION,
    490  1.1.1.2.4.2  rmind                     Op, NewPathExternal);
    491  1.1.1.2.4.2  rmind 
    492  1.1.1.2.4.2  rmind                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    493  1.1.1.2.4.2  rmind                     "AT ROOT:   %-24s", NewPathExternal));
    494  1.1.1.2.4.2  rmind             }
    495  1.1.1.2.4.2  rmind             else
    496  1.1.1.2.4.2  rmind             {
    497  1.1.1.2.4.2  rmind                 /* Node is not correct, do not use this optimization */
    498  1.1.1.2.4.2  rmind 
    499  1.1.1.2.4.2  rmind                 Status = AE_NOT_FOUND;
    500  1.1.1.2.4.2  rmind                 ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    501  1.1.1.2.4.2  rmind                     " ***** WRONG NODE"));
    502  1.1.1.2.4.2  rmind                 AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
    503  1.1.1.2.4.2  rmind                     "Not using optimized name - found wrong node");
    504  1.1.1.2.4.2  rmind             }
    505  1.1.1.2.4.2  rmind         }
    506  1.1.1.2.4.2  rmind         else
    507  1.1.1.2.4.2  rmind         {
    508  1.1.1.2.4.2  rmind             /* The lookup failed, we obviously cannot use this optimization */
    509  1.1.1.2.4.2  rmind 
    510  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    511  1.1.1.2.4.2  rmind                 " ***** NOT FOUND"));
    512  1.1.1.2.4.2  rmind             AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op,
    513  1.1.1.2.4.2  rmind                 "Not using optimized name - did not find node");
    514  1.1.1.2.4.2  rmind         }
    515  1.1.1.2.4.2  rmind 
    516  1.1.1.2.4.2  rmind         ACPI_FREE (NewPathExternal);
    517  1.1.1.2.4.2  rmind         return (Status);
    518  1.1.1.2.4.2  rmind     }
    519  1.1.1.2.4.2  rmind 
    520  1.1.1.2.4.2  rmind     /* Could not optimize */
    521  1.1.1.2.4.2  rmind 
    522  1.1.1.2.4.2  rmind     return (AE_NOT_FOUND);
    523  1.1.1.2.4.2  rmind }
    524  1.1.1.2.4.2  rmind 
    525  1.1.1.2.4.2  rmind 
    526  1.1.1.2.4.2  rmind /*******************************************************************************
    527  1.1.1.2.4.2  rmind  *
    528  1.1.1.2.4.2  rmind  * FUNCTION:    OptOptimizeNamePath
    529  1.1.1.2.4.2  rmind  *
    530  1.1.1.2.4.2  rmind  * PARAMETERS:  Op                  - Current parser op
    531  1.1.1.2.4.2  rmind  *              Flags               - Opcode info flags
    532  1.1.1.2.4.2  rmind  *              WalkState           - Current state
    533  1.1.1.2.4.2  rmind  *              AmlNameString       - Unoptimized namepath
    534  1.1.1.2.4.2  rmind  *              TargetNode          - Node to which AmlNameString refers
    535  1.1.1.2.4.2  rmind  *
    536  1.1.1.2.4.2  rmind  * RETURN:      None.  If path is optimized, the Op is updated with new path
    537  1.1.1.2.4.2  rmind  *
    538  1.1.1.2.4.2  rmind  * DESCRIPTION: Optimize a Named Declaration or Reference to the minimal length.
    539  1.1.1.2.4.2  rmind  *              Must take into account both the current location in the
    540  1.1.1.2.4.2  rmind  *              namespace and the actual reference path.
    541  1.1.1.2.4.2  rmind  *
    542  1.1.1.2.4.2  rmind  ******************************************************************************/
    543  1.1.1.2.4.2  rmind 
    544  1.1.1.2.4.2  rmind void
    545  1.1.1.2.4.2  rmind OptOptimizeNamePath (
    546  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *Op,
    547  1.1.1.2.4.2  rmind     UINT32                  Flags,
    548  1.1.1.2.4.2  rmind     ACPI_WALK_STATE         *WalkState,
    549  1.1.1.2.4.2  rmind     char                    *AmlNameString,
    550  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *TargetNode)
    551  1.1.1.2.4.2  rmind {
    552  1.1.1.2.4.2  rmind     ACPI_STATUS             Status;
    553  1.1.1.2.4.2  rmind     ACPI_BUFFER             TargetPath;
    554  1.1.1.2.4.2  rmind     ACPI_BUFFER             CurrentPath;
    555  1.1.1.2.4.2  rmind     ACPI_SIZE               AmlNameStringLength;
    556  1.1.1.2.4.2  rmind     ACPI_NAMESPACE_NODE     *CurrentNode;
    557  1.1.1.2.4.2  rmind     char                    *ExternalNameString;
    558  1.1.1.2.4.2  rmind     char                    *NewPath = NULL;
    559  1.1.1.2.4.2  rmind     ACPI_SIZE               HowMuchShorter;
    560  1.1.1.2.4.2  rmind     ACPI_PARSE_OBJECT       *NextOp;
    561  1.1.1.2.4.2  rmind 
    562  1.1.1.2.4.2  rmind 
    563  1.1.1.2.4.2  rmind     ACPI_FUNCTION_TRACE (OptOptimizeNamePath);
    564  1.1.1.2.4.2  rmind 
    565  1.1.1.2.4.2  rmind 
    566  1.1.1.2.4.2  rmind     /* This is an optional optimization */
    567  1.1.1.2.4.2  rmind 
    568  1.1.1.2.4.2  rmind     if (!Gbl_ReferenceOptimizationFlag)
    569  1.1.1.2.4.2  rmind     {
    570  1.1.1.2.4.2  rmind         return_VOID;
    571  1.1.1.2.4.2  rmind     }
    572  1.1.1.2.4.2  rmind 
    573  1.1.1.2.4.2  rmind     /* Various required items */
    574  1.1.1.2.4.2  rmind 
    575  1.1.1.2.4.2  rmind     if (!TargetNode || !WalkState || !AmlNameString || !Op->Common.Parent)
    576  1.1.1.2.4.2  rmind     {
    577  1.1.1.2.4.2  rmind         return_VOID;
    578  1.1.1.2.4.2  rmind     }
    579  1.1.1.2.4.2  rmind 
    580  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "%5d [%12.12s] [%12.12s] ",
    581  1.1.1.2.4.2  rmind         Op->Asl.LogicalLineNumber,
    582  1.1.1.2.4.2  rmind         AcpiPsGetOpcodeName (Op->Common.Parent->Common.AmlOpcode),
    583  1.1.1.2.4.2  rmind         AcpiPsGetOpcodeName (Op->Common.AmlOpcode)));
    584  1.1.1.2.4.2  rmind 
    585  1.1.1.2.4.2  rmind     if (!(Flags & (AML_NAMED | AML_CREATE)))
    586  1.1.1.2.4.2  rmind     {
    587  1.1.1.2.4.2  rmind         if (Op->Asl.CompileFlags & NODE_IS_NAME_DECLARATION)
    588  1.1.1.2.4.2  rmind         {
    589  1.1.1.2.4.2  rmind             /* We don't want to fuss with actual name declaration nodes here */
    590  1.1.1.2.4.2  rmind 
    591  1.1.1.2.4.2  rmind             ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    592  1.1.1.2.4.2  rmind                 "******* NAME DECLARATION\n"));
    593  1.1.1.2.4.2  rmind             return_VOID;
    594  1.1.1.2.4.2  rmind         }
    595  1.1.1.2.4.2  rmind     }
    596  1.1.1.2.4.2  rmind 
    597  1.1.1.2.4.2  rmind     /*
    598  1.1.1.2.4.2  rmind      * The original path must be longer than one NameSeg (4 chars) for there
    599  1.1.1.2.4.2  rmind      * to be any possibility that it can be optimized to a shorter string
    600  1.1.1.2.4.2  rmind      */
    601  1.1.1.2.4.2  rmind     AmlNameStringLength = ACPI_STRLEN (AmlNameString);
    602  1.1.1.2.4.2  rmind     if (AmlNameStringLength <= ACPI_NAME_SIZE)
    603  1.1.1.2.4.2  rmind     {
    604  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    605  1.1.1.2.4.2  rmind             "NAMESEG %4.4s\n", AmlNameString));
    606  1.1.1.2.4.2  rmind         return_VOID;
    607  1.1.1.2.4.2  rmind     }
    608  1.1.1.2.4.2  rmind 
    609  1.1.1.2.4.2  rmind     /*
    610  1.1.1.2.4.2  rmind      * We need to obtain the node that represents the current scope -- where
    611  1.1.1.2.4.2  rmind      * we are right now in the namespace.  We will compare this path
    612  1.1.1.2.4.2  rmind      * against the Namepath, looking for commonality.
    613  1.1.1.2.4.2  rmind      */
    614  1.1.1.2.4.2  rmind     CurrentNode = AcpiGbl_RootNode;
    615  1.1.1.2.4.2  rmind     if (WalkState->ScopeInfo)
    616  1.1.1.2.4.2  rmind     {
    617  1.1.1.2.4.2  rmind         CurrentNode = WalkState->ScopeInfo->Scope.Node;
    618  1.1.1.2.4.2  rmind     }
    619  1.1.1.2.4.2  rmind 
    620  1.1.1.2.4.2  rmind     if (Flags & (AML_NAMED | AML_CREATE))
    621  1.1.1.2.4.2  rmind     {
    622  1.1.1.2.4.2  rmind         /* This is the declaration of a new name */
    623  1.1.1.2.4.2  rmind 
    624  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "NAME"));
    625  1.1.1.2.4.2  rmind 
    626  1.1.1.2.4.2  rmind         /*
    627  1.1.1.2.4.2  rmind          * The node of interest is the parent of this node
    628  1.1.1.2.4.2  rmind          * (the containing scope)
    629  1.1.1.2.4.2  rmind          */
    630  1.1.1.2.4.2  rmind         CurrentNode = Op->Asl.Parent->Asl.Node;
    631  1.1.1.2.4.2  rmind         if (!CurrentNode)
    632  1.1.1.2.4.2  rmind         {
    633  1.1.1.2.4.2  rmind             CurrentNode = AcpiGbl_RootNode;
    634  1.1.1.2.4.2  rmind         }
    635  1.1.1.2.4.2  rmind     }
    636  1.1.1.2.4.2  rmind     else
    637  1.1.1.2.4.2  rmind     {
    638  1.1.1.2.4.2  rmind         /* This is a reference to an existing named object */
    639  1.1.1.2.4.2  rmind 
    640  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "REF "));
    641  1.1.1.2.4.2  rmind     }
    642  1.1.1.2.4.2  rmind 
    643  1.1.1.2.4.2  rmind     /*
    644  1.1.1.2.4.2  rmind      * Obtain the full paths to the two nodes that we are interested in
    645  1.1.1.2.4.2  rmind      * (Target and current namespace location) in external
    646  1.1.1.2.4.2  rmind      * format -- something we can easily manipulate
    647  1.1.1.2.4.2  rmind      */
    648  1.1.1.2.4.2  rmind     TargetPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    649  1.1.1.2.4.2  rmind     Status = AcpiNsHandleToPathname (TargetNode, &TargetPath);
    650  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    651  1.1.1.2.4.2  rmind     {
    652  1.1.1.2.4.2  rmind         AslCoreSubsystemError (Op, Status, "Getting Target NamePath",
    653  1.1.1.2.4.2  rmind             ASL_NO_ABORT);
    654  1.1.1.2.4.2  rmind         return_VOID;
    655  1.1.1.2.4.2  rmind     }
    656  1.1.1.2.4.2  rmind     TargetPath.Length--;    /* Subtract one for null terminator */
    657  1.1.1.2.4.2  rmind 
    658  1.1.1.2.4.2  rmind     /* CurrentPath is the path to this scope (where we are in the namespace) */
    659  1.1.1.2.4.2  rmind 
    660  1.1.1.2.4.2  rmind     CurrentPath.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    661  1.1.1.2.4.2  rmind     Status = AcpiNsHandleToPathname (CurrentNode, &CurrentPath);
    662  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    663  1.1.1.2.4.2  rmind     {
    664  1.1.1.2.4.2  rmind         AslCoreSubsystemError (Op, Status, "Getting Current NamePath",
    665  1.1.1.2.4.2  rmind             ASL_NO_ABORT);
    666  1.1.1.2.4.2  rmind         return_VOID;
    667  1.1.1.2.4.2  rmind     }
    668  1.1.1.2.4.2  rmind     CurrentPath.Length--;   /* Subtract one for null terminator */
    669  1.1.1.2.4.2  rmind 
    670  1.1.1.2.4.2  rmind     /* Debug output only */
    671  1.1.1.2.4.2  rmind 
    672  1.1.1.2.4.2  rmind     Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, AmlNameString,
    673  1.1.1.2.4.2  rmind                 NULL, &ExternalNameString);
    674  1.1.1.2.4.2  rmind     if (ACPI_FAILURE (Status))
    675  1.1.1.2.4.2  rmind     {
    676  1.1.1.2.4.2  rmind         AslCoreSubsystemError (Op, Status, "Externalizing NamePath",
    677  1.1.1.2.4.2  rmind             ASL_NO_ABORT);
    678  1.1.1.2.4.2  rmind         return_VOID;
    679  1.1.1.2.4.2  rmind     }
    680  1.1.1.2.4.2  rmind 
    681  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS,
    682  1.1.1.2.4.2  rmind         "%37s (%2u) ==> %-32s(%2u) %-32s",
    683  1.1.1.2.4.2  rmind         (char *) CurrentPath.Pointer, (UINT32) CurrentPath.Length,
    684  1.1.1.2.4.2  rmind         (char *) TargetPath.Pointer, (UINT32) TargetPath.Length, ExternalNameString));
    685  1.1.1.2.4.2  rmind 
    686  1.1.1.2.4.2  rmind     ACPI_FREE (ExternalNameString);
    687  1.1.1.2.4.2  rmind 
    688  1.1.1.2.4.2  rmind     /*
    689  1.1.1.2.4.2  rmind      * Attempt an optmization depending on the type of namepath
    690  1.1.1.2.4.2  rmind      */
    691  1.1.1.2.4.2  rmind     if (Flags & (AML_NAMED | AML_CREATE))
    692  1.1.1.2.4.2  rmind     {
    693  1.1.1.2.4.2  rmind         /*
    694  1.1.1.2.4.2  rmind          * This is a named opcode and the namepath is a name declaration, not
    695  1.1.1.2.4.2  rmind          * a reference.
    696  1.1.1.2.4.2  rmind          */
    697  1.1.1.2.4.2  rmind         Status = OptOptimizeNameDeclaration (Op, WalkState, CurrentNode,
    698  1.1.1.2.4.2  rmind                     TargetNode, AmlNameString, &NewPath);
    699  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    700  1.1.1.2.4.2  rmind         {
    701  1.1.1.2.4.2  rmind             /*
    702  1.1.1.2.4.2  rmind              * 2) now attempt to
    703  1.1.1.2.4.2  rmind              *    optimize the namestring with carats (up-arrow)
    704  1.1.1.2.4.2  rmind              */
    705  1.1.1.2.4.2  rmind             Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
    706  1.1.1.2.4.2  rmind                             TargetNode, &CurrentPath, &TargetPath,
    707  1.1.1.2.4.2  rmind                             AmlNameStringLength, 1, &NewPath);
    708  1.1.1.2.4.2  rmind         }
    709  1.1.1.2.4.2  rmind     }
    710  1.1.1.2.4.2  rmind     else
    711  1.1.1.2.4.2  rmind     {
    712  1.1.1.2.4.2  rmind         /*
    713  1.1.1.2.4.2  rmind          * This is a reference to an existing named object
    714  1.1.1.2.4.2  rmind          *
    715  1.1.1.2.4.2  rmind          * 1) Check if search-to-root can be utilized using the last
    716  1.1.1.2.4.2  rmind          *    NameSeg of the NamePath
    717  1.1.1.2.4.2  rmind          */
    718  1.1.1.2.4.2  rmind         Status = OptSearchToRoot (Op, WalkState, CurrentNode,
    719  1.1.1.2.4.2  rmind                         TargetNode, &TargetPath, &NewPath);
    720  1.1.1.2.4.2  rmind         if (ACPI_FAILURE (Status))
    721  1.1.1.2.4.2  rmind         {
    722  1.1.1.2.4.2  rmind             /*
    723  1.1.1.2.4.2  rmind              * 2) Search-to-root could not be used, now attempt to
    724  1.1.1.2.4.2  rmind              *    optimize the namestring with carats (up-arrow)
    725  1.1.1.2.4.2  rmind              */
    726  1.1.1.2.4.2  rmind             Status = OptBuildShortestPath (Op, WalkState, CurrentNode,
    727  1.1.1.2.4.2  rmind                             TargetNode, &CurrentPath, &TargetPath,
    728  1.1.1.2.4.2  rmind                             AmlNameStringLength, 0, &NewPath);
    729  1.1.1.2.4.2  rmind         }
    730  1.1.1.2.4.2  rmind     }
    731  1.1.1.2.4.2  rmind 
    732  1.1.1.2.4.2  rmind     /*
    733  1.1.1.2.4.2  rmind      * Success from above indicates that the NamePath was successfully
    734  1.1.1.2.4.2  rmind      * optimized.  We need to update the parse op with the new name
    735  1.1.1.2.4.2  rmind      */
    736  1.1.1.2.4.2  rmind     if (ACPI_SUCCESS (Status))
    737  1.1.1.2.4.2  rmind     {
    738  1.1.1.2.4.2  rmind         HowMuchShorter = (AmlNameStringLength - ACPI_STRLEN (NewPath));
    739  1.1.1.2.4.2  rmind         OptTotal += HowMuchShorter;
    740  1.1.1.2.4.2  rmind 
    741  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " REDUCED %2u (%u)",
    742  1.1.1.2.4.2  rmind             (UINT32) HowMuchShorter, OptTotal));
    743  1.1.1.2.4.2  rmind 
    744  1.1.1.2.4.2  rmind         if (Flags & AML_NAMED)
    745  1.1.1.2.4.2  rmind         {
    746  1.1.1.2.4.2  rmind             if (Op->Asl.AmlOpcode == AML_ALIAS_OP)
    747  1.1.1.2.4.2  rmind             {
    748  1.1.1.2.4.2  rmind                 /*
    749  1.1.1.2.4.2  rmind                  * ALIAS is the only oddball opcode, the name declaration
    750  1.1.1.2.4.2  rmind                  * (alias name) is the second operand
    751  1.1.1.2.4.2  rmind                  */
    752  1.1.1.2.4.2  rmind                 Op->Asl.Child->Asl.Next->Asl.Value.String = NewPath;
    753  1.1.1.2.4.2  rmind                 Op->Asl.Child->Asl.Next->Asl.AmlLength = ACPI_STRLEN (NewPath);
    754  1.1.1.2.4.2  rmind             }
    755  1.1.1.2.4.2  rmind             else
    756  1.1.1.2.4.2  rmind             {
    757  1.1.1.2.4.2  rmind                 Op->Asl.Child->Asl.Value.String = NewPath;
    758  1.1.1.2.4.2  rmind                 Op->Asl.Child->Asl.AmlLength = ACPI_STRLEN (NewPath);
    759  1.1.1.2.4.2  rmind             }
    760  1.1.1.2.4.2  rmind         }
    761  1.1.1.2.4.2  rmind         else if (Flags & AML_CREATE)
    762  1.1.1.2.4.2  rmind         {
    763  1.1.1.2.4.2  rmind             /* Name must appear as the last parameter */
    764  1.1.1.2.4.2  rmind 
    765  1.1.1.2.4.2  rmind             NextOp = Op->Asl.Child;
    766  1.1.1.2.4.2  rmind             while (!(NextOp->Asl.CompileFlags & NODE_IS_NAME_DECLARATION))
    767  1.1.1.2.4.2  rmind             {
    768  1.1.1.2.4.2  rmind                 NextOp = NextOp->Asl.Next;
    769  1.1.1.2.4.2  rmind             }
    770  1.1.1.2.4.2  rmind             /* Update the parse node with the new NamePath */
    771  1.1.1.2.4.2  rmind 
    772  1.1.1.2.4.2  rmind             NextOp->Asl.Value.String = NewPath;
    773  1.1.1.2.4.2  rmind             NextOp->Asl.AmlLength = ACPI_STRLEN (NewPath);
    774  1.1.1.2.4.2  rmind         }
    775  1.1.1.2.4.2  rmind         else
    776  1.1.1.2.4.2  rmind         {
    777  1.1.1.2.4.2  rmind             /* Update the parse node with the new NamePath */
    778  1.1.1.2.4.2  rmind 
    779  1.1.1.2.4.2  rmind             Op->Asl.Value.String = NewPath;
    780  1.1.1.2.4.2  rmind             Op->Asl.AmlLength = ACPI_STRLEN (NewPath);
    781  1.1.1.2.4.2  rmind         }
    782  1.1.1.2.4.2  rmind     }
    783  1.1.1.2.4.2  rmind     else
    784  1.1.1.2.4.2  rmind     {
    785  1.1.1.2.4.2  rmind         ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, " ALREADY OPTIMAL"));
    786  1.1.1.2.4.2  rmind     }
    787  1.1.1.2.4.2  rmind 
    788  1.1.1.2.4.2  rmind     /* Cleanup path buffers */
    789  1.1.1.2.4.2  rmind 
    790  1.1.1.2.4.2  rmind     ACPI_FREE (TargetPath.Pointer);
    791  1.1.1.2.4.2  rmind     ACPI_FREE (CurrentPath.Pointer);
    792  1.1.1.2.4.2  rmind 
    793  1.1.1.2.4.2  rmind     ACPI_DEBUG_PRINT_RAW ((ACPI_DB_OPTIMIZATIONS, "\n"));
    794  1.1.1.2.4.2  rmind     return_VOID;
    795  1.1.1.2.4.2  rmind }
    796  1.1.1.2.4.2  rmind 
    797