1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2005, 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.
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
62 * DESCRIPTION: Implementation of _OSI predefined control method
63 * Supported = _OSI (String)
65 ******************************************************************************/
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
;
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
);
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;
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
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 ******************************************************************************/
130 acpi_ut_evaluate_object (
131 struct acpi_namespace_node
*prefix_node
,
133 u32 expected_return_btypes
,
134 union acpi_operand_object
**return_desc
)
136 struct acpi_parameter_info info
;
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
));
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
;
184 case ACPI_TYPE_BUFFER
:
185 return_btype
= ACPI_BTYPE_BUFFER
;
188 case ACPI_TYPE_STRING
:
189 return_btype
= ACPI_BTYPE_STRING
;
192 case ACPI_TYPE_PACKAGE
:
193 return_btype
= ACPI_BTYPE_PACKAGE
;
201 if ((acpi_gbl_enable_interpreter_slack
) &&
202 (!expected_return_btypes
)) {
204 * We received a return object, but one was not expected. This can
205 * happen frequently if the "implicit return" feature is enabled.
206 * Just delete the return object and return AE_OK.
208 acpi_ut_remove_reference (info
.return_object
);
209 return_ACPI_STATUS (AE_OK
);
212 /* Is the return object one of the expected types? */
214 if (!(expected_return_btypes
& return_btype
)) {
215 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
216 prefix_node
, path
, AE_TYPE
);
218 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
219 "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
220 path
, acpi_ut_get_object_type_name (info
.return_object
),
221 expected_return_btypes
));
223 /* On error exit, we must delete the return object */
225 acpi_ut_remove_reference (info
.return_object
);
226 return_ACPI_STATUS (AE_TYPE
);
229 /* Object type is OK, return it */
231 *return_desc
= info
.return_object
;
232 return_ACPI_STATUS (AE_OK
);
236 /*******************************************************************************
238 * FUNCTION: acpi_ut_evaluate_numeric_object
240 * PARAMETERS: *object_name - Object name to be evaluated
241 * device_node - Node for the device
242 * *Address - Where the value is returned
246 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
247 * and stores result in *Address.
249 * NOTE: Internal function, no parameter validation
251 ******************************************************************************/
254 acpi_ut_evaluate_numeric_object (
256 struct acpi_namespace_node
*device_node
,
257 acpi_integer
*address
)
259 union acpi_operand_object
*obj_desc
;
263 ACPI_FUNCTION_TRACE ("ut_evaluate_numeric_object");
266 status
= acpi_ut_evaluate_object (device_node
, object_name
,
267 ACPI_BTYPE_INTEGER
, &obj_desc
);
268 if (ACPI_FAILURE (status
)) {
269 return_ACPI_STATUS (status
);
272 /* Get the returned Integer */
274 *address
= obj_desc
->integer
.value
;
276 /* On exit, we must delete the return object */
278 acpi_ut_remove_reference (obj_desc
);
279 return_ACPI_STATUS (status
);
283 /*******************************************************************************
285 * FUNCTION: acpi_ut_copy_id_string
287 * PARAMETERS: Destination - Where to copy the string
288 * Source - Source string
289 * max_length - Length of the destination buffer
293 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
294 * Performs removal of a leading asterisk if present -- workaround
295 * for a known issue on a bunch of machines.
297 ******************************************************************************/
300 acpi_ut_copy_id_string (
303 acpi_size max_length
)
308 * Workaround for ID strings that have a leading asterisk. This construct
309 * is not allowed by the ACPI specification (ID strings must be
310 * alphanumeric), but enough existing machines have this embedded in their
311 * ID strings that the following code is useful.
313 if (*source
== '*') {
317 /* Do the actual copy */
319 ACPI_STRNCPY (destination
, source
, max_length
);
323 /*******************************************************************************
325 * FUNCTION: acpi_ut_execute_HID
327 * PARAMETERS: device_node - Node for the device
328 * *Hid - Where the HID is returned
332 * DESCRIPTION: Executes the _HID control method that returns the hardware
335 * NOTE: Internal function, no parameter validation
337 ******************************************************************************/
340 acpi_ut_execute_HID (
341 struct acpi_namespace_node
*device_node
,
342 struct acpi_device_id
*hid
)
344 union acpi_operand_object
*obj_desc
;
348 ACPI_FUNCTION_TRACE ("ut_execute_HID");
351 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__HID
,
352 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &obj_desc
);
353 if (ACPI_FAILURE (status
)) {
354 return_ACPI_STATUS (status
);
357 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_INTEGER
) {
358 /* Convert the Numeric HID to string */
360 acpi_ex_eisa_id_to_string ((u32
) obj_desc
->integer
.value
, hid
->value
);
363 /* Copy the String HID from the returned object */
365 acpi_ut_copy_id_string (hid
->value
, obj_desc
->string
.pointer
,
366 sizeof (hid
->value
));
369 /* On exit, we must delete the return object */
371 acpi_ut_remove_reference (obj_desc
);
372 return_ACPI_STATUS (status
);
376 /*******************************************************************************
378 * FUNCTION: acpi_ut_translate_one_cid
380 * PARAMETERS: obj_desc - _CID object, must be integer or string
381 * one_cid - Where the CID string is returned
385 * DESCRIPTION: Return a numeric or string _CID value as a string.
388 * NOTE: Assumes a maximum _CID string length of
389 * ACPI_MAX_CID_LENGTH.
391 ******************************************************************************/
394 acpi_ut_translate_one_cid (
395 union acpi_operand_object
*obj_desc
,
396 struct acpi_compatible_id
*one_cid
)
400 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
401 case ACPI_TYPE_INTEGER
:
403 /* Convert the Numeric CID to string */
405 acpi_ex_eisa_id_to_string ((u32
) obj_desc
->integer
.value
, one_cid
->value
);
408 case ACPI_TYPE_STRING
:
410 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
411 return (AE_AML_STRING_LIMIT
);
414 /* Copy the String CID from the returned object */
416 acpi_ut_copy_id_string (one_cid
->value
, obj_desc
->string
.pointer
,
417 ACPI_MAX_CID_LENGTH
);
427 /*******************************************************************************
429 * FUNCTION: acpi_ut_execute_CID
431 * PARAMETERS: device_node - Node for the device
432 * *Cid - Where the CID is returned
436 * DESCRIPTION: Executes the _CID control method that returns one or more
437 * compatible hardware IDs for the device.
439 * NOTE: Internal function, no parameter validation
441 ******************************************************************************/
444 acpi_ut_execute_CID (
445 struct acpi_namespace_node
*device_node
,
446 struct acpi_compatible_id_list
**return_cid_list
)
448 union acpi_operand_object
*obj_desc
;
452 struct acpi_compatible_id_list
*cid_list
;
456 ACPI_FUNCTION_TRACE ("ut_execute_CID");
459 /* Evaluate the _CID method for this device */
461 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__CID
,
462 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
| ACPI_BTYPE_PACKAGE
,
464 if (ACPI_FAILURE (status
)) {
465 return_ACPI_STATUS (status
);
468 /* Get the number of _CIDs returned */
471 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_PACKAGE
) {
472 count
= obj_desc
->package
.count
;
475 /* Allocate a worst-case buffer for the _CIDs */
477 size
= (((count
- 1) * sizeof (struct acpi_compatible_id
)) +
478 sizeof (struct acpi_compatible_id_list
));
480 cid_list
= ACPI_MEM_CALLOCATE ((acpi_size
) size
);
482 return_ACPI_STATUS (AE_NO_MEMORY
);
487 cid_list
->count
= count
;
488 cid_list
->size
= size
;
491 * A _CID can return either a single compatible ID or a package of compatible
492 * IDs. Each compatible ID can be one of the following:
493 * -- Number (32 bit compressed EISA ID) or
494 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss").
497 /* The _CID object can be either a single CID or a package (list) of CIDs */
499 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_PACKAGE
) {
500 /* Translate each package element */
502 for (i
= 0; i
< count
; i
++) {
503 status
= acpi_ut_translate_one_cid (obj_desc
->package
.elements
[i
],
505 if (ACPI_FAILURE (status
)) {
511 /* Only one CID, translate to a string */
513 status
= acpi_ut_translate_one_cid (obj_desc
, cid_list
->id
);
516 /* Cleanup on error */
518 if (ACPI_FAILURE (status
)) {
519 ACPI_MEM_FREE (cid_list
);
522 *return_cid_list
= cid_list
;
525 /* On exit, we must delete the _CID return object */
527 acpi_ut_remove_reference (obj_desc
);
528 return_ACPI_STATUS (status
);
532 /*******************************************************************************
534 * FUNCTION: acpi_ut_execute_UID
536 * PARAMETERS: device_node - Node for the device
537 * *Uid - Where the UID is returned
541 * DESCRIPTION: Executes the _UID control method that returns the hardware
544 * NOTE: Internal function, no parameter validation
546 ******************************************************************************/
549 acpi_ut_execute_UID (
550 struct acpi_namespace_node
*device_node
,
551 struct acpi_device_id
*uid
)
553 union acpi_operand_object
*obj_desc
;
557 ACPI_FUNCTION_TRACE ("ut_execute_UID");
560 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__UID
,
561 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &obj_desc
);
562 if (ACPI_FAILURE (status
)) {
563 return_ACPI_STATUS (status
);
566 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_INTEGER
) {
567 /* Convert the Numeric UID to string */
569 acpi_ex_unsigned_integer_to_string (obj_desc
->integer
.value
, uid
->value
);
572 /* Copy the String UID from the returned object */
574 acpi_ut_copy_id_string (uid
->value
, obj_desc
->string
.pointer
,
575 sizeof (uid
->value
));
578 /* On exit, we must delete the return object */
580 acpi_ut_remove_reference (obj_desc
);
581 return_ACPI_STATUS (status
);
585 /*******************************************************************************
587 * FUNCTION: acpi_ut_execute_STA
589 * PARAMETERS: device_node - Node for the device
590 * *Flags - Where the status flags are returned
594 * DESCRIPTION: Executes _STA for selected device and stores results in
597 * NOTE: Internal function, no parameter validation
599 ******************************************************************************/
602 acpi_ut_execute_STA (
603 struct acpi_namespace_node
*device_node
,
606 union acpi_operand_object
*obj_desc
;
610 ACPI_FUNCTION_TRACE ("ut_execute_STA");
613 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__STA
,
614 ACPI_BTYPE_INTEGER
, &obj_desc
);
615 if (ACPI_FAILURE (status
)) {
616 if (AE_NOT_FOUND
== status
) {
617 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
618 "_STA on %4.4s was not found, assuming device is present\n",
619 acpi_ut_get_node_name (device_node
)));
625 return_ACPI_STATUS (status
);
628 /* Extract the status flags */
630 *flags
= (u32
) obj_desc
->integer
.value
;
632 /* On exit, we must delete the return object */
634 acpi_ut_remove_reference (obj_desc
);
635 return_ACPI_STATUS (status
);
639 /*******************************************************************************
641 * FUNCTION: acpi_ut_execute_Sxds
643 * PARAMETERS: device_node - Node for the device
644 * *Flags - Where the status flags are returned
648 * DESCRIPTION: Executes _STA for selected device and stores results in
651 * NOTE: Internal function, no parameter validation
653 ******************************************************************************/
656 acpi_ut_execute_sxds (
657 struct acpi_namespace_node
*device_node
,
660 union acpi_operand_object
*obj_desc
;
665 ACPI_FUNCTION_TRACE ("ut_execute_Sxds");
668 for (i
= 0; i
< 4; i
++) {
670 status
= acpi_ut_evaluate_object (device_node
,
671 (char *) acpi_gbl_highest_dstate_names
[i
],
672 ACPI_BTYPE_INTEGER
, &obj_desc
);
673 if (ACPI_FAILURE (status
)) {
674 if (status
!= AE_NOT_FOUND
) {
675 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
676 "%s on Device %4.4s, %s\n",
677 (char *) acpi_gbl_highest_dstate_names
[i
],
678 acpi_ut_get_node_name (device_node
),
679 acpi_format_exception (status
)));
681 return_ACPI_STATUS (status
);
685 /* Extract the Dstate value */
687 highest
[i
] = (u8
) obj_desc
->integer
.value
;
689 /* Delete the return object */
691 acpi_ut_remove_reference (obj_desc
);
695 return_ACPI_STATUS (AE_OK
);