Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /****************************************************************************** |
2 | * | |
3 | * Module Name: nsxfname - Public interfaces to the ACPI subsystem | |
4 | * ACPI Namespace oriented interfaces | |
5 | * | |
6 | *****************************************************************************/ | |
7 | ||
8 | /* | |
4a90c7e8 | 9 | * Copyright (C) 2000 - 2006, R. Byron Moore |
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 | ||
45 | #include <linux/module.h> | |
46 | ||
47 | #include <acpi/acpi.h> | |
48 | #include <acpi/acnamesp.h> | |
49 | ||
1da177e4 | 50 | #define _COMPONENT ACPI_NAMESPACE |
4be44fcd | 51 | ACPI_MODULE_NAME("nsxfname") |
1da177e4 LT |
52 | |
53 | /****************************************************************************** | |
54 | * | |
55 | * FUNCTION: acpi_get_handle | |
56 | * | |
57 | * PARAMETERS: Parent - Object to search under (search scope). | |
44f6c012 RM |
58 | * Pathname - Pointer to an asciiz string containing the |
59 | * name | |
60 | * ret_handle - Where the return handle is returned | |
1da177e4 LT |
61 | * |
62 | * RETURN: Status | |
63 | * | |
64 | * DESCRIPTION: This routine will search for a caller specified name in the | |
65 | * name space. The caller can restrict the search region by | |
66 | * specifying a non NULL parent. The parent value is itself a | |
67 | * namespace handle. | |
68 | * | |
69 | ******************************************************************************/ | |
1da177e4 | 70 | acpi_status |
4be44fcd LB |
71 | acpi_get_handle(acpi_handle parent, |
72 | acpi_string pathname, acpi_handle * ret_handle) | |
1da177e4 | 73 | { |
4be44fcd LB |
74 | acpi_status status; |
75 | struct acpi_namespace_node *node = NULL; | |
76 | struct acpi_namespace_node *prefix_node = NULL; | |
1da177e4 | 77 | |
4be44fcd | 78 | ACPI_FUNCTION_ENTRY(); |
1da177e4 LT |
79 | |
80 | /* Parameter Validation */ | |
81 | ||
82 | if (!ret_handle || !pathname) { | |
83 | return (AE_BAD_PARAMETER); | |
84 | } | |
85 | ||
86 | /* Convert a parent handle to a prefix node */ | |
87 | ||
88 | if (parent) { | |
4be44fcd LB |
89 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
90 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
91 | return (status); |
92 | } | |
93 | ||
4be44fcd | 94 | prefix_node = acpi_ns_map_handle_to_node(parent); |
1da177e4 | 95 | if (!prefix_node) { |
4be44fcd | 96 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
97 | return (AE_BAD_PARAMETER); |
98 | } | |
99 | ||
4be44fcd LB |
100 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
101 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
102 | return (status); |
103 | } | |
104 | } | |
105 | ||
106 | /* Special case for root, since we can't search for it */ | |
107 | ||
4be44fcd LB |
108 | if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) { |
109 | *ret_handle = | |
110 | acpi_ns_convert_entry_to_handle(acpi_gbl_root_node); | |
1da177e4 LT |
111 | return (AE_OK); |
112 | } | |
113 | ||
114 | /* | |
115 | * Find the Node and convert to a handle | |
116 | */ | |
4be44fcd LB |
117 | status = |
118 | acpi_ns_get_node_by_path(pathname, prefix_node, ACPI_NS_NO_UPSEARCH, | |
119 | &node); | |
1da177e4 LT |
120 | |
121 | *ret_handle = NULL; | |
4be44fcd LB |
122 | if (ACPI_SUCCESS(status)) { |
123 | *ret_handle = acpi_ns_convert_entry_to_handle(node); | |
1da177e4 LT |
124 | } |
125 | ||
126 | return (status); | |
127 | } | |
1da177e4 | 128 | |
4be44fcd | 129 | EXPORT_SYMBOL(acpi_get_handle); |
1da177e4 LT |
130 | |
131 | /****************************************************************************** | |
132 | * | |
133 | * FUNCTION: acpi_get_name | |
134 | * | |
135 | * PARAMETERS: Handle - Handle to be converted to a pathname | |
136 | * name_type - Full pathname or single segment | |
137 | * Buffer - Buffer for returned path | |
138 | * | |
139 | * RETURN: Pointer to a string containing the fully qualified Name. | |
140 | * | |
141 | * DESCRIPTION: This routine returns the fully qualified name associated with | |
142 | * the Handle parameter. This and the acpi_pathname_to_handle are | |
143 | * complementary functions. | |
144 | * | |
145 | ******************************************************************************/ | |
146 | ||
147 | acpi_status | |
4be44fcd | 148 | acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer) |
1da177e4 | 149 | { |
4be44fcd LB |
150 | acpi_status status; |
151 | struct acpi_namespace_node *node; | |
1da177e4 LT |
152 | |
153 | /* Parameter validation */ | |
154 | ||
155 | if (name_type > ACPI_NAME_TYPE_MAX) { | |
156 | return (AE_BAD_PARAMETER); | |
157 | } | |
158 | ||
4be44fcd LB |
159 | status = acpi_ut_validate_buffer(buffer); |
160 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
161 | return (status); |
162 | } | |
163 | ||
164 | if (name_type == ACPI_FULL_PATHNAME) { | |
52fc0b02 | 165 | |
1da177e4 LT |
166 | /* Get the full pathname (From the namespace root) */ |
167 | ||
4be44fcd | 168 | status = acpi_ns_handle_to_pathname(handle, buffer); |
1da177e4 LT |
169 | return (status); |
170 | } | |
171 | ||
172 | /* | |
173 | * Wants the single segment ACPI name. | |
174 | * Validate handle and convert to a namespace Node | |
175 | */ | |
4be44fcd LB |
176 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
177 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
178 | return (status); |
179 | } | |
180 | ||
4be44fcd | 181 | node = acpi_ns_map_handle_to_node(handle); |
1da177e4 LT |
182 | if (!node) { |
183 | status = AE_BAD_PARAMETER; | |
184 | goto unlock_and_exit; | |
185 | } | |
186 | ||
187 | /* Validate/Allocate/Clear caller buffer */ | |
188 | ||
4be44fcd LB |
189 | status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH); |
190 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
191 | goto unlock_and_exit; |
192 | } | |
193 | ||
194 | /* Just copy the ACPI name from the Node and zero terminate it */ | |
195 | ||
4be44fcd LB |
196 | ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node), |
197 | ACPI_NAME_SIZE); | |
198 | ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0; | |
1da177e4 LT |
199 | status = AE_OK; |
200 | ||
4be44fcd | 201 | unlock_and_exit: |
1da177e4 | 202 | |
4be44fcd | 203 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
204 | return (status); |
205 | } | |
1da177e4 | 206 | |
4be44fcd | 207 | EXPORT_SYMBOL(acpi_get_name); |
1da177e4 LT |
208 | |
209 | /****************************************************************************** | |
210 | * | |
211 | * FUNCTION: acpi_get_object_info | |
212 | * | |
213 | * PARAMETERS: Handle - Object Handle | |
44f6c012 | 214 | * Buffer - Where the info is returned |
1da177e4 LT |
215 | * |
216 | * RETURN: Status | |
217 | * | |
218 | * DESCRIPTION: Returns information about an object as gleaned from the | |
219 | * namespace node and possibly by running several standard | |
220 | * control methods (Such as in the case of a device.) | |
221 | * | |
222 | ******************************************************************************/ | |
223 | ||
224 | acpi_status | |
4be44fcd | 225 | acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer) |
1da177e4 | 226 | { |
4be44fcd LB |
227 | acpi_status status; |
228 | struct acpi_namespace_node *node; | |
229 | struct acpi_device_info *info; | |
230 | struct acpi_device_info *return_info; | |
1da177e4 | 231 | struct acpi_compatible_id_list *cid_list = NULL; |
4be44fcd | 232 | acpi_size size; |
1da177e4 LT |
233 | |
234 | /* Parameter validation */ | |
235 | ||
236 | if (!handle || !buffer) { | |
237 | return (AE_BAD_PARAMETER); | |
238 | } | |
239 | ||
4be44fcd LB |
240 | status = acpi_ut_validate_buffer(buffer); |
241 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
242 | return (status); |
243 | } | |
244 | ||
4be44fcd | 245 | info = ACPI_MEM_CALLOCATE(sizeof(struct acpi_device_info)); |
1da177e4 LT |
246 | if (!info) { |
247 | return (AE_NO_MEMORY); | |
248 | } | |
249 | ||
4be44fcd LB |
250 | status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE); |
251 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
252 | goto cleanup; |
253 | } | |
254 | ||
4be44fcd | 255 | node = acpi_ns_map_handle_to_node(handle); |
1da177e4 | 256 | if (!node) { |
4be44fcd | 257 | (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
1da177e4 LT |
258 | goto cleanup; |
259 | } | |
260 | ||
261 | /* Init return structure */ | |
262 | ||
4be44fcd | 263 | size = sizeof(struct acpi_device_info); |
1da177e4 | 264 | |
4be44fcd LB |
265 | info->type = node->type; |
266 | info->name = node->name.integer; | |
1da177e4 LT |
267 | info->valid = 0; |
268 | ||
4be44fcd LB |
269 | status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE); |
270 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
271 | goto cleanup; |
272 | } | |
273 | ||
274 | /* If not a device, we are all done */ | |
275 | ||
276 | if (info->type == ACPI_TYPE_DEVICE) { | |
277 | /* | |
278 | * Get extra info for ACPI Devices objects only: | |
279 | * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods. | |
280 | * | |
281 | * Note: none of these methods are required, so they may or may | |
282 | * not be present for this device. The Info->Valid bitfield is used | |
283 | * to indicate which methods were found and ran successfully. | |
284 | */ | |
285 | ||
286 | /* Execute the Device._HID method */ | |
287 | ||
4be44fcd LB |
288 | status = acpi_ut_execute_HID(node, &info->hardware_id); |
289 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
290 | info->valid |= ACPI_VALID_HID; |
291 | } | |
292 | ||
293 | /* Execute the Device._UID method */ | |
294 | ||
4be44fcd LB |
295 | status = acpi_ut_execute_UID(node, &info->unique_id); |
296 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
297 | info->valid |= ACPI_VALID_UID; |
298 | } | |
299 | ||
300 | /* Execute the Device._CID method */ | |
301 | ||
4be44fcd LB |
302 | status = acpi_ut_execute_CID(node, &cid_list); |
303 | if (ACPI_SUCCESS(status)) { | |
b8e4d893 | 304 | size += cid_list->size; |
1da177e4 LT |
305 | info->valid |= ACPI_VALID_CID; |
306 | } | |
307 | ||
308 | /* Execute the Device._STA method */ | |
309 | ||
4be44fcd LB |
310 | status = acpi_ut_execute_STA(node, &info->current_status); |
311 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
312 | info->valid |= ACPI_VALID_STA; |
313 | } | |
314 | ||
315 | /* Execute the Device._ADR method */ | |
316 | ||
4be44fcd LB |
317 | status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node, |
318 | &info->address); | |
319 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
320 | info->valid |= ACPI_VALID_ADR; |
321 | } | |
322 | ||
323 | /* Execute the Device._sx_d methods */ | |
324 | ||
4be44fcd LB |
325 | status = acpi_ut_execute_sxds(node, info->highest_dstates); |
326 | if (ACPI_SUCCESS(status)) { | |
1da177e4 LT |
327 | info->valid |= ACPI_VALID_SXDS; |
328 | } | |
329 | } | |
330 | ||
331 | /* Validate/Allocate/Clear caller buffer */ | |
332 | ||
4be44fcd LB |
333 | status = acpi_ut_initialize_buffer(buffer, size); |
334 | if (ACPI_FAILURE(status)) { | |
1da177e4 LT |
335 | goto cleanup; |
336 | } | |
337 | ||
338 | /* Populate the return buffer */ | |
339 | ||
340 | return_info = buffer->pointer; | |
4be44fcd | 341 | ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info)); |
1da177e4 LT |
342 | |
343 | if (cid_list) { | |
4be44fcd LB |
344 | ACPI_MEMCPY(&return_info->compatibility_id, cid_list, |
345 | cid_list->size); | |
1da177e4 LT |
346 | } |
347 | ||
4be44fcd LB |
348 | cleanup: |
349 | ACPI_MEM_FREE(info); | |
1da177e4 | 350 | if (cid_list) { |
4be44fcd | 351 | ACPI_MEM_FREE(cid_list); |
1da177e4 LT |
352 | } |
353 | return (status); | |
354 | } | |
1da177e4 | 355 | |
4be44fcd | 356 | EXPORT_SYMBOL(acpi_get_object_info); |