blob: c1e8bfb0f7f42c1b5fda1902914d6e66c46bdd16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: exresnte - AML Interpreter object resolution
4 *
5 *****************************************************************************/
6
7/*
Bob Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, Intel Corp.
Linus Torvalds1da177e2005-04-16 15:20:36 -07009 * 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 Torvalds1da177e2005-04-16 15:20:36 -070044#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -050045#include "accommon.h"
46#include "acdispat.h"
47#include "acinterp.h"
48#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("exresnte")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_ex_resolve_node_to_value
56 *
57 * PARAMETERS: object_ptr - Pointer to a location that contains
58 * a pointer to a NS node, and will receive a
59 * pointer to the resolved object.
Bob Moore73a30902012-10-31 02:26:55 +000060 * walk_state - Current state. Valid only if executing AML
61 * code. NULL if simply resolving an object
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 *
63 * RETURN: Status
64 *
65 * DESCRIPTION: Resolve a Namespace node to a valued object
66 *
67 * Note: for some of the data types, the pointer attached to the Node
68 * can be either a pointer to an actual internal object or a pointer into the
Bob Moore73a30902012-10-31 02:26:55 +000069 * AML stream itself. These types are currently:
Linus Torvalds1da177e2005-04-16 15:20:36 -070070 *
71 * ACPI_TYPE_INTEGER
72 * ACPI_TYPE_STRING
73 * ACPI_TYPE_BUFFER
74 * ACPI_TYPE_MUTEX
75 * ACPI_TYPE_PACKAGE
76 *
77 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070078acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040079acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
80 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081{
Len Brown4be44fc2005-08-05 00:44:28 -040082 acpi_status status = AE_OK;
83 union acpi_operand_object *source_desc;
84 union acpi_operand_object *obj_desc = NULL;
85 struct acpi_namespace_node *node;
86 acpi_object_type entry_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
Bob Mooreb229cf92006-04-21 17:15:00 -040088 ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
90 /*
Bob Moore73a30902012-10-31 02:26:55 +000091 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 * object that is attached to the Node.
93 */
Len Brown4be44fc2005-08-05 00:44:28 -040094 node = *object_ptr;
95 source_desc = acpi_ns_get_attached_object(node);
96 entry_type = acpi_ns_get_type((acpi_handle) node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Bob Mooreb229cf92006-04-21 17:15:00 -040098 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -040099 node, source_desc,
100 acpi_ut_get_type_name(entry_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101
102 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400103 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400104
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105 /* There is always exactly one level of indirection */
106
Len Brown4be44fc2005-08-05 00:44:28 -0400107 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
108 source_desc = acpi_ns_get_attached_object(node);
109 entry_type = acpi_ns_get_type((acpi_handle) node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 *object_ptr = node;
111 }
112
113 /*
114 * Several object types require no further processing:
Bob Moore1fad8732015-12-29 13:54:36 +0800115 * 1) Device/Thermal objects don't have a "real" subobject, return Node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 * 2) Method locals and arguments have a pseudo-Node
Bob Mooreb1609872008-04-10 19:06:40 +0400117 * 3) 10/2007: Added method type to assist with Package construction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 */
Bob Moore4c90ece2006-06-08 16:29:00 -0400119 if ((entry_type == ACPI_TYPE_DEVICE) ||
120 (entry_type == ACPI_TYPE_THERMAL) ||
Bob Mooreb1609872008-04-10 19:06:40 +0400121 (entry_type == ACPI_TYPE_METHOD) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400122 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
123 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
126 if (!source_desc) {
Bob Moore06d18602014-01-08 13:44:51 +0800127 ACPI_ERROR((AE_INFO, "No object attached to node [%4.4s] %p",
128 node->name.ascii, node));
Bob Moore4712f712015-08-25 10:28:26 +0800129 return_ACPI_STATUS(AE_AML_UNINITIALIZED_NODE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130 }
131
132 /*
133 * Action is based on the type of the Node, which indicates the type
134 * of the attached object or pointer
135 */
136 switch (entry_type) {
137 case ACPI_TYPE_PACKAGE:
138
Bob Moore3371c192009-02-18 14:44:03 +0800139 if (source_desc->common.type != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500140 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
141 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400142 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 }
144
Len Brown4be44fc2005-08-05 00:44:28 -0400145 status = acpi_ds_get_package_arguments(source_desc);
146 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400147
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 /* Return an additional reference to the object */
149
150 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400151 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 }
153 break;
154
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 case ACPI_TYPE_BUFFER:
156
Bob Moore3371c192009-02-18 14:44:03 +0800157 if (source_desc->common.type != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500158 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
159 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400160 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 }
162
Len Brown4be44fc2005-08-05 00:44:28 -0400163 status = acpi_ds_get_buffer_arguments(source_desc);
164 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /* Return an additional reference to the object */
167
168 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400169 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171 break;
172
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 case ACPI_TYPE_STRING:
174
Bob Moore3371c192009-02-18 14:44:03 +0800175 if (source_desc->common.type != ACPI_TYPE_STRING) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500176 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
177 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400178 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 }
180
181 /* Return an additional reference to the object */
182
183 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400184 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700185 break;
186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 case ACPI_TYPE_INTEGER:
188
Bob Moore3371c192009-02-18 14:44:03 +0800189 if (source_desc->common.type != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500190 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
191 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400192 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193 }
194
195 /* Return an additional reference to the object */
196
197 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400198 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 break;
200
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 case ACPI_TYPE_BUFFER_FIELD:
202 case ACPI_TYPE_LOCAL_REGION_FIELD:
203 case ACPI_TYPE_LOCAL_BANK_FIELD:
204 case ACPI_TYPE_LOCAL_INDEX_FIELD:
205
Len Brown4be44fc2005-08-05 00:44:28 -0400206 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400207 "FieldRead Node=%p SourceDesc=%p Type=%X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400208 node, source_desc, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Len Brown4be44fc2005-08-05 00:44:28 -0400210 status =
211 acpi_ex_read_data_from_field(walk_state, source_desc,
212 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 break;
214
Len Brown4be44fc2005-08-05 00:44:28 -0400215 /* For these objects, just return the object attached to the Node */
Robert Moore44f6c012005-04-18 22:49:35 -0400216
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 case ACPI_TYPE_MUTEX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 case ACPI_TYPE_POWER:
219 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220 case ACPI_TYPE_EVENT:
221 case ACPI_TYPE_REGION:
222
223 /* Return an additional reference to the object */
224
225 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400226 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 break;
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229 /* TYPE_ANY is untyped, and thus there is no object associated with it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230
231 case ACPI_TYPE_ANY:
232
Bob Mooreb8e4d892006-01-27 16:43:00 -0500233 ACPI_ERROR((AE_INFO,
234 "Untyped entry %p, no attached object!", node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237
238 case ACPI_TYPE_LOCAL_REFERENCE:
239
Bob Moore1044f1f2008-09-27 11:08:41 +0800240 switch (source_desc->reference.class) {
241 case ACPI_REFCLASS_TABLE: /* This is a ddb_handle */
242 case ACPI_REFCLASS_REFOF:
243 case ACPI_REFCLASS_INDEX:
Lin Ming1cb2ef62008-04-10 19:06:41 +0400244
245 /* Return an additional reference to the object */
Bob Moore52fc0b02006-10-02 00:00:00 -0400246
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400248 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 break;
250
251 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 /* No named references are allowed here */
254
Bob Mooreb8e4d892006-01-27 16:43:00 -0500255 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800256 "Unsupported Reference type 0x%X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800257 source_desc->reference.class));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 }
261 break;
262
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 default:
264
Robert Moore44f6c012005-04-18 22:49:35 -0400265 /* Default case is for unknown types */
266
Bob Mooreb8e4d892006-01-27 16:43:00 -0500267 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800268 "Node %p - Unknown object type 0x%X",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500269 node, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Len Brown4be44fc2005-08-05 00:44:28 -0400271 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 } /* switch (entry_type) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Robert Moore44f6c012005-04-18 22:49:35 -0400275 /* Return the object descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Len Brown4be44fc2005-08-05 00:44:28 -0400277 *object_ptr = (void *)obj_desc;
278 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279}