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

pstree.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: pstree - Parser op tree manipulation/traversal/search
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 __PSTREE_C__
00118 
00119 #include "acpi.h"
00120 #include "accommon.h"
00121 #include "acparser.h"
00122 #include "amlcode.h"
00123 
00124 #define _COMPONENT          ACPI_PARSER
00125         ACPI_MODULE_NAME    ("pstree")
00126 
00127 /* Local prototypes */
00128 
00129 #ifdef ACPI_OBSOLETE_FUNCTIONS
00130 ACPI_PARSE_OBJECT *
00131 AcpiPsGetChild (
00132     ACPI_PARSE_OBJECT       *op);
00133 #endif
00134 
00135 
00136 /*******************************************************************************
00137  *
00138  * FUNCTION:    AcpiPsGetArg
00139  *
00140  * PARAMETERS:  Op              - Get an argument for this op
00141  *              Argn            - Nth argument to get
00142  *
00143  * RETURN:      The argument (as an Op object). NULL if argument does not exist
00144  *
00145  * DESCRIPTION: Get the specified op's argument.
00146  *
00147  ******************************************************************************/
00148 
00149 ACPI_PARSE_OBJECT *
00150 AcpiPsGetArg (
00151     ACPI_PARSE_OBJECT       *Op,
00152     UINT32                  Argn)
00153 {
00154     ACPI_PARSE_OBJECT       *Arg = NULL;
00155     const ACPI_OPCODE_INFO  *OpInfo;
00156 
00157 
00158     ACPI_FUNCTION_ENTRY ();
00159 
00160 
00161     /* Get the info structure for this opcode */
00162 
00163     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
00164     if (OpInfo->Class == AML_CLASS_UNKNOWN)
00165     {
00166         /* Invalid opcode or ASCII character */
00167 
00168         return (NULL);
00169     }
00170 
00171     /* Check if this opcode requires argument sub-objects */
00172 
00173     if (!(OpInfo->Flags & AML_HAS_ARGS))
00174     {
00175         /* Has no linked argument objects */
00176 
00177         return (NULL);
00178     }
00179 
00180     /* Get the requested argument object */
00181 
00182     Arg = Op->Common.Value.Arg;
00183     while (Arg && Argn)
00184     {
00185         Argn--;
00186         Arg = Arg->Common.Next;
00187     }
00188 
00189     return (Arg);
00190 }
00191 
00192 
00193 /*******************************************************************************
00194  *
00195  * FUNCTION:    AcpiPsAppendArg
00196  *
00197  * PARAMETERS:  Op              - Append an argument to this Op.
00198  *              Arg             - Argument Op to append
00199  *
00200  * RETURN:      None.
00201  *
00202  * DESCRIPTION: Append an argument to an op's argument list (a NULL arg is OK)
00203  *
00204  ******************************************************************************/
00205 
00206 void
00207 AcpiPsAppendArg (
00208     ACPI_PARSE_OBJECT       *Op,
00209     ACPI_PARSE_OBJECT       *Arg)
00210 {
00211     ACPI_PARSE_OBJECT       *PrevArg;
00212     const ACPI_OPCODE_INFO  *OpInfo;
00213 
00214 
00215     ACPI_FUNCTION_ENTRY ();
00216 
00217 
00218     if (!Op)
00219     {
00220         return;
00221     }
00222 
00223     /* Get the info structure for this opcode */
00224 
00225     OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
00226     if (OpInfo->Class == AML_CLASS_UNKNOWN)
00227     {
00228         /* Invalid opcode */
00229 
00230         ACPI_ERROR ((AE_INFO, "Invalid AML Opcode: 0x%2.2X",
00231             Op->Common.AmlOpcode));
00232         return;
00233     }
00234 
00235     /* Check if this opcode requires argument sub-objects */
00236 
00237     if (!(OpInfo->Flags & AML_HAS_ARGS))
00238     {
00239         /* Has no linked argument objects */
00240 
00241         return;
00242     }
00243 
00244     /* Append the argument to the linked argument list */
00245 
00246     if (Op->Common.Value.Arg)
00247     {
00248         /* Append to existing argument list */
00249 
00250         PrevArg = Op->Common.Value.Arg;
00251         while (PrevArg->Common.Next)
00252         {
00253             PrevArg = PrevArg->Common.Next;
00254         }
00255         PrevArg->Common.Next = Arg;
00256     }
00257     else
00258     {
00259         /* No argument list, this will be the first argument */
00260 
00261         Op->Common.Value.Arg = Arg;
00262     }
00263 
00264     /* Set the parent in this arg and any args linked after it */
00265 
00266     while (Arg)
00267     {
00268         Arg->Common.Parent = Op;
00269         Arg = Arg->Common.Next;
00270 
00271         Op->Common.ArgListLength++;
00272     }
00273 }
00274 
00275 
00276 /*******************************************************************************
00277  *
00278  * FUNCTION:    AcpiPsGetDepthNext
00279  *
00280  * PARAMETERS:  Origin          - Root of subtree to search
00281  *              Op              - Last (previous) Op that was found
00282  *
00283  * RETURN:      Next Op found in the search.
00284  *
00285  * DESCRIPTION: Get next op in tree (walking the tree in depth-first order)
00286  *              Return NULL when reaching "origin" or when walking up from root
00287  *
00288  ******************************************************************************/
00289 
00290 ACPI_PARSE_OBJECT *
00291 AcpiPsGetDepthNext (
00292     ACPI_PARSE_OBJECT       *Origin,
00293     ACPI_PARSE_OBJECT       *Op)
00294 {
00295     ACPI_PARSE_OBJECT       *Next = NULL;
00296     ACPI_PARSE_OBJECT       *Parent;
00297     ACPI_PARSE_OBJECT       *Arg;
00298 
00299 
00300     ACPI_FUNCTION_ENTRY ();
00301 
00302 
00303     if (!Op)
00304     {
00305         return (NULL);
00306     }
00307 
00308     /* Look for an argument or child */
00309 
00310     Next = AcpiPsGetArg (Op, 0);
00311     if (Next)
00312     {
00313         return (Next);
00314     }
00315 
00316     /* Look for a sibling */
00317 
00318     Next = Op->Common.Next;
00319     if (Next)
00320     {
00321         return (Next);
00322     }
00323 
00324     /* Look for a sibling of parent */
00325 
00326     Parent = Op->Common.Parent;
00327 
00328     while (Parent)
00329     {
00330         Arg = AcpiPsGetArg (Parent, 0);
00331         while (Arg && (Arg != Origin) && (Arg != Op))
00332         {
00333             Arg = Arg->Common.Next;
00334         }
00335 
00336         if (Arg == Origin)
00337         {
00338             /* Reached parent of origin, end search */
00339 
00340             return (NULL);
00341         }
00342 
00343         if (Parent->Common.Next)
00344         {
00345             /* Found sibling of parent */
00346 
00347             return (Parent->Common.Next);
00348         }
00349 
00350         Op = Parent;
00351         Parent = Parent->Common.Parent;
00352     }
00353 
00354     return (Next);
00355 }
00356 
00357 
00358 #ifdef ACPI_OBSOLETE_FUNCTIONS
00359 /*******************************************************************************
00360  *
00361  * FUNCTION:    AcpiPsGetChild
00362  *
00363  * PARAMETERS:  Op              - Get the child of this Op
00364  *
00365  * RETURN:      Child Op, Null if none is found.
00366  *
00367  * DESCRIPTION: Get op's children or NULL if none
00368  *
00369  ******************************************************************************/
00370 
00371 ACPI_PARSE_OBJECT *
00372 AcpiPsGetChild (
00373     ACPI_PARSE_OBJECT       *Op)
00374 {
00375     ACPI_PARSE_OBJECT       *Child = NULL;
00376 
00377 
00378     ACPI_FUNCTION_ENTRY ();
00379 
00380 
00381     switch (Op->Common.AmlOpcode)
00382     {
00383     case AML_SCOPE_OP:
00384     case AML_ELSE_OP:
00385     case AML_DEVICE_OP:
00386     case AML_THERMAL_ZONE_OP:
00387     case AML_INT_METHODCALL_OP:
00388 
00389         Child = AcpiPsGetArg (Op, 0);
00390         break;
00391 
00392 
00393     case AML_BUFFER_OP:
00394     case AML_PACKAGE_OP:
00395     case AML_METHOD_OP:
00396     case AML_IF_OP:
00397     case AML_WHILE_OP:
00398     case AML_FIELD_OP:
00399 
00400         Child = AcpiPsGetArg (Op, 1);
00401         break;
00402 
00403 
00404     case AML_POWER_RES_OP:
00405     case AML_INDEX_FIELD_OP:
00406 
00407         Child = AcpiPsGetArg (Op, 2);
00408         break;
00409 
00410 
00411     case AML_PROCESSOR_OP:
00412     case AML_BANK_FIELD_OP:
00413 
00414         Child = AcpiPsGetArg (Op, 3);
00415         break;
00416 
00417 
00418     default:
00419         /* All others have no children */
00420         break;
00421     }
00422 
00423     return (Child);
00424 }
00425 #endif
00426 
00427 

Generated on Sat May 26 2012 04:25:55 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.