]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: dsmthdat - control method arguments and local variables | |
4 | * | |
5 | ******************************************************************************/ | |
6 | ||
7 | /* | |
c8100dc4 | 8 | * Copyright (C) 2000 - 2016, Intel Corp. |
1da177e4 LT |
9 | * 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 | ||
1da177e4 | 44 | #include <acpi/acpi.h> |
e2f7a777 LB |
45 | #include "accommon.h" |
46 | #include "acdispat.h" | |
47 | #include "acnamesp.h" | |
48 | #include "acinterp.h" | |
1da177e4 | 49 | |
1da177e4 | 50 | #define _COMPONENT ACPI_DISPATCHER |
4be44fcd | 51 | ACPI_MODULE_NAME("dsmthdat") |
1da177e4 | 52 | |
44f6c012 | 53 | /* Local prototypes */ |
44f6c012 | 54 | static void |
1044f1f6 | 55 | acpi_ds_method_data_delete_value(u8 type, |
4be44fcd | 56 | u32 index, struct acpi_walk_state *walk_state); |
44f6c012 RM |
57 | |
58 | static acpi_status | |
1044f1f6 | 59 | acpi_ds_method_data_set_value(u8 type, |
4be44fcd LB |
60 | u32 index, |
61 | union acpi_operand_object *object, | |
62 | struct acpi_walk_state *walk_state); | |
44f6c012 RM |
63 | |
64 | #ifdef ACPI_OBSOLETE_FUNCTIONS | |
65 | acpi_object_type | |
4be44fcd LB |
66 | acpi_ds_method_data_get_type(u16 opcode, |
67 | u32 index, struct acpi_walk_state *walk_state); | |
44f6c012 RM |
68 | #endif |
69 | ||
1da177e4 LT |
70 | /******************************************************************************* |
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 | |
73a3090a | 79 | * and locals. The data struct is an array of namespace nodes for |
44f6c012 | 80 | * each - this allows ref_of and de_ref_of to work properly for these |
1da177e4 LT |
81 | * special data types. |
82 | * | |
83 | * NOTES: walk_state fields are initialized to zero by the | |
8313524a | 84 | * ACPI_ALLOCATE_ZEROED(). |
1da177e4 LT |
85 | * |
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 | ||
4be44fcd | 91 | void acpi_ds_method_data_init(struct acpi_walk_state *walk_state) |
1da177e4 | 92 | { |
4be44fcd | 93 | u32 i; |
1da177e4 | 94 | |
b229cf92 | 95 | ACPI_FUNCTION_TRACE(ds_method_data_init); |
1da177e4 LT |
96 | |
97 | /* Init the method arguments */ | |
98 | ||
99 | for (i = 0; i < ACPI_METHOD_NUM_ARGS; i++) { | |
4be44fcd | 100 | ACPI_MOVE_32_TO_32(&walk_state->arguments[i].name, |
1da177e4 | 101 | NAMEOF_ARG_NTE); |
1fad8738 | 102 | |
1da177e4 | 103 | walk_state->arguments[i].name.integer |= (i << 24); |
61686124 | 104 | walk_state->arguments[i].descriptor_type = ACPI_DESC_TYPE_NAMED; |
4be44fcd | 105 | walk_state->arguments[i].type = ACPI_TYPE_ANY; |
c45b5c09 | 106 | walk_state->arguments[i].flags = ANOBJ_METHOD_ARG; |
1da177e4 LT |
107 | } |
108 | ||
109 | /* Init the method locals */ | |
110 | ||
111 | for (i = 0; i < ACPI_METHOD_NUM_LOCALS; i++) { | |
4be44fcd | 112 | ACPI_MOVE_32_TO_32(&walk_state->local_variables[i].name, |
1da177e4 LT |
113 | NAMEOF_LOCAL_NTE); |
114 | ||
115 | walk_state->local_variables[i].name.integer |= (i << 24); | |
61686124 | 116 | walk_state->local_variables[i].descriptor_type = |
4be44fcd LB |
117 | ACPI_DESC_TYPE_NAMED; |
118 | walk_state->local_variables[i].type = ACPI_TYPE_ANY; | |
c45b5c09 | 119 | walk_state->local_variables[i].flags = ANOBJ_METHOD_LOCAL; |
1da177e4 LT |
120 | } |
121 | ||
122 | return_VOID; | |
123 | } | |
124 | ||
1da177e4 LT |
125 | /******************************************************************************* |
126 | * | |
127 | * FUNCTION: acpi_ds_method_data_delete_all | |
128 | * | |
129 | * PARAMETERS: walk_state - Current walk state object | |
130 | * | |
131 | * RETURN: None | |
132 | * | |
73a3090a | 133 | * DESCRIPTION: Delete method locals and arguments. Arguments are only |
1da177e4 LT |
134 | * deleted if this method was called from another method. |
135 | * | |
136 | ******************************************************************************/ | |
137 | ||
4be44fcd | 138 | void acpi_ds_method_data_delete_all(struct acpi_walk_state *walk_state) |
1da177e4 | 139 | { |
4be44fcd | 140 | u32 index; |
1da177e4 | 141 | |
b229cf92 | 142 | ACPI_FUNCTION_TRACE(ds_method_data_delete_all); |
1da177e4 LT |
143 | |
144 | /* Detach the locals */ | |
145 | ||
146 | for (index = 0; index < ACPI_METHOD_NUM_LOCALS; index++) { | |
147 | if (walk_state->local_variables[index].object) { | |
b27d6597 | 148 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Local%u=%p\n", |
4be44fcd LB |
149 | index, |
150 | walk_state->local_variables[index]. | |
151 | object)); | |
1da177e4 LT |
152 | |
153 | /* Detach object (if present) and remove a reference */ | |
154 | ||
4be44fcd LB |
155 | acpi_ns_detach_object(&walk_state-> |
156 | local_variables[index]); | |
1da177e4 LT |
157 | } |
158 | } | |
159 | ||
160 | /* Detach the arguments */ | |
161 | ||
162 | for (index = 0; index < ACPI_METHOD_NUM_ARGS; index++) { | |
163 | if (walk_state->arguments[index].object) { | |
b27d6597 | 164 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Deleting Arg%u=%p\n", |
4be44fcd LB |
165 | index, |
166 | walk_state->arguments[index].object)); | |
1da177e4 LT |
167 | |
168 | /* Detach object (if present) and remove a reference */ | |
169 | ||
4be44fcd | 170 | acpi_ns_detach_object(&walk_state->arguments[index]); |
1da177e4 LT |
171 | } |
172 | } | |
173 | ||
174 | return_VOID; | |
175 | } | |
176 | ||
1da177e4 LT |
177 | /******************************************************************************* |
178 | * | |
179 | * FUNCTION: acpi_ds_method_data_init_args | |
180 | * | |
ba494bee | 181 | * PARAMETERS: *params - Pointer to a parameter list for the method |
1da177e4 LT |
182 | * max_param_count - The arg count for this method |
183 | * walk_state - Current walk state object | |
184 | * | |
185 | * RETURN: Status | |
186 | * | |
73a3090a | 187 | * DESCRIPTION: Initialize arguments for a method. The parameter list is a list |
1da177e4 LT |
188 | * of ACPI operand objects, either null terminated or whose length |
189 | * is defined by max_param_count. | |
190 | * | |
191 | ******************************************************************************/ | |
192 | ||
193 | acpi_status | |
4be44fcd LB |
194 | acpi_ds_method_data_init_args(union acpi_operand_object **params, |
195 | u32 max_param_count, | |
196 | struct acpi_walk_state *walk_state) | |
1da177e4 | 197 | { |
4be44fcd LB |
198 | acpi_status status; |
199 | u32 index = 0; | |
1da177e4 | 200 | |
b229cf92 | 201 | ACPI_FUNCTION_TRACE_PTR(ds_method_data_init_args, params); |
1da177e4 LT |
202 | |
203 | if (!params) { | |
4be44fcd | 204 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
1fad8738 | 205 | "No parameter list passed to method\n")); |
4be44fcd | 206 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
207 | } |
208 | ||
44f6c012 | 209 | /* Copy passed parameters into the new method stack frame */ |
1da177e4 | 210 | |
44f6c012 | 211 | while ((index < ACPI_METHOD_NUM_ARGS) && |
4be44fcd | 212 | (index < max_param_count) && params[index]) { |
1da177e4 LT |
213 | /* |
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 | */ | |
1fad8738 BM |
218 | status = |
219 | acpi_ds_method_data_set_value(ACPI_REFCLASS_ARG, index, | |
220 | params[index], walk_state); | |
4be44fcd LB |
221 | if (ACPI_FAILURE(status)) { |
222 | return_ACPI_STATUS(status); | |
1da177e4 LT |
223 | } |
224 | ||
225 | index++; | |
226 | } | |
227 | ||
b27d6597 | 228 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "%u args passed to method\n", index)); |
4be44fcd | 229 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
230 | } |
231 | ||
1da177e4 LT |
232 | /******************************************************************************* |
233 | * | |
234 | * FUNCTION: acpi_ds_method_data_get_node | |
235 | * | |
ba494bee | 236 | * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or |
1044f1f6 | 237 | * ACPI_REFCLASS_ARG |
ba494bee | 238 | * index - Which Local or Arg whose type to get |
1da177e4 | 239 | * walk_state - Current walk state object |
ba494bee | 240 | * node - Where the node is returned. |
1da177e4 | 241 | * |
44f6c012 RM |
242 | * RETURN: Status and node |
243 | * | |
244 | * DESCRIPTION: Get the Node associated with a local or arg. | |
1da177e4 LT |
245 | * |
246 | ******************************************************************************/ | |
247 | ||
248 | acpi_status | |
1044f1f6 | 249 | acpi_ds_method_data_get_node(u8 type, |
4be44fcd LB |
250 | u32 index, |
251 | struct acpi_walk_state *walk_state, | |
252 | struct acpi_namespace_node **node) | |
1da177e4 | 253 | { |
b229cf92 | 254 | ACPI_FUNCTION_TRACE(ds_method_data_get_node); |
1da177e4 LT |
255 | |
256 | /* | |
257 | * Method Locals and Arguments are supported | |
258 | */ | |
1044f1f6 BM |
259 | switch (type) { |
260 | case ACPI_REFCLASS_LOCAL: | |
1da177e4 LT |
261 | |
262 | if (index > ACPI_METHOD_MAX_LOCAL) { | |
b8e4d893 | 263 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 264 | "Local index %u is invalid (max %u)", |
b8e4d893 | 265 | index, ACPI_METHOD_MAX_LOCAL)); |
4be44fcd | 266 | return_ACPI_STATUS(AE_AML_INVALID_INDEX); |
1da177e4 LT |
267 | } |
268 | ||
269 | /* Return a pointer to the pseudo-node */ | |
270 | ||
271 | *node = &walk_state->local_variables[index]; | |
272 | break; | |
273 | ||
1044f1f6 | 274 | case ACPI_REFCLASS_ARG: |
1da177e4 LT |
275 | |
276 | if (index > ACPI_METHOD_MAX_ARG) { | |
b8e4d893 | 277 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 278 | "Arg index %u is invalid (max %u)", |
b8e4d893 | 279 | index, ACPI_METHOD_MAX_ARG)); |
4be44fcd | 280 | return_ACPI_STATUS(AE_AML_INVALID_INDEX); |
1da177e4 LT |
281 | } |
282 | ||
283 | /* Return a pointer to the pseudo-node */ | |
284 | ||
285 | *node = &walk_state->arguments[index]; | |
286 | break; | |
287 | ||
288 | default: | |
1d1ea1b7 | 289 | |
f6a22b0b | 290 | ACPI_ERROR((AE_INFO, "Type %u is invalid", type)); |
1044f1f6 | 291 | return_ACPI_STATUS(AE_TYPE); |
1da177e4 LT |
292 | } |
293 | ||
4be44fcd | 294 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
295 | } |
296 | ||
1da177e4 LT |
297 | /******************************************************************************* |
298 | * | |
299 | * FUNCTION: acpi_ds_method_data_set_value | |
300 | * | |
ba494bee | 301 | * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or |
1044f1f6 | 302 | * ACPI_REFCLASS_ARG |
ba494bee BM |
303 | * index - Which Local or Arg to get |
304 | * object - Object to be inserted into the stack entry | |
1da177e4 LT |
305 | * walk_state - Current walk state object |
306 | * | |
307 | * RETURN: Status | |
308 | * | |
309 | * DESCRIPTION: Insert an object onto the method stack at entry Opcode:Index. | |
310 | * Note: There is no "implicit conversion" for locals. | |
311 | * | |
312 | ******************************************************************************/ | |
313 | ||
44f6c012 | 314 | static acpi_status |
1044f1f6 | 315 | acpi_ds_method_data_set_value(u8 type, |
4be44fcd LB |
316 | u32 index, |
317 | union acpi_operand_object *object, | |
318 | struct acpi_walk_state *walk_state) | |
1da177e4 | 319 | { |
4be44fcd LB |
320 | acpi_status status; |
321 | struct acpi_namespace_node *node; | |
1da177e4 | 322 | |
b229cf92 | 323 | ACPI_FUNCTION_TRACE(ds_method_data_set_value); |
1da177e4 | 324 | |
4be44fcd | 325 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
b27d6597 | 326 | "NewObj %p Type %2.2X, Refs=%u [%s]\n", object, |
1044f1f6 | 327 | type, object->common.reference_count, |
4be44fcd | 328 | acpi_ut_get_type_name(object->common.type))); |
1da177e4 LT |
329 | |
330 | /* Get the namespace node for the arg/local */ | |
331 | ||
1044f1f6 | 332 | status = acpi_ds_method_data_get_node(type, index, walk_state, &node); |
4be44fcd LB |
333 | if (ACPI_FAILURE(status)) { |
334 | return_ACPI_STATUS(status); | |
1da177e4 LT |
335 | } |
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. | |
ba494bee | 341 | * (See ACPI Specification 2.0C) |
1da177e4 | 342 | */ |
4be44fcd | 343 | acpi_ut_add_reference(object); |
1da177e4 LT |
344 | |
345 | /* Install the object */ | |
346 | ||
347 | node->object = object; | |
4be44fcd | 348 | return_ACPI_STATUS(status); |
1da177e4 LT |
349 | } |
350 | ||
1da177e4 LT |
351 | /******************************************************************************* |
352 | * | |
353 | * FUNCTION: acpi_ds_method_data_get_value | |
354 | * | |
ba494bee | 355 | * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or |
1044f1f6 | 356 | * ACPI_REFCLASS_ARG |
ba494bee | 357 | * index - Which localVar or argument to get |
1da177e4 | 358 | * walk_state - Current walk state object |
44f6c012 | 359 | * dest_desc - Where Arg or Local value is returned |
1da177e4 LT |
360 | * |
361 | * RETURN: Status | |
362 | * | |
44f6c012 | 363 | * DESCRIPTION: Retrieve value of selected Arg or Local for this method |
1da177e4 LT |
364 | * Used only in acpi_ex_resolve_to_value(). |
365 | * | |
366 | ******************************************************************************/ | |
367 | ||
368 | acpi_status | |
1044f1f6 | 369 | acpi_ds_method_data_get_value(u8 type, |
4be44fcd LB |
370 | u32 index, |
371 | struct acpi_walk_state *walk_state, | |
372 | union acpi_operand_object **dest_desc) | |
1da177e4 | 373 | { |
4be44fcd LB |
374 | acpi_status status; |
375 | struct acpi_namespace_node *node; | |
376 | union acpi_operand_object *object; | |
1da177e4 | 377 | |
b229cf92 | 378 | ACPI_FUNCTION_TRACE(ds_method_data_get_value); |
1da177e4 LT |
379 | |
380 | /* Validate the object descriptor */ | |
381 | ||
382 | if (!dest_desc) { | |
b8e4d893 | 383 | ACPI_ERROR((AE_INFO, "Null object descriptor pointer")); |
4be44fcd | 384 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
385 | } |
386 | ||
387 | /* Get the namespace node for the arg/local */ | |
388 | ||
1044f1f6 | 389 | status = acpi_ds_method_data_get_node(type, index, walk_state, &node); |
4be44fcd LB |
390 | if (ACPI_FAILURE(status)) { |
391 | return_ACPI_STATUS(status); | |
1da177e4 LT |
392 | } |
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) | |
73a3090a | 406 | * before it was initialized. Either case is an error. |
1da177e4 LT |
407 | */ |
408 | ||
409 | /* If slack enabled, init the local_x/arg_x to an Integer of value zero */ | |
410 | ||
411 | if (acpi_gbl_enable_interpreter_slack) { | |
dc95a270 | 412 | object = acpi_ut_create_integer_object((u64) 0); |
1da177e4 | 413 | if (!object) { |
4be44fcd | 414 | return_ACPI_STATUS(AE_NO_MEMORY); |
1da177e4 LT |
415 | } |
416 | ||
1da177e4 LT |
417 | node->object = object; |
418 | } | |
419 | ||
420 | /* Otherwise, return the error */ | |
421 | ||
4be44fcd | 422 | else |
1044f1f6 BM |
423 | switch (type) { |
424 | case ACPI_REFCLASS_ARG: | |
1da177e4 | 425 | |
b8e4d893 | 426 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 427 | "Uninitialized Arg[%u] at node %p", |
b8e4d893 | 428 | index, node)); |
1da177e4 | 429 | |
4be44fcd | 430 | return_ACPI_STATUS(AE_AML_UNINITIALIZED_ARG); |
1da177e4 | 431 | |
1044f1f6 | 432 | case ACPI_REFCLASS_LOCAL: |
e678902e BM |
433 | /* |
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 | */ | |
4be44fcd | 437 | return_ACPI_STATUS(AE_AML_UNINITIALIZED_LOCAL); |
1da177e4 | 438 | |
4be44fcd | 439 | default: |
1044f1f6 | 440 | |
b8e4d893 | 441 | ACPI_ERROR((AE_INFO, |
f6a22b0b | 442 | "Not a Arg/Local opcode: 0x%X", |
1044f1f6 | 443 | type)); |
4be44fcd LB |
444 | return_ACPI_STATUS(AE_AML_INTERNAL); |
445 | } | |
1da177e4 LT |
446 | } |
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; | |
4be44fcd | 453 | acpi_ut_add_reference(object); |
1da177e4 | 454 | |
4be44fcd | 455 | return_ACPI_STATUS(AE_OK); |
1da177e4 LT |
456 | } |
457 | ||
1da177e4 LT |
458 | /******************************************************************************* |
459 | * | |
460 | * FUNCTION: acpi_ds_method_data_delete_value | |
461 | * | |
ba494bee | 462 | * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or |
1044f1f6 | 463 | * ACPI_REFCLASS_ARG |
ba494bee | 464 | * index - Which localVar or argument to delete |
1da177e4 LT |
465 | * walk_state - Current walk state object |
466 | * | |
467 | * RETURN: None | |
468 | * | |
73a3090a | 469 | * DESCRIPTION: Delete the entry at Opcode:Index. Inserts |
1da177e4 LT |
470 | * a null into the stack slot after the object is deleted. |
471 | * | |
472 | ******************************************************************************/ | |
473 | ||
44f6c012 | 474 | static void |
1044f1f6 | 475 | acpi_ds_method_data_delete_value(u8 type, |
4be44fcd | 476 | u32 index, struct acpi_walk_state *walk_state) |
1da177e4 | 477 | { |
4be44fcd LB |
478 | acpi_status status; |
479 | struct acpi_namespace_node *node; | |
480 | union acpi_operand_object *object; | |
1da177e4 | 481 | |
b229cf92 | 482 | ACPI_FUNCTION_TRACE(ds_method_data_delete_value); |
1da177e4 LT |
483 | |
484 | /* Get the namespace node for the arg/local */ | |
485 | ||
1044f1f6 | 486 | status = acpi_ds_method_data_get_node(type, index, walk_state, &node); |
4be44fcd | 487 | if (ACPI_FAILURE(status)) { |
1da177e4 LT |
488 | return_VOID; |
489 | } | |
490 | ||
491 | /* Get the associated object */ | |
492 | ||
4be44fcd | 493 | object = acpi_ns_get_attached_object(node); |
1da177e4 LT |
494 | |
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) && | |
4be44fcd | 503 | (ACPI_GET_DESCRIPTOR_TYPE(object) == ACPI_DESC_TYPE_OPERAND)) { |
1da177e4 LT |
504 | /* |
505 | * There is a valid object. | |
506 | * Decrement the reference count by one to balance the | |
507 | * increment when the object was stored. | |
508 | */ | |
4be44fcd | 509 | acpi_ut_remove_reference(object); |
1da177e4 LT |
510 | } |
511 | ||
512 | return_VOID; | |
513 | } | |
514 | ||
1da177e4 LT |
515 | /******************************************************************************* |
516 | * | |
517 | * FUNCTION: acpi_ds_store_object_to_local | |
518 | * | |
ba494bee | 519 | * PARAMETERS: type - Either ACPI_REFCLASS_LOCAL or |
1044f1f6 | 520 | * ACPI_REFCLASS_ARG |
ba494bee | 521 | * index - Which Local or Arg to set |
1da177e4 LT |
522 | * obj_desc - Value to be stored |
523 | * walk_state - Current walk state | |
524 | * | |
525 | * RETURN: Status | |
526 | * | |
73a3090a | 527 | * DESCRIPTION: Store a value in an Arg or Local. The obj_desc is installed |
1da177e4 LT |
528 | * as the new value for the Arg or Local and the reference count |
529 | * for obj_desc is incremented. | |
530 | * | |
531 | ******************************************************************************/ | |
532 | ||
533 | acpi_status | |
1044f1f6 | 534 | acpi_ds_store_object_to_local(u8 type, |
4be44fcd LB |
535 | u32 index, |
536 | union acpi_operand_object *obj_desc, | |
537 | struct acpi_walk_state *walk_state) | |
1da177e4 | 538 | { |
4be44fcd LB |
539 | 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; | |
1da177e4 | 543 | |
b229cf92 | 544 | ACPI_FUNCTION_TRACE(ds_store_object_to_local); |
b27d6597 | 545 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Type=%2.2X Index=%u Obj=%p\n", |
1044f1f6 | 546 | type, index, obj_desc)); |
1da177e4 LT |
547 | |
548 | /* Parameter validation */ | |
549 | ||
550 | if (!obj_desc) { | |
4be44fcd | 551 | return_ACPI_STATUS(AE_BAD_PARAMETER); |
1da177e4 LT |
552 | } |
553 | ||
554 | /* Get the namespace node for the arg/local */ | |
555 | ||
1044f1f6 | 556 | status = acpi_ds_method_data_get_node(type, index, walk_state, &node); |
4be44fcd LB |
557 | if (ACPI_FAILURE(status)) { |
558 | return_ACPI_STATUS(status); | |
1da177e4 LT |
559 | } |
560 | ||
4be44fcd | 561 | current_obj_desc = acpi_ns_get_attached_object(node); |
1da177e4 | 562 | if (current_obj_desc == obj_desc) { |
4be44fcd LB |
563 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, "Obj=%p already installed!\n", |
564 | obj_desc)); | |
565 | return_ACPI_STATUS(status); | |
1da177e4 LT |
566 | } |
567 | ||
568 | /* | |
569 | * If the reference count on the object is more than one, we must | |
73a3090a | 570 | * take a copy of the object before we store. A reference count |
1da177e4 LT |
571 | * 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) { | |
4be44fcd LB |
577 | 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); | |
1da177e4 LT |
582 | } |
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 | */ | |
1044f1f6 | 608 | if (type == ACPI_REFCLASS_ARG) { |
1da177e4 | 609 | /* |
44f6c012 RM |
610 | * If we have a valid reference object that came from ref_of(), |
611 | * do the indirect store | |
1da177e4 | 612 | */ |
4be44fcd | 613 | if ((ACPI_GET_DESCRIPTOR_TYPE(current_obj_desc) == |
1fad8738 BM |
614 | 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)) { | |
4be44fcd | 619 | ACPI_DEBUG_PRINT((ACPI_DB_EXEC, |
b229cf92 | 620 | "Arg (%p) is an ObjRef(Node), storing in node %p\n", |
4be44fcd LB |
621 | new_obj_desc, |
622 | current_obj_desc)); | |
1da177e4 LT |
623 | |
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 | */ | |
4be44fcd LB |
629 | 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); | |
1da177e4 LT |
636 | |
637 | /* Remove local reference if we copied the object above */ | |
638 | ||
639 | if (new_obj_desc != obj_desc) { | |
4be44fcd | 640 | acpi_ut_remove_reference(new_obj_desc); |
1da177e4 | 641 | } |
1fad8738 | 642 | |
4be44fcd | 643 | return_ACPI_STATUS(status); |
1da177e4 LT |
644 | } |
645 | } | |
646 | ||
1044f1f6 BM |
647 | /* Delete the existing object before storing the new one */ |
648 | ||
649 | acpi_ds_method_data_delete_value(type, index, walk_state); | |
1da177e4 LT |
650 | } |
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 | */ | |
4be44fcd | 657 | status = |
1044f1f6 | 658 | acpi_ds_method_data_set_value(type, index, new_obj_desc, |
4be44fcd | 659 | walk_state); |
1da177e4 LT |
660 | |
661 | /* Remove local reference if we copied the object above */ | |
662 | ||
663 | if (new_obj_desc != obj_desc) { | |
4be44fcd | 664 | acpi_ut_remove_reference(new_obj_desc); |
1da177e4 LT |
665 | } |
666 | ||
4be44fcd | 667 | return_ACPI_STATUS(status); |
1da177e4 LT |
668 | } |
669 | ||
44f6c012 RM |
670 | #ifdef ACPI_OBSOLETE_FUNCTIONS |
671 | /******************************************************************************* | |
672 | * | |
673 | * FUNCTION: acpi_ds_method_data_get_type | |
674 | * | |
ba494bee BM |
675 | * PARAMETERS: opcode - Either AML_LOCAL_OP or AML_ARG_OP |
676 | * index - Which Local or Arg whose type to get | |
44f6c012 RM |
677 | * 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 | ||
685 | acpi_object_type | |
4be44fcd LB |
686 | acpi_ds_method_data_get_type(u16 opcode, |
687 | u32 index, struct acpi_walk_state *walk_state) | |
44f6c012 | 688 | { |
4be44fcd LB |
689 | acpi_status status; |
690 | struct acpi_namespace_node *node; | |
691 | union acpi_operand_object *object; | |
44f6c012 | 692 | |
b229cf92 | 693 | ACPI_FUNCTION_TRACE(ds_method_data_get_type); |
44f6c012 RM |
694 | |
695 | /* Get the namespace node for the arg/local */ | |
696 | ||
4be44fcd LB |
697 | status = acpi_ds_method_data_get_node(opcode, index, walk_state, &node); |
698 | if (ACPI_FAILURE(status)) { | |
699 | return_VALUE((ACPI_TYPE_NOT_FOUND)); | |
44f6c012 RM |
700 | } |
701 | ||
702 | /* Get the object */ | |
703 | ||
4be44fcd | 704 | object = acpi_ns_get_attached_object(node); |
44f6c012 | 705 | if (!object) { |
52fc0b02 | 706 | |
44f6c012 RM |
707 | /* Uninitialized local/arg, return TYPE_ANY */ |
708 | ||
4be44fcd | 709 | return_VALUE(ACPI_TYPE_ANY); |
44f6c012 RM |
710 | } |
711 | ||
712 | /* Get the object type */ | |
713 | ||
3371c19c | 714 | return_VALUE(object->type); |
44f6c012 RM |
715 | } |
716 | #endif |