Merge trunk HEAD (46152)
[reactos.git] / drivers / bus / acpi / namespace / nsxfname.c
1 /******************************************************************************
2 *
3 * Module Name: nsxfname - Public interfaces to the ACPI subsystem
4 * ACPI Namespace oriented interfaces
5 * $Revision: 1.1 $
6 *
7 *****************************************************************************/
8
9 /*
10 * Copyright (C) 2000, 2001 R. Byron Moore
11 *
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.
16 *
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.
21 *
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
25 */
26
27
28 #include <acpi.h>
29
30
31 #define _COMPONENT ACPI_NAMESPACE
32 MODULE_NAME ("nsxfname")
33
34
35 /****************************************************************************
36 *
37 * FUNCTION: Acpi_get_handle
38 *
39 * PARAMETERS: Parent - Object to search under (search scope).
40 * Path_name - Pointer to an asciiz string containing the
41 * name
42 * Ret_handle - Where the return handle is placed
43 *
44 * RETURN: Status
45 *
46 * DESCRIPTION: This routine will search for a caller specified name in the
47 * name space. The caller can restrict the search region by
48 * specifying a non NULL parent. The parent value is itself a
49 * namespace handle.
50 *
51 ******************************************************************************/
52
53 ACPI_STATUS
54 acpi_get_handle (
55 ACPI_HANDLE parent,
56 ACPI_STRING pathname,
57 ACPI_HANDLE *ret_handle)
58 {
59 ACPI_STATUS status;
60 ACPI_NAMESPACE_NODE *node = NULL;
61 ACPI_NAMESPACE_NODE *prefix_node = NULL;
62
63
64 if (!ret_handle || !pathname) {
65 return (AE_BAD_PARAMETER);
66 }
67
68 /* Convert a parent handle to a prefix node */
69
70 if (parent) {
71 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
72
73 prefix_node = acpi_ns_convert_handle_to_entry (parent);
74 if (!prefix_node) {
75 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
76 return (AE_BAD_PARAMETER);
77 }
78
79 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
80 }
81
82 /* Special case for root, since we can't search for it */
83
84 if (STRCMP (pathname, NS_ROOT_PATH) == 0) {
85 *ret_handle = acpi_ns_convert_entry_to_handle (acpi_gbl_root_node);
86 return (AE_OK);
87 }
88
89 /*
90 * Find the Node and convert to a handle
91 */
92 status = acpi_ns_get_node (pathname, prefix_node, &node);
93
94 *ret_handle = NULL;
95 if (ACPI_SUCCESS (status)) {
96 *ret_handle = acpi_ns_convert_entry_to_handle (node);
97 }
98
99 return (status);
100 }
101
102
103 /****************************************************************************
104 *
105 * FUNCTION: Acpi_get_pathname
106 *
107 * PARAMETERS: Handle - Handle to be converted to a pathname
108 * Name_type - Full pathname or single segment
109 * Ret_path_ptr - Buffer for returned path
110 *
111 * RETURN: Pointer to a string containing the fully qualified Name.
112 *
113 * DESCRIPTION: This routine returns the fully qualified name associated with
114 * the Handle parameter. This and the Acpi_pathname_to_handle are
115 * complementary functions.
116 *
117 ******************************************************************************/
118
119 ACPI_STATUS
120 acpi_get_name (
121 ACPI_HANDLE handle,
122 u32 name_type,
123 ACPI_BUFFER *ret_path_ptr)
124 {
125 ACPI_STATUS status;
126 ACPI_NAMESPACE_NODE *node;
127
128
129 /* Buffer pointer must be valid always */
130
131 if (!ret_path_ptr || (name_type > ACPI_NAME_TYPE_MAX)) {
132 return (AE_BAD_PARAMETER);
133 }
134
135 /* Allow length to be zero and ignore the pointer */
136
137 if ((ret_path_ptr->length) &&
138 (!ret_path_ptr->pointer)) {
139 return (AE_BAD_PARAMETER);
140 }
141
142 if (name_type == ACPI_FULL_PATHNAME) {
143 /* Get the full pathname (From the namespace root) */
144
145 status = acpi_ns_handle_to_pathname (handle, &ret_path_ptr->length,
146 ret_path_ptr->pointer);
147 return (status);
148 }
149
150 /*
151 * Wants the single segment ACPI name.
152 * Validate handle and convert to an Node
153 */
154
155 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
156 node = acpi_ns_convert_handle_to_entry (handle);
157 if (!node) {
158 status = AE_BAD_PARAMETER;
159 goto unlock_and_exit;
160 }
161
162 /* Check if name will fit in buffer */
163
164 if (ret_path_ptr->length < PATH_SEGMENT_LENGTH) {
165 ret_path_ptr->length = PATH_SEGMENT_LENGTH;
166 status = AE_BUFFER_OVERFLOW;
167 goto unlock_and_exit;
168 }
169
170 /* Just copy the ACPI name from the Node and zero terminate it */
171
172 STRNCPY (ret_path_ptr->pointer, (NATIVE_CHAR *) &node->name,
173 ACPI_NAME_SIZE);
174 ((NATIVE_CHAR *) ret_path_ptr->pointer) [ACPI_NAME_SIZE] = 0;
175 status = AE_OK;
176
177
178 unlock_and_exit:
179
180 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
181 return (status);
182 }
183
184
185 /****************************************************************************
186 *
187 * FUNCTION: Acpi_get_object_info
188 *
189 * PARAMETERS: Handle - Object Handle
190 * Info - Where the info is returned
191 *
192 * RETURN: Status
193 *
194 * DESCRIPTION: Returns information about an object as gleaned from the
195 * namespace node and possibly by running several standard
196 * control methods (Such as in the case of a device.)
197 *
198 ******************************************************************************/
199
200 ACPI_STATUS
201 acpi_get_object_info (
202 ACPI_HANDLE handle,
203 ACPI_DEVICE_INFO *info)
204 {
205 DEVICE_ID hid;
206 DEVICE_ID uid;
207 ACPI_STATUS status;
208 u32 device_status = 0;
209 ACPI_INTEGER address = 0;
210 ACPI_NAMESPACE_NODE *node;
211
212
213 /* Parameter validation */
214
215 if (!handle || !info) {
216 return (AE_BAD_PARAMETER);
217 }
218
219 acpi_cm_acquire_mutex (ACPI_MTX_NAMESPACE);
220
221 node = acpi_ns_convert_handle_to_entry (handle);
222 if (!node) {
223 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
224 return (AE_BAD_PARAMETER);
225 }
226
227 info->type = node->type;
228 info->name = node->name;
229
230 acpi_cm_release_mutex (ACPI_MTX_NAMESPACE);
231
232 /*
233 * If not a device, we are all done.
234 */
235 if (info->type != ACPI_TYPE_DEVICE) {
236 return (AE_OK);
237 }
238
239
240 /*
241 * Get extra info for ACPI devices only. Run the
242 * _HID, _UID, _STA, and _ADR methods. Note: none
243 * of these methods are required, so they may or may
244 * not be present. The Info->Valid bits are used
245 * to indicate which methods ran successfully.
246 */
247
248 info->valid = 0;
249
250 /* Execute the _HID method and save the result */
251
252 status = acpi_cm_execute_HID (node, &hid);
253 if (ACPI_SUCCESS (status)) {
254 STRNCPY (info->hardware_id, hid.buffer, sizeof(info->hardware_id));
255
256 info->valid |= ACPI_VALID_HID;
257 }
258
259 /* Execute the _UID method and save the result */
260
261 status = acpi_cm_execute_UID (node, &uid);
262 if (ACPI_SUCCESS (status)) {
263 STRCPY (info->unique_id, uid.buffer);
264
265 info->valid |= ACPI_VALID_UID;
266 }
267
268 /*
269 * Execute the _STA method and save the result
270 * _STA is not always present
271 */
272
273 status = acpi_cm_execute_STA (node, &device_status);
274 if (ACPI_SUCCESS (status)) {
275 info->current_status = device_status;
276 info->valid |= ACPI_VALID_STA;
277 }
278
279 /*
280 * Execute the _ADR method and save result if successful
281 * _ADR is not always present
282 */
283
284 status = acpi_cm_evaluate_numeric_object (METHOD_NAME__ADR,
285 node, &address);
286
287 if (ACPI_SUCCESS (status)) {
288 info->address = address;
289 info->valid |= ACPI_VALID_ADR;
290 }
291
292 return (AE_OK);
293 }
294