]> git.karo-electronics.de Git - karo-tx-linux.git/blob - drivers/acpi/acpica/nsxfeval.c
Merge branch 'acpi-video-next' into linux-next
[karo-tx-linux.git] / drivers / acpi / acpica / nsxfeval.c
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 - 2013, Intel Corp.
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/export.h>
46 #include <acpi/acpi.h>
47 #include "accommon.h"
48 #include "acnamesp.h"
49 #include "acinterp.h"
50
51 #define _COMPONENT          ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsxfeval")
53
54 /* Local prototypes */
55 static void acpi_ns_resolve_references(struct acpi_evaluate_info *info);
56
57 /*******************************************************************************
58  *
59  * FUNCTION:    acpi_evaluate_object_typed
60  *
61  * PARAMETERS:  handle              - Object handle (optional)
62  *              pathname            - Object pathname (optional)
63  *              external_params     - List of parameters to pass to method,
64  *                                    terminated by NULL. May be NULL
65  *                                    if no parameters are being passed.
66  *              return_buffer       - Where to put method's return value (if
67  *                                    any). If NULL, no value is returned.
68  *              return_type         - Expected type of return object
69  *
70  * RETURN:      Status
71  *
72  * DESCRIPTION: Find and evaluate the given object, passing the given
73  *              parameters if necessary. One of "Handle" or "Pathname" must
74  *              be valid (non-null)
75  *
76  ******************************************************************************/
77
78 acpi_status
79 acpi_evaluate_object_typed(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         ACPI_FUNCTION_TRACE(acpi_evaluate_object_typed);
89
90         /* Return buffer must be valid */
91
92         if (!return_buffer) {
93                 return_ACPI_STATUS(AE_BAD_PARAMETER);
94         }
95
96         if (return_buffer->length == ACPI_ALLOCATE_BUFFER) {
97                 must_free = TRUE;
98         }
99
100         /* Evaluate the object */
101
102         status =
103             acpi_evaluate_object(handle, pathname, external_params,
104                                  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
117                 /* Error because caller specifically asked for a return value */
118
119                 ACPI_ERROR((AE_INFO, "No return value"));
120                 return_ACPI_STATUS(AE_NULL_OBJECT);
121         }
122
123         /* Examine the object type returned from evaluate_object */
124
125         if (((union acpi_object *)return_buffer->pointer)->type == return_type) {
126                 return_ACPI_STATUS(AE_OK);
127         }
128
129         /* Return object type does not match requested type */
130
131         ACPI_ERROR((AE_INFO,
132                     "Incorrect return type [%s] requested [%s]",
133                     acpi_ut_get_type_name(((union acpi_object *)return_buffer->
134                                            pointer)->type),
135                     acpi_ut_get_type_name(return_type)));
136
137         if (must_free) {
138
139                 /* Caller used ACPI_ALLOCATE_BUFFER, free the return buffer */
140
141                 ACPI_FREE(return_buffer->pointer);
142                 return_buffer->pointer = NULL;
143         }
144
145         return_buffer->length = 0;
146         return_ACPI_STATUS(AE_TYPE);
147 }
148
149 ACPI_EXPORT_SYMBOL(acpi_evaluate_object_typed)
150
151 /*******************************************************************************
152  *
153  * FUNCTION:    acpi_evaluate_object
154  *
155  * PARAMETERS:  handle              - Object handle (optional)
156  *              pathname            - Object pathname (optional)
157  *              external_params     - List of parameters to pass to method,
158  *                                    terminated by NULL. May be NULL
159  *                                    if no parameters are being passed.
160  *              return_buffer       - Where to put method's return value (if
161  *                                    any). If NULL, no value is returned.
162  *
163  * RETURN:      Status
164  *
165  * DESCRIPTION: Find and evaluate the given object, passing the given
166  *              parameters if necessary. One of "Handle" or "Pathname" must
167  *              be valid (non-null)
168  *
169  ******************************************************************************/
170 acpi_status
171 acpi_evaluate_object(acpi_handle handle,
172                      acpi_string pathname,
173                      struct acpi_object_list *external_params,
174                      struct acpi_buffer *return_buffer)
175 {
176         acpi_status status;
177         struct acpi_evaluate_info *info;
178         acpi_size buffer_space_needed;
179         u32 i;
180
181         ACPI_FUNCTION_TRACE(acpi_evaluate_object);
182
183         /* Allocate and initialize the evaluation information block */
184
185         info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
186         if (!info) {
187                 return_ACPI_STATUS(AE_NO_MEMORY);
188         }
189
190         /* Convert and validate the device handle */
191
192         info->prefix_node = acpi_ns_validate_handle(handle);
193         if (!info->prefix_node) {
194                 status = AE_BAD_PARAMETER;
195                 goto cleanup;
196         }
197
198         /*
199          * Get the actual namespace node for the target object.
200          * Handles these cases:
201          *
202          * 1) Null node, valid pathname from root (absolute path)
203          * 2) Node and valid pathname (path relative to Node)
204          * 3) Node, Null pathname
205          */
206         if ((pathname) && (ACPI_IS_ROOT_PREFIX(pathname[0]))) {
207
208                 /* The path is fully qualified, just evaluate by name */
209
210                 info->prefix_node = NULL;
211         } else if (!handle) {
212                 /*
213                  * A handle is optional iff a fully qualified pathname is specified.
214                  * Since we've already handled fully qualified names above, this is
215                  * an error.
216                  */
217                 if (!pathname) {
218                         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
219                                           "Both Handle and Pathname are NULL"));
220                 } else {
221                         ACPI_DEBUG_PRINT((ACPI_DB_INFO,
222                                           "Null Handle with relative pathname [%s]",
223                                           pathname));
224                 }
225
226                 status = AE_BAD_PARAMETER;
227                 goto cleanup;
228         }
229
230         info->relative_pathname = pathname;
231
232         /*
233          * Convert all external objects passed as arguments to the
234          * internal version(s).
235          */
236         if (external_params && external_params->count) {
237                 info->param_count = (u16)external_params->count;
238
239                 /* Warn on impossible argument count */
240
241                 if (info->param_count > ACPI_METHOD_NUM_ARGS) {
242                         ACPI_WARN_PREDEFINED((AE_INFO, pathname,
243                                               ACPI_WARN_ALWAYS,
244                                               "Excess arguments (%u) - using only %u",
245                                               info->param_count,
246                                               ACPI_METHOD_NUM_ARGS));
247
248                         info->param_count = ACPI_METHOD_NUM_ARGS;
249                 }
250
251                 /*
252                  * Allocate a new parameter block for the internal objects
253                  * Add 1 to count to allow for null terminated internal list
254                  */
255                 info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size) info->
256                                                          param_count +
257                                                          1) * sizeof(void *));
258                 if (!info->parameters) {
259                         status = AE_NO_MEMORY;
260                         goto cleanup;
261                 }
262
263                 /* Convert each external object in the list to an internal object */
264
265                 for (i = 0; i < info->param_count; i++) {
266                         status =
267                             acpi_ut_copy_eobject_to_iobject(&external_params->
268                                                             pointer[i],
269                                                             &info->
270                                                             parameters[i]);
271                         if (ACPI_FAILURE(status)) {
272                                 goto cleanup;
273                         }
274                 }
275
276                 info->parameters[info->param_count] = NULL;
277         }
278
279 #if 0
280
281         /*
282          * Begin incoming argument count analysis. Check for too few args
283          * and too many args.
284          */
285
286         switch (acpi_ns_get_type(info->node)) {
287         case ACPI_TYPE_METHOD:
288
289                 /* Check incoming argument count against the method definition */
290
291                 if (info->obj_desc->method.param_count > info->param_count) {
292                         ACPI_ERROR((AE_INFO,
293                                     "Insufficient arguments (%u) - %u are required",
294                                     info->param_count,
295                                     info->obj_desc->method.param_count));
296
297                         status = AE_MISSING_ARGUMENTS;
298                         goto cleanup;
299                 }
300
301                 else if (info->obj_desc->method.param_count < info->param_count) {
302                         ACPI_WARNING((AE_INFO,
303                                       "Excess arguments (%u) - only %u are required",
304                                       info->param_count,
305                                       info->obj_desc->method.param_count));
306
307                         /* Just pass the required number of arguments */
308
309                         info->param_count = info->obj_desc->method.param_count;
310                 }
311
312                 /*
313                  * Any incoming external objects to be passed as arguments to the
314                  * method must be converted to internal objects
315                  */
316                 if (info->param_count) {
317                         /*
318                          * Allocate a new parameter block for the internal objects
319                          * Add 1 to count to allow for null terminated internal list
320                          */
321                         info->parameters = ACPI_ALLOCATE_ZEROED(((acpi_size)
322                                                                  info->
323                                                                  param_count +
324                                                                  1) *
325                                                                 sizeof(void *));
326                         if (!info->parameters) {
327                                 status = AE_NO_MEMORY;
328                                 goto cleanup;
329                         }
330
331                         /* Convert each external object in the list to an internal object */
332
333                         for (i = 0; i < info->param_count; i++) {
334                                 status =
335                                     acpi_ut_copy_eobject_to_iobject
336                                     (&external_params->pointer[i],
337                                      &info->parameters[i]);
338                                 if (ACPI_FAILURE(status)) {
339                                         goto cleanup;
340                                 }
341                         }
342
343                         info->parameters[info->param_count] = NULL;
344                 }
345                 break;
346
347         default:
348
349                 /* Warn if arguments passed to an object that is not a method */
350
351                 if (info->param_count) {
352                         ACPI_WARNING((AE_INFO,
353                                       "%u arguments were passed to a non-method ACPI object",
354                                       info->param_count));
355                 }
356                 break;
357         }
358
359 #endif
360
361         /* Now we can evaluate the object */
362
363         status = acpi_ns_evaluate(info);
364
365         /*
366          * If we are expecting a return value, and all went well above,
367          * copy the return value to an external object.
368          */
369         if (return_buffer) {
370                 if (!info->return_object) {
371                         return_buffer->length = 0;
372                 } else {
373                         if (ACPI_GET_DESCRIPTOR_TYPE(info->return_object) ==
374                             ACPI_DESC_TYPE_NAMED) {
375                                 /*
376                                  * If we received a NS Node as a return object, this means that
377                                  * the object we are evaluating has nothing interesting to
378                                  * return (such as a mutex, etc.)  We return an error because
379                                  * these types are essentially unsupported by this interface.
380                                  * We don't check up front because this makes it easier to add
381                                  * support for various types at a later date if necessary.
382                                  */
383                                 status = AE_TYPE;
384                                 info->return_object = NULL;     /* No need to delete a NS Node */
385                                 return_buffer->length = 0;
386                         }
387
388                         if (ACPI_SUCCESS(status)) {
389
390                                 /* Dereference Index and ref_of references */
391
392                                 acpi_ns_resolve_references(info);
393
394                                 /* Get the size of the returned object */
395
396                                 status =
397                                     acpi_ut_get_object_size(info->return_object,
398                                                             &buffer_space_needed);
399                                 if (ACPI_SUCCESS(status)) {
400
401                                         /* Validate/Allocate/Clear caller buffer */
402
403                                         status =
404                                             acpi_ut_initialize_buffer
405                                             (return_buffer,
406                                              buffer_space_needed);
407                                         if (ACPI_FAILURE(status)) {
408                                                 /*
409                                                  * Caller's buffer is too small or a new one can't
410                                                  * be allocated
411                                                  */
412                                                 ACPI_DEBUG_PRINT((ACPI_DB_INFO,
413                                                                   "Needed buffer size %X, %s\n",
414                                                                   (u32)
415                                                                   buffer_space_needed,
416                                                                   acpi_format_exception
417                                                                   (status)));
418                                         } else {
419                                                 /* We have enough space for the object, build it */
420
421                                                 status =
422                                                     acpi_ut_copy_iobject_to_eobject
423                                                     (info->return_object,
424                                                      return_buffer);
425                                         }
426                                 }
427                         }
428                 }
429         }
430
431         if (info->return_object) {
432                 /*
433                  * Delete the internal return object. NOTE: Interpreter must be
434                  * locked to avoid race condition.
435                  */
436                 acpi_ex_enter_interpreter();
437
438                 /* Remove one reference on the return object (should delete it) */
439
440                 acpi_ut_remove_reference(info->return_object);
441                 acpi_ex_exit_interpreter();
442         }
443
444       cleanup:
445
446         /* Free the input parameter list (if we created one) */
447
448         if (info->parameters) {
449
450                 /* Free the allocated parameter block */
451
452                 acpi_ut_delete_internal_object_list(info->parameters);
453         }
454
455         ACPI_FREE(info);
456         return_ACPI_STATUS(status);
457 }
458
459 ACPI_EXPORT_SYMBOL(acpi_evaluate_object)
460
461 /*******************************************************************************
462  *
463  * FUNCTION:    acpi_ns_resolve_references
464  *
465  * PARAMETERS:  info                    - Evaluation info block
466  *
467  * RETURN:      Info->return_object is replaced with the dereferenced object
468  *
469  * DESCRIPTION: Dereference certain reference objects. Called before an
470  *              internal return object is converted to an external union acpi_object.
471  *
472  * Performs an automatic dereference of Index and ref_of reference objects.
473  * These reference objects are not supported by the union acpi_object, so this is a
474  * last resort effort to return something useful. Also, provides compatibility
475  * with other ACPI implementations.
476  *
477  * NOTE: does not handle references within returned package objects or nested
478  * references, but this support could be added later if found to be necessary.
479  *
480  ******************************************************************************/
481 static void acpi_ns_resolve_references(struct acpi_evaluate_info *info)
482 {
483         union acpi_operand_object *obj_desc = NULL;
484         struct acpi_namespace_node *node;
485
486         /* We are interested in reference objects only */
487
488         if ((info->return_object)->common.type != ACPI_TYPE_LOCAL_REFERENCE) {
489                 return;
490         }
491
492         /*
493          * Two types of references are supported - those created by Index and
494          * ref_of operators. A name reference (AML_NAMEPATH_OP) can be converted
495          * to an union acpi_object, so it is not dereferenced here. A ddb_handle
496          * (AML_LOAD_OP) cannot be dereferenced, nor can it be converted to
497          * an union acpi_object.
498          */
499         switch (info->return_object->reference.class) {
500         case ACPI_REFCLASS_INDEX:
501
502                 obj_desc = *(info->return_object->reference.where);
503                 break;
504
505         case ACPI_REFCLASS_REFOF:
506
507                 node = info->return_object->reference.object;
508                 if (node) {
509                         obj_desc = node->object;
510                 }
511                 break;
512
513         default:
514
515                 return;
516         }
517
518         /* Replace the existing reference object */
519
520         if (obj_desc) {
521                 acpi_ut_add_reference(obj_desc);
522                 acpi_ut_remove_reference(info->return_object);
523                 info->return_object = obj_desc;
524         }
525
526         return;
527 }
528
529 /*******************************************************************************
530  *
531  * FUNCTION:    acpi_walk_namespace
532  *
533  * PARAMETERS:  type                - acpi_object_type to search for
534  *              start_object        - Handle in namespace where search begins
535  *              max_depth           - Depth to which search is to reach
536  *              descending_callback - Called during tree descent
537  *                                    when an object of "Type" is found
538  *              ascending_callback  - Called during tree ascent
539  *                                    when an object of "Type" is found
540  *              context             - Passed to user function(s) above
541  *              return_value        - Location where return value of
542  *                                    user_function is put if terminated early
543  *
544  * RETURNS      Return value from the user_function if terminated early.
545  *              Otherwise, returns NULL.
546  *
547  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
548  *              starting (and ending) at the object specified by start_handle.
549  *              The callback function is called whenever an object that matches
550  *              the type parameter is found. If the callback function returns
551  *              a non-zero value, the search is terminated immediately and this
552  *              value is returned to the caller.
553  *
554  *              The point of this procedure is to provide a generic namespace
555  *              walk routine that can be called from multiple places to
556  *              provide multiple services; the callback function(s) can be
557  *              tailored to each task, whether it is a print function,
558  *              a compare function, etc.
559  *
560  ******************************************************************************/
561
562 acpi_status
563 acpi_walk_namespace(acpi_object_type type,
564                     acpi_handle start_object,
565                     u32 max_depth,
566                     acpi_walk_callback descending_callback,
567                     acpi_walk_callback ascending_callback,
568                     void *context, void **return_value)
569 {
570         acpi_status status;
571
572         ACPI_FUNCTION_TRACE(acpi_walk_namespace);
573
574         /* Parameter validation */
575
576         if ((type > ACPI_TYPE_LOCAL_MAX) ||
577             (!max_depth) || (!descending_callback && !ascending_callback)) {
578                 return_ACPI_STATUS(AE_BAD_PARAMETER);
579         }
580
581         /*
582          * Need to acquire the namespace reader lock to prevent interference
583          * with any concurrent table unloads (which causes the deletion of
584          * namespace objects). We cannot allow the deletion of a namespace node
585          * while the user function is using it. The exception to this are the
586          * nodes created and deleted during control method execution -- these
587          * nodes are marked as temporary nodes and are ignored by the namespace
588          * walk. Thus, control methods can be executed while holding the
589          * namespace deletion lock (and the user function can execute control
590          * methods.)
591          */
592         status = acpi_ut_acquire_read_lock(&acpi_gbl_namespace_rw_lock);
593         if (ACPI_FAILURE(status)) {
594                 return_ACPI_STATUS(status);
595         }
596
597         /*
598          * Lock the namespace around the walk. The namespace will be
599          * unlocked/locked around each call to the user function - since the user
600          * function must be allowed to make ACPICA calls itself (for example, it
601          * will typically execute control methods during device enumeration.)
602          */
603         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
604         if (ACPI_FAILURE(status)) {
605                 goto unlock_and_exit;
606         }
607
608         /* Now we can validate the starting node */
609
610         if (!acpi_ns_validate_handle(start_object)) {
611                 status = AE_BAD_PARAMETER;
612                 goto unlock_and_exit2;
613         }
614
615         status = acpi_ns_walk_namespace(type, start_object, max_depth,
616                                         ACPI_NS_WALK_UNLOCK,
617                                         descending_callback, ascending_callback,
618                                         context, return_value);
619
620       unlock_and_exit2:
621         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
622
623       unlock_and_exit:
624         (void)acpi_ut_release_read_lock(&acpi_gbl_namespace_rw_lock);
625         return_ACPI_STATUS(status);
626 }
627
628 ACPI_EXPORT_SYMBOL(acpi_walk_namespace)
629
630 /*******************************************************************************
631  *
632  * FUNCTION:    acpi_ns_get_device_callback
633  *
634  * PARAMETERS:  Callback from acpi_get_device
635  *
636  * RETURN:      Status
637  *
638  * DESCRIPTION: Takes callbacks from walk_namespace and filters out all non-
639  *              present devices, or if they specified a HID, it filters based
640  *              on that.
641  *
642  ******************************************************************************/
643 static acpi_status
644 acpi_ns_get_device_callback(acpi_handle obj_handle,
645                             u32 nesting_level,
646                             void *context, void **return_value)
647 {
648         struct acpi_get_devices_info *info = context;
649         acpi_status status;
650         struct acpi_namespace_node *node;
651         u32 flags;
652         struct acpi_pnp_device_id *hid;
653         struct acpi_pnp_device_id_list *cid;
654         u32 i;
655         u8 found;
656         int no_match;
657
658         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
659         if (ACPI_FAILURE(status)) {
660                 return (status);
661         }
662
663         node = acpi_ns_validate_handle(obj_handle);
664         status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
665         if (ACPI_FAILURE(status)) {
666                 return (status);
667         }
668
669         if (!node) {
670                 return (AE_BAD_PARAMETER);
671         }
672
673         /*
674          * First, filter based on the device HID and CID.
675          *
676          * 01/2010: For this case where a specific HID is requested, we don't
677          * want to run _STA until we have an actual HID match. Thus, we will
678          * not unnecessarily execute _STA on devices for which the caller
679          * doesn't care about. Previously, _STA was executed unconditionally
680          * on all devices found here.
681          *
682          * A side-effect of this change is that now we will continue to search
683          * for a matching HID even under device trees where the parent device
684          * would have returned a _STA that indicates it is not present or
685          * not functioning (thus aborting the search on that branch).
686          */
687         if (info->hid != NULL) {
688                 status = acpi_ut_execute_HID(node, &hid);
689                 if (status == AE_NOT_FOUND) {
690                         return (AE_OK);
691                 } else if (ACPI_FAILURE(status)) {
692                         return (AE_CTRL_DEPTH);
693                 }
694
695                 no_match = ACPI_STRCMP(hid->string, info->hid);
696                 ACPI_FREE(hid);
697
698                 if (no_match) {
699                         /*
700                          * HID does not match, attempt match within the
701                          * list of Compatible IDs (CIDs)
702                          */
703                         status = acpi_ut_execute_CID(node, &cid);
704                         if (status == AE_NOT_FOUND) {
705                                 return (AE_OK);
706                         } else if (ACPI_FAILURE(status)) {
707                                 return (AE_CTRL_DEPTH);
708                         }
709
710                         /* Walk the CID list */
711
712                         found = FALSE;
713                         for (i = 0; i < cid->count; i++) {
714                                 if (ACPI_STRCMP(cid->ids[i].string, info->hid)
715                                     == 0) {
716
717                                         /* Found a matching CID */
718
719                                         found = TRUE;
720                                         break;
721                                 }
722                         }
723
724                         ACPI_FREE(cid);
725                         if (!found) {
726                                 return (AE_OK);
727                         }
728                 }
729         }
730
731         /* Run _STA to determine if device is present */
732
733         status = acpi_ut_execute_STA(node, &flags);
734         if (ACPI_FAILURE(status)) {
735                 return (AE_CTRL_DEPTH);
736         }
737
738         if (!(flags & ACPI_STA_DEVICE_PRESENT) &&
739             !(flags & ACPI_STA_DEVICE_FUNCTIONING)) {
740                 /*
741                  * Don't examine the children of the device only when the
742                  * device is neither present nor functional. See ACPI spec,
743                  * description of _STA for more information.
744                  */
745                 return (AE_CTRL_DEPTH);
746         }
747
748         /* We have a valid device, invoke the user function */
749
750         status = info->user_function(obj_handle, nesting_level, info->context,
751                                      return_value);
752         return (status);
753 }
754
755 /*******************************************************************************
756  *
757  * FUNCTION:    acpi_get_devices
758  *
759  * PARAMETERS:  HID                 - HID to search for. Can be NULL.
760  *              user_function       - Called when a matching object is found
761  *              context             - Passed to user function
762  *              return_value        - Location where return value of
763  *                                    user_function is put if terminated early
764  *
765  * RETURNS      Return value from the user_function if terminated early.
766  *              Otherwise, returns NULL.
767  *
768  * DESCRIPTION: Performs a modified depth-first walk of the namespace tree,
769  *              starting (and ending) at the object specified by start_handle.
770  *              The user_function is called whenever an object of type
771  *              Device is found. If the user function returns
772  *              a non-zero value, the search is terminated immediately and this
773  *              value is returned to the caller.
774  *
775  *              This is a wrapper for walk_namespace, but the callback performs
776  *              additional filtering. Please see acpi_ns_get_device_callback.
777  *
778  ******************************************************************************/
779
780 acpi_status
781 acpi_get_devices(const char *HID,
782                  acpi_walk_callback user_function,
783                  void *context, void **return_value)
784 {
785         acpi_status status;
786         struct acpi_get_devices_info info;
787
788         ACPI_FUNCTION_TRACE(acpi_get_devices);
789
790         /* Parameter validation */
791
792         if (!user_function) {
793                 return_ACPI_STATUS(AE_BAD_PARAMETER);
794         }
795
796         /*
797          * We're going to call their callback from OUR callback, so we need
798          * to know what it is, and their context parameter.
799          */
800         info.hid = HID;
801         info.context = context;
802         info.user_function = user_function;
803
804         /*
805          * Lock the namespace around the walk.
806          * The namespace will be unlocked/locked around each call
807          * to the user function - since this function
808          * must be allowed to make Acpi calls itself.
809          */
810         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
811         if (ACPI_FAILURE(status)) {
812                 return_ACPI_STATUS(status);
813         }
814
815         status = acpi_ns_walk_namespace(ACPI_TYPE_DEVICE, ACPI_ROOT_OBJECT,
816                                         ACPI_UINT32_MAX, ACPI_NS_WALK_UNLOCK,
817                                         acpi_ns_get_device_callback, NULL,
818                                         &info, return_value);
819
820         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
821         return_ACPI_STATUS(status);
822 }
823
824 ACPI_EXPORT_SYMBOL(acpi_get_devices)
825
826 /*******************************************************************************
827  *
828  * FUNCTION:    acpi_attach_data
829  *
830  * PARAMETERS:  obj_handle          - Namespace node
831  *              handler             - Handler for this attachment
832  *              data                - Pointer to data to be attached
833  *
834  * RETURN:      Status
835  *
836  * DESCRIPTION: Attach arbitrary data and handler to a namespace node.
837  *
838  ******************************************************************************/
839 acpi_status
840 acpi_attach_data(acpi_handle obj_handle,
841                  acpi_object_handler handler, void *data)
842 {
843         struct acpi_namespace_node *node;
844         acpi_status status;
845
846         /* Parameter validation */
847
848         if (!obj_handle || !handler || !data) {
849                 return (AE_BAD_PARAMETER);
850         }
851
852         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
853         if (ACPI_FAILURE(status)) {
854                 return (status);
855         }
856
857         /* Convert and validate the handle */
858
859         node = acpi_ns_validate_handle(obj_handle);
860         if (!node) {
861                 status = AE_BAD_PARAMETER;
862                 goto unlock_and_exit;
863         }
864
865         status = acpi_ns_attach_data(node, handler, data);
866
867       unlock_and_exit:
868         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
869         return (status);
870 }
871
872 ACPI_EXPORT_SYMBOL(acpi_attach_data)
873
874 /*******************************************************************************
875  *
876  * FUNCTION:    acpi_detach_data
877  *
878  * PARAMETERS:  obj_handle          - Namespace node handle
879  *              handler             - Handler used in call to acpi_attach_data
880  *
881  * RETURN:      Status
882  *
883  * DESCRIPTION: Remove data that was previously attached to a node.
884  *
885  ******************************************************************************/
886 acpi_status
887 acpi_detach_data(acpi_handle obj_handle, acpi_object_handler handler)
888 {
889         struct acpi_namespace_node *node;
890         acpi_status status;
891
892         /* Parameter validation */
893
894         if (!obj_handle || !handler) {
895                 return (AE_BAD_PARAMETER);
896         }
897
898         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
899         if (ACPI_FAILURE(status)) {
900                 return (status);
901         }
902
903         /* Convert and validate the handle */
904
905         node = acpi_ns_validate_handle(obj_handle);
906         if (!node) {
907                 status = AE_BAD_PARAMETER;
908                 goto unlock_and_exit;
909         }
910
911         status = acpi_ns_detach_data(node, handler);
912
913       unlock_and_exit:
914         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
915         return (status);
916 }
917
918 ACPI_EXPORT_SYMBOL(acpi_detach_data)
919
920 /*******************************************************************************
921  *
922  * FUNCTION:    acpi_get_data
923  *
924  * PARAMETERS:  obj_handle          - Namespace node
925  *              handler             - Handler used in call to attach_data
926  *              data                - Where the data is returned
927  *
928  * RETURN:      Status
929  *
930  * DESCRIPTION: Retrieve data that was previously attached to a namespace node.
931  *
932  ******************************************************************************/
933 acpi_status
934 acpi_get_data(acpi_handle obj_handle, acpi_object_handler handler, void **data)
935 {
936         struct acpi_namespace_node *node;
937         acpi_status status;
938
939         /* Parameter validation */
940
941         if (!obj_handle || !handler || !data) {
942                 return (AE_BAD_PARAMETER);
943         }
944
945         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
946         if (ACPI_FAILURE(status)) {
947                 return (status);
948         }
949
950         /* Convert and validate the handle */
951
952         node = acpi_ns_validate_handle(obj_handle);
953         if (!node) {
954                 status = AE_BAD_PARAMETER;
955                 goto unlock_and_exit;
956         }
957
958         status = acpi_ns_get_attached_data(node, handler, data);
959
960       unlock_and_exit:
961         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
962         return (status);
963 }
964
965 ACPI_EXPORT_SYMBOL(acpi_get_data)