ACPI: ACPICA 20060421
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / acpi / utilities / uteval.c
1 /******************************************************************************
2 *
3 * Module Name: uteval - Object evaluation
4 *
5 *****************************************************************************/
6
7 /*
8 * Copyright (C) 2000 - 2006, R. Byron Moore
9 * All rights reserved.
10 *
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
29 *
30 * NO WARRANTY
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
42 */
43
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46 #include <acpi/acinterp.h>
47
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("uteval")
50
51 /* Local prototypes */
52 static void
53 acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length);
54
55 static acpi_status
56 acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
57 struct acpi_compatible_id *one_cid);
58
59 /*
60 * Strings supported by the _OSI predefined (internal) method.
61 */
62 static const char *acpi_interfaces_supported[] = {
63 /* Operating System Vendor Strings */
64
65 "Linux",
66 "Windows 2000",
67 "Windows 2001",
68 "Windows 2001 SP0",
69 "Windows 2001 SP1",
70 "Windows 2001 SP2",
71 "Windows 2001 SP3",
72 "Windows 2001 SP4",
73 "Windows 2001.1",
74 "Windows 2001.1 SP1", /* Added 03/2006 */
75 "Windows 2006", /* Added 03/2006 */
76
77 /* Feature Group Strings */
78
79 "Extended Address Space Descriptor"
80 /*
81 * All "optional" feature group strings (features that are implemented
82 * by the host) should be implemented in the host version of
83 * acpi_os_validate_interface and should not be added here.
84 */
85 };
86
87 /*******************************************************************************
88 *
89 * FUNCTION: acpi_ut_osi_implementation
90 *
91 * PARAMETERS: walk_state - Current walk state
92 *
93 * RETURN: Status
94 *
95 * DESCRIPTION: Implementation of the _OSI predefined control method
96 *
97 ******************************************************************************/
98
99 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
100 {
101 acpi_status status;
102 union acpi_operand_object *string_desc;
103 union acpi_operand_object *return_desc;
104 acpi_native_uint i;
105
106 ACPI_FUNCTION_TRACE(ut_osi_implementation);
107
108 /* Validate the string input argument */
109
110 string_desc = walk_state->arguments[0].object;
111 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
112 return_ACPI_STATUS(AE_TYPE);
113 }
114
115 /* Create a return object */
116
117 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
118 if (!return_desc) {
119 return_ACPI_STATUS(AE_NO_MEMORY);
120 }
121
122 /* Default return value is SUPPORTED */
123
124 return_desc->integer.value = ACPI_UINT32_MAX;
125 walk_state->return_desc = return_desc;
126
127 /* Compare input string to static table of supported interfaces */
128
129 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
130 if (!ACPI_STRCMP
131 (string_desc->string.pointer,
132 acpi_interfaces_supported[i])) {
133
134 /* The interface is supported */
135
136 return_ACPI_STATUS(AE_CTRL_TERMINATE);
137 }
138 }
139
140 /*
141 * Did not match the string in the static table, call the host OSL to
142 * check for a match with one of the optional strings (such as
143 * "Module Device", "3.0 Thermal Model", etc.)
144 */
145 status = acpi_os_validate_interface(string_desc->string.pointer);
146 if (ACPI_SUCCESS(status)) {
147
148 /* The interface is supported */
149
150 return_ACPI_STATUS(AE_CTRL_TERMINATE);
151 }
152
153 /* The interface is not supported */
154
155 return_desc->integer.value = 0;
156 return_ACPI_STATUS(AE_CTRL_TERMINATE);
157 }
158
159 /*******************************************************************************
160 *
161 * FUNCTION: acpi_ut_evaluate_object
162 *
163 * PARAMETERS: prefix_node - Starting node
164 * Path - Path to object from starting node
165 * expected_return_types - Bitmap of allowed return types
166 * return_desc - Where a return value is stored
167 *
168 * RETURN: Status
169 *
170 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
171 * return object. Common code that simplifies accessing objects
172 * that have required return objects of fixed types.
173 *
174 * NOTE: Internal function, no parameter validation
175 *
176 ******************************************************************************/
177
178 acpi_status
179 acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
180 char *path,
181 u32 expected_return_btypes,
182 union acpi_operand_object **return_desc)
183 {
184 struct acpi_parameter_info info;
185 acpi_status status;
186 u32 return_btype;
187
188 ACPI_FUNCTION_TRACE(ut_evaluate_object);
189
190 info.node = prefix_node;
191 info.parameters = NULL;
192 info.parameter_type = ACPI_PARAM_ARGS;
193
194 /* Evaluate the object/method */
195
196 status = acpi_ns_evaluate_relative(path, &info);
197 if (ACPI_FAILURE(status)) {
198 if (status == AE_NOT_FOUND) {
199 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
200 "[%4.4s.%s] was not found\n",
201 acpi_ut_get_node_name(prefix_node),
202 path));
203 } else {
204 ACPI_ERROR_METHOD("Method execution failed",
205 prefix_node, path, status);
206 }
207
208 return_ACPI_STATUS(status);
209 }
210
211 /* Did we get a return object? */
212
213 if (!info.return_object) {
214 if (expected_return_btypes) {
215 ACPI_ERROR_METHOD("No object was returned from",
216 prefix_node, path, AE_NOT_EXIST);
217
218 return_ACPI_STATUS(AE_NOT_EXIST);
219 }
220
221 return_ACPI_STATUS(AE_OK);
222 }
223
224 /* Map the return object type to the bitmapped type */
225
226 switch (ACPI_GET_OBJECT_TYPE(info.return_object)) {
227 case ACPI_TYPE_INTEGER:
228 return_btype = ACPI_BTYPE_INTEGER;
229 break;
230
231 case ACPI_TYPE_BUFFER:
232 return_btype = ACPI_BTYPE_BUFFER;
233 break;
234
235 case ACPI_TYPE_STRING:
236 return_btype = ACPI_BTYPE_STRING;
237 break;
238
239 case ACPI_TYPE_PACKAGE:
240 return_btype = ACPI_BTYPE_PACKAGE;
241 break;
242
243 default:
244 return_btype = 0;
245 break;
246 }
247
248 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
249 /*
250 * We received a return object, but one was not expected. This can
251 * happen frequently if the "implicit return" feature is enabled.
252 * Just delete the return object and return AE_OK.
253 */
254 acpi_ut_remove_reference(info.return_object);
255 return_ACPI_STATUS(AE_OK);
256 }
257
258 /* Is the return object one of the expected types? */
259
260 if (!(expected_return_btypes & return_btype)) {
261 ACPI_ERROR_METHOD("Return object type is incorrect",
262 prefix_node, path, AE_TYPE);
263
264 ACPI_ERROR((AE_INFO,
265 "Type returned from %s was incorrect: %s, expected Btypes: %X",
266 path,
267 acpi_ut_get_object_type_name(info.return_object),
268 expected_return_btypes));
269
270 /* On error exit, we must delete the return object */
271
272 acpi_ut_remove_reference(info.return_object);
273 return_ACPI_STATUS(AE_TYPE);
274 }
275
276 /* Object type is OK, return it */
277
278 *return_desc = info.return_object;
279 return_ACPI_STATUS(AE_OK);
280 }
281
282 /*******************************************************************************
283 *
284 * FUNCTION: acpi_ut_evaluate_numeric_object
285 *
286 * PARAMETERS: object_name - Object name to be evaluated
287 * device_node - Node for the device
288 * Address - Where the value is returned
289 *
290 * RETURN: Status
291 *
292 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
293 * and stores result in *Address.
294 *
295 * NOTE: Internal function, no parameter validation
296 *
297 ******************************************************************************/
298
299 acpi_status
300 acpi_ut_evaluate_numeric_object(char *object_name,
301 struct acpi_namespace_node *device_node,
302 acpi_integer * address)
303 {
304 union acpi_operand_object *obj_desc;
305 acpi_status status;
306
307 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
308
309 status = acpi_ut_evaluate_object(device_node, object_name,
310 ACPI_BTYPE_INTEGER, &obj_desc);
311 if (ACPI_FAILURE(status)) {
312 return_ACPI_STATUS(status);
313 }
314
315 /* Get the returned Integer */
316
317 *address = obj_desc->integer.value;
318
319 /* On exit, we must delete the return object */
320
321 acpi_ut_remove_reference(obj_desc);
322 return_ACPI_STATUS(status);
323 }
324
325 /*******************************************************************************
326 *
327 * FUNCTION: acpi_ut_copy_id_string
328 *
329 * PARAMETERS: Destination - Where to copy the string
330 * Source - Source string
331 * max_length - Length of the destination buffer
332 *
333 * RETURN: None
334 *
335 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
336 * Performs removal of a leading asterisk if present -- workaround
337 * for a known issue on a bunch of machines.
338 *
339 ******************************************************************************/
340
341 static void
342 acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
343 {
344
345 /*
346 * Workaround for ID strings that have a leading asterisk. This construct
347 * is not allowed by the ACPI specification (ID strings must be
348 * alphanumeric), but enough existing machines have this embedded in their
349 * ID strings that the following code is useful.
350 */
351 if (*source == '*') {
352 source++;
353 }
354
355 /* Do the actual copy */
356
357 ACPI_STRNCPY(destination, source, max_length);
358 }
359
360 /*******************************************************************************
361 *
362 * FUNCTION: acpi_ut_execute_HID
363 *
364 * PARAMETERS: device_node - Node for the device
365 * Hid - Where the HID is returned
366 *
367 * RETURN: Status
368 *
369 * DESCRIPTION: Executes the _HID control method that returns the hardware
370 * ID of the device.
371 *
372 * NOTE: Internal function, no parameter validation
373 *
374 ******************************************************************************/
375
376 acpi_status
377 acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
378 struct acpi_device_id *hid)
379 {
380 union acpi_operand_object *obj_desc;
381 acpi_status status;
382
383 ACPI_FUNCTION_TRACE(ut_execute_HID);
384
385 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
386 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
387 &obj_desc);
388 if (ACPI_FAILURE(status)) {
389 return_ACPI_STATUS(status);
390 }
391
392 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
393
394 /* Convert the Numeric HID to string */
395
396 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
397 hid->value);
398 } else {
399 /* Copy the String HID from the returned object */
400
401 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
402 sizeof(hid->value));
403 }
404
405 /* On exit, we must delete the return object */
406
407 acpi_ut_remove_reference(obj_desc);
408 return_ACPI_STATUS(status);
409 }
410
411 /*******************************************************************************
412 *
413 * FUNCTION: acpi_ut_translate_one_cid
414 *
415 * PARAMETERS: obj_desc - _CID object, must be integer or string
416 * one_cid - Where the CID string is returned
417 *
418 * RETURN: Status
419 *
420 * DESCRIPTION: Return a numeric or string _CID value as a string.
421 * (Compatible ID)
422 *
423 * NOTE: Assumes a maximum _CID string length of
424 * ACPI_MAX_CID_LENGTH.
425 *
426 ******************************************************************************/
427
428 static acpi_status
429 acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
430 struct acpi_compatible_id *one_cid)
431 {
432
433 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
434 case ACPI_TYPE_INTEGER:
435
436 /* Convert the Numeric CID to string */
437
438 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
439 one_cid->value);
440 return (AE_OK);
441
442 case ACPI_TYPE_STRING:
443
444 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
445 return (AE_AML_STRING_LIMIT);
446 }
447
448 /* Copy the String CID from the returned object */
449
450 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
451 ACPI_MAX_CID_LENGTH);
452 return (AE_OK);
453
454 default:
455
456 return (AE_TYPE);
457 }
458 }
459
460 /*******************************************************************************
461 *
462 * FUNCTION: acpi_ut_execute_CID
463 *
464 * PARAMETERS: device_node - Node for the device
465 * return_cid_list - Where the CID list is returned
466 *
467 * RETURN: Status
468 *
469 * DESCRIPTION: Executes the _CID control method that returns one or more
470 * compatible hardware IDs for the device.
471 *
472 * NOTE: Internal function, no parameter validation
473 *
474 ******************************************************************************/
475
476 acpi_status
477 acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
478 struct acpi_compatible_id_list ** return_cid_list)
479 {
480 union acpi_operand_object *obj_desc;
481 acpi_status status;
482 u32 count;
483 u32 size;
484 struct acpi_compatible_id_list *cid_list;
485 acpi_native_uint i;
486
487 ACPI_FUNCTION_TRACE(ut_execute_CID);
488
489 /* Evaluate the _CID method for this device */
490
491 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
492 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
493 | ACPI_BTYPE_PACKAGE, &obj_desc);
494 if (ACPI_FAILURE(status)) {
495 return_ACPI_STATUS(status);
496 }
497
498 /* Get the number of _CIDs returned */
499
500 count = 1;
501 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
502 count = obj_desc->package.count;
503 }
504
505 /* Allocate a worst-case buffer for the _CIDs */
506
507 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
508 sizeof(struct acpi_compatible_id_list));
509
510 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
511 if (!cid_list) {
512 return_ACPI_STATUS(AE_NO_MEMORY);
513 }
514
515 /* Init CID list */
516
517 cid_list->count = count;
518 cid_list->size = size;
519
520 /*
521 * A _CID can return either a single compatible ID or a package of
522 * compatible IDs. Each compatible ID can be one of the following:
523 * 1) Integer (32 bit compressed EISA ID) or
524 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
525 */
526
527 /* The _CID object can be either a single CID or a package (list) of CIDs */
528
529 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
530
531 /* Translate each package element */
532
533 for (i = 0; i < count; i++) {
534 status =
535 acpi_ut_translate_one_cid(obj_desc->package.
536 elements[i],
537 &cid_list->id[i]);
538 if (ACPI_FAILURE(status)) {
539 break;
540 }
541 }
542 } else {
543 /* Only one CID, translate to a string */
544
545 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
546 }
547
548 /* Cleanup on error */
549
550 if (ACPI_FAILURE(status)) {
551 ACPI_FREE(cid_list);
552 } else {
553 *return_cid_list = cid_list;
554 }
555
556 /* On exit, we must delete the _CID return object */
557
558 acpi_ut_remove_reference(obj_desc);
559 return_ACPI_STATUS(status);
560 }
561
562 /*******************************************************************************
563 *
564 * FUNCTION: acpi_ut_execute_UID
565 *
566 * PARAMETERS: device_node - Node for the device
567 * Uid - Where the UID is returned
568 *
569 * RETURN: Status
570 *
571 * DESCRIPTION: Executes the _UID control method that returns the hardware
572 * ID of the device.
573 *
574 * NOTE: Internal function, no parameter validation
575 *
576 ******************************************************************************/
577
578 acpi_status
579 acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
580 struct acpi_device_id *uid)
581 {
582 union acpi_operand_object *obj_desc;
583 acpi_status status;
584
585 ACPI_FUNCTION_TRACE(ut_execute_UID);
586
587 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
588 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
589 &obj_desc);
590 if (ACPI_FAILURE(status)) {
591 return_ACPI_STATUS(status);
592 }
593
594 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
595
596 /* Convert the Numeric UID to string */
597
598 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
599 uid->value);
600 } else {
601 /* Copy the String UID from the returned object */
602
603 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
604 sizeof(uid->value));
605 }
606
607 /* On exit, we must delete the return object */
608
609 acpi_ut_remove_reference(obj_desc);
610 return_ACPI_STATUS(status);
611 }
612
613 /*******************************************************************************
614 *
615 * FUNCTION: acpi_ut_execute_STA
616 *
617 * PARAMETERS: device_node - Node for the device
618 * Flags - Where the status flags are returned
619 *
620 * RETURN: Status
621 *
622 * DESCRIPTION: Executes _STA for selected device and stores results in
623 * *Flags.
624 *
625 * NOTE: Internal function, no parameter validation
626 *
627 ******************************************************************************/
628
629 acpi_status
630 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
631 {
632 union acpi_operand_object *obj_desc;
633 acpi_status status;
634
635 ACPI_FUNCTION_TRACE(ut_execute_STA);
636
637 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
638 ACPI_BTYPE_INTEGER, &obj_desc);
639 if (ACPI_FAILURE(status)) {
640 if (AE_NOT_FOUND == status) {
641 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
642 "_STA on %4.4s was not found, assuming device is present\n",
643 acpi_ut_get_node_name(device_node)));
644
645 *flags = ACPI_UINT32_MAX;
646 status = AE_OK;
647 }
648
649 return_ACPI_STATUS(status);
650 }
651
652 /* Extract the status flags */
653
654 *flags = (u32) obj_desc->integer.value;
655
656 /* On exit, we must delete the return object */
657
658 acpi_ut_remove_reference(obj_desc);
659 return_ACPI_STATUS(status);
660 }
661
662 /*******************************************************************************
663 *
664 * FUNCTION: acpi_ut_execute_Sxds
665 *
666 * PARAMETERS: device_node - Node for the device
667 * Flags - Where the status flags are returned
668 *
669 * RETURN: Status
670 *
671 * DESCRIPTION: Executes _STA for selected device and stores results in
672 * *Flags.
673 *
674 * NOTE: Internal function, no parameter validation
675 *
676 ******************************************************************************/
677
678 acpi_status
679 acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
680 {
681 union acpi_operand_object *obj_desc;
682 acpi_status status;
683 u32 i;
684
685 ACPI_FUNCTION_TRACE(ut_execute_sxds);
686
687 for (i = 0; i < 4; i++) {
688 highest[i] = 0xFF;
689 status = acpi_ut_evaluate_object(device_node,
690 ACPI_CAST_PTR(char,
691 acpi_gbl_highest_dstate_names
692 [i]),
693 ACPI_BTYPE_INTEGER, &obj_desc);
694 if (ACPI_FAILURE(status)) {
695 if (status != AE_NOT_FOUND) {
696 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
697 "%s on Device %4.4s, %s\n",
698 ACPI_CAST_PTR(char,
699 acpi_gbl_highest_dstate_names
700 [i]),
701 acpi_ut_get_node_name
702 (device_node),
703 acpi_format_exception
704 (status)));
705
706 return_ACPI_STATUS(status);
707 }
708 } else {
709 /* Extract the Dstate value */
710
711 highest[i] = (u8) obj_desc->integer.value;
712
713 /* Delete the return object */
714
715 acpi_ut_remove_reference(obj_desc);
716 }
717 }
718
719 return_ACPI_STATUS(AE_OK);
720 }