xref: /openbmc/linux/drivers/acpi/acpica/nsxfeval.c (revision 3e8214e5c2bd449b30109d4a098597ab1b7c9fb9)
195b482a8SLen Brown /*******************************************************************************
295b482a8SLen Brown  *
395b482a8SLen Brown  * Module Name: nsxfeval - Public interfaces to the ACPI subsystem
495b482a8SLen Brown  *                         ACPI Object evaluation interfaces
595b482a8SLen Brown  *
695b482a8SLen Brown  ******************************************************************************/
795b482a8SLen Brown 
895b482a8SLen Brown /*
977848130SBob Moore  * Copyright (C) 2000 - 2012, Intel Corp.
1095b482a8SLen Brown  * All rights reserved.
1195b482a8SLen Brown  *
1295b482a8SLen Brown  * Redistribution and use in source and binary forms, with or without
1395b482a8SLen Brown  * modification, are permitted provided that the following conditions
1495b482a8SLen Brown  * are met:
1595b482a8SLen Brown  * 1. Redistributions of source code must retain the above copyright
1695b482a8SLen Brown  *    notice, this list of conditions, and the following disclaimer,
1795b482a8SLen Brown  *    without modification.
1895b482a8SLen Brown  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
1995b482a8SLen Brown  *    substantially similar to the "NO WARRANTY" disclaimer below
2095b482a8SLen Brown  *    ("Disclaimer") and any redistribution must be conditioned upon
2195b482a8SLen Brown  *    including a substantially similar Disclaimer requirement for further
2295b482a8SLen Brown  *    binary redistribution.
2395b482a8SLen Brown  * 3. Neither the names of the above-listed copyright holders nor the names
2495b482a8SLen Brown  *    of any contributors may be used to endorse or promote products derived
2595b482a8SLen Brown  *    from this software without specific prior written permission.
2695b482a8SLen Brown  *
2795b482a8SLen Brown  * Alternatively, this software may be distributed under the terms of the
2895b482a8SLen Brown  * GNU General Public License ("GPL") version 2 as published by the Free
2995b482a8SLen Brown  * Software Foundation.
3095b482a8SLen Brown  *
3195b482a8SLen Brown  * NO WARRANTY
3295b482a8SLen Brown  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
3395b482a8SLen Brown  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
3495b482a8SLen Brown  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
3595b482a8SLen Brown  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
3695b482a8SLen Brown  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
3795b482a8SLen Brown  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
3895b482a8SLen Brown  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3995b482a8SLen Brown  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
4095b482a8SLen Brown  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
4195b482a8SLen Brown  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
4295b482a8SLen Brown  * POSSIBILITY OF SUCH DAMAGES.
4395b482a8SLen Brown  */
4495b482a8SLen Brown 
45214f2c90SPaul Gortmaker #include <linux/export.h>
4695b482a8SLen Brown #include <acpi/acpi.h>
47e2f7a777SLen Brown #include "accommon.h"
48e2f7a777SLen Brown #include "acnamesp.h"
49e2f7a777SLen Brown #include "acinterp.h"
5095b482a8SLen Brown 
5195b482a8SLen Brown #define _COMPONENT          ACPI_NAMESPACE
5295b482a8SLen Brown ACPI_MODULE_NAME("nsxfeval")
5395b482a8SLen Brown 
5495b482a8SLen Brown /* Local prototypes */
5595b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
5695b482a8SLen Brown 
5795b482a8SLen Brown /*******************************************************************************
5895b482a8SLen Brown  *
5995b482a8SLen Brown  * FUNCTION:    acpi_evaluate_object_typed
6095b482a8SLen Brown  *
61ba494beeSBob Moore  * PARAMETERS:  handle              - Object handle (optional)
62ba494beeSBob Moore  *              pathname            - Object pathname (optional)
6395b482a8SLen Brown  *              external_params     - List of parameters to pass to method,
6495b482a8SLen Brown  *                                    terminated by NULL. May be NULL
6595b482a8SLen Brown  *                                    if no parameters are being passed.
6695b482a8SLen Brown  *              return_buffer       - Where to put method's return value (if
6795b482a8SLen Brown  *                                    any). If NULL, no value is returned.
6895b482a8SLen Brown  *              return_type         - Expected type of return object
6995b482a8SLen Brown  *
7095b482a8SLen Brown  * RETURN:      Status
7195b482a8SLen Brown  *
7295b482a8SLen Brown  * DESCRIPTION: Find and evaluate the given object, passing the given
7395b482a8SLen Brown  *              parameters if necessary. One of "Handle" or "Pathname" must
7495b482a8SLen Brown  *              be valid (non-null)
7595b482a8SLen Brown  *
7695b482a8SLen Brown  ******************************************************************************/
7795b482a8SLen Brown 
7895b482a8SLen Brown acpi_status
7995b482a8SLen Brown acpi_evaluate_object_typed(acpi_handle handle,
8095b482a8SLen Brown 			   acpi_string pathname,
8195b482a8SLen Brown 			   struct acpi_object_list *external_params,
8295b482a8SLen Brown 			   struct acpi_buffer *return_buffer,
8395b482a8SLen Brown 			   acpi_object_type return_type)
8495b482a8SLen Brown {
8595b482a8SLen Brown 	acpi_status status;
8695b482a8SLen Brown 	u8 must_free = FALSE;
8795b482a8SLen Brown 
8895b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
8995b482a8SLen Brown 
9095b482a8SLen Brown 	/* Return buffer must be valid */
9195b482a8SLen Brown 
9295b482a8SLen Brown 	if (!return_buffer) {
9395b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
9495b482a8SLen Brown 	}
9595b482a8SLen Brown 
9695b482a8SLen Brown 	if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
9795b482a8SLen Brown 		must_free = TRUE;
9895b482a8SLen Brown 	}
9995b482a8SLen Brown 
10095b482a8SLen Brown 	/* Evaluate the object */
10195b482a8SLen Brown 
10295b482a8SLen Brown 	status =
10395b482a8SLen Brown 	    acpi_evaluate_object(handle, pathname, external_params,
10495b482a8SLen Brown 				 return_buffer);
10595b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
10695b482a8SLen Brown 		return_ACPI_STATUS(status);
10795b482a8SLen Brown 	}
10895b482a8SLen Brown 
10995b482a8SLen Brown 	/* Type ANY means "don't care" */
11095b482a8SLen Brown 
11195b482a8SLen Brown 	if (return_type == ACPI_TYPE_ANY) {
11295b482a8SLen Brown 		return_ACPI_STATUS(AE_OK);
11395b482a8SLen Brown 	}
11495b482a8SLen Brown 
11595b482a8SLen Brown 	if (return_buffer->length == 0) {
11695b482a8SLen Brown 
11795b482a8SLen Brown 		/* Error because caller specifically asked for a return value */
11895b482a8SLen Brown 
11995b482a8SLen Brown 		ACPI_ERROR((AE_INFO, "No return value"));
12095b482a8SLen Brown 		return_ACPI_STATUS(AE_NULL_OBJECT);
12195b482a8SLen Brown 	}
12295b482a8SLen Brown 
12395b482a8SLen Brown 	/* Examine the object type returned from evaluate_object */
12495b482a8SLen Brown 
12595b482a8SLen Brown 	if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
12695b482a8SLen Brown 		return_ACPI_STATUS(AE_OK);
12795b482a8SLen Brown 	}
12895b482a8SLen Brown 
12995b482a8SLen Brown 	/* Return object type does not match requested type */
13095b482a8SLen Brown 
13195b482a8SLen Brown 	ACPI_ERROR((AE_INFO,
13295b482a8SLen Brown 		    "Incorrect return type [%s] requested [%s]",
13395b482a8SLen Brown 		    acpi_ut_get_type_name(((union acpi_object *)return_buffer->
13495b482a8SLen Brown 					   pointer)->type),
13595b482a8SLen Brown 		    acpi_ut_get_type_name(return_type)));
13695b482a8SLen Brown 
13795b482a8SLen Brown 	if (must_free) {
13895b482a8SLen Brown 
13995b482a8SLen Brown 		/* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
14095b482a8SLen Brown 
14195b482a8SLen Brown 		ACPI_FREE(return_buffer->pointer);
14295b482a8SLen Brown 		return_buffer->pointer = NULL;
14395b482a8SLen Brown 	}
14495b482a8SLen Brown 
14595b482a8SLen Brown 	return_buffer->length = 0;
14695b482a8SLen Brown 	return_ACPI_STATUS(AE_TYPE);
14795b482a8SLen Brown }
14895b482a8SLen Brown 
14995b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
1502c03d07aSLuca Tettamanti 
15195b482a8SLen Brown /*******************************************************************************
15295b482a8SLen Brown  *
15395b482a8SLen Brown  * FUNCTION:    acpi_evaluate_object
15495b482a8SLen Brown  *
155ba494beeSBob Moore  * PARAMETERS:  handle              - Object handle (optional)
156ba494beeSBob Moore  *              pathname            - Object pathname (optional)
15795b482a8SLen Brown  *              external_params     - List of parameters to pass to method,
15895b482a8SLen Brown  *                                    terminated by NULL. May be NULL
15995b482a8SLen Brown  *                                    if no parameters are being passed.
16095b482a8SLen Brown  *              return_buffer       - Where to put method's return value (if
16195b482a8SLen Brown  *                                    any). If NULL, no value is returned.
16295b482a8SLen Brown  *
16395b482a8SLen Brown  * RETURN:      Status
16495b482a8SLen Brown  *
16595b482a8SLen Brown  * DESCRIPTION: Find and evaluate the given object, passing the given
16695b482a8SLen Brown  *              parameters if necessary. One of "Handle" or "Pathname" must
16795b482a8SLen Brown  *              be valid (non-null)
16895b482a8SLen Brown  *
16995b482a8SLen Brown  ******************************************************************************/
17095b482a8SLen Brown acpi_status
17195b482a8SLen Brown acpi_evaluate_object(acpi_handle handle,
17295b482a8SLen Brown 		     acpi_string pathname,
17395b482a8SLen Brown 		     struct acpi_object_list *external_params,
17495b482a8SLen Brown 		     struct acpi_buffer *return_buffer)
17595b482a8SLen Brown {
17695b482a8SLen Brown 	acpi_status status;
17795b482a8SLen Brown 	struct acpi_evaluate_info *info;
17895b482a8SLen Brown 	acpi_size buffer_space_needed;
17995b482a8SLen Brown 	u32 i;
18095b482a8SLen Brown 
18195b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_evaluate_object);
18295b482a8SLen Brown 
18395b482a8SLen Brown 	/* Allocate and initialize the evaluation information block */
18495b482a8SLen Brown 
18595b482a8SLen Brown 	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
18695b482a8SLen Brown 	if (!info) {
18795b482a8SLen Brown 		return_ACPI_STATUS(AE_NO_MEMORY);
18895b482a8SLen Brown 	}
18995b482a8SLen Brown 
19095b482a8SLen Brown 	info->pathname = pathname;
19195b482a8SLen Brown 
19295b482a8SLen Brown 	/* Convert and validate the device handle */
19395b482a8SLen Brown 
194f24b664dSBob Moore 	info->prefix_node = acpi_ns_validate_handle(handle);
19595b482a8SLen Brown 	if (!info->prefix_node) {
19695b482a8SLen Brown 		status = AE_BAD_PARAMETER;
19795b482a8SLen Brown 		goto cleanup;
19895b482a8SLen Brown 	}
19995b482a8SLen Brown 
20095b482a8SLen Brown 	/*
20195b482a8SLen Brown 	 * If there are parameters to be passed to a control method, the external
20295b482a8SLen Brown 	 * objects must all be converted to internal objects
20395b482a8SLen Brown 	 */
20495b482a8SLen Brown 	if (external_params && external_params->count) {
20595b482a8SLen Brown 		/*
20695b482a8SLen Brown 		 * Allocate a new parameter block for the internal objects
20795b482a8SLen Brown 		 * Add 1 to count to allow for null terminated internal list
20895b482a8SLen Brown 		 */
20995b482a8SLen Brown 		info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
21095b482a8SLen Brown 							 external_params->
21195b482a8SLen Brown 							 count +
21295b482a8SLen Brown 							 1) * sizeof(void *));
21395b482a8SLen Brown 		if (!info->parameters) {
21495b482a8SLen Brown 			status = AE_NO_MEMORY;
21595b482a8SLen Brown 			goto cleanup;
21695b482a8SLen Brown 		}
21795b482a8SLen Brown 
21895b482a8SLen Brown 		/* Convert each external object in the list to an internal object */
21995b482a8SLen Brown 
22095b482a8SLen Brown 		for (i = 0; i < external_params->count; i++) {
22195b482a8SLen Brown 			status =
22295b482a8SLen Brown 			    acpi_ut_copy_eobject_to_iobject(&external_params->
22395b482a8SLen Brown 							    pointer[i],
22495b482a8SLen Brown 							    &info->
22595b482a8SLen Brown 							    parameters[i]);
22695b482a8SLen Brown 			if (ACPI_FAILURE(status)) {
22795b482a8SLen Brown 				goto cleanup;
22895b482a8SLen Brown 			}
22995b482a8SLen Brown 		}
23095b482a8SLen Brown 		info->parameters[external_params->count] = NULL;
23195b482a8SLen Brown 	}
23295b482a8SLen Brown 
23395b482a8SLen Brown 	/*
23495b482a8SLen Brown 	 * Three major cases:
23595b482a8SLen Brown 	 * 1) Fully qualified pathname
23695b482a8SLen Brown 	 * 2) No handle, not fully qualified pathname (error)
23795b482a8SLen Brown 	 * 3) Valid handle
23895b482a8SLen Brown 	 */
23995b482a8SLen Brown 	if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) {
24095b482a8SLen Brown 
24195b482a8SLen Brown 		/* The path is fully qualified, just evaluate by name */
24295b482a8SLen Brown 
24395b482a8SLen Brown 		info->prefix_node = NULL;
24495b482a8SLen Brown 		status = acpi_ns_evaluate(info);
24595b482a8SLen Brown 	} else if (!handle) {
24695b482a8SLen Brown 		/*
24795b482a8SLen Brown 		 * A handle is optional iff a fully qualified pathname is specified.
24895b482a8SLen Brown 		 * Since we've already handled fully qualified names above, this is
24995b482a8SLen Brown 		 * an error
25095b482a8SLen Brown 		 */
25195b482a8SLen Brown 		if (!pathname) {
25295b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
25395b482a8SLen Brown 					  "Both Handle and Pathname are NULL"));
25495b482a8SLen Brown 		} else {
25595b482a8SLen Brown 			ACPI_DEBUG_PRINT((ACPI_DB_INFO,
25695b482a8SLen Brown 					  "Null Handle with relative pathname [%s]",
25795b482a8SLen Brown 					  pathname));
25895b482a8SLen Brown 		}
25995b482a8SLen Brown 
26095b482a8SLen Brown 		status = AE_BAD_PARAMETER;
26195b482a8SLen Brown 	} else {
26295b482a8SLen Brown 		/* We have a namespace a node and a possible relative path */
26395b482a8SLen Brown 
26495b482a8SLen Brown 		status = acpi_ns_evaluate(info);
26595b482a8SLen Brown 	}
26695b482a8SLen Brown 
26795b482a8SLen Brown 	/*
26895b482a8SLen Brown 	 * If we are expecting a return value, and all went well above,
26995b482a8SLen Brown 	 * copy the return value to an external object.
27095b482a8SLen Brown 	 */
27195b482a8SLen Brown 	if (return_buffer) {
27295b482a8SLen Brown 		if (!info->return_object) {
27395b482a8SLen Brown 			return_buffer->length = 0;
27495b482a8SLen Brown 		} else {
27595b482a8SLen Brown 			if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
27695b482a8SLen Brown 			    ACPI_DESC_TYPE_NAMED) {
27795b482a8SLen Brown 				/*
27895b482a8SLen Brown 				 * If we received a NS Node as a return object, this means that
27995b482a8SLen Brown 				 * the object we are evaluating has nothing interesting to
28095b482a8SLen Brown 				 * return (such as a mutex, etc.)  We return an error because
28195b482a8SLen Brown 				 * these types are essentially unsupported by this interface.
28295b482a8SLen Brown 				 * We don't check up front because this makes it easier to add
28395b482a8SLen Brown 				 * support for various types at a later date if necessary.
28495b482a8SLen Brown 				 */
28595b482a8SLen Brown 				status = AE_TYPE;
28695b482a8SLen Brown 				info->return_object = NULL;	/* No need to delete a NS Node */
28795b482a8SLen Brown 				return_buffer->length = 0;
28895b482a8SLen Brown 			}
28995b482a8SLen Brown 
29095b482a8SLen Brown 			if (ACPI_SUCCESS(status)) {
29195b482a8SLen Brown 
29295b482a8SLen Brown 				/* Dereference Index and ref_of references */
29395b482a8SLen Brown 
29495b482a8SLen Brown 				acpi_ns_resolve_references(info);
29595b482a8SLen Brown 
29695b482a8SLen Brown 				/* Get the size of the returned object */
29795b482a8SLen Brown 
29895b482a8SLen Brown 				status =
29995b482a8SLen Brown 				    acpi_ut_get_object_size(info->return_object,
30095b482a8SLen Brown 							    &buffer_space_needed);
30195b482a8SLen Brown 				if (ACPI_SUCCESS(status)) {
30295b482a8SLen Brown 
30395b482a8SLen Brown 					/* Validate/Allocate/Clear caller buffer */
30495b482a8SLen Brown 
30595b482a8SLen Brown 					status =
30695b482a8SLen Brown 					    acpi_ut_initialize_buffer
30795b482a8SLen Brown 					    (return_buffer,
30895b482a8SLen Brown 					     buffer_space_needed);
30995b482a8SLen Brown 					if (ACPI_FAILURE(status)) {
31095b482a8SLen Brown 						/*
31195b482a8SLen Brown 						 * Caller's buffer is too small or a new one can't
31295b482a8SLen Brown 						 * be allocated
31395b482a8SLen Brown 						 */
31495b482a8SLen Brown 						ACPI_DEBUG_PRINT((ACPI_DB_INFO,
31595b482a8SLen Brown 								  "Needed buffer size %X, %s\n",
31695b482a8SLen Brown 								  (u32)
31795b482a8SLen Brown 								  buffer_space_needed,
31895b482a8SLen Brown 								  acpi_format_exception
31995b482a8SLen Brown 								  (status)));
32095b482a8SLen Brown 					} else {
32195b482a8SLen Brown 						/* We have enough space for the object, build it */
32295b482a8SLen Brown 
32395b482a8SLen Brown 						status =
32495b482a8SLen Brown 						    acpi_ut_copy_iobject_to_eobject
32595b482a8SLen Brown 						    (info->return_object,
32695b482a8SLen Brown 						     return_buffer);
32795b482a8SLen Brown 					}
32895b482a8SLen Brown 				}
32995b482a8SLen Brown 			}
33095b482a8SLen Brown 		}
33195b482a8SLen Brown 	}
33295b482a8SLen Brown 
33395b482a8SLen Brown 	if (info->return_object) {
33495b482a8SLen Brown 		/*
33595b482a8SLen Brown 		 * Delete the internal return object. NOTE: Interpreter must be
33695b482a8SLen Brown 		 * locked to avoid race condition.
33795b482a8SLen Brown 		 */
33895b482a8SLen Brown 		acpi_ex_enter_interpreter();
33995b482a8SLen Brown 
34095b482a8SLen Brown 		/* Remove one reference on the return object (should delete it) */
34195b482a8SLen Brown 
34295b482a8SLen Brown 		acpi_ut_remove_reference(info->return_object);
34395b482a8SLen Brown 		acpi_ex_exit_interpreter();
34495b482a8SLen Brown 	}
34595b482a8SLen Brown 
34695b482a8SLen Brown       cleanup:
34795b482a8SLen Brown 
34895b482a8SLen Brown 	/* Free the input parameter list (if we created one) */
34995b482a8SLen Brown 
35095b482a8SLen Brown 	if (info->parameters) {
35195b482a8SLen Brown 
35295b482a8SLen Brown 		/* Free the allocated parameter block */
35395b482a8SLen Brown 
35495b482a8SLen Brown 		acpi_ut_delete_internal_object_list(info->parameters);
35595b482a8SLen Brown 	}
35695b482a8SLen Brown 
35795b482a8SLen Brown 	ACPI_FREE(info);
35895b482a8SLen Brown 	return_ACPI_STATUS(status);
35995b482a8SLen Brown }
36095b482a8SLen Brown 
36195b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
36295b482a8SLen Brown 
36395b482a8SLen Brown /*******************************************************************************
36495b482a8SLen Brown  *
36595b482a8SLen Brown  * FUNCTION:    acpi_ns_resolve_references
36695b482a8SLen Brown  *
367ba494beeSBob Moore  * PARAMETERS:  info                    - Evaluation info block
36895b482a8SLen Brown  *
36995b482a8SLen Brown  * RETURN:      Info->return_object is replaced with the dereferenced object
37095b482a8SLen Brown  *
37195b482a8SLen Brown  * DESCRIPTION: Dereference certain reference objects. Called before an
37295b482a8SLen Brown  *              internal return object is converted to an external union acpi_object.
37395b482a8SLen Brown  *
37495b482a8SLen Brown  * Performs an automatic dereference of Index and ref_of reference objects.
37595b482a8SLen Brown  * These reference objects are not supported by the union acpi_object, so this is a
37695b482a8SLen Brown  * last resort effort to return something useful. Also, provides compatibility
37795b482a8SLen Brown  * with other ACPI implementations.
37895b482a8SLen Brown  *
37995b482a8SLen Brown  * NOTE: does not handle references within returned package objects or nested
38095b482a8SLen Brown  * references, but this support could be added later if found to be necessary.
38195b482a8SLen Brown  *
38295b482a8SLen Brown  ******************************************************************************/
38395b482a8SLen Brown static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
38495b482a8SLen Brown {
38595b482a8SLen Brown 	union acpi_operand_object *obj_desc = NULL;
38695b482a8SLen Brown 	struct acpi_namespace_node *node;
38795b482a8SLen Brown 
38895b482a8SLen Brown 	/* We are interested in reference objects only */
38995b482a8SLen Brown 
3903371c19cSBob Moore 	if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
39195b482a8SLen Brown 		return;
39295b482a8SLen Brown 	}
39395b482a8SLen Brown 
39495b482a8SLen Brown 	/*
39595b482a8SLen Brown 	 * Two types of references are supported - those created by Index and
39695b482a8SLen Brown 	 * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
39795b482a8SLen Brown 	 * to an union acpi_object, so it is not dereferenced here. A ddb_handle
39895b482a8SLen Brown 	 * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
39995b482a8SLen Brown 	 * an union acpi_object.
40095b482a8SLen Brown 	 */
40195b482a8SLen Brown 	switch (info->return_object->reference.class) {
40295b482a8SLen Brown 	case ACPI_REFCLASS_INDEX:
40395b482a8SLen Brown 
40495b482a8SLen Brown 		obj_desc = *(info->return_object->reference.where);
40595b482a8SLen Brown 		break;
40695b482a8SLen Brown 
40795b482a8SLen Brown 	case ACPI_REFCLASS_REFOF:
40895b482a8SLen Brown 
40995b482a8SLen Brown 		node = info->return_object->reference.object;
41095b482a8SLen Brown 		if (node) {
41195b482a8SLen Brown 			obj_desc = node->object;
41295b482a8SLen Brown 		}
41395b482a8SLen Brown 		break;
41495b482a8SLen Brown 
41595b482a8SLen Brown 	default:
41695b482a8SLen Brown 		return;
41795b482a8SLen Brown 	}
41895b482a8SLen Brown 
41995b482a8SLen Brown 	/* Replace the existing reference object */
42095b482a8SLen Brown 
42195b482a8SLen Brown 	if (obj_desc) {
42295b482a8SLen Brown 		acpi_ut_add_reference(obj_desc);
42395b482a8SLen Brown 		acpi_ut_remove_reference(info->return_object);
42495b482a8SLen Brown 		info->return_object = obj_desc;
42595b482a8SLen Brown 	}
42695b482a8SLen Brown 
42795b482a8SLen Brown 	return;
42895b482a8SLen Brown }
42995b482a8SLen Brown 
43095b482a8SLen Brown /*******************************************************************************
43195b482a8SLen Brown  *
43295b482a8SLen Brown  * FUNCTION:    acpi_walk_namespace
43395b482a8SLen Brown  *
434ba494beeSBob Moore  * PARAMETERS:  type                - acpi_object_type to search for
43595b482a8SLen Brown  *              start_object        - Handle in namespace where search begins
43695b482a8SLen Brown  *              max_depth           - Depth to which search is to reach
4372263576cSLin Ming  *              pre_order_visit     - Called during tree pre-order visit
4382263576cSLin Ming  *                                    when an object of "Type" is found
4392263576cSLin Ming  *              post_order_visit    - Called during tree post-order visit
4402263576cSLin Ming  *                                    when an object of "Type" is found
441ba494beeSBob Moore  *              context             - Passed to user function(s) above
44295b482a8SLen Brown  *              return_value        - Location where return value of
44395b482a8SLen Brown  *                                    user_function is put if terminated early
44495b482a8SLen Brown  *
44595b482a8SLen Brown  * RETURNS      Return value from the user_function if terminated early.
44695b482a8SLen Brown  *              Otherwise, returns NULL.
44795b482a8SLen Brown  *
44895b482a8SLen Brown  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
44995b482a8SLen Brown  *              starting (and ending) at the object specified by start_handle.
4502263576cSLin Ming  *              The callback function is called whenever an object that matches
4512263576cSLin Ming  *              the type parameter is found. If the callback function returns
45295b482a8SLen Brown  *              a non-zero value, the search is terminated immediately and this
45395b482a8SLen Brown  *              value is returned to the caller.
45495b482a8SLen Brown  *
45595b482a8SLen Brown  *              The point of this procedure is to provide a generic namespace
45695b482a8SLen Brown  *              walk routine that can be called from multiple places to
4572263576cSLin Ming  *              provide multiple services; the callback function(s) can be
4582263576cSLin Ming  *              tailored to each task, whether it is a print function,
4592263576cSLin Ming  *              a compare function, etc.
46095b482a8SLen Brown  *
46195b482a8SLen Brown  ******************************************************************************/
46295b482a8SLen Brown 
46395b482a8SLen Brown acpi_status
46495b482a8SLen Brown acpi_walk_namespace(acpi_object_type type,
46595b482a8SLen Brown 		    acpi_handle start_object,
46695b482a8SLen Brown 		    u32 max_depth,
4672263576cSLin Ming 		    acpi_walk_callback pre_order_visit,
4682263576cSLin Ming 		    acpi_walk_callback post_order_visit,
46995b482a8SLen Brown 		    void *context, void **return_value)
47095b482a8SLen Brown {
47195b482a8SLen Brown 	acpi_status status;
47295b482a8SLen Brown 
47395b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_walk_namespace);
47495b482a8SLen Brown 
47595b482a8SLen Brown 	/* Parameter validation */
47695b482a8SLen Brown 
4772263576cSLin Ming 	if ((type > ACPI_TYPE_LOCAL_MAX) ||
4782263576cSLin Ming 	    (!max_depth) || (!pre_order_visit && !post_order_visit)) {
47995b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
48095b482a8SLen Brown 	}
48195b482a8SLen Brown 
48295b482a8SLen Brown 	/*
4838a335a23SBob Moore 	 * Need to acquire the namespace reader lock to prevent interference
4848a335a23SBob Moore 	 * with any concurrent table unloads (which causes the deletion of
4858a335a23SBob Moore 	 * namespace objects). We cannot allow the deletion of a namespace node
4868a335a23SBob Moore 	 * while the user function is using it. The exception to this are the
4878a335a23SBob Moore 	 * nodes created and deleted during control method execution -- these
4888a335a23SBob Moore 	 * nodes are marked as temporary nodes and are ignored by the namespace
4898a335a23SBob Moore 	 * walk. Thus, control methods can be executed while holding the
4908a335a23SBob Moore 	 * namespace deletion lock (and the user function can execute control
4918a335a23SBob Moore 	 * methods.)
4928a335a23SBob Moore 	 */
4938a335a23SBob Moore 	status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
4948a335a23SBob Moore 	if (ACPI_FAILURE(status)) {
4958a335a23SBob Moore 		return status;
4968a335a23SBob Moore 	}
4978a335a23SBob Moore 
4988a335a23SBob Moore 	/*
4998a335a23SBob Moore 	 * Lock the namespace around the walk. The namespace will be
5008a335a23SBob Moore 	 * unlocked/locked around each call to the user function - since the user
5018a335a23SBob Moore 	 * function must be allowed to make ACPICA calls itself (for example, it
5028a335a23SBob Moore 	 * will typically execute control methods during device enumeration.)
50395b482a8SLen Brown 	 */
50495b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
50595b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
5068a335a23SBob Moore 		goto unlock_and_exit;
50795b482a8SLen Brown 	}
50895b482a8SLen Brown 
50995b482a8SLen Brown 	status = acpi_ns_walk_namespace(type, start_object, max_depth,
5102263576cSLin Ming 					ACPI_NS_WALK_UNLOCK, pre_order_visit,
5112263576cSLin Ming 					post_order_visit, context,
5122263576cSLin Ming 					return_value);
51395b482a8SLen Brown 
51495b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
5158a335a23SBob Moore 
5168a335a23SBob Moore       unlock_and_exit:
5178a335a23SBob Moore 	(void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
51895b482a8SLen Brown 	return_ACPI_STATUS(status);
51995b482a8SLen Brown }
52095b482a8SLen Brown 
52195b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
52295b482a8SLen Brown 
52395b482a8SLen Brown /*******************************************************************************
52495b482a8SLen Brown  *
52595b482a8SLen Brown  * FUNCTION:    acpi_ns_get_device_callback
52695b482a8SLen Brown  *
52795b482a8SLen Brown  * PARAMETERS:  Callback from acpi_get_device
52895b482a8SLen Brown  *
52995b482a8SLen Brown  * RETURN:      Status
53095b482a8SLen Brown  *
53195b482a8SLen Brown  * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
53295b482a8SLen Brown  *              present devices, or if they specified a HID, it filters based
53395b482a8SLen Brown  *              on that.
53495b482a8SLen Brown  *
53595b482a8SLen Brown  ******************************************************************************/
53695b482a8SLen Brown static acpi_status
53795b482a8SLen Brown acpi_ns_get_device_callback(acpi_handle obj_handle,
53895b482a8SLen Brown 			    u32 nesting_level,
53995b482a8SLen Brown 			    void *context, void **return_value)
54095b482a8SLen Brown {
54195b482a8SLen Brown 	struct acpi_get_devices_info *info = context;
54295b482a8SLen Brown 	acpi_status status;
54395b482a8SLen Brown 	struct acpi_namespace_node *node;
54495b482a8SLen Brown 	u32 flags;
54578e25fefSLv Zheng 	struct acpi_pnp_device_id *hid;
54678e25fefSLv Zheng 	struct acpi_pnp_device_id_list *cid;
54795b482a8SLen Brown 	u32 i;
54815b8dd53SBob Moore 	u8 found;
54915b8dd53SBob Moore 	int no_match;
55095b482a8SLen Brown 
55195b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
55295b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
55368aafc35SBob Moore 		return_ACPI_STATUS(status);
55495b482a8SLen Brown 	}
55595b482a8SLen Brown 
556f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
55795b482a8SLen Brown 	status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
55895b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
55995b482a8SLen Brown 		return (status);
56095b482a8SLen Brown 	}
56195b482a8SLen Brown 
56295b482a8SLen Brown 	if (!node) {
56395b482a8SLen Brown 		return (AE_BAD_PARAMETER);
56495b482a8SLen Brown 	}
56595b482a8SLen Brown 
56695b482a8SLen Brown 	/*
5675f8902acSLin Ming 	 * First, filter based on the device HID and CID.
5685f8902acSLin Ming 	 *
5695f8902acSLin Ming 	 * 01/2010: For this case where a specific HID is requested, we don't
5705f8902acSLin Ming 	 * want to run _STA until we have an actual HID match. Thus, we will
5715f8902acSLin Ming 	 * not unnecessarily execute _STA on devices for which the caller
5725f8902acSLin Ming 	 * doesn't care about. Previously, _STA was executed unconditionally
5735f8902acSLin Ming 	 * on all devices found here.
5745f8902acSLin Ming 	 *
5755f8902acSLin Ming 	 * A side-effect of this change is that now we will continue to search
5765f8902acSLin Ming 	 * for a matching HID even under device trees where the parent device
5775f8902acSLin Ming 	 * would have returned a _STA that indicates it is not present or
5785f8902acSLin Ming 	 * not functioning (thus aborting the search on that branch).
57995b482a8SLen Brown 	 */
58095b482a8SLen Brown 	if (info->hid != NULL) {
58195b482a8SLen Brown 		status = acpi_ut_execute_HID(node, &hid);
58295b482a8SLen Brown 		if (status == AE_NOT_FOUND) {
58395b482a8SLen Brown 			return (AE_OK);
58495b482a8SLen Brown 		} else if (ACPI_FAILURE(status)) {
58595b482a8SLen Brown 			return (AE_CTRL_DEPTH);
58695b482a8SLen Brown 		}
58795b482a8SLen Brown 
58815b8dd53SBob Moore 		no_match = ACPI_STRCMP(hid->string, info->hid);
58915b8dd53SBob Moore 		ACPI_FREE(hid);
59095b482a8SLen Brown 
59115b8dd53SBob Moore 		if (no_match) {
59215b8dd53SBob Moore 			/*
59315b8dd53SBob Moore 			 * HID does not match, attempt match within the
59415b8dd53SBob Moore 			 * list of Compatible IDs (CIDs)
59515b8dd53SBob Moore 			 */
59695b482a8SLen Brown 			status = acpi_ut_execute_CID(node, &cid);
59795b482a8SLen Brown 			if (status == AE_NOT_FOUND) {
59895b482a8SLen Brown 				return (AE_OK);
59995b482a8SLen Brown 			} else if (ACPI_FAILURE(status)) {
60095b482a8SLen Brown 				return (AE_CTRL_DEPTH);
60195b482a8SLen Brown 			}
60295b482a8SLen Brown 
60395b482a8SLen Brown 			/* Walk the CID list */
60495b482a8SLen Brown 
605739dcbb9SLv Zheng 			found = FALSE;
60695b482a8SLen Brown 			for (i = 0; i < cid->count; i++) {
60715b8dd53SBob Moore 				if (ACPI_STRCMP(cid->ids[i].string, info->hid)
60815b8dd53SBob Moore 				    == 0) {
609*3e8214e5SLv Zheng 
61075c8044fSLv Zheng 					/* Found a matching CID */
611*3e8214e5SLv Zheng 
612739dcbb9SLv Zheng 					found = TRUE;
61395b482a8SLen Brown 					break;
61495b482a8SLen Brown 				}
61595b482a8SLen Brown 			}
616739dcbb9SLv Zheng 
61795b482a8SLen Brown 			ACPI_FREE(cid);
618739dcbb9SLv Zheng 			if (!found) {
61995b482a8SLen Brown 				return (AE_OK);
62095b482a8SLen Brown 			}
62195b482a8SLen Brown 		}
622739dcbb9SLv Zheng 	}
62395b482a8SLen Brown 
6245f8902acSLin Ming 	/* Run _STA to determine if device is present */
6255f8902acSLin Ming 
6265f8902acSLin Ming 	status = acpi_ut_execute_STA(node, &flags);
6275f8902acSLin Ming 	if (ACPI_FAILURE(status)) {
6285f8902acSLin Ming 		return (AE_CTRL_DEPTH);
6295f8902acSLin Ming 	}
6305f8902acSLin Ming 
6315f8902acSLin Ming 	if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
6325f8902acSLin Ming 	    !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
6335f8902acSLin Ming 		/*
6345f8902acSLin Ming 		 * Don't examine the children of the device only when the
6355f8902acSLin Ming 		 * device is neither present nor functional. See ACPI spec,
6365f8902acSLin Ming 		 * description of _STA for more information.
6375f8902acSLin Ming 		 */
6385f8902acSLin Ming 		return (AE_CTRL_DEPTH);
6395f8902acSLin Ming 	}
6405f8902acSLin Ming 
6415f8902acSLin Ming 	/* We have a valid device, invoke the user function */
6425f8902acSLin Ming 
64395b482a8SLen Brown 	status = info->user_function(obj_handle, nesting_level, info->context,
64495b482a8SLen Brown 				     return_value);
64595b482a8SLen Brown 	return (status);
64695b482a8SLen Brown }
64795b482a8SLen Brown 
64895b482a8SLen Brown /*******************************************************************************
64995b482a8SLen Brown  *
65095b482a8SLen Brown  * FUNCTION:    acpi_get_devices
65195b482a8SLen Brown  *
65295b482a8SLen Brown  * PARAMETERS:  HID                 - HID to search for. Can be NULL.
65395b482a8SLen Brown  *              user_function       - Called when a matching object is found
654ba494beeSBob Moore  *              context             - Passed to user function
65595b482a8SLen Brown  *              return_value        - Location where return value of
65695b482a8SLen Brown  *                                    user_function is put if terminated early
65795b482a8SLen Brown  *
65895b482a8SLen Brown  * RETURNS      Return value from the user_function if terminated early.
65995b482a8SLen Brown  *              Otherwise, returns NULL.
66095b482a8SLen Brown  *
66195b482a8SLen Brown  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
66295b482a8SLen Brown  *              starting (and ending) at the object specified by start_handle.
66395b482a8SLen Brown  *              The user_function is called whenever an object of type
66495b482a8SLen Brown  *              Device is found. If the user function returns
66595b482a8SLen Brown  *              a non-zero value, the search is terminated immediately and this
66695b482a8SLen Brown  *              value is returned to the caller.
66795b482a8SLen Brown  *
66895b482a8SLen Brown  *              This is a wrapper for walk_namespace, but the callback performs
66995b482a8SLen Brown  *              additional filtering. Please see acpi_ns_get_device_callback.
67095b482a8SLen Brown  *
67195b482a8SLen Brown  ******************************************************************************/
67295b482a8SLen Brown 
67395b482a8SLen Brown acpi_status
67495b482a8SLen Brown acpi_get_devices(const char *HID,
67595b482a8SLen Brown 		 acpi_walk_callback user_function,
67695b482a8SLen Brown 		 void *context, void **return_value)
67795b482a8SLen Brown {
67895b482a8SLen Brown 	acpi_status status;
67995b482a8SLen Brown 	struct acpi_get_devices_info info;
68095b482a8SLen Brown 
68195b482a8SLen Brown 	ACPI_FUNCTION_TRACE(acpi_get_devices);
68295b482a8SLen Brown 
68395b482a8SLen Brown 	/* Parameter validation */
68495b482a8SLen Brown 
68595b482a8SLen Brown 	if (!user_function) {
68695b482a8SLen Brown 		return_ACPI_STATUS(AE_BAD_PARAMETER);
68795b482a8SLen Brown 	}
68895b482a8SLen Brown 
68995b482a8SLen Brown 	/*
69095b482a8SLen Brown 	 * We're going to call their callback from OUR callback, so we need
69195b482a8SLen Brown 	 * to know what it is, and their context parameter.
69295b482a8SLen Brown 	 */
69395b482a8SLen Brown 	info.hid = HID;
69495b482a8SLen Brown 	info.context = context;
69595b482a8SLen Brown 	info.user_function = user_function;
69695b482a8SLen Brown 
69795b482a8SLen Brown 	/*
69895b482a8SLen Brown 	 * Lock the namespace around the walk.
69995b482a8SLen Brown 	 * The namespace will be unlocked/locked around each call
70095b482a8SLen Brown 	 * to the user function - since this function
70195b482a8SLen Brown 	 * must be allowed to make Acpi calls itself.
70295b482a8SLen Brown 	 */
70395b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
70495b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
70595b482a8SLen Brown 		return_ACPI_STATUS(status);
70695b482a8SLen Brown 	}
70795b482a8SLen Brown 
70895b482a8SLen Brown 	status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
70995b482a8SLen Brown 					ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
7102263576cSLin Ming 					acpi_ns_get_device_callback, NULL,
7112263576cSLin Ming 					&info, return_value);
71295b482a8SLen Brown 
71395b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
71495b482a8SLen Brown 	return_ACPI_STATUS(status);
71595b482a8SLen Brown }
71695b482a8SLen Brown 
71795b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_devices)
71895b482a8SLen Brown 
71995b482a8SLen Brown /*******************************************************************************
72095b482a8SLen Brown  *
72195b482a8SLen Brown  * FUNCTION:    acpi_attach_data
72295b482a8SLen Brown  *
72395b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node
724ba494beeSBob Moore  *              handler             - Handler for this attachment
725ba494beeSBob Moore  *              data                - Pointer to data to be attached
72695b482a8SLen Brown  *
72795b482a8SLen Brown  * RETURN:      Status
72895b482a8SLen Brown  *
72995b482a8SLen Brown  * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
73095b482a8SLen Brown  *
73195b482a8SLen Brown  ******************************************************************************/
73295b482a8SLen Brown acpi_status
73395b482a8SLen Brown acpi_attach_data(acpi_handle obj_handle,
73495b482a8SLen Brown 		 acpi_object_handler handler, void *data)
73595b482a8SLen Brown {
73695b482a8SLen Brown 	struct acpi_namespace_node *node;
73795b482a8SLen Brown 	acpi_status status;
73895b482a8SLen Brown 
73995b482a8SLen Brown 	/* Parameter validation */
74095b482a8SLen Brown 
74195b482a8SLen Brown 	if (!obj_handle || !handler || !data) {
74295b482a8SLen Brown 		return (AE_BAD_PARAMETER);
74395b482a8SLen Brown 	}
74495b482a8SLen Brown 
74595b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
74695b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
74795b482a8SLen Brown 		return (status);
74895b482a8SLen Brown 	}
74995b482a8SLen Brown 
75095b482a8SLen Brown 	/* Convert and validate the handle */
75195b482a8SLen Brown 
752f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
75395b482a8SLen Brown 	if (!node) {
75495b482a8SLen Brown 		status = AE_BAD_PARAMETER;
75595b482a8SLen Brown 		goto unlock_and_exit;
75695b482a8SLen Brown 	}
75795b482a8SLen Brown 
75895b482a8SLen Brown 	status = acpi_ns_attach_data(node, handler, data);
75995b482a8SLen Brown 
76095b482a8SLen Brown       unlock_and_exit:
76195b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
76295b482a8SLen Brown 	return (status);
76395b482a8SLen Brown }
76495b482a8SLen Brown 
76595b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_attach_data)
76695b482a8SLen Brown 
76795b482a8SLen Brown /*******************************************************************************
76895b482a8SLen Brown  *
76995b482a8SLen Brown  * FUNCTION:    acpi_detach_data
77095b482a8SLen Brown  *
77195b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node handle
772ba494beeSBob Moore  *              handler             - Handler used in call to acpi_attach_data
77395b482a8SLen Brown  *
77495b482a8SLen Brown  * RETURN:      Status
77595b482a8SLen Brown  *
77695b482a8SLen Brown  * DESCRIPTION: Remove data that was previously attached to a node.
77795b482a8SLen Brown  *
77895b482a8SLen Brown  ******************************************************************************/
77995b482a8SLen Brown acpi_status
78095b482a8SLen Brown acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
78195b482a8SLen Brown {
78295b482a8SLen Brown 	struct acpi_namespace_node *node;
78395b482a8SLen Brown 	acpi_status status;
78495b482a8SLen Brown 
78595b482a8SLen Brown 	/* Parameter validation */
78695b482a8SLen Brown 
78795b482a8SLen Brown 	if (!obj_handle || !handler) {
78895b482a8SLen Brown 		return (AE_BAD_PARAMETER);
78995b482a8SLen Brown 	}
79095b482a8SLen Brown 
79195b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
79295b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
79395b482a8SLen Brown 		return (status);
79495b482a8SLen Brown 	}
79595b482a8SLen Brown 
79695b482a8SLen Brown 	/* Convert and validate the handle */
79795b482a8SLen Brown 
798f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
79995b482a8SLen Brown 	if (!node) {
80095b482a8SLen Brown 		status = AE_BAD_PARAMETER;
80195b482a8SLen Brown 		goto unlock_and_exit;
80295b482a8SLen Brown 	}
80395b482a8SLen Brown 
80495b482a8SLen Brown 	status = acpi_ns_detach_data(node, handler);
80595b482a8SLen Brown 
80695b482a8SLen Brown       unlock_and_exit:
80795b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
80895b482a8SLen Brown 	return (status);
80995b482a8SLen Brown }
81095b482a8SLen Brown 
81195b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_detach_data)
81295b482a8SLen Brown 
81395b482a8SLen Brown /*******************************************************************************
81495b482a8SLen Brown  *
81595b482a8SLen Brown  * FUNCTION:    acpi_get_data
81695b482a8SLen Brown  *
81795b482a8SLen Brown  * PARAMETERS:  obj_handle          - Namespace node
818ba494beeSBob Moore  *              handler             - Handler used in call to attach_data
819ba494beeSBob Moore  *              data                - Where the data is returned
82095b482a8SLen Brown  *
82195b482a8SLen Brown  * RETURN:      Status
82295b482a8SLen Brown  *
82395b482a8SLen Brown  * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
82495b482a8SLen Brown  *
82595b482a8SLen Brown  ******************************************************************************/
82695b482a8SLen Brown acpi_status
82795b482a8SLen Brown acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
82895b482a8SLen Brown {
82995b482a8SLen Brown 	struct acpi_namespace_node *node;
83095b482a8SLen Brown 	acpi_status status;
83195b482a8SLen Brown 
83295b482a8SLen Brown 	/* Parameter validation */
83395b482a8SLen Brown 
83495b482a8SLen Brown 	if (!obj_handle || !handler || !data) {
83595b482a8SLen Brown 		return (AE_BAD_PARAMETER);
83695b482a8SLen Brown 	}
83795b482a8SLen Brown 
83895b482a8SLen Brown 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
83995b482a8SLen Brown 	if (ACPI_FAILURE(status)) {
84095b482a8SLen Brown 		return (status);
84195b482a8SLen Brown 	}
84295b482a8SLen Brown 
84395b482a8SLen Brown 	/* Convert and validate the handle */
84495b482a8SLen Brown 
845f24b664dSBob Moore 	node = acpi_ns_validate_handle(obj_handle);
84695b482a8SLen Brown 	if (!node) {
84795b482a8SLen Brown 		status = AE_BAD_PARAMETER;
84895b482a8SLen Brown 		goto unlock_and_exit;
84995b482a8SLen Brown 	}
85095b482a8SLen Brown 
85195b482a8SLen Brown 	status = acpi_ns_get_attached_data(node, handler, data);
85295b482a8SLen Brown 
85395b482a8SLen Brown       unlock_and_exit:
85495b482a8SLen Brown 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
85595b482a8SLen Brown 	return (status);
85695b482a8SLen Brown }
85795b482a8SLen Brown 
85895b482a8SLen Brown ACPI_EXPORT_SYMBOL(acpi_get_data)
859