nsutils.c revision 99146
167754Smsmith/******************************************************************************
267754Smsmith *
367754Smsmith * Module Name: nsutils - Utilities for accessing ACPI namespace, accessing
467754Smsmith *                        parents and siblings and Scope manipulation
599146Siwasaki *              $Revision: 105 $
667754Smsmith *
767754Smsmith *****************************************************************************/
867754Smsmith
967754Smsmith/******************************************************************************
1067754Smsmith *
1167754Smsmith * 1. Copyright Notice
1267754Smsmith *
1391116Smsmith * Some or all of this work - Copyright (c) 1999 - 2002, Intel Corp.
1470243Smsmith * All rights reserved.
1567754Smsmith *
1667754Smsmith * 2. License
1767754Smsmith *
1867754Smsmith * 2.1. This is your license from Intel Corp. under its intellectual property
1967754Smsmith * rights.  You may have additional license terms from the party that provided
2067754Smsmith * you this software, covering your right to use that party's intellectual
2167754Smsmith * property rights.
2267754Smsmith *
2367754Smsmith * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
2467754Smsmith * copy of the source code appearing in this file ("Covered Code") an
2567754Smsmith * irrevocable, perpetual, worldwide license under Intel's copyrights in the
2667754Smsmith * base code distributed originally by Intel ("Original Intel Code") to copy,
2767754Smsmith * make derivatives, distribute, use and display any portion of the Covered
2867754Smsmith * Code in any form, with the right to sublicense such rights; and
2967754Smsmith *
3067754Smsmith * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
3167754Smsmith * license (with the right to sublicense), under only those claims of Intel
3267754Smsmith * patents that are infringed by the Original Intel Code, to make, use, sell,
3367754Smsmith * offer to sell, and import the Covered Code and derivative works thereof
3467754Smsmith * solely to the minimum extent necessary to exercise the above copyright
3567754Smsmith * license, and in no event shall the patent license extend to any additions
3667754Smsmith * to or modifications of the Original Intel Code.  No other license or right
3767754Smsmith * is granted directly or by implication, estoppel or otherwise;
3867754Smsmith *
3967754Smsmith * The above copyright and patent license is granted only if the following
4067754Smsmith * conditions are met:
4167754Smsmith *
4267754Smsmith * 3. Conditions
4367754Smsmith *
4467754Smsmith * 3.1. Redistribution of Source with Rights to Further Distribute Source.
4567754Smsmith * Redistribution of source code of any substantial portion of the Covered
4667754Smsmith * Code or modification with rights to further distribute source must include
4767754Smsmith * the above Copyright Notice, the above License, this list of Conditions,
4867754Smsmith * and the following Disclaimer and Export Compliance provision.  In addition,
4967754Smsmith * Licensee must cause all Covered Code to which Licensee contributes to
5067754Smsmith * contain a file documenting the changes Licensee made to create that Covered
5167754Smsmith * Code and the date of any change.  Licensee must include in that file the
5267754Smsmith * documentation of any changes made by any predecessor Licensee.  Licensee
5367754Smsmith * must include a prominent statement that the modification is derived,
5467754Smsmith * directly or indirectly, from Original Intel Code.
5567754Smsmith *
5667754Smsmith * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
5767754Smsmith * Redistribution of source code of any substantial portion of the Covered
5867754Smsmith * Code or modification without rights to further distribute source must
5967754Smsmith * include the following Disclaimer and Export Compliance provision in the
6067754Smsmith * documentation and/or other materials provided with distribution.  In
6167754Smsmith * addition, Licensee may not authorize further sublicense of source of any
6267754Smsmith * portion of the Covered Code, and must include terms to the effect that the
6367754Smsmith * license from Licensee to its licensee is limited to the intellectual
6467754Smsmith * property embodied in the software Licensee provides to its licensee, and
6567754Smsmith * not to intellectual property embodied in modifications its licensee may
6667754Smsmith * make.
6767754Smsmith *
6867754Smsmith * 3.3. Redistribution of Executable. Redistribution in executable form of any
6967754Smsmith * substantial portion of the Covered Code or modification must reproduce the
7067754Smsmith * above Copyright Notice, and the following Disclaimer and Export Compliance
7167754Smsmith * provision in the documentation and/or other materials provided with the
7267754Smsmith * distribution.
7367754Smsmith *
7467754Smsmith * 3.4. Intel retains all right, title, and interest in and to the Original
7567754Smsmith * Intel Code.
7667754Smsmith *
7767754Smsmith * 3.5. Neither the name Intel nor any other trademark owned or controlled by
7867754Smsmith * Intel shall be used in advertising or otherwise to promote the sale, use or
7967754Smsmith * other dealings in products derived from or relating to the Covered Code
8067754Smsmith * without prior written authorization from Intel.
8167754Smsmith *
8267754Smsmith * 4. Disclaimer and Export Compliance
8367754Smsmith *
8467754Smsmith * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
8567754Smsmith * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
8667754Smsmith * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
8767754Smsmith * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
8867754Smsmith * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
8967754Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
9067754Smsmith * PARTICULAR PURPOSE.
9167754Smsmith *
9267754Smsmith * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
9367754Smsmith * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
9467754Smsmith * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
9567754Smsmith * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
9667754Smsmith * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
9767754Smsmith * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
9867754Smsmith * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
9967754Smsmith * LIMITED REMEDY.
10067754Smsmith *
10167754Smsmith * 4.3. Licensee shall not export, either directly or indirectly, any of this
10267754Smsmith * software or system incorporating such software without first obtaining any
10367754Smsmith * required license or other approval from the U. S. Department of Commerce or
10467754Smsmith * any other agency or department of the United States Government.  In the
10567754Smsmith * event Licensee exports any such software from the United States or
10667754Smsmith * re-exports any such software from a foreign destination, Licensee shall
10767754Smsmith * ensure that the distribution and export/re-export of the software is in
10867754Smsmith * compliance with all laws, regulations, orders, or other restrictions of the
10967754Smsmith * U.S. Export Administration Regulations. Licensee agrees that neither it nor
11067754Smsmith * any of its subsidiaries will export/re-export any technical data, process,
11167754Smsmith * software, or service, directly or indirectly, to any country for which the
11267754Smsmith * United States government or any agency thereof requires an export license,
11367754Smsmith * other governmental approval, or letter of assurance, without first obtaining
11467754Smsmith * such license, approval or letter.
11567754Smsmith *
11667754Smsmith *****************************************************************************/
11767754Smsmith
11867754Smsmith#define __NSUTILS_C__
11967754Smsmith
12067754Smsmith#include "acpi.h"
12167754Smsmith#include "acnamesp.h"
12267754Smsmith#include "acinterp.h"
12367754Smsmith#include "amlcode.h"
12467754Smsmith#include "actables.h"
12567754Smsmith
12677424Smsmith#define _COMPONENT          ACPI_NAMESPACE
12791116Smsmith        ACPI_MODULE_NAME    ("nsutils")
12867754Smsmith
12967754Smsmith
13077424Smsmith/*******************************************************************************
13167754Smsmith *
13267754Smsmith * FUNCTION:    AcpiNsValidRootPrefix
13367754Smsmith *
13467754Smsmith * PARAMETERS:  Prefix          - Character to be checked
13567754Smsmith *
13667754Smsmith * RETURN:      TRUE if a valid prefix
13767754Smsmith *
13867754Smsmith * DESCRIPTION: Check if a character is a valid ACPI Root prefix
13967754Smsmith *
14077424Smsmith ******************************************************************************/
14167754Smsmith
14267754SmsmithBOOLEAN
14367754SmsmithAcpiNsValidRootPrefix (
14467754Smsmith    NATIVE_CHAR             Prefix)
14567754Smsmith{
14667754Smsmith
14767754Smsmith    return ((BOOLEAN) (Prefix == '\\'));
14867754Smsmith}
14967754Smsmith
15067754Smsmith
15177424Smsmith/*******************************************************************************
15267754Smsmith *
15367754Smsmith * FUNCTION:    AcpiNsValidPathSeparator
15467754Smsmith *
15567754Smsmith * PARAMETERS:  Sep              - Character to be checked
15667754Smsmith *
15767754Smsmith * RETURN:      TRUE if a valid path separator
15867754Smsmith *
15967754Smsmith * DESCRIPTION: Check if a character is a valid ACPI path separator
16067754Smsmith *
16177424Smsmith ******************************************************************************/
16267754Smsmith
16367754SmsmithBOOLEAN
16467754SmsmithAcpiNsValidPathSeparator (
16567754Smsmith    NATIVE_CHAR             Sep)
16667754Smsmith{
16767754Smsmith
16867754Smsmith    return ((BOOLEAN) (Sep == '.'));
16967754Smsmith}
17067754Smsmith
17167754Smsmith
17277424Smsmith/*******************************************************************************
17367754Smsmith *
17467754Smsmith * FUNCTION:    AcpiNsGetType
17567754Smsmith *
17667754Smsmith * PARAMETERS:  Handle              - Parent Node to be examined
17767754Smsmith *
17867754Smsmith * RETURN:      Type field from Node whose handle is passed
17967754Smsmith *
18077424Smsmith ******************************************************************************/
18167754Smsmith
18291116SmsmithACPI_OBJECT_TYPE
18367754SmsmithAcpiNsGetType (
18477424Smsmith    ACPI_NAMESPACE_NODE     *Node)
18567754Smsmith{
18691116Smsmith    ACPI_FUNCTION_TRACE ("NsGetType");
18767754Smsmith
18867754Smsmith
18977424Smsmith    if (!Node)
19067754Smsmith    {
19191116Smsmith        ACPI_REPORT_WARNING (("NsGetType: Null Node ptr"));
19267754Smsmith        return_VALUE (ACPI_TYPE_ANY);
19367754Smsmith    }
19467754Smsmith
19591116Smsmith    return_VALUE ((ACPI_OBJECT_TYPE) Node->Type);
19667754Smsmith}
19767754Smsmith
19867754Smsmith
19977424Smsmith/*******************************************************************************
20067754Smsmith *
20167754Smsmith * FUNCTION:    AcpiNsLocal
20267754Smsmith *
20367754Smsmith * PARAMETERS:  Type            - A namespace object type
20467754Smsmith *
20567754Smsmith * RETURN:      LOCAL if names must be found locally in objects of the
20667754Smsmith *              passed type, 0 if enclosing scopes should be searched
20767754Smsmith *
20877424Smsmith ******************************************************************************/
20967754Smsmith
21067754SmsmithUINT32
21167754SmsmithAcpiNsLocal (
21291116Smsmith    ACPI_OBJECT_TYPE        Type)
21367754Smsmith{
21491116Smsmith    ACPI_FUNCTION_TRACE ("NsLocal");
21567754Smsmith
21667754Smsmith
21777424Smsmith    if (!AcpiUtValidObjectType (Type))
21867754Smsmith    {
21967754Smsmith        /* Type code out of range  */
22067754Smsmith
22191116Smsmith        ACPI_REPORT_WARNING (("NsLocal: Invalid Object Type\n"));
22291116Smsmith        return_VALUE (ACPI_NS_NORMAL);
22367754Smsmith    }
22467754Smsmith
22591116Smsmith    return_VALUE ((UINT32) AcpiGbl_NsProperties[Type] & ACPI_NS_LOCAL);
22667754Smsmith}
22767754Smsmith
22867754Smsmith
22977424Smsmith/*******************************************************************************
23067754Smsmith *
23177424Smsmith * FUNCTION:    AcpiNsGetInternalNameLength
23267754Smsmith *
23383174Smsmith * PARAMETERS:  Info            - Info struct initialized with the
23477424Smsmith *                                external name pointer.
23567754Smsmith *
23667754Smsmith * RETURN:      Status
23767754Smsmith *
23883174Smsmith * DESCRIPTION: Calculate the length of the internal (AML) namestring
23977424Smsmith *              corresponding to the external (ASL) namestring.
24067754Smsmith *
24177424Smsmith ******************************************************************************/
24267754Smsmith
24367754SmsmithACPI_STATUS
24477424SmsmithAcpiNsGetInternalNameLength (
24577424Smsmith    ACPI_NAMESTRING_INFO    *Info)
24667754Smsmith{
24777424Smsmith    NATIVE_CHAR             *NextExternalChar;
24867754Smsmith    UINT32                  i;
24967754Smsmith
25067754Smsmith
25191116Smsmith    ACPI_FUNCTION_ENTRY ();
25283174Smsmith
25383174Smsmith
25477424Smsmith    NextExternalChar = Info->ExternalName;
25577424Smsmith    Info->NumCarats = 0;
25677424Smsmith    Info->NumSegments = 0;
25777424Smsmith    Info->FullyQualified = FALSE;
25883174Smsmith
25967754Smsmith    /*
26067754Smsmith     * For the internal name, the required length is 4 bytes
26167754Smsmith     * per segment, plus 1 each for RootPrefix, MultiNamePrefixOp,
26267754Smsmith     * segment count, trailing null (which is not really needed,
26367754Smsmith     * but no there's harm in putting it there)
26467754Smsmith     *
26567754Smsmith     * strlen() + 1 covers the first NameSeg, which has no
26667754Smsmith     * path separator
26767754Smsmith     */
26877424Smsmith    if (AcpiNsValidRootPrefix (NextExternalChar[0]))
26967754Smsmith    {
27077424Smsmith        Info->FullyQualified = TRUE;
27177424Smsmith        NextExternalChar++;
27267754Smsmith    }
27369450Smsmith    else
27469450Smsmith    {
27569450Smsmith        /*
27669450Smsmith         * Handle Carat prefixes
27769450Smsmith         */
27877424Smsmith        while (*NextExternalChar == '^')
27969450Smsmith        {
28077424Smsmith            Info->NumCarats++;
28177424Smsmith            NextExternalChar++;
28269450Smsmith        }
28369450Smsmith    }
28469450Smsmith
28567754Smsmith    /*
28667754Smsmith     * Determine the number of ACPI name "segments" by counting
28767754Smsmith     * the number of path separators within the string.  Start
28867754Smsmith     * with one segment since the segment count is (# separators)
28967754Smsmith     * + 1, and zero separators is ok.
29067754Smsmith     */
29177424Smsmith    if (*NextExternalChar)
29267754Smsmith    {
29377424Smsmith        Info->NumSegments = 1;
29477424Smsmith        for (i = 0; NextExternalChar[i]; i++)
29567754Smsmith        {
29677424Smsmith            if (AcpiNsValidPathSeparator (NextExternalChar[i]))
29769450Smsmith            {
29877424Smsmith                Info->NumSegments++;
29969450Smsmith            }
30067754Smsmith        }
30167754Smsmith    }
30267754Smsmith
30383174Smsmith    Info->Length = (ACPI_NAME_SIZE * Info->NumSegments) +
30477424Smsmith                    4 + Info->NumCarats;
30567754Smsmith
30677424Smsmith    Info->NextExternalChar = NextExternalChar;
30767754Smsmith
30877424Smsmith    return (AE_OK);
30977424Smsmith}
31067754Smsmith
31167754Smsmith
31277424Smsmith/*******************************************************************************
31377424Smsmith *
31477424Smsmith * FUNCTION:    AcpiNsBuildInternalName
31577424Smsmith *
31677424Smsmith * PARAMETERS:  Info            - Info struct fully initialized
31777424Smsmith *
31877424Smsmith * RETURN:      Status
31977424Smsmith *
32083174Smsmith * DESCRIPTION: Construct the internal (AML) namestring
32177424Smsmith *              corresponding to the external (ASL) namestring.
32277424Smsmith *
32377424Smsmith ******************************************************************************/
32477424Smsmith
32577424SmsmithACPI_STATUS
32677424SmsmithAcpiNsBuildInternalName (
32777424Smsmith    ACPI_NAMESTRING_INFO    *Info)
32877424Smsmith{
32977424Smsmith    UINT32                  NumSegments = Info->NumSegments;
33077424Smsmith    NATIVE_CHAR             *InternalName = Info->InternalName;
33177424Smsmith    NATIVE_CHAR             *ExternalName = Info->NextExternalChar;
33277424Smsmith    NATIVE_CHAR             *Result = NULL;
33377424Smsmith    UINT32                  i;
33477424Smsmith
33577424Smsmith
33691116Smsmith    ACPI_FUNCTION_TRACE ("NsBuildInternalName");
33777424Smsmith
33883174Smsmith
33967754Smsmith    /* Setup the correct prefixes, counts, and pointers */
34067754Smsmith
34177424Smsmith    if (Info->FullyQualified)
34267754Smsmith    {
34367754Smsmith        InternalName[0] = '\\';
34469450Smsmith
34569450Smsmith        if (NumSegments <= 1)
34669450Smsmith        {
34769450Smsmith            Result = &InternalName[1];
34869450Smsmith        }
34969450Smsmith        else if (NumSegments == 2)
35069450Smsmith        {
35169450Smsmith            InternalName[1] = AML_DUAL_NAME_PREFIX;
35269450Smsmith            Result = &InternalName[2];
35369450Smsmith        }
35469450Smsmith        else
35569450Smsmith        {
35669450Smsmith            InternalName[1] = AML_MULTI_NAME_PREFIX_OP;
35769450Smsmith            InternalName[2] = (char) NumSegments;
35869450Smsmith            Result = &InternalName[3];
35969450Smsmith        }
36067754Smsmith    }
36167754Smsmith    else
36267754Smsmith    {
36369450Smsmith        /*
36469450Smsmith         * Not fully qualified.
36569450Smsmith         * Handle Carats first, then append the name segments
36669450Smsmith         */
36769450Smsmith        i = 0;
36877424Smsmith        if (Info->NumCarats)
36969450Smsmith        {
37077424Smsmith            for (i = 0; i < Info->NumCarats; i++)
37169450Smsmith            {
37269450Smsmith                InternalName[i] = '^';
37369450Smsmith            }
37469450Smsmith        }
37569450Smsmith
37691116Smsmith        if (NumSegments <= 1)
37769450Smsmith        {
37869450Smsmith            Result = &InternalName[i];
37969450Smsmith        }
38069450Smsmith        else if (NumSegments == 2)
38169450Smsmith        {
38269450Smsmith            InternalName[i] = AML_DUAL_NAME_PREFIX;
38369450Smsmith            Result = &InternalName[i+1];
38469450Smsmith        }
38569450Smsmith        else
38669450Smsmith        {
38769450Smsmith            InternalName[i] = AML_MULTI_NAME_PREFIX_OP;
38869450Smsmith            InternalName[i+1] = (char) NumSegments;
38969450Smsmith            Result = &InternalName[i+2];
39069450Smsmith        }
39167754Smsmith    }
39267754Smsmith
39367754Smsmith    /* Build the name (minus path separators) */
39467754Smsmith
39567754Smsmith    for (; NumSegments; NumSegments--)
39667754Smsmith    {
39767754Smsmith        for (i = 0; i < ACPI_NAME_SIZE; i++)
39867754Smsmith        {
39967754Smsmith            if (AcpiNsValidPathSeparator (*ExternalName) ||
40067754Smsmith               (*ExternalName == 0))
40167754Smsmith            {
40277424Smsmith                /* Pad the segment with underscore(s) if segment is short */
40367754Smsmith
40467754Smsmith                Result[i] = '_';
40567754Smsmith            }
40667754Smsmith            else
40767754Smsmith            {
40877424Smsmith                /* Convert the character to uppercase and save it */
40967754Smsmith
41091116Smsmith                Result[i] = (char) ACPI_TOUPPER (*ExternalName);
41167754Smsmith                ExternalName++;
41267754Smsmith            }
41367754Smsmith        }
41467754Smsmith
41567754Smsmith        /* Now we must have a path separator, or the pathname is bad */
41667754Smsmith
41767754Smsmith        if (!AcpiNsValidPathSeparator (*ExternalName) &&
41867754Smsmith            (*ExternalName != 0))
41967754Smsmith        {
42067754Smsmith            return_ACPI_STATUS (AE_BAD_PARAMETER);
42167754Smsmith        }
42267754Smsmith
42367754Smsmith        /* Move on the next segment */
42467754Smsmith
42567754Smsmith        ExternalName++;
42667754Smsmith        Result += ACPI_NAME_SIZE;
42767754Smsmith    }
42867754Smsmith
42977424Smsmith    /* Terminate the string */
43067754Smsmith
43167754Smsmith    *Result = 0;
43267754Smsmith
43377424Smsmith    if (Info->FullyQualified)
43467754Smsmith    {
43582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (abs) \"\\%s\"\n",
43699146Siwasaki            InternalName, InternalName));
43767754Smsmith    }
43867754Smsmith    else
43967754Smsmith    {
44082367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "returning [%p] (rel) \"%s\"\n",
44199146Siwasaki            InternalName, InternalName));
44267754Smsmith    }
44367754Smsmith
44467754Smsmith    return_ACPI_STATUS (AE_OK);
44567754Smsmith}
44667754Smsmith
44767754Smsmith
44877424Smsmith/*******************************************************************************
44967754Smsmith *
45077424Smsmith * FUNCTION:    AcpiNsInternalizeName
45177424Smsmith *
45277424Smsmith * PARAMETERS:  *ExternalName           - External representation of name
45377424Smsmith *              **Converted Name        - Where to return the resulting
45477424Smsmith *                                        internal represention of the name
45577424Smsmith *
45677424Smsmith * RETURN:      Status
45777424Smsmith *
45877424Smsmith * DESCRIPTION: Convert an external representation (e.g. "\_PR_.CPU0")
45977424Smsmith *              to internal form (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
46077424Smsmith *
46177424Smsmith *******************************************************************************/
46277424Smsmith
46377424SmsmithACPI_STATUS
46477424SmsmithAcpiNsInternalizeName (
46577424Smsmith    NATIVE_CHAR             *ExternalName,
46677424Smsmith    NATIVE_CHAR             **ConvertedName)
46777424Smsmith{
46877424Smsmith    NATIVE_CHAR             *InternalName;
46977424Smsmith    ACPI_NAMESTRING_INFO    Info;
47077424Smsmith    ACPI_STATUS             Status;
47177424Smsmith
47277424Smsmith
47391116Smsmith    ACPI_FUNCTION_TRACE ("NsInternalizeName");
47477424Smsmith
47577424Smsmith
47677424Smsmith    if ((!ExternalName)      ||
47777424Smsmith        (*ExternalName == 0) ||
47877424Smsmith        (!ConvertedName))
47977424Smsmith    {
48077424Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
48177424Smsmith    }
48277424Smsmith
48377424Smsmith    /* Get the length of the new internal name */
48477424Smsmith
48577424Smsmith    Info.ExternalName = ExternalName;
48677424Smsmith    AcpiNsGetInternalNameLength (&Info);
48777424Smsmith
48877424Smsmith    /* We need a segment to store the internal  name */
48977424Smsmith
49080062Smsmith    InternalName = ACPI_MEM_CALLOCATE (Info.Length);
49177424Smsmith    if (!InternalName)
49277424Smsmith    {
49377424Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
49477424Smsmith    }
49577424Smsmith
49677424Smsmith    /* Build the name */
49777424Smsmith
49877424Smsmith    Info.InternalName = InternalName;
49977424Smsmith    Status = AcpiNsBuildInternalName (&Info);
50077424Smsmith    if (ACPI_FAILURE (Status))
50177424Smsmith    {
50280062Smsmith        ACPI_MEM_FREE (InternalName);
50377424Smsmith        return_ACPI_STATUS (Status);
50477424Smsmith    }
50577424Smsmith
50677424Smsmith    *ConvertedName = InternalName;
50777424Smsmith    return_ACPI_STATUS (AE_OK);
50877424Smsmith}
50977424Smsmith
51077424Smsmith
51177424Smsmith/*******************************************************************************
51277424Smsmith *
51367754Smsmith * FUNCTION:    AcpiNsExternalizeName
51467754Smsmith *
51567754Smsmith * PARAMETERS:  *InternalName          - Internal representation of name
51667754Smsmith *              **ConvertedName        - Where to return the resulting
51777424Smsmith *                                       external representation of name
51867754Smsmith *
51967754Smsmith * RETURN:      Status
52067754Smsmith *
52167754Smsmith * DESCRIPTION: Convert internal name (e.g. 5c 2f 02 5f 50 52 5f 43 50 55 30)
52267754Smsmith *              to its external form (e.g. "\_PR_.CPU0")
52367754Smsmith *
52477424Smsmith ******************************************************************************/
52567754Smsmith
52667754SmsmithACPI_STATUS
52767754SmsmithAcpiNsExternalizeName (
52867754Smsmith    UINT32                  InternalNameLength,
52967754Smsmith    char                    *InternalName,
53067754Smsmith    UINT32                  *ConvertedNameLength,
53167754Smsmith    char                    **ConvertedName)
53267754Smsmith{
53367754Smsmith    UINT32                  PrefixLength = 0;
53467754Smsmith    UINT32                  NamesIndex = 0;
53591116Smsmith    UINT32                  NumSegments = 0;
53667754Smsmith    UINT32                  i = 0;
53767754Smsmith    UINT32                  j = 0;
53891116Smsmith    UINT32                  RequiredLength;
53967754Smsmith
54067754Smsmith
54191116Smsmith    ACPI_FUNCTION_TRACE ("NsExternalizeName");
54267754Smsmith
54367754Smsmith
54467754Smsmith    if (!InternalNameLength     ||
54567754Smsmith        !InternalName           ||
54667754Smsmith        !ConvertedName)
54767754Smsmith    {
54867754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
54967754Smsmith    }
55067754Smsmith
55167754Smsmith    /*
55267754Smsmith     * Check for a prefix (one '\' | one or more '^').
55367754Smsmith     */
55467754Smsmith    switch (InternalName[0])
55567754Smsmith    {
55667754Smsmith    case '\\':
55767754Smsmith        PrefixLength = 1;
55867754Smsmith        break;
55967754Smsmith
56067754Smsmith    case '^':
56167754Smsmith        for (i = 0; i < InternalNameLength; i++)
56267754Smsmith        {
56367754Smsmith            if (InternalName[i] != '^')
56467754Smsmith            {
56567754Smsmith                PrefixLength = i + 1;
56667754Smsmith            }
56767754Smsmith        }
56867754Smsmith
56967754Smsmith        if (i == InternalNameLength)
57067754Smsmith        {
57167754Smsmith            PrefixLength = i;
57267754Smsmith        }
57367754Smsmith
57467754Smsmith        break;
57567754Smsmith    }
57667754Smsmith
57767754Smsmith    /*
57867754Smsmith     * Check for object names.  Note that there could be 0-255 of these
57967754Smsmith     * 4-byte elements.
58067754Smsmith     */
58167754Smsmith    if (PrefixLength < InternalNameLength)
58267754Smsmith    {
58367754Smsmith        switch (InternalName[PrefixLength])
58467754Smsmith        {
58591116Smsmith        case AML_MULTI_NAME_PREFIX_OP:
58667754Smsmith
58791116Smsmith            /* <count> 4-byte names */
58867754Smsmith
58967754Smsmith            NamesIndex = PrefixLength + 2;
59091116Smsmith            NumSegments = (UINT32) (UINT8) InternalName[PrefixLength + 1];
59167754Smsmith            break;
59267754Smsmith
59391116Smsmith        case AML_DUAL_NAME_PREFIX:
59467754Smsmith
59591116Smsmith            /* Two 4-byte names */
59667754Smsmith
59767754Smsmith            NamesIndex = PrefixLength + 1;
59891116Smsmith            NumSegments = 2;
59967754Smsmith            break;
60067754Smsmith
60191116Smsmith        case 0:
60267754Smsmith
60391116Smsmith            /* NullName */
60467754Smsmith
60567754Smsmith            NamesIndex = 0;
60691116Smsmith            NumSegments = 0;
60767754Smsmith            break;
60867754Smsmith
60991116Smsmith        default:
61067754Smsmith
61191116Smsmith            /* one 4-byte name */
61267754Smsmith
61367754Smsmith            NamesIndex = PrefixLength;
61491116Smsmith            NumSegments = 1;
61567754Smsmith            break;
61667754Smsmith        }
61767754Smsmith    }
61867754Smsmith
61967754Smsmith    /*
62067754Smsmith     * Calculate the length of ConvertedName, which equals the length
62167754Smsmith     * of the prefix, length of all object names, length of any required
62267754Smsmith     * punctuation ('.') between object names, plus the NULL terminator.
62367754Smsmith     */
62491116Smsmith    RequiredLength = PrefixLength + (4 * NumSegments) +
62591116Smsmith                        ((NumSegments > 0) ? (NumSegments - 1) : 0) + 1;
62667754Smsmith
62767754Smsmith    /*
62867754Smsmith     * Check to see if we're still in bounds.  If not, there's a problem
62967754Smsmith     * with InternalName (invalid format).
63067754Smsmith     */
63191116Smsmith    if (RequiredLength > InternalNameLength)
63267754Smsmith    {
63391116Smsmith        ACPI_REPORT_ERROR (("NsExternalizeName: Invalid internal name\n"));
63467754Smsmith        return_ACPI_STATUS (AE_BAD_PATHNAME);
63567754Smsmith    }
63667754Smsmith
63767754Smsmith    /*
63867754Smsmith     * Build ConvertedName...
63967754Smsmith     */
64091116Smsmith    *ConvertedName = ACPI_MEM_CALLOCATE (RequiredLength);
64167754Smsmith    if (!(*ConvertedName))
64267754Smsmith    {
64367754Smsmith        return_ACPI_STATUS (AE_NO_MEMORY);
64467754Smsmith    }
64567754Smsmith
64667754Smsmith    j = 0;
64767754Smsmith
64867754Smsmith    for (i = 0; i < PrefixLength; i++)
64967754Smsmith    {
65067754Smsmith        (*ConvertedName)[j++] = InternalName[i];
65167754Smsmith    }
65267754Smsmith
65391116Smsmith    if (NumSegments > 0)
65467754Smsmith    {
65591116Smsmith        for (i = 0; i < NumSegments; i++)
65667754Smsmith        {
65767754Smsmith            if (i > 0)
65867754Smsmith            {
65967754Smsmith                (*ConvertedName)[j++] = '.';
66067754Smsmith            }
66167754Smsmith
66267754Smsmith            (*ConvertedName)[j++] = InternalName[NamesIndex++];
66367754Smsmith            (*ConvertedName)[j++] = InternalName[NamesIndex++];
66467754Smsmith            (*ConvertedName)[j++] = InternalName[NamesIndex++];
66567754Smsmith            (*ConvertedName)[j++] = InternalName[NamesIndex++];
66667754Smsmith        }
66767754Smsmith    }
66867754Smsmith
66991116Smsmith    if (ConvertedNameLength)
67091116Smsmith    {
67191116Smsmith        *ConvertedNameLength = RequiredLength;
67291116Smsmith    }
67391116Smsmith
67467754Smsmith    return_ACPI_STATUS (AE_OK);
67567754Smsmith}
67667754Smsmith
67767754Smsmith
67877424Smsmith/*******************************************************************************
67967754Smsmith *
68085756Smsmith * FUNCTION:    AcpiNsMapHandleToNode
68167754Smsmith *
68267754Smsmith * PARAMETERS:  Handle          - Handle to be converted to an Node
68367754Smsmith *
68467754Smsmith * RETURN:      A Name table entry pointer
68567754Smsmith *
68667754Smsmith * DESCRIPTION: Convert a namespace handle to a real Node
68767754Smsmith *
68887031Smsmith * Note: Real integer handles allow for more verification
68987031Smsmith *       and keep all pointers within this subsystem.
69087031Smsmith *
69177424Smsmith ******************************************************************************/
69267754Smsmith
69367754SmsmithACPI_NAMESPACE_NODE *
69485756SmsmithAcpiNsMapHandleToNode (
69567754Smsmith    ACPI_HANDLE             Handle)
69667754Smsmith{
69767754Smsmith
69891116Smsmith    ACPI_FUNCTION_ENTRY ();
69983174Smsmith
70083174Smsmith
70167754Smsmith    /*
70287031Smsmith     * Simple implementation.
70367754Smsmith     */
70467754Smsmith    if (!Handle)
70567754Smsmith    {
70667754Smsmith        return (NULL);
70767754Smsmith    }
70867754Smsmith
70967754Smsmith    if (Handle == ACPI_ROOT_OBJECT)
71067754Smsmith    {
71167754Smsmith        return (AcpiGbl_RootNode);
71267754Smsmith    }
71367754Smsmith
71467754Smsmith    /* We can at least attempt to verify the handle */
71567754Smsmith
71691116Smsmith    if (ACPI_GET_DESCRIPTOR_TYPE (Handle) != ACPI_DESC_TYPE_NAMED)
71767754Smsmith    {
71867754Smsmith        return (NULL);
71967754Smsmith    }
72067754Smsmith
72167754Smsmith    return ((ACPI_NAMESPACE_NODE *) Handle);
72267754Smsmith}
72367754Smsmith
72467754Smsmith
72577424Smsmith/*******************************************************************************
72667754Smsmith *
72767754Smsmith * FUNCTION:    AcpiNsConvertEntryToHandle
72867754Smsmith *
72967754Smsmith * PARAMETERS:  Node          - Node to be converted to a Handle
73067754Smsmith *
73167754Smsmith * RETURN:      An USER ACPI_HANDLE
73267754Smsmith *
73367754Smsmith * DESCRIPTION: Convert a real Node to a namespace handle
73467754Smsmith *
73577424Smsmith ******************************************************************************/
73667754Smsmith
73767754SmsmithACPI_HANDLE
73867754SmsmithAcpiNsConvertEntryToHandle (
73967754Smsmith    ACPI_NAMESPACE_NODE         *Node)
74067754Smsmith{
74167754Smsmith
74267754Smsmith
74367754Smsmith    /*
74467754Smsmith     * Simple implementation for now;
74567754Smsmith     */
74667754Smsmith    return ((ACPI_HANDLE) Node);
74767754Smsmith
74867754Smsmith
74967754Smsmith/* ---------------------------------------------------
75067754Smsmith
75167754Smsmith    if (!Node)
75267754Smsmith    {
75367754Smsmith        return (NULL);
75467754Smsmith    }
75567754Smsmith
75667754Smsmith    if (Node == AcpiGbl_RootNode)
75767754Smsmith    {
75867754Smsmith        return (ACPI_ROOT_OBJECT);
75967754Smsmith    }
76067754Smsmith
76167754Smsmith
76267754Smsmith    return ((ACPI_HANDLE) Node);
76367754Smsmith------------------------------------------------------*/
76467754Smsmith}
76567754Smsmith
76667754Smsmith
76777424Smsmith/*******************************************************************************
76867754Smsmith *
76967754Smsmith * FUNCTION:    AcpiNsTerminate
77067754Smsmith *
77167754Smsmith * PARAMETERS:  none
77267754Smsmith *
77367754Smsmith * RETURN:      none
77467754Smsmith *
77567754Smsmith * DESCRIPTION: free memory allocated for table storage.
77667754Smsmith *
77767754Smsmith ******************************************************************************/
77867754Smsmith
77967754Smsmithvoid
78067754SmsmithAcpiNsTerminate (void)
78167754Smsmith{
78267754Smsmith    ACPI_OPERAND_OBJECT     *ObjDesc;
78367754Smsmith    ACPI_NAMESPACE_NODE     *ThisNode;
78467754Smsmith
78567754Smsmith
78691116Smsmith    ACPI_FUNCTION_TRACE ("NsTerminate");
78767754Smsmith
78867754Smsmith
78967754Smsmith    ThisNode = AcpiGbl_RootNode;
79067754Smsmith
79167754Smsmith    /*
79267754Smsmith     * 1) Free the entire namespace -- all objects, tables, and stacks
79377424Smsmith     *
79467754Smsmith     * Delete all objects linked to the root
79567754Smsmith     * (additional table descriptors)
79667754Smsmith     */
79767754Smsmith    AcpiNsDeleteNamespaceSubtree (ThisNode);
79867754Smsmith
79967754Smsmith    /* Detach any object(s) attached to the root */
80067754Smsmith
80167754Smsmith    ObjDesc = AcpiNsGetAttachedObject (ThisNode);
80267754Smsmith    if (ObjDesc)
80367754Smsmith    {
80467754Smsmith        AcpiNsDetachObject (ThisNode);
80577424Smsmith        AcpiUtRemoveReference (ObjDesc);
80667754Smsmith    }
80767754Smsmith
80867754Smsmith    AcpiNsDeleteChildren (ThisNode);
80982367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "Namespace freed\n"));
81067754Smsmith
81167754Smsmith
81267754Smsmith    /*
81367754Smsmith     * 2) Now we can delete the ACPI tables
81467754Smsmith     */
81567754Smsmith    AcpiTbDeleteAcpiTables ();
81682367Smsmith    ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "ACPI Tables freed\n"));
81767754Smsmith
81867754Smsmith    return_VOID;
81967754Smsmith}
82067754Smsmith
82167754Smsmith
82277424Smsmith/*******************************************************************************
82367754Smsmith *
82467754Smsmith * FUNCTION:    AcpiNsOpensScope
82567754Smsmith *
82667754Smsmith * PARAMETERS:  Type        - A valid namespace type
82767754Smsmith *
82867754Smsmith * RETURN:      NEWSCOPE if the passed type "opens a name scope" according
82967754Smsmith *              to the ACPI specification, else 0
83067754Smsmith *
83177424Smsmith ******************************************************************************/
83267754Smsmith
83367754SmsmithUINT32
83467754SmsmithAcpiNsOpensScope (
83591116Smsmith    ACPI_OBJECT_TYPE        Type)
83667754Smsmith{
83791116Smsmith    ACPI_FUNCTION_TRACE_U32 ("NsOpensScope", Type);
83867754Smsmith
83967754Smsmith
84077424Smsmith    if (!AcpiUtValidObjectType (Type))
84167754Smsmith    {
84267754Smsmith        /* type code out of range  */
84367754Smsmith
84491116Smsmith        ACPI_REPORT_WARNING (("NsOpensScope: Invalid Object Type %X\n", Type));
84591116Smsmith        return_VALUE (ACPI_NS_NORMAL);
84667754Smsmith    }
84767754Smsmith
84891116Smsmith    return_VALUE (((UINT32) AcpiGbl_NsProperties[Type]) & ACPI_NS_NEWSCOPE);
84967754Smsmith}
85067754Smsmith
85167754Smsmith
85277424Smsmith/*******************************************************************************
85367754Smsmith *
85491116Smsmith * FUNCTION:    AcpiNsGetNodeByPath
85567754Smsmith *
85667754Smsmith * PARAMETERS:  *Pathname   - Name to be found, in external (ASL) format. The
85767754Smsmith *                            \ (backslash) and ^ (carat) prefixes, and the
85867754Smsmith *                            . (period) to separate segments are supported.
85967754Smsmith *              StartNode   - Root of subtree to be searched, or NS_ALL for the
86067754Smsmith *                            root of the name space.  If Name is fully
86167754Smsmith *                            qualified (first INT8 is '\'), the passed value
86267754Smsmith *                            of Scope will not be accessed.
86391116Smsmith *              Flags       - Used to indicate whether to perform upsearch or
86491116Smsmith *                            not.
86567754Smsmith *              ReturnNode  - Where the Node is returned
86667754Smsmith *
86767754Smsmith * DESCRIPTION: Look up a name relative to a given scope and return the
86867754Smsmith *              corresponding Node.  NOTE: Scope can be null.
86967754Smsmith *
87067754Smsmith * MUTEX:       Locks namespace
87167754Smsmith *
87277424Smsmith ******************************************************************************/
87367754Smsmith
87467754SmsmithACPI_STATUS
87591116SmsmithAcpiNsGetNodeByPath (
87667754Smsmith    NATIVE_CHAR             *Pathname,
87767754Smsmith    ACPI_NAMESPACE_NODE     *StartNode,
87891116Smsmith    UINT32                  Flags,
87967754Smsmith    ACPI_NAMESPACE_NODE     **ReturnNode)
88067754Smsmith{
88167754Smsmith    ACPI_GENERIC_STATE      ScopeInfo;
88267754Smsmith    ACPI_STATUS             Status;
88367754Smsmith    NATIVE_CHAR             *InternalPath = NULL;
88467754Smsmith
88567754Smsmith
88691116Smsmith    ACPI_FUNCTION_TRACE_PTR ("NsGetNodeByPath", Pathname);
88767754Smsmith
88867754Smsmith
88967754Smsmith    if (!Pathname)
89067754Smsmith    {
89167754Smsmith        return_ACPI_STATUS (AE_BAD_PARAMETER);
89267754Smsmith    }
89367754Smsmith
89467754Smsmith    /* Convert path to internal representation */
89567754Smsmith
89667754Smsmith    Status = AcpiNsInternalizeName (Pathname, &InternalPath);
89767754Smsmith    if (ACPI_FAILURE (Status))
89867754Smsmith    {
89967754Smsmith        return_ACPI_STATUS (Status);
90067754Smsmith    }
90167754Smsmith
90291116Smsmith    /* Must lock namespace during lookup */
90367754Smsmith
90491116Smsmith    Status = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
90591116Smsmith    if (ACPI_FAILURE (Status))
90691116Smsmith    {
90791116Smsmith        return_ACPI_STATUS (Status);
90891116Smsmith    }
90967754Smsmith
91069746Smsmith    /* Setup lookup scope (search starting point) */
91167754Smsmith
91269746Smsmith    ScopeInfo.Scope.Node = StartNode;
91367754Smsmith
91467754Smsmith    /* Lookup the name in the namespace */
91567754Smsmith
91667754Smsmith    Status = AcpiNsLookup (&ScopeInfo, InternalPath,
91791116Smsmith                            ACPI_TYPE_ANY, ACPI_IMODE_EXECUTE,
91891116Smsmith                            (Flags | ACPI_NS_DONT_OPEN_SCOPE),
91967754Smsmith                            NULL, ReturnNode);
92067754Smsmith    if (ACPI_FAILURE (Status))
92167754Smsmith    {
92282367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s, %s\n",
92380062Smsmith                InternalPath, AcpiFormatException (Status)));
92467754Smsmith    }
92567754Smsmith
92667754Smsmith    /* Cleanup */
92767754Smsmith
92891116Smsmith    (void) AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
92980062Smsmith    ACPI_MEM_FREE (InternalPath);
93067754Smsmith    return_ACPI_STATUS (Status);
93167754Smsmith}
93267754Smsmith
93367754Smsmith
93477424Smsmith/*******************************************************************************
93567754Smsmith *
93667754Smsmith * FUNCTION:    AcpiNsFindParentName
93767754Smsmith *
93867754Smsmith * PARAMETERS:  *ChildNode             - Named Obj whose name is to be found
93967754Smsmith *
94067754Smsmith * RETURN:      The ACPI name
94167754Smsmith *
94267754Smsmith * DESCRIPTION: Search for the given obj in its parent scope and return the
94367754Smsmith *              name segment, or "????" if the parent name can't be found
94467754Smsmith *              (which "should not happen").
94567754Smsmith *
94677424Smsmith ******************************************************************************/
94767754Smsmith
94867754SmsmithACPI_NAME
94967754SmsmithAcpiNsFindParentName (
95067754Smsmith    ACPI_NAMESPACE_NODE     *ChildNode)
95167754Smsmith{
95267754Smsmith    ACPI_NAMESPACE_NODE     *ParentNode;
95367754Smsmith
95467754Smsmith
95591116Smsmith    ACPI_FUNCTION_TRACE ("NsFindParentName");
95667754Smsmith
95767754Smsmith
95867754Smsmith    if (ChildNode)
95967754Smsmith    {
96067754Smsmith        /* Valid entry.  Get the parent Node */
96167754Smsmith
96291116Smsmith        ParentNode = AcpiNsGetParentNode (ChildNode);
96367754Smsmith        if (ParentNode)
96467754Smsmith        {
96582367Smsmith            ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Parent of %p [%4.4s] is %p [%4.4s]\n",
96691116Smsmith                ChildNode,  (char *) &ChildNode->Name,
96791116Smsmith                ParentNode, (char *) &ParentNode->Name));
96867754Smsmith
96999146Siwasaki            if (ParentNode->Name.Integer)
97067754Smsmith            {
97199146Siwasaki                return_VALUE (ParentNode->Name.Integer);
97267754Smsmith            }
97367754Smsmith        }
97467754Smsmith
97582367Smsmith        ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "unable to find parent of %p (%4.4s)\n",
97691116Smsmith            ChildNode, (char *) &ChildNode->Name));
97767754Smsmith    }
97867754Smsmith
97967754Smsmith    return_VALUE (ACPI_UNKNOWN_NAME);
98067754Smsmith}
98167754Smsmith
98267754Smsmith
98371867Smsmith#if defined(ACPI_DEBUG) || defined(ENABLE_DEBUGGER)
98467754Smsmith
98577424Smsmith/*******************************************************************************
98667754Smsmith *
98767754Smsmith * FUNCTION:    AcpiNsExistDownstreamSibling
98867754Smsmith *
98967754Smsmith * PARAMETERS:  *Node          - pointer to first Node to examine
99067754Smsmith *
99167754Smsmith * RETURN:      TRUE if sibling is found, FALSE otherwise
99267754Smsmith *
99367754Smsmith * DESCRIPTION: Searches remainder of scope being processed to determine
99467754Smsmith *              whether there is a downstream sibling to the current
99567754Smsmith *              object.  This function is used to determine what type of
99667754Smsmith *              line drawing character to use when displaying namespace
99767754Smsmith *              trees.
99867754Smsmith *
99977424Smsmith ******************************************************************************/
100067754Smsmith
100167754SmsmithBOOLEAN
100267754SmsmithAcpiNsExistDownstreamSibling (
100367754Smsmith    ACPI_NAMESPACE_NODE     *Node)
100467754Smsmith{
100567754Smsmith
100667754Smsmith    if (!Node)
100767754Smsmith    {
100867754Smsmith        return (FALSE);
100967754Smsmith    }
101067754Smsmith
101199146Siwasaki    if (Node->Name.Integer)
101267754Smsmith    {
101367754Smsmith        return (TRUE);
101467754Smsmith    }
101567754Smsmith
101667754Smsmith    return (FALSE);
101767754Smsmith}
101867754Smsmith
101967754Smsmith#endif /* ACPI_DEBUG */
102067754Smsmith
102167754Smsmith
102277424Smsmith/*******************************************************************************
102367754Smsmith *
102491116Smsmith * FUNCTION:    AcpiNsGetParentNode
102567754Smsmith *
102667754Smsmith * PARAMETERS:  Node       - Current table entry
102767754Smsmith *
102867754Smsmith * RETURN:      Parent entry of the given entry
102967754Smsmith *
103067754Smsmith * DESCRIPTION: Obtain the parent entry for a given entry in the namespace.
103167754Smsmith *
103277424Smsmith ******************************************************************************/
103367754Smsmith
103467754Smsmith
103567754SmsmithACPI_NAMESPACE_NODE *
103691116SmsmithAcpiNsGetParentNode (
103767754Smsmith    ACPI_NAMESPACE_NODE     *Node)
103867754Smsmith{
103991116Smsmith    ACPI_FUNCTION_ENTRY ();
104067754Smsmith
104167754Smsmith
104269746Smsmith    if (!Node)
104369746Smsmith    {
104469746Smsmith        return (NULL);
104569746Smsmith    }
104669746Smsmith
104767754Smsmith    /*
104867754Smsmith     * Walk to the end of this peer list.
104967754Smsmith     * The last entry is marked with a flag and the peer
105067754Smsmith     * pointer is really a pointer back to the parent.
105167754Smsmith     * This saves putting a parent back pointer in each and
105267754Smsmith     * every named object!
105367754Smsmith     */
105467754Smsmith    while (!(Node->Flags & ANOBJ_END_OF_PEER_LIST))
105567754Smsmith    {
105667754Smsmith        Node = Node->Peer;
105767754Smsmith    }
105867754Smsmith
105967754Smsmith
106067754Smsmith    return (Node->Peer);
106167754Smsmith}
106267754Smsmith
106367754Smsmith
106477424Smsmith/*******************************************************************************
106567754Smsmith *
106685756Smsmith * FUNCTION:    AcpiNsGetNextValidNode
106767754Smsmith *
106867754Smsmith * PARAMETERS:  Node       - Current table entry
106967754Smsmith *
107085756Smsmith * RETURN:      Next valid Node in the linked node list.  NULL if no more valid
107185756Smsmith *              nodess
107267754Smsmith *
107385756Smsmith * DESCRIPTION: Find the next valid node within a name table.
107467754Smsmith *              Useful for implementing NULL-end-of-list loops.
107567754Smsmith *
107677424Smsmith ******************************************************************************/
107767754Smsmith
107867754Smsmith
107967754SmsmithACPI_NAMESPACE_NODE *
108085756SmsmithAcpiNsGetNextValidNode (
108167754Smsmith    ACPI_NAMESPACE_NODE     *Node)
108267754Smsmith{
108367754Smsmith
108467754Smsmith    /* If we are at the end of this peer list, return NULL */
108567754Smsmith
108667754Smsmith    if (Node->Flags & ANOBJ_END_OF_PEER_LIST)
108767754Smsmith    {
108867754Smsmith        return NULL;
108967754Smsmith    }
109067754Smsmith
109167754Smsmith    /* Otherwise just return the next peer */
109267754Smsmith
109367754Smsmith    return (Node->Peer);
109467754Smsmith}
109567754Smsmith
109667754Smsmith
1097