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