| 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 | 6c9deb7 | 2007-02-02 19:48:24 +0300 | [diff] [blame] | 9 | * Copyright (C) 2000 - 2007, 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; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 173 | struct acpi_evaluate_info *info; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 174 | acpi_size buffer_space_needed; | 
|  | 175 | u32 i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 176 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 177 | ACPI_FUNCTION_TRACE(acpi_evaluate_object); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 178 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 179 | /* Allocate and initialize the evaluation information block */ | 
|  | 180 |  | 
|  | 181 | info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info)); | 
|  | 182 | if (!info) { | 
|  | 183 | return_ACPI_STATUS(AE_NO_MEMORY); | 
|  | 184 | } | 
|  | 185 |  | 
|  | 186 | info->pathname = pathname; | 
|  | 187 | info->parameter_type = ACPI_PARAM_ARGS; | 
|  | 188 |  | 
|  | 189 | /* Convert and validate the device handle */ | 
|  | 190 |  | 
|  | 191 | info->prefix_node = acpi_ns_map_handle_to_node(handle); | 
|  | 192 | if (!info->prefix_node) { | 
|  | 193 | status = AE_BAD_PARAMETER; | 
|  | 194 | goto cleanup; | 
|  | 195 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 |  | 
|  | 197 | /* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 198 | * If there are parameters to be passed to a control method, the external | 
|  | 199 | * objects must all be converted to internal objects | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | */ | 
|  | 201 | if (external_params && external_params->count) { | 
|  | 202 | /* | 
|  | 203 | * Allocate a new parameter block for the internal objects | 
|  | 204 | * Add 1 to count to allow for null terminated internal list | 
|  | 205 | */ | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 206 | info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) | 
|  | 207 | external_params-> | 
|  | 208 | count + | 
|  | 209 | 1) * sizeof(void *)); | 
|  | 210 | if (!info->parameters) { | 
|  | 211 | status = AE_NO_MEMORY; | 
|  | 212 | goto cleanup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 213 | } | 
|  | 214 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 215 | /* Convert each external object in the list to an internal object */ | 
|  | 216 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 217 | for (i = 0; i < external_params->count; i++) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 218 | status = | 
|  | 219 | acpi_ut_copy_eobject_to_iobject(&external_params-> | 
|  | 220 | pointer[i], | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 221 | &info-> | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 222 | parameters[i]); | 
|  | 223 | if (ACPI_FAILURE(status)) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 224 | goto cleanup; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 225 | } | 
|  | 226 | } | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 227 | info->parameters[external_params->count] = NULL; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 228 | } | 
|  | 229 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 230 | /* | 
|  | 231 | * Three major cases: | 
|  | 232 | * 1) Fully qualified pathname | 
|  | 233 | * 2) No handle, not fully qualified pathname (error) | 
|  | 234 | * 3) Valid handle | 
|  | 235 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 236 | if ((pathname) && (acpi_ns_valid_root_prefix(pathname[0]))) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 237 |  | 
|  | 238 | /* The path is fully qualified, just evaluate by name */ | 
|  | 239 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 240 | info->prefix_node = NULL; | 
|  | 241 | status = acpi_ns_evaluate(info); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 242 | } else if (!handle) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 243 | /* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 244 | * A handle is optional iff a fully qualified pathname is specified. | 
|  | 245 | * Since we've already handled fully qualified names above, this is | 
|  | 246 | * an error | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | */ | 
|  | 248 | if (!pathname) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 249 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 250 | "Both Handle and Pathname are NULL")); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 251 | } else { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 252 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 253 | "Null Handle with relative pathname [%s]", | 
|  | 254 | pathname)); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 255 | } | 
|  | 256 |  | 
|  | 257 | status = AE_BAD_PARAMETER; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 258 | } else { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 259 | /* We have a namespace a node and a possible relative path */ | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 260 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 261 | status = acpi_ns_evaluate(info); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | } | 
|  | 263 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 264 | /* | 
|  | 265 | * If we are expecting a return value, and all went well above, | 
|  | 266 | * copy the return value to an external object. | 
|  | 267 | */ | 
|  | 268 | if (return_buffer) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 269 | if (!info->return_object) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | return_buffer->length = 0; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 271 | } else { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 272 | if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) == | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 273 | ACPI_DESC_TYPE_NAMED) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | /* | 
|  | 275 | * If we received a NS Node as a return object, this means that | 
|  | 276 | * the object we are evaluating has nothing interesting to | 
|  | 277 | * return (such as a mutex, etc.)  We return an error because | 
|  | 278 | * these types are essentially unsupported by this interface. | 
|  | 279 | * We don't check up front because this makes it easier to add | 
|  | 280 | * support for various types at a later date if necessary. | 
|  | 281 | */ | 
|  | 282 | status = AE_TYPE; | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 283 | info->return_object = NULL;	/* No need to delete a NS Node */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | return_buffer->length = 0; | 
|  | 285 | } | 
|  | 286 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 287 | if (ACPI_SUCCESS(status)) { | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 288 |  | 
|  | 289 | /* Get the size of the returned object */ | 
|  | 290 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 291 | status = | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 292 | acpi_ut_get_object_size(info->return_object, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 293 | &buffer_space_needed); | 
|  | 294 | if (ACPI_SUCCESS(status)) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 295 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | /* Validate/Allocate/Clear caller buffer */ | 
|  | 297 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 298 | status = | 
|  | 299 | acpi_ut_initialize_buffer | 
|  | 300 | (return_buffer, | 
|  | 301 | buffer_space_needed); | 
|  | 302 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 303 | /* | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 304 | * Caller's buffer is too small or a new one can't | 
|  | 305 | * be allocated | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 306 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 307 | ACPI_DEBUG_PRINT((ACPI_DB_INFO, | 
|  | 308 | "Needed buffer size %X, %s\n", | 
|  | 309 | (u32) | 
|  | 310 | buffer_space_needed, | 
|  | 311 | acpi_format_exception | 
|  | 312 | (status))); | 
|  | 313 | } else { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 314 | /* We have enough space for the object, build it */ | 
|  | 315 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 316 | status = | 
|  | 317 | acpi_ut_copy_iobject_to_eobject | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 318 | (info->return_object, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 319 | return_buffer); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 320 | } | 
|  | 321 | } | 
|  | 322 | } | 
|  | 323 | } | 
|  | 324 | } | 
|  | 325 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 326 | if (info->return_object) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | /* | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 328 | * Delete the internal return object. NOTE: Interpreter must be | 
|  | 329 | * locked to avoid race condition. | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 330 | */ | 
| Bob Moore | 1ba753a | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 331 | acpi_ex_enter_interpreter(); | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 332 |  | 
| Bob Moore | 1ba753a | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 333 | /* Remove one reference on the return object (should delete it) */ | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 334 |  | 
| Bob Moore | 1ba753a | 2007-02-02 19:48:20 +0300 | [diff] [blame] | 335 | acpi_ut_remove_reference(info->return_object); | 
|  | 336 | acpi_ex_exit_interpreter(); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 337 | } | 
|  | 338 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 339 | cleanup: | 
|  | 340 |  | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 341 | /* Free the input parameter list (if we created one) */ | 
|  | 342 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 343 | if (info->parameters) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 344 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | /* Free the allocated parameter block */ | 
|  | 346 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 347 | acpi_ut_delete_internal_object_list(info->parameters); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 348 | } | 
|  | 349 |  | 
| Bob Moore | 4119532 | 2006-05-26 16:36:00 -0400 | [diff] [blame] | 350 | ACPI_FREE(info); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 351 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 353 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 354 | ACPI_EXPORT_SYMBOL(acpi_evaluate_object) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 355 |  | 
|  | 356 | /******************************************************************************* | 
|  | 357 | * | 
|  | 358 | * FUNCTION:    acpi_walk_namespace | 
|  | 359 | * | 
|  | 360 | * PARAMETERS:  Type                - acpi_object_type to search for | 
|  | 361 | *              start_object        - Handle in namespace where search begins | 
|  | 362 | *              max_depth           - Depth to which search is to reach | 
|  | 363 | *              user_function       - Called when an object of "Type" is found | 
|  | 364 | *              Context             - Passed to user function | 
|  | 365 | *              return_value        - Location where return value of | 
|  | 366 | *                                    user_function is put if terminated early | 
|  | 367 | * | 
|  | 368 | * RETURNS      Return value from the user_function if terminated early. | 
|  | 369 | *              Otherwise, returns NULL. | 
|  | 370 | * | 
|  | 371 | * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, | 
|  | 372 | *              starting (and ending) at the object specified by start_handle. | 
|  | 373 | *              The user_function is called whenever an object that matches | 
|  | 374 | *              the type parameter is found.  If the user function returns | 
|  | 375 | *              a non-zero value, the search is terminated immediately and this | 
|  | 376 | *              value is returned to the caller. | 
|  | 377 | * | 
|  | 378 | *              The point of this procedure is to provide a generic namespace | 
|  | 379 | *              walk routine that can be called from multiple places to | 
|  | 380 | *              provide multiple services;  the User Function can be tailored | 
|  | 381 | *              to each task, whether it is a print function, a compare | 
|  | 382 | *              function, etc. | 
|  | 383 | * | 
|  | 384 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 386 | acpi_walk_namespace(acpi_object_type type, | 
|  | 387 | acpi_handle start_object, | 
|  | 388 | u32 max_depth, | 
|  | 389 | acpi_walk_callback user_function, | 
|  | 390 | void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 392 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 394 | ACPI_FUNCTION_TRACE(acpi_walk_namespace); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 395 |  | 
|  | 396 | /* Parameter validation */ | 
|  | 397 |  | 
| Bob Moore | 96db255 | 2005-11-02 00:00:00 -0500 | [diff] [blame] | 398 | if ((type > ACPI_TYPE_LOCAL_MAX) || (!max_depth) || (!user_function)) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 399 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 400 | } | 
|  | 401 |  | 
|  | 402 | /* | 
|  | 403 | * Lock the namespace around the walk. | 
|  | 404 | * The namespace will be unlocked/locked around each call | 
|  | 405 | * to the user function - since this function | 
|  | 406 | * must be allowed to make Acpi calls itself. | 
|  | 407 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 408 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 409 | if (ACPI_FAILURE(status)) { | 
|  | 410 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 411 | } | 
|  | 412 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 413 | status = acpi_ns_walk_namespace(type, start_object, max_depth, | 
|  | 414 | ACPI_NS_WALK_UNLOCK, | 
|  | 415 | user_function, context, return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 416 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 417 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 418 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 420 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 421 | ACPI_EXPORT_SYMBOL(acpi_walk_namespace) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 |  | 
|  | 423 | /******************************************************************************* | 
|  | 424 | * | 
|  | 425 | * FUNCTION:    acpi_ns_get_device_callback | 
|  | 426 | * | 
|  | 427 | * PARAMETERS:  Callback from acpi_get_device | 
|  | 428 | * | 
|  | 429 | * RETURN:      Status | 
|  | 430 | * | 
|  | 431 | * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non- | 
|  | 432 | *              present devices, or if they specified a HID, it filters based | 
|  | 433 | *              on that. | 
|  | 434 | * | 
|  | 435 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 436 | static acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 437 | acpi_ns_get_device_callback(acpi_handle obj_handle, | 
|  | 438 | u32 nesting_level, | 
|  | 439 | void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 440 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 441 | struct acpi_get_devices_info *info = context; | 
|  | 442 | acpi_status status; | 
|  | 443 | struct acpi_namespace_node *node; | 
|  | 444 | u32 flags; | 
|  | 445 | struct acpi_device_id hid; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 446 | struct acpi_compatible_id_list *cid; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 447 | acpi_native_uint i; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 449 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 450 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | return (status); | 
|  | 452 | } | 
|  | 453 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 454 | node = acpi_ns_map_handle_to_node(obj_handle); | 
|  | 455 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 456 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 457 | return (status); | 
|  | 458 | } | 
|  | 459 |  | 
|  | 460 | if (!node) { | 
|  | 461 | return (AE_BAD_PARAMETER); | 
|  | 462 | } | 
|  | 463 |  | 
|  | 464 | /* Run _STA to determine if device is present */ | 
|  | 465 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 466 | status = acpi_ut_execute_STA(node, &flags); | 
|  | 467 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | return (AE_CTRL_DEPTH); | 
|  | 469 | } | 
|  | 470 |  | 
| Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 471 | if (!(flags & ACPI_STA_DEVICE_PRESENT)) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 472 |  | 
| Bob Moore | defba1d | 2005-12-16 17:05:00 -0500 | [diff] [blame] | 473 | /* Don't examine children of the device if not present */ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 |  | 
|  | 475 | return (AE_CTRL_DEPTH); | 
|  | 476 | } | 
|  | 477 |  | 
|  | 478 | /* Filter based on device HID & CID */ | 
|  | 479 |  | 
|  | 480 | if (info->hid != NULL) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 481 | status = acpi_ut_execute_HID(node, &hid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | if (status == AE_NOT_FOUND) { | 
|  | 483 | return (AE_OK); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 484 | } else if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 485 | return (AE_CTRL_DEPTH); | 
|  | 486 | } | 
|  | 487 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 488 | if (ACPI_STRNCMP(hid.value, info->hid, sizeof(hid.value)) != 0) { | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 489 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | /* Get the list of Compatible IDs */ | 
|  | 491 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 492 | status = acpi_ut_execute_CID(node, &cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | if (status == AE_NOT_FOUND) { | 
|  | 494 | return (AE_OK); | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 495 | } else if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 496 | return (AE_CTRL_DEPTH); | 
|  | 497 | } | 
|  | 498 |  | 
|  | 499 | /* Walk the CID list */ | 
|  | 500 |  | 
|  | 501 | for (i = 0; i < cid->count; i++) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 502 | if (ACPI_STRNCMP(cid->id[i].value, info->hid, | 
|  | 503 | sizeof(struct | 
|  | 504 | acpi_compatible_id)) != | 
|  | 505 | 0) { | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 506 | ACPI_FREE(cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 507 | return (AE_OK); | 
|  | 508 | } | 
|  | 509 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 510 | ACPI_FREE(cid); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 511 | } | 
|  | 512 | } | 
|  | 513 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 514 | status = info->user_function(obj_handle, nesting_level, info->context, | 
|  | 515 | return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | return (status); | 
|  | 517 | } | 
|  | 518 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | /******************************************************************************* | 
|  | 520 | * | 
|  | 521 | * FUNCTION:    acpi_get_devices | 
|  | 522 | * | 
|  | 523 | * PARAMETERS:  HID                 - HID to search for. Can be NULL. | 
|  | 524 | *              user_function       - Called when a matching object is found | 
|  | 525 | *              Context             - Passed to user function | 
|  | 526 | *              return_value        - Location where return value of | 
|  | 527 | *                                    user_function is put if terminated early | 
|  | 528 | * | 
|  | 529 | * RETURNS      Return value from the user_function if terminated early. | 
|  | 530 | *              Otherwise, returns NULL. | 
|  | 531 | * | 
|  | 532 | * DESCRIPTION: Performs a modified depth-first walk of the namespace tree, | 
|  | 533 | *              starting (and ending) at the object specified by start_handle. | 
|  | 534 | *              The user_function is called whenever an object of type | 
|  | 535 | *              Device is found.  If the user function returns | 
|  | 536 | *              a non-zero value, the search is terminated immediately and this | 
|  | 537 | *              value is returned to the caller. | 
|  | 538 | * | 
|  | 539 | *              This is a wrapper for walk_namespace, but the callback performs | 
|  | 540 | *              additional filtering. Please see acpi_get_device_callback. | 
|  | 541 | * | 
|  | 542 | ******************************************************************************/ | 
|  | 543 |  | 
|  | 544 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 545 | acpi_get_devices(char *HID, | 
|  | 546 | acpi_walk_callback user_function, | 
|  | 547 | void *context, void **return_value) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 548 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 549 | acpi_status status; | 
|  | 550 | struct acpi_get_devices_info info; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 551 |  | 
| Bob Moore | b229cf9 | 2006-04-21 17:15:00 -0400 | [diff] [blame] | 552 | ACPI_FUNCTION_TRACE(acpi_get_devices); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 |  | 
|  | 554 | /* Parameter validation */ | 
|  | 555 |  | 
|  | 556 | if (!user_function) { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 557 | return_ACPI_STATUS(AE_BAD_PARAMETER); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 558 | } | 
|  | 559 |  | 
|  | 560 | /* | 
|  | 561 | * We're going to call their callback from OUR callback, so we need | 
|  | 562 | * to know what it is, and their context parameter. | 
|  | 563 | */ | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 564 | info.hid = HID; | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 565 | info.context = context; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 566 | info.user_function = user_function; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 |  | 
|  | 568 | /* | 
|  | 569 | * Lock the namespace around the walk. | 
|  | 570 | * The namespace will be unlocked/locked around each call | 
|  | 571 | * to the user function - since this function | 
|  | 572 | * must be allowed to make Acpi calls itself. | 
|  | 573 | */ | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 574 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 575 | if (ACPI_FAILURE(status)) { | 
|  | 576 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 577 | } | 
|  | 578 |  | 
| Bob Moore | 52fc0b0 | 2006-10-02 00:00:00 -0400 | [diff] [blame] | 579 | status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT, | 
|  | 580 | ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK, | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 581 | acpi_ns_get_device_callback, &info, | 
|  | 582 | return_value); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 583 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 584 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
|  | 585 | return_ACPI_STATUS(status); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | } | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 588 | ACPI_EXPORT_SYMBOL(acpi_get_devices) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 589 |  | 
|  | 590 | /******************************************************************************* | 
|  | 591 | * | 
|  | 592 | * FUNCTION:    acpi_attach_data | 
|  | 593 | * | 
|  | 594 | * PARAMETERS:  obj_handle          - Namespace node | 
|  | 595 | *              Handler             - Handler for this attachment | 
|  | 596 | *              Data                - Pointer to data to be attached | 
|  | 597 | * | 
|  | 598 | * RETURN:      Status | 
|  | 599 | * | 
|  | 600 | * DESCRIPTION: Attach arbitrary data and handler to a namespace node. | 
|  | 601 | * | 
|  | 602 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 603 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 604 | acpi_attach_data(acpi_handle obj_handle, | 
|  | 605 | acpi_object_handler handler, void *data) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 607 | struct acpi_namespace_node *node; | 
|  | 608 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 |  | 
|  | 610 | /* Parameter validation */ | 
|  | 611 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 612 | if (!obj_handle || !handler || !data) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | return (AE_BAD_PARAMETER); | 
|  | 614 | } | 
|  | 615 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 616 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 617 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 618 | return (status); | 
|  | 619 | } | 
|  | 620 |  | 
|  | 621 | /* Convert and validate the handle */ | 
|  | 622 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 623 | node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | if (!node) { | 
|  | 625 | status = AE_BAD_PARAMETER; | 
|  | 626 | goto unlock_and_exit; | 
|  | 627 | } | 
|  | 628 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 629 | status = acpi_ns_attach_data(node, handler, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 630 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 631 | unlock_and_exit: | 
|  | 632 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 633 | return (status); | 
|  | 634 | } | 
|  | 635 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 636 | ACPI_EXPORT_SYMBOL(acpi_attach_data) | 
|  | 637 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 638 | /******************************************************************************* | 
|  | 639 | * | 
|  | 640 | * FUNCTION:    acpi_detach_data | 
|  | 641 | * | 
|  | 642 | * PARAMETERS:  obj_handle          - Namespace node handle | 
|  | 643 | *              Handler             - Handler used in call to acpi_attach_data | 
|  | 644 | * | 
|  | 645 | * RETURN:      Status | 
|  | 646 | * | 
|  | 647 | * DESCRIPTION: Remove data that was previously attached to a node. | 
|  | 648 | * | 
|  | 649 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 650 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 651 | acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler) | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 653 | struct acpi_namespace_node *node; | 
|  | 654 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 655 |  | 
|  | 656 | /* Parameter validation */ | 
|  | 657 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 658 | if (!obj_handle || !handler) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 659 | return (AE_BAD_PARAMETER); | 
|  | 660 | } | 
|  | 661 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 662 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 663 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 664 | return (status); | 
|  | 665 | } | 
|  | 666 |  | 
|  | 667 | /* Convert and validate the handle */ | 
|  | 668 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 669 | node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | if (!node) { | 
|  | 671 | status = AE_BAD_PARAMETER; | 
|  | 672 | goto unlock_and_exit; | 
|  | 673 | } | 
|  | 674 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 675 | status = acpi_ns_detach_data(node, handler); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 677 | unlock_and_exit: | 
|  | 678 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | return (status); | 
|  | 680 | } | 
|  | 681 |  | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 682 | ACPI_EXPORT_SYMBOL(acpi_detach_data) | 
|  | 683 |  | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 684 | /******************************************************************************* | 
|  | 685 | * | 
|  | 686 | * FUNCTION:    acpi_get_data | 
|  | 687 | * | 
|  | 688 | * PARAMETERS:  obj_handle          - Namespace node | 
|  | 689 | *              Handler             - Handler used in call to attach_data | 
|  | 690 | *              Data                - Where the data is returned | 
|  | 691 | * | 
|  | 692 | * RETURN:      Status | 
|  | 693 | * | 
|  | 694 | * DESCRIPTION: Retrieve data that was previously attached to a namespace node. | 
|  | 695 | * | 
|  | 696 | ******************************************************************************/ | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | acpi_status | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 698 | 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] | 699 | { | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 700 | struct acpi_namespace_node *node; | 
|  | 701 | acpi_status status; | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 702 |  | 
|  | 703 | /* Parameter validation */ | 
|  | 704 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 705 | if (!obj_handle || !handler || !data) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 706 | return (AE_BAD_PARAMETER); | 
|  | 707 | } | 
|  | 708 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 709 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); | 
|  | 710 | if (ACPI_FAILURE(status)) { | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 711 | return (status); | 
|  | 712 | } | 
|  | 713 |  | 
|  | 714 | /* Convert and validate the handle */ | 
|  | 715 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 716 | node = acpi_ns_map_handle_to_node(obj_handle); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 717 | if (!node) { | 
|  | 718 | status = AE_BAD_PARAMETER; | 
|  | 719 | goto unlock_and_exit; | 
|  | 720 | } | 
|  | 721 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 722 | status = acpi_ns_get_attached_data(node, handler, data); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 723 |  | 
| Len Brown | 4be44fc | 2005-08-05 00:44:28 -0400 | [diff] [blame] | 724 | unlock_and_exit: | 
|  | 725 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); | 
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | return (status); | 
|  | 727 | } | 
| Bob Moore | 8313524 | 2006-10-03 00:00:00 -0400 | [diff] [blame] | 728 |  | 
|  | 729 | ACPI_EXPORT_SYMBOL(acpi_get_data) |