ACPICA: Clarify ACPI_FREE_BUFFER usage.
[deliverable/linux.git] / drivers / acpi / acpica / 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/*
25f044e6 9 * Copyright (C) 2000 - 2013, Intel Corp.
1da177e4
LT
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
839e928f
LZ
45#define EXPORT_ACPI_INTERFACES
46
1da177e4 47#include <acpi/acpi.h>
e2f7a777
LB
48#include "accommon.h"
49#include "acnamesp.h"
1da177e4 50
1da177e4 51#define _COMPONENT ACPI_NAMESPACE
4be44fcd 52ACPI_MODULE_NAME("nsxfobj")
1da177e4 53
0f0fe1a0
JK
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 ******************************************************************************/
66acpi_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
f24b664d 84 node = acpi_ns_validate_handle(handle);
0f0fe1a0
JK
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
96ACPI_EXPORT_SYMBOL(acpi_get_id)
97
1da177e4
LT
98/*******************************************************************************
99 *
100 * FUNCTION: acpi_get_type
101 *
ba494bee 102 * PARAMETERS: handle - Handle of object whose type is desired
44f6c012 103 * ret_type - Where the type will be placed
1da177e4
LT
104 *
105 * RETURN: Status
106 *
107 * DESCRIPTION: This routine returns the type associatd with a particular handle
108 *
109 ******************************************************************************/
4be44fcd 110acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
1da177e4 111{
4be44fcd
LB
112 struct acpi_namespace_node *node;
113 acpi_status status;
1da177e4
LT
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
4be44fcd
LB
130 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
131 if (ACPI_FAILURE(status)) {
1da177e4
LT
132 return (status);
133 }
134
135 /* Convert and validate the handle */
136
f24b664d 137 node = acpi_ns_validate_handle(handle);
1da177e4 138 if (!node) {
4be44fcd 139 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
140 return (AE_BAD_PARAMETER);
141 }
142
143 *ret_type = node->type;
144
4be44fcd 145 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
146 return (status);
147}
1da177e4 148
8313524a 149ACPI_EXPORT_SYMBOL(acpi_get_type)
1da177e4
LT
150
151/*******************************************************************************
152 *
153 * FUNCTION: acpi_get_parent
154 *
ba494bee 155 * PARAMETERS: handle - Handle of object whose parent is desired
1da177e4
LT
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 ******************************************************************************/
4be44fcd 164acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
1da177e4 165{
4be44fcd 166 struct acpi_namespace_node *node;
c446eed6 167 struct acpi_namespace_node *parent_node;
4be44fcd 168 acpi_status status;
1da177e4
LT
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
4be44fcd
LB
180 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
181 if (ACPI_FAILURE(status)) {
1da177e4
LT
182 return (status);
183 }
184
185 /* Convert and validate the handle */
186
f24b664d 187 node = acpi_ns_validate_handle(handle);
1da177e4
LT
188 if (!node) {
189 status = AE_BAD_PARAMETER;
190 goto unlock_and_exit;
191 }
192
193 /* Get the parent entry */
194
c45b5c09 195 parent_node = node->parent;
f24b664d 196 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
1da177e4
LT
197
198 /* Return exception if parent is null */
199
c446eed6 200 if (!parent_node) {
1da177e4
LT
201 status = AE_NULL_ENTRY;
202 }
203
4be44fcd 204 unlock_and_exit:
1da177e4 205
4be44fcd 206 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
207 return (status);
208}
1da177e4 209
8313524a 210ACPI_EXPORT_SYMBOL(acpi_get_parent)
1da177e4
LT
211
212/*******************************************************************************
213 *
214 * FUNCTION: acpi_get_next_object
215 *
ba494bee
BM
216 * PARAMETERS: type - Type of object to be searched for
217 * parent - Parent object whose children we are getting
1da177e4
LT
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 *
73a3090a
BM
224 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
225 * valid, Scope is ignored. Otherwise, the first object within
1da177e4
LT
226 * Scope is returned.
227 *
228 ******************************************************************************/
1da177e4 229acpi_status
4be44fcd
LB
230acpi_get_next_object(acpi_object_type type,
231 acpi_handle parent,
232 acpi_handle child, acpi_handle * ret_handle)
1da177e4 233{
4be44fcd
LB
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;
1da177e4
LT
238
239 /* Parameter validation */
240
241 if (type > ACPI_TYPE_EXTERNAL_MAX) {
242 return (AE_BAD_PARAMETER);
243 }
244
4be44fcd
LB
245 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
246 if (ACPI_FAILURE(status)) {
1da177e4
LT
247 return (status);
248 }
249
250 /* If null handle, use the parent */
251
252 if (!child) {
52fc0b02 253
1da177e4
LT
254 /* Start search at the beginning of the specified scope */
255
f24b664d 256 parent_node = acpi_ns_validate_handle(parent);
1da177e4
LT
257 if (!parent_node) {
258 status = AE_BAD_PARAMETER;
259 goto unlock_and_exit;
260 }
4be44fcd 261 } else {
1da177e4
LT
262 /* Non-null handle, ignore the parent */
263 /* Convert and validate the handle */
264
f24b664d 265 child_node = acpi_ns_validate_handle(child);
1da177e4
LT
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
8c725bf9 274 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
1da177e4
LT
275 if (!node) {
276 status = AE_NOT_FOUND;
277 goto unlock_and_exit;
278 }
279
280 if (ret_handle) {
f24b664d 281 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
1da177e4
LT
282 }
283
4be44fcd 284 unlock_and_exit:
1da177e4 285
4be44fcd 286 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
1da177e4
LT
287 return (status);
288}
1da177e4 289
8313524a 290ACPI_EXPORT_SYMBOL(acpi_get_next_object)
This page took 1.057952 seconds and 5 git commands to generate.