[ACPI] ACPICA 20060113
[linux-2.6/kvm.git] / drivers / acpi / namespace / nsxfname.c
blob853e6d170c9607941af7fa973c62e2cbfa54b87f
1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
8 /*
9 * Copyright (C) 2000 - 2006, R. Byron Moore
10 * All rights reserved.
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.
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.
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.
45 #include <linux/module.h>
47 #include <acpi/acpi.h>
48 #include <acpi/acnamesp.h>
50 #define _COMPONENT ACPI_NAMESPACE
51 ACPI_MODULE_NAME("nsxfname")
53 /******************************************************************************
55 * FUNCTION: acpi_get_handle
57 * PARAMETERS: Parent - Object to search under (search scope).
58 * Pathname - Pointer to an asciiz string containing the
59 * name
60 * ret_handle - Where the return handle is returned
62 * RETURN: Status
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.
69 ******************************************************************************/
70 acpi_status
71 acpi_get_handle(acpi_handle parent,
72 acpi_string pathname, acpi_handle * ret_handle)
74 acpi_status status;
75 struct acpi_namespace_node *node = NULL;
76 struct acpi_namespace_node *prefix_node = NULL;
78 ACPI_FUNCTION_ENTRY();
80 /* Parameter Validation */
82 if (!ret_handle || !pathname) {
83 return (AE_BAD_PARAMETER);
86 /* Convert a parent handle to a prefix node */
88 if (parent) {
89 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
90 if (ACPI_FAILURE(status)) {
91 return (status);
94 prefix_node = acpi_ns_map_handle_to_node(parent);
95 if (!prefix_node) {
96 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
97 return (AE_BAD_PARAMETER);
100 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
101 if (ACPI_FAILURE(status)) {
102 return (status);
106 /* Special case for root, since we can't search for it */
108 if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) {
109 *ret_handle =
110 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
111 return (AE_OK);
115 * Find the Node and convert to a handle
117 status =
118 acpi_ns_get_node_by_path(pathname, prefix_node, ACPI_NS_NO_UPSEARCH,
119 &node);
121 *ret_handle = NULL;
122 if (ACPI_SUCCESS(status)) {
123 *ret_handle = acpi_ns_convert_entry_to_handle(node);
126 return (status);
129 EXPORT_SYMBOL(acpi_get_handle);
131 /******************************************************************************
133 * FUNCTION: acpi_get_name
135 * PARAMETERS: Handle - Handle to be converted to a pathname
136 * name_type - Full pathname or single segment
137 * Buffer - Buffer for returned path
139 * RETURN: Pointer to a string containing the fully qualified Name.
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.
145 ******************************************************************************/
147 acpi_status
148 acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
150 acpi_status status;
151 struct acpi_namespace_node *node;
153 /* Parameter validation */
155 if (name_type > ACPI_NAME_TYPE_MAX) {
156 return (AE_BAD_PARAMETER);
159 status = acpi_ut_validate_buffer(buffer);
160 if (ACPI_FAILURE(status)) {
161 return (status);
164 if (name_type == ACPI_FULL_PATHNAME) {
165 /* Get the full pathname (From the namespace root) */
167 status = acpi_ns_handle_to_pathname(handle, buffer);
168 return (status);
172 * Wants the single segment ACPI name.
173 * Validate handle and convert to a namespace Node
175 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
176 if (ACPI_FAILURE(status)) {
177 return (status);
180 node = acpi_ns_map_handle_to_node(handle);
181 if (!node) {
182 status = AE_BAD_PARAMETER;
183 goto unlock_and_exit;
186 /* Validate/Allocate/Clear caller buffer */
188 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
189 if (ACPI_FAILURE(status)) {
190 goto unlock_and_exit;
193 /* Just copy the ACPI name from the Node and zero terminate it */
195 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
196 ACPI_NAME_SIZE);
197 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
198 status = AE_OK;
200 unlock_and_exit:
202 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
203 return (status);
206 EXPORT_SYMBOL(acpi_get_name);
208 /******************************************************************************
210 * FUNCTION: acpi_get_object_info
212 * PARAMETERS: Handle - Object Handle
213 * Buffer - Where the info is returned
215 * RETURN: Status
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.)
221 ******************************************************************************/
223 acpi_status
224 acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
226 acpi_status status;
227 struct acpi_namespace_node *node;
228 struct acpi_device_info *info;
229 struct acpi_device_info *return_info;
230 struct acpi_compatible_id_list *cid_list = NULL;
231 acpi_size size;
233 /* Parameter validation */
235 if (!handle || !buffer) {
236 return (AE_BAD_PARAMETER);
239 status = acpi_ut_validate_buffer(buffer);
240 if (ACPI_FAILURE(status)) {
241 return (status);
244 info = ACPI_MEM_CALLOCATE(sizeof(struct acpi_device_info));
245 if (!info) {
246 return (AE_NO_MEMORY);
249 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
250 if (ACPI_FAILURE(status)) {
251 goto cleanup;
254 node = acpi_ns_map_handle_to_node(handle);
255 if (!node) {
256 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
257 goto cleanup;
260 /* Init return structure */
262 size = sizeof(struct acpi_device_info);
264 info->type = node->type;
265 info->name = node->name.integer;
266 info->valid = 0;
268 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
269 if (ACPI_FAILURE(status)) {
270 goto cleanup;
273 /* If not a device, we are all done */
275 if (info->type == ACPI_TYPE_DEVICE) {
277 * Get extra info for ACPI Devices objects only:
278 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
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.
285 /* Execute the Device._HID method */
287 status = acpi_ut_execute_HID(node, &info->hardware_id);
288 if (ACPI_SUCCESS(status)) {
289 info->valid |= ACPI_VALID_HID;
292 /* Execute the Device._UID method */
294 status = acpi_ut_execute_UID(node, &info->unique_id);
295 if (ACPI_SUCCESS(status)) {
296 info->valid |= ACPI_VALID_UID;
299 /* Execute the Device._CID method */
301 status = acpi_ut_execute_CID(node, &cid_list);
302 if (ACPI_SUCCESS(status)) {
303 size += ((acpi_size) cid_list->count - 1) *
304 sizeof(struct acpi_compatible_id);
305 info->valid |= ACPI_VALID_CID;
308 /* Execute the Device._STA method */
310 status = acpi_ut_execute_STA(node, &info->current_status);
311 if (ACPI_SUCCESS(status)) {
312 info->valid |= ACPI_VALID_STA;
315 /* Execute the Device._ADR method */
317 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
318 &info->address);
319 if (ACPI_SUCCESS(status)) {
320 info->valid |= ACPI_VALID_ADR;
323 /* Execute the Device._sx_d methods */
325 status = acpi_ut_execute_sxds(node, info->highest_dstates);
326 if (ACPI_SUCCESS(status)) {
327 info->valid |= ACPI_VALID_SXDS;
331 /* Validate/Allocate/Clear caller buffer */
333 status = acpi_ut_initialize_buffer(buffer, size);
334 if (ACPI_FAILURE(status)) {
335 goto cleanup;
338 /* Populate the return buffer */
340 return_info = buffer->pointer;
341 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
343 if (cid_list) {
344 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
345 cid_list->size);
348 cleanup:
349 ACPI_MEM_FREE(info);
350 if (cid_list) {
351 ACPI_MEM_FREE(cid_list);
353 return (status);
356 EXPORT_SYMBOL(acpi_get_object_info);