Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dsopcode - Dispatcher Op Region support and handling of |
| 4 | * "control" opcodes |
| 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/acevents.h> |
| 53 | |
| 54 | #define _COMPONENT ACPI_DISPATCHER |
| 55 | ACPI_MODULE_NAME ("dsopcode") |
| 56 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 57 | /* Local prototypes */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 59 | static acpi_status |
| 60 | acpi_ds_execute_arguments ( |
| 61 | struct acpi_namespace_node *node, |
| 62 | struct acpi_namespace_node *scope_node, |
| 63 | u32 aml_length, |
| 64 | u8 *aml_start); |
| 65 | |
| 66 | static acpi_status |
| 67 | acpi_ds_init_buffer_field ( |
| 68 | u16 aml_opcode, |
| 69 | union acpi_operand_object *obj_desc, |
| 70 | union acpi_operand_object *buffer_desc, |
| 71 | union acpi_operand_object *offset_desc, |
| 72 | union acpi_operand_object *length_desc, |
| 73 | union acpi_operand_object *result_desc); |
| 74 | |
| 75 | |
| 76 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | * |
| 78 | * FUNCTION: acpi_ds_execute_arguments |
| 79 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 80 | * PARAMETERS: Node - Object NS node |
| 81 | * scope_node - Parent NS node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * aml_length - Length of executable AML |
| 83 | * aml_start - Pointer to the AML |
| 84 | * |
| 85 | * RETURN: Status. |
| 86 | * |
| 87 | * DESCRIPTION: Late (deferred) execution of region or field arguments |
| 88 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 89 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 91 | static acpi_status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | acpi_ds_execute_arguments ( |
| 93 | struct acpi_namespace_node *node, |
| 94 | struct acpi_namespace_node *scope_node, |
| 95 | u32 aml_length, |
| 96 | u8 *aml_start) |
| 97 | { |
| 98 | acpi_status status; |
| 99 | union acpi_parse_object *op; |
| 100 | struct acpi_walk_state *walk_state; |
| 101 | |
| 102 | |
| 103 | ACPI_FUNCTION_TRACE ("ds_execute_arguments"); |
| 104 | |
| 105 | |
| 106 | /* |
| 107 | * Allocate a new parser op to be the root of the parsed tree |
| 108 | */ |
| 109 | op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP); |
| 110 | if (!op) { |
| 111 | return_ACPI_STATUS (AE_NO_MEMORY); |
| 112 | } |
| 113 | |
| 114 | /* Save the Node for use in acpi_ps_parse_aml */ |
| 115 | |
| 116 | op->common.node = scope_node; |
| 117 | |
| 118 | /* Create and initialize a new parser state */ |
| 119 | |
| 120 | walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL); |
| 121 | if (!walk_state) { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 122 | status = AE_NO_MEMORY; |
| 123 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | } |
| 125 | |
| 126 | status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start, |
| 127 | aml_length, NULL, 1); |
| 128 | if (ACPI_FAILURE (status)) { |
| 129 | acpi_ds_delete_walk_state (walk_state); |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 130 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
| 133 | /* Mark this parse as a deferred opcode */ |
| 134 | |
| 135 | walk_state->parse_flags = ACPI_PARSE_DEFERRED_OP; |
| 136 | walk_state->deferred_node = node; |
| 137 | |
| 138 | /* Pass1: Parse the entire declaration */ |
| 139 | |
| 140 | status = acpi_ps_parse_aml (walk_state); |
| 141 | if (ACPI_FAILURE (status)) { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 142 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | } |
| 144 | |
| 145 | /* Get and init the Op created above */ |
| 146 | |
| 147 | op->common.node = node; |
| 148 | acpi_ps_delete_parse_tree (op); |
| 149 | |
| 150 | /* Evaluate the deferred arguments */ |
| 151 | |
| 152 | op = acpi_ps_alloc_op (AML_INT_EVAL_SUBTREE_OP); |
| 153 | if (!op) { |
| 154 | return_ACPI_STATUS (AE_NO_MEMORY); |
| 155 | } |
| 156 | |
| 157 | op->common.node = scope_node; |
| 158 | |
| 159 | /* Create and initialize a new parser state */ |
| 160 | |
| 161 | walk_state = acpi_ds_create_walk_state (0, NULL, NULL, NULL); |
| 162 | if (!walk_state) { |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 163 | status = AE_NO_MEMORY; |
| 164 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | /* Execute the opcode and arguments */ |
| 168 | |
| 169 | status = acpi_ds_init_aml_walk (walk_state, op, NULL, aml_start, |
| 170 | aml_length, NULL, 3); |
| 171 | if (ACPI_FAILURE (status)) { |
| 172 | acpi_ds_delete_walk_state (walk_state); |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 173 | goto cleanup; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | /* Mark this execution as a deferred opcode */ |
| 177 | |
| 178 | walk_state->deferred_node = node; |
| 179 | status = acpi_ps_parse_aml (walk_state); |
Robert Moore | 88ac00f | 2005-05-26 00:00:00 -0400 | [diff] [blame^] | 180 | |
| 181 | cleanup: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | acpi_ps_delete_parse_tree (op); |
| 183 | return_ACPI_STATUS (status); |
| 184 | } |
| 185 | |
| 186 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 187 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | * |
| 189 | * FUNCTION: acpi_ds_get_buffer_field_arguments |
| 190 | * |
| 191 | * PARAMETERS: obj_desc - A valid buffer_field object |
| 192 | * |
| 193 | * RETURN: Status. |
| 194 | * |
| 195 | * DESCRIPTION: Get buffer_field Buffer and Index. This implements the late |
| 196 | * evaluation of these field attributes. |
| 197 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 198 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 199 | |
| 200 | acpi_status |
| 201 | acpi_ds_get_buffer_field_arguments ( |
| 202 | union acpi_operand_object *obj_desc) |
| 203 | { |
| 204 | union acpi_operand_object *extra_desc; |
| 205 | struct acpi_namespace_node *node; |
| 206 | acpi_status status; |
| 207 | |
| 208 | |
| 209 | ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_field_arguments", obj_desc); |
| 210 | |
| 211 | |
| 212 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { |
| 213 | return_ACPI_STATUS (AE_OK); |
| 214 | } |
| 215 | |
| 216 | /* Get the AML pointer (method object) and buffer_field node */ |
| 217 | |
| 218 | extra_desc = acpi_ns_get_secondary_object (obj_desc); |
| 219 | node = obj_desc->buffer_field.node; |
| 220 | |
| 221 | ACPI_DEBUG_EXEC(acpi_ut_display_init_pathname (ACPI_TYPE_BUFFER_FIELD, node, NULL)); |
| 222 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] buffer_field Arg Init\n", |
| 223 | acpi_ut_get_node_name (node))); |
| 224 | |
| 225 | /* Execute the AML code for the term_arg arguments */ |
| 226 | |
| 227 | status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node), |
| 228 | extra_desc->extra.aml_length, extra_desc->extra.aml_start); |
| 229 | return_ACPI_STATUS (status); |
| 230 | } |
| 231 | |
| 232 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 233 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * |
| 235 | * FUNCTION: acpi_ds_get_buffer_arguments |
| 236 | * |
| 237 | * PARAMETERS: obj_desc - A valid Buffer object |
| 238 | * |
| 239 | * RETURN: Status. |
| 240 | * |
| 241 | * DESCRIPTION: Get Buffer length and initializer byte list. This implements |
| 242 | * the late evaluation of these attributes. |
| 243 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 244 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | |
| 246 | acpi_status |
| 247 | acpi_ds_get_buffer_arguments ( |
| 248 | union acpi_operand_object *obj_desc) |
| 249 | { |
| 250 | struct acpi_namespace_node *node; |
| 251 | acpi_status status; |
| 252 | |
| 253 | |
| 254 | ACPI_FUNCTION_TRACE_PTR ("ds_get_buffer_arguments", obj_desc); |
| 255 | |
| 256 | |
| 257 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { |
| 258 | return_ACPI_STATUS (AE_OK); |
| 259 | } |
| 260 | |
| 261 | /* Get the Buffer node */ |
| 262 | |
| 263 | node = obj_desc->buffer.node; |
| 264 | if (!node) { |
| 265 | ACPI_REPORT_ERROR (( |
| 266 | "No pointer back to NS node in buffer obj %p\n", obj_desc)); |
| 267 | return_ACPI_STATUS (AE_AML_INTERNAL); |
| 268 | } |
| 269 | |
| 270 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Buffer Arg Init\n")); |
| 271 | |
| 272 | /* Execute the AML code for the term_arg arguments */ |
| 273 | |
| 274 | status = acpi_ds_execute_arguments (node, node, |
| 275 | obj_desc->buffer.aml_length, obj_desc->buffer.aml_start); |
| 276 | return_ACPI_STATUS (status); |
| 277 | } |
| 278 | |
| 279 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 280 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 281 | * |
| 282 | * FUNCTION: acpi_ds_get_package_arguments |
| 283 | * |
| 284 | * PARAMETERS: obj_desc - A valid Package object |
| 285 | * |
| 286 | * RETURN: Status. |
| 287 | * |
| 288 | * DESCRIPTION: Get Package length and initializer byte list. This implements |
| 289 | * the late evaluation of these attributes. |
| 290 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 291 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
| 293 | acpi_status |
| 294 | acpi_ds_get_package_arguments ( |
| 295 | union acpi_operand_object *obj_desc) |
| 296 | { |
| 297 | struct acpi_namespace_node *node; |
| 298 | acpi_status status; |
| 299 | |
| 300 | |
| 301 | ACPI_FUNCTION_TRACE_PTR ("ds_get_package_arguments", obj_desc); |
| 302 | |
| 303 | |
| 304 | if (obj_desc->common.flags & AOPOBJ_DATA_VALID) { |
| 305 | return_ACPI_STATUS (AE_OK); |
| 306 | } |
| 307 | |
| 308 | /* Get the Package node */ |
| 309 | |
| 310 | node = obj_desc->package.node; |
| 311 | if (!node) { |
| 312 | ACPI_REPORT_ERROR (( |
| 313 | "No pointer back to NS node in package %p\n", obj_desc)); |
| 314 | return_ACPI_STATUS (AE_AML_INTERNAL); |
| 315 | } |
| 316 | |
| 317 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Package Arg Init\n")); |
| 318 | |
| 319 | /* Execute the AML code for the term_arg arguments */ |
| 320 | |
| 321 | status = acpi_ds_execute_arguments (node, node, |
| 322 | obj_desc->package.aml_length, obj_desc->package.aml_start); |
| 323 | return_ACPI_STATUS (status); |
| 324 | } |
| 325 | |
| 326 | |
| 327 | /***************************************************************************** |
| 328 | * |
| 329 | * FUNCTION: acpi_ds_get_region_arguments |
| 330 | * |
| 331 | * PARAMETERS: obj_desc - A valid region object |
| 332 | * |
| 333 | * RETURN: Status. |
| 334 | * |
| 335 | * DESCRIPTION: Get region address and length. This implements the late |
| 336 | * evaluation of these region attributes. |
| 337 | * |
| 338 | ****************************************************************************/ |
| 339 | |
| 340 | acpi_status |
| 341 | acpi_ds_get_region_arguments ( |
| 342 | union acpi_operand_object *obj_desc) |
| 343 | { |
| 344 | struct acpi_namespace_node *node; |
| 345 | acpi_status status; |
| 346 | union acpi_operand_object *extra_desc; |
| 347 | |
| 348 | |
| 349 | ACPI_FUNCTION_TRACE_PTR ("ds_get_region_arguments", obj_desc); |
| 350 | |
| 351 | |
| 352 | if (obj_desc->region.flags & AOPOBJ_DATA_VALID) { |
| 353 | return_ACPI_STATUS (AE_OK); |
| 354 | } |
| 355 | |
| 356 | extra_desc = acpi_ns_get_secondary_object (obj_desc); |
| 357 | if (!extra_desc) { |
| 358 | return_ACPI_STATUS (AE_NOT_EXIST); |
| 359 | } |
| 360 | |
| 361 | /* Get the Region node */ |
| 362 | |
| 363 | node = obj_desc->region.node; |
| 364 | |
| 365 | ACPI_DEBUG_EXEC (acpi_ut_display_init_pathname (ACPI_TYPE_REGION, node, NULL)); |
| 366 | |
| 367 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s] op_region Arg Init at AML %p\n", |
| 368 | acpi_ut_get_node_name (node), extra_desc->extra.aml_start)); |
| 369 | |
| 370 | /* Execute the argument AML */ |
| 371 | |
| 372 | status = acpi_ds_execute_arguments (node, acpi_ns_get_parent_node (node), |
| 373 | extra_desc->extra.aml_length, extra_desc->extra.aml_start); |
| 374 | return_ACPI_STATUS (status); |
| 375 | } |
| 376 | |
| 377 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 378 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | * |
| 380 | * FUNCTION: acpi_ds_initialize_region |
| 381 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 382 | * PARAMETERS: obj_handle - Region namespace node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | * |
| 384 | * RETURN: Status |
| 385 | * |
| 386 | * DESCRIPTION: Front end to ev_initialize_region |
| 387 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 388 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 389 | |
| 390 | acpi_status |
| 391 | acpi_ds_initialize_region ( |
| 392 | acpi_handle obj_handle) |
| 393 | { |
| 394 | union acpi_operand_object *obj_desc; |
| 395 | acpi_status status; |
| 396 | |
| 397 | |
| 398 | obj_desc = acpi_ns_get_attached_object (obj_handle); |
| 399 | |
| 400 | /* Namespace is NOT locked */ |
| 401 | |
| 402 | status = acpi_ev_initialize_region (obj_desc, FALSE); |
| 403 | return (status); |
| 404 | } |
| 405 | |
| 406 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 407 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | * |
| 409 | * FUNCTION: acpi_ds_init_buffer_field |
| 410 | * |
| 411 | * PARAMETERS: aml_opcode - create_xxx_field |
| 412 | * obj_desc - buffer_field object |
| 413 | * buffer_desc - Host Buffer |
| 414 | * offset_desc - Offset into buffer |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 415 | * length_desc - Length of field (CREATE_FIELD_OP only) |
| 416 | * result_desc - Where to store the result |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | * |
| 418 | * RETURN: Status |
| 419 | * |
| 420 | * DESCRIPTION: Perform actual initialization of a buffer field |
| 421 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 422 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 424 | static acpi_status |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | acpi_ds_init_buffer_field ( |
| 426 | u16 aml_opcode, |
| 427 | union acpi_operand_object *obj_desc, |
| 428 | union acpi_operand_object *buffer_desc, |
| 429 | union acpi_operand_object *offset_desc, |
| 430 | union acpi_operand_object *length_desc, |
| 431 | union acpi_operand_object *result_desc) |
| 432 | { |
| 433 | u32 offset; |
| 434 | u32 bit_offset; |
| 435 | u32 bit_count; |
| 436 | u8 field_flags; |
| 437 | acpi_status status; |
| 438 | |
| 439 | |
| 440 | ACPI_FUNCTION_TRACE_PTR ("ds_init_buffer_field", obj_desc); |
| 441 | |
| 442 | |
| 443 | /* Host object must be a Buffer */ |
| 444 | |
| 445 | if (ACPI_GET_OBJECT_TYPE (buffer_desc) != ACPI_TYPE_BUFFER) { |
| 446 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 447 | "Target of Create Field is not a Buffer object - %s\n", |
| 448 | acpi_ut_get_object_type_name (buffer_desc))); |
| 449 | |
| 450 | status = AE_AML_OPERAND_TYPE; |
| 451 | goto cleanup; |
| 452 | } |
| 453 | |
| 454 | /* |
| 455 | * The last parameter to all of these opcodes (result_desc) started |
| 456 | * out as a name_string, and should therefore now be a NS node |
| 457 | * after resolution in acpi_ex_resolve_operands(). |
| 458 | */ |
| 459 | if (ACPI_GET_DESCRIPTOR_TYPE (result_desc) != ACPI_DESC_TYPE_NAMED) { |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 460 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 461 | "(%s) destination not a NS Node [%s]\n", |
| 462 | acpi_ps_get_opcode_name (aml_opcode), |
| 463 | acpi_ut_get_descriptor_name (result_desc))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
| 465 | status = AE_AML_OPERAND_TYPE; |
| 466 | goto cleanup; |
| 467 | } |
| 468 | |
| 469 | offset = (u32) offset_desc->integer.value; |
| 470 | |
| 471 | /* |
| 472 | * Setup the Bit offsets and counts, according to the opcode |
| 473 | */ |
| 474 | switch (aml_opcode) { |
| 475 | case AML_CREATE_FIELD_OP: |
| 476 | |
| 477 | /* Offset is in bits, count is in bits */ |
| 478 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 479 | field_flags = AML_FIELD_ACCESS_BYTE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | bit_offset = offset; |
| 481 | bit_count = (u32) length_desc->integer.value; |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 482 | |
| 483 | /* Must have a valid (>0) bit count */ |
| 484 | |
| 485 | if (bit_count == 0) { |
| 486 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 487 | "Attempt to create_field of length 0\n")); |
| 488 | status = AE_AML_OPERAND_VALUE; |
| 489 | goto cleanup; |
| 490 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | break; |
| 492 | |
| 493 | case AML_CREATE_BIT_FIELD_OP: |
| 494 | |
| 495 | /* Offset is in bits, Field is one bit */ |
| 496 | |
| 497 | bit_offset = offset; |
| 498 | bit_count = 1; |
| 499 | field_flags = AML_FIELD_ACCESS_BYTE; |
| 500 | break; |
| 501 | |
| 502 | case AML_CREATE_BYTE_FIELD_OP: |
| 503 | |
| 504 | /* Offset is in bytes, field is one byte */ |
| 505 | |
| 506 | bit_offset = 8 * offset; |
| 507 | bit_count = 8; |
| 508 | field_flags = AML_FIELD_ACCESS_BYTE; |
| 509 | break; |
| 510 | |
| 511 | case AML_CREATE_WORD_FIELD_OP: |
| 512 | |
| 513 | /* Offset is in bytes, field is one word */ |
| 514 | |
| 515 | bit_offset = 8 * offset; |
| 516 | bit_count = 16; |
| 517 | field_flags = AML_FIELD_ACCESS_WORD; |
| 518 | break; |
| 519 | |
| 520 | case AML_CREATE_DWORD_FIELD_OP: |
| 521 | |
| 522 | /* Offset is in bytes, field is one dword */ |
| 523 | |
| 524 | bit_offset = 8 * offset; |
| 525 | bit_count = 32; |
| 526 | field_flags = AML_FIELD_ACCESS_DWORD; |
| 527 | break; |
| 528 | |
| 529 | case AML_CREATE_QWORD_FIELD_OP: |
| 530 | |
| 531 | /* Offset is in bytes, field is one qword */ |
| 532 | |
| 533 | bit_offset = 8 * offset; |
| 534 | bit_count = 64; |
| 535 | field_flags = AML_FIELD_ACCESS_QWORD; |
| 536 | break; |
| 537 | |
| 538 | default: |
| 539 | |
| 540 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 541 | "Unknown field creation opcode %02x\n", |
| 542 | aml_opcode)); |
| 543 | status = AE_AML_BAD_OPCODE; |
| 544 | goto cleanup; |
| 545 | } |
| 546 | |
| 547 | /* Entire field must fit within the current length of the buffer */ |
| 548 | |
| 549 | if ((bit_offset + bit_count) > |
| 550 | (8 * (u32) buffer_desc->buffer.length)) { |
| 551 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, |
| 552 | "Field [%4.4s] size %d exceeds Buffer [%4.4s] size %d (bits)\n", |
| 553 | acpi_ut_get_node_name (result_desc), |
| 554 | bit_offset + bit_count, |
| 555 | acpi_ut_get_node_name (buffer_desc->buffer.node), |
| 556 | 8 * (u32) buffer_desc->buffer.length)); |
| 557 | status = AE_AML_BUFFER_LIMIT; |
| 558 | goto cleanup; |
| 559 | } |
| 560 | |
| 561 | /* |
| 562 | * Initialize areas of the field object that are common to all fields |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 563 | * For field_flags, use LOCK_RULE = 0 (NO_LOCK), |
| 564 | * UPDATE_RULE = 0 (UPDATE_PRESERVE) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | */ |
| 566 | status = acpi_ex_prep_common_field_object (obj_desc, field_flags, 0, |
| 567 | bit_offset, bit_count); |
| 568 | if (ACPI_FAILURE (status)) { |
| 569 | goto cleanup; |
| 570 | } |
| 571 | |
| 572 | obj_desc->buffer_field.buffer_obj = buffer_desc; |
| 573 | |
| 574 | /* Reference count for buffer_desc inherits obj_desc count */ |
| 575 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 576 | buffer_desc->common.reference_count = (u16) |
| 577 | (buffer_desc->common.reference_count + obj_desc->common.reference_count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | |
| 579 | |
| 580 | cleanup: |
| 581 | |
| 582 | /* Always delete the operands */ |
| 583 | |
| 584 | acpi_ut_remove_reference (offset_desc); |
| 585 | acpi_ut_remove_reference (buffer_desc); |
| 586 | |
| 587 | if (aml_opcode == AML_CREATE_FIELD_OP) { |
| 588 | acpi_ut_remove_reference (length_desc); |
| 589 | } |
| 590 | |
| 591 | /* On failure, delete the result descriptor */ |
| 592 | |
| 593 | if (ACPI_FAILURE (status)) { |
| 594 | acpi_ut_remove_reference (result_desc); /* Result descriptor */ |
| 595 | } |
| 596 | else { |
| 597 | /* Now the address and length are valid for this buffer_field */ |
| 598 | |
| 599 | obj_desc->buffer_field.flags |= AOPOBJ_DATA_VALID; |
| 600 | } |
| 601 | |
| 602 | return_ACPI_STATUS (status); |
| 603 | } |
| 604 | |
| 605 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 606 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | * |
| 608 | * FUNCTION: acpi_ds_eval_buffer_field_operands |
| 609 | * |
| 610 | * PARAMETERS: walk_state - Current walk |
| 611 | * Op - A valid buffer_field Op object |
| 612 | * |
| 613 | * RETURN: Status |
| 614 | * |
| 615 | * DESCRIPTION: Get buffer_field Buffer and Index |
| 616 | * Called from acpi_ds_exec_end_op during buffer_field parse tree walk |
| 617 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 618 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | |
| 620 | acpi_status |
| 621 | acpi_ds_eval_buffer_field_operands ( |
| 622 | struct acpi_walk_state *walk_state, |
| 623 | union acpi_parse_object *op) |
| 624 | { |
| 625 | acpi_status status; |
| 626 | union acpi_operand_object *obj_desc; |
| 627 | struct acpi_namespace_node *node; |
| 628 | union acpi_parse_object *next_op; |
| 629 | |
| 630 | |
| 631 | ACPI_FUNCTION_TRACE_PTR ("ds_eval_buffer_field_operands", op); |
| 632 | |
| 633 | |
| 634 | /* |
| 635 | * This is where we evaluate the address and length fields of the |
| 636 | * create_xxx_field declaration |
| 637 | */ |
| 638 | node = op->common.node; |
| 639 | |
| 640 | /* next_op points to the op that holds the Buffer */ |
| 641 | |
| 642 | next_op = op->common.value.arg; |
| 643 | |
| 644 | /* Evaluate/create the address and length operands */ |
| 645 | |
| 646 | status = acpi_ds_create_operands (walk_state, next_op); |
| 647 | if (ACPI_FAILURE (status)) { |
| 648 | return_ACPI_STATUS (status); |
| 649 | } |
| 650 | |
| 651 | obj_desc = acpi_ns_get_attached_object (node); |
| 652 | if (!obj_desc) { |
| 653 | return_ACPI_STATUS (AE_NOT_EXIST); |
| 654 | } |
| 655 | |
| 656 | /* Resolve the operands */ |
| 657 | |
| 658 | status = acpi_ex_resolve_operands (op->common.aml_opcode, |
| 659 | ACPI_WALK_OPERANDS, walk_state); |
| 660 | |
| 661 | ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, |
| 662 | acpi_ps_get_opcode_name (op->common.aml_opcode), |
| 663 | walk_state->num_operands, "after acpi_ex_resolve_operands"); |
| 664 | |
| 665 | if (ACPI_FAILURE (status)) { |
| 666 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "(%s) bad operand(s) (%X)\n", |
| 667 | acpi_ps_get_opcode_name (op->common.aml_opcode), status)); |
| 668 | |
| 669 | return_ACPI_STATUS (status); |
| 670 | } |
| 671 | |
| 672 | /* Initialize the Buffer Field */ |
| 673 | |
| 674 | if (op->common.aml_opcode == AML_CREATE_FIELD_OP) { |
| 675 | /* NOTE: Slightly different operands for this opcode */ |
| 676 | |
| 677 | status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc, |
| 678 | walk_state->operands[0], walk_state->operands[1], |
| 679 | walk_state->operands[2], walk_state->operands[3]); |
| 680 | } |
| 681 | else { |
| 682 | /* All other, create_xxx_field opcodes */ |
| 683 | |
| 684 | status = acpi_ds_init_buffer_field (op->common.aml_opcode, obj_desc, |
| 685 | walk_state->operands[0], walk_state->operands[1], |
| 686 | NULL, walk_state->operands[2]); |
| 687 | } |
| 688 | |
| 689 | return_ACPI_STATUS (status); |
| 690 | } |
| 691 | |
| 692 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 693 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 694 | * |
| 695 | * FUNCTION: acpi_ds_eval_region_operands |
| 696 | * |
| 697 | * PARAMETERS: walk_state - Current walk |
| 698 | * Op - A valid region Op object |
| 699 | * |
| 700 | * RETURN: Status |
| 701 | * |
| 702 | * DESCRIPTION: Get region address and length |
| 703 | * Called from acpi_ds_exec_end_op during op_region parse tree walk |
| 704 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 705 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | |
| 707 | acpi_status |
| 708 | acpi_ds_eval_region_operands ( |
| 709 | struct acpi_walk_state *walk_state, |
| 710 | union acpi_parse_object *op) |
| 711 | { |
| 712 | acpi_status status; |
| 713 | union acpi_operand_object *obj_desc; |
| 714 | union acpi_operand_object *operand_desc; |
| 715 | struct acpi_namespace_node *node; |
| 716 | union acpi_parse_object *next_op; |
| 717 | |
| 718 | |
| 719 | ACPI_FUNCTION_TRACE_PTR ("ds_eval_region_operands", op); |
| 720 | |
| 721 | |
| 722 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 723 | * This is where we evaluate the address and length fields of the |
| 724 | * op_region declaration |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 725 | */ |
| 726 | node = op->common.node; |
| 727 | |
| 728 | /* next_op points to the op that holds the space_iD */ |
| 729 | |
| 730 | next_op = op->common.value.arg; |
| 731 | |
| 732 | /* next_op points to address op */ |
| 733 | |
| 734 | next_op = next_op->common.next; |
| 735 | |
| 736 | /* Evaluate/create the address and length operands */ |
| 737 | |
| 738 | status = acpi_ds_create_operands (walk_state, next_op); |
| 739 | if (ACPI_FAILURE (status)) { |
| 740 | return_ACPI_STATUS (status); |
| 741 | } |
| 742 | |
| 743 | /* Resolve the length and address operands to numbers */ |
| 744 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 745 | status = acpi_ex_resolve_operands (op->common.aml_opcode, |
| 746 | ACPI_WALK_OPERANDS, walk_state); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | if (ACPI_FAILURE (status)) { |
| 748 | return_ACPI_STATUS (status); |
| 749 | } |
| 750 | |
| 751 | ACPI_DUMP_OPERANDS (ACPI_WALK_OPERANDS, ACPI_IMODE_EXECUTE, |
| 752 | acpi_ps_get_opcode_name (op->common.aml_opcode), |
| 753 | 1, "after acpi_ex_resolve_operands"); |
| 754 | |
| 755 | obj_desc = acpi_ns_get_attached_object (node); |
| 756 | if (!obj_desc) { |
| 757 | return_ACPI_STATUS (AE_NOT_EXIST); |
| 758 | } |
| 759 | |
| 760 | /* |
| 761 | * Get the length operand and save it |
| 762 | * (at Top of stack) |
| 763 | */ |
| 764 | operand_desc = walk_state->operands[walk_state->num_operands - 1]; |
| 765 | |
| 766 | obj_desc->region.length = (u32) operand_desc->integer.value; |
| 767 | acpi_ut_remove_reference (operand_desc); |
| 768 | |
| 769 | /* |
| 770 | * Get the address and save it |
| 771 | * (at top of stack - 1) |
| 772 | */ |
| 773 | operand_desc = walk_state->operands[walk_state->num_operands - 2]; |
| 774 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 775 | obj_desc->region.address = (acpi_physical_address) |
| 776 | operand_desc->integer.value; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | acpi_ut_remove_reference (operand_desc); |
| 778 | |
| 779 | ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "rgn_obj %p Addr %8.8X%8.8X Len %X\n", |
| 780 | obj_desc, |
| 781 | ACPI_FORMAT_UINT64 (obj_desc->region.address), |
| 782 | obj_desc->region.length)); |
| 783 | |
| 784 | /* Now the address and length are valid for this opregion */ |
| 785 | |
| 786 | obj_desc->region.flags |= AOPOBJ_DATA_VALID; |
| 787 | |
| 788 | return_ACPI_STATUS (status); |
| 789 | } |
| 790 | |
| 791 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 792 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 793 | * |
| 794 | * FUNCTION: acpi_ds_eval_data_object_operands |
| 795 | * |
| 796 | * PARAMETERS: walk_state - Current walk |
| 797 | * Op - A valid data_object Op object |
| 798 | * obj_desc - data_object |
| 799 | * |
| 800 | * RETURN: Status |
| 801 | * |
| 802 | * DESCRIPTION: Get the operands and complete the following data object types: |
| 803 | * Buffer, Package. |
| 804 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 805 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 806 | |
| 807 | acpi_status |
| 808 | acpi_ds_eval_data_object_operands ( |
| 809 | struct acpi_walk_state *walk_state, |
| 810 | union acpi_parse_object *op, |
| 811 | union acpi_operand_object *obj_desc) |
| 812 | { |
| 813 | acpi_status status; |
| 814 | union acpi_operand_object *arg_desc; |
| 815 | u32 length; |
| 816 | |
| 817 | |
| 818 | ACPI_FUNCTION_TRACE ("ds_eval_data_object_operands"); |
| 819 | |
| 820 | |
| 821 | /* The first operand (for all of these data objects) is the length */ |
| 822 | |
| 823 | status = acpi_ds_create_operand (walk_state, op->common.value.arg, 1); |
| 824 | if (ACPI_FAILURE (status)) { |
| 825 | return_ACPI_STATUS (status); |
| 826 | } |
| 827 | |
| 828 | status = acpi_ex_resolve_operands (walk_state->opcode, |
| 829 | &(walk_state->operands [walk_state->num_operands -1]), |
| 830 | walk_state); |
| 831 | if (ACPI_FAILURE (status)) { |
| 832 | return_ACPI_STATUS (status); |
| 833 | } |
| 834 | |
| 835 | /* Extract length operand */ |
| 836 | |
| 837 | arg_desc = walk_state->operands [walk_state->num_operands - 1]; |
| 838 | length = (u32) arg_desc->integer.value; |
| 839 | |
| 840 | /* Cleanup for length operand */ |
| 841 | |
| 842 | status = acpi_ds_obj_stack_pop (1, walk_state); |
| 843 | if (ACPI_FAILURE (status)) { |
| 844 | return_ACPI_STATUS (status); |
| 845 | } |
| 846 | |
| 847 | acpi_ut_remove_reference (arg_desc); |
| 848 | |
| 849 | /* |
| 850 | * Create the actual data object |
| 851 | */ |
| 852 | switch (op->common.aml_opcode) { |
| 853 | case AML_BUFFER_OP: |
| 854 | |
| 855 | status = acpi_ds_build_internal_buffer_obj (walk_state, op, length, &obj_desc); |
| 856 | break; |
| 857 | |
| 858 | case AML_PACKAGE_OP: |
| 859 | case AML_VAR_PACKAGE_OP: |
| 860 | |
| 861 | status = acpi_ds_build_internal_package_obj (walk_state, op, length, &obj_desc); |
| 862 | break; |
| 863 | |
| 864 | default: |
| 865 | return_ACPI_STATUS (AE_AML_BAD_OPCODE); |
| 866 | } |
| 867 | |
| 868 | if (ACPI_SUCCESS (status)) { |
| 869 | /* |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 870 | * Return the object in the walk_state, unless the parent is a package - |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 871 | * in this case, the return object will be stored in the parse tree |
| 872 | * for the package. |
| 873 | */ |
| 874 | if ((!op->common.parent) || |
| 875 | ((op->common.parent->common.aml_opcode != AML_PACKAGE_OP) && |
| 876 | (op->common.parent->common.aml_opcode != AML_VAR_PACKAGE_OP) && |
| 877 | (op->common.parent->common.aml_opcode != AML_NAME_OP))) { |
| 878 | walk_state->result_obj = obj_desc; |
| 879 | } |
| 880 | } |
| 881 | |
| 882 | return_ACPI_STATUS (status); |
| 883 | } |
| 884 | |
| 885 | |
| 886 | /******************************************************************************* |
| 887 | * |
| 888 | * FUNCTION: acpi_ds_exec_begin_control_op |
| 889 | * |
| 890 | * PARAMETERS: walk_list - The list that owns the walk stack |
| 891 | * Op - The control Op |
| 892 | * |
| 893 | * RETURN: Status |
| 894 | * |
| 895 | * DESCRIPTION: Handles all control ops encountered during control method |
| 896 | * execution. |
| 897 | * |
| 898 | ******************************************************************************/ |
| 899 | |
| 900 | acpi_status |
| 901 | acpi_ds_exec_begin_control_op ( |
| 902 | struct acpi_walk_state *walk_state, |
| 903 | union acpi_parse_object *op) |
| 904 | { |
| 905 | acpi_status status = AE_OK; |
| 906 | union acpi_generic_state *control_state; |
| 907 | |
| 908 | |
| 909 | ACPI_FUNCTION_NAME ("ds_exec_begin_control_op"); |
| 910 | |
| 911 | |
| 912 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "Op=%p Opcode=%2.2X State=%p\n", op, |
| 913 | op->common.aml_opcode, walk_state)); |
| 914 | |
| 915 | switch (op->common.aml_opcode) { |
| 916 | case AML_IF_OP: |
| 917 | case AML_WHILE_OP: |
| 918 | |
| 919 | /* |
| 920 | * IF/WHILE: Create a new control state to manage these |
| 921 | * constructs. We need to manage these as a stack, in order |
| 922 | * to handle nesting. |
| 923 | */ |
| 924 | control_state = acpi_ut_create_control_state (); |
| 925 | if (!control_state) { |
| 926 | status = AE_NO_MEMORY; |
| 927 | break; |
| 928 | } |
| 929 | /* |
| 930 | * Save a pointer to the predicate for multiple executions |
| 931 | * of a loop |
| 932 | */ |
| 933 | control_state->control.aml_predicate_start = walk_state->parser_state.aml - 1; |
| 934 | control_state->control.package_end = walk_state->parser_state.pkg_end; |
| 935 | control_state->control.opcode = op->common.aml_opcode; |
| 936 | |
| 937 | |
| 938 | /* Push the control state on this walk's control stack */ |
| 939 | |
| 940 | acpi_ut_push_generic_state (&walk_state->control_state, control_state); |
| 941 | break; |
| 942 | |
| 943 | case AML_ELSE_OP: |
| 944 | |
| 945 | /* Predicate is in the state object */ |
| 946 | /* If predicate is true, the IF was executed, ignore ELSE part */ |
| 947 | |
| 948 | if (walk_state->last_predicate) { |
| 949 | status = AE_CTRL_TRUE; |
| 950 | } |
| 951 | |
| 952 | break; |
| 953 | |
| 954 | case AML_RETURN_OP: |
| 955 | |
| 956 | break; |
| 957 | |
| 958 | default: |
| 959 | break; |
| 960 | } |
| 961 | |
| 962 | return (status); |
| 963 | } |
| 964 | |
| 965 | |
| 966 | /******************************************************************************* |
| 967 | * |
| 968 | * FUNCTION: acpi_ds_exec_end_control_op |
| 969 | * |
| 970 | * PARAMETERS: walk_list - The list that owns the walk stack |
| 971 | * Op - The control Op |
| 972 | * |
| 973 | * RETURN: Status |
| 974 | * |
| 975 | * DESCRIPTION: Handles all control ops encountered during control method |
| 976 | * execution. |
| 977 | * |
| 978 | ******************************************************************************/ |
| 979 | |
| 980 | acpi_status |
| 981 | acpi_ds_exec_end_control_op ( |
| 982 | struct acpi_walk_state *walk_state, |
| 983 | union acpi_parse_object *op) |
| 984 | { |
| 985 | acpi_status status = AE_OK; |
| 986 | union acpi_generic_state *control_state; |
| 987 | |
| 988 | |
| 989 | ACPI_FUNCTION_NAME ("ds_exec_end_control_op"); |
| 990 | |
| 991 | |
| 992 | switch (op->common.aml_opcode) { |
| 993 | case AML_IF_OP: |
| 994 | |
| 995 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[IF_OP] Op=%p\n", op)); |
| 996 | |
| 997 | /* |
| 998 | * Save the result of the predicate in case there is an |
| 999 | * ELSE to come |
| 1000 | */ |
| 1001 | walk_state->last_predicate = |
| 1002 | (u8) walk_state->control_state->common.value; |
| 1003 | |
| 1004 | /* |
| 1005 | * Pop the control state that was created at the start |
| 1006 | * of the IF and free it |
| 1007 | */ |
| 1008 | control_state = acpi_ut_pop_generic_state (&walk_state->control_state); |
| 1009 | acpi_ut_delete_generic_state (control_state); |
| 1010 | break; |
| 1011 | |
| 1012 | |
| 1013 | case AML_ELSE_OP: |
| 1014 | |
| 1015 | break; |
| 1016 | |
| 1017 | |
| 1018 | case AML_WHILE_OP: |
| 1019 | |
| 1020 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, "[WHILE_OP] Op=%p\n", op)); |
| 1021 | |
| 1022 | if (walk_state->control_state->common.value) { |
| 1023 | /* Predicate was true, go back and evaluate it again! */ |
| 1024 | |
| 1025 | status = AE_CTRL_PENDING; |
| 1026 | } |
| 1027 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 1028 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 1029 | "[WHILE_OP] termination! Op=%p\n",op)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1030 | |
| 1031 | /* Pop this control state and free it */ |
| 1032 | |
| 1033 | control_state = acpi_ut_pop_generic_state (&walk_state->control_state); |
| 1034 | |
| 1035 | walk_state->aml_last_while = control_state->control.aml_predicate_start; |
| 1036 | acpi_ut_delete_generic_state (control_state); |
| 1037 | break; |
| 1038 | |
| 1039 | |
| 1040 | case AML_RETURN_OP: |
| 1041 | |
| 1042 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 1043 | "[RETURN_OP] Op=%p Arg=%p\n",op, op->common.value.arg)); |
| 1044 | |
| 1045 | /* |
| 1046 | * One optional operand -- the return value |
| 1047 | * It can be either an immediate operand or a result that |
| 1048 | * has been bubbled up the tree |
| 1049 | */ |
| 1050 | if (op->common.value.arg) { |
| 1051 | /* Since we have a real Return(), delete any implicit return */ |
| 1052 | |
| 1053 | acpi_ds_clear_implicit_return (walk_state); |
| 1054 | |
| 1055 | /* Return statement has an immediate operand */ |
| 1056 | |
| 1057 | status = acpi_ds_create_operands (walk_state, op->common.value.arg); |
| 1058 | if (ACPI_FAILURE (status)) { |
| 1059 | return (status); |
| 1060 | } |
| 1061 | |
| 1062 | /* |
| 1063 | * If value being returned is a Reference (such as |
| 1064 | * an arg or local), resolve it now because it may |
| 1065 | * cease to exist at the end of the method. |
| 1066 | */ |
| 1067 | status = acpi_ex_resolve_to_value (&walk_state->operands [0], walk_state); |
| 1068 | if (ACPI_FAILURE (status)) { |
| 1069 | return (status); |
| 1070 | } |
| 1071 | |
| 1072 | /* |
| 1073 | * Get the return value and save as the last result |
| 1074 | * value. This is the only place where walk_state->return_desc |
| 1075 | * is set to anything other than zero! |
| 1076 | */ |
| 1077 | walk_state->return_desc = walk_state->operands[0]; |
| 1078 | } |
| 1079 | else if ((walk_state->results) && |
| 1080 | (walk_state->results->results.num_results > 0)) { |
| 1081 | /* Since we have a real Return(), delete any implicit return */ |
| 1082 | |
| 1083 | acpi_ds_clear_implicit_return (walk_state); |
| 1084 | |
| 1085 | /* |
| 1086 | * The return value has come from a previous calculation. |
| 1087 | * |
| 1088 | * If value being returned is a Reference (such as |
| 1089 | * an arg or local), resolve it now because it may |
| 1090 | * cease to exist at the end of the method. |
| 1091 | * |
| 1092 | * Allow references created by the Index operator to return unchanged. |
| 1093 | */ |
| 1094 | if ((ACPI_GET_DESCRIPTOR_TYPE (walk_state->results->results.obj_desc[0]) == ACPI_DESC_TYPE_OPERAND) && |
| 1095 | (ACPI_GET_OBJECT_TYPE (walk_state->results->results.obj_desc [0]) == ACPI_TYPE_LOCAL_REFERENCE) && |
| 1096 | ((walk_state->results->results.obj_desc [0])->reference.opcode != AML_INDEX_OP)) { |
| 1097 | status = acpi_ex_resolve_to_value (&walk_state->results->results.obj_desc [0], walk_state); |
| 1098 | if (ACPI_FAILURE (status)) { |
| 1099 | return (status); |
| 1100 | } |
| 1101 | } |
| 1102 | |
| 1103 | walk_state->return_desc = walk_state->results->results.obj_desc [0]; |
| 1104 | } |
| 1105 | else { |
| 1106 | /* No return operand */ |
| 1107 | |
| 1108 | if (walk_state->num_operands) { |
| 1109 | acpi_ut_remove_reference (walk_state->operands [0]); |
| 1110 | } |
| 1111 | |
| 1112 | walk_state->operands [0] = NULL; |
| 1113 | walk_state->num_operands = 0; |
| 1114 | walk_state->return_desc = NULL; |
| 1115 | } |
| 1116 | |
| 1117 | |
| 1118 | ACPI_DEBUG_PRINT ((ACPI_DB_DISPATCH, |
| 1119 | "Completed RETURN_OP State=%p, ret_val=%p\n", |
| 1120 | walk_state, walk_state->return_desc)); |
| 1121 | |
| 1122 | /* End the control method execution right now */ |
| 1123 | |
| 1124 | status = AE_CTRL_TERMINATE; |
| 1125 | break; |
| 1126 | |
| 1127 | |
| 1128 | case AML_NOOP_OP: |
| 1129 | |
| 1130 | /* Just do nothing! */ |
| 1131 | break; |
| 1132 | |
| 1133 | |
| 1134 | case AML_BREAK_POINT_OP: |
| 1135 | |
| 1136 | /* Call up to the OS service layer to handle this */ |
| 1137 | |
| 1138 | status = acpi_os_signal (ACPI_SIGNAL_BREAKPOINT, "Executed AML Breakpoint opcode"); |
| 1139 | |
| 1140 | /* If and when it returns, all done. */ |
| 1141 | |
| 1142 | break; |
| 1143 | |
| 1144 | |
| 1145 | case AML_BREAK_OP: |
| 1146 | case AML_CONTINUE_OP: /* ACPI 2.0 */ |
| 1147 | |
| 1148 | |
| 1149 | /* Pop and delete control states until we find a while */ |
| 1150 | |
| 1151 | while (walk_state->control_state && |
| 1152 | (walk_state->control_state->control.opcode != AML_WHILE_OP)) { |
| 1153 | control_state = acpi_ut_pop_generic_state (&walk_state->control_state); |
| 1154 | acpi_ut_delete_generic_state (control_state); |
| 1155 | } |
| 1156 | |
| 1157 | /* No while found? */ |
| 1158 | |
| 1159 | if (!walk_state->control_state) { |
| 1160 | return (AE_AML_NO_WHILE); |
| 1161 | } |
| 1162 | |
| 1163 | /* Was: walk_state->aml_last_while = walk_state->control_state->Control.aml_predicate_start; */ |
| 1164 | |
| 1165 | walk_state->aml_last_while = walk_state->control_state->control.package_end; |
| 1166 | |
| 1167 | /* Return status depending on opcode */ |
| 1168 | |
| 1169 | if (op->common.aml_opcode == AML_BREAK_OP) { |
| 1170 | status = AE_CTRL_BREAK; |
| 1171 | } |
| 1172 | else { |
| 1173 | status = AE_CTRL_CONTINUE; |
| 1174 | } |
| 1175 | break; |
| 1176 | |
| 1177 | |
| 1178 | default: |
| 1179 | |
| 1180 | ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Unknown control opcode=%X Op=%p\n", |
| 1181 | op->common.aml_opcode, op)); |
| 1182 | |
| 1183 | status = AE_AML_BAD_OPCODE; |
| 1184 | break; |
| 1185 | } |
| 1186 | |
| 1187 | return (status); |
| 1188 | } |
| 1189 | |