blob: 0856d42e690982c66790ddb564a080a79c8421d9 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*******************************************************************************
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
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("nsxfobj")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_get_type
56 *
57 * PARAMETERS: Handle - Handle of object whose type is desired
Robert Moore44f6c012005-04-18 22:49:35 -040058 * ret_type - Where the type will be placed
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: This routine returns the type associatd with a particular handle
63 *
64 ******************************************************************************/
Len Brown4be44fc2005-08-05 00:44:28 -040065acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
Linus Torvalds1da177e2005-04-16 15:20:36 -070066{
Len Brown4be44fc2005-08-05 00:44:28 -040067 struct acpi_namespace_node *node;
68 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -070069
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
Len Brown4be44fc2005-08-05 00:44:28 -040085 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
86 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return (status);
88 }
89
90 /* Convert and validate the handle */
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -040094 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return (AE_BAD_PARAMETER);
96 }
97
98 *ret_type = node->type;
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 return (status);
102}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
Len Brown4be44fc2005-08-05 00:44:28 -0400104EXPORT_SYMBOL(acpi_get_type);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700105
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
Len Brown4be44fc2005-08-05 00:44:28 -0400120acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121{
Len Brown4be44fc2005-08-05 00:44:28 -0400122 struct acpi_namespace_node *node;
123 acpi_status status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124
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
Len Brown4be44fc2005-08-05 00:44:28 -0400135 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
136 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137 return (status);
138 }
139
140 /* Convert and validate the handle */
141
Len Brown4be44fc2005-08-05 00:44:28 -0400142 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143 if (!node) {
144 status = AE_BAD_PARAMETER;
145 goto unlock_and_exit;
146 }
147
148 /* Get the parent entry */
149
150 *ret_handle =
Len Brown4be44fc2005-08-05 00:44:28 -0400151 acpi_ns_convert_entry_to_handle(acpi_ns_get_parent_node(node));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* Return exception if parent is null */
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 if (!acpi_ns_get_parent_node(node)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 status = AE_NULL_ENTRY;
157 }
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700160
Len Brown4be44fc2005-08-05 00:44:28 -0400161 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 return (status);
163}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700164
Len Brown4be44fc2005-08-05 00:44:28 -0400165EXPORT_SYMBOL(acpi_get_parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166
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
Len Brown4be44fc2005-08-05 00:44:28 -0400186acpi_get_next_object(acpi_object_type type,
187 acpi_handle parent,
188 acpi_handle child, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700189{
Len Brown4be44fc2005-08-05 00:44:28 -0400190 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;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
195 /* Parameter validation */
196
197 if (type > ACPI_TYPE_EXTERNAL_MAX) {
198 return (AE_BAD_PARAMETER);
199 }
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 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
Len Brown4be44fc2005-08-05 00:44:28 -0400211 parent_node = acpi_ns_map_handle_to_node(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 if (!parent_node) {
213 status = AE_BAD_PARAMETER;
214 goto unlock_and_exit;
215 }
Len Brown4be44fc2005-08-05 00:44:28 -0400216 } else {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 /* Non-null handle, ignore the parent */
218 /* Convert and validate the handle */
219
Len Brown4be44fc2005-08-05 00:44:28 -0400220 child_node = acpi_ns_map_handle_to_node(child);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221 if (!child_node) {
222 status = AE_BAD_PARAMETER;
223 goto unlock_and_exit;
224 }
225 }
226
227 /* Internal function does the real work */
228
Len Brown4be44fc2005-08-05 00:44:28 -0400229 node = acpi_ns_get_next_node(type, parent_node, child_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 if (!node) {
231 status = AE_NOT_FOUND;
232 goto unlock_and_exit;
233 }
234
235 if (ret_handle) {
Len Brown4be44fc2005-08-05 00:44:28 -0400236 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 }
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Len Brown4be44fc2005-08-05 00:44:28 -0400241 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 return (status);
243}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700244
Robert Moore44f6c012005-04-18 22:49:35 -0400245EXPORT_SYMBOL(acpi_get_next_object);