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