blob: da0f5468184cc15fbc8fd887bf8b6bc09fd06ec6 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
2 *
3 * Module Name: dsmthdat - control method arguments and local variables
4 *
5 ******************************************************************************/
6
7/*
Len Brown75a44ce2008-04-23 23:00:13 -04008 * Copyright (C) 2000 - 2008, 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 "acnamesp.h"
48#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("dsmthdat")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
Robert Moore44f6c012005-04-18 22:49:35 -040053/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040054static void
Bob Moore1044f1f2008-09-27 11:08:41 +080055acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -040056 u32 index, struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040057
58static acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +080059acpi_ds_method_data_set_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -040060 u32 index,
61 union acpi_operand_object *object,
62 struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040063
64#ifdef ACPI_OBSOLETE_FUNCTIONS
65acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -040066acpi_ds_method_data_get_type(u16 opcode,
67 u32 index, struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040068#endif
69
Linus Torvalds1da177e2005-04-16 15:20:36 -070070/*******************************************************************************
71 *
72 * FUNCTION: acpi_ds_method_data_init
73 *
74 * PARAMETERS: walk_state - Current walk state object
75 *
76 * RETURN: Status
77 *
78 * DESCRIPTION: Initialize the data structures that hold the method's arguments
Robert Moore44f6c012005-04-18 22:49:35 -040079 * and locals. The data struct is an array of namespace nodes for
80 * each - this allows ref_of and de_ref_of to work properly for these
Linus Torvalds1da177e2005-04-16 15:20:36 -070081 * special data types.
82 *
83 * NOTES: walk_state fields are initialized to zero by the
Bob Moore83135242006-10-03 00:00:00 -040084 * ACPI_ALLOCATE_ZEROED().
Linus Torvalds1da177e2005-04-16 15:20:36 -070085 *
86 * A pseudo-Namespace Node is assigned to each argument and local
87 * so that ref_of() can return a pointer to the Node.
88 *
89 ******************************************************************************/
90
Len Brown4be44fc2005-08-05 00:44:28 -040091void acpi_ds_method_data_init(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
Len Brown4be44fc2005-08-05 00:44:28 -040093 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070094
Bob Mooreb229cf92006-04-21 17:15:00 -040095 ACPI_FUNCTION_TRACE(ds_method_data_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -070096
97 /* Init the method arguments */
98
99 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400100 ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 NAMEOF_ARG_NTE);
102 walk_state->arguments[i].name.integer |= (i << 24);
Bob Moore616861242006-03-17 16:44:00 -0500103 walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED;
Len Brown4be44fc2005-08-05 00:44:28 -0400104 walk_state->arguments[i].type = ACPI_TYPE_ANY;
Bob Moore616861242006-03-17 16:44:00 -0500105 walk_state->arguments[i].flags =
106 ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_ARG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107 }
108
109 /* Init the method locals */
110
111 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400112 ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700113 NAMEOF_LOCAL_NTE);
114
115 walk_state->local_variables[i].name.integer |= (i << 24);
Bob Moore616861242006-03-17 16:44:00 -0500116 walk_state->local_variables[i].descriptor_type =
Len Brown4be44fc2005-08-05 00:44:28 -0400117 ACPI_DESC_TYPE_NAMED;
118 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
Bob Moore616861242006-03-17 16:44:00 -0500119 walk_state->local_variables[i].flags =
120 ANOBJ_END_OF_PEER_LIST | ANOBJ_METHOD_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
123 return_VOID;
124}
125
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126/*******************************************************************************
127 *
128 * FUNCTION: acpi_ds_method_data_delete_all
129 *
130 * PARAMETERS: walk_state - Current walk state object
131 *
132 * RETURN: None
133 *
134 * DESCRIPTION: Delete method locals and arguments. Arguments are only
135 * deleted if this method was called from another method.
136 *
137 ******************************************************************************/
138
Len Brown4be44fc2005-08-05 00:44:28 -0400139void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140{
Len Brown4be44fc2005-08-05 00:44:28 -0400141 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
Bob Mooreb229cf92006-04-21 17:15:00 -0400143 ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144
145 /* Detach the locals */
146
147 for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
148 if (walk_state->local_variables[index].object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400149 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%d=%p\n",
150 index,
151 walk_state->local_variables[index].
152 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
154 /* Detach object (if present) and remove a reference */
155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 acpi_ns_detach_object(&walk_state->
157 local_variables[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 }
159 }
160
161 /* Detach the arguments */
162
163 for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
164 if (walk_state->arguments[index].object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400165 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%d=%p\n",
166 index,
167 walk_state->arguments[index].object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168
169 /* Detach object (if present) and remove a reference */
170
Len Brown4be44fc2005-08-05 00:44:28 -0400171 acpi_ns_detach_object(&walk_state->arguments[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172 }
173 }
174
175 return_VOID;
176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178/*******************************************************************************
179 *
180 * FUNCTION: acpi_ds_method_data_init_args
181 *
182 * PARAMETERS: *Params - Pointer to a parameter list for the method
183 * max_param_count - The arg count for this method
184 * walk_state - Current walk state object
185 *
186 * RETURN: Status
187 *
188 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
189 * of ACPI operand objects, either null terminated or whose length
190 * is defined by max_param_count.
191 *
192 ******************************************************************************/
193
194acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400195acpi_ds_method_data_init_args(union acpi_operand_object **params,
196 u32 max_param_count,
197 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Len Brown4be44fc2005-08-05 00:44:28 -0400199 acpi_status status;
200 u32 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Bob Mooreb229cf92006-04-21 17:15:00 -0400202 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
204 if (!params) {
Len Brown4be44fc2005-08-05 00:44:28 -0400205 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
206 "No param list passed to method\n"));
207 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208 }
209
Robert Moore44f6c012005-04-18 22:49:35 -0400210 /* Copy passed parameters into the new method stack frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Robert Moore44f6c012005-04-18 22:49:35 -0400212 while ((index < ACPI_METHOD_NUM_ARGS) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400213 (index < max_param_count) && params[index]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 /*
215 * A valid parameter.
216 * Store the argument in the method/walk descriptor.
217 * Do not copy the arg in order to implement call by reference
218 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800219 status = acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
Len Brown4be44fc2005-08-05 00:44:28 -0400220 params[index],
221 walk_state);
222 if (ACPI_FAILURE(status)) {
223 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224 }
225
226 index++;
227 }
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%d args passed to method\n", index));
230 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231}
232
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233/*******************************************************************************
234 *
235 * FUNCTION: acpi_ds_method_data_get_node
236 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800237 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
238 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400239 * Index - Which Local or Arg whose type to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 * walk_state - Current walk state object
Robert Moore44f6c012005-04-18 22:49:35 -0400241 * Node - Where the node is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 *
Robert Moore44f6c012005-04-18 22:49:35 -0400243 * RETURN: Status and node
244 *
245 * DESCRIPTION: Get the Node associated with a local or arg.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700246 *
247 ******************************************************************************/
248
249acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800250acpi_ds_method_data_get_node(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400251 u32 index,
252 struct acpi_walk_state *walk_state,
253 struct acpi_namespace_node **node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254{
Bob Mooreb229cf92006-04-21 17:15:00 -0400255 ACPI_FUNCTION_TRACE(ds_method_data_get_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256
257 /*
258 * Method Locals and Arguments are supported
259 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800260 switch (type) {
261 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262
263 if (index > ACPI_METHOD_MAX_LOCAL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500264 ACPI_ERROR((AE_INFO,
265 "Local index %d is invalid (max %d)",
266 index, ACPI_METHOD_MAX_LOCAL));
Len Brown4be44fc2005-08-05 00:44:28 -0400267 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700268 }
269
270 /* Return a pointer to the pseudo-node */
271
272 *node = &walk_state->local_variables[index];
273 break;
274
Bob Moore1044f1f2008-09-27 11:08:41 +0800275 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
277 if (index > ACPI_METHOD_MAX_ARG) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500278 ACPI_ERROR((AE_INFO,
279 "Arg index %d is invalid (max %d)",
280 index, ACPI_METHOD_MAX_ARG));
Len Brown4be44fc2005-08-05 00:44:28 -0400281 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282 }
283
284 /* Return a pointer to the pseudo-node */
285
286 *node = &walk_state->arguments[index];
287 break;
288
289 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800290 ACPI_ERROR((AE_INFO, "Type %d is invalid", type));
291 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 }
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295}
296
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297/*******************************************************************************
298 *
299 * FUNCTION: acpi_ds_method_data_set_value
300 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800301 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
302 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400303 * Index - Which Local or Arg to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 * Object - Object to be inserted into the stack entry
305 * walk_state - Current walk state object
306 *
307 * RETURN: Status
308 *
309 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
310 * Note: There is no "implicit conversion" for locals.
311 *
312 ******************************************************************************/
313
Robert Moore44f6c012005-04-18 22:49:35 -0400314static acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800315acpi_ds_method_data_set_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400316 u32 index,
317 union acpi_operand_object *object,
318 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319{
Len Brown4be44fc2005-08-05 00:44:28 -0400320 acpi_status status;
321 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Bob Mooreb229cf92006-04-21 17:15:00 -0400323 ACPI_FUNCTION_TRACE(ds_method_data_set_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324
Len Brown4be44fc2005-08-05 00:44:28 -0400325 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Moore1044f1f2008-09-27 11:08:41 +0800326 "NewObj %p Type %2.2X, Refs=%d [%s]\n", object,
327 type, object->common.reference_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400328 acpi_ut_get_type_name(object->common.type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329
330 /* Get the namespace node for the arg/local */
331
Bob Moore1044f1f2008-09-27 11:08:41 +0800332 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400333 if (ACPI_FAILURE(status)) {
334 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700335 }
336
337 /*
338 * Increment ref count so object can't be deleted while installed.
339 * NOTE: We do not copy the object in order to preserve the call by
340 * reference semantics of ACPI Control Method invocation.
Bob Moore958dd242006-05-12 17:12:00 -0400341 * (See ACPI Specification 2.0_c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 */
Len Brown4be44fc2005-08-05 00:44:28 -0400343 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344
345 /* Install the object */
346
347 node->object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400348 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351/*******************************************************************************
352 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700353 * FUNCTION: acpi_ds_method_data_get_value
354 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800355 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
356 * ACPI_REFCLASS_ARG
Bob Moore958dd242006-05-12 17:12:00 -0400357 * Index - Which local_var or argument to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 * walk_state - Current walk state object
Robert Moore44f6c012005-04-18 22:49:35 -0400359 * dest_desc - Where Arg or Local value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360 *
361 * RETURN: Status
362 *
Robert Moore44f6c012005-04-18 22:49:35 -0400363 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700364 * Used only in acpi_ex_resolve_to_value().
365 *
366 ******************************************************************************/
367
368acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800369acpi_ds_method_data_get_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400370 u32 index,
371 struct acpi_walk_state *walk_state,
372 union acpi_operand_object **dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373{
Len Brown4be44fc2005-08-05 00:44:28 -0400374 acpi_status status;
375 struct acpi_namespace_node *node;
376 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
Bob Mooreb229cf92006-04-21 17:15:00 -0400378 ACPI_FUNCTION_TRACE(ds_method_data_get_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379
380 /* Validate the object descriptor */
381
382 if (!dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500383 ACPI_ERROR((AE_INFO, "Null object descriptor pointer"));
Len Brown4be44fc2005-08-05 00:44:28 -0400384 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385 }
386
387 /* Get the namespace node for the arg/local */
388
Bob Moore1044f1f2008-09-27 11:08:41 +0800389 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400390 if (ACPI_FAILURE(status)) {
391 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392 }
393
394 /* Get the object from the node */
395
396 object = node->object;
397
398 /* Examine the returned object, it must be valid. */
399
400 if (!object) {
401 /*
402 * Index points to uninitialized object.
403 * This means that either 1) The expected argument was
404 * not passed to the method, or 2) A local variable
405 * was referenced by the method (via the ASL)
406 * before it was initialized. Either case is an error.
407 */
408
409 /* If slack enabled, init the local_x/arg_x to an Integer of value zero */
410
411 if (acpi_gbl_enable_interpreter_slack) {
Len Brown4be44fc2005-08-05 00:44:28 -0400412 object =
413 acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400415 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700416 }
417
418 object->integer.value = 0;
419 node->object = object;
420 }
421
422 /* Otherwise, return the error */
423
Len Brown4be44fc2005-08-05 00:44:28 -0400424 else
Bob Moore1044f1f2008-09-27 11:08:41 +0800425 switch (type) {
426 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Bob Mooreb8e4d892006-01-27 16:43:00 -0500428 ACPI_ERROR((AE_INFO,
429 "Uninitialized Arg[%d] at node %p",
430 index, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Len Brown4be44fc2005-08-05 00:44:28 -0400432 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Bob Moore1044f1f2008-09-27 11:08:41 +0800434 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435
Bob Mooreb8e4d892006-01-27 16:43:00 -0500436 ACPI_ERROR((AE_INFO,
437 "Uninitialized Local[%d] at node %p",
438 index, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439
Len Brown4be44fc2005-08-05 00:44:28 -0400440 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441
Len Brown4be44fc2005-08-05 00:44:28 -0400442 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800443
Bob Mooreb8e4d892006-01-27 16:43:00 -0500444 ACPI_ERROR((AE_INFO,
445 "Not a Arg/Local opcode: %X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800446 type));
Len Brown4be44fc2005-08-05 00:44:28 -0400447 return_ACPI_STATUS(AE_AML_INTERNAL);
448 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 }
450
451 /*
452 * The Index points to an initialized and valid object.
453 * Return an additional reference to the object
454 */
455 *dest_desc = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400456 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457
Len Brown4be44fc2005-08-05 00:44:28 -0400458 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459}
460
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461/*******************************************************************************
462 *
463 * FUNCTION: acpi_ds_method_data_delete_value
464 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800465 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
466 * ACPI_REFCLASS_ARG
Bob Moore958dd242006-05-12 17:12:00 -0400467 * Index - Which local_var or argument to delete
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 * walk_state - Current walk state object
469 *
470 * RETURN: None
471 *
Robert Moore44f6c012005-04-18 22:49:35 -0400472 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473 * a null into the stack slot after the object is deleted.
474 *
475 ******************************************************************************/
476
Robert Moore44f6c012005-04-18 22:49:35 -0400477static void
Bob Moore1044f1f2008-09-27 11:08:41 +0800478acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400479 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480{
Len Brown4be44fc2005-08-05 00:44:28 -0400481 acpi_status status;
482 struct acpi_namespace_node *node;
483 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Bob Mooreb229cf92006-04-21 17:15:00 -0400485 ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486
487 /* Get the namespace node for the arg/local */
488
Bob Moore1044f1f2008-09-27 11:08:41 +0800489 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400490 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491 return_VOID;
492 }
493
494 /* Get the associated object */
495
Len Brown4be44fc2005-08-05 00:44:28 -0400496 object = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700497
498 /*
499 * Undefine the Arg or Local by setting its descriptor
500 * pointer to NULL. Locals/Args can contain both
501 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
502 */
503 node->object = NULL;
504
505 if ((object) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400506 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 /*
508 * There is a valid object.
509 * Decrement the reference count by one to balance the
510 * increment when the object was stored.
511 */
Len Brown4be44fc2005-08-05 00:44:28 -0400512 acpi_ut_remove_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 }
514
515 return_VOID;
516}
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518/*******************************************************************************
519 *
520 * FUNCTION: acpi_ds_store_object_to_local
521 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800522 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
523 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400524 * Index - Which Local or Arg to set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 * obj_desc - Value to be stored
526 * walk_state - Current walk state
527 *
528 * RETURN: Status
529 *
530 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
531 * as the new value for the Arg or Local and the reference count
532 * for obj_desc is incremented.
533 *
534 ******************************************************************************/
535
536acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800537acpi_ds_store_object_to_local(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400538 u32 index,
539 union acpi_operand_object *obj_desc,
540 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541{
Len Brown4be44fc2005-08-05 00:44:28 -0400542 acpi_status status;
543 struct acpi_namespace_node *node;
544 union acpi_operand_object *current_obj_desc;
545 union acpi_operand_object *new_obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
Bob Mooreb229cf92006-04-21 17:15:00 -0400547 ACPI_FUNCTION_TRACE(ds_store_object_to_local);
Bob Moore1044f1f2008-09-27 11:08:41 +0800548 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%d Obj=%p\n",
549 type, index, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550
551 /* Parameter validation */
552
553 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400554 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 }
556
557 /* Get the namespace node for the arg/local */
558
Bob Moore1044f1f2008-09-27 11:08:41 +0800559 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400560 if (ACPI_FAILURE(status)) {
561 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 }
563
Len Brown4be44fc2005-08-05 00:44:28 -0400564 current_obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 if (current_obj_desc == obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400566 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
567 obj_desc));
568 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569 }
570
571 /*
572 * If the reference count on the object is more than one, we must
573 * take a copy of the object before we store. A reference count
574 * of exactly 1 means that the object was just created during the
575 * evaluation of an expression, and we can safely use it since it
576 * is not used anywhere else.
577 */
578 new_obj_desc = obj_desc;
579 if (obj_desc->common.reference_count > 1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400580 status =
581 acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
582 walk_state);
583 if (ACPI_FAILURE(status)) {
584 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 }
586 }
587
588 /*
589 * If there is an object already in this slot, we either
590 * have to delete it, or if this is an argument and there
591 * is an object reference stored there, we have to do
592 * an indirect store!
593 */
594 if (current_obj_desc) {
595 /*
596 * Check for an indirect store if an argument
597 * contains an object reference (stored as an Node).
598 * We don't allow this automatic dereferencing for
599 * locals, since a store to a local should overwrite
600 * anything there, including an object reference.
601 *
602 * If both Arg0 and Local0 contain ref_of (Local4):
603 *
604 * Store (1, Arg0) - Causes indirect store to local4
605 * Store (1, Local0) - Stores 1 in local0, overwriting
606 * the reference to local4
607 * Store (1, de_refof (Local0)) - Causes indirect store to local4
608 *
609 * Weird, but true.
610 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800611 if (type == ACPI_REFCLASS_ARG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400613 * If we have a valid reference object that came from ref_of(),
614 * do the indirect store
Linus Torvalds1da177e2005-04-16 15:20:36 -0700615 */
Len Brown4be44fc2005-08-05 00:44:28 -0400616 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
617 ACPI_DESC_TYPE_OPERAND)
618 && (current_obj_desc->common.type ==
619 ACPI_TYPE_LOCAL_REFERENCE)
Bob Moore1044f1f2008-09-27 11:08:41 +0800620 && (current_obj_desc->reference.class ==
621 ACPI_REFCLASS_REFOF)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400622 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400623 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400624 new_obj_desc,
625 current_obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700626
627 /*
628 * Store this object to the Node (perform the indirect store)
629 * NOTE: No implicit conversion is performed, as per the ACPI
630 * specification rules on storing to Locals/Args.
631 */
Len Brown4be44fc2005-08-05 00:44:28 -0400632 status =
633 acpi_ex_store_object_to_node(new_obj_desc,
634 current_obj_desc->
635 reference.
636 object,
637 walk_state,
638 ACPI_NO_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 /* Remove local reference if we copied the object above */
641
642 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400643 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
Len Brown4be44fc2005-08-05 00:44:28 -0400645 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 }
647 }
648
Bob Moore1044f1f2008-09-27 11:08:41 +0800649 /* Delete the existing object before storing the new one */
650
651 acpi_ds_method_data_delete_value(type, index, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700652 }
653
654 /*
655 * Install the Obj descriptor (*new_obj_desc) into
656 * the descriptor for the Arg or Local.
657 * (increments the object reference count by one)
658 */
Len Brown4be44fc2005-08-05 00:44:28 -0400659 status =
Bob Moore1044f1f2008-09-27 11:08:41 +0800660 acpi_ds_method_data_set_value(type, index, new_obj_desc,
Len Brown4be44fc2005-08-05 00:44:28 -0400661 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700662
663 /* Remove local reference if we copied the object above */
664
665 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400666 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667 }
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670}
671
Robert Moore44f6c012005-04-18 22:49:35 -0400672#ifdef ACPI_OBSOLETE_FUNCTIONS
673/*******************************************************************************
674 *
675 * FUNCTION: acpi_ds_method_data_get_type
676 *
677 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
678 * Index - Which Local or Arg whose type to get
679 * walk_state - Current walk state object
680 *
681 * RETURN: Data type of current value of the selected Arg or Local
682 *
683 * DESCRIPTION: Get the type of the object stored in the Local or Arg
684 *
685 ******************************************************************************/
686
687acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -0400688acpi_ds_method_data_get_type(u16 opcode,
689 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400690{
Len Brown4be44fc2005-08-05 00:44:28 -0400691 acpi_status status;
692 struct acpi_namespace_node *node;
693 union acpi_operand_object *object;
Robert Moore44f6c012005-04-18 22:49:35 -0400694
Bob Mooreb229cf92006-04-21 17:15:00 -0400695 ACPI_FUNCTION_TRACE(ds_method_data_get_type);
Robert Moore44f6c012005-04-18 22:49:35 -0400696
697 /* Get the namespace node for the arg/local */
698
Len Brown4be44fc2005-08-05 00:44:28 -0400699 status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
700 if (ACPI_FAILURE(status)) {
701 return_VALUE((ACPI_TYPE_NOT_FOUND));
Robert Moore44f6c012005-04-18 22:49:35 -0400702 }
703
704 /* Get the object */
705
Len Brown4be44fc2005-08-05 00:44:28 -0400706 object = acpi_ns_get_attached_object(node);
Robert Moore44f6c012005-04-18 22:49:35 -0400707 if (!object) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400708
Robert Moore44f6c012005-04-18 22:49:35 -0400709 /* Uninitialized local/arg, return TYPE_ANY */
710
Len Brown4be44fc2005-08-05 00:44:28 -0400711 return_VALUE(ACPI_TYPE_ANY);
Robert Moore44f6c012005-04-18 22:49:35 -0400712 }
713
714 /* Get the object type */
715
Len Brown4be44fc2005-08-05 00:44:28 -0400716 return_VALUE(ACPI_GET_OBJECT_TYPE(object));
Robert Moore44f6c012005-04-18 22:49:35 -0400717}
718#endif