1 /*******************************************************************************
3 * Module Name: nseval - Object evaluation interfaces -- includes control
4 * method lookup and execution.
6 ******************************************************************************/
9 * Copyright (C) 2000 - 2004, R. Byron Moore
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions, and the following disclaimer,
17 * without modification.
18 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
19 * substantially similar to the "NO WARRANTY" disclaimer below
20 * ("Disclaimer") and any redistribution must be conditioned upon
21 * including a substantially similar Disclaimer requirement for further
22 * binary redistribution.
23 * 3. Neither the names of the above-listed copyright holders nor the names
24 * of any contributors may be used to endorse or promote products derived
25 * from this software without specific prior written permission.
27 * Alternatively, this software may be distributed under the terms of the
28 * GNU General Public License ("GPL") version 2 as published by the Free
29 * Software Foundation.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
37 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
38 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
39 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
40 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
41 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
42 * POSSIBILITY OF SUCH DAMAGES.
46 #include <acpi/acpi.h>
47 #include <acpi/acparser.h>
48 #include <acpi/acinterp.h>
49 #include <acpi/acnamesp.h>
52 #define _COMPONENT ACPI_NAMESPACE
53 ACPI_MODULE_NAME ("nseval")
56 /*******************************************************************************
58 * FUNCTION: acpi_ns_evaluate_relative
60 * PARAMETERS: Handle - The relative containing object
61 * Pathname - Name of method to execute, If NULL, the
62 * handle is the object to execute
63 * Params - List of parameters to pass to the method,
64 * terminated by NULL. Params itself may be
65 * NULL if no parameters are being passed.
66 * return_object - Where to put method's return value (if
67 * any). If NULL, no value is returned.
71 * DESCRIPTION: Find and execute the requested method using the handle as a
74 * MUTEX: Locks Namespace
76 ******************************************************************************/
79 acpi_ns_evaluate_relative (
81 struct acpi_parameter_info *info)
84 struct acpi_namespace_node *node = NULL;
85 union acpi_generic_state *scope_info;
86 char *internal_path = NULL;
89 ACPI_FUNCTION_TRACE ("ns_evaluate_relative");
93 * Must have a valid object handle
95 if (!info || !info->node) {
96 return_ACPI_STATUS (AE_BAD_PARAMETER);
99 /* Build an internal name string for the method */
101 status = acpi_ns_internalize_name (pathname, &internal_path);
102 if (ACPI_FAILURE (status)) {
103 return_ACPI_STATUS (status);
106 scope_info = acpi_ut_create_generic_state ();
111 /* Get the prefix handle and Node */
113 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
114 if (ACPI_FAILURE (status)) {
118 info->node = acpi_ns_map_handle_to_node (info->node);
120 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
121 status = AE_BAD_PARAMETER;
125 /* Lookup the name in the namespace */
127 scope_info->scope.node = info->node;
128 status = acpi_ns_lookup (scope_info, internal_path, ACPI_TYPE_ANY,
129 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
132 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
134 if (ACPI_FAILURE (status)) {
135 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object [%s] not found [%s]\n",
136 pathname, acpi_format_exception (status)));
141 * Now that we have a handle to the object, we can attempt
144 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
145 pathname, node, acpi_ns_get_attached_object (node)));
148 status = acpi_ns_evaluate_by_handle (info);
150 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
154 acpi_ut_delete_generic_state (scope_info);
157 ACPI_MEM_FREE (internal_path);
158 return_ACPI_STATUS (status);
162 /*******************************************************************************
164 * FUNCTION: acpi_ns_evaluate_by_name
166 * PARAMETERS: Pathname - Fully qualified pathname to the object
168 * return_object - Where to put method's return value (if
169 * any). If NULL, no value is returned.
170 * Params - List of parameters to pass to the method,
171 * terminated by NULL. Params itself may be
172 * NULL if no parameters are being passed.
176 * DESCRIPTION: Find and execute the requested method passing the given
179 * MUTEX: Locks Namespace
181 ******************************************************************************/
184 acpi_ns_evaluate_by_name (
186 struct acpi_parameter_info *info)
189 char *internal_path = NULL;
192 ACPI_FUNCTION_TRACE ("ns_evaluate_by_name");
195 /* Build an internal name string for the method */
197 status = acpi_ns_internalize_name (pathname, &internal_path);
198 if (ACPI_FAILURE (status)) {
199 return_ACPI_STATUS (status);
202 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
203 if (ACPI_FAILURE (status)) {
207 /* Lookup the name in the namespace */
209 status = acpi_ns_lookup (NULL, internal_path, ACPI_TYPE_ANY,
210 ACPI_IMODE_EXECUTE, ACPI_NS_NO_UPSEARCH, NULL,
213 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
215 if (ACPI_FAILURE (status)) {
216 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Object at [%s] was not found, status=%.4X\n",
222 * Now that we have a handle to the object, we can attempt
225 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "%s [%p] Value %p\n",
226 pathname, info->node, acpi_ns_get_attached_object (info->node)));
228 status = acpi_ns_evaluate_by_handle (info);
230 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "*** Completed eval of object %s ***\n",
239 ACPI_MEM_FREE (internal_path);
242 return_ACPI_STATUS (status);
246 /*******************************************************************************
248 * FUNCTION: acpi_ns_evaluate_by_handle
250 * PARAMETERS: Handle - Method Node to execute
251 * Params - List of parameters to pass to the method,
252 * terminated by NULL. Params itself may be
253 * NULL if no parameters are being passed.
254 * param_type - Type of Parameter list
255 * return_object - Where to put method's return value (if
256 * any). If NULL, no value is returned.
260 * DESCRIPTION: Execute the requested method passing the given parameters
262 * MUTEX: Locks Namespace
264 ******************************************************************************/
267 acpi_ns_evaluate_by_handle (
268 struct acpi_parameter_info *info)
273 ACPI_FUNCTION_TRACE ("ns_evaluate_by_handle");
276 /* Check if namespace has been initialized */
278 if (!acpi_gbl_root_node) {
279 return_ACPI_STATUS (AE_NO_NAMESPACE);
282 /* Parameter Validation */
285 return_ACPI_STATUS (AE_BAD_PARAMETER);
288 /* Initialize the return value to an invalid object */
290 info->return_object = NULL;
292 /* Get the prefix handle and Node */
294 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
295 if (ACPI_FAILURE (status)) {
296 return_ACPI_STATUS (status);
299 info->node = acpi_ns_map_handle_to_node (info->node);
301 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
302 return_ACPI_STATUS (AE_BAD_PARAMETER);
306 * For a method alias, we must grab the actual method node
307 * so that proper scoping context will be established
310 if (acpi_ns_get_type (info->node) == ACPI_TYPE_LOCAL_METHOD_ALIAS) {
311 info->node = ACPI_CAST_PTR (struct acpi_namespace_node, info->node->object);
315 * Two major cases here:
316 * 1) The object is an actual control method -- execute it.
317 * 2) The object is not a method -- just return it's current
320 * In both cases, the namespace is unlocked by the
323 if (acpi_ns_get_type (info->node) == ACPI_TYPE_METHOD) {
325 * Case 1) We have an actual control method to execute
327 status = acpi_ns_execute_control_method (info);
331 * Case 2) Object is NOT a method, just return its
334 status = acpi_ns_get_object_value (info);
338 * Check if there is a return value on the stack that must
341 if (status == AE_CTRL_RETURN_VALUE) {
342 /* Map AE_CTRL_RETURN_VALUE to AE_OK, we are done with it */
348 * Namespace was unlocked by the handling acpi_ns* function,
351 return_ACPI_STATUS (status);
355 /*******************************************************************************
357 * FUNCTION: acpi_ns_execute_control_method
359 * PARAMETERS: method_node - The method to execute
360 * Params - List of parameters to pass to the method,
361 * terminated by NULL. Params itself may be
362 * NULL if no parameters are being passed.
363 * return_obj_desc - List of result objects to be returned
368 * DESCRIPTION: Execute the requested method passing the given parameters
370 * MUTEX: Assumes namespace is locked
372 ******************************************************************************/
375 acpi_ns_execute_control_method (
376 struct acpi_parameter_info *info)
379 union acpi_operand_object *obj_desc;
382 ACPI_FUNCTION_TRACE ("ns_execute_control_method");
385 /* Verify that there is a method associated with this object */
387 obj_desc = acpi_ns_get_attached_object (info->node);
389 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No attached method object\n"));
391 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
392 return_ACPI_STATUS (AE_NULL_OBJECT);
395 ACPI_DUMP_PATHNAME (info->node, "Execute Method:",
396 ACPI_LV_INFO, _COMPONENT);
398 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Method at AML address %p Length %X\n",
399 obj_desc->method.aml_start + 1, obj_desc->method.aml_length - 1));
402 * Unlock the namespace before execution. This allows namespace access
403 * via the external Acpi* interfaces while a method is being executed.
404 * However, any namespace deletion must acquire both the namespace and
405 * interpreter locks to ensure that no thread is using the portion of the
406 * namespace that is being deleted.
408 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
409 if (ACPI_FAILURE (status)) {
410 return_ACPI_STATUS (status);
414 * Execute the method via the interpreter. The interpreter is locked
415 * here before calling into the AML parser
417 status = acpi_ex_enter_interpreter ();
418 if (ACPI_FAILURE (status)) {
419 return_ACPI_STATUS (status);
422 status = acpi_psx_execute (info);
423 acpi_ex_exit_interpreter ();
425 return_ACPI_STATUS (status);
429 /*******************************************************************************
431 * FUNCTION: acpi_ns_get_object_value
433 * PARAMETERS: Node - The object
434 * return_obj_desc - Where the objects value is returned
438 * DESCRIPTION: Return the current value of the object
440 * MUTEX: Assumes namespace is locked, leaves namespace unlocked
442 ******************************************************************************/
445 acpi_ns_get_object_value (
446 struct acpi_parameter_info *info)
448 acpi_status status = AE_OK;
449 struct acpi_namespace_node *resolved_node = info->node;
452 ACPI_FUNCTION_TRACE ("ns_get_object_value");
456 * Objects require additional resolution steps (e.g., the
457 * Node may be a field that must be read, etc.) -- we can't just grab
458 * the object out of the node.
462 * Use resolve_node_to_value() to get the associated value. This call
463 * always deletes obj_desc (allocated above).
465 * NOTE: we can get away with passing in NULL for a walk state
466 * because obj_desc is guaranteed to not be a reference to either
467 * a method local or a method argument (because this interface can only be
468 * called from the acpi_evaluate external interface, never called from
469 * a running control method.)
471 * Even though we do not directly invoke the interpreter
472 * for this, we must enter it because we could access an opregion.
473 * The opregion access code assumes that the interpreter
476 * We must release the namespace lock before entering the
479 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
480 if (ACPI_FAILURE (status)) {
481 return_ACPI_STATUS (status);
484 status = acpi_ex_enter_interpreter ();
485 if (ACPI_SUCCESS (status)) {
486 status = acpi_ex_resolve_node_to_value (&resolved_node, NULL);
488 * If acpi_ex_resolve_node_to_value() succeeded, the return value was
489 * placed in resolved_node.
491 acpi_ex_exit_interpreter ();
493 if (ACPI_SUCCESS (status)) {
494 status = AE_CTRL_RETURN_VALUE;
495 info->return_object = ACPI_CAST_PTR (union acpi_operand_object, resolved_node);
496 ACPI_DEBUG_PRINT ((ACPI_DB_NAMES, "Returning object %p [%s]\n",
497 info->return_object, acpi_ut_get_object_type_name (info->return_object)));
501 /* Namespace is unlocked */
503 return_ACPI_STATUS (status);