Merge tag 'microblaze-3.15-rc1' of git://git.monstr.eu/linux-2.6-microblaze
[cascardo/linux.git] / drivers / acpi / acpica / 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 - 2014, 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 #define EXPORT_ACPI_INTERFACES
46
47 #include <acpi/acpi.h>
48 #include "accommon.h"
49 #include "acnamesp.h"
50
51 #define _COMPONENT          ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsxfobj")
53
54 /*******************************************************************************
55  *
56  * FUNCTION:    acpi_get_id
57  *
58  * PARAMETERS:  Handle          - Handle of object whose id is desired
59  *              ret_id          - Where the id will be placed
60  *
61  * RETURN:      Status
62  *
63  * DESCRIPTION: This routine returns the owner id associated with a handle
64  *
65  ******************************************************************************/
66 acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
67 {
68         struct acpi_namespace_node *node;
69         acpi_status status;
70
71         /* Parameter Validation */
72
73         if (!ret_id) {
74                 return (AE_BAD_PARAMETER);
75         }
76
77         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
78         if (ACPI_FAILURE(status)) {
79                 return (status);
80         }
81
82         /* Convert and validate the handle */
83
84         node = acpi_ns_validate_handle(handle);
85         if (!node) {
86                 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
87                 return (AE_BAD_PARAMETER);
88         }
89
90         *ret_id = node->owner_id;
91
92         status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
93         return (status);
94 }
95
96 ACPI_EXPORT_SYMBOL(acpi_get_id)
97
98 /*******************************************************************************
99  *
100  * FUNCTION:    acpi_get_type
101  *
102  * PARAMETERS:  handle          - Handle of object whose type is desired
103  *              ret_type        - Where the type will be placed
104  *
105  * RETURN:      Status
106  *
107  * DESCRIPTION: This routine returns the type associatd with a particular handle
108  *
109  ******************************************************************************/
110 acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
111 {
112         struct acpi_namespace_node *node;
113         acpi_status status;
114
115         /* Parameter Validation */
116
117         if (!ret_type) {
118                 return (AE_BAD_PARAMETER);
119         }
120
121         /*
122          * Special case for the predefined Root Node
123          * (return type ANY)
124          */
125         if (handle == ACPI_ROOT_OBJECT) {
126                 *ret_type = ACPI_TYPE_ANY;
127                 return (AE_OK);
128         }
129
130         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
131         if (ACPI_FAILURE(status)) {
132                 return (status);
133         }
134
135         /* Convert and validate the handle */
136
137         node = acpi_ns_validate_handle(handle);
138         if (!node) {
139                 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
140                 return (AE_BAD_PARAMETER);
141         }
142
143         *ret_type = node->type;
144
145         status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
146         return (status);
147 }
148
149 ACPI_EXPORT_SYMBOL(acpi_get_type)
150
151 /*******************************************************************************
152  *
153  * FUNCTION:    acpi_get_parent
154  *
155  * PARAMETERS:  handle          - Handle of object whose parent is desired
156  *              ret_handle      - Where the parent handle will be placed
157  *
158  * RETURN:      Status
159  *
160  * DESCRIPTION: Returns a handle to the parent of the object represented by
161  *              Handle.
162  *
163  ******************************************************************************/
164 acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
165 {
166         struct acpi_namespace_node *node;
167         struct acpi_namespace_node *parent_node;
168         acpi_status status;
169
170         if (!ret_handle) {
171                 return (AE_BAD_PARAMETER);
172         }
173
174         /* Special case for the predefined Root Node (no parent) */
175
176         if (handle == ACPI_ROOT_OBJECT) {
177                 return (AE_NULL_ENTRY);
178         }
179
180         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
181         if (ACPI_FAILURE(status)) {
182                 return (status);
183         }
184
185         /* Convert and validate the handle */
186
187         node = acpi_ns_validate_handle(handle);
188         if (!node) {
189                 status = AE_BAD_PARAMETER;
190                 goto unlock_and_exit;
191         }
192
193         /* Get the parent entry */
194
195         parent_node = node->parent;
196         *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
197
198         /* Return exception if parent is null */
199
200         if (!parent_node) {
201                 status = AE_NULL_ENTRY;
202         }
203
204 unlock_and_exit:
205
206         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
207         return (status);
208 }
209
210 ACPI_EXPORT_SYMBOL(acpi_get_parent)
211
212 /*******************************************************************************
213  *
214  * FUNCTION:    acpi_get_next_object
215  *
216  * PARAMETERS:  type            - Type of object to be searched for
217  *              parent          - Parent object whose children we are getting
218  *              last_child      - Previous child that was found.
219  *                                The NEXT child will be returned
220  *              ret_handle      - Where handle to the next object is placed
221  *
222  * RETURN:      Status
223  *
224  * DESCRIPTION: Return the next peer object within the namespace. If Handle is
225  *              valid, Scope is ignored. Otherwise, the first object within
226  *              Scope is returned.
227  *
228  ******************************************************************************/
229 acpi_status
230 acpi_get_next_object(acpi_object_type type,
231                      acpi_handle parent,
232                      acpi_handle child, acpi_handle * ret_handle)
233 {
234         acpi_status status;
235         struct acpi_namespace_node *node;
236         struct acpi_namespace_node *parent_node = NULL;
237         struct acpi_namespace_node *child_node = NULL;
238
239         /* Parameter validation */
240
241         if (type > ACPI_TYPE_EXTERNAL_MAX) {
242                 return (AE_BAD_PARAMETER);
243         }
244
245         status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
246         if (ACPI_FAILURE(status)) {
247                 return (status);
248         }
249
250         /* If null handle, use the parent */
251
252         if (!child) {
253
254                 /* Start search at the beginning of the specified scope */
255
256                 parent_node = acpi_ns_validate_handle(parent);
257                 if (!parent_node) {
258                         status = AE_BAD_PARAMETER;
259                         goto unlock_and_exit;
260                 }
261         } else {
262                 /* Non-null handle, ignore the parent */
263                 /* Convert and validate the handle */
264
265                 child_node = acpi_ns_validate_handle(child);
266                 if (!child_node) {
267                         status = AE_BAD_PARAMETER;
268                         goto unlock_and_exit;
269                 }
270         }
271
272         /* Internal function does the real work */
273
274         node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
275         if (!node) {
276                 status = AE_NOT_FOUND;
277                 goto unlock_and_exit;
278         }
279
280         if (ret_handle) {
281                 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
282         }
283
284 unlock_and_exit:
285
286         (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
287         return (status);
288 }
289
290 ACPI_EXPORT_SYMBOL(acpi_get_next_object)