xref: /onnv-gate/usr/src/uts/intel/io/acpica/namespace/nswalk.c (revision 9980:13d7f3eec672)
13446Smrj /******************************************************************************
23446Smrj  *
33446Smrj  * Module Name: nswalk - Functions for walking the ACPI namespace
43446Smrj  *
53446Smrj  *****************************************************************************/
63446Smrj 
73446Smrj /******************************************************************************
83446Smrj  *
93446Smrj  * 1. Copyright Notice
103446Smrj  *
11*9980SDana.Myers@Sun.COM  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
123446Smrj  * All rights reserved.
133446Smrj  *
143446Smrj  * 2. License
153446Smrj  *
163446Smrj  * 2.1. This is your license from Intel Corp. under its intellectual property
173446Smrj  * rights.  You may have additional license terms from the party that provided
183446Smrj  * you this software, covering your right to use that party's intellectual
193446Smrj  * property rights.
203446Smrj  *
213446Smrj  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
223446Smrj  * copy of the source code appearing in this file ("Covered Code") an
233446Smrj  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
243446Smrj  * base code distributed originally by Intel ("Original Intel Code") to copy,
253446Smrj  * make derivatives, distribute, use and display any portion of the Covered
263446Smrj  * Code in any form, with the right to sublicense such rights; and
273446Smrj  *
283446Smrj  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
293446Smrj  * license (with the right to sublicense), under only those claims of Intel
303446Smrj  * patents that are infringed by the Original Intel Code, to make, use, sell,
313446Smrj  * offer to sell, and import the Covered Code and derivative works thereof
323446Smrj  * solely to the minimum extent necessary to exercise the above copyright
333446Smrj  * license, and in no event shall the patent license extend to any additions
343446Smrj  * to or modifications of the Original Intel Code.  No other license or right
353446Smrj  * is granted directly or by implication, estoppel or otherwise;
363446Smrj  *
373446Smrj  * The above copyright and patent license is granted only if the following
383446Smrj  * conditions are met:
393446Smrj  *
403446Smrj  * 3. Conditions
413446Smrj  *
423446Smrj  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
433446Smrj  * Redistribution of source code of any substantial portion of the Covered
443446Smrj  * Code or modification with rights to further distribute source must include
453446Smrj  * the above Copyright Notice, the above License, this list of Conditions,
463446Smrj  * and the following Disclaimer and Export Compliance provision.  In addition,
473446Smrj  * Licensee must cause all Covered Code to which Licensee contributes to
483446Smrj  * contain a file documenting the changes Licensee made to create that Covered
493446Smrj  * Code and the date of any change.  Licensee must include in that file the
503446Smrj  * documentation of any changes made by any predecessor Licensee.  Licensee
513446Smrj  * must include a prominent statement that the modification is derived,
523446Smrj  * directly or indirectly, from Original Intel Code.
533446Smrj  *
543446Smrj  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
553446Smrj  * Redistribution of source code of any substantial portion of the Covered
563446Smrj  * Code or modification without rights to further distribute source must
573446Smrj  * include the following Disclaimer and Export Compliance provision in the
583446Smrj  * documentation and/or other materials provided with distribution.  In
593446Smrj  * addition, Licensee may not authorize further sublicense of source of any
603446Smrj  * portion of the Covered Code, and must include terms to the effect that the
613446Smrj  * license from Licensee to its licensee is limited to the intellectual
623446Smrj  * property embodied in the software Licensee provides to its licensee, and
633446Smrj  * not to intellectual property embodied in modifications its licensee may
643446Smrj  * make.
653446Smrj  *
663446Smrj  * 3.3. Redistribution of Executable. Redistribution in executable form of any
673446Smrj  * substantial portion of the Covered Code or modification must reproduce the
683446Smrj  * above Copyright Notice, and the following Disclaimer and Export Compliance
693446Smrj  * provision in the documentation and/or other materials provided with the
703446Smrj  * distribution.
713446Smrj  *
723446Smrj  * 3.4. Intel retains all right, title, and interest in and to the Original
733446Smrj  * Intel Code.
743446Smrj  *
753446Smrj  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
763446Smrj  * Intel shall be used in advertising or otherwise to promote the sale, use or
773446Smrj  * other dealings in products derived from or relating to the Covered Code
783446Smrj  * without prior written authorization from Intel.
793446Smrj  *
803446Smrj  * 4. Disclaimer and Export Compliance
813446Smrj  *
823446Smrj  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
833446Smrj  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
843446Smrj  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
853446Smrj  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
863446Smrj  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
873446Smrj  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
883446Smrj  * PARTICULAR PURPOSE.
893446Smrj  *
903446Smrj  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
913446Smrj  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
923446Smrj  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
933446Smrj  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
943446Smrj  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
953446Smrj  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
963446Smrj  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
973446Smrj  * LIMITED REMEDY.
983446Smrj  *
993446Smrj  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1003446Smrj  * software or system incorporating such software without first obtaining any
1013446Smrj  * required license or other approval from the U. S. Department of Commerce or
1023446Smrj  * any other agency or department of the United States Government.  In the
1033446Smrj  * event Licensee exports any such software from the United States or
1043446Smrj  * re-exports any such software from a foreign destination, Licensee shall
1053446Smrj  * ensure that the distribution and export/re-export of the software is in
1063446Smrj  * compliance with all laws, regulations, orders, or other restrictions of the
1073446Smrj  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1083446Smrj  * any of its subsidiaries will export/re-export any technical data, process,
1093446Smrj  * software, or service, directly or indirectly, to any country for which the
1103446Smrj  * United States government or any agency thereof requires an export license,
1113446Smrj  * other governmental approval, or letter of assurance, without first obtaining
1123446Smrj  * such license, approval or letter.
1133446Smrj  *
1143446Smrj  *****************************************************************************/
1153446Smrj 
1163446Smrj 
1173446Smrj #define __NSWALK_C__
1183446Smrj 
1193446Smrj #include "acpi.h"
120*9980SDana.Myers@Sun.COM #include "accommon.h"
1213446Smrj #include "acnamesp.h"
1223446Smrj 
1233446Smrj 
1243446Smrj #define _COMPONENT          ACPI_NAMESPACE
1253446Smrj         ACPI_MODULE_NAME    ("nswalk")
1263446Smrj 
1273446Smrj 
1283446Smrj /*******************************************************************************
1293446Smrj  *
1303446Smrj  * FUNCTION:    AcpiNsGetNextNode
1313446Smrj  *
132*9980SDana.Myers@Sun.COM  * PARAMETERS:  ParentNode          - Parent node whose children we are
133*9980SDana.Myers@Sun.COM  *                                    getting
134*9980SDana.Myers@Sun.COM  *              ChildNode           - Previous child that was found.
135*9980SDana.Myers@Sun.COM  *                                    The NEXT child will be returned
136*9980SDana.Myers@Sun.COM  *
137*9980SDana.Myers@Sun.COM  * RETURN:      ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
138*9980SDana.Myers@Sun.COM  *                                    none is found.
139*9980SDana.Myers@Sun.COM  *
140*9980SDana.Myers@Sun.COM  * DESCRIPTION: Return the next peer node within the namespace.  If Handle
141*9980SDana.Myers@Sun.COM  *              is valid, Scope is ignored.  Otherwise, the first node
142*9980SDana.Myers@Sun.COM  *              within Scope is returned.
143*9980SDana.Myers@Sun.COM  *
144*9980SDana.Myers@Sun.COM  ******************************************************************************/
145*9980SDana.Myers@Sun.COM 
146*9980SDana.Myers@Sun.COM ACPI_NAMESPACE_NODE *
147*9980SDana.Myers@Sun.COM AcpiNsGetNextNode (
148*9980SDana.Myers@Sun.COM     ACPI_NAMESPACE_NODE     *ParentNode,
149*9980SDana.Myers@Sun.COM     ACPI_NAMESPACE_NODE     *ChildNode)
150*9980SDana.Myers@Sun.COM {
151*9980SDana.Myers@Sun.COM     ACPI_FUNCTION_ENTRY ();
152*9980SDana.Myers@Sun.COM 
153*9980SDana.Myers@Sun.COM 
154*9980SDana.Myers@Sun.COM     if (!ChildNode)
155*9980SDana.Myers@Sun.COM     {
156*9980SDana.Myers@Sun.COM         /* It's really the parent's _scope_ that we want */
157*9980SDana.Myers@Sun.COM 
158*9980SDana.Myers@Sun.COM         return (ParentNode->Child);
159*9980SDana.Myers@Sun.COM     }
160*9980SDana.Myers@Sun.COM 
161*9980SDana.Myers@Sun.COM     /*
162*9980SDana.Myers@Sun.COM      * Get the next node.
163*9980SDana.Myers@Sun.COM      *
164*9980SDana.Myers@Sun.COM      * If we are at the end of this peer list, return NULL
165*9980SDana.Myers@Sun.COM      */
166*9980SDana.Myers@Sun.COM     if (ChildNode->Flags & ANOBJ_END_OF_PEER_LIST)
167*9980SDana.Myers@Sun.COM     {
168*9980SDana.Myers@Sun.COM         return NULL;
169*9980SDana.Myers@Sun.COM     }
170*9980SDana.Myers@Sun.COM 
171*9980SDana.Myers@Sun.COM     /* Otherwise just return the next peer */
172*9980SDana.Myers@Sun.COM 
173*9980SDana.Myers@Sun.COM     return (ChildNode->Peer);
174*9980SDana.Myers@Sun.COM }
175*9980SDana.Myers@Sun.COM 
176*9980SDana.Myers@Sun.COM 
177*9980SDana.Myers@Sun.COM /*******************************************************************************
178*9980SDana.Myers@Sun.COM  *
179*9980SDana.Myers@Sun.COM  * FUNCTION:    AcpiNsGetNextNodeTyped
180*9980SDana.Myers@Sun.COM  *
1813446Smrj  * PARAMETERS:  Type                - Type of node to be searched for
1823446Smrj  *              ParentNode          - Parent node whose children we are
1833446Smrj  *                                    getting
1843446Smrj  *              ChildNode           - Previous child that was found.
1853446Smrj  *                                    The NEXT child will be returned
1863446Smrj  *
1873446Smrj  * RETURN:      ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
1883446Smrj  *                                    none is found.
1893446Smrj  *
1903446Smrj  * DESCRIPTION: Return the next peer node within the namespace.  If Handle
1913446Smrj  *              is valid, Scope is ignored.  Otherwise, the first node
1923446Smrj  *              within Scope is returned.
1933446Smrj  *
1943446Smrj  ******************************************************************************/
1953446Smrj 
1963446Smrj ACPI_NAMESPACE_NODE *
197*9980SDana.Myers@Sun.COM AcpiNsGetNextNodeTyped (
1983446Smrj     ACPI_OBJECT_TYPE        Type,
1993446Smrj     ACPI_NAMESPACE_NODE     *ParentNode,
2003446Smrj     ACPI_NAMESPACE_NODE     *ChildNode)
2013446Smrj {
2023446Smrj     ACPI_NAMESPACE_NODE     *NextNode = NULL;
2033446Smrj 
2043446Smrj 
2053446Smrj     ACPI_FUNCTION_ENTRY ();
2063446Smrj 
2073446Smrj 
208*9980SDana.Myers@Sun.COM     NextNode = AcpiNsGetNextNode (ParentNode, ChildNode);
2093446Smrj 
2103446Smrj     /* If any type is OK, we are done */
2113446Smrj 
2123446Smrj     if (Type == ACPI_TYPE_ANY)
2133446Smrj     {
2143446Smrj         /* NextNode is NULL if we are at the end-of-list */
2153446Smrj 
2163446Smrj         return (NextNode);
2173446Smrj     }
2183446Smrj 
2193446Smrj     /* Must search for the node -- but within this scope only */
2203446Smrj 
2213446Smrj     while (NextNode)
2223446Smrj     {
2233446Smrj         /* If type matches, we are done */
2243446Smrj 
2253446Smrj         if (NextNode->Type == Type)
2263446Smrj         {
2273446Smrj             return (NextNode);
2283446Smrj         }
2293446Smrj 
2303446Smrj         /* Otherwise, move on to the next node */
2313446Smrj 
2323446Smrj         NextNode = AcpiNsGetNextValidNode (NextNode);
2333446Smrj     }
2343446Smrj 
2353446Smrj     /* Not found */
2363446Smrj 
2373446Smrj     return (NULL);
2383446Smrj }
2393446Smrj 
2403446Smrj 
2413446Smrj /*******************************************************************************
2423446Smrj  *
2433446Smrj  * FUNCTION:    AcpiNsWalkNamespace
2443446Smrj  *
2453446Smrj  * PARAMETERS:  Type                - ACPI_OBJECT_TYPE to search for
2463446Smrj  *              StartNode           - Handle in namespace where search begins
2473446Smrj  *              MaxDepth            - Depth to which search is to reach
2487851SDana.Myers@Sun.COM  *              Flags               - Whether to unlock the NS before invoking
2493446Smrj  *                                    the callback routine
2503446Smrj  *              UserFunction        - Called when an object of "Type" is found
2513446Smrj  *              Context             - Passed to user function
2523446Smrj  *              ReturnValue         - from the UserFunction if terminated early.
2533446Smrj  *                                    Otherwise, returns NULL.
2543446Smrj  * RETURNS:     Status
2553446Smrj  *
2563446Smrj  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
2573446Smrj  *              starting (and ending) at the node specified by StartHandle.
2583446Smrj  *              The UserFunction is called whenever a node that matches
2593446Smrj  *              the type parameter is found.  If the user function returns
260*9980SDana.Myers@Sun.COM  *              a non-zero value, the search is terminated immediately and
261*9980SDana.Myers@Sun.COM  *              this value is returned to the caller.
2623446Smrj  *
2633446Smrj  *              The point of this procedure is to provide a generic namespace
2643446Smrj  *              walk routine that can be called from multiple places to
2653446Smrj  *              provide multiple services;  the User Function can be tailored
2663446Smrj  *              to each task, whether it is a print function, a compare
2673446Smrj  *              function, etc.
2683446Smrj  *
2693446Smrj  ******************************************************************************/
2703446Smrj 
2713446Smrj ACPI_STATUS
2723446Smrj AcpiNsWalkNamespace (
2733446Smrj     ACPI_OBJECT_TYPE        Type,
2743446Smrj     ACPI_HANDLE             StartNode,
2753446Smrj     UINT32                  MaxDepth,
2767851SDana.Myers@Sun.COM     UINT32                  Flags,
2773446Smrj     ACPI_WALK_CALLBACK      UserFunction,
2783446Smrj     void                    *Context,
2793446Smrj     void                    **ReturnValue)
2803446Smrj {
2813446Smrj     ACPI_STATUS             Status;
2823446Smrj     ACPI_STATUS             MutexStatus;
2833446Smrj     ACPI_NAMESPACE_NODE     *ChildNode;
2843446Smrj     ACPI_NAMESPACE_NODE     *ParentNode;
2853446Smrj     ACPI_OBJECT_TYPE        ChildType;
2863446Smrj     UINT32                  Level;
2873446Smrj 
2883446Smrj 
2893446Smrj     ACPI_FUNCTION_TRACE (NsWalkNamespace);
2903446Smrj 
2913446Smrj 
2923446Smrj     /* Special case for the namespace Root Node */
2933446Smrj 
2943446Smrj     if (StartNode == ACPI_ROOT_OBJECT)
2953446Smrj     {
2963446Smrj         StartNode = AcpiGbl_RootNode;
2973446Smrj     }
2983446Smrj 
2993446Smrj     /* Null child means "get first node" */
3003446Smrj 
3013446Smrj     ParentNode  = StartNode;
3023446Smrj     ChildNode   = NULL;
3033446Smrj     ChildType   = ACPI_TYPE_ANY;
3043446Smrj     Level       = 1;
3053446Smrj 
3063446Smrj     /*
3073446Smrj      * Traverse the tree of nodes until we bubble back up to where we
3083446Smrj      * started. When Level is zero, the loop is done because we have
3093446Smrj      * bubbled up to (and passed) the original parent handle (StartEntry)
3103446Smrj      */
3113446Smrj     while (Level > 0)
3123446Smrj     {
3133446Smrj         /* Get the next node in this scope.  Null if not found */
3143446Smrj 
3153446Smrj         Status = AE_OK;
316*9980SDana.Myers@Sun.COM         ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
3173446Smrj         if (ChildNode)
3183446Smrj         {
3197851SDana.Myers@Sun.COM             /* Found next child, get the type if we are not searching for ANY */
3207851SDana.Myers@Sun.COM 
3213446Smrj             if (Type != ACPI_TYPE_ANY)
3223446Smrj             {
3233446Smrj                 ChildType = ChildNode->Type;
3243446Smrj             }
3253446Smrj 
3267851SDana.Myers@Sun.COM             /*
3277851SDana.Myers@Sun.COM              * Ignore all temporary namespace nodes (created during control
3287851SDana.Myers@Sun.COM              * method execution) unless told otherwise. These temporary nodes
329*9980SDana.Myers@Sun.COM              * can cause a race condition because they can be deleted during
330*9980SDana.Myers@Sun.COM              * the execution of the user function (if the namespace is
331*9980SDana.Myers@Sun.COM              * unlocked before invocation of the user function.) Only the
332*9980SDana.Myers@Sun.COM              * debugger namespace dump will examine the temporary nodes.
3337851SDana.Myers@Sun.COM              */
3347851SDana.Myers@Sun.COM             if ((ChildNode->Flags & ANOBJ_TEMPORARY) &&
3357851SDana.Myers@Sun.COM                 !(Flags & ACPI_NS_WALK_TEMP_NODES))
3367851SDana.Myers@Sun.COM             {
3377851SDana.Myers@Sun.COM                 Status = AE_CTRL_DEPTH;
3387851SDana.Myers@Sun.COM             }
3397851SDana.Myers@Sun.COM 
3407851SDana.Myers@Sun.COM             /* Type must match requested type */
3417851SDana.Myers@Sun.COM 
3427851SDana.Myers@Sun.COM             else if (ChildType == Type)
3433446Smrj             {
3443446Smrj                 /*
3457851SDana.Myers@Sun.COM                  * Found a matching node, invoke the user callback function.
3467851SDana.Myers@Sun.COM                  * Unlock the namespace if flag is set.
3473446Smrj                  */
3487851SDana.Myers@Sun.COM                 if (Flags & ACPI_NS_WALK_UNLOCK)
3493446Smrj                 {
3503446Smrj                     MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
3513446Smrj                     if (ACPI_FAILURE (MutexStatus))
3523446Smrj                     {
3533446Smrj                         return_ACPI_STATUS (MutexStatus);
3543446Smrj                     }
3553446Smrj                 }
3563446Smrj 
3577851SDana.Myers@Sun.COM                 Status = UserFunction (ChildNode, Level, Context, ReturnValue);
3583446Smrj 
3597851SDana.Myers@Sun.COM                 if (Flags & ACPI_NS_WALK_UNLOCK)
3603446Smrj                 {
3613446Smrj                     MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
3623446Smrj                     if (ACPI_FAILURE (MutexStatus))
3633446Smrj                     {
3643446Smrj                         return_ACPI_STATUS (MutexStatus);
3653446Smrj                     }
3663446Smrj                 }
3673446Smrj 
3683446Smrj                 switch (Status)
3693446Smrj                 {
3703446Smrj                 case AE_OK:
3713446Smrj                 case AE_CTRL_DEPTH:
3723446Smrj 
3733446Smrj                     /* Just keep going */
3743446Smrj                     break;
3753446Smrj 
3763446Smrj                 case AE_CTRL_TERMINATE:
3773446Smrj 
3783446Smrj                     /* Exit now, with OK status */
3793446Smrj 
3803446Smrj                     return_ACPI_STATUS (AE_OK);
3813446Smrj 
3823446Smrj                 default:
3833446Smrj 
3843446Smrj                     /* All others are valid exceptions */
3853446Smrj 
3863446Smrj                     return_ACPI_STATUS (Status);
3873446Smrj                 }
3883446Smrj             }
3893446Smrj 
3903446Smrj             /*
3917851SDana.Myers@Sun.COM              * Depth first search: Attempt to go down another level in the
3927851SDana.Myers@Sun.COM              * namespace if we are allowed to.  Don't go any further if we have
3937851SDana.Myers@Sun.COM              * reached the caller specified maximum depth or if the user
3947851SDana.Myers@Sun.COM              * function has specified that the maximum depth has been reached.
3953446Smrj              */
3963446Smrj             if ((Level < MaxDepth) && (Status != AE_CTRL_DEPTH))
3973446Smrj             {
398*9980SDana.Myers@Sun.COM                 if (ChildNode->Child)
3993446Smrj                 {
4007851SDana.Myers@Sun.COM                     /* There is at least one child of this node, visit it */
4017851SDana.Myers@Sun.COM 
4023446Smrj                     Level++;
4033446Smrj                     ParentNode = ChildNode;
4047851SDana.Myers@Sun.COM                     ChildNode = NULL;
4053446Smrj                 }
4063446Smrj             }
4073446Smrj         }
4083446Smrj         else
4093446Smrj         {
4103446Smrj             /*
4117851SDana.Myers@Sun.COM              * No more children of this node (AcpiNsGetNextNode failed), go
4127851SDana.Myers@Sun.COM              * back upwards in the namespace tree to the node's parent.
4133446Smrj              */
4143446Smrj             Level--;
4153446Smrj             ChildNode = ParentNode;
4163446Smrj             ParentNode = AcpiNsGetParentNode (ParentNode);
4173446Smrj         }
4183446Smrj     }
4193446Smrj 
4203446Smrj     /* Complete walk, not terminated by user function */
4213446Smrj 
4223446Smrj     return_ACPI_STATUS (AE_OK);
4233446Smrj }
4243446Smrj 
4253446Smrj 
426