initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / acpi / namespace / nsxfobj.c
blob537032073d0433c64777ac6cc62dd486aee7578b
1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2004, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME ("nsxfobj")
53 /*******************************************************************************
55 * FUNCTION: acpi_get_type
57 * PARAMETERS: Handle - Handle of object whose type is desired
58 * *ret_type - Where the type will be placed
60 * RETURN: Status
62 * DESCRIPTION: This routine returns the type associatd with a particular handle
64 ******************************************************************************/
66 acpi_status
67 acpi_get_type (
68 acpi_handle handle,
69 acpi_object_type *ret_type)
71 struct acpi_namespace_node *node;
72 acpi_status status;
75 /* Parameter Validation */
77 if (!ret_type) {
78 return (AE_BAD_PARAMETER);
82 * Special case for the predefined Root Node
83 * (return type ANY)
85 if (handle == ACPI_ROOT_OBJECT) {
86 *ret_type = ACPI_TYPE_ANY;
87 return (AE_OK);
90 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
91 if (ACPI_FAILURE (status)) {
92 return (status);
95 /* Convert and validate the handle */
97 node = acpi_ns_map_handle_to_node (handle);
98 if (!node) {
99 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
100 return (AE_BAD_PARAMETER);
103 *ret_type = node->type;
106 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
107 return (status);
111 /*******************************************************************************
113 * FUNCTION: acpi_get_parent
115 * PARAMETERS: Handle - Handle of object whose parent is desired
116 * ret_handle - Where the parent handle will be placed
118 * RETURN: Status
120 * DESCRIPTION: Returns a handle to the parent of the object represented by
121 * Handle.
123 ******************************************************************************/
125 acpi_status
126 acpi_get_parent (
127 acpi_handle handle,
128 acpi_handle *ret_handle)
130 struct acpi_namespace_node *node;
131 acpi_status status;
134 if (!ret_handle) {
135 return (AE_BAD_PARAMETER);
138 /* Special case for the predefined Root Node (no parent) */
140 if (handle == ACPI_ROOT_OBJECT) {
141 return (AE_NULL_ENTRY);
144 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
145 if (ACPI_FAILURE (status)) {
146 return (status);
149 /* Convert and validate the handle */
151 node = acpi_ns_map_handle_to_node (handle);
152 if (!node) {
153 status = AE_BAD_PARAMETER;
154 goto unlock_and_exit;
157 /* Get the parent entry */
159 *ret_handle =
160 acpi_ns_convert_entry_to_handle (acpi_ns_get_parent_node (node));
162 /* Return exception if parent is null */
164 if (!acpi_ns_get_parent_node (node)) {
165 status = AE_NULL_ENTRY;
169 unlock_and_exit:
171 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
172 return (status);
176 /*******************************************************************************
178 * FUNCTION: acpi_get_next_object
180 * PARAMETERS: Type - Type of object to be searched for
181 * Parent - Parent object whose children we are getting
182 * last_child - Previous child that was found.
183 * The NEXT child will be returned
184 * ret_handle - Where handle to the next object is placed
186 * RETURN: Status
188 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
189 * valid, Scope is ignored. Otherwise, the first object within
190 * Scope is returned.
192 ******************************************************************************/
194 acpi_status
195 acpi_get_next_object (
196 acpi_object_type type,
197 acpi_handle parent,
198 acpi_handle child,
199 acpi_handle *ret_handle)
201 acpi_status status;
202 struct acpi_namespace_node *node;
203 struct acpi_namespace_node *parent_node = NULL;
204 struct acpi_namespace_node *child_node = NULL;
207 /* Parameter validation */
209 if (type > ACPI_TYPE_EXTERNAL_MAX) {
210 return (AE_BAD_PARAMETER);
213 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
214 if (ACPI_FAILURE (status)) {
215 return (status);
218 /* If null handle, use the parent */
220 if (!child) {
221 /* Start search at the beginning of the specified scope */
223 parent_node = acpi_ns_map_handle_to_node (parent);
224 if (!parent_node) {
225 status = AE_BAD_PARAMETER;
226 goto unlock_and_exit;
229 else {
230 /* Non-null handle, ignore the parent */
231 /* Convert and validate the handle */
233 child_node = acpi_ns_map_handle_to_node (child);
234 if (!child_node) {
235 status = AE_BAD_PARAMETER;
236 goto unlock_and_exit;
240 /* Internal function does the real work */
242 node = acpi_ns_get_next_node (type, parent_node, child_node);
243 if (!node) {
244 status = AE_NOT_FOUND;
245 goto unlock_and_exit;
248 if (ret_handle) {
249 *ret_handle = acpi_ns_convert_entry_to_handle (node);
253 unlock_and_exit:
255 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
256 return (status);