blob: 79a0d281f96b5f787115d19ea76d8aa769124cfb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001
2/******************************************************************************
3 *
4 * Module Name: exresnte - AML Interpreter object resolution
5 *
6 *****************************************************************************/
7
8/*
Bob Moore6c9deb72007-02-02 19:48:24 +03009 * Copyright (C) 2000 - 2007, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * All rights reserved.
11 *
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
26 *
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
30 *
31 * NO WARRANTY
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
43 */
44
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acdispat.h>
47#include <acpi/acinterp.h>
48#include <acpi/acnamesp.h>
49#include <acpi/acparser.h>
50#include <acpi/amlcode.h>
51
Linus Torvalds1da177e2005-04-16 15:20:36 -070052#define _COMPONENT ACPI_EXECUTER
Len Brown4be44fc2005-08-05 00:44:28 -040053ACPI_MODULE_NAME("exresnte")
Linus Torvalds1da177e2005-04-16 15:20:36 -070054
55/*******************************************************************************
56 *
57 * FUNCTION: acpi_ex_resolve_node_to_value
58 *
59 * PARAMETERS: object_ptr - Pointer to a location that contains
60 * a pointer to a NS node, and will receive a
61 * pointer to the resolved object.
62 * walk_state - Current state. Valid only if executing AML
63 * code. NULL if simply resolving an object
64 *
65 * RETURN: Status
66 *
67 * DESCRIPTION: Resolve a Namespace node to a valued object
68 *
69 * Note: for some of the data types, the pointer attached to the Node
70 * can be either a pointer to an actual internal object or a pointer into the
71 * AML stream itself. These types are currently:
72 *
73 * ACPI_TYPE_INTEGER
74 * ACPI_TYPE_STRING
75 * ACPI_TYPE_BUFFER
76 * ACPI_TYPE_MUTEX
77 * ACPI_TYPE_PACKAGE
78 *
79 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070080acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040081acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
82 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Len Brown4be44fc2005-08-05 00:44:28 -040084 acpi_status status = AE_OK;
85 union acpi_operand_object *source_desc;
86 union acpi_operand_object *obj_desc = NULL;
87 struct acpi_namespace_node *node;
88 acpi_object_type entry_type;
Linus Torvalds1da177e2005-04-16 15:20:36 -070089
Bob Mooreb229cf92006-04-21 17:15:00 -040090 ACPI_FUNCTION_TRACE(ex_resolve_node_to_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -070091
92 /*
93 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
94 * object that is attached to the Node.
95 */
Len Brown4be44fc2005-08-05 00:44:28 -040096 node = *object_ptr;
97 source_desc = acpi_ns_get_attached_object(node);
98 entry_type = acpi_ns_get_type((acpi_handle) node);
Linus Torvalds1da177e2005-04-16 15:20:36 -070099
Bob Mooreb229cf92006-04-21 17:15:00 -0400100 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p SourceDesc=%p [%s]\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400101 node, source_desc,
102 acpi_ut_get_type_name(entry_type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400105 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400106
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 /* There is always exactly one level of indirection */
108
Len Brown4be44fc2005-08-05 00:44:28 -0400109 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
110 source_desc = acpi_ns_get_attached_object(node);
111 entry_type = acpi_ns_get_type((acpi_handle) node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 *object_ptr = node;
113 }
114
115 /*
116 * Several object types require no further processing:
Bob Moore4c90ece2006-06-08 16:29:00 -0400117 * 1) Device/Thermal objects don't have a "real" subobject, return the Node
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 * 2) Method locals and arguments have a pseudo-Node
Bob Mooreb1609872008-04-10 19:06:40 +0400119 * 3) 10/2007: Added method type to assist with Package construction.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 */
Bob Moore4c90ece2006-06-08 16:29:00 -0400121 if ((entry_type == ACPI_TYPE_DEVICE) ||
122 (entry_type == ACPI_TYPE_THERMAL) ||
Bob Mooreb1609872008-04-10 19:06:40 +0400123 (entry_type == ACPI_TYPE_METHOD) ||
Len Brown4be44fc2005-08-05 00:44:28 -0400124 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
125 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 }
127
128 if (!source_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500129 ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
Len Brown4be44fc2005-08-05 00:44:28 -0400130 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 }
132
133 /*
134 * Action is based on the type of the Node, which indicates the type
135 * of the attached object or pointer
136 */
137 switch (entry_type) {
138 case ACPI_TYPE_PACKAGE:
139
Len Brown4be44fc2005-08-05 00:44:28 -0400140 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500141 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
142 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400143 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 }
145
Len Brown4be44fc2005-08-05 00:44:28 -0400146 status = acpi_ds_get_package_arguments(source_desc);
147 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 /* Return an additional reference to the object */
150
151 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400152 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 }
154 break;
155
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 case ACPI_TYPE_BUFFER:
157
Len Brown4be44fc2005-08-05 00:44:28 -0400158 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500159 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
160 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400161 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 }
163
Len Brown4be44fc2005-08-05 00:44:28 -0400164 status = acpi_ds_get_buffer_arguments(source_desc);
165 if (ACPI_SUCCESS(status)) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400166
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 /* Return an additional reference to the object */
168
169 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400170 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172 break;
173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 case ACPI_TYPE_STRING:
175
Len Brown4be44fc2005-08-05 00:44:28 -0400176 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500177 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
178 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400179 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 }
181
182 /* Return an additional reference to the object */
183
184 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400185 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 break;
187
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 case ACPI_TYPE_INTEGER:
189
Len Brown4be44fc2005-08-05 00:44:28 -0400190 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500191 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
192 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400193 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 }
195
196 /* Return an additional reference to the object */
197
198 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400199 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 break;
201
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202 case ACPI_TYPE_BUFFER_FIELD:
203 case ACPI_TYPE_LOCAL_REGION_FIELD:
204 case ACPI_TYPE_LOCAL_BANK_FIELD:
205 case ACPI_TYPE_LOCAL_INDEX_FIELD:
206
Len Brown4be44fc2005-08-05 00:44:28 -0400207 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400208 "FieldRead Node=%p SourceDesc=%p Type=%X\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400209 node, source_desc, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Len Brown4be44fc2005-08-05 00:44:28 -0400211 status =
212 acpi_ex_read_data_from_field(walk_state, source_desc,
213 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 break;
215
Len Brown4be44fc2005-08-05 00:44:28 -0400216 /* For these objects, just return the object attached to the Node */
Robert Moore44f6c012005-04-18 22:49:35 -0400217
Linus Torvalds1da177e2005-04-16 15:20:36 -0700218 case ACPI_TYPE_MUTEX:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219 case ACPI_TYPE_POWER:
220 case ACPI_TYPE_PROCESSOR:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 case ACPI_TYPE_EVENT:
222 case ACPI_TYPE_REGION:
223
224 /* Return an additional reference to the object */
225
226 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400227 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 break;
229
Len Brown4be44fc2005-08-05 00:44:28 -0400230 /* TYPE_ANY is untyped, and thus there is no object associated with it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231
232 case ACPI_TYPE_ANY:
233
Bob Mooreb8e4d892006-01-27 16:43:00 -0500234 ACPI_ERROR((AE_INFO,
235 "Untyped entry %p, no attached object!", node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Len Brown4be44fc2005-08-05 00:44:28 -0400237 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238
239 case ACPI_TYPE_LOCAL_REFERENCE:
240
241 switch (source_desc->reference.opcode) {
242 case AML_LOAD_OP:
243
244 /* This is a ddb_handle */
245 /* Return an additional reference to the object */
246
Bob Moore52fc0b02006-10-02 00:00:00 -0400247 case AML_REF_OF_OP:
248
Linus Torvalds1da177e2005-04-16 15:20:36 -0700249 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400250 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 break;
252
253 default:
254 /* No named references are allowed here */
255
Bob Mooreb8e4d892006-01-27 16:43:00 -0500256 ACPI_ERROR((AE_INFO,
257 "Unsupported Reference opcode %X (%s)",
258 source_desc->reference.opcode,
259 acpi_ps_get_opcode_name(source_desc->
260 reference.opcode)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Len Brown4be44fc2005-08-05 00:44:28 -0400262 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 }
264 break;
265
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 default:
267
Robert Moore44f6c012005-04-18 22:49:35 -0400268 /* Default case is for unknown types */
269
Bob Mooreb8e4d892006-01-27 16:43:00 -0500270 ACPI_ERROR((AE_INFO,
271 "Node %p - Unknown object type %X",
272 node, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
Len Brown4be44fc2005-08-05 00:44:28 -0400276 } /* switch (entry_type) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277
Robert Moore44f6c012005-04-18 22:49:35 -0400278 /* Return the object descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700279
Len Brown4be44fc2005-08-05 00:44:28 -0400280 *object_ptr = (void *)obj_desc;
281 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282}