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.
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
,
98 (char *)acpi_gbl_valid_osi_strings
[i
])) {
99 /* This string is supported */
101 return_desc
->integer
.value
= 0xFFFFFFFF;
106 walk_state
->return_desc
= return_desc
;
107 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(struct acpi_namespace_node
*prefix_node
,
132 u32 expected_return_btypes
,
133 union acpi_operand_object
**return_desc
)
135 struct acpi_parameter_info info
;
139 ACPI_FUNCTION_TRACE("ut_evaluate_object");
141 info
.node
= prefix_node
;
142 info
.parameters
= NULL
;
143 info
.parameter_type
= ACPI_PARAM_ARGS
;
145 /* Evaluate the object/method */
147 status
= acpi_ns_evaluate_relative(path
, &info
);
148 if (ACPI_FAILURE(status
)) {
149 if (status
== AE_NOT_FOUND
) {
150 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
151 "[%4.4s.%s] was not found\n",
152 acpi_ut_get_node_name(prefix_node
),
155 ACPI_REPORT_METHOD_ERROR("Method execution failed",
156 prefix_node
, path
, status
);
159 return_ACPI_STATUS(status
);
162 /* Did we get a return object? */
164 if (!info
.return_object
) {
165 if (expected_return_btypes
) {
166 ACPI_REPORT_METHOD_ERROR("No object was returned from",
170 return_ACPI_STATUS(AE_NOT_EXIST
);
173 return_ACPI_STATUS(AE_OK
);
176 /* Map the return object type to the bitmapped type */
178 switch (ACPI_GET_OBJECT_TYPE(info
.return_object
)) {
179 case ACPI_TYPE_INTEGER
:
180 return_btype
= ACPI_BTYPE_INTEGER
;
183 case ACPI_TYPE_BUFFER
:
184 return_btype
= ACPI_BTYPE_BUFFER
;
187 case ACPI_TYPE_STRING
:
188 return_btype
= ACPI_BTYPE_STRING
;
191 case ACPI_TYPE_PACKAGE
:
192 return_btype
= ACPI_BTYPE_PACKAGE
;
200 if ((acpi_gbl_enable_interpreter_slack
) && (!expected_return_btypes
)) {
202 * We received a return object, but one was not expected. This can
203 * happen frequently if the "implicit return" feature is enabled.
204 * Just delete the return object and return AE_OK.
206 acpi_ut_remove_reference(info
.return_object
);
207 return_ACPI_STATUS(AE_OK
);
210 /* Is the return object one of the expected types? */
212 if (!(expected_return_btypes
& return_btype
)) {
213 ACPI_REPORT_METHOD_ERROR("Return object type is incorrect",
214 prefix_node
, path
, AE_TYPE
);
216 ACPI_DEBUG_PRINT((ACPI_DB_ERROR
,
217 "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
219 acpi_ut_get_object_type_name(info
.
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
);
235 /*******************************************************************************
237 * FUNCTION: acpi_ut_evaluate_numeric_object
239 * PARAMETERS: object_name - Object name to be evaluated
240 * device_node - Node for the device
241 * Address - Where the value is returned
245 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
246 * and stores result in *Address.
248 * NOTE: Internal function, no parameter validation
250 ******************************************************************************/
253 acpi_ut_evaluate_numeric_object(char *object_name
,
254 struct acpi_namespace_node
*device_node
,
255 acpi_integer
* address
)
257 union acpi_operand_object
*obj_desc
;
260 ACPI_FUNCTION_TRACE("ut_evaluate_numeric_object");
262 status
= acpi_ut_evaluate_object(device_node
, object_name
,
263 ACPI_BTYPE_INTEGER
, &obj_desc
);
264 if (ACPI_FAILURE(status
)) {
265 return_ACPI_STATUS(status
);
268 /* Get the returned Integer */
270 *address
= obj_desc
->integer
.value
;
272 /* On exit, we must delete the return object */
274 acpi_ut_remove_reference(obj_desc
);
275 return_ACPI_STATUS(status
);
278 /*******************************************************************************
280 * FUNCTION: acpi_ut_copy_id_string
282 * PARAMETERS: Destination - Where to copy the string
283 * Source - Source string
284 * max_length - Length of the destination buffer
288 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
289 * Performs removal of a leading asterisk if present -- workaround
290 * for a known issue on a bunch of machines.
292 ******************************************************************************/
295 acpi_ut_copy_id_string(char *destination
, char *source
, acpi_size max_length
)
299 * Workaround for ID strings that have a leading asterisk. This construct
300 * is not allowed by the ACPI specification (ID strings must be
301 * alphanumeric), but enough existing machines have this embedded in their
302 * ID strings that the following code is useful.
304 if (*source
== '*') {
308 /* Do the actual copy */
310 ACPI_STRNCPY(destination
, source
, max_length
);
313 /*******************************************************************************
315 * FUNCTION: acpi_ut_execute_HID
317 * PARAMETERS: device_node - Node for the device
318 * Hid - Where the HID is returned
322 * DESCRIPTION: Executes the _HID control method that returns the hardware
325 * NOTE: Internal function, no parameter validation
327 ******************************************************************************/
330 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
331 struct acpi_device_id
*hid
)
333 union acpi_operand_object
*obj_desc
;
336 ACPI_FUNCTION_TRACE("ut_execute_HID");
338 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
339 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
341 if (ACPI_FAILURE(status
)) {
342 return_ACPI_STATUS(status
);
345 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
346 /* Convert the Numeric HID to string */
348 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
351 /* Copy the String HID from the returned object */
353 acpi_ut_copy_id_string(hid
->value
, obj_desc
->string
.pointer
,
357 /* On exit, we must delete the return object */
359 acpi_ut_remove_reference(obj_desc
);
360 return_ACPI_STATUS(status
);
363 /*******************************************************************************
365 * FUNCTION: acpi_ut_translate_one_cid
367 * PARAMETERS: obj_desc - _CID object, must be integer or string
368 * one_cid - Where the CID string is returned
372 * DESCRIPTION: Return a numeric or string _CID value as a string.
375 * NOTE: Assumes a maximum _CID string length of
376 * ACPI_MAX_CID_LENGTH.
378 ******************************************************************************/
381 acpi_ut_translate_one_cid(union acpi_operand_object
*obj_desc
,
382 struct acpi_compatible_id
*one_cid
)
385 switch (ACPI_GET_OBJECT_TYPE(obj_desc
)) {
386 case ACPI_TYPE_INTEGER
:
388 /* Convert the Numeric CID to string */
390 acpi_ex_eisa_id_to_string((u32
) obj_desc
->integer
.value
,
394 case ACPI_TYPE_STRING
:
396 if (obj_desc
->string
.length
> ACPI_MAX_CID_LENGTH
) {
397 return (AE_AML_STRING_LIMIT
);
400 /* Copy the String CID from the returned object */
402 acpi_ut_copy_id_string(one_cid
->value
, obj_desc
->string
.pointer
,
403 ACPI_MAX_CID_LENGTH
);
412 /*******************************************************************************
414 * FUNCTION: acpi_ut_execute_CID
416 * PARAMETERS: device_node - Node for the device
417 * return_cid_list - Where the CID list is returned
421 * DESCRIPTION: Executes the _CID control method that returns one or more
422 * compatible hardware IDs for the device.
424 * NOTE: Internal function, no parameter validation
426 ******************************************************************************/
429 acpi_ut_execute_CID(struct acpi_namespace_node
* device_node
,
430 struct acpi_compatible_id_list
** return_cid_list
)
432 union acpi_operand_object
*obj_desc
;
436 struct acpi_compatible_id_list
*cid_list
;
439 ACPI_FUNCTION_TRACE("ut_execute_CID");
441 /* Evaluate the _CID method for this device */
443 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
444 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
445 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
446 if (ACPI_FAILURE(status
)) {
447 return_ACPI_STATUS(status
);
450 /* Get the number of _CIDs returned */
453 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
454 count
= obj_desc
->package
.count
;
457 /* Allocate a worst-case buffer for the _CIDs */
459 size
= (((count
- 1) * sizeof(struct acpi_compatible_id
)) +
460 sizeof(struct acpi_compatible_id_list
));
462 cid_list
= ACPI_MEM_CALLOCATE((acpi_size
) size
);
464 return_ACPI_STATUS(AE_NO_MEMORY
);
469 cid_list
->count
= count
;
470 cid_list
->size
= size
;
473 * A _CID can return either a single compatible ID or a package of
474 * compatible IDs. Each compatible ID can be one of the following:
475 * 1) Integer (32 bit compressed EISA ID) or
476 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
479 /* The _CID object can be either a single CID or a package (list) of CIDs */
481 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_PACKAGE
) {
482 /* Translate each package element */
484 for (i
= 0; i
< count
; i
++) {
486 acpi_ut_translate_one_cid(obj_desc
->package
.
489 if (ACPI_FAILURE(status
)) {
494 /* Only one CID, translate to a string */
496 status
= acpi_ut_translate_one_cid(obj_desc
, cid_list
->id
);
499 /* Cleanup on error */
501 if (ACPI_FAILURE(status
)) {
502 ACPI_MEM_FREE(cid_list
);
504 *return_cid_list
= cid_list
;
507 /* On exit, we must delete the _CID return object */
509 acpi_ut_remove_reference(obj_desc
);
510 return_ACPI_STATUS(status
);
513 /*******************************************************************************
515 * FUNCTION: acpi_ut_execute_UID
517 * PARAMETERS: device_node - Node for the device
518 * Uid - Where the UID is returned
522 * DESCRIPTION: Executes the _UID control method that returns the hardware
525 * NOTE: Internal function, no parameter validation
527 ******************************************************************************/
530 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
531 struct acpi_device_id
*uid
)
533 union acpi_operand_object
*obj_desc
;
536 ACPI_FUNCTION_TRACE("ut_execute_UID");
538 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
539 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
541 if (ACPI_FAILURE(status
)) {
542 return_ACPI_STATUS(status
);
545 if (ACPI_GET_OBJECT_TYPE(obj_desc
) == ACPI_TYPE_INTEGER
) {
546 /* Convert the Numeric UID to string */
548 acpi_ex_unsigned_integer_to_string(obj_desc
->integer
.value
,
551 /* Copy the String UID from the returned object */
553 acpi_ut_copy_id_string(uid
->value
, obj_desc
->string
.pointer
,
557 /* On exit, we must delete the return object */
559 acpi_ut_remove_reference(obj_desc
);
560 return_ACPI_STATUS(status
);
563 /*******************************************************************************
565 * FUNCTION: acpi_ut_execute_STA
567 * PARAMETERS: device_node - Node for the device
568 * Flags - Where the status flags are returned
572 * DESCRIPTION: Executes _STA for selected device and stores results in
575 * NOTE: Internal function, no parameter validation
577 ******************************************************************************/
580 acpi_ut_execute_STA(struct acpi_namespace_node
*device_node
, u32
* flags
)
582 union acpi_operand_object
*obj_desc
;
585 ACPI_FUNCTION_TRACE("ut_execute_STA");
587 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__STA
,
588 ACPI_BTYPE_INTEGER
, &obj_desc
);
589 if (ACPI_FAILURE(status
)) {
590 if (AE_NOT_FOUND
== status
) {
591 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
592 "_STA on %4.4s was not found, assuming device is present\n",
593 acpi_ut_get_node_name(device_node
)));
599 return_ACPI_STATUS(status
);
602 /* Extract the status flags */
604 *flags
= (u32
) obj_desc
->integer
.value
;
606 /* On exit, we must delete the return object */
608 acpi_ut_remove_reference(obj_desc
);
609 return_ACPI_STATUS(status
);
612 /*******************************************************************************
614 * FUNCTION: acpi_ut_execute_Sxds
616 * PARAMETERS: device_node - Node for the device
617 * Flags - Where the status flags are returned
621 * DESCRIPTION: Executes _STA for selected device and stores results in
624 * NOTE: Internal function, no parameter validation
626 ******************************************************************************/
629 acpi_ut_execute_sxds(struct acpi_namespace_node
*device_node
, u8
* highest
)
631 union acpi_operand_object
*obj_desc
;
635 ACPI_FUNCTION_TRACE("ut_execute_Sxds");
637 for (i
= 0; i
< 4; i
++) {
639 status
= acpi_ut_evaluate_object(device_node
,
641 acpi_gbl_highest_dstate_names
642 [i
], ACPI_BTYPE_INTEGER
,
644 if (ACPI_FAILURE(status
)) {
645 if (status
!= AE_NOT_FOUND
) {
646 ACPI_DEBUG_PRINT((ACPI_DB_EXEC
,
647 "%s on Device %4.4s, %s\n",
649 acpi_gbl_highest_dstate_names
651 acpi_ut_get_node_name
653 acpi_format_exception
656 return_ACPI_STATUS(status
);
659 /* Extract the Dstate value */
661 highest
[i
] = (u8
) obj_desc
->integer
.value
;
663 /* Delete the return object */
665 acpi_ut_remove_reference(obj_desc
);
669 return_ACPI_STATUS(AE_OK
);