blob: 9589fea2499790bc4fc989baeb3700d49137390e [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/*
Len Brown75a44ce2008-04-23 23:00:13 -04009 * Copyright (C) 2000 - 2008, Intel Corp.
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>
Len Browne2f7a772009-01-09 00:30:03 -050046#include "accommon.h"
47#include "acnamesp.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Linus Torvalds1da177e2005-04-16 15:20:36 -070049#define _COMPONENT ACPI_NAMESPACE
Len Brown4be44fc2005-08-05 00:44:28 -040050ACPI_MODULE_NAME("nsxfname")
Linus Torvalds1da177e2005-04-16 15:20:36 -070051
52/******************************************************************************
53 *
54 * FUNCTION: acpi_get_handle
55 *
56 * PARAMETERS: Parent - Object to search under (search scope).
Robert Moore44f6c012005-04-18 22:49:35 -040057 * Pathname - Pointer to an asciiz string containing the
58 * name
59 * ret_handle - Where the return handle is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 *
61 * RETURN: Status
62 *
63 * DESCRIPTION: This routine will search for a caller specified name in the
64 * name space. The caller can restrict the search region by
65 * specifying a non NULL parent. The parent value is itself a
66 * namespace handle.
67 *
68 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -070069acpi_status
Len Brown4be44fc2005-08-05 00:44:28 -040070acpi_get_handle(acpi_handle parent,
71 acpi_string pathname, acpi_handle * ret_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -070072{
Len Brown4be44fc2005-08-05 00:44:28 -040073 acpi_status status;
74 struct acpi_namespace_node *node = NULL;
75 struct acpi_namespace_node *prefix_node = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
Len Brown4be44fc2005-08-05 00:44:28 -040077 ACPI_FUNCTION_ENTRY();
Linus Torvalds1da177e2005-04-16 15:20:36 -070078
79 /* Parameter Validation */
80
81 if (!ret_handle || !pathname) {
82 return (AE_BAD_PARAMETER);
83 }
84
85 /* Convert a parent handle to a prefix node */
86
87 if (parent) {
Len Brown4be44fc2005-08-05 00:44:28 -040088 prefix_node = acpi_ns_map_handle_to_node(parent);
Linus Torvalds1da177e2005-04-16 15:20:36 -070089 if (!prefix_node) {
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 return (AE_BAD_PARAMETER);
91 }
Linus Torvalds1da177e2005-04-16 15:20:36 -070092 }
93
94 /*
Bob Mooref1c2b1d2007-02-02 19:48:22 +030095 * Valid cases are:
96 * 1) Fully qualified pathname
97 * 2) Parent + Relative pathname
98 *
99 * Error for <null Parent + relative path>
Linus Torvalds1da177e2005-04-16 15:20:36 -0700100 */
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300101 if (acpi_ns_valid_root_prefix(pathname[0])) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Bob Mooref1c2b1d2007-02-02 19:48:22 +0300103 /* Pathname is fully qualified (starts with '\') */
104
105 /* Special case for root-only, since we can't search for it */
106
107 if (!ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH)) {
108 *ret_handle =
109 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
110 return (AE_OK);
111 }
112 } else if (!prefix_node) {
113
114 /* Relative path with null prefix is disallowed */
115
116 return (AE_BAD_PARAMETER);
117 }
118
119 /* Find the Node and convert to a handle */
120
121 status =
122 acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH, &node);
Len Brown4be44fc2005-08-05 00:44:28 -0400123 if (ACPI_SUCCESS(status)) {
124 *ret_handle = acpi_ns_convert_entry_to_handle(node);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 }
126
127 return (status);
128}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
Bob Moore83135242006-10-03 00:00:00 -0400130ACPI_EXPORT_SYMBOL(acpi_get_handle)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131
132/******************************************************************************
133 *
134 * FUNCTION: acpi_get_name
135 *
136 * PARAMETERS: Handle - Handle to be converted to a pathname
137 * name_type - Full pathname or single segment
138 * Buffer - Buffer for returned path
139 *
140 * RETURN: Pointer to a string containing the fully qualified Name.
141 *
142 * DESCRIPTION: This routine returns the fully qualified name associated with
143 * the Handle parameter. This and the acpi_pathname_to_handle are
144 * complementary functions.
145 *
146 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147acpi_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) {
Bob Moore52fc0b02006-10-02 00:00:00 -0400165
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 /* Get the full pathname (From the namespace root) */
167
Len Brown4be44fc2005-08-05 00:44:28 -0400168 status = acpi_ns_handle_to_pathname(handle, buffer);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 return (status);
170 }
171
172 /*
173 * Wants the single segment ACPI name.
174 * Validate handle and convert to a namespace Node
175 */
Len Brown4be44fc2005-08-05 00:44:28 -0400176 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
177 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178 return (status);
179 }
180
Len Brown4be44fc2005-08-05 00:44:28 -0400181 node = acpi_ns_map_handle_to_node(handle);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182 if (!node) {
183 status = AE_BAD_PARAMETER;
184 goto unlock_and_exit;
185 }
186
187 /* Validate/Allocate/Clear caller buffer */
188
Len Brown4be44fc2005-08-05 00:44:28 -0400189 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
190 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700191 goto unlock_and_exit;
192 }
193
194 /* Just copy the ACPI name from the Node and zero terminate it */
195
Len Brown4be44fc2005-08-05 00:44:28 -0400196 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
197 ACPI_NAME_SIZE);
198 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 status = AE_OK;
200
Len Brown4be44fc2005-08-05 00:44:28 -0400201 unlock_and_exit:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700202
Len Brown4be44fc2005-08-05 00:44:28 -0400203 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700204 return (status);
205}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700206
Bob Moore83135242006-10-03 00:00:00 -0400207ACPI_EXPORT_SYMBOL(acpi_get_name)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700208
209/******************************************************************************
210 *
211 * FUNCTION: acpi_get_object_info
212 *
213 * PARAMETERS: Handle - Object Handle
Robert Moore44f6c012005-04-18 22:49:35 -0400214 * Buffer - Where the info is returned
Linus Torvalds1da177e2005-04-16 15:20:36 -0700215 *
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 ******************************************************************************/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223acpi_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
Bob Moore83135242006-10-03 00:00:00 -0400244 info = ACPI_ALLOCATE_ZEROED(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);
Fiodor Suietov237a9272008-07-04 10:18:34 +0800257 status = AE_BAD_PARAMETER;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 goto cleanup;
259 }
260
261 /* Init return structure */
262
Len Brown4be44fc2005-08-05 00:44:28 -0400263 size = sizeof(struct acpi_device_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
Len Brown4be44fc2005-08-05 00:44:28 -0400265 info->type = node->type;
266 info->name = node->name.integer;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 info->valid = 0;
268
Bob Moore0a1fbf22008-07-04 10:53:58 +0800269 if (node->type == ACPI_TYPE_METHOD) {
270 info->param_count = node->object->method.param_count;
271 }
272
Len Brown4be44fc2005-08-05 00:44:28 -0400273 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
274 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 goto cleanup;
276 }
277
278 /* If not a device, we are all done */
279
280 if (info->type == ACPI_TYPE_DEVICE) {
281 /*
282 * Get extra info for ACPI Devices objects only:
283 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
284 *
285 * Note: none of these methods are required, so they may or may
286 * not be present for this device. The Info->Valid bitfield is used
287 * to indicate which methods were found and ran successfully.
288 */
289
290 /* Execute the Device._HID method */
291
Len Brown4be44fc2005-08-05 00:44:28 -0400292 status = acpi_ut_execute_HID(node, &info->hardware_id);
293 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294 info->valid |= ACPI_VALID_HID;
295 }
296
297 /* Execute the Device._UID method */
298
Len Brown4be44fc2005-08-05 00:44:28 -0400299 status = acpi_ut_execute_UID(node, &info->unique_id);
300 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 info->valid |= ACPI_VALID_UID;
302 }
303
304 /* Execute the Device._CID method */
305
Len Brown4be44fc2005-08-05 00:44:28 -0400306 status = acpi_ut_execute_CID(node, &cid_list);
307 if (ACPI_SUCCESS(status)) {
Bob Mooreb8e4d892006-01-27 16:43:00 -0500308 size += cid_list->size;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 info->valid |= ACPI_VALID_CID;
310 }
311
312 /* Execute the Device._STA method */
313
Len Brown4be44fc2005-08-05 00:44:28 -0400314 status = acpi_ut_execute_STA(node, &info->current_status);
315 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 info->valid |= ACPI_VALID_STA;
317 }
318
319 /* Execute the Device._ADR method */
320
Len Brown4be44fc2005-08-05 00:44:28 -0400321 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
322 &info->address);
323 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700324 info->valid |= ACPI_VALID_ADR;
325 }
326
327 /* Execute the Device._sx_d methods */
328
Len Brown4be44fc2005-08-05 00:44:28 -0400329 status = acpi_ut_execute_sxds(node, info->highest_dstates);
330 if (ACPI_SUCCESS(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331 info->valid |= ACPI_VALID_SXDS;
332 }
333 }
334
335 /* Validate/Allocate/Clear caller buffer */
336
Len Brown4be44fc2005-08-05 00:44:28 -0400337 status = acpi_ut_initialize_buffer(buffer, size);
338 if (ACPI_FAILURE(status)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700339 goto cleanup;
340 }
341
342 /* Populate the return buffer */
343
344 return_info = buffer->pointer;
Len Brown4be44fc2005-08-05 00:44:28 -0400345 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346
347 if (cid_list) {
Len Brown4be44fc2005-08-05 00:44:28 -0400348 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
349 cid_list->size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700350 }
351
Len Brown4be44fc2005-08-05 00:44:28 -0400352 cleanup:
Bob Moore83135242006-10-03 00:00:00 -0400353 ACPI_FREE(info);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354 if (cid_list) {
Bob Moore83135242006-10-03 00:00:00 -0400355 ACPI_FREE(cid_list);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700356 }
357 return (status);
358}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700359
Bob Moore83135242006-10-03 00:00:00 -0400360ACPI_EXPORT_SYMBOL(acpi_get_object_info)