1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation, includes control method execution
5 ******************************************************************************/
8 * Copyright (C) 2000 - 2013, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
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.
44 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nseval")
53 /* Local prototypes */
55 acpi_ns_exec_module_code(union acpi_operand_object
*method_obj
,
56 struct acpi_evaluate_info
*info
);
58 /*******************************************************************************
60 * FUNCTION: acpi_ns_evaluate
62 * PARAMETERS: info - Evaluation info block, contains:
63 * prefix_node - Prefix or Method/Object Node to execute
64 * relative_path - Name of method to execute, If NULL, the
65 * Node is the object to execute
66 * parameters - List of parameters to pass to the method,
67 * terminated by NULL. Params itself may be
68 * NULL if no parameters are being passed.
69 * return_object - Where to put method's return value (if
70 * any). If NULL, no value is returned.
71 * parameter_type - Type of Parameter list
72 * return_object - Where to put method's return value (if
73 * any). If NULL, no value is returned.
74 * flags - ACPI_IGNORE_RETURN_VALUE to delete return
78 * DESCRIPTION: Execute a control method or return the current value of an
79 * ACPI namespace object.
81 * MUTEX: Locks interpreter
83 ******************************************************************************/
85 acpi_status
acpi_ns_evaluate(struct acpi_evaluate_info
*info
)
89 ACPI_FUNCTION_TRACE(ns_evaluate
);
92 return_ACPI_STATUS(AE_BAD_PARAMETER
);
97 * Get the actual namespace node for the target object if we
98 * need to. Handles these cases:
100 * 1) Null node, valid pathname from root (absolute path)
101 * 2) Node and valid pathname (path relative to Node)
102 * 3) Node, Null pathname
105 acpi_ns_get_node(info
->prefix_node
, info
->relative_pathname
,
106 ACPI_NS_NO_UPSEARCH
, &info
->node
);
107 if (ACPI_FAILURE(status
)) {
108 return_ACPI_STATUS(status
);
113 * For a method alias, we must grab the actual method node so that
114 * proper scoping context will be established before execution.
116 if (acpi_ns_get_type(info
->node
) == ACPI_TYPE_LOCAL_METHOD_ALIAS
) {
118 ACPI_CAST_PTR(struct acpi_namespace_node
,
122 /* Complete the info block initialization */
124 info
->return_object
= NULL
;
125 info
->node_flags
= info
->node
->flags
;
126 info
->obj_desc
= acpi_ns_get_attached_object(info
->node
);
128 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "%s [%p] Value %p\n",
129 info
->relative_pathname
, info
->node
,
130 acpi_ns_get_attached_object(info
->node
)));
132 /* Get info if we have a predefined name (_HID, etc.) */
135 acpi_ut_match_predefined_method(info
->node
->name
.ascii
);
137 /* Get the full pathname to the object, for use in warning messages */
139 info
->full_pathname
= acpi_ns_get_external_pathname(info
->node
);
140 if (!info
->full_pathname
) {
141 return_ACPI_STATUS(AE_NO_MEMORY
);
144 /* Count the number of arguments being passed in */
146 info
->param_count
= 0;
147 if (info
->parameters
) {
148 while (info
->parameters
[info
->param_count
]) {
152 /* Warn on impossible argument count */
154 if (info
->param_count
> ACPI_METHOD_NUM_ARGS
) {
155 ACPI_WARN_PREDEFINED((AE_INFO
, info
->full_pathname
,
157 "Excess arguments (%u) - using only %u",
159 ACPI_METHOD_NUM_ARGS
));
161 info
->param_count
= ACPI_METHOD_NUM_ARGS
;
166 * For predefined names: Check that the declared argument count
167 * matches the ACPI spec -- otherwise this is a BIOS error.
169 acpi_ns_check_acpi_compliance(info
->full_pathname
, info
->node
,
173 * For all names: Check that the incoming argument count for
174 * this method/object matches the actual ASL/AML definition.
176 acpi_ns_check_argument_count(info
->full_pathname
, info
->node
,
177 info
->param_count
, info
->predefined
);
179 /* For predefined names: Typecheck all incoming arguments */
181 acpi_ns_check_argument_types(info
);
184 * Three major evaluation cases:
186 * 1) Object types that cannot be evaluated by definition
187 * 2) The object is a control method -- execute it
188 * 3) The object is not a method -- just return it's current value
190 switch (acpi_ns_get_type(info
->node
)) {
191 case ACPI_TYPE_DEVICE
:
192 case ACPI_TYPE_EVENT
:
193 case ACPI_TYPE_MUTEX
:
194 case ACPI_TYPE_REGION
:
195 case ACPI_TYPE_THERMAL
:
196 case ACPI_TYPE_LOCAL_SCOPE
:
198 * 1) Disallow evaluation of certain object types. For these,
199 * object evaluation is undefined and not supported.
202 "%s: Evaluation of object type [%s] is not supported",
204 acpi_ut_get_type_name(info
->node
->type
)));
209 case ACPI_TYPE_METHOD
:
211 * 2) Object is a control method - execute it
214 /* Verify that there is a method object associated with this node */
216 if (!info
->obj_desc
) {
218 "%s: Method has no attached sub-object",
219 info
->full_pathname
));
220 status
= AE_NULL_OBJECT
;
224 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
225 "**** Execute method [%s] at AML address %p length %X\n",
227 info
->obj_desc
->method
.aml_start
+ 1,
228 info
->obj_desc
->method
.aml_length
- 1));
231 * Any namespace deletion must acquire both the namespace and
232 * interpreter locks to ensure that no thread is using the portion of
233 * the namespace that is being deleted.
235 * Execute the method via the interpreter. The interpreter is locked
236 * here before calling into the AML parser
238 acpi_ex_enter_interpreter();
239 status
= acpi_ps_execute_method(info
);
240 acpi_ex_exit_interpreter();
245 * 3) All other non-method objects -- get the current object value
249 * Some objects require additional resolution steps (e.g., the Node
250 * may be a field that must be read, etc.) -- we can't just grab
251 * the object out of the node.
253 * Use resolve_node_to_value() to get the associated value.
255 * NOTE: we can get away with passing in NULL for a walk state because
256 * the Node is guaranteed to not be a reference to either a method
257 * local or a method argument (because this interface is never called
258 * from a running method.)
260 * Even though we do not directly invoke the interpreter for object
261 * resolution, we must lock it because we could access an op_region.
262 * The op_region access code assumes that the interpreter is locked.
264 acpi_ex_enter_interpreter();
266 /* TBD: resolve_node_to_value has a strange interface, fix */
268 info
->return_object
=
269 ACPI_CAST_PTR(union acpi_operand_object
, info
->node
);
272 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
273 (struct acpi_namespace_node
,
274 &info
->return_object
), NULL
);
275 acpi_ex_exit_interpreter();
277 if (ACPI_FAILURE(status
)) {
281 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "Returned object %p [%s]\n",
283 acpi_ut_get_object_type_name(info
->
286 status
= AE_CTRL_RETURN_VALUE
; /* Always has a "return value" */
291 * For predefined names, check the return value against the ACPI
292 * specification. Some incorrect return value types are repaired.
294 (void)acpi_ns_check_return_value(info
->node
, info
, info
->param_count
,
295 status
, &info
->return_object
);
297 /* Check if there is a return value that must be dealt with */
299 if (status
== AE_CTRL_RETURN_VALUE
) {
301 /* If caller does not want the return value, delete it */
303 if (info
->flags
& ACPI_IGNORE_RETURN_VALUE
) {
304 acpi_ut_remove_reference(info
->return_object
);
305 info
->return_object
= NULL
;
308 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
313 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
314 "*** Completed evaluation of object %s ***\n",
315 info
->relative_pathname
));
319 * Namespace was unlocked by the handling acpi_ns* function, so we
320 * just free the pathname and return
322 ACPI_FREE(info
->full_pathname
);
323 info
->full_pathname
= NULL
;
324 return_ACPI_STATUS(status
);
327 /*******************************************************************************
329 * FUNCTION: acpi_ns_exec_module_code_list
333 * RETURN: None. Exceptions during method execution are ignored, since
334 * we cannot abort a table load.
336 * DESCRIPTION: Execute all elements of the global module-level code list.
337 * Each element is executed as a single control method.
339 ******************************************************************************/
341 void acpi_ns_exec_module_code_list(void)
343 union acpi_operand_object
*prev
;
344 union acpi_operand_object
*next
;
345 struct acpi_evaluate_info
*info
;
346 u32 method_count
= 0;
348 ACPI_FUNCTION_TRACE(ns_exec_module_code_list
);
350 /* Exit now if the list is empty */
352 next
= acpi_gbl_module_code_list
;
357 /* Allocate the evaluation information block */
359 info
= ACPI_ALLOCATE(sizeof(struct acpi_evaluate_info
));
364 /* Walk the list, executing each "method" */
368 next
= next
->method
.mutex
;
370 /* Clear the link field and execute the method */
372 prev
->method
.mutex
= NULL
;
373 acpi_ns_exec_module_code(prev
, info
);
376 /* Delete the (temporary) method object */
378 acpi_ut_remove_reference(prev
);
382 "Executed %u blocks of module-level executable AML code",
386 acpi_gbl_module_code_list
= NULL
;
390 /*******************************************************************************
392 * FUNCTION: acpi_ns_exec_module_code
394 * PARAMETERS: method_obj - Object container for the module-level code
395 * info - Info block for method evaluation
397 * RETURN: None. Exceptions during method execution are ignored, since
398 * we cannot abort a table load.
400 * DESCRIPTION: Execute a control method containing a block of module-level
401 * executable AML code. The control method is temporarily
402 * installed to the root node, then evaluated.
404 ******************************************************************************/
407 acpi_ns_exec_module_code(union acpi_operand_object
*method_obj
,
408 struct acpi_evaluate_info
*info
)
410 union acpi_operand_object
*parent_obj
;
411 struct acpi_namespace_node
*parent_node
;
412 acpi_object_type type
;
415 ACPI_FUNCTION_TRACE(ns_exec_module_code
);
418 * Get the parent node. We cheat by using the next_object field
419 * of the method object descriptor.
421 parent_node
= ACPI_CAST_PTR(struct acpi_namespace_node
,
422 method_obj
->method
.next_object
);
423 type
= acpi_ns_get_type(parent_node
);
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.
429 * We can't do this in acpi_ps_link_module_code because
430 * acpi_gbl_root_node->Object is NULL at PASS1.
432 if ((type
== ACPI_TYPE_DEVICE
) && parent_node
->object
) {
433 method_obj
->method
.dispatch
.handler
=
434 parent_node
->object
->device
.handler
;
437 /* Must clear next_object (acpi_ns_attach_object needs the field) */
439 method_obj
->method
.next_object
= NULL
;
441 /* Initialize the evaluation information block */
443 ACPI_MEMSET(info
, 0, sizeof(struct acpi_evaluate_info
));
444 info
->prefix_node
= parent_node
;
447 * Get the currently attached parent object. Add a reference, because the
448 * ref count will be decreased when the method object is installed to
451 parent_obj
= acpi_ns_get_attached_object(parent_node
);
453 acpi_ut_add_reference(parent_obj
);
456 /* Install the method (module-level code) in the parent node */
458 status
= acpi_ns_attach_object(parent_node
, method_obj
,
460 if (ACPI_FAILURE(status
)) {
464 /* Execute the parent node as a control method */
466 status
= acpi_ns_evaluate(info
);
468 ACPI_DEBUG_PRINT((ACPI_DB_INIT
, "Executed module-level code at %p\n",
469 method_obj
->method
.aml_start
));
471 /* Delete a possible implicit return value (in slack mode) */
473 if (info
->return_object
) {
474 acpi_ut_remove_reference(info
->return_object
);
477 /* Detach the temporary method object */
479 acpi_ns_detach_object(parent_node
);
481 /* Restore the original parent object */
484 status
= acpi_ns_attach_object(parent_node
, parent_obj
, type
);
486 parent_node
->type
= (u8
)type
;
491 acpi_ut_remove_reference(parent_obj
);