1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2008, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
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.
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.
44 #include <acpi/acpi.h>
45 #include <acpi/acnamesp.h>
46 #include <acpi/acinterp.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("uteval")
51 /* Local prototypes */
53 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
);
56 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
57 struct acpi_compatible_id
*one_cid
);
60 * Strings supported by the _OSI predefined (internal) method.
62 static char *acpi_interfaces_supported
[] = {
63 /* Operating System Vendor Strings */
65 "Windows 2000", /* Windows 2000 */
66 "Windows 2001", /* Windows XP */
67 "Windows 2001 SP1", /* Windows XP SP1 */
68 "Windows 2001 SP2", /* Windows XP SP2 */
69 "Windows 2001.1", /* Windows Server 2003 */
70 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */
71 "Windows 2006", /* Windows Vista - Added 03/2006 */
73 /* Feature Group Strings */
75 "Extended Address Space Descriptor"
77 * All "optional" feature group strings (features that are implemented
78 * by the host) should be implemented in the host version of
79 * acpi_os_validate_interface and should not be added here.
83 /*******************************************************************************
85 * FUNCTION: acpi_ut_osi_implementation
87 * PARAMETERS: walk_state - Current walk state
91 * DESCRIPTION: Implementation of the _OSI predefined control method
93 ******************************************************************************/
95 acpi_status
acpi_ut_osi_implementation(struct acpi_walk_state
*walk_state
)
98 union acpi_operand_object
*string_desc
;
99 union acpi_operand_object
*return_desc
;
102 ACPI_FUNCTION_TRACE(ut_osi_implementation
);
104 /* Validate the string input argument */
106 string_desc
= walk_state
->arguments
[0].object
;
107 if (!string_desc
|| (string_desc
->common
.type
!= ACPI_TYPE_STRING
)) {
108 return_ACPI_STATUS(AE_TYPE
);
111 /* Create a return object */
113 return_desc
= acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
115 return_ACPI_STATUS(AE_NO_MEMORY
);
118 /* Default return value is SUPPORTED */
120 return_desc
->integer
.value
= ACPI_UINT32_MAX
;
121 walk_state
->return_desc
= return_desc
;
123 /* Compare input string to static table of supported interfaces */
125 for (i
= 0; i
< ACPI_ARRAY_LENGTH(acpi_interfaces_supported
); i
++) {
127 (string_desc
->string
.pointer
,
128 acpi_interfaces_supported
[i
])) {
130 /* The interface is supported */
132 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
137 * Did not match the string in the static table, call the host OSL to
138 * check for a match with one of the optional strings (such as
139 * "Module Device", "3.0 Thermal Model", etc.)
141 status
= acpi_os_validate_interface(string_desc
->string
.pointer
);
142 if (ACPI_SUCCESS(status
)) {
144 /* The interface is supported */
146 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
149 /* The interface is not supported */
151 return_desc
->integer
.value
= 0;
152 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
155 /*******************************************************************************
157 * FUNCTION: acpi_osi_invalidate
159 * PARAMETERS: interface_string
163 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
165 ******************************************************************************/
167 acpi_status
acpi_osi_invalidate(char *interface
)
171 for (i
= 0; i
< ACPI_ARRAY_LENGTH(acpi_interfaces_supported
); i
++) {
172 if (!ACPI_STRCMP(interface
, acpi_interfaces_supported
[i
])) {
173 *acpi_interfaces_supported
[i
] = '\0';
180 /*******************************************************************************
182 * FUNCTION: acpi_ut_evaluate_object
184 * PARAMETERS: prefix_node - Starting node
185 * Path - Path to object from starting node
186 * expected_return_types - Bitmap of allowed return types
187 * return_desc - Where a return value is stored
191 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
192 * return object. Common code that simplifies accessing objects
193 * that have required return objects of fixed types.
195 * NOTE: Internal function, no parameter validation
197 ******************************************************************************/
200 acpi_ut_evaluate_object(struct acpi_namespace_node
*prefix_node
,
202 u32 expected_return_btypes
,
203 union acpi_operand_object
**return_desc
)
205 struct acpi_evaluate_info
*info
;
209 ACPI_FUNCTION_TRACE(ut_evaluate_object
);
211 /* Allocate the evaluation information block */
213 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
215 return_ACPI_STATUS(AE_NO_MEMORY
);
218 info
->prefix_node
= prefix_node
;
219 info
->pathname
= path
;
221 /* Evaluate the object/method */
223 status
= acpi_ns_evaluate(info
);
224 if (ACPI_FAILURE(status
)) {
225 if (status
== AE_NOT_FOUND
) {
226 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
227 "[%4.4s.%s] was not found\n",
228 acpi_ut_get_node_name(prefix_node
),
231 ACPI_ERROR_METHOD("Method execution failed",
232 prefix_node
, path
, status
);
238 /* Did we get a return object? */
240 if (!info
->return_object
) {
241 if (expected_return_btypes
) {
242 ACPI_ERROR_METHOD("No object was returned from",
243 prefix_node
, path
, AE_NOT_EXIST
);
245 status
= AE_NOT_EXIST
;
251 /* Map the return object type to the bitmapped type */
253 switch (ACPI_GET_OBJECT_TYPE(info
->return_object
)) {
254 case ACPI_TYPE_INTEGER
:
255 return_btype
= ACPI_BTYPE_INTEGER
;
258 case ACPI_TYPE_BUFFER
:
259 return_btype
= ACPI_BTYPE_BUFFER
;
262 case ACPI_TYPE_STRING
:
263 return_btype
= ACPI_BTYPE_STRING
;
266 case ACPI_TYPE_PACKAGE
:
267 return_btype
= ACPI_BTYPE_PACKAGE
;
275 if ((acpi_gbl_enable_interpreter_slack
) && (!expected_return_btypes
)) {
277 * We received a return object, but one was not expected. This can
278 * happen frequently if the "implicit return" feature is enabled.
279 * Just delete the return object and return AE_OK.
281 acpi_ut_remove_reference(info
->return_object
);
285 /* Is the return object one of the expected types? */
287 if (!(expected_return_btypes
& return_btype
)) {
288 ACPI_ERROR_METHOD("Return object type is incorrect",
289 prefix_node
, path
, AE_TYPE
);
292 "Type returned from %s was incorrect: %s, expected Btypes: %X",
294 acpi_ut_get_object_type_name(info
->return_object
),
295 expected_return_btypes
));
297 /* On error exit, we must delete the return object */
299 acpi_ut_remove_reference(info
->return_object
);
304 /* Object type is OK, return it */
306 *return_desc
= info
->return_object
;
310 return_ACPI_STATUS(status
);
313 /*******************************************************************************
315 * FUNCTION: acpi_ut_evaluate_numeric_object
317 * PARAMETERS: object_name - Object name to be evaluated
318 * device_node - Node for the device
319 * Address - Where the value is returned
323 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
324 * and stores result in *Address.
326 * NOTE: Internal function, no parameter validation
328 ******************************************************************************/
331 acpi_ut_evaluate_numeric_object(char *object_name
,
332 struct acpi_namespace_node
*device_node
,
333 acpi_integer
* address
)
335 union acpi_operand_object
*obj_desc
;
338 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object
);
340 status
= acpi_ut_evaluate_object(device_node
, object_name
,
341 ACPI_BTYPE_INTEGER
, &obj_desc
);
342 if (ACPI_FAILURE(status
)) {
343 return_ACPI_STATUS(status
);
346 /* Get the returned Integer */
348 *address
= obj_desc
->integer
.value
;
350 /* On exit, we must delete the return object */
352 acpi_ut_remove_reference(obj_desc
);
353 return_ACPI_STATUS(status
);
356 /*******************************************************************************
358 * FUNCTION: acpi_ut_copy_id_string
360 * PARAMETERS: Destination - Where to copy the string
361 * Source - Source string
362 * max_length - Length of the destination buffer
366 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
367 * Performs removal of a leading asterisk if present -- workaround
368 * for a known issue on a bunch of machines.
370 ******************************************************************************/
373 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
)
377 * Workaround for ID strings that have a leading asterisk. This construct
378 * is not allowed by the ACPI specification (ID strings must be
379 * alphanumeric), but enough existing machines have this embedded in their
380 * ID strings that the following code is useful.
382 if (*source
== '*') {
386 /* Do the actual copy */
388 ACPI_STRNCPY(destination
, source
, max_length
);
391 /*******************************************************************************
393 * FUNCTION: acpi_ut_execute_HID
395 * PARAMETERS: device_node - Node for the device
396 * Hid - Where the HID is returned
400 * DESCRIPTION: Executes the _HID control method that returns the hardware
403 * NOTE: Internal function, no parameter validation
405 ******************************************************************************/
408 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
409 struct acpica_device_id
*hid
)
411 union acpi_operand_object
*obj_desc
;
414 ACPI_FUNCTION_TRACE(ut_execute_HID
);
416 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
417 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
419 if (ACPI_FAILURE(status
)) {
420 return_ACPI_STATUS(status
);
423 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
425 /* Convert the Numeric HID to string */
427 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
430 /* Copy the String HID from the returned object */
432 acpi_ut_copy_id_string(hid
->value
, obj_desc
->string
.pointer
,
436 /* On exit, we must delete the return object */
438 acpi_ut_remove_reference(obj_desc
);
439 return_ACPI_STATUS(status
);
442 /*******************************************************************************
444 * FUNCTION: acpi_ut_translate_one_cid
446 * PARAMETERS: obj_desc - _CID object, must be integer or string
447 * one_cid - Where the CID string is returned
451 * DESCRIPTION: Return a numeric or string _CID value as a string.
454 * NOTE: Assumes a maximum _CID string length of
455 * ACPI_MAX_CID_LENGTH.
457 ******************************************************************************/
460 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
461 struct acpi_compatible_id
*one_cid
)
464 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
465 case ACPI_TYPE_INTEGER
:
467 /* Convert the Numeric CID to string */
469 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
473 case ACPI_TYPE_STRING
:
475 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
476 return (AE_AML_STRING_LIMIT
);
479 /* Copy the String CID from the returned object */
481 acpi_ut_copy_id_string(one_cid
->value
, obj_desc
->string
.pointer
,
482 ACPI_MAX_CID_LENGTH
);
491 /*******************************************************************************
493 * FUNCTION: acpi_ut_execute_CID
495 * PARAMETERS: device_node - Node for the device
496 * return_cid_list - Where the CID list is returned
500 * DESCRIPTION: Executes the _CID control method that returns one or more
501 * compatible hardware IDs for the device.
503 * NOTE: Internal function, no parameter validation
505 ******************************************************************************/
508 acpi_ut_execute_CID(struct acpi_namespace_node
* device_node
,
509 struct acpi_compatible_id_list
** return_cid_list
)
511 union acpi_operand_object
*obj_desc
;
515 struct acpi_compatible_id_list
*cid_list
;
518 ACPI_FUNCTION_TRACE(ut_execute_CID
);
520 /* Evaluate the _CID method for this device */
522 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
523 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
524 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
525 if (ACPI_FAILURE(status
)) {
526 return_ACPI_STATUS(status
);
529 /* Get the number of _CIDs returned */
532 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
533 count
= obj_desc
->package
.count
;
536 /* Allocate a worst-case buffer for the _CIDs */
538 size
= (((count
- 1) * sizeof(struct acpi_compatible_id
)) +
539 sizeof(struct acpi_compatible_id_list
));
541 cid_list
= ACPI_ALLOCATE_ZEROED((acpi_size
) size
);
543 return_ACPI_STATUS(AE_NO_MEMORY
);
548 cid_list
->count
= count
;
549 cid_list
->size
= size
;
552 * A _CID can return either a single compatible ID or a package of
553 * compatible IDs. Each compatible ID can be one of the following:
554 * 1) Integer (32 bit compressed EISA ID) or
555 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
558 /* The _CID object can be either a single CID or a package (list) of CIDs */
560 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
562 /* Translate each package element */
564 for (i
= 0; i
< count
; i
++) {
566 acpi_ut_translate_one_cid(obj_desc
->package
.
569 if (ACPI_FAILURE(status
)) {
574 /* Only one CID, translate to a string */
576 status
= acpi_ut_translate_one_cid(obj_desc
, cid_list
->id
);
579 /* Cleanup on error */
581 if (ACPI_FAILURE(status
)) {
584 *return_cid_list
= cid_list
;
587 /* On exit, we must delete the _CID return object */
589 acpi_ut_remove_reference(obj_desc
);
590 return_ACPI_STATUS(status
);
593 /*******************************************************************************
595 * FUNCTION: acpi_ut_execute_UID
597 * PARAMETERS: device_node - Node for the device
598 * Uid - Where the UID is returned
602 * DESCRIPTION: Executes the _UID control method that returns the hardware
605 * NOTE: Internal function, no parameter validation
607 ******************************************************************************/
610 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
611 struct acpica_device_id
*uid
)
613 union acpi_operand_object
*obj_desc
;
616 ACPI_FUNCTION_TRACE(ut_execute_UID
);
618 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
619 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
621 if (ACPI_FAILURE(status
)) {
622 return_ACPI_STATUS(status
);
625 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
627 /* Convert the Numeric UID to string */
629 acpi_ex_unsigned_integer_to_string(obj_desc
->integer
.value
,
632 /* Copy the String UID from the returned object */
634 acpi_ut_copy_id_string(uid
->value
, obj_desc
->string
.pointer
,
638 /* On exit, we must delete the return object */
640 acpi_ut_remove_reference(obj_desc
);
641 return_ACPI_STATUS(status
);
644 /*******************************************************************************
646 * FUNCTION: acpi_ut_execute_STA
648 * PARAMETERS: device_node - Node for the device
649 * Flags - Where the status flags are returned
653 * DESCRIPTION: Executes _STA for selected device and stores results in
656 * NOTE: Internal function, no parameter validation
658 ******************************************************************************/
661 acpi_ut_execute_STA(struct acpi_namespace_node
*device_node
, u32
* flags
)
663 union acpi_operand_object
*obj_desc
;
666 ACPI_FUNCTION_TRACE(ut_execute_STA
);
668 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__STA
,
669 ACPI_BTYPE_INTEGER
, &obj_desc
);
670 if (ACPI_FAILURE(status
)) {
671 if (AE_NOT_FOUND
== status
) {
672 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
673 "_STA on %4.4s was not found, assuming device is present\n",
674 acpi_ut_get_node_name(device_node
)));
676 *flags
= ACPI_UINT32_MAX
;
680 return_ACPI_STATUS(status
);
683 /* Extract the status flags */
685 *flags
= (u32
) obj_desc
->integer
.value
;
687 /* On exit, we must delete the return object */
689 acpi_ut_remove_reference(obj_desc
);
690 return_ACPI_STATUS(status
);
693 /*******************************************************************************
695 * FUNCTION: acpi_ut_execute_Sxds
697 * PARAMETERS: device_node - Node for the device
698 * Flags - Where the status flags are returned
702 * DESCRIPTION: Executes _STA for selected device and stores results in
705 * NOTE: Internal function, no parameter validation
707 ******************************************************************************/
710 acpi_ut_execute_sxds(struct acpi_namespace_node
*device_node
, u8
* highest
)
712 union acpi_operand_object
*obj_desc
;
716 ACPI_FUNCTION_TRACE(ut_execute_sxds
);
718 for (i
= 0; i
< 4; i
++) {
720 status
= acpi_ut_evaluate_object(device_node
,
722 acpi_gbl_highest_dstate_names
724 ACPI_BTYPE_INTEGER
, &obj_desc
);
725 if (ACPI_FAILURE(status
)) {
726 if (status
!= AE_NOT_FOUND
) {
727 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
728 "%s on Device %4.4s, %s\n",
730 acpi_gbl_highest_dstate_names
732 acpi_ut_get_node_name
734 acpi_format_exception
737 return_ACPI_STATUS(status
);
740 /* Extract the Dstate value */
742 highest
[i
] = (u8
) obj_desc
->integer
.value
;
744 /* Delete the return object */
746 acpi_ut_remove_reference(obj_desc
);
750 return_ACPI_STATUS(AE_OK
);