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