Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Module Name: dsobject - Dispatcher object management routines |
| 4 | * |
| 5 | *****************************************************************************/ |
| 6 | |
| 7 | /* |
Len Brown | 75a44ce | 2008-04-23 23:00:13 -0400 | [diff] [blame] | 8 | * Copyright (C) 2000 - 2008, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | * All rights reserved. |
| 10 | * |
| 11 | * Redistribution and use in source and binary forms, with or without |
| 12 | * modification, are permitted provided that the following conditions |
| 13 | * are met: |
| 14 | * 1. Redistributions of source code must retain the above copyright |
| 15 | * notice, this list of conditions, and the following disclaimer, |
| 16 | * without modification. |
| 17 | * 2. Redistributions in binary form must reproduce at minimum a disclaimer |
| 18 | * substantially similar to the "NO WARRANTY" disclaimer below |
| 19 | * ("Disclaimer") and any redistribution must be conditioned upon |
| 20 | * including a substantially similar Disclaimer requirement for further |
| 21 | * binary redistribution. |
| 22 | * 3. Neither the names of the above-listed copyright holders nor the names |
| 23 | * of any contributors may be used to endorse or promote products derived |
| 24 | * from this software without specific prior written permission. |
| 25 | * |
| 26 | * Alternatively, this software may be distributed under the terms of the |
| 27 | * GNU General Public License ("GPL") version 2 as published by the Free |
| 28 | * Software Foundation. |
| 29 | * |
| 30 | * NO WARRANTY |
| 31 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 32 | * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 33 | * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR |
| 34 | * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 35 | * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 36 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 37 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 38 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 39 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 40 | * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 41 | * POSSIBILITY OF SUCH DAMAGES. |
| 42 | */ |
| 43 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | #include <acpi/acpi.h> |
| 45 | #include <acpi/acparser.h> |
| 46 | #include <acpi/amlcode.h> |
| 47 | #include <acpi/acdispat.h> |
| 48 | #include <acpi/acnamesp.h> |
| 49 | #include <acpi/acinterp.h> |
| 50 | |
| 51 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 52 | ACPI_MODULE_NAME("dsobject") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 54 | /* Local prototypes */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 55 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 56 | acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, |
| 57 | union acpi_parse_object *op, |
| 58 | union acpi_operand_object **obj_desc_ptr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | |
| 60 | #ifndef ACPI_NO_METHOD_EXECUTION |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 61 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | * |
| 63 | * FUNCTION: acpi_ds_build_internal_object |
| 64 | * |
| 65 | * PARAMETERS: walk_state - Current walk state |
| 66 | * Op - Parser object to be translated |
| 67 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 68 | * |
| 69 | * RETURN: Status |
| 70 | * |
| 71 | * DESCRIPTION: Translate a parser Op object to the equivalent namespace object |
| 72 | * Simple objects are any objects other than a package object! |
| 73 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 74 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 76 | static acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 77 | acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, |
| 78 | union acpi_parse_object *op, |
| 79 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 81 | union acpi_operand_object *obj_desc; |
| 82 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 84 | ACPI_FUNCTION_TRACE(ds_build_internal_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | |
| 86 | *obj_desc_ptr = NULL; |
| 87 | if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { |
| 88 | /* |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 89 | * This is a named object reference. If this name was |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | * previously looked up in the namespace, it was stored in this op. |
| 91 | * Otherwise, go ahead and look it up now |
| 92 | */ |
| 93 | if (!op->common.node) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | status = acpi_ns_lookup(walk_state->scope_info, |
| 95 | op->common.value.string, |
| 96 | ACPI_TYPE_ANY, |
| 97 | ACPI_IMODE_EXECUTE, |
| 98 | ACPI_NS_SEARCH_PARENT | |
| 99 | ACPI_NS_DONT_OPEN_SCOPE, NULL, |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 100 | ACPI_CAST_INDIRECT_PTR(struct |
| 101 | acpi_namespace_node, |
| 102 | &(op-> |
| 103 | common. |
| 104 | node))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 105 | if (ACPI_FAILURE(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 106 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 107 | /* Check if we are resolving a named reference within a package */ |
| 108 | |
| 109 | if ((status == AE_NOT_FOUND) |
| 110 | && (acpi_gbl_enable_interpreter_slack) |
| 111 | && |
| 112 | ((op->common.parent->common.aml_opcode == |
| 113 | AML_PACKAGE_OP) |
| 114 | || (op->common.parent->common.aml_opcode == |
| 115 | AML_VAR_PACKAGE_OP))) { |
| 116 | /* |
| 117 | * We didn't find the target and we are populating elements |
| 118 | * of a package - ignore if slack enabled. Some ASL code |
| 119 | * contains dangling invalid references in packages and |
| 120 | * expects that no exception will be issued. Leave the |
| 121 | * element as a null element. It cannot be used, but it |
| 122 | * can be overwritten by subsequent ASL code - this is |
| 123 | * typically the case. |
| 124 | */ |
| 125 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 126 | "Ignoring unresolved reference in package [%4.4s]\n", |
| 127 | walk_state-> |
| 128 | scope_info->scope. |
| 129 | node->name.ascii)); |
| 130 | |
| 131 | return_ACPI_STATUS(AE_OK); |
| 132 | } else { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 133 | ACPI_ERROR_NAMESPACE(op->common.value. |
| 134 | string, status); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 135 | } |
| 136 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 137 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | } |
| 139 | } |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 140 | |
| 141 | /* Special object resolution for elements of a package */ |
| 142 | |
| 143 | if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || |
| 144 | (op->common.parent->common.aml_opcode == |
| 145 | AML_VAR_PACKAGE_OP)) { |
| 146 | /* |
| 147 | * Attempt to resolve the node to a value before we insert it into |
| 148 | * the package. If this is a reference to a common data type, |
| 149 | * resolve it immediately. According to the ACPI spec, package |
| 150 | * elements can only be "data objects" or method references. |
| 151 | * Attempt to resolve to an Integer, Buffer, String or Package. |
| 152 | * If cannot, return the named reference (for things like Devices, |
| 153 | * Methods, etc.) Buffer Fields and Fields will resolve to simple |
| 154 | * objects (int/buf/str/pkg). |
| 155 | * |
| 156 | * NOTE: References to things like Devices, Methods, Mutexes, etc. |
| 157 | * will remain as named references. This behavior is not described |
| 158 | * in the ACPI spec, but it appears to be an oversight. |
| 159 | */ |
Bob Moore | b7f9f04 | 2008-04-10 19:06:40 +0400 | [diff] [blame] | 160 | obj_desc = |
| 161 | ACPI_CAST_PTR(union acpi_operand_object, |
| 162 | op->common.node); |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 163 | |
| 164 | status = |
| 165 | acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR |
| 166 | (struct |
| 167 | acpi_namespace_node, |
| 168 | &obj_desc), |
| 169 | walk_state); |
| 170 | if (ACPI_FAILURE(status)) { |
| 171 | return_ACPI_STATUS(status); |
| 172 | } |
| 173 | |
| 174 | switch (op->common.node->type) { |
| 175 | /* |
| 176 | * For these types, we need the actual node, not the subobject. |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 177 | * However, the subobject did not get an extra reference count above. |
| 178 | * |
| 179 | * TBD: should ex_resolve_node_to_value be changed to fix this? |
| 180 | */ |
| 181 | case ACPI_TYPE_DEVICE: |
| 182 | case ACPI_TYPE_THERMAL: |
| 183 | |
| 184 | acpi_ut_add_reference(op->common.node->object); |
| 185 | |
| 186 | /*lint -fallthrough */ |
| 187 | /* |
| 188 | * For these types, we need the actual node, not the subobject. |
| 189 | * The subobject got an extra reference count in ex_resolve_node_to_value. |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 190 | */ |
| 191 | case ACPI_TYPE_MUTEX: |
| 192 | case ACPI_TYPE_METHOD: |
| 193 | case ACPI_TYPE_POWER: |
| 194 | case ACPI_TYPE_PROCESSOR: |
| 195 | case ACPI_TYPE_EVENT: |
| 196 | case ACPI_TYPE_REGION: |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 197 | |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 198 | /* We will create a reference object for these types below */ |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 199 | break; |
| 200 | |
| 201 | default: |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 202 | /* |
| 203 | * All other types - the node was resolved to an actual |
| 204 | * object, we are done. |
| 205 | */ |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 206 | goto exit; |
| 207 | } |
| 208 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | } |
| 210 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 211 | /* Create and init a new internal ACPI object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 212 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 213 | obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info |
| 214 | (op->common.aml_opcode))-> |
| 215 | object_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 217 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | } |
| 219 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 220 | status = |
| 221 | acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode, |
| 222 | &obj_desc); |
| 223 | if (ACPI_FAILURE(status)) { |
| 224 | acpi_ut_remove_reference(obj_desc); |
| 225 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 228 | exit: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | *obj_desc_ptr = obj_desc; |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 230 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | } |
| 232 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 233 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 234 | * |
| 235 | * FUNCTION: acpi_ds_build_internal_buffer_obj |
| 236 | * |
| 237 | * PARAMETERS: walk_state - Current walk state |
| 238 | * Op - Parser object to be translated |
| 239 | * buffer_length - Length of the buffer |
| 240 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 241 | * |
| 242 | * RETURN: Status |
| 243 | * |
| 244 | * DESCRIPTION: Translate a parser Op package object to the equivalent |
| 245 | * namespace object |
| 246 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 247 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | |
| 249 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 250 | acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, |
| 251 | union acpi_parse_object *op, |
| 252 | u32 buffer_length, |
| 253 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 255 | union acpi_parse_object *arg; |
| 256 | union acpi_operand_object *obj_desc; |
| 257 | union acpi_parse_object *byte_list; |
| 258 | u32 byte_list_length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 260 | ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 262 | /* |
| 263 | * If we are evaluating a Named buffer object "Name (xxxx, Buffer)". |
| 264 | * The buffer object already exists (from the NS node), otherwise it must |
| 265 | * be created. |
| 266 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 267 | obj_desc = *obj_desc_ptr; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 268 | if (!obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 269 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | /* Create a new buffer object */ |
| 271 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | *obj_desc_ptr = obj_desc; |
| 274 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | } |
| 278 | |
| 279 | /* |
| 280 | * Second arg is the buffer data (optional) byte_list can be either |
| 281 | * individual bytes or a string initializer. In either case, a |
| 282 | * byte_list appears in the AML. |
| 283 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 284 | arg = op->common.value.arg; /* skip first arg */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | |
| 286 | byte_list = arg->named.next; |
| 287 | if (byte_list) { |
| 288 | if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 289 | ACPI_ERROR((AE_INFO, |
| 290 | "Expecting bytelist, got AML opcode %X in op %p", |
| 291 | byte_list->common.aml_opcode, byte_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | return (AE_TYPE); |
| 295 | } |
| 296 | |
| 297 | byte_list_length = (u32) byte_list->common.value.integer; |
| 298 | } |
| 299 | |
| 300 | /* |
| 301 | * The buffer length (number of bytes) will be the larger of: |
| 302 | * 1) The specified buffer length and |
| 303 | * 2) The length of the initializer byte list |
| 304 | */ |
| 305 | obj_desc->buffer.length = buffer_length; |
| 306 | if (byte_list_length > buffer_length) { |
| 307 | obj_desc->buffer.length = byte_list_length; |
| 308 | } |
| 309 | |
| 310 | /* Allocate the buffer */ |
| 311 | |
| 312 | if (obj_desc->buffer.length == 0) { |
| 313 | obj_desc->buffer.pointer = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 314 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 315 | "Buffer defined with zero length in AML, creating\n")); |
| 316 | } else { |
| 317 | obj_desc->buffer.pointer = |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 318 | ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | if (!obj_desc->buffer.pointer) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | acpi_ut_delete_object_desc(obj_desc); |
| 321 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | } |
| 323 | |
| 324 | /* Initialize buffer from the byte_list (if present) */ |
| 325 | |
| 326 | if (byte_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 327 | ACPI_MEMCPY(obj_desc->buffer.pointer, |
| 328 | byte_list->named.data, byte_list_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | obj_desc->buffer.flags |= AOPOBJ_DATA_VALID; |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 333 | op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 334 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 335 | } |
| 336 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 337 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 338 | * |
| 339 | * FUNCTION: acpi_ds_build_internal_package_obj |
| 340 | * |
| 341 | * PARAMETERS: walk_state - Current walk state |
| 342 | * Op - Parser object to be translated |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 343 | * element_count - Number of elements in the package - this is |
| 344 | * the num_elements argument to Package() |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 346 | * |
| 347 | * RETURN: Status |
| 348 | * |
| 349 | * DESCRIPTION: Translate a parser Op package object to the equivalent |
| 350 | * namespace object |
| 351 | * |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 352 | * NOTE: The number of elements in the package will be always be the num_elements |
| 353 | * count, regardless of the number of elements in the package list. If |
| 354 | * num_elements is smaller, only that many package list elements are used. |
| 355 | * if num_elements is larger, the Package object is padded out with |
| 356 | * objects of type Uninitialized (as per ACPI spec.) |
| 357 | * |
| 358 | * Even though the ASL compilers do not allow num_elements to be smaller |
| 359 | * than the Package list length (for the fixed length package opcode), some |
| 360 | * BIOS code modifies the AML on the fly to adjust the num_elements, and |
| 361 | * this code compensates for that. This also provides compatibility with |
| 362 | * other AML interpreters. |
| 363 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 364 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
| 366 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 367 | acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state, |
| 368 | union acpi_parse_object *op, |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 369 | u32 element_count, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 370 | union acpi_operand_object **obj_desc_ptr) |
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_parse_object *arg; |
| 373 | union acpi_parse_object *parent; |
| 374 | union acpi_operand_object *obj_desc = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 375 | acpi_status status = AE_OK; |
Bob Moore | 0ba7d25 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 376 | unsigned i; |
Bob Moore | 91d0213 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 377 | u16 index; |
| 378 | u16 reference_count; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 380 | ACPI_FUNCTION_TRACE(ds_build_internal_package_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | |
| 382 | /* Find the parent of a possibly nested package */ |
| 383 | |
| 384 | parent = op->common.parent; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 385 | while ((parent->common.aml_opcode == AML_PACKAGE_OP) || |
| 386 | (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | parent = parent->common.parent; |
| 388 | } |
| 389 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 390 | /* |
| 391 | * If we are evaluating a Named package object "Name (xxxx, Package)", |
| 392 | * the package object already exists, otherwise it must be created. |
| 393 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | obj_desc = *obj_desc_ptr; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 395 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 396 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | *obj_desc_ptr = obj_desc; |
| 398 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } |
| 401 | |
| 402 | obj_desc->package.node = parent->common.node; |
| 403 | } |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | /* |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 406 | * Allocate the element array (array of pointers to the individual |
| 407 | * objects) based on the num_elements parameter. Add an extra pointer slot |
| 408 | * so that the list is always null terminated. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | */ |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 410 | obj_desc->package.elements = ACPI_ALLOCATE_ZEROED(((acpi_size) |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 411 | element_count + |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 412 | 1) * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
| 414 | if (!obj_desc->package.elements) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 415 | acpi_ut_delete_object_desc(obj_desc); |
| 416 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } |
| 418 | |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 419 | obj_desc->package.count = element_count; |
| 420 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 421 | /* |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 422 | * Initialize the elements of the package, up to the num_elements count. |
| 423 | * Package is automatically padded with uninitialized (NULL) elements |
| 424 | * if num_elements is greater than the package list length. Likewise, |
| 425 | * Package is truncated if num_elements is less than the list length. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | arg = op->common.value.arg; |
| 428 | arg = arg->common.next; |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 429 | for (i = 0; arg && (i < element_count); i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 431 | if (arg->common.node->type == ACPI_TYPE_METHOD) { |
| 432 | /* |
| 433 | * A method reference "looks" to the parser to be a method |
| 434 | * invocation, so we special case it here |
| 435 | */ |
| 436 | arg->common.aml_opcode = AML_INT_NAMEPATH_OP; |
| 437 | status = |
| 438 | acpi_ds_build_internal_object(walk_state, |
| 439 | arg, |
| 440 | &obj_desc-> |
| 441 | package. |
| 442 | elements[i]); |
| 443 | } else { |
| 444 | /* This package element is already built, just get it */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 445 | |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 446 | obj_desc->package.elements[i] = |
| 447 | ACPI_CAST_PTR(union acpi_operand_object, |
| 448 | arg->common.node); |
| 449 | } |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | } else { |
| 451 | status = acpi_ds_build_internal_object(walk_state, arg, |
| 452 | &obj_desc-> |
| 453 | package. |
| 454 | elements[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | } |
Bob Moore | 91d0213 | 2008-04-10 19:06:38 +0400 | [diff] [blame] | 456 | |
| 457 | if (*obj_desc_ptr) { |
| 458 | |
| 459 | /* Existing package, get existing reference count */ |
| 460 | |
| 461 | reference_count = |
| 462 | (*obj_desc_ptr)->common.reference_count; |
| 463 | if (reference_count > 1) { |
| 464 | |
| 465 | /* Make new element ref count match original ref count */ |
| 466 | |
| 467 | for (index = 0; index < (reference_count - 1); |
| 468 | index++) { |
| 469 | acpi_ut_add_reference((obj_desc-> |
| 470 | package. |
| 471 | elements[i])); |
| 472 | } |
| 473 | } |
| 474 | } |
| 475 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | arg = arg->common.next; |
| 477 | } |
| 478 | |
Bob Moore | 0ba7d25 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 479 | /* Check for match between num_elements and actual length of package_list */ |
| 480 | |
| 481 | if (arg) { |
| 482 | /* |
| 483 | * num_elements was exhausted, but there are remaining elements in the |
| 484 | * package_list. |
| 485 | * |
| 486 | * Note: technically, this is an error, from ACPI spec: "It is an error |
| 487 | * for NumElements to be less than the number of elements in the |
| 488 | * PackageList". However, for now, we just print an error message and |
| 489 | * no exception is returned. |
| 490 | */ |
| 491 | while (arg) { |
| 492 | |
| 493 | /* Find out how many elements there really are */ |
| 494 | |
| 495 | i++; |
| 496 | arg = arg->common.next; |
| 497 | } |
| 498 | |
| 499 | ACPI_ERROR((AE_INFO, |
| 500 | "Package List length (%X) larger than NumElements count (%X), truncated\n", |
| 501 | i, element_count)); |
| 502 | } else if (i < element_count) { |
| 503 | /* |
| 504 | * Arg list (elements) was exhausted, but we did not reach num_elements count. |
| 505 | * Note: this is not an error, the package is padded out with NULLs. |
| 506 | */ |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 507 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
Bob Moore | 0ba7d25 | 2008-04-10 19:06:43 +0400 | [diff] [blame] | 508 | "Package List length (%X) smaller than NumElements count (%X), padded with null elements\n", |
| 509 | i, element_count)); |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 510 | } |
| 511 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 512 | obj_desc->package.flags |= AOPOBJ_DATA_VALID; |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 513 | op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 515 | } |
| 516 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 517 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | * |
| 519 | * FUNCTION: acpi_ds_create_node |
| 520 | * |
| 521 | * PARAMETERS: walk_state - Current walk state |
| 522 | * Node - NS Node to be initialized |
| 523 | * Op - Parser object to be translated |
| 524 | * |
| 525 | * RETURN: Status |
| 526 | * |
| 527 | * DESCRIPTION: Create the object to be associated with a namespace node |
| 528 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 529 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | |
| 531 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | acpi_ds_create_node(struct acpi_walk_state *walk_state, |
| 533 | struct acpi_namespace_node *node, |
| 534 | union acpi_parse_object *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 536 | acpi_status status; |
| 537 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 539 | ACPI_FUNCTION_TRACE_PTR(ds_create_node, op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 540 | |
| 541 | /* |
| 542 | * Because of the execution pass through the non-control-method |
| 543 | * parts of the table, we can arrive here twice. Only init |
| 544 | * the named object node the first time through |
| 545 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 546 | if (acpi_ns_get_attached_object(node)) { |
| 547 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | } |
| 549 | |
| 550 | if (!op->common.value.arg) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 551 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 552 | /* No arguments, there is nothing to do */ |
| 553 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 554 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | } |
| 556 | |
| 557 | /* Build an internal object for the argument(s) */ |
| 558 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 559 | status = acpi_ds_build_internal_object(walk_state, op->common.value.arg, |
| 560 | &obj_desc); |
| 561 | if (ACPI_FAILURE(status)) { |
| 562 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /* Re-type the object according to its argument */ |
| 566 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 567 | node->type = ACPI_GET_OBJECT_TYPE(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 568 | |
| 569 | /* Attach obj to node */ |
| 570 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 571 | status = acpi_ns_attach_object(node, obj_desc, node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 572 | |
| 573 | /* Remove local reference to the object */ |
| 574 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 575 | acpi_ut_remove_reference(obj_desc); |
| 576 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } |
| 578 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 579 | #endif /* ACPI_NO_METHOD_EXECUTION */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 581 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 582 | * |
| 583 | * FUNCTION: acpi_ds_init_object_from_op |
| 584 | * |
| 585 | * PARAMETERS: walk_state - Current walk state |
| 586 | * Op - Parser op used to init the internal object |
| 587 | * Opcode - AML opcode associated with the object |
| 588 | * ret_obj_desc - Namespace object to be initialized |
| 589 | * |
| 590 | * RETURN: Status |
| 591 | * |
| 592 | * DESCRIPTION: Initialize a namespace object from a parser Op and its |
| 593 | * associated arguments. The namespace object is a more compact |
| 594 | * representation of the Op and its arguments. |
| 595 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 596 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | |
| 598 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 599 | acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state, |
| 600 | union acpi_parse_object *op, |
| 601 | u16 opcode, |
| 602 | union acpi_operand_object **ret_obj_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 604 | const struct acpi_opcode_info *op_info; |
| 605 | union acpi_operand_object *obj_desc; |
| 606 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 607 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 608 | ACPI_FUNCTION_TRACE(ds_init_object_from_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | obj_desc = *ret_obj_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | op_info = acpi_ps_get_opcode_info(opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | if (op_info->class == AML_CLASS_UNKNOWN) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 613 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | /* Unknown opcode */ |
| 615 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | /* Perform per-object initialization */ |
| 620 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 621 | switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | case ACPI_TYPE_BUFFER: |
| 623 | |
| 624 | /* |
| 625 | * Defer evaluation of Buffer term_arg operand |
| 626 | */ |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 627 | obj_desc->buffer.node = |
| 628 | ACPI_CAST_PTR(struct acpi_namespace_node, |
| 629 | walk_state->operands[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 | obj_desc->buffer.aml_start = op->named.data; |
| 631 | obj_desc->buffer.aml_length = op->named.length; |
| 632 | break; |
| 633 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 634 | case ACPI_TYPE_PACKAGE: |
| 635 | |
| 636 | /* |
| 637 | * Defer evaluation of Package term_arg operand |
| 638 | */ |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 639 | obj_desc->package.node = |
| 640 | ACPI_CAST_PTR(struct acpi_namespace_node, |
| 641 | walk_state->operands[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 642 | obj_desc->package.aml_start = op->named.data; |
| 643 | obj_desc->package.aml_length = op->named.length; |
| 644 | break; |
| 645 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | case ACPI_TYPE_INTEGER: |
| 647 | |
| 648 | switch (op_info->type) { |
| 649 | case AML_TYPE_CONSTANT: |
| 650 | /* |
| 651 | * Resolve AML Constants here - AND ONLY HERE! |
| 652 | * All constants are integers. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 653 | * We mark the integer with a flag that indicates that it started |
| 654 | * life as a constant -- so that stores to constants will perform |
| 655 | * as expected (noop). zero_op is used as a placeholder for optional |
| 656 | * target operands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | */ |
| 658 | obj_desc->common.flags = AOPOBJ_AML_CONSTANT; |
| 659 | |
| 660 | switch (opcode) { |
| 661 | case AML_ZERO_OP: |
| 662 | |
| 663 | obj_desc->integer.value = 0; |
| 664 | break; |
| 665 | |
| 666 | case AML_ONE_OP: |
| 667 | |
| 668 | obj_desc->integer.value = 1; |
| 669 | break; |
| 670 | |
| 671 | case AML_ONES_OP: |
| 672 | |
| 673 | obj_desc->integer.value = ACPI_INTEGER_MAX; |
| 674 | |
| 675 | /* Truncate value if we are executing from a 32-bit ACPI table */ |
| 676 | |
| 677 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | acpi_ex_truncate_for32bit_table(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | #endif |
| 680 | break; |
| 681 | |
| 682 | case AML_REVISION_OP: |
| 683 | |
| 684 | obj_desc->integer.value = ACPI_CA_VERSION; |
| 685 | break; |
| 686 | |
| 687 | default: |
| 688 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 689 | ACPI_ERROR((AE_INFO, |
| 690 | "Unknown constant opcode %X", |
| 691 | opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 692 | status = AE_AML_OPERAND_TYPE; |
| 693 | break; |
| 694 | } |
| 695 | break; |
| 696 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | case AML_TYPE_LITERAL: |
| 698 | |
| 699 | obj_desc->integer.value = op->common.value.integer; |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 700 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | acpi_ex_truncate_for32bit_table(obj_desc); |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 702 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | break; |
| 704 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 | default: |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 706 | ACPI_ERROR((AE_INFO, "Unknown Integer type %X", |
| 707 | op_info->type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | status = AE_AML_OPERAND_TYPE; |
| 709 | break; |
| 710 | } |
| 711 | break; |
| 712 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | case ACPI_TYPE_STRING: |
| 714 | |
| 715 | obj_desc->string.pointer = op->common.value.string; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 716 | obj_desc->string.length = |
| 717 | (u32) ACPI_STRLEN(op->common.value.string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | |
| 719 | /* |
| 720 | * The string is contained in the ACPI table, don't ever try |
| 721 | * to delete it |
| 722 | */ |
| 723 | obj_desc->common.flags |= AOPOBJ_STATIC_POINTER; |
| 724 | break; |
| 725 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | case ACPI_TYPE_METHOD: |
| 727 | break; |
| 728 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 730 | |
| 731 | switch (op_info->type) { |
| 732 | case AML_TYPE_LOCAL_VARIABLE: |
| 733 | |
| 734 | /* Split the opcode into a base opcode + offset */ |
| 735 | |
| 736 | obj_desc->reference.opcode = AML_LOCAL_OP; |
| 737 | obj_desc->reference.offset = opcode - AML_LOCAL_OP; |
| 738 | |
| 739 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 740 | status = acpi_ds_method_data_get_node(AML_LOCAL_OP, |
| 741 | obj_desc-> |
| 742 | reference.offset, |
| 743 | walk_state, |
| 744 | (struct |
| 745 | acpi_namespace_node |
| 746 | **)&obj_desc-> |
| 747 | reference.object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | #endif |
| 749 | break; |
| 750 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | case AML_TYPE_METHOD_ARGUMENT: |
| 752 | |
| 753 | /* Split the opcode into a base opcode + offset */ |
| 754 | |
| 755 | obj_desc->reference.opcode = AML_ARG_OP; |
| 756 | obj_desc->reference.offset = opcode - AML_ARG_OP; |
| 757 | |
| 758 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 759 | status = acpi_ds_method_data_get_node(AML_ARG_OP, |
| 760 | obj_desc-> |
| 761 | reference.offset, |
| 762 | walk_state, |
| 763 | (struct |
| 764 | acpi_namespace_node |
| 765 | **)&obj_desc-> |
| 766 | reference.object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | #endif |
| 768 | break; |
| 769 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 770 | default: /* Other literals, etc.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | |
| 772 | if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 773 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 774 | /* Node was saved in Op */ |
| 775 | |
| 776 | obj_desc->reference.node = op->common.node; |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 777 | obj_desc->reference.object = |
| 778 | op->common.node->object; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | obj_desc->reference.opcode = opcode; |
| 782 | break; |
| 783 | } |
| 784 | break; |
| 785 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | default: |
| 787 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 788 | ACPI_ERROR((AE_INFO, "Unimplemented data type: %X", |
| 789 | ACPI_GET_OBJECT_TYPE(obj_desc))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | |
| 791 | status = AE_AML_OPERAND_TYPE; |
| 792 | break; |
| 793 | } |
| 794 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 795 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 796 | } |