blob: 1303e2b062bb2ac262fac2ddc5e83bf8ce5b8593 [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 */
Len Brown4be44fc2005-08-05 00:44:28 -0400115 status =
116 acpi_ns_get_node_by_path(pathname, prefix_node, ACPI_NS_NO_UPSEARCH,
117 &node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119 *ret_handle = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400120 if (ACPI_SUCCESS(status)) {
121 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 }
123
124 return (status);
125}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126
Bob Moore83135242006-10-03 00:00:00 -0400127ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129/******************************************************************************
130 *
131 * FUNCTION: acpi_get_name
132 *
133 * PARAMETERS: Handle - Handle to be converted to a pathname
134 * name_type - Full pathname or single segment
135 * Buffer - Buffer for returned path
136 *
137 * RETURN: Pointer to a string containing the fully qualified Name.
138 *
139 * DESCRIPTION: This routine returns the fully qualified name associated with
140 * the Handle parameter. This and the acpi_pathname_to_handle are
141 * complementary functions.
142 *
143 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400145acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146{
Len Brown4be44fc2005-08-05 00:44:28 -0400147 acpi_status status;
148 struct acpi_namespace_node *node;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149
150 /* Parameter validation */
151
152 if (name_type > ACPI_NAME_TYPE_MAX) {
153 return (AE_BAD_PARAMETER);
154 }
155
Len Brown4be44fc2005-08-05 00:44:28 -0400156 status = acpi_ut_validate_buffer(buffer);
157 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 return (status);
159 }
160
161 if (name_type == ACPI_FULL_PATHNAME) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400162
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 /* Get the full pathname (From the namespace root) */
164
Len Brown4be44fc2005-08-05 00:44:28 -0400165 status = acpi_ns_handle_to_pathname(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 return (status);
167 }
168
169 /*
170 * Wants the single segment ACPI name.
171 * Validate handle and convert to a namespace Node
172 */
Len Brown4be44fc2005-08-05 00:44:28 -0400173 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
174 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700175 return (status);
176 }
177
Len Brown4be44fc2005-08-05 00:44:28 -0400178 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179 if (!node) {
180 status = AE_BAD_PARAMETER;
181 goto unlock_and_exit;
182 }
183
184 /* Validate/Allocate/Clear caller buffer */
185
Len Brown4be44fc2005-08-05 00:44:28 -0400186 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
187 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 goto unlock_and_exit;
189 }
190
191 /* Just copy the ACPI name from the Node and zero terminate it */
192
Len Brown4be44fc2005-08-05 00:44:28 -0400193 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
194 ACPI_NAME_SIZE);
195 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196 status = AE_OK;
197
Len Brown4be44fc2005-08-05 00:44:28 -0400198 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Len Brown4be44fc2005-08-05 00:44:28 -0400200 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201 return (status);
202}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Bob Moore83135242006-10-03 00:00:00 -0400204ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700205
206/******************************************************************************
207 *
208 * FUNCTION: acpi_get_object_info
209 *
210 * PARAMETERS: Handle - Object Handle
Robert Moore44f6c012005-04-18 22:49:35 -0400211 * Buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212 *
213 * RETURN: Status
214 *
215 * DESCRIPTION: Returns information about an object as gleaned from the
216 * namespace node and possibly by running several standard
217 * control methods (Such as in the case of a device.)
218 *
219 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700220acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -0400221acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222{
Len Brown4be44fc2005-08-05 00:44:28 -0400223 acpi_status status;
224 struct acpi_namespace_node *node;
225 struct acpi_device_info *info;
226 struct acpi_device_info *return_info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 struct acpi_compatible_id_list *cid_list = NULL;
Len Brown4be44fc2005-08-05 00:44:28 -0400228 acpi_size size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229
230 /* Parameter validation */
231
232 if (!handle || !buffer) {
233 return (AE_BAD_PARAMETER);
234 }
235
Len Brown4be44fc2005-08-05 00:44:28 -0400236 status = acpi_ut_validate_buffer(buffer);
237 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 return (status);
239 }
240
Bob Moore83135242006-10-03 00:00:00 -0400241 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (!info) {
243 return (AE_NO_MEMORY);
244 }
245
Len Brown4be44fc2005-08-05 00:44:28 -0400246 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
247 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 goto cleanup;
249 }
250
Len Brown4be44fc2005-08-05 00:44:28 -0400251 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252 if (!node) {
Len Brown4be44fc2005-08-05 00:44:28 -0400253 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700254 goto cleanup;
255 }
256
257 /* Init return structure */
258
Len Brown4be44fc2005-08-05 00:44:28 -0400259 size = sizeof(struct acpi_device_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700260
Len Brown4be44fc2005-08-05 00:44:28 -0400261 info->type = node->type;
262 info->name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263 info->valid = 0;
264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
266 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 goto cleanup;
268 }
269
270 /* If not a device, we are all done */
271
272 if (info->type == ACPI_TYPE_DEVICE) {
273 /*
274 * Get extra info for ACPI Devices objects only:
275 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
276 *
277 * Note: none of these methods are required, so they may or may
278 * not be present for this device. The Info->Valid bitfield is used
279 * to indicate which methods were found and ran successfully.
280 */
281
282 /* Execute the Device._HID method */
283
Len Brown4be44fc2005-08-05 00:44:28 -0400284 status = acpi_ut_execute_HID(node, &info->hardware_id);
285 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700286 info->valid |= ACPI_VALID_HID;
287 }
288
289 /* Execute the Device._UID method */
290
Len Brown4be44fc2005-08-05 00:44:28 -0400291 status = acpi_ut_execute_UID(node, &info->unique_id);
292 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 info->valid |= ACPI_VALID_UID;
294 }
295
296 /* Execute the Device._CID method */
297
Len Brown4be44fc2005-08-05 00:44:28 -0400298 status = acpi_ut_execute_CID(node, &cid_list);
299 if (ACPI_SUCCESS(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500300 size += cid_list->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 info->valid |= ACPI_VALID_CID;
302 }
303
304 /* Execute the Device._STA method */
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 status = acpi_ut_execute_STA(node, &info->current_status);
307 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308 info->valid |= ACPI_VALID_STA;
309 }
310
311 /* Execute the Device._ADR method */
312
Len Brown4be44fc2005-08-05 00:44:28 -0400313 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
314 &info->address);
315 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 info->valid |= ACPI_VALID_ADR;
317 }
318
319 /* Execute the Device._sx_d methods */
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 status = acpi_ut_execute_sxds(node, info->highest_dstates);
322 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 info->valid |= ACPI_VALID_SXDS;
324 }
325 }
326
327 /* Validate/Allocate/Clear caller buffer */
328
Len Brown4be44fc2005-08-05 00:44:28 -0400329 status = acpi_ut_initialize_buffer(buffer, size);
330 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 goto cleanup;
332 }
333
334 /* Populate the return buffer */
335
336 return_info = buffer->pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400337 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 if (cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400340 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
341 cid_list->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700342 }
343
Len Brown4be44fc2005-08-05 00:44:28 -0400344 cleanup:
Bob Moore83135242006-10-03 00:00:00 -0400345 ACPI_FREE(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400347 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700348 }
349 return (status);
350}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351
Bob Moore83135242006-10-03 00:00:00 -0400352ACPI_EXPORT_SYMBOL(acpi_get_object_info)