xref: /openbmc/linux/drivers/acpi/acpica/nsxfeval.c (revision c13aca79ff3c4af5fd31a5b2743a90eba6e36a26)
1*95857638SErik Schmauss // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
295b482a8SLen Brown /*******************************************************************************
395b482a8SLen Brown  *
495b482a8SLen Brown  * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
595b482a8SLen Brown  *                         ACPI Object evaluation interfaces
695b482a8SLen Brown  *
795b482a8SLen Brown  ******************************************************************************/
895b482a8SLen Brown 
9839e928fSLv Zheng #define EXPORT_ACPI_INTERFACES
10839e928fSLv Zheng 
1195b482a8SLen Brown #include <acpi/acpi.h>
12e2f7a777SLen Brown #include "accommon.h"
13e2f7a777SLen Brown #include "acnamesp.h"
14e2f7a777SLen Brown #include "acinterp.h"
1595b482a8SLen Brown 
1695b482a8SLen Brown #define _COMPONENT          ACPI_NAMESPACE
1795b482a8SLen Brown ACPI_MODULE_NAME("nsxfeval")
1895b482a8SLen Brown 
1995b482a8SLen Brown /* Local prototypes */
2095b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
2195b482a8SLen Brown 
2295b482a8SLen Brown /*******************************************************************************
2395b482a8SLen Brown  *
2495b482a8SLen Brown  * FUNCTION:    acpi_evaluate_object_typed
2595b482a8SLen Brown  *
26ba494beeSBob Moore  * PARAMETERS:  handle              - Object handle (optional)
27ba494beeSBob Moore  *              pathname            - Object pathname (optional)
28896bece7SBob Moore  *              external_params     - List of parameters to pass to a method,
2995b482a8SLen Brown  *                                    terminated by NULL. May be NULL
3095b482a8SLen Brown  *                                    if no parameters are being passed.
31896bece7SBob Moore  *              return_buffer       - Where to put the object's return value (if
3295b482a8SLen Brown  *                                    any). If NULL, no value is returned.
3395b482a8SLen Brown  *              return_type         - Expected type of return object
3495b482a8SLen Brown  *
3595b482a8SLen Brown  * RETURN:      Status
3695b482a8SLen Brown  *
3795b482a8SLen Brown  * DESCRIPTION: Find and evaluate the given object, passing the given
3895b482a8SLen Brown  *              parameters if necessary. One of "Handle" or "Pathname" must
3995b482a8SLen Brown  *              be valid (non-null)
4095b482a8SLen Brown  *
4195b482a8SLen Brown  ******************************************************************************/
4295b482a8SLen Brown 
4395b482a8SLen Brown acpi_status
acpi_evaluate_object_typed(acpi_handle handle,acpi_string pathname,struct acpi_object_list * external_params,struct acpi_buffer * return_buffer,acpi_object_type return_type)4495b482a8SLen Brown acpi_evaluate_object_typed(acpi_handle handle,
4595b482a8SLen Brown 			   acpi_string pathname,
4695b482a8SLen Brown 			   struct acpi_object_list *external_params,
4795b482a8SLen Brown 			   struct acpi_buffer *return_buffer,
4895b482a8SLen Brown 			   acpi_object_type return_type)
4995b482a8SLen Brown {
5095b482a8SLen Brown 	acpi_status status;
51bb3fec14SLv Zheng 	u8 free_buffer_on_error = FALSE;
522d2a9543SBob Moore 	acpi_handle target_handle;
532d2a9543SBob Moore 	char *full_pathname;
5495b482a8SLen Brown 
5595b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
5695b482a8SLen Brown 
5795b482a8SLen Brown 	/* Return buffer must be valid */
5895b482a8SLen Brown 
5995b482a8SLen Brown 	if (!return_buffer) {
6095b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
6195b482a8SLen Brown 	}
6295b482a8SLen Brown 
6395b482a8SLen Brown 	if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
64bb3fec14SLv Zheng 		free_buffer_on_error = TRUE;
6595b482a8SLen Brown 	}
6695b482a8SLen Brown 
67896bece7SBob Moore 	/* Get a handle here, in order to build an error message if needed */
68896bece7SBob Moore 
69896bece7SBob Moore 	target_handle = handle;
709b40eebcSRafael J. Wysocki 	if (pathname) {
712d2a9543SBob Moore 		status = acpi_get_handle(handle, pathname, &target_handle);
7295b482a8SLen Brown 		if (ACPI_FAILURE(status)) {
7395b482a8SLen Brown 			return_ACPI_STATUS(status);
7495b482a8SLen Brown 		}
759b40eebcSRafael J. Wysocki 	}
7695b482a8SLen Brown 
772d2a9543SBob Moore 	full_pathname = acpi_ns_get_external_pathname(target_handle);
782d2a9543SBob Moore 	if (!full_pathname) {
792d2a9543SBob Moore 		return_ACPI_STATUS(AE_NO_MEMORY);
802d2a9543SBob Moore 	}
812d2a9543SBob Moore 
822d2a9543SBob Moore 	/* Evaluate the object */
832d2a9543SBob Moore 
842d2a9543SBob Moore 	status = acpi_evaluate_object(target_handle, NULL, external_params,
852d2a9543SBob Moore 				      return_buffer);
862d2a9543SBob Moore 	if (ACPI_FAILURE(status)) {
872d2a9543SBob Moore 		goto exit;
882d2a9543SBob Moore 	}
892d2a9543SBob Moore 
902d2a9543SBob Moore 	/* Type ANY means "don't care about return value type" */
9195b482a8SLen Brown 
9295b482a8SLen Brown 	if (return_type == ACPI_TYPE_ANY) {
932d2a9543SBob Moore 		goto exit;
9495b482a8SLen Brown 	}
9595b482a8SLen Brown 
9695b482a8SLen Brown 	if (return_buffer->length == 0) {
9795b482a8SLen Brown 
9895b482a8SLen Brown 		/* Error because caller specifically asked for a return value */
9995b482a8SLen Brown 
1002d2a9543SBob Moore 		ACPI_ERROR((AE_INFO, "%s did not return any object",
1012d2a9543SBob Moore 			    full_pathname));
1022d2a9543SBob Moore 		status = AE_NULL_OBJECT;
1032d2a9543SBob Moore 		goto exit;
10495b482a8SLen Brown 	}
10595b482a8SLen Brown 
10695b482a8SLen Brown 	/* Examine the object type returned from evaluate_object */
10795b482a8SLen Brown 
10895b482a8SLen Brown 	if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
1092d2a9543SBob Moore 		goto exit;
11095b482a8SLen Brown 	}
11195b482a8SLen Brown 
11295b482a8SLen Brown 	/* Return object type does not match requested type */
11395b482a8SLen Brown 
11495b482a8SLen Brown 	ACPI_ERROR((AE_INFO,
1152d2a9543SBob Moore 		    "Incorrect return type from %s - received [%s], requested [%s]",
1162d2a9543SBob Moore 		    full_pathname,
11795b482a8SLen Brown 		    acpi_ut_get_type_name(((union acpi_object *)return_buffer->
11895b482a8SLen Brown 					   pointer)->type),
11995b482a8SLen Brown 		    acpi_ut_get_type_name(return_type)));
12095b482a8SLen Brown 
121bb3fec14SLv Zheng 	if (free_buffer_on_error) {
122bb3fec14SLv Zheng 		/*
123bb3fec14SLv Zheng 		 * Free a buffer created via ACPI_ALLOCATE_BUFFER.
124bb3fec14SLv Zheng 		 * Note: We use acpi_os_free here because acpi_os_allocate was used
125bb3fec14SLv Zheng 		 * to allocate the buffer. This purposefully bypasses the
126bb3fec14SLv Zheng 		 * (optionally enabled) allocation tracking mechanism since we
127bb3fec14SLv Zheng 		 * only want to track internal allocations.
128bb3fec14SLv Zheng 		 */
129bb3fec14SLv Zheng 		acpi_os_free(return_buffer->pointer);
13095b482a8SLen Brown 		return_buffer->pointer = NULL;
13195b482a8SLen Brown 	}
13295b482a8SLen Brown 
13395b482a8SLen Brown 	return_buffer->length = 0;
1342d2a9543SBob Moore 	status = AE_TYPE;
1352d2a9543SBob Moore 
1362d2a9543SBob Moore exit:
1372d2a9543SBob Moore 	ACPI_FREE(full_pathname);
1382d2a9543SBob Moore 	return_ACPI_STATUS(status);
13995b482a8SLen Brown }
14095b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)14195b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
1422c03d07aSLuca Tettamanti 
14395b482a8SLen Brown /*******************************************************************************
14495b482a8SLen Brown  *
14595b482a8SLen Brown  * FUNCTION:    acpi_evaluate_object
14695b482a8SLen Brown  *
147ba494beeSBob Moore  * PARAMETERS:  handle              - Object handle (optional)
148ba494beeSBob Moore  *              pathname            - Object pathname (optional)
14995b482a8SLen Brown  *              external_params     - List of parameters to pass to method,
15095b482a8SLen Brown  *                                    terminated by NULL. May be NULL
15195b482a8SLen Brown  *                                    if no parameters are being passed.
15295b482a8SLen Brown  *              return_buffer       - Where to put method's return value (if
15395b482a8SLen Brown  *                                    any). If NULL, no value is returned.
15495b482a8SLen Brown  *
15595b482a8SLen Brown  * RETURN:      Status
15695b482a8SLen Brown  *
15795b482a8SLen Brown  * DESCRIPTION: Find and evaluate the given object, passing the given
15895b482a8SLen Brown  *              parameters if necessary. One of "Handle" or "Pathname" must
15995b482a8SLen Brown  *              be valid (non-null)
16095b482a8SLen Brown  *
16195b482a8SLen Brown  ******************************************************************************/
16295b482a8SLen Brown acpi_status
16395b482a8SLen Brown acpi_evaluate_object(acpi_handle handle,
16495b482a8SLen Brown 		     acpi_string pathname,
16595b482a8SLen Brown 		     struct acpi_object_list *external_params,
16695b482a8SLen Brown 		     struct acpi_buffer *return_buffer)
16795b482a8SLen Brown {
16895b482a8SLen Brown 	acpi_status status;
16995b482a8SLen Brown 	struct acpi_evaluate_info *info;
17095b482a8SLen Brown 	acpi_size buffer_space_needed;
17195b482a8SLen Brown 	u32 i;
17295b482a8SLen Brown 
17395b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_evaluate_object);
17495b482a8SLen Brown 
17595b482a8SLen Brown 	/* Allocate and initialize the evaluation information block */
17695b482a8SLen Brown 
17795b482a8SLen Brown 	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
17895b482a8SLen Brown 	if (!info) {
17995b482a8SLen Brown 		return_ACPI_STATUS(AE_NO_MEMORY);
18095b482a8SLen Brown 	}
18195b482a8SLen Brown 
18295b482a8SLen Brown 	/* Convert and validate the device handle */
18395b482a8SLen Brown 
184f24b664dSBob Moore 	info->prefix_node = acpi_ns_validate_handle(handle);
18595b482a8SLen Brown 	if (!info->prefix_node) {
18695b482a8SLen Brown 		status = AE_BAD_PARAMETER;
18795b482a8SLen Brown 		goto cleanup;
18895b482a8SLen Brown 	}
18995b482a8SLen Brown 
19095b482a8SLen Brown 	/*
19129a241ccSBob Moore 	 * Get the actual namespace node for the target object.
19229a241ccSBob Moore 	 * Handles these cases:
19329a241ccSBob Moore 	 *
19429a241ccSBob Moore 	 * 1) Null node, valid pathname from root (absolute path)
19529a241ccSBob Moore 	 * 2) Node and valid pathname (path relative to Node)
19629a241ccSBob Moore 	 * 3) Node, Null pathname
19795b482a8SLen Brown 	 */
19804a81dceSBob Moore 	if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) {
19995b482a8SLen Brown 
20095b482a8SLen Brown 		/* The path is fully qualified, just evaluate by name */
20195b482a8SLen Brown 
20295b482a8SLen Brown 		info->prefix_node = NULL;
20395b482a8SLen Brown 	} else if (!handle) {
20495b482a8SLen Brown 		/*
20595b482a8SLen Brown 		 * A handle is optional iff a fully qualified pathname is specified.
20695b482a8SLen Brown 		 * Since we've already handled fully qualified names above, this is
20729a241ccSBob Moore 		 * an error.
20895b482a8SLen Brown 		 */
20995b482a8SLen Brown 		if (!pathname) {
21095b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
21195b482a8SLen Brown 					  "Both Handle and Pathname are NULL"));
21295b482a8SLen Brown 		} else {
21395b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
21495b482a8SLen Brown 					  "Null Handle with relative pathname [%s]",
21595b482a8SLen Brown 					  pathname));
21695b482a8SLen Brown 		}
21795b482a8SLen Brown 
21895b482a8SLen Brown 		status = AE_BAD_PARAMETER;
21929a241ccSBob Moore 		goto cleanup;
22029a241ccSBob Moore 	}
22129a241ccSBob Moore 
22229a241ccSBob Moore 	info->relative_pathname = pathname;
22329a241ccSBob Moore 
22429a241ccSBob Moore 	/*
22529a241ccSBob Moore 	 * Convert all external objects passed as arguments to the
22629a241ccSBob Moore 	 * internal version(s).
22729a241ccSBob Moore 	 */
22829a241ccSBob Moore 	if (external_params && external_params->count) {
22929a241ccSBob Moore 		info->param_count = (u16)external_params->count;
23029a241ccSBob Moore 
23129a241ccSBob Moore 		/* Warn on impossible argument count */
23229a241ccSBob Moore 
23329a241ccSBob Moore 		if (info->param_count > ACPI_METHOD_NUM_ARGS) {
23429a241ccSBob Moore 			ACPI_WARN_PREDEFINED((AE_INFO, pathname,
23529a241ccSBob Moore 					      ACPI_WARN_ALWAYS,
23629a241ccSBob Moore 					      "Excess arguments (%u) - using only %u",
23729a241ccSBob Moore 					      info->param_count,
23829a241ccSBob Moore 					      ACPI_METHOD_NUM_ARGS));
23929a241ccSBob Moore 
24029a241ccSBob Moore 			info->param_count = ACPI_METHOD_NUM_ARGS;
24129a241ccSBob Moore 		}
24229a241ccSBob Moore 
24329a241ccSBob Moore 		/*
24429a241ccSBob Moore 		 * Allocate a new parameter block for the internal objects
24529a241ccSBob Moore 		 * Add 1 to count to allow for null terminated internal list
24629a241ccSBob Moore 		 */
24729a241ccSBob Moore 		info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)info->
24829a241ccSBob Moore 							 param_count +
24929a241ccSBob Moore 							 1) * sizeof(void *));
25029a241ccSBob Moore 		if (!info->parameters) {
25129a241ccSBob Moore 			status = AE_NO_MEMORY;
25229a241ccSBob Moore 			goto cleanup;
25329a241ccSBob Moore 		}
25429a241ccSBob Moore 
25529a241ccSBob Moore 		/* Convert each external object in the list to an internal object */
25629a241ccSBob Moore 
25729a241ccSBob Moore 		for (i = 0; i < info->param_count; i++) {
25829a241ccSBob Moore 			status =
25929a241ccSBob Moore 			    acpi_ut_copy_eobject_to_iobject(&external_params->
26029a241ccSBob Moore 							    pointer[i],
26129a241ccSBob Moore 							    &info->
26229a241ccSBob Moore 							    parameters[i]);
26329a241ccSBob Moore 			if (ACPI_FAILURE(status)) {
26429a241ccSBob Moore 				goto cleanup;
26529a241ccSBob Moore 			}
26629a241ccSBob Moore 		}
26729a241ccSBob Moore 
26829a241ccSBob Moore 		info->parameters[info->param_count] = NULL;
26929a241ccSBob Moore 	}
27029a241ccSBob Moore 
2717dbec553SBob Moore #ifdef _FUTURE_FEATURE
27229a241ccSBob Moore 
27329a241ccSBob Moore 	/*
27429a241ccSBob Moore 	 * Begin incoming argument count analysis. Check for too few args
27529a241ccSBob Moore 	 * and too many args.
27629a241ccSBob Moore 	 */
27729a241ccSBob Moore 	switch (acpi_ns_get_type(info->node)) {
27829a241ccSBob Moore 	case ACPI_TYPE_METHOD:
27929a241ccSBob Moore 
28029a241ccSBob Moore 		/* Check incoming argument count against the method definition */
28129a241ccSBob Moore 
28229a241ccSBob Moore 		if (info->obj_desc->method.param_count > info->param_count) {
28329a241ccSBob Moore 			ACPI_ERROR((AE_INFO,
28429a241ccSBob Moore 				    "Insufficient arguments (%u) - %u are required",
28529a241ccSBob Moore 				    info->param_count,
28629a241ccSBob Moore 				    info->obj_desc->method.param_count));
28729a241ccSBob Moore 
28829a241ccSBob Moore 			status = AE_MISSING_ARGUMENTS;
28929a241ccSBob Moore 			goto cleanup;
29029a241ccSBob Moore 		}
29129a241ccSBob Moore 
29229a241ccSBob Moore 		else if (info->obj_desc->method.param_count < info->param_count) {
29329a241ccSBob Moore 			ACPI_WARNING((AE_INFO,
29429a241ccSBob Moore 				      "Excess arguments (%u) - only %u are required",
29529a241ccSBob Moore 				      info->param_count,
29629a241ccSBob Moore 				      info->obj_desc->method.param_count));
29729a241ccSBob Moore 
29829a241ccSBob Moore 			/* Just pass the required number of arguments */
29929a241ccSBob Moore 
30029a241ccSBob Moore 			info->param_count = info->obj_desc->method.param_count;
30129a241ccSBob Moore 		}
30229a241ccSBob Moore 
30329a241ccSBob Moore 		/*
30429a241ccSBob Moore 		 * Any incoming external objects to be passed as arguments to the
30529a241ccSBob Moore 		 * method must be converted to internal objects
30629a241ccSBob Moore 		 */
30729a241ccSBob Moore 		if (info->param_count) {
30829a241ccSBob Moore 			/*
30929a241ccSBob Moore 			 * Allocate a new parameter block for the internal objects
31029a241ccSBob Moore 			 * Add 1 to count to allow for null terminated internal list
31129a241ccSBob Moore 			 */
31229a241ccSBob Moore 			info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
31329a241ccSBob Moore 								 info->
31429a241ccSBob Moore 								 param_count +
31529a241ccSBob Moore 								 1) *
31629a241ccSBob Moore 								sizeof(void *));
31729a241ccSBob Moore 			if (!info->parameters) {
31829a241ccSBob Moore 				status = AE_NO_MEMORY;
31929a241ccSBob Moore 				goto cleanup;
32029a241ccSBob Moore 			}
32129a241ccSBob Moore 
32229a241ccSBob Moore 			/* Convert each external object in the list to an internal object */
32329a241ccSBob Moore 
32429a241ccSBob Moore 			for (i = 0; i < info->param_count; i++) {
32529a241ccSBob Moore 				status =
32629a241ccSBob Moore 				    acpi_ut_copy_eobject_to_iobject
32729a241ccSBob Moore 				    (&external_params->pointer[i],
32829a241ccSBob Moore 				     &info->parameters[i]);
32929a241ccSBob Moore 				if (ACPI_FAILURE(status)) {
33029a241ccSBob Moore 					goto cleanup;
33129a241ccSBob Moore 				}
33229a241ccSBob Moore 			}
33329a241ccSBob Moore 
33429a241ccSBob Moore 			info->parameters[info->param_count] = NULL;
33529a241ccSBob Moore 		}
33629a241ccSBob Moore 		break;
33729a241ccSBob Moore 
33829a241ccSBob Moore 	default:
33929a241ccSBob Moore 
34029a241ccSBob Moore 		/* Warn if arguments passed to an object that is not a method */
34129a241ccSBob Moore 
34229a241ccSBob Moore 		if (info->param_count) {
34329a241ccSBob Moore 			ACPI_WARNING((AE_INFO,
34429a241ccSBob Moore 				      "%u arguments were passed to a non-method ACPI object",
34529a241ccSBob Moore 				      info->param_count));
34629a241ccSBob Moore 		}
34729a241ccSBob Moore 		break;
34829a241ccSBob Moore 	}
34929a241ccSBob Moore 
35029a241ccSBob Moore #endif
35129a241ccSBob Moore 
35229a241ccSBob Moore 	/* Now we can evaluate the object */
35395b482a8SLen Brown 
35495b482a8SLen Brown 	status = acpi_ns_evaluate(info);
35595b482a8SLen Brown 
35695b482a8SLen Brown 	/*
35795b482a8SLen Brown 	 * If we are expecting a return value, and all went well above,
35895b482a8SLen Brown 	 * copy the return value to an external object.
35995b482a8SLen Brown 	 */
3607dbec553SBob Moore 	if (!return_buffer) {
3617dbec553SBob Moore 		goto cleanup_return_object;
3627dbec553SBob Moore 	}
3637dbec553SBob Moore 
36495b482a8SLen Brown 	if (!info->return_object) {
36595b482a8SLen Brown 		return_buffer->length = 0;
3667dbec553SBob Moore 		goto cleanup;
3677dbec553SBob Moore 	}
3687dbec553SBob Moore 
36995b482a8SLen Brown 	if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
37095b482a8SLen Brown 	    ACPI_DESC_TYPE_NAMED) {
37195b482a8SLen Brown 		/*
37295b482a8SLen Brown 		 * If we received a NS Node as a return object, this means that
37395b482a8SLen Brown 		 * the object we are evaluating has nothing interesting to
37495b482a8SLen Brown 		 * return (such as a mutex, etc.)  We return an error because
37595b482a8SLen Brown 		 * these types are essentially unsupported by this interface.
37695b482a8SLen Brown 		 * We don't check up front because this makes it easier to add
37795b482a8SLen Brown 		 * support for various types at a later date if necessary.
37895b482a8SLen Brown 		 */
37995b482a8SLen Brown 		status = AE_TYPE;
38095b482a8SLen Brown 		info->return_object = NULL;	/* No need to delete a NS Node */
38195b482a8SLen Brown 		return_buffer->length = 0;
38295b482a8SLen Brown 	}
38395b482a8SLen Brown 
3847dbec553SBob Moore 	if (ACPI_FAILURE(status)) {
3857dbec553SBob Moore 		goto cleanup_return_object;
3867dbec553SBob Moore 	}
38795b482a8SLen Brown 
38895b482a8SLen Brown 	/* Dereference Index and ref_of references */
38995b482a8SLen Brown 
39095b482a8SLen Brown 	acpi_ns_resolve_references(info);
39195b482a8SLen Brown 
39295b482a8SLen Brown 	/* Get the size of the returned object */
39395b482a8SLen Brown 
3947dbec553SBob Moore 	status = acpi_ut_get_object_size(info->return_object,
39595b482a8SLen Brown 					 &buffer_space_needed);
39695b482a8SLen Brown 	if (ACPI_SUCCESS(status)) {
39795b482a8SLen Brown 
39895b482a8SLen Brown 		/* Validate/Allocate/Clear caller buffer */
39995b482a8SLen Brown 
4007dbec553SBob Moore 		status = acpi_ut_initialize_buffer(return_buffer,
40195b482a8SLen Brown 						   buffer_space_needed);
40295b482a8SLen Brown 		if (ACPI_FAILURE(status)) {
40395b482a8SLen Brown 			/*
40495b482a8SLen Brown 			 * Caller's buffer is too small or a new one can't
40595b482a8SLen Brown 			 * be allocated
40695b482a8SLen Brown 			 */
40795b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
40895b482a8SLen Brown 					  "Needed buffer size %X, %s\n",
4097dbec553SBob Moore 					  (u32)buffer_space_needed,
4107dbec553SBob Moore 					  acpi_format_exception(status)));
41195b482a8SLen Brown 		} else {
41295b482a8SLen Brown 			/* We have enough space for the object, build it */
41395b482a8SLen Brown 
41495b482a8SLen Brown 			status =
4157dbec553SBob Moore 			    acpi_ut_copy_iobject_to_eobject(info->return_object,
41695b482a8SLen Brown 							    return_buffer);
41795b482a8SLen Brown 		}
41895b482a8SLen Brown 	}
4197dbec553SBob Moore 
4207dbec553SBob Moore cleanup_return_object:
42195b482a8SLen Brown 
42295b482a8SLen Brown 	if (info->return_object) {
42395b482a8SLen Brown 		/*
42495b482a8SLen Brown 		 * Delete the internal return object. NOTE: Interpreter must be
42595b482a8SLen Brown 		 * locked to avoid race condition.
42695b482a8SLen Brown 		 */
42795b482a8SLen Brown 		acpi_ex_enter_interpreter();
42895b482a8SLen Brown 
42995b482a8SLen Brown 		/* Remove one reference on the return object (should delete it) */
43095b482a8SLen Brown 
43195b482a8SLen Brown 		acpi_ut_remove_reference(info->return_object);
43295b482a8SLen Brown 		acpi_ex_exit_interpreter();
43395b482a8SLen Brown 	}
43495b482a8SLen Brown 
43595b482a8SLen Brown cleanup:
43695b482a8SLen Brown 
43795b482a8SLen Brown 	/* Free the input parameter list (if we created one) */
43895b482a8SLen Brown 
43995b482a8SLen Brown 	if (info->parameters) {
44095b482a8SLen Brown 
44195b482a8SLen Brown 		/* Free the allocated parameter block */
44295b482a8SLen Brown 
44395b482a8SLen Brown 		acpi_ut_delete_internal_object_list(info->parameters);
44495b482a8SLen Brown 	}
44595b482a8SLen Brown 
44695b482a8SLen Brown 	ACPI_FREE(info);
44795b482a8SLen Brown 	return_ACPI_STATUS(status);
44895b482a8SLen Brown }
44995b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_evaluate_object)45095b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
45195b482a8SLen Brown 
45295b482a8SLen Brown /*******************************************************************************
45395b482a8SLen Brown  *
45495b482a8SLen Brown  * FUNCTION:    acpi_ns_resolve_references
45595b482a8SLen Brown  *
456ba494beeSBob Moore  * PARAMETERS:  info                    - Evaluation info block
45795b482a8SLen Brown  *
45895b482a8SLen Brown  * RETURN:      Info->return_object is replaced with the dereferenced object
45995b482a8SLen Brown  *
46095b482a8SLen Brown  * DESCRIPTION: Dereference certain reference objects. Called before an
46195b482a8SLen Brown  *              internal return object is converted to an external union acpi_object.
46295b482a8SLen Brown  *
46395b482a8SLen Brown  * Performs an automatic dereference of Index and ref_of reference objects.
46495b482a8SLen Brown  * These reference objects are not supported by the union acpi_object, so this is a
46595b482a8SLen Brown  * last resort effort to return something useful. Also, provides compatibility
46695b482a8SLen Brown  * with other ACPI implementations.
46795b482a8SLen Brown  *
46895b482a8SLen Brown  * NOTE: does not handle references within returned package objects or nested
46995b482a8SLen Brown  * references, but this support could be added later if found to be necessary.
47095b482a8SLen Brown  *
47195b482a8SLen Brown  ******************************************************************************/
47295b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
47395b482a8SLen Brown {
47495b482a8SLen Brown 	union acpi_operand_object *obj_desc = NULL;
47595b482a8SLen Brown 	struct acpi_namespace_node *node;
47695b482a8SLen Brown 
47795b482a8SLen Brown 	/* We are interested in reference objects only */
47895b482a8SLen Brown 
4793371c19cSBob Moore 	if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
48095b482a8SLen Brown 		return;
48195b482a8SLen Brown 	}
48295b482a8SLen Brown 
48395b482a8SLen Brown 	/*
48495b482a8SLen Brown 	 * Two types of references are supported - those created by Index and
48595b482a8SLen Brown 	 * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
48603440c4eSMasahiro Yamada 	 * to a union acpi_object, so it is not dereferenced here. A ddb_handle
48795b482a8SLen Brown 	 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
48803440c4eSMasahiro Yamada 	 * a union acpi_object.
48995b482a8SLen Brown 	 */
49095b482a8SLen Brown 	switch (info->return_object->reference.class) {
49195b482a8SLen Brown 	case ACPI_REFCLASS_INDEX:
49295b482a8SLen Brown 
49395b482a8SLen Brown 		obj_desc = *(info->return_object->reference.where);
49495b482a8SLen Brown 		break;
49595b482a8SLen Brown 
49695b482a8SLen Brown 	case ACPI_REFCLASS_REFOF:
49795b482a8SLen Brown 
49895b482a8SLen Brown 		node = info->return_object->reference.object;
49995b482a8SLen Brown 		if (node) {
50095b482a8SLen Brown 			obj_desc = node->object;
50195b482a8SLen Brown 		}
50295b482a8SLen Brown 		break;
50395b482a8SLen Brown 
50495b482a8SLen Brown 	default:
5051d1ea1b7SChao Guan 
50695b482a8SLen Brown 		return;
50795b482a8SLen Brown 	}
50895b482a8SLen Brown 
50995b482a8SLen Brown 	/* Replace the existing reference object */
51095b482a8SLen Brown 
51195b482a8SLen Brown 	if (obj_desc) {
51295b482a8SLen Brown 		acpi_ut_add_reference(obj_desc);
51395b482a8SLen Brown 		acpi_ut_remove_reference(info->return_object);
51495b482a8SLen Brown 		info->return_object = obj_desc;
51595b482a8SLen Brown 	}
51695b482a8SLen Brown 
51795b482a8SLen Brown 	return;
51895b482a8SLen Brown }
51995b482a8SLen Brown 
52095b482a8SLen Brown /*******************************************************************************
52195b482a8SLen Brown  *
52295b482a8SLen Brown  * FUNCTION:    acpi_walk_namespace
52395b482a8SLen Brown  *
524ba494beeSBob Moore  * PARAMETERS:  type                - acpi_object_type to search for
52595b482a8SLen Brown  *              start_object        - Handle in namespace where search begins
52695b482a8SLen Brown  *              max_depth           - Depth to which search is to reach
5274ef17507SBob Moore  *              descending_callback - Called during tree descent
5282263576cSLin Ming  *                                    when an object of "Type" is found
5294ef17507SBob Moore  *              ascending_callback  - Called during tree ascent
5302263576cSLin Ming  *                                    when an object of "Type" is found
531ba494beeSBob Moore  *              context             - Passed to user function(s) above
53295b482a8SLen Brown  *              return_value        - Location where return value of
53395b482a8SLen Brown  *                                    user_function is put if terminated early
53495b482a8SLen Brown  *
53595b482a8SLen Brown  * RETURNS      Return value from the user_function if terminated early.
53695b482a8SLen Brown  *              Otherwise, returns NULL.
53795b482a8SLen Brown  *
53895b482a8SLen Brown  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
53995b482a8SLen Brown  *              starting (and ending) at the object specified by start_handle.
5402263576cSLin Ming  *              The callback function is called whenever an object that matches
5412263576cSLin Ming  *              the type parameter is found. If the callback function returns
54295b482a8SLen Brown  *              a non-zero value, the search is terminated immediately and this
54395b482a8SLen Brown  *              value is returned to the caller.
54495b482a8SLen Brown  *
54595b482a8SLen Brown  *              The point of this procedure is to provide a generic namespace
54695b482a8SLen Brown  *              walk routine that can be called from multiple places to
5472263576cSLin Ming  *              provide multiple services; the callback function(s) can be
5482263576cSLin Ming  *              tailored to each task, whether it is a print function,
5492263576cSLin Ming  *              a compare function, etc.
55095b482a8SLen Brown  *
55195b482a8SLen Brown  ******************************************************************************/
55295b482a8SLen Brown 
55395b482a8SLen Brown acpi_status
acpi_walk_namespace(acpi_object_type type,acpi_handle start_object,u32 max_depth,acpi_walk_callback descending_callback,acpi_walk_callback ascending_callback,void * context,void ** return_value)55495b482a8SLen Brown acpi_walk_namespace(acpi_object_type type,
55595b482a8SLen Brown 		    acpi_handle start_object,
55695b482a8SLen Brown 		    u32 max_depth,
5574ef17507SBob Moore 		    acpi_walk_callback descending_callback,
5584ef17507SBob Moore 		    acpi_walk_callback ascending_callback,
55995b482a8SLen Brown 		    void *context, void **return_value)
56095b482a8SLen Brown {
56195b482a8SLen Brown 	acpi_status status;
56295b482a8SLen Brown 
56395b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_walk_namespace);
56495b482a8SLen Brown 
56595b482a8SLen Brown 	/* Parameter validation */
56695b482a8SLen Brown 
5672263576cSLin Ming 	if ((type > ACPI_TYPE_LOCAL_MAX) ||
5684ef17507SBob Moore 	    (!max_depth) || (!descending_callback && !ascending_callback)) {
56995b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
57095b482a8SLen Brown 	}
57195b482a8SLen Brown 
57295b482a8SLen Brown 	/*
5738a335a23SBob Moore 	 * Need to acquire the namespace reader lock to prevent interference
5748a335a23SBob Moore 	 * with any concurrent table unloads (which causes the deletion of
5758a335a23SBob Moore 	 * namespace objects). We cannot allow the deletion of a namespace node
5768a335a23SBob Moore 	 * while the user function is using it. The exception to this are the
5778a335a23SBob Moore 	 * nodes created and deleted during control method execution -- these
5788a335a23SBob Moore 	 * nodes are marked as temporary nodes and are ignored by the namespace
5798a335a23SBob Moore 	 * walk. Thus, control methods can be executed while holding the
5808a335a23SBob Moore 	 * namespace deletion lock (and the user function can execute control
5818a335a23SBob Moore 	 * methods.)
5828a335a23SBob Moore 	 */
5838a335a23SBob Moore 	status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
5848a335a23SBob Moore 	if (ACPI_FAILURE(status)) {
5857b6afb67SLv Zheng 		return_ACPI_STATUS(status);
5868a335a23SBob Moore 	}
5878a335a23SBob Moore 
5888a335a23SBob Moore 	/*
5898a335a23SBob Moore 	 * Lock the namespace around the walk. The namespace will be
5908a335a23SBob Moore 	 * unlocked/locked around each call to the user function - since the user
5918a335a23SBob Moore 	 * function must be allowed to make ACPICA calls itself (for example, it
5928a335a23SBob Moore 	 * will typically execute control methods during device enumeration.)
59395b482a8SLen Brown 	 */
59495b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
59595b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
5968a335a23SBob Moore 		goto unlock_and_exit;
59795b482a8SLen Brown 	}
59895b482a8SLen Brown 
599d53d8207SBob Moore 	/* Now we can validate the starting node */
600d53d8207SBob Moore 
601d53d8207SBob Moore 	if (!acpi_ns_validate_handle(start_object)) {
602d53d8207SBob Moore 		status = AE_BAD_PARAMETER;
603d53d8207SBob Moore 		goto unlock_and_exit2;
604d53d8207SBob Moore 	}
605d53d8207SBob Moore 
60695b482a8SLen Brown 	status = acpi_ns_walk_namespace(type, start_object, max_depth,
6074ef17507SBob Moore 					ACPI_NS_WALK_UNLOCK,
6084ef17507SBob Moore 					descending_callback, ascending_callback,
6094ef17507SBob Moore 					context, return_value);
61095b482a8SLen Brown 
611d53d8207SBob Moore unlock_and_exit2:
61295b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
6138a335a23SBob Moore 
6148a335a23SBob Moore unlock_and_exit:
6158a335a23SBob Moore 	(void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
61695b482a8SLen Brown 	return_ACPI_STATUS(status);
61795b482a8SLen Brown }
61895b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_walk_namespace)61995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
62095b482a8SLen Brown 
62195b482a8SLen Brown /*******************************************************************************
62295b482a8SLen Brown  *
62395b482a8SLen Brown  * FUNCTION:    acpi_ns_get_device_callback
62495b482a8SLen Brown  *
62595b482a8SLen Brown  * PARAMETERS:  Callback from acpi_get_device
62695b482a8SLen Brown  *
62795b482a8SLen Brown  * RETURN:      Status
62895b482a8SLen Brown  *
62995b482a8SLen Brown  * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
63095b482a8SLen Brown  *              present devices, or if they specified a HID, it filters based
63195b482a8SLen Brown  *              on that.
63295b482a8SLen Brown  *
63395b482a8SLen Brown  ******************************************************************************/
63495b482a8SLen Brown static acpi_status
63595b482a8SLen Brown acpi_ns_get_device_callback(acpi_handle obj_handle,
63695b482a8SLen Brown 			    u32 nesting_level,
63795b482a8SLen Brown 			    void *context, void **return_value)
63895b482a8SLen Brown {
63995b482a8SLen Brown 	struct acpi_get_devices_info *info = context;
64095b482a8SLen Brown 	acpi_status status;
64195b482a8SLen Brown 	struct acpi_namespace_node *node;
64295b482a8SLen Brown 	u32 flags;
64378e25fefSLv Zheng 	struct acpi_pnp_device_id *hid;
64478e25fefSLv Zheng 	struct acpi_pnp_device_id_list *cid;
64595b482a8SLen Brown 	u32 i;
64615b8dd53SBob Moore 	u8 found;
64715b8dd53SBob Moore 	int no_match;
64895b482a8SLen Brown 
64995b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
65095b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
6517b6afb67SLv Zheng 		return (status);
65295b482a8SLen Brown 	}
65395b482a8SLen Brown 
654f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
65595b482a8SLen Brown 	status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
65695b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
65795b482a8SLen Brown 		return (status);
65895b482a8SLen Brown 	}
65995b482a8SLen Brown 
66095b482a8SLen Brown 	if (!node) {
66195b482a8SLen Brown 		return (AE_BAD_PARAMETER);
66295b482a8SLen Brown 	}
66395b482a8SLen Brown 
66495b482a8SLen Brown 	/*
6655f8902acSLin Ming 	 * First, filter based on the device HID and CID.
6665f8902acSLin Ming 	 *
6675f8902acSLin Ming 	 * 01/2010: For this case where a specific HID is requested, we don't
6685f8902acSLin Ming 	 * want to run _STA until we have an actual HID match. Thus, we will
6695f8902acSLin Ming 	 * not unnecessarily execute _STA on devices for which the caller
6705f8902acSLin Ming 	 * doesn't care about. Previously, _STA was executed unconditionally
6715f8902acSLin Ming 	 * on all devices found here.
6725f8902acSLin Ming 	 *
6735f8902acSLin Ming 	 * A side-effect of this change is that now we will continue to search
6745f8902acSLin Ming 	 * for a matching HID even under device trees where the parent device
6755f8902acSLin Ming 	 * would have returned a _STA that indicates it is not present or
6765f8902acSLin Ming 	 * not functioning (thus aborting the search on that branch).
67795b482a8SLen Brown 	 */
67895b482a8SLen Brown 	if (info->hid != NULL) {
67995b482a8SLen Brown 		status = acpi_ut_execute_HID(node, &hid);
68095b482a8SLen Brown 		if (status == AE_NOT_FOUND) {
68195b482a8SLen Brown 			return (AE_OK);
68295b482a8SLen Brown 		} else if (ACPI_FAILURE(status)) {
68395b482a8SLen Brown 			return (AE_CTRL_DEPTH);
68495b482a8SLen Brown 		}
68595b482a8SLen Brown 
6864fa4616eSBob Moore 		no_match = strcmp(hid->string, info->hid);
68715b8dd53SBob Moore 		ACPI_FREE(hid);
68895b482a8SLen Brown 
68915b8dd53SBob Moore 		if (no_match) {
69015b8dd53SBob Moore 			/*
69115b8dd53SBob Moore 			 * HID does not match, attempt match within the
69215b8dd53SBob Moore 			 * list of Compatible IDs (CIDs)
69315b8dd53SBob Moore 			 */
69495b482a8SLen Brown 			status = acpi_ut_execute_CID(node, &cid);
69595b482a8SLen Brown 			if (status == AE_NOT_FOUND) {
69695b482a8SLen Brown 				return (AE_OK);
69795b482a8SLen Brown 			} else if (ACPI_FAILURE(status)) {
69895b482a8SLen Brown 				return (AE_CTRL_DEPTH);
69995b482a8SLen Brown 			}
70095b482a8SLen Brown 
70195b482a8SLen Brown 			/* Walk the CID list */
70295b482a8SLen Brown 
703739dcbb9SLv Zheng 			found = FALSE;
70495b482a8SLen Brown 			for (i = 0; i < cid->count; i++) {
7054fa4616eSBob Moore 				if (strcmp(cid->ids[i].string, info->hid) == 0) {
7063e8214e5SLv Zheng 
70775c8044fSLv Zheng 					/* Found a matching CID */
7083e8214e5SLv Zheng 
709739dcbb9SLv Zheng 					found = TRUE;
71095b482a8SLen Brown 					break;
71195b482a8SLen Brown 				}
71295b482a8SLen Brown 			}
713739dcbb9SLv Zheng 
71495b482a8SLen Brown 			ACPI_FREE(cid);
715739dcbb9SLv Zheng 			if (!found) {
71695b482a8SLen Brown 				return (AE_OK);
71795b482a8SLen Brown 			}
71895b482a8SLen Brown 		}
719739dcbb9SLv Zheng 	}
72095b482a8SLen Brown 
7215f8902acSLin Ming 	/* Run _STA to determine if device is present */
7225f8902acSLin Ming 
7235f8902acSLin Ming 	status = acpi_ut_execute_STA(node, &flags);
7245f8902acSLin Ming 	if (ACPI_FAILURE(status)) {
7255f8902acSLin Ming 		return (AE_CTRL_DEPTH);
7265f8902acSLin Ming 	}
7275f8902acSLin Ming 
7285f8902acSLin Ming 	if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
7295f8902acSLin Ming 	    !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
7305f8902acSLin Ming 		/*
7315f8902acSLin Ming 		 * Don't examine the children of the device only when the
7325f8902acSLin Ming 		 * device is neither present nor functional. See ACPI spec,
7335f8902acSLin Ming 		 * description of _STA for more information.
7345f8902acSLin Ming 		 */
7355f8902acSLin Ming 		return (AE_CTRL_DEPTH);
7365f8902acSLin Ming 	}
7375f8902acSLin Ming 
7385f8902acSLin Ming 	/* We have a valid device, invoke the user function */
7395f8902acSLin Ming 
7401fad8738SBob Moore 	status = info->user_function(obj_handle, nesting_level,
7411fad8738SBob Moore 				     info->context, return_value);
74295b482a8SLen Brown 	return (status);
74395b482a8SLen Brown }
74495b482a8SLen Brown 
74595b482a8SLen Brown /*******************************************************************************
74695b482a8SLen Brown  *
74795b482a8SLen Brown  * FUNCTION:    acpi_get_devices
74895b482a8SLen Brown  *
74995b482a8SLen Brown  * PARAMETERS:  HID                 - HID to search for. Can be NULL.
75095b482a8SLen Brown  *              user_function       - Called when a matching object is found
751ba494beeSBob Moore  *              context             - Passed to user function
75295b482a8SLen Brown  *              return_value        - Location where return value of
75395b482a8SLen Brown  *                                    user_function is put if terminated early
75495b482a8SLen Brown  *
75595b482a8SLen Brown  * RETURNS      Return value from the user_function if terminated early.
75695b482a8SLen Brown  *              Otherwise, returns NULL.
75795b482a8SLen Brown  *
75895b482a8SLen Brown  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
75995b482a8SLen Brown  *              starting (and ending) at the object specified by start_handle.
76095b482a8SLen Brown  *              The user_function is called whenever an object of type
76195b482a8SLen Brown  *              Device is found. If the user function returns
76295b482a8SLen Brown  *              a non-zero value, the search is terminated immediately and this
76395b482a8SLen Brown  *              value is returned to the caller.
76495b482a8SLen Brown  *
76595b482a8SLen Brown  *              This is a wrapper for walk_namespace, but the callback performs
76695b482a8SLen Brown  *              additional filtering. Please see acpi_ns_get_device_callback.
76795b482a8SLen Brown  *
76895b482a8SLen Brown  ******************************************************************************/
76995b482a8SLen Brown 
77095b482a8SLen Brown acpi_status
acpi_get_devices(const char * HID,acpi_walk_callback user_function,void * context,void ** return_value)77195b482a8SLen Brown acpi_get_devices(const char *HID,
77295b482a8SLen Brown 		 acpi_walk_callback user_function,
77395b482a8SLen Brown 		 void *context, void **return_value)
77495b482a8SLen Brown {
77595b482a8SLen Brown 	acpi_status status;
77695b482a8SLen Brown 	struct acpi_get_devices_info info;
77795b482a8SLen Brown 
77895b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_get_devices);
77995b482a8SLen Brown 
78095b482a8SLen Brown 	/* Parameter validation */
78195b482a8SLen Brown 
78295b482a8SLen Brown 	if (!user_function) {
78395b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
78495b482a8SLen Brown 	}
78595b482a8SLen Brown 
78695b482a8SLen Brown 	/*
78795b482a8SLen Brown 	 * We're going to call their callback from OUR callback, so we need
78895b482a8SLen Brown 	 * to know what it is, and their context parameter.
78995b482a8SLen Brown 	 */
79095b482a8SLen Brown 	info.hid = HID;
79195b482a8SLen Brown 	info.context = context;
79295b482a8SLen Brown 	info.user_function = user_function;
79395b482a8SLen Brown 
79495b482a8SLen Brown 	/*
79595b482a8SLen Brown 	 * Lock the namespace around the walk.
79695b482a8SLen Brown 	 * The namespace will be unlocked/locked around each call
79795b482a8SLen Brown 	 * to the user function - since this function
79895b482a8SLen Brown 	 * must be allowed to make Acpi calls itself.
79995b482a8SLen Brown 	 */
80095b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
80195b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
80295b482a8SLen Brown 		return_ACPI_STATUS(status);
80395b482a8SLen Brown 	}
80495b482a8SLen Brown 
80595b482a8SLen Brown 	status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
80695b482a8SLen Brown 					ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
8072263576cSLin Ming 					acpi_ns_get_device_callback, NULL,
8082263576cSLin Ming 					&info, return_value);
80995b482a8SLen Brown 
81095b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
81195b482a8SLen Brown 	return_ACPI_STATUS(status);
81295b482a8SLen Brown }
81395b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_get_devices)81495b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_devices)
81595b482a8SLen Brown 
81695b482a8SLen Brown /*******************************************************************************
81795b482a8SLen Brown  *
81895b482a8SLen Brown  * FUNCTION:    acpi_attach_data
81995b482a8SLen Brown  *
82095b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node
821ba494beeSBob Moore  *              handler             - Handler for this attachment
822ba494beeSBob Moore  *              data                - Pointer to data to be attached
82395b482a8SLen Brown  *
82495b482a8SLen Brown  * RETURN:      Status
82595b482a8SLen Brown  *
82695b482a8SLen Brown  * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
82795b482a8SLen Brown  *
82895b482a8SLen Brown  ******************************************************************************/
82995b482a8SLen Brown acpi_status
83095b482a8SLen Brown acpi_attach_data(acpi_handle obj_handle,
83195b482a8SLen Brown 		 acpi_object_handler handler, void *data)
83295b482a8SLen Brown {
83395b482a8SLen Brown 	struct acpi_namespace_node *node;
83495b482a8SLen Brown 	acpi_status status;
83595b482a8SLen Brown 
83695b482a8SLen Brown 	/* Parameter validation */
83795b482a8SLen Brown 
83895b482a8SLen Brown 	if (!obj_handle || !handler || !data) {
83995b482a8SLen Brown 		return (AE_BAD_PARAMETER);
84095b482a8SLen Brown 	}
84195b482a8SLen Brown 
84295b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
84395b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
84495b482a8SLen Brown 		return (status);
84595b482a8SLen Brown 	}
84695b482a8SLen Brown 
84795b482a8SLen Brown 	/* Convert and validate the handle */
84895b482a8SLen Brown 
849f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
85095b482a8SLen Brown 	if (!node) {
85195b482a8SLen Brown 		status = AE_BAD_PARAMETER;
85295b482a8SLen Brown 		goto unlock_and_exit;
85395b482a8SLen Brown 	}
85495b482a8SLen Brown 
85595b482a8SLen Brown 	status = acpi_ns_attach_data(node, handler, data);
85695b482a8SLen Brown 
85795b482a8SLen Brown unlock_and_exit:
85895b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
85995b482a8SLen Brown 	return (status);
86095b482a8SLen Brown }
86195b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_attach_data)86295b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_attach_data)
86395b482a8SLen Brown 
86495b482a8SLen Brown /*******************************************************************************
86595b482a8SLen Brown  *
86695b482a8SLen Brown  * FUNCTION:    acpi_detach_data
86795b482a8SLen Brown  *
86895b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node handle
869ba494beeSBob Moore  *              handler             - Handler used in call to acpi_attach_data
87095b482a8SLen Brown  *
87195b482a8SLen Brown  * RETURN:      Status
87295b482a8SLen Brown  *
87395b482a8SLen Brown  * DESCRIPTION: Remove data that was previously attached to a node.
87495b482a8SLen Brown  *
87595b482a8SLen Brown  ******************************************************************************/
87695b482a8SLen Brown acpi_status
87795b482a8SLen Brown acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
87895b482a8SLen Brown {
87995b482a8SLen Brown 	struct acpi_namespace_node *node;
88095b482a8SLen Brown 	acpi_status status;
88195b482a8SLen Brown 
88295b482a8SLen Brown 	/* Parameter validation */
88395b482a8SLen Brown 
88495b482a8SLen Brown 	if (!obj_handle || !handler) {
88595b482a8SLen Brown 		return (AE_BAD_PARAMETER);
88695b482a8SLen Brown 	}
88795b482a8SLen Brown 
88895b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
88995b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
89095b482a8SLen Brown 		return (status);
89195b482a8SLen Brown 	}
89295b482a8SLen Brown 
89395b482a8SLen Brown 	/* Convert and validate the handle */
89495b482a8SLen Brown 
895f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
89695b482a8SLen Brown 	if (!node) {
89795b482a8SLen Brown 		status = AE_BAD_PARAMETER;
89895b482a8SLen Brown 		goto unlock_and_exit;
89995b482a8SLen Brown 	}
90095b482a8SLen Brown 
90195b482a8SLen Brown 	status = acpi_ns_detach_data(node, handler);
90295b482a8SLen Brown 
90395b482a8SLen Brown unlock_and_exit:
90495b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
90595b482a8SLen Brown 	return (status);
90695b482a8SLen Brown }
90795b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_detach_data)90895b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_detach_data)
90995b482a8SLen Brown 
91095b482a8SLen Brown /*******************************************************************************
91195b482a8SLen Brown  *
9127c2e1771SRafael J. Wysocki  * FUNCTION:    acpi_get_data_full
91395b482a8SLen Brown  *
91495b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node
915ba494beeSBob Moore  *              handler             - Handler used in call to attach_data
916ba494beeSBob Moore  *              data                - Where the data is returned
9177c2e1771SRafael J. Wysocki  *              callback            - function to execute before returning
91895b482a8SLen Brown  *
91995b482a8SLen Brown  * RETURN:      Status
92095b482a8SLen Brown  *
9217c2e1771SRafael J. Wysocki  * DESCRIPTION: Retrieve data that was previously attached to a namespace node
9227c2e1771SRafael J. Wysocki  *              and execute a callback before returning.
92395b482a8SLen Brown  *
92495b482a8SLen Brown  ******************************************************************************/
92595b482a8SLen Brown acpi_status
9267c2e1771SRafael J. Wysocki acpi_get_data_full(acpi_handle obj_handle, acpi_object_handler handler,
9277c2e1771SRafael J. Wysocki 		   void **data, void (*callback)(void *))
92895b482a8SLen Brown {
92995b482a8SLen Brown 	struct acpi_namespace_node *node;
93095b482a8SLen Brown 	acpi_status status;
93195b482a8SLen Brown 
93295b482a8SLen Brown 	/* Parameter validation */
93395b482a8SLen Brown 
93495b482a8SLen Brown 	if (!obj_handle || !handler || !data) {
93595b482a8SLen Brown 		return (AE_BAD_PARAMETER);
93695b482a8SLen Brown 	}
93795b482a8SLen Brown 
93895b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
93995b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
94095b482a8SLen Brown 		return (status);
94195b482a8SLen Brown 	}
94295b482a8SLen Brown 
94395b482a8SLen Brown 	/* Convert and validate the handle */
94495b482a8SLen Brown 
945f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
94695b482a8SLen Brown 	if (!node) {
94795b482a8SLen Brown 		status = AE_BAD_PARAMETER;
94895b482a8SLen Brown 		goto unlock_and_exit;
94995b482a8SLen Brown 	}
95095b482a8SLen Brown 
95195b482a8SLen Brown 	status = acpi_ns_get_attached_data(node, handler, data);
9527c2e1771SRafael J. Wysocki 	if (ACPI_SUCCESS(status) && callback) {
9537c2e1771SRafael J. Wysocki 		callback(*data);
9547c2e1771SRafael J. Wysocki 	}
95595b482a8SLen Brown 
95695b482a8SLen Brown unlock_and_exit:
95795b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
95895b482a8SLen Brown 	return (status);
95995b482a8SLen Brown }
96095b482a8SLen Brown 
ACPI_EXPORT_SYMBOL(acpi_get_data_full)9617c2e1771SRafael J. Wysocki ACPI_EXPORT_SYMBOL(acpi_get_data_full)
9627c2e1771SRafael J. Wysocki 
9637c2e1771SRafael J. Wysocki /*******************************************************************************
9647c2e1771SRafael J. Wysocki  *
9657c2e1771SRafael J. Wysocki  * FUNCTION:    acpi_get_data
9667c2e1771SRafael J. Wysocki  *
9677c2e1771SRafael J. Wysocki  * PARAMETERS:  obj_handle          - Namespace node
9687c2e1771SRafael J. Wysocki  *              handler             - Handler used in call to attach_data
9697c2e1771SRafael J. Wysocki  *              data                - Where the data is returned
9707c2e1771SRafael J. Wysocki  *
9717c2e1771SRafael J. Wysocki  * RETURN:      Status
9727c2e1771SRafael J. Wysocki  *
9737c2e1771SRafael J. Wysocki  * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
9747c2e1771SRafael J. Wysocki  *
9757c2e1771SRafael J. Wysocki  ******************************************************************************/
9767c2e1771SRafael J. Wysocki acpi_status
9777c2e1771SRafael J. Wysocki acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
9787c2e1771SRafael J. Wysocki {
9797c2e1771SRafael J. Wysocki 	return acpi_get_data_full(obj_handle, handler, data, NULL);
9807c2e1771SRafael J. Wysocki }
9817c2e1771SRafael J. Wysocki 
98295b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_data)
983