- Kai Germaschewski: ISDN update (including Makefiles)
[davej-history.git] / drivers / acpi / namespace / nsxfname.c
blob2947f7f06eba976a3249571b97fba1d5a859f024
1 /******************************************************************************
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 * $Revision: 73 $
7 *****************************************************************************/
9 /*
10 * Copyright (C) 2000 R. Byron Moore
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #include "acpi.h"
29 #include "acinterp.h"
30 #include "acnamesp.h"
31 #include "amlcode.h"
32 #include "acparser.h"
33 #include "acdispat.h"
34 #include "acevents.h"
37 #define _COMPONENT NAMESPACE
38 MODULE_NAME ("nsxfname")
41 /****************************************************************************
43 * FUNCTION: Acpi_get_handle
45 * PARAMETERS: Parent - Object to search under (search scope).
46 * Path_name - Pointer to an asciiz string containing the
47 * name
48 * Ret_handle - Where the return handle is placed
50 * RETURN: Status
52 * DESCRIPTION: This routine will search for a caller specified name in the
53 * name space. The caller can restrict the search region by
54 * specifying a non NULL parent. The parent value is itself a
55 * namespace handle.
57 ******************************************************************************/
59 ACPI_STATUS
60 acpi_get_handle (
61 ACPI_HANDLE parent,
62 ACPI_STRING pathname,
63 ACPI_HANDLE *ret_handle)
65 ACPI_STATUS status;
66 ACPI_NAMESPACE_NODE *node = NULL;
67 ACPI_NAMESPACE_NODE *prefix_node = NULL;
70 if (!ret_handle || !pathname) {
71 return (AE_BAD_PARAMETER);
74 /* Convert a parent handle to a prefix node */
76 if (parent) {
77 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
79 prefix_node = acpi_ns_convert_handle_to_entry (parent);
80 if (!prefix_node) {
81 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
82 return (AE_BAD_PARAMETER);
85 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
88 /* Special case for root, since we can't search for it */
90 if (STRCMP (pathname, NS_ROOT_PATH) == 0) {
91 *ret_handle = acpi_ns_convert_entry_to_handle (acpi_gbl_root_node);
92 return (AE_OK);
96 * Find the Node and convert to a handle
98 status = acpi_ns_get_node (pathname, prefix_node, &node);
100 *ret_handle = NULL;
101 if (ACPI_SUCCESS (status)) {
102 *ret_handle = acpi_ns_convert_entry_to_handle (node);
105 return (status);
109 /****************************************************************************
111 * FUNCTION: Acpi_get_pathname
113 * PARAMETERS: Handle - Handle to be converted to a pathname
114 * Name_type - Full pathname or single segment
115 * Ret_path_ptr - Buffer for returned path
117 * RETURN: Pointer to a string containing the fully qualified Name.
119 * DESCRIPTION: This routine returns the fully qualified name associated with
120 * the Handle parameter. This and the Acpi_pathname_to_handle are
121 * complementary functions.
123 ******************************************************************************/
125 ACPI_STATUS
126 acpi_get_name (
127 ACPI_HANDLE handle,
128 u32 name_type,
129 ACPI_BUFFER *ret_path_ptr)
131 ACPI_STATUS status;
132 ACPI_NAMESPACE_NODE *node;
135 /* Buffer pointer must be valid always */
137 if (!ret_path_ptr || (name_type > ACPI_NAME_TYPE_MAX)) {
138 return (AE_BAD_PARAMETER);
141 /* Allow length to be zero and ignore the pointer */
143 if ((ret_path_ptr->length) &&
144 (!ret_path_ptr->pointer))
146 return (AE_BAD_PARAMETER);
149 if (name_type == ACPI_FULL_PATHNAME) {
150 /* Get the full pathname (From the namespace root) */
152 status = acpi_ns_handle_to_pathname (handle, &ret_path_ptr->length,
153 ret_path_ptr->pointer);
154 return (status);
158 * Wants the single segment ACPI name.
159 * Validate handle and convert to an Node
162 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
163 node = acpi_ns_convert_handle_to_entry (handle);
164 if (!node) {
165 status = AE_BAD_PARAMETER;
166 goto unlock_and_exit;
169 /* Check if name will fit in buffer */
171 if (ret_path_ptr->length < PATH_SEGMENT_LENGTH) {
172 ret_path_ptr->length = PATH_SEGMENT_LENGTH;
173 status = AE_BUFFER_OVERFLOW;
174 goto unlock_and_exit;
177 /* Just copy the ACPI name from the Node and zero terminate it */
179 STRNCPY (ret_path_ptr->pointer, (NATIVE_CHAR *) &node->name,
180 ACPI_NAME_SIZE);
181 ((NATIVE_CHAR *) ret_path_ptr->pointer) [ACPI_NAME_SIZE] = 0;
182 status = AE_OK;
185 unlock_and_exit:
187 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
188 return (status);
192 /****************************************************************************
194 * FUNCTION: Acpi_get_object_info
196 * PARAMETERS: Handle - Object Handle
197 * Info - Where the info is returned
199 * RETURN: Status
201 * DESCRIPTION: Returns information about an object as gleaned from the
202 * namespace node and possibly by running several standard
203 * control methods (Such as in the case of a device.)
205 ******************************************************************************/
207 ACPI_STATUS
208 acpi_get_object_info (
209 ACPI_HANDLE handle,
210 ACPI_DEVICE_INFO *info)
212 DEVICE_ID hid;
213 DEVICE_ID uid;
214 ACPI_STATUS status;
215 u32 device_status = 0;
216 ACPI_INTEGER address = 0;
217 ACPI_NAMESPACE_NODE *node;
220 /* Parameter validation */
222 if (!handle || !info) {
223 return (AE_BAD_PARAMETER);
226 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
228 node = acpi_ns_convert_handle_to_entry (handle);
229 if (!node) {
230 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
231 return (AE_BAD_PARAMETER);
234 info->type = node->type;
235 info->name = node->name;
237 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
240 * If not a device, we are all done.
242 if (info->type != ACPI_TYPE_DEVICE) {
243 return (AE_OK);
248 * Get extra info for ACPI devices only. Run the
249 * _HID, _UID, _STA, and _ADR methods. Note: none
250 * of these methods are required, so they may or may
251 * not be present. The Info->Valid bits are used
252 * to indicate which methods ran successfully.
255 info->valid = 0;
257 /* Execute the _HID method and save the result */
259 status = acpi_cm_execute_HID (node, &hid);
260 if (ACPI_SUCCESS (status)) {
261 STRNCPY (info->hardware_id, hid.buffer, sizeof(info->hardware_id));
263 info->valid |= ACPI_VALID_HID;
266 /* Execute the _UID method and save the result */
268 status = acpi_cm_execute_UID (node, &uid);
269 if (ACPI_SUCCESS (status)) {
270 STRCPY (info->unique_id, uid.buffer);
272 info->valid |= ACPI_VALID_UID;
276 * Execute the _STA method and save the result
277 * _STA is not always present
280 status = acpi_cm_execute_STA (node, &device_status);
281 if (ACPI_SUCCESS (status)) {
282 info->current_status = device_status;
283 info->valid |= ACPI_VALID_STA;
287 * Execute the _ADR method and save result if successful
288 * _ADR is not always present
291 status = acpi_cm_evaluate_numeric_object (METHOD_NAME__ADR,
292 node, &address);
294 if (ACPI_SUCCESS (status)) {
295 info->address = address;
296 info->valid |= ACPI_VALID_ADR;
299 return (AE_OK);