Merge ../from-linus
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / executer / exresnte.c
CommitLineData
1da177e4
LT
1
2/******************************************************************************
3 *
4 * Module Name: exresnte - AML Interpreter object resolution
5 *
6 *****************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2005, R. Byron Moore
10 * 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
1da177e4
LT
45#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
1da177e4 52#define _COMPONENT ACPI_EXECUTER
4be44fcd 53ACPI_MODULE_NAME("exresnte")
1da177e4
LT
54
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 ******************************************************************************/
1da177e4 80acpi_status
4be44fcd
LB
81acpi_ex_resolve_node_to_value(struct acpi_namespace_node **object_ptr,
82 struct acpi_walk_state *walk_state)
1da177e4 83{
4be44fcd
LB
84 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;
1da177e4 89
4be44fcd 90 ACPI_FUNCTION_TRACE("ex_resolve_node_to_value");
1da177e4
LT
91
92 /*
93 * The stack pointer points to a struct acpi_namespace_node (Node). Get the
94 * object that is attached to the Node.
95 */
4be44fcd
LB
96 node = *object_ptr;
97 source_desc = acpi_ns_get_attached_object(node);
98 entry_type = acpi_ns_get_type((acpi_handle) node);
1da177e4 99
4be44fcd
LB
100 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)));
1da177e4
LT
103
104 if ((entry_type == ACPI_TYPE_LOCAL_ALIAS) ||
4be44fcd 105 (entry_type == ACPI_TYPE_LOCAL_METHOD_ALIAS)) {
1da177e4
LT
106 /* There is always exactly one level of indirection */
107
4be44fcd
LB
108 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);
1da177e4
LT
111 *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 ||
4be44fcd
LB
120 (node->flags & (ANOBJ_METHOD_ARG | ANOBJ_METHOD_LOCAL))) {
121 return_ACPI_STATUS(AE_OK);
1da177e4
LT
122 }
123
124 if (!source_desc) {
4be44fcd
LB
125 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
126 "No object attached to node %p\n", node));
127 return_ACPI_STATUS(AE_AML_NO_OPERAND);
1da177e4
LT
128 }
129
130 /*
131 * Action is based on the type of the Node, which indicates the type
132 * of the attached object or pointer
133 */
134 switch (entry_type) {
135 case ACPI_TYPE_PACKAGE:
136
4be44fcd
LB
137 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_PACKAGE) {
138 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
139 "Object not a Package, type %s\n",
140 acpi_ut_get_object_type_name
141 (source_desc)));
142 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4
LT
143 }
144
4be44fcd
LB
145 status = acpi_ds_get_package_arguments(source_desc);
146 if (ACPI_SUCCESS(status)) {
1da177e4
LT
147 /* Return an additional reference to the object */
148
149 obj_desc = source_desc;
4be44fcd 150 acpi_ut_add_reference(obj_desc);
1da177e4
LT
151 }
152 break;
153
1da177e4
LT
154 case ACPI_TYPE_BUFFER:
155
4be44fcd
LB
156 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_BUFFER) {
157 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
158 "Object not a Buffer, type %s\n",
159 acpi_ut_get_object_type_name
160 (source_desc)));
161 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4
LT
162 }
163
4be44fcd
LB
164 status = acpi_ds_get_buffer_arguments(source_desc);
165 if (ACPI_SUCCESS(status)) {
1da177e4
LT
166 /* Return an additional reference to the object */
167
168 obj_desc = source_desc;
4be44fcd 169 acpi_ut_add_reference(obj_desc);
1da177e4
LT
170 }
171 break;
172
1da177e4
LT
173 case ACPI_TYPE_STRING:
174
4be44fcd
LB
175 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_STRING) {
176 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
177 "Object not a String, type %s\n",
178 acpi_ut_get_object_type_name
179 (source_desc)));
180 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4
LT
181 }
182
183 /* Return an additional reference to the object */
184
185 obj_desc = source_desc;
4be44fcd 186 acpi_ut_add_reference(obj_desc);
1da177e4
LT
187 break;
188
1da177e4
LT
189 case ACPI_TYPE_INTEGER:
190
4be44fcd
LB
191 if (ACPI_GET_OBJECT_TYPE(source_desc) != ACPI_TYPE_INTEGER) {
192 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
193 "Object not a Integer, type %s\n",
194 acpi_ut_get_object_type_name
195 (source_desc)));
196 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4
LT
197 }
198
199 /* Return an additional reference to the object */
200
201 obj_desc = source_desc;
4be44fcd 202 acpi_ut_add_reference(obj_desc);
1da177e4
LT
203 break;
204
1da177e4
LT
205 case ACPI_TYPE_BUFFER_FIELD:
206 case ACPI_TYPE_LOCAL_REGION_FIELD:
207 case ACPI_TYPE_LOCAL_BANK_FIELD:
208 case ACPI_TYPE_LOCAL_INDEX_FIELD:
209
4be44fcd
LB
210 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
211 "field_read Node=%p source_desc=%p Type=%X\n",
212 node, source_desc, entry_type));
1da177e4 213
4be44fcd
LB
214 status =
215 acpi_ex_read_data_from_field(walk_state, source_desc,
216 &obj_desc);
1da177e4
LT
217 break;
218
4be44fcd 219 /* For these objects, just return the object attached to the Node */
44f6c012 220
1da177e4
LT
221 case ACPI_TYPE_MUTEX:
222 case ACPI_TYPE_METHOD:
223 case ACPI_TYPE_POWER:
224 case ACPI_TYPE_PROCESSOR:
225 case ACPI_TYPE_THERMAL:
226 case ACPI_TYPE_EVENT:
227 case ACPI_TYPE_REGION:
228
229 /* Return an additional reference to the object */
230
231 obj_desc = source_desc;
4be44fcd 232 acpi_ut_add_reference(obj_desc);
1da177e4
LT
233 break;
234
4be44fcd 235 /* TYPE_ANY is untyped, and thus there is no object associated with it */
1da177e4
LT
236
237 case ACPI_TYPE_ANY:
238
4be44fcd
LB
239 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
240 "Untyped entry %p, no attached object!\n",
241 node));
1da177e4 242
4be44fcd 243 return_ACPI_STATUS(AE_AML_OPERAND_TYPE); /* Cannot be AE_TYPE */
1da177e4
LT
244
245 case ACPI_TYPE_LOCAL_REFERENCE:
246
247 switch (source_desc->reference.opcode) {
248 case AML_LOAD_OP:
249
250 /* This is a ddb_handle */
251 /* Return an additional reference to the object */
252
253 obj_desc = source_desc;
4be44fcd 254 acpi_ut_add_reference(obj_desc);
1da177e4
LT
255 break;
256
257 default:
258 /* No named references are allowed here */
259
4be44fcd
LB
260 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
261 "Unsupported Reference opcode %X (%s)\n",
262 source_desc->reference.opcode,
263 acpi_ps_get_opcode_name(source_desc->
264 reference.
265 opcode)));
1da177e4 266
4be44fcd 267 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4
LT
268 }
269 break;
270
1da177e4
LT
271 default:
272
44f6c012
RM
273 /* Default case is for unknown types */
274
4be44fcd
LB
275 ACPI_DEBUG_PRINT((ACPI_DB_ERROR,
276 "Node %p - Unknown object type %X\n",
277 node, entry_type));
1da177e4 278
4be44fcd 279 return_ACPI_STATUS(AE_AML_OPERAND_TYPE);
1da177e4 280
4be44fcd 281 } /* switch (entry_type) */
1da177e4 282
44f6c012 283 /* Return the object descriptor */
1da177e4 284
4be44fcd
LB
285 *object_ptr = (void *)obj_desc;
286 return_ACPI_STATUS(status);
1da177e4 287}