1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
9 * Copyright (C) 2000 - 2013, 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 #include <linux/export.h>
46 #include <acpi/acpi.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nsxfobj")
53 /*******************************************************************************
55 * FUNCTION: acpi_get_id
57 * PARAMETERS: Handle - Handle of object whose id is desired
58 * ret_id - Where the id will be placed
62 * DESCRIPTION: This routine returns the owner id associated with a handle
64 ******************************************************************************/
65 acpi_status
acpi_get_id(acpi_handle handle
, acpi_owner_id
* ret_id
)
67 struct acpi_namespace_node
*node
;
70 /* Parameter Validation */
73 return (AE_BAD_PARAMETER
);
76 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
77 if (ACPI_FAILURE(status
)) {
81 /* Convert and validate the handle */
83 node
= acpi_ns_validate_handle(handle
);
85 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
86 return (AE_BAD_PARAMETER
);
89 *ret_id
= node
->owner_id
;
91 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
95 ACPI_EXPORT_SYMBOL(acpi_get_id
)
97 /*******************************************************************************
99 * FUNCTION: acpi_get_type
101 * PARAMETERS: handle - Handle of object whose type is desired
102 * ret_type - Where the type will be placed
106 * DESCRIPTION: This routine returns the type associatd with a particular handle
108 ******************************************************************************/
109 acpi_status
acpi_get_type(acpi_handle handle
, acpi_object_type
* ret_type
)
111 struct acpi_namespace_node
*node
;
114 /* Parameter Validation */
117 return (AE_BAD_PARAMETER
);
121 * Special case for the predefined Root Node
124 if (handle
== ACPI_ROOT_OBJECT
) {
125 *ret_type
= ACPI_TYPE_ANY
;
129 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
130 if (ACPI_FAILURE(status
)) {
134 /* Convert and validate the handle */
136 node
= acpi_ns_validate_handle(handle
);
138 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
139 return (AE_BAD_PARAMETER
);
142 *ret_type
= node
->type
;
144 status
= acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
148 ACPI_EXPORT_SYMBOL(acpi_get_type
)
150 /*******************************************************************************
152 * FUNCTION: acpi_get_parent
154 * PARAMETERS: handle - Handle of object whose parent is desired
155 * ret_handle - Where the parent handle will be placed
159 * DESCRIPTION: Returns a handle to the parent of the object represented by
162 ******************************************************************************/
163 acpi_status
acpi_get_parent(acpi_handle handle
, acpi_handle
* ret_handle
)
165 struct acpi_namespace_node
*node
;
166 struct acpi_namespace_node
*parent_node
;
170 return (AE_BAD_PARAMETER
);
173 /* Special case for the predefined Root Node (no parent) */
175 if (handle
== ACPI_ROOT_OBJECT
) {
176 return (AE_NULL_ENTRY
);
179 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
180 if (ACPI_FAILURE(status
)) {
184 /* Convert and validate the handle */
186 node
= acpi_ns_validate_handle(handle
);
188 status
= AE_BAD_PARAMETER
;
189 goto unlock_and_exit
;
192 /* Get the parent entry */
194 parent_node
= node
->parent
;
195 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, parent_node
);
197 /* Return exception if parent is null */
200 status
= AE_NULL_ENTRY
;
205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
209 ACPI_EXPORT_SYMBOL(acpi_get_parent
)
211 /*******************************************************************************
213 * FUNCTION: acpi_get_next_object
215 * PARAMETERS: type - Type of object to be searched for
216 * parent - Parent object whose children we are getting
217 * last_child - Previous child that was found.
218 * The NEXT child will be returned
219 * ret_handle - Where handle to the next object is placed
223 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
224 * valid, Scope is ignored. Otherwise, the first object within
227 ******************************************************************************/
229 acpi_get_next_object(acpi_object_type type
,
231 acpi_handle child
, acpi_handle
* ret_handle
)
234 struct acpi_namespace_node
*node
;
235 struct acpi_namespace_node
*parent_node
= NULL
;
236 struct acpi_namespace_node
*child_node
= NULL
;
238 /* Parameter validation */
240 if (type
> ACPI_TYPE_EXTERNAL_MAX
) {
241 return (AE_BAD_PARAMETER
);
244 status
= acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE
);
245 if (ACPI_FAILURE(status
)) {
249 /* If null handle, use the parent */
253 /* Start search at the beginning of the specified scope */
255 parent_node
= acpi_ns_validate_handle(parent
);
257 status
= AE_BAD_PARAMETER
;
258 goto unlock_and_exit
;
261 /* Non-null handle, ignore the parent */
262 /* Convert and validate the handle */
264 child_node
= acpi_ns_validate_handle(child
);
266 status
= AE_BAD_PARAMETER
;
267 goto unlock_and_exit
;
271 /* Internal function does the real work */
273 node
= acpi_ns_get_next_node_typed(type
, parent_node
, child_node
);
275 status
= AE_NOT_FOUND
;
276 goto unlock_and_exit
;
280 *ret_handle
= ACPI_CAST_PTR(acpi_handle
, node
);
285 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE
);
289 ACPI_EXPORT_SYMBOL(acpi_get_next_object
)