Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dswexec - Dispatcher method execution callbacks; |
| 4 | * dispatch to interpreter. |
| 5 | * |
| 6 | *****************************************************************************/ |
| 7 | |
| 8 | /* |
| 9 | * Copyright (C) 2000 - 2005, R. Byron Moore |
| 10 | * All rights reserved. |
| 11 | * |
| 12 | * Redistribution and use in source and binary forms, with or without |
| 13 | * modification, are permitted provided that the following conditions |
| 14 | * are met: |
| 15 | * 1. Redistributions of source code must retain the above copyright |
| 16 | * notice, this list of conditions, and the following disclaimer, |
| 17 | * without modification. |
| 18 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 19 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 20 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 21 | * including a substantially similar Disclaimer requirement for further |
| 22 | * binary redistribution. |
| 23 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 24 | * of any contributors may be used to endorse or promote products derived |
| 25 | * from this software without specific prior written permission. |
| 26 | * |
| 27 | * Alternatively, this software may be distributed under the terms of the |
| 28 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 29 | * Software Foundation. |
| 30 | * |
| 31 | * NO WARRANTY |
| 32 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 33 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 34 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 35 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 36 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 37 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 38 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 39 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 40 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 41 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 42 | * POSSIBILITY OF SUCH DAMAGES. |
| 43 | */ |
| 44 | |
| 45 | |
| 46 | #include <acpi/acpi.h> |
| 47 | #include <acpi/acparser.h> |
| 48 | #include <acpi/amlcode.h> |
| 49 | #include <acpi/acdispat.h> |
| 50 | #include <acpi/acinterp.h> |
| 51 | #include <acpi/acnamesp.h> |
| 52 | #include <acpi/acdebug.h> |
| 53 | #include <acpi/acdisasm.h> |
| 54 | |
| 55 | |
| 56 | #define _COMPONENT ACPI_DISPATCHER |
| 57 | ACPI_MODULE_NAME ("dswexec") |
| 58 | |
| 59 | /* |
| 60 | * Dispatch table for opcode classes |
| 61 | */ |
| 62 | static ACPI_EXECUTE_OP acpi_gbl_op_type_dispatch [] = { |
| 63 | acpi_ex_opcode_0A_0T_1R, |
| 64 | acpi_ex_opcode_1A_0T_0R, |
| 65 | acpi_ex_opcode_1A_0T_1R, |
| 66 | acpi_ex_opcode_1A_1T_0R, |
| 67 | acpi_ex_opcode_1A_1T_1R, |
| 68 | acpi_ex_opcode_2A_0T_0R, |
| 69 | acpi_ex_opcode_2A_0T_1R, |
| 70 | acpi_ex_opcode_2A_1T_1R, |
| 71 | acpi_ex_opcode_2A_2T_1R, |
| 72 | acpi_ex_opcode_3A_0T_0R, |
| 73 | acpi_ex_opcode_3A_1T_1R, |
| 74 | acpi_ex_opcode_6A_0T_1R}; |
| 75 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 76 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | /***************************************************************************** |
| 78 | * |
| 79 | * FUNCTION: acpi_ds_get_predicate_value |
| 80 | * |
| 81 | * PARAMETERS: walk_state - Current state of the parse tree walk |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 82 | * result_obj - if non-zero, pop result from result stack |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | * |
| 84 | * RETURN: Status |
| 85 | * |
| 86 | * DESCRIPTION: Get the result of a predicate evaluation |
| 87 | * |
| 88 | ****************************************************************************/ |
| 89 | |
| 90 | acpi_status |
| 91 | acpi_ds_get_predicate_value ( |
| 92 | struct acpi_walk_state *walk_state, |
| 93 | union acpi_operand_object *result_obj) { |
| 94 | acpi_status status = AE_OK; |
| 95 | union acpi_operand_object *obj_desc; |
| 96 | union acpi_operand_object *local_obj_desc = NULL; |
| 97 | |
| 98 | |
| 99 | ACPI_FUNCTION_TRACE_PTR ("ds_get_predicate_value", walk_state); |
| 100 | |
| 101 | |
| 102 | walk_state->control_state->common.state = 0; |
| 103 | |
| 104 | if (result_obj) { |
| 105 | status = acpi_ds_result_pop (&obj_desc, walk_state); |
| 106 | if (ACPI_FAILURE (status)) { |
| 107 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 108 | "Could not get result from predicate evaluation, %s\n", |
| 109 | acpi_format_exception (status))); |
| 110 | |
| 111 | return_ACPI_STATUS (status); |
| 112 | } |
| 113 | } |
| 114 | else { |
| 115 | status = acpi_ds_create_operand (walk_state, walk_state->op, 0); |
| 116 | if (ACPI_FAILURE (status)) { |
| 117 | return_ACPI_STATUS (status); |
| 118 | } |
| 119 | |
| 120 | status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state); |
| 121 | if (ACPI_FAILURE (status)) { |
| 122 | return_ACPI_STATUS (status); |
| 123 | } |
| 124 | |
| 125 | obj_desc = walk_state->operands [0]; |
| 126 | } |
| 127 | |
| 128 | if (!obj_desc) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 129 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 130 | "No predicate obj_desc=%p State=%p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | obj_desc, walk_state)); |
| 132 | |
| 133 | return_ACPI_STATUS (AE_AML_NO_OPERAND); |
| 134 | } |
| 135 | |
| 136 | /* |
| 137 | * Result of predicate evaluation must be an Integer |
| 138 | * object. Implicitly convert the argument if necessary. |
| 139 | */ |
| 140 | status = acpi_ex_convert_to_integer (obj_desc, &local_obj_desc, 16); |
| 141 | if (ACPI_FAILURE (status)) { |
| 142 | goto cleanup; |
| 143 | } |
| 144 | |
| 145 | if (ACPI_GET_OBJECT_TYPE (local_obj_desc) != ACPI_TYPE_INTEGER) { |
| 146 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 147 | "Bad predicate (not an integer) obj_desc=%p State=%p Type=%X\n", |
| 148 | obj_desc, walk_state, ACPI_GET_OBJECT_TYPE (obj_desc))); |
| 149 | |
| 150 | status = AE_AML_OPERAND_TYPE; |
| 151 | goto cleanup; |
| 152 | } |
| 153 | |
| 154 | /* Truncate the predicate to 32-bits if necessary */ |
| 155 | |
| 156 | acpi_ex_truncate_for32bit_table (local_obj_desc); |
| 157 | |
| 158 | /* |
| 159 | * Save the result of the predicate evaluation on |
| 160 | * the control stack |
| 161 | */ |
| 162 | if (local_obj_desc->integer.value) { |
| 163 | walk_state->control_state->common.value = TRUE; |
| 164 | } |
| 165 | else { |
| 166 | /* |
| 167 | * Predicate is FALSE, we will just toss the |
| 168 | * rest of the package |
| 169 | */ |
| 170 | walk_state->control_state->common.value = FALSE; |
| 171 | status = AE_CTRL_FALSE; |
| 172 | } |
| 173 | |
| 174 | |
| 175 | cleanup: |
| 176 | |
| 177 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Completed a predicate eval=%X Op=%p\n", |
| 178 | walk_state->control_state->common.value, walk_state->op)); |
| 179 | |
| 180 | /* Break to debugger to display result */ |
| 181 | |
| 182 | ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (local_obj_desc, walk_state)); |
| 183 | |
| 184 | /* |
| 185 | * Delete the predicate result object (we know that |
| 186 | * we don't need it anymore) |
| 187 | */ |
| 188 | if (local_obj_desc != obj_desc) { |
| 189 | acpi_ut_remove_reference (local_obj_desc); |
| 190 | } |
| 191 | acpi_ut_remove_reference (obj_desc); |
| 192 | |
| 193 | walk_state->control_state->common.state = ACPI_CONTROL_NORMAL; |
| 194 | return_ACPI_STATUS (status); |
| 195 | } |
| 196 | |
| 197 | |
| 198 | /***************************************************************************** |
| 199 | * |
| 200 | * FUNCTION: acpi_ds_exec_begin_op |
| 201 | * |
| 202 | * PARAMETERS: walk_state - Current state of the parse tree walk |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 203 | * out_op - Where to return op if a new one is created |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | * |
| 205 | * RETURN: Status |
| 206 | * |
| 207 | * DESCRIPTION: Descending callback used during the execution of control |
| 208 | * methods. This is where most operators and operands are |
| 209 | * dispatched to the interpreter. |
| 210 | * |
| 211 | ****************************************************************************/ |
| 212 | |
| 213 | acpi_status |
| 214 | acpi_ds_exec_begin_op ( |
| 215 | struct acpi_walk_state *walk_state, |
| 216 | union acpi_parse_object **out_op) |
| 217 | { |
| 218 | union acpi_parse_object *op; |
| 219 | acpi_status status = AE_OK; |
| 220 | u32 opcode_class; |
| 221 | |
| 222 | |
| 223 | ACPI_FUNCTION_TRACE_PTR ("ds_exec_begin_op", walk_state); |
| 224 | |
| 225 | |
| 226 | op = walk_state->op; |
| 227 | if (!op) { |
| 228 | status = acpi_ds_load2_begin_op (walk_state, out_op); |
| 229 | if (ACPI_FAILURE (status)) { |
| 230 | return_ACPI_STATUS (status); |
| 231 | } |
| 232 | |
| 233 | op = *out_op; |
| 234 | walk_state->op = op; |
| 235 | walk_state->opcode = op->common.aml_opcode; |
| 236 | walk_state->op_info = acpi_ps_get_opcode_info (op->common.aml_opcode); |
| 237 | |
| 238 | if (acpi_ns_opens_scope (walk_state->op_info->object_type)) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 239 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 240 | "(%s) Popping scope for Op %p\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | acpi_ut_get_type_name (walk_state->op_info->object_type), op)); |
| 242 | |
| 243 | status = acpi_ds_scope_stack_pop (walk_state); |
| 244 | if (ACPI_FAILURE (status)) { |
| 245 | return_ACPI_STATUS (status); |
| 246 | } |
| 247 | } |
| 248 | } |
| 249 | |
| 250 | if (op == walk_state->origin) { |
| 251 | if (out_op) { |
| 252 | *out_op = op; |
| 253 | } |
| 254 | |
| 255 | return_ACPI_STATUS (AE_OK); |
| 256 | } |
| 257 | |
| 258 | /* |
| 259 | * If the previous opcode was a conditional, this opcode |
| 260 | * must be the beginning of the associated predicate. |
| 261 | * Save this knowledge in the current scope descriptor |
| 262 | */ |
| 263 | if ((walk_state->control_state) && |
| 264 | (walk_state->control_state->common.state == |
| 265 | ACPI_CONTROL_CONDITIONAL_EXECUTING)) { |
| 266 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Exec predicate Op=%p State=%p\n", |
| 267 | op, walk_state)); |
| 268 | |
| 269 | walk_state->control_state->common.state = ACPI_CONTROL_PREDICATE_EXECUTING; |
| 270 | |
| 271 | /* Save start of predicate */ |
| 272 | |
| 273 | walk_state->control_state->control.predicate_op = op; |
| 274 | } |
| 275 | |
| 276 | |
| 277 | opcode_class = walk_state->op_info->class; |
| 278 | |
| 279 | /* We want to send namepaths to the load code */ |
| 280 | |
| 281 | if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { |
| 282 | opcode_class = AML_CLASS_NAMED_OBJECT; |
| 283 | } |
| 284 | |
| 285 | /* |
| 286 | * Handle the opcode based upon the opcode type |
| 287 | */ |
| 288 | switch (opcode_class) { |
| 289 | case AML_CLASS_CONTROL: |
| 290 | |
| 291 | status = acpi_ds_result_stack_push (walk_state); |
| 292 | if (ACPI_FAILURE (status)) { |
| 293 | return_ACPI_STATUS (status); |
| 294 | } |
| 295 | |
| 296 | status = acpi_ds_exec_begin_control_op (walk_state, op); |
| 297 | break; |
| 298 | |
| 299 | |
| 300 | case AML_CLASS_NAMED_OBJECT: |
| 301 | |
| 302 | if (walk_state->walk_type == ACPI_WALK_METHOD) { |
| 303 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 304 | * Found a named object declaration during method execution; |
| 305 | * we must enter this object into the namespace. The created |
| 306 | * object is temporary and will be deleted upon completion of |
| 307 | * the execution of this method. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | */ |
| 309 | status = acpi_ds_load2_begin_op (walk_state, NULL); |
| 310 | } |
| 311 | |
| 312 | if (op->common.aml_opcode == AML_REGION_OP) { |
| 313 | status = acpi_ds_result_stack_push (walk_state); |
| 314 | } |
| 315 | break; |
| 316 | |
| 317 | |
| 318 | case AML_CLASS_EXECUTE: |
| 319 | case AML_CLASS_CREATE: |
| 320 | |
| 321 | /* |
| 322 | * Most operators with arguments. |
| 323 | * Start a new result/operand state |
| 324 | */ |
| 325 | status = acpi_ds_result_stack_push (walk_state); |
| 326 | break; |
| 327 | |
| 328 | |
| 329 | default: |
| 330 | break; |
| 331 | } |
| 332 | |
| 333 | /* Nothing to do here during method execution */ |
| 334 | |
| 335 | return_ACPI_STATUS (status); |
| 336 | } |
| 337 | |
| 338 | |
| 339 | /***************************************************************************** |
| 340 | * |
| 341 | * FUNCTION: acpi_ds_exec_end_op |
| 342 | * |
| 343 | * PARAMETERS: walk_state - Current state of the parse tree walk |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 344 | * |
| 345 | * RETURN: Status |
| 346 | * |
| 347 | * DESCRIPTION: Ascending callback used during the execution of control |
| 348 | * methods. The only thing we really need to do here is to |
| 349 | * notice the beginning of IF, ELSE, and WHILE blocks. |
| 350 | * |
| 351 | ****************************************************************************/ |
| 352 | |
| 353 | acpi_status |
| 354 | acpi_ds_exec_end_op ( |
| 355 | struct acpi_walk_state *walk_state) |
| 356 | { |
| 357 | union acpi_parse_object *op; |
| 358 | acpi_status status = AE_OK; |
| 359 | u32 op_type; |
| 360 | u32 op_class; |
| 361 | union acpi_parse_object *next_op; |
| 362 | union acpi_parse_object *first_arg; |
| 363 | |
| 364 | |
| 365 | ACPI_FUNCTION_TRACE_PTR ("ds_exec_end_op", walk_state); |
| 366 | |
| 367 | |
| 368 | op = walk_state->op; |
| 369 | op_type = walk_state->op_info->type; |
| 370 | op_class = walk_state->op_info->class; |
| 371 | |
| 372 | if (op_class == AML_CLASS_UNKNOWN) { |
| 373 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown opcode %X\n", op->common.aml_opcode)); |
| 374 | return_ACPI_STATUS (AE_NOT_IMPLEMENTED); |
| 375 | } |
| 376 | |
| 377 | first_arg = op->common.value.arg; |
| 378 | |
| 379 | /* Init the walk state */ |
| 380 | |
| 381 | walk_state->num_operands = 0; |
| 382 | walk_state->return_desc = NULL; |
| 383 | walk_state->result_obj = NULL; |
| 384 | |
| 385 | /* Call debugger for single step support (DEBUG build only) */ |
| 386 | |
| 387 | ACPI_DEBUGGER_EXEC (status = acpi_db_single_step (walk_state, op, op_class)); |
| 388 | ACPI_DEBUGGER_EXEC (if (ACPI_FAILURE (status)) {return_ACPI_STATUS (status);}); |
| 389 | |
| 390 | /* Decode the Opcode Class */ |
| 391 | |
| 392 | switch (op_class) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 393 | case AML_CLASS_ARGUMENT: /* constants, literals, etc. - do nothing */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | break; |
| 395 | |
| 396 | |
| 397 | case AML_CLASS_EXECUTE: /* most operators with arguments */ |
| 398 | |
| 399 | /* Build resolved operand stack */ |
| 400 | |
| 401 | status = acpi_ds_create_operands (walk_state, first_arg); |
| 402 | if (ACPI_FAILURE (status)) { |
| 403 | goto cleanup; |
| 404 | } |
| 405 | |
| 406 | /* Done with this result state (Now that operand stack is built) */ |
| 407 | |
| 408 | status = acpi_ds_result_stack_pop (walk_state); |
| 409 | if (ACPI_FAILURE (status)) { |
| 410 | goto cleanup; |
| 411 | } |
| 412 | |
| 413 | /* |
| 414 | * All opcodes require operand resolution, with the only exceptions |
| 415 | * being the object_type and size_of operators. |
| 416 | */ |
| 417 | if (!(walk_state->op_info->flags & AML_NO_OPERAND_RESOLVE)) { |
| 418 | /* Resolve all operands */ |
| 419 | |
| 420 | status = acpi_ex_resolve_operands (walk_state->opcode, |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 421 | &(walk_state->operands [walk_state->num_operands -1]), |
| 422 | walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | if (ACPI_SUCCESS (status)) { |
| 424 | ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 425 | acpi_ps_get_opcode_name (walk_state->opcode), |
| 426 | walk_state->num_operands, "after ex_resolve_operands"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | } |
| 428 | } |
| 429 | |
| 430 | if (ACPI_SUCCESS (status)) { |
| 431 | /* |
| 432 | * Dispatch the request to the appropriate interpreter handler |
| 433 | * routine. There is one routine per opcode "type" based upon the |
| 434 | * number of opcode arguments and return type. |
| 435 | */ |
| 436 | status = acpi_gbl_op_type_dispatch[op_type] (walk_state); |
| 437 | } |
| 438 | else { |
| 439 | /* |
| 440 | * Treat constructs of the form "Store(local_x,local_x)" as noops when the |
| 441 | * Local is uninitialized. |
| 442 | */ |
| 443 | if ((status == AE_AML_UNINITIALIZED_LOCAL) && |
| 444 | (walk_state->opcode == AML_STORE_OP) && |
| 445 | (walk_state->operands[0]->common.type == ACPI_TYPE_LOCAL_REFERENCE) && |
| 446 | (walk_state->operands[1]->common.type == ACPI_TYPE_LOCAL_REFERENCE) && |
| 447 | (walk_state->operands[0]->reference.opcode == |
| 448 | walk_state->operands[1]->reference.opcode) && |
| 449 | (walk_state->operands[0]->reference.offset == |
| 450 | walk_state->operands[1]->reference.offset)) { |
| 451 | status = AE_OK; |
| 452 | } |
| 453 | else { |
| 454 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 455 | "[%s]: Could not resolve operands, %s\n", |
| 456 | acpi_ps_get_opcode_name (walk_state->opcode), |
| 457 | acpi_format_exception (status))); |
| 458 | } |
| 459 | } |
| 460 | |
| 461 | /* Always delete the argument objects and clear the operand stack */ |
| 462 | |
| 463 | acpi_ds_clear_operands (walk_state); |
| 464 | |
| 465 | /* |
| 466 | * If a result object was returned from above, push it on the |
| 467 | * current result stack |
| 468 | */ |
| 469 | if (ACPI_SUCCESS (status) && |
| 470 | walk_state->result_obj) { |
| 471 | status = acpi_ds_result_push (walk_state->result_obj, walk_state); |
| 472 | } |
| 473 | |
| 474 | break; |
| 475 | |
| 476 | |
| 477 | default: |
| 478 | |
| 479 | switch (op_type) { |
| 480 | case AML_TYPE_CONTROL: /* Type 1 opcode, IF/ELSE/WHILE/NOOP */ |
| 481 | |
| 482 | /* 1 Operand, 0 external_result, 0 internal_result */ |
| 483 | |
| 484 | status = acpi_ds_exec_end_control_op (walk_state, op); |
| 485 | |
| 486 | /* Make sure to properly pop the result stack */ |
| 487 | |
| 488 | if (ACPI_SUCCESS (status)) { |
| 489 | status = acpi_ds_result_stack_pop (walk_state); |
| 490 | } |
| 491 | else if (status == AE_CTRL_PENDING) { |
| 492 | status = acpi_ds_result_stack_pop (walk_state); |
| 493 | if (ACPI_SUCCESS (status)) { |
| 494 | status = AE_CTRL_PENDING; |
| 495 | } |
| 496 | } |
| 497 | break; |
| 498 | |
| 499 | |
| 500 | case AML_TYPE_METHOD_CALL: |
| 501 | |
| 502 | /* |
| 503 | * If the method is referenced from within a package |
| 504 | * declaration, it is not a invocation of the method, just |
| 505 | * a reference to it. |
| 506 | */ |
| 507 | if ((op->asl.parent) && |
| 508 | ((op->asl.parent->asl.aml_opcode == AML_PACKAGE_OP) || |
| 509 | (op->asl.parent->asl.aml_opcode == AML_VAR_PACKAGE_OP))) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 510 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 511 | "Method Reference in a Package, Op=%p\n", op)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | op->common.node = (struct acpi_namespace_node *) op->asl.value.arg->asl.node->object; |
| 513 | acpi_ut_add_reference (op->asl.value.arg->asl.node->object); |
| 514 | return_ACPI_STATUS (AE_OK); |
| 515 | } |
| 516 | |
| 517 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Method invocation, Op=%p\n", op)); |
| 518 | |
| 519 | /* |
| 520 | * (AML_METHODCALL) Op->Asl.Value.Arg->Asl.Node contains |
| 521 | * the method Node pointer |
| 522 | */ |
| 523 | /* next_op points to the op that holds the method name */ |
| 524 | |
| 525 | next_op = first_arg; |
| 526 | |
| 527 | /* next_op points to first argument op */ |
| 528 | |
| 529 | next_op = next_op->common.next; |
| 530 | |
| 531 | /* |
| 532 | * Get the method's arguments and put them on the operand stack |
| 533 | */ |
| 534 | status = acpi_ds_create_operands (walk_state, next_op); |
| 535 | if (ACPI_FAILURE (status)) { |
| 536 | break; |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * Since the operands will be passed to another control method, |
| 541 | * we must resolve all local references here (Local variables, |
| 542 | * arguments to *this* method, etc.) |
| 543 | */ |
| 544 | status = acpi_ds_resolve_operands (walk_state); |
| 545 | if (ACPI_FAILURE (status)) { |
| 546 | /* On error, clear all resolved operands */ |
| 547 | |
| 548 | acpi_ds_clear_operands (walk_state); |
| 549 | break; |
| 550 | } |
| 551 | |
| 552 | /* |
| 553 | * Tell the walk loop to preempt this running method and |
| 554 | * execute the new method |
| 555 | */ |
| 556 | status = AE_CTRL_TRANSFER; |
| 557 | |
| 558 | /* |
| 559 | * Return now; we don't want to disturb anything, |
| 560 | * especially the operand count! |
| 561 | */ |
| 562 | return_ACPI_STATUS (status); |
| 563 | |
| 564 | |
| 565 | case AML_TYPE_CREATE_FIELD: |
| 566 | |
| 567 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, |
| 568 | "Executing create_field Buffer/Index Op=%p\n", op)); |
| 569 | |
| 570 | status = acpi_ds_load2_end_op (walk_state); |
| 571 | if (ACPI_FAILURE (status)) { |
| 572 | break; |
| 573 | } |
| 574 | |
| 575 | status = acpi_ds_eval_buffer_field_operands (walk_state, op); |
| 576 | break; |
| 577 | |
| 578 | |
| 579 | case AML_TYPE_CREATE_OBJECT: |
| 580 | |
| 581 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, |
| 582 | "Executing create_object (Buffer/Package) Op=%p\n", op)); |
| 583 | |
| 584 | switch (op->common.parent->common.aml_opcode) { |
| 585 | case AML_NAME_OP: |
| 586 | |
| 587 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 588 | * Put the Node on the object stack (Contains the ACPI Name |
| 589 | * of this object) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | */ |
| 591 | walk_state->operands[0] = (void *) op->common.parent->common.node; |
| 592 | walk_state->num_operands = 1; |
| 593 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 594 | status = acpi_ds_create_node (walk_state, |
| 595 | op->common.parent->common.node, |
| 596 | op->common.parent); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | if (ACPI_FAILURE (status)) { |
| 598 | break; |
| 599 | } |
| 600 | |
| 601 | /* Fall through */ |
| 602 | /*lint -fallthrough */ |
| 603 | |
| 604 | case AML_INT_EVAL_SUBTREE_OP: |
| 605 | |
| 606 | status = acpi_ds_eval_data_object_operands (walk_state, op, |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 607 | acpi_ns_get_attached_object (op->common.parent->common.node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | break; |
| 609 | |
| 610 | default: |
| 611 | |
| 612 | status = acpi_ds_eval_data_object_operands (walk_state, op, NULL); |
| 613 | break; |
| 614 | } |
| 615 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 616 | /* Done with result state (Now that operand stack is built) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
| 618 | status = acpi_ds_result_stack_pop (walk_state); |
| 619 | if (ACPI_FAILURE (status)) { |
| 620 | goto cleanup; |
| 621 | } |
| 622 | |
| 623 | /* |
| 624 | * If a result object was returned from above, push it on the |
| 625 | * current result stack |
| 626 | */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 627 | if (walk_state->result_obj) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 628 | status = acpi_ds_result_push (walk_state->result_obj, walk_state); |
| 629 | } |
| 630 | break; |
| 631 | |
| 632 | |
| 633 | case AML_TYPE_NAMED_FIELD: |
| 634 | case AML_TYPE_NAMED_COMPLEX: |
| 635 | case AML_TYPE_NAMED_SIMPLE: |
| 636 | case AML_TYPE_NAMED_NO_OBJ: |
| 637 | |
| 638 | status = acpi_ds_load2_end_op (walk_state); |
| 639 | if (ACPI_FAILURE (status)) { |
| 640 | break; |
| 641 | } |
| 642 | |
| 643 | if (op->common.aml_opcode == AML_REGION_OP) { |
| 644 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, |
| 645 | "Executing op_region Address/Length Op=%p\n", op)); |
| 646 | |
| 647 | status = acpi_ds_eval_region_operands (walk_state, op); |
| 648 | if (ACPI_FAILURE (status)) { |
| 649 | break; |
| 650 | } |
| 651 | |
| 652 | status = acpi_ds_result_stack_pop (walk_state); |
| 653 | } |
| 654 | |
| 655 | break; |
| 656 | |
| 657 | |
| 658 | case AML_TYPE_UNDEFINED: |
| 659 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 660 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 661 | "Undefined opcode type Op=%p\n", op)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | return_ACPI_STATUS (AE_NOT_IMPLEMENTED); |
| 663 | |
| 664 | |
| 665 | case AML_TYPE_BOGUS: |
| 666 | |
| 667 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 668 | "Internal opcode=%X type Op=%p\n", |
| 669 | walk_state->opcode, op)); |
| 670 | break; |
| 671 | |
| 672 | |
| 673 | default: |
| 674 | |
| 675 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 676 | "Unimplemented opcode, class=%X type=%X Opcode=%X Op=%p\n", |
| 677 | op_class, op_type, op->common.aml_opcode, op)); |
| 678 | |
| 679 | status = AE_NOT_IMPLEMENTED; |
| 680 | break; |
| 681 | } |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | * ACPI 2.0 support for 64-bit integers: Truncate numeric |
| 686 | * result value if we are executing from a 32-bit ACPI table |
| 687 | */ |
| 688 | acpi_ex_truncate_for32bit_table (walk_state->result_obj); |
| 689 | |
| 690 | /* |
| 691 | * Check if we just completed the evaluation of a |
| 692 | * conditional predicate |
| 693 | */ |
| 694 | |
| 695 | if ((ACPI_SUCCESS (status)) && |
| 696 | (walk_state->control_state) && |
| 697 | (walk_state->control_state->common.state == |
| 698 | ACPI_CONTROL_PREDICATE_EXECUTING) && |
| 699 | (walk_state->control_state->control.predicate_op == op)) { |
| 700 | status = acpi_ds_get_predicate_value (walk_state, walk_state->result_obj); |
| 701 | walk_state->result_obj = NULL; |
| 702 | } |
| 703 | |
| 704 | |
| 705 | cleanup: |
| 706 | |
| 707 | /* Invoke exception handler on error */ |
| 708 | |
| 709 | if (ACPI_FAILURE (status) && |
| 710 | acpi_gbl_exception_handler && |
| 711 | !(status & AE_CODE_CONTROL)) { |
| 712 | acpi_ex_exit_interpreter (); |
| 713 | status = acpi_gbl_exception_handler (status, |
| 714 | walk_state->method_node->name.integer, walk_state->opcode, |
| 715 | walk_state->aml_offset, NULL); |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 716 | (void) acpi_ex_enter_interpreter (); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | } |
| 718 | |
| 719 | if (walk_state->result_obj) { |
| 720 | /* Break to debugger to display result */ |
| 721 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame^] | 722 | ACPI_DEBUGGER_EXEC (acpi_db_display_result_object (walk_state->result_obj, |
| 723 | walk_state)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
| 725 | /* |
| 726 | * Delete the result op if and only if: |
| 727 | * Parent will not use the result -- such as any |
| 728 | * non-nested type2 op in a method (parent will be method) |
| 729 | */ |
| 730 | acpi_ds_delete_result_if_not_used (op, walk_state->result_obj, walk_state); |
| 731 | } |
| 732 | |
| 733 | #ifdef _UNDER_DEVELOPMENT |
| 734 | |
| 735 | if (walk_state->parser_state.aml == walk_state->parser_state.aml_end) { |
| 736 | acpi_db_method_end (walk_state); |
| 737 | } |
| 738 | #endif |
| 739 | |
| 740 | /* Always clear the object stack */ |
| 741 | |
| 742 | walk_state->num_operands = 0; |
| 743 | |
| 744 | #ifdef ACPI_DISASSEMBLER |
| 745 | |
| 746 | /* On error, display method locals/args */ |
| 747 | |
| 748 | if (ACPI_FAILURE (status)) { |
| 749 | acpi_dm_dump_method_info (status, walk_state, op); |
| 750 | } |
| 751 | #endif |
| 752 | |
| 753 | return_ACPI_STATUS (status); |
| 754 | } |
| 755 | |
| 756 | |