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