Home | History | Annotate | Line # | Download | only in compiler
asltree.c revision 1.18.6.1
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3      1.11  christos  * Module Name: asltree - Parse tree management
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7  1.18.6.1  perseant /******************************************************************************
      8  1.18.6.1  perseant  *
      9  1.18.6.1  perseant  * 1. Copyright Notice
     10  1.18.6.1  perseant  *
     11  1.18.6.1  perseant  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.18.6.1  perseant  * 2. License
     15  1.18.6.1  perseant  *
     16  1.18.6.1  perseant  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.18.6.1  perseant  * rights. You may have additional license terms from the party that provided
     18  1.18.6.1  perseant  * you this software, covering your right to use that party's intellectual
     19  1.18.6.1  perseant  * property rights.
     20  1.18.6.1  perseant  *
     21  1.18.6.1  perseant  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.18.6.1  perseant  * copy of the source code appearing in this file ("Covered Code") an
     23  1.18.6.1  perseant  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.18.6.1  perseant  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.18.6.1  perseant  * make derivatives, distribute, use and display any portion of the Covered
     26  1.18.6.1  perseant  * Code in any form, with the right to sublicense such rights; and
     27  1.18.6.1  perseant  *
     28  1.18.6.1  perseant  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.18.6.1  perseant  * license (with the right to sublicense), under only those claims of Intel
     30  1.18.6.1  perseant  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.18.6.1  perseant  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.18.6.1  perseant  * solely to the minimum extent necessary to exercise the above copyright
     33  1.18.6.1  perseant  * license, and in no event shall the patent license extend to any additions
     34  1.18.6.1  perseant  * to or modifications of the Original Intel Code. No other license or right
     35  1.18.6.1  perseant  * is granted directly or by implication, estoppel or otherwise;
     36  1.18.6.1  perseant  *
     37  1.18.6.1  perseant  * The above copyright and patent license is granted only if the following
     38  1.18.6.1  perseant  * conditions are met:
     39  1.18.6.1  perseant  *
     40  1.18.6.1  perseant  * 3. Conditions
     41  1.18.6.1  perseant  *
     42  1.18.6.1  perseant  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.18.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     44  1.18.6.1  perseant  * Code or modification with rights to further distribute source must include
     45  1.18.6.1  perseant  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.18.6.1  perseant  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.18.6.1  perseant  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.18.6.1  perseant  * contain a file documenting the changes Licensee made to create that Covered
     49  1.18.6.1  perseant  * Code and the date of any change. Licensee must include in that file the
     50  1.18.6.1  perseant  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.18.6.1  perseant  * must include a prominent statement that the modification is derived,
     52  1.18.6.1  perseant  * directly or indirectly, from Original Intel Code.
     53  1.18.6.1  perseant  *
     54  1.18.6.1  perseant  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.18.6.1  perseant  * Redistribution of source code of any substantial portion of the Covered
     56  1.18.6.1  perseant  * Code or modification without rights to further distribute source must
     57  1.18.6.1  perseant  * include the following Disclaimer and Export Compliance provision in the
     58  1.18.6.1  perseant  * documentation and/or other materials provided with distribution. In
     59  1.18.6.1  perseant  * addition, Licensee may not authorize further sublicense of source of any
     60  1.18.6.1  perseant  * portion of the Covered Code, and must include terms to the effect that the
     61  1.18.6.1  perseant  * license from Licensee to its licensee is limited to the intellectual
     62  1.18.6.1  perseant  * property embodied in the software Licensee provides to its licensee, and
     63  1.18.6.1  perseant  * not to intellectual property embodied in modifications its licensee may
     64  1.18.6.1  perseant  * make.
     65  1.18.6.1  perseant  *
     66  1.18.6.1  perseant  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.18.6.1  perseant  * substantial portion of the Covered Code or modification must reproduce the
     68  1.18.6.1  perseant  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.18.6.1  perseant  * provision in the documentation and/or other materials provided with the
     70  1.18.6.1  perseant  * distribution.
     71  1.18.6.1  perseant  *
     72  1.18.6.1  perseant  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.18.6.1  perseant  * Intel Code.
     74  1.18.6.1  perseant  *
     75  1.18.6.1  perseant  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.18.6.1  perseant  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.18.6.1  perseant  * other dealings in products derived from or relating to the Covered Code
     78  1.18.6.1  perseant  * without prior written authorization from Intel.
     79  1.18.6.1  perseant  *
     80  1.18.6.1  perseant  * 4. Disclaimer and Export Compliance
     81  1.18.6.1  perseant  *
     82  1.18.6.1  perseant  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.18.6.1  perseant  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.18.6.1  perseant  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.18.6.1  perseant  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.18.6.1  perseant  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.18.6.1  perseant  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.18.6.1  perseant  * PARTICULAR PURPOSE.
     89  1.18.6.1  perseant  *
     90  1.18.6.1  perseant  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.18.6.1  perseant  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.18.6.1  perseant  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.18.6.1  perseant  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.18.6.1  perseant  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.18.6.1  perseant  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.18.6.1  perseant  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.18.6.1  perseant  * LIMITED REMEDY.
     98  1.18.6.1  perseant  *
     99  1.18.6.1  perseant  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.18.6.1  perseant  * software or system incorporating such software without first obtaining any
    101  1.18.6.1  perseant  * required license or other approval from the U. S. Department of Commerce or
    102  1.18.6.1  perseant  * any other agency or department of the United States Government. In the
    103  1.18.6.1  perseant  * event Licensee exports any such software from the United States or
    104  1.18.6.1  perseant  * re-exports any such software from a foreign destination, Licensee shall
    105  1.18.6.1  perseant  * ensure that the distribution and export/re-export of the software is in
    106  1.18.6.1  perseant  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.18.6.1  perseant  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.18.6.1  perseant  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.18.6.1  perseant  * software, or service, directly or indirectly, to any country for which the
    110  1.18.6.1  perseant  * United States government or any agency thereof requires an export license,
    111  1.18.6.1  perseant  * other governmental approval, or letter of assurance, without first obtaining
    112  1.18.6.1  perseant  * such license, approval or letter.
    113  1.18.6.1  perseant  *
    114  1.18.6.1  perseant  *****************************************************************************
    115  1.18.6.1  perseant  *
    116  1.18.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    117  1.18.6.1  perseant  * following license:
    118  1.18.6.1  perseant  *
    119       1.2  christos  * Redistribution and use in source and binary forms, with or without
    120       1.2  christos  * modification, are permitted provided that the following conditions
    121       1.2  christos  * are met:
    122       1.2  christos  * 1. Redistributions of source code must retain the above copyright
    123       1.2  christos  *    notice, this list of conditions, and the following disclaimer,
    124       1.2  christos  *    without modification.
    125       1.2  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126       1.2  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
    127       1.2  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
    128       1.2  christos  *    including a substantially similar Disclaimer requirement for further
    129       1.2  christos  *    binary redistribution.
    130       1.2  christos  * 3. Neither the names of the above-listed copyright holders nor the names
    131       1.2  christos  *    of any contributors may be used to endorse or promote products derived
    132       1.2  christos  *    from this software without specific prior written permission.
    133       1.2  christos  *
    134       1.2  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135       1.2  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136      1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137       1.2  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.18.6.1  perseant  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.18.6.1  perseant  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.18.6.1  perseant  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.18.6.1  perseant  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.18.6.1  perseant  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.18.6.1  perseant  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.18.6.1  perseant  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.18.6.1  perseant  *
    146  1.18.6.1  perseant  * Alternatively, you may choose to be licensed under the terms of the
    147  1.18.6.1  perseant  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.18.6.1  perseant  * Software Foundation.
    149  1.18.6.1  perseant  *
    150  1.18.6.1  perseant  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "aslcompiler.h"
    153       1.1    jruoho #include "aslcompiler.y.h"
    154       1.3  christos #include "acapps.h"
    155       1.1    jruoho 
    156       1.1    jruoho #define _COMPONENT          ACPI_COMPILER
    157       1.1    jruoho         ACPI_MODULE_NAME    ("asltree")
    158       1.1    jruoho 
    159       1.6  christos 
    160       1.6  christos /*******************************************************************************
    161       1.6  christos  *
    162      1.11  christos  * FUNCTION:    TrSetOpIntegerValue
    163       1.1    jruoho  *
    164      1.11  christos  * PARAMETERS:  ParseOpcode         - New opcode to be assigned to the op
    165      1.11  christos  *              Op                  - An existing parse op
    166       1.1    jruoho  *
    167      1.11  christos  * RETURN:      The updated op
    168       1.1    jruoho  *
    169      1.11  christos  * DESCRIPTION: Used to set the integer value of a op,
    170      1.11  christos  *              usually to a specific size (8, 16, 32, or 64 bits)
    171       1.1    jruoho  *
    172       1.1    jruoho  ******************************************************************************/
    173       1.1    jruoho 
    174       1.1    jruoho ACPI_PARSE_OBJECT *
    175      1.11  christos TrSetOpIntegerValue (
    176       1.1    jruoho     UINT32                  ParseOpcode,
    177       1.1    jruoho     ACPI_PARSE_OBJECT       *Op)
    178       1.1    jruoho {
    179       1.1    jruoho 
    180       1.1    jruoho     if (!Op)
    181       1.1    jruoho     {
    182       1.3  christos         return (NULL);
    183       1.1    jruoho     }
    184       1.1    jruoho 
    185       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    186      1.11  christos         "\nUpdateOp: Old - %s, New - %s\n",
    187       1.1    jruoho         UtGetOpName (Op->Asl.ParseOpcode),
    188       1.1    jruoho         UtGetOpName (ParseOpcode));
    189       1.1    jruoho 
    190       1.1    jruoho     /* Assign new opcode and name */
    191       1.1    jruoho 
    192       1.1    jruoho     if (Op->Asl.ParseOpcode == PARSEOP_ONES)
    193       1.1    jruoho     {
    194       1.1    jruoho         switch (ParseOpcode)
    195       1.1    jruoho         {
    196       1.1    jruoho         case PARSEOP_BYTECONST:
    197       1.3  christos 
    198       1.3  christos             Op->Asl.Value.Integer = ACPI_UINT8_MAX;
    199       1.1    jruoho             break;
    200       1.1    jruoho 
    201       1.1    jruoho         case PARSEOP_WORDCONST:
    202       1.3  christos 
    203       1.3  christos             Op->Asl.Value.Integer = ACPI_UINT16_MAX;
    204       1.1    jruoho             break;
    205       1.1    jruoho 
    206       1.1    jruoho         case PARSEOP_DWORDCONST:
    207       1.3  christos 
    208       1.3  christos             Op->Asl.Value.Integer = ACPI_UINT32_MAX;
    209       1.1    jruoho             break;
    210       1.1    jruoho 
    211       1.3  christos         /* Don't need to do the QWORD case */
    212       1.3  christos 
    213       1.1    jruoho         default:
    214       1.3  christos 
    215       1.3  christos             /* Don't care about others */
    216       1.1    jruoho             break;
    217       1.1    jruoho         }
    218       1.1    jruoho     }
    219       1.1    jruoho 
    220       1.1    jruoho     Op->Asl.ParseOpcode = (UINT16) ParseOpcode;
    221       1.1    jruoho     UtSetParseOpName (Op);
    222       1.1    jruoho 
    223       1.1    jruoho     /*
    224       1.1    jruoho      * For the BYTE, WORD, and DWORD constants, make sure that the integer
    225       1.1    jruoho      * that was passed in will actually fit into the data type
    226       1.1    jruoho      */
    227       1.1    jruoho     switch (ParseOpcode)
    228       1.1    jruoho     {
    229       1.1    jruoho     case PARSEOP_BYTECONST:
    230       1.3  christos 
    231       1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT8_MAX);
    232       1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT8_MAX;
    233       1.1    jruoho         break;
    234       1.1    jruoho 
    235       1.1    jruoho     case PARSEOP_WORDCONST:
    236       1.3  christos 
    237       1.3  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT16_MAX);
    238       1.3  christos         Op->Asl.Value.Integer &= ACPI_UINT16_MAX;
    239       1.1    jruoho         break;
    240       1.1    jruoho 
    241      1.11  christos     case PARSEOP_DWORDCONST:
    242       1.5  christos 
    243      1.11  christos         UtCheckIntegerRange (Op, 0x00, ACPI_UINT32_MAX);
    244      1.11  christos         Op->Asl.Value.Integer &= ACPI_UINT32_MAX;
    245      1.11  christos         break;
    246       1.5  christos 
    247      1.11  christos     default:
    248       1.5  christos 
    249      1.11  christos         /* Don't care about others, don't need to check QWORD */
    250       1.5  christos 
    251      1.11  christos         break;
    252      1.11  christos     }
    253       1.5  christos 
    254      1.11  christos     /* Converter: if this is a method invocation, turn off capture comments */
    255       1.5  christos 
    256      1.12  christos     if (AcpiGbl_CaptureComments &&
    257      1.11  christos         (ParseOpcode == PARSEOP_METHODCALL))
    258      1.11  christos     {
    259      1.13  christos         AslGbl_CommentState.CaptureComments = FALSE;
    260      1.11  christos     }
    261       1.5  christos 
    262      1.11  christos     return (Op);
    263       1.5  christos }
    264       1.5  christos 
    265       1.5  christos 
    266       1.5  christos /*******************************************************************************
    267       1.5  christos  *
    268      1.11  christos  * FUNCTION:    TrSetOpFlags
    269       1.1    jruoho  *
    270      1.11  christos  * PARAMETERS:  Op                  - An existing parse op
    271      1.11  christos  *              Flags               - New flags word
    272       1.1    jruoho  *
    273      1.11  christos  * RETURN:      The updated parser op
    274       1.1    jruoho  *
    275      1.11  christos  * DESCRIPTION: Set bits in the op flags word. Will not clear bits, only set
    276       1.1    jruoho  *
    277       1.1    jruoho  ******************************************************************************/
    278       1.1    jruoho 
    279       1.1    jruoho ACPI_PARSE_OBJECT *
    280      1.11  christos TrSetOpFlags (
    281      1.11  christos     ACPI_PARSE_OBJECT       *Op,
    282      1.11  christos     UINT32                  Flags)
    283       1.1    jruoho {
    284       1.1    jruoho 
    285      1.11  christos     if (!Op)
    286      1.11  christos     {
    287      1.11  christos         return (NULL);
    288      1.11  christos     }
    289       1.1    jruoho 
    290      1.11  christos     DbgPrint (ASL_PARSE_OUTPUT,
    291      1.11  christos         "\nSetOpFlags: %s Op %p, %8.8X", Op->Asl.ParseOpName, Op, Flags);
    292       1.1    jruoho 
    293      1.11  christos     TrPrintOpFlags (Flags, ASL_PARSE_OUTPUT);
    294      1.11  christos     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    295       1.5  christos 
    296      1.11  christos     Op->Asl.CompileFlags |= Flags;
    297       1.5  christos     return (Op);
    298       1.5  christos }
    299       1.5  christos 
    300       1.5  christos 
    301       1.5  christos /*******************************************************************************
    302       1.5  christos  *
    303      1.11  christos  * FUNCTION:    TrSetOpAmlLength
    304       1.5  christos  *
    305      1.11  christos  * PARAMETERS:  Op                  - An existing parse op
    306      1.11  christos  *              Length              - AML Length
    307       1.5  christos  *
    308      1.11  christos  * RETURN:      The updated parser op
    309       1.5  christos  *
    310      1.11  christos  * DESCRIPTION: Set the AML Length in a op. Used by the parser to indicate
    311      1.11  christos  *              the presence of a op that must be reduced to a fixed length
    312      1.11  christos  *              constant.
    313       1.5  christos  *
    314       1.5  christos  ******************************************************************************/
    315       1.5  christos 
    316       1.5  christos ACPI_PARSE_OBJECT *
    317      1.11  christos TrSetOpAmlLength (
    318      1.11  christos     ACPI_PARSE_OBJECT       *Op,
    319      1.11  christos     UINT32                  Length)
    320       1.5  christos {
    321       1.5  christos 
    322      1.11  christos     DbgPrint (ASL_PARSE_OUTPUT,
    323      1.11  christos         "\nSetOpAmlLength: Op %p, %8.8X\n", Op, Length);
    324       1.5  christos 
    325      1.11  christos     if (!Op)
    326      1.11  christos     {
    327      1.11  christos         return (NULL);
    328      1.11  christos     }
    329       1.1    jruoho 
    330      1.11  christos     Op->Asl.AmlLength = Length;
    331       1.3  christos     return (Op);
    332       1.1    jruoho }
    333       1.1    jruoho 
    334       1.1    jruoho 
    335       1.1    jruoho /*******************************************************************************
    336       1.1    jruoho  *
    337      1.11  christos  * FUNCTION:    TrSetOpParent
    338       1.2  christos  *
    339      1.11  christos  * PARAMETERS:  Op                  - To be set to new parent
    340      1.11  christos  *              ParentOp            - The parent
    341       1.2  christos  *
    342      1.11  christos  * RETURN:      None, sets Op parent directly
    343       1.2  christos  *
    344      1.11  christos  * DESCRIPTION: Change the parent of a parse op.
    345       1.2  christos  *
    346       1.2  christos  ******************************************************************************/
    347       1.2  christos 
    348      1.11  christos void
    349      1.11  christos TrSetOpParent (
    350      1.11  christos     ACPI_PARSE_OBJECT       *Op,
    351      1.11  christos     ACPI_PARSE_OBJECT       *ParentOp)
    352       1.2  christos {
    353       1.2  christos 
    354      1.11  christos     Op->Asl.Parent = ParentOp;
    355       1.2  christos }
    356       1.2  christos 
    357       1.2  christos 
    358       1.2  christos /*******************************************************************************
    359       1.2  christos  *
    360      1.11  christos  * FUNCTION:    TrSetOpCurrentFilename
    361       1.5  christos  *
    362      1.11  christos  * PARAMETERS:  Op                  - An existing parse op
    363       1.5  christos  *
    364      1.11  christos  * RETURN:      None
    365       1.5  christos  *
    366      1.11  christos  * DESCRIPTION: Save the include file filename. Used for debug output only.
    367       1.5  christos  *
    368       1.5  christos  ******************************************************************************/
    369       1.5  christos 
    370      1.11  christos void
    371      1.11  christos TrSetOpCurrentFilename (
    372      1.11  christos     ACPI_PARSE_OBJECT       *Op)
    373       1.5  christos {
    374       1.5  christos 
    375      1.13  christos     Op->Asl.Filename = AslGbl_PreviousIncludeFilename;
    376       1.5  christos }
    377       1.5  christos 
    378       1.5  christos 
    379       1.5  christos /*******************************************************************************
    380       1.5  christos  *
    381      1.11  christos  * FUNCTION:    TrSetOpIntegerWidth
    382       1.1    jruoho  *
    383      1.11  christos  * PARAMETERS:  Op                  - An existing parse op
    384       1.1    jruoho  *
    385      1.11  christos  * RETURN:      None
    386       1.1    jruoho  *
    387      1.11  christos  * DESCRIPTION:
    388       1.1    jruoho  *
    389       1.1    jruoho  ******************************************************************************/
    390       1.1    jruoho 
    391      1.11  christos void
    392      1.11  christos TrSetOpIntegerWidth (
    393      1.11  christos     ACPI_PARSE_OBJECT       *TableSignatureOp,
    394      1.11  christos     ACPI_PARSE_OBJECT       *RevisionOp)
    395       1.1    jruoho {
    396       1.1    jruoho 
    397      1.11  christos     /* TBD: Check table sig? (DSDT vs. SSDT) */
    398       1.1    jruoho 
    399      1.11  christos     /* Handle command-line version override */
    400       1.1    jruoho 
    401      1.13  christos     if (AslGbl_RevisionOverride)
    402      1.11  christos     {
    403      1.13  christos         AcpiUtSetIntegerWidth (AslGbl_RevisionOverride);
    404      1.11  christos     }
    405      1.11  christos     else
    406       1.1    jruoho     {
    407      1.11  christos         AcpiUtSetIntegerWidth ((UINT8) RevisionOp->Asl.Value.Integer);
    408       1.1    jruoho     }
    409       1.1    jruoho }
    410       1.1    jruoho 
    411       1.1    jruoho 
    412       1.1    jruoho /*******************************************************************************
    413       1.1    jruoho  *
    414      1.11  christos  * FUNCTION:    TrSetOpEndLineNumber
    415       1.1    jruoho  *
    416      1.11  christos  * PARAMETERS:  Op                - An existing parse op
    417       1.1    jruoho  *
    418      1.11  christos  * RETURN:      None.
    419       1.1    jruoho  *
    420      1.11  christos  * DESCRIPTION: Set the ending line numbers (file line and logical line) of a
    421      1.11  christos  *              parse op to the current line numbers.
    422       1.1    jruoho  *
    423       1.1    jruoho  ******************************************************************************/
    424       1.1    jruoho 
    425      1.11  christos void
    426      1.11  christos TrSetOpEndLineNumber (
    427      1.11  christos     ACPI_PARSE_OBJECT       *Op)
    428       1.1    jruoho {
    429       1.1    jruoho 
    430      1.11  christos     /* If the end line # is already set, just return */
    431       1.1    jruoho 
    432      1.11  christos     if (Op->Asl.EndLine)
    433       1.1    jruoho     {
    434      1.11  christos         return;
    435       1.1    jruoho     }
    436       1.1    jruoho 
    437      1.13  christos     Op->Asl.EndLine = AslGbl_CurrentLineNumber;
    438      1.13  christos     Op->Asl.EndLogicalLine = AslGbl_LogicalLineNumber;
    439       1.1    jruoho }
    440       1.1    jruoho 
    441       1.1    jruoho 
    442       1.1    jruoho /*******************************************************************************
    443       1.1    jruoho  *
    444      1.11  christos  * FUNCTION:    TrLinkOpChildren
    445       1.1    jruoho  *
    446      1.11  christos  * PARAMETERS:  Op                - An existing parse op
    447       1.9  christos  *              NumChildren        - Number of children to follow
    448      1.11  christos  *              ...                - A list of child ops to link to the new
    449      1.11  christos  *                                   op. NumChildren long.
    450       1.1    jruoho  *
    451      1.11  christos  * RETURN:      The updated (linked) op
    452       1.1    jruoho  *
    453      1.11  christos  * DESCRIPTION: Link a group of ops to an existing parse op
    454       1.1    jruoho  *
    455       1.1    jruoho  ******************************************************************************/
    456       1.1    jruoho 
    457       1.1    jruoho ACPI_PARSE_OBJECT *
    458      1.11  christos TrLinkOpChildren (
    459       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    460       1.1    jruoho     UINT32                  NumChildren,
    461       1.1    jruoho     ...)
    462       1.1    jruoho {
    463       1.1    jruoho     ACPI_PARSE_OBJECT       *Child;
    464       1.1    jruoho     ACPI_PARSE_OBJECT       *PrevChild;
    465      1.14  christos     ACPI_PARSE_OBJECT       *LastSibling;
    466       1.1    jruoho     va_list                 ap;
    467       1.1    jruoho     UINT32                  i;
    468       1.1    jruoho     BOOLEAN                 FirstChild;
    469       1.1    jruoho 
    470      1.18  christos     ACPI_FUNCTION_NAME (TrLinkOpChildren);
    471       1.1    jruoho 
    472       1.1    jruoho     va_start (ap, NumChildren);
    473       1.1    jruoho 
    474      1.11  christos     TrSetOpEndLineNumber (Op);
    475       1.1    jruoho 
    476       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    477       1.1    jruoho         "\nLinkChildren  Line [%u to %u] NewParent %p Child %u Op %s  ",
    478       1.1    jruoho         Op->Asl.LineNumber, Op->Asl.EndLine,
    479       1.1    jruoho         Op, NumChildren, UtGetOpName(Op->Asl.ParseOpcode));
    480       1.1    jruoho 
    481       1.1    jruoho     switch (Op->Asl.ParseOpcode)
    482       1.1    jruoho     {
    483       1.6  christos     case PARSEOP_ASL_CODE:
    484       1.3  christos 
    485      1.14  christos         if (!AslGbl_ParseTreeRoot)
    486      1.14  christos         {
    487      1.14  christos             DbgPrint (ASL_PARSE_OUTPUT, "Creating first Definition Block\n");
    488      1.14  christos             AslGbl_ParseTreeRoot = Op;
    489      1.14  christos             Op->Asl.ParseOpcode = PARSEOP_DEFAULT_ARG;
    490      1.14  christos         }
    491      1.14  christos         else
    492      1.14  christos         {
    493      1.14  christos             DbgPrint (ASL_PARSE_OUTPUT, "Creating subsequent Definition Block\n");
    494      1.14  christos             Op = AslGbl_ParseTreeRoot;
    495      1.14  christos         }
    496      1.14  christos 
    497       1.6  christos         DbgPrint (ASL_PARSE_OUTPUT, "ASLCODE (Tree Completed)->");
    498       1.6  christos         break;
    499       1.6  christos 
    500       1.6  christos     case PARSEOP_DEFINITION_BLOCK:
    501       1.6  christos 
    502       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "DEFINITION_BLOCK (Tree Completed)->");
    503       1.1    jruoho         break;
    504       1.1    jruoho 
    505       1.1    jruoho     case PARSEOP_OPERATIONREGION:
    506       1.3  christos 
    507       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OPREGION->");
    508       1.1    jruoho         break;
    509       1.1    jruoho 
    510       1.1    jruoho     case PARSEOP_OR:
    511       1.3  christos 
    512       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "OR->");
    513       1.1    jruoho         break;
    514       1.1    jruoho 
    515       1.1    jruoho     default:
    516       1.3  christos 
    517       1.1    jruoho         /* Nothing to do for other opcodes */
    518       1.3  christos 
    519       1.1    jruoho         break;
    520       1.1    jruoho     }
    521       1.1    jruoho 
    522       1.9  christos     /* The following is for capturing comments */
    523       1.9  christos 
    524      1.12  christos     if (AcpiGbl_CaptureComments)
    525       1.9  christos     {
    526       1.9  christos         /*
    527       1.9  christos          * If there are "regular comments" detected at this point,
    528       1.9  christos          * then is an endBlk comment. Categorize it as so and distribute
    529      1.11  christos          * all regular comments to this parse op.
    530       1.9  christos          */
    531      1.13  christos         if (AslGbl_CommentListHead)
    532       1.9  christos         {
    533      1.13  christos             Op->Asl.EndBlkComment = AslGbl_CommentListHead;
    534       1.9  christos             CvDbgPrint ("EndBlk Comment for %s: %s",
    535      1.13  christos                 Op->Asl.ParseOpName, AslGbl_CommentListHead->Comment);
    536      1.13  christos             AslGbl_CommentListHead = NULL;
    537      1.13  christos             AslGbl_CommentListTail = NULL;
    538       1.9  christos         }
    539       1.9  christos     }
    540       1.9  christos 
    541      1.11  christos     /* Link the new op to it's children */
    542       1.1    jruoho 
    543       1.1    jruoho     PrevChild = NULL;
    544       1.1    jruoho     FirstChild = TRUE;
    545       1.1    jruoho     for (i = 0; i < NumChildren; i++)
    546       1.1    jruoho     {
    547       1.1    jruoho         Child = va_arg (ap, ACPI_PARSE_OBJECT *);
    548       1.1    jruoho 
    549       1.1    jruoho         if ((Child == PrevChild) && (Child != NULL))
    550       1.1    jruoho         {
    551       1.1    jruoho             AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Child,
    552      1.11  christos                 "Child op list invalid");
    553       1.3  christos             va_end(ap);
    554       1.3  christos             return (Op);
    555       1.1    jruoho         }
    556       1.1    jruoho 
    557       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%p, ", Child);
    558       1.1    jruoho 
    559       1.1    jruoho         /*
    560       1.1    jruoho          * If child is NULL, this means that an optional argument
    561       1.3  christos          * was omitted. We must create a placeholder with a special
    562       1.1    jruoho          * opcode (DEFAULT_ARG) so that the code generator will know
    563       1.1    jruoho          * that it must emit the correct default for this argument
    564       1.1    jruoho          */
    565       1.1    jruoho         if (!Child)
    566       1.1    jruoho         {
    567      1.11  christos             Child = TrAllocateOp (PARSEOP_DEFAULT_ARG);
    568       1.1    jruoho         }
    569       1.1    jruoho 
    570       1.1    jruoho         /* Link first child to parent */
    571       1.1    jruoho 
    572       1.1    jruoho         if (FirstChild)
    573       1.1    jruoho         {
    574       1.1    jruoho             FirstChild = FALSE;
    575      1.14  christos 
    576      1.14  christos             /*
    577      1.14  christos              * In the case that multiple definition blocks are being compiled,
    578      1.14  christos              * append the definition block to the end of the child list as the
    579      1.14  christos              * last sibling. This is done to facilitate namespace cross-
    580      1.14  christos              * reference between multiple definition blocks.
    581      1.14  christos              */
    582      1.14  christos             if (Op->Asl.Child &&
    583      1.14  christos                 (Op->Asl.Child->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK))
    584      1.14  christos             {
    585      1.14  christos                 LastSibling = Op->Asl.Child;
    586      1.14  christos                 while (LastSibling->Asl.Next)
    587      1.14  christos                 {
    588      1.14  christos                     LastSibling = LastSibling->Asl.Next;
    589      1.14  christos                 }
    590      1.14  christos                 LastSibling->Asl.Next = Child;
    591      1.14  christos             }
    592      1.14  christos             else
    593      1.14  christos             {
    594      1.14  christos                 Op->Asl.Child = Child;
    595      1.14  christos             }
    596       1.1    jruoho         }
    597       1.1    jruoho 
    598       1.1    jruoho         /* Point all children to parent */
    599       1.1    jruoho 
    600       1.1    jruoho         Child->Asl.Parent = Op;
    601       1.1    jruoho 
    602       1.1    jruoho         /* Link children in a peer list */
    603       1.1    jruoho 
    604       1.1    jruoho         if (PrevChild)
    605       1.1    jruoho         {
    606       1.1    jruoho             PrevChild->Asl.Next = Child;
    607      1.11  christos         }
    608       1.1    jruoho 
    609       1.1    jruoho         /*
    610      1.11  christos          * This child might be a list, point all ops in the list
    611       1.1    jruoho          * to the same parent
    612       1.1    jruoho          */
    613       1.1    jruoho         while (Child->Asl.Next)
    614       1.1    jruoho         {
    615       1.1    jruoho             Child = Child->Asl.Next;
    616       1.1    jruoho             Child->Asl.Parent = Op;
    617       1.1    jruoho         }
    618       1.6  christos 
    619       1.1    jruoho         PrevChild = Child;
    620       1.1    jruoho     }
    621       1.3  christos 
    622       1.1    jruoho     va_end(ap);
    623       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT, "\n\n");
    624       1.9  christos 
    625      1.12  christos     if (AcpiGbl_CaptureComments)
    626       1.9  christos     {
    627      1.13  christos         AslGbl_CommentState.LatestParseOp = Op;
    628      1.18  christos         CvDbgPrint ("%s=====Set latest parse op to this op.\n",  ACPI_GET_FUNCTION_NAME);
    629       1.9  christos     }
    630      1.11  christos 
    631       1.3  christos     return (Op);
    632       1.1    jruoho }
    633       1.1    jruoho 
    634       1.1    jruoho 
    635       1.1    jruoho /*******************************************************************************
    636       1.1    jruoho  *
    637      1.11  christos  * FUNCTION:    TrLinkPeerOp
    638       1.1    jruoho  *
    639       1.1    jruoho  * PARAMETERS:  Op1           - First peer
    640       1.1    jruoho  *              Op2           - Second peer
    641       1.1    jruoho  *
    642      1.11  christos  * RETURN:      Op1 or the non-null op.
    643       1.1    jruoho  *
    644      1.11  christos  * DESCRIPTION: Link two ops as peers. Handles cases where one peer is null.
    645       1.1    jruoho  *
    646       1.1    jruoho  ******************************************************************************/
    647       1.1    jruoho 
    648       1.1    jruoho ACPI_PARSE_OBJECT *
    649      1.11  christos TrLinkPeerOp (
    650       1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
    651       1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
    652       1.1    jruoho {
    653       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    654       1.1    jruoho 
    655       1.1    jruoho 
    656       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    657      1.11  christos         "\nLinkPeerOp: 1=%p (%s), 2=%p (%s)\n",
    658       1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode) : NULL,
    659       1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode) : NULL);
    660       1.1    jruoho 
    661       1.1    jruoho 
    662       1.1    jruoho     if ((!Op1) && (!Op2))
    663       1.1    jruoho     {
    664      1.11  christos         DbgPrint (ASL_PARSE_OUTPUT, "\nTwo Null ops!\n");
    665       1.3  christos         return (Op1);
    666       1.1    jruoho     }
    667       1.1    jruoho 
    668      1.11  christos     /* If one of the ops is null, just return the non-null op */
    669       1.1    jruoho 
    670       1.1    jruoho     if (!Op2)
    671       1.1    jruoho     {
    672       1.3  christos         return (Op1);
    673       1.1    jruoho     }
    674       1.1    jruoho 
    675       1.1    jruoho     if (!Op1)
    676       1.1    jruoho     {
    677       1.3  christos         return (Op2);
    678       1.1    jruoho     }
    679       1.1    jruoho 
    680       1.1    jruoho     if (Op1 == Op2)
    681       1.1    jruoho     {
    682       1.1    jruoho         DbgPrint (ASL_DEBUG_OUTPUT,
    683      1.11  christos             "\n************* Internal error, linking op to itself %p\n",
    684       1.1    jruoho             Op1);
    685       1.1    jruoho         AslError (ASL_WARNING, ASL_MSG_COMPILER_INTERNAL, Op1,
    686      1.11  christos             "Linking op to itself");
    687       1.3  christos         return (Op1);
    688       1.1    jruoho     }
    689       1.1    jruoho 
    690       1.1    jruoho     Op1->Asl.Parent = Op2->Asl.Parent;
    691       1.1    jruoho 
    692       1.1    jruoho     /*
    693       1.1    jruoho      * Op 1 may already have a peer list (such as an IF/ELSE pair),
    694       1.1    jruoho      * so we must walk to the end of the list and attach the new
    695       1.1    jruoho      * peer at the end
    696       1.1    jruoho      */
    697       1.1    jruoho     Next = Op1;
    698       1.1    jruoho     while (Next->Asl.Next)
    699       1.1    jruoho     {
    700       1.1    jruoho         Next = Next->Asl.Next;
    701       1.1    jruoho     }
    702       1.1    jruoho 
    703       1.1    jruoho     Next->Asl.Next = Op2;
    704       1.3  christos     return (Op1);
    705       1.1    jruoho }
    706       1.1    jruoho 
    707       1.1    jruoho 
    708       1.1    jruoho /*******************************************************************************
    709       1.1    jruoho  *
    710      1.11  christos  * FUNCTION:    TrLinkPeerOps
    711       1.1    jruoho  *
    712      1.11  christos  * PARAMETERS:  NumPeers            - The number of ops in the list to follow
    713      1.11  christos  *              ...                 - A list of ops to link together as peers
    714       1.1    jruoho  *
    715      1.11  christos  * RETURN:      The first op in the list (head of the peer list)
    716       1.1    jruoho  *
    717      1.11  christos  * DESCRIPTION: Link together an arbitrary number of peer ops.
    718       1.1    jruoho  *
    719       1.1    jruoho  ******************************************************************************/
    720       1.1    jruoho 
    721       1.1    jruoho ACPI_PARSE_OBJECT *
    722      1.11  christos TrLinkPeerOps (
    723       1.1    jruoho     UINT32                  NumPeers,
    724       1.1    jruoho     ...)
    725       1.1    jruoho {
    726       1.1    jruoho     ACPI_PARSE_OBJECT       *This;
    727       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    728       1.1    jruoho     va_list                 ap;
    729       1.1    jruoho     UINT32                  i;
    730       1.1    jruoho     ACPI_PARSE_OBJECT       *Start;
    731       1.1    jruoho 
    732       1.1    jruoho 
    733       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    734      1.11  christos         "\nLinkPeerOps: (%u) ", NumPeers);
    735       1.1    jruoho 
    736       1.1    jruoho     va_start (ap, NumPeers);
    737       1.1    jruoho     This = va_arg (ap, ACPI_PARSE_OBJECT *);
    738       1.1    jruoho     Start = This;
    739       1.1    jruoho 
    740       1.1    jruoho     /*
    741       1.1    jruoho      * Link all peers
    742       1.1    jruoho      */
    743       1.1    jruoho     for (i = 0; i < (NumPeers -1); i++)
    744       1.1    jruoho     {
    745       1.1    jruoho         DbgPrint (ASL_PARSE_OUTPUT, "%u=%p ", (i+1), This);
    746       1.1    jruoho 
    747       1.1    jruoho         while (This->Asl.Next)
    748       1.1    jruoho         {
    749       1.1    jruoho             This = This->Asl.Next;
    750       1.1    jruoho         }
    751       1.1    jruoho 
    752      1.11  christos         /* Get another peer op */
    753       1.1    jruoho 
    754       1.1    jruoho         Next = va_arg (ap, ACPI_PARSE_OBJECT *);
    755       1.1    jruoho         if (!Next)
    756       1.1    jruoho         {
    757      1.11  christos             Next = TrAllocateOp (PARSEOP_DEFAULT_ARG);
    758       1.1    jruoho         }
    759       1.1    jruoho 
    760      1.11  christos         /* link new op to the current op */
    761       1.1    jruoho 
    762       1.1    jruoho         This->Asl.Next = Next;
    763       1.1    jruoho         This = Next;
    764       1.1    jruoho     }
    765      1.11  christos 
    766       1.1    jruoho     va_end (ap);
    767       1.5  christos     DbgPrint (ASL_PARSE_OUTPUT,"\n");
    768       1.1    jruoho     return (Start);
    769       1.1    jruoho }
    770       1.1    jruoho 
    771       1.1    jruoho 
    772       1.1    jruoho /*******************************************************************************
    773       1.1    jruoho  *
    774      1.11  christos  * FUNCTION:    TrLinkChildOp
    775       1.1    jruoho  *
    776      1.11  christos  * PARAMETERS:  Op1           - Parent op
    777       1.1    jruoho  *              Op2           - Op to become a child
    778       1.1    jruoho  *
    779      1.11  christos  * RETURN:      The parent op
    780       1.1    jruoho  *
    781      1.11  christos  * DESCRIPTION: Link two ops together as a parent and child
    782       1.1    jruoho  *
    783       1.1    jruoho  ******************************************************************************/
    784       1.1    jruoho 
    785       1.1    jruoho ACPI_PARSE_OBJECT *
    786      1.11  christos TrLinkChildOp (
    787       1.1    jruoho     ACPI_PARSE_OBJECT       *Op1,
    788       1.1    jruoho     ACPI_PARSE_OBJECT       *Op2)
    789       1.1    jruoho {
    790       1.1    jruoho     ACPI_PARSE_OBJECT       *Next;
    791       1.1    jruoho 
    792       1.1    jruoho 
    793       1.1    jruoho     DbgPrint (ASL_PARSE_OUTPUT,
    794      1.11  christos         "\nLinkChildOp: Parent=%p (%s), Child=%p (%s)\n",
    795       1.1    jruoho         Op1, Op1 ? UtGetOpName(Op1->Asl.ParseOpcode): NULL,
    796       1.1    jruoho         Op2, Op2 ? UtGetOpName(Op2->Asl.ParseOpcode): NULL);
    797       1.1    jruoho 
    798       1.9  christos     /*
    799      1.11  christos      * Converter: if TrLinkChildOp is called to link a method call,
    800       1.9  christos      * turn on capture comments as it signifies that we are done parsing
    801       1.9  christos      * a method call.
    802       1.9  christos      */
    803      1.12  christos     if (AcpiGbl_CaptureComments && Op1)
    804       1.9  christos     {
    805       1.9  christos         if (Op1->Asl.ParseOpcode == PARSEOP_METHODCALL)
    806       1.9  christos         {
    807      1.13  christos             AslGbl_CommentState.CaptureComments = TRUE;
    808       1.9  christos         }
    809      1.13  christos         AslGbl_CommentState.LatestParseOp = Op1;
    810       1.9  christos     }
    811      1.11  christos 
    812       1.1    jruoho     if (!Op1 || !Op2)
    813       1.1    jruoho     {
    814       1.3  christos         return (Op1);
    815       1.1    jruoho     }
    816       1.1    jruoho 
    817       1.1    jruoho     Op1->Asl.Child = Op2;
    818       1.1    jruoho 
    819       1.1    jruoho     /* Set the child and all peers of the child to point to the parent */
    820       1.1    jruoho 
    821       1.1    jruoho     Next = Op2;
    822       1.1    jruoho     while (Next)
    823       1.1    jruoho     {
    824       1.1    jruoho         Next->Asl.Parent = Op1;
    825       1.1    jruoho         Next = Next->Asl.Next;
    826       1.1    jruoho     }
    827       1.1    jruoho 
    828       1.3  christos     return (Op1);
    829       1.1    jruoho }
    830       1.1    jruoho 
    831       1.1    jruoho 
    832       1.1    jruoho /*******************************************************************************
    833       1.1    jruoho  *
    834       1.1    jruoho  * FUNCTION:    TrWalkParseTree
    835       1.1    jruoho  *
    836      1.11  christos  * PARAMETERS:  Op                      - Walk starting point
    837      1.11  christos  *              Visitation              - Type of walk
    838       1.1    jruoho  *              DescendingCallback      - Called during tree descent
    839       1.1    jruoho  *              AscendingCallback       - Called during tree ascent
    840       1.1    jruoho  *              Context                 - To be passed to the callbacks
    841       1.1    jruoho  *
    842       1.1    jruoho  * RETURN:      Status from callback(s)
    843       1.1    jruoho  *
    844       1.1    jruoho  * DESCRIPTION: Walk the entire parse tree.
    845       1.1    jruoho  *
    846       1.1    jruoho  ******************************************************************************/
    847       1.1    jruoho 
    848       1.1    jruoho ACPI_STATUS
    849       1.1    jruoho TrWalkParseTree (
    850       1.1    jruoho     ACPI_PARSE_OBJECT       *Op,
    851       1.1    jruoho     UINT32                  Visitation,
    852       1.1    jruoho     ASL_WALK_CALLBACK       DescendingCallback,
    853       1.1    jruoho     ASL_WALK_CALLBACK       AscendingCallback,
    854       1.1    jruoho     void                    *Context)
    855       1.1    jruoho {
    856       1.1    jruoho     UINT32                  Level;
    857      1.11  christos     BOOLEAN                 OpPreviouslyVisited;
    858       1.1    jruoho     ACPI_PARSE_OBJECT       *StartOp = Op;
    859       1.1    jruoho     ACPI_STATUS             Status;
    860      1.14  christos     ACPI_PARSE_OBJECT       *Restore = NULL;
    861      1.14  christos     BOOLEAN                 WalkOneDefinitionBlock = Visitation & ASL_WALK_VISIT_DB_SEPARATELY;
    862       1.1    jruoho 
    863       1.1    jruoho 
    864      1.13  christos     if (!AslGbl_ParseTreeRoot)
    865       1.1    jruoho     {
    866       1.1    jruoho         return (AE_OK);
    867       1.1    jruoho     }
    868       1.1    jruoho 
    869       1.1    jruoho     Level = 0;
    870      1.11  christos     OpPreviouslyVisited = FALSE;
    871       1.1    jruoho 
    872      1.14  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
    873      1.14  christos         WalkOneDefinitionBlock)
    874      1.14  christos     {
    875      1.14  christos         Restore = Op->Asl.Next;
    876      1.14  christos         Op->Asl.Next = NULL;
    877      1.14  christos     }
    878      1.14  christos     switch (Visitation & ~ASL_WALK_VISIT_DB_SEPARATELY)
    879       1.1    jruoho     {
    880       1.1    jruoho     case ASL_WALK_VISIT_DOWNWARD:
    881       1.1    jruoho 
    882       1.1    jruoho         while (Op)
    883       1.1    jruoho         {
    884      1.11  christos             if (!OpPreviouslyVisited)
    885       1.1    jruoho             {
    886      1.11  christos                 /* Let the callback process the op. */
    887       1.1    jruoho 
    888       1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
    889       1.1    jruoho                 if (ACPI_SUCCESS (Status))
    890       1.1    jruoho                 {
    891       1.1    jruoho                     /* Visit children first, once */
    892       1.1    jruoho 
    893       1.1    jruoho                     if (Op->Asl.Child)
    894       1.1    jruoho                     {
    895       1.1    jruoho                         Level++;
    896       1.1    jruoho                         Op = Op->Asl.Child;
    897       1.1    jruoho                         continue;
    898       1.1    jruoho                     }
    899       1.1    jruoho                 }
    900       1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
    901       1.1    jruoho                 {
    902       1.1    jruoho                     /* Exit immediately on any error */
    903       1.1    jruoho 
    904      1.14  christos                     goto ErrorExit;
    905       1.1    jruoho                 }
    906       1.1    jruoho             }
    907       1.1    jruoho 
    908       1.1    jruoho             /* Terminate walk at start op */
    909       1.1    jruoho 
    910       1.1    jruoho             if (Op == StartOp)
    911       1.1    jruoho             {
    912       1.1    jruoho                 break;
    913       1.1    jruoho             }
    914       1.1    jruoho 
    915       1.1    jruoho             /* No more children, visit peers */
    916       1.1    jruoho 
    917       1.1    jruoho             if (Op->Asl.Next)
    918       1.1    jruoho             {
    919       1.1    jruoho                 Op = Op->Asl.Next;
    920      1.11  christos                 OpPreviouslyVisited = FALSE;
    921       1.1    jruoho             }
    922       1.1    jruoho             else
    923       1.1    jruoho             {
    924       1.1    jruoho                 /* No children or peers, re-visit parent */
    925       1.1    jruoho 
    926       1.1    jruoho                 if (Level != 0 )
    927       1.1    jruoho                 {
    928       1.1    jruoho                     Level--;
    929       1.1    jruoho                 }
    930       1.1    jruoho                 Op = Op->Asl.Parent;
    931      1.11  christos                 OpPreviouslyVisited = TRUE;
    932       1.1    jruoho             }
    933       1.1    jruoho         }
    934       1.1    jruoho         break;
    935       1.1    jruoho 
    936       1.1    jruoho     case ASL_WALK_VISIT_UPWARD:
    937       1.1    jruoho 
    938       1.1    jruoho         while (Op)
    939       1.1    jruoho         {
    940      1.11  christos             /* Visit leaf op (no children) or parent op on return trip */
    941       1.1    jruoho 
    942       1.1    jruoho             if ((!Op->Asl.Child) ||
    943      1.11  christos                 (OpPreviouslyVisited))
    944       1.1    jruoho             {
    945      1.11  christos                 /* Let the callback process the op. */
    946       1.1    jruoho 
    947       1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
    948       1.1    jruoho                 if (ACPI_FAILURE (Status))
    949       1.1    jruoho                 {
    950      1.14  christos                     goto ErrorExit;
    951       1.1    jruoho                 }
    952       1.1    jruoho             }
    953       1.1    jruoho             else
    954       1.1    jruoho             {
    955       1.1    jruoho                 /* Visit children first, once */
    956       1.1    jruoho 
    957       1.1    jruoho                 Level++;
    958       1.1    jruoho                 Op = Op->Asl.Child;
    959       1.1    jruoho                 continue;
    960       1.1    jruoho             }
    961       1.1    jruoho 
    962       1.1    jruoho             /* Terminate walk at start op */
    963       1.1    jruoho 
    964       1.1    jruoho             if (Op == StartOp)
    965       1.1    jruoho             {
    966       1.1    jruoho                 break;
    967       1.1    jruoho             }
    968       1.1    jruoho 
    969       1.1    jruoho             /* No more children, visit peers */
    970       1.1    jruoho 
    971       1.1    jruoho             if (Op->Asl.Next)
    972       1.1    jruoho             {
    973       1.1    jruoho                 Op = Op->Asl.Next;
    974      1.11  christos                 OpPreviouslyVisited = FALSE;
    975       1.1    jruoho             }
    976       1.1    jruoho             else
    977       1.1    jruoho             {
    978       1.1    jruoho                 /* No children or peers, re-visit parent */
    979       1.1    jruoho 
    980       1.1    jruoho                 if (Level != 0 )
    981       1.1    jruoho                 {
    982       1.1    jruoho                     Level--;
    983       1.1    jruoho                 }
    984       1.1    jruoho                 Op = Op->Asl.Parent;
    985      1.11  christos                 OpPreviouslyVisited = TRUE;
    986       1.1    jruoho             }
    987       1.1    jruoho         }
    988       1.1    jruoho         break;
    989       1.1    jruoho 
    990       1.1    jruoho      case ASL_WALK_VISIT_TWICE:
    991       1.1    jruoho 
    992       1.1    jruoho         while (Op)
    993       1.1    jruoho         {
    994      1.11  christos             if (OpPreviouslyVisited)
    995       1.1    jruoho             {
    996       1.1    jruoho                 Status = AscendingCallback (Op, Level, Context);
    997       1.1    jruoho                 if (ACPI_FAILURE (Status))
    998       1.1    jruoho                 {
    999      1.14  christos                     goto ErrorExit;
   1000       1.1    jruoho                 }
   1001       1.1    jruoho             }
   1002       1.1    jruoho             else
   1003       1.1    jruoho             {
   1004      1.11  christos                 /* Let the callback process the op. */
   1005       1.1    jruoho 
   1006       1.1    jruoho                 Status = DescendingCallback (Op, Level, Context);
   1007       1.1    jruoho                 if (ACPI_SUCCESS (Status))
   1008       1.1    jruoho                 {
   1009       1.1    jruoho                     /* Visit children first, once */
   1010       1.1    jruoho 
   1011       1.1    jruoho                     if (Op->Asl.Child)
   1012       1.1    jruoho                     {
   1013       1.1    jruoho                         Level++;
   1014       1.1    jruoho                         Op = Op->Asl.Child;
   1015       1.1    jruoho                         continue;
   1016       1.1    jruoho                     }
   1017       1.1    jruoho                 }
   1018       1.1    jruoho                 else if (Status != AE_CTRL_DEPTH)
   1019       1.1    jruoho                 {
   1020       1.1    jruoho                     /* Exit immediately on any error */
   1021       1.1    jruoho 
   1022      1.14  christos                     goto ErrorExit;
   1023       1.1    jruoho                 }
   1024       1.1    jruoho             }
   1025       1.1    jruoho 
   1026       1.1    jruoho             /* Terminate walk at start op */
   1027       1.1    jruoho 
   1028       1.1    jruoho             if (Op == StartOp)
   1029       1.1    jruoho             {
   1030       1.1    jruoho                 break;
   1031       1.1    jruoho             }
   1032       1.1    jruoho 
   1033       1.1    jruoho             /* No more children, visit peers */
   1034       1.1    jruoho 
   1035       1.1    jruoho             if (Op->Asl.Next)
   1036       1.1    jruoho             {
   1037       1.1    jruoho                 Op = Op->Asl.Next;
   1038      1.11  christos                 OpPreviouslyVisited = FALSE;
   1039       1.1    jruoho             }
   1040       1.1    jruoho             else
   1041       1.1    jruoho             {
   1042       1.1    jruoho                 /* No children or peers, re-visit parent */
   1043       1.1    jruoho 
   1044       1.1    jruoho                 if (Level != 0 )
   1045       1.1    jruoho                 {
   1046       1.1    jruoho                     Level--;
   1047       1.1    jruoho                 }
   1048       1.1    jruoho                 Op = Op->Asl.Parent;
   1049      1.11  christos                 OpPreviouslyVisited = TRUE;
   1050       1.1    jruoho             }
   1051       1.1    jruoho         }
   1052       1.1    jruoho         break;
   1053       1.1    jruoho 
   1054       1.1    jruoho     default:
   1055       1.1    jruoho         /* No other types supported */
   1056       1.1    jruoho         break;
   1057       1.1    jruoho     }
   1058       1.1    jruoho 
   1059       1.1    jruoho     /* If we get here, the walk completed with no errors */
   1060       1.1    jruoho 
   1061      1.14  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
   1062      1.14  christos         WalkOneDefinitionBlock)
   1063      1.14  christos     {
   1064      1.14  christos         Op->Asl.Next = Restore;
   1065      1.14  christos     }
   1066      1.14  christos 
   1067       1.1    jruoho     return (AE_OK);
   1068      1.14  christos 
   1069      1.14  christos ErrorExit:
   1070      1.14  christos 
   1071      1.14  christos     if (Op->Asl.ParseOpcode == PARSEOP_DEFINITION_BLOCK &&
   1072      1.14  christos         WalkOneDefinitionBlock)
   1073      1.14  christos     {
   1074      1.14  christos         Op->Asl.Next = Restore;
   1075      1.14  christos     }
   1076      1.14  christos     return (Status);
   1077       1.1    jruoho }
   1078