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: exresnte - AML Interpreter object resolution |
| 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 "acdispat.h" |
| 13 | #include "acinterp.h" |
| 14 | #include "acnamesp.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | #define _COMPONENT ACPI_EXECUTER |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 17 | ACPI_MODULE_NAME("exresnte") |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | |
| 19 | /******************************************************************************* |
| 20 | * |
| 21 | * FUNCTION: acpi_ex_resolve_node_to_value |
| 22 | * |
| 23 | * PARAMETERS: object_ptr - Pointer to a location that contains |
| 24 | * a pointer to a NS node, and will receive a |
| 25 | * pointer to the resolved object. |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 26 | * walk_state - Current state. Valid only if executing AML |
| 27 | * code. NULL if simply resolving an object |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | * |
| 29 | * RETURN: Status |
| 30 | * |
| 31 | * DESCRIPTION: Resolve a Namespace node to a valued object |
| 32 | * |
| 33 | * Note: for some of the data types, the pointer attached to the Node |
| 34 | * can be either a pointer to an actual internal object or a pointer into the |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 35 | * AML stream itself. These types are currently: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | * |
| 37 | * ACPI_TYPE_INTEGER |
| 38 | * ACPI_TYPE_STRING |
| 39 | * ACPI_TYPE_BUFFER |
| 40 | * ACPI_TYPE_MUTEX |
| 41 | * ACPI_TYPE_PACKAGE |
| 42 | * |
| 43 | ******************************************************************************/ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | acpi_status |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 45 | acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr, |
| 46 | struct acpi_walk_state *walk_state) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | { |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 48 | acpi_status status = AE_OK; |
| 49 | union acpi_operand_object *source_desc; |
| 50 | union acpi_operand_object *obj_desc = NULL; |
| 51 | struct acpi_namespace_node *node; |
| 52 | acpi_object_type entry_type; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 54 | ACPI_FUNCTION_TRACE(ex_resolve_node_to_value); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
| 56 | /* |
Bob Moore | 73a3090 | 2012-10-31 02:26:55 +0000 | [diff] [blame] | 57 | * The stack pointer points to a struct acpi_namespace_node (Node). Get the |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | * object that is attached to the Node. |
| 59 | */ |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 60 | node = *object_ptr; |
| 61 | source_desc = acpi_ns_get_attached_object(node); |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 62 | entry_type = acpi_ns_get_type((acpi_handle)node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 64 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 65 | node, source_desc, |
| 66 | acpi_ut_get_type_name(entry_type))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 67 | |
| 68 | if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 69 | (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 70 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 71 | /* There is always exactly one level of indirection */ |
| 72 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 73 | node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object); |
| 74 | source_desc = acpi_ns_get_attached_object(node); |
Lv Zheng | f5c1e1c | 2016-05-05 12:57:53 +0800 | [diff] [blame] | 75 | entry_type = acpi_ns_get_type((acpi_handle)node); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | *object_ptr = node; |
| 77 | } |
| 78 | |
| 79 | /* |
| 80 | * Several object types require no further processing: |
Bob Moore | 1fad873 | 2015-12-29 13:54:36 +0800 | [diff] [blame] | 81 | * 1) Device/Thermal objects don't have a "real" subobject, return Node |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | * 2) Method locals and arguments have a pseudo-Node |
Bob Moore | b160987 | 2008-04-10 19:06:40 +0400 | [diff] [blame] | 83 | * 3) 10/2007: Added method type to assist with Package construction. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | */ |
Bob Moore | 4c90ece | 2006-06-08 16:29:00 -0400 | [diff] [blame] | 85 | if ((entry_type == ACPI_TYPE_DEVICE) || |
| 86 | (entry_type == ACPI_TYPE_THERMAL) || |
Bob Moore | b160987 | 2008-04-10 19:06:40 +0400 | [diff] [blame] | 87 | (entry_type == ACPI_TYPE_METHOD) || |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) { |
| 89 | return_ACPI_STATUS(AE_OK); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | if (!source_desc) { |
Bob Moore | 06d1860 | 2014-01-08 13:44:51 +0800 | [diff] [blame] | 93 | ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p", |
| 94 | node->name.ascii, node)); |
Bob Moore | 4712f71 | 2015-08-25 10:28:26 +0800 | [diff] [blame] | 95 | return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 96 | } |
| 97 | |
| 98 | /* |
| 99 | * Action is based on the type of the Node, which indicates the type |
| 100 | * of the attached object or pointer |
| 101 | */ |
| 102 | switch (entry_type) { |
| 103 | case ACPI_TYPE_PACKAGE: |
| 104 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 105 | if (source_desc->common.type != ACPI_TYPE_PACKAGE) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 106 | ACPI_ERROR((AE_INFO, "Object not a Package, type %s", |
| 107 | acpi_ut_get_object_type_name(source_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 108 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 109 | } |
| 110 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 111 | status = acpi_ds_get_package_arguments(source_desc); |
| 112 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 113 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 114 | /* Return an additional reference to the object */ |
| 115 | |
| 116 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 117 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | } |
| 119 | break; |
| 120 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | case ACPI_TYPE_BUFFER: |
| 122 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 123 | if (source_desc->common.type != ACPI_TYPE_BUFFER) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 124 | ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s", |
| 125 | acpi_ut_get_object_type_name(source_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 126 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | } |
| 128 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 129 | status = acpi_ds_get_buffer_arguments(source_desc); |
| 130 | if (ACPI_SUCCESS(status)) { |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Return an additional reference to the object */ |
| 133 | |
| 134 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 135 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | } |
| 137 | break; |
| 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | case ACPI_TYPE_STRING: |
| 140 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 141 | if (source_desc->common.type != ACPI_TYPE_STRING) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 142 | ACPI_ERROR((AE_INFO, "Object not a String, type %s", |
| 143 | acpi_ut_get_object_type_name(source_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 144 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | } |
| 146 | |
| 147 | /* Return an additional reference to the object */ |
| 148 | |
| 149 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 150 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | break; |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | case ACPI_TYPE_INTEGER: |
| 154 | |
Bob Moore | 3371c19 | 2009-02-18 14:44:03 +0800 | [diff] [blame] | 155 | if (source_desc->common.type != ACPI_TYPE_INTEGER) { |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 156 | ACPI_ERROR((AE_INFO, "Object not a Integer, type %s", |
| 157 | acpi_ut_get_object_type_name(source_desc))); |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 158 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | } |
| 160 | |
| 161 | /* Return an additional reference to the object */ |
| 162 | |
| 163 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 164 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 165 | break; |
| 166 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 167 | case ACPI_TYPE_BUFFER_FIELD: |
| 168 | case ACPI_TYPE_LOCAL_REGION_FIELD: |
| 169 | case ACPI_TYPE_LOCAL_BANK_FIELD: |
| 170 | case ACPI_TYPE_LOCAL_INDEX_FIELD: |
| 171 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 173 | "FieldRead Node=%p SourceDesc=%p Type=%X\n", |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | node, source_desc, entry_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 176 | status = |
| 177 | acpi_ex_read_data_from_field(walk_state, source_desc, |
| 178 | &obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 | break; |
| 180 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 181 | /* For these objects, just return the object attached to the Node */ |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 182 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | case ACPI_TYPE_MUTEX: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | case ACPI_TYPE_POWER: |
| 185 | case ACPI_TYPE_PROCESSOR: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 186 | case ACPI_TYPE_EVENT: |
| 187 | case ACPI_TYPE_REGION: |
| 188 | |
| 189 | /* Return an additional reference to the object */ |
| 190 | |
| 191 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 192 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 193 | break; |
| 194 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 195 | /* TYPE_ANY is untyped, and thus there is no object associated with it */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | case ACPI_TYPE_ANY: |
| 198 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 199 | ACPI_ERROR((AE_INFO, |
| 200 | "Untyped entry %p, no attached object!", node)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 202 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 203 | |
| 204 | case ACPI_TYPE_LOCAL_REFERENCE: |
| 205 | |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 206 | switch (source_desc->reference.class) { |
| 207 | case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */ |
| 208 | case ACPI_REFCLASS_REFOF: |
| 209 | case ACPI_REFCLASS_INDEX: |
Lin Ming | 1cb2ef6 | 2008-04-10 19:06:41 +0400 | [diff] [blame] | 210 | |
| 211 | /* Return an additional reference to the object */ |
Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 212 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | obj_desc = source_desc; |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 214 | acpi_ut_add_reference(obj_desc); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | break; |
| 216 | |
| 217 | default: |
Chao Guan | 1d1ea1b7 | 2013-06-08 00:58:14 +0000 | [diff] [blame] | 218 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | /* No named references are allowed here */ |
| 220 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 221 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 222 | "Unsupported Reference type 0x%X", |
Bob Moore | 1044f1f | 2008-09-27 11:08:41 +0800 | [diff] [blame] | 223 | source_desc->reference.class)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 225 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | } |
| 227 | break; |
| 228 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | default: |
| 230 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 231 | /* Default case is for unknown types */ |
| 232 | |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 233 | ACPI_ERROR((AE_INFO, |
Bob Moore | f6a22b0 | 2010-03-05 17:56:40 +0800 | [diff] [blame] | 234 | "Node %p - Unknown object type 0x%X", |
Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 235 | node, entry_type)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | return_ACPI_STATUS(AE_AML_OPERAND_TYPE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 238 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 239 | } /* switch (entry_type) */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 240 | |
Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 241 | /* Return the object descriptor */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | |
Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | *object_ptr = (void *)obj_desc; |
| 244 | return_ACPI_STATUS(status); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 245 | } |