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 /*******************************************************************************
19 * FUNCTION: acpi_ns_evaluate
21 * PARAMETERS: info - Evaluation info block, contains these fields
23 * prefix_node - Prefix or Method/Object Node to execute
24 * relative_path - Name of method to execute, If NULL, the
25 * Node is the object to execute
26 * parameters - List of parameters to pass to the method,
27 * terminated by NULL. Params itself may be
28 * NULL if no parameters are being passed.
29 * parameter_type - Type of Parameter list
30 * return_object - Where to put method's return value (if
31 * any). If NULL, no value is returned.
32 * flags - ACPI_IGNORE_RETURN_VALUE to delete return
36 * DESCRIPTION: Execute a control method or return the current value of an
37 * ACPI namespace object.
39 * MUTEX: Locks interpreter
41 ******************************************************************************/
42 acpi_status
acpi_ns_evaluate(struct acpi_evaluate_info
*info
)
46 ACPI_FUNCTION_TRACE(ns_evaluate
);
49 return_ACPI_STATUS(AE_BAD_PARAMETER
);
54 * Get the actual namespace node for the target object if we
55 * need to. Handles these cases:
57 * 1) Null node, valid pathname from root (absolute path)
58 * 2) Node and valid pathname (path relative to Node)
59 * 3) Node, Null pathname
62 acpi_ns_get_node(info
->prefix_node
, info
->relative_pathname
,
63 ACPI_NS_NO_UPSEARCH
, &info
->node
);
64 if (ACPI_FAILURE(status
)) {
65 return_ACPI_STATUS(status
);
70 * For a method alias, we must grab the actual method node so that
71 * proper scoping context will be established before execution.
73 if (acpi_ns_get_type(info
->node
) == ACPI_TYPE_LOCAL_METHOD_ALIAS
) {
75 ACPI_CAST_PTR(struct acpi_namespace_node
,
79 /* Complete the info block initialization */
81 info
->return_object
= NULL
;
82 info
->node_flags
= info
->node
->flags
;
83 info
->obj_desc
= acpi_ns_get_attached_object(info
->node
);
85 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "%s [%p] Value %p\n",
86 info
->relative_pathname
, info
->node
,
87 acpi_ns_get_attached_object(info
->node
)));
89 /* Get info if we have a predefined name (_HID, etc.) */
92 acpi_ut_match_predefined_method(info
->node
->name
.ascii
);
94 /* Get the full pathname to the object, for use in warning messages */
96 info
->full_pathname
= acpi_ns_get_normalized_pathname(info
->node
, TRUE
);
97 if (!info
->full_pathname
) {
98 return_ACPI_STATUS(AE_NO_MEMORY
);
101 /* Optional object evaluation log */
103 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION
,
104 "%-26s: %s (%s)\n", " Enter evaluation",
105 &info
->full_pathname
[1],
106 acpi_ut_get_type_name(info
->node
->type
)));
108 /* Count the number of arguments being passed in */
110 info
->param_count
= 0;
111 if (info
->parameters
) {
112 while (info
->parameters
[info
->param_count
]) {
116 /* Warn on impossible argument count */
118 if (info
->param_count
> ACPI_METHOD_NUM_ARGS
) {
119 ACPI_WARN_PREDEFINED((AE_INFO
, info
->full_pathname
,
121 "Excess arguments (%u) - using only %u",
123 ACPI_METHOD_NUM_ARGS
));
125 info
->param_count
= ACPI_METHOD_NUM_ARGS
;
130 * For predefined names: Check that the declared argument count
131 * matches the ACPI spec -- otherwise this is a BIOS error.
133 acpi_ns_check_acpi_compliance(info
->full_pathname
, info
->node
,
137 * For all names: Check that the incoming argument count for
138 * this method/object matches the actual ASL/AML definition.
140 acpi_ns_check_argument_count(info
->full_pathname
, info
->node
,
141 info
->param_count
, info
->predefined
);
143 /* For predefined names: Typecheck all incoming arguments */
145 acpi_ns_check_argument_types(info
);
148 * Three major evaluation cases:
150 * 1) Object types that cannot be evaluated by definition
151 * 2) The object is a control method -- execute it
152 * 3) The object is not a method -- just return it's current value
154 switch (acpi_ns_get_type(info
->node
)) {
156 case ACPI_TYPE_DEVICE
:
157 case ACPI_TYPE_EVENT
:
158 case ACPI_TYPE_MUTEX
:
159 case ACPI_TYPE_REGION
:
160 case ACPI_TYPE_THERMAL
:
161 case ACPI_TYPE_LOCAL_SCOPE
:
163 * 1) Disallow evaluation of these object types. For these,
164 * object evaluation is undefined.
167 "%s: This object type [%s] "
168 "never contains data and cannot be evaluated",
170 acpi_ut_get_type_name(info
->node
->type
)));
175 case ACPI_TYPE_METHOD
:
177 * 2) Object is a control method - execute it
180 /* Verify that there is a method object associated with this node */
182 if (!info
->obj_desc
) {
184 "%s: Method has no attached sub-object",
185 info
->full_pathname
));
186 status
= AE_NULL_OBJECT
;
190 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
191 "**** Execute method [%s] at AML address %p length %X\n",
193 info
->obj_desc
->method
.aml_start
+ 1,
194 info
->obj_desc
->method
.aml_length
- 1));
197 * Any namespace deletion must acquire both the namespace and
198 * interpreter locks to ensure that no thread is using the portion of
199 * the namespace that is being deleted.
201 * Execute the method via the interpreter. The interpreter is locked
202 * here before calling into the AML parser
204 acpi_ex_enter_interpreter();
205 status
= acpi_ps_execute_method(info
);
206 acpi_ex_exit_interpreter();
211 * 3) All other non-method objects -- get the current object value
215 * Some objects require additional resolution steps (e.g., the Node
216 * may be a field that must be read, etc.) -- we can't just grab
217 * the object out of the node.
219 * Use resolve_node_to_value() to get the associated value.
221 * NOTE: we can get away with passing in NULL for a walk state because
222 * the Node is guaranteed to not be a reference to either a method
223 * local or a method argument (because this interface is never called
224 * from a running method.)
226 * Even though we do not directly invoke the interpreter for object
227 * resolution, we must lock it because we could access an op_region.
228 * The op_region access code assumes that the interpreter is locked.
230 acpi_ex_enter_interpreter();
232 /* TBD: resolve_node_to_value has a strange interface, fix */
234 info
->return_object
=
235 ACPI_CAST_PTR(union acpi_operand_object
, info
->node
);
238 acpi_ex_resolve_node_to_value(ACPI_CAST_INDIRECT_PTR
239 (struct acpi_namespace_node
,
240 &info
->return_object
), NULL
);
241 acpi_ex_exit_interpreter();
243 if (ACPI_FAILURE(status
)) {
244 info
->return_object
= NULL
;
248 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
, "Returned object %p [%s]\n",
250 acpi_ut_get_object_type_name(info
->
253 status
= AE_CTRL_RETURN_VALUE
; /* Always has a "return value" */
258 * For predefined names, check the return value against the ACPI
259 * specification. Some incorrect return value types are repaired.
261 (void)acpi_ns_check_return_value(info
->node
, info
, info
->param_count
,
262 status
, &info
->return_object
);
264 /* Check if there is a return value that must be dealt with */
266 if (status
== AE_CTRL_RETURN_VALUE
) {
268 /* If caller does not want the return value, delete it */
270 if (info
->flags
& ACPI_IGNORE_RETURN_VALUE
) {
271 acpi_ut_remove_reference(info
->return_object
);
272 info
->return_object
= NULL
;
275 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
278 } else if (ACPI_FAILURE(status
)) {
280 /* If return_object exists, delete it */
282 if (info
->return_object
) {
283 acpi_ut_remove_reference(info
->return_object
);
284 info
->return_object
= NULL
;
288 ACPI_DEBUG_PRINT((ACPI_DB_NAMES
,
289 "*** Completed evaluation of object %s ***\n",
290 info
->relative_pathname
));
293 /* Optional object evaluation log */
295 ACPI_DEBUG_PRINT_RAW((ACPI_DB_EVALUATION
,
296 "%-26s: %s\n", " Exit evaluation",
297 &info
->full_pathname
[1]));
300 * Namespace was unlocked by the handling acpi_ns* function, so we
301 * just free the pathname and return
303 ACPI_FREE(info
->full_pathname
);
304 info
->full_pathname
= NULL
;
305 return_ACPI_STATUS(status
);