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