Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 2 | /****************************************************************************** |
| 3 | * |
| 4 | * Module Name: dsobject - Dispatcher object management routines |
| 5 | * |
Bob Moore | 4441e55 | 2021-01-15 10:48:25 -0800 | [diff] [blame^] | 6 | * Copyright (C) 2000 - 2021, Intel Corp. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 7 | * |
Erik Schmauss | 9585763 | 2018-03-14 16:13:07 -0700 | [diff] [blame] | 8 | *****************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 9 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <acpi/acpi.h> |
Len Brown | e2f7a77 | 2009-01-09 00:30:03 -0500 | [diff] [blame] | 11 | #include "accommon.h" |
| 12 | #include "acparser.h" |
| 13 | #include "amlcode.h" |
| 14 | #include "acdispat.h" |
| 15 | #include "acnamesp.h" |
| 16 | #include "acinterp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | |
| 18 | #define _COMPONENT ACPI_DISPATCHER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 19 | ACPI_MODULE_NAME("dsobject") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 20 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 21 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 22 | * |
| 23 | * FUNCTION: acpi_ds_build_internal_object |
| 24 | * |
| 25 | * PARAMETERS: walk_state - Current walk state |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 26 | * op - Parser object to be translated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 28 | * |
| 29 | * RETURN: Status |
| 30 | * |
| 31 | * DESCRIPTION: Translate a parser Op object to the equivalent namespace object |
| 32 | * Simple objects are any objects other than a package object! |
| 33 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 34 | ******************************************************************************/ |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 35 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 36 | acpi_ds_build_internal_object(struct acpi_walk_state *walk_state, |
| 37 | union acpi_parse_object *op, |
| 38 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 40 | union acpi_operand_object *obj_desc; |
| 41 | acpi_status status; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 43 | ACPI_FUNCTION_TRACE(ds_build_internal_object); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | |
| 45 | *obj_desc_ptr = NULL; |
| 46 | if (op->common.aml_opcode == AML_INT_NAMEPATH_OP) { |
| 47 | /* |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 48 | * This is a named object reference. If this name was |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 49 | * previously looked up in the namespace, it was stored in |
| 50 | * this op. Otherwise, go ahead and look it up now |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 | */ |
| 52 | if (!op->common.node) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 53 | |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 54 | /* Check if we are resolving a named reference within a package */ |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 55 | |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 56 | if ((op->common.parent->common.aml_opcode == |
| 57 | AML_PACKAGE_OP) |
| 58 | || (op->common.parent->common.aml_opcode == |
| 59 | AML_VARIABLE_PACKAGE_OP)) { |
| 60 | /* |
| 61 | * We won't resolve package elements here, we will do this |
| 62 | * after all ACPI tables are loaded into the namespace. This |
| 63 | * behavior supports both forward references to named objects |
| 64 | * and external references to objects in other tables. |
| 65 | */ |
| 66 | goto create_new_object; |
| 67 | } else { |
| 68 | status = acpi_ns_lookup(walk_state->scope_info, |
| 69 | op->common.value.string, |
| 70 | ACPI_TYPE_ANY, |
| 71 | ACPI_IMODE_EXECUTE, |
| 72 | ACPI_NS_SEARCH_PARENT | |
| 73 | ACPI_NS_DONT_OPEN_SCOPE, |
| 74 | NULL, |
| 75 | ACPI_CAST_INDIRECT_PTR |
| 76 | (struct |
| 77 | acpi_namespace_node, |
| 78 | &(op->common.node))); |
| 79 | if (ACPI_FAILURE(status)) { |
Bob Moore | 16ccf82 | 2017-11-17 15:42:22 -0800 | [diff] [blame] | 80 | ACPI_ERROR_NAMESPACE(walk_state-> |
| 81 | scope_info, |
| 82 | op->common.value. |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 83 | string, status); |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 84 | return_ACPI_STATUS(status); |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 85 | } |
Bob Moore | 152c300 | 2007-10-17 16:10:18 -0400 | [diff] [blame] | 86 | } |
| 87 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | } |
| 89 | |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 90 | create_new_object: |
| 91 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 92 | /* Create and init a new internal ACPI object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 94 | obj_desc = acpi_ut_create_internal_object((acpi_ps_get_opcode_info |
| 95 | (op->common.aml_opcode))-> |
| 96 | object_type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 98 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | } |
| 100 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 101 | status = |
| 102 | acpi_ds_init_object_from_op(walk_state, op, op->common.aml_opcode, |
| 103 | &obj_desc); |
| 104 | if (ACPI_FAILURE(status)) { |
| 105 | acpi_ut_remove_reference(obj_desc); |
| 106 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 107 | } |
| 108 | |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 109 | /* |
| 110 | * Handling for unresolved package reference elements. |
| 111 | * These are elements that are namepaths. |
| 112 | */ |
| 113 | if ((op->common.parent->common.aml_opcode == AML_PACKAGE_OP) || |
| 114 | (op->common.parent->common.aml_opcode == AML_VARIABLE_PACKAGE_OP)) { |
| 115 | obj_desc->reference.resolved = TRUE; |
| 116 | |
| 117 | if ((op->common.aml_opcode == AML_INT_NAMEPATH_OP) && |
| 118 | !obj_desc->reference.node) { |
| 119 | /* |
| 120 | * Name was unresolved above. |
| 121 | * Get the prefix node for later lookup |
| 122 | */ |
| 123 | obj_desc->reference.node = |
| 124 | walk_state->scope_info->scope.node; |
| 125 | obj_desc->reference.aml = op->common.aml; |
| 126 | obj_desc->reference.resolved = FALSE; |
| 127 | } |
| 128 | } |
| 129 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | *obj_desc_ptr = obj_desc; |
Bob Moore | 9e41d93 | 2008-04-10 19:06:39 +0400 | [diff] [blame] | 131 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | } |
| 133 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 134 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | * |
| 136 | * FUNCTION: acpi_ds_build_internal_buffer_obj |
| 137 | * |
| 138 | * PARAMETERS: walk_state - Current walk state |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 139 | * op - Parser object to be translated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | * buffer_length - Length of the buffer |
| 141 | * obj_desc_ptr - Where the ACPI internal object is returned |
| 142 | * |
| 143 | * RETURN: Status |
| 144 | * |
| 145 | * DESCRIPTION: Translate a parser Op package object to the equivalent |
| 146 | * namespace object |
| 147 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 148 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | |
| 150 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 151 | acpi_ds_build_internal_buffer_obj(struct acpi_walk_state *walk_state, |
| 152 | union acpi_parse_object *op, |
| 153 | u32 buffer_length, |
| 154 | union acpi_operand_object **obj_desc_ptr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 156 | union acpi_parse_object *arg; |
| 157 | union acpi_operand_object *obj_desc; |
| 158 | union acpi_parse_object *byte_list; |
| 159 | u32 byte_list_length = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 160 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 161 | ACPI_FUNCTION_TRACE(ds_build_internal_buffer_obj); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 162 | |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 163 | /* |
| 164 | * If we are evaluating a Named buffer object "Name (xxxx, Buffer)". |
| 165 | * The buffer object already exists (from the NS node), otherwise it must |
| 166 | * be created. |
| 167 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | obj_desc = *obj_desc_ptr; |
Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 169 | if (!obj_desc) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 170 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | /* Create a new buffer object */ |
| 172 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 173 | obj_desc = acpi_ut_create_internal_object(ACPI_TYPE_BUFFER); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | *obj_desc_ptr = obj_desc; |
| 175 | if (!obj_desc) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
| 180 | /* |
| 181 | * Second arg is the buffer data (optional) byte_list can be either |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 182 | * individual bytes or a string initializer. In either case, a |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | * byte_list appears in the AML. |
| 184 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 185 | arg = op->common.value.arg; /* skip first arg */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | |
| 187 | byte_list = arg->named.next; |
| 188 | if (byte_list) { |
| 189 | if (byte_list->common.aml_opcode != AML_INT_BYTELIST_OP) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 190 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 191 | "Expecting bytelist, found AML opcode 0x%X in op %p", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 192 | byte_list->common.aml_opcode, byte_list)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 194 | acpi_ut_remove_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 195 | return (AE_TYPE); |
| 196 | } |
| 197 | |
| 198 | byte_list_length = (u32) byte_list->common.value.integer; |
| 199 | } |
| 200 | |
| 201 | /* |
| 202 | * The buffer length (number of bytes) will be the larger of: |
| 203 | * 1) The specified buffer length and |
| 204 | * 2) The length of the initializer byte list |
| 205 | */ |
| 206 | obj_desc->buffer.length = buffer_length; |
| 207 | if (byte_list_length > buffer_length) { |
| 208 | obj_desc->buffer.length = byte_list_length; |
| 209 | } |
| 210 | |
| 211 | /* Allocate the buffer */ |
| 212 | |
| 213 | if (obj_desc->buffer.length == 0) { |
| 214 | obj_desc->buffer.pointer = NULL; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 215 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
| 216 | "Buffer defined with zero length in AML, creating\n")); |
| 217 | } else { |
| 218 | obj_desc->buffer.pointer = |
Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 219 | ACPI_ALLOCATE_ZEROED(obj_desc->buffer.length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | if (!obj_desc->buffer.pointer) { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 221 | acpi_ut_delete_object_desc(obj_desc); |
| 222 | return_ACPI_STATUS(AE_NO_MEMORY); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | /* Initialize buffer from the byte_list (if present) */ |
| 226 | |
| 227 | if (byte_list) { |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 228 | memcpy(obj_desc->buffer.pointer, byte_list->named.data, |
| 229 | byte_list_length); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | } |
| 231 | } |
| 232 | |
| 233 | obj_desc->buffer.flags |= AOPOBJ_DATA_VALID; |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 234 | op->common.node = ACPI_CAST_PTR(struct acpi_namespace_node, obj_desc); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 235 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 238 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 239 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | * FUNCTION: acpi_ds_create_node |
| 241 | * |
| 242 | * PARAMETERS: walk_state - Current walk state |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 243 | * node - NS Node to be initialized |
| 244 | * op - Parser object to be translated |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | * |
| 246 | * RETURN: Status |
| 247 | * |
| 248 | * DESCRIPTION: Create the object to be associated with a namespace node |
| 249 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 250 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 253 | acpi_ds_create_node(struct acpi_walk_state *walk_state, |
| 254 | struct acpi_namespace_node *node, |
| 255 | union acpi_parse_object *op) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 257 | acpi_status status; |
| 258 | union acpi_operand_object *obj_desc; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 260 | ACPI_FUNCTION_TRACE_PTR(ds_create_node, op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 261 | |
| 262 | /* |
| 263 | * Because of the execution pass through the non-control-method |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 264 | * parts of the table, we can arrive here twice. Only init |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | * the named object node the first time through |
| 266 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 267 | if (acpi_ns_get_attached_object(node)) { |
| 268 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | } |
| 270 | |
| 271 | if (!op->common.value.arg) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 272 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | /* No arguments, there is nothing to do */ |
| 274 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 275 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | } |
| 277 | |
| 278 | /* Build an internal object for the argument(s) */ |
| 279 | |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 280 | status = |
| 281 | acpi_ds_build_internal_object(walk_state, op->common.value.arg, |
| 282 | &obj_desc); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 283 | if (ACPI_FAILURE(status)) { |
| 284 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /* Re-type the object according to its argument */ |
| 288 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 289 | node->type = obj_desc->common.type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | |
| 291 | /* Attach obj to node */ |
| 292 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | status = acpi_ns_attach_object(node, obj_desc, node->type); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | |
| 295 | /* Remove local reference to the object */ |
| 296 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 297 | acpi_ut_remove_reference(obj_desc); |
| 298 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 299 | } |
| 300 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 301 | /******************************************************************************* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 302 | * |
| 303 | * FUNCTION: acpi_ds_init_object_from_op |
| 304 | * |
| 305 | * PARAMETERS: walk_state - Current walk state |
Bob Moore | ba494be | 2012-07-12 09:40:10 +0800 | [diff] [blame] | 306 | * op - Parser op used to init the internal object |
| 307 | * opcode - AML opcode associated with the object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | * ret_obj_desc - Namespace object to be initialized |
| 309 | * |
| 310 | * RETURN: Status |
| 311 | * |
| 312 | * DESCRIPTION: Initialize a namespace object from a parser Op and its |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 313 | * associated arguments. The namespace object is a more compact |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 314 | * representation of the Op and its arguments. |
| 315 | * |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 316 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 317 | |
| 318 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | acpi_ds_init_object_from_op(struct acpi_walk_state *walk_state, |
| 320 | union acpi_parse_object *op, |
| 321 | u16 opcode, |
| 322 | union acpi_operand_object **ret_obj_desc) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 324 | const struct acpi_opcode_info *op_info; |
| 325 | union acpi_operand_object *obj_desc; |
| 326 | acpi_status status = AE_OK; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 328 | ACPI_FUNCTION_TRACE(ds_init_object_from_op); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | |
| 330 | obj_desc = *ret_obj_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 331 | op_info = acpi_ps_get_opcode_info(opcode); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | if (op_info->class == AML_CLASS_UNKNOWN) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* Unknown opcode */ |
| 335 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 336 | return_ACPI_STATUS(AE_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } |
| 338 | |
| 339 | /* Perform per-object initialization */ |
| 340 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 341 | switch (obj_desc->common.type) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | case ACPI_TYPE_BUFFER: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | /* |
| 344 | * Defer evaluation of Buffer term_arg operand |
| 345 | */ |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 346 | obj_desc->buffer.node = |
| 347 | ACPI_CAST_PTR(struct acpi_namespace_node, |
| 348 | walk_state->operands[0]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | obj_desc->buffer.aml_start = op->named.data; |
| 350 | obj_desc->buffer.aml_length = op->named.length; |
| 351 | break; |
| 352 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 | case ACPI_TYPE_PACKAGE: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 354 | /* |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 355 | * Defer evaluation of Package term_arg operand and all |
| 356 | * package elements. (01/2017): We defer the element |
| 357 | * resolution to allow forward references from the package |
| 358 | * in order to provide compatibility with other ACPI |
| 359 | * implementations. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | */ |
Bob Moore | 8f9337c | 2007-02-02 19:48:18 +0300 | [diff] [blame] | 361 | obj_desc->package.node = |
| 362 | ACPI_CAST_PTR(struct acpi_namespace_node, |
| 363 | walk_state->operands[0]); |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 364 | |
| 365 | if (!op->named.data) { |
| 366 | return_ACPI_STATUS(AE_OK); |
| 367 | } |
| 368 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | obj_desc->package.aml_start = op->named.data; |
| 370 | obj_desc->package.aml_length = op->named.length; |
| 371 | break; |
| 372 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 373 | case ACPI_TYPE_INTEGER: |
| 374 | |
| 375 | switch (op_info->type) { |
| 376 | case AML_TYPE_CONSTANT: |
| 377 | /* |
| 378 | * Resolve AML Constants here - AND ONLY HERE! |
| 379 | * All constants are integers. |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 380 | * We mark the integer with a flag that indicates that it started |
| 381 | * life as a constant -- so that stores to constants will perform |
| 382 | * as expected (noop). zero_op is used as a placeholder for optional |
| 383 | * target operands. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 384 | */ |
| 385 | obj_desc->common.flags = AOPOBJ_AML_CONSTANT; |
| 386 | |
| 387 | switch (opcode) { |
| 388 | case AML_ZERO_OP: |
| 389 | |
| 390 | obj_desc->integer.value = 0; |
| 391 | break; |
| 392 | |
| 393 | case AML_ONE_OP: |
| 394 | |
| 395 | obj_desc->integer.value = 1; |
| 396 | break; |
| 397 | |
| 398 | case AML_ONES_OP: |
| 399 | |
Bob Moore | 5df7e6c | 2010-01-21 10:06:32 +0800 | [diff] [blame] | 400 | obj_desc->integer.value = ACPI_UINT64_MAX; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | |
| 402 | /* Truncate value if we are executing from a 32-bit ACPI table */ |
| 403 | |
Bob Moore | ef42e53 | 2012-12-31 00:07:18 +0000 | [diff] [blame] | 404 | (void)acpi_ex_truncate_for32bit_table(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | break; |
| 406 | |
| 407 | case AML_REVISION_OP: |
| 408 | |
| 409 | obj_desc->integer.value = ACPI_CA_VERSION; |
| 410 | break; |
| 411 | |
| 412 | default: |
| 413 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 414 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 415 | "Unknown constant opcode 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 416 | opcode)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | status = AE_AML_OPERAND_TYPE; |
| 418 | break; |
| 419 | } |
| 420 | break; |
| 421 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | case AML_TYPE_LITERAL: |
| 423 | |
| 424 | obj_desc->integer.value = op->common.value.integer; |
Bob Moore | ef42e53 | 2012-12-31 00:07:18 +0000 | [diff] [blame] | 425 | |
Bob Moore | ef42e53 | 2012-12-31 00:07:18 +0000 | [diff] [blame] | 426 | if (acpi_ex_truncate_for32bit_table(obj_desc)) { |
| 427 | |
| 428 | /* Warn if we found a 64-bit constant in a 32-bit table */ |
| 429 | |
| 430 | ACPI_WARNING((AE_INFO, |
| 431 | "Truncated 64-bit constant found in 32-bit table: %8.8X%8.8X => %8.8X", |
| 432 | ACPI_FORMAT_UINT64(op->common. |
| 433 | value.integer), |
| 434 | (u32)obj_desc->integer.value)); |
| 435 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | break; |
| 437 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 439 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 440 | ACPI_ERROR((AE_INFO, "Unknown Integer type 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 441 | op_info->type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 442 | status = AE_AML_OPERAND_TYPE; |
| 443 | break; |
| 444 | } |
| 445 | break; |
| 446 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 447 | case ACPI_TYPE_STRING: |
| 448 | |
| 449 | obj_desc->string.pointer = op->common.value.string; |
Bob Moore | 4fa4616 | 2015-07-01 14:45:11 +0800 | [diff] [blame] | 450 | obj_desc->string.length = (u32)strlen(op->common.value.string); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
| 452 | /* |
| 453 | * The string is contained in the ACPI table, don't ever try |
| 454 | * to delete it |
| 455 | */ |
| 456 | obj_desc->common.flags |= AOPOBJ_STATIC_POINTER; |
| 457 | break; |
| 458 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | case ACPI_TYPE_METHOD: |
| 460 | break; |
| 461 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 463 | |
| 464 | switch (op_info->type) { |
| 465 | case AML_TYPE_LOCAL_VARIABLE: |
| 466 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 467 | /* Local ID (0-7) is (AML opcode - base AML_FIRST_LOCAL_OP) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | |
Bob Moore | ba9c3f5 | 2009-04-22 13:13:48 +0800 | [diff] [blame] | 469 | obj_desc->reference.value = |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 470 | ((u32)opcode) - AML_FIRST_LOCAL_OP; |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 471 | obj_desc->reference.class = ACPI_REFCLASS_LOCAL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 473 | status = |
| 474 | acpi_ds_method_data_get_node(ACPI_REFCLASS_LOCAL, |
| 475 | obj_desc->reference. |
| 476 | value, walk_state, |
| 477 | ACPI_CAST_INDIRECT_PTR |
| 478 | (struct |
| 479 | acpi_namespace_node, |
| 480 | &obj_desc->reference. |
| 481 | object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | break; |
| 483 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | case AML_TYPE_METHOD_ARGUMENT: |
| 485 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 486 | /* Arg ID (0-6) is (AML opcode - base AML_FIRST_ARG_OP) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | |
Bob Moore | 9ff5a21a | 2017-04-26 16:18:40 +0800 | [diff] [blame] | 488 | obj_desc->reference.value = |
| 489 | ((u32)opcode) - AML_FIRST_ARG_OP; |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 490 | obj_desc->reference.class = ACPI_REFCLASS_ARG; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 491 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 492 | status = acpi_ds_method_data_get_node(ACPI_REFCLASS_ARG, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 493 | obj_desc-> |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 494 | reference.value, |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | walk_state, |
Bob Moore | 57e664c | 2008-09-27 10:40:39 +0800 | [diff] [blame] | 496 | ACPI_CAST_INDIRECT_PTR |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 497 | (struct |
Bob Moore | 57e664c | 2008-09-27 10:40:39 +0800 | [diff] [blame] | 498 | acpi_namespace_node, |
| 499 | &obj_desc-> |
| 500 | reference. |
| 501 | object)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 502 | break; |
| 503 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 504 | default: /* Object name or Debug object */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 506 | switch (op->common.aml_opcode) { |
| 507 | case AML_INT_NAMEPATH_OP: |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 508 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 509 | /* Node was saved in Op */ |
| 510 | |
| 511 | obj_desc->reference.node = op->common.node; |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 512 | obj_desc->reference.class = ACPI_REFCLASS_NAME; |
Bob Moore | a62a711 | 2017-08-03 14:27:22 +0800 | [diff] [blame] | 513 | if (op->common.node) { |
| 514 | obj_desc->reference.object = |
| 515 | op->common.node->object; |
| 516 | } |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 517 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 518 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 519 | case AML_DEBUG_OP: |
| 520 | |
| 521 | obj_desc->reference.class = ACPI_REFCLASS_DEBUG; |
| 522 | break; |
| 523 | |
| 524 | default: |
| 525 | |
| 526 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 527 | "Unimplemented reference type for AML opcode: 0x%4.4X", |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 528 | opcode)); |
| 529 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
| 530 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | break; |
| 532 | } |
| 533 | break; |
| 534 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | default: |
| 536 | |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 537 | ACPI_ERROR((AE_INFO, "Unimplemented data type: 0x%X", |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 538 | obj_desc->common.type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | |
| 540 | status = AE_AML_OPERAND_TYPE; |
| 541 | break; |
| 542 | } |
| 543 | |
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 | } |