1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
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
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.
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
62 * DESCRIPTION: This routine returns the type associatd with a particular handle
64 ******************************************************************************/
69 acpi_object_type
*ret_type
)
71 struct acpi_namespace_node
*node
;
75 /* Parameter Validation */
78 return (AE_BAD_PARAMETER
);
82 * Special case for the predefined Root Node
85 if (handle
== ACPI_ROOT_OBJECT
) {
86 *ret_type
= ACPI_TYPE_ANY
;
90 status
= acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE
);
91 if (ACPI_FAILURE (status
)) {
95 /* Convert and validate the handle */
97 node
= acpi_ns_map_handle_to_node (handle
);
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
);
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
120 * DESCRIPTION: Returns a handle to the parent of the object represented by
123 ******************************************************************************/
128 acpi_handle
*ret_handle
)
130 struct acpi_namespace_node
*node
;
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
)) {
149 /* Convert and validate the handle */
151 node
= acpi_ns_map_handle_to_node (handle
);
153 status
= AE_BAD_PARAMETER
;
154 goto unlock_and_exit
;
157 /* Get the parent entry */
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
;
171 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);
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
188 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
189 * valid, Scope is ignored. Otherwise, the first object within
192 ******************************************************************************/
195 acpi_get_next_object (
196 acpi_object_type type
,
199 acpi_handle
*ret_handle
)
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
)) {
218 /* If null handle, use the parent */
221 /* Start search at the beginning of the specified scope */
223 parent_node
= acpi_ns_map_handle_to_node (parent
);
225 status
= AE_BAD_PARAMETER
;
226 goto unlock_and_exit
;
230 /* Non-null handle, ignore the parent */
231 /* Convert and validate the handle */
233 child_node
= acpi_ns_map_handle_to_node (child
);
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
);
244 status
= AE_NOT_FOUND
;
245 goto unlock_and_exit
;
249 *ret_handle
= acpi_ns_convert_entry_to_handle (node
);
255 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE
);