1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2006, R. Byron Moore
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 const char *acpi_interfaces_supported
[] = {
63 /* Operating System Vendor Strings */
74 "Windows 2001.1 SP1", /* Added 03/2006 */
75 "Windows 2006", /* Added 03/2006 */
77 /* Feature Group Strings */
79 "Extended Address Space Descriptor"
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.
87 /*******************************************************************************
89 * FUNCTION: acpi_ut_osi_implementation
91 * PARAMETERS: walk_state - Current walk state
95 * DESCRIPTION: Implementation of the _OSI predefined control method
97 ******************************************************************************/
99 acpi_status
acpi_ut_osi_implementation(struct acpi_walk_state
*walk_state
)
102 union acpi_operand_object
*string_desc
;
103 union acpi_operand_object
*return_desc
;
106 ACPI_FUNCTION_TRACE(ut_osi_implementation
);
108 /* Validate the string input argument */
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
);
115 /* Create a return object */
117 return_desc
= acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
119 return_ACPI_STATUS(AE_NO_MEMORY
);
122 /* Default return value is SUPPORTED */
124 return_desc
->integer
.value
= ACPI_UINT32_MAX
;
125 walk_state
->return_desc
= return_desc
;
127 /* Compare input string to static table of supported interfaces */
129 for (i
= 0; i
< ACPI_ARRAY_LENGTH(acpi_interfaces_supported
); i
++) {
131 (string_desc
->string
.pointer
,
132 acpi_interfaces_supported
[i
])) {
134 /* The interface is supported */
136 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
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.)
145 status
= acpi_os_validate_interface(string_desc
->string
.pointer
);
146 if (ACPI_SUCCESS(status
)) {
148 /* The interface is supported */
150 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
153 /* The interface is not supported */
155 return_desc
->integer
.value
= 0;
156 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
159 /*******************************************************************************
161 * FUNCTION: acpi_ut_evaluate_object
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
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.
174 * NOTE: Internal function, no parameter validation
176 ******************************************************************************/
179 acpi_ut_evaluate_object(struct acpi_namespace_node
*prefix_node
,
181 u32 expected_return_btypes
,
182 union acpi_operand_object
**return_desc
)
184 struct acpi_parameter_info info
;
188 ACPI_FUNCTION_TRACE(ut_evaluate_object
);
190 info
.node
= prefix_node
;
191 info
.parameters
= NULL
;
192 info
.parameter_type
= ACPI_PARAM_ARGS
;
194 /* Evaluate the object/method */
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
),
204 ACPI_ERROR_METHOD("Method execution failed",
205 prefix_node
, path
, status
);
208 return_ACPI_STATUS(status
);
211 /* Did we get a return object? */
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
);
218 return_ACPI_STATUS(AE_NOT_EXIST
);
221 return_ACPI_STATUS(AE_OK
);
224 /* Map the return object type to the bitmapped type */
226 switch (ACPI_GET_OBJECT_TYPE(info
.return_object
)) {
227 case ACPI_TYPE_INTEGER
:
228 return_btype
= ACPI_BTYPE_INTEGER
;
231 case ACPI_TYPE_BUFFER
:
232 return_btype
= ACPI_BTYPE_BUFFER
;
235 case ACPI_TYPE_STRING
:
236 return_btype
= ACPI_BTYPE_STRING
;
239 case ACPI_TYPE_PACKAGE
:
240 return_btype
= ACPI_BTYPE_PACKAGE
;
248 if ((acpi_gbl_enable_interpreter_slack
) && (!expected_return_btypes
)) {
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.
254 acpi_ut_remove_reference(info
.return_object
);
255 return_ACPI_STATUS(AE_OK
);
258 /* Is the return object one of the expected types? */
260 if (!(expected_return_btypes
& return_btype
)) {
261 ACPI_ERROR_METHOD("Return object type is incorrect",
262 prefix_node
, path
, AE_TYPE
);
265 "Type returned from %s was incorrect: %s, expected Btypes: %X",
267 acpi_ut_get_object_type_name(info
.return_object
),
268 expected_return_btypes
));
270 /* On error exit, we must delete the return object */
272 acpi_ut_remove_reference(info
.return_object
);
273 return_ACPI_STATUS(AE_TYPE
);
276 /* Object type is OK, return it */
278 *return_desc
= info
.return_object
;
279 return_ACPI_STATUS(AE_OK
);
282 /*******************************************************************************
284 * FUNCTION: acpi_ut_evaluate_numeric_object
286 * PARAMETERS: object_name - Object name to be evaluated
287 * device_node - Node for the device
288 * Address - Where the value is returned
292 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
293 * and stores result in *Address.
295 * NOTE: Internal function, no parameter validation
297 ******************************************************************************/
300 acpi_ut_evaluate_numeric_object(char *object_name
,
301 struct acpi_namespace_node
*device_node
,
302 acpi_integer
* address
)
304 union acpi_operand_object
*obj_desc
;
307 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object
);
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
);
315 /* Get the returned Integer */
317 *address
= obj_desc
->integer
.value
;
319 /* On exit, we must delete the return object */
321 acpi_ut_remove_reference(obj_desc
);
322 return_ACPI_STATUS(status
);
325 /*******************************************************************************
327 * FUNCTION: acpi_ut_copy_id_string
329 * PARAMETERS: Destination - Where to copy the string
330 * Source - Source string
331 * max_length - Length of the destination buffer
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.
339 ******************************************************************************/
342 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
)
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.
351 if (*source
== '*') {
355 /* Do the actual copy */
357 ACPI_STRNCPY(destination
, source
, max_length
);
360 /*******************************************************************************
362 * FUNCTION: acpi_ut_execute_HID
364 * PARAMETERS: device_node - Node for the device
365 * Hid - Where the HID is returned
369 * DESCRIPTION: Executes the _HID control method that returns the hardware
372 * NOTE: Internal function, no parameter validation
374 ******************************************************************************/
377 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
378 struct acpi_device_id
*hid
)
380 union acpi_operand_object
*obj_desc
;
383 ACPI_FUNCTION_TRACE(ut_execute_HID
);
385 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
386 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
388 if (ACPI_FAILURE(status
)) {
389 return_ACPI_STATUS(status
);
392 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
394 /* Convert the Numeric HID to string */
396 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
399 /* Copy the String HID from the returned object */
401 acpi_ut_copy_id_string(hid
->value
, obj_desc
->string
.pointer
,
405 /* On exit, we must delete the return object */
407 acpi_ut_remove_reference(obj_desc
);
408 return_ACPI_STATUS(status
);
411 /*******************************************************************************
413 * FUNCTION: acpi_ut_translate_one_cid
415 * PARAMETERS: obj_desc - _CID object, must be integer or string
416 * one_cid - Where the CID string is returned
420 * DESCRIPTION: Return a numeric or string _CID value as a string.
423 * NOTE: Assumes a maximum _CID string length of
424 * ACPI_MAX_CID_LENGTH.
426 ******************************************************************************/
429 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
430 struct acpi_compatible_id
*one_cid
)
433 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
434 case ACPI_TYPE_INTEGER
:
436 /* Convert the Numeric CID to string */
438 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
442 case ACPI_TYPE_STRING
:
444 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
445 return (AE_AML_STRING_LIMIT
);
448 /* Copy the String CID from the returned object */
450 acpi_ut_copy_id_string(one_cid
->value
, obj_desc
->string
.pointer
,
451 ACPI_MAX_CID_LENGTH
);
460 /*******************************************************************************
462 * FUNCTION: acpi_ut_execute_CID
464 * PARAMETERS: device_node - Node for the device
465 * return_cid_list - Where the CID list is returned
469 * DESCRIPTION: Executes the _CID control method that returns one or more
470 * compatible hardware IDs for the device.
472 * NOTE: Internal function, no parameter validation
474 ******************************************************************************/
477 acpi_ut_execute_CID(struct acpi_namespace_node
* device_node
,
478 struct acpi_compatible_id_list
** return_cid_list
)
480 union acpi_operand_object
*obj_desc
;
484 struct acpi_compatible_id_list
*cid_list
;
487 ACPI_FUNCTION_TRACE(ut_execute_CID
);
489 /* Evaluate the _CID method for this device */
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
);
498 /* Get the number of _CIDs returned */
501 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
502 count
= obj_desc
->package
.count
;
505 /* Allocate a worst-case buffer for the _CIDs */
507 size
= (((count
- 1) * sizeof(struct acpi_compatible_id
)) +
508 sizeof(struct acpi_compatible_id_list
));
510 cid_list
= ACPI_ALLOCATE_ZEROED((acpi_size
) size
);
512 return_ACPI_STATUS(AE_NO_MEMORY
);
517 cid_list
->count
= count
;
518 cid_list
->size
= size
;
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")
527 /* The _CID object can be either a single CID or a package (list) of CIDs */
529 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
531 /* Translate each package element */
533 for (i
= 0; i
< count
; i
++) {
535 acpi_ut_translate_one_cid(obj_desc
->package
.
538 if (ACPI_FAILURE(status
)) {
543 /* Only one CID, translate to a string */
545 status
= acpi_ut_translate_one_cid(obj_desc
, cid_list
->id
);
548 /* Cleanup on error */
550 if (ACPI_FAILURE(status
)) {
553 *return_cid_list
= cid_list
;
556 /* On exit, we must delete the _CID return object */
558 acpi_ut_remove_reference(obj_desc
);
559 return_ACPI_STATUS(status
);
562 /*******************************************************************************
564 * FUNCTION: acpi_ut_execute_UID
566 * PARAMETERS: device_node - Node for the device
567 * Uid - Where the UID is returned
571 * DESCRIPTION: Executes the _UID control method that returns the hardware
574 * NOTE: Internal function, no parameter validation
576 ******************************************************************************/
579 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
580 struct acpi_device_id
*uid
)
582 union acpi_operand_object
*obj_desc
;
585 ACPI_FUNCTION_TRACE(ut_execute_UID
);
587 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
588 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
590 if (ACPI_FAILURE(status
)) {
591 return_ACPI_STATUS(status
);
594 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
596 /* Convert the Numeric UID to string */
598 acpi_ex_unsigned_integer_to_string(obj_desc
->integer
.value
,
601 /* Copy the String UID from the returned object */
603 acpi_ut_copy_id_string(uid
->value
, obj_desc
->string
.pointer
,
607 /* On exit, we must delete the return object */
609 acpi_ut_remove_reference(obj_desc
);
610 return_ACPI_STATUS(status
);
613 /*******************************************************************************
615 * FUNCTION: acpi_ut_execute_STA
617 * PARAMETERS: device_node - Node for the device
618 * Flags - Where the status flags are returned
622 * DESCRIPTION: Executes _STA for selected device and stores results in
625 * NOTE: Internal function, no parameter validation
627 ******************************************************************************/
630 acpi_ut_execute_STA(struct acpi_namespace_node
*device_node
, u32
* flags
)
632 union acpi_operand_object
*obj_desc
;
635 ACPI_FUNCTION_TRACE(ut_execute_STA
);
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
)));
645 *flags
= ACPI_UINT32_MAX
;
649 return_ACPI_STATUS(status
);
652 /* Extract the status flags */
654 *flags
= (u32
) obj_desc
->integer
.value
;
656 /* On exit, we must delete the return object */
658 acpi_ut_remove_reference(obj_desc
);
659 return_ACPI_STATUS(status
);
662 /*******************************************************************************
664 * FUNCTION: acpi_ut_execute_Sxds
666 * PARAMETERS: device_node - Node for the device
667 * Flags - Where the status flags are returned
671 * DESCRIPTION: Executes _STA for selected device and stores results in
674 * NOTE: Internal function, no parameter validation
676 ******************************************************************************/
679 acpi_ut_execute_sxds(struct acpi_namespace_node
*device_node
, u8
* highest
)
681 union acpi_operand_object
*obj_desc
;
685 ACPI_FUNCTION_TRACE(ut_execute_sxds
);
687 for (i
= 0; i
< 4; i
++) {
689 status
= acpi_ut_evaluate_object(device_node
,
691 acpi_gbl_highest_dstate_names
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",
699 acpi_gbl_highest_dstate_names
701 acpi_ut_get_node_name
703 acpi_format_exception
706 return_ACPI_STATUS(status
);
709 /* Extract the Dstate value */
711 highest
[i
] = (u8
) obj_desc
->integer
.value
;
713 /* Delete the return object */
715 acpi_ut_remove_reference(obj_desc
);
719 return_ACPI_STATUS(AE_OK
);