blob: 8095306fcd8c6d3ee246a44f9a41306e37e7fa9f [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/*
Bob Moorea8357b02010-01-22 19:07:36 +08008 * Copyright (C) 2000 - 2010, 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 Moore61686122006-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;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800105 walk_state->arguments[i].flags = ANOBJ_METHOD_ARG;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 }
107
108 /* Init the method locals */
109
110 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -0400111 ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 NAMEOF_LOCAL_NTE);
113
114 walk_state->local_variables[i].name.integer |= (i << 24);
Bob Moore61686122006-03-17 16:44:00 -0500115 walk_state->local_variables[i].descriptor_type =
Len Brown4be44fc2005-08-05 00:44:28 -0400116 ACPI_DESC_TYPE_NAMED;
117 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800118 walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 }
120
121 return_VOID;
122}
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/*******************************************************************************
125 *
126 * FUNCTION: acpi_ds_method_data_delete_all
127 *
128 * PARAMETERS: walk_state - Current walk state object
129 *
130 * RETURN: None
131 *
132 * DESCRIPTION: Delete method locals and arguments. Arguments are only
133 * deleted if this method was called from another method.
134 *
135 ******************************************************************************/
136
Len Brown4be44fc2005-08-05 00:44:28 -0400137void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138{
Len Brown4be44fc2005-08-05 00:44:28 -0400139 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140
Bob Mooreb229cf92006-04-21 17:15:00 -0400141 ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 /* Detach the locals */
144
145 for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
146 if (walk_state->local_variables[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800147 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400148 index,
149 walk_state->local_variables[index].
150 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
152 /* Detach object (if present) and remove a reference */
153
Len Brown4be44fc2005-08-05 00:44:28 -0400154 acpi_ns_detach_object(&walk_state->
155 local_variables[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 }
157 }
158
159 /* Detach the arguments */
160
161 for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
162 if (walk_state->arguments[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800163 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400164 index,
165 walk_state->arguments[index].object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 /* Detach object (if present) and remove a reference */
168
Len Brown4be44fc2005-08-05 00:44:28 -0400169 acpi_ns_detach_object(&walk_state->arguments[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700170 }
171 }
172
173 return_VOID;
174}
175
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176/*******************************************************************************
177 *
178 * FUNCTION: acpi_ds_method_data_init_args
179 *
180 * PARAMETERS: *Params - Pointer to a parameter list for the method
181 * max_param_count - The arg count for this method
182 * walk_state - Current walk state object
183 *
184 * RETURN: Status
185 *
186 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
187 * of ACPI operand objects, either null terminated or whose length
188 * is defined by max_param_count.
189 *
190 ******************************************************************************/
191
192acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400193acpi_ds_method_data_init_args(union acpi_operand_object **params,
194 u32 max_param_count,
195 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196{
Len Brown4be44fc2005-08-05 00:44:28 -0400197 acpi_status status;
198 u32 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Bob Mooreb229cf92006-04-21 17:15:00 -0400200 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
202 if (!params) {
Len Brown4be44fc2005-08-05 00:44:28 -0400203 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
204 "No param list passed to method\n"));
205 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206 }
207
Robert Moore44f6c012005-04-18 22:49:35 -0400208 /* Copy passed parameters into the new method stack frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209
Robert Moore44f6c012005-04-18 22:49:35 -0400210 while ((index < ACPI_METHOD_NUM_ARGS) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400211 (index < max_param_count) && params[index]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 /*
213 * A valid parameter.
214 * Store the argument in the method/walk descriptor.
215 * Do not copy the arg in order to implement call by reference
216 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800217 status = acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
Len Brown4be44fc2005-08-05 00:44:28 -0400218 params[index],
219 walk_state);
220 if (ACPI_FAILURE(status)) {
221 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222 }
223
224 index++;
225 }
226
Bob Mooreb27d6592010-05-26 11:47:13 +0800227 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index));
Len Brown4be44fc2005-08-05 00:44:28 -0400228 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229}
230
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231/*******************************************************************************
232 *
233 * FUNCTION: acpi_ds_method_data_get_node
234 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800235 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
236 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400237 * Index - Which Local or Arg whose type to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 * walk_state - Current walk state object
Robert Moore44f6c012005-04-18 22:49:35 -0400239 * Node - Where the node is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 *
Robert Moore44f6c012005-04-18 22:49:35 -0400241 * RETURN: Status and node
242 *
243 * DESCRIPTION: Get the Node associated with a local or arg.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244 *
245 ******************************************************************************/
246
247acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800248acpi_ds_method_data_get_node(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400249 u32 index,
250 struct acpi_walk_state *walk_state,
251 struct acpi_namespace_node **node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252{
Bob Mooreb229cf92006-04-21 17:15:00 -0400253 ACPI_FUNCTION_TRACE(ds_method_data_get_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254
255 /*
256 * Method Locals and Arguments are supported
257 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800258 switch (type) {
259 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
261 if (index > ACPI_METHOD_MAX_LOCAL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500262 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800263 "Local index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500264 index, ACPI_METHOD_MAX_LOCAL));
Len Brown4be44fc2005-08-05 00:44:28 -0400265 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 }
267
268 /* Return a pointer to the pseudo-node */
269
270 *node = &walk_state->local_variables[index];
271 break;
272
Bob Moore1044f1f2008-09-27 11:08:41 +0800273 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
275 if (index > ACPI_METHOD_MAX_ARG) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500276 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800277 "Arg index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500278 index, ACPI_METHOD_MAX_ARG));
Len Brown4be44fc2005-08-05 00:44:28 -0400279 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 }
281
282 /* Return a pointer to the pseudo-node */
283
284 *node = &walk_state->arguments[index];
285 break;
286
287 default:
Bob Mooref6a22b02010-03-05 17:56:40 +0800288 ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
Bob Moore1044f1f2008-09-27 11:08:41 +0800289 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700290 }
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293}
294
Linus Torvalds1da177e2005-04-16 15:20:36 -0700295/*******************************************************************************
296 *
297 * FUNCTION: acpi_ds_method_data_set_value
298 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800299 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
300 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400301 * Index - Which Local or Arg to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700302 * Object - Object to be inserted into the stack entry
303 * walk_state - Current walk state object
304 *
305 * RETURN: Status
306 *
307 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
308 * Note: There is no "implicit conversion" for locals.
309 *
310 ******************************************************************************/
311
Robert Moore44f6c012005-04-18 22:49:35 -0400312static acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800313acpi_ds_method_data_set_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400314 u32 index,
315 union acpi_operand_object *object,
316 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317{
Len Brown4be44fc2005-08-05 00:44:28 -0400318 acpi_status status;
319 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700320
Bob Mooreb229cf92006-04-21 17:15:00 -0400321 ACPI_FUNCTION_TRACE(ds_method_data_set_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322
Len Brown4be44fc2005-08-05 00:44:28 -0400323 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb27d6592010-05-26 11:47:13 +0800324 "NewObj %p Type %2.2X, Refs=%u [%s]\n", object,
Bob Moore1044f1f2008-09-27 11:08:41 +0800325 type, object->common.reference_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400326 acpi_ut_get_type_name(object->common.type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327
328 /* Get the namespace node for the arg/local */
329
Bob Moore1044f1f2008-09-27 11:08:41 +0800330 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400331 if (ACPI_FAILURE(status)) {
332 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333 }
334
335 /*
336 * Increment ref count so object can't be deleted while installed.
337 * NOTE: We do not copy the object in order to preserve the call by
338 * reference semantics of ACPI Control Method invocation.
Bob Moore958dd242006-05-12 17:12:00 -0400339 * (See ACPI Specification 2.0_c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700340 */
Len Brown4be44fc2005-08-05 00:44:28 -0400341 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342
343 /* Install the object */
344
345 node->object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400346 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347}
348
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349/*******************************************************************************
350 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 * FUNCTION: acpi_ds_method_data_get_value
352 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800353 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
354 * ACPI_REFCLASS_ARG
Bob Moore958dd242006-05-12 17:12:00 -0400355 * Index - Which local_var or argument to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 * walk_state - Current walk state object
Robert Moore44f6c012005-04-18 22:49:35 -0400357 * dest_desc - Where Arg or Local value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 *
359 * RETURN: Status
360 *
Robert Moore44f6c012005-04-18 22:49:35 -0400361 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700362 * Used only in acpi_ex_resolve_to_value().
363 *
364 ******************************************************************************/
365
366acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800367acpi_ds_method_data_get_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400368 u32 index,
369 struct acpi_walk_state *walk_state,
370 union acpi_operand_object **dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371{
Len Brown4be44fc2005-08-05 00:44:28 -0400372 acpi_status status;
373 struct acpi_namespace_node *node;
374 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375
Bob Mooreb229cf92006-04-21 17:15:00 -0400376 ACPI_FUNCTION_TRACE(ds_method_data_get_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377
378 /* Validate the object descriptor */
379
380 if (!dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500381 ACPI_ERROR((AE_INFO, "Null object descriptor pointer"));
Len Brown4be44fc2005-08-05 00:44:28 -0400382 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383 }
384
385 /* Get the namespace node for the arg/local */
386
Bob Moore1044f1f2008-09-27 11:08:41 +0800387 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400388 if (ACPI_FAILURE(status)) {
389 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390 }
391
392 /* Get the object from the node */
393
394 object = node->object;
395
396 /* Examine the returned object, it must be valid. */
397
398 if (!object) {
399 /*
400 * Index points to uninitialized object.
401 * This means that either 1) The expected argument was
402 * not passed to the method, or 2) A local variable
403 * was referenced by the method (via the ASL)
404 * before it was initialized. Either case is an error.
405 */
406
407 /* If slack enabled, init the local_x/arg_x to an Integer of value zero */
408
409 if (acpi_gbl_enable_interpreter_slack) {
Bob Mooredc95a272009-11-12 09:52:45 +0800410 object = acpi_ut_create_integer_object((u64) 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700411 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400412 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 }
414
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 node->object = object;
416 }
417
418 /* Otherwise, return the error */
419
Len Brown4be44fc2005-08-05 00:44:28 -0400420 else
Bob Moore1044f1f2008-09-27 11:08:41 +0800421 switch (type) {
422 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700423
Bob Mooreb8e4d892006-01-27 16:43:00 -0500424 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800425 "Uninitialized Arg[%u] at node %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500426 index, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700427
Len Brown4be44fc2005-08-05 00:44:28 -0400428 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Bob Moore1044f1f2008-09-27 11:08:41 +0800430 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Bob Mooree6789022009-09-03 09:58:14 +0800432 /*
433 * No error message for this case, will be trapped again later to
434 * detect and ignore cases of Store(local_x,local_x)
435 */
Len Brown4be44fc2005-08-05 00:44:28 -0400436 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Len Brown4be44fc2005-08-05 00:44:28 -0400438 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800439
Bob Mooreb8e4d892006-01-27 16:43:00 -0500440 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800441 "Not a Arg/Local opcode: 0x%X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800442 type));
Len Brown4be44fc2005-08-05 00:44:28 -0400443 return_ACPI_STATUS(AE_AML_INTERNAL);
444 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445 }
446
447 /*
448 * The Index points to an initialized and valid object.
449 * Return an additional reference to the object
450 */
451 *dest_desc = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400452 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453
Len Brown4be44fc2005-08-05 00:44:28 -0400454 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455}
456
Linus Torvalds1da177e2005-04-16 15:20:36 -0700457/*******************************************************************************
458 *
459 * FUNCTION: acpi_ds_method_data_delete_value
460 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800461 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
462 * ACPI_REFCLASS_ARG
Bob Moore958dd242006-05-12 17:12:00 -0400463 * Index - Which local_var or argument to delete
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 * walk_state - Current walk state object
465 *
466 * RETURN: None
467 *
Robert Moore44f6c012005-04-18 22:49:35 -0400468 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469 * a null into the stack slot after the object is deleted.
470 *
471 ******************************************************************************/
472
Robert Moore44f6c012005-04-18 22:49:35 -0400473static void
Bob Moore1044f1f2008-09-27 11:08:41 +0800474acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400475 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476{
Len Brown4be44fc2005-08-05 00:44:28 -0400477 acpi_status status;
478 struct acpi_namespace_node *node;
479 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480
Bob Mooreb229cf92006-04-21 17:15:00 -0400481 ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
483 /* Get the namespace node for the arg/local */
484
Bob Moore1044f1f2008-09-27 11:08:41 +0800485 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400486 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487 return_VOID;
488 }
489
490 /* Get the associated object */
491
Len Brown4be44fc2005-08-05 00:44:28 -0400492 object = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
494 /*
495 * Undefine the Arg or Local by setting its descriptor
496 * pointer to NULL. Locals/Args can contain both
497 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
498 */
499 node->object = NULL;
500
501 if ((object) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400502 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 /*
504 * There is a valid object.
505 * Decrement the reference count by one to balance the
506 * increment when the object was stored.
507 */
Len Brown4be44fc2005-08-05 00:44:28 -0400508 acpi_ut_remove_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 }
510
511 return_VOID;
512}
513
Linus Torvalds1da177e2005-04-16 15:20:36 -0700514/*******************************************************************************
515 *
516 * FUNCTION: acpi_ds_store_object_to_local
517 *
Bob Moore1044f1f2008-09-27 11:08:41 +0800518 * PARAMETERS: Type - Either ACPI_REFCLASS_LOCAL or
519 * ACPI_REFCLASS_ARG
Robert Moore44f6c012005-04-18 22:49:35 -0400520 * Index - Which Local or Arg to set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 * obj_desc - Value to be stored
522 * walk_state - Current walk state
523 *
524 * RETURN: Status
525 *
526 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
527 * as the new value for the Arg or Local and the reference count
528 * for obj_desc is incremented.
529 *
530 ******************************************************************************/
531
532acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800533acpi_ds_store_object_to_local(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400534 u32 index,
535 union acpi_operand_object *obj_desc,
536 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537{
Len Brown4be44fc2005-08-05 00:44:28 -0400538 acpi_status status;
539 struct acpi_namespace_node *node;
540 union acpi_operand_object *current_obj_desc;
541 union acpi_operand_object *new_obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Bob Mooreb229cf92006-04-21 17:15:00 -0400543 ACPI_FUNCTION_TRACE(ds_store_object_to_local);
Bob Mooreb27d6592010-05-26 11:47:13 +0800544 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
Bob Moore1044f1f2008-09-27 11:08:41 +0800545 type, index, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546
547 /* Parameter validation */
548
549 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400550 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700551 }
552
553 /* Get the namespace node for the arg/local */
554
Bob Moore1044f1f2008-09-27 11:08:41 +0800555 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400556 if (ACPI_FAILURE(status)) {
557 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558 }
559
Len Brown4be44fc2005-08-05 00:44:28 -0400560 current_obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561 if (current_obj_desc == obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400562 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
563 obj_desc));
564 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 }
566
567 /*
568 * If the reference count on the object is more than one, we must
569 * take a copy of the object before we store. A reference count
570 * of exactly 1 means that the object was just created during the
571 * evaluation of an expression, and we can safely use it since it
572 * is not used anywhere else.
573 */
574 new_obj_desc = obj_desc;
575 if (obj_desc->common.reference_count > 1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400576 status =
577 acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
578 walk_state);
579 if (ACPI_FAILURE(status)) {
580 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 }
582 }
583
584 /*
585 * If there is an object already in this slot, we either
586 * have to delete it, or if this is an argument and there
587 * is an object reference stored there, we have to do
588 * an indirect store!
589 */
590 if (current_obj_desc) {
591 /*
592 * Check for an indirect store if an argument
593 * contains an object reference (stored as an Node).
594 * We don't allow this automatic dereferencing for
595 * locals, since a store to a local should overwrite
596 * anything there, including an object reference.
597 *
598 * If both Arg0 and Local0 contain ref_of (Local4):
599 *
600 * Store (1, Arg0) - Causes indirect store to local4
601 * Store (1, Local0) - Stores 1 in local0, overwriting
602 * the reference to local4
603 * Store (1, de_refof (Local0)) - Causes indirect store to local4
604 *
605 * Weird, but true.
606 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800607 if (type == ACPI_REFCLASS_ARG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400609 * If we have a valid reference object that came from ref_of(),
610 * do the indirect store
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 */
Len Brown4be44fc2005-08-05 00:44:28 -0400612 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
613 ACPI_DESC_TYPE_OPERAND)
614 && (current_obj_desc->common.type ==
615 ACPI_TYPE_LOCAL_REFERENCE)
Bob Moore1044f1f2008-09-27 11:08:41 +0800616 && (current_obj_desc->reference.class ==
617 ACPI_REFCLASS_REFOF)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400618 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400619 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400620 new_obj_desc,
621 current_obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
623 /*
624 * Store this object to the Node (perform the indirect store)
625 * NOTE: No implicit conversion is performed, as per the ACPI
626 * specification rules on storing to Locals/Args.
627 */
Len Brown4be44fc2005-08-05 00:44:28 -0400628 status =
629 acpi_ex_store_object_to_node(new_obj_desc,
630 current_obj_desc->
631 reference.
632 object,
633 walk_state,
634 ACPI_NO_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700635
636 /* Remove local reference if we copied the object above */
637
638 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400639 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 }
Len Brown4be44fc2005-08-05 00:44:28 -0400641 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 }
643 }
644
Bob Moore1044f1f2008-09-27 11:08:41 +0800645 /* Delete the existing object before storing the new one */
646
647 acpi_ds_method_data_delete_value(type, index, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 }
649
650 /*
651 * Install the Obj descriptor (*new_obj_desc) into
652 * the descriptor for the Arg or Local.
653 * (increments the object reference count by one)
654 */
Len Brown4be44fc2005-08-05 00:44:28 -0400655 status =
Bob Moore1044f1f2008-09-27 11:08:41 +0800656 acpi_ds_method_data_set_value(type, index, new_obj_desc,
Len Brown4be44fc2005-08-05 00:44:28 -0400657 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658
659 /* Remove local reference if we copied the object above */
660
661 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400662 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 }
664
Len Brown4be44fc2005-08-05 00:44:28 -0400665 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666}
667
Robert Moore44f6c012005-04-18 22:49:35 -0400668#ifdef ACPI_OBSOLETE_FUNCTIONS
669/*******************************************************************************
670 *
671 * FUNCTION: acpi_ds_method_data_get_type
672 *
673 * PARAMETERS: Opcode - Either AML_LOCAL_OP or AML_ARG_OP
674 * Index - Which Local or Arg whose type to get
675 * walk_state - Current walk state object
676 *
677 * RETURN: Data type of current value of the selected Arg or Local
678 *
679 * DESCRIPTION: Get the type of the object stored in the Local or Arg
680 *
681 ******************************************************************************/
682
683acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -0400684acpi_ds_method_data_get_type(u16 opcode,
685 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400686{
Len Brown4be44fc2005-08-05 00:44:28 -0400687 acpi_status status;
688 struct acpi_namespace_node *node;
689 union acpi_operand_object *object;
Robert Moore44f6c012005-04-18 22:49:35 -0400690
Bob Mooreb229cf92006-04-21 17:15:00 -0400691 ACPI_FUNCTION_TRACE(ds_method_data_get_type);
Robert Moore44f6c012005-04-18 22:49:35 -0400692
693 /* Get the namespace node for the arg/local */
694
Len Brown4be44fc2005-08-05 00:44:28 -0400695 status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
696 if (ACPI_FAILURE(status)) {
697 return_VALUE((ACPI_TYPE_NOT_FOUND));
Robert Moore44f6c012005-04-18 22:49:35 -0400698 }
699
700 /* Get the object */
701
Len Brown4be44fc2005-08-05 00:44:28 -0400702 object = acpi_ns_get_attached_object(node);
Robert Moore44f6c012005-04-18 22:49:35 -0400703 if (!object) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400704
Robert Moore44f6c012005-04-18 22:49:35 -0400705 /* Uninitialized local/arg, return TYPE_ANY */
706
Len Brown4be44fc2005-08-05 00:44:28 -0400707 return_VALUE(ACPI_TYPE_ANY);
Robert Moore44f6c012005-04-18 22:49:35 -0400708 }
709
710 /* Get the object type */
711
Bob Moore3371c192009-02-18 14:44:03 +0800712 return_VALUE(object->type);
Robert Moore44f6c012005-04-18 22:49:35 -0400713}
714#endif