Home | History | Annotate | Line # | Download | only in parser
      1       1.1  christos /******************************************************************************
      2       1.1  christos  *
      3       1.1  christos  * Module Name: psobject - Support for parse objects
      4       1.1  christos  *
      5       1.1  christos  *****************************************************************************/
      6       1.1  christos 
      7  1.1.1.19  christos /******************************************************************************
      8  1.1.1.19  christos  *
      9  1.1.1.19  christos  * 1. Copyright Notice
     10  1.1.1.19  christos  *
     11  1.1.1.20  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12       1.1  christos  * All rights reserved.
     13       1.1  christos  *
     14  1.1.1.19  christos  * 2. License
     15  1.1.1.19  christos  *
     16  1.1.1.19  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.19  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.19  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.19  christos  * property rights.
     20  1.1.1.19  christos  *
     21  1.1.1.19  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.19  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.19  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.19  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.19  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.19  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.19  christos  *
     28  1.1.1.19  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.19  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.19  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.19  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.19  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.19  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.19  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.19  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.19  christos  *
     37  1.1.1.19  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.19  christos  * conditions are met:
     39  1.1.1.19  christos  *
     40  1.1.1.19  christos  * 3. Conditions
     41  1.1.1.19  christos  *
     42  1.1.1.19  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.19  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.19  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.19  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.19  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.19  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.19  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.19  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.19  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.19  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.19  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.19  christos  *
     54  1.1.1.19  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.19  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.19  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.19  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.19  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.19  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.19  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.19  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.19  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.19  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.19  christos  * make.
     65  1.1.1.19  christos  *
     66  1.1.1.19  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.19  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.19  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.19  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.19  christos  * distribution.
     71  1.1.1.19  christos  *
     72  1.1.1.19  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.19  christos  * Intel Code.
     74  1.1.1.19  christos  *
     75  1.1.1.19  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.19  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.19  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.19  christos  * without prior written authorization from Intel.
     79  1.1.1.19  christos  *
     80  1.1.1.19  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.19  christos  *
     82  1.1.1.19  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.19  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.19  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.19  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.19  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.19  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.19  christos  * PARTICULAR PURPOSE.
     89  1.1.1.19  christos  *
     90  1.1.1.19  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.19  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.19  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.19  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.19  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.19  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.19  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.19  christos  * LIMITED REMEDY.
     98  1.1.1.19  christos  *
     99  1.1.1.19  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.19  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.19  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.19  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.19  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.19  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.19  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.19  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.19  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.19  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.19  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.19  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.19  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.19  christos  * such license, approval or letter.
    113  1.1.1.19  christos  *
    114  1.1.1.19  christos  *****************************************************************************
    115  1.1.1.19  christos  *
    116  1.1.1.19  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.19  christos  * following license:
    118  1.1.1.19  christos  *
    119       1.1  christos  * Redistribution and use in source and binary forms, with or without
    120       1.1  christos  * modification, are permitted provided that the following conditions
    121       1.1  christos  * are met:
    122       1.1  christos  * 1. Redistributions of source code must retain the above copyright
    123       1.1  christos  *    notice, this list of conditions, and the following disclaimer,
    124       1.1  christos  *    without modification.
    125       1.1  christos  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126       1.1  christos  *    substantially similar to the "NO WARRANTY" disclaimer below
    127       1.1  christos  *    ("Disclaimer") and any redistribution must be conditioned upon
    128       1.1  christos  *    including a substantially similar Disclaimer requirement for further
    129       1.1  christos  *    binary redistribution.
    130       1.1  christos  * 3. Neither the names of the above-listed copyright holders nor the names
    131       1.1  christos  *    of any contributors may be used to endorse or promote products derived
    132       1.1  christos  *    from this software without specific prior written permission.
    133       1.1  christos  *
    134       1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135       1.1  christos  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.16  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137       1.1  christos  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.19  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.19  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.19  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.19  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.19  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.19  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.19  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.19  christos  *
    146  1.1.1.19  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.19  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.19  christos  * Software Foundation.
    149  1.1.1.19  christos  *
    150  1.1.1.19  christos  *****************************************************************************/
    151       1.1  christos 
    152       1.1  christos #include "acpi.h"
    153       1.1  christos #include "accommon.h"
    154       1.1  christos #include "acparser.h"
    155       1.1  christos #include "amlcode.h"
    156   1.1.1.7  christos #include "acconvert.h"
    157  1.1.1.11  christos #include "acnamesp.h"
    158       1.1  christos 
    159       1.1  christos #define _COMPONENT          ACPI_PARSER
    160       1.1  christos         ACPI_MODULE_NAME    ("psobject")
    161       1.1  christos 
    162       1.1  christos 
    163       1.1  christos /* Local prototypes */
    164       1.1  christos 
    165       1.1  christos static ACPI_STATUS
    166       1.1  christos AcpiPsGetAmlOpcode (
    167       1.1  christos     ACPI_WALK_STATE         *WalkState);
    168       1.1  christos 
    169       1.1  christos 
    170       1.1  christos /*******************************************************************************
    171       1.1  christos  *
    172       1.1  christos  * FUNCTION:    AcpiPsGetAmlOpcode
    173       1.1  christos  *
    174       1.1  christos  * PARAMETERS:  WalkState           - Current state
    175       1.1  christos  *
    176       1.1  christos  * RETURN:      Status
    177       1.1  christos  *
    178       1.1  christos  * DESCRIPTION: Extract the next AML opcode from the input stream.
    179       1.1  christos  *
    180       1.1  christos  ******************************************************************************/
    181       1.1  christos 
    182       1.1  christos static ACPI_STATUS
    183       1.1  christos AcpiPsGetAmlOpcode (
    184       1.1  christos     ACPI_WALK_STATE         *WalkState)
    185       1.1  christos {
    186  1.1.1.10  christos     ACPI_ERROR_ONLY (UINT32 AmlOffset);
    187   1.1.1.4  christos 
    188       1.1  christos 
    189       1.1  christos     ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState);
    190       1.1  christos 
    191       1.1  christos 
    192   1.1.1.4  christos     WalkState->Aml = WalkState->ParserState.Aml;
    193       1.1  christos     WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState));
    194       1.1  christos 
    195       1.1  christos     /*
    196       1.1  christos      * First cut to determine what we have found:
    197       1.1  christos      * 1) A valid AML opcode
    198       1.1  christos      * 2) A name string
    199       1.1  christos      * 3) An unknown/invalid opcode
    200       1.1  christos      */
    201       1.1  christos     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
    202       1.1  christos 
    203       1.1  christos     switch (WalkState->OpInfo->Class)
    204       1.1  christos     {
    205       1.1  christos     case AML_CLASS_ASCII:
    206       1.1  christos     case AML_CLASS_PREFIX:
    207       1.1  christos         /*
    208       1.1  christos          * Starts with a valid prefix or ASCII char, this is a name
    209       1.1  christos          * string. Convert the bare name string to a namepath.
    210       1.1  christos          */
    211       1.1  christos         WalkState->Opcode = AML_INT_NAMEPATH_OP;
    212       1.1  christos         WalkState->ArgTypes = ARGP_NAMESTRING;
    213       1.1  christos         break;
    214       1.1  christos 
    215       1.1  christos     case AML_CLASS_UNKNOWN:
    216       1.1  christos 
    217       1.1  christos         /* The opcode is unrecognized. Complain and skip unknown opcodes */
    218       1.1  christos 
    219       1.1  christos         if (WalkState->PassNumber == 2)
    220       1.1  christos         {
    221  1.1.1.10  christos             ACPI_ERROR_ONLY(AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
    222  1.1.1.10  christos                 WalkState->ParserState.AmlStart));
    223   1.1.1.4  christos 
    224       1.1  christos             ACPI_ERROR ((AE_INFO,
    225       1.1  christos                 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
    226       1.1  christos                 WalkState->Opcode,
    227   1.1.1.4  christos                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))));
    228       1.1  christos 
    229       1.1  christos             ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48);
    230       1.1  christos 
    231       1.1  christos #ifdef ACPI_ASL_COMPILER
    232       1.1  christos             /*
    233       1.1  christos              * This is executed for the disassembler only. Output goes
    234       1.1  christos              * to the disassembled ASL output file.
    235       1.1  christos              */
    236       1.1  christos             AcpiOsPrintf (
    237       1.1  christos                 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
    238       1.1  christos                 WalkState->Opcode,
    239   1.1.1.4  christos                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)));
    240       1.1  christos 
    241   1.1.1.8  christos             ACPI_ERROR ((AE_INFO,
    242   1.1.1.8  christos                 "Aborting disassembly, AML byte code is corrupt"));
    243   1.1.1.8  christos 
    244       1.1  christos             /* Dump the context surrounding the invalid opcode */
    245       1.1  christos 
    246       1.1  christos             AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16),
    247       1.1  christos                 48, DB_BYTE_DISPLAY,
    248   1.1.1.4  christos                 (AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16));
    249       1.1  christos             AcpiOsPrintf (" */\n");
    250   1.1.1.8  christos 
    251   1.1.1.8  christos             /*
    252   1.1.1.8  christos              * Just abort the disassembly, cannot continue because the
    253   1.1.1.8  christos              * parser is essentially lost. The disassembler can then
    254   1.1.1.8  christos              * randomly fail because an ill-constructed parse tree
    255   1.1.1.8  christos              * can result.
    256   1.1.1.8  christos              */
    257   1.1.1.8  christos             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
    258       1.1  christos #endif
    259       1.1  christos         }
    260       1.1  christos 
    261       1.1  christos         /* Increment past one-byte or two-byte opcode */
    262       1.1  christos 
    263       1.1  christos         WalkState->ParserState.Aml++;
    264       1.1  christos         if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */
    265       1.1  christos         {
    266       1.1  christos             WalkState->ParserState.Aml++;
    267       1.1  christos         }
    268       1.1  christos 
    269       1.1  christos         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
    270       1.1  christos 
    271       1.1  christos     default:
    272       1.1  christos 
    273       1.1  christos         /* Found opcode info, this is a normal opcode */
    274       1.1  christos 
    275   1.1.1.5  christos         WalkState->ParserState.Aml +=
    276   1.1.1.5  christos             AcpiPsGetOpcodeSize (WalkState->Opcode);
    277       1.1  christos         WalkState->ArgTypes = WalkState->OpInfo->ParseArgs;
    278       1.1  christos         break;
    279       1.1  christos     }
    280       1.1  christos 
    281       1.1  christos     return_ACPI_STATUS (AE_OK);
    282       1.1  christos }
    283       1.1  christos 
    284       1.1  christos 
    285       1.1  christos /*******************************************************************************
    286       1.1  christos  *
    287       1.1  christos  * FUNCTION:    AcpiPsBuildNamedOp
    288       1.1  christos  *
    289       1.1  christos  * PARAMETERS:  WalkState           - Current state
    290       1.1  christos  *              AmlOpStart          - Begin of named Op in AML
    291       1.1  christos  *              UnnamedOp           - Early Op (not a named Op)
    292       1.1  christos  *              Op                  - Returned Op
    293       1.1  christos  *
    294       1.1  christos  * RETURN:      Status
    295       1.1  christos  *
    296       1.1  christos  * DESCRIPTION: Parse a named Op
    297       1.1  christos  *
    298       1.1  christos  ******************************************************************************/
    299       1.1  christos 
    300       1.1  christos ACPI_STATUS
    301       1.1  christos AcpiPsBuildNamedOp (
    302       1.1  christos     ACPI_WALK_STATE         *WalkState,
    303       1.1  christos     UINT8                   *AmlOpStart,
    304       1.1  christos     ACPI_PARSE_OBJECT       *UnnamedOp,
    305       1.1  christos     ACPI_PARSE_OBJECT       **Op)
    306       1.1  christos {
    307       1.1  christos     ACPI_STATUS             Status = AE_OK;
    308       1.1  christos     ACPI_PARSE_OBJECT       *Arg = NULL;
    309       1.1  christos 
    310       1.1  christos 
    311       1.1  christos     ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState);
    312       1.1  christos 
    313       1.1  christos 
    314       1.1  christos     UnnamedOp->Common.Value.Arg = NULL;
    315       1.1  christos     UnnamedOp->Common.ArgListLength = 0;
    316       1.1  christos     UnnamedOp->Common.AmlOpcode = WalkState->Opcode;
    317       1.1  christos 
    318       1.1  christos     /*
    319       1.1  christos      * Get and append arguments until we find the node that contains
    320       1.1  christos      * the name (the type ARGP_NAME).
    321       1.1  christos      */
    322       1.1  christos     while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
    323       1.1  christos           (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME))
    324       1.1  christos     {
    325   1.1.1.7  christos         ASL_CV_CAPTURE_COMMENTS (WalkState);
    326       1.1  christos         Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
    327   1.1.1.5  christos             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
    328       1.1  christos         if (ACPI_FAILURE (Status))
    329       1.1  christos         {
    330       1.1  christos             return_ACPI_STATUS (Status);
    331       1.1  christos         }
    332       1.1  christos 
    333       1.1  christos         AcpiPsAppendArg (UnnamedOp, Arg);
    334       1.1  christos         INCREMENT_ARG_LIST (WalkState->ArgTypes);
    335       1.1  christos     }
    336       1.1  christos 
    337   1.1.1.7  christos     /* are there any inline comments associated with the NameSeg?? If so, save this. */
    338   1.1.1.7  christos 
    339   1.1.1.7  christos     ASL_CV_CAPTURE_COMMENTS (WalkState);
    340   1.1.1.7  christos 
    341   1.1.1.7  christos #ifdef ACPI_ASL_COMPILER
    342   1.1.1.7  christos     if (AcpiGbl_CurrentInlineComment != NULL)
    343   1.1.1.7  christos     {
    344   1.1.1.7  christos         UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment;
    345   1.1.1.7  christos         AcpiGbl_CurrentInlineComment = NULL;
    346   1.1.1.7  christos     }
    347   1.1.1.7  christos #endif
    348   1.1.1.7  christos 
    349       1.1  christos     /*
    350       1.1  christos      * Make sure that we found a NAME and didn't run out of arguments
    351       1.1  christos      */
    352       1.1  christos     if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes))
    353       1.1  christos     {
    354       1.1  christos         return_ACPI_STATUS (AE_AML_NO_OPERAND);
    355       1.1  christos     }
    356       1.1  christos 
    357       1.1  christos     /* We know that this arg is a name, move to next arg */
    358       1.1  christos 
    359       1.1  christos     INCREMENT_ARG_LIST (WalkState->ArgTypes);
    360       1.1  christos 
    361       1.1  christos     /*
    362       1.1  christos      * Find the object. This will either insert the object into
    363       1.1  christos      * the namespace or simply look it up
    364       1.1  christos      */
    365       1.1  christos     WalkState->Op = NULL;
    366       1.1  christos 
    367       1.1  christos     Status = WalkState->DescendingCallback (WalkState, Op);
    368       1.1  christos     if (ACPI_FAILURE (Status))
    369       1.1  christos     {
    370   1.1.1.2  christos         if (Status != AE_CTRL_TERMINATE)
    371   1.1.1.2  christos         {
    372   1.1.1.2  christos             ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog"));
    373   1.1.1.2  christos         }
    374       1.1  christos         return_ACPI_STATUS (Status);
    375       1.1  christos     }
    376       1.1  christos 
    377       1.1  christos     if (!*Op)
    378       1.1  christos     {
    379       1.1  christos         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
    380       1.1  christos     }
    381       1.1  christos 
    382       1.1  christos     Status = AcpiPsNextParseState (WalkState, *Op, Status);
    383       1.1  christos     if (ACPI_FAILURE (Status))
    384       1.1  christos     {
    385       1.1  christos         if (Status == AE_CTRL_PENDING)
    386       1.1  christos         {
    387   1.1.1.2  christos             Status = AE_CTRL_PARSE_PENDING;
    388       1.1  christos         }
    389       1.1  christos         return_ACPI_STATUS (Status);
    390       1.1  christos     }
    391       1.1  christos 
    392       1.1  christos     AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg);
    393       1.1  christos 
    394   1.1.1.7  christos #ifdef ACPI_ASL_COMPILER
    395   1.1.1.7  christos 
    396   1.1.1.7  christos     /* save any comments that might be associated with UnnamedOp. */
    397   1.1.1.7  christos 
    398   1.1.1.7  christos     (*Op)->Common.InlineComment     = UnnamedOp->Common.InlineComment;
    399   1.1.1.7  christos     (*Op)->Common.EndNodeComment    = UnnamedOp->Common.EndNodeComment;
    400   1.1.1.7  christos     (*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment;
    401   1.1.1.7  christos     (*Op)->Common.NameComment       = UnnamedOp->Common.NameComment;
    402   1.1.1.7  christos     (*Op)->Common.CommentList       = UnnamedOp->Common.CommentList;
    403   1.1.1.7  christos     (*Op)->Common.EndBlkComment     = UnnamedOp->Common.EndBlkComment;
    404   1.1.1.7  christos     (*Op)->Common.CvFilename        = UnnamedOp->Common.CvFilename;
    405   1.1.1.7  christos     (*Op)->Common.CvParentFilename  = UnnamedOp->Common.CvParentFilename;
    406   1.1.1.7  christos     (*Op)->Named.Aml                = UnnamedOp->Common.Aml;
    407   1.1.1.7  christos 
    408   1.1.1.7  christos     UnnamedOp->Common.InlineComment     = NULL;
    409   1.1.1.7  christos     UnnamedOp->Common.EndNodeComment    = NULL;
    410   1.1.1.7  christos     UnnamedOp->Common.CloseBraceComment = NULL;
    411   1.1.1.7  christos     UnnamedOp->Common.NameComment       = NULL;
    412   1.1.1.7  christos     UnnamedOp->Common.CommentList       = NULL;
    413   1.1.1.7  christos     UnnamedOp->Common.EndBlkComment     = NULL;
    414   1.1.1.7  christos #endif
    415   1.1.1.7  christos 
    416       1.1  christos     if ((*Op)->Common.AmlOpcode == AML_REGION_OP ||
    417       1.1  christos         (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP)
    418       1.1  christos     {
    419       1.1  christos         /*
    420       1.1  christos          * Defer final parsing of an OperationRegion body, because we don't
    421       1.1  christos          * have enough info in the first pass to parse it correctly (i.e.,
    422       1.1  christos          * there may be method calls within the TermArg elements of the body.)
    423       1.1  christos          *
    424       1.1  christos          * However, we must continue parsing because the opregion is not a
    425       1.1  christos          * standalone package -- we don't know where the end is at this point.
    426       1.1  christos          *
    427       1.1  christos          * (Length is unknown until parse of the body complete)
    428       1.1  christos          */
    429       1.1  christos         (*Op)->Named.Data = AmlOpStart;
    430       1.1  christos         (*Op)->Named.Length = 0;
    431       1.1  christos     }
    432       1.1  christos 
    433       1.1  christos     return_ACPI_STATUS (AE_OK);
    434       1.1  christos }
    435       1.1  christos 
    436       1.1  christos 
    437       1.1  christos /*******************************************************************************
    438       1.1  christos  *
    439       1.1  christos  * FUNCTION:    AcpiPsCreateOp
    440       1.1  christos  *
    441       1.1  christos  * PARAMETERS:  WalkState           - Current state
    442       1.1  christos  *              AmlOpStart          - Op start in AML
    443       1.1  christos  *              NewOp               - Returned Op
    444       1.1  christos  *
    445       1.1  christos  * RETURN:      Status
    446       1.1  christos  *
    447       1.1  christos  * DESCRIPTION: Get Op from AML
    448       1.1  christos  *
    449       1.1  christos  ******************************************************************************/
    450       1.1  christos 
    451       1.1  christos ACPI_STATUS
    452       1.1  christos AcpiPsCreateOp (
    453       1.1  christos     ACPI_WALK_STATE         *WalkState,
    454       1.1  christos     UINT8                   *AmlOpStart,
    455       1.1  christos     ACPI_PARSE_OBJECT       **NewOp)
    456       1.1  christos {
    457       1.1  christos     ACPI_STATUS             Status = AE_OK;
    458       1.1  christos     ACPI_PARSE_OBJECT       *Op;
    459       1.1  christos     ACPI_PARSE_OBJECT       *NamedOp = NULL;
    460       1.1  christos     ACPI_PARSE_OBJECT       *ParentScope;
    461       1.1  christos     UINT8                   ArgumentCount;
    462       1.1  christos     const ACPI_OPCODE_INFO  *OpInfo;
    463       1.1  christos 
    464       1.1  christos 
    465       1.1  christos     ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState);
    466       1.1  christos 
    467       1.1  christos 
    468       1.1  christos     Status = AcpiPsGetAmlOpcode (WalkState);
    469       1.1  christos     if (Status == AE_CTRL_PARSE_CONTINUE)
    470       1.1  christos     {
    471       1.1  christos         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
    472       1.1  christos     }
    473   1.1.1.8  christos     if (ACPI_FAILURE (Status))
    474   1.1.1.8  christos     {
    475   1.1.1.8  christos         return_ACPI_STATUS (Status);
    476   1.1.1.8  christos     }
    477       1.1  christos 
    478       1.1  christos     /* Create Op structure and append to parent's argument list */
    479       1.1  christos 
    480       1.1  christos     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
    481   1.1.1.4  christos     Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart);
    482       1.1  christos     if (!Op)
    483       1.1  christos     {
    484       1.1  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    485       1.1  christos     }
    486       1.1  christos 
    487       1.1  christos     if (WalkState->OpInfo->Flags & AML_NAMED)
    488       1.1  christos     {
    489       1.1  christos         Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp);
    490       1.1  christos         AcpiPsFreeOp (Op);
    491   1.1.1.8  christos 
    492   1.1.1.8  christos #ifdef ACPI_ASL_COMPILER
    493   1.1.1.8  christos         if (AcpiGbl_DisasmFlag && WalkState->Opcode == AML_EXTERNAL_OP &&
    494   1.1.1.8  christos             Status == AE_NOT_FOUND)
    495   1.1.1.8  christos         {
    496   1.1.1.8  christos             /*
    497   1.1.1.8  christos              * If parsing of AML_EXTERNAL_OP's name path fails, then skip
    498   1.1.1.8  christos              * past this opcode and keep parsing. This is a much better
    499   1.1.1.8  christos              * alternative than to abort the entire disassembler. At this
    500   1.1.1.8  christos              * point, the ParserState is at the end of the namepath of the
    501   1.1.1.8  christos              * external declaration opcode. Setting WalkState->Aml to
    502   1.1.1.8  christos              * WalkState->ParserState.Aml + 2 moves increments the
    503   1.1.1.8  christos              * WalkState->Aml past the object type and the paramcount of the
    504   1.1.1.9  christos              * external opcode.
    505   1.1.1.8  christos              */
    506   1.1.1.8  christos             WalkState->Aml = WalkState->ParserState.Aml + 2;
    507   1.1.1.9  christos             WalkState->ParserState.Aml = WalkState->Aml;
    508   1.1.1.8  christos             return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
    509   1.1.1.8  christos         }
    510   1.1.1.8  christos #endif
    511       1.1  christos         if (ACPI_FAILURE (Status))
    512       1.1  christos         {
    513       1.1  christos             return_ACPI_STATUS (Status);
    514       1.1  christos         }
    515       1.1  christos 
    516       1.1  christos         *NewOp = NamedOp;
    517       1.1  christos         return_ACPI_STATUS (AE_OK);
    518       1.1  christos     }
    519       1.1  christos 
    520       1.1  christos     /* Not a named opcode, just allocate Op and append to parent */
    521       1.1  christos 
    522       1.1  christos     if (WalkState->OpInfo->Flags & AML_CREATE)
    523       1.1  christos     {
    524       1.1  christos         /*
    525       1.1  christos          * Backup to beginning of CreateXXXfield declaration
    526       1.1  christos          * BodyLength is unknown until we parse the body
    527       1.1  christos          */
    528       1.1  christos         Op->Named.Data = AmlOpStart;
    529       1.1  christos         Op->Named.Length = 0;
    530       1.1  christos     }
    531       1.1  christos 
    532       1.1  christos     if (WalkState->Opcode == AML_BANK_FIELD_OP)
    533       1.1  christos     {
    534       1.1  christos         /*
    535       1.1  christos          * Backup to beginning of BankField declaration
    536       1.1  christos          * BodyLength is unknown until we parse the body
    537       1.1  christos          */
    538       1.1  christos         Op->Named.Data = AmlOpStart;
    539       1.1  christos         Op->Named.Length = 0;
    540       1.1  christos     }
    541       1.1  christos 
    542       1.1  christos     ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState));
    543       1.1  christos     AcpiPsAppendArg (ParentScope, Op);
    544       1.1  christos 
    545       1.1  christos     if (ParentScope)
    546       1.1  christos     {
    547       1.1  christos         OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode);
    548       1.1  christos         if (OpInfo->Flags & AML_HAS_TARGET)
    549       1.1  christos         {
    550       1.1  christos             ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type);
    551       1.1  christos             if (ParentScope->Common.ArgListLength > ArgumentCount)
    552       1.1  christos             {
    553       1.1  christos                 Op->Common.Flags |= ACPI_PARSEOP_TARGET;
    554       1.1  christos             }
    555       1.1  christos         }
    556   1.1.1.6  christos 
    557   1.1.1.6  christos         /*
    558   1.1.1.6  christos          * Special case for both Increment() and Decrement(), where
    559   1.1.1.6  christos          * the lone argument is both a source and a target.
    560   1.1.1.6  christos          */
    561   1.1.1.6  christos         else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) ||
    562   1.1.1.6  christos                 (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP))
    563       1.1  christos         {
    564       1.1  christos             Op->Common.Flags |= ACPI_PARSEOP_TARGET;
    565       1.1  christos         }
    566       1.1  christos     }
    567       1.1  christos 
    568       1.1  christos     if (WalkState->DescendingCallback != NULL)
    569       1.1  christos     {
    570       1.1  christos         /*
    571       1.1  christos          * Find the object. This will either insert the object into
    572       1.1  christos          * the namespace or simply look it up
    573       1.1  christos          */
    574       1.1  christos         WalkState->Op = *NewOp = Op;
    575       1.1  christos 
    576       1.1  christos         Status = WalkState->DescendingCallback (WalkState, &Op);
    577       1.1  christos         Status = AcpiPsNextParseState (WalkState, Op, Status);
    578       1.1  christos         if (Status == AE_CTRL_PENDING)
    579       1.1  christos         {
    580       1.1  christos             Status = AE_CTRL_PARSE_PENDING;
    581       1.1  christos         }
    582       1.1  christos     }
    583       1.1  christos 
    584       1.1  christos     return_ACPI_STATUS (Status);
    585       1.1  christos }
    586       1.1  christos 
    587       1.1  christos 
    588       1.1  christos /*******************************************************************************
    589       1.1  christos  *
    590       1.1  christos  * FUNCTION:    AcpiPsCompleteOp
    591       1.1  christos  *
    592       1.1  christos  * PARAMETERS:  WalkState           - Current state
    593       1.1  christos  *              Op                  - Returned Op
    594       1.1  christos  *              Status              - Parse status before complete Op
    595       1.1  christos  *
    596       1.1  christos  * RETURN:      Status
    597       1.1  christos  *
    598       1.1  christos  * DESCRIPTION: Complete Op
    599       1.1  christos  *
    600       1.1  christos  ******************************************************************************/
    601       1.1  christos 
    602       1.1  christos ACPI_STATUS
    603       1.1  christos AcpiPsCompleteOp (
    604       1.1  christos     ACPI_WALK_STATE         *WalkState,
    605       1.1  christos     ACPI_PARSE_OBJECT       **Op,
    606       1.1  christos     ACPI_STATUS             Status)
    607       1.1  christos {
    608       1.1  christos     ACPI_STATUS             Status2;
    609       1.1  christos 
    610       1.1  christos 
    611       1.1  christos     ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState);
    612       1.1  christos 
    613       1.1  christos 
    614       1.1  christos     /*
    615       1.1  christos      * Finished one argument of the containing scope
    616       1.1  christos      */
    617       1.1  christos     WalkState->ParserState.Scope->ParseScope.ArgCount--;
    618       1.1  christos 
    619       1.1  christos     /* Close this Op (will result in parse subtree deletion) */
    620       1.1  christos 
    621       1.1  christos     Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
    622       1.1  christos     if (ACPI_FAILURE (Status2))
    623       1.1  christos     {
    624       1.1  christos         return_ACPI_STATUS (Status2);
    625       1.1  christos     }
    626       1.1  christos 
    627       1.1  christos     *Op = NULL;
    628       1.1  christos 
    629       1.1  christos     switch (Status)
    630       1.1  christos     {
    631       1.1  christos     case AE_OK:
    632       1.1  christos 
    633       1.1  christos         break;
    634       1.1  christos 
    635       1.1  christos     case AE_CTRL_TRANSFER:
    636       1.1  christos 
    637       1.1  christos         /* We are about to transfer to a called method */
    638       1.1  christos 
    639       1.1  christos         WalkState->PrevOp = NULL;
    640       1.1  christos         WalkState->PrevArgTypes = WalkState->ArgTypes;
    641       1.1  christos         return_ACPI_STATUS (Status);
    642       1.1  christos 
    643       1.1  christos     case AE_CTRL_END:
    644       1.1  christos 
    645       1.1  christos         AcpiPsPopScope (&(WalkState->ParserState), Op,
    646       1.1  christos             &WalkState->ArgTypes, &WalkState->ArgCount);
    647       1.1  christos 
    648       1.1  christos         if (*Op)
    649       1.1  christos         {
    650       1.1  christos             WalkState->Op = *Op;
    651       1.1  christos             WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
    652       1.1  christos             WalkState->Opcode = (*Op)->Common.AmlOpcode;
    653       1.1  christos 
    654       1.1  christos             Status = WalkState->AscendingCallback (WalkState);
    655  1.1.1.14  christos             (void) AcpiPsNextParseState (WalkState, *Op, Status);
    656       1.1  christos 
    657       1.1  christos             Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
    658       1.1  christos             if (ACPI_FAILURE (Status2))
    659       1.1  christos             {
    660       1.1  christos                 return_ACPI_STATUS (Status2);
    661       1.1  christos             }
    662       1.1  christos         }
    663       1.1  christos 
    664       1.1  christos         break;
    665       1.1  christos 
    666       1.1  christos     case AE_CTRL_BREAK:
    667       1.1  christos     case AE_CTRL_CONTINUE:
    668       1.1  christos 
    669       1.1  christos         /* Pop off scopes until we find the While */
    670       1.1  christos 
    671       1.1  christos         while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP))
    672       1.1  christos         {
    673       1.1  christos             AcpiPsPopScope (&(WalkState->ParserState), Op,
    674       1.1  christos                 &WalkState->ArgTypes, &WalkState->ArgCount);
    675       1.1  christos         }
    676       1.1  christos 
    677       1.1  christos         /* Close this iteration of the While loop */
    678       1.1  christos 
    679       1.1  christos         WalkState->Op = *Op;
    680       1.1  christos         WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
    681       1.1  christos         WalkState->Opcode = (*Op)->Common.AmlOpcode;
    682       1.1  christos 
    683       1.1  christos         Status = WalkState->AscendingCallback (WalkState);
    684  1.1.1.14  christos         (void) AcpiPsNextParseState (WalkState, *Op, Status);
    685       1.1  christos 
    686       1.1  christos         Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
    687       1.1  christos         if (ACPI_FAILURE (Status2))
    688       1.1  christos         {
    689       1.1  christos             return_ACPI_STATUS (Status2);
    690       1.1  christos         }
    691       1.1  christos 
    692       1.1  christos         break;
    693       1.1  christos 
    694       1.1  christos     case AE_CTRL_TERMINATE:
    695       1.1  christos 
    696       1.1  christos         /* Clean up */
    697       1.1  christos         do
    698       1.1  christos         {
    699       1.1  christos             if (*Op)
    700       1.1  christos             {
    701       1.1  christos                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
    702       1.1  christos                 if (ACPI_FAILURE (Status2))
    703       1.1  christos                 {
    704       1.1  christos                     return_ACPI_STATUS (Status2);
    705       1.1  christos                 }
    706       1.1  christos 
    707       1.1  christos                 AcpiUtDeleteGenericState (
    708       1.1  christos                     AcpiUtPopGenericState (&WalkState->ControlState));
    709       1.1  christos             }
    710       1.1  christos 
    711       1.1  christos             AcpiPsPopScope (&(WalkState->ParserState), Op,
    712       1.1  christos                 &WalkState->ArgTypes, &WalkState->ArgCount);
    713       1.1  christos 
    714       1.1  christos         } while (*Op);
    715       1.1  christos 
    716       1.1  christos         return_ACPI_STATUS (AE_OK);
    717       1.1  christos 
    718       1.1  christos     default:  /* All other non-AE_OK status */
    719       1.1  christos 
    720       1.1  christos         do
    721       1.1  christos         {
    722       1.1  christos             if (*Op)
    723       1.1  christos             {
    724  1.1.1.11  christos                 /*
    725  1.1.1.11  christos                  * These Opcodes need to be removed from the namespace because they
    726  1.1.1.11  christos                  * get created even if these opcodes cannot be created due to
    727  1.1.1.11  christos                  * errors.
    728  1.1.1.11  christos                  */
    729  1.1.1.11  christos                 if (((*Op)->Common.AmlOpcode == AML_REGION_OP) ||
    730  1.1.1.11  christos                     ((*Op)->Common.AmlOpcode == AML_DATA_REGION_OP))
    731  1.1.1.11  christos                 {
    732  1.1.1.11  christos                     AcpiNsDeleteChildren ((*Op)->Common.Node);
    733  1.1.1.11  christos                     AcpiNsRemoveNode ((*Op)->Common.Node);
    734  1.1.1.11  christos                     (*Op)->Common.Node = NULL;
    735  1.1.1.11  christos                     AcpiPsDeleteParseTree (*Op);
    736  1.1.1.11  christos                 }
    737  1.1.1.11  christos 
    738       1.1  christos                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
    739       1.1  christos                 if (ACPI_FAILURE (Status2))
    740       1.1  christos                 {
    741       1.1  christos                     return_ACPI_STATUS (Status2);
    742       1.1  christos                 }
    743       1.1  christos             }
    744       1.1  christos 
    745       1.1  christos             AcpiPsPopScope (&(WalkState->ParserState), Op,
    746       1.1  christos                 &WalkState->ArgTypes, &WalkState->ArgCount);
    747       1.1  christos 
    748       1.1  christos         } while (*Op);
    749       1.1  christos 
    750       1.1  christos 
    751       1.1  christos #if 0
    752       1.1  christos         /*
    753       1.1  christos          * TBD: Cleanup parse ops on error
    754       1.1  christos          */
    755       1.1  christos         if (*Op == NULL)
    756       1.1  christos         {
    757       1.1  christos             AcpiPsPopScope (ParserState, Op,
    758       1.1  christos                 &WalkState->ArgTypes, &WalkState->ArgCount);
    759       1.1  christos         }
    760       1.1  christos #endif
    761       1.1  christos         WalkState->PrevOp = NULL;
    762       1.1  christos         WalkState->PrevArgTypes = WalkState->ArgTypes;
    763  1.1.1.11  christos 
    764  1.1.1.11  christos         if (WalkState->ParseFlags & ACPI_PARSE_MODULE_LEVEL)
    765  1.1.1.11  christos         {
    766  1.1.1.11  christos             /*
    767  1.1.1.11  christos              * There was something that went wrong while executing code at the
    768  1.1.1.11  christos              * module-level. We need to skip parsing whatever caused the
    769  1.1.1.11  christos              * error and keep going. One runtime error during the table load
    770  1.1.1.11  christos              * should not cause the entire table to not be loaded. This is
    771  1.1.1.11  christos              * because there could be correct AML beyond the parts that caused
    772  1.1.1.11  christos              * the runtime error.
    773  1.1.1.11  christos              */
    774  1.1.1.12  christos             ACPI_INFO (("Ignoring error and continuing table load"));
    775  1.1.1.11  christos             return_ACPI_STATUS (AE_OK);
    776  1.1.1.11  christos         }
    777       1.1  christos         return_ACPI_STATUS (Status);
    778       1.1  christos     }
    779       1.1  christos 
    780       1.1  christos     /* This scope complete? */
    781       1.1  christos 
    782       1.1  christos     if (AcpiPsHasCompletedScope (&(WalkState->ParserState)))
    783       1.1  christos     {
    784       1.1  christos         AcpiPsPopScope (&(WalkState->ParserState), Op,
    785       1.1  christos             &WalkState->ArgTypes, &WalkState->ArgCount);
    786       1.1  christos         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op));
    787       1.1  christos     }
    788       1.1  christos     else
    789       1.1  christos     {
    790       1.1  christos         *Op = NULL;
    791       1.1  christos     }
    792       1.1  christos 
    793       1.1  christos     return_ACPI_STATUS (AE_OK);
    794       1.1  christos }
    795       1.1  christos 
    796       1.1  christos 
    797       1.1  christos /*******************************************************************************
    798       1.1  christos  *
    799       1.1  christos  * FUNCTION:    AcpiPsCompleteFinalOp
    800       1.1  christos  *
    801       1.1  christos  * PARAMETERS:  WalkState           - Current state
    802       1.1  christos  *              Op                  - Current Op
    803       1.1  christos  *              Status              - Current parse status before complete last
    804       1.1  christos  *                                    Op
    805       1.1  christos  *
    806       1.1  christos  * RETURN:      Status
    807       1.1  christos  *
    808       1.1  christos  * DESCRIPTION: Complete last Op.
    809       1.1  christos  *
    810       1.1  christos  ******************************************************************************/
    811       1.1  christos 
    812       1.1  christos ACPI_STATUS
    813       1.1  christos AcpiPsCompleteFinalOp (
    814       1.1  christos     ACPI_WALK_STATE         *WalkState,
    815       1.1  christos     ACPI_PARSE_OBJECT       *Op,
    816       1.1  christos     ACPI_STATUS             Status)
    817       1.1  christos {
    818  1.1.1.19  christos     ACPI_STATUS             ReturnStatus = Status;
    819  1.1.1.19  christos     BOOLEAN                 Ascending = TRUE;
    820       1.1  christos 
    821       1.1  christos 
    822       1.1  christos     ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState);
    823       1.1  christos 
    824       1.1  christos 
    825       1.1  christos     /*
    826       1.1  christos      * Complete the last Op (if not completed), and clear the scope stack.
    827       1.1  christos      * It is easily possible to end an AML "package" with an unbounded number
    828       1.1  christos      * of open scopes (such as when several ASL blocks are closed with
    829       1.1  christos      * sequential closing braces). We want to terminate each one cleanly.
    830       1.1  christos      */
    831       1.1  christos     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op));
    832       1.1  christos     do
    833       1.1  christos     {
    834       1.1  christos         if (Op)
    835       1.1  christos         {
    836  1.1.1.19  christos             if (Ascending && WalkState->AscendingCallback != NULL)
    837       1.1  christos             {
    838       1.1  christos                 WalkState->Op = Op;
    839       1.1  christos                 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
    840       1.1  christos                 WalkState->Opcode = Op->Common.AmlOpcode;
    841       1.1  christos 
    842       1.1  christos                 Status = WalkState->AscendingCallback (WalkState);
    843       1.1  christos                 Status = AcpiPsNextParseState (WalkState, Op, Status);
    844       1.1  christos                 if (Status == AE_CTRL_PENDING)
    845       1.1  christos                 {
    846       1.1  christos                     Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK);
    847       1.1  christos                     if (ACPI_FAILURE (Status))
    848       1.1  christos                     {
    849       1.1  christos                         return_ACPI_STATUS (Status);
    850       1.1  christos                     }
    851       1.1  christos                 }
    852       1.1  christos 
    853       1.1  christos                 if (Status == AE_CTRL_TERMINATE)
    854       1.1  christos                 {
    855  1.1.1.19  christos                     Ascending = FALSE;
    856  1.1.1.19  christos                     ReturnStatus = AE_CTRL_TERMINATE;
    857       1.1  christos                 }
    858       1.1  christos 
    859       1.1  christos                 else if (ACPI_FAILURE (Status))
    860       1.1  christos                 {
    861       1.1  christos                     /* First error is most important */
    862       1.1  christos 
    863  1.1.1.19  christos                     Ascending = FALSE;
    864  1.1.1.19  christos                     ReturnStatus = Status;
    865       1.1  christos                 }
    866       1.1  christos             }
    867       1.1  christos 
    868  1.1.1.19  christos             Status = AcpiPsCompleteThisOp (WalkState, Op);
    869  1.1.1.19  christos             if (ACPI_FAILURE (Status))
    870       1.1  christos             {
    871  1.1.1.19  christos                 Ascending = FALSE;
    872  1.1.1.19  christos                 if (ACPI_SUCCESS (ReturnStatus) ||
    873  1.1.1.19  christos                     ReturnStatus == AE_CTRL_TERMINATE)
    874  1.1.1.19  christos                 {
    875  1.1.1.19  christos                     ReturnStatus = Status;
    876  1.1.1.19  christos                 }
    877       1.1  christos             }
    878       1.1  christos         }
    879       1.1  christos 
    880       1.1  christos         AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes,
    881       1.1  christos             &WalkState->ArgCount);
    882       1.1  christos 
    883       1.1  christos     } while (Op);
    884       1.1  christos 
    885  1.1.1.19  christos     return_ACPI_STATUS (ReturnStatus);
    886       1.1  christos }
    887