13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
43446Smrj  *                        parents and siblings and Scope manipulation
5*7851SDana.Myers@Sun.COM  *              $Revision: 1.157 $
63446Smrj  *
73446Smrj  *****************************************************************************/
83446Smrj 
93446Smrj /******************************************************************************
103446Smrj  *
113446Smrj  * 1. Copyright Notice
123446Smrj  *
13*7851SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2008, Intel Corp.
143446Smrj  * All rights reserved.
153446Smrj  *
163446Smrj  * 2. License
173446Smrj  *
183446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
193446Smrj  * rights.  You may have additional license terms from the party that provided
203446Smrj  * you this software, covering your right to use that party's intellectual
213446Smrj  * property rights.
223446Smrj  *
233446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
243446Smrj  * copy of the source code appearing in this file ("Covered Code") an
253446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
263446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
273446Smrj  * make derivatives, distribute, use and display any portion of the Covered
283446Smrj  * Code in any form, with the right to sublicense such rights; and
293446Smrj  *
303446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
313446Smrj  * license (with the right to sublicense), under only those claims of Intel
323446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
333446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
343446Smrj  * solely to the minimum extent necessary to exercise the above copyright
353446Smrj  * license, and in no event shall the patent license extend to any additions
363446Smrj  * to or modifications of the Original Intel Code.  No other license or right
373446Smrj  * is granted directly or by implication, estoppel or otherwise;
383446Smrj  *
393446Smrj  * The above copyright and patent license is granted only if the following
403446Smrj  * conditions are met:
413446Smrj  *
423446Smrj  * 3. Conditions
433446Smrj  *
443446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
453446Smrj  * Redistribution of source code of any substantial portion of the Covered
463446Smrj  * Code or modification with rights to further distribute source must include
473446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
483446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
493446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
503446Smrj  * contain a file documenting the changes Licensee made to create that Covered
513446Smrj  * Code and the date of any change.  Licensee must include in that file the
523446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
533446Smrj  * must include a prominent statement that the modification is derived,
543446Smrj  * directly or indirectly, from Original Intel Code.
553446Smrj  *
563446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
573446Smrj  * Redistribution of source code of any substantial portion of the Covered
583446Smrj  * Code or modification without rights to further distribute source must
593446Smrj  * include the following Disclaimer and Export Compliance provision in the
603446Smrj  * documentation and/or other materials provided with distribution.  In
613446Smrj  * addition, Licensee may not authorize further sublicense of source of any
623446Smrj  * portion of the Covered Code, and must include terms to the effect that the
633446Smrj  * license from Licensee to its licensee is limited to the intellectual
643446Smrj  * property embodied in the software Licensee provides to its licensee, and
653446Smrj  * not to intellectual property embodied in modifications its licensee may
663446Smrj  * make.
673446Smrj  *
683446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
693446Smrj  * substantial portion of the Covered Code or modification must reproduce the
703446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
713446Smrj  * provision in the documentation and/or other materials provided with the
723446Smrj  * distribution.
733446Smrj  *
743446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
753446Smrj  * Intel Code.
763446Smrj  *
773446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
783446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
793446Smrj  * other dealings in products derived from or relating to the Covered Code
803446Smrj  * without prior written authorization from Intel.
813446Smrj  *
823446Smrj  * 4. Disclaimer and Export Compliance
833446Smrj  *
843446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
853446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
863446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
873446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
883446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
893446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
903446Smrj  * PARTICULAR PURPOSE.
913446Smrj  *
923446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
933446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
943446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
953446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
963446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
973446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
983446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
993446Smrj  * LIMITED REMEDY.
1003446Smrj  *
1013446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1023446Smrj  * software or system incorporating such software without first obtaining any
1033446Smrj  * required license or other approval from the U. S. Department of Commerce or
1043446Smrj  * any other agency or department of the United States Government.  In the
1053446Smrj  * event Licensee exports any such software from the United States or
1063446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1073446Smrj  * ensure that the distribution and export/re-export of the software is in
1083446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1093446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1103446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1113446Smrj  * software, or service, directly or indirectly, to any country for which the
1123446Smrj  * United States government or any agency thereof requires an export license,
1133446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1143446Smrj  * such license, approval or letter.
1153446Smrj  *
1163446Smrj  *****************************************************************************/
1173446Smrj 
1183446Smrj #define __NSUTILS_C__
1193446Smrj 
1203446Smrj #include "acpi.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj #include "amlcode.h"
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_NAMESPACE
1253446Smrj         ACPI_MODULE_NAME    ("nsutils")
1263446Smrj 
1273446Smrj /* Local prototypes */
1283446Smrj 
1293446Smrj static BOOLEAN
1303446Smrj AcpiNsValidPathSeparator (
1313446Smrj     char                    Sep);
1323446Smrj 
1333446Smrj #ifdef ACPI_OBSOLETE_FUNCTIONS
1343446Smrj ACPI_NAME
1353446Smrj AcpiNsFindParentName (
1363446Smrj     ACPI_NAMESPACE_NODE     *NodeToSearch);
1373446Smrj #endif
1383446Smrj 
1393446Smrj 
1403446Smrj /*******************************************************************************
1413446Smrj  *
1423446Smrj  * FUNCTION:    AcpiNsReportError
1433446Smrj  *
1443446Smrj  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
1453446Smrj  *              LineNumber          - Caller's line number (for error output)
1463446Smrj  *              InternalName        - Name or path of the namespace node
1473446Smrj  *              LookupStatus        - Exception code from NS lookup
1483446Smrj  *
1493446Smrj  * RETURN:      None
1503446Smrj  *
1513446Smrj  * DESCRIPTION: Print warning message with full pathname
1523446Smrj  *
1533446Smrj  ******************************************************************************/
1543446Smrj 
1553446Smrj void
1563446Smrj AcpiNsReportError (
157*7851SDana.Myers@Sun.COM     const char              *ModuleName,
1583446Smrj     UINT32                  LineNumber,
159*7851SDana.Myers@Sun.COM     const char              *InternalName,
1603446Smrj     ACPI_STATUS             LookupStatus)
1613446Smrj {
1623446Smrj     ACPI_STATUS             Status;
1633446Smrj     UINT32                  BadName;
1643446Smrj     char                    *Name = NULL;
1653446Smrj 
1663446Smrj 
1673446Smrj     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
1683446Smrj 
1693446Smrj     if (LookupStatus == AE_BAD_CHARACTER)
1703446Smrj     {
1713446Smrj         /* There is a non-ascii character in the name */
1723446Smrj 
1733446Smrj         ACPI_MOVE_32_TO_32 (&BadName, InternalName);
1743446Smrj         AcpiOsPrintf ("[0x%4.4X] (NON-ASCII)", BadName);
1753446Smrj     }
1763446Smrj     else
1773446Smrj     {
1783446Smrj         /* Convert path to external format */
1793446Smrj 
1803446Smrj         Status = AcpiNsExternalizeName (ACPI_UINT32_MAX,
1813446Smrj                     InternalName, NULL, &Name);
1823446Smrj 
1833446Smrj         /* Print target name */
1843446Smrj 
1853446Smrj         if (ACPI_SUCCESS (Status))
1863446Smrj         {
1873446Smrj             AcpiOsPrintf ("[%s]", Name);
1883446Smrj         }
1893446Smrj         else
1903446Smrj         {
1913446Smrj             AcpiOsPrintf ("[COULD NOT EXTERNALIZE NAME]");
1923446Smrj         }
1933446Smrj 
1943446Smrj         if (Name)
1953446Smrj         {
1963446Smrj             ACPI_FREE (Name);
1973446Smrj         }
1983446Smrj     }
1993446Smrj 
2003446Smrj     AcpiOsPrintf (" Namespace lookup failure, %s\n",
2013446Smrj         AcpiFormatException (LookupStatus));
2023446Smrj }
2033446Smrj 
2043446Smrj 
2053446Smrj /*******************************************************************************
2063446Smrj  *
2073446Smrj  * FUNCTION:    AcpiNsReportMethodError
2083446Smrj  *
2093446Smrj  * PARAMETERS:  ModuleName          - Caller's module name (for error output)
2103446Smrj  *              LineNumber          - Caller's line number (for error output)
2113446Smrj  *              Message             - Error message to use on failure
2123446Smrj  *              PrefixNode          - Prefix relative to the path
2133446Smrj  *              Path                - Path to the node (optional)
2143446Smrj  *              MethodStatus        - Execution status
2153446Smrj  *
2163446Smrj  * RETURN:      None
2173446Smrj  *
2183446Smrj  * DESCRIPTION: Print warning message with full pathname
2193446Smrj  *
2203446Smrj  ******************************************************************************/
2213446Smrj 
2223446Smrj void
2233446Smrj AcpiNsReportMethodError (
224*7851SDana.Myers@Sun.COM     const char              *ModuleName,
2253446Smrj     UINT32                  LineNumber,
226*7851SDana.Myers@Sun.COM     const char              *Message,
2273446Smrj     ACPI_NAMESPACE_NODE     *PrefixNode,
228*7851SDana.Myers@Sun.COM     const char              *Path,
2293446Smrj     ACPI_STATUS             MethodStatus)
2303446Smrj {
2313446Smrj     ACPI_STATUS             Status;
2323446Smrj     ACPI_NAMESPACE_NODE     *Node = PrefixNode;
2333446Smrj 
2343446Smrj 
2353446Smrj     AcpiOsPrintf ("ACPI Error (%s-%04d): ", ModuleName, LineNumber);
2363446Smrj 
2373446Smrj     if (Path)
2383446Smrj     {
2393446Smrj         Status = AcpiNsGetNode (PrefixNode, Path, ACPI_NS_NO_UPSEARCH,
2403446Smrj                     &Node);
2413446Smrj         if (ACPI_FAILURE (Status))
2423446Smrj         {
2433446Smrj             AcpiOsPrintf ("[Could not get node by pathname]");
2443446Smrj         }
2453446Smrj     }
2463446Smrj 
2473446Smrj     AcpiNsPrintNodePathname (Node, Message);
2483446Smrj     AcpiOsPrintf (", %s\n", AcpiFormatException (MethodStatus));
2493446Smrj }
2503446Smrj 
2513446Smrj 
2523446Smrj /*******************************************************************************
2533446Smrj  *
2543446Smrj  * FUNCTION:    AcpiNsPrintNodePathname
2553446Smrj  *
2563446Smrj  * PARAMETERS:  Node            - Object
2573446Smrj  *              Message         - Prefix message
2583446Smrj  *
2593446Smrj  * DESCRIPTION: Print an object's full namespace pathname
2603446Smrj  *              Manages allocation/freeing of a pathname buffer
2613446Smrj  *
2623446Smrj  ******************************************************************************/
2633446Smrj 
2643446Smrj void
2653446Smrj AcpiNsPrintNodePathname (
2663446Smrj     ACPI_NAMESPACE_NODE     *Node,
267*7851SDana.Myers@Sun.COM     const char              *Message)
2683446Smrj {
2693446Smrj     ACPI_BUFFER             Buffer;
2703446Smrj     ACPI_STATUS             Status;
2713446Smrj 
2723446Smrj 
2733446Smrj     if (!Node)
2743446Smrj     {
2753446Smrj         AcpiOsPrintf ("[NULL NAME]");
2763446Smrj         return;
2773446Smrj     }
2783446Smrj 
2793446Smrj     /* Convert handle to full pathname and print it (with supplied message) */
2803446Smrj 
2813446Smrj     Buffer.Length = ACPI_ALLOCATE_LOCAL_BUFFER;
2823446Smrj 
2833446Smrj     Status = AcpiNsHandleToPathname (Node, &Buffer);
2843446Smrj     if (ACPI_SUCCESS (Status))
2853446Smrj     {
2863446Smrj         if (Message)
2873446Smrj         {
2883446Smrj             AcpiOsPrintf ("%s ", Message);
2893446Smrj         }
2903446Smrj 
2913446Smrj         AcpiOsPrintf ("[%s] (Node %p)", (char *) Buffer.Pointer, Node);
2923446Smrj         ACPI_FREE (Buffer.Pointer);
2933446Smrj     }
2943446Smrj }
2953446Smrj 
2963446Smrj 
2973446Smrj /*******************************************************************************
2983446Smrj  *
2993446Smrj  * FUNCTION:    AcpiNsValidRootPrefix
3003446Smrj  *
3013446Smrj  * PARAMETERS:  Prefix          - Character to be checked
3023446Smrj  *
3033446Smrj  * RETURN:      TRUE if a valid prefix
3043446Smrj  *
3053446Smrj  * DESCRIPTION: Check if a character is a valid ACPI Root prefix
3063446Smrj  *
3073446Smrj  ******************************************************************************/
3083446Smrj 
3093446Smrj BOOLEAN
3103446Smrj AcpiNsValidRootPrefix (
3113446Smrj     char                    Prefix)
3123446Smrj {
3133446Smrj 
3143446Smrj     return ((BOOLEAN) (Prefix == '\\'));
3153446Smrj }
3163446Smrj 
3173446Smrj 
3183446Smrj /*******************************************************************************
3193446Smrj  *
3203446Smrj  * FUNCTION:    AcpiNsValidPathSeparator
3213446Smrj  *
3223446Smrj  * PARAMETERS:  Sep         - Character to be checked
3233446Smrj  *
3243446Smrj  * RETURN:      TRUE if a valid path separator
3253446Smrj  *
3263446Smrj  * DESCRIPTION: Check if a character is a valid ACPI path separator
3273446Smrj  *
3283446Smrj  ******************************************************************************/
3293446Smrj 
3303446Smrj static BOOLEAN
3313446Smrj AcpiNsValidPathSeparator (
3323446Smrj     char                    Sep)
3333446Smrj {
3343446Smrj 
3353446Smrj     return ((BOOLEAN) (Sep == '.'));
3363446Smrj }
3373446Smrj 
3383446Smrj 
3393446Smrj /*******************************************************************************
3403446Smrj  *
3413446Smrj  * FUNCTION:    AcpiNsGetType
3423446Smrj  *
3433446Smrj  * PARAMETERS:  Node        - Parent Node to be examined
3443446Smrj  *
3453446Smrj  * RETURN:      Type field from Node whose handle is passed
3463446Smrj  *
3473446Smrj  * DESCRIPTION: Return the type of a Namespace node
3483446Smrj  *
3493446Smrj  ******************************************************************************/
3503446Smrj 
3513446Smrj ACPI_OBJECT_TYPE
3523446Smrj AcpiNsGetType (
3533446Smrj     ACPI_NAMESPACE_NODE     *Node)
3543446Smrj {
3553446Smrj     ACPI_FUNCTION_TRACE (NsGetType);
3563446Smrj 
3573446Smrj 
3583446Smrj     if (!Node)
3593446Smrj     {
3603446Smrj         ACPI_WARNING ((AE_INFO, "Null Node parameter"));
3613446Smrj         return_UINT32 (ACPI_TYPE_ANY);
3623446Smrj     }
3633446Smrj 
3643446Smrj     return_UINT32 ((ACPI_OBJECT_TYPE) Node->Type);
3653446Smrj }
3663446Smrj 
3673446Smrj 
3683446Smrj /*******************************************************************************
3693446Smrj  *
3703446Smrj  * FUNCTION:    AcpiNsLocal
3713446Smrj  *
3723446Smrj  * PARAMETERS:  Type        - A namespace object type
3733446Smrj  *
3743446Smrj  * RETURN:      LOCAL if names must be found locally in objects of the
3753446Smrj  *              passed type, 0 if enclosing scopes should be searched
3763446Smrj  *
3773446Smrj  * DESCRIPTION: Returns scope rule for the given object type.
3783446Smrj  *
3793446Smrj  ******************************************************************************/
3803446Smrj 
3813446Smrj UINT32
3823446Smrj AcpiNsLocal (
3833446Smrj     ACPI_OBJECT_TYPE        Type)
3843446Smrj {
3853446Smrj     ACPI_FUNCTION_TRACE (NsLocal);
3863446Smrj 
3873446Smrj 
3883446Smrj     if (!AcpiUtValidObjectType (Type))
3893446Smrj     {
3903446Smrj         /* Type code out of range  */
3913446Smrj 
3923446Smrj         ACPI_WARNING ((AE_INFO, "Invalid Object Type %X", Type));
3933446Smrj         return_UINT32 (ACPI_NS_NORMAL);
3943446Smrj     }
3953446Smrj 
3963446Smrj     return_UINT32 ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
3973446Smrj }
3983446Smrj 
3993446Smrj 
4003446Smrj /*******************************************************************************
4013446Smrj  *
4023446Smrj  * FUNCTION:    AcpiNsGetInternalNameLength
4033446Smrj  *
4043446Smrj  * PARAMETERS:  Info            - Info struct initialized with the
4053446Smrj  *                                external name pointer.
4063446Smrj  *
4073446Smrj  * RETURN:      None
4083446Smrj  *
4093446Smrj  * DESCRIPTION: Calculate the length of the internal (AML) namestring
4103446Smrj  *              corresponding to the external (ASL) namestring.
4113446Smrj  *
4123446Smrj  ******************************************************************************/
4133446Smrj 
4143446Smrj void
4153446Smrj AcpiNsGetInternalNameLength (
4163446Smrj     ACPI_NAMESTRING_INFO    *Info)
4173446Smrj {
418*7851SDana.Myers@Sun.COM     const char              *NextExternalChar;
4193446Smrj     UINT32                  i;
4203446Smrj 
4213446Smrj 
4223446Smrj     ACPI_FUNCTION_ENTRY ();
4233446Smrj 
4243446Smrj 
4253446Smrj     NextExternalChar = Info->ExternalName;
4263446Smrj     Info->NumCarats = 0;
4273446Smrj     Info->NumSegments = 0;
4283446Smrj     Info->FullyQualified = FALSE;
4293446Smrj 
4303446Smrj     /*
4313446Smrj      * For the internal name, the required length is 4 bytes per segment, plus
4323446Smrj      * 1 each for RootPrefix, MultiNamePrefixOp, segment count, trailing null
4333446Smrj      * (which is not really needed, but no there's harm in putting it there)
4343446Smrj      *
4353446Smrj      * strlen() + 1 covers the first NameSeg, which has no path separator
4363446Smrj      */
4373446Smrj     if (AcpiNsValidRootPrefix (NextExternalChar[0]))
4383446Smrj     {
4393446Smrj         Info->FullyQualified = TRUE;
4403446Smrj         NextExternalChar++;
4413446Smrj     }
4423446Smrj     else
4433446Smrj     {
4443446Smrj         /*
4453446Smrj          * Handle Carat prefixes
4463446Smrj          */
4473446Smrj         while (*NextExternalChar == '^')
4483446Smrj         {
4493446Smrj             Info->NumCarats++;
4503446Smrj             NextExternalChar++;
4513446Smrj         }
4523446Smrj     }
4533446Smrj 
4543446Smrj     /*
4553446Smrj      * Determine the number of ACPI name "segments" by counting the number of
4563446Smrj      * path separators within the string. Start with one segment since the
4573446Smrj      * segment count is [(# separators) + 1], and zero separators is ok.
4583446Smrj      */
4593446Smrj     if (*NextExternalChar)
4603446Smrj     {
4613446Smrj         Info->NumSegments = 1;
4623446Smrj         for (i = 0; NextExternalChar[i]; i++)
4633446Smrj         {
4643446Smrj             if (AcpiNsValidPathSeparator (NextExternalChar[i]))
4653446Smrj             {
4663446Smrj                 Info->NumSegments++;
4673446Smrj             }
4683446Smrj         }
4693446Smrj     }
4703446Smrj 
4713446Smrj     Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
4723446Smrj                     4 + Info->NumCarats;
4733446Smrj 
4743446Smrj     Info->NextExternalChar = NextExternalChar;
4753446Smrj }
4763446Smrj 
4773446Smrj 
4783446Smrj /*******************************************************************************
4793446Smrj  *
4803446Smrj  * FUNCTION:    AcpiNsBuildInternalName
4813446Smrj  *
4823446Smrj  * PARAMETERS:  Info            - Info struct fully initialized
4833446Smrj  *
4843446Smrj  * RETURN:      Status
4853446Smrj  *
4863446Smrj  * DESCRIPTION: Construct the internal (AML) namestring
4873446Smrj  *              corresponding to the external (ASL) namestring.
4883446Smrj  *
4893446Smrj  ******************************************************************************/
4903446Smrj 
4913446Smrj ACPI_STATUS
4923446Smrj AcpiNsBuildInternalName (
4933446Smrj     ACPI_NAMESTRING_INFO    *Info)
4943446Smrj {
4953446Smrj     UINT32                  NumSegments = Info->NumSegments;
4963446Smrj     char                    *InternalName = Info->InternalName;
497*7851SDana.Myers@Sun.COM     const char              *ExternalName = Info->NextExternalChar;
4983446Smrj     char                    *Result = NULL;
499*7851SDana.Myers@Sun.COM     UINT32                  i;
5003446Smrj 
5013446Smrj 
5023446Smrj     ACPI_FUNCTION_TRACE (NsBuildInternalName);
5033446Smrj 
5043446Smrj 
5053446Smrj     /* Setup the correct prefixes, counts, and pointers */
5063446Smrj 
5073446Smrj     if (Info->FullyQualified)
5083446Smrj     {
5093446Smrj         InternalName[0] = '\\';
5103446Smrj 
5113446Smrj         if (NumSegments <= 1)
5123446Smrj         {
5133446Smrj             Result = &InternalName[1];
5143446Smrj         }
5153446Smrj         else if (NumSegments == 2)
5163446Smrj         {
5173446Smrj             InternalName[1] = AML_DUAL_NAME_PREFIX;
5183446Smrj             Result = &InternalName[2];
5193446Smrj         }
5203446Smrj         else
5213446Smrj         {
5223446Smrj             InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
5233446Smrj             InternalName[2] = (char) NumSegments;
5243446Smrj             Result = &InternalName[3];
5253446Smrj         }
5263446Smrj     }
5273446Smrj     else
5283446Smrj     {
5293446Smrj         /*
5303446Smrj          * Not fully qualified.
5313446Smrj          * Handle Carats first, then append the name segments
5323446Smrj          */
5333446Smrj         i = 0;
5343446Smrj         if (Info->NumCarats)
5353446Smrj         {
5363446Smrj             for (i = 0; i < Info->NumCarats; i++)
5373446Smrj             {
5383446Smrj                 InternalName[i] = '^';
5393446Smrj             }
5403446Smrj         }
5413446Smrj 
5423446Smrj         if (NumSegments <= 1)
5433446Smrj         {
5443446Smrj             Result = &InternalName[i];
5453446Smrj         }
5463446Smrj         else if (NumSegments == 2)
5473446Smrj         {
5483446Smrj             InternalName[i] = AML_DUAL_NAME_PREFIX;
549*7851SDana.Myers@Sun.COM             Result = &InternalName[(ACPI_SIZE) i+1];
5503446Smrj         }
5513446Smrj         else
5523446Smrj         {
5533446Smrj             InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
554*7851SDana.Myers@Sun.COM             InternalName[(ACPI_SIZE) i+1] = (char) NumSegments;
555*7851SDana.Myers@Sun.COM             Result = &InternalName[(ACPI_SIZE) i+2];
5563446Smrj         }
5573446Smrj     }
5583446Smrj 
5593446Smrj     /* Build the name (minus path separators) */
5603446Smrj 
5613446Smrj     for (; NumSegments; NumSegments--)
5623446Smrj     {
5633446Smrj         for (i = 0; i < ACPI_NAME_SIZE; i++)
5643446Smrj         {
5653446Smrj             if (AcpiNsValidPathSeparator (*ExternalName) ||
5663446Smrj                (*ExternalName == 0))
5673446Smrj             {
5683446Smrj                 /* Pad the segment with underscore(s) if segment is short */
5693446Smrj 
5703446Smrj                 Result[i] = '_';
5713446Smrj             }
5723446Smrj             else
5733446Smrj             {
5743446Smrj                 /* Convert the character to uppercase and save it */
5753446Smrj 
5763446Smrj                 Result[i] = (char) ACPI_TOUPPER ((int) *ExternalName);
5773446Smrj                 ExternalName++;
5783446Smrj             }
5793446Smrj         }
5803446Smrj 
5813446Smrj         /* Now we must have a path separator, or the pathname is bad */
5823446Smrj 
5833446Smrj         if (!AcpiNsValidPathSeparator (*ExternalName) &&
5843446Smrj             (*ExternalName != 0))
5853446Smrj         {
5863446Smrj             return_ACPI_STATUS (AE_BAD_PARAMETER);
5873446Smrj         }
5883446Smrj 
5893446Smrj         /* Move on the next segment */
5903446Smrj 
5913446Smrj         ExternalName++;
5923446Smrj         Result += ACPI_NAME_SIZE;
5933446Smrj     }
5943446Smrj 
5953446Smrj     /* Terminate the string */
5963446Smrj 
5973446Smrj     *Result = 0;
5983446Smrj 
5993446Smrj     if (Info->FullyQualified)
6003446Smrj     {
6013446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (abs) \"\\%s\"\n",
6023446Smrj             InternalName, InternalName));
6033446Smrj     }
6043446Smrj     else
6053446Smrj     {
6063446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Returning [%p] (rel) \"%s\"\n",
6073446Smrj             InternalName, InternalName));
6083446Smrj     }
6093446Smrj 
6103446Smrj     return_ACPI_STATUS (AE_OK);
6113446Smrj }
6123446Smrj 
6133446Smrj 
6143446Smrj /*******************************************************************************
6153446Smrj  *
6163446Smrj  * FUNCTION:    AcpiNsInternalizeName
6173446Smrj  *
6183446Smrj  * PARAMETERS:  *ExternalName           - External representation of name
6193446Smrj  *              **Converted Name        - Where to return the resulting
6203446Smrj  *                                        internal represention of the name
6213446Smrj  *
6223446Smrj  * RETURN:      Status
6233446Smrj  *
6243446Smrj  * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
6253446Smrj  *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
6263446Smrj  *
6273446Smrj  *******************************************************************************/
6283446Smrj 
6293446Smrj ACPI_STATUS
6303446Smrj AcpiNsInternalizeName (
631*7851SDana.Myers@Sun.COM     const char              *ExternalName,
6323446Smrj     char                    **ConvertedName)
6333446Smrj {
6343446Smrj     char                    *InternalName;
6353446Smrj     ACPI_NAMESTRING_INFO    Info;
6363446Smrj     ACPI_STATUS             Status;
6373446Smrj 
6383446Smrj 
6393446Smrj     ACPI_FUNCTION_TRACE (NsInternalizeName);
6403446Smrj 
6413446Smrj 
6423446Smrj     if ((!ExternalName)      ||
6433446Smrj         (*ExternalName == 0) ||
6443446Smrj         (!ConvertedName))
6453446Smrj     {
6463446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
6473446Smrj     }
6483446Smrj 
6493446Smrj     /* Get the length of the new internal name */
6503446Smrj 
6513446Smrj     Info.ExternalName = ExternalName;
6523446Smrj     AcpiNsGetInternalNameLength (&Info);
6533446Smrj 
6543446Smrj     /* We need a segment to store the internal  name */
6553446Smrj 
6563446Smrj     InternalName = ACPI_ALLOCATE_ZEROED (Info.Length);
6573446Smrj     if (!InternalName)
6583446Smrj     {
6593446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
6603446Smrj     }
6613446Smrj 
6623446Smrj     /* Build the name */
6633446Smrj 
6643446Smrj     Info.InternalName = InternalName;
6653446Smrj     Status = AcpiNsBuildInternalName (&Info);
6663446Smrj     if (ACPI_FAILURE (Status))
6673446Smrj     {
6683446Smrj         ACPI_FREE (InternalName);
6693446Smrj         return_ACPI_STATUS (Status);
6703446Smrj     }
6713446Smrj 
6723446Smrj     *ConvertedName = InternalName;
6733446Smrj     return_ACPI_STATUS (AE_OK);
6743446Smrj }
6753446Smrj 
6763446Smrj 
6773446Smrj /*******************************************************************************
6783446Smrj  *
6793446Smrj  * FUNCTION:    AcpiNsExternalizeName
6803446Smrj  *
6813446Smrj  * PARAMETERS:  InternalNameLength  - Lenth of the internal name below
6823446Smrj  *              InternalName        - Internal representation of name
6833446Smrj  *              ConvertedNameLength - Where the length is returned
6843446Smrj  *              ConvertedName       - Where the resulting external name
6853446Smrj  *                                    is returned
6863446Smrj  *
6873446Smrj  * RETURN:      Status
6883446Smrj  *
6893446Smrj  * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
6903446Smrj  *              to its external (printable) form (e.g. "\_PR_.CPU0")
6913446Smrj  *
6923446Smrj  ******************************************************************************/
6933446Smrj 
6943446Smrj ACPI_STATUS
6953446Smrj AcpiNsExternalizeName (
6963446Smrj     UINT32                  InternalNameLength,
697*7851SDana.Myers@Sun.COM     const char              *InternalName,
6983446Smrj     UINT32                  *ConvertedNameLength,
6993446Smrj     char                    **ConvertedName)
7003446Smrj {
701*7851SDana.Myers@Sun.COM     UINT32                  NamesIndex = 0;
702*7851SDana.Myers@Sun.COM     UINT32                  NumSegments = 0;
703*7851SDana.Myers@Sun.COM     UINT32                  RequiredLength;
704*7851SDana.Myers@Sun.COM     UINT32                  PrefixLength = 0;
705*7851SDana.Myers@Sun.COM     UINT32                  i = 0;
706*7851SDana.Myers@Sun.COM     UINT32                  j = 0;
7073446Smrj 
7083446Smrj 
7093446Smrj     ACPI_FUNCTION_TRACE (NsExternalizeName);
7103446Smrj 
7113446Smrj 
7123446Smrj     if (!InternalNameLength     ||
7133446Smrj         !InternalName           ||
7143446Smrj         !ConvertedName)
7153446Smrj     {
7163446Smrj         return_ACPI_STATUS (AE_BAD_PARAMETER);
7173446Smrj     }
7183446Smrj 
7193446Smrj     /*
7203446Smrj      * Check for a prefix (one '\' | one or more '^').
7213446Smrj      */
7223446Smrj     switch (InternalName[0])
7233446Smrj     {
7243446Smrj     case '\\':
7253446Smrj         PrefixLength = 1;
7263446Smrj         break;
7273446Smrj 
7283446Smrj     case '^':
7293446Smrj         for (i = 0; i < InternalNameLength; i++)
7303446Smrj         {
7313446Smrj             if (InternalName[i] == '^')
7323446Smrj             {
7333446Smrj                 PrefixLength = i + 1;
7343446Smrj             }
7353446Smrj             else
7363446Smrj             {
7373446Smrj                 break;
7383446Smrj             }
7393446Smrj         }
7403446Smrj 
7413446Smrj         if (i == InternalNameLength)
7423446Smrj         {
7433446Smrj             PrefixLength = i;
7443446Smrj         }
7453446Smrj 
7463446Smrj         break;
7473446Smrj 
7483446Smrj     default:
7493446Smrj         break;
7503446Smrj     }
7513446Smrj 
7523446Smrj     /*
7533446Smrj      * Check for object names.  Note that there could be 0-255 of these
7543446Smrj      * 4-byte elements.
7553446Smrj      */
7563446Smrj     if (PrefixLength < InternalNameLength)
7573446Smrj     {
7583446Smrj         switch (InternalName[PrefixLength])
7593446Smrj         {
7603446Smrj         case AML_MULTI_NAME_PREFIX_OP:
7613446Smrj 
7623446Smrj             /* <count> 4-byte names */
7633446Smrj 
7643446Smrj             NamesIndex = PrefixLength + 2;
765*7851SDana.Myers@Sun.COM             NumSegments = (UINT8)
766*7851SDana.Myers@Sun.COM                 InternalName[(ACPI_SIZE) PrefixLength + 1];
7673446Smrj             break;
7683446Smrj 
7693446Smrj         case AML_DUAL_NAME_PREFIX:
7703446Smrj 
7713446Smrj             /* Two 4-byte names */
7723446Smrj 
7733446Smrj             NamesIndex = PrefixLength + 1;
7743446Smrj             NumSegments = 2;
7753446Smrj             break;
7763446Smrj 
7773446Smrj         case 0:
7783446Smrj 
7793446Smrj             /* NullName */
7803446Smrj 
7813446Smrj             NamesIndex = 0;
7823446Smrj             NumSegments = 0;
7833446Smrj             break;
7843446Smrj 
7853446Smrj         default:
7863446Smrj 
7873446Smrj             /* one 4-byte name */
7883446Smrj 
7893446Smrj             NamesIndex = PrefixLength;
7903446Smrj             NumSegments = 1;
7913446Smrj             break;
7923446Smrj         }
7933446Smrj     }
7943446Smrj 
7953446Smrj     /*
7963446Smrj      * Calculate the length of ConvertedName, which equals the length
7973446Smrj      * of the prefix, length of all object names, length of any required
7983446Smrj      * punctuation ('.') between object names, plus the NULL terminator.
7993446Smrj      */
8003446Smrj     RequiredLength = PrefixLength + (4 * NumSegments) +
8013446Smrj                         ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
8023446Smrj 
8033446Smrj     /*
8043446Smrj      * Check to see if we're still in bounds.  If not, there's a problem
8053446Smrj      * with InternalName (invalid format).
8063446Smrj      */
8073446Smrj     if (RequiredLength > InternalNameLength)
8083446Smrj     {
8093446Smrj         ACPI_ERROR ((AE_INFO, "Invalid internal name"));
8103446Smrj         return_ACPI_STATUS (AE_BAD_PATHNAME);
8113446Smrj     }
8123446Smrj 
8133446Smrj     /*
8143446Smrj      * Build ConvertedName
8153446Smrj      */
8163446Smrj     *ConvertedName = ACPI_ALLOCATE_ZEROED (RequiredLength);
8173446Smrj     if (!(*ConvertedName))
8183446Smrj     {
8193446Smrj         return_ACPI_STATUS (AE_NO_MEMORY);
8203446Smrj     }
8213446Smrj 
8223446Smrj     j = 0;
8233446Smrj 
8243446Smrj     for (i = 0; i < PrefixLength; i++)
8253446Smrj     {
8263446Smrj         (*ConvertedName)[j++] = InternalName[i];
8273446Smrj     }
8283446Smrj 
8293446Smrj     if (NumSegments > 0)
8303446Smrj     {
8313446Smrj         for (i = 0; i < NumSegments; i++)
8323446Smrj         {
8333446Smrj             if (i > 0)
8343446Smrj             {
8353446Smrj                 (*ConvertedName)[j++] = '.';
8363446Smrj             }
8373446Smrj 
8383446Smrj             (*ConvertedName)[j++] = InternalName[NamesIndex++];
8393446Smrj             (*ConvertedName)[j++] = InternalName[NamesIndex++];
8403446Smrj             (*ConvertedName)[j++] = InternalName[NamesIndex++];
8413446Smrj             (*ConvertedName)[j++] = InternalName[NamesIndex++];
8423446Smrj         }
8433446Smrj     }
8443446Smrj 
8453446Smrj     if (ConvertedNameLength)
8463446Smrj     {
8473446Smrj         *ConvertedNameLength = (UINT32) RequiredLength;
8483446Smrj     }
8493446Smrj 
8503446Smrj     return_ACPI_STATUS (AE_OK);
8513446Smrj }
8523446Smrj 
8533446Smrj 
8543446Smrj /*******************************************************************************
8553446Smrj  *
8563446Smrj  * FUNCTION:    AcpiNsMapHandleToNode
8573446Smrj  *
8583446Smrj  * PARAMETERS:  Handle          - Handle to be converted to an Node
8593446Smrj  *
8603446Smrj  * RETURN:      A Name table entry pointer
8613446Smrj  *
8623446Smrj  * DESCRIPTION: Convert a namespace handle to a real Node
8633446Smrj  *
8643446Smrj  * Note: Real integer handles would allow for more verification
8653446Smrj  *       and keep all pointers within this subsystem - however this introduces
8663446Smrj  *       more (and perhaps unnecessary) overhead.
8673446Smrj  *
8683446Smrj  ******************************************************************************/
8693446Smrj 
8703446Smrj ACPI_NAMESPACE_NODE *
8713446Smrj AcpiNsMapHandleToNode (
8723446Smrj     ACPI_HANDLE             Handle)
8733446Smrj {
8743446Smrj 
8753446Smrj     ACPI_FUNCTION_ENTRY ();
8763446Smrj 
8773446Smrj 
8783446Smrj     /*
8793446Smrj      * Simple implementation
8803446Smrj      */
8813446Smrj     if ((!Handle) || (Handle == ACPI_ROOT_OBJECT))
8823446Smrj     {
8833446Smrj         return (AcpiGbl_RootNode);
8843446Smrj     }
8853446Smrj 
8863446Smrj     /* We can at least attempt to verify the handle */
8873446Smrj 
8883446Smrj     if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
8893446Smrj     {
8903446Smrj         return (NULL);
8913446Smrj     }
8923446Smrj 
8933446Smrj     return (ACPI_CAST_PTR (ACPI_NAMESPACE_NODE, Handle));
8943446Smrj }
8953446Smrj 
8963446Smrj 
8973446Smrj /*******************************************************************************
8983446Smrj  *
8993446Smrj  * FUNCTION:    AcpiNsConvertEntryToHandle
9003446Smrj  *
9013446Smrj  * PARAMETERS:  Node          - Node to be converted to a Handle
9023446Smrj  *
9033446Smrj  * RETURN:      A user handle
9043446Smrj  *
9053446Smrj  * DESCRIPTION: Convert a real Node to a namespace handle
9063446Smrj  *
9073446Smrj  ******************************************************************************/
9083446Smrj 
9093446Smrj ACPI_HANDLE
9103446Smrj AcpiNsConvertEntryToHandle (
9113446Smrj     ACPI_NAMESPACE_NODE         *Node)
9123446Smrj {
9133446Smrj 
9143446Smrj 
9153446Smrj     /*
9163446Smrj      * Simple implementation for now;
9173446Smrj      */
9183446Smrj     return ((ACPI_HANDLE) Node);
9193446Smrj 
9203446Smrj 
9213446Smrj /* Example future implementation ---------------------
9223446Smrj 
9233446Smrj     if (!Node)
9243446Smrj     {
9253446Smrj         return (NULL);
9263446Smrj     }
9273446Smrj 
9283446Smrj     if (Node == AcpiGbl_RootNode)
9293446Smrj     {
9303446Smrj         return (ACPI_ROOT_OBJECT);
9313446Smrj     }
9323446Smrj 
9333446Smrj 
9343446Smrj     return ((ACPI_HANDLE) Node);
9353446Smrj ------------------------------------------------------*/
9363446Smrj }
9373446Smrj 
9383446Smrj 
9393446Smrj /*******************************************************************************
9403446Smrj  *
9413446Smrj  * FUNCTION:    AcpiNsTerminate
9423446Smrj  *
9433446Smrj  * PARAMETERS:  none
9443446Smrj  *
9453446Smrj  * RETURN:      none
9463446Smrj  *
9473446Smrj  * DESCRIPTION: free memory allocated for namespace and ACPI table storage.
9483446Smrj  *
9493446Smrj  ******************************************************************************/
9503446Smrj 
9513446Smrj void
9523446Smrj AcpiNsTerminate (
9533446Smrj     void)
9543446Smrj {
9553446Smrj     ACPI_OPERAND_OBJECT     *ObjDesc;
9563446Smrj 
9573446Smrj 
9583446Smrj     ACPI_FUNCTION_TRACE (NsTerminate);
9593446Smrj 
9603446Smrj 
9613446Smrj     /*
9623446Smrj      * 1) Free the entire namespace -- all nodes and objects
9633446Smrj      *
9643446Smrj      * Delete all object descriptors attached to namepsace nodes
9653446Smrj      */
9663446Smrj     AcpiNsDeleteNamespaceSubtree (AcpiGbl_RootNode);
9673446Smrj 
9683446Smrj     /* Detach any objects attached to the root */
9693446Smrj 
9703446Smrj     ObjDesc = AcpiNsGetAttachedObject (AcpiGbl_RootNode);
9713446Smrj     if (ObjDesc)
9723446Smrj     {
9733446Smrj         AcpiNsDetachObject (AcpiGbl_RootNode);
9743446Smrj     }
9753446Smrj 
9763446Smrj     ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
9773446Smrj     return_VOID;
9783446Smrj }
9793446Smrj 
9803446Smrj 
9813446Smrj /*******************************************************************************
9823446Smrj  *
9833446Smrj  * FUNCTION:    AcpiNsOpensScope
9843446Smrj  *
9853446Smrj  * PARAMETERS:  Type        - A valid namespace type
9863446Smrj  *
9873446Smrj  * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
9883446Smrj  *              to the ACPI specification, else 0
9893446Smrj  *
9903446Smrj  ******************************************************************************/
9913446Smrj 
9923446Smrj UINT32
9933446Smrj AcpiNsOpensScope (
9943446Smrj     ACPI_OBJECT_TYPE        Type)
9953446Smrj {
9963446Smrj     ACPI_FUNCTION_TRACE_STR (NsOpensScope, AcpiUtGetTypeName (Type));
9973446Smrj 
9983446Smrj 
9993446Smrj     if (!AcpiUtValidObjectType (Type))
10003446Smrj     {
10013446Smrj         /* type code out of range  */
10023446Smrj 
10033446Smrj         ACPI_WARNING ((AE_INFO, "Invalid Object Type %X", Type));
10043446Smrj         return_UINT32 (ACPI_NS_NORMAL);
10053446Smrj     }
10063446Smrj 
10073446Smrj     return_UINT32 (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
10083446Smrj }
10093446Smrj 
10103446Smrj 
10113446Smrj /*******************************************************************************
10123446Smrj  *
10133446Smrj  * FUNCTION:    AcpiNsGetNode
10143446Smrj  *
10153446Smrj  * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
10163446Smrj  *                            \ (backslash) and ^ (carat) prefixes, and the
10173446Smrj  *                            . (period) to separate segments are supported.
10183446Smrj  *              PrefixNode   - Root of subtree to be searched, or NS_ALL for the
10193446Smrj  *                            root of the name space.  If Name is fully
10203446Smrj  *                            qualified (first INT8 is '\'), the passed value
10213446Smrj  *                            of Scope will not be accessed.
10223446Smrj  *              Flags       - Used to indicate whether to perform upsearch or
10233446Smrj  *                            not.
10243446Smrj  *              ReturnNode  - Where the Node is returned
10253446Smrj  *
10263446Smrj  * DESCRIPTION: Look up a name relative to a given scope and return the
10273446Smrj  *              corresponding Node.  NOTE: Scope can be null.
10283446Smrj  *
10293446Smrj  * MUTEX:       Locks namespace
10303446Smrj  *
10313446Smrj  ******************************************************************************/
10323446Smrj 
10333446Smrj ACPI_STATUS
10343446Smrj AcpiNsGetNode (
10353446Smrj     ACPI_NAMESPACE_NODE     *PrefixNode,
1036*7851SDana.Myers@Sun.COM     const char              *Pathname,
10373446Smrj     UINT32                  Flags,
10383446Smrj     ACPI_NAMESPACE_NODE     **ReturnNode)
10393446Smrj {
10403446Smrj     ACPI_GENERIC_STATE      ScopeInfo;
10413446Smrj     ACPI_STATUS             Status;
10423446Smrj     char                    *InternalPath;
10433446Smrj 
10443446Smrj 
10453446Smrj     ACPI_FUNCTION_TRACE_PTR (NsGetNode, Pathname);
10463446Smrj 
10473446Smrj 
10483446Smrj     if (!Pathname)
10493446Smrj     {
10503446Smrj         *ReturnNode = PrefixNode;
10513446Smrj         if (!PrefixNode)
10523446Smrj         {
10533446Smrj             *ReturnNode = AcpiGbl_RootNode;
10543446Smrj         }
10553446Smrj         return_ACPI_STATUS (AE_OK);
10563446Smrj     }
10573446Smrj 
10583446Smrj     /* Convert path to internal representation */
10593446Smrj 
10603446Smrj     Status = AcpiNsInternalizeName (Pathname, &InternalPath);
10613446Smrj     if (ACPI_FAILURE (Status))
10623446Smrj     {
10633446Smrj         return_ACPI_STATUS (Status);
10643446Smrj     }
10653446Smrj 
10663446Smrj     /* Must lock namespace during lookup */
10673446Smrj 
10683446Smrj     Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
10693446Smrj     if (ACPI_FAILURE (Status))
10703446Smrj     {
10713446Smrj         goto Cleanup;
10723446Smrj     }
10733446Smrj 
10743446Smrj     /* Setup lookup scope (search starting point) */
10753446Smrj 
10763446Smrj     ScopeInfo.Scope.Node = PrefixNode;
10773446Smrj 
10783446Smrj     /* Lookup the name in the namespace */
10793446Smrj 
10803446Smrj     Status = AcpiNsLookup (&ScopeInfo, InternalPath, ACPI_TYPE_ANY,
10813446Smrj                 ACPI_IMODE_EXECUTE, (Flags | ACPI_NS_DONT_OPEN_SCOPE),
10823446Smrj                 NULL, ReturnNode);
10833446Smrj     if (ACPI_FAILURE (Status))
10843446Smrj     {
10853446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
10863446Smrj                 Pathname, AcpiFormatException (Status)));
10873446Smrj     }
10883446Smrj 
10893446Smrj     (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
10903446Smrj 
10913446Smrj Cleanup:
10923446Smrj     ACPI_FREE (InternalPath);
10933446Smrj     return_ACPI_STATUS (Status);
10943446Smrj }
10953446Smrj 
10963446Smrj 
10973446Smrj /*******************************************************************************
10983446Smrj  *
10993446Smrj  * FUNCTION:    AcpiNsGetParentNode
11003446Smrj  *
11013446Smrj  * PARAMETERS:  Node       - Current table entry
11023446Smrj  *
11033446Smrj  * RETURN:      Parent entry of the given entry
11043446Smrj  *
11053446Smrj  * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
11063446Smrj  *
11073446Smrj  ******************************************************************************/
11083446Smrj 
11093446Smrj ACPI_NAMESPACE_NODE *
11103446Smrj AcpiNsGetParentNode (
11113446Smrj     ACPI_NAMESPACE_NODE     *Node)
11123446Smrj {
11133446Smrj     ACPI_FUNCTION_ENTRY ();
11143446Smrj 
11153446Smrj 
11163446Smrj     if (!Node)
11173446Smrj     {
11183446Smrj         return (NULL);
11193446Smrj     }
11203446Smrj 
11213446Smrj     /*
11223446Smrj      * Walk to the end of this peer list. The last entry is marked with a flag
11233446Smrj      * and the peer pointer is really a pointer back to the parent. This saves
11243446Smrj      * putting a parent back pointer in each and every named object!
11253446Smrj      */
11263446Smrj     while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
11273446Smrj     {
11283446Smrj         Node = Node->Peer;
11293446Smrj     }
11303446Smrj 
11313446Smrj     return (Node->Peer);
11323446Smrj }
11333446Smrj 
11343446Smrj 
11353446Smrj /*******************************************************************************
11363446Smrj  *
11373446Smrj  * FUNCTION:    AcpiNsGetNextValidNode
11383446Smrj  *
11393446Smrj  * PARAMETERS:  Node       - Current table entry
11403446Smrj  *
11413446Smrj  * RETURN:      Next valid Node in the linked node list. NULL if no more valid
11423446Smrj  *              nodes.
11433446Smrj  *
11443446Smrj  * DESCRIPTION: Find the next valid node within a name table.
11453446Smrj  *              Useful for implementing NULL-end-of-list loops.
11463446Smrj  *
11473446Smrj  ******************************************************************************/
11483446Smrj 
11493446Smrj ACPI_NAMESPACE_NODE *
11503446Smrj AcpiNsGetNextValidNode (
11513446Smrj     ACPI_NAMESPACE_NODE     *Node)
11523446Smrj {
11533446Smrj 
11543446Smrj     /* If we are at the end of this peer list, return NULL */
11553446Smrj 
11563446Smrj     if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
11573446Smrj     {
11583446Smrj         return NULL;
11593446Smrj     }
11603446Smrj 
11613446Smrj     /* Otherwise just return the next peer */
11623446Smrj 
11633446Smrj     return (Node->Peer);
11643446Smrj }
11653446Smrj 
11663446Smrj 
11673446Smrj #ifdef ACPI_OBSOLETE_FUNCTIONS
11683446Smrj /*******************************************************************************
11693446Smrj  *
11703446Smrj  * FUNCTION:    AcpiNsFindParentName
11713446Smrj  *
11723446Smrj  * PARAMETERS:  *ChildNode             - Named Obj whose name is to be found
11733446Smrj  *
11743446Smrj  * RETURN:      The ACPI name
11753446Smrj  *
11763446Smrj  * DESCRIPTION: Search for the given obj in its parent scope and return the
11773446Smrj  *              name segment, or "????" if the parent name can't be found
11783446Smrj  *              (which "should not happen").
11793446Smrj  *
11803446Smrj  ******************************************************************************/
11813446Smrj 
11823446Smrj ACPI_NAME
11833446Smrj AcpiNsFindParentName (
11843446Smrj     ACPI_NAMESPACE_NODE     *ChildNode)
11853446Smrj {
11863446Smrj     ACPI_NAMESPACE_NODE     *ParentNode;
11873446Smrj 
11883446Smrj 
11893446Smrj     ACPI_FUNCTION_TRACE (NsFindParentName);
11903446Smrj 
11913446Smrj 
11923446Smrj     if (ChildNode)
11933446Smrj     {
11943446Smrj         /* Valid entry.  Get the parent Node */
11953446Smrj 
11963446Smrj         ParentNode = AcpiNsGetParentNode (ChildNode);
11973446Smrj         if (ParentNode)
11983446Smrj         {
11993446Smrj             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
12003446Smrj                 "Parent of %p [%4.4s] is %p [%4.4s]\n",
12013446Smrj                 ChildNode,  AcpiUtGetNodeName (ChildNode),
12023446Smrj                 ParentNode, AcpiUtGetNodeName (ParentNode)));
12033446Smrj 
12043446Smrj             if (ParentNode->Name.Integer)
12053446Smrj             {
12063446Smrj                 return_VALUE ((ACPI_NAME) ParentNode->Name.Integer);
12073446Smrj             }
12083446Smrj         }
12093446Smrj 
12103446Smrj         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
12113446Smrj             "Unable to find parent of %p (%4.4s)\n",
12123446Smrj             ChildNode, AcpiUtGetNodeName (ChildNode)));
12133446Smrj     }
12143446Smrj 
12153446Smrj     return_VALUE (ACPI_UNKNOWN_NAME);
12163446Smrj }
12173446Smrj #endif
12183446Smrj 
12193446Smrj 
1220