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