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")
53 /* Local prototypes */
56 acpi_ut_copy_id_string (
59 acpi_size max_length
);
62 acpi_ut_translate_one_cid (
63 union acpi_operand_object
*obj_desc
,
64 struct acpi_compatible_id
*one_cid
);
67 /*******************************************************************************
69 * FUNCTION: acpi_ut_osi_implementation
71 * PARAMETERS: walk_state - Current walk state
75 * DESCRIPTION: Implementation of _OSI predefined control method
76 * Supported = _OSI (String)
78 ******************************************************************************/
81 acpi_ut_osi_implementation (
82 struct acpi_walk_state
*walk_state
)
84 union acpi_operand_object
*string_desc
;
85 union acpi_operand_object
*return_desc
;
89 ACPI_FUNCTION_TRACE ("ut_osi_implementation");
92 /* Validate the string input argument */
94 string_desc
= walk_state
->arguments
[0].object
;
95 if (!string_desc
|| (string_desc
->common
.type
!= ACPI_TYPE_STRING
)) {
96 return_ACPI_STATUS (AE_TYPE
);
99 /* Create a return object (Default value = 0) */
101 return_desc
= acpi_ut_create_internal_object (ACPI_TYPE_INTEGER
);
103 return_ACPI_STATUS (AE_NO_MEMORY
);
106 /* Compare input string to table of supported strings */
108 for (i
= 0; i
< ACPI_NUM_OSI_STRINGS
; i
++) {
109 if (!ACPI_STRCMP (string_desc
->string
.pointer
,
110 (char *) acpi_gbl_valid_osi_strings
[i
])) {
111 /* This string is supported */
113 return_desc
->integer
.value
= 0xFFFFFFFF;
118 walk_state
->return_desc
= return_desc
;
119 return_ACPI_STATUS (AE_CTRL_TERMINATE
);
123 /*******************************************************************************
125 * FUNCTION: acpi_ut_evaluate_object
127 * PARAMETERS: prefix_node - Starting node
128 * Path - Path to object from starting node
129 * expected_return_types - Bitmap of allowed return types
130 * return_desc - Where a return value is stored
134 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
135 * return object. Common code that simplifies accessing objects
136 * that have required return objects of fixed types.
138 * NOTE: Internal function, no parameter validation
140 ******************************************************************************/
143 acpi_ut_evaluate_object (
144 struct acpi_namespace_node
*prefix_node
,
146 u32 expected_return_btypes
,
147 union acpi_operand_object
**return_desc
)
149 struct acpi_parameter_info info
;
154 ACPI_FUNCTION_TRACE ("ut_evaluate_object");
157 info
.node
= prefix_node
;
158 info
.parameters
= NULL
;
159 info
.parameter_type
= ACPI_PARAM_ARGS
;
161 /* Evaluate the object/method */
163 status
= acpi_ns_evaluate_relative (path
, &info
);
164 if (ACPI_FAILURE (status
)) {
165 if (status
== AE_NOT_FOUND
) {
166 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
, "[%4.4s.%s] was not found\n",
167 acpi_ut_get_node_name (prefix_node
), path
));
170 ACPI_REPORT_METHOD_ERROR ("Method execution failed",
171 prefix_node
, path
, status
);
174 return_ACPI_STATUS (status
);
177 /* Did we get a return object? */
179 if (!info
.return_object
) {
180 if (expected_return_btypes
) {
181 ACPI_REPORT_METHOD_ERROR ("No object was returned from",
182 prefix_node
, path
, AE_NOT_EXIST
);
184 return_ACPI_STATUS (AE_NOT_EXIST
);
187 return_ACPI_STATUS (AE_OK
);
190 /* Map the return object type to the bitmapped type */
192 switch (ACPI_GET_OBJECT_TYPE (info
.return_object
)) {
193 case ACPI_TYPE_INTEGER
:
194 return_btype
= ACPI_BTYPE_INTEGER
;
197 case ACPI_TYPE_BUFFER
:
198 return_btype
= ACPI_BTYPE_BUFFER
;
201 case ACPI_TYPE_STRING
:
202 return_btype
= ACPI_BTYPE_STRING
;
205 case ACPI_TYPE_PACKAGE
:
206 return_btype
= ACPI_BTYPE_PACKAGE
;
214 if ((acpi_gbl_enable_interpreter_slack
) &&
215 (!expected_return_btypes
)) {
217 * We received a return object, but one was not expected. This can
218 * happen frequently if the "implicit return" feature is enabled.
219 * Just delete the return object and return AE_OK.
221 acpi_ut_remove_reference (info
.return_object
);
222 return_ACPI_STATUS (AE_OK
);
225 /* Is the return object one of the expected types? */
227 if (!(expected_return_btypes
& return_btype
)) {
228 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
229 prefix_node
, path
, AE_TYPE
);
231 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
232 "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
233 path
, acpi_ut_get_object_type_name (info
.return_object
),
234 expected_return_btypes
));
236 /* On error exit, we must delete the return object */
238 acpi_ut_remove_reference (info
.return_object
);
239 return_ACPI_STATUS (AE_TYPE
);
242 /* Object type is OK, return it */
244 *return_desc
= info
.return_object
;
245 return_ACPI_STATUS (AE_OK
);
249 /*******************************************************************************
251 * FUNCTION: acpi_ut_evaluate_numeric_object
253 * PARAMETERS: object_name - Object name to be evaluated
254 * device_node - Node for the device
255 * Address - Where the value is returned
259 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
260 * and stores result in *Address.
262 * NOTE: Internal function, no parameter validation
264 ******************************************************************************/
267 acpi_ut_evaluate_numeric_object (
269 struct acpi_namespace_node
*device_node
,
270 acpi_integer
*address
)
272 union acpi_operand_object
*obj_desc
;
276 ACPI_FUNCTION_TRACE ("ut_evaluate_numeric_object");
279 status
= acpi_ut_evaluate_object (device_node
, object_name
,
280 ACPI_BTYPE_INTEGER
, &obj_desc
);
281 if (ACPI_FAILURE (status
)) {
282 return_ACPI_STATUS (status
);
285 /* Get the returned Integer */
287 *address
= obj_desc
->integer
.value
;
289 /* On exit, we must delete the return object */
291 acpi_ut_remove_reference (obj_desc
);
292 return_ACPI_STATUS (status
);
296 /*******************************************************************************
298 * FUNCTION: acpi_ut_copy_id_string
300 * PARAMETERS: Destination - Where to copy the string
301 * Source - Source string
302 * max_length - Length of the destination buffer
306 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
307 * Performs removal of a leading asterisk if present -- workaround
308 * for a known issue on a bunch of machines.
310 ******************************************************************************/
313 acpi_ut_copy_id_string (
316 acpi_size max_length
)
320 * Workaround for ID strings that have a leading asterisk. This construct
321 * is not allowed by the ACPI specification (ID strings must be
322 * alphanumeric), but enough existing machines have this embedded in their
323 * ID strings that the following code is useful.
325 if (*source
== '*') {
329 /* Do the actual copy */
331 ACPI_STRNCPY (destination
, source
, max_length
);
335 /*******************************************************************************
337 * FUNCTION: acpi_ut_execute_HID
339 * PARAMETERS: device_node - Node for the device
340 * Hid - Where the HID is returned
344 * DESCRIPTION: Executes the _HID control method that returns the hardware
347 * NOTE: Internal function, no parameter validation
349 ******************************************************************************/
352 acpi_ut_execute_HID (
353 struct acpi_namespace_node
*device_node
,
354 struct acpi_device_id
*hid
)
356 union acpi_operand_object
*obj_desc
;
360 ACPI_FUNCTION_TRACE ("ut_execute_HID");
363 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__HID
,
364 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &obj_desc
);
365 if (ACPI_FAILURE (status
)) {
366 return_ACPI_STATUS (status
);
369 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_INTEGER
) {
370 /* Convert the Numeric HID to string */
372 acpi_ex_eisa_id_to_string ((u32
) obj_desc
->integer
.value
, hid
->value
);
375 /* Copy the String HID from the returned object */
377 acpi_ut_copy_id_string (hid
->value
, obj_desc
->string
.pointer
,
378 sizeof (hid
->value
));
381 /* On exit, we must delete the return object */
383 acpi_ut_remove_reference (obj_desc
);
384 return_ACPI_STATUS (status
);
388 /*******************************************************************************
390 * FUNCTION: acpi_ut_translate_one_cid
392 * PARAMETERS: obj_desc - _CID object, must be integer or string
393 * one_cid - Where the CID string is returned
397 * DESCRIPTION: Return a numeric or string _CID value as a string.
400 * NOTE: Assumes a maximum _CID string length of
401 * ACPI_MAX_CID_LENGTH.
403 ******************************************************************************/
406 acpi_ut_translate_one_cid (
407 union acpi_operand_object
*obj_desc
,
408 struct acpi_compatible_id
*one_cid
)
412 switch (ACPI_GET_OBJECT_TYPE (obj_desc
)) {
413 case ACPI_TYPE_INTEGER
:
415 /* Convert the Numeric CID to string */
417 acpi_ex_eisa_id_to_string ((u32
) obj_desc
->integer
.value
, one_cid
->value
);
420 case ACPI_TYPE_STRING
:
422 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
423 return (AE_AML_STRING_LIMIT
);
426 /* Copy the String CID from the returned object */
428 acpi_ut_copy_id_string (one_cid
->value
, obj_desc
->string
.pointer
,
429 ACPI_MAX_CID_LENGTH
);
439 /*******************************************************************************
441 * FUNCTION: acpi_ut_execute_CID
443 * PARAMETERS: device_node - Node for the device
444 * return_cid_list - Where the CID list is returned
448 * DESCRIPTION: Executes the _CID control method that returns one or more
449 * compatible hardware IDs for the device.
451 * NOTE: Internal function, no parameter validation
453 ******************************************************************************/
456 acpi_ut_execute_CID (
457 struct acpi_namespace_node
*device_node
,
458 struct acpi_compatible_id_list
**return_cid_list
)
460 union acpi_operand_object
*obj_desc
;
464 struct acpi_compatible_id_list
*cid_list
;
468 ACPI_FUNCTION_TRACE ("ut_execute_CID");
471 /* Evaluate the _CID method for this device */
473 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__CID
,
474 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
| ACPI_BTYPE_PACKAGE
,
476 if (ACPI_FAILURE (status
)) {
477 return_ACPI_STATUS (status
);
480 /* Get the number of _CIDs returned */
483 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_PACKAGE
) {
484 count
= obj_desc
->package
.count
;
487 /* Allocate a worst-case buffer for the _CIDs */
489 size
= (((count
- 1) * sizeof (struct acpi_compatible_id
)) +
490 sizeof (struct acpi_compatible_id_list
));
492 cid_list
= ACPI_MEM_CALLOCATE ((acpi_size
) size
);
494 return_ACPI_STATUS (AE_NO_MEMORY
);
499 cid_list
->count
= count
;
500 cid_list
->size
= size
;
503 * A _CID can return either a single compatible ID or a package of
504 * compatible IDs. Each compatible ID can be one of the following:
505 * 1) Integer (32 bit compressed EISA ID) or
506 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
509 /* The _CID object can be either a single CID or a package (list) of CIDs */
511 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_PACKAGE
) {
512 /* Translate each package element */
514 for (i
= 0; i
< count
; i
++) {
515 status
= acpi_ut_translate_one_cid (obj_desc
->package
.elements
[i
],
517 if (ACPI_FAILURE (status
)) {
523 /* Only one CID, translate to a string */
525 status
= acpi_ut_translate_one_cid (obj_desc
, cid_list
->id
);
528 /* Cleanup on error */
530 if (ACPI_FAILURE (status
)) {
531 ACPI_MEM_FREE (cid_list
);
534 *return_cid_list
= cid_list
;
537 /* On exit, we must delete the _CID return object */
539 acpi_ut_remove_reference (obj_desc
);
540 return_ACPI_STATUS (status
);
544 /*******************************************************************************
546 * FUNCTION: acpi_ut_execute_UID
548 * PARAMETERS: device_node - Node for the device
549 * Uid - Where the UID is returned
553 * DESCRIPTION: Executes the _UID control method that returns the hardware
556 * NOTE: Internal function, no parameter validation
558 ******************************************************************************/
561 acpi_ut_execute_UID (
562 struct acpi_namespace_node
*device_node
,
563 struct acpi_device_id
*uid
)
565 union acpi_operand_object
*obj_desc
;
569 ACPI_FUNCTION_TRACE ("ut_execute_UID");
572 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__UID
,
573 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &obj_desc
);
574 if (ACPI_FAILURE (status
)) {
575 return_ACPI_STATUS (status
);
578 if (ACPI_GET_OBJECT_TYPE (obj_desc
) == ACPI_TYPE_INTEGER
) {
579 /* Convert the Numeric UID to string */
581 acpi_ex_unsigned_integer_to_string (obj_desc
->integer
.value
, uid
->value
);
584 /* Copy the String UID from the returned object */
586 acpi_ut_copy_id_string (uid
->value
, obj_desc
->string
.pointer
,
587 sizeof (uid
->value
));
590 /* On exit, we must delete the return object */
592 acpi_ut_remove_reference (obj_desc
);
593 return_ACPI_STATUS (status
);
597 /*******************************************************************************
599 * FUNCTION: acpi_ut_execute_STA
601 * PARAMETERS: device_node - Node for the device
602 * Flags - Where the status flags are returned
606 * DESCRIPTION: Executes _STA for selected device and stores results in
609 * NOTE: Internal function, no parameter validation
611 ******************************************************************************/
614 acpi_ut_execute_STA (
615 struct acpi_namespace_node
*device_node
,
618 union acpi_operand_object
*obj_desc
;
622 ACPI_FUNCTION_TRACE ("ut_execute_STA");
625 status
= acpi_ut_evaluate_object (device_node
, METHOD_NAME__STA
,
626 ACPI_BTYPE_INTEGER
, &obj_desc
);
627 if (ACPI_FAILURE (status
)) {
628 if (AE_NOT_FOUND
== status
) {
629 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
630 "_STA on %4.4s was not found, assuming device is present\n",
631 acpi_ut_get_node_name (device_node
)));
637 return_ACPI_STATUS (status
);
640 /* Extract the status flags */
642 *flags
= (u32
) obj_desc
->integer
.value
;
644 /* On exit, we must delete the return object */
646 acpi_ut_remove_reference (obj_desc
);
647 return_ACPI_STATUS (status
);
651 /*******************************************************************************
653 * FUNCTION: acpi_ut_execute_Sxds
655 * PARAMETERS: device_node - Node for the device
656 * Flags - Where the status flags are returned
660 * DESCRIPTION: Executes _STA for selected device and stores results in
663 * NOTE: Internal function, no parameter validation
665 ******************************************************************************/
668 acpi_ut_execute_sxds (
669 struct acpi_namespace_node
*device_node
,
672 union acpi_operand_object
*obj_desc
;
677 ACPI_FUNCTION_TRACE ("ut_execute_Sxds");
680 for (i
= 0; i
< 4; i
++) {
682 status
= acpi_ut_evaluate_object (device_node
,
683 (char *) acpi_gbl_highest_dstate_names
[i
],
684 ACPI_BTYPE_INTEGER
, &obj_desc
);
685 if (ACPI_FAILURE (status
)) {
686 if (status
!= AE_NOT_FOUND
) {
687 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
688 "%s on Device %4.4s, %s\n",
689 (char *) acpi_gbl_highest_dstate_names
[i
],
690 acpi_ut_get_node_name (device_node
),
691 acpi_format_exception (status
)));
693 return_ACPI_STATUS (status
);
697 /* Extract the Dstate value */
699 highest
[i
] = (u8
) obj_desc
->integer
.value
;
701 /* Delete the return object */
703 acpi_ut_remove_reference (obj_desc
);
707 return_ACPI_STATUS (AE_OK
);