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 - 2004, 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 
46 #include <acpi/acpi.h>
47 #include <acpi/acnamesp.h>
48 
49 
50 #define _COMPONENT          ACPI_NAMESPACE
51 	 ACPI_MODULE_NAME    ("nsxfobj")
52 
53 /*******************************************************************************
54  *
55  * FUNCTION:    acpi_get_type
56  *
57  * PARAMETERS:  Handle          - Handle of object whose type is desired
58  *              *ret_type       - Where the type will be placed
59  *
60  * RETURN:      Status
61  *
62  * DESCRIPTION: This routine returns the type associatd with a particular handle
63  *
64  ******************************************************************************/
65 
66 acpi_status
acpi_get_type(acpi_handle handle,acpi_object_type * ret_type)67 acpi_get_type (
68 	acpi_handle                     handle,
69 	acpi_object_type                *ret_type)
70 {
71 	struct acpi_namespace_node      *node;
72 	acpi_status                     status;
73 
74 
75 	/* Parameter Validation */
76 
77 	if (!ret_type) {
78 		return (AE_BAD_PARAMETER);
79 	}
80 
81 	/*
82 	 * Special case for the predefined Root Node
83 	 * (return type ANY)
84 	 */
85 	if (handle == ACPI_ROOT_OBJECT) {
86 		*ret_type = ACPI_TYPE_ANY;
87 		return (AE_OK);
88 	}
89 
90 	status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
91 	if (ACPI_FAILURE (status)) {
92 		return (status);
93 	}
94 
95 	/* Convert and validate the handle */
96 
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);
101 	}
102 
103 	*ret_type = node->type;
104 
105 
106 	status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
107 	return (status);
108 }
109 
110 
111 /*******************************************************************************
112  *
113  * FUNCTION:    acpi_get_parent
114  *
115  * PARAMETERS:  Handle          - Handle of object whose parent is desired
116  *              ret_handle      - Where the parent handle will be placed
117  *
118  * RETURN:      Status
119  *
120  * DESCRIPTION: Returns a handle to the parent of the object represented by
121  *              Handle.
122  *
123  ******************************************************************************/
124 
125 acpi_status
acpi_get_parent(acpi_handle handle,acpi_handle * ret_handle)126 acpi_get_parent (
127 	acpi_handle                     handle,
128 	acpi_handle                     *ret_handle)
129 {
130 	struct acpi_namespace_node      *node;
131 	acpi_status                     status;
132 
133 
134 	if (!ret_handle) {
135 		return (AE_BAD_PARAMETER);
136 	}
137 
138 	/* Special case for the predefined Root Node (no parent) */
139 
140 	if (handle == ACPI_ROOT_OBJECT) {
141 		return (AE_NULL_ENTRY);
142 	}
143 
144 	status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
145 	if (ACPI_FAILURE (status)) {
146 		return (status);
147 	}
148 
149 	/* Convert and validate the handle */
150 
151 	node = acpi_ns_map_handle_to_node (handle);
152 	if (!node) {
153 		status = AE_BAD_PARAMETER;
154 		goto unlock_and_exit;
155 	}
156 
157 	/* Get the parent entry */
158 
159 	*ret_handle =
160 		acpi_ns_convert_entry_to_handle (acpi_ns_get_parent_node (node));
161 
162 	/* Return exception if parent is null */
163 
164 	if (!acpi_ns_get_parent_node (node)) {
165 		status = AE_NULL_ENTRY;
166 	}
167 
168 
169 unlock_and_exit:
170 
171 	(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
172 	return (status);
173 }
174 
175 
176 /*******************************************************************************
177  *
178  * FUNCTION:    acpi_get_next_object
179  *
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
185  *
186  * RETURN:      Status
187  *
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.
191  *
192  ******************************************************************************/
193 
194 acpi_status
acpi_get_next_object(acpi_object_type type,acpi_handle parent,acpi_handle child,acpi_handle * ret_handle)195 acpi_get_next_object (
196 	acpi_object_type                type,
197 	acpi_handle                     parent,
198 	acpi_handle                     child,
199 	acpi_handle                     *ret_handle)
200 {
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;
205 
206 
207 	/* Parameter validation */
208 
209 	if (type > ACPI_TYPE_EXTERNAL_MAX) {
210 		return (AE_BAD_PARAMETER);
211 	}
212 
213 	status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
214 	if (ACPI_FAILURE (status)) {
215 		return (status);
216 	}
217 
218 	/* If null handle, use the parent */
219 
220 	if (!child) {
221 		/* Start search at the beginning of the specified scope */
222 
223 		parent_node = acpi_ns_map_handle_to_node (parent);
224 		if (!parent_node) {
225 			status = AE_BAD_PARAMETER;
226 			goto unlock_and_exit;
227 		}
228 	}
229 	else {
230 		/* Non-null handle, ignore the parent */
231 		/* Convert and validate the handle */
232 
233 		child_node = acpi_ns_map_handle_to_node (child);
234 		if (!child_node) {
235 			status = AE_BAD_PARAMETER;
236 			goto unlock_and_exit;
237 		}
238 	}
239 
240 	/* Internal function does the real work */
241 
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;
246 	}
247 
248 	if (ret_handle) {
249 		*ret_handle = acpi_ns_convert_entry_to_handle (node);
250 	}
251 
252 
253 unlock_and_exit:
254 
255 	(void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
256 	return (status);
257 }
258 
259 
260