1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /*******************************************************************************
4 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
5 * ACPI Object oriented interfaces
7 ******************************************************************************/
9 #define EXPORT_ACPI_INTERFACES
11 #include <acpi/acpi.h>
15 #define _COMPONENT ACPI_NAMESPACE
16 ACPI_MODULE_NAME("nsxfobj")
18 /*******************************************************************************
20 * FUNCTION: acpi_get_type
22 * PARAMETERS: handle - Handle of object whose type is desired
23 * ret_type - Where the type will be placed
27 * DESCRIPTION: This routine returns the type associatd with a particular handle
29 ******************************************************************************/
30 acpi_status
acpi_get_type(acpi_handle handle
, acpi_object_type
*ret_type
)
32 struct acpi_namespace_node
*node
;
35 /* Parameter Validation */
38 return (AE_BAD_PARAMETER
);
41 /* Special case for the predefined Root Node (return type ANY) */
43 if (handle
== ACPI_ROOT_OBJECT
) {
44 *ret_type
= ACPI_TYPE_ANY
;
48 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
49 if (ACPI_FAILURE(status
)) {
53 /* Convert and validate the handle */
55 node
= acpi_ns_validate_handle(handle
);
57 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
58 return (AE_BAD_PARAMETER
);
61 *ret_type
= node
->type
;
63 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
67 ACPI_EXPORT_SYMBOL(acpi_get_type
)
69 /*******************************************************************************
71 * FUNCTION: acpi_get_parent
73 * PARAMETERS: handle - Handle of object whose parent is desired
74 * ret_handle - Where the parent handle will be placed
78 * DESCRIPTION: Returns a handle to the parent of the object represented by
81 ******************************************************************************/
82 acpi_status
acpi_get_parent(acpi_handle handle
, acpi_handle
*ret_handle
)
84 struct acpi_namespace_node
*node
;
85 struct acpi_namespace_node
*parent_node
;
89 return (AE_BAD_PARAMETER
);
92 /* Special case for the predefined Root Node (no parent) */
94 if (handle
== ACPI_ROOT_OBJECT
) {
95 return (AE_NULL_ENTRY
);
98 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
99 if (ACPI_FAILURE(status
)) {
103 /* Convert and validate the handle */
105 node
= acpi_ns_validate_handle(handle
);
107 status
= AE_BAD_PARAMETER
;
108 goto unlock_and_exit
;
111 /* Get the parent entry */
113 parent_node
= node
->parent
;
114 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, parent_node
);
116 /* Return exception if parent is null */
119 status
= AE_NULL_ENTRY
;
124 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
128 ACPI_EXPORT_SYMBOL(acpi_get_parent
)
130 /*******************************************************************************
132 * FUNCTION: acpi_get_next_object
134 * PARAMETERS: type - Type of object to be searched for
135 * parent - Parent object whose children we are getting
136 * last_child - Previous child that was found.
137 * The NEXT child will be returned
138 * ret_handle - Where handle to the next object is placed
142 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
143 * valid, Scope is ignored. Otherwise, the first object within
146 ******************************************************************************/
148 acpi_get_next_object(acpi_object_type type
,
150 acpi_handle child
, acpi_handle
*ret_handle
)
153 struct acpi_namespace_node
*node
;
154 struct acpi_namespace_node
*parent_node
= NULL
;
155 struct acpi_namespace_node
*child_node
= NULL
;
157 /* Parameter validation */
159 if (type
> ACPI_TYPE_EXTERNAL_MAX
) {
160 return (AE_BAD_PARAMETER
);
163 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
164 if (ACPI_FAILURE(status
)) {
168 /* If null handle, use the parent */
172 /* Start search at the beginning of the specified scope */
174 parent_node
= acpi_ns_validate_handle(parent
);
176 status
= AE_BAD_PARAMETER
;
177 goto unlock_and_exit
;
180 /* Non-null handle, ignore the parent */
181 /* Convert and validate the handle */
183 child_node
= acpi_ns_validate_handle(child
);
185 status
= AE_BAD_PARAMETER
;
186 goto unlock_and_exit
;
190 /* Internal function does the real work */
192 node
= acpi_ns_get_next_node_typed(type
, parent_node
, child_node
);
194 status
= AE_NOT_FOUND
;
195 goto unlock_and_exit
;
199 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, node
);
204 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
208 ACPI_EXPORT_SYMBOL(acpi_get_next_object
)