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