xref: /freebsd/sys/contrib/dev/acpica/components/parser/psobject.c (revision 67d9aa44229b5b088d4a818015ba321e41432dbf)
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  *
110d84335fSJung-uk Kim  * Some or all of this work - Copyright (c) 1999 - 2017, 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>
157efcc2a30SJung-uk Kim 
158efcc2a30SJung-uk Kim #define _COMPONENT          ACPI_PARSER
159efcc2a30SJung-uk Kim         ACPI_MODULE_NAME    ("psobject")
160efcc2a30SJung-uk Kim 
161efcc2a30SJung-uk Kim 
162efcc2a30SJung-uk Kim /* Local prototypes */
163efcc2a30SJung-uk Kim 
164efcc2a30SJung-uk Kim static ACPI_STATUS
165efcc2a30SJung-uk Kim AcpiPsGetAmlOpcode (
166efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState);
167efcc2a30SJung-uk Kim 
168efcc2a30SJung-uk Kim 
169efcc2a30SJung-uk Kim /*******************************************************************************
170efcc2a30SJung-uk Kim  *
171efcc2a30SJung-uk Kim  * FUNCTION:    AcpiPsGetAmlOpcode
172efcc2a30SJung-uk Kim  *
173efcc2a30SJung-uk Kim  * PARAMETERS:  WalkState           - Current state
174efcc2a30SJung-uk Kim  *
175efcc2a30SJung-uk Kim  * RETURN:      Status
176efcc2a30SJung-uk Kim  *
177efcc2a30SJung-uk Kim  * DESCRIPTION: Extract the next AML opcode from the input stream.
178efcc2a30SJung-uk Kim  *
179efcc2a30SJung-uk Kim  ******************************************************************************/
180efcc2a30SJung-uk Kim 
181efcc2a30SJung-uk Kim static ACPI_STATUS
182efcc2a30SJung-uk Kim AcpiPsGetAmlOpcode (
183efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState)
184efcc2a30SJung-uk Kim {
185fe0f0bbbSJung-uk Kim     UINT32                  AmlOffset;
186fe0f0bbbSJung-uk Kim 
187efcc2a30SJung-uk Kim 
188efcc2a30SJung-uk Kim     ACPI_FUNCTION_TRACE_PTR (PsGetAmlOpcode, WalkState);
189efcc2a30SJung-uk Kim 
190efcc2a30SJung-uk Kim 
191fe0f0bbbSJung-uk Kim     WalkState->Aml = WalkState->ParserState.Aml;
192efcc2a30SJung-uk Kim     WalkState->Opcode = AcpiPsPeekOpcode (&(WalkState->ParserState));
193efcc2a30SJung-uk Kim 
194efcc2a30SJung-uk Kim     /*
195efcc2a30SJung-uk Kim      * First cut to determine what we have found:
196efcc2a30SJung-uk Kim      * 1) A valid AML opcode
197efcc2a30SJung-uk Kim      * 2) A name string
198efcc2a30SJung-uk Kim      * 3) An unknown/invalid opcode
199efcc2a30SJung-uk Kim      */
200efcc2a30SJung-uk Kim     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
201efcc2a30SJung-uk Kim 
202efcc2a30SJung-uk Kim     switch (WalkState->OpInfo->Class)
203efcc2a30SJung-uk Kim     {
204efcc2a30SJung-uk Kim     case AML_CLASS_ASCII:
205efcc2a30SJung-uk Kim     case AML_CLASS_PREFIX:
206efcc2a30SJung-uk Kim         /*
207efcc2a30SJung-uk Kim          * Starts with a valid prefix or ASCII char, this is a name
208efcc2a30SJung-uk Kim          * string. Convert the bare name string to a namepath.
209efcc2a30SJung-uk Kim          */
210efcc2a30SJung-uk Kim         WalkState->Opcode = AML_INT_NAMEPATH_OP;
211efcc2a30SJung-uk Kim         WalkState->ArgTypes = ARGP_NAMESTRING;
212efcc2a30SJung-uk Kim         break;
213efcc2a30SJung-uk Kim 
214efcc2a30SJung-uk Kim     case AML_CLASS_UNKNOWN:
215efcc2a30SJung-uk Kim 
216efcc2a30SJung-uk Kim         /* The opcode is unrecognized. Complain and skip unknown opcodes */
217efcc2a30SJung-uk Kim 
218efcc2a30SJung-uk Kim         if (WalkState->PassNumber == 2)
219efcc2a30SJung-uk Kim         {
220fe0f0bbbSJung-uk Kim             AmlOffset = (UINT32) ACPI_PTR_DIFF (WalkState->Aml,
221fe0f0bbbSJung-uk Kim                 WalkState->ParserState.AmlStart);
222fe0f0bbbSJung-uk Kim 
223efcc2a30SJung-uk Kim             ACPI_ERROR ((AE_INFO,
224efcc2a30SJung-uk Kim                 "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring",
225efcc2a30SJung-uk Kim                 WalkState->Opcode,
226fe0f0bbbSJung-uk Kim                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER))));
227efcc2a30SJung-uk Kim 
228efcc2a30SJung-uk Kim             ACPI_DUMP_BUFFER ((WalkState->ParserState.Aml - 16), 48);
229efcc2a30SJung-uk Kim 
230efcc2a30SJung-uk Kim #ifdef ACPI_ASL_COMPILER
231efcc2a30SJung-uk Kim             /*
232efcc2a30SJung-uk Kim              * This is executed for the disassembler only. Output goes
233efcc2a30SJung-uk Kim              * to the disassembled ASL output file.
234efcc2a30SJung-uk Kim              */
235efcc2a30SJung-uk Kim             AcpiOsPrintf (
236efcc2a30SJung-uk Kim                 "/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n",
237efcc2a30SJung-uk Kim                 WalkState->Opcode,
238fe0f0bbbSJung-uk Kim                 (UINT32) (AmlOffset + sizeof (ACPI_TABLE_HEADER)));
239efcc2a30SJung-uk Kim 
240af051161SJung-uk Kim             ACPI_ERROR ((AE_INFO,
241af051161SJung-uk Kim                 "Aborting disassembly, AML byte code is corrupt"));
242af051161SJung-uk Kim 
243efcc2a30SJung-uk Kim             /* Dump the context surrounding the invalid opcode */
244efcc2a30SJung-uk Kim 
245efcc2a30SJung-uk Kim             AcpiUtDumpBuffer (((UINT8 *) WalkState->ParserState.Aml - 16),
246efcc2a30SJung-uk Kim                 48, DB_BYTE_DISPLAY,
247fe0f0bbbSJung-uk Kim                 (AmlOffset + sizeof (ACPI_TABLE_HEADER) - 16));
248efcc2a30SJung-uk Kim             AcpiOsPrintf (" */\n");
249af051161SJung-uk Kim 
250af051161SJung-uk Kim             /*
251af051161SJung-uk Kim              * Just abort the disassembly, cannot continue because the
252af051161SJung-uk Kim              * parser is essentially lost. The disassembler can then
253af051161SJung-uk Kim              * randomly fail because an ill-constructed parse tree
254af051161SJung-uk Kim              * can result.
255af051161SJung-uk Kim              */
256af051161SJung-uk Kim             return_ACPI_STATUS (AE_AML_BAD_OPCODE);
257efcc2a30SJung-uk Kim #endif
258efcc2a30SJung-uk Kim         }
259efcc2a30SJung-uk Kim 
260efcc2a30SJung-uk Kim         /* Increment past one-byte or two-byte opcode */
261efcc2a30SJung-uk Kim 
262efcc2a30SJung-uk Kim         WalkState->ParserState.Aml++;
263efcc2a30SJung-uk Kim         if (WalkState->Opcode > 0xFF) /* Can only happen if first byte is 0x5B */
264efcc2a30SJung-uk Kim         {
265efcc2a30SJung-uk Kim             WalkState->ParserState.Aml++;
266efcc2a30SJung-uk Kim         }
267efcc2a30SJung-uk Kim 
268efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
269efcc2a30SJung-uk Kim 
270efcc2a30SJung-uk Kim     default:
271efcc2a30SJung-uk Kim 
272efcc2a30SJung-uk Kim         /* Found opcode info, this is a normal opcode */
273efcc2a30SJung-uk Kim 
274f8146b88SJung-uk Kim         WalkState->ParserState.Aml +=
275f8146b88SJung-uk Kim             AcpiPsGetOpcodeSize (WalkState->Opcode);
276efcc2a30SJung-uk Kim         WalkState->ArgTypes = WalkState->OpInfo->ParseArgs;
277efcc2a30SJung-uk Kim         break;
278efcc2a30SJung-uk Kim     }
279efcc2a30SJung-uk Kim 
280efcc2a30SJung-uk Kim     return_ACPI_STATUS (AE_OK);
281efcc2a30SJung-uk Kim }
282efcc2a30SJung-uk Kim 
283efcc2a30SJung-uk Kim 
284efcc2a30SJung-uk Kim /*******************************************************************************
285efcc2a30SJung-uk Kim  *
286efcc2a30SJung-uk Kim  * FUNCTION:    AcpiPsBuildNamedOp
287efcc2a30SJung-uk Kim  *
288efcc2a30SJung-uk Kim  * PARAMETERS:  WalkState           - Current state
289efcc2a30SJung-uk Kim  *              AmlOpStart          - Begin of named Op in AML
290efcc2a30SJung-uk Kim  *              UnnamedOp           - Early Op (not a named Op)
291efcc2a30SJung-uk Kim  *              Op                  - Returned Op
292efcc2a30SJung-uk Kim  *
293efcc2a30SJung-uk Kim  * RETURN:      Status
294efcc2a30SJung-uk Kim  *
295efcc2a30SJung-uk Kim  * DESCRIPTION: Parse a named Op
296efcc2a30SJung-uk Kim  *
297efcc2a30SJung-uk Kim  ******************************************************************************/
298efcc2a30SJung-uk Kim 
299efcc2a30SJung-uk Kim ACPI_STATUS
300efcc2a30SJung-uk Kim AcpiPsBuildNamedOp (
301efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
302efcc2a30SJung-uk Kim     UINT8                   *AmlOpStart,
303efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *UnnamedOp,
304efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       **Op)
305efcc2a30SJung-uk Kim {
306efcc2a30SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
307efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *Arg = NULL;
308efcc2a30SJung-uk Kim 
309efcc2a30SJung-uk Kim 
310efcc2a30SJung-uk Kim     ACPI_FUNCTION_TRACE_PTR (PsBuildNamedOp, WalkState);
311efcc2a30SJung-uk Kim 
312efcc2a30SJung-uk Kim 
313efcc2a30SJung-uk Kim     UnnamedOp->Common.Value.Arg = NULL;
314efcc2a30SJung-uk Kim     UnnamedOp->Common.ArgListLength = 0;
315efcc2a30SJung-uk Kim     UnnamedOp->Common.AmlOpcode = WalkState->Opcode;
316efcc2a30SJung-uk Kim 
317efcc2a30SJung-uk Kim     /*
318efcc2a30SJung-uk Kim      * Get and append arguments until we find the node that contains
319efcc2a30SJung-uk Kim      * the name (the type ARGP_NAME).
320efcc2a30SJung-uk Kim      */
321efcc2a30SJung-uk Kim     while (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) &&
322efcc2a30SJung-uk Kim           (GET_CURRENT_ARG_TYPE (WalkState->ArgTypes) != ARGP_NAME))
323efcc2a30SJung-uk Kim     {
3240d84335fSJung-uk Kim         ASL_CV_CAPTURE_COMMENTS (WalkState);
325efcc2a30SJung-uk Kim         Status = AcpiPsGetNextArg (WalkState, &(WalkState->ParserState),
326efcc2a30SJung-uk Kim             GET_CURRENT_ARG_TYPE (WalkState->ArgTypes), &Arg);
327efcc2a30SJung-uk Kim         if (ACPI_FAILURE (Status))
328efcc2a30SJung-uk Kim         {
329efcc2a30SJung-uk Kim             return_ACPI_STATUS (Status);
330efcc2a30SJung-uk Kim         }
331efcc2a30SJung-uk Kim 
332efcc2a30SJung-uk Kim         AcpiPsAppendArg (UnnamedOp, Arg);
333efcc2a30SJung-uk Kim         INCREMENT_ARG_LIST (WalkState->ArgTypes);
334efcc2a30SJung-uk Kim     }
335efcc2a30SJung-uk Kim 
3360d84335fSJung-uk Kim     /* are there any inline comments associated with the NameSeg?? If so, save this. */
3370d84335fSJung-uk Kim 
3380d84335fSJung-uk Kim     ASL_CV_CAPTURE_COMMENTS (WalkState);
3390d84335fSJung-uk Kim 
3400d84335fSJung-uk Kim #ifdef ACPI_ASL_COMPILER
3410d84335fSJung-uk Kim     if (AcpiGbl_CurrentInlineComment != NULL)
3420d84335fSJung-uk Kim     {
3430d84335fSJung-uk Kim         UnnamedOp->Common.NameComment = AcpiGbl_CurrentInlineComment;
3440d84335fSJung-uk Kim         AcpiGbl_CurrentInlineComment = NULL;
3450d84335fSJung-uk Kim     }
3460d84335fSJung-uk Kim #endif
3470d84335fSJung-uk Kim 
348efcc2a30SJung-uk Kim     /*
349efcc2a30SJung-uk Kim      * Make sure that we found a NAME and didn't run out of arguments
350efcc2a30SJung-uk Kim      */
351efcc2a30SJung-uk Kim     if (!GET_CURRENT_ARG_TYPE (WalkState->ArgTypes))
352efcc2a30SJung-uk Kim     {
353efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_AML_NO_OPERAND);
354efcc2a30SJung-uk Kim     }
355efcc2a30SJung-uk Kim 
356efcc2a30SJung-uk Kim     /* We know that this arg is a name, move to next arg */
357efcc2a30SJung-uk Kim 
358efcc2a30SJung-uk Kim     INCREMENT_ARG_LIST (WalkState->ArgTypes);
359efcc2a30SJung-uk Kim 
360efcc2a30SJung-uk Kim     /*
361efcc2a30SJung-uk Kim      * Find the object. This will either insert the object into
362efcc2a30SJung-uk Kim      * the namespace or simply look it up
363efcc2a30SJung-uk Kim      */
364efcc2a30SJung-uk Kim     WalkState->Op = NULL;
365efcc2a30SJung-uk Kim 
366efcc2a30SJung-uk Kim     Status = WalkState->DescendingCallback (WalkState, Op);
367efcc2a30SJung-uk Kim     if (ACPI_FAILURE (Status))
368efcc2a30SJung-uk Kim     {
369313a0c13SJung-uk Kim         if (Status != AE_CTRL_TERMINATE)
370313a0c13SJung-uk Kim         {
371efcc2a30SJung-uk Kim             ACPI_EXCEPTION ((AE_INFO, Status, "During name lookup/catalog"));
372313a0c13SJung-uk Kim         }
373efcc2a30SJung-uk Kim         return_ACPI_STATUS (Status);
374efcc2a30SJung-uk Kim     }
375efcc2a30SJung-uk Kim 
376efcc2a30SJung-uk Kim     if (!*Op)
377efcc2a30SJung-uk Kim     {
378efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
379efcc2a30SJung-uk Kim     }
380efcc2a30SJung-uk Kim 
381efcc2a30SJung-uk Kim     Status = AcpiPsNextParseState (WalkState, *Op, Status);
382efcc2a30SJung-uk Kim     if (ACPI_FAILURE (Status))
383efcc2a30SJung-uk Kim     {
384efcc2a30SJung-uk Kim         if (Status == AE_CTRL_PENDING)
385efcc2a30SJung-uk Kim         {
386313a0c13SJung-uk Kim             Status = AE_CTRL_PARSE_PENDING;
387efcc2a30SJung-uk Kim         }
388efcc2a30SJung-uk Kim         return_ACPI_STATUS (Status);
389efcc2a30SJung-uk Kim     }
390efcc2a30SJung-uk Kim 
391efcc2a30SJung-uk Kim     AcpiPsAppendArg (*Op, UnnamedOp->Common.Value.Arg);
392efcc2a30SJung-uk Kim 
3930d84335fSJung-uk Kim #ifdef ACPI_ASL_COMPILER
3940d84335fSJung-uk Kim 
3950d84335fSJung-uk Kim     /* save any comments that might be associated with UnnamedOp. */
3960d84335fSJung-uk Kim 
3970d84335fSJung-uk Kim     (*Op)->Common.InlineComment     = UnnamedOp->Common.InlineComment;
3980d84335fSJung-uk Kim     (*Op)->Common.EndNodeComment    = UnnamedOp->Common.EndNodeComment;
3990d84335fSJung-uk Kim     (*Op)->Common.CloseBraceComment = UnnamedOp->Common.CloseBraceComment;
4000d84335fSJung-uk Kim     (*Op)->Common.NameComment       = UnnamedOp->Common.NameComment;
4010d84335fSJung-uk Kim     (*Op)->Common.CommentList       = UnnamedOp->Common.CommentList;
4020d84335fSJung-uk Kim     (*Op)->Common.EndBlkComment     = UnnamedOp->Common.EndBlkComment;
4030d84335fSJung-uk Kim     (*Op)->Common.CvFilename        = UnnamedOp->Common.CvFilename;
4040d84335fSJung-uk Kim     (*Op)->Common.CvParentFilename  = UnnamedOp->Common.CvParentFilename;
4050d84335fSJung-uk Kim     (*Op)->Named.Aml                = UnnamedOp->Common.Aml;
4060d84335fSJung-uk Kim 
4070d84335fSJung-uk Kim     UnnamedOp->Common.InlineComment     = NULL;
4080d84335fSJung-uk Kim     UnnamedOp->Common.EndNodeComment    = NULL;
4090d84335fSJung-uk Kim     UnnamedOp->Common.CloseBraceComment = NULL;
4100d84335fSJung-uk Kim     UnnamedOp->Common.NameComment       = NULL;
4110d84335fSJung-uk Kim     UnnamedOp->Common.CommentList       = NULL;
4120d84335fSJung-uk Kim     UnnamedOp->Common.EndBlkComment     = NULL;
4130d84335fSJung-uk Kim #endif
4140d84335fSJung-uk Kim 
415efcc2a30SJung-uk Kim     if ((*Op)->Common.AmlOpcode == AML_REGION_OP ||
416efcc2a30SJung-uk Kim         (*Op)->Common.AmlOpcode == AML_DATA_REGION_OP)
417efcc2a30SJung-uk Kim     {
418efcc2a30SJung-uk Kim         /*
419efcc2a30SJung-uk Kim          * Defer final parsing of an OperationRegion body, because we don't
420efcc2a30SJung-uk Kim          * have enough info in the first pass to parse it correctly (i.e.,
421efcc2a30SJung-uk Kim          * there may be method calls within the TermArg elements of the body.)
422efcc2a30SJung-uk Kim          *
423efcc2a30SJung-uk Kim          * However, we must continue parsing because the opregion is not a
424efcc2a30SJung-uk Kim          * standalone package -- we don't know where the end is at this point.
425efcc2a30SJung-uk Kim          *
426efcc2a30SJung-uk Kim          * (Length is unknown until parse of the body complete)
427efcc2a30SJung-uk Kim          */
428efcc2a30SJung-uk Kim         (*Op)->Named.Data = AmlOpStart;
429efcc2a30SJung-uk Kim         (*Op)->Named.Length = 0;
430efcc2a30SJung-uk Kim     }
431efcc2a30SJung-uk Kim 
432efcc2a30SJung-uk Kim     return_ACPI_STATUS (AE_OK);
433efcc2a30SJung-uk Kim }
434efcc2a30SJung-uk Kim 
435efcc2a30SJung-uk Kim 
436efcc2a30SJung-uk Kim /*******************************************************************************
437efcc2a30SJung-uk Kim  *
438efcc2a30SJung-uk Kim  * FUNCTION:    AcpiPsCreateOp
439efcc2a30SJung-uk Kim  *
440efcc2a30SJung-uk Kim  * PARAMETERS:  WalkState           - Current state
441efcc2a30SJung-uk Kim  *              AmlOpStart          - Op start in AML
442efcc2a30SJung-uk Kim  *              NewOp               - Returned Op
443efcc2a30SJung-uk Kim  *
444efcc2a30SJung-uk Kim  * RETURN:      Status
445efcc2a30SJung-uk Kim  *
446efcc2a30SJung-uk Kim  * DESCRIPTION: Get Op from AML
447efcc2a30SJung-uk Kim  *
448efcc2a30SJung-uk Kim  ******************************************************************************/
449efcc2a30SJung-uk Kim 
450efcc2a30SJung-uk Kim ACPI_STATUS
451efcc2a30SJung-uk Kim AcpiPsCreateOp (
452efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
453efcc2a30SJung-uk Kim     UINT8                   *AmlOpStart,
454efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       **NewOp)
455efcc2a30SJung-uk Kim {
456efcc2a30SJung-uk Kim     ACPI_STATUS             Status = AE_OK;
457efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *Op;
458efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *NamedOp = NULL;
459efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *ParentScope;
460efcc2a30SJung-uk Kim     UINT8                   ArgumentCount;
461efcc2a30SJung-uk Kim     const ACPI_OPCODE_INFO  *OpInfo;
462efcc2a30SJung-uk Kim 
463efcc2a30SJung-uk Kim 
464efcc2a30SJung-uk Kim     ACPI_FUNCTION_TRACE_PTR (PsCreateOp, WalkState);
465efcc2a30SJung-uk Kim 
466efcc2a30SJung-uk Kim 
467efcc2a30SJung-uk Kim     Status = AcpiPsGetAmlOpcode (WalkState);
468efcc2a30SJung-uk Kim     if (Status == AE_CTRL_PARSE_CONTINUE)
469efcc2a30SJung-uk Kim     {
470efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
471efcc2a30SJung-uk Kim     }
472af051161SJung-uk Kim     if (ACPI_FAILURE (Status))
473af051161SJung-uk Kim     {
474af051161SJung-uk Kim         return_ACPI_STATUS (Status);
475af051161SJung-uk Kim     }
476efcc2a30SJung-uk Kim 
477efcc2a30SJung-uk Kim     /* Create Op structure and append to parent's argument list */
478efcc2a30SJung-uk Kim 
479efcc2a30SJung-uk Kim     WalkState->OpInfo = AcpiPsGetOpcodeInfo (WalkState->Opcode);
480fe0f0bbbSJung-uk Kim     Op = AcpiPsAllocOp (WalkState->Opcode, AmlOpStart);
481efcc2a30SJung-uk Kim     if (!Op)
482efcc2a30SJung-uk Kim     {
483efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_NO_MEMORY);
484efcc2a30SJung-uk Kim     }
485efcc2a30SJung-uk Kim 
486efcc2a30SJung-uk Kim     if (WalkState->OpInfo->Flags & AML_NAMED)
487efcc2a30SJung-uk Kim     {
488efcc2a30SJung-uk Kim         Status = AcpiPsBuildNamedOp (WalkState, AmlOpStart, Op, &NamedOp);
489efcc2a30SJung-uk Kim         AcpiPsFreeOp (Op);
4905f9b24faSJung-uk Kim 
4915f9b24faSJung-uk Kim #ifdef ACPI_ASL_COMPILER
4925f9b24faSJung-uk Kim         if (AcpiGbl_DisasmFlag && WalkState->Opcode == AML_EXTERNAL_OP &&
4935f9b24faSJung-uk Kim             Status == AE_NOT_FOUND)
4945f9b24faSJung-uk Kim         {
4955f9b24faSJung-uk Kim             /*
4965f9b24faSJung-uk Kim              * If parsing of AML_EXTERNAL_OP's name path fails, then skip
4975f9b24faSJung-uk Kim              * past this opcode and keep parsing. This is a much better
4985f9b24faSJung-uk Kim              * alternative than to abort the entire disassembler. At this
4995f9b24faSJung-uk Kim              * point, the ParserState is at the end of the namepath of the
5005f9b24faSJung-uk Kim              * external declaration opcode. Setting WalkState->Aml to
5015f9b24faSJung-uk Kim              * WalkState->ParserState.Aml + 2 moves increments the
5025f9b24faSJung-uk Kim              * WalkState->Aml past the object type and the paramcount of the
503*67d9aa44SJung-uk Kim              * external opcode.
5045f9b24faSJung-uk Kim              */
5055f9b24faSJung-uk Kim             WalkState->Aml = WalkState->ParserState.Aml + 2;
506*67d9aa44SJung-uk Kim             WalkState->ParserState.Aml = WalkState->Aml;
5075f9b24faSJung-uk Kim             return_ACPI_STATUS (AE_CTRL_PARSE_CONTINUE);
5085f9b24faSJung-uk Kim         }
5095f9b24faSJung-uk Kim #endif
510efcc2a30SJung-uk Kim         if (ACPI_FAILURE (Status))
511efcc2a30SJung-uk Kim         {
512efcc2a30SJung-uk Kim             return_ACPI_STATUS (Status);
513efcc2a30SJung-uk Kim         }
514efcc2a30SJung-uk Kim 
515efcc2a30SJung-uk Kim         *NewOp = NamedOp;
516efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_OK);
517efcc2a30SJung-uk Kim     }
518efcc2a30SJung-uk Kim 
519efcc2a30SJung-uk Kim     /* Not a named opcode, just allocate Op and append to parent */
520efcc2a30SJung-uk Kim 
521efcc2a30SJung-uk Kim     if (WalkState->OpInfo->Flags & AML_CREATE)
522efcc2a30SJung-uk Kim     {
523efcc2a30SJung-uk Kim         /*
524efcc2a30SJung-uk Kim          * Backup to beginning of CreateXXXfield declaration
525efcc2a30SJung-uk Kim          * BodyLength is unknown until we parse the body
526efcc2a30SJung-uk Kim          */
527efcc2a30SJung-uk Kim         Op->Named.Data = AmlOpStart;
528efcc2a30SJung-uk Kim         Op->Named.Length = 0;
529efcc2a30SJung-uk Kim     }
530efcc2a30SJung-uk Kim 
531efcc2a30SJung-uk Kim     if (WalkState->Opcode == AML_BANK_FIELD_OP)
532efcc2a30SJung-uk Kim     {
533efcc2a30SJung-uk Kim         /*
534efcc2a30SJung-uk Kim          * Backup to beginning of BankField declaration
535efcc2a30SJung-uk Kim          * BodyLength is unknown until we parse the body
536efcc2a30SJung-uk Kim          */
537efcc2a30SJung-uk Kim         Op->Named.Data = AmlOpStart;
538efcc2a30SJung-uk Kim         Op->Named.Length = 0;
539efcc2a30SJung-uk Kim     }
540efcc2a30SJung-uk Kim 
541efcc2a30SJung-uk Kim     ParentScope = AcpiPsGetParentScope (&(WalkState->ParserState));
542efcc2a30SJung-uk Kim     AcpiPsAppendArg (ParentScope, Op);
543efcc2a30SJung-uk Kim 
544efcc2a30SJung-uk Kim     if (ParentScope)
545efcc2a30SJung-uk Kim     {
546efcc2a30SJung-uk Kim         OpInfo = AcpiPsGetOpcodeInfo (ParentScope->Common.AmlOpcode);
547efcc2a30SJung-uk Kim         if (OpInfo->Flags & AML_HAS_TARGET)
548efcc2a30SJung-uk Kim         {
549efcc2a30SJung-uk Kim             ArgumentCount = AcpiPsGetArgumentCount (OpInfo->Type);
550efcc2a30SJung-uk Kim             if (ParentScope->Common.ArgListLength > ArgumentCount)
551efcc2a30SJung-uk Kim             {
552efcc2a30SJung-uk Kim                 Op->Common.Flags |= ACPI_PARSEOP_TARGET;
553efcc2a30SJung-uk Kim             }
554efcc2a30SJung-uk Kim         }
5551cc50d6bSJung-uk Kim 
5561cc50d6bSJung-uk Kim         /*
5571cc50d6bSJung-uk Kim          * Special case for both Increment() and Decrement(), where
5581cc50d6bSJung-uk Kim          * the lone argument is both a source and a target.
5591cc50d6bSJung-uk Kim          */
5601cc50d6bSJung-uk Kim         else if ((ParentScope->Common.AmlOpcode == AML_INCREMENT_OP) ||
5611cc50d6bSJung-uk Kim                 (ParentScope->Common.AmlOpcode == AML_DECREMENT_OP))
562efcc2a30SJung-uk Kim         {
563efcc2a30SJung-uk Kim             Op->Common.Flags |= ACPI_PARSEOP_TARGET;
564efcc2a30SJung-uk Kim         }
565efcc2a30SJung-uk Kim     }
566efcc2a30SJung-uk Kim 
567efcc2a30SJung-uk Kim     if (WalkState->DescendingCallback != NULL)
568efcc2a30SJung-uk Kim     {
569efcc2a30SJung-uk Kim         /*
570efcc2a30SJung-uk Kim          * Find the object. This will either insert the object into
571efcc2a30SJung-uk Kim          * the namespace or simply look it up
572efcc2a30SJung-uk Kim          */
573efcc2a30SJung-uk Kim         WalkState->Op = *NewOp = Op;
574efcc2a30SJung-uk Kim 
575efcc2a30SJung-uk Kim         Status = WalkState->DescendingCallback (WalkState, &Op);
576efcc2a30SJung-uk Kim         Status = AcpiPsNextParseState (WalkState, Op, Status);
577efcc2a30SJung-uk Kim         if (Status == AE_CTRL_PENDING)
578efcc2a30SJung-uk Kim         {
579efcc2a30SJung-uk Kim             Status = AE_CTRL_PARSE_PENDING;
580efcc2a30SJung-uk Kim         }
581efcc2a30SJung-uk Kim     }
582efcc2a30SJung-uk Kim 
583efcc2a30SJung-uk Kim     return_ACPI_STATUS (Status);
584efcc2a30SJung-uk Kim }
585efcc2a30SJung-uk Kim 
586efcc2a30SJung-uk Kim 
587efcc2a30SJung-uk Kim /*******************************************************************************
588efcc2a30SJung-uk Kim  *
589efcc2a30SJung-uk Kim  * FUNCTION:    AcpiPsCompleteOp
590efcc2a30SJung-uk Kim  *
591efcc2a30SJung-uk Kim  * PARAMETERS:  WalkState           - Current state
592efcc2a30SJung-uk Kim  *              Op                  - Returned Op
593efcc2a30SJung-uk Kim  *              Status              - Parse status before complete Op
594efcc2a30SJung-uk Kim  *
595efcc2a30SJung-uk Kim  * RETURN:      Status
596efcc2a30SJung-uk Kim  *
597efcc2a30SJung-uk Kim  * DESCRIPTION: Complete Op
598efcc2a30SJung-uk Kim  *
599efcc2a30SJung-uk Kim  ******************************************************************************/
600efcc2a30SJung-uk Kim 
601efcc2a30SJung-uk Kim ACPI_STATUS
602efcc2a30SJung-uk Kim AcpiPsCompleteOp (
603efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
604efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       **Op,
605efcc2a30SJung-uk Kim     ACPI_STATUS             Status)
606efcc2a30SJung-uk Kim {
607efcc2a30SJung-uk Kim     ACPI_STATUS             Status2;
608efcc2a30SJung-uk Kim 
609efcc2a30SJung-uk Kim 
610efcc2a30SJung-uk Kim     ACPI_FUNCTION_TRACE_PTR (PsCompleteOp, WalkState);
611efcc2a30SJung-uk Kim 
612efcc2a30SJung-uk Kim 
613efcc2a30SJung-uk Kim     /*
614efcc2a30SJung-uk Kim      * Finished one argument of the containing scope
615efcc2a30SJung-uk Kim      */
616efcc2a30SJung-uk Kim     WalkState->ParserState.Scope->ParseScope.ArgCount--;
617efcc2a30SJung-uk Kim 
618efcc2a30SJung-uk Kim     /* Close this Op (will result in parse subtree deletion) */
619efcc2a30SJung-uk Kim 
620efcc2a30SJung-uk Kim     Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
621efcc2a30SJung-uk Kim     if (ACPI_FAILURE (Status2))
622efcc2a30SJung-uk Kim     {
623efcc2a30SJung-uk Kim         return_ACPI_STATUS (Status2);
624efcc2a30SJung-uk Kim     }
625efcc2a30SJung-uk Kim 
626efcc2a30SJung-uk Kim     *Op = NULL;
627efcc2a30SJung-uk Kim 
628efcc2a30SJung-uk Kim     switch (Status)
629efcc2a30SJung-uk Kim     {
630efcc2a30SJung-uk Kim     case AE_OK:
631efcc2a30SJung-uk Kim 
632a9d8d09cSJung-uk Kim         break;
633efcc2a30SJung-uk Kim 
634efcc2a30SJung-uk Kim     case AE_CTRL_TRANSFER:
635efcc2a30SJung-uk Kim 
636efcc2a30SJung-uk Kim         /* We are about to transfer to a called method */
637efcc2a30SJung-uk Kim 
638efcc2a30SJung-uk Kim         WalkState->PrevOp = NULL;
639efcc2a30SJung-uk Kim         WalkState->PrevArgTypes = WalkState->ArgTypes;
640efcc2a30SJung-uk Kim         return_ACPI_STATUS (Status);
641efcc2a30SJung-uk Kim 
642efcc2a30SJung-uk Kim     case AE_CTRL_END:
643efcc2a30SJung-uk Kim 
644efcc2a30SJung-uk Kim         AcpiPsPopScope (&(WalkState->ParserState), Op,
645efcc2a30SJung-uk Kim             &WalkState->ArgTypes, &WalkState->ArgCount);
646efcc2a30SJung-uk Kim 
647efcc2a30SJung-uk Kim         if (*Op)
648efcc2a30SJung-uk Kim         {
649efcc2a30SJung-uk Kim             WalkState->Op = *Op;
650efcc2a30SJung-uk Kim             WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
651efcc2a30SJung-uk Kim             WalkState->Opcode = (*Op)->Common.AmlOpcode;
652efcc2a30SJung-uk Kim 
653efcc2a30SJung-uk Kim             Status = WalkState->AscendingCallback (WalkState);
654efcc2a30SJung-uk Kim             Status = AcpiPsNextParseState (WalkState, *Op, Status);
655efcc2a30SJung-uk Kim 
656efcc2a30SJung-uk Kim             Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
657efcc2a30SJung-uk Kim             if (ACPI_FAILURE (Status2))
658efcc2a30SJung-uk Kim             {
659efcc2a30SJung-uk Kim                 return_ACPI_STATUS (Status2);
660efcc2a30SJung-uk Kim             }
661efcc2a30SJung-uk Kim         }
662efcc2a30SJung-uk Kim 
663efcc2a30SJung-uk Kim         Status = AE_OK;
664efcc2a30SJung-uk Kim         break;
665efcc2a30SJung-uk Kim 
666efcc2a30SJung-uk Kim     case AE_CTRL_BREAK:
667efcc2a30SJung-uk Kim     case AE_CTRL_CONTINUE:
668efcc2a30SJung-uk Kim 
669efcc2a30SJung-uk Kim         /* Pop off scopes until we find the While */
670efcc2a30SJung-uk Kim 
671efcc2a30SJung-uk Kim         while (!(*Op) || ((*Op)->Common.AmlOpcode != AML_WHILE_OP))
672efcc2a30SJung-uk Kim         {
673efcc2a30SJung-uk Kim             AcpiPsPopScope (&(WalkState->ParserState), Op,
674efcc2a30SJung-uk Kim                 &WalkState->ArgTypes, &WalkState->ArgCount);
675efcc2a30SJung-uk Kim         }
676efcc2a30SJung-uk Kim 
677efcc2a30SJung-uk Kim         /* Close this iteration of the While loop */
678efcc2a30SJung-uk Kim 
679efcc2a30SJung-uk Kim         WalkState->Op = *Op;
680efcc2a30SJung-uk Kim         WalkState->OpInfo = AcpiPsGetOpcodeInfo ((*Op)->Common.AmlOpcode);
681efcc2a30SJung-uk Kim         WalkState->Opcode = (*Op)->Common.AmlOpcode;
682efcc2a30SJung-uk Kim 
683efcc2a30SJung-uk Kim         Status = WalkState->AscendingCallback (WalkState);
684efcc2a30SJung-uk Kim         Status = AcpiPsNextParseState (WalkState, *Op, Status);
685efcc2a30SJung-uk Kim 
686efcc2a30SJung-uk Kim         Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
687efcc2a30SJung-uk Kim         if (ACPI_FAILURE (Status2))
688efcc2a30SJung-uk Kim         {
689efcc2a30SJung-uk Kim             return_ACPI_STATUS (Status2);
690efcc2a30SJung-uk Kim         }
691efcc2a30SJung-uk Kim 
692efcc2a30SJung-uk Kim         Status = AE_OK;
693efcc2a30SJung-uk Kim         break;
694efcc2a30SJung-uk Kim 
695efcc2a30SJung-uk Kim     case AE_CTRL_TERMINATE:
696efcc2a30SJung-uk Kim 
697efcc2a30SJung-uk Kim         /* Clean up */
698efcc2a30SJung-uk Kim         do
699efcc2a30SJung-uk Kim         {
700efcc2a30SJung-uk Kim             if (*Op)
701efcc2a30SJung-uk Kim             {
702efcc2a30SJung-uk Kim                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
703efcc2a30SJung-uk Kim                 if (ACPI_FAILURE (Status2))
704efcc2a30SJung-uk Kim                 {
705efcc2a30SJung-uk Kim                     return_ACPI_STATUS (Status2);
706efcc2a30SJung-uk Kim                 }
707efcc2a30SJung-uk Kim 
708efcc2a30SJung-uk Kim                 AcpiUtDeleteGenericState (
709efcc2a30SJung-uk Kim                     AcpiUtPopGenericState (&WalkState->ControlState));
710efcc2a30SJung-uk Kim             }
711efcc2a30SJung-uk Kim 
712efcc2a30SJung-uk Kim             AcpiPsPopScope (&(WalkState->ParserState), Op,
713efcc2a30SJung-uk Kim                 &WalkState->ArgTypes, &WalkState->ArgCount);
714efcc2a30SJung-uk Kim 
715efcc2a30SJung-uk Kim         } while (*Op);
716efcc2a30SJung-uk Kim 
717efcc2a30SJung-uk Kim         return_ACPI_STATUS (AE_OK);
718efcc2a30SJung-uk Kim 
719efcc2a30SJung-uk Kim     default:  /* All other non-AE_OK status */
720efcc2a30SJung-uk Kim 
721efcc2a30SJung-uk Kim         do
722efcc2a30SJung-uk Kim         {
723efcc2a30SJung-uk Kim             if (*Op)
724efcc2a30SJung-uk Kim             {
725efcc2a30SJung-uk Kim                 Status2 = AcpiPsCompleteThisOp (WalkState, *Op);
726efcc2a30SJung-uk Kim                 if (ACPI_FAILURE (Status2))
727efcc2a30SJung-uk Kim                 {
728efcc2a30SJung-uk Kim                     return_ACPI_STATUS (Status2);
729efcc2a30SJung-uk Kim                 }
730efcc2a30SJung-uk Kim             }
731efcc2a30SJung-uk Kim 
732efcc2a30SJung-uk Kim             AcpiPsPopScope (&(WalkState->ParserState), Op,
733efcc2a30SJung-uk Kim                 &WalkState->ArgTypes, &WalkState->ArgCount);
734efcc2a30SJung-uk Kim 
735efcc2a30SJung-uk Kim         } while (*Op);
736efcc2a30SJung-uk Kim 
737efcc2a30SJung-uk Kim 
738efcc2a30SJung-uk Kim #if 0
739efcc2a30SJung-uk Kim         /*
740efcc2a30SJung-uk Kim          * TBD: Cleanup parse ops on error
741efcc2a30SJung-uk Kim          */
742efcc2a30SJung-uk Kim         if (*Op == NULL)
743efcc2a30SJung-uk Kim         {
744efcc2a30SJung-uk Kim             AcpiPsPopScope (ParserState, Op,
745efcc2a30SJung-uk Kim                 &WalkState->ArgTypes, &WalkState->ArgCount);
746efcc2a30SJung-uk Kim         }
747efcc2a30SJung-uk Kim #endif
748efcc2a30SJung-uk Kim         WalkState->PrevOp = NULL;
749efcc2a30SJung-uk Kim         WalkState->PrevArgTypes = WalkState->ArgTypes;
750efcc2a30SJung-uk Kim         return_ACPI_STATUS (Status);
751efcc2a30SJung-uk Kim     }
752efcc2a30SJung-uk Kim 
753efcc2a30SJung-uk Kim     /* This scope complete? */
754efcc2a30SJung-uk Kim 
755efcc2a30SJung-uk Kim     if (AcpiPsHasCompletedScope (&(WalkState->ParserState)))
756efcc2a30SJung-uk Kim     {
757efcc2a30SJung-uk Kim         AcpiPsPopScope (&(WalkState->ParserState), Op,
758efcc2a30SJung-uk Kim             &WalkState->ArgTypes, &WalkState->ArgCount);
759efcc2a30SJung-uk Kim         ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *Op));
760efcc2a30SJung-uk Kim     }
761efcc2a30SJung-uk Kim     else
762efcc2a30SJung-uk Kim     {
763efcc2a30SJung-uk Kim         *Op = NULL;
764efcc2a30SJung-uk Kim     }
765efcc2a30SJung-uk Kim 
766efcc2a30SJung-uk Kim     return_ACPI_STATUS (AE_OK);
767efcc2a30SJung-uk Kim }
768efcc2a30SJung-uk Kim 
769efcc2a30SJung-uk Kim 
770efcc2a30SJung-uk Kim /*******************************************************************************
771efcc2a30SJung-uk Kim  *
772efcc2a30SJung-uk Kim  * FUNCTION:    AcpiPsCompleteFinalOp
773efcc2a30SJung-uk Kim  *
774efcc2a30SJung-uk Kim  * PARAMETERS:  WalkState           - Current state
775efcc2a30SJung-uk Kim  *              Op                  - Current Op
776efcc2a30SJung-uk Kim  *              Status              - Current parse status before complete last
777efcc2a30SJung-uk Kim  *                                    Op
778efcc2a30SJung-uk Kim  *
779efcc2a30SJung-uk Kim  * RETURN:      Status
780efcc2a30SJung-uk Kim  *
781efcc2a30SJung-uk Kim  * DESCRIPTION: Complete last Op.
782efcc2a30SJung-uk Kim  *
783efcc2a30SJung-uk Kim  ******************************************************************************/
784efcc2a30SJung-uk Kim 
785efcc2a30SJung-uk Kim ACPI_STATUS
786efcc2a30SJung-uk Kim AcpiPsCompleteFinalOp (
787efcc2a30SJung-uk Kim     ACPI_WALK_STATE         *WalkState,
788efcc2a30SJung-uk Kim     ACPI_PARSE_OBJECT       *Op,
789efcc2a30SJung-uk Kim     ACPI_STATUS             Status)
790efcc2a30SJung-uk Kim {
791efcc2a30SJung-uk Kim     ACPI_STATUS             Status2;
792efcc2a30SJung-uk Kim 
793efcc2a30SJung-uk Kim 
794efcc2a30SJung-uk Kim     ACPI_FUNCTION_TRACE_PTR (PsCompleteFinalOp, WalkState);
795efcc2a30SJung-uk Kim 
796efcc2a30SJung-uk Kim 
797efcc2a30SJung-uk Kim     /*
798efcc2a30SJung-uk Kim      * Complete the last Op (if not completed), and clear the scope stack.
799efcc2a30SJung-uk Kim      * It is easily possible to end an AML "package" with an unbounded number
800efcc2a30SJung-uk Kim      * of open scopes (such as when several ASL blocks are closed with
801efcc2a30SJung-uk Kim      * sequential closing braces). We want to terminate each one cleanly.
802efcc2a30SJung-uk Kim      */
803efcc2a30SJung-uk Kim     ACPI_DEBUG_PRINT ((ACPI_DB_PARSE, "AML package complete at Op %p\n", Op));
804efcc2a30SJung-uk Kim     do
805efcc2a30SJung-uk Kim     {
806efcc2a30SJung-uk Kim         if (Op)
807efcc2a30SJung-uk Kim         {
808efcc2a30SJung-uk Kim             if (WalkState->AscendingCallback != NULL)
809efcc2a30SJung-uk Kim             {
810efcc2a30SJung-uk Kim                 WalkState->Op = Op;
811efcc2a30SJung-uk Kim                 WalkState->OpInfo = AcpiPsGetOpcodeInfo (Op->Common.AmlOpcode);
812efcc2a30SJung-uk Kim                 WalkState->Opcode = Op->Common.AmlOpcode;
813efcc2a30SJung-uk Kim 
814efcc2a30SJung-uk Kim                 Status = WalkState->AscendingCallback (WalkState);
815efcc2a30SJung-uk Kim                 Status = AcpiPsNextParseState (WalkState, Op, Status);
816efcc2a30SJung-uk Kim                 if (Status == AE_CTRL_PENDING)
817efcc2a30SJung-uk Kim                 {
818efcc2a30SJung-uk Kim                     Status = AcpiPsCompleteOp (WalkState, &Op, AE_OK);
819efcc2a30SJung-uk Kim                     if (ACPI_FAILURE (Status))
820efcc2a30SJung-uk Kim                     {
821efcc2a30SJung-uk Kim                         return_ACPI_STATUS (Status);
822efcc2a30SJung-uk Kim                     }
823efcc2a30SJung-uk Kim                 }
824efcc2a30SJung-uk Kim 
825efcc2a30SJung-uk Kim                 if (Status == AE_CTRL_TERMINATE)
826efcc2a30SJung-uk Kim                 {
827efcc2a30SJung-uk Kim                     Status = AE_OK;
828efcc2a30SJung-uk Kim 
829efcc2a30SJung-uk Kim                     /* Clean up */
830efcc2a30SJung-uk Kim                     do
831efcc2a30SJung-uk Kim                     {
832efcc2a30SJung-uk Kim                         if (Op)
833efcc2a30SJung-uk Kim                         {
834efcc2a30SJung-uk Kim                             Status2 = AcpiPsCompleteThisOp (WalkState, Op);
835efcc2a30SJung-uk Kim                             if (ACPI_FAILURE (Status2))
836efcc2a30SJung-uk Kim                             {
837efcc2a30SJung-uk Kim                                 return_ACPI_STATUS (Status2);
838efcc2a30SJung-uk Kim                             }
839efcc2a30SJung-uk Kim                         }
840efcc2a30SJung-uk Kim 
841efcc2a30SJung-uk Kim                         AcpiPsPopScope (&(WalkState->ParserState), &Op,
842efcc2a30SJung-uk Kim                             &WalkState->ArgTypes, &WalkState->ArgCount);
843efcc2a30SJung-uk Kim 
844efcc2a30SJung-uk Kim                     } while (Op);
845efcc2a30SJung-uk Kim 
846efcc2a30SJung-uk Kim                     return_ACPI_STATUS (Status);
847efcc2a30SJung-uk Kim                 }
848efcc2a30SJung-uk Kim 
849efcc2a30SJung-uk Kim                 else if (ACPI_FAILURE (Status))
850efcc2a30SJung-uk Kim                 {
851efcc2a30SJung-uk Kim                     /* First error is most important */
852efcc2a30SJung-uk Kim 
853efcc2a30SJung-uk Kim                     (void) AcpiPsCompleteThisOp (WalkState, Op);
854efcc2a30SJung-uk Kim                     return_ACPI_STATUS (Status);
855efcc2a30SJung-uk Kim                 }
856efcc2a30SJung-uk Kim             }
857efcc2a30SJung-uk Kim 
858efcc2a30SJung-uk Kim             Status2 = AcpiPsCompleteThisOp (WalkState, Op);
859efcc2a30SJung-uk Kim             if (ACPI_FAILURE (Status2))
860efcc2a30SJung-uk Kim             {
861efcc2a30SJung-uk Kim                 return_ACPI_STATUS (Status2);
862efcc2a30SJung-uk Kim             }
863efcc2a30SJung-uk Kim         }
864efcc2a30SJung-uk Kim 
865efcc2a30SJung-uk Kim         AcpiPsPopScope (&(WalkState->ParserState), &Op, &WalkState->ArgTypes,
866efcc2a30SJung-uk Kim             &WalkState->ArgCount);
867efcc2a30SJung-uk Kim 
868efcc2a30SJung-uk Kim     } while (Op);
869efcc2a30SJung-uk Kim 
870efcc2a30SJung-uk Kim     return_ACPI_STATUS (Status);
871efcc2a30SJung-uk Kim }
872