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