| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1 | /****************************************************************************** | 
 | 2 |  * | 
 | 3 |  * Module Name: psloop - Main AML parse loop | 
 | 4 |  * | 
 | 5 |  *****************************************************************************/ | 
 | 6 |  | 
 | 7 | /* | 
| Bob Moore | 7784813 | 2012-01-12 13:27:23 +0800 | [diff] [blame] | 8 |  * Copyright (C) 2000 - 2012, Intel Corp. | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 9 |  * All rights reserved. | 
 | 10 |  * | 
 | 11 |  * Redistribution and use in source and binary forms, with or without | 
 | 12 |  * modification, are permitted provided that the following conditions | 
 | 13 |  * are met: | 
 | 14 |  * 1. Redistributions of source code must retain the above copyright | 
 | 15 |  *    notice, this list of conditions, and the following disclaimer, | 
 | 16 |  *    without modification. | 
 | 17 |  * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
 | 18 |  *    substantially similar to the "NO WARRANTY" disclaimer below | 
 | 19 |  *    ("Disclaimer") and any redistribution must be conditioned upon | 
 | 20 |  *    including a substantially similar Disclaimer requirement for further | 
 | 21 |  *    binary redistribution. | 
 | 22 |  * 3. Neither the names of the above-listed copyright holders nor the names | 
 | 23 |  *    of any contributors may be used to endorse or promote products derived | 
 | 24 |  *    from this software without specific prior written permission. | 
 | 25 |  * | 
 | 26 |  * Alternatively, this software may be distributed under the terms of the | 
 | 27 |  * GNU General Public License ("GPL") version 2 as published by the Free | 
 | 28 |  * Software Foundation. | 
 | 29 |  * | 
 | 30 |  * NO WARRANTY | 
 | 31 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 32 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 33 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
 | 34 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 35 |  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
 | 36 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
 | 37 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
 | 38 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
 | 39 |  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
 | 40 |  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
 | 41 |  * POSSIBILITY OF SUCH DAMAGES. | 
 | 42 |  */ | 
 | 43 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 44 | /* | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 45 |  * Parse the AML and build an operation tree as most interpreters, (such as | 
 | 46 |  * Perl) do. Parsing is done by hand rather than with a YACC generated parser | 
 | 47 |  * to tightly constrain stack and dynamic memory usage. Parsing is kept | 
 | 48 |  * flexible and the code fairly compact by parsing based on a list of AML | 
 | 49 |  * opcode templates in aml_op_info[]. | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 50 |  */ | 
 | 51 |  | 
 | 52 | #include <acpi/acpi.h> | 
| Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 53 | #include "accommon.h" | 
 | 54 | #include "acparser.h" | 
 | 55 | #include "acdispat.h" | 
 | 56 | #include "amlcode.h" | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 57 |  | 
 | 58 | #define _COMPONENT          ACPI_PARSER | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 59 | ACPI_MODULE_NAME("psloop") | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 60 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 61 | static u32 acpi_gbl_depth = 0; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 62 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 63 | /* Local prototypes */ | 
 | 64 |  | 
 | 65 | static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state); | 
 | 66 |  | 
 | 67 | static acpi_status | 
 | 68 | acpi_ps_build_named_op(struct acpi_walk_state *walk_state, | 
 | 69 | 		       u8 * aml_op_start, | 
 | 70 | 		       union acpi_parse_object *unnamed_op, | 
 | 71 | 		       union acpi_parse_object **op); | 
 | 72 |  | 
 | 73 | static acpi_status | 
 | 74 | acpi_ps_create_op(struct acpi_walk_state *walk_state, | 
 | 75 | 		  u8 * aml_op_start, union acpi_parse_object **new_op); | 
 | 76 |  | 
 | 77 | static acpi_status | 
 | 78 | acpi_ps_get_arguments(struct acpi_walk_state *walk_state, | 
 | 79 | 		      u8 * aml_op_start, union acpi_parse_object *op); | 
 | 80 |  | 
 | 81 | static acpi_status | 
 | 82 | acpi_ps_complete_op(struct acpi_walk_state *walk_state, | 
 | 83 | 		    union acpi_parse_object **op, acpi_status status); | 
 | 84 |  | 
 | 85 | static acpi_status | 
 | 86 | acpi_ps_complete_final_op(struct acpi_walk_state *walk_state, | 
 | 87 | 			  union acpi_parse_object *op, acpi_status status); | 
 | 88 |  | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 89 | static void | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 90 | acpi_ps_link_module_code(union acpi_parse_object *parent_op, | 
 | 91 | 			 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id); | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 92 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 93 | /******************************************************************************* | 
 | 94 |  * | 
 | 95 |  * FUNCTION:    acpi_ps_get_aml_opcode | 
 | 96 |  * | 
 | 97 |  * PARAMETERS:  walk_state          - Current state | 
 | 98 |  * | 
 | 99 |  * RETURN:      Status | 
 | 100 |  * | 
 | 101 |  * DESCRIPTION: Extract the next AML opcode from the input stream. | 
 | 102 |  * | 
 | 103 |  ******************************************************************************/ | 
 | 104 |  | 
 | 105 | static acpi_status acpi_ps_get_aml_opcode(struct acpi_walk_state *walk_state) | 
 | 106 | { | 
 | 107 |  | 
 | 108 | 	ACPI_FUNCTION_TRACE_PTR(ps_get_aml_opcode, walk_state); | 
 | 109 |  | 
 | 110 | 	walk_state->aml_offset = | 
 | 111 | 	    (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml, | 
 | 112 | 				walk_state->parser_state.aml_start); | 
 | 113 | 	walk_state->opcode = acpi_ps_peek_opcode(&(walk_state->parser_state)); | 
 | 114 |  | 
 | 115 | 	/* | 
 | 116 | 	 * First cut to determine what we have found: | 
 | 117 | 	 * 1) A valid AML opcode | 
 | 118 | 	 * 2) A name string | 
 | 119 | 	 * 3) An unknown/invalid opcode | 
 | 120 | 	 */ | 
 | 121 | 	walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); | 
 | 122 |  | 
 | 123 | 	switch (walk_state->op_info->class) { | 
 | 124 | 	case AML_CLASS_ASCII: | 
 | 125 | 	case AML_CLASS_PREFIX: | 
 | 126 | 		/* | 
 | 127 | 		 * Starts with a valid prefix or ASCII char, this is a name | 
 | 128 | 		 * string. Convert the bare name string to a namepath. | 
 | 129 | 		 */ | 
 | 130 | 		walk_state->opcode = AML_INT_NAMEPATH_OP; | 
 | 131 | 		walk_state->arg_types = ARGP_NAMESTRING; | 
 | 132 | 		break; | 
 | 133 |  | 
 | 134 | 	case AML_CLASS_UNKNOWN: | 
 | 135 |  | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 136 | 		/* The opcode is unrecognized. Complain and skip unknown opcodes */ | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 137 |  | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 138 | 		if (walk_state->pass_number == 2) { | 
 | 139 | 			ACPI_ERROR((AE_INFO, | 
 | 140 | 				    "Unknown opcode 0x%.2X at table offset 0x%.4X, ignoring", | 
 | 141 | 				    walk_state->opcode, | 
| Bob Moore | 17b1f45 | 2012-10-31 02:28:27 +0000 | [diff] [blame] | 142 | 				    (u32)(walk_state->aml_offset + | 
 | 143 | 					  sizeof(struct acpi_table_header)))); | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 144 |  | 
| Bob Moore | c8d586f | 2012-12-31 00:05:39 +0000 | [diff] [blame^] | 145 | 			ACPI_DUMP_BUFFER((walk_state->parser_state.aml - 16), | 
 | 146 | 					 48); | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 147 |  | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 148 | #ifdef ACPI_ASL_COMPILER | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 149 | 			/* | 
 | 150 | 			 * This is executed for the disassembler only. Output goes | 
 | 151 | 			 * to the disassembled ASL output file. | 
 | 152 | 			 */ | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 153 | 			acpi_os_printf | 
 | 154 | 			    ("/*\nError: Unknown opcode 0x%.2X at table offset 0x%.4X, context:\n", | 
 | 155 | 			     walk_state->opcode, | 
| Bob Moore | 17b1f45 | 2012-10-31 02:28:27 +0000 | [diff] [blame] | 156 | 			     (u32)(walk_state->aml_offset + | 
 | 157 | 				   sizeof(struct acpi_table_header))); | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 158 |  | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 159 | 			/* Dump the context surrounding the invalid opcode */ | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 160 |  | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 161 | 			acpi_ut_dump_buffer(((u8 *)walk_state->parser_state. | 
 | 162 | 					     aml - 16), 48, DB_BYTE_DISPLAY, | 
| Bob Moore | c8d586f | 2012-12-31 00:05:39 +0000 | [diff] [blame^] | 163 | 					    (walk_state->aml_offset + | 
 | 164 | 					     sizeof(struct acpi_table_header) - | 
 | 165 | 					     16)); | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 166 | 			acpi_os_printf(" */\n"); | 
 | 167 | #endif | 
 | 168 | 		} | 
 | 169 |  | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 170 | 		/* Increment past one-byte or two-byte opcode */ | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 171 |  | 
 | 172 | 		walk_state->parser_state.aml++; | 
| Bob Moore | 97171c6 | 2012-10-31 02:28:11 +0000 | [diff] [blame] | 173 | 		if (walk_state->opcode > 0xFF) {	/* Can only happen if first byte is 0x5B */ | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 174 | 			walk_state->parser_state.aml++; | 
 | 175 | 		} | 
 | 176 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 177 | 		return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); | 
 | 178 |  | 
 | 179 | 	default: | 
 | 180 |  | 
 | 181 | 		/* Found opcode info, this is a normal opcode */ | 
 | 182 |  | 
 | 183 | 		walk_state->parser_state.aml += | 
 | 184 | 		    acpi_ps_get_opcode_size(walk_state->opcode); | 
 | 185 | 		walk_state->arg_types = walk_state->op_info->parse_args; | 
 | 186 | 		break; | 
 | 187 | 	} | 
 | 188 |  | 
 | 189 | 	return_ACPI_STATUS(AE_OK); | 
 | 190 | } | 
 | 191 |  | 
 | 192 | /******************************************************************************* | 
 | 193 |  * | 
 | 194 |  * FUNCTION:    acpi_ps_build_named_op | 
 | 195 |  * | 
 | 196 |  * PARAMETERS:  walk_state          - Current state | 
 | 197 |  *              aml_op_start        - Begin of named Op in AML | 
 | 198 |  *              unnamed_op          - Early Op (not a named Op) | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 199 |  *              op                  - Returned Op | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 200 |  * | 
 | 201 |  * RETURN:      Status | 
 | 202 |  * | 
 | 203 |  * DESCRIPTION: Parse a named Op | 
 | 204 |  * | 
 | 205 |  ******************************************************************************/ | 
 | 206 |  | 
 | 207 | static acpi_status | 
 | 208 | acpi_ps_build_named_op(struct acpi_walk_state *walk_state, | 
 | 209 | 		       u8 * aml_op_start, | 
 | 210 | 		       union acpi_parse_object *unnamed_op, | 
 | 211 | 		       union acpi_parse_object **op) | 
 | 212 | { | 
 | 213 | 	acpi_status status = AE_OK; | 
 | 214 | 	union acpi_parse_object *arg = NULL; | 
 | 215 |  | 
 | 216 | 	ACPI_FUNCTION_TRACE_PTR(ps_build_named_op, walk_state); | 
 | 217 |  | 
 | 218 | 	unnamed_op->common.value.arg = NULL; | 
| Bob Moore | 4e3156b | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 219 | 	unnamed_op->common.arg_list_length = 0; | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 220 | 	unnamed_op->common.aml_opcode = walk_state->opcode; | 
 | 221 |  | 
 | 222 | 	/* | 
 | 223 | 	 * Get and append arguments until we find the node that contains | 
 | 224 | 	 * the name (the type ARGP_NAME). | 
 | 225 | 	 */ | 
 | 226 | 	while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) && | 
 | 227 | 	       (GET_CURRENT_ARG_TYPE(walk_state->arg_types) != ARGP_NAME)) { | 
 | 228 | 		status = | 
 | 229 | 		    acpi_ps_get_next_arg(walk_state, | 
 | 230 | 					 &(walk_state->parser_state), | 
 | 231 | 					 GET_CURRENT_ARG_TYPE(walk_state-> | 
 | 232 | 							      arg_types), &arg); | 
 | 233 | 		if (ACPI_FAILURE(status)) { | 
 | 234 | 			return_ACPI_STATUS(status); | 
 | 235 | 		} | 
 | 236 |  | 
 | 237 | 		acpi_ps_append_arg(unnamed_op, arg); | 
 | 238 | 		INCREMENT_ARG_LIST(walk_state->arg_types); | 
 | 239 | 	} | 
 | 240 |  | 
 | 241 | 	/* | 
 | 242 | 	 * Make sure that we found a NAME and didn't run out of arguments | 
 | 243 | 	 */ | 
 | 244 | 	if (!GET_CURRENT_ARG_TYPE(walk_state->arg_types)) { | 
 | 245 | 		return_ACPI_STATUS(AE_AML_NO_OPERAND); | 
 | 246 | 	} | 
 | 247 |  | 
 | 248 | 	/* We know that this arg is a name, move to next arg */ | 
 | 249 |  | 
 | 250 | 	INCREMENT_ARG_LIST(walk_state->arg_types); | 
 | 251 |  | 
 | 252 | 	/* | 
 | 253 | 	 * Find the object. This will either insert the object into | 
 | 254 | 	 * the namespace or simply look it up | 
 | 255 | 	 */ | 
 | 256 | 	walk_state->op = NULL; | 
 | 257 |  | 
 | 258 | 	status = walk_state->descending_callback(walk_state, op); | 
 | 259 | 	if (ACPI_FAILURE(status)) { | 
 | 260 | 		ACPI_EXCEPTION((AE_INFO, status, "During name lookup/catalog")); | 
 | 261 | 		return_ACPI_STATUS(status); | 
 | 262 | 	} | 
 | 263 |  | 
| Valery Podrezov | 9bc75cf | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 264 | 	if (!*op) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 265 | 		return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); | 
 | 266 | 	} | 
 | 267 |  | 
 | 268 | 	status = acpi_ps_next_parse_state(walk_state, *op, status); | 
 | 269 | 	if (ACPI_FAILURE(status)) { | 
 | 270 | 		if (status == AE_CTRL_PENDING) { | 
 | 271 | 			return_ACPI_STATUS(AE_CTRL_PARSE_PENDING); | 
 | 272 | 		} | 
 | 273 | 		return_ACPI_STATUS(status); | 
 | 274 | 	} | 
 | 275 |  | 
 | 276 | 	acpi_ps_append_arg(*op, unnamed_op->common.value.arg); | 
 | 277 | 	acpi_gbl_depth++; | 
 | 278 |  | 
