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