Merge master.kernel.org:/pub/scm/linux/kernel/git/dwmw2/audit-2.6
[sfrench/cifs-2.6.git] / drivers / acpi / namespace / nsxfobj.c
1 /*******************************************************************************
2  *
3  * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4  *                         ACPI Object oriented 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
50 #define _COMPONENT          ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nsxfobj")
52
53 /*******************************************************************************
54  *
55  * FUNCTION:    acpi_get_type
56  *
57  * PARAMETERS:  Handle          - Handle of object whose type is desired
58  *              ret_type        - Where the type will be placed
59  *
60  * RETURN:      Status
61  *
62  * DESCRIPTION: This routine returns the type associatd with a particular handle
63  *
64  ******************************************************************************/
65 acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
66 {
67         struct acpi_namespace_node *node;
68         acpi_status status;
69
70         /* Parameter Validation */
71
72         if (!ret_type) {
73                 return (AE_BAD_PARAMETER);
74         }
75
76         /*
77          * Special case for the predefined Root Node
78          * (return type ANY)
79          */
80         if (handle == ACPI_ROOT_OBJECT) {
81                 *ret_type = ACPI_TYPE_ANY;
82                 return (AE_OK);
83         }
84
85         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
86         if (ACPI_FAILURE(status)) {
87                 return (status);
88         }
89
90         /* Convert and validate the handle */
91
92         node = acpi_ns_map_handle_to_node(handle);
93         if (!node) {
94                 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
95                 return (AE_BAD_PARAMETER);
96         }
97
98         *ret_type = node->type;
99
100         status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
101         return (status);
102 }
103
104 EXPORT_SYMBOL(acpi_get_type);
105
106 /*******************************************************************************
107  *
108  * FUNCTION:    acpi_get_parent
109  *
110  * PARAMETERS:  Handle          - Handle of object whose parent is desired
111  *              ret_handle      - Where the parent handle will be placed
112  *
113  * RETURN:      Status
114  *
115  * DESCRIPTION: Returns a handle to the parent of the object represented by
116  *              Handle.
117  *
118  ******************************************************************************/
119
120 acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
121 {
122         struct acpi_namespace_node *node;
123         acpi_status status;
124
125         if (!ret_handle) {
126                 return (AE_BAD_PARAMETER);
127         }
128
129         /* Special case for the predefined Root Node (no parent) */
130
131         if (handle == ACPI_ROOT_OBJECT) {
132                 return (AE_NULL_ENTRY);
133         }
134
135         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
136         if (ACPI_FAILURE(status)) {
137                 return (status);
138         }
139
140         /* Convert and validate the handle */
141
142         node = acpi_ns_map_handle_to_node(handle);
143         if (!node) {
144                 status = AE_BAD_PARAMETER;
145                 goto unlock_and_exit;
146         }
147
148         /* Get the parent entry */
149
150         *ret_handle =
151             acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
152
153         /* Return exception if parent is null */
154
155         if (!acpi_ns_get_parent_node(node)) {
156                 status = AE_NULL_ENTRY;
157         }
158
159       unlock_and_exit:
160
161         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
162         return (status);
163 }
164
165 EXPORT_SYMBOL(acpi_get_parent);
166
167 /*******************************************************************************
168  *
169  * FUNCTION:    acpi_get_next_object
170  *
171  * PARAMETERS:  Type            - Type of object to be searched for
172  *              Parent          - Parent object whose children we are getting
173  *              last_child      - Previous child that was found.
174  *                                The NEXT child will be returned
175  *              ret_handle      - Where handle to the next object is placed
176  *
177  * RETURN:      Status
178  *
179  * DESCRIPTION: Return the next peer object within the namespace.  If Handle is
180  *              valid, Scope is ignored.  Otherwise, the first object within
181  *              Scope is returned.
182  *
183  ******************************************************************************/
184
185 acpi_status
186 acpi_get_next_object(acpi_object_type type,
187                      acpi_handle parent,
188                      acpi_handle child, acpi_handle * ret_handle)
189 {
190         acpi_status status;
191         struct acpi_namespace_node *node;
192         struct acpi_namespace_node *parent_node = NULL;
193         struct acpi_namespace_node *child_node = NULL;
194
195         /* Parameter validation */
196
197         if (type > ACPI_TYPE_EXTERNAL_MAX) {
198                 return (AE_BAD_PARAMETER);
199         }
200
201         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
202         if (ACPI_FAILURE(status)) {
203                 return (status);
204         }
205
206         /* If null handle, use the parent */
207
208         if (!child) {
209                 /* Start search at the beginning of the specified scope */
210
211                 parent_node = acpi_ns_map_handle_to_node(parent);
212                 if (!parent_node) {
213                         status = AE_BAD_PARAMETER;
214                         goto unlock_and_exit;
215                 }
216         } else {
217                 /* Non-null handle, ignore the parent */
218                 /* Convert and validate the handle */
219
220                 child_node = acpi_ns_map_handle_to_node(child);
221                 if (!child_node) {
222                         status = AE_BAD_PARAMETER;
223                         goto unlock_and_exit;
224                 }
225         }
226
227         /* Internal function does the real work */
228
229         node = acpi_ns_get_next_node(type, parent_node, child_node);
230         if (!node) {
231                 status = AE_NOT_FOUND;
232                 goto unlock_and_exit;
233         }
234
235         if (ret_handle) {
236                 *ret_handle = acpi_ns_convert_entry_to_handle(node);
237         }
238
239       unlock_and_exit:
240
241         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
242         return (status);
243 }
244
245 EXPORT_SYMBOL(acpi_get_next_object);