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