Merge trunk HEAD (46152)
[reactos.git] / drivers / bus / acpi / utils / cmeval.c
1 /******************************************************************************
2 *
3 * Module Name: cmeval - Object evaluation
4 * $Revision: 1.1 $
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
29 #define _COMPONENT ACPI_UTILITIES
30 MODULE_NAME ("cmeval")
31
32
33 /****************************************************************************
34 *
35 * FUNCTION: Acpi_cm_evaluate_numeric_object
36 *
37 * PARAMETERS: *Object_name - Object name to be evaluated
38 * Device_node - Node for the device
39 * *Address - Where the value is returned
40 *
41 * RETURN: Status
42 *
43 * DESCRIPTION: evaluates a numeric namespace object for a selected device
44 * and stores results in *Address.
45 *
46 * NOTE: Internal function, no parameter validation
47 *
48 ***************************************************************************/
49
50 ACPI_STATUS
51 acpi_cm_evaluate_numeric_object (
52 NATIVE_CHAR *object_name,
53 ACPI_NAMESPACE_NODE *device_node,
54 ACPI_INTEGER *address)
55 {
56 ACPI_OPERAND_OBJECT *obj_desc;
57 ACPI_STATUS status;
58
59
60 /* Execute the method */
61
62 status = acpi_ns_evaluate_relative (device_node, object_name, NULL, &obj_desc);
63 if (ACPI_FAILURE (status)) {
64
65 return (status);
66 }
67
68
69 /* Did we get a return object? */
70
71 if (!obj_desc) {
72 return (AE_TYPE);
73 }
74
75 /* Is the return object of the correct type? */
76
77 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
78 status = AE_TYPE;
79 }
80 else {
81 /*
82 * Since the structure is a union, setting any field will set all
83 * of the variables in the union
84 */
85 *address = obj_desc->integer.value;
86 }
87
88 /* On exit, we must delete the return object */
89
90 acpi_cm_remove_reference (obj_desc);
91
92 return (status);
93 }
94
95
96 /****************************************************************************
97 *
98 * FUNCTION: Acpi_cm_execute_HID
99 *
100 * PARAMETERS: Device_node - Node for the device
101 * *Hid - Where the HID is returned
102 *
103 * RETURN: Status
104 *
105 * DESCRIPTION: Executes the _HID control method that returns the hardware
106 * ID of the device.
107 *
108 * NOTE: Internal function, no parameter validation
109 *
110 ***************************************************************************/
111
112 ACPI_STATUS
113 acpi_cm_execute_HID (
114 ACPI_NAMESPACE_NODE *device_node,
115 DEVICE_ID *hid)
116 {
117 ACPI_OPERAND_OBJECT *obj_desc;
118 ACPI_STATUS status;
119
120
121 /* Execute the method */
122
123 status = acpi_ns_evaluate_relative (device_node,
124 METHOD_NAME__HID, NULL, &obj_desc);
125 if (ACPI_FAILURE (status)) {
126
127
128 return (status);
129 }
130
131 /* Did we get a return object? */
132
133 if (!obj_desc) {
134 return (AE_TYPE);
135 }
136
137 /*
138 * A _HID can return either a Number (32 bit compressed EISA ID) or
139 * a string
140 */
141
142 if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
143 (obj_desc->common.type != ACPI_TYPE_STRING)) {
144 status = AE_TYPE;
145 }
146
147 else {
148 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
149 /* Convert the Numeric HID to string */
150
151 acpi_aml_eisa_id_to_string ((u32) obj_desc->integer.value, hid->buffer);
152 }
153
154 else {
155 /* Copy the String HID from the returned object */
156
157 STRNCPY(hid->buffer, obj_desc->string.pointer, sizeof(hid->buffer));
158 }
159 }
160
161
162 /* On exit, we must delete the return object */
163
164 acpi_cm_remove_reference (obj_desc);
165
166 return (status);
167 }
168
169
170 /****************************************************************************
171 *
172 * FUNCTION: Acpi_cm_execute_UID
173 *
174 * PARAMETERS: Device_node - Node for the device
175 * *Uid - Where the UID is returned
176 *
177 * RETURN: Status
178 *
179 * DESCRIPTION: Executes the _UID control method that returns the hardware
180 * ID of the device.
181 *
182 * NOTE: Internal function, no parameter validation
183 *
184 ***************************************************************************/
185
186 ACPI_STATUS
187 acpi_cm_execute_UID (
188 ACPI_NAMESPACE_NODE *device_node,
189 DEVICE_ID *uid)
190 {
191 ACPI_OPERAND_OBJECT *obj_desc;
192 ACPI_STATUS status;
193
194
195 /* Execute the method */
196
197 status = acpi_ns_evaluate_relative (device_node,
198 METHOD_NAME__UID, NULL, &obj_desc);
199 if (ACPI_FAILURE (status)) {
200
201
202 return (status);
203 }
204
205 /* Did we get a return object? */
206
207 if (!obj_desc) {
208 return (AE_TYPE);
209 }
210
211 /*
212 * A _UID can return either a Number (32 bit compressed EISA ID) or
213 * a string
214 */
215
216 if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
217 (obj_desc->common.type != ACPI_TYPE_STRING)) {
218 status = AE_TYPE;
219 }
220
221 else {
222 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
223 /* Convert the Numeric UID to string */
224
225 acpi_aml_unsigned_integer_to_string (obj_desc->integer.value, uid->buffer);
226 }
227
228 else {
229 /* Copy the String UID from the returned object */
230
231 STRNCPY(uid->buffer, obj_desc->string.pointer, sizeof(uid->buffer));
232 }
233 }
234
235
236 /* On exit, we must delete the return object */
237
238 acpi_cm_remove_reference (obj_desc);
239
240 return (status);
241 }
242
243 /****************************************************************************
244 *
245 * FUNCTION: Acpi_cm_execute_STA
246 *
247 * PARAMETERS: Device_node - Node for the device
248 * *Flags - Where the status flags are returned
249 *
250 * RETURN: Status
251 *
252 * DESCRIPTION: Executes _STA for selected device and stores results in
253 * *Flags.
254 *
255 * NOTE: Internal function, no parameter validation
256 *
257 ***************************************************************************/
258
259 ACPI_STATUS
260 acpi_cm_execute_STA (
261 ACPI_NAMESPACE_NODE *device_node,
262 u32 *flags)
263 {
264 ACPI_OPERAND_OBJECT *obj_desc;
265 ACPI_STATUS status;
266
267
268 /* Execute the method */
269
270 status = acpi_ns_evaluate_relative (device_node,
271 METHOD_NAME__STA, NULL, &obj_desc);
272 if (AE_NOT_FOUND == status) {
273 *flags = 0x0F;
274 status = AE_OK;
275 }
276
277
278 else /* success */ {
279 /* Did we get a return object? */
280
281 if (!obj_desc) {
282 return (AE_TYPE);
283 }
284
285 /* Is the return object of the correct type? */
286
287 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
288 status = AE_TYPE;
289 }
290
291 else {
292 /* Extract the status flags */
293
294 *flags = (u32) obj_desc->integer.value;
295 }
296
297 /* On exit, we must delete the return object */
298
299 acpi_cm_remove_reference (obj_desc);
300 }
301
302 return (status);
303 }