[ACPI] Lindent all ACPI files
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / namespace / nsxfobj.c
CommitLineData
1da177e4
LT
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
1da177e4 50#define _COMPONENT ACPI_NAMESPACE
4be44fcd 51ACPI_MODULE_NAME("nsxfobj")
1da177e4
LT
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_get_type
56 *
57 * PARAMETERS: Handle - Handle of object whose type is desired
44f6c012 58 * ret_type - Where the type will be placed
1da177e4
LT
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: This routine returns the type associatd with a particular handle
63 *
64 ******************************************************************************/
4be44fcd 65acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
1da177e4 66{
4be44fcd
LB
67 struct acpi_namespace_node *node;
68 acpi_status status;
1da177e4
LT
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
4be44fcd
LB
85 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
86 if (ACPI_FAILURE(status)) {
1da177e4
LT
87 return (status);
88 }
89
90 /* Convert and validate the handle */
91
4be44fcd 92 node = acpi_ns_map_handle_to_node(handle);
1da177e4 93 if (!node) {
4be44fcd 94 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
95 return (AE_BAD_PARAMETER);
96 }
97
98 *ret_type = node->type;
99
4be44fcd 100 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
101 return (status);
102}
1da177e4 103
4be44fcd 104EXPORT_SYMBOL(acpi_get_type);
1da177e4
LT
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
4be44fcd 120acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
1da177e4 121{
4be44fcd
LB
122 struct acpi_namespace_node *node;
123 acpi_status status;
1da177e4
LT
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
4be44fcd
LB
135 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
136 if (ACPI_FAILURE(status)) {
1da177e4
LT
137 return (status);
138 }
139
140 /* Convert and validate the handle */
141
4be44fcd 142 node = acpi_ns_map_handle_to_node(handle);
1da177e4
LT
143 if (!node) {
144 status = AE_BAD_PARAMETER;
145 goto unlock_and_exit;
146 }
147
148 /* Get the parent entry */
149
150 *ret_handle =
4be44fcd 151 acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
1da177e4
LT
152
153 /* Return exception if parent is null */
154
4be44fcd 155 if (!acpi_ns_get_parent_node(node)) {
1da177e4
LT
156 status = AE_NULL_ENTRY;
157 }
158
4be44fcd 159 unlock_and_exit:
1da177e4 160
4be44fcd 161 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
162 return (status);
163}
1da177e4 164
4be44fcd 165EXPORT_SYMBOL(acpi_get_parent);
1da177e4
LT
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
185acpi_status
4be44fcd
LB
186acpi_get_next_object(acpi_object_type type,
187 acpi_handle parent,
188 acpi_handle child, acpi_handle * ret_handle)
1da177e4 189{
4be44fcd
LB
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;
1da177e4
LT
194
195 /* Parameter validation */
196
197 if (type > ACPI_TYPE_EXTERNAL_MAX) {
198 return (AE_BAD_PARAMETER);
199 }
200
4be44fcd
LB
201 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE(status)) {
1da177e4
LT
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
4be44fcd 211 parent_node = acpi_ns_map_handle_to_node(parent);
1da177e4
LT
212 if (!parent_node) {
213 status = AE_BAD_PARAMETER;
214 goto unlock_and_exit;
215 }
4be44fcd 216 } else {
1da177e4
LT
217 /* Non-null handle, ignore the parent */
218 /* Convert and validate the handle */
219
4be44fcd 220 child_node = acpi_ns_map_handle_to_node(child);
1da177e4
LT
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
4be44fcd 229 node = acpi_ns_get_next_node(type, parent_node, child_node);
1da177e4
LT
230 if (!node) {
231 status = AE_NOT_FOUND;
232 goto unlock_and_exit;
233 }
234
235 if (ret_handle) {
4be44fcd 236 *ret_handle = acpi_ns_convert_entry_to_handle(node);
1da177e4
LT
237 }
238
4be44fcd 239 unlock_and_exit:
1da177e4 240
4be44fcd 241 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
242 return (status);
243}
1da177e4 244
44f6c012 245EXPORT_SYMBOL(acpi_get_next_object);