:pserver:cvsanon@mok.lvcm.com:/CVS/ReactOS reactos
[reactos.git] / drivers / bus / acpi / utils / cmeval.c
1 /******************************************************************************
2  *
3  * Module Name: cmeval - Object evaluation
4  *              $Revision$
5  *
6  *****************************************************************************/
7
8 /*
9  *  Copyright (C) 2000, 2001 R. Byron Moore
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
24  */
25
26
27 #include "acpi.h"
28 #include "acnamesp.h"
29 #include "acinterp.h"
30
31
32 #define _COMPONENT          ACPI_UTILITIES
33          MODULE_NAME         ("cmeval")
34
35
36 /****************************************************************************
37  *
38  * FUNCTION:    Acpi_cm_evaluate_numeric_object
39  *
40  * PARAMETERS:  *Object_name        - Object name to be evaluated
41  *              Device_node         - Node for the device
42  *              *Address            - Where the value is returned
43  *
44  * RETURN:      Status
45  *
46  * DESCRIPTION: evaluates a numeric namespace object for a selected device
47  *              and stores results in *Address.
48  *
49  *              NOTE: Internal function, no parameter validation
50  *
51  ***************************************************************************/
52
53 ACPI_STATUS
54 acpi_cm_evaluate_numeric_object (
55         NATIVE_CHAR             *object_name,
56         ACPI_NAMESPACE_NODE     *device_node,
57         ACPI_INTEGER            *address)
58 {
59         ACPI_OPERAND_OBJECT     *obj_desc;
60         ACPI_STATUS             status;
61
62
63         /* Execute the method */
64
65         status = acpi_ns_evaluate_relative (device_node, object_name, NULL, &obj_desc);
66         if (ACPI_FAILURE (status)) {
67
68                 return (status);
69         }
70
71
72         /* Did we get a return object? */
73
74         if (!obj_desc) {
75                 return (AE_TYPE);
76         }
77
78         /* Is the return object of the correct type? */
79
80         if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
81                 status = AE_TYPE;
82         }
83         else {
84                 /*
85                  * Since the structure is a union, setting any field will set all
86                  * of the variables in the union
87                  */
88                 *address = obj_desc->integer.value;
89         }
90
91         /* On exit, we must delete the return object */
92
93         acpi_cm_remove_reference (obj_desc);
94
95         return (status);
96 }
97
98
99 /****************************************************************************
100  *
101  * FUNCTION:    Acpi_cm_execute_HID
102  *
103  * PARAMETERS:  Device_node         - Node for the device
104  *              *Hid                - Where the HID is returned
105  *
106  * RETURN:      Status
107  *
108  * DESCRIPTION: Executes the _HID control method that returns the hardware
109  *              ID of the device.
110  *
111  *              NOTE: Internal function, no parameter validation
112  *
113  ***************************************************************************/
114
115 ACPI_STATUS
116 acpi_cm_execute_HID (
117         ACPI_NAMESPACE_NODE     *device_node,
118         DEVICE_ID               *hid)
119 {
120         ACPI_OPERAND_OBJECT     *obj_desc;
121         ACPI_STATUS             status;
122
123
124         /* Execute the method */
125
126         status = acpi_ns_evaluate_relative (device_node,
127                          METHOD_NAME__HID, NULL, &obj_desc);
128         if (ACPI_FAILURE (status)) {
129
130
131                 return (status);
132         }
133
134         /* Did we get a return object? */
135
136         if (!obj_desc) {
137                 return (AE_TYPE);
138         }
139
140         /*
141          *  A _HID can return either a Number (32 bit compressed EISA ID) or
142          *  a string
143          */
144
145         if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
146                 (obj_desc->common.type != ACPI_TYPE_STRING)) {
147                 status = AE_TYPE;
148         }
149
150         else {
151                 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
152                         /* Convert the Numeric HID to string */
153
154                         acpi_aml_eisa_id_to_string ((u32) obj_desc->integer.value, hid->buffer);
155                 }
156
157                 else {
158                         /* Copy the String HID from the returned object */
159
160                         STRNCPY(hid->buffer, obj_desc->string.pointer, sizeof(hid->buffer));
161                 }
162         }
163
164
165         /* On exit, we must delete the return object */
166
167         acpi_cm_remove_reference (obj_desc);
168
169         return (status);
170 }
171
172
173 /****************************************************************************
174  *
175  * FUNCTION:    Acpi_cm_execute_UID
176  *
177  * PARAMETERS:  Device_node         - Node for the device
178  *              *Uid                - Where the UID is returned
179  *
180  * RETURN:      Status
181  *
182  * DESCRIPTION: Executes the _UID control method that returns the hardware
183  *              ID of the device.
184  *
185  *              NOTE: Internal function, no parameter validation
186  *
187  ***************************************************************************/
188
189 ACPI_STATUS
190 acpi_cm_execute_UID (
191         ACPI_NAMESPACE_NODE     *device_node,
192         DEVICE_ID               *uid)
193 {
194         ACPI_OPERAND_OBJECT     *obj_desc;
195         ACPI_STATUS             status;
196
197
198         /* Execute the method */
199
200         status = acpi_ns_evaluate_relative (device_node,
201                          METHOD_NAME__UID, NULL, &obj_desc);
202         if (ACPI_FAILURE (status)) {
203
204
205                 return (status);
206         }
207
208         /* Did we get a return object? */
209
210         if (!obj_desc) {
211                 return (AE_TYPE);
212         }
213
214         /*
215          *  A _UID can return either a Number (32 bit compressed EISA ID) or
216          *  a string
217          */
218
219         if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
220                 (obj_desc->common.type != ACPI_TYPE_STRING)) {
221                 status = AE_TYPE;
222         }
223
224         else {
225                 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
226                         /* Convert the Numeric UID to string */
227
228                         acpi_aml_unsigned_integer_to_string (obj_desc->integer.value, uid->buffer);
229                 }
230
231                 else {
232                         /* Copy the String UID from the returned object */
233
234                         STRNCPY(uid->buffer, obj_desc->string.pointer, sizeof(uid->buffer));
235                 }
236         }
237
238
239         /* On exit, we must delete the return object */
240
241         acpi_cm_remove_reference (obj_desc);
242
243         return (status);
244 }
245
246 /****************************************************************************
247  *
248  * FUNCTION:    Acpi_cm_execute_STA
249  *
250  * PARAMETERS:  Device_node         - Node for the device
251  *              *Flags              - Where the status flags are returned
252  *
253  * RETURN:      Status
254  *
255  * DESCRIPTION: Executes _STA for selected device and stores results in
256  *              *Flags.
257  *
258  *              NOTE: Internal function, no parameter validation
259  *
260  ***************************************************************************/
261
262 ACPI_STATUS
263 acpi_cm_execute_STA (
264         ACPI_NAMESPACE_NODE     *device_node,
265         u32                     *flags)
266 {
267         ACPI_OPERAND_OBJECT     *obj_desc;
268         ACPI_STATUS             status;
269
270
271         /* Execute the method */
272
273         status = acpi_ns_evaluate_relative (device_node,
274                          METHOD_NAME__STA, NULL, &obj_desc);
275         if (AE_NOT_FOUND == status) {
276                 *flags = 0x0F;
277                 status = AE_OK;
278         }
279
280
281         else /* success */ {
282                 /* Did we get a return object? */
283
284                 if (!obj_desc) {
285                         return (AE_TYPE);
286                 }
287
288                 /* Is the return object of the correct type? */
289
290                 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
291                         status = AE_TYPE;
292                 }
293
294                 else {
295                         /* Extract the status flags */
296
297                         *flags = (u32) obj_desc->integer.value;
298                 }
299
300                 /* On exit, we must delete the return object */
301
302                 acpi_cm_remove_reference (obj_desc);
303         }
304
305         return (status);
306 }