File: /usr/src/linux/drivers/acpi/utilities/uteval.c
1 /******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 * $Revision: 30 $
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 ("uteval")
34
35
36 /*******************************************************************************
37 *
38 * FUNCTION: Acpi_ut_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_ut_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 FUNCTION_TRACE ("Ut_evaluate_numeric_object");
64
65
66 /* Execute the method */
67
68 status = acpi_ns_evaluate_relative (device_node, object_name, NULL, &obj_desc);
69 if (ACPI_FAILURE (status)) {
70 if (status == AE_NOT_FOUND) {
71 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "%s on %4.4s was not found\n",
72 object_name, &device_node->name));
73 }
74 else {
75 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "%s on %4.4s failed with status %s\n",
76 object_name, &device_node->name,
77 acpi_format_exception (status)));
78 }
79
80 return_ACPI_STATUS (status);
81 }
82
83
84 /* Did we get a return object? */
85
86 if (!obj_desc) {
87 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from %s\n",
88 object_name));
89 return_ACPI_STATUS (AE_TYPE);
90 }
91
92 /* Is the return object of the correct type? */
93
94 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
95 status = AE_TYPE;
96 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
97 "Type returned from %s was not a number: %X \n",
98 object_name, obj_desc->common.type));
99 }
100 else {
101 /*
102 * Since the structure is a union, setting any field will set all
103 * of the variables in the union
104 */
105 *address = obj_desc->integer.value;
106 }
107
108 /* On exit, we must delete the return object */
109
110 acpi_ut_remove_reference (obj_desc);
111
112 return_ACPI_STATUS (status);
113 }
114
115
116 /*******************************************************************************
117 *
118 * FUNCTION: Acpi_ut_execute_HID
119 *
120 * PARAMETERS: Device_node - Node for the device
121 * *Hid - Where the HID is returned
122 *
123 * RETURN: Status
124 *
125 * DESCRIPTION: Executes the _HID control method that returns the hardware
126 * ID of the device.
127 *
128 * NOTE: Internal function, no parameter validation
129 *
130 ******************************************************************************/
131
132 acpi_status
133 acpi_ut_execute_HID (
134 acpi_namespace_node *device_node,
135 ACPI_DEVICE_ID *hid)
136 {
137 acpi_operand_object *obj_desc;
138 acpi_status status;
139
140
141 FUNCTION_TRACE ("Ut_execute_HID");
142
143
144 /* Execute the method */
145
146 status = acpi_ns_evaluate_relative (device_node,
147 METHOD_NAME__HID, NULL, &obj_desc);
148 if (ACPI_FAILURE (status)) {
149 if (status == AE_NOT_FOUND) {
150 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "_HID on %4.4s was not found\n",
151 &device_node->name));
152 }
153
154 else {
155 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_HID on %4.4s failed %s\n",
156 &device_node->name, acpi_format_exception (status)));
157 }
158
159 return_ACPI_STATUS (status);
160 }
161
162 /* Did we get a return object? */
163
164 if (!obj_desc) {
165 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _HID\n"));
166 return_ACPI_STATUS (AE_TYPE);
167 }
168
169 /*
170 * A _HID can return either a Number (32 bit compressed EISA ID) or
171 * a string
172 */
173 if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
174 (obj_desc->common.type != ACPI_TYPE_STRING)) {
175 status = AE_TYPE;
176 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
177 "Type returned from _HID not a number or string: %s(%X) \n",
178 acpi_ut_get_type_name (obj_desc->common.type), obj_desc->common.type));
179 }
180
181 else {
182 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
183 /* Convert the Numeric HID to string */
184
185 acpi_ex_eisa_id_to_string ((u32) obj_desc->integer.value, hid->buffer);
186 }
187
188 else {
189 /* Copy the String HID from the returned object */
190
191 STRNCPY(hid->buffer, obj_desc->string.pointer, sizeof(hid->buffer));
192 }
193 }
194
195
196 /* On exit, we must delete the return object */
197
198 acpi_ut_remove_reference (obj_desc);
199
200 return_ACPI_STATUS (status);
201 }
202
203
204 /*******************************************************************************
205 *
206 * FUNCTION: Acpi_ut_execute_UID
207 *
208 * PARAMETERS: Device_node - Node for the device
209 * *Uid - Where the UID is returned
210 *
211 * RETURN: Status
212 *
213 * DESCRIPTION: Executes the _UID control method that returns the hardware
214 * ID of the device.
215 *
216 * NOTE: Internal function, no parameter validation
217 *
218 ******************************************************************************/
219
220 acpi_status
221 acpi_ut_execute_UID (
222 acpi_namespace_node *device_node,
223 ACPI_DEVICE_ID *uid)
224 {
225 acpi_operand_object *obj_desc;
226 acpi_status status;
227
228
229 PROC_NAME ("Ut_execute_UID");
230
231
232 /* Execute the method */
233
234 status = acpi_ns_evaluate_relative (device_node,
235 METHOD_NAME__UID, NULL, &obj_desc);
236 if (ACPI_FAILURE (status)) {
237 if (status == AE_NOT_FOUND) {
238 ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "_UID on %4.4s was not found\n",
239 &device_node->name));
240 }
241
242 else {
243 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
244 "_UID on %4.4s failed %s\n",
245 &device_node->name, acpi_format_exception (status)));
246 }
247
248 return (status);
249 }
250
251 /* Did we get a return object? */
252
253 if (!obj_desc) {
254 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _UID\n"));
255 return (AE_TYPE);
256 }
257
258 /*
259 * A _UID can return either a Number (32 bit compressed EISA ID) or
260 * a string
261 */
262 if ((obj_desc->common.type != ACPI_TYPE_INTEGER) &&
263 (obj_desc->common.type != ACPI_TYPE_STRING)) {
264 status = AE_TYPE;
265 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
266 "Type returned from _UID was not a number or string: %X \n",
267 obj_desc->common.type));
268 }
269
270 else {
271 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
272 /* Convert the Numeric UID to string */
273
274 acpi_ex_unsigned_integer_to_string (obj_desc->integer.value, uid->buffer);
275 }
276
277 else {
278 /* Copy the String UID from the returned object */
279
280 STRNCPY(uid->buffer, obj_desc->string.pointer, sizeof(uid->buffer));
281 }
282 }
283
284
285 /* On exit, we must delete the return object */
286
287 acpi_ut_remove_reference (obj_desc);
288
289 return (status);
290 }
291
292
293 /*******************************************************************************
294 *
295 * FUNCTION: Acpi_ut_execute_STA
296 *
297 * PARAMETERS: Device_node - Node for the device
298 * *Flags - Where the status flags are returned
299 *
300 * RETURN: Status
301 *
302 * DESCRIPTION: Executes _STA for selected device and stores results in
303 * *Flags.
304 *
305 * NOTE: Internal function, no parameter validation
306 *
307 ******************************************************************************/
308
309 acpi_status
310 acpi_ut_execute_STA (
311 acpi_namespace_node *device_node,
312 u32 *flags)
313 {
314 acpi_operand_object *obj_desc;
315 acpi_status status;
316
317
318 FUNCTION_TRACE ("Ut_execute_STA");
319
320
321 /* Execute the method */
322
323 status = acpi_ns_evaluate_relative (device_node,
324 METHOD_NAME__STA, NULL, &obj_desc);
325 if (AE_NOT_FOUND == status) {
326 ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
327 "_STA on %4.4s was not found, assuming present.\n",
328 &device_node->name));
329
330 *flags = 0x0F;
331 status = AE_OK;
332 }
333
334 else if (ACPI_FAILURE (status)) {
335 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "_STA on %4.4s failed %s\n",
336 &device_node->name,
337 acpi_format_exception (status)));
338 }
339
340 else /* success */ {
341 /* Did we get a return object? */
342
343 if (!obj_desc) {
344 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "No object was returned from _STA\n"));
345 return_ACPI_STATUS (AE_TYPE);
346 }
347
348 /* Is the return object of the correct type? */
349
350 if (obj_desc->common.type != ACPI_TYPE_INTEGER) {
351 status = AE_TYPE;
352 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
353 "Type returned from _STA was not a number: %X \n",
354 obj_desc->common.type));
355 }
356
357 else {
358 /* Extract the status flags */
359
360 *flags = (u32) obj_desc->integer.value;
361 }
362
363 /* On exit, we must delete the return object */
364
365 acpi_ut_remove_reference (obj_desc);
366 }
367
368 return_ACPI_STATUS (status);
369 }
370