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