blob: d80b76455c505ec15e2fa0a3c07f4ac1afa30c2f [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/******************************************************************************
3 *
4 * Module Name: exresnte - AML Interpreter object resolution
5 *
Bob Moore4441e552021-01-15 10:48:25 -08006 * Copyright (C) 2000 - 2021, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07007 *
Erik Schmauss95857632018-03-14 16:13:07 -07008 *****************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -07009
Linus Torvalds1da177e2005-04-16 15:20:36 -070010#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050011#include "accommon.h"
12#include "acdispat.h"
13#include "acinterp.h"
14#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070015
Linus Torvalds1da177e2005-04-16 15:20:36 -070016#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040017ACPI_MODULE_NAME("exresnte")
Linus Torvalds1da177e2005-04-16 15:20:36 -070018
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 Moore73a30902012-10-31 02:26:55 +000026 * walk_state - Current state. Valid only if executing AML
27 * code. NULL if simply resolving an object
Linus Torvalds1da177e2005-04-16 15:20:36 -070028 *
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 Moore73a30902012-10-31 02:26:55 +000035 * AML stream itself. These types are currently:
Linus Torvalds1da177e2005-04-16 15:20:36 -070036 *
37 * ACPI_TYPE_INTEGER
38 * ACPI_TYPE_STRING
39 * ACPI_TYPE_BUFFER
40 * ACPI_TYPE_MUTEX
41 * ACPI_TYPE_PACKAGE
42 *
43 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070044acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040045acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
46 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070047{
Len Brown4be44fc2005-08-05 00:44:28 -040048 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 Torvalds1da177e2005-04-16 15:20:36 -070053
Bob Mooreb229cf92006-04-21 17:15:00 -040054 ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
56 /*
Bob Moore73a30902012-10-31 02:26:55 +000057 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 * object that is attached to the Node.
59 */
Len Brown4be44fc2005-08-05 00:44:28 -040060 node = *object_ptr;
61 source_desc = acpi_ns_get_attached_object(node);
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080062 entry_type = acpi_ns_get_type((acpi_handle)node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070063
Bob Mooreb229cf92006-04-21 17:15:00 -040064 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -040065 node, source_desc,
66 acpi_ut_get_type_name(entry_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -070067
68 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
Len Brown4be44fc2005-08-05 00:44:28 -040069 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
Bob Moore52fc0b02006-10-02 00:00:00 -040070
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 /* There is always exactly one level of indirection */
72
Len Brown4be44fc2005-08-05 00:44:28 -040073 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
74 source_desc = acpi_ns_get_attached_object(node);
Lv Zhengf5c1e1c2016-05-05 12:57:53 +080075 entry_type = acpi_ns_get_type((acpi_handle)node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 *object_ptr = node;
77 }
78
79 /*
80 * Several object types require no further processing:
Bob Moore1fad8732015-12-29 13:54:36 +080081 * 1) Device/Thermal objects don't have a "real" subobject, return Node
Linus Torvalds1da177e2005-04-16 15:20:36 -070082 * 2) Method locals and arguments have a pseudo-Node
Bob Mooreb1609872008-04-10 19:06:40 +040083 * 3) 10/2007: Added method type to assist with Package construction.
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 */
Bob Moore4c90ece2006-06-08 16:29:00 -040085 if ((entry_type == ACPI_TYPE_DEVICE) ||
86 (entry_type == ACPI_TYPE_THERMAL) ||
Bob Mooreb1609872008-04-10 19:06:40 +040087 (entry_type == ACPI_TYPE_METHOD) ||
Len Brown4be44fc2005-08-05 00:44:28 -040088 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
89 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 }
91
92 if (!source_desc) {
Bob Moore06d18602014-01-08 13:44:51 +080093 ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
94 node->name.ascii, node));
Bob Moore4712f712015-08-25 10:28:26 +080095 return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096 }
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 Moore3371c192009-02-18 14:44:03 +0800105 if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500106 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
107 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400108 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 }
110
Len Brown4be44fc2005-08-05 00:44:28 -0400111 status = acpi_ds_get_package_arguments(source_desc);
112 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400113
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 /* Return an additional reference to the object */
115
116 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400117 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 }
119 break;
120
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 case ACPI_TYPE_BUFFER:
122
Bob Moore3371c192009-02-18 14:44:03 +0800123 if (source_desc->common.type != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500124 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
125 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
Len Brown4be44fc2005-08-05 00:44:28 -0400129 status = acpi_ds_get_buffer_arguments(source_desc);
130 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400131
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 /* Return an additional reference to the object */
133
134 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400135 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 }
137 break;
138
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 case ACPI_TYPE_STRING:
140
Bob Moore3371c192009-02-18 14:44:03 +0800141 if (source_desc->common.type != ACPI_TYPE_STRING) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500142 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
143 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400144 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 }
146
147 /* Return an additional reference to the object */
148
149 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400150 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 break;
152
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 case ACPI_TYPE_INTEGER:
154
Bob Moore3371c192009-02-18 14:44:03 +0800155 if (source_desc->common.type != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500156 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
157 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400158 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700159 }
160
161 /* Return an additional reference to the object */
162
163 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400164 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 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 Brown4be44fc2005-08-05 00:44:28 -0400172 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400173 "FieldRead Node=%p SourceDesc=%p Type=%X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400174 node, source_desc, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 status =
177 acpi_ex_read_data_from_field(walk_state, source_desc,
178 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 break;
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 /* For these objects, just return the object attached to the Node */
Robert Moore44f6c012005-04-18 22:49:35 -0400182
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183 case ACPI_TYPE_MUTEX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700184 case ACPI_TYPE_POWER:
185 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 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 Brown4be44fc2005-08-05 00:44:28 -0400192 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 break;
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 /* TYPE_ANY is untyped, and thus there is no object associated with it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197 case ACPI_TYPE_ANY:
198
Bob Mooreb8e4d892006-01-27 16:43:00 -0500199 ACPI_ERROR((AE_INFO,
200 "Untyped entry %p, no attached object!", node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 case ACPI_TYPE_LOCAL_REFERENCE:
205
Bob Moore1044f1f2008-09-27 11:08:41 +0800206 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 Ming1cb2ef62008-04-10 19:06:41 +0400210
211 /* Return an additional reference to the object */
Bob Moore52fc0b02006-10-02 00:00:00 -0400212
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400214 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 break;
216
217 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000218
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 /* No named references are allowed here */
220
Bob Mooreb8e4d892006-01-27 16:43:00 -0500221 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800222 "Unsupported Reference type 0x%X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800223 source_desc->reference.class));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224
Len Brown4be44fc2005-08-05 00:44:28 -0400225 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 }
227 break;
228
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 default:
230
Robert Moore44f6c012005-04-18 22:49:35 -0400231 /* Default case is for unknown types */
232
Bob Mooreb8e4d892006-01-27 16:43:00 -0500233 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800234 "Node %p - Unknown object type 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500235 node, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Len Brown4be44fc2005-08-05 00:44:28 -0400237 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 } /* switch (entry_type) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Robert Moore44f6c012005-04-18 22:49:35 -0400241 /* Return the object descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Len Brown4be44fc2005-08-05 00:44:28 -0400243 *object_ptr = (void *)obj_desc;
244 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245}