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