1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
9 * Copyright (C) 2000 - 2005, 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
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.
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.
45 #include <linux/module.h>
47 #include <acpi/acpi.h>
48 #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
62 * DESCRIPTION: This routine returns the type associatd with a particular handle
64 ******************************************************************************/
65 acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
67 struct acpi_namespace_node *node;
70 /* Parameter Validation */
73 return (AE_BAD_PARAMETER);
77 * Special case for the predefined Root Node
80 if (handle == ACPI_ROOT_OBJECT) {
81 *ret_type = ACPI_TYPE_ANY;
85 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
86 if (ACPI_FAILURE(status)) {
90 /* Convert and validate the handle */
92 node = acpi_ns_map_handle_to_node(handle);
94 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
95 return (AE_BAD_PARAMETER);
98 *ret_type = node->type;
100 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
104 EXPORT_SYMBOL(acpi_get_type);
106 /*******************************************************************************
108 * FUNCTION: acpi_get_parent
110 * PARAMETERS: Handle - Handle of object whose parent is desired
111 * ret_handle - Where the parent handle will be placed
115 * DESCRIPTION: Returns a handle to the parent of the object represented by
118 ******************************************************************************/
120 acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
122 struct acpi_namespace_node *node;
126 return (AE_BAD_PARAMETER);
129 /* Special case for the predefined Root Node (no parent) */
131 if (handle == ACPI_ROOT_OBJECT) {
132 return (AE_NULL_ENTRY);
135 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
136 if (ACPI_FAILURE(status)) {
140 /* Convert and validate the handle */
142 node = acpi_ns_map_handle_to_node(handle);
144 status = AE_BAD_PARAMETER;
145 goto unlock_and_exit;
148 /* Get the parent entry */
151 acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
153 /* Return exception if parent is null */
155 if (!acpi_ns_get_parent_node(node)) {
156 status = AE_NULL_ENTRY;
161 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
165 EXPORT_SYMBOL(acpi_get_parent);
167 /*******************************************************************************
169 * FUNCTION: acpi_get_next_object
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
179 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
180 * valid, Scope is ignored. Otherwise, the first object within
183 ******************************************************************************/
186 acpi_get_next_object(acpi_object_type type,
188 acpi_handle child, acpi_handle * ret_handle)
191 struct acpi_namespace_node *node;
192 struct acpi_namespace_node *parent_node = NULL;
193 struct acpi_namespace_node *child_node = NULL;
195 /* Parameter validation */
197 if (type > ACPI_TYPE_EXTERNAL_MAX) {
198 return (AE_BAD_PARAMETER);
201 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE(status)) {
206 /* If null handle, use the parent */
209 /* Start search at the beginning of the specified scope */
211 parent_node = acpi_ns_map_handle_to_node(parent);
213 status = AE_BAD_PARAMETER;
214 goto unlock_and_exit;
217 /* Non-null handle, ignore the parent */
218 /* Convert and validate the handle */
220 child_node = acpi_ns_map_handle_to_node(child);
222 status = AE_BAD_PARAMETER;
223 goto unlock_and_exit;
227 /* Internal function does the real work */
229 node = acpi_ns_get_next_node(type, parent_node, child_node);
231 status = AE_NOT_FOUND;
232 goto unlock_and_exit;
236 *ret_handle = acpi_ns_convert_entry_to_handle(node);
241 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
245 EXPORT_SYMBOL(acpi_get_next_object);