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 | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
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 | /* |
| 45 | * Parse the AML and build an operation tree as most interpreters, |
| 46 | * like Perl, do. Parsing is done by hand rather than with a YACC |
| 47 | * generated parser to tightly constrain stack and dynamic memory |
| 48 | * usage. At the same time, parsing is kept flexible and the code |
| 49 | * fairly compact by parsing based on a list of AML opcode |
| 50 | * templates in aml_op_info[] |
| 51 | */ |
| 52 | |
| 53 | #include <acpi/acpi.h> |
| 54 | #include <acpi/acparser.h> |
| 55 | #include <acpi/acdispat.h> |
| 56 | #include <acpi/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 | |
| 63 | /******************************************************************************* |
| 64 | * |
| 65 | * FUNCTION: acpi_ps_parse_loop |
| 66 | * |
| 67 | * PARAMETERS: walk_state - Current state |
| 68 | * |
| 69 | * RETURN: Status |
| 70 | * |
| 71 | * DESCRIPTION: Parse AML (pointed to by the current parser state) and return |
| 72 | * a tree of ops. |
| 73 | * |
| 74 | ******************************************************************************/ |
| 75 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 76 | acpi_status acpi_ps_parse_loop(struct acpi_walk_state *walk_state) |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 77 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | acpi_status status = AE_OK; |
| 79 | acpi_status status2; |
| 80 | union acpi_parse_object *op = NULL; /* current op */ |
| 81 | union acpi_parse_object *arg = NULL; |
| 82 | union acpi_parse_object *pre_op = NULL; |
| 83 | struct acpi_parse_state *parser_state; |
| 84 | u8 *aml_op_start = NULL; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 85 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 86 | ACPI_FUNCTION_TRACE_PTR("ps_parse_loop", walk_state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 87 | |
| 88 | if (walk_state->descending_callback == NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 89 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | parser_state = &walk_state->parser_state; |
| 93 | walk_state->arg_types = 0; |
| 94 | |
| 95 | #if (!defined (ACPI_NO_METHOD_EXECUTION) && !defined (ACPI_CONSTANT_EVAL_ONLY)) |
| 96 | |
| 97 | if (walk_state->walk_type & ACPI_WALK_METHOD_RESTART) { |
| 98 | /* We are restarting a preempted control method */ |
| 99 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 100 | if (acpi_ps_has_completed_scope(parser_state)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 101 | /* |
| 102 | * We must check if a predicate to an IF or WHILE statement |
| 103 | * was just completed |
| 104 | */ |
| 105 | if ((parser_state->scope->parse_scope.op) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 106 | ((parser_state->scope->parse_scope.op->common. |
| 107 | aml_opcode == AML_IF_OP) |
| 108 | || (parser_state->scope->parse_scope.op->common. |
| 109 | aml_opcode == AML_WHILE_OP)) |
| 110 | && (walk_state->control_state) |
| 111 | && (walk_state->control_state->common.state == |
| 112 | ACPI_CONTROL_PREDICATE_EXECUTING)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 113 | /* |
| 114 | * A predicate was just completed, get the value of the |
| 115 | * predicate and branch based on that value |
| 116 | */ |
| 117 | walk_state->op = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 118 | status = |
| 119 | acpi_ds_get_predicate_value(walk_state, |
| 120 | ACPI_TO_POINTER |
| 121 | (TRUE)); |
| 122 | if (ACPI_FAILURE(status) |
| 123 | && ((status & AE_CODE_MASK) != |
| 124 | AE_CODE_CONTROL)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 125 | if (status == AE_AML_NO_RETURN_VALUE) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 126 | ACPI_EXCEPTION((AE_INFO, status, |
| 127 | "Invoked method did not return a value")); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 128 | |
| 129 | } |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 130 | ACPI_EXCEPTION((AE_INFO, status, |
| 131 | "get_predicate Failed")); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 132 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 133 | } |
| 134 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | status = |
| 136 | acpi_ps_next_parse_state(walk_state, op, |
| 137 | status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 138 | } |
| 139 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 140 | acpi_ps_pop_scope(parser_state, &op, |
| 141 | &walk_state->arg_types, |
| 142 | &walk_state->arg_count); |
| 143 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 144 | "Popped scope, Op=%p\n", op)); |
| 145 | } else if (walk_state->prev_op) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 146 | /* We were in the middle of an op */ |
| 147 | |
| 148 | op = walk_state->prev_op; |
| 149 | walk_state->arg_types = walk_state->prev_arg_types; |
| 150 | } |
| 151 | } |
| 152 | #endif |
| 153 | |
| 154 | /* Iterative parsing loop, while there is more AML to process: */ |
| 155 | |
| 156 | while ((parser_state->aml < parser_state->aml_end) || (op)) { |
| 157 | aml_op_start = parser_state->aml; |
| 158 | if (!op) { |
| 159 | /* Get the next opcode from the AML stream */ |
| 160 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 161 | walk_state->aml_offset = |
| 162 | (u32) ACPI_PTR_DIFF(parser_state->aml, |
| 163 | parser_state->aml_start); |
| 164 | walk_state->opcode = acpi_ps_peek_opcode(parser_state); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 165 | |
| 166 | /* |
| 167 | * First cut to determine what we have found: |
| 168 | * 1) A valid AML opcode |
| 169 | * 2) A name string |
| 170 | * 3) An unknown/invalid opcode |
| 171 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | walk_state->op_info = |
| 173 | acpi_ps_get_opcode_info(walk_state->opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 174 | switch (walk_state->op_info->class) { |
| 175 | case AML_CLASS_ASCII: |
| 176 | case AML_CLASS_PREFIX: |
| 177 | /* |
| 178 | * Starts with a valid prefix or ASCII char, this is a name |
| 179 | * string. Convert the bare name string to a namepath. |
| 180 | */ |
| 181 | walk_state->opcode = AML_INT_NAMEPATH_OP; |
| 182 | walk_state->arg_types = ARGP_NAMESTRING; |
| 183 | break; |
| 184 | |
| 185 | case AML_CLASS_UNKNOWN: |
| 186 | |
| 187 | /* The opcode is unrecognized. Just skip unknown opcodes */ |
| 188 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 189 | ACPI_ERROR((AE_INFO, |
| 190 | "Found unknown opcode %X at AML address %p offset %X, ignoring", |
| 191 | walk_state->opcode, |
| 192 | parser_state->aml, |
| 193 | walk_state->aml_offset)); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 194 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | ACPI_DUMP_BUFFER(parser_state->aml, 128); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 196 | |
| 197 | /* Assume one-byte bad opcode */ |
| 198 | |
| 199 | parser_state->aml++; |
| 200 | continue; |
| 201 | |
| 202 | default: |
| 203 | |
| 204 | /* Found opcode info, this is a normal opcode */ |
| 205 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 206 | parser_state->aml += |
| 207 | acpi_ps_get_opcode_size(walk_state->opcode); |
| 208 | walk_state->arg_types = |
| 209 | walk_state->op_info->parse_args; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 210 | break; |
| 211 | } |
| 212 | |
| 213 | /* Create Op structure and append to parent's argument list */ |
| 214 | |
| 215 | if (walk_state->op_info->flags & AML_NAMED) { |
| 216 | /* Allocate a new pre_op if necessary */ |
| 217 | |
| 218 | if (!pre_op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | pre_op = |
| 220 | acpi_ps_alloc_op(walk_state-> |
| 221 | opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 222 | if (!pre_op) { |
| 223 | status = AE_NO_MEMORY; |
| 224 | goto close_this_op; |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | pre_op->common.value.arg = NULL; |
| 229 | pre_op->common.aml_opcode = walk_state->opcode; |
| 230 | |
| 231 | /* |
| 232 | * Get and append arguments until we find the node that contains |
| 233 | * the name (the type ARGP_NAME). |
| 234 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | while (GET_CURRENT_ARG_TYPE |
| 236 | (walk_state->arg_types) |
| 237 | && |
| 238 | (GET_CURRENT_ARG_TYPE |
| 239 | (walk_state->arg_types) != ARGP_NAME)) { |
| 240 | status = |
| 241 | acpi_ps_get_next_arg(walk_state, |
| 242 | parser_state, |
| 243 | GET_CURRENT_ARG_TYPE |
| 244 | (walk_state-> |
| 245 | arg_types), |
| 246 | &arg); |
| 247 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 248 | goto close_this_op; |
| 249 | } |
| 250 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | acpi_ps_append_arg(pre_op, arg); |
| 252 | INCREMENT_ARG_LIST(walk_state-> |
| 253 | arg_types); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 254 | } |
| 255 | |
| 256 | /* |
| 257 | * Make sure that we found a NAME and didn't run out of |
| 258 | * arguments |
| 259 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 260 | if (!GET_CURRENT_ARG_TYPE |
| 261 | (walk_state->arg_types)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 262 | status = AE_AML_NO_OPERAND; |
| 263 | goto close_this_op; |
| 264 | } |
| 265 | |
| 266 | /* We know that this arg is a name, move to next arg */ |
| 267 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 268 | INCREMENT_ARG_LIST(walk_state->arg_types); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 269 | |
| 270 | /* |
| 271 | * Find the object. This will either insert the object into |
| 272 | * the namespace or simply look it up |
| 273 | */ |
| 274 | walk_state->op = NULL; |
| 275 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 276 | status = |
| 277 | walk_state->descending_callback(walk_state, |
| 278 | &op); |
| 279 | if (ACPI_FAILURE(status)) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 280 | ACPI_EXCEPTION((AE_INFO, status, |
| 281 | "During name lookup/catalog")); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 282 | goto close_this_op; |
| 283 | } |
| 284 | |
| 285 | if (!op) { |
| 286 | continue; |
| 287 | } |
| 288 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 289 | status = |
| 290 | acpi_ps_next_parse_state(walk_state, op, |
| 291 | status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 292 | if (status == AE_CTRL_PENDING) { |
| 293 | status = AE_OK; |
| 294 | goto close_this_op; |
| 295 | } |
| 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 298 | goto close_this_op; |
| 299 | } |
| 300 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 301 | acpi_ps_append_arg(op, |
| 302 | pre_op->common.value.arg); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 303 | acpi_gbl_depth++; |
| 304 | |
| 305 | if (op->common.aml_opcode == AML_REGION_OP) { |
| 306 | /* |
| 307 | * Defer final parsing of an operation_region body, |
| 308 | * because we don't have enough info in the first pass |
| 309 | * to parse it correctly (i.e., there may be method |
| 310 | * calls within the term_arg elements of the body.) |
| 311 | * |
| 312 | * However, we must continue parsing because |
| 313 | * the opregion is not a standalone package -- |
| 314 | * we don't know where the end is at this point. |
| 315 | * |
| 316 | * (Length is unknown until parse of the body complete) |
| 317 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 318 | op->named.data = aml_op_start; |
| 319 | op->named.length = 0; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 320 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 321 | } else { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 322 | /* Not a named opcode, just allocate Op and append to parent */ |
| 323 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | walk_state->op_info = |
| 325 | acpi_ps_get_opcode_info(walk_state->opcode); |
| 326 | op = acpi_ps_alloc_op(walk_state->opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 327 | if (!op) { |
| 328 | status = AE_NO_MEMORY; |
| 329 | goto close_this_op; |
| 330 | } |
| 331 | |
| 332 | if (walk_state->op_info->flags & AML_CREATE) { |
| 333 | /* |
| 334 | * Backup to beginning of create_xXXfield declaration |
| 335 | * body_length is unknown until we parse the body |
| 336 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 337 | op->named.data = aml_op_start; |
| 338 | op->named.length = 0; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 339 | } |
| 340 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 341 | acpi_ps_append_arg(acpi_ps_get_parent_scope |
| 342 | (parser_state), op); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 343 | |
| 344 | if ((walk_state->descending_callback != NULL)) { |
| 345 | /* |
| 346 | * Find the object. This will either insert the object into |
| 347 | * the namespace or simply look it up |
| 348 | */ |
| 349 | walk_state->op = op; |
| 350 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | status = |
| 352 | walk_state-> |
| 353 | descending_callback(walk_state, |
| 354 | &op); |
| 355 | status = |
| 356 | acpi_ps_next_parse_state(walk_state, |
| 357 | op, |
| 358 | status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 359 | if (status == AE_CTRL_PENDING) { |
| 360 | status = AE_OK; |
| 361 | goto close_this_op; |
| 362 | } |
| 363 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 364 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 365 | goto close_this_op; |
| 366 | } |
| 367 | } |
| 368 | } |
| 369 | |
| 370 | op->common.aml_offset = walk_state->aml_offset; |
| 371 | |
| 372 | if (walk_state->op_info) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 373 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 374 | "Opcode %4.4X [%s] Op %p Aml %p aml_offset %5.5X\n", |
| 375 | (u32) op->common.aml_opcode, |
| 376 | walk_state->op_info->name, op, |
| 377 | parser_state->aml, |
| 378 | op->common.aml_offset)); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 379 | } |
| 380 | } |
| 381 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 382 | /* |
| 383 | * Start arg_count at zero because we don't know if there are |
| 384 | * any args yet |
| 385 | */ |
| 386 | walk_state->arg_count = 0; |
| 387 | |
| 388 | /* Are there any arguments that must be processed? */ |
| 389 | |
| 390 | if (walk_state->arg_types) { |
| 391 | /* Get arguments */ |
| 392 | |
| 393 | switch (op->common.aml_opcode) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | case AML_BYTE_OP: /* AML_BYTEDATA_ARG */ |
| 395 | case AML_WORD_OP: /* AML_WORDDATA_ARG */ |
| 396 | case AML_DWORD_OP: /* AML_DWORDATA_ARG */ |
| 397 | case AML_QWORD_OP: /* AML_QWORDATA_ARG */ |
| 398 | case AML_STRING_OP: /* AML_ASCIICHARLIST_ARG */ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 399 | |
| 400 | /* Fill in constant or string argument directly */ |
| 401 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | acpi_ps_get_next_simple_arg(parser_state, |
| 403 | GET_CURRENT_ARG_TYPE |
| 404 | (walk_state-> |
| 405 | arg_types), op); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 406 | break; |
| 407 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | case AML_INT_NAMEPATH_OP: /* AML_NAMESTRING_ARG */ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 409 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 410 | status = |
| 411 | acpi_ps_get_next_namepath(walk_state, |
| 412 | parser_state, op, |
| 413 | 1); |
| 414 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 415 | goto close_this_op; |
| 416 | } |
| 417 | |
| 418 | walk_state->arg_types = 0; |
| 419 | break; |
| 420 | |
| 421 | default: |
| 422 | /* |
| 423 | * Op is not a constant or string, append each argument |
| 424 | * to the Op |
| 425 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 426 | while (GET_CURRENT_ARG_TYPE |
| 427 | (walk_state->arg_types) |
| 428 | && !walk_state->arg_count) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 429 | walk_state->aml_offset = (u32) |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 430 | ACPI_PTR_DIFF(parser_state->aml, |
| 431 | parser_state-> |
| 432 | aml_start); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 433 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 434 | status = |
| 435 | acpi_ps_get_next_arg(walk_state, |
| 436 | parser_state, |
| 437 | GET_CURRENT_ARG_TYPE |
| 438 | (walk_state-> |
| 439 | arg_types), |
| 440 | &arg); |
| 441 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 442 | goto close_this_op; |
| 443 | } |
| 444 | |
| 445 | if (arg) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 446 | arg->common.aml_offset = |
| 447 | walk_state->aml_offset; |
| 448 | acpi_ps_append_arg(op, arg); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 449 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | INCREMENT_ARG_LIST(walk_state-> |
| 451 | arg_types); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 452 | } |
| 453 | |
| 454 | /* Special processing for certain opcodes */ |
| 455 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | /* TBD (remove): Temporary mechanism to disable this code if needed */ |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 457 | |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 458 | #ifdef ACPI_ENABLE_MODULE_LEVEL_CODE |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 459 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 460 | if ((walk_state->pass_number <= |
| 461 | ACPI_IMODE_LOAD_PASS1) |
| 462 | && |
| 463 | ((walk_state-> |
| 464 | parse_flags & ACPI_PARSE_DISASSEMBLE) == |
| 465 | 0)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 466 | /* |
| 467 | * We want to skip If/Else/While constructs during Pass1 |
| 468 | * because we want to actually conditionally execute the |
| 469 | * code during Pass2. |
| 470 | * |
| 471 | * Except for disassembly, where we always want to |
| 472 | * walk the If/Else/While packages |
| 473 | */ |
| 474 | switch (op->common.aml_opcode) { |
| 475 | case AML_IF_OP: |
| 476 | case AML_ELSE_OP: |
| 477 | case AML_WHILE_OP: |
| 478 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 479 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 480 | "Pass1: Skipping an If/Else/While body\n")); |
Robert Moore | 0c9938c | 2005-07-29 15:15:00 -0700 | [diff] [blame] | 481 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 482 | /* Skip body of if/else/while in pass 1 */ |
| 483 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | parser_state->aml = |
| 485 | parser_state->pkg_end; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 486 | walk_state->arg_count = 0; |
| 487 | break; |
| 488 | |
| 489 | default: |
| 490 | break; |
| 491 | } |
| 492 | } |
Robert Moore | f9f4601 | 2005-07-08 00:00:00 -0400 | [diff] [blame] | 493 | #endif |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 494 | switch (op->common.aml_opcode) { |
| 495 | case AML_METHOD_OP: |
| 496 | |
| 497 | /* |
| 498 | * Skip parsing of control method |
| 499 | * because we don't have enough info in the first pass |
| 500 | * to parse it correctly. |
| 501 | * |
| 502 | * Save the length and address of the body |
| 503 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 504 | op->named.data = parser_state->aml; |
| 505 | op->named.length = |
| 506 | (u32) (parser_state->pkg_end - |
| 507 | parser_state->aml); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 508 | |
| 509 | /* Skip body of method */ |
| 510 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 511 | parser_state->aml = |
| 512 | parser_state->pkg_end; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 513 | walk_state->arg_count = 0; |
| 514 | break; |
| 515 | |
| 516 | case AML_BUFFER_OP: |
| 517 | case AML_PACKAGE_OP: |
| 518 | case AML_VAR_PACKAGE_OP: |
| 519 | |
| 520 | if ((op->common.parent) && |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 521 | (op->common.parent->common. |
| 522 | aml_opcode == AML_NAME_OP) |
| 523 | && (walk_state->pass_number <= |
| 524 | ACPI_IMODE_LOAD_PASS2)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 525 | /* |
| 526 | * Skip parsing of Buffers and Packages |
| 527 | * because we don't have enough info in the first pass |
| 528 | * to parse them correctly. |
| 529 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 530 | op->named.data = aml_op_start; |
| 531 | op->named.length = |
| 532 | (u32) (parser_state-> |
| 533 | pkg_end - |
| 534 | aml_op_start); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 535 | |
| 536 | /* Skip body */ |
| 537 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 538 | parser_state->aml = |
| 539 | parser_state->pkg_end; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 540 | walk_state->arg_count = 0; |
| 541 | } |
| 542 | break; |
| 543 | |
| 544 | case AML_WHILE_OP: |
| 545 | |
| 546 | if (walk_state->control_state) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 547 | walk_state->control_state-> |
| 548 | control.package_end = |
| 549 | parser_state->pkg_end; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 550 | } |
| 551 | break; |
| 552 | |
| 553 | default: |
| 554 | |
| 555 | /* No action for all other opcodes */ |
| 556 | break; |
| 557 | } |
| 558 | break; |
| 559 | } |
| 560 | } |
| 561 | |
| 562 | /* Check for arguments that need to be processed */ |
| 563 | |
| 564 | if (walk_state->arg_count) { |
| 565 | /* |
| 566 | * There are arguments (complex ones), push Op and |
| 567 | * prepare for argument |
| 568 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 569 | status = acpi_ps_push_scope(parser_state, op, |
| 570 | walk_state->arg_types, |
| 571 | walk_state->arg_count); |
| 572 | if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 573 | goto close_this_op; |
| 574 | } |
| 575 | op = NULL; |
| 576 | continue; |
| 577 | } |
| 578 | |
| 579 | /* |
| 580 | * All arguments have been processed -- Op is complete, |
| 581 | * prepare for next |
| 582 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 583 | walk_state->op_info = |
| 584 | acpi_ps_get_opcode_info(op->common.aml_opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 585 | if (walk_state->op_info->flags & AML_NAMED) { |
| 586 | if (acpi_gbl_depth) { |
| 587 | acpi_gbl_depth--; |
| 588 | } |
| 589 | |
| 590 | if (op->common.aml_opcode == AML_REGION_OP) { |
| 591 | /* |
| 592 | * Skip parsing of control method or opregion body, |
| 593 | * because we don't have enough info in the first pass |
| 594 | * to parse them correctly. |
| 595 | * |
| 596 | * Completed parsing an op_region declaration, we now |
| 597 | * know the length. |
| 598 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | op->named.length = |
| 600 | (u32) (parser_state->aml - op->named.data); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 601 | } |
| 602 | } |
| 603 | |
| 604 | if (walk_state->op_info->flags & AML_CREATE) { |
| 605 | /* |
| 606 | * Backup to beginning of create_xXXfield declaration (1 for |
| 607 | * Opcode) |
| 608 | * |
| 609 | * body_length is unknown until we parse the body |
| 610 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | op->named.length = |
| 612 | (u32) (parser_state->aml - op->named.data); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 613 | } |
| 614 | |
| 615 | /* This op complete, notify the dispatcher */ |
| 616 | |
| 617 | if (walk_state->ascending_callback != NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 618 | walk_state->op = op; |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 619 | walk_state->opcode = op->common.aml_opcode; |
| 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | status = walk_state->ascending_callback(walk_state); |
| 622 | status = |
| 623 | acpi_ps_next_parse_state(walk_state, op, status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 624 | if (status == AE_CTRL_PENDING) { |
| 625 | status = AE_OK; |
| 626 | goto close_this_op; |
| 627 | } |
| 628 | } |
| 629 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 630 | close_this_op: |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 631 | /* |
| 632 | * Finished one argument of the containing scope |
| 633 | */ |
| 634 | parser_state->scope->parse_scope.arg_count--; |
| 635 | |
| 636 | /* Finished with pre_op */ |
| 637 | |
| 638 | if (pre_op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 639 | acpi_ps_free_op(pre_op); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 640 | pre_op = NULL; |
| 641 | } |
| 642 | |
| 643 | /* Close this Op (will result in parse subtree deletion) */ |
| 644 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 645 | status2 = acpi_ps_complete_this_op(walk_state, op); |
| 646 | if (ACPI_FAILURE(status2)) { |
| 647 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 648 | } |
| 649 | op = NULL; |
| 650 | |
| 651 | switch (status) { |
| 652 | case AE_OK: |
| 653 | break; |
| 654 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 655 | case AE_CTRL_TRANSFER: |
| 656 | |
| 657 | /* We are about to transfer to a called method. */ |
| 658 | |
| 659 | walk_state->prev_op = op; |
| 660 | walk_state->prev_arg_types = walk_state->arg_types; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 662 | |
| 663 | case AE_CTRL_END: |
| 664 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | acpi_ps_pop_scope(parser_state, &op, |
| 666 | &walk_state->arg_types, |
| 667 | &walk_state->arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 668 | |
| 669 | if (op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 670 | walk_state->op = op; |
| 671 | walk_state->op_info = |
| 672 | acpi_ps_get_opcode_info(op->common. |
| 673 | aml_opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 674 | walk_state->opcode = op->common.aml_opcode; |
| 675 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 676 | status = |
| 677 | walk_state->ascending_callback(walk_state); |
| 678 | status = |
| 679 | acpi_ps_next_parse_state(walk_state, op, |
| 680 | status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 681 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 682 | status2 = |
| 683 | acpi_ps_complete_this_op(walk_state, op); |
| 684 | if (ACPI_FAILURE(status2)) { |
| 685 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 686 | } |
| 687 | op = NULL; |
| 688 | } |
| 689 | status = AE_OK; |
| 690 | break; |
| 691 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 692 | case AE_CTRL_BREAK: |
| 693 | case AE_CTRL_CONTINUE: |
| 694 | |
| 695 | /* Pop off scopes until we find the While */ |
| 696 | |
| 697 | while (!op || (op->common.aml_opcode != AML_WHILE_OP)) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | acpi_ps_pop_scope(parser_state, &op, |
| 699 | &walk_state->arg_types, |
| 700 | &walk_state->arg_count); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 701 | |
| 702 | if (op->common.aml_opcode != AML_WHILE_OP) { |
| 703 | status2 = |
| 704 | acpi_ds_result_stack_pop |
| 705 | (walk_state); |
| 706 | if (ACPI_FAILURE(status2)) { |
| 707 | return_ACPI_STATUS(status2); |
| 708 | } |
| 709 | } |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /* Close this iteration of the While loop */ |
| 713 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 714 | walk_state->op = op; |
| 715 | walk_state->op_info = |
| 716 | acpi_ps_get_opcode_info(op->common.aml_opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 717 | walk_state->opcode = op->common.aml_opcode; |
| 718 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | status = walk_state->ascending_callback(walk_state); |
| 720 | status = |
| 721 | acpi_ps_next_parse_state(walk_state, op, status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 722 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 723 | status2 = acpi_ps_complete_this_op(walk_state, op); |
| 724 | if (ACPI_FAILURE(status2)) { |
| 725 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 726 | } |
| 727 | op = NULL; |
| 728 | |
| 729 | status = AE_OK; |
| 730 | break; |
| 731 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 732 | case AE_CTRL_TERMINATE: |
| 733 | |
| 734 | status = AE_OK; |
| 735 | |
| 736 | /* Clean up */ |
| 737 | do { |
| 738 | if (op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 739 | status2 = |
| 740 | acpi_ps_complete_this_op(walk_state, |
| 741 | op); |
| 742 | if (ACPI_FAILURE(status2)) { |
| 743 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 744 | } |
| 745 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 746 | acpi_ps_pop_scope(parser_state, &op, |
| 747 | &walk_state->arg_types, |
| 748 | &walk_state->arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 749 | |
| 750 | } while (op); |
| 751 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 752 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 753 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 754 | default: /* All other non-AE_OK status */ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 755 | |
| 756 | do { |
| 757 | if (op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 758 | status2 = |
| 759 | acpi_ps_complete_this_op(walk_state, |
| 760 | op); |
| 761 | if (ACPI_FAILURE(status2)) { |
| 762 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 763 | } |
| 764 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 765 | acpi_ps_pop_scope(parser_state, &op, |
| 766 | &walk_state->arg_types, |
| 767 | &walk_state->arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 768 | |
| 769 | } while (op); |
| 770 | |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 771 | /* |
| 772 | * TBD: Cleanup parse ops on error |
| 773 | */ |
| 774 | #if 0 |
| 775 | if (op == NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 776 | acpi_ps_pop_scope(parser_state, &op, |
| 777 | &walk_state->arg_types, |
| 778 | &walk_state->arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 779 | } |
| 780 | #endif |
| 781 | walk_state->prev_op = op; |
| 782 | walk_state->prev_arg_types = walk_state->arg_types; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 783 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 784 | } |
| 785 | |
| 786 | /* This scope complete? */ |
| 787 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 788 | if (acpi_ps_has_completed_scope(parser_state)) { |
| 789 | acpi_ps_pop_scope(parser_state, &op, |
| 790 | &walk_state->arg_types, |
| 791 | &walk_state->arg_count); |
| 792 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, |
| 793 | "Popped scope, Op=%p\n", op)); |
| 794 | } else { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 795 | op = NULL; |
| 796 | } |
| 797 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 798 | } /* while parser_state->Aml */ |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 799 | |
| 800 | /* |
| 801 | * Complete the last Op (if not completed), and clear the scope stack. |
| 802 | * It is easily possible to end an AML "package" with an unbounded number |
| 803 | * of open scopes (such as when several ASL blocks are closed with |
| 804 | * sequential closing braces). We want to terminate each one cleanly. |
| 805 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 806 | ACPI_DEBUG_PRINT((ACPI_DB_PARSE, "AML package complete at Op %p\n", |
| 807 | op)); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 808 | do { |
| 809 | if (op) { |
| 810 | if (walk_state->ascending_callback != NULL) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 811 | walk_state->op = op; |
| 812 | walk_state->op_info = |
| 813 | acpi_ps_get_opcode_info(op->common. |
| 814 | aml_opcode); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 815 | walk_state->opcode = op->common.aml_opcode; |
| 816 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 817 | status = |
| 818 | walk_state->ascending_callback(walk_state); |
| 819 | status = |
| 820 | acpi_ps_next_parse_state(walk_state, op, |
| 821 | status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 822 | if (status == AE_CTRL_PENDING) { |
| 823 | status = AE_OK; |
| 824 | goto close_this_op; |
| 825 | } |
| 826 | |
| 827 | if (status == AE_CTRL_TERMINATE) { |
| 828 | status = AE_OK; |
| 829 | |
| 830 | /* Clean up */ |
| 831 | do { |
| 832 | if (op) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 833 | status2 = |
| 834 | acpi_ps_complete_this_op |
| 835 | (walk_state, op); |
| 836 | if (ACPI_FAILURE |
| 837 | (status2)) { |
| 838 | return_ACPI_STATUS |
| 839 | (status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 840 | } |
| 841 | } |
| 842 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 843 | acpi_ps_pop_scope(parser_state, |
| 844 | &op, |
| 845 | &walk_state-> |
| 846 | arg_types, |
| 847 | &walk_state-> |
| 848 | arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 849 | |
| 850 | } while (op); |
| 851 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 852 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 853 | } |
| 854 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 855 | else if (ACPI_FAILURE(status)) { |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 856 | /* First error is most important */ |
| 857 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 858 | (void) |
| 859 | acpi_ps_complete_this_op(walk_state, |
| 860 | op); |
| 861 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 862 | } |
| 863 | } |
| 864 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 865 | status2 = acpi_ps_complete_this_op(walk_state, op); |
| 866 | if (ACPI_FAILURE(status2)) { |
| 867 | return_ACPI_STATUS(status2); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 868 | } |
| 869 | } |
| 870 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 871 | acpi_ps_pop_scope(parser_state, &op, &walk_state->arg_types, |
| 872 | &walk_state->arg_count); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 873 | |
| 874 | } while (op); |
| 875 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 876 | return_ACPI_STATUS(status); |
Robert Moore | 73459f7 | 2005-06-24 00:00:00 -0400 | [diff] [blame] | 877 | } |