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 | /* |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 8 | * Copyright (C) 2000 - 2006, R. Byron Moore |
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 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -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 | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 106 | /* Check if we are resolving a named reference within a package */ |
| 107 | |
| 108 | if ((status == AE_NOT_FOUND) |
| 109 | && (acpi_gbl_enable_interpreter_slack) |
| 110 | && |
| 111 | ((op->common.parent->common.aml_opcode == |
| 112 | AML_PACKAGE_OP) |
| 113 | || (op->common.parent->common.aml_opcode == |
| 114 | AML_VAR_PACKAGE_OP))) { |
| 115 | /* |
| 116 | * We didn't find the target and we are populating elements |
| 117 | * of a package - ignore if slack enabled. Some ASL code |
| 118 | * contains dangling invalid references in packages and |
| 119 | * expects that no exception will be issued. Leave the |
| 120 | * element as a null element. It cannot be used, but it |
| 121 | * can be overwritten by subsequent ASL code - this is |
| 122 | * typically the case. |
| 123 | */ |
| 124 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, |
| 125 | "Ignoring unresolved reference in package [%4.4s]\n", |
| 126 | walk_state-> |
| 127 | scope_info->scope. |
| 128 | node->name.ascii)); |
| 129 | |
| 130 | return_ACPI_STATUS(AE_OK); |
| 131 | } else { |
| 132 | ACPI_REPORT_NSERROR(op->common.value. |
| 133 | string, status); |
| 134 | } |
| 135 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 136 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | } |
| 140 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 141 | /* Create and init a new internal ACPI object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 143 | obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info |
| 144 | (op->common.aml_opcode))-> |
| 145 | object_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 147 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 148 | } |
| 149 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | status = |
| 151 | acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode, |
| 152 | &obj_desc); |
| 153 | if (ACPI_FAILURE(status)) { |
| 154 | acpi_ut_remove_reference(obj_desc); |
| 155 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 156 | } |
| 157 | |
| 158 | *obj_desc_ptr = obj_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 159 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | } |
| 161 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 162 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 163 | * |
| 164 | * FUNCTION: acpi_ds_build_internal_buffer_obj |
| 165 | * |
| 166 | * PARAMETERS: walk_state - Current walk state |
| 167 | * Op - Parser object to be translated |
| 168 | * buffer_length - Length of the buffer |
| 169 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 170 | * |
| 171 | * RETURN: Status |
| 172 | * |
| 173 | * DESCRIPTION: Translate a parser Op package object to the equivalent |
| 174 | * namespace object |
| 175 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 176 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | |
| 178 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 179 | acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, |
| 180 | union acpi_parse_object *op, |
| 181 | u32 buffer_length, |
| 182 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 184 | union acpi_parse_object *arg; |
| 185 | union acpi_operand_object *obj_desc; |
| 186 | union acpi_parse_object *byte_list; |
| 187 | u32 byte_list_length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 188 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 189 | ACPI_FUNCTION_TRACE("ds_build_internal_buffer_obj"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 190 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 191 | /* |
| 192 | * If we are evaluating a Named buffer object "Name (xxxx, Buffer)". |
| 193 | * The buffer object already exists (from the NS node), otherwise it must |
| 194 | * be created. |
| 195 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | obj_desc = *obj_desc_ptr; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 197 | if (!obj_desc) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 198 | /* Create a new buffer object */ |
| 199 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 200 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | *obj_desc_ptr = obj_desc; |
| 202 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 203 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 204 | } |
| 205 | } |
| 206 | |
| 207 | /* |
| 208 | * Second arg is the buffer data (optional) byte_list can be either |
| 209 | * individual bytes or a string initializer. In either case, a |
| 210 | * byte_list appears in the AML. |
| 211 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 212 | arg = op->common.value.arg; /* skip first arg */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | |
| 214 | byte_list = arg->named.next; |
| 215 | if (byte_list) { |
| 216 | if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) { |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 217 | ACPI_REPORT_ERROR(("Expecting bytelist, got AML opcode %X in op %p\n", byte_list->common.aml_opcode, byte_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | return (AE_TYPE); |
| 221 | } |
| 222 | |
| 223 | byte_list_length = (u32) byte_list->common.value.integer; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * The buffer length (number of bytes) will be the larger of: |
| 228 | * 1) The specified buffer length and |
| 229 | * 2) The length of the initializer byte list |
| 230 | */ |
| 231 | obj_desc->buffer.length = buffer_length; |
| 232 | if (byte_list_length > buffer_length) { |
| 233 | obj_desc->buffer.length = byte_list_length; |
| 234 | } |
| 235 | |
| 236 | /* Allocate the buffer */ |
| 237 | |
| 238 | if (obj_desc->buffer.length == 0) { |
| 239 | obj_desc->buffer.pointer = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 240 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 241 | "Buffer defined with zero length in AML, creating\n")); |
| 242 | } else { |
| 243 | obj_desc->buffer.pointer = |
| 244 | ACPI_MEM_CALLOCATE(obj_desc->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | if (!obj_desc->buffer.pointer) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 246 | acpi_ut_delete_object_desc(obj_desc); |
| 247 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | } |
| 249 | |
| 250 | /* Initialize buffer from the byte_list (if present) */ |
| 251 | |
| 252 | if (byte_list) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | ACPI_MEMCPY(obj_desc->buffer.pointer, |
| 254 | byte_list->named.data, byte_list_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } |
| 256 | } |
| 257 | |
| 258 | obj_desc->buffer.flags |= AOPOBJ_DATA_VALID; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | op->common.node = (struct acpi_namespace_node *)obj_desc; |
| 260 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 263 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | * |
| 265 | * FUNCTION: acpi_ds_build_internal_package_obj |
| 266 | * |
| 267 | * PARAMETERS: walk_state - Current walk state |
| 268 | * Op - Parser object to be translated |
| 269 | * package_length - Number of elements in the package |
| 270 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 271 | * |
| 272 | * RETURN: Status |
| 273 | * |
| 274 | * DESCRIPTION: Translate a parser Op package object to the equivalent |
| 275 | * namespace object |
| 276 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 277 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | |
| 279 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 280 | acpi_ds_build_internal_package_obj(struct acpi_walk_state *walk_state, |
| 281 | union acpi_parse_object *op, |
| 282 | u32 package_length, |
| 283 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 285 | union acpi_parse_object *arg; |
| 286 | union acpi_parse_object *parent; |
| 287 | union acpi_operand_object *obj_desc = NULL; |
| 288 | u32 package_list_length; |
| 289 | acpi_status status = AE_OK; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 290 | acpi_native_uint i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | ACPI_FUNCTION_TRACE("ds_build_internal_package_obj"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | |
| 294 | /* Find the parent of a possibly nested package */ |
| 295 | |
| 296 | parent = op->common.parent; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | while ((parent->common.aml_opcode == AML_PACKAGE_OP) || |
| 298 | (parent->common.aml_opcode == AML_VAR_PACKAGE_OP)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | parent = parent->common.parent; |
| 300 | } |
| 301 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 302 | /* |
| 303 | * If we are evaluating a Named package object "Name (xxxx, Package)", |
| 304 | * the package object already exists, otherwise it must be created. |
| 305 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | obj_desc = *obj_desc_ptr; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 307 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_PACKAGE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | *obj_desc_ptr = obj_desc; |
| 310 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 311 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 312 | } |
| 313 | |
| 314 | obj_desc->package.node = parent->common.node; |
| 315 | } |
| 316 | |
| 317 | obj_desc->package.count = package_length; |
| 318 | |
| 319 | /* Count the number of items in the package list */ |
| 320 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | arg = op->common.value.arg; |
| 322 | arg = arg->common.next; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 323 | for (package_list_length = 0; arg; package_list_length++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | arg = arg->common.next; |
| 325 | } |
| 326 | |
| 327 | /* |
| 328 | * The package length (number of elements) will be the greater |
| 329 | * of the specified length and the length of the initializer list |
| 330 | */ |
| 331 | if (package_list_length > package_length) { |
| 332 | obj_desc->package.count = package_list_length; |
| 333 | } |
| 334 | |
| 335 | /* |
| 336 | * Allocate the pointer array (array of pointers to the |
| 337 | * individual objects). Add an extra pointer slot so |
| 338 | * that the list is always null terminated. |
| 339 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 340 | obj_desc->package.elements = ACPI_MEM_CALLOCATE(((acpi_size) obj_desc-> |
| 341 | package.count + |
| 342 | 1) * sizeof(void *)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
| 344 | if (!obj_desc->package.elements) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 345 | acpi_ut_delete_object_desc(obj_desc); |
| 346 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 347 | } |
| 348 | |
| 349 | /* |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 350 | * Initialize all elements of the package |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | arg = op->common.value.arg; |
| 353 | arg = arg->common.next; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 354 | for (i = 0; arg; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | if (arg->common.aml_opcode == AML_INT_RETURN_VALUE_OP) { |
| 356 | /* Object (package or buffer) is already built */ |
| 357 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 358 | obj_desc->package.elements[i] = |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 359 | ACPI_CAST_PTR(union acpi_operand_object, |
| 360 | arg->common.node); |
| 361 | } else { |
| 362 | status = acpi_ds_build_internal_object(walk_state, arg, |
| 363 | &obj_desc-> |
| 364 | package. |
| 365 | elements[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 366 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | arg = arg->common.next; |
| 368 | } |
| 369 | |
| 370 | obj_desc->package.flags |= AOPOBJ_DATA_VALID; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 371 | op->common.node = (struct acpi_namespace_node *)obj_desc; |
| 372 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | } |
| 374 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 375 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | * |
| 377 | * FUNCTION: acpi_ds_create_node |
| 378 | * |
| 379 | * PARAMETERS: walk_state - Current walk state |
| 380 | * Node - NS Node to be initialized |
| 381 | * Op - Parser object to be translated |
| 382 | * |
| 383 | * RETURN: Status |
| 384 | * |
| 385 | * DESCRIPTION: Create the object to be associated with a namespace node |
| 386 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 387 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
| 389 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 390 | acpi_ds_create_node(struct acpi_walk_state *walk_state, |
| 391 | struct acpi_namespace_node *node, |
| 392 | union acpi_parse_object *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 394 | acpi_status status; |
| 395 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 397 | ACPI_FUNCTION_TRACE_PTR("ds_create_node", op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 | |
| 399 | /* |
| 400 | * Because of the execution pass through the non-control-method |
| 401 | * parts of the table, we can arrive here twice. Only init |
| 402 | * the named object node the first time through |
| 403 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 404 | if (acpi_ns_get_attached_object(node)) { |
| 405 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | } |
| 407 | |
| 408 | if (!op->common.value.arg) { |
| 409 | /* No arguments, there is nothing to do */ |
| 410 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | } |
| 413 | |
| 414 | /* Build an internal object for the argument(s) */ |
| 415 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | status = acpi_ds_build_internal_object(walk_state, op->common.value.arg, |
| 417 | &obj_desc); |
| 418 | if (ACPI_FAILURE(status)) { |
| 419 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 | } |
| 421 | |
| 422 | /* Re-type the object according to its argument */ |
| 423 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 424 | node->type = ACPI_GET_OBJECT_TYPE(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | |
| 426 | /* Attach obj to node */ |
| 427 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 428 | status = acpi_ns_attach_object(node, obj_desc, node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
| 430 | /* Remove local reference to the object */ |
| 431 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 432 | acpi_ut_remove_reference(obj_desc); |
| 433 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 434 | } |
| 435 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 436 | #endif /* ACPI_NO_METHOD_EXECUTION */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 437 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 438 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | * |
| 440 | * FUNCTION: acpi_ds_init_object_from_op |
| 441 | * |
| 442 | * PARAMETERS: walk_state - Current walk state |
| 443 | * Op - Parser op used to init the internal object |
| 444 | * Opcode - AML opcode associated with the object |
| 445 | * ret_obj_desc - Namespace object to be initialized |
| 446 | * |
| 447 | * RETURN: Status |
| 448 | * |
| 449 | * DESCRIPTION: Initialize a namespace object from a parser Op and its |
| 450 | * associated arguments. The namespace object is a more compact |
| 451 | * representation of the Op and its arguments. |
| 452 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 453 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 456 | acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state, |
| 457 | union acpi_parse_object *op, |
| 458 | u16 opcode, |
| 459 | union acpi_operand_object **ret_obj_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 461 | const struct acpi_opcode_info *op_info; |
| 462 | union acpi_operand_object *obj_desc; |
| 463 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 465 | ACPI_FUNCTION_TRACE("ds_init_object_from_op"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 466 | |
| 467 | obj_desc = *ret_obj_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 468 | op_info = acpi_ps_get_opcode_info(opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | if (op_info->class == AML_CLASS_UNKNOWN) { |
| 470 | /* Unknown opcode */ |
| 471 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 472 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | } |
| 474 | |
| 475 | /* Perform per-object initialization */ |
| 476 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 477 | switch (ACPI_GET_OBJECT_TYPE(obj_desc)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | case ACPI_TYPE_BUFFER: |
| 479 | |
| 480 | /* |
| 481 | * Defer evaluation of Buffer term_arg operand |
| 482 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 483 | obj_desc->buffer.node = (struct acpi_namespace_node *) |
| 484 | walk_state->operands[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | obj_desc->buffer.aml_start = op->named.data; |
| 486 | obj_desc->buffer.aml_length = op->named.length; |
| 487 | break; |
| 488 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 489 | case ACPI_TYPE_PACKAGE: |
| 490 | |
| 491 | /* |
| 492 | * Defer evaluation of Package term_arg operand |
| 493 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 494 | obj_desc->package.node = (struct acpi_namespace_node *) |
| 495 | walk_state->operands[0]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | obj_desc->package.aml_start = op->named.data; |
| 497 | obj_desc->package.aml_length = op->named.length; |
| 498 | break; |
| 499 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 500 | case ACPI_TYPE_INTEGER: |
| 501 | |
| 502 | switch (op_info->type) { |
| 503 | case AML_TYPE_CONSTANT: |
| 504 | /* |
| 505 | * Resolve AML Constants here - AND ONLY HERE! |
| 506 | * All constants are integers. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 507 | * We mark the integer with a flag that indicates that it started |
| 508 | * life as a constant -- so that stores to constants will perform |
| 509 | * as expected (noop). zero_op is used as a placeholder for optional |
| 510 | * target operands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | */ |
| 512 | obj_desc->common.flags = AOPOBJ_AML_CONSTANT; |
| 513 | |
| 514 | switch (opcode) { |
| 515 | case AML_ZERO_OP: |
| 516 | |
| 517 | obj_desc->integer.value = 0; |
| 518 | break; |
| 519 | |
| 520 | case AML_ONE_OP: |
| 521 | |
| 522 | obj_desc->integer.value = 1; |
| 523 | break; |
| 524 | |
| 525 | case AML_ONES_OP: |
| 526 | |
| 527 | obj_desc->integer.value = ACPI_INTEGER_MAX; |
| 528 | |
| 529 | /* Truncate value if we are executing from a 32-bit ACPI table */ |
| 530 | |
| 531 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 532 | acpi_ex_truncate_for32bit_table(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | #endif |
| 534 | break; |
| 535 | |
| 536 | case AML_REVISION_OP: |
| 537 | |
| 538 | obj_desc->integer.value = ACPI_CA_VERSION; |
| 539 | break; |
| 540 | |
| 541 | default: |
| 542 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 543 | ACPI_REPORT_ERROR(("Unknown constant opcode %X\n", opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | status = AE_AML_OPERAND_TYPE; |
| 545 | break; |
| 546 | } |
| 547 | break; |
| 548 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | case AML_TYPE_LITERAL: |
| 550 | |
| 551 | obj_desc->integer.value = op->common.value.integer; |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 552 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 553 | acpi_ex_truncate_for32bit_table(obj_desc); |
Robert Moore | 6f42ccf | 2005-05-13 00:00:00 -0400 | [diff] [blame] | 554 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 555 | break; |
| 556 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 557 | default: |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 558 | ACPI_REPORT_ERROR(("Unknown Integer type %X\n", |
| 559 | op_info->type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | status = AE_AML_OPERAND_TYPE; |
| 561 | break; |
| 562 | } |
| 563 | break; |
| 564 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | case ACPI_TYPE_STRING: |
| 566 | |
| 567 | obj_desc->string.pointer = op->common.value.string; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | obj_desc->string.length = |
| 569 | (u32) ACPI_STRLEN(op->common.value.string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | |
| 571 | /* |
| 572 | * The string is contained in the ACPI table, don't ever try |
| 573 | * to delete it |
| 574 | */ |
| 575 | obj_desc->common.flags |= AOPOBJ_STATIC_POINTER; |
| 576 | break; |
| 577 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 578 | case ACPI_TYPE_METHOD: |
| 579 | break; |
| 580 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 582 | |
| 583 | switch (op_info->type) { |
| 584 | case AML_TYPE_LOCAL_VARIABLE: |
| 585 | |
| 586 | /* Split the opcode into a base opcode + offset */ |
| 587 | |
| 588 | obj_desc->reference.opcode = AML_LOCAL_OP; |
| 589 | obj_desc->reference.offset = opcode - AML_LOCAL_OP; |
| 590 | |
| 591 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 592 | status = acpi_ds_method_data_get_node(AML_LOCAL_OP, |
| 593 | obj_desc-> |
| 594 | reference.offset, |
| 595 | walk_state, |
| 596 | (struct |
| 597 | acpi_namespace_node |
| 598 | **)&obj_desc-> |
| 599 | reference.object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 600 | #endif |
| 601 | break; |
| 602 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | case AML_TYPE_METHOD_ARGUMENT: |
| 604 | |
| 605 | /* Split the opcode into a base opcode + offset */ |
| 606 | |
| 607 | obj_desc->reference.opcode = AML_ARG_OP; |
| 608 | obj_desc->reference.offset = opcode - AML_ARG_OP; |
| 609 | |
| 610 | #ifndef ACPI_NO_METHOD_EXECUTION |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 611 | status = acpi_ds_method_data_get_node(AML_ARG_OP, |
| 612 | obj_desc-> |
| 613 | reference.offset, |
| 614 | walk_state, |
| 615 | (struct |
| 616 | acpi_namespace_node |
| 617 | **)&obj_desc-> |
| 618 | reference.object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | #endif |
| 620 | break; |
| 621 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 622 | default: /* Other literals, etc.. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { |
| 625 | /* Node was saved in Op */ |
| 626 | |
| 627 | obj_desc->reference.node = op->common.node; |
| 628 | } |
| 629 | |
| 630 | obj_desc->reference.opcode = opcode; |
| 631 | break; |
| 632 | } |
| 633 | break; |
| 634 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 635 | default: |
| 636 | |
Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame^] | 637 | ACPI_REPORT_ERROR(("Unimplemented data type: %X\n", |
| 638 | ACPI_GET_OBJECT_TYPE(obj_desc))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 639 | |
| 640 | status = AE_AML_OPERAND_TYPE; |
| 641 | break; |
| 642 | } |
| 643 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 644 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | } |