| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /******************************************************************************* | 
 | 2 |  * | 
 | 3 |  * Module Name: nsxfeval - Public interfaces to the ACPI subsystem | 
 | 4 |  *                         ACPI Object evaluation interfaces | 
 | 5 |  * | 
 | 6 |  ******************************************************************************/ | 
 | 7 |  | 
 | 8 | /* | 
| Bob Moore | 4a90c7e | 2006-01-13 16:22:00 -0500 | [diff] [blame] | 9 |  * Copyright (C) 2000 - 2006, R. Byron Moore | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 |  * All rights reserved. | 
 | 11 |  * | 
 | 12 |  * Redistribution and use in source and binary forms, with or without | 
 | 13 |  * modification, are permitted provided that the following conditions | 
 | 14 |  * are met: | 
 | 15 |  * 1. Redistributions of source code must retain the above copyright | 
 | 16 |  *    notice, this list of conditions, and the following disclaimer, | 
 | 17 |  *    without modification. | 
 | 18 |  * 2. Redistributions in binary form must reproduce at minimum a disclaimer | 
 | 19 |  *    substantially similar to the "NO WARRANTY" disclaimer below | 
 | 20 |  *    ("Disclaimer") and any redistribution must be conditioned upon | 
 | 21 |  *    including a substantially similar Disclaimer requirement for further | 
 | 22 |  *    binary redistribution. | 
 | 23 |  * 3. Neither the names of the above-listed copyright holders nor the names | 
 | 24 |  *    of any contributors may be used to endorse or promote products derived | 
 | 25 |  *    from this software without specific prior written permission. | 
 | 26 |  * | 
 | 27 |  * Alternatively, this software may be distributed under the terms of the | 
 | 28 |  * GNU General Public License ("GPL") version 2 as published by the Free | 
 | 29 |  * Software Foundation. | 
 | 30 |  * | 
 | 31 |  * NO WARRANTY | 
 | 32 |  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | 
 | 33 |  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | 
 | 34 |  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR | 
 | 35 |  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | 
 | 36 |  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | 
 | 37 |  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | 
 | 38 |  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | 
 | 39 |  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | 
 | 40 |  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING | 
 | 41 |  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | 
 | 42 |  * POSSIBILITY OF SUCH DAMAGES. | 
 | 43 |  */ | 
 | 44 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | #include <acpi/acpi.h> | 
 | 46 | #include <acpi/acnamesp.h> | 
 | 47 | #include <acpi/acinterp.h> | 
 | 48 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | #define _COMPONENT          ACPI_NAMESPACE | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 50 | ACPI_MODULE_NAME("nsxfeval") | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 51 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 52 | #ifdef ACPI_FUTURE_USAGE | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 53 | /******************************************************************************* | 
 | 54 |  * | 
 | 55 |  * FUNCTION:    acpi_evaluate_object_typed | 
 | 56 |  * | 
 | 57 |  * PARAMETERS:  Handle              - Object handle (optional) | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 58 |  *              Pathname            - Object pathname (optional) | 
 | 59 |  *              external_params     - List of parameters to pass to method, | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 |  *                                    terminated by NULL.  May be NULL | 
 | 61 |  *                                    if no parameters are being passed. | 
| Robert Moore | 44f6c01 | 2005-04-18 22:49:35 -0400 | [diff] [blame] | 62 |  *              return_buffer       - Where to put method's return value (if | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 |  *                                    any).  If NULL, no value is returned. | 
 | 64 |  *              return_type         - Expected type of return object | 
 | 65 |  * | 
 | 66 |  * RETURN:      Status | 
 | 67 |  * | 
 | 68 |  * DESCRIPTION: Find and evaluate the given object, passing the given | 
 | 69 |  *              parameters if necessary.  One of "Handle" or "Pathname" must | 
 | 70 |  *              be valid (non-null) | 
 | 71 |  * | 
 | 72 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 74 | acpi_evaluate_object_typed(acpi_handle handle, | 
 | 75 | 			   acpi_string pathname, | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 76 | 			   struct acpi_object_list * external_params, | 
 | 77 | 			   struct acpi_buffer * return_buffer, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 78 | 			   acpi_object_type return_type) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 80 | 	acpi_status status; | 
 | 81 | 	u8 must_free = FALSE; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 83 | 	ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 |  | 
 | 85 | 	/* Return buffer must be valid */ | 
 | 86 |  | 
 | 87 | 	if (!return_buffer) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 88 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | 	} | 
 | 90 |  | 
 | 91 | 	if (return_buffer->length == ACPI_ALLOCATE_BUFFER) { | 
 | 92 | 		must_free = TRUE; | 
 | 93 | 	} | 
 | 94 |  | 
 | 95 | 	/* Evaluate the object */ | 
 | 96 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 97 | 	status = | 
 | 98 | 	    acpi_evaluate_object(handle, pathname, external_params, | 
 | 99 | 				 return_buffer); | 
 | 100 | 	if (ACPI_FAILURE(status)) { | 
 | 101 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | 	} | 
 | 103 |  | 
 | 104 | 	/* Type ANY means "don't care" */ | 
 | 105 |  | 
 | 106 | 	if (return_type == ACPI_TYPE_ANY) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 107 | 		return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 108 | 	} | 
 | 109 |  | 
 | 110 | 	if (return_buffer->length == 0) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 111 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | 		/* Error because caller specifically asked for a return value */ | 
 | 113 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 114 | 		ACPI_ERROR((AE_INFO, "No return value")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 115 | 		return_ACPI_STATUS(AE_NULL_OBJECT); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | 	} | 
 | 117 |  | 
 | 118 | 	/* Examine the object type returned from evaluate_object */ | 
 | 119 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 120 | 	if (((union acpi_object *)return_buffer->pointer)->type == return_type) { | 
 | 121 | 		return_ACPI_STATUS(AE_OK); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | 	} | 
 | 123 |  | 
 | 124 | 	/* Return object type does not match requested type */ | 
 | 125 |  | 
| Bob Moore | b8e4d89 | 2006-01-27 16:43:00 -0500 | [diff] [blame] | 126 | 	ACPI_ERROR((AE_INFO, | 
 | 127 | 		    "Incorrect return type [%s] requested [%s]", | 
 | 128 | 		    acpi_ut_get_type_name(((union acpi_object *)return_buffer-> | 
 | 129 | 					   pointer)->type), | 
 | 130 | 		    acpi_ut_get_type_name(return_type))); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 |  | 
 | 132 | 	if (must_free) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 133 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | 		/* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */ | 
 | 135 |  | 
| Len Brown | 02438d8 | 2006-06-30 03:19:10 -0400 | [diff] [blame] | 136 | 		ACPI_FREE(return_buffer->pointer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | 		return_buffer->pointer = NULL; | 
 | 138 | 	} | 
 | 139 |  | 
 | 140 | 	return_buffer->length = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 141 | 	return_ACPI_STATUS(AE_TYPE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 142 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 143 |  | 
 | 144 | ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed) | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 145 | #endif				/*  ACPI_FUTURE_USAGE  */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 |  | 
 | 147 | /******************************************************************************* | 
 | 148 |  * | 
 | 149 |  * FUNCTION:    acpi_evaluate_object | 
 | 150 |  * | 
 | 151 |  * PARAMETERS:  Handle              - Object handle (optional) | 
 | 152 |  *              Pathname            - Object pathname (optional) | 
 | 153 |  *              external_params     - List of parameters to pass to method, | 
 | 154 |  *                                    terminated by NULL.  May be NULL | 
 | 155 |  *                                    if no parameters are being passed. | 
 | 156 |  *              return_buffer       - Where to put method's return value (if | 
 | 157 |  *                                    any).  If NULL, no value is returned. | 
 | 158 |  * | 
 | 159 |  * RETURN:      Status | 
 | 160 |  * | 
 | 161 |  * DESCRIPTION: Find and evaluate the given object, passing the given | 
 | 162 |  *              parameters if necessary.  One of "Handle" or "Pathname" must | 
 | 163 |  *              be valid (non-null) | 
 | 164 |  * | 
 | 165 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 167 | acpi_evaluate_object(acpi_handle handle, | 
 | 168 | 		     acpi_string pathname, | 
 | 169 | 		     struct acpi_object_list *external_params, | 
 | 170 | 		     struct acpi_buffer *return_buffer) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 171 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 172 | 	acpi_status status; | 
 | 173 | 	acpi_status status2; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 174 | 	struct acpi_evaluate_info *info; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 175 | 	acpi_size buffer_space_needed; | 
 | 176 | 	u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 177 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 178 | 	ACPI_FUNCTION_TRACE(acpi_evaluate_object); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 179 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 180 | 	/* Allocate and initialize the evaluation information block */ | 
 | 181 |  | 
 | 182 | 	info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | 
 | 183 | 	if (!info) { | 
 | 184 | 		return_ACPI_STATUS(AE_NO_MEMORY); | 
 | 185 | 	} | 
 | 186 |  | 
 | 187 | 	info->pathname = pathname; | 
 | 188 | 	info->parameter_type = ACPI_PARAM_ARGS; | 
 | 189 |  | 
 | 190 | 	/* Convert and validate the device handle */ | 
 | 191 |  | 
 | 192 | 	info->prefix_node = acpi_ns_map_handle_to_node(handle); | 
 | 193 | 	if (!info->prefix_node) { | 
 | 194 | 		status = AE_BAD_PARAMETER; | 
 | 195 | 		goto cleanup; | 
 | 196 | 	} | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 |  | 
 | 198 | 	/* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 199 | 	 * If there are parameters to be passed to a control method, the external | 
 | 200 | 	 * objects must all be converted to internal objects | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | 	 */ | 
 | 202 | 	if (external_params && external_params->count) { | 
 | 203 | 		/* | 
 | 204 | 		 * Allocate a new parameter block for the internal objects | 
 | 205 | 		 * Add 1 to count to allow for null terminated internal list | 
 | 206 | 		 */ | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 207 | 		info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) | 
 | 208 | 							 external_params-> | 
 | 209 | 							 count + | 
 | 210 | 							 1) * sizeof(void *)); | 
 | 211 | 		if (!info->parameters) { | 
 | 212 | 			status = AE_NO_MEMORY; | 
 | 213 | 			goto cleanup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | 		} | 
 | 215 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 216 | 		/* Convert each external object in the list to an internal object */ | 
 | 217 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | 		for (i = 0; i < external_params->count; i++) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 219 | 			status = | 
 | 220 | 			    acpi_ut_copy_eobject_to_iobject(&external_params-> | 
 | 221 | 							    pointer[i], | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 222 | 							    &info-> | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 223 | 							    parameters[i]); | 
 | 224 | 			if (ACPI_FAILURE(status)) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 225 | 				goto cleanup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | 			} | 
 | 227 | 		} | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 228 | 		info->parameters[external_params->count] = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | 	} | 
 | 230 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 231 | 	/* | 
 | 232 | 	 * Three major cases: | 
 | 233 | 	 * 1) Fully qualified pathname | 
 | 234 | 	 * 2) No handle, not fully qualified pathname (error) | 
 | 235 | 	 * 3) Valid handle | 
 | 236 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 237 | 	if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 238 |  | 
 | 239 | 		/* The path is fully qualified, just evaluate by name */ | 
 | 240 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 241 | 		info->prefix_node = NULL; | 
 | 242 | 		status = acpi_ns_evaluate(info); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 243 | 	} else if (!handle) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | 		/* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 245 | 		 * A handle is optional iff a fully qualified pathname is specified. | 
 | 246 | 		 * Since we've already handled fully qualified names above, this is | 
 | 247 | 		 * an error | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 248 | 		 */ | 
 | 249 | 		if (!pathname) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 250 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 251 | 					  "Both Handle and Pathname are NULL")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 252 | 		} else { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 253 | 			ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 254 | 					  "Null Handle with relative pathname [%s]", | 
 | 255 | 					  pathname)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | 		} | 
 | 257 |  | 
 | 258 | 		status = AE_BAD_PARAMETER; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 259 | 	} else { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 260 | 		/* We have a namespace a node and a possible relative path */ | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 261 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 262 | 		status = acpi_ns_evaluate(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | 	} | 
 | 264 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 265 | 	/* | 
 | 266 | 	 * If we are expecting a return value, and all went well above, | 
 | 267 | 	 * copy the return value to an external object. | 
 | 268 | 	 */ | 
 | 269 | 	if (return_buffer) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 270 | 		if (!info->return_object) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | 			return_buffer->length = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 272 | 		} else { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 273 | 			if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 274 | 			    ACPI_DESC_TYPE_NAMED) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | 				/* | 
 | 276 | 				 * If we received a NS Node as a return object, this means that | 
 | 277 | 				 * the object we are evaluating has nothing interesting to | 
 | 278 | 				 * return (such as a mutex, etc.)  We return an error because | 
 | 279 | 				 * these types are essentially unsupported by this interface. | 
 | 280 | 				 * We don't check up front because this makes it easier to add | 
 | 281 | 				 * support for various types at a later date if necessary. | 
 | 282 | 				 */ | 
 | 283 | 				status = AE_TYPE; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 284 | 				info->return_object = NULL;	/* No need to delete a NS Node */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | 				return_buffer->length = 0; | 
 | 286 | 			} | 
 | 287 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 288 | 			if (ACPI_SUCCESS(status)) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 289 |  | 
 | 290 | 				/* Get the size of the returned object */ | 
 | 291 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 292 | 				status = | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 293 | 				    acpi_ut_get_object_size(info->return_object, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 294 | 							    &buffer_space_needed); | 
 | 295 | 				if (ACPI_SUCCESS(status)) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 296 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | 					/* Validate/Allocate/Clear caller buffer */ | 
 | 298 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 299 | 					status = | 
 | 300 | 					    acpi_ut_initialize_buffer | 
 | 301 | 					    (return_buffer, | 
 | 302 | 					     buffer_space_needed); | 
 | 303 | 					if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | 						/* | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 305 | 						 * Caller's buffer is too small or a new one can't | 
 | 306 | 						 * be allocated | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | 						 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 308 | 						ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
 | 309 | 								  "Needed buffer size %X, %s\n", | 
 | 310 | 								  (u32) | 
 | 311 | 								  buffer_space_needed, | 
 | 312 | 								  acpi_format_exception | 
 | 313 | 								  (status))); | 
 | 314 | 					} else { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 315 | 						/* We have enough space for the object, build it */ | 
 | 316 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 317 | 						status = | 
 | 318 | 						    acpi_ut_copy_iobject_to_eobject | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 319 | 						    (info->return_object, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 320 | 						     return_buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 321 | 					} | 
 | 322 | 				} | 
 | 323 | 			} | 
 | 324 | 		} | 
 | 325 | 	} | 
 | 326 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 327 | 	if (info->return_object) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | 		/* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 329 | 		 * Delete the internal return object. NOTE: Interpreter must be | 
 | 330 | 		 * locked to avoid race condition. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | 		 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 332 | 		status2 = acpi_ex_enter_interpreter(); | 
 | 333 | 		if (ACPI_SUCCESS(status2)) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 334 |  | 
 | 335 | 			/* Remove one reference on the return object (should delete it) */ | 
 | 336 |  | 
 | 337 | 			acpi_ut_remove_reference(info->return_object); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 338 | 			acpi_ex_exit_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | 		} | 
 | 340 | 	} | 
 | 341 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 342 |       cleanup: | 
 | 343 |  | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 344 | 	/* Free the input parameter list (if we created one) */ | 
 | 345 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 346 | 	if (info->parameters) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 347 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | 		/* Free the allocated parameter block */ | 
 | 349 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 350 | 		acpi_ut_delete_internal_object_list(info->parameters); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 351 | 	} | 
 | 352 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 353 | 	ACPI_FREE(info); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 354 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 357 | ACPI_EXPORT_SYMBOL(acpi_evaluate_object) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 |  | 
 | 359 | /******************************************************************************* | 
 | 360 |  * | 
 | 361 |  * FUNCTION:    acpi_walk_namespace | 
 | 362 |  * | 
 | 363 |  * PARAMETERS:  Type                - acpi_object_type to search for | 
 | 364 |  *              start_object        - Handle in namespace where search begins | 
 | 365 |  *              max_depth           - Depth to which search is to reach | 
 | 366 |  *              user_function       - Called when an object of "Type" is found | 
 | 367 |  *              Context             - Passed to user function | 
 | 368 |  *              return_value        - Location where return value of | 
 | 369 |  *                                    user_function is put if terminated early | 
 | 370 |  * | 
 | 371 |  * RETURNS      Return value from the user_function if terminated early. | 
 | 372 |  *              Otherwise, returns NULL. | 
 | 373 |  * | 
 | 374 |  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, | 
 | 375 |  *              starting (and ending) at the object specified by start_handle. | 
 | 376 |  *              The user_function is called whenever an object that matches | 
 | 377 |  *              the type parameter is found.  If the user function returns | 
 | 378 |  *              a non-zero value, the search is terminated immediately and this | 
 | 379 |  *              value is returned to the caller. | 
 | 380 |  * | 
 | 381 |  *              The point of this procedure is to provide a generic namespace | 
 | 382 |  *              walk routine that can be called from multiple places to | 
 | 383 |  *              provide multiple services;  the User Function can be tailored | 
 | 384 |  *              to each task, whether it is a print function, a compare | 
 | 385 |  *              function, etc. | 
 | 386 |  * | 
 | 387 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 389 | acpi_walk_namespace(acpi_object_type type, | 
 | 390 | 		    acpi_handle start_object, | 
 | 391 | 		    u32 max_depth, | 
 | 392 | 		    acpi_walk_callback user_function, | 
 | 393 | 		    void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 395 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 397 | 	ACPI_FUNCTION_TRACE(acpi_walk_namespace); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 398 |  | 
 | 399 | 	/* Parameter validation */ | 
 | 400 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 401 | 	if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 402 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | 	} | 
 | 404 |  | 
 | 405 | 	/* | 
 | 406 | 	 * Lock the namespace around the walk. | 
 | 407 | 	 * The namespace will be unlocked/locked around each call | 
 | 408 | 	 * to the user function - since this function | 
 | 409 | 	 * must be allowed to make Acpi calls itself. | 
 | 410 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 411 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 412 | 	if (ACPI_FAILURE(status)) { | 
 | 413 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | 	} | 
 | 415 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 416 | 	status = acpi_ns_walk_namespace(type, start_object, max_depth, | 
 | 417 | 					ACPI_NS_WALK_UNLOCK, | 
 | 418 | 					user_function, context, return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 420 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 421 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 423 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 424 | ACPI_EXPORT_SYMBOL(acpi_walk_namespace) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 |  | 
 | 426 | /******************************************************************************* | 
 | 427 |  * | 
 | 428 |  * FUNCTION:    acpi_ns_get_device_callback | 
 | 429 |  * | 
 | 430 |  * PARAMETERS:  Callback from acpi_get_device | 
 | 431 |  * | 
 | 432 |  * RETURN:      Status | 
 | 433 |  * | 
 | 434 |  * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- | 
 | 435 |  *              present devices, or if they specified a HID, it filters based | 
 | 436 |  *              on that. | 
 | 437 |  * | 
 | 438 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 440 | acpi_ns_get_device_callback(acpi_handle obj_handle, | 
 | 441 | 			    u32 nesting_level, | 
 | 442 | 			    void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 443 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 444 | 	struct acpi_get_devices_info *info = context; | 
 | 445 | 	acpi_status status; | 
 | 446 | 	struct acpi_namespace_node *node; | 
 | 447 | 	u32 flags; | 
 | 448 | 	struct acpi_device_id hid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | 	struct acpi_compatible_id_list *cid; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 450 | 	acpi_native_uint i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 452 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 453 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | 		return (status); | 
 | 455 | 	} | 
 | 456 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 457 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
 | 458 | 	status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 459 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 460 | 		return (status); | 
 | 461 | 	} | 
 | 462 |  | 
 | 463 | 	if (!node) { | 
 | 464 | 		return (AE_BAD_PARAMETER); | 
 | 465 | 	} | 
 | 466 |  | 
 | 467 | 	/* Run _STA to determine if device is present */ | 
 | 468 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 469 | 	status = acpi_ut_execute_STA(node, &flags); | 
 | 470 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 471 | 		return (AE_CTRL_DEPTH); | 
 | 472 | 	} | 
 | 473 |  | 
| Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 474 | 	if (!(flags & ACPI_STA_DEVICE_PRESENT)) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 475 |  | 
| Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 476 | 		/* Don't examine children of the device if not present */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 |  | 
 | 478 | 		return (AE_CTRL_DEPTH); | 
 | 479 | 	} | 
 | 480 |  | 
 | 481 | 	/* Filter based on device HID & CID */ | 
 | 482 |  | 
 | 483 | 	if (info->hid != NULL) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | 		status = acpi_ut_execute_HID(node, &hid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | 		if (status == AE_NOT_FOUND) { | 
 | 486 | 			return (AE_OK); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 487 | 		} else if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | 			return (AE_CTRL_DEPTH); | 
 | 489 | 		} | 
 | 490 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 491 | 		if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 492 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | 			/* Get the list of Compatible IDs */ | 
 | 494 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | 			status = acpi_ut_execute_CID(node, &cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | 			if (status == AE_NOT_FOUND) { | 
 | 497 | 				return (AE_OK); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 498 | 			} else if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 499 | 				return (AE_CTRL_DEPTH); | 
 | 500 | 			} | 
 | 501 |  | 
 | 502 | 			/* Walk the CID list */ | 
 | 503 |  | 
 | 504 | 			for (i = 0; i < cid->count; i++) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 505 | 				if (ACPI_STRNCMP(cid->id[i].value, info->hid, | 
 | 506 | 						 sizeof(struct | 
 | 507 | 							acpi_compatible_id)) != | 
 | 508 | 				    0) { | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 509 | 					ACPI_FREE(cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 510 | 					return (AE_OK); | 
 | 511 | 				} | 
 | 512 | 			} | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 513 | 			ACPI_FREE(cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 514 | 		} | 
 | 515 | 	} | 
 | 516 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 517 | 	status = info->user_function(obj_handle, nesting_level, info->context, | 
 | 518 | 				     return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | 	return (status); | 
 | 520 | } | 
 | 521 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | /******************************************************************************* | 
 | 523 |  * | 
 | 524 |  * FUNCTION:    acpi_get_devices | 
 | 525 |  * | 
 | 526 |  * PARAMETERS:  HID                 - HID to search for. Can be NULL. | 
 | 527 |  *              user_function       - Called when a matching object is found | 
 | 528 |  *              Context             - Passed to user function | 
 | 529 |  *              return_value        - Location where return value of | 
 | 530 |  *                                    user_function is put if terminated early | 
 | 531 |  * | 
 | 532 |  * RETURNS      Return value from the user_function if terminated early. | 
 | 533 |  *              Otherwise, returns NULL. | 
 | 534 |  * | 
 | 535 |  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, | 
 | 536 |  *              starting (and ending) at the object specified by start_handle. | 
 | 537 |  *              The user_function is called whenever an object of type | 
 | 538 |  *              Device is found.  If the user function returns | 
 | 539 |  *              a non-zero value, the search is terminated immediately and this | 
 | 540 |  *              value is returned to the caller. | 
 | 541 |  * | 
 | 542 |  *              This is a wrapper for walk_namespace, but the callback performs | 
 | 543 |  *              additional filtering. Please see acpi_get_device_callback. | 
 | 544 |  * | 
 | 545 |  ******************************************************************************/ | 
 | 546 |  | 
 | 547 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 548 | acpi_get_devices(char *HID, | 
 | 549 | 		 acpi_walk_callback user_function, | 
 | 550 | 		 void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 552 | 	acpi_status status; | 
 | 553 | 	struct acpi_get_devices_info info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 555 | 	ACPI_FUNCTION_TRACE(acpi_get_devices); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 |  | 
 | 557 | 	/* Parameter validation */ | 
 | 558 |  | 
 | 559 | 	if (!user_function) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 560 | 		return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | 	} | 
 | 562 |  | 
 | 563 | 	/* | 
 | 564 | 	 * We're going to call their callback from OUR callback, so we need | 
 | 565 | 	 * to know what it is, and their context parameter. | 
 | 566 | 	 */ | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 567 | 	info.hid = HID; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 568 | 	info.context = context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 569 | 	info.user_function = user_function; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 |  | 
 | 571 | 	/* | 
 | 572 | 	 * Lock the namespace around the walk. | 
 | 573 | 	 * The namespace will be unlocked/locked around each call | 
 | 574 | 	 * to the user function - since this function | 
 | 575 | 	 * must be allowed to make Acpi calls itself. | 
 | 576 | 	 */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 577 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 578 | 	if (ACPI_FAILURE(status)) { | 
 | 579 | 		return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 580 | 	} | 
 | 581 |  | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 582 | 	status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 
 | 583 | 					ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 584 | 					acpi_ns_get_device_callback, &info, | 
 | 585 | 					return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 587 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
 | 588 | 	return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 591 | ACPI_EXPORT_SYMBOL(acpi_get_devices) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 592 |  | 
 | 593 | /******************************************************************************* | 
 | 594 |  * | 
 | 595 |  * FUNCTION:    acpi_attach_data | 
 | 596 |  * | 
 | 597 |  * PARAMETERS:  obj_handle          - Namespace node | 
 | 598 |  *              Handler             - Handler for this attachment | 
 | 599 |  *              Data                - Pointer to data to be attached | 
 | 600 |  * | 
 | 601 |  * RETURN:      Status | 
 | 602 |  * | 
 | 603 |  * DESCRIPTION: Attach arbitrary data and handler to a namespace node. | 
 | 604 |  * | 
 | 605 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | acpi_attach_data(acpi_handle obj_handle, | 
 | 608 | 		 acpi_object_handler handler, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 610 | 	struct acpi_namespace_node *node; | 
 | 611 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 |  | 
 | 613 | 	/* Parameter validation */ | 
 | 614 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 615 | 	if (!obj_handle || !handler || !data) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | 		return (AE_BAD_PARAMETER); | 
 | 617 | 	} | 
 | 618 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 619 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 620 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | 		return (status); | 
 | 622 | 	} | 
 | 623 |  | 
 | 624 | 	/* Convert and validate the handle */ | 
 | 625 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 626 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | 	if (!node) { | 
 | 628 | 		status = AE_BAD_PARAMETER; | 
 | 629 | 		goto unlock_and_exit; | 
 | 630 | 	} | 
 | 631 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 632 | 	status = acpi_ns_attach_data(node, handler, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 634 |       unlock_and_exit: | 
 | 635 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | 	return (status); | 
 | 637 | } | 
 | 638 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 639 | ACPI_EXPORT_SYMBOL(acpi_attach_data) | 
 | 640 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | /******************************************************************************* | 
 | 642 |  * | 
 | 643 |  * FUNCTION:    acpi_detach_data | 
 | 644 |  * | 
 | 645 |  * PARAMETERS:  obj_handle          - Namespace node handle | 
 | 646 |  *              Handler             - Handler used in call to acpi_attach_data | 
 | 647 |  * | 
 | 648 |  * RETURN:      Status | 
 | 649 |  * | 
 | 650 |  * DESCRIPTION: Remove data that was previously attached to a node. | 
 | 651 |  * | 
 | 652 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 653 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 654 | acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 656 | 	struct acpi_namespace_node *node; | 
 | 657 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 |  | 
 | 659 | 	/* Parameter validation */ | 
 | 660 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 661 | 	if (!obj_handle || !handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 662 | 		return (AE_BAD_PARAMETER); | 
 | 663 | 	} | 
 | 664 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 665 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 666 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | 		return (status); | 
 | 668 | 	} | 
 | 669 |  | 
 | 670 | 	/* Convert and validate the handle */ | 
 | 671 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 672 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 673 | 	if (!node) { | 
 | 674 | 		status = AE_BAD_PARAMETER; | 
 | 675 | 		goto unlock_and_exit; | 
 | 676 | 	} | 
 | 677 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 678 | 	status = acpi_ns_detach_data(node, handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 680 |       unlock_and_exit: | 
 | 681 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | 	return (status); | 
 | 683 | } | 
 | 684 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 685 | ACPI_EXPORT_SYMBOL(acpi_detach_data) | 
 | 686 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | /******************************************************************************* | 
 | 688 |  * | 
 | 689 |  * FUNCTION:    acpi_get_data | 
 | 690 |  * | 
 | 691 |  * PARAMETERS:  obj_handle          - Namespace node | 
 | 692 |  *              Handler             - Handler used in call to attach_data | 
 | 693 |  *              Data                - Where the data is returned | 
 | 694 |  * | 
 | 695 |  * RETURN:      Status | 
 | 696 |  * | 
 | 697 |  * DESCRIPTION: Retrieve data that was previously attached to a namespace node. | 
 | 698 |  * | 
 | 699 |  ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 701 | acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 703 | 	struct acpi_namespace_node *node; | 
 | 704 | 	acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 705 |  | 
 | 706 | 	/* Parameter validation */ | 
 | 707 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 708 | 	if (!obj_handle || !handler || !data) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | 		return (AE_BAD_PARAMETER); | 
 | 710 | 	} | 
 | 711 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 712 | 	status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
 | 713 | 	if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | 		return (status); | 
 | 715 | 	} | 
 | 716 |  | 
 | 717 | 	/* Convert and validate the handle */ | 
 | 718 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 719 | 	node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 720 | 	if (!node) { | 
 | 721 | 		status = AE_BAD_PARAMETER; | 
 | 722 | 		goto unlock_and_exit; | 
 | 723 | 	} | 
 | 724 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 725 | 	status = acpi_ns_get_attached_data(node, handler, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 727 |       unlock_and_exit: | 
 | 728 | 	(void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 729 | 	return (status); | 
 | 730 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 731 |  | 
 | 732 | ACPI_EXPORT_SYMBOL(acpi_get_data) |