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