blob: 45cbebaa32c08d5aec9cfb0706423ace6ad885ae [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 Moorec8100dc2016-01-15 08:17:03 +08008 * Copyright (C) 2000 - 2016, 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
Bob Moore73a30902012-10-31 02:26:55 +000079 * and locals. The data struct is an array of namespace nodes for
Robert Moore44f6c012005-04-18 22:49:35 -040080 * 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);
Bob Moore1fad8732015-12-29 13:54:36 +0800102
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103 walk_state->arguments[i].name.integer |= (i << 24);
Bob Moore616861242006-03-17 16:44:00 -0500104 walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED;
Len Brown4be44fc2005-08-05 00:44:28 -0400105 walk_state->arguments[i].type = ACPI_TYPE_ANY;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800106 walk_state->arguments[i].flags = 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;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +0800119 walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 }
121
122 return_VOID;
123}
124
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125/*******************************************************************************
126 *
127 * FUNCTION: acpi_ds_method_data_delete_all
128 *
129 * PARAMETERS: walk_state - Current walk state object
130 *
131 * RETURN: None
132 *
Bob Moore73a30902012-10-31 02:26:55 +0000133 * DESCRIPTION: Delete method locals and arguments. Arguments are only
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 * deleted if this method was called from another method.
135 *
136 ******************************************************************************/
137
Len Brown4be44fc2005-08-05 00:44:28 -0400138void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139{
Len Brown4be44fc2005-08-05 00:44:28 -0400140 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141
Bob Mooreb229cf92006-04-21 17:15:00 -0400142 ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
144 /* Detach the locals */
145
146 for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
147 if (walk_state->local_variables[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800148 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400149 index,
150 walk_state->local_variables[index].
151 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* Detach object (if present) and remove a reference */
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 acpi_ns_detach_object(&walk_state->
156 local_variables[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 }
158 }
159
160 /* Detach the arguments */
161
162 for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
163 if (walk_state->arguments[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800164 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400165 index,
166 walk_state->arguments[index].object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167
168 /* Detach object (if present) and remove a reference */
169
Len Brown4be44fc2005-08-05 00:44:28 -0400170 acpi_ns_detach_object(&walk_state->arguments[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172 }
173
174 return_VOID;
175}
176
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177/*******************************************************************************
178 *
179 * FUNCTION: acpi_ds_method_data_init_args
180 *
Bob Mooreba494be2012-07-12 09:40:10 +0800181 * PARAMETERS: *params - Pointer to a parameter list for the method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 * max_param_count - The arg count for this method
183 * walk_state - Current walk state object
184 *
185 * RETURN: Status
186 *
Bob Moore73a30902012-10-31 02:26:55 +0000187 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 * of ACPI operand objects, either null terminated or whose length
189 * is defined by max_param_count.
190 *
191 ******************************************************************************/
192
193acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400194acpi_ds_method_data_init_args(union acpi_operand_object **params,
195 u32 max_param_count,
196 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197{
Len Brown4be44fc2005-08-05 00:44:28 -0400198 acpi_status status;
199 u32 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200
Bob Mooreb229cf92006-04-21 17:15:00 -0400201 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
203 if (!params) {
Len Brown4be44fc2005-08-05 00:44:28 -0400204 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Moore1fad8732015-12-29 13:54:36 +0800205 "No parameter list passed to method\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400206 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207 }
208
Robert Moore44f6c012005-04-18 22:49:35 -0400209 /* Copy passed parameters into the new method stack frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700210
Robert Moore44f6c012005-04-18 22:49:35 -0400211 while ((index < ACPI_METHOD_NUM_ARGS) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400212 (index < max_param_count) && params[index]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 /*
214 * A valid parameter.
215 * Store the argument in the method/walk descriptor.
216 * Do not copy the arg in order to implement call by reference
217 */
Bob Moore1fad8732015-12-29 13:54:36 +0800218 status =
219 acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
220 params[index], walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400221 if (ACPI_FAILURE(status)) {
222 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 }
224
225 index++;
226 }
227
Bob Mooreb27d6592010-05-26 11:47:13 +0800228 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index));
Len Brown4be44fc2005-08-05 00:44:28 -0400229 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230}
231
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232/*******************************************************************************
233 *
234 * FUNCTION: acpi_ds_method_data_get_node
235 *
Bob Mooreba494be2012-07-12 09:40:10 +0800236 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800237 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800238 * index - Which Local or Arg whose type to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239 * walk_state - Current walk state object
Bob Mooreba494be2012-07-12 09:40:10 +0800240 * node - Where the node is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 *
Robert Moore44f6c012005-04-18 22:49:35 -0400242 * RETURN: Status and node
243 *
244 * DESCRIPTION: Get the Node associated with a local or arg.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 *
246 ******************************************************************************/
247
248acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800249acpi_ds_method_data_get_node(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400250 u32 index,
251 struct acpi_walk_state *walk_state,
252 struct acpi_namespace_node **node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
Bob Mooreb229cf92006-04-21 17:15:00 -0400254 ACPI_FUNCTION_TRACE(ds_method_data_get_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255
256 /*
257 * Method Locals and Arguments are supported
258 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800259 switch (type) {
260 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
262 if (index > ACPI_METHOD_MAX_LOCAL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500263 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800264 "Local index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500265 index, ACPI_METHOD_MAX_LOCAL));
Len Brown4be44fc2005-08-05 00:44:28 -0400266 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 }
268
269 /* Return a pointer to the pseudo-node */
270
271 *node = &walk_state->local_variables[index];
272 break;
273
Bob Moore1044f1f2008-09-27 11:08:41 +0800274 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275
276 if (index > ACPI_METHOD_MAX_ARG) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500277 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800278 "Arg index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500279 index, ACPI_METHOD_MAX_ARG));
Len Brown4be44fc2005-08-05 00:44:28 -0400280 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 }
282
283 /* Return a pointer to the pseudo-node */
284
285 *node = &walk_state->arguments[index];
286 break;
287
288 default:
Chao Guan1d1ea1b2013-06-08 00:58:14 +0000289
Bob Mooref6a22b02010-03-05 17:56:40 +0800290 ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
Bob Moore1044f1f2008-09-27 11:08:41 +0800291 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 Mooreba494be2012-07-12 09:40:10 +0800301 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800302 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800303 * index - Which Local or Arg to get
304 * object - Object to be inserted into the stack entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700305 * 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 Mooreb27d6592010-05-26 11:47:13 +0800326 "NewObj %p Type %2.2X, Refs=%u [%s]\n", object,
Bob Moore1044f1f2008-09-27 11:08:41 +0800327 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 Mooreba494be2012-07-12 09:40:10 +0800341 * (See ACPI Specification 2.0C)
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 Mooreba494be2012-07-12 09:40:10 +0800355 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800356 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800357 * index - Which localVar 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)
Bob Moore73a30902012-10-31 02:26:55 +0000406 * before it was initialized. Either case is an error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700407 */
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) {
Bob Mooredc95a272009-11-12 09:52:45 +0800412 object = acpi_ut_create_integer_object((u64) 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700413 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400414 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700415 }
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 node->object = object;
418 }
419
420 /* Otherwise, return the error */
421
Len Brown4be44fc2005-08-05 00:44:28 -0400422 else
Bob Moore1044f1f2008-09-27 11:08:41 +0800423 switch (type) {
424 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700425
Bob Mooreb8e4d892006-01-27 16:43:00 -0500426 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800427 "Uninitialized Arg[%u] at node %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500428 index, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429
Len Brown4be44fc2005-08-05 00:44:28 -0400430 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700431
Bob Moore1044f1f2008-09-27 11:08:41 +0800432 case ACPI_REFCLASS_LOCAL:
Bob Mooree6789022009-09-03 09:58:14 +0800433 /*
434 * No error message for this case, will be trapped again later to
435 * detect and ignore cases of Store(local_x,local_x)
436 */
Len Brown4be44fc2005-08-05 00:44:28 -0400437 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438
Len Brown4be44fc2005-08-05 00:44:28 -0400439 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800440
Bob Mooreb8e4d892006-01-27 16:43:00 -0500441 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800442 "Not a Arg/Local opcode: 0x%X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800443 type));
Len Brown4be44fc2005-08-05 00:44:28 -0400444 return_ACPI_STATUS(AE_AML_INTERNAL);
445 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 }
447
448 /*
449 * The Index points to an initialized and valid object.
450 * Return an additional reference to the object
451 */
452 *dest_desc = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400453 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454
Len Brown4be44fc2005-08-05 00:44:28 -0400455 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456}
457
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458/*******************************************************************************
459 *
460 * FUNCTION: acpi_ds_method_data_delete_value
461 *
Bob Mooreba494be2012-07-12 09:40:10 +0800462 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800463 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800464 * index - Which localVar or argument to delete
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 * walk_state - Current walk state object
466 *
467 * RETURN: None
468 *
Bob Moore73a30902012-10-31 02:26:55 +0000469 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 * a null into the stack slot after the object is deleted.
471 *
472 ******************************************************************************/
473
Robert Moore44f6c012005-04-18 22:49:35 -0400474static void
Bob Moore1044f1f2008-09-27 11:08:41 +0800475acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400476 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477{
Len Brown4be44fc2005-08-05 00:44:28 -0400478 acpi_status status;
479 struct acpi_namespace_node *node;
480 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481
Bob Mooreb229cf92006-04-21 17:15:00 -0400482 ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
484 /* Get the namespace node for the arg/local */
485
Bob Moore1044f1f2008-09-27 11:08:41 +0800486 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400487 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 return_VOID;
489 }
490
491 /* Get the associated object */
492
Len Brown4be44fc2005-08-05 00:44:28 -0400493 object = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
495 /*
496 * Undefine the Arg or Local by setting its descriptor
497 * pointer to NULL. Locals/Args can contain both
498 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
499 */
500 node->object = NULL;
501
502 if ((object) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400503 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700504 /*
505 * There is a valid object.
506 * Decrement the reference count by one to balance the
507 * increment when the object was stored.
508 */
Len Brown4be44fc2005-08-05 00:44:28 -0400509 acpi_ut_remove_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510 }
511
512 return_VOID;
513}
514
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515/*******************************************************************************
516 *
517 * FUNCTION: acpi_ds_store_object_to_local
518 *
Bob Mooreba494be2012-07-12 09:40:10 +0800519 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800520 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800521 * index - Which Local or Arg to set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 * obj_desc - Value to be stored
523 * walk_state - Current walk state
524 *
525 * RETURN: Status
526 *
Bob Moore73a30902012-10-31 02:26:55 +0000527 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700528 * as the new value for the Arg or Local and the reference count
529 * for obj_desc is incremented.
530 *
531 ******************************************************************************/
532
533acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800534acpi_ds_store_object_to_local(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400535 u32 index,
536 union acpi_operand_object *obj_desc,
537 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538{
Len Brown4be44fc2005-08-05 00:44:28 -0400539 acpi_status status;
540 struct acpi_namespace_node *node;
541 union acpi_operand_object *current_obj_desc;
542 union acpi_operand_object *new_obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543
Bob Mooreb229cf92006-04-21 17:15:00 -0400544 ACPI_FUNCTION_TRACE(ds_store_object_to_local);
Bob Mooreb27d6592010-05-26 11:47:13 +0800545 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
Bob Moore1044f1f2008-09-27 11:08:41 +0800546 type, index, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
548 /* Parameter validation */
549
550 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400551 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552 }
553
554 /* Get the namespace node for the arg/local */
555
Bob Moore1044f1f2008-09-27 11:08:41 +0800556 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400557 if (ACPI_FAILURE(status)) {
558 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559 }
560
Len Brown4be44fc2005-08-05 00:44:28 -0400561 current_obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700562 if (current_obj_desc == obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400563 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
564 obj_desc));
565 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566 }
567
568 /*
569 * If the reference count on the object is more than one, we must
Bob Moore73a30902012-10-31 02:26:55 +0000570 * take a copy of the object before we store. A reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571 * of exactly 1 means that the object was just created during the
572 * evaluation of an expression, and we can safely use it since it
573 * is not used anywhere else.
574 */
575 new_obj_desc = obj_desc;
576 if (obj_desc->common.reference_count > 1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400577 status =
578 acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
579 walk_state);
580 if (ACPI_FAILURE(status)) {
581 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700582 }
583 }
584
585 /*
586 * If there is an object already in this slot, we either
587 * have to delete it, or if this is an argument and there
588 * is an object reference stored there, we have to do
589 * an indirect store!
590 */
591 if (current_obj_desc) {
592 /*
593 * Check for an indirect store if an argument
594 * contains an object reference (stored as an Node).
595 * We don't allow this automatic dereferencing for
596 * locals, since a store to a local should overwrite
597 * anything there, including an object reference.
598 *
599 * If both Arg0 and Local0 contain ref_of (Local4):
600 *
601 * Store (1, Arg0) - Causes indirect store to local4
602 * Store (1, Local0) - Stores 1 in local0, overwriting
603 * the reference to local4
604 * Store (1, de_refof (Local0)) - Causes indirect store to local4
605 *
606 * Weird, but true.
607 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800608 if (type == ACPI_REFCLASS_ARG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400610 * If we have a valid reference object that came from ref_of(),
611 * do the indirect store
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 */
Len Brown4be44fc2005-08-05 00:44:28 -0400613 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
Bob Moore1fad8732015-12-29 13:54:36 +0800614 ACPI_DESC_TYPE_OPERAND) &&
615 (current_obj_desc->common.type ==
616 ACPI_TYPE_LOCAL_REFERENCE) &&
617 (current_obj_desc->reference.class ==
618 ACPI_REFCLASS_REFOF)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400619 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400620 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400621 new_obj_desc,
622 current_obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623
624 /*
625 * Store this object to the Node (perform the indirect store)
626 * NOTE: No implicit conversion is performed, as per the ACPI
627 * specification rules on storing to Locals/Args.
628 */
Len Brown4be44fc2005-08-05 00:44:28 -0400629 status =
630 acpi_ex_store_object_to_node(new_obj_desc,
631 current_obj_desc->
632 reference.
633 object,
634 walk_state,
635 ACPI_NO_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636
637 /* Remove local reference if we copied the object above */
638
639 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400640 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
Bob Moore1fad8732015-12-29 13:54:36 +0800642
Len Brown4be44fc2005-08-05 00:44:28 -0400643 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645 }
646
Bob Moore1044f1f2008-09-27 11:08:41 +0800647 /* Delete the existing object before storing the new one */
648
649 acpi_ds_method_data_delete_value(type, index, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700650 }
651
652 /*
653 * Install the Obj descriptor (*new_obj_desc) into
654 * the descriptor for the Arg or Local.
655 * (increments the object reference count by one)
656 */
Len Brown4be44fc2005-08-05 00:44:28 -0400657 status =
Bob Moore1044f1f2008-09-27 11:08:41 +0800658 acpi_ds_method_data_set_value(type, index, new_obj_desc,
Len Brown4be44fc2005-08-05 00:44:28 -0400659 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700660
661 /* Remove local reference if we copied the object above */
662
663 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400664 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665 }
666
Len Brown4be44fc2005-08-05 00:44:28 -0400667 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668}
669
Robert Moore44f6c012005-04-18 22:49:35 -0400670#ifdef ACPI_OBSOLETE_FUNCTIONS
671/*******************************************************************************
672 *
673 * FUNCTION: acpi_ds_method_data_get_type
674 *
Bob Mooreba494be2012-07-12 09:40:10 +0800675 * PARAMETERS: opcode - Either AML_LOCAL_OP or AML_ARG_OP
676 * index - Which Local or Arg whose type to get
Robert Moore44f6c012005-04-18 22:49:35 -0400677 * walk_state - Current walk state object
678 *
679 * RETURN: Data type of current value of the selected Arg or Local
680 *
681 * DESCRIPTION: Get the type of the object stored in the Local or Arg
682 *
683 ******************************************************************************/
684
685acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -0400686acpi_ds_method_data_get_type(u16 opcode,
687 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400688{
Len Brown4be44fc2005-08-05 00:44:28 -0400689 acpi_status status;
690 struct acpi_namespace_node *node;
691 union acpi_operand_object *object;
Robert Moore44f6c012005-04-18 22:49:35 -0400692
Bob Mooreb229cf92006-04-21 17:15:00 -0400693 ACPI_FUNCTION_TRACE(ds_method_data_get_type);
Robert Moore44f6c012005-04-18 22:49:35 -0400694
695 /* Get the namespace node for the arg/local */
696
Len Brown4be44fc2005-08-05 00:44:28 -0400697 status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
698 if (ACPI_FAILURE(status)) {
699 return_VALUE((ACPI_TYPE_NOT_FOUND));
Robert Moore44f6c012005-04-18 22:49:35 -0400700 }
701
702 /* Get the object */
703
Len Brown4be44fc2005-08-05 00:44:28 -0400704 object = acpi_ns_get_attached_object(node);
Robert Moore44f6c012005-04-18 22:49:35 -0400705 if (!object) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400706
Robert Moore44f6c012005-04-18 22:49:35 -0400707 /* Uninitialized local/arg, return TYPE_ANY */
708
Len Brown4be44fc2005-08-05 00:44:28 -0400709 return_VALUE(ACPI_TYPE_ANY);
Robert Moore44f6c012005-04-18 22:49:35 -0400710 }
711
712 /* Get the object type */
713
Bob Moore3371c192009-02-18 14:44:03 +0800714 return_VALUE(object->type);
Robert Moore44f6c012005-04-18 22:49:35 -0400715}
716#endif