1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
9 * Copyright (C) 2000 - 2004, 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
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.
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>
51 #define _COMPONENT ACPI_NAMESPACE
52 ACPI_MODULE_NAME ("nsxfname")
55 /******************************************************************************
57 * FUNCTION: acpi_get_handle
59 * PARAMETERS: Parent - Object to search under (search scope).
60 * path_name - Pointer to an asciiz string containing the
62 * ret_handle - Where the return handle is placed
66 * DESCRIPTION: This routine will search for a caller specified name in the
67 * name space. The caller can restrict the search region by
68 * specifying a non NULL parent. The parent value is itself a
71 ******************************************************************************/
77 acpi_handle *ret_handle)
80 struct acpi_namespace_node *node = NULL;
81 struct acpi_namespace_node *prefix_node = NULL;
84 ACPI_FUNCTION_ENTRY ();
87 /* Parameter Validation */
89 if (!ret_handle || !pathname) {
90 return (AE_BAD_PARAMETER);
93 /* Convert a parent handle to a prefix node */
96 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
97 if (ACPI_FAILURE (status)) {
101 prefix_node = acpi_ns_map_handle_to_node (parent);
103 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
104 return (AE_BAD_PARAMETER);
107 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
108 if (ACPI_FAILURE (status)) {
113 /* Special case for root, since we can't search for it */
115 if (ACPI_STRCMP (pathname, ACPI_NS_ROOT_PATH) == 0) {
116 *ret_handle = acpi_ns_convert_entry_to_handle (acpi_gbl_root_node);
121 * Find the Node and convert to a handle
123 status = acpi_ns_get_node_by_path (pathname, prefix_node, ACPI_NS_NO_UPSEARCH,
127 if (ACPI_SUCCESS (status)) {
128 *ret_handle = acpi_ns_convert_entry_to_handle (node);
133 EXPORT_SYMBOL(acpi_get_handle);
136 /******************************************************************************
138 * FUNCTION: acpi_get_name
140 * PARAMETERS: Handle - Handle to be converted to a pathname
141 * name_type - Full pathname or single segment
142 * Buffer - Buffer for returned path
144 * RETURN: Pointer to a string containing the fully qualified Name.
146 * DESCRIPTION: This routine returns the fully qualified name associated with
147 * the Handle parameter. This and the acpi_pathname_to_handle are
148 * complementary functions.
150 ******************************************************************************/
156 struct acpi_buffer *buffer)
159 struct acpi_namespace_node *node;
162 /* Parameter validation */
164 if (name_type > ACPI_NAME_TYPE_MAX) {
165 return (AE_BAD_PARAMETER);
168 status = acpi_ut_validate_buffer (buffer);
169 if (ACPI_FAILURE (status)) {
173 if (name_type == ACPI_FULL_PATHNAME) {
174 /* Get the full pathname (From the namespace root) */
176 status = acpi_ns_handle_to_pathname (handle, buffer);
181 * Wants the single segment ACPI name.
182 * Validate handle and convert to a namespace Node
184 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
185 if (ACPI_FAILURE (status)) {
189 node = acpi_ns_map_handle_to_node (handle);
191 status = AE_BAD_PARAMETER;
192 goto unlock_and_exit;
195 /* Validate/Allocate/Clear caller buffer */
197 status = acpi_ut_initialize_buffer (buffer, ACPI_PATH_SEGMENT_LENGTH);
198 if (ACPI_FAILURE (status)) {
199 goto unlock_and_exit;
202 /* Just copy the ACPI name from the Node and zero terminate it */
204 ACPI_STRNCPY (buffer->pointer, acpi_ut_get_node_name (node),
206 ((char *) buffer->pointer) [ACPI_NAME_SIZE] = 0;
212 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
215 EXPORT_SYMBOL(acpi_get_name);
218 /******************************************************************************
220 * FUNCTION: acpi_get_object_info
222 * PARAMETERS: Handle - Object Handle
223 * Info - Where the info is returned
227 * DESCRIPTION: Returns information about an object as gleaned from the
228 * namespace node and possibly by running several standard
229 * control methods (Such as in the case of a device.)
231 ******************************************************************************/
234 acpi_get_object_info (
236 struct acpi_buffer *buffer)
239 struct acpi_namespace_node *node;
240 struct acpi_device_info info;
241 struct acpi_device_info *return_info;
242 struct acpi_compatible_id_list *cid_list = NULL;
246 /* Parameter validation */
248 if (!handle || !buffer) {
249 return (AE_BAD_PARAMETER);
252 status = acpi_ut_validate_buffer (buffer);
253 if (ACPI_FAILURE (status)) {
257 status = acpi_ut_acquire_mutex (ACPI_MTX_NAMESPACE);
258 if (ACPI_FAILURE (status)) {
262 node = acpi_ns_map_handle_to_node (handle);
264 (void) acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
265 return (AE_BAD_PARAMETER);
268 /* Init return structure */
270 size = sizeof (struct acpi_device_info);
271 ACPI_MEMSET (&info, 0, size);
273 info.type = node->type;
274 info.name = node->name.integer;
277 status = acpi_ut_release_mutex (ACPI_MTX_NAMESPACE);
278 if (ACPI_FAILURE (status)) {
282 /* If not a device, we are all done */
284 if (info.type == ACPI_TYPE_DEVICE) {
286 * Get extra info for ACPI Devices objects only:
287 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
289 * Note: none of these methods are required, so they may or may
290 * not be present for this device. The Info.Valid bitfield is used
291 * to indicate which methods were found and ran successfully.
294 /* Execute the Device._HID method */
296 status = acpi_ut_execute_HID (node, &info.hardware_id);
297 if (ACPI_SUCCESS (status)) {
298 info.valid |= ACPI_VALID_HID;
301 /* Execute the Device._UID method */
303 status = acpi_ut_execute_UID (node, &info.unique_id);
304 if (ACPI_SUCCESS (status)) {
305 info.valid |= ACPI_VALID_UID;
308 /* Execute the Device._CID method */
310 status = acpi_ut_execute_CID (node, &cid_list);
311 if (ACPI_SUCCESS (status)) {
312 size += ((acpi_size) cid_list->count - 1) *
313 sizeof (struct acpi_compatible_id);
314 info.valid |= ACPI_VALID_CID;
317 /* Execute the Device._STA method */
319 status = acpi_ut_execute_STA (node, &info.current_status);
320 if (ACPI_SUCCESS (status)) {
321 info.valid |= ACPI_VALID_STA;
324 /* Execute the Device._ADR method */
326 status = acpi_ut_evaluate_numeric_object (METHOD_NAME__ADR, node,
328 if (ACPI_SUCCESS (status)) {
329 info.valid |= ACPI_VALID_ADR;
332 /* Execute the Device._sx_d methods */
334 status = acpi_ut_execute_sxds (node, info.highest_dstates);
335 if (ACPI_SUCCESS (status)) {
336 info.valid |= ACPI_VALID_SXDS;
342 /* Validate/Allocate/Clear caller buffer */
344 status = acpi_ut_initialize_buffer (buffer, size);
345 if (ACPI_FAILURE (status)) {
349 /* Populate the return buffer */
351 return_info = buffer->pointer;
352 ACPI_MEMCPY (return_info, &info, sizeof (struct acpi_device_info));
355 ACPI_MEMCPY (&return_info->compatibility_id, cid_list, cid_list->size);
361 ACPI_MEM_FREE (cid_list);
365 EXPORT_SYMBOL(acpi_get_object_info);