1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
9 * Copyright (C) 2000 - 2016, Intel Corp.
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 #define EXPORT_ACPI_INTERFACES
47 #include <acpi/acpi.h>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME("nsxfobj")
54 /*******************************************************************************
56 * FUNCTION: acpi_get_type
58 * PARAMETERS: handle - Handle of object whose type is desired
59 * ret_type - Where the type will be placed
63 * DESCRIPTION: This routine returns the type associatd with a particular handle
65 ******************************************************************************/
66 acpi_status
acpi_get_type(acpi_handle handle
, acpi_object_type
*ret_type
)
68 struct acpi_namespace_node
*node
;
71 /* Parameter Validation */
74 return (AE_BAD_PARAMETER
);
77 /* Special case for the predefined Root Node (return type ANY) */
79 if (handle
== ACPI_ROOT_OBJECT
) {
80 *ret_type
= ACPI_TYPE_ANY
;
84 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
85 if (ACPI_FAILURE(status
)) {
89 /* Convert and validate the handle */
91 node
= acpi_ns_validate_handle(handle
);
93 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
94 return (AE_BAD_PARAMETER
);
97 *ret_type
= node
->type
;
99 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
103 ACPI_EXPORT_SYMBOL(acpi_get_type
)
105 /*******************************************************************************
107 * FUNCTION: acpi_get_parent
109 * PARAMETERS: handle - Handle of object whose parent is desired
110 * ret_handle - Where the parent handle will be placed
114 * DESCRIPTION: Returns a handle to the parent of the object represented by
117 ******************************************************************************/
118 acpi_status
acpi_get_parent(acpi_handle handle
, acpi_handle
*ret_handle
)
120 struct acpi_namespace_node
*node
;
121 struct acpi_namespace_node
*parent_node
;
125 return (AE_BAD_PARAMETER
);
128 /* Special case for the predefined Root Node (no parent) */
130 if (handle
== ACPI_ROOT_OBJECT
) {
131 return (AE_NULL_ENTRY
);
134 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
135 if (ACPI_FAILURE(status
)) {
139 /* Convert and validate the handle */
141 node
= acpi_ns_validate_handle(handle
);
143 status
= AE_BAD_PARAMETER
;
144 goto unlock_and_exit
;
147 /* Get the parent entry */
149 parent_node
= node
->parent
;
150 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, parent_node
);
152 /* Return exception if parent is null */
155 status
= AE_NULL_ENTRY
;
160 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
164 ACPI_EXPORT_SYMBOL(acpi_get_parent
)
166 /*******************************************************************************
168 * FUNCTION: acpi_get_next_object
170 * PARAMETERS: type - Type of object to be searched for
171 * parent - Parent object whose children we are getting
172 * last_child - Previous child that was found.
173 * The NEXT child will be returned
174 * ret_handle - Where handle to the next object is placed
178 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
179 * valid, Scope is ignored. Otherwise, the first object within
182 ******************************************************************************/
184 acpi_get_next_object(acpi_object_type type
,
186 acpi_handle child
, acpi_handle
*ret_handle
)
189 struct acpi_namespace_node
*node
;
190 struct acpi_namespace_node
*parent_node
= NULL
;
191 struct acpi_namespace_node
*child_node
= NULL
;
193 /* Parameter validation */
195 if (type
> ACPI_TYPE_EXTERNAL_MAX
) {
196 return (AE_BAD_PARAMETER
);
199 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
200 if (ACPI_FAILURE(status
)) {
204 /* If null handle, use the parent */
208 /* Start search at the beginning of the specified scope */
210 parent_node
= acpi_ns_validate_handle(parent
);
212 status
= AE_BAD_PARAMETER
;
213 goto unlock_and_exit
;
216 /* Non-null handle, ignore the parent */
217 /* Convert and validate the handle */
219 child_node
= acpi_ns_validate_handle(child
);
221 status
= AE_BAD_PARAMETER
;
222 goto unlock_and_exit
;
226 /* Internal function does the real work */
228 node
= acpi_ns_get_next_node_typed(type
, parent_node
, child_node
);
230 status
= AE_NOT_FOUND
;
231 goto unlock_and_exit
;
235 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, node
);
240 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
244 ACPI_EXPORT_SYMBOL(acpi_get_next_object
)