Home | History | Annotate | Line # | Download | only in namespace
nsnames.c revision 1.1.1.6
      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.5  christos  * Copyright (C) 2000 - 2015, 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    jruoho 
     54      1.1    jruoho /*******************************************************************************
     55      1.1    jruoho  *
     56      1.1    jruoho  * FUNCTION:    AcpiNsGetExternalPathname
     57      1.1    jruoho  *
     58      1.1    jruoho  * PARAMETERS:  Node            - Namespace node whose pathname is needed
     59      1.1    jruoho  *
     60      1.1    jruoho  * RETURN:      Pointer to storage containing the fully qualified name of
     61      1.1    jruoho  *              the node, In external format (name segments separated by path
     62      1.1    jruoho  *              separators.)
     63      1.1    jruoho  *
     64      1.1    jruoho  * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
     65      1.1    jruoho  *              for error and debug statements.
     66      1.1    jruoho  *
     67      1.1    jruoho  ******************************************************************************/
     68      1.1    jruoho 
     69      1.1    jruoho char *
     70      1.1    jruoho AcpiNsGetExternalPathname (
     71      1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
     72      1.1    jruoho {
     73      1.1    jruoho     char                    *NameBuffer;
     74      1.1    jruoho 
     75      1.1    jruoho 
     76      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (NsGetExternalPathname, Node);
     77      1.1    jruoho 
     78      1.1    jruoho 
     79  1.1.1.6  christos     NameBuffer = AcpiNsGetNormalizedPathname (Node, FALSE);
     80      1.1    jruoho 
     81      1.1    jruoho     return_PTR (NameBuffer);
     82      1.1    jruoho }
     83      1.1    jruoho 
     84      1.1    jruoho 
     85      1.1    jruoho /*******************************************************************************
     86      1.1    jruoho  *
     87      1.1    jruoho  * FUNCTION:    AcpiNsGetPathnameLength
     88      1.1    jruoho  *
     89      1.1    jruoho  * PARAMETERS:  Node        - Namespace node
     90      1.1    jruoho  *
     91      1.1    jruoho  * RETURN:      Length of path, including prefix
     92      1.1    jruoho  *
     93      1.1    jruoho  * DESCRIPTION: Get the length of the pathname string for this node
     94      1.1    jruoho  *
     95      1.1    jruoho  ******************************************************************************/
     96      1.1    jruoho 
     97      1.1    jruoho ACPI_SIZE
     98      1.1    jruoho AcpiNsGetPathnameLength (
     99      1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
    100      1.1    jruoho {
    101      1.1    jruoho     ACPI_SIZE               Size;
    102      1.1    jruoho 
    103      1.1    jruoho 
    104      1.1    jruoho     ACPI_FUNCTION_ENTRY ();
    105      1.1    jruoho 
    106      1.1    jruoho 
    107  1.1.1.6  christos     Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, FALSE);
    108      1.1    jruoho 
    109  1.1.1.6  christos     return (Size);
    110      1.1    jruoho }
    111      1.1    jruoho 
    112      1.1    jruoho 
    113      1.1    jruoho /*******************************************************************************
    114      1.1    jruoho  *
    115      1.1    jruoho  * FUNCTION:    AcpiNsHandleToPathname
    116      1.1    jruoho  *
    117      1.1    jruoho  * PARAMETERS:  TargetHandle            - Handle of named object whose name is
    118      1.1    jruoho  *                                        to be found
    119      1.1    jruoho  *              Buffer                  - Where the pathname is returned
    120  1.1.1.6  christos  *              NoTrailing              - Remove trailing '_' for each name
    121  1.1.1.6  christos  *                                        segment
    122      1.1    jruoho  *
    123      1.1    jruoho  * RETURN:      Status, Buffer is filled with pathname if status is AE_OK
    124      1.1    jruoho  *
    125      1.1    jruoho  * DESCRIPTION: Build and return a full namespace pathname
    126      1.1    jruoho  *
    127      1.1    jruoho  ******************************************************************************/
    128      1.1    jruoho 
    129      1.1    jruoho ACPI_STATUS
    130      1.1    jruoho AcpiNsHandleToPathname (
    131      1.1    jruoho     ACPI_HANDLE             TargetHandle,
    132  1.1.1.6  christos     ACPI_BUFFER             *Buffer,
    133  1.1.1.6  christos     BOOLEAN                 NoTrailing)
    134      1.1    jruoho {
    135      1.1    jruoho     ACPI_STATUS             Status;
    136      1.1    jruoho     ACPI_NAMESPACE_NODE     *Node;
    137      1.1    jruoho     ACPI_SIZE               RequiredSize;
    138      1.1    jruoho 
    139      1.1    jruoho 
    140      1.1    jruoho     ACPI_FUNCTION_TRACE_PTR (NsHandleToPathname, TargetHandle);
    141      1.1    jruoho 
    142      1.1    jruoho 
    143      1.1    jruoho     Node = AcpiNsValidateHandle (TargetHandle);
    144      1.1    jruoho     if (!Node)
    145      1.1    jruoho     {
    146      1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    147      1.1    jruoho     }
    148      1.1    jruoho 
    149      1.1    jruoho     /* Determine size required for the caller buffer */
    150      1.1    jruoho 
    151  1.1.1.6  christos     RequiredSize = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
    152      1.1    jruoho     if (!RequiredSize)
    153      1.1    jruoho     {
    154      1.1    jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    155      1.1    jruoho     }
    156      1.1    jruoho 
    157      1.1    jruoho     /* Validate/Allocate/Clear caller buffer */
    158      1.1    jruoho 
    159      1.1    jruoho     Status = AcpiUtInitializeBuffer (Buffer, RequiredSize);
    160      1.1    jruoho     if (ACPI_FAILURE (Status))
    161      1.1    jruoho     {
    162      1.1    jruoho         return_ACPI_STATUS (Status);
    163      1.1    jruoho     }
    164      1.1    jruoho 
    165      1.1    jruoho     /* Build the path in the caller buffer */
    166      1.1    jruoho 
    167  1.1.1.6  christos     (void) AcpiNsBuildNormalizedPath (Node, Buffer->Pointer,
    168  1.1.1.6  christos             RequiredSize, NoTrailing);
    169      1.1    jruoho     if (ACPI_FAILURE (Status))
    170      1.1    jruoho     {
    171      1.1    jruoho         return_ACPI_STATUS (Status);
    172      1.1    jruoho     }
    173      1.1    jruoho 
    174      1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s [%X]\n",
    175      1.1    jruoho         (char *) Buffer->Pointer, (UINT32) RequiredSize));
    176      1.1    jruoho     return_ACPI_STATUS (AE_OK);
    177      1.1    jruoho }
    178  1.1.1.6  christos 
    179  1.1.1.6  christos 
    180  1.1.1.6  christos /*******************************************************************************
    181  1.1.1.6  christos  *
    182  1.1.1.6  christos  * FUNCTION:    AcpiNsBuildNormalizedPath
    183  1.1.1.6  christos  *
    184  1.1.1.6  christos  * PARAMETERS:  Node        - Namespace node
    185  1.1.1.6  christos  *              FullPath    - Where the path name is returned
    186  1.1.1.6  christos  *              PathSize    - Size of returned path name buffer
    187  1.1.1.6  christos  *              NoTrailing  - Remove trailing '_' from each name segment
    188  1.1.1.6  christos  *
    189  1.1.1.6  christos  * RETURN:      Return 1 if the AML path is empty, otherwise returning (length
    190  1.1.1.6  christos  *              of pathname + 1) which means the 'FullPath' contains a trailing
    191  1.1.1.6  christos  *              null.
    192  1.1.1.6  christos  *
    193  1.1.1.6  christos  * DESCRIPTION: Build and return a full namespace pathname.
    194  1.1.1.6  christos  *              Note that if the size of 'FullPath' isn't large enough to
    195  1.1.1.6  christos  *              contain the namespace node's path name, the actual required
    196  1.1.1.6  christos  *              buffer length is returned, and it should be greater than
    197  1.1.1.6  christos  *              'PathSize'. So callers are able to check the returning value
    198  1.1.1.6  christos  *              to determine the buffer size of 'FullPath'.
    199  1.1.1.6  christos  *
    200  1.1.1.6  christos  ******************************************************************************/
    201  1.1.1.6  christos 
    202  1.1.1.6  christos UINT32
    203  1.1.1.6  christos AcpiNsBuildNormalizedPath (
    204  1.1.1.6  christos     ACPI_NAMESPACE_NODE     *Node,
    205  1.1.1.6  christos     char                    *FullPath,
    206  1.1.1.6  christos     UINT32                  PathSize,
    207  1.1.1.6  christos     BOOLEAN                 NoTrailing)
    208  1.1.1.6  christos {
    209  1.1.1.6  christos     UINT32                  Length = 0, i;
    210  1.1.1.6  christos     char                    Name[ACPI_NAME_SIZE];
    211  1.1.1.6  christos     BOOLEAN                 DoNoTrailing;
    212  1.1.1.6  christos     char                    c, *Left, *Right;
    213  1.1.1.6  christos     ACPI_NAMESPACE_NODE     *NextNode;
    214  1.1.1.6  christos 
    215  1.1.1.6  christos 
    216  1.1.1.6  christos     ACPI_FUNCTION_TRACE_PTR (NsBuildNormalizedPath, Node);
    217  1.1.1.6  christos 
    218  1.1.1.6  christos 
    219  1.1.1.6  christos #define ACPI_PATH_PUT8(Path, Size, Byte, Length)    \
    220  1.1.1.6  christos     do {                                            \
    221  1.1.1.6  christos         if ((Length) < (Size))                      \
    222  1.1.1.6  christos         {                                           \
    223  1.1.1.6  christos             (Path)[(Length)] = (Byte);              \
    224  1.1.1.6  christos         }                                           \
    225  1.1.1.6  christos         (Length)++;                                 \
    226  1.1.1.6  christos     } while (0)
    227  1.1.1.6  christos 
    228  1.1.1.6  christos     /*
    229  1.1.1.6  christos      * Make sure the PathSize is correct, so that we don't need to
    230  1.1.1.6  christos      * validate both FullPath and PathSize.
    231  1.1.1.6  christos      */
    232  1.1.1.6  christos     if (!FullPath)
    233  1.1.1.6  christos     {
    234  1.1.1.6  christos         PathSize = 0;
    235  1.1.1.6  christos     }
    236  1.1.1.6  christos 
    237  1.1.1.6  christos     if (!Node)
    238  1.1.1.6  christos     {
    239  1.1.1.6  christos         goto BuildTrailingNull;
    240  1.1.1.6  christos     }
    241  1.1.1.6  christos 
    242  1.1.1.6  christos     NextNode = Node;
    243  1.1.1.6  christos     while (NextNode && NextNode != AcpiGbl_RootNode)
    244  1.1.1.6  christos     {
    245  1.1.1.6  christos         if (NextNode != Node)
    246  1.1.1.6  christos         {
    247  1.1.1.6  christos             ACPI_PATH_PUT8(FullPath, PathSize, AML_DUAL_NAME_PREFIX, Length);
    248  1.1.1.6  christos         }
    249  1.1.1.6  christos         ACPI_MOVE_32_TO_32 (Name, &NextNode->Name);
    250  1.1.1.6  christos         DoNoTrailing = NoTrailing;
    251  1.1.1.6  christos         for (i = 0; i < 4; i++)
    252  1.1.1.6  christos         {
    253  1.1.1.6  christos             c = Name[4-i-1];
    254  1.1.1.6  christos             if (DoNoTrailing && c != '_')
    255  1.1.1.6  christos             {
    256  1.1.1.6  christos                 DoNoTrailing = FALSE;
    257  1.1.1.6  christos             }
    258  1.1.1.6  christos             if (!DoNoTrailing)
    259  1.1.1.6  christos             {
    260  1.1.1.6  christos                 ACPI_PATH_PUT8(FullPath, PathSize, c, Length);
    261  1.1.1.6  christos             }
    262  1.1.1.6  christos         }
    263  1.1.1.6  christos         NextNode = NextNode->Parent;
    264  1.1.1.6  christos     }
    265  1.1.1.6  christos     ACPI_PATH_PUT8(FullPath, PathSize, AML_ROOT_PREFIX, Length);
    266  1.1.1.6  christos 
    267  1.1.1.6  christos     /* Reverse the path string */
    268  1.1.1.6  christos 
    269  1.1.1.6  christos     if (Length <= PathSize)
    270  1.1.1.6  christos     {
    271  1.1.1.6  christos         Left = FullPath;
    272  1.1.1.6  christos         Right = FullPath+Length-1;
    273  1.1.1.6  christos         while (Left < Right)
    274  1.1.1.6  christos         {
    275  1.1.1.6  christos             c = *Left;
    276  1.1.1.6  christos             *Left++ = *Right;
    277  1.1.1.6  christos             *Right-- = c;
    278  1.1.1.6  christos         }
    279  1.1.1.6  christos     }
    280  1.1.1.6  christos 
    281  1.1.1.6  christos     /* Append the trailing null */
    282  1.1.1.6  christos 
    283  1.1.1.6  christos BuildTrailingNull:
    284  1.1.1.6  christos     ACPI_PATH_PUT8(FullPath, PathSize, '\0', Length);
    285  1.1.1.6  christos 
    286  1.1.1.6  christos #undef ACPI_PATH_PUT8
    287  1.1.1.6  christos 
    288  1.1.1.6  christos     return_UINT32 (Length);
    289  1.1.1.6  christos }
    290  1.1.1.6  christos 
    291  1.1.1.6  christos 
    292  1.1.1.6  christos /*******************************************************************************
    293  1.1.1.6  christos  *
    294  1.1.1.6  christos  * FUNCTION:    AcpiNsGetNormalizedPathname
    295  1.1.1.6  christos  *
    296  1.1.1.6  christos  * PARAMETERS:  Node            - Namespace node whose pathname is needed
    297  1.1.1.6  christos  *              NoTrailing      - Remove trailing '_' from each name segment
    298  1.1.1.6  christos  *
    299  1.1.1.6  christos  * RETURN:      Pointer to storage containing the fully qualified name of
    300  1.1.1.6  christos  *              the node, In external format (name segments separated by path
    301  1.1.1.6  christos  *              separators.)
    302  1.1.1.6  christos  *
    303  1.1.1.6  christos  * DESCRIPTION: Used to obtain the full pathname to a namespace node, usually
    304  1.1.1.6  christos  *              for error and debug statements. All trailing '_' will be
    305  1.1.1.6  christos  *              removed from the full pathname if 'NoTrailing' is specified..
    306  1.1.1.6  christos  *
    307  1.1.1.6  christos  ******************************************************************************/
    308  1.1.1.6  christos 
    309  1.1.1.6  christos char *
    310  1.1.1.6  christos AcpiNsGetNormalizedPathname (
    311  1.1.1.6  christos     ACPI_NAMESPACE_NODE     *Node,
    312  1.1.1.6  christos     BOOLEAN                 NoTrailing)
    313  1.1.1.6  christos {
    314  1.1.1.6  christos     char                    *NameBuffer;
    315  1.1.1.6  christos     ACPI_SIZE               Size;
    316  1.1.1.6  christos 
    317  1.1.1.6  christos 
    318  1.1.1.6  christos     ACPI_FUNCTION_TRACE_PTR (NsGetNormalizedPathname, Node);
    319  1.1.1.6  christos 
    320  1.1.1.6  christos 
    321  1.1.1.6  christos     /* Calculate required buffer size based on depth below root */
    322  1.1.1.6  christos 
    323  1.1.1.6  christos     Size = AcpiNsBuildNormalizedPath (Node, NULL, 0, NoTrailing);
    324  1.1.1.6  christos     if (!Size)
    325  1.1.1.6  christos     {
    326  1.1.1.6  christos         return_PTR (NULL);
    327  1.1.1.6  christos     }
    328  1.1.1.6  christos 
    329  1.1.1.6  christos     /* Allocate a buffer to be returned to caller */
    330  1.1.1.6  christos 
    331  1.1.1.6  christos     NameBuffer = ACPI_ALLOCATE_ZEROED (Size);
    332  1.1.1.6  christos     if (!NameBuffer)
    333  1.1.1.6  christos     {
    334  1.1.1.6  christos         ACPI_ERROR ((AE_INFO, "Could not allocate %u bytes", (UINT32) Size));
    335  1.1.1.6  christos         return_PTR (NULL);
    336  1.1.1.6  christos     }
    337  1.1.1.6  christos 
    338  1.1.1.6  christos     /* Build the path in the allocated buffer */
    339  1.1.1.6  christos 
    340  1.1.1.6  christos     (void) AcpiNsBuildNormalizedPath (Node, NameBuffer, Size, NoTrailing);
    341  1.1.1.6  christos 
    342  1.1.1.6  christos     return_PTR (NameBuffer);
    343  1.1.1.6  christos }
    344