Home | History | Annotate | Line # | Download | only in namespace
nsutils.c revision 1.1
      1  1.1  jruoho /******************************************************************************
      2  1.1  jruoho  *
      3  1.1  jruoho  * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
      4  1.1  jruoho  *                        parents and siblings and Scope manipulation
      5  1.1  jruoho  *
      6  1.1  jruoho  *****************************************************************************/
      7  1.1  jruoho 
      8  1.1  jruoho /******************************************************************************
      9  1.1  jruoho  *
     10  1.1  jruoho  * 1. Copyright Notice
     11  1.1  jruoho  *
     12  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     13  1.1  jruoho  * All rights reserved.
     14  1.1  jruoho  *
     15  1.1  jruoho  * 2. License
     16  1.1  jruoho  *
     17  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     19  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     20  1.1  jruoho  * property rights.
     21  1.1  jruoho  *
     22  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     24  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     27  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     28  1.1  jruoho  *
     29  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     31  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     33  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     34  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     35  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     36  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     37  1.1  jruoho  *
     38  1.1  jruoho  * The above copyright and patent license is granted only if the following
     39  1.1  jruoho  * conditions are met:
     40  1.1  jruoho  *
     41  1.1  jruoho  * 3. Conditions
     42  1.1  jruoho  *
     43  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     45  1.1  jruoho  * Code or modification with rights to further distribute source must include
     46  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     47  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     48  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     49  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     50  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     51  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     52  1.1  jruoho  * must include a prominent statement that the modification is derived,
     53  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     54  1.1  jruoho  *
     55  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     57  1.1  jruoho  * Code or modification without rights to further distribute source must
     58  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     59  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     60  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     61  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     62  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     63  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     64  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     65  1.1  jruoho  * make.
     66  1.1  jruoho  *
     67  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     69  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     71  1.1  jruoho  * distribution.
     72  1.1  jruoho  *
     73  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  1.1  jruoho  * Intel Code.
     75  1.1  jruoho  *
     76  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     79  1.1  jruoho  * without prior written authorization from Intel.
     80  1.1  jruoho  *
     81  1.1  jruoho  * 4. Disclaimer and Export Compliance
     82  1.1  jruoho  *
     83  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     86  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     87  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     88  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  1.1  jruoho  * PARTICULAR PURPOSE.
     90  1.1  jruoho  *
     91  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     97  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  1.1  jruoho  * LIMITED REMEDY.
     99  1.1  jruoho  *
    100  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  1.1  jruoho  * software or system incorporating such software without first obtaining any
    102  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    103  1.1  jruoho  * any other agency or department of the United States Government.  In the
    104  1.1  jruoho  * event Licensee exports any such software from the United States or
    105  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    106  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    107  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    108  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    110  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    111  1.1  jruoho  * United States government or any agency thereof requires an export license,
    112  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    113  1.1  jruoho  * such license, approval or letter.
    114  1.1  jruoho  *
    115  1.1  jruoho  *****************************************************************************/
    116  1.1  jruoho 
    117  1.1  jruoho #define __NSUTILS_C__
    118  1.1  jruoho 
    119  1.1  jruoho #include "acpi.h"
    120  1.1  jruoho #include "accommon.h"
    121  1.1  jruoho #include "acnamesp.h"
    122  1.1  jruoho #include "amlcode.h"
    123  1.1  jruoho 
    124  1.1  jruoho #define _COMPONENT          ACPI_NAMESPACE
    125  1.1  jruoho         ACPI_MODULE_NAME    ("nsutils")
    126  1.1  jruoho 
    127  1.1  jruoho /* Local prototypes */
    128  1.1  jruoho 
    129  1.1  jruoho static BOOLEAN
    130  1.1  jruoho AcpiNsValidPathSeparator (
    131  1.1  jruoho     char                    Sep);
    132  1.1  jruoho 
    133  1.1  jruoho #ifdef ACPI_OBSOLETE_FUNCTIONS
    134  1.1  jruoho ACPI_NAME
    135  1.1  jruoho AcpiNsFindParentName (
    136  1.1  jruoho     ACPI_NAMESPACE_NODE     *NodeToSearch);
    137  1.1  jruoho #endif
    138  1.1  jruoho 
    139  1.1  jruoho 
    140  1.1  jruoho /*******************************************************************************
    141  1.1  jruoho  *
    142  1.1  jruoho  * FUNCTION:    AcpiNsReportError
    143  1.1  jruoho  *
    144  1.1  jruoho  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
    145  1.1  jruoho  *              LineNumber          - Caller's line number (for error output)
    146  1.1  jruoho  *              InternalName        - Name or path of the namespace node
    147  1.1  jruoho  *              LookupStatus        - Exception code from NS lookup
    148  1.1  jruoho  *
    149  1.1  jruoho  * RETURN:      None
    150  1.1  jruoho  *
    151  1.1  jruoho  * DESCRIPTION: Print warning message with full pathname
    152  1.1  jruoho  *
    153  1.1  jruoho  ******************************************************************************/
    154  1.1  jruoho 
    155  1.1  jruoho void
    156  1.1  jruoho AcpiNsReportError (
    157  1.1  jruoho     const char              *ModuleName,
    158  1.1  jruoho     UINT32                  LineNumber,
    159  1.1  jruoho     const char              *InternalName,
    160  1.1  jruoho     ACPI_STATUS             LookupStatus)
    161  1.1  jruoho {
    162  1.1  jruoho     ACPI_STATUS             Status;
    163  1.1  jruoho     UINT32                  BadName;
    164  1.1  jruoho     char                    *Name = NULL;
    165  1.1  jruoho 
    166  1.1  jruoho 
    167  1.1  jruoho     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
    168  1.1  jruoho 
    169  1.1  jruoho     if (LookupStatus == AE_BAD_CHARACTER)
    170  1.1  jruoho     {
    171  1.1  jruoho         /* There is a non-ascii character in the name */
    172  1.1  jruoho 
    173  1.1  jruoho         ACPI_MOVE_32_TO_32 (&BadName, ACPI_CAST_PTR (UINT32, InternalName));
    174  1.1  jruoho         AcpiOsPrintf ("[0x%4.4X] (NON-ASCII)", BadName);
    175  1.1  jruoho     }
    176  1.1  jruoho     else
    177  1.1  jruoho     {
    178  1.1  jruoho         /* Convert path to external format */
    179  1.1  jruoho 
    180  1.1  jruoho         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
    181  1.1  jruoho                     InternalName, NULL, &Name);
    182  1.1  jruoho 
    183  1.1  jruoho         /* Print target name */
    184  1.1  jruoho 
    185  1.1  jruoho         if (ACPI_SUCCESS (Status))
    186  1.1  jruoho         {
    187  1.1  jruoho             AcpiOsPrintf ("[%s]", Name);
    188  1.1  jruoho         }
    189  1.1  jruoho         else
    190  1.1  jruoho         {
    191  1.1  jruoho             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
    192  1.1  jruoho         }
    193  1.1  jruoho 
    194  1.1  jruoho         if (Name)
    195  1.1  jruoho         {
    196  1.1  jruoho             ACPI_FREE (Name);
    197  1.1  jruoho         }
    198  1.1  jruoho     }
    199  1.1  jruoho 
    200  1.1  jruoho     AcpiOsPrintf (" Namespace lookup failure, %s\n",
    201  1.1  jruoho         AcpiFormatException (LookupStatus));
    202  1.1  jruoho }
    203  1.1  jruoho 
    204  1.1  jruoho 
    205  1.1  jruoho /*******************************************************************************
    206  1.1  jruoho  *
    207  1.1  jruoho  * FUNCTION:    AcpiNsReportMethodError
    208  1.1  jruoho  *
    209  1.1  jruoho  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
    210  1.1  jruoho  *              LineNumber          - Caller's line number (for error output)
    211  1.1  jruoho  *              Message             - Error message to use on failure
    212  1.1  jruoho  *              PrefixNode          - Prefix relative to the path
    213  1.1  jruoho  *              Path                - Path to the node (optional)
    214  1.1  jruoho  *              MethodStatus        - Execution status
    215  1.1  jruoho  *
    216  1.1  jruoho  * RETURN:      None
    217  1.1  jruoho  *
    218  1.1  jruoho  * DESCRIPTION: Print warning message with full pathname
    219  1.1  jruoho  *
    220  1.1  jruoho  ******************************************************************************/
    221  1.1  jruoho 
    222  1.1  jruoho void
    223  1.1  jruoho AcpiNsReportMethodError (
    224  1.1  jruoho     const char              *ModuleName,
    225  1.1  jruoho     UINT32                  LineNumber,
    226  1.1  jruoho     const char              *Message,
    227  1.1  jruoho     ACPI_NAMESPACE_NODE     *PrefixNode,
    228  1.1  jruoho     const char              *Path,
    229  1.1  jruoho     ACPI_STATUS             MethodStatus)
    230  1.1  jruoho {
    231  1.1  jruoho     ACPI_STATUS             Status;
    232  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
    233  1.1  jruoho 
    234  1.1  jruoho 
    235  1.1  jruoho     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
    236  1.1  jruoho 
    237  1.1  jruoho     if (Path)
    238  1.1  jruoho     {
    239  1.1  jruoho         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
    240  1.1  jruoho                     &Node);
    241  1.1  jruoho         if (ACPI_FAILURE (Status))
    242  1.1  jruoho         {
    243  1.1  jruoho             AcpiOsPrintf ("[Could not get node by pathname]");
    244  1.1  jruoho         }
    245  1.1  jruoho     }
    246  1.1  jruoho 
    247  1.1  jruoho     AcpiNsPrintNodePathname (Node, Message);
    248  1.1  jruoho     AcpiOsPrintf (", %s\n", AcpiFormatException (MethodStatus));
    249  1.1  jruoho }
    250  1.1  jruoho 
    251  1.1  jruoho 
    252  1.1  jruoho /*******************************************************************************
    253  1.1  jruoho  *
    254  1.1  jruoho  * FUNCTION:    AcpiNsPrintNodePathname
    255  1.1  jruoho  *
    256  1.1  jruoho  * PARAMETERS:  Node            - Object
    257  1.1  jruoho  *              Message         - Prefix message
    258  1.1  jruoho  *
    259  1.1  jruoho  * DESCRIPTION: Print an object's full namespace pathname
    260  1.1  jruoho  *              Manages allocation/freeing of a pathname buffer
    261  1.1  jruoho  *
    262  1.1  jruoho  ******************************************************************************/
    263  1.1  jruoho 
    264  1.1  jruoho void
    265  1.1  jruoho AcpiNsPrintNodePathname (
    266  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
    267  1.1  jruoho     const char              *Message)
    268  1.1  jruoho {
    269  1.1  jruoho     ACPI_BUFFER             Buffer;
    270  1.1  jruoho     ACPI_STATUS             Status;
    271  1.1  jruoho 
    272  1.1  jruoho 
    273  1.1  jruoho     if (!Node)
    274  1.1  jruoho     {
    275  1.1  jruoho         AcpiOsPrintf ("[NULL NAME]");
    276  1.1  jruoho         return;
    277  1.1  jruoho     }
    278  1.1  jruoho 
    279  1.1  jruoho     /* Convert handle to full pathname and print it (with supplied message) */
    280  1.1  jruoho 
    281  1.1  jruoho     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
    282  1.1  jruoho 
    283  1.1  jruoho     Status = AcpiNsHandleToPathname (Node, &Buffer);
    284  1.1  jruoho     if (ACPI_SUCCESS (Status))
    285  1.1  jruoho     {
    286  1.1  jruoho         if (Message)
    287  1.1  jruoho         {
    288  1.1  jruoho             AcpiOsPrintf ("%s ", Message);
    289  1.1  jruoho         }
    290  1.1  jruoho 
    291  1.1  jruoho         AcpiOsPrintf ("[%s] (Node %p)", (char *) Buffer.Pointer, Node);
    292  1.1  jruoho         ACPI_FREE (Buffer.Pointer);
    293  1.1  jruoho     }
    294  1.1  jruoho }
    295  1.1  jruoho 
    296  1.1  jruoho 
    297  1.1  jruoho /*******************************************************************************
    298  1.1  jruoho  *
    299  1.1  jruoho  * FUNCTION:    AcpiNsValidRootPrefix
    300  1.1  jruoho  *
    301  1.1  jruoho  * PARAMETERS:  Prefix          - Character to be checked
    302  1.1  jruoho  *
    303  1.1  jruoho  * RETURN:      TRUE if a valid prefix
    304  1.1  jruoho  *
    305  1.1  jruoho  * DESCRIPTION: Check if a character is a valid ACPI Root prefix
    306  1.1  jruoho  *
    307  1.1  jruoho  ******************************************************************************/
    308  1.1  jruoho 
    309  1.1  jruoho BOOLEAN
    310  1.1  jruoho AcpiNsValidRootPrefix (
    311  1.1  jruoho     char                    Prefix)
    312  1.1  jruoho {
    313  1.1  jruoho 
    314  1.1  jruoho     return ((BOOLEAN) (Prefix == '\\'));
    315  1.1  jruoho }
    316  1.1  jruoho 
    317  1.1  jruoho 
    318  1.1  jruoho /*******************************************************************************
    319  1.1  jruoho  *
    320  1.1  jruoho  * FUNCTION:    AcpiNsValidPathSeparator
    321  1.1  jruoho  *
    322  1.1  jruoho  * PARAMETERS:  Sep         - Character to be checked
    323  1.1  jruoho  *
    324  1.1  jruoho  * RETURN:      TRUE if a valid path separator
    325  1.1  jruoho  *
    326  1.1  jruoho  * DESCRIPTION: Check if a character is a valid ACPI path separator
    327  1.1  jruoho  *
    328  1.1  jruoho  ******************************************************************************/
    329  1.1  jruoho 
    330  1.1  jruoho static BOOLEAN
    331  1.1  jruoho AcpiNsValidPathSeparator (
    332  1.1  jruoho     char                    Sep)
    333  1.1  jruoho {
    334  1.1  jruoho 
    335  1.1  jruoho     return ((BOOLEAN) (Sep == '.'));
    336  1.1  jruoho }
    337  1.1  jruoho 
    338  1.1  jruoho 
    339  1.1  jruoho /*******************************************************************************
    340  1.1  jruoho  *
    341  1.1  jruoho  * FUNCTION:    AcpiNsGetType
    342  1.1  jruoho  *
    343  1.1  jruoho  * PARAMETERS:  Node        - Parent Node to be examined
    344  1.1  jruoho  *
    345  1.1  jruoho  * RETURN:      Type field from Node whose handle is passed
    346  1.1  jruoho  *
    347  1.1  jruoho  * DESCRIPTION: Return the type of a Namespace node
    348  1.1  jruoho  *
    349  1.1  jruoho  ******************************************************************************/
    350  1.1  jruoho 
    351  1.1  jruoho ACPI_OBJECT_TYPE
    352  1.1  jruoho AcpiNsGetType (
    353  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node)
    354  1.1  jruoho {
    355  1.1  jruoho     ACPI_FUNCTION_TRACE (NsGetType);
    356  1.1  jruoho 
    357  1.1  jruoho 
    358  1.1  jruoho     if (!Node)
    359  1.1  jruoho     {
    360  1.1  jruoho         ACPI_WARNING ((AE_INFO, "Null Node parameter"));
    361  1.1  jruoho         return_UINT32 (ACPI_TYPE_ANY);
    362  1.1  jruoho     }
    363  1.1  jruoho 
    364  1.1  jruoho     return_UINT32 ((ACPI_OBJECT_TYPE) Node->Type);
    365  1.1  jruoho }
    366  1.1  jruoho 
    367  1.1  jruoho 
    368  1.1  jruoho /*******************************************************************************
    369  1.1  jruoho  *
    370  1.1  jruoho  * FUNCTION:    AcpiNsLocal
    371  1.1  jruoho  *
    372  1.1  jruoho  * PARAMETERS:  Type        - A namespace object type
    373  1.1  jruoho  *
    374  1.1  jruoho  * RETURN:      LOCAL if names must be found locally in objects of the
    375  1.1  jruoho  *              passed type, 0 if enclosing scopes should be searched
    376  1.1  jruoho  *
    377  1.1  jruoho  * DESCRIPTION: Returns scope rule for the given object type.
    378  1.1  jruoho  *
    379  1.1  jruoho  ******************************************************************************/
    380  1.1  jruoho 
    381  1.1  jruoho UINT32
    382  1.1  jruoho AcpiNsLocal (
    383  1.1  jruoho     ACPI_OBJECT_TYPE        Type)
    384  1.1  jruoho {
    385  1.1  jruoho     ACPI_FUNCTION_TRACE (NsLocal);
    386  1.1  jruoho 
    387  1.1  jruoho 
    388  1.1  jruoho     if (!AcpiUtValidObjectType (Type))
    389  1.1  jruoho     {
    390  1.1  jruoho         /* Type code out of range  */
    391  1.1  jruoho 
    392  1.1  jruoho         ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
    393  1.1  jruoho         return_UINT32 (ACPI_NS_NORMAL);
    394  1.1  jruoho     }
    395  1.1  jruoho 
    396  1.1  jruoho     return_UINT32 ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
    397  1.1  jruoho }
    398  1.1  jruoho 
    399  1.1  jruoho 
    400  1.1  jruoho /*******************************************************************************
    401  1.1  jruoho  *
    402  1.1  jruoho  * FUNCTION:    AcpiNsGetInternalNameLength
    403  1.1  jruoho  *
    404  1.1  jruoho  * PARAMETERS:  Info            - Info struct initialized with the
    405  1.1  jruoho  *                                external name pointer.
    406  1.1  jruoho  *
    407  1.1  jruoho  * RETURN:      None
    408  1.1  jruoho  *
    409  1.1  jruoho  * DESCRIPTION: Calculate the length of the internal (AML) namestring
    410  1.1  jruoho  *              corresponding to the external (ASL) namestring.
    411  1.1  jruoho  *
    412  1.1  jruoho  ******************************************************************************/
    413  1.1  jruoho 
    414  1.1  jruoho void
    415  1.1  jruoho AcpiNsGetInternalNameLength (
    416  1.1  jruoho     ACPI_NAMESTRING_INFO    *Info)
    417  1.1  jruoho {
    418  1.1  jruoho     const char              *NextExternalChar;
    419  1.1  jruoho     UINT32                  i;
    420  1.1  jruoho 
    421  1.1  jruoho 
    422  1.1  jruoho     ACPI_FUNCTION_ENTRY ();
    423  1.1  jruoho 
    424  1.1  jruoho 
    425  1.1  jruoho     NextExternalChar = Info->ExternalName;
    426  1.1  jruoho     Info->NumCarats = 0;
    427  1.1  jruoho     Info->NumSegments = 0;
    428  1.1  jruoho     Info->FullyQualified = FALSE;
    429  1.1  jruoho 
    430  1.1  jruoho     /*
    431  1.1  jruoho      * For the internal name, the required length is 4 bytes per segment, plus
    432  1.1  jruoho      * 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null
    433  1.1  jruoho      * (which is not really needed, but no there's harm in putting it there)
    434  1.1  jruoho      *
    435  1.1  jruoho      * strlen() + 1 covers the first NameSeg, which has no path separator
    436  1.1  jruoho      */
    437  1.1  jruoho     if (AcpiNsValidRootPrefix (*NextExternalChar))
    438  1.1  jruoho     {
    439  1.1  jruoho         Info->FullyQualified = TRUE;
    440  1.1  jruoho         NextExternalChar++;
    441  1.1  jruoho 
    442  1.1  jruoho         /* Skip redundant RootPrefix, like \\_SB.PCI0.SBRG.EC0 */
    443  1.1  jruoho 
    444  1.1  jruoho         while (AcpiNsValidRootPrefix (*NextExternalChar))
    445  1.1  jruoho         {
    446  1.1  jruoho             NextExternalChar++;
    447  1.1  jruoho         }
    448  1.1  jruoho     }
    449  1.1  jruoho     else
    450  1.1  jruoho     {
    451  1.1  jruoho         /* Handle Carat prefixes */
    452  1.1  jruoho 
    453  1.1  jruoho         while (*NextExternalChar == '^')
    454  1.1  jruoho         {
    455  1.1  jruoho             Info->NumCarats++;
    456  1.1  jruoho             NextExternalChar++;
    457  1.1  jruoho         }
    458  1.1  jruoho     }
    459  1.1  jruoho 
    460  1.1  jruoho     /*
    461  1.1  jruoho      * Determine the number of ACPI name "segments" by counting the number of
    462  1.1  jruoho      * path separators within the string. Start with one segment since the
    463  1.1  jruoho      * segment count is [(# separators) + 1], and zero separators is ok.
    464  1.1  jruoho      */
    465  1.1  jruoho     if (*NextExternalChar)
    466  1.1  jruoho     {
    467  1.1  jruoho         Info->NumSegments = 1;
    468  1.1  jruoho         for (i = 0; NextExternalChar[i]; i++)
    469  1.1  jruoho         {
    470  1.1  jruoho             if (AcpiNsValidPathSeparator (NextExternalChar[i]))
    471  1.1  jruoho             {
    472  1.1  jruoho                 Info->NumSegments++;
    473  1.1  jruoho             }
    474  1.1  jruoho         }
    475  1.1  jruoho     }
    476  1.1  jruoho 
    477  1.1  jruoho     Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
    478  1.1  jruoho                     4 + Info->NumCarats;
    479  1.1  jruoho 
    480  1.1  jruoho     Info->NextExternalChar = NextExternalChar;
    481  1.1  jruoho }
    482  1.1  jruoho 
    483  1.1  jruoho 
    484  1.1  jruoho /*******************************************************************************
    485  1.1  jruoho  *
    486  1.1  jruoho  * FUNCTION:    AcpiNsBuildInternalName
    487  1.1  jruoho  *
    488  1.1  jruoho  * PARAMETERS:  Info            - Info struct fully initialized
    489  1.1  jruoho  *
    490  1.1  jruoho  * RETURN:      Status
    491  1.1  jruoho  *
    492  1.1  jruoho  * DESCRIPTION: Construct the internal (AML) namestring
    493  1.1  jruoho  *              corresponding to the external (ASL) namestring.
    494  1.1  jruoho  *
    495  1.1  jruoho  ******************************************************************************/
    496  1.1  jruoho 
    497  1.1  jruoho ACPI_STATUS
    498  1.1  jruoho AcpiNsBuildInternalName (
    499  1.1  jruoho     ACPI_NAMESTRING_INFO    *Info)
    500  1.1  jruoho {
    501  1.1  jruoho     UINT32                  NumSegments = Info->NumSegments;
    502  1.1  jruoho     char                    *InternalName = Info->InternalName;
    503  1.1  jruoho     const char              *ExternalName = Info->NextExternalChar;
    504  1.1  jruoho     char                    *Result = NULL;
    505  1.1  jruoho     UINT32                  i;
    506  1.1  jruoho 
    507  1.1  jruoho 
    508  1.1  jruoho     ACPI_FUNCTION_TRACE (NsBuildInternalName);
    509  1.1  jruoho 
    510  1.1  jruoho 
    511  1.1  jruoho     /* Setup the correct prefixes, counts, and pointers */
    512  1.1  jruoho 
    513  1.1  jruoho     if (Info->FullyQualified)
    514  1.1  jruoho     {
    515  1.1  jruoho         InternalName[0] = '\\';
    516  1.1  jruoho 
    517  1.1  jruoho         if (NumSegments <= 1)
    518  1.1  jruoho         {
    519  1.1  jruoho             Result = &InternalName[1];
    520  1.1  jruoho         }
    521  1.1  jruoho         else if (NumSegments == 2)
    522  1.1  jruoho         {
    523  1.1  jruoho             InternalName[1] = AML_DUAL_NAME_PREFIX;
    524  1.1  jruoho             Result = &InternalName[2];
    525  1.1  jruoho         }
    526  1.1  jruoho         else
    527  1.1  jruoho         {
    528  1.1  jruoho             InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
    529  1.1  jruoho             InternalName[2] = (char) NumSegments;
    530  1.1  jruoho             Result = &InternalName[3];
    531  1.1  jruoho         }
    532  1.1  jruoho     }
    533  1.1  jruoho     else
    534  1.1  jruoho     {
    535  1.1  jruoho         /*
    536  1.1  jruoho          * Not fully qualified.
    537  1.1  jruoho          * Handle Carats first, then append the name segments
    538  1.1  jruoho          */
    539  1.1  jruoho         i = 0;
    540  1.1  jruoho         if (Info->NumCarats)
    541  1.1  jruoho         {
    542  1.1  jruoho             for (i = 0; i < Info->NumCarats; i++)
    543  1.1  jruoho             {
    544  1.1  jruoho                 InternalName[i] = '^';
    545  1.1  jruoho             }
    546  1.1  jruoho         }
    547  1.1  jruoho 
    548  1.1  jruoho         if (NumSegments <= 1)
    549  1.1  jruoho         {
    550  1.1  jruoho             Result = &InternalName[i];
    551  1.1  jruoho         }
    552  1.1  jruoho         else if (NumSegments == 2)
    553  1.1  jruoho         {
    554  1.1  jruoho             InternalName[i] = AML_DUAL_NAME_PREFIX;
    555  1.1  jruoho             Result = &InternalName[(ACPI_SIZE) i+1];
    556  1.1  jruoho         }
    557  1.1  jruoho         else
    558  1.1  jruoho         {
    559  1.1  jruoho             InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
    560  1.1  jruoho             InternalName[(ACPI_SIZE) i+1] = (char) NumSegments;
    561  1.1  jruoho             Result = &InternalName[(ACPI_SIZE) i+2];
    562  1.1  jruoho         }
    563  1.1  jruoho     }
    564  1.1  jruoho 
    565  1.1  jruoho     /* Build the name (minus path separators) */
    566  1.1  jruoho 
    567  1.1  jruoho     for (; NumSegments; NumSegments--)
    568  1.1  jruoho     {
    569  1.1  jruoho         for (i = 0; i < ACPI_NAME_SIZE; i++)
    570  1.1  jruoho         {
    571  1.1  jruoho             if (AcpiNsValidPathSeparator (*ExternalName) ||
    572  1.1  jruoho                (*ExternalName == 0))
    573  1.1  jruoho             {
    574  1.1  jruoho                 /* Pad the segment with underscore(s) if segment is short */
    575  1.1  jruoho 
    576  1.1  jruoho                 Result[i] = '_';
    577  1.1  jruoho             }
    578  1.1  jruoho             else
    579  1.1  jruoho             {
    580  1.1  jruoho                 /* Convert the character to uppercase and save it */
    581  1.1  jruoho 
    582  1.1  jruoho                 Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
    583  1.1  jruoho                 ExternalName++;
    584  1.1  jruoho             }
    585  1.1  jruoho         }
    586  1.1  jruoho 
    587  1.1  jruoho         /* Now we must have a path separator, or the pathname is bad */
    588  1.1  jruoho 
    589  1.1  jruoho         if (!AcpiNsValidPathSeparator (*ExternalName) &&
    590  1.1  jruoho             (*ExternalName != 0))
    591  1.1  jruoho         {
    592  1.1  jruoho             return_ACPI_STATUS (AE_BAD_PARAMETER);
    593  1.1  jruoho         }
    594  1.1  jruoho 
    595  1.1  jruoho         /* Move on the next segment */
    596  1.1  jruoho 
    597  1.1  jruoho         ExternalName++;
    598  1.1  jruoho         Result += ACPI_NAME_SIZE;
    599  1.1  jruoho     }
    600  1.1  jruoho 
    601  1.1  jruoho     /* Terminate the string */
    602  1.1  jruoho 
    603  1.1  jruoho     *Result = 0;
    604  1.1  jruoho 
    605  1.1  jruoho     if (Info->FullyQualified)
    606  1.1  jruoho     {
    607  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
    608  1.1  jruoho             InternalName, InternalName));
    609  1.1  jruoho     }
    610  1.1  jruoho     else
    611  1.1  jruoho     {
    612  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
    613  1.1  jruoho             InternalName, InternalName));
    614  1.1  jruoho     }
    615  1.1  jruoho 
    616  1.1  jruoho     return_ACPI_STATUS (AE_OK);
    617  1.1  jruoho }
    618  1.1  jruoho 
    619  1.1  jruoho 
    620  1.1  jruoho /*******************************************************************************
    621  1.1  jruoho  *
    622  1.1  jruoho  * FUNCTION:    AcpiNsInternalizeName
    623  1.1  jruoho  *
    624  1.1  jruoho  * PARAMETERS:  *ExternalName           - External representation of name
    625  1.1  jruoho  *              **Converted Name        - Where to return the resulting
    626  1.1  jruoho  *                                        internal represention of the name
    627  1.1  jruoho  *
    628  1.1  jruoho  * RETURN:      Status
    629  1.1  jruoho  *
    630  1.1  jruoho  * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
    631  1.1  jruoho  *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
    632  1.1  jruoho  *
    633  1.1  jruoho  *******************************************************************************/
    634  1.1  jruoho 
    635  1.1  jruoho ACPI_STATUS
    636  1.1  jruoho AcpiNsInternalizeName (
    637  1.1  jruoho     const char              *ExternalName,
    638  1.1  jruoho     char                    **ConvertedName)
    639  1.1  jruoho {
    640  1.1  jruoho     char                    *InternalName;
    641  1.1  jruoho     ACPI_NAMESTRING_INFO    Info;
    642  1.1  jruoho     ACPI_STATUS             Status;
    643  1.1  jruoho 
    644  1.1  jruoho 
    645  1.1  jruoho     ACPI_FUNCTION_TRACE (NsInternalizeName);
    646  1.1  jruoho 
    647  1.1  jruoho 
    648  1.1  jruoho     if ((!ExternalName)      ||
    649  1.1  jruoho         (*ExternalName == 0) ||
    650  1.1  jruoho         (!ConvertedName))
    651  1.1  jruoho     {
    652  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    653  1.1  jruoho     }
    654  1.1  jruoho 
    655  1.1  jruoho     /* Get the length of the new internal name */
    656  1.1  jruoho 
    657  1.1  jruoho     Info.ExternalName = ExternalName;
    658  1.1  jruoho     AcpiNsGetInternalNameLength (&Info);
    659  1.1  jruoho 
    660  1.1  jruoho     /* We need a segment to store the internal  name */
    661  1.1  jruoho 
    662  1.1  jruoho     InternalName = ACPI_ALLOCATE_ZEROED (Info.Length);
    663  1.1  jruoho     if (!InternalName)
    664  1.1  jruoho     {
    665  1.1  jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    666  1.1  jruoho     }
    667  1.1  jruoho 
    668  1.1  jruoho     /* Build the name */
    669  1.1  jruoho 
    670  1.1  jruoho     Info.InternalName = InternalName;
    671  1.1  jruoho     Status = AcpiNsBuildInternalName (&Info);
    672  1.1  jruoho     if (ACPI_FAILURE (Status))
    673  1.1  jruoho     {
    674  1.1  jruoho         ACPI_FREE (InternalName);
    675  1.1  jruoho         return_ACPI_STATUS (Status);
    676  1.1  jruoho     }
    677  1.1  jruoho 
    678  1.1  jruoho     *ConvertedName = InternalName;
    679  1.1  jruoho     return_ACPI_STATUS (AE_OK);
    680  1.1  jruoho }
    681  1.1  jruoho 
    682  1.1  jruoho 
    683  1.1  jruoho /*******************************************************************************
    684  1.1  jruoho  *
    685  1.1  jruoho  * FUNCTION:    AcpiNsExternalizeName
    686  1.1  jruoho  *
    687  1.1  jruoho  * PARAMETERS:  InternalNameLength  - Lenth of the internal name below
    688  1.1  jruoho  *              InternalName        - Internal representation of name
    689  1.1  jruoho  *              ConvertedNameLength - Where the length is returned
    690  1.1  jruoho  *              ConvertedName       - Where the resulting external name
    691  1.1  jruoho  *                                    is returned
    692  1.1  jruoho  *
    693  1.1  jruoho  * RETURN:      Status
    694  1.1  jruoho  *
    695  1.1  jruoho  * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
    696  1.1  jruoho  *              to its external (printable) form (e.g. "\_PR_.CPU0")
    697  1.1  jruoho  *
    698  1.1  jruoho  ******************************************************************************/
    699  1.1  jruoho 
    700  1.1  jruoho ACPI_STATUS
    701  1.1  jruoho AcpiNsExternalizeName (
    702  1.1  jruoho     UINT32                  InternalNameLength,
    703  1.1  jruoho     const char              *InternalName,
    704  1.1  jruoho     UINT32                  *ConvertedNameLength,
    705  1.1  jruoho     char                    **ConvertedName)
    706  1.1  jruoho {
    707  1.1  jruoho     UINT32                  NamesIndex = 0;
    708  1.1  jruoho     UINT32                  NumSegments = 0;
    709  1.1  jruoho     UINT32                  RequiredLength;
    710  1.1  jruoho     UINT32                  PrefixLength = 0;
    711  1.1  jruoho     UINT32                  i = 0;
    712  1.1  jruoho     UINT32                  j = 0;
    713  1.1  jruoho 
    714  1.1  jruoho 
    715  1.1  jruoho     ACPI_FUNCTION_TRACE (NsExternalizeName);
    716  1.1  jruoho 
    717  1.1  jruoho 
    718  1.1  jruoho     if (!InternalNameLength     ||
    719  1.1  jruoho         !InternalName           ||
    720  1.1  jruoho         !ConvertedName)
    721  1.1  jruoho     {
    722  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PARAMETER);
    723  1.1  jruoho     }
    724  1.1  jruoho 
    725  1.1  jruoho     /* Check for a prefix (one '\' | one or more '^') */
    726  1.1  jruoho 
    727  1.1  jruoho     switch (InternalName[0])
    728  1.1  jruoho     {
    729  1.1  jruoho     case '\\':
    730  1.1  jruoho         PrefixLength = 1;
    731  1.1  jruoho         break;
    732  1.1  jruoho 
    733  1.1  jruoho     case '^':
    734  1.1  jruoho         for (i = 0; i < InternalNameLength; i++)
    735  1.1  jruoho         {
    736  1.1  jruoho             if (InternalName[i] == '^')
    737  1.1  jruoho             {
    738  1.1  jruoho                 PrefixLength = i + 1;
    739  1.1  jruoho             }
    740  1.1  jruoho             else
    741  1.1  jruoho             {
    742  1.1  jruoho                 break;
    743  1.1  jruoho             }
    744  1.1  jruoho         }
    745  1.1  jruoho 
    746  1.1  jruoho         if (i == InternalNameLength)
    747  1.1  jruoho         {
    748  1.1  jruoho             PrefixLength = i;
    749  1.1  jruoho         }
    750  1.1  jruoho 
    751  1.1  jruoho         break;
    752  1.1  jruoho 
    753  1.1  jruoho     default:
    754  1.1  jruoho         break;
    755  1.1  jruoho     }
    756  1.1  jruoho 
    757  1.1  jruoho     /*
    758  1.1  jruoho      * Check for object names. Note that there could be 0-255 of these
    759  1.1  jruoho      * 4-byte elements.
    760  1.1  jruoho      */
    761  1.1  jruoho     if (PrefixLength < InternalNameLength)
    762  1.1  jruoho     {
    763  1.1  jruoho         switch (InternalName[PrefixLength])
    764  1.1  jruoho         {
    765  1.1  jruoho         case AML_MULTI_NAME_PREFIX_OP:
    766  1.1  jruoho 
    767  1.1  jruoho             /* <count> 4-byte names */
    768  1.1  jruoho 
    769  1.1  jruoho             NamesIndex = PrefixLength + 2;
    770  1.1  jruoho             NumSegments = (UINT8)
    771  1.1  jruoho                 InternalName[(ACPI_SIZE) PrefixLength + 1];
    772  1.1  jruoho             break;
    773  1.1  jruoho 
    774  1.1  jruoho         case AML_DUAL_NAME_PREFIX:
    775  1.1  jruoho 
    776  1.1  jruoho             /* Two 4-byte names */
    777  1.1  jruoho 
    778  1.1  jruoho             NamesIndex = PrefixLength + 1;
    779  1.1  jruoho             NumSegments = 2;
    780  1.1  jruoho             break;
    781  1.1  jruoho 
    782  1.1  jruoho         case 0:
    783  1.1  jruoho 
    784  1.1  jruoho             /* NullName */
    785  1.1  jruoho 
    786  1.1  jruoho             NamesIndex = 0;
    787  1.1  jruoho             NumSegments = 0;
    788  1.1  jruoho             break;
    789  1.1  jruoho 
    790  1.1  jruoho         default:
    791  1.1  jruoho 
    792  1.1  jruoho             /* one 4-byte name */
    793  1.1  jruoho 
    794  1.1  jruoho             NamesIndex = PrefixLength;
    795  1.1  jruoho             NumSegments = 1;
    796  1.1  jruoho             break;
    797  1.1  jruoho         }
    798  1.1  jruoho     }
    799  1.1  jruoho 
    800  1.1  jruoho     /*
    801  1.1  jruoho      * Calculate the length of ConvertedName, which equals the length
    802  1.1  jruoho      * of the prefix, length of all object names, length of any required
    803  1.1  jruoho      * punctuation ('.') between object names, plus the NULL terminator.
    804  1.1  jruoho      */
    805  1.1  jruoho     RequiredLength = PrefixLength + (4 * NumSegments) +
    806  1.1  jruoho                         ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
    807  1.1  jruoho 
    808  1.1  jruoho     /*
    809  1.1  jruoho      * Check to see if we're still in bounds.  If not, there's a problem
    810  1.1  jruoho      * with InternalName (invalid format).
    811  1.1  jruoho      */
    812  1.1  jruoho     if (RequiredLength > InternalNameLength)
    813  1.1  jruoho     {
    814  1.1  jruoho         ACPI_ERROR ((AE_INFO, "Invalid internal name"));
    815  1.1  jruoho         return_ACPI_STATUS (AE_BAD_PATHNAME);
    816  1.1  jruoho     }
    817  1.1  jruoho 
    818  1.1  jruoho     /* Build the ConvertedName */
    819  1.1  jruoho 
    820  1.1  jruoho     *ConvertedName = ACPI_ALLOCATE_ZEROED (RequiredLength);
    821  1.1  jruoho     if (!(*ConvertedName))
    822  1.1  jruoho     {
    823  1.1  jruoho         return_ACPI_STATUS (AE_NO_MEMORY);
    824  1.1  jruoho     }
    825  1.1  jruoho 
    826  1.1  jruoho     j = 0;
    827  1.1  jruoho 
    828  1.1  jruoho     for (i = 0; i < PrefixLength; i++)
    829  1.1  jruoho     {
    830  1.1  jruoho         (*ConvertedName)[j++] = InternalName[i];
    831  1.1  jruoho     }
    832  1.1  jruoho 
    833  1.1  jruoho     if (NumSegments > 0)
    834  1.1  jruoho     {
    835  1.1  jruoho         for (i = 0; i < NumSegments; i++)
    836  1.1  jruoho         {
    837  1.1  jruoho             if (i > 0)
    838  1.1  jruoho             {
    839  1.1  jruoho                 (*ConvertedName)[j++] = '.';
    840  1.1  jruoho             }
    841  1.1  jruoho 
    842  1.1  jruoho             (*ConvertedName)[j++] = InternalName[NamesIndex++];
    843  1.1  jruoho             (*ConvertedName)[j++] = InternalName[NamesIndex++];
    844  1.1  jruoho             (*ConvertedName)[j++] = InternalName[NamesIndex++];
    845  1.1  jruoho             (*ConvertedName)[j++] = InternalName[NamesIndex++];
    846  1.1  jruoho         }
    847  1.1  jruoho     }
    848  1.1  jruoho 
    849  1.1  jruoho     if (ConvertedNameLength)
    850  1.1  jruoho     {
    851  1.1  jruoho         *ConvertedNameLength = (UINT32) RequiredLength;
    852  1.1  jruoho     }
    853  1.1  jruoho 
    854  1.1  jruoho     return_ACPI_STATUS (AE_OK);
    855  1.1  jruoho }
    856  1.1  jruoho 
    857  1.1  jruoho 
    858  1.1  jruoho /*******************************************************************************
    859  1.1  jruoho  *
    860  1.1  jruoho  * FUNCTION:    AcpiNsValidateHandle
    861  1.1  jruoho  *
    862  1.1  jruoho  * PARAMETERS:  Handle          - Handle to be validated and typecast to a
    863  1.1  jruoho  *                                namespace node.
    864  1.1  jruoho  *
    865  1.1  jruoho  * RETURN:      A pointer to a namespace node
    866  1.1  jruoho  *
    867  1.1  jruoho  * DESCRIPTION: Convert a namespace handle to a namespace node. Handles special
    868  1.1  jruoho  *              cases for the root node.
    869  1.1  jruoho  *
    870  1.1  jruoho  * NOTE: Real integer handles would allow for more verification
    871  1.1  jruoho  *       and keep all pointers within this subsystem - however this introduces
    872  1.1  jruoho  *       more overhead and has not been necessary to this point. Drivers
    873  1.1  jruoho  *       holding handles are typically notified before a node becomes invalid
    874  1.1  jruoho  *       due to a table unload.
    875  1.1  jruoho  *
    876  1.1  jruoho  ******************************************************************************/
    877  1.1  jruoho 
    878  1.1  jruoho ACPI_NAMESPACE_NODE *
    879  1.1  jruoho AcpiNsValidateHandle (
    880  1.1  jruoho     ACPI_HANDLE             Handle)
    881  1.1  jruoho {
    882  1.1  jruoho 
    883  1.1  jruoho     ACPI_FUNCTION_ENTRY ();
    884  1.1  jruoho 
    885  1.1  jruoho 
    886  1.1  jruoho     /* Parameter validation */
    887  1.1  jruoho 
    888  1.1  jruoho     if ((!Handle) || (Handle == ACPI_ROOT_OBJECT))
    889  1.1  jruoho     {
    890  1.1  jruoho         return (AcpiGbl_RootNode);
    891  1.1  jruoho     }
    892  1.1  jruoho 
    893  1.1  jruoho     /* We can at least attempt to verify the handle */
    894  1.1  jruoho 
    895  1.1  jruoho     if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
    896  1.1  jruoho     {
    897  1.1  jruoho         return (NULL);
    898  1.1  jruoho     }
    899  1.1  jruoho 
    900  1.1  jruoho     return (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle));
    901  1.1  jruoho }
    902  1.1  jruoho 
    903  1.1  jruoho 
    904  1.1  jruoho /*******************************************************************************
    905  1.1  jruoho  *
    906  1.1  jruoho  * FUNCTION:    AcpiNsTerminate
    907  1.1  jruoho  *
    908  1.1  jruoho  * PARAMETERS:  none
    909  1.1  jruoho  *
    910  1.1  jruoho  * RETURN:      none
    911  1.1  jruoho  *
    912  1.1  jruoho  * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
    913  1.1  jruoho  *
    914  1.1  jruoho  ******************************************************************************/
    915  1.1  jruoho 
    916  1.1  jruoho void
    917  1.1  jruoho AcpiNsTerminate (
    918  1.1  jruoho     void)
    919  1.1  jruoho {
    920  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    921  1.1  jruoho 
    922  1.1  jruoho 
    923  1.1  jruoho     ACPI_FUNCTION_TRACE (NsTerminate);
    924  1.1  jruoho 
    925  1.1  jruoho 
    926  1.1  jruoho     /*
    927  1.1  jruoho      * 1) Free the entire namespace -- all nodes and objects
    928  1.1  jruoho      *
    929  1.1  jruoho      * Delete all object descriptors attached to namepsace nodes
    930  1.1  jruoho      */
    931  1.1  jruoho     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
    932  1.1  jruoho 
    933  1.1  jruoho     /* Detach any objects attached to the root */
    934  1.1  jruoho 
    935  1.1  jruoho     ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
    936  1.1  jruoho     if (ObjDesc)
    937  1.1  jruoho     {
    938  1.1  jruoho         AcpiNsDetachObject (AcpiGbl_RootNode);
    939  1.1  jruoho     }
    940  1.1  jruoho 
    941  1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
    942  1.1  jruoho     return_VOID;
    943  1.1  jruoho }
    944  1.1  jruoho 
    945  1.1  jruoho 
    946  1.1  jruoho /*******************************************************************************
    947  1.1  jruoho  *
    948  1.1  jruoho  * FUNCTION:    AcpiNsOpensScope
    949  1.1  jruoho  *
    950  1.1  jruoho  * PARAMETERS:  Type        - A valid namespace type
    951  1.1  jruoho  *
    952  1.1  jruoho  * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
    953  1.1  jruoho  *              to the ACPI specification, else 0
    954  1.1  jruoho  *
    955  1.1  jruoho  ******************************************************************************/
    956  1.1  jruoho 
    957  1.1  jruoho UINT32
    958  1.1  jruoho AcpiNsOpensScope (
    959  1.1  jruoho     ACPI_OBJECT_TYPE        Type)
    960  1.1  jruoho {
    961  1.1  jruoho     ACPI_FUNCTION_TRACE_STR (NsOpensScope, AcpiUtGetTypeName (Type));
    962  1.1  jruoho 
    963  1.1  jruoho 
    964  1.1  jruoho     if (!AcpiUtValidObjectType (Type))
    965  1.1  jruoho     {
    966  1.1  jruoho         /* type code out of range  */
    967  1.1  jruoho 
    968  1.1  jruoho         ACPI_WARNING ((AE_INFO, "Invalid Object Type 0x%X", Type));
    969  1.1  jruoho         return_UINT32 (ACPI_NS_NORMAL);
    970  1.1  jruoho     }
    971  1.1  jruoho 
    972  1.1  jruoho     return_UINT32 (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
    973  1.1  jruoho }
    974  1.1  jruoho 
    975  1.1  jruoho 
    976  1.1  jruoho /*******************************************************************************
    977  1.1  jruoho  *
    978  1.1  jruoho  * FUNCTION:    AcpiNsGetNode
    979  1.1  jruoho  *
    980  1.1  jruoho  * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
    981  1.1  jruoho  *                            \ (backslash) and ^ (carat) prefixes, and the
    982  1.1  jruoho  *                            . (period) to separate segments are supported.
    983  1.1  jruoho  *              PrefixNode   - Root of subtree to be searched, or NS_ALL for the
    984  1.1  jruoho  *                            root of the name space.  If Name is fully
    985  1.1  jruoho  *                            qualified (first INT8 is '\'), the passed value
    986  1.1  jruoho  *                            of Scope will not be accessed.
    987  1.1  jruoho  *              Flags       - Used to indicate whether to perform upsearch or
    988  1.1  jruoho  *                            not.
    989  1.1  jruoho  *              ReturnNode  - Where the Node is returned
    990  1.1  jruoho  *
    991  1.1  jruoho  * DESCRIPTION: Look up a name relative to a given scope and return the
    992  1.1  jruoho  *              corresponding Node.  NOTE: Scope can be null.
    993  1.1  jruoho  *
    994  1.1  jruoho  * MUTEX:       Locks namespace
    995  1.1  jruoho  *
    996  1.1  jruoho  ******************************************************************************/
    997  1.1  jruoho 
    998  1.1  jruoho ACPI_STATUS
    999  1.1  jruoho AcpiNsGetNode (
   1000  1.1  jruoho     ACPI_NAMESPACE_NODE     *PrefixNode,
   1001  1.1  jruoho     const char              *Pathname,
   1002  1.1  jruoho     UINT32                  Flags,
   1003  1.1  jruoho     ACPI_NAMESPACE_NODE     **ReturnNode)
   1004  1.1  jruoho {
   1005  1.1  jruoho     ACPI_GENERIC_STATE      ScopeInfo;
   1006  1.1  jruoho     ACPI_STATUS             Status;
   1007  1.1  jruoho     char                    *InternalPath;
   1008  1.1  jruoho 
   1009  1.1  jruoho 
   1010  1.1  jruoho     ACPI_FUNCTION_TRACE_PTR (NsGetNode, ACPI_CAST_PTR (char, Pathname));
   1011  1.1  jruoho 
   1012  1.1  jruoho 
   1013  1.1  jruoho     if (!Pathname)
   1014  1.1  jruoho     {
   1015  1.1  jruoho         *ReturnNode = PrefixNode;
   1016  1.1  jruoho         if (!PrefixNode)
   1017  1.1  jruoho         {
   1018  1.1  jruoho             *ReturnNode = AcpiGbl_RootNode;
   1019  1.1  jruoho         }
   1020  1.1  jruoho         return_ACPI_STATUS (AE_OK);
   1021  1.1  jruoho     }
   1022  1.1  jruoho 
   1023  1.1  jruoho     /* Convert path to internal representation */
   1024  1.1  jruoho 
   1025  1.1  jruoho     Status = AcpiNsInternalizeName (Pathname, &InternalPath);
   1026  1.1  jruoho     if (ACPI_FAILURE (Status))
   1027  1.1  jruoho     {
   1028  1.1  jruoho         return_ACPI_STATUS (Status);
   1029  1.1  jruoho     }
   1030  1.1  jruoho 
   1031  1.1  jruoho     /* Must lock namespace during lookup */
   1032  1.1  jruoho 
   1033  1.1  jruoho     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
   1034  1.1  jruoho     if (ACPI_FAILURE (Status))
   1035  1.1  jruoho     {
   1036  1.1  jruoho         goto Cleanup;
   1037  1.1  jruoho     }
   1038  1.1  jruoho 
   1039  1.1  jruoho     /* Setup lookup scope (search starting point) */
   1040  1.1  jruoho 
   1041  1.1  jruoho     ScopeInfo.Scope.Node = PrefixNode;
   1042  1.1  jruoho 
   1043  1.1  jruoho     /* Lookup the name in the namespace */
   1044  1.1  jruoho 
   1045  1.1  jruoho     Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
   1046  1.1  jruoho                 ACPI_IMODE_EXECUTE, (Flags | ACPI_NS_DONT_OPEN_SCOPE),
   1047  1.1  jruoho                 NULL, ReturnNode);
   1048  1.1  jruoho     if (ACPI_FAILURE (Status))
   1049  1.1  jruoho     {
   1050  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "%s, %s\n",
   1051  1.1  jruoho                 Pathname, AcpiFormatException (Status)));
   1052  1.1  jruoho     }
   1053  1.1  jruoho 
   1054  1.1  jruoho     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
   1055  1.1  jruoho 
   1056  1.1  jruoho Cleanup:
   1057  1.1  jruoho     ACPI_FREE (InternalPath);
   1058  1.1  jruoho     return_ACPI_STATUS (Status);
   1059  1.1  jruoho }
   1060