Loading...
1/*******************************************************************************
2 *
3 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
4 * ACPI Object oriented interfaces
5 *
6 ******************************************************************************/
7
8/*
9 * Copyright (C) 2000 - 2012, Intel Corp.
10 * All rights reserved.
11 *
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.
26 *
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.
30 *
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.
43 */
44
45#include <linux/export.h>
46#include <acpi/acpi.h>
47#include "accommon.h"
48#include "acnamesp.h"
49
50#define _COMPONENT ACPI_NAMESPACE
51ACPI_MODULE_NAME("nsxfobj")
52
53/*******************************************************************************
54 *
55 * FUNCTION: acpi_get_id
56 *
57 * PARAMETERS: Handle - Handle of object whose id is desired
58 * ret_id - Where the id will be placed
59 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: This routine returns the owner id associated with a handle
63 *
64 ******************************************************************************/
65acpi_status acpi_get_id(acpi_handle handle, acpi_owner_id * ret_id)
66{
67 struct acpi_namespace_node *node;
68 acpi_status status;
69
70 /* Parameter Validation */
71
72 if (!ret_id) {
73 return (AE_BAD_PARAMETER);
74 }
75
76 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
77 if (ACPI_FAILURE(status)) {
78 return (status);
79 }
80
81 /* Convert and validate the handle */
82
83 node = acpi_ns_validate_handle(handle);
84 if (!node) {
85 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
86 return (AE_BAD_PARAMETER);
87 }
88
89 *ret_id = node->owner_id;
90
91 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
92 return (status);
93}
94
95ACPI_EXPORT_SYMBOL(acpi_get_id)
96
97/*******************************************************************************
98 *
99 * FUNCTION: acpi_get_type
100 *
101 * PARAMETERS: Handle - Handle of object whose type is desired
102 * ret_type - Where the type will be placed
103 *
104 * RETURN: Status
105 *
106 * DESCRIPTION: This routine returns the type associatd with a particular handle
107 *
108 ******************************************************************************/
109acpi_status acpi_get_type(acpi_handle handle, acpi_object_type * ret_type)
110{
111 struct acpi_namespace_node *node;
112 acpi_status status;
113
114 /* Parameter Validation */
115
116 if (!ret_type) {
117 return (AE_BAD_PARAMETER);
118 }
119
120 /*
121 * Special case for the predefined Root Node
122 * (return type ANY)
123 */
124 if (handle == ACPI_ROOT_OBJECT) {
125 *ret_type = ACPI_TYPE_ANY;
126 return (AE_OK);
127 }
128
129 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
130 if (ACPI_FAILURE(status)) {
131 return (status);
132 }
133
134 /* Convert and validate the handle */
135
136 node = acpi_ns_validate_handle(handle);
137 if (!node) {
138 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
139 return (AE_BAD_PARAMETER);
140 }
141
142 *ret_type = node->type;
143
144 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
145 return (status);
146}
147
148ACPI_EXPORT_SYMBOL(acpi_get_type)
149
150/*******************************************************************************
151 *
152 * FUNCTION: acpi_get_parent
153 *
154 * PARAMETERS: Handle - Handle of object whose parent is desired
155 * ret_handle - Where the parent handle will be placed
156 *
157 * RETURN: Status
158 *
159 * DESCRIPTION: Returns a handle to the parent of the object represented by
160 * Handle.
161 *
162 ******************************************************************************/
163acpi_status acpi_get_parent(acpi_handle handle, acpi_handle * ret_handle)
164{
165 struct acpi_namespace_node *node;
166 struct acpi_namespace_node *parent_node;
167 acpi_status status;
168
169 if (!ret_handle) {
170 return (AE_BAD_PARAMETER);
171 }
172
173 /* Special case for the predefined Root Node (no parent) */
174
175 if (handle == ACPI_ROOT_OBJECT) {
176 return (AE_NULL_ENTRY);
177 }
178
179 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
180 if (ACPI_FAILURE(status)) {
181 return (status);
182 }
183
184 /* Convert and validate the handle */
185
186 node = acpi_ns_validate_handle(handle);
187 if (!node) {
188 status = AE_BAD_PARAMETER;
189 goto unlock_and_exit;
190 }
191
192 /* Get the parent entry */
193
194 parent_node = node->parent;
195 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
196
197 /* Return exception if parent is null */
198
199 if (!parent_node) {
200 status = AE_NULL_ENTRY;
201 }
202
203 unlock_and_exit:
204
205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
206 return (status);
207}
208
209ACPI_EXPORT_SYMBOL(acpi_get_parent)
210
211/*******************************************************************************
212 *
213 * FUNCTION: acpi_get_next_object
214 *
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
220 *
221 * RETURN: Status
222 *
223 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
224 * valid, Scope is ignored. Otherwise, the first object within
225 * Scope is returned.
226 *
227 ******************************************************************************/
228acpi_status
229acpi_get_next_object(acpi_object_type type,
230 acpi_handle parent,
231 acpi_handle child, acpi_handle * ret_handle)
232{
233 acpi_status status;
234 struct acpi_namespace_node *node;
235 struct acpi_namespace_node *parent_node = NULL;
236 struct acpi_namespace_node *child_node = NULL;
237
238 /* Parameter validation */
239
240 if (type > ACPI_TYPE_EXTERNAL_MAX) {
241 return (AE_BAD_PARAMETER);
242 }
243
244 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
245 if (ACPI_FAILURE(status)) {
246 return (status);
247 }
248
249 /* If null handle, use the parent */
250
251 if (!child) {
252
253 /* Start search at the beginning of the specified scope */
254
255 parent_node = acpi_ns_validate_handle(parent);
256 if (!parent_node) {
257 status = AE_BAD_PARAMETER;
258 goto unlock_and_exit;
259 }
260 } else {
261 /* Non-null handle, ignore the parent */
262 /* Convert and validate the handle */
263
264 child_node = acpi_ns_validate_handle(child);
265 if (!child_node) {
266 status = AE_BAD_PARAMETER;
267 goto unlock_and_exit;
268 }
269 }
270
271 /* Internal function does the real work */
272
273 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
274 if (!node) {
275 status = AE_NOT_FOUND;
276 goto unlock_and_exit;
277 }
278
279 if (ret_handle) {
280 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
281 }
282
283 unlock_and_exit:
284
285 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
286 return (status);
287}
288
289ACPI_EXPORT_SYMBOL(acpi_get_next_object)
1// SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2/*******************************************************************************
3 *
4 * Module Name: nsxfobj - Public interfaces to the ACPI subsystem
5 * ACPI Object oriented interfaces
6 *
7 ******************************************************************************/
8
9#define EXPORT_ACPI_INTERFACES
10
11#include <acpi/acpi.h>
12#include "accommon.h"
13#include "acnamesp.h"
14
15#define _COMPONENT ACPI_NAMESPACE
16ACPI_MODULE_NAME("nsxfobj")
17
18/*******************************************************************************
19 *
20 * FUNCTION: acpi_get_type
21 *
22 * PARAMETERS: handle - Handle of object whose type is desired
23 * ret_type - Where the type will be placed
24 *
25 * RETURN: Status
26 *
27 * DESCRIPTION: This routine returns the type associated with a particular
28 * handle
29 *
30 ******************************************************************************/
31acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type)
32{
33 struct acpi_namespace_node *node;
34 acpi_status status;
35
36 /* Parameter Validation */
37
38 if (!ret_type) {
39 return (AE_BAD_PARAMETER);
40 }
41
42 /* Special case for the predefined Root Node (return type ANY) */
43
44 if (handle == ACPI_ROOT_OBJECT) {
45 *ret_type = ACPI_TYPE_ANY;
46 return (AE_OK);
47 }
48
49 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
50 if (ACPI_FAILURE(status)) {
51 return (status);
52 }
53
54 /* Convert and validate the handle */
55
56 node = acpi_ns_validate_handle(handle);
57 if (!node) {
58 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
59 return (AE_BAD_PARAMETER);
60 }
61
62 *ret_type = node->type;
63
64 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
65 return (status);
66}
67
68ACPI_EXPORT_SYMBOL(acpi_get_type)
69
70/*******************************************************************************
71 *
72 * FUNCTION: acpi_get_parent
73 *
74 * PARAMETERS: handle - Handle of object whose parent is desired
75 * ret_handle - Where the parent handle will be placed
76 *
77 * RETURN: Status
78 *
79 * DESCRIPTION: Returns a handle to the parent of the object represented by
80 * Handle.
81 *
82 ******************************************************************************/
83acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle)
84{
85 struct acpi_namespace_node *node;
86 struct acpi_namespace_node *parent_node;
87 acpi_status status;
88
89 if (!ret_handle) {
90 return (AE_BAD_PARAMETER);
91 }
92
93 /* Special case for the predefined Root Node (no parent) */
94
95 if (handle == ACPI_ROOT_OBJECT) {
96 return (AE_NULL_ENTRY);
97 }
98
99 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
100 if (ACPI_FAILURE(status)) {
101 return (status);
102 }
103
104 /* Convert and validate the handle */
105
106 node = acpi_ns_validate_handle(handle);
107 if (!node) {
108 status = AE_BAD_PARAMETER;
109 goto unlock_and_exit;
110 }
111
112 /* Get the parent entry */
113
114 parent_node = node->parent;
115 *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node);
116
117 /* Return exception if parent is null */
118
119 if (!parent_node) {
120 status = AE_NULL_ENTRY;
121 }
122
123unlock_and_exit:
124
125 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
126 return (status);
127}
128
129ACPI_EXPORT_SYMBOL(acpi_get_parent)
130
131/*******************************************************************************
132 *
133 * FUNCTION: acpi_get_next_object
134 *
135 * PARAMETERS: type - Type of object to be searched for
136 * parent - Parent object whose children we are getting
137 * last_child - Previous child that was found.
138 * The NEXT child will be returned
139 * ret_handle - Where handle to the next object is placed
140 *
141 * RETURN: Status
142 *
143 * DESCRIPTION: Return the next peer object within the namespace. If Handle is
144 * valid, Scope is ignored. Otherwise, the first object within
145 * Scope is returned.
146 *
147 ******************************************************************************/
148acpi_status
149acpi_get_next_object(acpi_object_type type,
150 acpi_handle parent,
151 acpi_handle child, acpi_handle *ret_handle)
152{
153 acpi_status status;
154 struct acpi_namespace_node *node;
155 struct acpi_namespace_node *parent_node = NULL;
156 struct acpi_namespace_node *child_node = NULL;
157
158 /* Parameter validation */
159
160 if (type > ACPI_TYPE_EXTERNAL_MAX) {
161 return (AE_BAD_PARAMETER);
162 }
163
164 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
165 if (ACPI_FAILURE(status)) {
166 return (status);
167 }
168
169 /* If null handle, use the parent */
170
171 if (!child) {
172
173 /* Start search at the beginning of the specified scope */
174
175 parent_node = acpi_ns_validate_handle(parent);
176 if (!parent_node) {
177 status = AE_BAD_PARAMETER;
178 goto unlock_and_exit;
179 }
180 } else {
181 /* Non-null handle, ignore the parent */
182 /* Convert and validate the handle */
183
184 child_node = acpi_ns_validate_handle(child);
185 if (!child_node) {
186 status = AE_BAD_PARAMETER;
187 goto unlock_and_exit;
188 }
189 }
190
191 /* Internal function does the real work */
192
193 node = acpi_ns_get_next_node_typed(type, parent_node, child_node);
194 if (!node) {
195 status = AE_NOT_FOUND;
196 goto unlock_and_exit;
197 }
198
199 if (ret_handle) {
200 *ret_handle = ACPI_CAST_PTR(acpi_handle, node);
201 }
202
203unlock_and_exit:
204
205 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
206 return (status);
207}
208
209ACPI_EXPORT_SYMBOL(acpi_get_next_object)