Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /******************************************************************************* |
2 | * | |
3 | * Module Name: nsxfobj - Public interfaces to the ACPI subsystem | |
4 | * ACPI Object oriented interfaces | |
5 | * | |
6 | ******************************************************************************/ | |
7 | ||
8 | /* | |
c8100dc4 | 9 | * Copyright (C) 2000 - 2016, Intel Corp. |
1da177e4 LT |
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 | ||
839e928f LZ |
45 | #define EXPORT_ACPI_INTERFACES |
46 | ||
1da177e4 | 47 | #include <acpi/acpi.h> |
e2f7a777 LB |
48 | #include "accommon.h" |
49 | #include "acnamesp.h" | |
1da177e4 | 50 | |
1da177e4 | 51 | #define _COMPONENT ACPI_NAMESPACE |
4be44fcd | 52 | ACPI_MODULE_NAME("nsxfobj") |
1da177e4 LT |
53 | |
54 | /******************************************************************************* | |
55 | * | |
56 | * FUNCTION: acpi_get_type | |
57 | * | |
ba494bee | 58 | * PARAMETERS: handle - Handle of object whose type is desired |
44f6c012 | 59 | * ret_type - Where the type will be placed |
1da177e4 LT |
60 | * |
61 | * RETURN: Status | |
62 | * | |
63 | * DESCRIPTION: This routine returns the type associatd with a particular handle | |
64 | * | |
65 | ******************************************************************************/ | |
f5c1e1c5 | 66 | acpi_status acpi_get_type(acpi_handle handle, acpi_object_type *ret_type) |
1da177e4 | 67 | { |
4be44fcd LB |
68 | struct acpi_namespace_node *node; |
69 | acpi_status status; | |
1da177e4 LT |
70 | |
71 | /* Parameter Validation */ | |
72 | ||
73 | if (!ret_type) { | |
74 | return (AE_BAD_PARAMETER); | |
75 | } | |
76 | ||
1fad8738 BM |
77 | /* Special case for the predefined Root Node (return type ANY) */ |
78 | ||
1da177e4 LT |
79 | if (handle == ACPI_ROOT_OBJECT) { |
80 | *ret_type = ACPI_TYPE_ANY; | |
81 | return (AE_OK); | |
82 | } | |
83 | ||
4be44fcd LB |
84 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
85 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
86 | return (status); |
87 | } | |
88 | ||
89 | /* Convert and validate the handle */ | |
90 | ||
f24b664d | 91 | node = acpi_ns_validate_handle(handle); |
1da177e4 | 92 | if (!node) { |
4be44fcd | 93 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
94 | return (AE_BAD_PARAMETER); |
95 | } | |
96 | ||
97 | *ret_type = node->type; | |
98 | ||
4be44fcd | 99 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
100 | return (status); |
101 | } | |
1da177e4 | 102 | |
8313524a | 103 | ACPI_EXPORT_SYMBOL(acpi_get_type) |
1da177e4 LT |
104 | |
105 | /******************************************************************************* | |
106 | * | |
107 | * FUNCTION: acpi_get_parent | |
108 | * | |
ba494bee | 109 | * PARAMETERS: handle - Handle of object whose parent is desired |
1da177e4 LT |
110 | * ret_handle - Where the parent handle will be placed |
111 | * | |
112 | * RETURN: Status | |
113 | * | |
114 | * DESCRIPTION: Returns a handle to the parent of the object represented by | |
115 | * Handle. | |
116 | * | |
117 | ******************************************************************************/ | |
f5c1e1c5 | 118 | acpi_status acpi_get_parent(acpi_handle handle, acpi_handle *ret_handle) |
1da177e4 | 119 | { |
4be44fcd | 120 | struct acpi_namespace_node *node; |
c446eed6 | 121 | struct acpi_namespace_node *parent_node; |
4be44fcd | 122 | acpi_status status; |
1da177e4 LT |
123 | |
124 | if (!ret_handle) { | |
125 | return (AE_BAD_PARAMETER); | |
126 | } | |
127 | ||
128 | /* Special case for the predefined Root Node (no parent) */ | |
129 | ||
130 | if (handle == ACPI_ROOT_OBJECT) { | |
131 | return (AE_NULL_ENTRY); | |
132 | } | |
133 | ||
4be44fcd LB |
134 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
135 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
136 | return (status); |
137 | } | |
138 | ||
139 | /* Convert and validate the handle */ | |
140 | ||
f24b664d | 141 | node = acpi_ns_validate_handle(handle); |
1da177e4 LT |
142 | if (!node) { |
143 | status = AE_BAD_PARAMETER; | |
144 | goto unlock_and_exit; | |
145 | } | |
146 | ||
147 | /* Get the parent entry */ | |
148 | ||
c45b5c09 | 149 | parent_node = node->parent; |
f24b664d | 150 | *ret_handle = ACPI_CAST_PTR(acpi_handle, parent_node); |
1da177e4 LT |
151 | |
152 | /* Return exception if parent is null */ | |
153 | ||
c446eed6 | 154 | if (!parent_node) { |
1da177e4 LT |
155 | status = AE_NULL_ENTRY; |
156 | } | |
157 | ||
10622bf8 | 158 | unlock_and_exit: |
1da177e4 | 159 | |
4be44fcd | 160 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
161 | return (status); |
162 | } | |
1da177e4 | 163 | |
8313524a | 164 | ACPI_EXPORT_SYMBOL(acpi_get_parent) |
1da177e4 LT |
165 | |
166 | /******************************************************************************* | |
167 | * | |
168 | * FUNCTION: acpi_get_next_object | |
169 | * | |
ba494bee BM |
170 | * PARAMETERS: type - Type of object to be searched for |
171 | * parent - Parent object whose children we are getting | |
1da177e4 LT |
172 | * last_child - Previous child that was found. |
173 | * The NEXT child will be returned | |
174 | * ret_handle - Where handle to the next object is placed | |
175 | * | |
176 | * RETURN: Status | |
177 | * | |
73a3090a BM |
178 | * DESCRIPTION: Return the next peer object within the namespace. If Handle is |
179 | * valid, Scope is ignored. Otherwise, the first object within | |
1da177e4 LT |
180 | * Scope is returned. |
181 | * | |
182 | ******************************************************************************/ | |
1da177e4 | 183 | acpi_status |
4be44fcd LB |
184 | acpi_get_next_object(acpi_object_type type, |
185 | acpi_handle parent, | |
f5c1e1c5 | 186 | acpi_handle child, acpi_handle *ret_handle) |
1da177e4 | 187 | { |
4be44fcd LB |
188 | acpi_status status; |
189 | struct acpi_namespace_node *node; | |
190 | struct acpi_namespace_node *parent_node = NULL; | |
191 | struct acpi_namespace_node *child_node = NULL; | |
1da177e4 LT |
192 | |
193 | /* Parameter validation */ | |
194 | ||
195 | if (type > ACPI_TYPE_EXTERNAL_MAX) { | |
196 | return (AE_BAD_PARAMETER); | |
197 | } | |
198 | ||
4be44fcd LB |
199 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
200 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
201 | return (status); |
202 | } | |
203 | ||
204 | /* If null handle, use the parent */ | |
205 | ||
206 | if (!child) { | |
52fc0b02 | 207 | |
1da177e4 LT |
208 | /* Start search at the beginning of the specified scope */ |
209 | ||
f24b664d | 210 | parent_node = acpi_ns_validate_handle(parent); |
1da177e4 LT |
211 | if (!parent_node) { |
212 | status = AE_BAD_PARAMETER; | |
213 | goto unlock_and_exit; | |
214 | } | |
4be44fcd | 215 | } else { |
1da177e4 LT |
216 | /* Non-null handle, ignore the parent */ |
217 | /* Convert and validate the handle */ | |
218 | ||
f24b664d | 219 | child_node = acpi_ns_validate_handle(child); |
1da177e4 LT |
220 | if (!child_node) { |
221 | status = AE_BAD_PARAMETER; | |
222 | goto unlock_and_exit; | |
223 | } | |
224 | } | |
225 | ||
226 | /* Internal function does the real work */ | |
227 | ||
8c725bf9 | 228 | node = acpi_ns_get_next_node_typed(type, parent_node, child_node); |
1da177e4 LT |
229 | if (!node) { |
230 | status = AE_NOT_FOUND; | |
231 | goto unlock_and_exit; | |
232 | } | |
233 | ||
234 | if (ret_handle) { | |
f24b664d | 235 | *ret_handle = ACPI_CAST_PTR(acpi_handle, node); |
1da177e4 LT |
236 | } |
237 | ||
10622bf8 | 238 | unlock_and_exit: |
1da177e4 | 239 | |
4be44fcd | 240 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
241 | return (status); |
242 | } | |
1da177e4 | 243 | |
8313524a | 244 | ACPI_EXPORT_SYMBOL(acpi_get_next_object) |