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