| Lin Ming | 941f48b | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 279 | 	if ((*op)->common.aml_opcode == AML_REGION_OP || | 
 | 280 | 	    (*op)->common.aml_opcode == AML_DATA_REGION_OP) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 281 | 		/* | 
 | 282 | 		 * Defer final parsing of an operation_region body, because we don't | 
 | 283 | 		 * have enough info in the first pass to parse it correctly (i.e., | 
 | 284 | 		 * there may be method calls within the term_arg elements of the body.) | 
 | 285 | 		 * | 
 | 286 | 		 * However, we must continue parsing because the opregion is not a | 
 | 287 | 		 * standalone package -- we don't know where the end is at this point. | 
 | 288 | 		 * | 
 | 289 | 		 * (Length is unknown until parse of the body complete) | 
 | 290 | 		 */ | 
 | 291 | 		(*op)->named.data = aml_op_start; | 
 | 292 | 		(*op)->named.length = 0; | 
 | 293 | 	} | 
 | 294 |  | 
 | 295 | 	return_ACPI_STATUS(AE_OK); | 
 | 296 | } | 
 | 297 |  | 
 | 298 | /******************************************************************************* | 
 | 299 |  * | 
 | 300 |  * FUNCTION:    acpi_ps_create_op | 
 | 301 |  * | 
 | 302 |  * PARAMETERS:  walk_state          - Current state | 
 | 303 |  *              aml_op_start        - Op start in AML | 
 | 304 |  *              new_op              - Returned Op | 
 | 305 |  * | 
 | 306 |  * RETURN:      Status | 
 | 307 |  * | 
 | 308 |  * DESCRIPTION: Get Op from AML | 
 | 309 |  * | 
 | 310 |  ******************************************************************************/ | 
 | 311 |  | 
 | 312 | static acpi_status | 
 | 313 | acpi_ps_create_op(struct acpi_walk_state *walk_state, | 
 | 314 | 		  u8 * aml_op_start, union acpi_parse_object **new_op) | 
 | 315 | { | 
 | 316 | 	acpi_status status = AE_OK; | 
 | 317 | 	union acpi_parse_object *op; | 
 | 318 | 	union acpi_parse_object *named_op = NULL; | 
| Bob Moore | 4e3156b | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 319 | 	union acpi_parse_object *parent_scope; | 
 | 320 | 	u8 argument_count; | 
 | 321 | 	const struct acpi_opcode_info *op_info; | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 322 |  | 
 | 323 | 	ACPI_FUNCTION_TRACE_PTR(ps_create_op, walk_state); | 
 | 324 |  | 
 | 325 | 	status = acpi_ps_get_aml_opcode(walk_state); | 
 | 326 | 	if (status == AE_CTRL_PARSE_CONTINUE) { | 
 | 327 | 		return_ACPI_STATUS(AE_CTRL_PARSE_CONTINUE); | 
 | 328 | 	} | 
 | 329 |  | 
 | 330 | 	/* Create Op structure and append to parent's argument list */ | 
 | 331 |  | 
 | 332 | 	walk_state->op_info = acpi_ps_get_opcode_info(walk_state->opcode); | 
 | 333 | 	op = acpi_ps_alloc_op(walk_state->opcode); | 
 | 334 | 	if (!op) { | 
 | 335 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
 | 336 | 	} | 
 | 337 |  | 
 | 338 | 	if (walk_state->op_info->flags & AML_NAMED) { | 
 | 339 | 		status = | 
 | 340 | 		    acpi_ps_build_named_op(walk_state, aml_op_start, op, | 
 | 341 | 					   &named_op); | 
 | 342 | 		acpi_ps_free_op(op); | 
 | 343 | 		if (ACPI_FAILURE(status)) { | 
 | 344 | 			return_ACPI_STATUS(status); | 
 | 345 | 		} | 
 | 346 |  | 
 | 347 | 		*new_op = named_op; | 
 | 348 | 		return_ACPI_STATUS(AE_OK); | 
 | 349 | 	} | 
 | 350 |  | 
 | 351 | 	/* Not a named opcode, just allocate Op and append to parent */ | 
 | 352 |  | 
 | 353 | 	if (walk_state->op_info->flags & AML_CREATE) { | 
 | 354 | 		/* | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 355 | 		 * Backup to beginning of create_XXXfield declaration | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 356 | 		 * body_length is unknown until we parse the body | 
 | 357 | 		 */ | 
 | 358 | 		op->named.data = aml_op_start; | 
 | 359 | 		op->named.length = 0; | 
 | 360 | 	} | 
 | 361 |  | 
| Lin Ming | ef805d9 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 362 | 	if (walk_state->opcode == AML_BANK_FIELD_OP) { | 
 | 363 | 		/* | 
 | 364 | 		 * Backup to beginning of bank_field declaration | 
 | 365 | 		 * body_length is unknown until we parse the body | 
 | 366 | 		 */ | 
 | 367 | 		op->named.data = aml_op_start; | 
 | 368 | 		op->named.length = 0; | 
 | 369 | 	} | 
 | 370 |  | 
| Bob Moore | 4e3156b | 2008-04-10 19:06:37 +0400 | [diff] [blame] | 371 | 	parent_scope = acpi_ps_get_parent_scope(&(walk_state->parser_state)); | 
 | 372 | 	acpi_ps_append_arg(parent_scope, op); | 
 | 373 |  | 
 | 374 | 	if (parent_scope) { | 
 | 375 | 		op_info = | 
 | 376 | 		    acpi_ps_get_opcode_info(parent_scope->common.aml_opcode); | 
 | 377 | 		if (op_info->flags & AML_HAS_TARGET) { | 
 | 378 | 			argument_count = | 
 | 379 | 			    acpi_ps_get_argument_count(op_info->type); | 
 | 380 | 			if (parent_scope->common.arg_list_length > | 
 | 381 | 			    argument_count) { | 
 | 382 | 				op->common.flags |= ACPI_PARSEOP_TARGET; | 
 | 383 | 			} | 
 | 384 | 		} else if (parent_scope->common.aml_opcode == AML_INCREMENT_OP) { | 
 | 385 | 			op->common.flags |= ACPI_PARSEOP_TARGET; | 
 | 386 | 		} | 
 | 387 | 	} | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 388 |  | 
 | 389 | 	if (walk_state->descending_callback != NULL) { | 
 | 390 | 		/* | 
 | 391 | 		 * Find the object. This will either insert the object into | 
 | 392 | 		 * the namespace or simply look it up | 
 | 393 | 		 */ | 
 | 394 | 		walk_state->op = *new_op = op; | 
 | 395 |  | 
 | 396 | 		status = walk_state->descending_callback(walk_state, &op); | 
 | 397 | 		status = acpi_ps_next_parse_state(walk_state, op, status); | 
 | 398 | 		if (status == AE_CTRL_PENDING) { | 
 | 399 | 			status = AE_CTRL_PARSE_PENDING; | 
 | 400 | 		} | 
 | 401 | 	} | 
 | 402 |  | 
 | 403 | 	return_ACPI_STATUS(status); | 
 | 404 | } | 
 | 405 |  | 
 | 406 | /******************************************************************************* | 
 | 407 |  * | 
 | 408 |  * FUNCTION:    acpi_ps_get_arguments | 
 | 409 |  * | 
 | 410 |  * PARAMETERS:  walk_state          - Current state | 
 | 411 |  *              aml_op_start        - Op start in AML | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 412 |  *              op                  - Current Op | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 413 |  * | 
 | 414 |  * RETURN:      Status | 
 | 415 |  * | 
 | 416 |  * DESCRIPTION: Get arguments for passed Op. | 
 | 417 |  * | 
 | 418 |  ******************************************************************************/ | 
 | 419 |  | 
 | 420 | static acpi_status | 
 | 421 | acpi_ps_get_arguments(struct acpi_walk_state *walk_state, | 
 | 422 | 		      u8 * aml_op_start, union acpi_parse_object *op) | 
 | 423 | { | 
 | 424 | 	acpi_status status = AE_OK; | 
 | 425 | 	union acpi_parse_object *arg = NULL; | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 426 | 	const struct acpi_opcode_info *op_info; | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 427 |  | 
 | 428 | 	ACPI_FUNCTION_TRACE_PTR(ps_get_arguments, walk_state); | 
 | 429 |  | 
 | 430 | 	switch (op->common.aml_opcode) { | 
 | 431 | 	case AML_BYTE_OP:	/* AML_BYTEDATA_ARG */ | 
 | 432 | 	case AML_WORD_OP:	/* AML_WORDDATA_ARG */ | 
 | 433 | 	case AML_DWORD_OP:	/* AML_DWORDATA_ARG */ | 
 | 434 | 	case AML_QWORD_OP:	/* AML_QWORDATA_ARG */ | 
 | 435 | 	case AML_STRING_OP:	/* AML_ASCIICHARLIST_ARG */ | 
 | 436 |  | 
 | 437 | 		/* Fill in constant or string argument directly */ | 
 | 438 |  | 
 | 439 | 		acpi_ps_get_next_simple_arg(&(walk_state->parser_state), | 
 | 440 | 					    GET_CURRENT_ARG_TYPE(walk_state-> | 
 | 441 | 								 arg_types), | 
 | 442 | 					    op); | 
 | 443 | 		break; | 
 | 444 |  | 
 | 445 | 	case AML_INT_NAMEPATH_OP:	/* AML_NAMESTRING_ARG */ | 
 | 446 |  | 
 | 447 | 		status = | 
 | 448 | 		    acpi_ps_get_next_namepath(walk_state, | 
 | 449 | 					      &(walk_state->parser_state), op, | 
 | 450 | 					      1); | 
 | 451 | 		if (ACPI_FAILURE(status)) { | 
 | 452 | 			return_ACPI_STATUS(status); | 
 | 453 | 		} | 
 | 454 |  | 
 | 455 | 		walk_state->arg_types = 0; | 
 | 456 | 		break; | 
 | 457 |  | 
 | 458 | 	default: | 
 | 459 | 		/* | 
 | 460 | 		 * Op is not a constant or string, append each argument to the Op | 
 | 461 | 		 */ | 
 | 462 | 		while (GET_CURRENT_ARG_TYPE(walk_state->arg_types) | 
 | 463 | 		       && !walk_state->arg_count) { | 
 | 464 | 			walk_state->aml_offset = | 
 | 465 | 			    (u32) ACPI_PTR_DIFF(walk_state->parser_state.aml, | 
 | 466 | 						walk_state->parser_state. | 
 | 467 | 						aml_start); | 
 | 468 |  | 
 | 469 | 			status = | 
 | 470 | 			    acpi_ps_get_next_arg(walk_state, | 
 | 471 | 						 &(walk_state->parser_state), | 
 | 472 | 						 GET_CURRENT_ARG_TYPE | 
 | 473 | 						 (walk_state->arg_types), &arg); | 
 | 474 | 			if (ACPI_FAILURE(status)) { | 
 | 475 | 				return_ACPI_STATUS(status); | 
 | 476 | 			} | 
 | 477 |  | 
 | 478 | 			if (arg) { | 
 | 479 | 				arg->common.aml_offset = walk_state->aml_offset; | 
 | 480 | 				acpi_ps_append_arg(op, arg); | 
 | 481 | 			} | 
 | 482 |  | 
 | 483 | 			INCREMENT_ARG_LIST(walk_state->arg_types); | 
 | 484 | 		} | 
 | 485 |  | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 486 | 		/* | 
 | 487 | 		 * Handle executable code at "module-level". This refers to | 
 | 488 | 		 * executable opcodes that appear outside of any control method. | 
 | 489 | 		 */ | 
 | 490 | 		if ((walk_state->pass_number <= ACPI_IMODE_LOAD_PASS2) && | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 491 | 		    ((walk_state->parse_flags & ACPI_PARSE_DISASSEMBLE) == 0)) { | 
 | 492 | 			/* | 
 | 493 | 			 * We want to skip If/Else/While constructs during Pass1 because we | 
 | 494 | 			 * want to actually conditionally execute the code during Pass2. | 
 | 495 | 			 * | 
 | 496 | 			 * Except for disassembly, where we always want to walk the | 
 | 497 | 			 * If/Else/While packages | 
 | 498 | 			 */ | 
 | 499 | 			switch (op->common.aml_opcode) { | 
 | 500 | 			case AML_IF_OP: | 
 | 501 | 			case AML_ELSE_OP: | 
 | 502 | 			case AML_WHILE_OP: | 
 | 503 |  | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 504 | 				/* | 
 | 505 | 				 * Currently supported module-level opcodes are: | 
 | 506 | 				 * IF/ELSE/WHILE. These appear to be the most common, | 
 | 507 | 				 * and easiest to support since they open an AML | 
 | 508 | 				 * package. | 
 | 509 | 				 */ | 
 | 510 | 				if (walk_state->pass_number == | 
 | 511 | 				    ACPI_IMODE_LOAD_PASS1) { | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 512 | 					acpi_ps_link_module_code(op->common. | 
 | 513 | 								 parent, | 
 | 514 | 								 aml_op_start, | 
 | 515 | 								 (u32) | 
 | 516 | 								 (walk_state-> | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 517 | 								 parser_state. | 
 | 518 | 								 pkg_end - | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 519 | 								 aml_op_start), | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 520 | 								 walk_state-> | 
 | 521 | 								 owner_id); | 
 | 522 | 				} | 
 | 523 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 524 | 				ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | 
 | 525 | 						  "Pass1: Skipping an If/Else/While body\n")); | 
 | 526 |  | 
 | 527 | 				/* Skip body of if/else/while in pass 1 */ | 
 | 528 |  | 
 | 529 | 				walk_state->parser_state.aml = | 
 | 530 | 				    walk_state->parser_state.pkg_end; | 
 | 531 | 				walk_state->arg_count = 0; | 
 | 532 | 				break; | 
 | 533 |  | 
 | 534 | 			default: | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 535 | 				/* | 
 | 536 | 				 * Check for an unsupported executable opcode at module | 
 | 537 | 				 * level. We must be in PASS1, the parent must be a SCOPE, | 
 | 538 | 				 * The opcode class must be EXECUTE, and the opcode must | 
 | 539 | 				 * not be an argument to another opcode. | 
 | 540 | 				 */ | 
 | 541 | 				if ((walk_state->pass_number == | 
 | 542 | 				     ACPI_IMODE_LOAD_PASS1) | 
 | 543 | 				    && (op->common.parent->common.aml_opcode == | 
 | 544 | 					AML_SCOPE_OP)) { | 
 | 545 | 					op_info = | 
 | 546 | 					    acpi_ps_get_opcode_info(op->common. | 
 | 547 | 								    aml_opcode); | 
 | 548 | 					if ((op_info->class == | 
 | 549 | 					     AML_CLASS_EXECUTE) && (!arg)) { | 
 | 550 | 						ACPI_WARNING((AE_INFO, | 
| Bob Moore | 00eb325 | 2012-10-31 02:27:48 +0000 | [diff] [blame] | 551 | 							      "Unsupported module-level executable opcode " | 
 | 552 | 							      "0x%.2X at table offset 0x%.4X", | 
 | 553 | 							      op->common. | 
 | 554 | 							      aml_opcode, | 
 | 555 | 							      (u32) | 
 | 556 | 							      (ACPI_PTR_DIFF | 
 | 557 | 							       (aml_op_start, | 
 | 558 | 								walk_state-> | 
 | 559 | 								parser_state. | 
 | 560 | 								aml_start) + | 
 | 561 | 							       sizeof(struct | 
 | 562 | 								      acpi_table_header)))); | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 563 | 					} | 
 | 564 | 				} | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 565 | 				break; | 
 | 566 | 			} | 
 | 567 | 		} | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 568 |  | 
 | 569 | 		/* Special processing for certain opcodes */ | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 570 |  | 
 | 571 | 		switch (op->common.aml_opcode) { | 
 | 572 | 		case AML_METHOD_OP: | 
 | 573 | 			/* | 
 | 574 | 			 * Skip parsing of control method because we don't have enough | 
 | 575 | 			 * info in the first pass to parse it correctly. | 
 | 576 | 			 * | 
 | 577 | 			 * Save the length and address of the body | 
 | 578 | 			 */ | 
 | 579 | 			op->named.data = walk_state->parser_state.aml; | 
 | 580 | 			op->named.length = (u32) | 
 | 581 | 			    (walk_state->parser_state.pkg_end - | 
 | 582 | 			     walk_state->parser_state.aml); | 
 | 583 |  | 
 | 584 | 			/* Skip body of method */ | 
 | 585 |  | 
 | 586 | 			walk_state->parser_state.aml = | 
 | 587 | 			    walk_state->parser_state.pkg_end; | 
 | 588 | 			walk_state->arg_count = 0; | 
 | 589 | 			break; | 
 | 590 |  | 
 | 591 | 		case AML_BUFFER_OP: | 
 | 592 | 		case AML_PACKAGE_OP: | 
 | 593 | 		case AML_VAR_PACKAGE_OP: | 
 | 594 |  | 
 | 595 | 			if ((op->common.parent) && | 
 | 596 | 			    (op->common.parent->common.aml_opcode == | 
 | 597 | 			     AML_NAME_OP) | 
 | 598 | 			    && (walk_state->pass_number <= | 
 | 599 | 				ACPI_IMODE_LOAD_PASS2)) { | 
 | 600 | 				/* | 
 | 601 | 				 * Skip parsing of Buffers and Packages because we don't have | 
 | 602 | 				 * enough info in the first pass to parse them correctly. | 
 | 603 | 				 */ | 
 | 604 | 				op->named.data = aml_op_start; | 
 | 605 | 				op->named.length = (u32) | 
 | 606 | 				    (walk_state->parser_state.pkg_end - | 
 | 607 | 				     aml_op_start); | 
 | 608 |  | 
 | 609 | 				/* Skip body */ | 
 | 610 |  | 
 | 611 | 				walk_state->parser_state.aml = | 
 | 612 | 				    walk_state->parser_state.pkg_end; | 
 | 613 | 				walk_state->arg_count = 0; | 
 | 614 | 			} | 
 | 615 | 			break; | 
 | 616 |  | 
 | 617 | 		case AML_WHILE_OP: | 
 | 618 |  | 
 | 619 | 			if (walk_state->control_state) { | 
 | 620 | 				walk_state->control_state->control.package_end = | 
 | 621 | 				    walk_state->parser_state.pkg_end; | 
 | 622 | 			} | 
 | 623 | 			break; | 
 | 624 |  | 
 | 625 | 		default: | 
 | 626 |  | 
 | 627 | 			/* No action for all other opcodes */ | 
 | 628 | 			break; | 
 | 629 | 		} | 
 | 630 |  | 
 | 631 | 		break; | 
 | 632 | 	} | 
 | 633 |  | 
 | 634 | 	return_ACPI_STATUS(AE_OK); | 
 | 635 | } | 
 | 636 |  | 
 | 637 | /******************************************************************************* | 
 | 638 |  * | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 639 |  * FUNCTION:    acpi_ps_link_module_code | 
 | 640 |  * | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 641 |  * PARAMETERS:  parent_op           - Parent parser op | 
 | 642 |  *              aml_start           - Pointer to the AML | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 643 |  *              aml_length          - Length of executable AML | 
 | 644 |  *              owner_id            - owner_id of module level code | 
 | 645 |  * | 
 | 646 |  * RETURN:      None. | 
 | 647 |  * | 
 | 648 |  * DESCRIPTION: Wrap the module-level code with a method object and link the | 
 | 649 |  *              object to the global list. Note, the mutex field of the method | 
 | 650 |  *              object is used to link multiple module-level code objects. | 
 | 651 |  * | 
 | 652 |  ******************************************************************************/ | 
 | 653 |  | 
 | 654 | static void | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 655 | acpi_ps_link_module_code(union acpi_parse_object *parent_op, | 
 | 656 | 			 u8 *aml_start, u32 aml_length, acpi_owner_id owner_id) | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 657 | { | 
 | 658 | 	union acpi_operand_object *prev; | 
 | 659 | 	union acpi_operand_object *next; | 
 | 660 | 	union acpi_operand_object *method_obj; | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 661 | 	struct acpi_namespace_node *parent_node; | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 662 |  | 
 | 663 | 	/* Get the tail of the list */ | 
 | 664 |  | 
 | 665 | 	prev = next = acpi_gbl_module_code_list; | 
 | 666 | 	while (next) { | 
 | 667 | 		prev = next; | 
 | 668 | 		next = next->method.mutex; | 
 | 669 | 	} | 
 | 670 |  | 
 | 671 | 	/* | 
 | 672 | 	 * Insert the module level code into the list. Merge it if it is | 
 | 673 | 	 * adjacent to the previous element. | 
 | 674 | 	 */ | 
 | 675 | 	if (!prev || | 
 | 676 | 	    ((prev->method.aml_start + prev->method.aml_length) != aml_start)) { | 
 | 677 |  | 
 | 678 | 		/* Create, initialize, and link a new temporary method object */ | 
 | 679 |  | 
 | 680 | 		method_obj = acpi_ut_create_internal_object(ACPI_TYPE_METHOD); | 
 | 681 | 		if (!method_obj) { | 
 | 682 | 			return; | 
 | 683 | 		} | 
 | 684 |  | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 685 | 		if (parent_op->common.node) { | 
 | 686 | 			parent_node = parent_op->common.node; | 
 | 687 | 		} else { | 
 | 688 | 			parent_node = acpi_gbl_root_node; | 
 | 689 | 		} | 
 | 690 |  | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 691 | 		method_obj->method.aml_start = aml_start; | 
 | 692 | 		method_obj->method.aml_length = aml_length; | 
 | 693 | 		method_obj->method.owner_id = owner_id; | 
| Lin Ming | 2629484 | 2011-01-12 09:19:43 +0800 | [diff] [blame] | 694 | 		method_obj->method.info_flags |= ACPI_METHOD_MODULE_LEVEL; | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 695 |  | 
| Lin Ming | 9a884ab | 2009-11-12 09:57:53 +0800 | [diff] [blame] | 696 | 		/* | 
 | 697 | 		 * Save the parent node in next_object. This is cheating, but we | 
 | 698 | 		 * don't want to expand the method object. | 
 | 699 | 		 */ | 
 | 700 | 		method_obj->method.next_object = | 
 | 701 | 		    ACPI_CAST_PTR(union acpi_operand_object, parent_node); | 
 | 702 |  | 
| Lin Ming | 7f0c826 | 2009-08-13 14:03:15 +0800 | [diff] [blame] | 703 | 		if (!prev) { | 
 | 704 | 			acpi_gbl_module_code_list = method_obj; | 
 | 705 | 		} else { | 
 | 706 | 			prev->method.mutex = method_obj; | 
 | 707 | 		} | 
 | 708 | 	} else { | 
 | 709 | 		prev->method.aml_length += aml_length; | 
 | 710 | 	} | 
 | 711 | } | 
 | 712 |  | 
 | 713 | /******************************************************************************* | 
 | 714 |  * | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 715 |  * FUNCTION:    acpi_ps_complete_op | 
 | 716 |  * | 
 | 717 |  * PARAMETERS:  walk_state          - Current state | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 718 |  *              op                  - Returned Op | 
 | 719 |  *              status              - Parse status before complete Op | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 720 |  * | 
 | 721 |  * RETURN:      Status | 
 | 722 |  * | 
 | 723 |  * DESCRIPTION: Complete Op | 
 | 724 |  * | 
 | 725 |  ******************************************************************************/ | 
 | 726 |  | 
 | 727 | static acpi_status | 
 | 728 | acpi_ps_complete_op(struct acpi_walk_state *walk_state, | 
 | 729 | 		    union acpi_parse_object **op, acpi_status status) | 
 | 730 | { | 
 | 731 | 	acpi_status status2; | 
 | 732 |  | 
 | 733 | 	ACPI_FUNCTION_TRACE_PTR(ps_complete_op, walk_state); | 
 | 734 |  | 
 | 735 | 	/* | 
 | 736 | 	 * Finished one argument of the containing scope | 
 | 737 | 	 */ | 
 | 738 | 	walk_state->parser_state.scope->parse_scope.arg_count--; | 
 | 739 |  | 
 | 740 | 	/* Close this Op (will result in parse subtree deletion) */ | 
 | 741 |  | 
 | 742 | 	status2 = acpi_ps_complete_this_op(walk_state, *op); | 
 | 743 | 	if (ACPI_FAILURE(status2)) { | 
 | 744 | 		return_ACPI_STATUS(status2); | 
 | 745 | 	} | 
 | 746 |  | 
 | 747 | 	*op = NULL; | 
 | 748 |  | 
 | 749 | 	switch (status) { | 
 | 750 | 	case AE_OK: | 
 | 751 | 		break; | 
 | 752 |  | 
 | 753 | 	case AE_CTRL_TRANSFER: | 
 | 754 |  | 
 | 755 | 		/* We are about to transfer to a called method */ | 
 | 756 |  | 
 | 757 | 		walk_state->prev_op = NULL; | 
 | 758 | 		walk_state->prev_arg_types = walk_state->arg_types; | 
 | 759 | 		return_ACPI_STATUS(status); | 
 | 760 |  | 
 | 761 | 	case AE_CTRL_END: | 
 | 762 |  | 
 | 763 | 		acpi_ps_pop_scope(&(walk_state->parser_state), op, | 
 | 764 | 				  &walk_state->arg_types, | 
 | 765 | 				  &walk_state->arg_count); | 
 | 766 |  | 
 | 767 | 		if (*op) { | 
 | 768 | 			walk_state->op = *op; | 
 | 769 | 			walk_state->op_info = | 
 | 770 | 			    acpi_ps_get_opcode_info((*op)->common.aml_opcode); | 
 | 771 | 			walk_state->opcode = (*op)->common.aml_opcode; | 
 | 772 |  | 
 | 773 | 			status = walk_state->ascending_callback(walk_state); | 
 | 774 | 			status = | 
 | 775 | 			    acpi_ps_next_parse_state(walk_state, *op, status); | 
 | 776 |  | 
 | 777 | 			status2 = acpi_ps_complete_this_op(walk_state, *op); | 
 | 778 | 			if (ACPI_FAILURE(status2)) { | 
 | 779 | 				return_ACPI_STATUS(status2); | 
 | 780 | 			} | 
 | 781 | 		} | 
 | 782 |  | 
 | 783 | 		status = AE_OK; | 
 | 784 | 		break; | 
 | 785 |  | 
 | 786 | 	case AE_CTRL_BREAK: | 
 | 787 | 	case AE_CTRL_CONTINUE: | 
 | 788 |  | 
 | 789 | 		/* Pop off scopes until we find the While */ | 
 | 790 |  | 
 | 791 | 		while (!(*op) || ((*op)->common.aml_opcode != AML_WHILE_OP)) { | 
 | 792 | 			acpi_ps_pop_scope(&(walk_state->parser_state), op, | 
 | 793 | 					  &walk_state->arg_types, | 
 | 794 | 					  &walk_state->arg_count); | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 795 | 		} | 
 | 796 |  | 
 | 797 | 		/* Close this iteration of the While loop */ | 
 | 798 |  | 
 | 799 | 		walk_state->op = *op; | 
 | 800 | 		walk_state->op_info = | 
 | 801 | 		    acpi_ps_get_opcode_info((*op)->common.aml_opcode); | 
 | 802 | 		walk_state->opcode = (*op)->common.aml_opcode; | 
 | 803 |  | 
 | 804 | 		status = walk_state->ascending_callback(walk_state); | 
 | 805 | 		status = acpi_ps_next_parse_state(walk_state, *op, status); | 
 | 806 |  | 
 | 807 | 		status2 = acpi_ps_complete_this_op(walk_state, *op); | 
 | 808 | 		if (ACPI_FAILURE(status2)) { | 
 | 809 | 			return_ACPI_STATUS(status2); | 
 | 810 | 		} | 
 | 811 |  | 
 | 812 | 		status = AE_OK; | 
 | 813 | 		break; | 
 | 814 |  | 
 | 815 | 	case AE_CTRL_TERMINATE: | 
 | 816 |  | 
 | 817 | 		/* Clean up */ | 
 | 818 | 		do { | 
 | 819 | 			if (*op) { | 
 | 820 | 				status2 = | 
 | 821 | 				    acpi_ps_complete_this_op(walk_state, *op); | 
 | 822 | 				if (ACPI_FAILURE(status2)) { | 
 | 823 | 					return_ACPI_STATUS(status2); | 
 | 824 | 				} | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 825 |  | 
 | 826 | 				acpi_ut_delete_generic_state | 
 | 827 | 				    (acpi_ut_pop_generic_state | 
 | 828 | 				     (&walk_state->control_state)); | 
 | 829 | 			} | 
 | 830 |  | 
 | 831 | 			acpi_ps_pop_scope(&(walk_state->parser_state), op, | 
 | 832 | 					  &walk_state->arg_types, | 
 | 833 | 					  &walk_state->arg_count); | 
 | 834 |  | 
 | 835 | 		} while (*op); | 
 | 836 |  | 
 | 837 | 		return_ACPI_STATUS(AE_OK); | 
 | 838 |  | 
 | 839 | 	default:		/* All other non-AE_OK status */ | 
 | 840 |  | 
 | 841 | 		do { | 
 | 842 | 			if (*op) { | 
 | 843 | 				status2 = | 
 | 844 | 				    acpi_ps_complete_this_op(walk_state, *op); | 
 | 845 | 				if (ACPI_FAILURE(status2)) { | 
 | 846 | 					return_ACPI_STATUS(status2); | 
 | 847 | 				} | 
 | 848 | 			} | 
 | 849 |  | 
 | 850 | 			acpi_ps_pop_scope(&(walk_state->parser_state), op, | 
 | 851 | 					  &walk_state->arg_types, | 
 | 852 | 					  &walk_state->arg_count); | 
 | 853 |  | 
 | 854 | 		} while (*op); | 
 | 855 |  | 
 | 856 | #if 0 | 
 | 857 | 		/* | 
 | 858 | 		 * TBD: Cleanup parse ops on error | 
 | 859 | 		 */ | 
 | 860 | 		if (*op == NULL) { | 
 | 861 | 			acpi_ps_pop_scope(parser_state, op, | 
 | 862 | 					  &walk_state->arg_types, | 
 | 863 | 					  &walk_state->arg_count); | 
 | 864 | 		} | 
 | 865 | #endif | 
 | 866 | 		walk_state->prev_op = NULL; | 
 | 867 | 		walk_state->prev_arg_types = walk_state->arg_types; | 
 | 868 | 		return_ACPI_STATUS(status); | 
 | 869 | 	} | 
 | 870 |  | 
 | 871 | 	/* This scope complete? */ | 
 | 872 |  | 
 | 873 | 	if (acpi_ps_has_completed_scope(&(walk_state->parser_state))) { | 
 | 874 | 		acpi_ps_pop_scope(&(walk_state->parser_state), op, | 
 | 875 | 				  &walk_state->arg_types, | 
 | 876 | 				  &walk_state->arg_count); | 
 | 877 | 		ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "Popped scope, Op=%p\n", *op)); | 
 | 878 | 	} else { | 
 | 879 | 		*op = NULL; | 
 | 880 | 	} | 
 | 881 |  | 
 | 882 | 	return_ACPI_STATUS(AE_OK); | 
 | 883 | } | 
 | 884 |  | 
 | 885 | /******************************************************************************* | 
 | 886 |  * | 
 | 887 |  * FUNCTION:    acpi_ps_complete_final_op | 
 | 888 |  * | 
 | 889 |  * PARAMETERS:  walk_state          - Current state | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 890 |  *              op                  - Current Op | 
 | 891 |  *              status              - Current parse status before complete last | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 892 |  *                                    Op | 
 | 893 |  * | 
 | 894 |  * RETURN:      Status | 
 | 895 |  * | 
 | 896 |  * DESCRIPTION: Complete last Op. | 
 | 897 |  * | 
 | 898 |  ******************************************************************************/ | 
 | 899 |  | 
 | 900 | static acpi_status | 
 | 901 | acpi_ps_complete_final_op(struct acpi_walk_state *walk_state, | 
 | 902 | 			  union acpi_parse_object *op, acpi_status status) | 
 | 903 | { | 
 | 904 | 	acpi_status status2; | 
 | 905 |  | 
 | 906 | 	ACPI_FUNCTION_TRACE_PTR(ps_complete_final_op, walk_state); | 
 | 907 |  | 
 | 908 | 	/* | 
 | 909 | 	 * Complete the last Op (if not completed), and clear the scope stack. | 
 | 910 | 	 * It is easily possible to end an AML "package" with an unbounded number | 
 | 911 | 	 * of open scopes (such as when several ASL blocks are closed with | 
 | 912 | 	 * sequential closing braces). We want to terminate each one cleanly. | 
 | 913 | 	 */ | 
 | 914 | 	ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n", | 
 | 915 | 			  op)); | 
 | 916 | 	do { | 
 | 917 | 		if (op) { | 
 | 918 | 			if (walk_state->ascending_callback != NULL) { | 
 | 919 | 				walk_state->op = op; | 
 | 920 | 				walk_state->op_info = | 
 | 921 | 				    acpi_ps_get_opcode_info(op->common. | 
 | 922 | 							    aml_opcode); | 
 | 923 | 				walk_state->opcode = op->common.aml_opcode; | 
 | 924 |  | 
 | 925 | 				status = | 
 | 926 | 				    walk_state->ascending_callback(walk_state); | 
 | 927 | 				status = | 
 | 928 | 				    acpi_ps_next_parse_state(walk_state, op, | 
 | 929 | 							     status); | 
 | 930 | 				if (status == AE_CTRL_PENDING) { | 
 | 931 | 					status = | 
 | 932 | 					    acpi_ps_complete_op(walk_state, &op, | 
 | 933 | 								AE_OK); | 
 | 934 | 					if (ACPI_FAILURE(status)) { | 
 | 935 | 						return_ACPI_STATUS(status); | 
 | 936 | 					} | 
 | 937 | 				} | 
 | 938 |  | 
 | 939 | 				if (status == AE_CTRL_TERMINATE) { | 
 | 940 | 					status = AE_OK; | 
 | 941 |  | 
 | 942 | 					/* Clean up */ | 
 | 943 | 					do { | 
 | 944 | 						if (op) { | 
 | 945 | 							status2 = | 
 | 946 | 							    acpi_ps_complete_this_op | 
 | 947 | 							    (walk_state, op); | 
 | 948 | 							if (ACPI_FAILURE | 
 | 949 | 							    (status2)) { | 
 | 950 | 								return_ACPI_STATUS | 
 | 951 | 								    (status2); | 
 | 952 | 							} | 
 | 953 | 						} | 
 | 954 |  | 
 | 955 | 						acpi_ps_pop_scope(& | 
 | 956 | 								  (walk_state-> | 
 | 957 | 								   parser_state), | 
 | 958 | 								  &op, | 
 | 959 | 								  &walk_state-> | 
 | 960 | 								  arg_types, | 
 | 961 | 								  &walk_state-> | 
 | 962 | 								  arg_count); | 
 | 963 |  | 
 | 964 | 					} while (op); | 
 | 965 |  | 
 | 966 | 					return_ACPI_STATUS(status); | 
 | 967 | 				} | 
 | 968 |  | 
 | 969 | 				else if (ACPI_FAILURE(status)) { | 
 | 970 |  | 
 | 971 | 					/* First error is most important */ | 
 | 972 |  | 
 | 973 | 					(void) | 
 | 974 | 					    acpi_ps_complete_this_op(walk_state, | 
 | 975 | 								     op); | 
 | 976 | 					return_ACPI_STATUS(status); | 
 | 977 | 				} | 
 | 978 | 			} | 
 | 979 |  | 
 | 980 | 			status2 = acpi_ps_complete_this_op(walk_state, op); | 
 | 981 | 			if (ACPI_FAILURE(status2)) { | 
 | 982 | 				return_ACPI_STATUS(status2); | 
 | 983 | 			} | 
 | 984 | 		} | 
 | 985 |  | 
 | 986 | 		acpi_ps_pop_scope(&(walk_state->parser_state), &op, | 
 | 987 | 				  &walk_state->arg_types, | 
 | 988 | 				  &walk_state->arg_count); | 
 | 989 |  | 
 | 990 | 	} while (op); | 
 | 991 |  | 
 | 992 | 	return_ACPI_STATUS(status); | 
 | 993 | } | 
 | 994 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 995 | /******************************************************************************* | 
 | 996 |  * | 
 | 997 |  * FUNCTION:    acpi_ps_parse_loop | 
 | 998 |  * | 
 | 999 |  * PARAMETERS:  walk_state          - Current state | 
 | 1000 |  * | 
 | 1001 |  * RETURN:      Status | 
 | 1002 |  * | 
 | 1003 |  * DESCRIPTION: Parse AML (pointed to by the current parser state) and return | 
 | 1004 |  *              a tree of ops. | 
 | 1005 |  * | 
 | 1006 |  ******************************************************************************/ | 
 | 1007 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1008 | acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1009 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1010 | 	acpi_status status = AE_OK; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1011 | 	union acpi_parse_object *op = NULL;	/* current op */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1012 | 	struct acpi_parse_state *parser_state; | 
 | 1013 | 	u8 *aml_op_start = NULL; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1014 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1015 | 	ACPI_FUNCTION_TRACE_PTR(ps_parse_loop, walk_state); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1016 |  | 
 | 1017 | 	if (walk_state->descending_callback == NULL) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1018 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1019 | 	} | 
 | 1020 |  | 
 | 1021 | 	parser_state = &walk_state->parser_state; | 
 | 1022 | 	walk_state->arg_types = 0; | 
 | 1023 |  | 
 | 1024 | #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) | 
 | 1025 |  | 
 | 1026 | 	if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 1027 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1028 | 		/* We are restarting a preempted control method */ | 
 | 1029 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1030 | 		if (acpi_ps_has_completed_scope(parser_state)) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1031 | 			/* | 
 | 1032 | 			 * We must check if a predicate to an IF or WHILE statement | 
 | 1033 | 			 * was just completed | 
 | 1034 | 			 */ | 
 | 1035 | 			if ((parser_state->scope->parse_scope.op) && | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1036 | 			    ((parser_state->scope->parse_scope.op->common. | 
 | 1037 | 			      aml_opcode == AML_IF_OP) | 
 | 1038 | 			     || (parser_state->scope->parse_scope.op->common. | 
 | 1039 | 				 aml_opcode == AML_WHILE_OP)) | 
 | 1040 | 			    && (walk_state->control_state) | 
 | 1041 | 			    && (walk_state->control_state->common.state == | 
 | 1042 | 				ACPI_CONTROL_PREDICATE_EXECUTING)) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1043 | 				/* | 
 | 1044 | 				 * A predicate was just completed, get the value of the | 
 | 1045 | 				 * predicate and branch based on that value | 
 | 1046 | 				 */ | 
 | 1047 | 				walk_state->op = NULL; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1048 | 				status = | 
 | 1049 | 				    acpi_ds_get_predicate_value(walk_state, | 
 | 1050 | 								ACPI_TO_POINTER | 
 | 1051 | 								(TRUE)); | 
 | 1052 | 				if (ACPI_FAILURE(status) | 
 | 1053 | 				    && ((status & AE_CODE_MASK) != | 
 | 1054 | 					AE_CODE_CONTROL)) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1055 | 					if (status == AE_AML_NO_RETURN_VALUE) { | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1056 | 						ACPI_EXCEPTION((AE_INFO, status, | 
 | 1057 | 								"Invoked method did not return a value")); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1058 | 					} | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1059 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 1060 | 					ACPI_EXCEPTION((AE_INFO, status, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1061 | 							"GetPredicate Failed")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1062 | 					return_ACPI_STATUS(status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1063 | 				} | 
 | 1064 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1065 | 				status = | 
 | 1066 | 				    acpi_ps_next_parse_state(walk_state, op, | 
 | 1067 | 							     status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1068 | 			} | 
 | 1069 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1070 | 			acpi_ps_pop_scope(parser_state, &op, | 
 | 1071 | 					  &walk_state->arg_types, | 
 | 1072 | 					  &walk_state->arg_count); | 
 | 1073 | 			ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | 
 | 1074 | 					  "Popped scope, Op=%p\n", op)); | 
 | 1075 | 		} else if (walk_state->prev_op) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 1076 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1077 | 			/* We were in the middle of an op */ | 
 | 1078 |  | 
 | 1079 | 			op = walk_state->prev_op; | 
 | 1080 | 			walk_state->arg_types = walk_state->prev_arg_types; | 
 | 1081 | 		} | 
 | 1082 | 	} | 
 | 1083 | #endif | 
 | 1084 |  | 
 | 1085 | 	/* Iterative parsing loop, while there is more AML to process: */ | 
 | 1086 |  | 
 | 1087 | 	while ((parser_state->aml < parser_state->aml_end) || (op)) { | 
 | 1088 | 		aml_op_start = parser_state->aml; | 
 | 1089 | 		if (!op) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1090 | 			status = | 
 | 1091 | 			    acpi_ps_create_op(walk_state, aml_op_start, &op); | 
 | 1092 | 			if (ACPI_FAILURE(status)) { | 
 | 1093 | 				if (status == AE_CTRL_PARSE_CONTINUE) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1094 | 					continue; | 
 | 1095 | 				} | 
 | 1096 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1097 | 				if (status == AE_CTRL_PARSE_PENDING) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1098 | 					status = AE_OK; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1099 | 				} | 
 | 1100 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1101 | 				status = | 
 | 1102 | 				    acpi_ps_complete_op(walk_state, &op, | 
 | 1103 | 							status); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1104 | 				if (ACPI_FAILURE(status)) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1105 | 					return_ACPI_STATUS(status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1106 | 				} | 
 | 1107 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1108 | 				continue; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1109 | 			} | 
 | 1110 |  | 
 | 1111 | 			op->common.aml_offset = walk_state->aml_offset; | 
 | 1112 |  | 
 | 1113 | 			if (walk_state->op_info) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1114 | 				ACPI_DEBUG_PRINT((ACPI_DB_PARSE, | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 1115 | 						  "Opcode %4.4X [%s] Op %p Aml %p AmlOffset %5.5X\n", | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1116 | 						  (u32) op->common.aml_opcode, | 
 | 1117 | 						  walk_state->op_info->name, op, | 
 | 1118 | 						  parser_state->aml, | 
 | 1119 | 						  op->common.aml_offset)); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1120 | 			} | 
 | 1121 | 		} | 
 | 1122 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1123 | 		/* | 
 | 1124 | 		 * Start arg_count at zero because we don't know if there are | 
 | 1125 | 		 * any args yet | 
 | 1126 | 		 */ | 
 | 1127 | 		walk_state->arg_count = 0; | 
 | 1128 |  | 
 | 1129 | 		/* Are there any arguments that must be processed? */ | 
 | 1130 |  | 
 | 1131 | 		if (walk_state->arg_types) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 1132 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1133 | 			/* Get arguments */ | 
 | 1134 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1135 | 			status = | 
 | 1136 | 			    acpi_ps_get_arguments(walk_state, aml_op_start, op); | 
 | 1137 | 			if (ACPI_FAILURE(status)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1138 | 				status = | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1139 | 				    acpi_ps_complete_op(walk_state, &op, | 
 | 1140 | 							status); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1141 | 				if (ACPI_FAILURE(status)) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1142 | 					return_ACPI_STATUS(status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1143 | 				} | 
 | 1144 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1145 | 				continue; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1146 | 			} | 
 | 1147 | 		} | 
 | 1148 |  | 
 | 1149 | 		/* Check for arguments that need to be processed */ | 
 | 1150 |  | 
 | 1151 | 		if (walk_state->arg_count) { | 
 | 1152 | 			/* | 
 | 1153 | 			 * There are arguments (complex ones), push Op and | 
 | 1154 | 			 * prepare for argument | 
 | 1155 | 			 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1156 | 			status = acpi_ps_push_scope(parser_state, op, | 
 | 1157 | 						    walk_state->arg_types, | 
 | 1158 | 						    walk_state->arg_count); | 
 | 1159 | 			if (ACPI_FAILURE(status)) { | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1160 | 				status = | 
 | 1161 | 				    acpi_ps_complete_op(walk_state, &op, | 
 | 1162 | 							status); | 
 | 1163 | 				if (ACPI_FAILURE(status)) { | 
 | 1164 | 					return_ACPI_STATUS(status); | 
 | 1165 | 				} | 
 | 1166 |  | 
 | 1167 | 				continue; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1168 | 			} | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1169 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1170 | 			op = NULL; | 
 | 1171 | 			continue; | 
 | 1172 | 		} | 
 | 1173 |  | 
 | 1174 | 		/* | 
 | 1175 | 		 * All arguments have been processed -- Op is complete, | 
 | 1176 | 		 * prepare for next | 
 | 1177 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1178 | 		walk_state->op_info = | 
 | 1179 | 		    acpi_ps_get_opcode_info(op->common.aml_opcode); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1180 | 		if (walk_state->op_info->flags & AML_NAMED) { | 
 | 1181 | 			if (acpi_gbl_depth) { | 
 | 1182 | 				acpi_gbl_depth--; | 
 | 1183 | 			} | 
 | 1184 |  | 
| Lin Ming | 941f48b | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 1185 | 			if (op->common.aml_opcode == AML_REGION_OP || | 
 | 1186 | 			    op->common.aml_opcode == AML_DATA_REGION_OP) { | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1187 | 				/* | 
 | 1188 | 				 * Skip parsing of control method or opregion body, | 
 | 1189 | 				 * because we don't have enough info in the first pass | 
 | 1190 | 				 * to parse them correctly. | 
 | 1191 | 				 * | 
 | 1192 | 				 * Completed parsing an op_region declaration, we now | 
 | 1193 | 				 * know the length. | 
 | 1194 | 				 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1195 | 				op->named.length = | 
 | 1196 | 				    (u32) (parser_state->aml - op->named.data); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1197 | 			} | 
 | 1198 | 		} | 
 | 1199 |  | 
 | 1200 | 		if (walk_state->op_info->flags & AML_CREATE) { | 
 | 1201 | 			/* | 
| Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 1202 | 			 * Backup to beginning of create_XXXfield declaration (1 for | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1203 | 			 * Opcode) | 
 | 1204 | 			 * | 
 | 1205 | 			 * body_length is unknown until we parse the body | 
 | 1206 | 			 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1207 | 			op->named.length = | 
 | 1208 | 			    (u32) (parser_state->aml - op->named.data); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1209 | 		} | 
 | 1210 |  | 
| Lin Ming | ef805d9 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 1211 | 		if (op->common.aml_opcode == AML_BANK_FIELD_OP) { | 
 | 1212 | 			/* | 
 | 1213 | 			 * Backup to beginning of bank_field declaration | 
 | 1214 | 			 * | 
 | 1215 | 			 * body_length is unknown until we parse the body | 
 | 1216 | 			 */ | 
 | 1217 | 			op->named.length = | 
 | 1218 | 			    (u32) (parser_state->aml - op->named.data); | 
 | 1219 | 		} | 
 | 1220 |  | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1221 | 		/* This op complete, notify the dispatcher */ | 
 | 1222 |  | 
 | 1223 | 		if (walk_state->ascending_callback != NULL) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1224 | 			walk_state->op = op; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1225 | 			walk_state->opcode = op->common.aml_opcode; | 
 | 1226 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1227 | 			status = walk_state->ascending_callback(walk_state); | 
 | 1228 | 			status = | 
 | 1229 | 			    acpi_ps_next_parse_state(walk_state, op, status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1230 | 			if (status == AE_CTRL_PENDING) { | 
 | 1231 | 				status = AE_OK; | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1232 | 			} | 
 | 1233 | 		} | 
 | 1234 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1235 | 		status = acpi_ps_complete_op(walk_state, &op, status); | 
 | 1236 | 		if (ACPI_FAILURE(status)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1237 | 			return_ACPI_STATUS(status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1238 | 		} | 
 | 1239 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1240 | 	}			/* while parser_state->Aml */ | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1241 |  | 
| Mikhail Kouzmich | 4d0b4af | 2007-02-02 19:48:21 +0300 | [diff] [blame] | 1242 | 	status = acpi_ps_complete_final_op(walk_state, op, status); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 1243 | 	return_ACPI_STATUS(status); | 
| Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 1244 | } |