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