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>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME("uteval")
52 /* Local prototypes */
54 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
);
57 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
58 struct acpi_compatible_id
*one_cid
);
61 * Strings supported by the _OSI predefined (internal) method.
63 static char *acpi_interfaces_supported
[] = {
64 /* Operating System Vendor Strings */
66 "Windows 2000", /* Windows 2000 */
67 "Windows 2001", /* Windows XP */
68 "Windows 2001 SP1", /* Windows XP SP1 */
69 "Windows 2001 SP2", /* Windows XP SP2 */
70 "Windows 2001.1", /* Windows Server 2003 */
71 "Windows 2001.1 SP1", /* Windows Server 2003 SP1 - Added 03/2006 */
72 "Windows 2006", /* Windows Vista - Added 03/2006 */
74 /* Feature Group Strings */
76 "Extended Address Space Descriptor"
78 * All "optional" feature group strings (features that are implemented
79 * by the host) should be implemented in the host version of
80 * acpi_os_validate_interface and should not be added here.
84 /*******************************************************************************
86 * FUNCTION: acpi_ut_osi_implementation
88 * PARAMETERS: walk_state - Current walk state
92 * DESCRIPTION: Implementation of the _OSI predefined control method
94 ******************************************************************************/
96 acpi_status
acpi_ut_osi_implementation(struct acpi_walk_state
*walk_state
)
99 union acpi_operand_object
*string_desc
;
100 union acpi_operand_object
*return_desc
;
103 ACPI_FUNCTION_TRACE(ut_osi_implementation
);
105 /* Validate the string input argument */
107 string_desc
= walk_state
->arguments
[0].object
;
108 if (!string_desc
|| (string_desc
->common
.type
!= ACPI_TYPE_STRING
)) {
109 return_ACPI_STATUS(AE_TYPE
);
112 /* Create a return object */
114 return_desc
= acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
116 return_ACPI_STATUS(AE_NO_MEMORY
);
119 /* Default return value is 0, NOT-SUPPORTED */
121 return_desc
->integer
.value
= 0;
122 walk_state
->return_desc
= return_desc
;
124 /* Compare input string to static table of supported interfaces */
126 for (i
= 0; i
< ACPI_ARRAY_LENGTH(acpi_interfaces_supported
); i
++) {
128 (string_desc
->string
.pointer
,
129 acpi_interfaces_supported
[i
])) {
130 return_desc
->integer
.value
= ACPI_UINT32_MAX
;
136 * Did not match the string in the static table, call the host OSL to
137 * check for a match with one of the optional strings (such as
138 * "Module Device", "3.0 Thermal Model", etc.)
140 status
= acpi_os_validate_interface(string_desc
->string
.pointer
);
141 if (ACPI_SUCCESS(status
)) {
142 return_desc
->integer
.value
= ACPI_UINT32_MAX
;
146 ACPI_DEBUG_PRINT_RAW((ACPI_DB_INFO
, "ACPI: BIOS _OSI(%s) %ssupported\n",
147 string_desc
->string
.pointer
,
148 return_desc
->integer
.value
== 0 ? "not-" : ""));
150 return_ACPI_STATUS(AE_OK
);
153 /*******************************************************************************
155 * FUNCTION: acpi_osi_invalidate
157 * PARAMETERS: interface_string
161 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
163 ******************************************************************************/
165 acpi_status
acpi_osi_invalidate(char *interface
)
169 for (i
= 0; i
< ACPI_ARRAY_LENGTH(acpi_interfaces_supported
); i
++) {
170 if (!ACPI_STRCMP(interface
, acpi_interfaces_supported
[i
])) {
171 *acpi_interfaces_supported
[i
] = '\0';
178 /*******************************************************************************
180 * FUNCTION: acpi_ut_evaluate_object
182 * PARAMETERS: prefix_node - Starting node
183 * Path - Path to object from starting node
184 * expected_return_types - Bitmap of allowed return types
185 * return_desc - Where a return value is stored
189 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
190 * return object. Common code that simplifies accessing objects
191 * that have required return objects of fixed types.
193 * NOTE: Internal function, no parameter validation
195 ******************************************************************************/
198 acpi_ut_evaluate_object(struct acpi_namespace_node
*prefix_node
,
200 u32 expected_return_btypes
,
201 union acpi_operand_object
**return_desc
)
203 struct acpi_evaluate_info
*info
;
207 ACPI_FUNCTION_TRACE(ut_evaluate_object
);
209 /* Allocate the evaluation information block */
211 info
= ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info
));
213 return_ACPI_STATUS(AE_NO_MEMORY
);
216 info
->prefix_node
= prefix_node
;
217 info
->pathname
= path
;
219 /* Evaluate the object/method */
221 status
= acpi_ns_evaluate(info
);
222 if (ACPI_FAILURE(status
)) {
223 if (status
== AE_NOT_FOUND
) {
224 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
225 "[%4.4s.%s] was not found\n",
226 acpi_ut_get_node_name(prefix_node
),
229 ACPI_ERROR_METHOD("Method execution failed",
230 prefix_node
, path
, status
);
236 /* Did we get a return object? */
238 if (!info
->return_object
) {
239 if (expected_return_btypes
) {
240 ACPI_ERROR_METHOD("No object was returned from",
241 prefix_node
, path
, AE_NOT_EXIST
);
243 status
= AE_NOT_EXIST
;
249 /* Map the return object type to the bitmapped type */
251 switch (ACPI_GET_OBJECT_TYPE(info
->return_object
)) {
252 case ACPI_TYPE_INTEGER
:
253 return_btype
= ACPI_BTYPE_INTEGER
;
256 case ACPI_TYPE_BUFFER
:
257 return_btype
= ACPI_BTYPE_BUFFER
;
260 case ACPI_TYPE_STRING
:
261 return_btype
= ACPI_BTYPE_STRING
;
264 case ACPI_TYPE_PACKAGE
:
265 return_btype
= ACPI_BTYPE_PACKAGE
;
273 if ((acpi_gbl_enable_interpreter_slack
) && (!expected_return_btypes
)) {
275 * We received a return object, but one was not expected. This can
276 * happen frequently if the "implicit return" feature is enabled.
277 * Just delete the return object and return AE_OK.
279 acpi_ut_remove_reference(info
->return_object
);
283 /* Is the return object one of the expected types? */
285 if (!(expected_return_btypes
& return_btype
)) {
286 ACPI_ERROR_METHOD("Return object type is incorrect",
287 prefix_node
, path
, AE_TYPE
);
290 "Type returned from %s was incorrect: %s, expected Btypes: %X",
292 acpi_ut_get_object_type_name(info
->return_object
),
293 expected_return_btypes
));
295 /* On error exit, we must delete the return object */
297 acpi_ut_remove_reference(info
->return_object
);
302 /* Object type is OK, return it */
304 *return_desc
= info
->return_object
;
308 return_ACPI_STATUS(status
);
311 /*******************************************************************************
313 * FUNCTION: acpi_ut_evaluate_numeric_object
315 * PARAMETERS: object_name - Object name to be evaluated
316 * device_node - Node for the device
317 * Address - Where the value is returned
321 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
322 * and stores result in *Address.
324 * NOTE: Internal function, no parameter validation
326 ******************************************************************************/
329 acpi_ut_evaluate_numeric_object(char *object_name
,
330 struct acpi_namespace_node
*device_node
,
331 acpi_integer
* address
)
333 union acpi_operand_object
*obj_desc
;
336 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object
);
338 status
= acpi_ut_evaluate_object(device_node
, object_name
,
339 ACPI_BTYPE_INTEGER
, &obj_desc
);
340 if (ACPI_FAILURE(status
)) {
341 return_ACPI_STATUS(status
);
344 /* Get the returned Integer */
346 *address
= obj_desc
->integer
.value
;
348 /* On exit, we must delete the return object */
350 acpi_ut_remove_reference(obj_desc
);
351 return_ACPI_STATUS(status
);
354 /*******************************************************************************
356 * FUNCTION: acpi_ut_copy_id_string
358 * PARAMETERS: Destination - Where to copy the string
359 * Source - Source string
360 * max_length - Length of the destination buffer
364 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
365 * Performs removal of a leading asterisk if present -- workaround
366 * for a known issue on a bunch of machines.
368 ******************************************************************************/
371 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
)
375 * Workaround for ID strings that have a leading asterisk. This construct
376 * is not allowed by the ACPI specification (ID strings must be
377 * alphanumeric), but enough existing machines have this embedded in their
378 * ID strings that the following code is useful.
380 if (*source
== '*') {
384 /* Do the actual copy */
386 ACPI_STRNCPY(destination
, source
, max_length
);
389 /*******************************************************************************
391 * FUNCTION: acpi_ut_execute_HID
393 * PARAMETERS: device_node - Node for the device
394 * Hid - Where the HID is returned
398 * DESCRIPTION: Executes the _HID control method that returns the hardware
401 * NOTE: Internal function, no parameter validation
403 ******************************************************************************/
406 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
407 struct acpica_device_id
*hid
)
409 union acpi_operand_object
*obj_desc
;
412 ACPI_FUNCTION_TRACE(ut_execute_HID
);
414 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
415 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
417 if (ACPI_FAILURE(status
)) {
418 return_ACPI_STATUS(status
);
421 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
423 /* Convert the Numeric HID to string */
425 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
428 /* Copy the String HID from the returned object */
430 acpi_ut_copy_id_string(hid
->value
, obj_desc
->string
.pointer
,
434 /* On exit, we must delete the return object */
436 acpi_ut_remove_reference(obj_desc
);
437 return_ACPI_STATUS(status
);
440 /*******************************************************************************
442 * FUNCTION: acpi_ut_translate_one_cid
444 * PARAMETERS: obj_desc - _CID object, must be integer or string
445 * one_cid - Where the CID string is returned
449 * DESCRIPTION: Return a numeric or string _CID value as a string.
452 * NOTE: Assumes a maximum _CID string length of
453 * ACPI_MAX_CID_LENGTH.
455 ******************************************************************************/
458 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
459 struct acpi_compatible_id
*one_cid
)
462 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
463 case ACPI_TYPE_INTEGER
:
465 /* Convert the Numeric CID to string */
467 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
471 case ACPI_TYPE_STRING
:
473 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
474 return (AE_AML_STRING_LIMIT
);
477 /* Copy the String CID from the returned object */
479 acpi_ut_copy_id_string(one_cid
->value
, obj_desc
->string
.pointer
,
480 ACPI_MAX_CID_LENGTH
);
489 /*******************************************************************************
491 * FUNCTION: acpi_ut_execute_CID
493 * PARAMETERS: device_node - Node for the device
494 * return_cid_list - Where the CID list is returned
498 * DESCRIPTION: Executes the _CID control method that returns one or more
499 * compatible hardware IDs for the device.
501 * NOTE: Internal function, no parameter validation
503 ******************************************************************************/
506 acpi_ut_execute_CID(struct acpi_namespace_node
* device_node
,
507 struct acpi_compatible_id_list
** return_cid_list
)
509 union acpi_operand_object
*obj_desc
;
513 struct acpi_compatible_id_list
*cid_list
;
516 ACPI_FUNCTION_TRACE(ut_execute_CID
);
518 /* Evaluate the _CID method for this device */
520 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
521 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
522 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
523 if (ACPI_FAILURE(status
)) {
524 return_ACPI_STATUS(status
);
527 /* Get the number of _CIDs returned */
530 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
531 count
= obj_desc
->package
.count
;
534 /* Allocate a worst-case buffer for the _CIDs */
536 size
= (((count
- 1) * sizeof(struct acpi_compatible_id
)) +
537 sizeof(struct acpi_compatible_id_list
));
539 cid_list
= ACPI_ALLOCATE_ZEROED((acpi_size
) size
);
541 return_ACPI_STATUS(AE_NO_MEMORY
);
546 cid_list
->count
= count
;
547 cid_list
->size
= size
;
550 * A _CID can return either a single compatible ID or a package of
551 * compatible IDs. Each compatible ID can be one of the following:
552 * 1) Integer (32 bit compressed EISA ID) or
553 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
556 /* The _CID object can be either a single CID or a package (list) of CIDs */
558 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
560 /* Translate each package element */
562 for (i
= 0; i
< count
; i
++) {
564 acpi_ut_translate_one_cid(obj_desc
->package
.
567 if (ACPI_FAILURE(status
)) {
572 /* Only one CID, translate to a string */
574 status
= acpi_ut_translate_one_cid(obj_desc
, cid_list
->id
);
577 /* Cleanup on error */
579 if (ACPI_FAILURE(status
)) {
582 *return_cid_list
= cid_list
;
585 /* On exit, we must delete the _CID return object */
587 acpi_ut_remove_reference(obj_desc
);
588 return_ACPI_STATUS(status
);
591 /*******************************************************************************
593 * FUNCTION: acpi_ut_execute_UID
595 * PARAMETERS: device_node - Node for the device
596 * Uid - Where the UID is returned
600 * DESCRIPTION: Executes the _UID control method that returns the hardware
603 * NOTE: Internal function, no parameter validation
605 ******************************************************************************/
608 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
609 struct acpica_device_id
*uid
)
611 union acpi_operand_object
*obj_desc
;
614 ACPI_FUNCTION_TRACE(ut_execute_UID
);
616 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
617 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
619 if (ACPI_FAILURE(status
)) {
620 return_ACPI_STATUS(status
);
623 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
625 /* Convert the Numeric UID to string */
627 acpi_ex_unsigned_integer_to_string(obj_desc
->integer
.value
,
630 /* Copy the String UID from the returned object */
632 acpi_ut_copy_id_string(uid
->value
, obj_desc
->string
.pointer
,
636 /* On exit, we must delete the return object */
638 acpi_ut_remove_reference(obj_desc
);
639 return_ACPI_STATUS(status
);
642 /*******************************************************************************
644 * FUNCTION: acpi_ut_execute_STA
646 * PARAMETERS: device_node - Node for the device
647 * Flags - Where the status flags are returned
651 * DESCRIPTION: Executes _STA for selected device and stores results in
654 * NOTE: Internal function, no parameter validation
656 ******************************************************************************/
659 acpi_ut_execute_STA(struct acpi_namespace_node
*device_node
, u32
* flags
)
661 union acpi_operand_object
*obj_desc
;
664 ACPI_FUNCTION_TRACE(ut_execute_STA
);
666 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__STA
,
667 ACPI_BTYPE_INTEGER
, &obj_desc
);
668 if (ACPI_FAILURE(status
)) {
669 if (AE_NOT_FOUND
== status
) {
670 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
671 "_STA on %4.4s was not found, assuming device is present\n",
672 acpi_ut_get_node_name(device_node
)));
674 *flags
= ACPI_UINT32_MAX
;
678 return_ACPI_STATUS(status
);
681 /* Extract the status flags */
683 *flags
= (u32
) obj_desc
->integer
.value
;
685 /* On exit, we must delete the return object */
687 acpi_ut_remove_reference(obj_desc
);
688 return_ACPI_STATUS(status
);
691 /*******************************************************************************
693 * FUNCTION: acpi_ut_execute_Sxds
695 * PARAMETERS: device_node - Node for the device
696 * Flags - Where the status flags are returned
700 * DESCRIPTION: Executes _STA for selected device and stores results in
703 * NOTE: Internal function, no parameter validation
705 ******************************************************************************/
708 acpi_ut_execute_sxds(struct acpi_namespace_node
*device_node
, u8
* highest
)
710 union acpi_operand_object
*obj_desc
;
714 ACPI_FUNCTION_TRACE(ut_execute_sxds
);
716 for (i
= 0; i
< 4; i
++) {
718 status
= acpi_ut_evaluate_object(device_node
,
720 acpi_gbl_highest_dstate_names
722 ACPI_BTYPE_INTEGER
, &obj_desc
);
723 if (ACPI_FAILURE(status
)) {
724 if (status
!= AE_NOT_FOUND
) {
725 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
726 "%s on Device %4.4s, %s\n",
728 acpi_gbl_highest_dstate_names
730 acpi_ut_get_node_name
732 acpi_format_exception
735 return_ACPI_STATUS(status
);
738 /* Extract the Dstate value */
740 highest
[i
] = (u8
) obj_desc
->integer
.value
;
742 /* Delete the return object */
744 acpi_ut_remove_reference(obj_desc
);
748 return_ACPI_STATUS(AE_OK
);