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