blob: 01b26c80d22b84e6e1b2bdc124951e8053367234 [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 Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, 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
Len Brown4be44fc2005-08-05 00:44:28 -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
Len Brown4be44fc2005-08-05 00:44:28 -0400100 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Entry=%p source_desc=%p [%s]\n",
101 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)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 /* There is always exactly one level of indirection */
107
Len Brown4be44fc2005-08-05 00:44:28 -0400108 node = ACPI_CAST_PTR(struct acpi_namespace_node, node->object);
109 source_desc = acpi_ns_get_attached_object(node);
110 entry_type = acpi_ns_get_type((acpi_handle) node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 *object_ptr = node;
112 }
113
114 /*
115 * Several object types require no further processing:
116 * 1) Devices rarely have an attached object, return the Node
117 * 2) Method locals and arguments have a pseudo-Node
118 */
119 if (entry_type == ACPI_TYPE_DEVICE ||
Len Brown4be44fc2005-08-05 00:44:28 -0400120 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
121 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 if (!source_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500125 ACPI_ERROR((AE_INFO, "No object attached to node %p", node));
Len Brown4be44fc2005-08-05 00:44:28 -0400126 return_ACPI_STATUS(AE_AML_NO_OPERAND);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 }
128
129 /*
130 * Action is based on the type of the Node, which indicates the type
131 * of the attached object or pointer
132 */
133 switch (entry_type) {
134 case ACPI_TYPE_PACKAGE:
135
Len Brown4be44fc2005-08-05 00:44:28 -0400136 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500137 ACPI_ERROR((AE_INFO, "Object not a Package, type %s",
138 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400139 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 }
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 status = acpi_ds_get_package_arguments(source_desc);
143 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 /* Return an additional reference to the object */
145
146 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400147 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 }
149 break;
150
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 case ACPI_TYPE_BUFFER:
152
Len Brown4be44fc2005-08-05 00:44:28 -0400153 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500154 ACPI_ERROR((AE_INFO, "Object not a Buffer, type %s",
155 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400156 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 status = acpi_ds_get_buffer_arguments(source_desc);
160 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 /* 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 }
166 break;
167
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 case ACPI_TYPE_STRING:
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500171 ACPI_ERROR((AE_INFO, "Object not a String, type %s",
172 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400173 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 }
175
176 /* Return an additional reference to the object */
177
178 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400179 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180 break;
181
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 case ACPI_TYPE_INTEGER:
183
Len Brown4be44fc2005-08-05 00:44:28 -0400184 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500185 ACPI_ERROR((AE_INFO, "Object not a Integer, type %s",
186 acpi_ut_get_object_type_name(source_desc)));
Len Brown4be44fc2005-08-05 00:44:28 -0400187 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 }
189
190 /* Return an additional reference to the object */
191
192 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400193 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194 break;
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 case ACPI_TYPE_BUFFER_FIELD:
197 case ACPI_TYPE_LOCAL_REGION_FIELD:
198 case ACPI_TYPE_LOCAL_BANK_FIELD:
199 case ACPI_TYPE_LOCAL_INDEX_FIELD:
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
202 "field_read Node=%p source_desc=%p Type=%X\n",
203 node, source_desc, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
Len Brown4be44fc2005-08-05 00:44:28 -0400205 status =
206 acpi_ex_read_data_from_field(walk_state, source_desc,
207 &obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 break;
209
Len Brown4be44fc2005-08-05 00:44:28 -0400210 /* For these objects, just return the object attached to the Node */
Robert Moore44f6c012005-04-18 22:49:35 -0400211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 case ACPI_TYPE_MUTEX:
213 case ACPI_TYPE_METHOD:
214 case ACPI_TYPE_POWER:
215 case ACPI_TYPE_PROCESSOR:
216 case ACPI_TYPE_THERMAL:
217 case ACPI_TYPE_EVENT:
218 case ACPI_TYPE_REGION:
219
220 /* Return an additional reference to the object */
221
222 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400223 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 break;
225
Len Brown4be44fc2005-08-05 00:44:28 -0400226 /* TYPE_ANY is untyped, and thus there is no object associated with it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227
228 case ACPI_TYPE_ANY:
229
Bob Mooreb8e4d892006-01-27 16:43:00 -0500230 ACPI_ERROR((AE_INFO,
231 "Untyped entry %p, no attached object!", node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Len Brown4be44fc2005-08-05 00:44:28 -0400233 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700234
235 case ACPI_TYPE_LOCAL_REFERENCE:
236
237 switch (source_desc->reference.opcode) {
238 case AML_LOAD_OP:
239
240 /* This is a ddb_handle */
241 /* Return an additional reference to the object */
242
243 obj_desc = source_desc;
Len Brown4be44fc2005-08-05 00:44:28 -0400244 acpi_ut_add_reference(obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 break;
246
247 default:
248 /* No named references are allowed here */
249
Bob Mooreb8e4d892006-01-27 16:43:00 -0500250 ACPI_ERROR((AE_INFO,
251 "Unsupported Reference opcode %X (%s)",
252 source_desc->reference.opcode,
253 acpi_ps_get_opcode_name(source_desc->
254 reference.opcode)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
Len Brown4be44fc2005-08-05 00:44:28 -0400256 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 }
258 break;
259
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260 default:
261
Robert Moore44f6c012005-04-18 22:49:35 -0400262 /* Default case is for unknown types */
263
Bob Mooreb8e4d892006-01-27 16:43:00 -0500264 ACPI_ERROR((AE_INFO,
265 "Node %p - Unknown object type %X",
266 node, entry_type));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Len Brown4be44fc2005-08-05 00:44:28 -0400270 } /* switch (entry_type) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Robert Moore44f6c012005-04-18 22:49:35 -0400272 /* Return the object descriptor */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273
Len Brown4be44fc2005-08-05 00:44:28 -0400274 *object_ptr = (void *)obj_desc;
275 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276}