Home | History | Annotate | Line # | Download | only in namespace
nsnames.c revision 1.1.1.10
      1       1.1    jruoho /*******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: nsnames - Name manipulation and search
      4       1.1    jruoho  *
      5       1.1    jruoho  ******************************************************************************/
      6       1.1    jruoho 
      7   1.1.1.2    jruoho /*
      8   1.1.1.8  christos  * Copyright (C) 2000 - 2017, 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 "acpi.h"
     45       1.1    jruoho #include "accommon.h"
     46       1.1    jruoho #include "amlcode.h"
     47       1.1    jruoho #include "acnamesp.h"
     48       1.1    jruoho 
     49       1.1    jruoho 
     50       1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
     51       1.1    jruoho         ACPI_MODULE_NAME    ("nsnames")
     52       1.1    jruoho 
     53  1.1.1.10  christos /* Local Prototypes */
     54  1.1.1.10  christos 
     55  1.1.1.10  christos static void
     56  1.1.1.10  christos AcpiNsNormalizePathname (
     57  1.1.1.10  christos     char                    *OriginalPath);
     58  1.1.1.10  christos 
     59       1.1    jruoho 
     60       1.1    jruoho /*******************************************************************************
     61       1.1    jruoho  *
     62       1.1    jruoho  * FUNCTION:    AcpiNsGetExternalPathname
     63       1.1    jruoho  *
     64       1.1    jruoho  * PARAMETERS:  Node            - Namespace node whose pathname is needed
     65       1.1    jruoho  *
     66       1.1    jruoho  * RETURN:      Pointer to storage containing the fully qualified name of
     67       1.1    jruoho  *              the node, In external format (name segments separated by path
     68       1.1    jruoho  *              separators.)
     69       1.1    jruoho  *
     70       1.1    jruoho  * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
     71       1.1    jruoho  *              for error and debug statements.
     72       1.1    jruoho  *
     73       1.1    jruoho  ******************************************************************************/
     74       1.1    jruoho 
     75       1.1    jruoho char *
     76       1.1    jruoho AcpiNsGetExternalPathname (
     77       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
     78       1.1    jruoho {
     79       1.1    jruoho     char                    *NameBuffer;
     80       1.1    jruoho 
     81       1.1    jruoho 
     82       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
     83       1.1    jruoho 
     84       1.1    jruoho 
     85   1.1.1.6  christos     NameBuffer = AcpiNsGetNormalizedPathname (Node, FALSE);
     86       1.1    jruoho     return_PTR (NameBuffer);
     87       1.1    jruoho }
     88       1.1    jruoho 
     89       1.1    jruoho 
     90       1.1    jruoho /*******************************************************************************
     91       1.1    jruoho  *
     92       1.1    jruoho  * FUNCTION:    AcpiNsGetPathnameLength
     93       1.1    jruoho  *
     94       1.1    jruoho  * PARAMETERS:  Node        - Namespace node
     95       1.1    jruoho  *
     96       1.1    jruoho  * RETURN:      Length of path, including prefix
     97       1.1    jruoho  *
     98       1.1    jruoho  * DESCRIPTION: Get the length of the pathname string for this node
     99       1.1    jruoho  *
    100       1.1    jruoho  ******************************************************************************/
    101       1.1    jruoho 
    102       1.1    jruoho ACPI_SIZE
    103       1.1    jruoho AcpiNsGetPathnameLength (
    104       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
    105       1.1    jruoho {
    106       1.1    jruoho     ACPI_SIZE               Size;
    107       1.1    jruoho 
    108       1.1    jruoho 
    109   1.1.1.9  christos     /* Validate the Node */
    110       1.1    jruoho 
    111   1.1.1.9  christos     if (ACPI_GET_DESCRIPTOR_TYPE (Node) != ACPI_DESC_TYPE_NAMED)
    112   1.1.1.9  christos     {
    113   1.1.1.9  christos         ACPI_ERROR ((AE_INFO,
    114   1.1.1.9  christos             "Invalid/cached reference target node: %p, descriptor type %d",
    115   1.1.1.9  christos             Node, ACPI_GET_DESCRIPTOR_TYPE (Node)));
    116   1.1.1.9  christos         return (0);
    117   1.1.1.9  christos     }
    118       1.1    jruoho 
    119   1.1.1.6  christos     Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, FALSE);
    120   1.1.1.6  christos     return (Size);
    121       1.1    jruoho }
    122       1.1    jruoho 
    123       1.1    jruoho 
    124       1.1    jruoho /*******************************************************************************
    125       1.1    jruoho  *
    126   1.1.1.8  christos  * FUNCTION:    AcpiNsHandleToName
    127   1.1.1.8  christos  *
    128   1.1.1.8  christos  * PARAMETERS:  TargetHandle            - Handle of named object whose name is
    129   1.1.1.8  christos  *                                        to be found
    130   1.1.1.8  christos  *              Buffer                  - Where the name is returned
    131   1.1.1.8  christos  *
    132   1.1.1.8  christos  * RETURN:      Status, Buffer is filled with name if status is AE_OK
    133   1.1.1.8  christos  *
    134   1.1.1.8  christos  * DESCRIPTION: Build and return a full namespace name
    135   1.1.1.8  christos  *
    136   1.1.1.8  christos  ******************************************************************************/
    137   1.1.1.8  christos 
    138   1.1.1.8  christos ACPI_STATUS
    139   1.1.1.8  christos AcpiNsHandleToName (
    140   1.1.1.8  christos     ACPI_HANDLE             TargetHandle,
    141   1.1.1.8  christos     ACPI_BUFFER             *Buffer)
    142   1.1.1.8  christos {
    143   1.1.1.8  christos     ACPI_STATUS             Status;
    144   1.1.1.8  christos     ACPI_NAMESPACE_NODE     *Node;
    145   1.1.1.8  christos     const char              *NodeName;
    146   1.1.1.8  christos 
    147   1.1.1.8  christos 
    148   1.1.1.8  christos     ACPI_FUNCTION_TRACE_PTR (NsHandleToName, TargetHandle);
    149   1.1.1.8  christos 
    150   1.1.1.8  christos 
    151   1.1.1.8  christos     Node = AcpiNsValidateHandle (TargetHandle);
    152   1.1.1.8  christos     if (!Node)
    153   1.1.1.8  christos     {
    154   1.1.1.8  christos         return_ACPI_STATUS (AE_BAD_PARAMETER);
    155   1.1.1.8  christos     }
    156   1.1.1.8  christos 
    157   1.1.1.8  christos     /* Validate/Allocate/Clear caller buffer */
    158   1.1.1.8  christos 
    159   1.1.1.8  christos     Status = AcpiUtInitializeBuffer (Buffer, ACPI_PATH_SEGMENT_LENGTH);
    160   1.1.1.8  christos     if (ACPI_FAILURE (Status))
    161   1.1.1.8  christos     {
    162   1.1.1.8  christos         return_ACPI_STATUS (Status);
    163   1.1.1.8  christos     }
    164   1.1.1.8  christos 
    165   1.1.1.8  christos     /* Just copy the ACPI name from the Node and zero terminate it */
    166   1.1.1.8  christos 
    167   1.1.1.8  christos     NodeName = AcpiUtGetNodeName (Node);
    168   1.1.1.8  christos     ACPI_MOVE_NAME (Buffer->Pointer, NodeName);
    169   1.1.1.8  christos     ((char *) Buffer->Pointer) [ACPI_NAME_SIZE] = 0;
    170   1.1.1.8  christos 
    171   1.1.1.8  christos     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%4.4s\n", (char *) Buffer->Pointer));
    172   1.1.1.8  christos     return_ACPI_STATUS (AE_OK);
    173   1.1.1.8  christos }
    174   1.1.1.8  christos 
    175   1.1.1.8  christos 
    176   1.1.1.8  christos /*******************************************************************************
    177   1.1.1.8  christos  *
    178       1.1    jruoho  * FUNCTION:    AcpiNsHandleToPathname
    179       1.1    jruoho  *
    180       1.1    jruoho  * PARAMETERS:  TargetHandle            - Handle of named object whose name is
    181       1.1    jruoho  *                                        to be found
    182       1.1    jruoho  *              Buffer                  - Where the pathname is returned
    183   1.1.1.6  christos  *              NoTrailing              - Remove trailing '_' for each name
    184   1.1.1.6  christos  *                                        segment
    185       1.1    jruoho  *
    186       1.1    jruoho  * RETURN:      Status, Buffer is filled with pathname if status is AE_OK
    187       1.1    jruoho  *
    188       1.1    jruoho  * DESCRIPTION: Build and return a full namespace pathname
    189       1.1    jruoho  *
    190       1.1    jruoho  ******************************************************************************/
    191       1.1    jruoho 
    192       1.1    jruoho ACPI_STATUS
    193       1.1    jruoho AcpiNsHandleToPathname (
    194       1.1    jruoho     ACPI_HANDLE             TargetHandle,
    195   1.1.1.6  christos     ACPI_BUFFER             *Buffer,
    196   1.1.1.6  christos     BOOLEAN                 NoTrailing)
    197       1.1    jruoho {
    198       1.1    jruoho     ACPI_STATUS             Status;
    199       1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    200       1.1    jruoho     ACPI_SIZE               RequiredSize;
    201       1.1    jruoho 
    202       1.1    jruoho 
    203       1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
    204       1.1    jruoho 
    205       1.1    jruoho 
    206       1.1    jruoho     Node = AcpiNsValidateHandle (TargetHandle);
    207       1.1    jruoho     if (!Node)
    208       1.1    jruoho     {
    209       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    210       1.1    jruoho     }
    211       1.1    jruoho 
    212       1.1    jruoho     /* Determine size required for the caller buffer */
    213       1.1    jruoho 
    214   1.1.1.6  christos     RequiredSize = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
    215       1.1    jruoho     if (!RequiredSize)
    216       1.1    jruoho     {
    217       1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    218       1.1    jruoho     }
    219       1.1    jruoho 
    220       1.1    jruoho     /* Validate/Allocate/Clear caller buffer */
    221       1.1    jruoho 
    222       1.1    jruoho     Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
    223       1.1    jruoho     if (ACPI_FAILURE (Status))
    224       1.1    jruoho     {
    225       1.1    jruoho         return_ACPI_STATUS (Status);
    226       1.1    jruoho     }
    227       1.1    jruoho 
    228       1.1    jruoho     /* Build the path in the caller buffer */
    229       1.1    jruoho 
    230   1.1.1.6  christos     (void) AcpiNsBuildNormalizedPath (Node, Buffer->Pointer,
    231   1.1.1.7  christos         RequiredSize, NoTrailing);
    232       1.1    jruoho 
    233       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
    234       1.1    jruoho         (char *) Buffer->Pointer, (UINT32) RequiredSize));
    235       1.1    jruoho     return_ACPI_STATUS (AE_OK);
    236       1.1    jruoho }
    237   1.1.1.6  christos 
    238   1.1.1.6  christos 
    239   1.1.1.6  christos /*******************************************************************************
    240   1.1.1.6  christos  *
    241   1.1.1.6  christos  * FUNCTION:    AcpiNsBuildNormalizedPath
    242   1.1.1.6  christos  *
    243   1.1.1.6  christos  * PARAMETERS:  Node        - Namespace node
    244   1.1.1.6  christos  *              FullPath    - Where the path name is returned
    245   1.1.1.6  christos  *              PathSize    - Size of returned path name buffer
    246   1.1.1.6  christos  *              NoTrailing  - Remove trailing '_' from each name segment
    247   1.1.1.6  christos  *
    248   1.1.1.6  christos  * RETURN:      Return 1 if the AML path is empty, otherwise returning (length
    249   1.1.1.6  christos  *              of pathname + 1) which means the 'FullPath' contains a trailing
    250   1.1.1.6  christos  *              null.
    251   1.1.1.6  christos  *
    252   1.1.1.6  christos  * DESCRIPTION: Build and return a full namespace pathname.
    253   1.1.1.6  christos  *              Note that if the size of 'FullPath' isn't large enough to
    254   1.1.1.6  christos  *              contain the namespace node's path name, the actual required
    255   1.1.1.6  christos  *              buffer length is returned, and it should be greater than
    256   1.1.1.6  christos  *              'PathSize'. So callers are able to check the returning value
    257   1.1.1.6  christos  *              to determine the buffer size of 'FullPath'.
    258   1.1.1.6  christos  *
    259   1.1.1.6  christos  ******************************************************************************/
    260   1.1.1.6  christos 
    261   1.1.1.6  christos UINT32
    262   1.1.1.6  christos AcpiNsBuildNormalizedPath (
    263   1.1.1.6  christos     ACPI_NAMESPACE_NODE     *Node,
    264   1.1.1.6  christos     char                    *FullPath,
    265   1.1.1.6  christos     UINT32                  PathSize,
    266   1.1.1.6  christos     BOOLEAN                 NoTrailing)
    267   1.1.1.6  christos {
    268   1.1.1.6  christos     UINT32                  Length = 0, i;
    269   1.1.1.6  christos     char                    Name[ACPI_NAME_SIZE];
    270   1.1.1.6  christos     BOOLEAN                 DoNoTrailing;
    271   1.1.1.6  christos     char                    c, *Left, *Right;
    272   1.1.1.6  christos     ACPI_NAMESPACE_NODE     *NextNode;
    273   1.1.1.6  christos 
    274   1.1.1.6  christos 
    275   1.1.1.6  christos     ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath, Node);
    276   1.1.1.6  christos 
    277   1.1.1.6  christos 
    278   1.1.1.6  christos #define ACPI_PATH_PUT8(Path, Size, Byte, Length)    \
    279   1.1.1.6  christos     do {                                            \
    280   1.1.1.6  christos         if ((Length) < (Size))                      \
    281   1.1.1.6  christos         {                                           \
    282   1.1.1.6  christos             (Path)[(Length)] = (Byte);              \
    283   1.1.1.6  christos         }                                           \
    284   1.1.1.6  christos         (Length)++;                                 \
    285   1.1.1.6  christos     } while (0)
    286   1.1.1.6  christos 
    287   1.1.1.6  christos     /*
    288   1.1.1.6  christos      * Make sure the PathSize is correct, so that we don't need to
    289   1.1.1.6  christos      * validate both FullPath and PathSize.
    290   1.1.1.6  christos      */
    291   1.1.1.6  christos     if (!FullPath)
    292   1.1.1.6  christos     {
    293   1.1.1.6  christos         PathSize = 0;
    294   1.1.1.6  christos     }
    295   1.1.1.6  christos 
    296   1.1.1.6  christos     if (!Node)
    297   1.1.1.6  christos     {
    298   1.1.1.6  christos         goto BuildTrailingNull;
    299   1.1.1.6  christos     }
    300   1.1.1.6  christos 
    301   1.1.1.6  christos     NextNode = Node;
    302   1.1.1.6  christos     while (NextNode && NextNode != AcpiGbl_RootNode)
    303   1.1.1.6  christos     {
    304   1.1.1.6  christos         if (NextNode != Node)
    305   1.1.1.6  christos         {
    306   1.1.1.6  christos             ACPI_PATH_PUT8(FullPath, PathSize, AML_DUAL_NAME_PREFIX, Length);
    307   1.1.1.6  christos         }
    308   1.1.1.7  christos 
    309   1.1.1.6  christos         ACPI_MOVE_32_TO_32 (Name, &NextNode->Name);
    310   1.1.1.6  christos         DoNoTrailing = NoTrailing;
    311   1.1.1.6  christos         for (i = 0; i < 4; i++)
    312   1.1.1.6  christos         {
    313   1.1.1.6  christos             c = Name[4-i-1];
    314   1.1.1.6  christos             if (DoNoTrailing && c != '_')
    315   1.1.1.6  christos             {
    316   1.1.1.6  christos                 DoNoTrailing = FALSE;
    317   1.1.1.6  christos             }
    318   1.1.1.6  christos             if (!DoNoTrailing)
    319   1.1.1.6  christos             {
    320   1.1.1.6  christos                 ACPI_PATH_PUT8(FullPath, PathSize, c, Length);
    321   1.1.1.6  christos             }
    322   1.1.1.6  christos         }
    323   1.1.1.7  christos 
    324   1.1.1.6  christos         NextNode = NextNode->Parent;
    325   1.1.1.6  christos     }
    326   1.1.1.7  christos 
    327   1.1.1.6  christos     ACPI_PATH_PUT8(FullPath, PathSize, AML_ROOT_PREFIX, Length);
    328   1.1.1.6  christos 
    329   1.1.1.6  christos     /* Reverse the path string */
    330   1.1.1.6  christos 
    331   1.1.1.6  christos     if (Length <= PathSize)
    332   1.1.1.6  christos     {
    333   1.1.1.6  christos         Left = FullPath;
    334   1.1.1.7  christos         Right = FullPath+Length - 1;
    335   1.1.1.7  christos 
    336   1.1.1.6  christos         while (Left < Right)
    337   1.1.1.6  christos         {
    338   1.1.1.6  christos             c = *Left;
    339   1.1.1.6  christos             *Left++ = *Right;
    340   1.1.1.6  christos             *Right-- = c;
    341   1.1.1.6  christos         }
    342   1.1.1.6  christos     }
    343   1.1.1.6  christos 
    344   1.1.1.6  christos     /* Append the trailing null */
    345   1.1.1.6  christos 
    346   1.1.1.6  christos BuildTrailingNull:
    347   1.1.1.7  christos     ACPI_PATH_PUT8 (FullPath, PathSize, '\0', Length);
    348   1.1.1.6  christos 
    349   1.1.1.6  christos #undef ACPI_PATH_PUT8
    350   1.1.1.6  christos 
    351   1.1.1.6  christos     return_UINT32 (Length);
    352   1.1.1.6  christos }
    353   1.1.1.6  christos 
    354   1.1.1.6  christos 
    355   1.1.1.6  christos /*******************************************************************************
    356   1.1.1.6  christos  *
    357   1.1.1.6  christos  * FUNCTION:    AcpiNsGetNormalizedPathname
    358   1.1.1.6  christos  *
    359   1.1.1.6  christos  * PARAMETERS:  Node            - Namespace node whose pathname is needed
    360   1.1.1.6  christos  *              NoTrailing      - Remove trailing '_' from each name segment
    361   1.1.1.6  christos  *
    362   1.1.1.6  christos  * RETURN:      Pointer to storage containing the fully qualified name of
    363   1.1.1.6  christos  *              the node, In external format (name segments separated by path
    364   1.1.1.6  christos  *              separators.)
    365   1.1.1.6  christos  *
    366   1.1.1.6  christos  * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
    367   1.1.1.6  christos  *              for error and debug statements. All trailing '_' will be
    368   1.1.1.6  christos  *              removed from the full pathname if 'NoTrailing' is specified..
    369   1.1.1.6  christos  *
    370   1.1.1.6  christos  ******************************************************************************/
    371   1.1.1.6  christos 
    372   1.1.1.6  christos char *
    373   1.1.1.6  christos AcpiNsGetNormalizedPathname (
    374   1.1.1.6  christos     ACPI_NAMESPACE_NODE     *Node,
    375   1.1.1.6  christos     BOOLEAN                 NoTrailing)
    376   1.1.1.6  christos {
    377   1.1.1.6  christos     char                    *NameBuffer;
    378   1.1.1.6  christos     ACPI_SIZE               Size;
    379   1.1.1.6  christos 
    380   1.1.1.6  christos 
    381   1.1.1.6  christos     ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname, Node);
    382   1.1.1.6  christos 
    383   1.1.1.6  christos 
    384   1.1.1.6  christos     /* Calculate required buffer size based on depth below root */
    385   1.1.1.6  christos 
    386   1.1.1.6  christos     Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
    387   1.1.1.6  christos     if (!Size)
    388   1.1.1.6  christos     {
    389   1.1.1.6  christos         return_PTR (NULL);
    390   1.1.1.6  christos     }
    391   1.1.1.6  christos 
    392   1.1.1.6  christos     /* Allocate a buffer to be returned to caller */
    393   1.1.1.6  christos 
    394   1.1.1.6  christos     NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
    395   1.1.1.6  christos     if (!NameBuffer)
    396   1.1.1.6  christos     {
    397   1.1.1.7  christos         ACPI_ERROR ((AE_INFO,
    398   1.1.1.7  christos             "Could not allocate %u bytes", (UINT32) Size));
    399   1.1.1.6  christos         return_PTR (NULL);
    400   1.1.1.6  christos     }
    401   1.1.1.6  christos 
    402   1.1.1.6  christos     /* Build the path in the allocated buffer */
    403   1.1.1.6  christos 
    404   1.1.1.6  christos     (void) AcpiNsBuildNormalizedPath (Node, NameBuffer, Size, NoTrailing);
    405   1.1.1.6  christos 
    406   1.1.1.6  christos     return_PTR (NameBuffer);
    407   1.1.1.6  christos }
    408  1.1.1.10  christos 
    409  1.1.1.10  christos 
    410  1.1.1.10  christos /*******************************************************************************
    411  1.1.1.10  christos  *
    412  1.1.1.10  christos  * FUNCTION:    AcpiNsBuildPrefixedPathname
    413  1.1.1.10  christos  *
    414  1.1.1.10  christos  * PARAMETERS:  PrefixScope         - Scope/Path that prefixes the internal path
    415  1.1.1.10  christos  *              InternalPath        - Name or path of the namespace node
    416  1.1.1.10  christos  *
    417  1.1.1.10  christos  * RETURN:      None
    418  1.1.1.10  christos  *
    419  1.1.1.10  christos  * DESCRIPTION: Construct a fully qualified pathname from a concatenation of:
    420  1.1.1.10  christos  *              1) Path associated with the PrefixScope namespace node
    421  1.1.1.10  christos  *              2) External path representation of the Internal path
    422  1.1.1.10  christos  *
    423  1.1.1.10  christos  ******************************************************************************/
    424  1.1.1.10  christos 
    425  1.1.1.10  christos char *
    426  1.1.1.10  christos AcpiNsBuildPrefixedPathname (
    427  1.1.1.10  christos     ACPI_GENERIC_STATE      *PrefixScope,
    428  1.1.1.10  christos     const char              *InternalPath)
    429  1.1.1.10  christos {
    430  1.1.1.10  christos     ACPI_STATUS             Status;
    431  1.1.1.10  christos     char                    *FullPath = NULL;
    432  1.1.1.10  christos     char                    *ExternalPath = NULL;
    433  1.1.1.10  christos     char                    *PrefixPath = NULL;
    434  1.1.1.10  christos     UINT32                  PrefixPathLength = 0;
    435  1.1.1.10  christos 
    436  1.1.1.10  christos 
    437  1.1.1.10  christos     /* If there is a prefix, get the pathname to it */
    438  1.1.1.10  christos 
    439  1.1.1.10  christos     if (PrefixScope && PrefixScope->Scope.Node)
    440  1.1.1.10  christos     {
    441  1.1.1.10  christos         PrefixPath = AcpiNsGetNormalizedPathname (PrefixScope->Scope.Node, TRUE);
    442  1.1.1.10  christos         if (PrefixPath)
    443  1.1.1.10  christos         {
    444  1.1.1.10  christos             PrefixPathLength = strlen (PrefixPath);
    445  1.1.1.10  christos         }
    446  1.1.1.10  christos     }
    447  1.1.1.10  christos 
    448  1.1.1.10  christos     Status = AcpiNsExternalizeName (ACPI_UINT32_MAX, InternalPath,
    449  1.1.1.10  christos         NULL, &ExternalPath);
    450  1.1.1.10  christos     if (ACPI_FAILURE (Status))
    451  1.1.1.10  christos     {
    452  1.1.1.10  christos         goto Cleanup;
    453  1.1.1.10  christos     }
    454  1.1.1.10  christos 
    455  1.1.1.10  christos     /* Merge the prefix path and the path. 2 is for one dot and trailing null */
    456  1.1.1.10  christos 
    457  1.1.1.10  christos     FullPath = ACPI_ALLOCATE_ZEROED (
    458  1.1.1.10  christos         PrefixPathLength + strlen (ExternalPath) + 2);
    459  1.1.1.10  christos     if (!FullPath)
    460  1.1.1.10  christos     {
    461  1.1.1.10  christos         goto Cleanup;
    462  1.1.1.10  christos     }
    463  1.1.1.10  christos 
    464  1.1.1.10  christos     /* Don't merge if the External path is already fully qualified */
    465  1.1.1.10  christos 
    466  1.1.1.10  christos     if (PrefixPath &&
    467  1.1.1.10  christos         (*ExternalPath != '\\') &&
    468  1.1.1.10  christos         (*ExternalPath != '^'))
    469  1.1.1.10  christos     {
    470  1.1.1.10  christos         strcat (FullPath, PrefixPath);
    471  1.1.1.10  christos         if (PrefixPath[1])
    472  1.1.1.10  christos         {
    473  1.1.1.10  christos             strcat (FullPath, ".");
    474  1.1.1.10  christos         }
    475  1.1.1.10  christos     }
    476  1.1.1.10  christos 
    477  1.1.1.10  christos     AcpiNsNormalizePathname (ExternalPath);
    478  1.1.1.10  christos     strcat (FullPath, ExternalPath);
    479  1.1.1.10  christos 
    480  1.1.1.10  christos Cleanup:
    481  1.1.1.10  christos     if (PrefixPath)
    482  1.1.1.10  christos     {
    483  1.1.1.10  christos         ACPI_FREE (PrefixPath);
    484  1.1.1.10  christos     }
    485  1.1.1.10  christos     if (ExternalPath)
    486  1.1.1.10  christos     {
    487  1.1.1.10  christos         ACPI_FREE (ExternalPath);
    488  1.1.1.10  christos     }
    489  1.1.1.10  christos 
    490  1.1.1.10  christos     return (FullPath);
    491  1.1.1.10  christos }
    492  1.1.1.10  christos 
    493  1.1.1.10  christos 
    494  1.1.1.10  christos /*******************************************************************************
    495  1.1.1.10  christos  *
    496  1.1.1.10  christos  * FUNCTION:    AcpiNsNormalizePathname
    497  1.1.1.10  christos  *
    498  1.1.1.10  christos  * PARAMETERS:  OriginalPath        - Path to be normalized, in External format
    499  1.1.1.10  christos  *
    500  1.1.1.10  christos  * RETURN:      The original path is processed in-place
    501  1.1.1.10  christos  *
    502  1.1.1.10  christos  * DESCRIPTION: Remove trailing underscores from each element of a path.
    503  1.1.1.10  christos  *
    504  1.1.1.10  christos  *              For example:  \A___.B___.C___ becomes \A.B.C
    505  1.1.1.10  christos  *
    506  1.1.1.10  christos  ******************************************************************************/
    507  1.1.1.10  christos 
    508  1.1.1.10  christos static void
    509  1.1.1.10  christos AcpiNsNormalizePathname (
    510  1.1.1.10  christos     char                    *OriginalPath)
    511  1.1.1.10  christos {
    512  1.1.1.10  christos     char                    *InputPath = OriginalPath;
    513  1.1.1.10  christos     char                    *NewPathBuffer;
    514  1.1.1.10  christos     char                    *NewPath;
    515  1.1.1.10  christos     UINT32                  i;
    516  1.1.1.10  christos 
    517  1.1.1.10  christos 
    518  1.1.1.10  christos     /* Allocate a temp buffer in which to construct the new path */
    519  1.1.1.10  christos 
    520  1.1.1.10  christos     NewPathBuffer = ACPI_ALLOCATE_ZEROED (strlen (InputPath) + 1);
    521  1.1.1.10  christos     NewPath = NewPathBuffer;
    522  1.1.1.10  christos     if (!NewPathBuffer)
    523  1.1.1.10  christos     {
    524  1.1.1.10  christos         return;
    525  1.1.1.10  christos     }
    526  1.1.1.10  christos 
    527  1.1.1.10  christos     /* Special characters may appear at the beginning of the path */
    528  1.1.1.10  christos 
    529  1.1.1.10  christos     if (*InputPath == '\\')
    530  1.1.1.10  christos     {
    531  1.1.1.10  christos         *NewPath = *InputPath;
    532  1.1.1.10  christos         NewPath++;
    533  1.1.1.10  christos         InputPath++;
    534  1.1.1.10  christos     }
    535  1.1.1.10  christos 
    536  1.1.1.10  christos     while (*InputPath == '^')
    537  1.1.1.10  christos     {
    538  1.1.1.10  christos         *NewPath = *InputPath;
    539  1.1.1.10  christos         NewPath++;
    540  1.1.1.10  christos         InputPath++;
    541  1.1.1.10  christos     }
    542  1.1.1.10  christos 
    543  1.1.1.10  christos     /* Remainder of the path */
    544  1.1.1.10  christos 
    545  1.1.1.10  christos     while (*InputPath)
    546  1.1.1.10  christos     {
    547  1.1.1.10  christos         /* Do one nameseg at a time */
    548  1.1.1.10  christos 
    549  1.1.1.10  christos         for (i = 0; (i < ACPI_NAME_SIZE) && *InputPath; i++)
    550  1.1.1.10  christos         {
    551  1.1.1.10  christos             if ((i == 0) || (*InputPath != '_')) /* First char is allowed to be underscore */
    552  1.1.1.10  christos             {
    553  1.1.1.10  christos                 *NewPath = *InputPath;
    554  1.1.1.10  christos                 NewPath++;
    555  1.1.1.10  christos             }
    556  1.1.1.10  christos 
    557  1.1.1.10  christos             InputPath++;
    558  1.1.1.10  christos         }
    559  1.1.1.10  christos 
    560  1.1.1.10  christos         /* Dot means that there are more namesegs to come */
    561  1.1.1.10  christos 
    562  1.1.1.10  christos         if (*InputPath == '.')
    563  1.1.1.10  christos         {
    564  1.1.1.10  christos             *NewPath = *InputPath;
    565  1.1.1.10  christos             NewPath++;
    566  1.1.1.10  christos             InputPath++;
    567  1.1.1.10  christos         }
    568  1.1.1.10  christos     }
    569  1.1.1.10  christos 
    570  1.1.1.10  christos     *NewPath = 0;
    571  1.1.1.10  christos     strcpy (OriginalPath, NewPathBuffer);
    572  1.1.1.10  christos     ACPI_FREE (NewPathBuffer);
    573  1.1.1.10  christos }
    574