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
);
59 /*******************************************************************************
61 * FUNCTION: acpi_ut_osi_implementation
63 * PARAMETERS: walk_state - Current walk state
67 * DESCRIPTION: Implementation of _OSI predefined control method
68 * Supported = _OSI (String)
70 ******************************************************************************/
72 acpi_status
acpi_ut_osi_implementation(struct acpi_walk_state
*walk_state
)
74 union acpi_operand_object
*string_desc
;
75 union acpi_operand_object
*return_desc
;
78 ACPI_FUNCTION_TRACE("ut_osi_implementation");
80 /* Validate the string input argument */
82 string_desc
= walk_state
->arguments
[0].object
;
83 if (!string_desc
|| (string_desc
->common
.type
!= ACPI_TYPE_STRING
)) {
84 return_ACPI_STATUS(AE_TYPE
);
87 /* Create a return object (Default value = 0) */
89 return_desc
= acpi_ut_create_internal_object(ACPI_TYPE_INTEGER
);
91 return_ACPI_STATUS(AE_NO_MEMORY
);
94 /* Compare input string to table of supported strings */
96 for (i
= 0; i
< ACPI_NUM_OSI_STRINGS
; i
++) {
97 if (!ACPI_STRCMP(string_desc
->string
.pointer
,
99 acpi_gbl_valid_osi_strings
[i
])))
101 /* This string is supported */
103 return_desc
->integer
.value
= 0xFFFFFFFF;
108 walk_state
->return_desc
= return_desc
;
109 return_ACPI_STATUS(AE_CTRL_TERMINATE
);
112 /*******************************************************************************
114 * FUNCTION: acpi_ut_evaluate_object
116 * PARAMETERS: prefix_node - Starting node
117 * Path - Path to object from starting node
118 * expected_return_types - Bitmap of allowed return types
119 * return_desc - Where a return value is stored
123 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
124 * return object. Common code that simplifies accessing objects
125 * that have required return objects of fixed types.
127 * NOTE: Internal function, no parameter validation
129 ******************************************************************************/
132 acpi_ut_evaluate_object(struct acpi_namespace_node
*prefix_node
,
134 u32 expected_return_btypes
,
135 union acpi_operand_object
**return_desc
)
137 struct acpi_parameter_info info
;
141 ACPI_FUNCTION_TRACE("ut_evaluate_object");
143 info
.node
= prefix_node
;
144 info
.parameters
= NULL
;
145 info
.parameter_type
= ACPI_PARAM_ARGS
;
147 /* Evaluate the object/method */
149 status
= acpi_ns_evaluate_relative(path
, &info
);
150 if (ACPI_FAILURE(status
)) {
151 if (status
== AE_NOT_FOUND
) {
152 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
153 "[%4.4s.%s] was not found\n",
154 acpi_ut_get_node_name(prefix_node
),
157 ACPI_REPORT_MTERROR("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_MTERROR("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
) && (!expected_return_btypes
)) {
203 * We received a return object, but one was not expected. This can
204 * happen frequently if the "implicit return" feature is enabled.
205 * Just delete the return object and return AE_OK.
207 acpi_ut_remove_reference(info
.return_object
);
208 return_ACPI_STATUS(AE_OK
);
211 /* Is the return object one of the expected types? */
213 if (!(expected_return_btypes
& return_btype
)) {
214 ACPI_REPORT_MTERROR("Return object type is incorrect",
215 prefix_node
, path
, AE_TYPE
);
217 ACPI_REPORT_ERROR(("Type returned from %s was incorrect: %s, expected Btypes: %X\n", path
, acpi_ut_get_object_type_name(info
.return_object
), expected_return_btypes
));
219 /* On error exit, we must delete the return object */
221 acpi_ut_remove_reference(info
.return_object
);
222 return_ACPI_STATUS(AE_TYPE
);
225 /* Object type is OK, return it */
227 *return_desc
= info
.return_object
;
228 return_ACPI_STATUS(AE_OK
);
231 /*******************************************************************************
233 * FUNCTION: acpi_ut_evaluate_numeric_object
235 * PARAMETERS: object_name - Object name to be evaluated
236 * device_node - Node for the device
237 * Address - Where the value is returned
241 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
242 * and stores result in *Address.
244 * NOTE: Internal function, no parameter validation
246 ******************************************************************************/
249 acpi_ut_evaluate_numeric_object(char *object_name
,
250 struct acpi_namespace_node
*device_node
,
251 acpi_integer
* address
)
253 union acpi_operand_object
*obj_desc
;
256 ACPI_FUNCTION_TRACE("ut_evaluate_numeric_object");
258 status
= acpi_ut_evaluate_object(device_node
, object_name
,
259 ACPI_BTYPE_INTEGER
, &obj_desc
);
260 if (ACPI_FAILURE(status
)) {
261 return_ACPI_STATUS(status
);
264 /* Get the returned Integer */
266 *address
= obj_desc
->integer
.value
;
268 /* On exit, we must delete the return object */
270 acpi_ut_remove_reference(obj_desc
);
271 return_ACPI_STATUS(status
);
274 /*******************************************************************************
276 * FUNCTION: acpi_ut_copy_id_string
278 * PARAMETERS: Destination - Where to copy the string
279 * Source - Source string
280 * max_length - Length of the destination buffer
284 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
285 * Performs removal of a leading asterisk if present -- workaround
286 * for a known issue on a bunch of machines.
288 ******************************************************************************/
291 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
)
295 * Workaround for ID strings that have a leading asterisk. This construct
296 * is not allowed by the ACPI specification (ID strings must be
297 * alphanumeric), but enough existing machines have this embedded in their
298 * ID strings that the following code is useful.
300 if (*source
== '*') {
304 /* Do the actual copy */
306 ACPI_STRNCPY(destination
, source
, max_length
);
309 /*******************************************************************************
311 * FUNCTION: acpi_ut_execute_HID
313 * PARAMETERS: device_node - Node for the device
314 * Hid - Where the HID is returned
318 * DESCRIPTION: Executes the _HID control method that returns the hardware
321 * NOTE: Internal function, no parameter validation
323 ******************************************************************************/
326 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
327 struct acpi_device_id
*hid
)
329 union acpi_operand_object
*obj_desc
;
332 ACPI_FUNCTION_TRACE("ut_execute_HID");
334 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
335 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
337 if (ACPI_FAILURE(status
)) {
338 return_ACPI_STATUS(status
);
341 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
342 /* Convert the Numeric HID to string */
344 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
347 /* Copy the String HID from the returned object */
349 acpi_ut_copy_id_string(hid
->value
, obj_desc
->string
.pointer
,
353 /* On exit, we must delete the return object */
355 acpi_ut_remove_reference(obj_desc
);
356 return_ACPI_STATUS(status
);
359 /*******************************************************************************
361 * FUNCTION: acpi_ut_translate_one_cid
363 * PARAMETERS: obj_desc - _CID object, must be integer or string
364 * one_cid - Where the CID string is returned
368 * DESCRIPTION: Return a numeric or string _CID value as a string.
371 * NOTE: Assumes a maximum _CID string length of
372 * ACPI_MAX_CID_LENGTH.
374 ******************************************************************************/
377 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
378 struct acpi_compatible_id
*one_cid
)
381 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
382 case ACPI_TYPE_INTEGER
:
384 /* Convert the Numeric CID to string */
386 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
390 case ACPI_TYPE_STRING
:
392 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
393 return (AE_AML_STRING_LIMIT
);
396 /* Copy the String CID from the returned object */
398 acpi_ut_copy_id_string(one_cid
->value
, obj_desc
->string
.pointer
,
399 ACPI_MAX_CID_LENGTH
);
408 /*******************************************************************************
410 * FUNCTION: acpi_ut_execute_CID
412 * PARAMETERS: device_node - Node for the device
413 * return_cid_list - Where the CID list is returned
417 * DESCRIPTION: Executes the _CID control method that returns one or more
418 * compatible hardware IDs for the device.
420 * NOTE: Internal function, no parameter validation
422 ******************************************************************************/
425 acpi_ut_execute_CID(struct acpi_namespace_node
* device_node
,
426 struct acpi_compatible_id_list
** return_cid_list
)
428 union acpi_operand_object
*obj_desc
;
432 struct acpi_compatible_id_list
*cid_list
;
435 ACPI_FUNCTION_TRACE("ut_execute_CID");
437 /* Evaluate the _CID method for this device */
439 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
440 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
441 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
442 if (ACPI_FAILURE(status
)) {
443 return_ACPI_STATUS(status
);
446 /* Get the number of _CIDs returned */
449 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
450 count
= obj_desc
->package
.count
;
453 /* Allocate a worst-case buffer for the _CIDs */
455 size
= (((count
- 1) * sizeof(struct acpi_compatible_id
)) +
456 sizeof(struct acpi_compatible_id_list
));
458 cid_list
= ACPI_MEM_CALLOCATE((acpi_size
) size
);
460 return_ACPI_STATUS(AE_NO_MEMORY
);
465 cid_list
->count
= count
;
466 cid_list
->size
= size
;
469 * A _CID can return either a single compatible ID or a package of
470 * compatible IDs. Each compatible ID can be one of the following:
471 * 1) Integer (32 bit compressed EISA ID) or
472 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
475 /* The _CID object can be either a single CID or a package (list) of CIDs */
477 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
478 /* Translate each package element */
480 for (i
= 0; i
< count
; i
++) {
482 acpi_ut_translate_one_cid(obj_desc
->package
.
485 if (ACPI_FAILURE(status
)) {
490 /* Only one CID, translate to a string */
492 status
= acpi_ut_translate_one_cid(obj_desc
, cid_list
->id
);
495 /* Cleanup on error */
497 if (ACPI_FAILURE(status
)) {
498 ACPI_MEM_FREE(cid_list
);
500 *return_cid_list
= cid_list
;
503 /* On exit, we must delete the _CID return object */
505 acpi_ut_remove_reference(obj_desc
);
506 return_ACPI_STATUS(status
);
509 /*******************************************************************************
511 * FUNCTION: acpi_ut_execute_UID
513 * PARAMETERS: device_node - Node for the device
514 * Uid - Where the UID is returned
518 * DESCRIPTION: Executes the _UID control method that returns the hardware
521 * NOTE: Internal function, no parameter validation
523 ******************************************************************************/
526 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
527 struct acpi_device_id
*uid
)
529 union acpi_operand_object
*obj_desc
;
532 ACPI_FUNCTION_TRACE("ut_execute_UID");
534 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
535 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
537 if (ACPI_FAILURE(status
)) {
538 return_ACPI_STATUS(status
);
541 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
542 /* Convert the Numeric UID to string */
544 acpi_ex_unsigned_integer_to_string(obj_desc
->integer
.value
,
547 /* Copy the String UID from the returned object */
549 acpi_ut_copy_id_string(uid
->value
, obj_desc
->string
.pointer
,
553 /* On exit, we must delete the return object */
555 acpi_ut_remove_reference(obj_desc
);
556 return_ACPI_STATUS(status
);
559 /*******************************************************************************
561 * FUNCTION: acpi_ut_execute_STA
563 * PARAMETERS: device_node - Node for the device
564 * Flags - Where the status flags are returned
568 * DESCRIPTION: Executes _STA for selected device and stores results in
571 * NOTE: Internal function, no parameter validation
573 ******************************************************************************/
576 acpi_ut_execute_STA(struct acpi_namespace_node
*device_node
, u32
* flags
)
578 union acpi_operand_object
*obj_desc
;
581 ACPI_FUNCTION_TRACE("ut_execute_STA");
583 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__STA
,
584 ACPI_BTYPE_INTEGER
, &obj_desc
);
585 if (ACPI_FAILURE(status
)) {
586 if (AE_NOT_FOUND
== status
) {
587 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
588 "_STA on %4.4s was not found, assuming device is present\n",
589 acpi_ut_get_node_name(device_node
)));
591 *flags
= ACPI_UINT32_MAX
;
595 return_ACPI_STATUS(status
);
598 /* Extract the status flags */
600 *flags
= (u32
) obj_desc
->integer
.value
;
602 /* On exit, we must delete the return object */
604 acpi_ut_remove_reference(obj_desc
);
605 return_ACPI_STATUS(status
);
608 /*******************************************************************************
610 * FUNCTION: acpi_ut_execute_Sxds
612 * PARAMETERS: device_node - Node for the device
613 * Flags - Where the status flags are returned
617 * DESCRIPTION: Executes _STA for selected device and stores results in
620 * NOTE: Internal function, no parameter validation
622 ******************************************************************************/
625 acpi_ut_execute_sxds(struct acpi_namespace_node
*device_node
, u8
* highest
)
627 union acpi_operand_object
*obj_desc
;
631 ACPI_FUNCTION_TRACE("ut_execute_Sxds");
633 for (i
= 0; i
< 4; i
++) {
635 status
= acpi_ut_evaluate_object(device_node
,
637 acpi_gbl_highest_dstate_names
639 ACPI_BTYPE_INTEGER
, &obj_desc
);
640 if (ACPI_FAILURE(status
)) {
641 if (status
!= AE_NOT_FOUND
) {
642 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
643 "%s on Device %4.4s, %s\n",
645 acpi_gbl_highest_dstate_names
647 acpi_ut_get_node_name
649 acpi_format_exception
652 return_ACPI_STATUS(status
);
655 /* Extract the Dstate value */
657 highest
[i
] = (u8
) obj_desc
->integer
.value
;
659 /* Delete the return object */
661 acpi_ut_remove_reference(obj_desc
);
665 return_ACPI_STATUS(AE_OK
);