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