1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: nseval - Object evaluation, includes control method execution
6 ******************************************************************************/
14 #define _COMPONENT ACPI_NAMESPACE
15 ACPI_MODULE_NAME("nseval")
17 /* Local prototypes */
19 acpi_ns_exec_module_code(union acpi_operand_object
*method_obj
,
20 struct acpi_evaluate_info
*info
);
22 /*******************************************************************************
24 * FUNCTION: acpi_ns_evaluate
26 * PARAMETERS: info - Evaluation info block, contains these fields
28 * prefix_node - Prefix or Method/Object Node to execute
29 * relative_path - Name of method to execute, If NULL, the
30 * Node is the object to execute
31 * parameters - List of parameters to pass to the method,
32 * terminated by NULL. Params itself may be
33 * NULL if no parameters are being passed.
34 * parameter_type - Type of Parameter list
35 * return_object - Where to put method's return value (if
36 * any). If NULL, no value is returned.
37 * flags - ACPI_IGNORE_RETURN_VALUE to delete return
41 * DESCRIPTION: Execute a control method or return the current value of an
42 * ACPI namespace object.
44 * MUTEX: Locks interpreter
46 ******************************************************************************/
48 acpi_status
acpi_ns_evaluate(struct acpi_evaluate_info
*info
)
52 ACPI_FUNCTION_TRACE(ns_evaluate
);
55 return_ACPI_STATUS(AE_BAD_PARAMETER
);
60 * Get the actual namespace node for the target object if we
61 * need to. Handles these cases:
63 * 1) Null node, valid pathname from root (absolute path)
64 * 2) Node and valid pathname (path relative to Node)
65 * 3) Node, Null pathname
68 acpi_ns_get_node(info
->prefix_node
, info
->relative_pathname
,
69 ACPI_NS_NO_UPSEARCH
, &info
->node
);
70 if (ACPI_FAILURE(status
)) {
71 return_ACPI_STATUS(status
);
76 * For a method alias, we must grab the actual method node so that
77 * proper scoping context will be established before execution.
79 if (acpi_ns_get_type(info
->node
) == ACPI_TYPE_LOCAL_METHOD_ALIAS
) {
81 ACPI_CAST_PTR(struct acpi_namespace_node
,
85 /* Complete the info block initialization */
87 info
->return_object
= NULL
;
88 info
->node_flags
= info
->node
->flags
;
89 info
->obj_desc
= acpi_ns_get_attached_object(info
->node
);
91 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "%s [%p] Value %p\n",
92 info
->relative_pathname
, info
->node
,
93 acpi_ns_get_attached_object(info
->node
)));
95 /* Get info if we have a predefined name (_HID, etc.) */
98 acpi_ut_match_predefined_method(info
->node
->name
.ascii
);
100 /* Get the full pathname to the object, for use in warning messages */
102 info
->full_pathname
= acpi_ns_get_normalized_pathname(info
->node
, TRUE
);
103 if (!info
->full_pathname
) {
104 return_ACPI_STATUS(AE_NO_MEMORY
);
107 /* Count the number of arguments being passed in */
109 info
->param_count
= 0;
110 if (info
->parameters
) {
111 while (info
->parameters
[info
->param_count
]) {
115 /* Warn on impossible argument count */
117 if (info
->param_count
> ACPI_METHOD_NUM_ARGS
) {
118 ACPI_WARN_PREDEFINED((AE_INFO
, info
->full_pathname
,
120 "Excess arguments (%u) - using only %u",
122 ACPI_METHOD_NUM_ARGS
));
124 info
->param_count
= ACPI_METHOD_NUM_ARGS
;
129 * For predefined names: Check that the declared argument count
130 * matches the ACPI spec -- otherwise this is a BIOS error.
132 acpi_ns_check_acpi_compliance(info
->full_pathname
, info
->node
,
136 * For all names: Check that the incoming argument count for
137 * this method/object matches the actual ASL/AML definition.
139 acpi_ns_check_argument_count(info
->full_pathname
, info
->node
,
140 info
->param_count
, info
->predefined
);
142 /* For predefined names: Typecheck all incoming arguments */
144 acpi_ns_check_argument_types(info
);
147 * Three major evaluation cases:
149 * 1) Object types that cannot be evaluated by definition
150 * 2) The object is a control method -- execute it
151 * 3) The object is not a method -- just return it's current value
153 switch (acpi_ns_get_type(info
->node
)) {
155 case ACPI_TYPE_DEVICE
:
156 case ACPI_TYPE_EVENT
:
157 case ACPI_TYPE_MUTEX
:
158 case ACPI_TYPE_REGION
:
159 case ACPI_TYPE_THERMAL
:
160 case ACPI_TYPE_LOCAL_SCOPE
:
162 * 1) Disallow evaluation of these object types. For these,
163 * object evaluation is undefined.
166 "%s: This object type [%s] "
167 "never contains data and cannot be evaluated",
169 acpi_ut_get_type_name(info
->node
->type
)));
174 case ACPI_TYPE_METHOD
:
176 * 2) Object is a control method - execute it
179 /* Verify that there is a method object associated with this node */
181 if (!info
->obj_desc
) {
183 "%s: Method has no attached sub-object",
184 info
->full_pathname
));
185 status
= AE_NULL_OBJECT
;
189 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
190 "**** Execute method [%s] at AML address %p length %X\n",
192 info
->obj_desc
->method
.aml_start
+ 1,
193 info
->obj_desc
->method
.aml_length
- 1));
196 * Any namespace deletion must acquire both the namespace and
197 * interpreter locks to ensure that no thread is using the portion of
198 * the namespace that is being deleted.
200 * Execute the method via the interpreter. The interpreter is locked
201 * here before calling into the AML parser
203 acpi_ex_enter_interpreter();
204 status
= acpi_ps_execute_method(info
);
205 acpi_ex_exit_interpreter();
210 * 3) All other non-method objects -- get the current object value
214 * Some objects require additional resolution steps (e.g., the Node
215 * may be a field that must be read, etc.) -- we can't just grab
216 * the object out of the node.
218 * Use resolve_node_to_value() to get the associated value.
220 * NOTE: we can get away with passing in NULL for a walk state because
221 * the Node is guaranteed to not be a reference to either a method
222 * local or a method argument (because this interface is never called
223 * from a running method.)
225 * Even though we do not directly invoke the interpreter for object
226 * resolution, we must lock it because we could access an op_region.
227 * The op_region access code assumes that the interpreter is locked.
229 acpi_ex_enter_interpreter();
231 /* TBD: resolve_node_to_value has a strange interface, fix */
233 info
->return_object
=
234 ACPI_CAST_PTR(union acpi_operand_object
, info
->node
);
237 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
238 (struct acpi_namespace_node
,
239 &info
->return_object
), NULL
);
240 acpi_ex_exit_interpreter();
242 if (ACPI_FAILURE(status
)) {
243 info
->return_object
= NULL
;
247 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "Returned object %p [%s]\n",
249 acpi_ut_get_object_type_name(info
->
252 status
= AE_CTRL_RETURN_VALUE
; /* Always has a "return value" */
257 * For predefined names, check the return value against the ACPI
258 * specification. Some incorrect return value types are repaired.
260 (void)acpi_ns_check_return_value(info
->node
, info
, info
->param_count
,
261 status
, &info
->return_object
);
263 /* Check if there is a return value that must be dealt with */
265 if (status
== AE_CTRL_RETURN_VALUE
) {
267 /* If caller does not want the return value, delete it */
269 if (info
->flags
& ACPI_IGNORE_RETURN_VALUE
) {
270 acpi_ut_remove_reference(info
->return_object
);
271 info
->return_object
= NULL
;
274 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
277 } else if (ACPI_FAILURE(status
)) {
279 /* If return_object exists, delete it */
281 if (info
->return_object
) {
282 acpi_ut_remove_reference(info
->return_object
);
283 info
->return_object
= NULL
;
287 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
288 "*** Completed evaluation of object %s ***\n",
289 info
->relative_pathname
));
293 * Namespace was unlocked by the handling acpi_ns* function, so we
294 * just free the pathname and return
296 ACPI_FREE(info
->full_pathname
);
297 info
->full_pathname
= NULL
;
298 return_ACPI_STATUS(status
);
301 /*******************************************************************************
303 * FUNCTION: acpi_ns_exec_module_code_list
307 * RETURN: None. Exceptions during method execution are ignored, since
308 * we cannot abort a table load.
310 * DESCRIPTION: Execute all elements of the global module-level code list.
311 * Each element is executed as a single control method.
313 * NOTE: With this option enabled, each block of detected executable AML
314 * code that is outside of any control method is wrapped with a temporary
315 * control method object and placed on a global list. The methods on this
316 * list are executed below.
318 * This function executes the module-level code for all tables only after
319 * all of the tables have been loaded. It is a legacy option and is
320 * not compatible with other ACPI implementations. See acpi_ns_load_table.
322 * This function will be removed when the legacy option is removed.
324 ******************************************************************************/
326 void acpi_ns_exec_module_code_list(void)
328 union acpi_operand_object
*prev
;
329 union acpi_operand_object
*next
;
330 struct acpi_evaluate_info
*info
;
331 u32 method_count
= 0;
333 ACPI_FUNCTION_TRACE(ns_exec_module_code_list
);
335 /* Exit now if the list is empty */
337 next
= acpi_gbl_module_code_list
;
339 ACPI_DEBUG_PRINT((ACPI_DB_INIT_NAMES
,
340 "Legacy MLC block list is empty\n"));
345 /* Allocate the evaluation information block */
347 info
= ACPI_ALLOCATE(sizeof(struct acpi_evaluate_info
));
352 /* Walk the list, executing each "method" */
356 next
= next
->method
.mutex
;
358 /* Clear the link field and execute the method */
360 prev
->method
.mutex
= NULL
;
361 acpi_ns_exec_module_code(prev
, info
);
364 /* Delete the (temporary) method object */
366 acpi_ut_remove_reference(prev
);
369 ACPI_INFO(("Executed %u blocks of module-level executable AML code",
373 acpi_gbl_module_code_list
= NULL
;
377 /*******************************************************************************
379 * FUNCTION: acpi_ns_exec_module_code
381 * PARAMETERS: method_obj - Object container for the module-level code
382 * info - Info block for method evaluation
384 * RETURN: None. Exceptions during method execution are ignored, since
385 * we cannot abort a table load.
387 * DESCRIPTION: Execute a control method containing a block of module-level
388 * executable AML code. The control method is temporarily
389 * installed to the root node, then evaluated.
391 ******************************************************************************/
394 acpi_ns_exec_module_code(union acpi_operand_object
*method_obj
,
395 struct acpi_evaluate_info
*info
)
397 union acpi_operand_object
*parent_obj
;
398 struct acpi_namespace_node
*parent_node
;
399 acpi_object_type type
;
402 ACPI_FUNCTION_TRACE(ns_exec_module_code
);
405 * Get the parent node. We cheat by using the next_object field
406 * of the method object descriptor.
409 ACPI_CAST_PTR(struct acpi_namespace_node
,
410 method_obj
->method
.next_object
);
411 type
= acpi_ns_get_type(parent_node
);
414 * Get the region handler and save it in the method object. We may need
415 * this if an operation region declaration causes a _REG method to be run.
417 * We can't do this in acpi_ps_link_module_code because
418 * acpi_gbl_root_node->Object is NULL at PASS1.
420 if ((type
== ACPI_TYPE_DEVICE
) && parent_node
->object
) {
421 method_obj
->method
.dispatch
.handler
=
422 parent_node
->object
->device
.handler
;
425 /* Must clear next_object (acpi_ns_attach_object needs the field) */
427 method_obj
->method
.next_object
= NULL
;
429 /* Initialize the evaluation information block */
431 memset(info
, 0, sizeof(struct acpi_evaluate_info
));
432 info
->prefix_node
= parent_node
;
435 * Get the currently attached parent object. Add a reference,
436 * because the ref count will be decreased when the method object
437 * is installed to the parent node.
439 parent_obj
= acpi_ns_get_attached_object(parent_node
);
441 acpi_ut_add_reference(parent_obj
);
444 /* Install the method (module-level code) in the parent node */
447 acpi_ns_attach_object(parent_node
, method_obj
, ACPI_TYPE_METHOD
);
448 if (ACPI_FAILURE(status
)) {
452 /* Execute the parent node as a control method */
454 status
= acpi_ns_evaluate(info
);
456 ACPI_DEBUG_PRINT((ACPI_DB_INIT_NAMES
,
457 "Executed module-level code at %p\n",
458 method_obj
->method
.aml_start
));
460 /* Delete a possible implicit return value (in slack mode) */
462 if (info
->return_object
) {
463 acpi_ut_remove_reference(info
->return_object
);
466 /* Detach the temporary method object */
468 acpi_ns_detach_object(parent_node
);
470 /* Restore the original parent object */
473 status
= acpi_ns_attach_object(parent_node
, parent_obj
, type
);
475 parent_node
->type
= (u8
)type
;
480 acpi_ut_remove_reference(parent_obj
);