195b482a8SLen Brown /****************************************************************************** 295b482a8SLen Brown * 395b482a8SLen Brown * Module Name: psloop - Main AML parse loop 495b482a8SLen Brown * 595b482a8SLen Brown *****************************************************************************/ 695b482a8SLen Brown 795b482a8SLen Brown /* 87735ca0eSBob Moore * Copyright (C) 2000 - 2017, Intel Corp. 995b482a8SLen Brown * All rights reserved. 1095b482a8SLen Brown * 1195b482a8SLen Brown * Redistribution and use in source and binary forms, with or without 1295b482a8SLen Brown * modification, are permitted provided that the following conditions 1395b482a8SLen Brown * are met: 1495b482a8SLen Brown * 1. Redistributions of source code must retain the above copyright 1595b482a8SLen Brown * notice, this list of conditions, and the following disclaimer, 1695b482a8SLen Brown * without modification. 1795b482a8SLen Brown * 2. Redistributions in binary form must reproduce at minimum a disclaimer 1895b482a8SLen Brown * substantially similar to the "NO WARRANTY" disclaimer below 1995b482a8SLen Brown * ("Disclaimer") and any redistribution must be conditioned upon 2095b482a8SLen Brown * including a substantially similar Disclaimer requirement for further 2195b482a8SLen Brown * binary redistribution. 2295b482a8SLen Brown * 3. Neither the names of the above-listed copyright holders nor the names 2395b482a8SLen Brown * of any contributors may be used to endorse or promote products derived 2495b482a8SLen Brown * from this software without specific prior written permission. 2595b482a8SLen Brown * 2695b482a8SLen Brown * Alternatively, this software may be distributed under the terms of the 2795b482a8SLen Brown * GNU General Public License ("GPL") version 2 as published by the Free 2895b482a8SLen Brown * Software Foundation. 2995b482a8SLen Brown * 3095b482a8SLen Brown * NO WARRANTY 3195b482a8SLen Brown * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 3295b482a8SLen Brown * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 3395b482a8SLen Brown * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR 3495b482a8SLen Brown * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 3595b482a8SLen Brown * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 3695b482a8SLen Brown * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 3795b482a8SLen Brown * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 3895b482a8SLen Brown * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 3995b482a8SLen Brown * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 4095b482a8SLen Brown * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 4195b482a8SLen Brown * POSSIBILITY OF SUCH DAMAGES. 4295b482a8SLen Brown */ 4395b482a8SLen Brown 4495b482a8SLen Brown /* 4595b482a8SLen Brown * Parse the AML and build an operation tree as most interpreters, (such as 4695b482a8SLen Brown * Perl) do. Parsing is done by hand rather than with a YACC generated parser 4795b482a8SLen Brown * to tightly constrain stack and dynamic memory usage. Parsing is kept 4895b482a8SLen Brown * flexible and the code fairly compact by parsing based on a list of AML 4995b482a8SLen Brown * opcode templates in aml_op_info[]. 5095b482a8SLen Brown */ 5195b482a8SLen Brown 5295b482a8SLen Brown #include <acpi/acpi.h> 53e2f7a777SLen Brown #include "accommon.h" 54ab6c5733SLv Zheng #include "acinterp.h" 55e2f7a777SLen Brown #include "acparser.h" 56e2f7a777SLen Brown #include "acdispat.h" 57e2f7a777SLen Brown #include "amlcode.h" 58*9cf7adecSBob Moore #include "acconvert.h" 5995b482a8SLen Brown 6095b482a8SLen Brown #define _COMPONENT ACPI_PARSER 6195b482a8SLen Brown ACPI_MODULE_NAME("psloop") 6295b482a8SLen Brown 6395b482a8SLen Brown /* Local prototypes */ 6495b482a8SLen Brown static acpi_status 6595b482a8SLen Brown acpi_ps_get_arguments(struct acpi_walk_state *walk_state, 6695b482a8SLen Brown u8 * aml_op_start, union acpi_parse_object *op); 6795b482a8SLen Brown 687f0c826aSLin Ming static void 699a884ab6SLin Ming acpi_ps_link_module_code(union acpi_parse_object *parent_op, 709a884ab6SLin Ming u8 *aml_start, u32 aml_length, acpi_owner_id owner_id); 717f0c826aSLin Ming 7295b482a8SLen Brown /******************************************************************************* 7395b482a8SLen Brown * 7495b482a8SLen Brown * FUNCTION: acpi_ps_get_arguments 7595b482a8SLen Brown * 7695b482a8SLen Brown * PARAMETERS: walk_state - Current state 7795b482a8SLen Brown * aml_op_start - Op start in AML 78ba494beeSBob Moore * op - Current Op 7995b482a8SLen Brown * 8095b482a8SLen Brown * RETURN: Status 8195b482a8SLen Brown * 8295b482a8SLen Brown * DESCRIPTION: Get arguments for passed Op. 8395b482a8SLen Brown * 8495b482a8SLen Brown ******************************************************************************/ 8595b482a8SLen Brown 8695b482a8SLen Brown static acpi_status 8795b482a8SLen Brown acpi_ps_get_arguments(struct acpi_walk_state *walk_state, 8895b482a8SLen Brown u8 * aml_op_start, union acpi_parse_object *op) 8995b482a8SLen Brown { 9095b482a8SLen Brown acpi_status status = AE_OK; 9195b482a8SLen Brown union acpi_parse_object *arg = NULL; 927f0c826aSLin Ming const struct acpi_opcode_info *op_info; 9395b482a8SLen Brown 9495b482a8SLen Brown ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state); 9595b482a8SLen Brown 96ce87e09dSBob Moore ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 97ce87e09dSBob Moore "Get arguments for opcode [%s]\n", 98ce87e09dSBob Moore op->common.aml_op_name)); 99ce87e09dSBob Moore 10095b482a8SLen Brown switch (op->common.aml_opcode) { 10195b482a8SLen Brown case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ 10295b482a8SLen Brown case AML_WORD_OP: /* AML_WORDDATA_ARG */ 10395b482a8SLen Brown case AML_DWORD_OP: /* AML_DWORDATA_ARG */ 10495b482a8SLen Brown case AML_QWORD_OP: /* AML_QWORDATA_ARG */ 10595b482a8SLen Brown case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ 10695b482a8SLen Brown 10795b482a8SLen Brown /* Fill in constant or string argument directly */ 10895b482a8SLen Brown 10995b482a8SLen Brown acpi_ps_get_next_simple_arg(&(walk_state->parser_state), 11095b482a8SLen Brown GET_CURRENT_ARG_TYPE(walk_state-> 11195b482a8SLen Brown arg_types), 11295b482a8SLen Brown op); 11395b482a8SLen Brown break; 11495b482a8SLen Brown 11595b482a8SLen Brown case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ 11695b482a8SLen Brown 11789438f96SBob Moore status = acpi_ps_get_next_namepath(walk_state, 11889438f96SBob Moore &(walk_state->parser_state), 11989438f96SBob Moore op, 12089438f96SBob Moore ACPI_POSSIBLE_METHOD_CALL); 12195b482a8SLen Brown if (ACPI_FAILURE(status)) { 12295b482a8SLen Brown return_ACPI_STATUS(status); 12395b482a8SLen Brown } 12495b482a8SLen Brown 12595b482a8SLen Brown walk_state->arg_types = 0; 12695b482a8SLen Brown break; 12795b482a8SLen Brown 12895b482a8SLen Brown default: 12995b482a8SLen Brown /* 13095b482a8SLen Brown * Op is not a constant or string, append each argument to the Op 13195b482a8SLen Brown */ 1321fad8738SBob Moore while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) && 1331fad8738SBob Moore !walk_state->arg_count) { 13483482f75SLv Zheng walk_state->aml = walk_state->parser_state.aml; 13595b482a8SLen Brown 136*9cf7adecSBob Moore switch (op->common.aml_opcode) { 137*9cf7adecSBob Moore case AML_METHOD_OP: 138*9cf7adecSBob Moore case AML_BUFFER_OP: 139*9cf7adecSBob Moore case AML_PACKAGE_OP: 140*9cf7adecSBob Moore case AML_VARIABLE_PACKAGE_OP: 141*9cf7adecSBob Moore case AML_WHILE_OP: 142*9cf7adecSBob Moore 143*9cf7adecSBob Moore break; 144*9cf7adecSBob Moore 145*9cf7adecSBob Moore default: 146*9cf7adecSBob Moore 147*9cf7adecSBob Moore ASL_CV_CAPTURE_COMMENTS(walk_state); 148*9cf7adecSBob Moore break; 149*9cf7adecSBob Moore } 150*9cf7adecSBob Moore 15195b482a8SLen Brown status = 15295b482a8SLen Brown acpi_ps_get_next_arg(walk_state, 15395b482a8SLen Brown &(walk_state->parser_state), 15495b482a8SLen Brown GET_CURRENT_ARG_TYPE 15595b482a8SLen Brown (walk_state->arg_types), &arg); 15695b482a8SLen Brown if (ACPI_FAILURE(status)) { 15795b482a8SLen Brown return_ACPI_STATUS(status); 15895b482a8SLen Brown } 15995b482a8SLen Brown 16095b482a8SLen Brown if (arg) { 16195b482a8SLen Brown acpi_ps_append_arg(op, arg); 16295b482a8SLen Brown } 16395b482a8SLen Brown 16495b482a8SLen Brown INCREMENT_ARG_LIST(walk_state->arg_types); 16595b482a8SLen Brown } 16695b482a8SLen Brown 1677f0c826aSLin Ming /* 1687f0c826aSLin Ming * Handle executable code at "module-level". This refers to 1697f0c826aSLin Ming * executable opcodes that appear outside of any control method. 1707f0c826aSLin Ming */ 1717f0c826aSLin Ming if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) && 17295b482a8SLen Brown ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) { 17395b482a8SLen Brown /* 17495b482a8SLen Brown * We want to skip If/Else/While constructs during Pass1 because we 17595b482a8SLen Brown * want to actually conditionally execute the code during Pass2. 17695b482a8SLen Brown * 17795b482a8SLen Brown * Except for disassembly, where we always want to walk the 17895b482a8SLen Brown * If/Else/While packages 17995b482a8SLen Brown */ 18095b482a8SLen Brown switch (op->common.aml_opcode) { 18195b482a8SLen Brown case AML_IF_OP: 18295b482a8SLen Brown case AML_ELSE_OP: 18395b482a8SLen Brown case AML_WHILE_OP: 1847f0c826aSLin Ming /* 1857f0c826aSLin Ming * Currently supported module-level opcodes are: 1867f0c826aSLin Ming * IF/ELSE/WHILE. These appear to be the most common, 1877f0c826aSLin Ming * and easiest to support since they open an AML 1887f0c826aSLin Ming * package. 1897f0c826aSLin Ming */ 1907f0c826aSLin Ming if (walk_state->pass_number == 1917f0c826aSLin Ming ACPI_IMODE_LOAD_PASS1) { 1929a884ab6SLin Ming acpi_ps_link_module_code(op->common. 1939a884ab6SLin Ming parent, 1949a884ab6SLin Ming aml_op_start, 1959a884ab6SLin Ming (u32) 1969a884ab6SLin Ming (walk_state-> 1977f0c826aSLin Ming parser_state. 1987f0c826aSLin Ming pkg_end - 1999a884ab6SLin Ming aml_op_start), 2007f0c826aSLin Ming walk_state-> 2017f0c826aSLin Ming owner_id); 2027f0c826aSLin Ming } 2037f0c826aSLin Ming 20495b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 20595b482a8SLen Brown "Pass1: Skipping an If/Else/While body\n")); 20695b482a8SLen Brown 20795b482a8SLen Brown /* Skip body of if/else/while in pass 1 */ 20895b482a8SLen Brown 20995b482a8SLen Brown walk_state->parser_state.aml = 21095b482a8SLen Brown walk_state->parser_state.pkg_end; 21195b482a8SLen Brown walk_state->arg_count = 0; 21295b482a8SLen Brown break; 21395b482a8SLen Brown 21495b482a8SLen Brown default: 2157f0c826aSLin Ming /* 2167f0c826aSLin Ming * Check for an unsupported executable opcode at module 2177f0c826aSLin Ming * level. We must be in PASS1, the parent must be a SCOPE, 2187f0c826aSLin Ming * The opcode class must be EXECUTE, and the opcode must 2197f0c826aSLin Ming * not be an argument to another opcode. 2207f0c826aSLin Ming */ 2217f0c826aSLin Ming if ((walk_state->pass_number == 2227f0c826aSLin Ming ACPI_IMODE_LOAD_PASS1) 2237f0c826aSLin Ming && (op->common.parent->common.aml_opcode == 2247f0c826aSLin Ming AML_SCOPE_OP)) { 2257f0c826aSLin Ming op_info = 2267f0c826aSLin Ming acpi_ps_get_opcode_info(op->common. 2277f0c826aSLin Ming aml_opcode); 2287f0c826aSLin Ming if ((op_info->class == 2297f0c826aSLin Ming AML_CLASS_EXECUTE) && (!arg)) { 2307f0c826aSLin Ming ACPI_WARNING((AE_INFO, 23100eb3255SBob Moore "Unsupported module-level executable opcode " 23200eb3255SBob Moore "0x%.2X at table offset 0x%.4X", 23300eb3255SBob Moore op->common. 23400eb3255SBob Moore aml_opcode, 23500eb3255SBob Moore (u32) 23600eb3255SBob Moore (ACPI_PTR_DIFF 23700eb3255SBob Moore (aml_op_start, 23800eb3255SBob Moore walk_state-> 23900eb3255SBob Moore parser_state. 24000eb3255SBob Moore aml_start) + 24100eb3255SBob Moore sizeof(struct 24200eb3255SBob Moore acpi_table_header)))); 2437f0c826aSLin Ming } 2447f0c826aSLin Ming } 24595b482a8SLen Brown break; 24695b482a8SLen Brown } 24795b482a8SLen Brown } 2487f0c826aSLin Ming 2497f0c826aSLin Ming /* Special processing for certain opcodes */ 25095b482a8SLen Brown 25195b482a8SLen Brown switch (op->common.aml_opcode) { 25295b482a8SLen Brown case AML_METHOD_OP: 25395b482a8SLen Brown /* 25495b482a8SLen Brown * Skip parsing of control method because we don't have enough 25595b482a8SLen Brown * info in the first pass to parse it correctly. 25695b482a8SLen Brown * 25795b482a8SLen Brown * Save the length and address of the body 25895b482a8SLen Brown */ 25995b482a8SLen Brown op->named.data = walk_state->parser_state.aml; 26095b482a8SLen Brown op->named.length = (u32) 26195b482a8SLen Brown (walk_state->parser_state.pkg_end - 26295b482a8SLen Brown walk_state->parser_state.aml); 26395b482a8SLen Brown 26495b482a8SLen Brown /* Skip body of method */ 26595b482a8SLen Brown 26695b482a8SLen Brown walk_state->parser_state.aml = 26795b482a8SLen Brown walk_state->parser_state.pkg_end; 26895b482a8SLen Brown walk_state->arg_count = 0; 26995b482a8SLen Brown break; 27095b482a8SLen Brown 27195b482a8SLen Brown case AML_BUFFER_OP: 27295b482a8SLen Brown case AML_PACKAGE_OP: 2739ff5a21aSBob Moore case AML_VARIABLE_PACKAGE_OP: 27495b482a8SLen Brown 27595b482a8SLen Brown if ((op->common.parent) && 27695b482a8SLen Brown (op->common.parent->common.aml_opcode == 27795b482a8SLen Brown AML_NAME_OP) 27895b482a8SLen Brown && (walk_state->pass_number <= 27995b482a8SLen Brown ACPI_IMODE_LOAD_PASS2)) { 28095b482a8SLen Brown /* 28195b482a8SLen Brown * Skip parsing of Buffers and Packages because we don't have 28295b482a8SLen Brown * enough info in the first pass to parse them correctly. 28395b482a8SLen Brown */ 28495b482a8SLen Brown op->named.data = aml_op_start; 28595b482a8SLen Brown op->named.length = (u32) 28695b482a8SLen Brown (walk_state->parser_state.pkg_end - 28795b482a8SLen Brown aml_op_start); 28895b482a8SLen Brown 28995b482a8SLen Brown /* Skip body */ 29095b482a8SLen Brown 29195b482a8SLen Brown walk_state->parser_state.aml = 29295b482a8SLen Brown walk_state->parser_state.pkg_end; 29395b482a8SLen Brown walk_state->arg_count = 0; 29495b482a8SLen Brown } 29595b482a8SLen Brown break; 29695b482a8SLen Brown 29795b482a8SLen Brown case AML_WHILE_OP: 29895b482a8SLen Brown 29995b482a8SLen Brown if (walk_state->control_state) { 30095b482a8SLen Brown walk_state->control_state->control.package_end = 30195b482a8SLen Brown walk_state->parser_state.pkg_end; 30295b482a8SLen Brown } 30395b482a8SLen Brown break; 30495b482a8SLen Brown 30595b482a8SLen Brown default: 30695b482a8SLen Brown 30795b482a8SLen Brown /* No action for all other opcodes */ 3081d1ea1b7SChao Guan 30995b482a8SLen Brown break; 31095b482a8SLen Brown } 31195b482a8SLen Brown 31295b482a8SLen Brown break; 31395b482a8SLen Brown } 31495b482a8SLen Brown 31595b482a8SLen Brown return_ACPI_STATUS(AE_OK); 31695b482a8SLen Brown } 31795b482a8SLen Brown 31895b482a8SLen Brown /******************************************************************************* 31995b482a8SLen Brown * 3207f0c826aSLin Ming * FUNCTION: acpi_ps_link_module_code 3217f0c826aSLin Ming * 3229a884ab6SLin Ming * PARAMETERS: parent_op - Parent parser op 3239a884ab6SLin Ming * aml_start - Pointer to the AML 3247f0c826aSLin Ming * aml_length - Length of executable AML 3257f0c826aSLin Ming * owner_id - owner_id of module level code 3267f0c826aSLin Ming * 3277f0c826aSLin Ming * RETURN: None. 3287f0c826aSLin Ming * 3297f0c826aSLin Ming * DESCRIPTION: Wrap the module-level code with a method object and link the 3307f0c826aSLin Ming * object to the global list. Note, the mutex field of the method 3317f0c826aSLin Ming * object is used to link multiple module-level code objects. 3327f0c826aSLin Ming * 3337f0c826aSLin Ming ******************************************************************************/ 3347f0c826aSLin Ming 3357f0c826aSLin Ming static void 3369a884ab6SLin Ming acpi_ps_link_module_code(union acpi_parse_object *parent_op, 3379a884ab6SLin Ming u8 *aml_start, u32 aml_length, acpi_owner_id owner_id) 3387f0c826aSLin Ming { 3397f0c826aSLin Ming union acpi_operand_object *prev; 3407f0c826aSLin Ming union acpi_operand_object *next; 3417f0c826aSLin Ming union acpi_operand_object *method_obj; 3429a884ab6SLin Ming struct acpi_namespace_node *parent_node; 3437f0c826aSLin Ming 34425823e78SBob Moore ACPI_FUNCTION_TRACE(ps_link_module_code); 34525823e78SBob Moore 3467f0c826aSLin Ming /* Get the tail of the list */ 3477f0c826aSLin Ming 3487f0c826aSLin Ming prev = next = acpi_gbl_module_code_list; 3497f0c826aSLin Ming while (next) { 3507f0c826aSLin Ming prev = next; 3517f0c826aSLin Ming next = next->method.mutex; 3527f0c826aSLin Ming } 3537f0c826aSLin Ming 3547f0c826aSLin Ming /* 3557f0c826aSLin Ming * Insert the module level code into the list. Merge it if it is 3567f0c826aSLin Ming * adjacent to the previous element. 3577f0c826aSLin Ming */ 3587f0c826aSLin Ming if (!prev || 3597f0c826aSLin Ming ((prev->method.aml_start + prev->method.aml_length) != aml_start)) { 3607f0c826aSLin Ming 3617f0c826aSLin Ming /* Create, initialize, and link a new temporary method object */ 3627f0c826aSLin Ming 3637f0c826aSLin Ming method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); 3647f0c826aSLin Ming if (!method_obj) { 36525823e78SBob Moore return_VOID; 3667f0c826aSLin Ming } 3677f0c826aSLin Ming 36825823e78SBob Moore ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 36925823e78SBob Moore "Create/Link new code block: %p\n", 37025823e78SBob Moore method_obj)); 37125823e78SBob Moore 3729a884ab6SLin Ming if (parent_op->common.node) { 3739a884ab6SLin Ming parent_node = parent_op->common.node; 3749a884ab6SLin Ming } else { 3759a884ab6SLin Ming parent_node = acpi_gbl_root_node; 3769a884ab6SLin Ming } 3779a884ab6SLin Ming 3787f0c826aSLin Ming method_obj->method.aml_start = aml_start; 3797f0c826aSLin Ming method_obj->method.aml_length = aml_length; 3807f0c826aSLin Ming method_obj->method.owner_id = owner_id; 38126294842SLin Ming method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL; 3827f0c826aSLin Ming 3839a884ab6SLin Ming /* 3849a884ab6SLin Ming * Save the parent node in next_object. This is cheating, but we 3859a884ab6SLin Ming * don't want to expand the method object. 3869a884ab6SLin Ming */ 3879a884ab6SLin Ming method_obj->method.next_object = 3889a884ab6SLin Ming ACPI_CAST_PTR(union acpi_operand_object, parent_node); 3899a884ab6SLin Ming 3907f0c826aSLin Ming if (!prev) { 3917f0c826aSLin Ming acpi_gbl_module_code_list = method_obj; 3927f0c826aSLin Ming } else { 3937f0c826aSLin Ming prev->method.mutex = method_obj; 3947f0c826aSLin Ming } 3957f0c826aSLin Ming } else { 39625823e78SBob Moore ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 39725823e78SBob Moore "Appending to existing code block: %p\n", 39825823e78SBob Moore prev)); 39925823e78SBob Moore 4007f0c826aSLin Ming prev->method.aml_length += aml_length; 4017f0c826aSLin Ming } 40225823e78SBob Moore 40325823e78SBob Moore return_VOID; 4047f0c826aSLin Ming } 4057f0c826aSLin Ming 4067f0c826aSLin Ming /******************************************************************************* 4077f0c826aSLin Ming * 40895b482a8SLen Brown * FUNCTION: acpi_ps_parse_loop 40995b482a8SLen Brown * 41095b482a8SLen Brown * PARAMETERS: walk_state - Current state 41195b482a8SLen Brown * 41295b482a8SLen Brown * RETURN: Status 41395b482a8SLen Brown * 41495b482a8SLen Brown * DESCRIPTION: Parse AML (pointed to by the current parser state) and return 41595b482a8SLen Brown * a tree of ops. 41695b482a8SLen Brown * 41795b482a8SLen Brown ******************************************************************************/ 41895b482a8SLen Brown 41995b482a8SLen Brown acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) 42095b482a8SLen Brown { 42195b482a8SLen Brown acpi_status status = AE_OK; 42295b482a8SLen Brown union acpi_parse_object *op = NULL; /* current op */ 42395b482a8SLen Brown struct acpi_parse_state *parser_state; 42495b482a8SLen Brown u8 *aml_op_start = NULL; 42595b482a8SLen Brown 42695b482a8SLen Brown ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state); 42795b482a8SLen Brown 42895b482a8SLen Brown if (walk_state->descending_callback == NULL) { 42995b482a8SLen Brown return_ACPI_STATUS(AE_BAD_PARAMETER); 43095b482a8SLen Brown } 43195b482a8SLen Brown 43295b482a8SLen Brown parser_state = &walk_state->parser_state; 43395b482a8SLen Brown walk_state->arg_types = 0; 43495b482a8SLen Brown 43595b482a8SLen Brown #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) 43695b482a8SLen Brown 43795b482a8SLen Brown if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { 43895b482a8SLen Brown 43995b482a8SLen Brown /* We are restarting a preempted control method */ 44095b482a8SLen Brown 44195b482a8SLen Brown if (acpi_ps_has_completed_scope(parser_state)) { 44295b482a8SLen Brown /* 44395b482a8SLen Brown * We must check if a predicate to an IF or WHILE statement 44495b482a8SLen Brown * was just completed 44595b482a8SLen Brown */ 44695b482a8SLen Brown if ((parser_state->scope->parse_scope.op) && 44795b482a8SLen Brown ((parser_state->scope->parse_scope.op->common. 44895b482a8SLen Brown aml_opcode == AML_IF_OP) 44995b482a8SLen Brown || (parser_state->scope->parse_scope.op->common. 45095b482a8SLen Brown aml_opcode == AML_WHILE_OP)) 45195b482a8SLen Brown && (walk_state->control_state) 45295b482a8SLen Brown && (walk_state->control_state->common.state == 45395b482a8SLen Brown ACPI_CONTROL_PREDICATE_EXECUTING)) { 45495b482a8SLen Brown /* 45595b482a8SLen Brown * A predicate was just completed, get the value of the 45695b482a8SLen Brown * predicate and branch based on that value 45795b482a8SLen Brown */ 45895b482a8SLen Brown walk_state->op = NULL; 45995b482a8SLen Brown status = 46095b482a8SLen Brown acpi_ds_get_predicate_value(walk_state, 46195b482a8SLen Brown ACPI_TO_POINTER 46295b482a8SLen Brown (TRUE)); 46395b482a8SLen Brown if (ACPI_FAILURE(status) 46495b482a8SLen Brown && ((status & AE_CODE_MASK) != 46595b482a8SLen Brown AE_CODE_CONTROL)) { 46695b482a8SLen Brown if (status == AE_AML_NO_RETURN_VALUE) { 46795b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, 46895b482a8SLen Brown "Invoked method did not return a value")); 46995b482a8SLen Brown } 47095b482a8SLen Brown 47195b482a8SLen Brown ACPI_EXCEPTION((AE_INFO, status, 47295b482a8SLen Brown "GetPredicate Failed")); 47395b482a8SLen Brown return_ACPI_STATUS(status); 47495b482a8SLen Brown } 47595b482a8SLen Brown 47695b482a8SLen Brown status = 47795b482a8SLen Brown acpi_ps_next_parse_state(walk_state, op, 47895b482a8SLen Brown status); 47995b482a8SLen Brown } 48095b482a8SLen Brown 48195b482a8SLen Brown acpi_ps_pop_scope(parser_state, &op, 48295b482a8SLen Brown &walk_state->arg_types, 48395b482a8SLen Brown &walk_state->arg_count); 48495b482a8SLen Brown ACPI_DEBUG_PRINT((ACPI_DB_PARSE, 48595b482a8SLen Brown "Popped scope, Op=%p\n", op)); 48695b482a8SLen Brown } else if (walk_state->prev_op) { 48795b482a8SLen Brown 48895b482a8SLen Brown /* We were in the middle of an op */ 48995b482a8SLen Brown 49095b482a8SLen Brown op = walk_state->prev_op; 49195b482a8SLen Brown walk_state->arg_types = walk_state->prev_arg_types; 49295b482a8SLen Brown } 49395b482a8SLen Brown } 49495b482a8SLen Brown #endif 49595b482a8SLen Brown 49695b482a8SLen Brown /* Iterative parsing loop, while there is more AML to process: */ 49795b482a8SLen Brown 49895b482a8SLen Brown while ((parser_state->aml < parser_state->aml_end) || (op)) { 499*9cf7adecSBob Moore ASL_CV_CAPTURE_COMMENTS(walk_state); 500*9cf7adecSBob Moore 50195b482a8SLen Brown aml_op_start = parser_state->aml; 50295b482a8SLen Brown if (!op) { 50395b482a8SLen Brown status = 50495b482a8SLen Brown acpi_ps_create_op(walk_state, aml_op_start, &op); 50595b482a8SLen Brown if (ACPI_FAILURE(status)) { 50695b482a8SLen Brown if (status == AE_CTRL_PARSE_CONTINUE) { 50795b482a8SLen Brown continue; 50895b482a8SLen Brown } 50995b482a8SLen Brown 51095b482a8SLen Brown if (status == AE_CTRL_PARSE_PENDING) { 51195b482a8SLen Brown status = AE_OK; 51295b482a8SLen Brown } 51395b482a8SLen Brown 51422b5afceSBob Moore if (status == AE_CTRL_TERMINATE) { 51522b5afceSBob Moore return_ACPI_STATUS(status); 51622b5afceSBob Moore } 51722b5afceSBob Moore 51895b482a8SLen Brown status = 51995b482a8SLen Brown acpi_ps_complete_op(walk_state, &op, 52095b482a8SLen Brown status); 52195b482a8SLen Brown if (ACPI_FAILURE(status)) { 52295b482a8SLen Brown return_ACPI_STATUS(status); 52395b482a8SLen Brown } 52495b482a8SLen Brown 52595b482a8SLen Brown continue; 52695b482a8SLen Brown } 52795b482a8SLen Brown 528ab6c5733SLv Zheng acpi_ex_start_trace_opcode(op, walk_state); 52995b482a8SLen Brown } 53095b482a8SLen Brown 53195b482a8SLen Brown /* 53295b482a8SLen Brown * Start arg_count at zero because we don't know if there are 53395b482a8SLen Brown * any args yet 53495b482a8SLen Brown */ 53595b482a8SLen Brown walk_state->arg_count = 0; 53695b482a8SLen Brown 537*9cf7adecSBob Moore switch (op->common.aml_opcode) { 538*9cf7adecSBob Moore case AML_BYTE_OP: 539*9cf7adecSBob Moore case AML_WORD_OP: 540*9cf7adecSBob Moore case AML_DWORD_OP: 541*9cf7adecSBob Moore case AML_QWORD_OP: 542*9cf7adecSBob Moore 543*9cf7adecSBob Moore break; 544*9cf7adecSBob Moore 545*9cf7adecSBob Moore default: 546*9cf7adecSBob Moore 547*9cf7adecSBob Moore ASL_CV_CAPTURE_COMMENTS(walk_state); 548*9cf7adecSBob Moore break; 549*9cf7adecSBob Moore } 550*9cf7adecSBob Moore 55195b482a8SLen Brown /* Are there any arguments that must be processed? */ 55295b482a8SLen Brown 55395b482a8SLen Brown if (walk_state->arg_types) { 55495b482a8SLen Brown 55595b482a8SLen Brown /* Get arguments */ 55695b482a8SLen Brown 55795b482a8SLen Brown status = 55895b482a8SLen Brown acpi_ps_get_arguments(walk_state, aml_op_start, op); 55995b482a8SLen Brown if (ACPI_FAILURE(status)) { 56095b482a8SLen Brown status = 56195b482a8SLen Brown acpi_ps_complete_op(walk_state, &op, 56295b482a8SLen Brown status); 56395b482a8SLen Brown if (ACPI_FAILURE(status)) { 56495b482a8SLen Brown return_ACPI_STATUS(status); 56595b482a8SLen Brown } 56695b482a8SLen Brown 56795b482a8SLen Brown continue; 56895b482a8SLen Brown } 56995b482a8SLen Brown } 57095b482a8SLen Brown 57195b482a8SLen Brown /* Check for arguments that need to be processed */ 57295b482a8SLen Brown 57395b482a8SLen Brown if (walk_state->arg_count) { 57495b482a8SLen Brown /* 57595b482a8SLen Brown * There are arguments (complex ones), push Op and 57695b482a8SLen Brown * prepare for argument 57795b482a8SLen Brown */ 57895b482a8SLen Brown status = acpi_ps_push_scope(parser_state, op, 57995b482a8SLen Brown walk_state->arg_types, 58095b482a8SLen Brown walk_state->arg_count); 58195b482a8SLen Brown if (ACPI_FAILURE(status)) { 58295b482a8SLen Brown status = 58395b482a8SLen Brown acpi_ps_complete_op(walk_state, &op, 58495b482a8SLen Brown status); 58595b482a8SLen Brown if (ACPI_FAILURE(status)) { 58695b482a8SLen Brown return_ACPI_STATUS(status); 58795b482a8SLen Brown } 58895b482a8SLen Brown 58995b482a8SLen Brown continue; 59095b482a8SLen Brown } 59195b482a8SLen Brown 59295b482a8SLen Brown op = NULL; 59395b482a8SLen Brown continue; 59495b482a8SLen Brown } 59595b482a8SLen Brown 59695b482a8SLen Brown /* 59795b482a8SLen Brown * All arguments have been processed -- Op is complete, 59895b482a8SLen Brown * prepare for next 59995b482a8SLen Brown */ 60095b482a8SLen Brown walk_state->op_info = 60195b482a8SLen Brown acpi_ps_get_opcode_info(op->common.aml_opcode); 60295b482a8SLen Brown if (walk_state->op_info->flags & AML_NAMED) { 60395b482a8SLen Brown if (op->common.aml_opcode == AML_REGION_OP || 60495b482a8SLen Brown op->common.aml_opcode == AML_DATA_REGION_OP) { 60595b482a8SLen Brown /* 60695b482a8SLen Brown * Skip parsing of control method or opregion body, 60795b482a8SLen Brown * because we don't have enough info in the first pass 60895b482a8SLen Brown * to parse them correctly. 60995b482a8SLen Brown * 61095b482a8SLen Brown * Completed parsing an op_region declaration, we now 61195b482a8SLen Brown * know the length. 61295b482a8SLen Brown */ 61395b482a8SLen Brown op->named.length = 61495b482a8SLen Brown (u32) (parser_state->aml - op->named.data); 61595b482a8SLen Brown } 61695b482a8SLen Brown } 61795b482a8SLen Brown 61895b482a8SLen Brown if (walk_state->op_info->flags & AML_CREATE) { 61995b482a8SLen Brown /* 620ba494beeSBob Moore * Backup to beginning of create_XXXfield declaration (1 for 62195b482a8SLen Brown * Opcode) 62295b482a8SLen Brown * 62395b482a8SLen Brown * body_length is unknown until we parse the body 62495b482a8SLen Brown */ 62595b482a8SLen Brown op->named.length = 62695b482a8SLen Brown (u32) (parser_state->aml - op->named.data); 62795b482a8SLen Brown } 62895b482a8SLen Brown 62995b482a8SLen Brown if (op->common.aml_opcode == AML_BANK_FIELD_OP) { 63095b482a8SLen Brown /* 63195b482a8SLen Brown * Backup to beginning of bank_field declaration 63295b482a8SLen Brown * 63395b482a8SLen Brown * body_length is unknown until we parse the body 63495b482a8SLen Brown */ 63595b482a8SLen Brown op->named.length = 63695b482a8SLen Brown (u32) (parser_state->aml - op->named.data); 63795b482a8SLen Brown } 63895b482a8SLen Brown 63995b482a8SLen Brown /* This op complete, notify the dispatcher */ 64095b482a8SLen Brown 64195b482a8SLen Brown if (walk_state->ascending_callback != NULL) { 64295b482a8SLen Brown walk_state->op = op; 64395b482a8SLen Brown walk_state->opcode = op->common.aml_opcode; 64495b482a8SLen Brown 64595b482a8SLen Brown status = walk_state->ascending_callback(walk_state); 64695b482a8SLen Brown status = 64795b482a8SLen Brown acpi_ps_next_parse_state(walk_state, op, status); 64895b482a8SLen Brown if (status == AE_CTRL_PENDING) { 64995b482a8SLen Brown status = AE_OK; 65095b482a8SLen Brown } 65195b482a8SLen Brown } 65295b482a8SLen Brown 65395b482a8SLen Brown status = acpi_ps_complete_op(walk_state, &op, status); 65495b482a8SLen Brown if (ACPI_FAILURE(status)) { 65595b482a8SLen Brown return_ACPI_STATUS(status); 65695b482a8SLen Brown } 65795b482a8SLen Brown 65895b482a8SLen Brown } /* while parser_state->Aml */ 65995b482a8SLen Brown 66095b482a8SLen Brown status = acpi_ps_complete_final_op(walk_state, op, status); 66195b482a8SLen Brown return_ACPI_STATUS(status); 66295b482a8SLen Brown } 663