ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

nswalk.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: nswalk - Functions for walking the ACPI namespace
00004  *
00005  *****************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 
00117 #define __NSWALK_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 #include "acnamesp.h"
00122 
00123 
00124 #define _COMPONENT          ACPI_NAMESPACE
00125         ACPI_MODULE_NAME    ("nswalk")
00126 
00127 
00128 /*******************************************************************************
00129  *
00130  * FUNCTION:    AcpiNsGetNextNode
00131  *
00132  * PARAMETERS:  ParentNode          - Parent node whose children we are
00133  *                                    getting
00134  *              ChildNode           - Previous child that was found.
00135  *                                    The NEXT child will be returned
00136  *
00137  * RETURN:      ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
00138  *                                    none is found.
00139  *
00140  * DESCRIPTION: Return the next peer node within the namespace.  If Handle
00141  *              is valid, Scope is ignored.  Otherwise, the first node
00142  *              within Scope is returned.
00143  *
00144  ******************************************************************************/
00145 
00146 ACPI_NAMESPACE_NODE *
00147 AcpiNsGetNextNode (
00148     ACPI_NAMESPACE_NODE     *ParentNode,
00149     ACPI_NAMESPACE_NODE     *ChildNode)
00150 {
00151     ACPI_FUNCTION_ENTRY ();
00152 
00153 
00154     if (!ChildNode)
00155     {
00156         /* It's really the parent's _scope_ that we want */
00157 
00158         return (ParentNode->Child);
00159     }
00160 
00161     /* Otherwise just return the next peer */
00162 
00163     return (ChildNode->Peer);
00164 }
00165 
00166 
00167 /*******************************************************************************
00168  *
00169  * FUNCTION:    AcpiNsGetNextNodeTyped
00170  *
00171  * PARAMETERS:  Type                - Type of node to be searched for
00172  *              ParentNode          - Parent node whose children we are
00173  *                                    getting
00174  *              ChildNode           - Previous child that was found.
00175  *                                    The NEXT child will be returned
00176  *
00177  * RETURN:      ACPI_NAMESPACE_NODE - Pointer to the NEXT child or NULL if
00178  *                                    none is found.
00179  *
00180  * DESCRIPTION: Return the next peer node within the namespace.  If Handle
00181  *              is valid, Scope is ignored.  Otherwise, the first node
00182  *              within Scope is returned.
00183  *
00184  ******************************************************************************/
00185 
00186 ACPI_NAMESPACE_NODE *
00187 AcpiNsGetNextNodeTyped (
00188     ACPI_OBJECT_TYPE        Type,
00189     ACPI_NAMESPACE_NODE     *ParentNode,
00190     ACPI_NAMESPACE_NODE     *ChildNode)
00191 {
00192     ACPI_NAMESPACE_NODE     *NextNode = NULL;
00193 
00194 
00195     ACPI_FUNCTION_ENTRY ();
00196 
00197 
00198     NextNode = AcpiNsGetNextNode (ParentNode, ChildNode);
00199 
00200     /* If any type is OK, we are done */
00201 
00202     if (Type == ACPI_TYPE_ANY)
00203     {
00204         /* NextNode is NULL if we are at the end-of-list */
00205 
00206         return (NextNode);
00207     }
00208 
00209     /* Must search for the node -- but within this scope only */
00210 
00211     while (NextNode)
00212     {
00213         /* If type matches, we are done */
00214 
00215         if (NextNode->Type == Type)
00216         {
00217             return (NextNode);
00218         }
00219 
00220         /* Otherwise, move on to the next peer node */
00221 
00222         NextNode = NextNode->Peer;
00223     }
00224 
00225     /* Not found */
00226 
00227     return (NULL);
00228 }
00229 
00230 
00231 /*******************************************************************************
00232  *
00233  * FUNCTION:    AcpiNsWalkNamespace
00234  *
00235  * PARAMETERS:  Type                - ACPI_OBJECT_TYPE to search for
00236  *              StartNode           - Handle in namespace where search begins
00237  *              MaxDepth            - Depth to which search is to reach
00238  *              Flags               - Whether to unlock the NS before invoking
00239  *                                    the callback routine
00240  *              PreOrderVisit       - Called during tree pre-order visit
00241  *                                    when an object of "Type" is found
00242  *              PostOrderVisit      - Called during tree post-order visit
00243  *                                    when an object of "Type" is found
00244  *              Context             - Passed to user function(s) above
00245  *              ReturnValue         - from the UserFunction if terminated
00246  *                                    early. Otherwise, returns NULL.
00247  * RETURNS:     Status
00248  *
00249  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
00250  *              starting (and ending) at the node specified by StartHandle.
00251  *              The callback function is called whenever a node that matches
00252  *              the type parameter is found. If the callback function returns
00253  *              a non-zero value, the search is terminated immediately and
00254  *              this value is returned to the caller.
00255  *
00256  *              The point of this procedure is to provide a generic namespace
00257  *              walk routine that can be called from multiple places to
00258  *              provide multiple services; the callback function(s) can be
00259  *              tailored to each task, whether it is a print function,
00260  *              a compare function, etc.
00261  *
00262  ******************************************************************************/
00263 
00264 ACPI_STATUS
00265 AcpiNsWalkNamespace (
00266     ACPI_OBJECT_TYPE        Type,
00267     ACPI_HANDLE             StartNode,
00268     UINT32                  MaxDepth,
00269     UINT32                  Flags,
00270     ACPI_WALK_CALLBACK      PreOrderVisit,
00271     ACPI_WALK_CALLBACK      PostOrderVisit,
00272     void                    *Context,
00273     void                    **ReturnValue)
00274 {
00275     ACPI_STATUS             Status;
00276     ACPI_STATUS             MutexStatus;
00277     ACPI_NAMESPACE_NODE     *ChildNode;
00278     ACPI_NAMESPACE_NODE     *ParentNode;
00279     ACPI_OBJECT_TYPE        ChildType;
00280     UINT32                  Level;
00281     BOOLEAN                 NodePreviouslyVisited = FALSE;
00282 
00283 
00284     ACPI_FUNCTION_TRACE (NsWalkNamespace);
00285 
00286 
00287     /* Special case for the namespace Root Node */
00288 
00289     if (StartNode == ACPI_ROOT_OBJECT)
00290     {
00291         StartNode = AcpiGbl_RootNode;
00292     }
00293 
00294     /* Null child means "get first node" */
00295 
00296     ParentNode  = StartNode;
00297     ChildNode   = AcpiNsGetNextNode (ParentNode, NULL);
00298     ChildType   = ACPI_TYPE_ANY;
00299     Level       = 1;
00300 
00301     /*
00302      * Traverse the tree of nodes until we bubble back up to where we
00303      * started. When Level is zero, the loop is done because we have
00304      * bubbled up to (and passed) the original parent handle (StartEntry)
00305      */
00306     while (Level > 0 && ChildNode)
00307     {
00308         Status = AE_OK;
00309 
00310         /* Found next child, get the type if we are not searching for ANY */
00311 
00312         if (Type != ACPI_TYPE_ANY)
00313         {
00314             ChildType = ChildNode->Type;
00315         }
00316 
00317         /*
00318          * Ignore all temporary namespace nodes (created during control
00319          * method execution) unless told otherwise. These temporary nodes
00320          * can cause a race condition because they can be deleted during
00321          * the execution of the user function (if the namespace is
00322          * unlocked before invocation of the user function.) Only the
00323          * debugger namespace dump will examine the temporary nodes.
00324          */
00325         if ((ChildNode->Flags & ANOBJ_TEMPORARY) &&
00326             !(Flags & ACPI_NS_WALK_TEMP_NODES))
00327         {
00328             Status = AE_CTRL_DEPTH;
00329         }
00330 
00331         /* Type must match requested type */
00332 
00333         else if (ChildType == Type)
00334         {
00335             /*
00336              * Found a matching node, invoke the user callback function.
00337              * Unlock the namespace if flag is set.
00338              */
00339             if (Flags & ACPI_NS_WALK_UNLOCK)
00340             {
00341                 MutexStatus = AcpiUtReleaseMutex (ACPI_MTX_NAMESPACE);
00342                 if (ACPI_FAILURE (MutexStatus))
00343                 {
00344                     return_ACPI_STATUS (MutexStatus);
00345                 }
00346             }
00347 
00348             /*
00349              * Invoke the user function, either pre-order or post-order
00350              * or both.
00351              */
00352             if (!NodePreviouslyVisited)
00353             {
00354                 if (PreOrderVisit)
00355                 {
00356                     Status = PreOrderVisit (ChildNode, Level,
00357                                 Context, ReturnValue);
00358                 }
00359             }
00360             else
00361             {
00362                 if (PostOrderVisit)
00363                 {
00364                     Status = PostOrderVisit (ChildNode, Level,
00365                                 Context, ReturnValue);
00366                 }
00367             }
00368 
00369             if (Flags & ACPI_NS_WALK_UNLOCK)
00370             {
00371                 MutexStatus = AcpiUtAcquireMutex (ACPI_MTX_NAMESPACE);
00372                 if (ACPI_FAILURE (MutexStatus))
00373                 {
00374                     return_ACPI_STATUS (MutexStatus);
00375                 }
00376             }
00377 
00378             switch (Status)
00379             {
00380             case AE_OK:
00381             case AE_CTRL_DEPTH:
00382 
00383                 /* Just keep going */
00384                 break;
00385 
00386             case AE_CTRL_TERMINATE:
00387 
00388                 /* Exit now, with OK status */
00389 
00390                 return_ACPI_STATUS (AE_OK);
00391 
00392             default:
00393 
00394                 /* All others are valid exceptions */
00395 
00396                 return_ACPI_STATUS (Status);
00397             }
00398         }
00399 
00400         /*
00401          * Depth first search: Attempt to go down another level in the
00402          * namespace if we are allowed to.  Don't go any further if we have
00403          * reached the caller specified maximum depth or if the user
00404          * function has specified that the maximum depth has been reached.
00405          */
00406         if (!NodePreviouslyVisited &&
00407             (Level < MaxDepth) &&
00408             (Status != AE_CTRL_DEPTH))
00409         {
00410             if (ChildNode->Child)
00411             {
00412                 /* There is at least one child of this node, visit it */
00413 
00414                 Level++;
00415                 ParentNode = ChildNode;
00416                 ChildNode = AcpiNsGetNextNode (ParentNode, NULL);
00417                 continue;
00418             }
00419         }
00420 
00421         /* No more children, re-visit this node */
00422 
00423         if (!NodePreviouslyVisited)
00424         {
00425             NodePreviouslyVisited = TRUE;
00426             continue;
00427         }
00428 
00429         /* No more children, visit peers */
00430 
00431         ChildNode = AcpiNsGetNextNode (ParentNode, ChildNode);
00432         if (ChildNode)
00433         {
00434             NodePreviouslyVisited = FALSE;
00435         }
00436 
00437         /* No peers, re-visit parent */
00438 
00439         else
00440         {
00441             /*
00442              * No more children of this node (AcpiNsGetNextNode failed), go
00443              * back upwards in the namespace tree to the node's parent.
00444              */
00445             Level--;
00446             ChildNode = ParentNode;
00447             ParentNode = ParentNode->Parent;
00448 
00449             NodePreviouslyVisited = TRUE;
00450         }
00451     }
00452 
00453     /* Complete walk, not terminated by user function */
00454 
00455     return_ACPI_STATUS (AE_OK);
00456 }
00457 
00458 

Generated on Sun May 27 2012 04:27:21 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.