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