Linux 4.1.16
[linux/fpc-iii.git] / drivers / acpi / acpica / nsxfobj.c
blob793383501f81f05cffd099559a0b6d8787f53880
1 /*******************************************************************************
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
6 ******************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2015, 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
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.
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.
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.
45 #define EXPORT_ACPI_INTERFACES
47 #include <acpi/acpi.h>
48 #include "accommon.h"
49 #include "acnamesp.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
61 * RETURN: Status
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;
69 acpi_status status;
71 /* Parameter Validation */
73 if (!ret_type) {
74 return (AE_BAD_PARAMETER);
78 * Special case for the predefined Root Node
79 * (return type ANY)
81 if (handle == ACPI_ROOT_OBJECT) {
82 *ret_type = ACPI_TYPE_ANY;
83 return (AE_OK);
86 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
87 if (ACPI_FAILURE(status)) {
88 return (status);
91 /* Convert and validate the handle */
93 node = acpi_ns_validate_handle(handle);
94 if (!node) {
95 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
96 return (AE_BAD_PARAMETER);
99 *ret_type = node->type;
101 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
102 return (status);
105 ACPI_EXPORT_SYMBOL(acpi_get_type)
107 /*******************************************************************************
109 * FUNCTION: acpi_get_parent
111 * PARAMETERS: handle - Handle of object whose parent is desired
112 * ret_handle - Where the parent handle will be placed
114 * RETURN: Status
116 * DESCRIPTION: Returns a handle to the parent of the object represented by
117 * Handle.
119 ******************************************************************************/
120 acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
122 struct acpi_namespace_node *node;
123 struct acpi_namespace_node *parent_node;
124 acpi_status status;
126 if (!ret_handle) {
127 return (AE_BAD_PARAMETER);
130 /* Special case for the predefined Root Node (no parent) */
132 if (handle == ACPI_ROOT_OBJECT) {
133 return (AE_NULL_ENTRY);
136 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
137 if (ACPI_FAILURE(status)) {
138 return (status);
141 /* Convert and validate the handle */
143 node = acpi_ns_validate_handle(handle);
144 if (!node) {
145 status = AE_BAD_PARAMETER;
146 goto unlock_and_exit;
149 /* Get the parent entry */
151 parent_node = node->parent;
152 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
154 /* Return exception if parent is null */
156 if (!parent_node) {
157 status = AE_NULL_ENTRY;
160 unlock_and_exit:
162 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
163 return (status);
166 ACPI_EXPORT_SYMBOL(acpi_get_parent)
168 /*******************************************************************************
170 * FUNCTION: acpi_get_next_object
172 * PARAMETERS: type - Type of object to be searched for
173 * parent - Parent object whose children we are getting
174 * last_child - Previous child that was found.
175 * The NEXT child will be returned
176 * ret_handle - Where handle to the next object is placed
178 * RETURN: Status
180 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
181 * valid, Scope is ignored. Otherwise, the first object within
182 * Scope is returned.
184 ******************************************************************************/
185 acpi_status
186 acpi_get_next_object(acpi_object_type type,
187 acpi_handle parent,
188 acpi_handle child, acpi_handle * ret_handle)
190 acpi_status status;
191 struct acpi_namespace_node *node;
192 struct acpi_namespace_node *parent_node = NULL;
193 struct acpi_namespace_node *child_node = NULL;
195 /* Parameter validation */
197 if (type > ACPI_TYPE_EXTERNAL_MAX) {
198 return (AE_BAD_PARAMETER);
201 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
202 if (ACPI_FAILURE(status)) {
203 return (status);
206 /* If null handle, use the parent */
208 if (!child) {
210 /* Start search at the beginning of the specified scope */
212 parent_node = acpi_ns_validate_handle(parent);
213 if (!parent_node) {
214 status = AE_BAD_PARAMETER;
215 goto unlock_and_exit;
217 } else {
218 /* Non-null handle, ignore the parent */
219 /* Convert and validate the handle */
221 child_node = acpi_ns_validate_handle(child);
222 if (!child_node) {
223 status = AE_BAD_PARAMETER;
224 goto unlock_and_exit;
228 /* Internal function does the real work */
230 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
231 if (!node) {
232 status = AE_NOT_FOUND;
233 goto unlock_and_exit;
236 if (ret_handle) {
237 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
240 unlock_and_exit:
242 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
243 return (status);
246 ACPI_EXPORT_SYMBOL(acpi_get_next_object)