blob: 8cd8675a47c0403c765c640f7b021b43fa89327a [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 *
6 *****************************************************************************/
7
8/*
Bob Moore4a90c7e2006-01-13 16:22:00 -05009 * Copyright (C) 2000 - 2006, R. Byron Moore
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * 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
Linus Torvalds1da177e2005-04-16 15:20:36 -070050#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040051ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53/******************************************************************************
54 *
55 * FUNCTION: acpi_get_handle
56 *
57 * PARAMETERS: Parent - Object to search under (search scope).
Robert Moore44f6c012005-04-18 22:49:35 -040058 * Pathname - Pointer to an asciiz string containing the
59 * name
60 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070061 *
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 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070070acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040071acpi_get_handle(acpi_handle parent,
72 acpi_string pathname, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070073{
Len Brown4be44fc2005-08-05 00:44:28 -040074 acpi_status status;
75 struct acpi_namespace_node *node = NULL;
76 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
Len Brown4be44fc2005-08-05 00:44:28 -040078 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
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) {
Len Brown4be44fc2005-08-05 00:44:28 -040089 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
90 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070091 return (status);
92 }
93
Len Brown4be44fc2005-08-05 00:44:28 -040094 prefix_node = acpi_ns_map_handle_to_node(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 if (!prefix_node) {
Len Brown4be44fc2005-08-05 00:44:28 -040096 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 return (AE_BAD_PARAMETER);
98 }
99
Len Brown4be44fc2005-08-05 00:44:28 -0400100 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
101 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102 return (status);
103 }
104 }
105
106 /* Special case for root, since we can't search for it */
107
Len Brown4be44fc2005-08-05 00:44:28 -0400108 if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) {
109 *ret_handle =
110 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 return (AE_OK);
112 }
113
114 /*
115 * Find the Node and convert to a handle
116 */
Len Brown4be44fc2005-08-05 00:44:28 -0400117 status =
118 acpi_ns_get_node_by_path(pathname, prefix_node, ACPI_NS_NO_UPSEARCH,
119 &node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120
121 *ret_handle = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400122 if (ACPI_SUCCESS(status)) {
123 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 }
125
126 return (status);
127}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
Len Brown4be44fc2005-08-05 00:44:28 -0400129EXPORT_SYMBOL(acpi_get_handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
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
147acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400148acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149{
Len Brown4be44fc2005-08-05 00:44:28 -0400150 acpi_status status;
151 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700152
153 /* Parameter validation */
154
155 if (name_type > ACPI_NAME_TYPE_MAX) {
156 return (AE_BAD_PARAMETER);
157 }
158
Len Brown4be44fc2005-08-05 00:44:28 -0400159 status = acpi_ut_validate_buffer(buffer);
160 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161 return (status);
162 }
163
164 if (name_type == ACPI_FULL_PATHNAME) {
165 /* Get the full pathname (From the namespace root) */
166
Len Brown4be44fc2005-08-05 00:44:28 -0400167 status = acpi_ns_handle_to_pathname(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700168 return (status);
169 }
170
171 /*
172 * Wants the single segment ACPI name.
173 * Validate handle and convert to a namespace Node
174 */
Len Brown4be44fc2005-08-05 00:44:28 -0400175 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
176 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177 return (status);
178 }
179
Len Brown4be44fc2005-08-05 00:44:28 -0400180 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181 if (!node) {
182 status = AE_BAD_PARAMETER;
183 goto unlock_and_exit;
184 }
185
186 /* Validate/Allocate/Clear caller buffer */
187
Len Brown4be44fc2005-08-05 00:44:28 -0400188 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
189 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 goto unlock_and_exit;
191 }
192
193 /* Just copy the ACPI name from the Node and zero terminate it */
194
Len Brown4be44fc2005-08-05 00:44:28 -0400195 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
196 ACPI_NAME_SIZE);
197 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198 status = AE_OK;
199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201
Len Brown4be44fc2005-08-05 00:44:28 -0400202 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203 return (status);
204}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
Len Brown4be44fc2005-08-05 00:44:28 -0400206EXPORT_SYMBOL(acpi_get_name);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
208/******************************************************************************
209 *
210 * FUNCTION: acpi_get_object_info
211 *
212 * PARAMETERS: Handle - Object Handle
Robert Moore44f6c012005-04-18 22:49:35 -0400213 * Buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700214 *
215 * RETURN: Status
216 *
217 * DESCRIPTION: Returns information about an object as gleaned from the
218 * namespace node and possibly by running several standard
219 * control methods (Such as in the case of a device.)
220 *
221 ******************************************************************************/
222
223acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400224acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700225{
Len Brown4be44fc2005-08-05 00:44:28 -0400226 acpi_status status;
227 struct acpi_namespace_node *node;
228 struct acpi_device_info *info;
229 struct acpi_device_info *return_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 struct acpi_compatible_id_list *cid_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400231 acpi_size size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
233 /* Parameter validation */
234
235 if (!handle || !buffer) {
236 return (AE_BAD_PARAMETER);
237 }
238
Len Brown4be44fc2005-08-05 00:44:28 -0400239 status = acpi_ut_validate_buffer(buffer);
240 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 return (status);
242 }
243
Len Brown4be44fc2005-08-05 00:44:28 -0400244 info = ACPI_MEM_CALLOCATE(sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 if (!info) {
246 return (AE_NO_MEMORY);
247 }
248
Len Brown4be44fc2005-08-05 00:44:28 -0400249 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
250 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 goto cleanup;
252 }
253
Len Brown4be44fc2005-08-05 00:44:28 -0400254 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400256 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 goto cleanup;
258 }
259
260 /* Init return structure */
261
Len Brown4be44fc2005-08-05 00:44:28 -0400262 size = sizeof(struct acpi_device_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 info->type = node->type;
265 info->name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 info->valid = 0;
267
Len Brown4be44fc2005-08-05 00:44:28 -0400268 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
269 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 goto cleanup;
271 }
272
273 /* If not a device, we are all done */
274
275 if (info->type == ACPI_TYPE_DEVICE) {
276 /*
277 * Get extra info for ACPI Devices objects only:
278 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
279 *
280 * Note: none of these methods are required, so they may or may
281 * not be present for this device. The Info->Valid bitfield is used
282 * to indicate which methods were found and ran successfully.
283 */
284
285 /* Execute the Device._HID method */
286
Len Brown4be44fc2005-08-05 00:44:28 -0400287 status = acpi_ut_execute_HID(node, &info->hardware_id);
288 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289 info->valid |= ACPI_VALID_HID;
290 }
291
292 /* Execute the Device._UID method */
293
Len Brown4be44fc2005-08-05 00:44:28 -0400294 status = acpi_ut_execute_UID(node, &info->unique_id);
295 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700296 info->valid |= ACPI_VALID_UID;
297 }
298
299 /* Execute the Device._CID method */
300
Len Brown4be44fc2005-08-05 00:44:28 -0400301 status = acpi_ut_execute_CID(node, &cid_list);
302 if (ACPI_SUCCESS(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500303 size += cid_list->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 info->valid |= ACPI_VALID_CID;
305 }
306
307 /* Execute the Device._STA method */
308
Len Brown4be44fc2005-08-05 00:44:28 -0400309 status = acpi_ut_execute_STA(node, &info->current_status);
310 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 info->valid |= ACPI_VALID_STA;
312 }
313
314 /* Execute the Device._ADR method */
315
Len Brown4be44fc2005-08-05 00:44:28 -0400316 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
317 &info->address);
318 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 info->valid |= ACPI_VALID_ADR;
320 }
321
322 /* Execute the Device._sx_d methods */
323
Len Brown4be44fc2005-08-05 00:44:28 -0400324 status = acpi_ut_execute_sxds(node, info->highest_dstates);
325 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700326 info->valid |= ACPI_VALID_SXDS;
327 }
328 }
329
330 /* Validate/Allocate/Clear caller buffer */
331
Len Brown4be44fc2005-08-05 00:44:28 -0400332 status = acpi_ut_initialize_buffer(buffer, size);
333 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 goto cleanup;
335 }
336
337 /* Populate the return buffer */
338
339 return_info = buffer->pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400340 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341
342 if (cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400343 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
344 cid_list->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 }
346
Len Brown4be44fc2005-08-05 00:44:28 -0400347 cleanup:
348 ACPI_MEM_FREE(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349 if (cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400350 ACPI_MEM_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 }
352 return (status);
353}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
Len Brown4be44fc2005-08-05 00:44:28 -0400355EXPORT_SYMBOL(acpi_get_object_info);