1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
6 *****************************************************************************/
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
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 <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
48 #define _COMPONENT ACPI_NAMESPACE
49 ACPI_MODULE_NAME("nsxfname")
51 /******************************************************************************
53 * FUNCTION: acpi_get_handle
55 * PARAMETERS: Parent - Object to search under (search scope).
56 * Pathname - Pointer to an asciiz string containing the
58 * ret_handle - Where the return handle is returned
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
67 ******************************************************************************/
69 acpi_get_handle(acpi_handle parent,
70 acpi_string pathname, acpi_handle * ret_handle)
73 struct acpi_namespace_node *node = NULL;
74 struct acpi_namespace_node *prefix_node = NULL;
76 ACPI_FUNCTION_ENTRY();
78 /* Parameter Validation */
80 if (!ret_handle || !pathname) {
81 return (AE_BAD_PARAMETER);
84 /* Convert a parent handle to a prefix node */
87 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
88 if (ACPI_FAILURE(status)) {
92 prefix_node = acpi_ns_map_handle_to_node(parent);
94 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
95 return (AE_BAD_PARAMETER);
98 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
99 if (ACPI_FAILURE(status)) {
104 /* Special case for root, since we can't search for it */
106 if (ACPI_STRCMP(pathname, ACPI_NS_ROOT_PATH) == 0) {
108 acpi_ns_convert_entry_to_handle(acpi_gbl_root_node);
113 * Find the Node and convert to a handle
115 status = acpi_ns_get_node(prefix_node, pathname, ACPI_NS_NO_UPSEARCH,
119 if (ACPI_SUCCESS(status)) {
120 *ret_handle = acpi_ns_convert_entry_to_handle(node);
126 ACPI_EXPORT_SYMBOL(acpi_get_handle)
128 /******************************************************************************
130 * FUNCTION: acpi_get_name
132 * PARAMETERS: Handle - Handle to be converted to a pathname
133 * name_type - Full pathname or single segment
134 * Buffer - Buffer for returned path
136 * RETURN: Pointer to a string containing the fully qualified Name.
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.
142 ******************************************************************************/
144 acpi_get_name(acpi_handle handle, u32 name_type, struct acpi_buffer * buffer)
147 struct acpi_namespace_node *node;
149 /* Parameter validation */
151 if (name_type > ACPI_NAME_TYPE_MAX) {
152 return (AE_BAD_PARAMETER);
155 status = acpi_ut_validate_buffer(buffer);
156 if (ACPI_FAILURE(status)) {
160 if (name_type == ACPI_FULL_PATHNAME) {
162 /* Get the full pathname (From the namespace root) */
164 status = acpi_ns_handle_to_pathname(handle, buffer);
169 * Wants the single segment ACPI name.
170 * Validate handle and convert to a namespace Node
172 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
173 if (ACPI_FAILURE(status)) {
177 node = acpi_ns_map_handle_to_node(handle);
179 status = AE_BAD_PARAMETER;
180 goto unlock_and_exit;
183 /* Validate/Allocate/Clear caller buffer */
185 status = acpi_ut_initialize_buffer(buffer, ACPI_PATH_SEGMENT_LENGTH);
186 if (ACPI_FAILURE(status)) {
187 goto unlock_and_exit;
190 /* Just copy the ACPI name from the Node and zero terminate it */
192 ACPI_STRNCPY(buffer->pointer, acpi_ut_get_node_name(node),
194 ((char *)buffer->pointer)[ACPI_NAME_SIZE] = 0;
199 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
203 ACPI_EXPORT_SYMBOL(acpi_get_name)
205 /******************************************************************************
207 * FUNCTION: acpi_get_object_info
209 * PARAMETERS: Handle - Object Handle
210 * Buffer - Where the info is returned
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.)
218 ******************************************************************************/
220 acpi_get_object_info(acpi_handle handle, struct acpi_buffer * buffer)
223 struct acpi_namespace_node *node;
224 struct acpi_device_info *info;
225 struct acpi_device_info *return_info;
226 struct acpi_compatible_id_list *cid_list = NULL;
229 /* Parameter validation */
231 if (!handle || !buffer) {
232 return (AE_BAD_PARAMETER);
235 status = acpi_ut_validate_buffer(buffer);
236 if (ACPI_FAILURE(status)) {
240 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_device_info));
242 return (AE_NO_MEMORY);
245 status = acpi_ut_acquire_mutex(ACPI_MTX_NAMESPACE);
246 if (ACPI_FAILURE(status)) {
250 node = acpi_ns_map_handle_to_node(handle);
252 (void)acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
256 /* Init return structure */
258 size = sizeof(struct acpi_device_info);
260 info->type = node->type;
261 info->name = node->name.integer;
264 status = acpi_ut_release_mutex(ACPI_MTX_NAMESPACE);
265 if (ACPI_FAILURE(status)) {
269 /* If not a device, we are all done */
271 if (info->type == ACPI_TYPE_DEVICE) {
273 * Get extra info for ACPI Devices objects only:
274 * Run the Device _HID, _UID, _CID, _STA, _ADR and _sx_d methods.
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.
281 /* Execute the Device._HID method */
283 status = acpi_ut_execute_HID(node, &info->hardware_id);
284 if (ACPI_SUCCESS(status)) {
285 info->valid |= ACPI_VALID_HID;
288 /* Execute the Device._UID method */
290 status = acpi_ut_execute_UID(node, &info->unique_id);
291 if (ACPI_SUCCESS(status)) {
292 info->valid |= ACPI_VALID_UID;
295 /* Execute the Device._CID method */
297 status = acpi_ut_execute_CID(node, &cid_list);
298 if (ACPI_SUCCESS(status)) {
299 size += cid_list->size;
300 info->valid |= ACPI_VALID_CID;
303 /* Execute the Device._STA method */
305 status = acpi_ut_execute_STA(node, &info->current_status);
306 if (ACPI_SUCCESS(status)) {
307 info->valid |= ACPI_VALID_STA;
310 /* Execute the Device._ADR method */
312 status = acpi_ut_evaluate_numeric_object(METHOD_NAME__ADR, node,
314 if (ACPI_SUCCESS(status)) {
315 info->valid |= ACPI_VALID_ADR;
318 /* Execute the Device._sx_d methods */
320 status = acpi_ut_execute_sxds(node, info->highest_dstates);
321 if (ACPI_SUCCESS(status)) {
322 info->valid |= ACPI_VALID_SXDS;
326 /* Validate/Allocate/Clear caller buffer */
328 status = acpi_ut_initialize_buffer(buffer, size);
329 if (ACPI_FAILURE(status)) {
333 /* Populate the return buffer */
335 return_info = buffer->pointer;
336 ACPI_MEMCPY(return_info, info, sizeof(struct acpi_device_info));
339 ACPI_MEMCPY(&return_info->compatibility_id, cid_list,
351 ACPI_EXPORT_SYMBOL(acpi_get_object_info)