]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - drivers/acpi/acpica/nseval.c
Merge branch 'for-4.10-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/tj...
[mirror_ubuntu-artful-kernel.git] / drivers / acpi / acpica / nseval.c
CommitLineData
1da177e4
LT
1/*******************************************************************************
2 *
4119532c 3 * Module Name: nseval - Object evaluation, includes control method execution
1da177e4
LT
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 "acparser.h"
47#include "acinterp.h"
48#include "acnamesp.h"
1da177e4 49
1da177e4 50#define _COMPONENT ACPI_NAMESPACE
4be44fcd 51ACPI_MODULE_NAME("nseval")
1da177e4 52
7f0c826a
LM
53/* Local prototypes */
54static void
55acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
56 struct acpi_evaluate_info *info);
57
1da177e4
LT
58/*******************************************************************************
59 *
4119532c 60 * FUNCTION: acpi_ns_evaluate
1da177e4 61 *
3d2967b5 62 * PARAMETERS: info - Evaluation info block, contains these fields
63 * and more:
4119532c 64 * prefix_node - Prefix or Method/Object Node to execute
29a241cc 65 * relative_path - Name of method to execute, If NULL, the
4119532c 66 * Node is the object to execute
ba494bee 67 * parameters - List of parameters to pass to the method,
44f6c012 68 * terminated by NULL. Params itself may be
1da177e4 69 * NULL if no parameters are being passed.
44f6c012
RM
70 * parameter_type - Type of Parameter list
71 * return_object - Where to put method's return value (if
72 * any). If NULL, no value is returned.
ba494bee 73 * flags - ACPI_IGNORE_RETURN_VALUE to delete return
1da177e4
LT
74 *
75 * RETURN: Status
76 *
4119532c
BM
77 * DESCRIPTION: Execute a control method or return the current value of an
78 * ACPI namespace object.
1da177e4 79 *
4119532c 80 * MUTEX: Locks interpreter
1da177e4
LT
81 *
82 ******************************************************************************/
7f0c826a 83
29a241cc 84acpi_status acpi_ns_evaluate(struct acpi_evaluate_info *info)
1da177e4 85{
4be44fcd 86 acpi_status status;
1da177e4 87
4119532c 88 ACPI_FUNCTION_TRACE(ns_evaluate);
1da177e4
LT
89
90 if (!info) {
4be44fcd 91 return_ACPI_STATUS(AE_BAD_PARAMETER);
1da177e4
LT
92 }
93
29a241cc 94 if (!info->node) {
c34c82bc 95 /*
29a241cc
BM
96 * Get the actual namespace node for the target object if we
97 * need to. Handles these cases:
c34c82bc 98 *
29a241cc
BM
99 * 1) Null node, valid pathname from root (absolute path)
100 * 2) Node and valid pathname (path relative to Node)
101 * 3) Node, Null pathname
c34c82bc 102 */
29a241cc
BM
103 status =
104 acpi_ns_get_node(info->prefix_node, info->relative_pathname,
105 ACPI_NS_NO_UPSEARCH, &info->node);
c34c82bc
BM
106 if (ACPI_FAILURE(status)) {
107 return_ACPI_STATUS(status);
108 }
1da177e4
LT
109 }
110
1da177e4 111 /*
29a241cc
BM
112 * For a method alias, we must grab the actual method node so that
113 * proper scoping context will be established before execution.
1da177e4 114 */
29a241cc
BM
115 if (acpi_ns_get_type(info->node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) {
116 info->node =
4be44fcd 117 ACPI_CAST_PTR(struct acpi_namespace_node,
29a241cc
BM
118 info->node->object);
119 }
120
121 /* Complete the info block initialization */
122
123 info->return_object = NULL;
124 info->node_flags = info->node->flags;
125 info->obj_desc = acpi_ns_get_attached_object(info->node);
126
127 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "%s [%p] Value %p\n",
128 info->relative_pathname, info->node,
129 acpi_ns_get_attached_object(info->node)));
130
131 /* Get info if we have a predefined name (_HID, etc.) */
132
133 info->predefined =
134 acpi_ut_match_predefined_method(info->node->name.ascii);
135
136 /* Get the full pathname to the object, for use in warning messages */
137
0e166e4f 138 info->full_pathname = acpi_ns_get_normalized_pathname(info->node, TRUE);
29a241cc
BM
139 if (!info->full_pathname) {
140 return_ACPI_STATUS(AE_NO_MEMORY);
1da177e4
LT
141 }
142
29a241cc
BM
143 /* Count the number of arguments being passed in */
144
145 info->param_count = 0;
146 if (info->parameters) {
147 while (info->parameters[info->param_count]) {
148 info->param_count++;
149 }
4119532c 150
29a241cc
BM
151 /* Warn on impossible argument count */
152
153 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
154 ACPI_WARN_PREDEFINED((AE_INFO, info->full_pathname,
155 ACPI_WARN_ALWAYS,
156 "Excess arguments (%u) - using only %u",
157 info->param_count,
158 ACPI_METHOD_NUM_ARGS));
159
160 info->param_count = ACPI_METHOD_NUM_ARGS;
161 }
162 }
163
164 /*
165 * For predefined names: Check that the declared argument count
166 * matches the ACPI spec -- otherwise this is a BIOS error.
167 */
168 acpi_ns_check_acpi_compliance(info->full_pathname, info->node,
169 info->predefined);
e8707b34 170
1da177e4 171 /*
29a241cc
BM
172 * For all names: Check that the incoming argument count for
173 * this method/object matches the actual ASL/AML definition.
174 */
175 acpi_ns_check_argument_count(info->full_pathname, info->node,
176 info->param_count, info->predefined);
177
178 /* For predefined names: Typecheck all incoming arguments */
179
180 acpi_ns_check_argument_types(info);
181
182 /*
183 * Three major evaluation cases:
1da177e4 184 *
29a241cc
BM
185 * 1) Object types that cannot be evaluated by definition
186 * 2) The object is a control method -- execute it
187 * 3) The object is not a method -- just return it's current value
1da177e4 188 */
29a241cc
BM
189 switch (acpi_ns_get_type(info->node)) {
190 case ACPI_TYPE_DEVICE:
191 case ACPI_TYPE_EVENT:
192 case ACPI_TYPE_MUTEX:
193 case ACPI_TYPE_REGION:
194 case ACPI_TYPE_THERMAL:
195 case ACPI_TYPE_LOCAL_SCOPE:
196 /*
197 * 1) Disallow evaluation of certain object types. For these,
198 * object evaluation is undefined and not supported.
199 */
200 ACPI_ERROR((AE_INFO,
201 "%s: Evaluation of object type [%s] is not supported",
202 info->full_pathname,
203 acpi_ut_get_type_name(info->node->type)));
204
205 status = AE_TYPE;
206 goto cleanup;
207
208 case ACPI_TYPE_METHOD:
1da177e4 209 /*
29a241cc 210 * 2) Object is a control method - execute it
1da177e4 211 */
1da177e4 212
4119532c 213 /* Verify that there is a method object associated with this node */
1da177e4 214
4119532c
BM
215 if (!info->obj_desc) {
216 ACPI_ERROR((AE_INFO,
29a241cc
BM
217 "%s: Method has no attached sub-object",
218 info->full_pathname));
219 status = AE_NULL_OBJECT;
220 goto cleanup;
4119532c 221 }
1da177e4 222
4119532c 223 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
29a241cc
BM
224 "**** Execute method [%s] at AML address %p length %X\n",
225 info->full_pathname,
4119532c
BM
226 info->obj_desc->method.aml_start + 1,
227 info->obj_desc->method.aml_length - 1));
1da177e4 228
4119532c
BM
229 /*
230 * Any namespace deletion must acquire both the namespace and
231 * interpreter locks to ensure that no thread is using the portion of
232 * the namespace that is being deleted.
233 *
234 * Execute the method via the interpreter. The interpreter is locked
235 * here before calling into the AML parser
236 */
4d2acd9e 237 acpi_ex_enter_interpreter();
4119532c
BM
238 status = acpi_ps_execute_method(info);
239 acpi_ex_exit_interpreter();
29a241cc
BM
240 break;
241
242 default:
4119532c 243 /*
29a241cc 244 * 3) All other non-method objects -- get the current object value
4119532c 245 */
1da177e4 246
4119532c 247 /*
29a241cc
BM
248 * Some objects require additional resolution steps (e.g., the Node
249 * may be a field that must be read, etc.) -- we can't just grab
250 * the object out of the node.
4119532c
BM
251 *
252 * Use resolve_node_to_value() to get the associated value.
253 *
254 * NOTE: we can get away with passing in NULL for a walk state because
29a241cc 255 * the Node is guaranteed to not be a reference to either a method
4119532c
BM
256 * local or a method argument (because this interface is never called
257 * from a running method.)
258 *
259 * Even though we do not directly invoke the interpreter for object
29a241cc
BM
260 * resolution, we must lock it because we could access an op_region.
261 * The op_region access code assumes that the interpreter is locked.
4119532c 262 */
4d2acd9e 263 acpi_ex_enter_interpreter();
1da177e4 264
29a241cc
BM
265 /* TBD: resolve_node_to_value has a strange interface, fix */
266
267 info->return_object =
268 ACPI_CAST_PTR(union acpi_operand_object, info->node);
1da177e4 269
4119532c 270 status =
29a241cc
BM
271 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
272 (struct acpi_namespace_node,
273 &info->return_object), NULL);
4119532c 274 acpi_ex_exit_interpreter();
1da177e4 275
29a241cc 276 if (ACPI_FAILURE(status)) {
4712f71b 277 info->return_object = NULL;
29a241cc 278 goto cleanup;
1da177e4 279 }
29a241cc
BM
280
281 ACPI_DEBUG_PRINT((ACPI_DB_NAMES, "Returned object %p [%s]\n",
282 info->return_object,
283 acpi_ut_get_object_type_name(info->
284 return_object)));
285
286 status = AE_CTRL_RETURN_VALUE; /* Always has a "return value" */
287 break;
1da177e4
LT
288 }
289
eeb4437e 290 /*
29a241cc
BM
291 * For predefined names, check the return value against the ACPI
292 * specification. Some incorrect return value types are repaired.
eeb4437e 293 */
29a241cc
BM
294 (void)acpi_ns_check_return_value(info->node, info, info->param_count,
295 status, &info->return_object);
e8707b34
BM
296
297 /* Check if there is a return value that must be dealt with */
298
4119532c
BM
299 if (status == AE_CTRL_RETURN_VALUE) {
300
301 /* If caller does not want the return value, delete it */
1da177e4 302
4119532c
BM
303 if (info->flags & ACPI_IGNORE_RETURN_VALUE) {
304 acpi_ut_remove_reference(info->return_object);
305 info->return_object = NULL;
306 }
307
308 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
309
310 status = AE_OK;
311 }
312
313 ACPI_DEBUG_PRINT((ACPI_DB_NAMES,
314 "*** Completed evaluation of object %s ***\n",
29a241cc 315 info->relative_pathname));
4119532c 316
10622bf8 317cleanup:
4119532c
BM
318 /*
319 * Namespace was unlocked by the handling acpi_ns* function, so we
29a241cc 320 * just free the pathname and return
4119532c 321 */
29a241cc
BM
322 ACPI_FREE(info->full_pathname);
323 info->full_pathname = NULL;
4be44fcd 324 return_ACPI_STATUS(status);
1da177e4 325}
7f0c826a
LM
326
327/*******************************************************************************
328 *
329 * FUNCTION: acpi_ns_exec_module_code_list
330 *
331 * PARAMETERS: None
332 *
333 * RETURN: None. Exceptions during method execution are ignored, since
334 * we cannot abort a table load.
335 *
336 * DESCRIPTION: Execute all elements of the global module-level code list.
337 * Each element is executed as a single control method.
338 *
339 ******************************************************************************/
340
341void acpi_ns_exec_module_code_list(void)
342{
343 union acpi_operand_object *prev;
344 union acpi_operand_object *next;
345 struct acpi_evaluate_info *info;
346 u32 method_count = 0;
347
348 ACPI_FUNCTION_TRACE(ns_exec_module_code_list);
349
350 /* Exit now if the list is empty */
351
352 next = acpi_gbl_module_code_list;
353 if (!next) {
354 return_VOID;
355 }
356
357 /* Allocate the evaluation information block */
358
359 info = ACPI_ALLOCATE(sizeof(struct acpi_evaluate_info));
360 if (!info) {
361 return_VOID;
362 }
363
364 /* Walk the list, executing each "method" */
365
366 while (next) {
367 prev = next;
368 next = next->method.mutex;
369
370 /* Clear the link field and execute the method */
371
372 prev->method.mutex = NULL;
373 acpi_ns_exec_module_code(prev, info);
374 method_count++;
375
376 /* Delete the (temporary) method object */
377
378 acpi_ut_remove_reference(prev);
379 }
380
05fb04b5 381 ACPI_INFO(("Executed %u blocks of module-level executable AML code",
7f0c826a
LM
382 method_count));
383
384 ACPI_FREE(info);
385 acpi_gbl_module_code_list = NULL;
386 return_VOID;
387}
388
389/*******************************************************************************
390 *
391 * FUNCTION: acpi_ns_exec_module_code
392 *
393 * PARAMETERS: method_obj - Object container for the module-level code
ba494bee 394 * info - Info block for method evaluation
7f0c826a
LM
395 *
396 * RETURN: None. Exceptions during method execution are ignored, since
397 * we cannot abort a table load.
398 *
399 * DESCRIPTION: Execute a control method containing a block of module-level
400 * executable AML code. The control method is temporarily
401 * installed to the root node, then evaluated.
402 *
403 ******************************************************************************/
404
405static void
406acpi_ns_exec_module_code(union acpi_operand_object *method_obj,
407 struct acpi_evaluate_info *info)
408{
9a884ab6
LM
409 union acpi_operand_object *parent_obj;
410 struct acpi_namespace_node *parent_node;
411 acpi_object_type type;
7f0c826a
LM
412 acpi_status status;
413
414 ACPI_FUNCTION_TRACE(ns_exec_module_code);
415
9a884ab6
LM
416 /*
417 * Get the parent node. We cheat by using the next_object field
418 * of the method object descriptor.
419 */
66e42ee5
LZ
420 parent_node =
421 ACPI_CAST_PTR(struct acpi_namespace_node,
9a884ab6
LM
422 method_obj->method.next_object);
423 type = acpi_ns_get_type(parent_node);
424
e31c32cf
LM
425 /*
426 * Get the region handler and save it in the method object. We may need
427 * this if an operation region declaration causes a _REG method to be run.
428 *
429 * We can't do this in acpi_ps_link_module_code because
430 * acpi_gbl_root_node->Object is NULL at PASS1.
431 */
432 if ((type == ACPI_TYPE_DEVICE) && parent_node->object) {
26294842 433 method_obj->method.dispatch.handler =
e31c32cf
LM
434 parent_node->object->device.handler;
435 }
436
9a884ab6
LM
437 /* Must clear next_object (acpi_ns_attach_object needs the field) */
438
439 method_obj->method.next_object = NULL;
440
7f0c826a
LM
441 /* Initialize the evaluation information block */
442
4fa4616e 443 memset(info, 0, sizeof(struct acpi_evaluate_info));
9a884ab6 444 info->prefix_node = parent_node;
7f0c826a
LM
445
446 /*
66e42ee5
LZ
447 * Get the currently attached parent object. Add a reference,
448 * because the ref count will be decreased when the method object
449 * is installed to the parent node.
7f0c826a 450 */
9a884ab6
LM
451 parent_obj = acpi_ns_get_attached_object(parent_node);
452 if (parent_obj) {
453 acpi_ut_add_reference(parent_obj);
454 }
7f0c826a 455
9a884ab6 456 /* Install the method (module-level code) in the parent node */
7f0c826a 457
66e42ee5
LZ
458 status =
459 acpi_ns_attach_object(parent_node, method_obj, ACPI_TYPE_METHOD);
7f0c826a
LM
460 if (ACPI_FAILURE(status)) {
461 goto exit;
462 }
463
9a884ab6 464 /* Execute the parent node as a control method */
7f0c826a
LM
465
466 status = acpi_ns_evaluate(info);
467
25823e78
BM
468 ACPI_DEBUG_PRINT((ACPI_DB_INIT_NAMES,
469 "Executed module-level code at %p\n",
7f0c826a
LM
470 method_obj->method.aml_start));
471
583061c5
LM
472 /* Delete a possible implicit return value (in slack mode) */
473
474 if (info->return_object) {
475 acpi_ut_remove_reference(info->return_object);
476 }
477
7f0c826a
LM
478 /* Detach the temporary method object */
479
9a884ab6 480 acpi_ns_detach_object(parent_node);
7f0c826a 481
9a884ab6 482 /* Restore the original parent object */
7f0c826a 483
9a884ab6
LM
484 if (parent_obj) {
485 status = acpi_ns_attach_object(parent_node, parent_obj, type);
486 } else {
487 parent_node->type = (u8)type;
488 }
7f0c826a 489
10622bf8 490exit:
9a884ab6
LM
491 if (parent_obj) {
492 acpi_ut_remove_reference(parent_obj);
493 }
7f0c826a
LM
494 return_VOID;
495}