MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / acpi / utilities / uteval.c
blob0aa1fde7ec49aa74a63ce786f148d3775a19ac48
1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2004, R. Byron Moore
9 * All rights reserved.
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.
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.
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.
45 #include <acpi/acpi.h>
46 #include <acpi/acnamesp.h>
47 #include <acpi/acinterp.h>
50 #define _COMPONENT ACPI_UTILITIES
51 ACPI_MODULE_NAME ("uteval")
54 /*******************************************************************************
56 * FUNCTION: acpi_ut_osi_implementation
58 * PARAMETERS: walk_state - Current walk state
60 * RETURN: Status
62 * DESCRIPTION: Implementation of _OSI predefined control method
63 * Supported = _OSI (String)
65 ******************************************************************************/
67 acpi_status
68 acpi_ut_osi_implementation (
69 struct acpi_walk_state *walk_state)
71 union acpi_operand_object *string_desc;
72 union acpi_operand_object *return_desc;
73 acpi_native_uint i;
76 ACPI_FUNCTION_TRACE ("ut_osi_implementation");
79 /* Validate the string input argument */
81 string_desc = walk_state->arguments[0].object;
82 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
83 return_ACPI_STATUS (AE_TYPE);
86 /* Create a return object (Default value = 0) */
88 return_desc = acpi_ut_create_internal_object (ACPI_TYPE_INTEGER);
89 if (!return_desc) {
90 return_ACPI_STATUS (AE_NO_MEMORY);
93 /* Compare input string to table of supported strings */
95 for (i = 0; i < ACPI_NUM_OSI_STRINGS; i++) {
96 if (!ACPI_STRCMP (string_desc->string.pointer,
97 (char *) acpi_gbl_valid_osi_strings[i])) {
98 /* This string is supported */
100 return_desc->integer.value = 0xFFFFFFFF;
101 break;
105 walk_state->return_desc = return_desc;
106 return_ACPI_STATUS (AE_CTRL_TERMINATE);
110 /*******************************************************************************
112 * FUNCTION: acpi_ut_evaluate_object
114 * PARAMETERS: prefix_node - Starting node
115 * Path - Path to object from starting node
116 * expected_return_types - Bitmap of allowed return types
117 * return_desc - Where a return value is stored
119 * RETURN: Status
121 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
122 * return object. Common code that simplifies accessing objects
123 * that have required return objects of fixed types.
125 * NOTE: Internal function, no parameter validation
127 ******************************************************************************/
129 acpi_status
130 acpi_ut_evaluate_object (
131 struct acpi_namespace_node *prefix_node,
132 char *path,
133 u32 expected_return_btypes,
134 union acpi_operand_object **return_desc)
136 struct acpi_parameter_info info;
137 acpi_status status;
138 u32 return_btype;
141 ACPI_FUNCTION_TRACE ("ut_evaluate_object");
144 info.node = prefix_node;
145 info.parameters = NULL;
146 info.parameter_type = ACPI_PARAM_ARGS;
148 /* Evaluate the object/method */
150 status = acpi_ns_evaluate_relative (path, &info);
151 if (ACPI_FAILURE (status)) {
152 if (status == AE_NOT_FOUND) {
153 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
154 acpi_ut_get_node_name (prefix_node), path));
156 else {
157 ACPI_REPORT_METHOD_ERROR ("Method execution failed",
158 prefix_node, path, status);
161 return_ACPI_STATUS (status);
164 /* Did we get a return object? */
166 if (!info.return_object) {
167 if (expected_return_btypes) {
168 ACPI_REPORT_METHOD_ERROR ("No object was returned from",
169 prefix_node, path, AE_NOT_EXIST);
171 return_ACPI_STATUS (AE_NOT_EXIST);
174 return_ACPI_STATUS (AE_OK);
177 /* Map the return object type to the bitmapped type */
179 switch (ACPI_GET_OBJECT_TYPE (info.return_object)) {
180 case ACPI_TYPE_INTEGER:
181 return_btype = ACPI_BTYPE_INTEGER;
182 break;
184 case ACPI_TYPE_BUFFER:
185 return_btype = ACPI_BTYPE_BUFFER;
186 break;
188 case ACPI_TYPE_STRING:
189 return_btype = ACPI_BTYPE_STRING;
190 break;
192 case ACPI_TYPE_PACKAGE:
193 return_btype = ACPI_BTYPE_PACKAGE;
194 break;
196 default:
197 return_btype = 0;
198 break;
201 /* Is the return object one of the expected types? */
203 if (!(expected_return_btypes & return_btype)) {
204 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
205 prefix_node, path, AE_TYPE);
207 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
208 "Type returned from %s was incorrect: %X\n",
209 path, ACPI_GET_OBJECT_TYPE (info.return_object)));
211 /* On error exit, we must delete the return object */
213 acpi_ut_remove_reference (info.return_object);
214 return_ACPI_STATUS (AE_TYPE);
217 /* Object type is OK, return it */
219 *return_desc = info.return_object;
220 return_ACPI_STATUS (AE_OK);
224 /*******************************************************************************
226 * FUNCTION: acpi_ut_evaluate_numeric_object
228 * PARAMETERS: *object_name - Object name to be evaluated
229 * device_node - Node for the device
230 * *Address - Where the value is returned
232 * RETURN: Status
234 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
235 * and stores result in *Address.
237 * NOTE: Internal function, no parameter validation
239 ******************************************************************************/
241 acpi_status
242 acpi_ut_evaluate_numeric_object (
243 char *object_name,
244 struct acpi_namespace_node *device_node,
245 acpi_integer *address)
247 union acpi_operand_object *obj_desc;
248 acpi_status status;
251 ACPI_FUNCTION_TRACE ("ut_evaluate_numeric_object");
254 status = acpi_ut_evaluate_object (device_node, object_name,
255 ACPI_BTYPE_INTEGER, &obj_desc);
256 if (ACPI_FAILURE (status)) {
257 return_ACPI_STATUS (status);
260 /* Get the returned Integer */
262 *address = obj_desc->integer.value;
264 /* On exit, we must delete the return object */
266 acpi_ut_remove_reference (obj_desc);
267 return_ACPI_STATUS (status);
271 /*******************************************************************************
273 * FUNCTION: acpi_ut_copy_id_string
275 * PARAMETERS: Destination - Where to copy the string
276 * Source - Source string
277 * max_length - Length of the destination buffer
279 * RETURN: None
281 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
282 * Performs removal of a leading asterisk if present -- workaround
283 * for a known issue on a bunch of machines.
285 ******************************************************************************/
287 static void
288 acpi_ut_copy_id_string (
289 char *destination,
290 char *source,
291 acpi_size max_length)
296 * Workaround for ID strings that have a leading asterisk. This construct
297 * is not allowed by the ACPI specification (ID strings must be
298 * alphanumeric), but enough existing machines have this embedded in their
299 * ID strings that the following code is useful.
301 if (*source == '*') {
302 source++;
305 /* Do the actual copy */
307 ACPI_STRNCPY (destination, source, max_length);
311 /*******************************************************************************
313 * FUNCTION: acpi_ut_execute_HID
315 * PARAMETERS: device_node - Node for the device
316 * *Hid - Where the HID is returned
318 * RETURN: Status
320 * DESCRIPTION: Executes the _HID control method that returns the hardware
321 * ID of the device.
323 * NOTE: Internal function, no parameter validation
325 ******************************************************************************/
327 acpi_status
328 acpi_ut_execute_HID (
329 struct acpi_namespace_node *device_node,
330 struct acpi_device_id *hid)
332 union acpi_operand_object *obj_desc;
333 acpi_status status;
336 ACPI_FUNCTION_TRACE ("ut_execute_HID");
339 status = acpi_ut_evaluate_object (device_node, METHOD_NAME__HID,
340 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &obj_desc);
341 if (ACPI_FAILURE (status)) {
342 return_ACPI_STATUS (status);
345 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
346 /* Convert the Numeric HID to string */
348 acpi_ex_eisa_id_to_string ((u32) obj_desc->integer.value, hid->value);
350 else {
351 /* Copy the String HID from the returned object */
353 acpi_ut_copy_id_string (hid->value, obj_desc->string.pointer,
354 sizeof (hid->value));
357 /* On exit, we must delete the return object */
359 acpi_ut_remove_reference (obj_desc);
360 return_ACPI_STATUS (status);
364 /*******************************************************************************
366 * FUNCTION: acpi_ut_translate_one_cid
368 * PARAMETERS: obj_desc - _CID object, must be integer or string
369 * one_cid - Where the CID string is returned
371 * RETURN: Status
373 * DESCRIPTION: Return a numeric or string _CID value as a string.
374 * (Compatible ID)
376 * NOTE: Assumes a maximum _CID string length of
377 * ACPI_MAX_CID_LENGTH.
379 ******************************************************************************/
381 static acpi_status
382 acpi_ut_translate_one_cid (
383 union acpi_operand_object *obj_desc,
384 struct acpi_compatible_id *one_cid)
388 switch (ACPI_GET_OBJECT_TYPE (obj_desc)) {
389 case ACPI_TYPE_INTEGER:
391 /* Convert the Numeric CID to string */
393 acpi_ex_eisa_id_to_string ((u32) obj_desc->integer.value, one_cid->value);
394 return (AE_OK);
396 case ACPI_TYPE_STRING:
398 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
399 return (AE_AML_STRING_LIMIT);
402 /* Copy the String CID from the returned object */
404 acpi_ut_copy_id_string (one_cid->value, obj_desc->string.pointer,
405 ACPI_MAX_CID_LENGTH);
406 return (AE_OK);
408 default:
410 return (AE_TYPE);
415 /*******************************************************************************
417 * FUNCTION: acpi_ut_execute_CID
419 * PARAMETERS: device_node - Node for the device
420 * *Cid - Where the CID is returned
422 * RETURN: Status
424 * DESCRIPTION: Executes the _CID control method that returns one or more
425 * compatible hardware IDs for the device.
427 * NOTE: Internal function, no parameter validation
429 ******************************************************************************/
431 acpi_status
432 acpi_ut_execute_CID (
433 struct acpi_namespace_node *device_node,
434 struct acpi_compatible_id_list **return_cid_list)
436 union acpi_operand_object *obj_desc;
437 acpi_status status;
438 u32 count;
439 u32 size;
440 struct acpi_compatible_id_list *cid_list;
441 acpi_native_uint i;
444 ACPI_FUNCTION_TRACE ("ut_execute_CID");
447 /* Evaluate the _CID method for this device */
449 status = acpi_ut_evaluate_object (device_node, METHOD_NAME__CID,
450 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
451 &obj_desc);
452 if (ACPI_FAILURE (status)) {
453 return_ACPI_STATUS (status);
456 /* Get the number of _CIDs returned */
458 count = 1;
459 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
460 count = obj_desc->package.count;
463 /* Allocate a worst-case buffer for the _CIDs */
465 size = (((count - 1) * sizeof (struct acpi_compatible_id)) +
466 sizeof (struct acpi_compatible_id_list));
468 cid_list = ACPI_MEM_CALLOCATE ((acpi_size) size);
469 if (!cid_list) {
470 return_ACPI_STATUS (AE_NO_MEMORY);
473 /* Init CID list */
475 cid_list->count = count;
476 cid_list->size = size;
479 * A _CID can return either a single compatible ID or a package of compatible
480 * IDs. Each compatible ID can be one of the following:
481 * -- Number (32 bit compressed EISA ID) or
482 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss").
485 /* The _CID object can be either a single CID or a package (list) of CIDs */
487 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_PACKAGE) {
488 /* Translate each package element */
490 for (i = 0; i < count; i++) {
491 status = acpi_ut_translate_one_cid (obj_desc->package.elements[i],
492 &cid_list->id[i]);
493 if (ACPI_FAILURE (status)) {
494 break;
498 else {
499 /* Only one CID, translate to a string */
501 status = acpi_ut_translate_one_cid (obj_desc, cid_list->id);
504 /* Cleanup on error */
506 if (ACPI_FAILURE (status)) {
507 ACPI_MEM_FREE (cid_list);
509 else {
510 *return_cid_list = cid_list;
513 /* On exit, we must delete the _CID return object */
515 acpi_ut_remove_reference (obj_desc);
516 return_ACPI_STATUS (status);
520 /*******************************************************************************
522 * FUNCTION: acpi_ut_execute_UID
524 * PARAMETERS: device_node - Node for the device
525 * *Uid - Where the UID is returned
527 * RETURN: Status
529 * DESCRIPTION: Executes the _UID control method that returns the hardware
530 * ID of the device.
532 * NOTE: Internal function, no parameter validation
534 ******************************************************************************/
536 acpi_status
537 acpi_ut_execute_UID (
538 struct acpi_namespace_node *device_node,
539 struct acpi_device_id *uid)
541 union acpi_operand_object *obj_desc;
542 acpi_status status;
545 ACPI_FUNCTION_TRACE ("ut_execute_UID");
548 status = acpi_ut_evaluate_object (device_node, METHOD_NAME__UID,
549 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &obj_desc);
550 if (ACPI_FAILURE (status)) {
551 return_ACPI_STATUS (status);
554 if (ACPI_GET_OBJECT_TYPE (obj_desc) == ACPI_TYPE_INTEGER) {
555 /* Convert the Numeric UID to string */
557 acpi_ex_unsigned_integer_to_string (obj_desc->integer.value, uid->value);
559 else {
560 /* Copy the String UID from the returned object */
562 acpi_ut_copy_id_string (uid->value, obj_desc->string.pointer,
563 sizeof (uid->value));
566 /* On exit, we must delete the return object */
568 acpi_ut_remove_reference (obj_desc);
569 return_ACPI_STATUS (status);
573 /*******************************************************************************
575 * FUNCTION: acpi_ut_execute_STA
577 * PARAMETERS: device_node - Node for the device
578 * *Flags - Where the status flags are returned
580 * RETURN: Status
582 * DESCRIPTION: Executes _STA for selected device and stores results in
583 * *Flags.
585 * NOTE: Internal function, no parameter validation
587 ******************************************************************************/
589 acpi_status
590 acpi_ut_execute_STA (
591 struct acpi_namespace_node *device_node,
592 u32 *flags)
594 union acpi_operand_object *obj_desc;
595 acpi_status status;
598 ACPI_FUNCTION_TRACE ("ut_execute_STA");
601 status = acpi_ut_evaluate_object (device_node, METHOD_NAME__STA,
602 ACPI_BTYPE_INTEGER, &obj_desc);
603 if (ACPI_FAILURE (status)) {
604 if (AE_NOT_FOUND == status) {
605 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
606 "_STA on %4.4s was not found, assuming device is present\n",
607 acpi_ut_get_node_name (device_node)));
609 *flags = 0x0F;
610 status = AE_OK;
613 return_ACPI_STATUS (status);
616 /* Extract the status flags */
618 *flags = (u32) obj_desc->integer.value;
620 /* On exit, we must delete the return object */
622 acpi_ut_remove_reference (obj_desc);
623 return_ACPI_STATUS (status);
627 /*******************************************************************************
629 * FUNCTION: acpi_ut_execute_Sxds
631 * PARAMETERS: device_node - Node for the device
632 * *Flags - Where the status flags are returned
634 * RETURN: Status
636 * DESCRIPTION: Executes _STA for selected device and stores results in
637 * *Flags.
639 * NOTE: Internal function, no parameter validation
641 ******************************************************************************/
643 acpi_status
644 acpi_ut_execute_sxds (
645 struct acpi_namespace_node *device_node,
646 u8 *highest)
648 union acpi_operand_object *obj_desc;
649 acpi_status status;
650 u32 i;
653 ACPI_FUNCTION_TRACE ("ut_execute_Sxds");
656 for (i = 0; i < 4; i++) {
657 highest[i] = 0xFF;
658 status = acpi_ut_evaluate_object (device_node,
659 (char *) acpi_gbl_highest_dstate_names[i],
660 ACPI_BTYPE_INTEGER, &obj_desc);
661 if (ACPI_FAILURE (status)) {
662 if (status != AE_NOT_FOUND) {
663 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
664 "%s on Device %4.4s, %s\n",
665 (char *) acpi_gbl_highest_dstate_names[i],
666 acpi_ut_get_node_name (device_node),
667 acpi_format_exception (status)));
669 return_ACPI_STATUS (status);
672 else {
673 /* Extract the Dstate value */
675 highest[i] = (u8) obj_desc->integer.value;
677 /* Delete the return object */
679 acpi_ut_remove_reference (obj_desc);
683 return_ACPI_STATUS (AE_OK);