2 /******************************************************************************
4 * Module Name: nseval - Object evaluation interfaces -- includes control
5 * method lookup and execution.
7 *****************************************************************************/
10 * Copyright (C) 2000 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
35 #define _COMPONENT NAMESPACE
36 MODULE_NAME ("nseval");
39 /****************************************************************************
41 * FUNCTION: Acpi_ns_evaluate_relative
43 * PARAMETERS: Rel_obj_entry - NTE of the relative containing object
44 * *Pathname - Name of method to execute, If NULL, the
45 * handle is the object to execute
46 * **Params - List of parameters to pass to the method,
47 * terminated by NULL. Params itself may be
48 * NULL if no parameters are being passed.
49 * *Return_object - Where to put method's return value (if
50 * any). If NULL, no value is returned.
54 * DESCRIPTION: Find and execute the requested method using the handle as a
57 * MUTEX: Locks Namespace
59 ****************************************************************************/
62 acpi_ns_evaluate_relative (
63 ACPI_NAMED_OBJECT
*handle
,
65 ACPI_OBJECT_INTERNAL
**params
,
66 ACPI_OBJECT_INTERNAL
**return_object
)
68 ACPI_NAMED_OBJECT
*rel_obj_entry
;
70 ACPI_NAMED_OBJECT
*obj_entry
= NULL
;
71 char *internal_path
= NULL
;
72 ACPI_GENERIC_STATE scope_info
;
76 * Must have a valid object handle
79 return (AE_BAD_PARAMETER
);
82 /* Build an internal name string for the method */
84 status
= acpi_ns_internalize_name (pathname
, &internal_path
);
85 if (ACPI_FAILURE (status
)) {
89 /* Get the prefix handle and NTE */
91 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE
);
93 rel_obj_entry
= acpi_ns_convert_handle_to_entry (handle
);
95 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);
96 status
= AE_BAD_PARAMETER
;
100 /* Lookup the name in the namespace */
102 scope_info
.scope
.name_table
= rel_obj_entry
->child_table
;
103 status
= acpi_ns_lookup (&scope_info
, internal_path
, ACPI_TYPE_ANY
,
105 NS_NO_UPSEARCH
, NULL
,
108 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);
110 if (status
!= AE_OK
) {
115 * Now that we have a handle to the object, we can attempt
119 status
= acpi_ns_evaluate_by_handle (obj_entry
, params
, return_object
);
125 acpi_cm_free (internal_path
);
131 /****************************************************************************
133 * FUNCTION: Acpi_ns_evaluate_by_name
135 * PARAMETERS: Pathname - Fully qualified pathname to the object
136 * *Return_object - Where to put method's return value (if
137 * any). If NULL, no value is returned.
138 * **Params - List of parameters to pass to the method,
139 * terminated by NULL. Params itself may be
140 * NULL if no parameters are being passed.
144 * DESCRIPTION: Find and execute the requested method passing the given
147 * MUTEX: Locks Namespace
149 ****************************************************************************/
152 acpi_ns_evaluate_by_name (
154 ACPI_OBJECT_INTERNAL
**params
,
155 ACPI_OBJECT_INTERNAL
**return_object
)
158 ACPI_NAMED_OBJECT
*obj_entry
= NULL
;
159 char *internal_path
= NULL
;
162 /* Build an internal name string for the method */
164 if (pathname
[0] != '\\' || pathname
[1] != '/') {
165 status
= acpi_ns_internalize_name (pathname
, &internal_path
);
166 if (ACPI_FAILURE (status
)) {
171 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE
);
173 /* Lookup the name in the namespace */
175 status
= acpi_ns_lookup (NULL
, internal_path
, ACPI_TYPE_ANY
,
177 NS_NO_UPSEARCH
, NULL
,
180 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);
182 if (status
!= AE_OK
) {
187 * Now that we have a handle to the object, we can attempt
191 status
= acpi_ns_evaluate_by_handle (obj_entry
, params
, return_object
);
199 acpi_cm_free (internal_path
);
206 /****************************************************************************
208 * FUNCTION: Acpi_ns_evaluate_by_handle
210 * PARAMETERS: Obj_entry - NTE of method to execute
211 * *Return_object - Where to put method's return value (if
212 * any). If NULL, no value is returned.
213 * **Params - List of parameters to pass to the method,
214 * terminated by NULL. Params itself may be
215 * NULL if no parameters are being passed.
219 * DESCRIPTION: Execute the requested method passing the given parameters
221 * MUTEX: Locks Namespace
223 ****************************************************************************/
226 acpi_ns_evaluate_by_handle (
227 ACPI_NAMED_OBJECT
*handle
,
228 ACPI_OBJECT_INTERNAL
**params
,
229 ACPI_OBJECT_INTERNAL
**return_object
)
231 ACPI_NAMED_OBJECT
*obj_entry
;
233 ACPI_OBJECT_INTERNAL
*local_return_object
;
236 /* Check if namespace has been initialized */
238 if (!acpi_gbl_root_object
->child_table
) {
239 return (AE_NO_NAMESPACE
);
242 /* Parameter Validation */
245 return (AE_BAD_PARAMETER
);
249 /* Initialize the return value to an invalid object */
251 *return_object
= NULL
;
254 /* Get the prefix handle and NTE */
256 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE
);
258 obj_entry
= acpi_ns_convert_handle_to_entry (handle
);
260 status
= AE_BAD_PARAMETER
;
261 goto unlock_and_exit
;
266 * Two major cases here:
267 * 1) The object is an actual control method -- execute it.
268 * 2) The object is not a method -- just return it's current
271 * In both cases, the namespace is unlocked by the
275 if (acpi_ns_get_type (obj_entry
) == ACPI_TYPE_METHOD
) {
277 * Case 1) We have an actual control method to execute
280 status
= acpi_ns_execute_control_method (obj_entry
,
282 &local_return_object
);
287 * Case 2) Object is NOT a method, just return its
291 status
= acpi_ns_get_object_value (obj_entry
,
292 &local_return_object
);
297 * Check if there is a return value on the stack that must
301 if (status
== AE_CTRL_RETURN_VALUE
) {
303 * If the Method returned a value and the caller
304 * provided a place to store a returned value, Copy
305 * the returned value to the object descriptor provided
311 * Valid return object, copy the pointer to
312 * the returned object
315 *return_object
= local_return_object
;
319 /* Map AE_RETURN_VALUE to AE_OK, we are done with it */
321 if (status
== AE_CTRL_RETURN_VALUE
) {
327 * Namespace was unlocked by the handling Acpi_ns* function,
336 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);
341 /****************************************************************************
343 * FUNCTION: Acpi_ns_execute_control_method
345 * PARAMETERS: Method_entry - The Nte of the object/method
346 * **Params - List of parameters to pass to the method,
347 * terminated by NULL. Params itself may be
348 * NULL if no parameters are being passed.
352 * DESCRIPTION: Execute the requested method passing the given parameters
354 * MUTEX: Assumes namespace is locked
356 ****************************************************************************/
359 acpi_ns_execute_control_method (
360 ACPI_NAMED_OBJECT
*method_entry
,
361 ACPI_OBJECT_INTERNAL
**params
,
362 ACPI_OBJECT_INTERNAL
**return_obj_desc
)
365 ACPI_OBJECT_INTERNAL
*obj_desc
;
368 /* Verify that there is a method associated with this object */
370 obj_desc
= acpi_ns_get_attached_object ((ACPI_HANDLE
) method_entry
);
376 * Valid method, Set the current scope to that of the Method,
382 * Unlock the namespace before execution. This allows namespace access
383 * via the external Acpi* interfaces while a method is being executed.
384 * However, any namespace deletion must acquire both the namespace and
385 * interpter locks to ensure that no thread is using the portion of the
386 * namespace that is being deleted.
389 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);
392 * Excecute the method via the interpreter
394 status
= acpi_aml_execute_method (method_entry
, params
, return_obj_desc
);
400 /****************************************************************************
402 * FUNCTION: Acpi_ns_get_object_value
404 * PARAMETERS: Object_entry - The Nte of the object
408 * DESCRIPTION: Return the current value of the object
410 * MUTEX: Assumes namespace is locked
412 ****************************************************************************/
415 acpi_ns_get_object_value (
416 ACPI_NAMED_OBJECT
*object_entry
,
417 ACPI_OBJECT_INTERNAL
**return_obj_desc
)
419 ACPI_STATUS status
= AE_OK
;
420 ACPI_OBJECT_INTERNAL
*obj_desc
;
421 ACPI_OBJECT_INTERNAL
*val_desc
;
425 * We take the value from certain objects directly
428 if ((object_entry
->type
== ACPI_TYPE_PROCESSOR
) ||
429 (object_entry
->type
== ACPI_TYPE_POWER
))
433 * Create a Reference object to contain the object
435 obj_desc
= acpi_cm_create_internal_object (object_entry
->type
);
437 status
= AE_NO_MEMORY
;
438 goto unlock_and_exit
;
442 * Get the attached object
445 val_desc
= acpi_ns_get_attached_object (object_entry
);
447 status
= AE_NULL_OBJECT
;
448 goto unlock_and_exit
;
452 * Just copy from the original to the return object
455 MEMCPY (&obj_desc
->common
.first_non_common_byte
,
456 &val_desc
->common
.first_non_common_byte
,
457 (sizeof(ACPI_OBJECT_COMMON
) -
458 sizeof(obj_desc
->common
.first_non_common_byte
)));
463 * Other objects require a reference object wrapper which we
464 * then attempt to resolve.
467 /* Create an Reference object to contain the object */
469 obj_desc
= acpi_cm_create_internal_object (INTERNAL_TYPE_REFERENCE
);
471 status
= AE_NO_MEMORY
;
472 goto unlock_and_exit
;
475 /* Construct a descriptor pointing to the name */
477 obj_desc
->reference
.op_code
= (u8
) AML_NAME_OP
;
478 obj_desc
->reference
.object
= (void *) object_entry
;
481 * Use Acpi_aml_resolve_to_value() to get the associated value.
482 * The call to Acpi_aml_resolve_to_value causes
483 * Obj_desc (allocated above) to always be deleted.
486 status
= acpi_aml_resolve_to_value (&obj_desc
);
490 * If Acpi_aml_resolve_to_value() succeeded, the return value was
491 * placed in Obj_desc.
494 if (status
== AE_OK
) {
495 status
= AE_CTRL_RETURN_VALUE
;
497 *return_obj_desc
= obj_desc
;
503 /* Unlock the namespace */
505 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE
);