blob: 978213a6c19f23063c47e37073ba7b5b401a166d [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070045#include <acpi/acpi.h>
46#include <acpi/acnamesp.h>
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040049ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
51/******************************************************************************
52 *
53 * FUNCTION: acpi_get_handle
54 *
55 * PARAMETERS: Parent - Object to search under (search scope).
Robert Moore44f6c012005-04-18 22:49:35 -040056 * Pathname - Pointer to an asciiz string containing the
57 * name
58 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 *
60 * RETURN: Status
61 *
62 * DESCRIPTION: This routine will search for a caller specified name in the
63 * name space. The caller can restrict the search region by
64 * specifying a non NULL parent. The parent value is itself a
65 * namespace handle.
66 *
67 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070068acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040069acpi_get_handle(acpi_handle parent,
70 acpi_string pathname, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070071{
Len Brown4be44fc2005-08-05 00:44:28 -040072 acpi_status status;
73 struct acpi_namespace_node *node = NULL;
74 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Len Brown4be44fc2005-08-05 00:44:28 -040076 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78 /* Parameter Validation */
79
80 if (!ret_handle || !pathname) {
81 return (AE_BAD_PARAMETER);
82 }
83
84 /* Convert a parent handle to a prefix node */
85
86 if (parent) {
Len Brown4be44fc2005-08-05 00:44:28 -040087 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
88 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 return (status);
90 }
91
Len Brown4be44fc2005-08-05 00:44:28 -040092 prefix_node = acpi_ns_map_handle_to_node(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070093 if (!prefix_node) {
Len Brown4be44fc2005-08-05 00:44:28 -040094 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return (AE_BAD_PARAMETER);
96 }
97
Len Brown4be44fc2005-08-05 00:44:28 -040098 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
99 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 return (status);
101 }
102 }
103
104 /* Special case for root, since we can't search for it */
105
Len Brown4be44fc2005-08-05 00:44:28 -0400106 if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) {
107 *ret_handle =
108 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109 return (AE_OK);
110 }
111
112 /*
113 * Find the Node and convert to a handle
114 */
Bob Moore41195322006-05-26 16:36:00 -0400115 status = acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH,
116 &node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 *ret_handle = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400119 if (ACPI_SUCCESS(status)) {
120 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 }
122
123 return (status);
124}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Bob Moore83135242006-10-03 00:00:00 -0400126ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127
128/******************************************************************************
129 *
130 * FUNCTION: acpi_get_name
131 *
132 * PARAMETERS: Handle - Handle to be converted to a pathname
133 * name_type - Full pathname or single segment
134 * Buffer - Buffer for returned path
135 *
136 * RETURN: Pointer to a string containing the fully qualified Name.
137 *
138 * DESCRIPTION: This routine returns the fully qualified name associated with
139 * the Handle parameter. This and the acpi_pathname_to_handle are
140 * complementary functions.
141 *
142 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400144acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145{
Len Brown4be44fc2005-08-05 00:44:28 -0400146 acpi_status status;
147 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
149 /* Parameter validation */
150
151 if (name_type > ACPI_NAME_TYPE_MAX) {
152 return (AE_BAD_PARAMETER);
153 }
154
Len Brown4be44fc2005-08-05 00:44:28 -0400155 status = acpi_ut_validate_buffer(buffer);
156 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 return (status);
158 }
159
160 if (name_type == ACPI_FULL_PATHNAME) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400161
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 /* Get the full pathname (From the namespace root) */
163
Len Brown4be44fc2005-08-05 00:44:28 -0400164 status = acpi_ns_handle_to_pathname(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 return (status);
166 }
167
168 /*
169 * Wants the single segment ACPI name.
170 * Validate handle and convert to a namespace Node
171 */
Len Brown4be44fc2005-08-05 00:44:28 -0400172 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
173 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 return (status);
175 }
176
Len Brown4be44fc2005-08-05 00:44:28 -0400177 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 if (!node) {
179 status = AE_BAD_PARAMETER;
180 goto unlock_and_exit;
181 }
182
183 /* Validate/Allocate/Clear caller buffer */
184
Len Brown4be44fc2005-08-05 00:44:28 -0400185 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
186 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 goto unlock_and_exit;
188 }
189
190 /* Just copy the ACPI name from the Node and zero terminate it */
191
Len Brown4be44fc2005-08-05 00:44:28 -0400192 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
193 ACPI_NAME_SIZE);
194 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195 status = AE_OK;
196
Len Brown4be44fc2005-08-05 00:44:28 -0400197 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198
Len Brown4be44fc2005-08-05 00:44:28 -0400199 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700200 return (status);
201}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Bob Moore83135242006-10-03 00:00:00 -0400203ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204
205/******************************************************************************
206 *
207 * FUNCTION: acpi_get_object_info
208 *
209 * PARAMETERS: Handle - Object Handle
Robert Moore44f6c012005-04-18 22:49:35 -0400210 * Buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211 *
212 * RETURN: Status
213 *
214 * DESCRIPTION: Returns information about an object as gleaned from the
215 * namespace node and possibly by running several standard
216 * control methods (Such as in the case of a device.)
217 *
218 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700219acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400220acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221{
Len Brown4be44fc2005-08-05 00:44:28 -0400222 acpi_status status;
223 struct acpi_namespace_node *node;
224 struct acpi_device_info *info;
225 struct acpi_device_info *return_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 struct acpi_compatible_id_list *cid_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400227 acpi_size size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228
229 /* Parameter validation */
230
231 if (!handle || !buffer) {
232 return (AE_BAD_PARAMETER);
233 }
234
Len Brown4be44fc2005-08-05 00:44:28 -0400235 status = acpi_ut_validate_buffer(buffer);
236 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return (status);
238 }
239
Bob Moore83135242006-10-03 00:00:00 -0400240 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700241 if (!info) {
242 return (AE_NO_MEMORY);
243 }
244
Len Brown4be44fc2005-08-05 00:44:28 -0400245 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
246 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 goto cleanup;
248 }
249
Len Brown4be44fc2005-08-05 00:44:28 -0400250 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700251 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400252 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 goto cleanup;
254 }
255
256 /* Init return structure */
257
Len Brown4be44fc2005-08-05 00:44:28 -0400258 size = sizeof(struct acpi_device_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Len Brown4be44fc2005-08-05 00:44:28 -0400260 info->type = node->type;
261 info->name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700262 info->valid = 0;
263
Len Brown4be44fc2005-08-05 00:44:28 -0400264 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
265 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266 goto cleanup;
267 }
268
269 /* If not a device, we are all done */
270
271 if (info->type == ACPI_TYPE_DEVICE) {
272 /*
273 * Get extra info for ACPI Devices objects only:
274 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
275 *
276 * Note: none of these methods are required, so they may or may
277 * not be present for this device. The Info->Valid bitfield is used
278 * to indicate which methods were found and ran successfully.
279 */
280
281 /* Execute the Device._HID method */
282
Len Brown4be44fc2005-08-05 00:44:28 -0400283 status = acpi_ut_execute_HID(node, &info->hardware_id);
284 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700285 info->valid |= ACPI_VALID_HID;
286 }
287
288 /* Execute the Device._UID method */
289
Len Brown4be44fc2005-08-05 00:44:28 -0400290 status = acpi_ut_execute_UID(node, &info->unique_id);
291 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292 info->valid |= ACPI_VALID_UID;
293 }
294
295 /* Execute the Device._CID method */
296
Len Brown4be44fc2005-08-05 00:44:28 -0400297 status = acpi_ut_execute_CID(node, &cid_list);
298 if (ACPI_SUCCESS(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500299 size += cid_list->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700300 info->valid |= ACPI_VALID_CID;
301 }
302
303 /* Execute the Device._STA method */
304
Len Brown4be44fc2005-08-05 00:44:28 -0400305 status = acpi_ut_execute_STA(node, &info->current_status);
306 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700307 info->valid |= ACPI_VALID_STA;
308 }
309
310 /* Execute the Device._ADR method */
311
Len Brown4be44fc2005-08-05 00:44:28 -0400312 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
313 &info->address);
314 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 info->valid |= ACPI_VALID_ADR;
316 }
317
318 /* Execute the Device._sx_d methods */
319
Len Brown4be44fc2005-08-05 00:44:28 -0400320 status = acpi_ut_execute_sxds(node, info->highest_dstates);
321 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322 info->valid |= ACPI_VALID_SXDS;
323 }
324 }
325
326 /* Validate/Allocate/Clear caller buffer */
327
Len Brown4be44fc2005-08-05 00:44:28 -0400328 status = acpi_ut_initialize_buffer(buffer, size);
329 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 goto cleanup;
331 }
332
333 /* Populate the return buffer */
334
335 return_info = buffer->pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400336 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700337
338 if (cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400339 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
340 cid_list->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 }
342
Len Brown4be44fc2005-08-05 00:44:28 -0400343 cleanup:
Bob Moore83135242006-10-03 00:00:00 -0400344 ACPI_FREE(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400346 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700347 }
348 return (status);
349}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350
Bob Moore83135242006-10-03 00:00:00 -0400351ACPI_EXPORT_SYMBOL(acpi_get_object_info)