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