blob: eca50517ad824bd6d5ab60d01c90dc67f533e812 [file] [log] [blame]
Erik Schmauss95857632018-03-14 16:13:07 -07001// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
Linus Torvalds1da177e2005-04-16 15:20:36 -07002/*******************************************************************************
3 *
4 * Module Name: dsmthdat - control method arguments and local variables
5 *
6 ******************************************************************************/
7
Linus Torvalds1da177e2005-04-16 15:20:36 -07008#include <acpi/acpi.h>
Len Browne2f7a772009-01-09 00:30:03 -05009#include "accommon.h"
10#include "acdispat.h"
11#include "acnamesp.h"
12#include "acinterp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070013
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#define _COMPONENT ACPI_DISPATCHER
Len Brown4be44fc2005-08-05 00:44:28 -040015ACPI_MODULE_NAME("dsmthdat")
Linus Torvalds1da177e2005-04-16 15:20:36 -070016
Robert Moore44f6c012005-04-18 22:49:35 -040017/* Local prototypes */
Robert Moore44f6c012005-04-18 22:49:35 -040018static void
Bob Moore1044f1f2008-09-27 11:08:41 +080019acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -040020 u32 index, struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040021
22static acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +080023acpi_ds_method_data_set_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -040024 u32 index,
25 union acpi_operand_object *object,
26 struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040027
28#ifdef ACPI_OBSOLETE_FUNCTIONS
29acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -040030acpi_ds_method_data_get_type(u16 opcode,
31 u32 index, struct acpi_walk_state *walk_state);
Robert Moore44f6c012005-04-18 22:49:35 -040032#endif
33
Linus Torvalds1da177e2005-04-16 15:20:36 -070034/*******************************************************************************
35 *
36 * FUNCTION: acpi_ds_method_data_init
37 *
38 * PARAMETERS: walk_state - Current walk state object
39 *
40 * RETURN: Status
41 *
42 * DESCRIPTION: Initialize the data structures that hold the method's arguments
Bob Moore73a30902012-10-31 02:26:55 +000043 * and locals. The data struct is an array of namespace nodes for
Robert Moore44f6c012005-04-18 22:49:35 -040044 * each - this allows ref_of and de_ref_of to work properly for these
Linus Torvalds1da177e2005-04-16 15:20:36 -070045 * special data types.
46 *
47 * NOTES: walk_state fields are initialized to zero by the
Bob Moore83135242006-10-03 00:00:00 -040048 * ACPI_ALLOCATE_ZEROED().
Linus Torvalds1da177e2005-04-16 15:20:36 -070049 *
50 * A pseudo-Namespace Node is assigned to each argument and local
51 * so that ref_of() can return a pointer to the Node.
52 *
53 ******************************************************************************/
54
Len Brown4be44fc2005-08-05 00:44:28 -040055void acpi_ds_method_data_init(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -070056{
Len Brown4be44fc2005-08-05 00:44:28 -040057 u32 i;
Linus Torvalds1da177e2005-04-16 15:20:36 -070058
Bob Mooreb229cf92006-04-21 17:15:00 -040059 ACPI_FUNCTION_TRACE(ds_method_data_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61 /* Init the method arguments */
62
63 for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -040064 ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -070065 NAMEOF_ARG_NTE);
Bob Moore1fad8732015-12-29 13:54:36 +080066
Linus Torvalds1da177e2005-04-16 15:20:36 -070067 walk_state->arguments[i].name.integer |= (i << 24);
Bob Moore616861242006-03-17 16:44:00 -050068 walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED;
Len Brown4be44fc2005-08-05 00:44:28 -040069 walk_state->arguments[i].type = ACPI_TYPE_ANY;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +080070 walk_state->arguments[i].flags = ANOBJ_METHOD_ARG;
Linus Torvalds1da177e2005-04-16 15:20:36 -070071 }
72
73 /* Init the method locals */
74
75 for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) {
Len Brown4be44fc2005-08-05 00:44:28 -040076 ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name,
Linus Torvalds1da177e2005-04-16 15:20:36 -070077 NAMEOF_LOCAL_NTE);
78
79 walk_state->local_variables[i].name.integer |= (i << 24);
Bob Moore616861242006-03-17 16:44:00 -050080 walk_state->local_variables[i].descriptor_type =
Len Brown4be44fc2005-08-05 00:44:28 -040081 ACPI_DESC_TYPE_NAMED;
82 walk_state->local_variables[i].type = ACPI_TYPE_ANY;
Alexey Starikovskiyc45b5c02010-05-26 11:53:07 +080083 walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 }
85
86 return_VOID;
87}
88
Linus Torvalds1da177e2005-04-16 15:20:36 -070089/*******************************************************************************
90 *
91 * FUNCTION: acpi_ds_method_data_delete_all
92 *
93 * PARAMETERS: walk_state - Current walk state object
94 *
95 * RETURN: None
96 *
Bob Moore73a30902012-10-31 02:26:55 +000097 * DESCRIPTION: Delete method locals and arguments. Arguments are only
Linus Torvalds1da177e2005-04-16 15:20:36 -070098 * deleted if this method was called from another method.
99 *
100 ******************************************************************************/
101
Len Brown4be44fc2005-08-05 00:44:28 -0400102void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103{
Len Brown4be44fc2005-08-05 00:44:28 -0400104 u32 index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
Bob Mooreb229cf92006-04-21 17:15:00 -0400106 ACPI_FUNCTION_TRACE(ds_method_data_delete_all);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700107
108 /* Detach the locals */
109
110 for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) {
111 if (walk_state->local_variables[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800112 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400113 index,
114 walk_state->local_variables[index].
115 object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117 /* Detach object (if present) and remove a reference */
118
Len Brown4be44fc2005-08-05 00:44:28 -0400119 acpi_ns_detach_object(&walk_state->
120 local_variables[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122 }
123
124 /* Detach the arguments */
125
126 for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) {
127 if (walk_state->arguments[index].object) {
Bob Mooreb27d6592010-05-26 11:47:13 +0800128 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400129 index,
130 walk_state->arguments[index].object));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132 /* Detach object (if present) and remove a reference */
133
Len Brown4be44fc2005-08-05 00:44:28 -0400134 acpi_ns_detach_object(&walk_state->arguments[index]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 }
136 }
137
138 return_VOID;
139}
140
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141/*******************************************************************************
142 *
143 * FUNCTION: acpi_ds_method_data_init_args
144 *
Bob Mooreba494be2012-07-12 09:40:10 +0800145 * PARAMETERS: *params - Pointer to a parameter list for the method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 * max_param_count - The arg count for this method
147 * walk_state - Current walk state object
148 *
149 * RETURN: Status
150 *
Bob Moore73a30902012-10-31 02:26:55 +0000151 * DESCRIPTION: Initialize arguments for a method. The parameter list is a list
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152 * of ACPI operand objects, either null terminated or whose length
153 * is defined by max_param_count.
154 *
155 ******************************************************************************/
156
157acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400158acpi_ds_method_data_init_args(union acpi_operand_object **params,
159 u32 max_param_count,
160 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161{
Len Brown4be44fc2005-08-05 00:44:28 -0400162 acpi_status status;
163 u32 index = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Bob Mooreb229cf92006-04-21 17:15:00 -0400165 ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
167 if (!params) {
Len Brown4be44fc2005-08-05 00:44:28 -0400168 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Moore1fad8732015-12-29 13:54:36 +0800169 "No parameter list passed to method\n"));
Len Brown4be44fc2005-08-05 00:44:28 -0400170 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171 }
172
Robert Moore44f6c012005-04-18 22:49:35 -0400173 /* Copy passed parameters into the new method stack frame */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174
Robert Moore44f6c012005-04-18 22:49:35 -0400175 while ((index < ACPI_METHOD_NUM_ARGS) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400176 (index < max_param_count) && params[index]) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 /*
178 * A valid parameter.
179 * Store the argument in the method/walk descriptor.
180 * Do not copy the arg in order to implement call by reference
181 */
Bob Moore1fad8732015-12-29 13:54:36 +0800182 status =
183 acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index,
184 params[index], walk_state);
Len Brown4be44fc2005-08-05 00:44:28 -0400185 if (ACPI_FAILURE(status)) {
186 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188
189 index++;
190 }
191
Bob Mooreb27d6592010-05-26 11:47:13 +0800192 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index));
Len Brown4be44fc2005-08-05 00:44:28 -0400193 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196/*******************************************************************************
197 *
198 * FUNCTION: acpi_ds_method_data_get_node
199 *
Bob Mooreba494be2012-07-12 09:40:10 +0800200 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800201 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800202 * index - Which Local or Arg whose type to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 * walk_state - Current walk state object
Bob Mooreba494be2012-07-12 09:40:10 +0800204 * node - Where the node is returned.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205 *
Robert Moore44f6c012005-04-18 22:49:35 -0400206 * RETURN: Status and node
207 *
208 * DESCRIPTION: Get the Node associated with a local or arg.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209 *
210 ******************************************************************************/
211
212acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800213acpi_ds_method_data_get_node(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400214 u32 index,
215 struct acpi_walk_state *walk_state,
216 struct acpi_namespace_node **node)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217{
Bob Mooreb229cf92006-04-21 17:15:00 -0400218 ACPI_FUNCTION_TRACE(ds_method_data_get_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219
220 /*
221 * Method Locals and Arguments are supported
222 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800223 switch (type) {
224 case ACPI_REFCLASS_LOCAL:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225
226 if (index > ACPI_METHOD_MAX_LOCAL) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500227 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800228 "Local index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500229 index, ACPI_METHOD_MAX_LOCAL));
Len Brown4be44fc2005-08-05 00:44:28 -0400230 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700231 }
232
233 /* Return a pointer to the pseudo-node */
234
235 *node = &walk_state->local_variables[index];
236 break;
237
Bob Moore1044f1f2008-09-27 11:08:41 +0800238 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700239
240 if (index > ACPI_METHOD_MAX_ARG) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500241 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800242 "Arg index %u is invalid (max %u)",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500243 index, ACPI_METHOD_MAX_ARG));
Len Brown4be44fc2005-08-05 00:44:28 -0400244 return_ACPI_STATUS(AE_AML_INVALID_INDEX);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 }
246
247 /* Return a pointer to the pseudo-node */
248
249 *node = &walk_state->arguments[index];
250 break;
251
252 default:
Chao Guan1d1ea1b72013-06-08 00:58:14 +0000253
Bob Mooref6a22b02010-03-05 17:56:40 +0800254 ACPI_ERROR((AE_INFO, "Type %u is invalid", type));
Bob Moore1044f1f2008-09-27 11:08:41 +0800255 return_ACPI_STATUS(AE_TYPE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 }
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259}
260
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261/*******************************************************************************
262 *
263 * FUNCTION: acpi_ds_method_data_set_value
264 *
Bob Mooreba494be2012-07-12 09:40:10 +0800265 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800266 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800267 * index - Which Local or Arg to get
268 * object - Object to be inserted into the stack entry
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269 * walk_state - Current walk state object
270 *
271 * RETURN: Status
272 *
273 * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index.
274 * Note: There is no "implicit conversion" for locals.
275 *
276 ******************************************************************************/
277
Robert Moore44f6c012005-04-18 22:49:35 -0400278static acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800279acpi_ds_method_data_set_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400280 u32 index,
281 union acpi_operand_object *object,
282 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283{
Len Brown4be44fc2005-08-05 00:44:28 -0400284 acpi_status status;
285 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286
Bob Mooreb229cf92006-04-21 17:15:00 -0400287 ACPI_FUNCTION_TRACE(ds_method_data_set_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288
Len Brown4be44fc2005-08-05 00:44:28 -0400289 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb27d6592010-05-26 11:47:13 +0800290 "NewObj %p Type %2.2X, Refs=%u [%s]\n", object,
Bob Moore1044f1f2008-09-27 11:08:41 +0800291 type, object->common.reference_count,
Len Brown4be44fc2005-08-05 00:44:28 -0400292 acpi_ut_get_type_name(object->common.type)));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293
294 /* Get the namespace node for the arg/local */
295
Bob Moore1044f1f2008-09-27 11:08:41 +0800296 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400297 if (ACPI_FAILURE(status)) {
298 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700299 }
300
301 /*
302 * Increment ref count so object can't be deleted while installed.
303 * NOTE: We do not copy the object in order to preserve the call by
304 * reference semantics of ACPI Control Method invocation.
Bob Mooreba494be2012-07-12 09:40:10 +0800305 * (See ACPI Specification 2.0C)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
Len Brown4be44fc2005-08-05 00:44:28 -0400307 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
309 /* Install the object */
310
311 node->object = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400312 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313}
314
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315/*******************************************************************************
316 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 * FUNCTION: acpi_ds_method_data_get_value
318 *
Bob Mooreba494be2012-07-12 09:40:10 +0800319 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800320 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800321 * index - Which localVar or argument to get
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 * walk_state - Current walk state object
Robert Moore44f6c012005-04-18 22:49:35 -0400323 * dest_desc - Where Arg or Local value is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 *
325 * RETURN: Status
326 *
Robert Moore44f6c012005-04-18 22:49:35 -0400327 * DESCRIPTION: Retrieve value of selected Arg or Local for this method
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 * Used only in acpi_ex_resolve_to_value().
329 *
330 ******************************************************************************/
331
332acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800333acpi_ds_method_data_get_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400334 u32 index,
335 struct acpi_walk_state *walk_state,
336 union acpi_operand_object **dest_desc)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337{
Len Brown4be44fc2005-08-05 00:44:28 -0400338 acpi_status status;
339 struct acpi_namespace_node *node;
340 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
Bob Mooreb229cf92006-04-21 17:15:00 -0400342 ACPI_FUNCTION_TRACE(ds_method_data_get_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700343
344 /* Validate the object descriptor */
345
346 if (!dest_desc) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500347 ACPI_ERROR((AE_INFO, "Null object descriptor pointer"));
Len Brown4be44fc2005-08-05 00:44:28 -0400348 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 }
350
351 /* Get the namespace node for the arg/local */
352
Bob Moore1044f1f2008-09-27 11:08:41 +0800353 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400354 if (ACPI_FAILURE(status)) {
355 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357
358 /* Get the object from the node */
359
360 object = node->object;
361
362 /* Examine the returned object, it must be valid. */
363
364 if (!object) {
365 /*
366 * Index points to uninitialized object.
367 * This means that either 1) The expected argument was
368 * not passed to the method, or 2) A local variable
369 * was referenced by the method (via the ASL)
Bob Moore73a30902012-10-31 02:26:55 +0000370 * before it was initialized. Either case is an error.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700371 */
372
373 /* If slack enabled, init the local_x/arg_x to an Integer of value zero */
374
375 if (acpi_gbl_enable_interpreter_slack) {
Bob Mooredc95a272009-11-12 09:52:45 +0800376 object = acpi_ut_create_integer_object((u64) 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 if (!object) {
Len Brown4be44fc2005-08-05 00:44:28 -0400378 return_ACPI_STATUS(AE_NO_MEMORY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 }
380
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381 node->object = object;
382 }
383
384 /* Otherwise, return the error */
385
Len Brown4be44fc2005-08-05 00:44:28 -0400386 else
Bob Moore1044f1f2008-09-27 11:08:41 +0800387 switch (type) {
388 case ACPI_REFCLASS_ARG:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700389
Bob Mooreb8e4d892006-01-27 16:43:00 -0500390 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800391 "Uninitialized Arg[%u] at node %p",
Bob Mooreb8e4d892006-01-27 16:43:00 -0500392 index, node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393
Len Brown4be44fc2005-08-05 00:44:28 -0400394 return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395
Bob Moore1044f1f2008-09-27 11:08:41 +0800396 case ACPI_REFCLASS_LOCAL:
Bob Mooree6789022009-09-03 09:58:14 +0800397 /*
398 * No error message for this case, will be trapped again later to
399 * detect and ignore cases of Store(local_x,local_x)
400 */
Len Brown4be44fc2005-08-05 00:44:28 -0400401 return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Len Brown4be44fc2005-08-05 00:44:28 -0400403 default:
Bob Moore1044f1f2008-09-27 11:08:41 +0800404
Bob Mooreb8e4d892006-01-27 16:43:00 -0500405 ACPI_ERROR((AE_INFO,
Bob Mooref6a22b02010-03-05 17:56:40 +0800406 "Not a Arg/Local opcode: 0x%X",
Bob Moore1044f1f2008-09-27 11:08:41 +0800407 type));
Len Brown4be44fc2005-08-05 00:44:28 -0400408 return_ACPI_STATUS(AE_AML_INTERNAL);
409 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700410 }
411
412 /*
413 * The Index points to an initialized and valid object.
414 * Return an additional reference to the object
415 */
416 *dest_desc = object;
Len Brown4be44fc2005-08-05 00:44:28 -0400417 acpi_ut_add_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700418
Len Brown4be44fc2005-08-05 00:44:28 -0400419 return_ACPI_STATUS(AE_OK);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420}
421
Linus Torvalds1da177e2005-04-16 15:20:36 -0700422/*******************************************************************************
423 *
424 * FUNCTION: acpi_ds_method_data_delete_value
425 *
Bob Mooreba494be2012-07-12 09:40:10 +0800426 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800427 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800428 * index - Which localVar or argument to delete
Linus Torvalds1da177e2005-04-16 15:20:36 -0700429 * walk_state - Current walk state object
430 *
431 * RETURN: None
432 *
Bob Moore73a30902012-10-31 02:26:55 +0000433 * DESCRIPTION: Delete the entry at Opcode:Index. Inserts
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434 * a null into the stack slot after the object is deleted.
435 *
436 ******************************************************************************/
437
Robert Moore44f6c012005-04-18 22:49:35 -0400438static void
Bob Moore1044f1f2008-09-27 11:08:41 +0800439acpi_ds_method_data_delete_value(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400440 u32 index, struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700441{
Len Brown4be44fc2005-08-05 00:44:28 -0400442 acpi_status status;
443 struct acpi_namespace_node *node;
444 union acpi_operand_object *object;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700445
Bob Mooreb229cf92006-04-21 17:15:00 -0400446 ACPI_FUNCTION_TRACE(ds_method_data_delete_value);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700447
448 /* Get the namespace node for the arg/local */
449
Bob Moore1044f1f2008-09-27 11:08:41 +0800450 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400451 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 return_VOID;
453 }
454
455 /* Get the associated object */
456
Len Brown4be44fc2005-08-05 00:44:28 -0400457 object = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458
459 /*
460 * Undefine the Arg or Local by setting its descriptor
461 * pointer to NULL. Locals/Args can contain both
462 * ACPI_OPERAND_OBJECTS and ACPI_NAMESPACE_NODEs
463 */
464 node->object = NULL;
465
466 if ((object) &&
Len Brown4be44fc2005-08-05 00:44:28 -0400467 (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700468 /*
469 * There is a valid object.
470 * Decrement the reference count by one to balance the
471 * increment when the object was stored.
472 */
Len Brown4be44fc2005-08-05 00:44:28 -0400473 acpi_ut_remove_reference(object);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475
476 return_VOID;
477}
478
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479/*******************************************************************************
480 *
481 * FUNCTION: acpi_ds_store_object_to_local
482 *
Bob Mooreba494be2012-07-12 09:40:10 +0800483 * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or
Bob Moore1044f1f2008-09-27 11:08:41 +0800484 * ACPI_REFCLASS_ARG
Bob Mooreba494be2012-07-12 09:40:10 +0800485 * index - Which Local or Arg to set
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486 * obj_desc - Value to be stored
487 * walk_state - Current walk state
488 *
489 * RETURN: Status
490 *
Bob Moore73a30902012-10-31 02:26:55 +0000491 * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492 * as the new value for the Arg or Local and the reference count
493 * for obj_desc is incremented.
494 *
495 ******************************************************************************/
496
497acpi_status
Bob Moore1044f1f2008-09-27 11:08:41 +0800498acpi_ds_store_object_to_local(u8 type,
Len Brown4be44fc2005-08-05 00:44:28 -0400499 u32 index,
500 union acpi_operand_object *obj_desc,
501 struct acpi_walk_state *walk_state)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700502{
Len Brown4be44fc2005-08-05 00:44:28 -0400503 acpi_status status;
504 struct acpi_namespace_node *node;
505 union acpi_operand_object *current_obj_desc;
506 union acpi_operand_object *new_obj_desc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Bob Mooreb229cf92006-04-21 17:15:00 -0400508 ACPI_FUNCTION_TRACE(ds_store_object_to_local);
Bob Mooreb27d6592010-05-26 11:47:13 +0800509 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n",
Bob Moore1044f1f2008-09-27 11:08:41 +0800510 type, index, obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511
512 /* Parameter validation */
513
514 if (!obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400515 return_ACPI_STATUS(AE_BAD_PARAMETER);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516 }
517
518 /* Get the namespace node for the arg/local */
519
Bob Moore1044f1f2008-09-27 11:08:41 +0800520 status = acpi_ds_method_data_get_node(type, index, walk_state, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400521 if (ACPI_FAILURE(status)) {
522 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700523 }
524
Len Brown4be44fc2005-08-05 00:44:28 -0400525 current_obj_desc = acpi_ns_get_attached_object(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 if (current_obj_desc == obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400527 ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n",
528 obj_desc));
529 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 }
531
532 /*
533 * If the reference count on the object is more than one, we must
Bob Moore73a30902012-10-31 02:26:55 +0000534 * take a copy of the object before we store. A reference count
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 * of exactly 1 means that the object was just created during the
536 * evaluation of an expression, and we can safely use it since it
537 * is not used anywhere else.
538 */
539 new_obj_desc = obj_desc;
540 if (obj_desc->common.reference_count > 1) {
Len Brown4be44fc2005-08-05 00:44:28 -0400541 status =
542 acpi_ut_copy_iobject_to_iobject(obj_desc, &new_obj_desc,
543 walk_state);
544 if (ACPI_FAILURE(status)) {
545 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 }
547 }
548
549 /*
550 * If there is an object already in this slot, we either
551 * have to delete it, or if this is an argument and there
552 * is an object reference stored there, we have to do
553 * an indirect store!
554 */
555 if (current_obj_desc) {
556 /*
557 * Check for an indirect store if an argument
558 * contains an object reference (stored as an Node).
559 * We don't allow this automatic dereferencing for
560 * locals, since a store to a local should overwrite
561 * anything there, including an object reference.
562 *
563 * If both Arg0 and Local0 contain ref_of (Local4):
564 *
565 * Store (1, Arg0) - Causes indirect store to local4
566 * Store (1, Local0) - Stores 1 in local0, overwriting
567 * the reference to local4
568 * Store (1, de_refof (Local0)) - Causes indirect store to local4
569 *
570 * Weird, but true.
571 */
Bob Moore1044f1f2008-09-27 11:08:41 +0800572 if (type == ACPI_REFCLASS_ARG) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700573 /*
Robert Moore44f6c012005-04-18 22:49:35 -0400574 * If we have a valid reference object that came from ref_of(),
575 * do the indirect store
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 */
Len Brown4be44fc2005-08-05 00:44:28 -0400577 if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) ==
Bob Moore1fad8732015-12-29 13:54:36 +0800578 ACPI_DESC_TYPE_OPERAND) &&
579 (current_obj_desc->common.type ==
580 ACPI_TYPE_LOCAL_REFERENCE) &&
581 (current_obj_desc->reference.class ==
582 ACPI_REFCLASS_REFOF)) {
Len Brown4be44fc2005-08-05 00:44:28 -0400583 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
Bob Mooreb229cf92006-04-21 17:15:00 -0400584 "Arg (%p) is an ObjRef(Node), storing in node %p\n",
Len Brown4be44fc2005-08-05 00:44:28 -0400585 new_obj_desc,
586 current_obj_desc));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
588 /*
589 * Store this object to the Node (perform the indirect store)
590 * NOTE: No implicit conversion is performed, as per the ACPI
591 * specification rules on storing to Locals/Args.
592 */
Len Brown4be44fc2005-08-05 00:44:28 -0400593 status =
594 acpi_ex_store_object_to_node(new_obj_desc,
595 current_obj_desc->
596 reference.
597 object,
598 walk_state,
599 ACPI_NO_IMPLICIT_CONVERSION);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600
601 /* Remove local reference if we copied the object above */
602
603 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400604 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 }
Bob Moore1fad8732015-12-29 13:54:36 +0800606
Len Brown4be44fc2005-08-05 00:44:28 -0400607 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 }
609 }
610
Bob Moore1044f1f2008-09-27 11:08:41 +0800611 /* Delete the existing object before storing the new one */
612
613 acpi_ds_method_data_delete_value(type, index, walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 }
615
616 /*
617 * Install the Obj descriptor (*new_obj_desc) into
618 * the descriptor for the Arg or Local.
619 * (increments the object reference count by one)
620 */
Len Brown4be44fc2005-08-05 00:44:28 -0400621 status =
Bob Moore1044f1f2008-09-27 11:08:41 +0800622 acpi_ds_method_data_set_value(type, index, new_obj_desc,
Len Brown4be44fc2005-08-05 00:44:28 -0400623 walk_state);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625 /* Remove local reference if we copied the object above */
626
627 if (new_obj_desc != obj_desc) {
Len Brown4be44fc2005-08-05 00:44:28 -0400628 acpi_ut_remove_reference(new_obj_desc);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 }
630
Len Brown4be44fc2005-08-05 00:44:28 -0400631 return_ACPI_STATUS(status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632}
633
Robert Moore44f6c012005-04-18 22:49:35 -0400634#ifdef ACPI_OBSOLETE_FUNCTIONS
635/*******************************************************************************
636 *
637 * FUNCTION: acpi_ds_method_data_get_type
638 *
Bob Moore9ff5a21a2017-04-26 16:18:40 +0800639 * PARAMETERS: opcode - Either AML_FIRST LOCAL_OP or
640 * AML_FIRST_ARG_OP
Bob Mooreba494be2012-07-12 09:40:10 +0800641 * index - Which Local or Arg whose type to get
Robert Moore44f6c012005-04-18 22:49:35 -0400642 * walk_state - Current walk state object
643 *
644 * RETURN: Data type of current value of the selected Arg or Local
645 *
646 * DESCRIPTION: Get the type of the object stored in the Local or Arg
647 *
648 ******************************************************************************/
649
650acpi_object_type
Len Brown4be44fc2005-08-05 00:44:28 -0400651acpi_ds_method_data_get_type(u16 opcode,
652 u32 index, struct acpi_walk_state *walk_state)
Robert Moore44f6c012005-04-18 22:49:35 -0400653{
Len Brown4be44fc2005-08-05 00:44:28 -0400654 acpi_status status;
655 struct acpi_namespace_node *node;
656 union acpi_operand_object *object;
Robert Moore44f6c012005-04-18 22:49:35 -0400657
Bob Mooreb229cf92006-04-21 17:15:00 -0400658 ACPI_FUNCTION_TRACE(ds_method_data_get_type);
Robert Moore44f6c012005-04-18 22:49:35 -0400659
660 /* Get the namespace node for the arg/local */
661
Len Brown4be44fc2005-08-05 00:44:28 -0400662 status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node);
663 if (ACPI_FAILURE(status)) {
664 return_VALUE((ACPI_TYPE_NOT_FOUND));
Robert Moore44f6c012005-04-18 22:49:35 -0400665 }
666
667 /* Get the object */
668
Len Brown4be44fc2005-08-05 00:44:28 -0400669 object = acpi_ns_get_attached_object(node);
Robert Moore44f6c012005-04-18 22:49:35 -0400670 if (!object) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400671
Robert Moore44f6c012005-04-18 22:49:35 -0400672 /* Uninitialized local/arg, return TYPE_ANY */
673
Len Brown4be44fc2005-08-05 00:44:28 -0400674 return_VALUE(ACPI_TYPE_ANY);
Robert Moore44f6c012005-04-18 22:49:35 -0400675 }
676
677 /* Get the object type */
678
Bob Moore3371c192009-02-18 14:44:03 +0800679 return_VALUE(object->type);
Robert Moore44f6c012005-04-18 22:49:35 -0400680}
681#endif