1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2007, 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 char *acpi_interfaces_supported[] = {
63 /* Operating System Vendor Strings */
73 "Windows 2001.1 SP1", /* Added 03/2006 */
74 "Windows 2006", /* Added 03/2006 */
76 /* Feature Group Strings */
78 "Extended Address Space Descriptor"
80 * All "optional" feature group strings (features that are implemented
81 * by the host) should be implemented in the host version of
82 * acpi_os_validate_interface and should not be added here.
86 /*******************************************************************************
88 * FUNCTION: acpi_ut_osi_implementation
90 * PARAMETERS: walk_state - Current walk state
94 * DESCRIPTION: Implementation of the _OSI predefined control method
96 ******************************************************************************/
98 acpi_status acpi_ut_osi_implementation(struct acpi_walk_state *walk_state)
101 union acpi_operand_object *string_desc;
102 union acpi_operand_object *return_desc;
105 ACPI_FUNCTION_TRACE(ut_osi_implementation);
107 /* Validate the string input argument */
109 string_desc = walk_state->arguments[0].object;
110 if (!string_desc || (string_desc->common.type != ACPI_TYPE_STRING)) {
111 return_ACPI_STATUS(AE_TYPE);
114 /* Create a return object */
116 return_desc = acpi_ut_create_internal_object(ACPI_TYPE_INTEGER);
118 return_ACPI_STATUS(AE_NO_MEMORY);
121 /* Default return value is SUPPORTED */
123 return_desc->integer.value = ACPI_UINT32_MAX;
124 walk_state->return_desc = return_desc;
126 /* Compare input string to static table of supported interfaces */
128 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
130 (string_desc->string.pointer,
131 acpi_interfaces_supported[i])) {
133 /* The interface is supported */
135 return_ACPI_STATUS(AE_CTRL_TERMINATE);
140 * Did not match the string in the static table, call the host OSL to
141 * check for a match with one of the optional strings (such as
142 * "Module Device", "3.0 Thermal Model", etc.)
144 status = acpi_os_validate_interface(string_desc->string.pointer);
145 if (ACPI_SUCCESS(status)) {
147 /* The interface is supported */
149 return_ACPI_STATUS(AE_CTRL_TERMINATE);
152 /* The interface is not supported */
154 return_desc->integer.value = 0;
155 return_ACPI_STATUS(AE_CTRL_TERMINATE);
158 /*******************************************************************************
160 * FUNCTION: acpi_osi_invalidate
162 * PARAMETERS: interface_string
166 * DESCRIPTION: invalidate string in pre-defiend _OSI string list
168 ******************************************************************************/
170 acpi_status acpi_osi_invalidate(char *interface)
174 for (i = 0; i < ACPI_ARRAY_LENGTH(acpi_interfaces_supported); i++) {
175 if (!ACPI_STRCMP(interface, acpi_interfaces_supported[i])) {
176 *acpi_interfaces_supported[i] = '\0';
183 /*******************************************************************************
185 * FUNCTION: acpi_ut_evaluate_object
187 * PARAMETERS: prefix_node - Starting node
188 * Path - Path to object from starting node
189 * expected_return_types - Bitmap of allowed return types
190 * return_desc - Where a return value is stored
194 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
195 * return object. Common code that simplifies accessing objects
196 * that have required return objects of fixed types.
198 * NOTE: Internal function, no parameter validation
200 ******************************************************************************/
203 acpi_ut_evaluate_object(struct acpi_namespace_node *prefix_node,
205 u32 expected_return_btypes,
206 union acpi_operand_object **return_desc)
208 struct acpi_evaluate_info *info;
212 ACPI_FUNCTION_TRACE(ut_evaluate_object);
214 /* Allocate the evaluation information block */
216 info = ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_evaluate_info));
218 return_ACPI_STATUS(AE_NO_MEMORY);
221 info->prefix_node = prefix_node;
222 info->pathname = path;
223 info->parameter_type = ACPI_PARAM_ARGS;
225 /* Evaluate the object/method */
227 status = acpi_ns_evaluate(info);
228 if (ACPI_FAILURE(status)) {
229 if (status == AE_NOT_FOUND) {
230 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
231 "[%4.4s.%s] was not found\n",
232 acpi_ut_get_node_name(prefix_node),
235 ACPI_ERROR_METHOD("Method execution failed",
236 prefix_node, path, status);
242 /* Did we get a return object? */
244 if (!info->return_object) {
245 if (expected_return_btypes) {
246 ACPI_ERROR_METHOD("No object was returned from",
247 prefix_node, path, AE_NOT_EXIST);
249 status = AE_NOT_EXIST;
255 /* Map the return object type to the bitmapped type */
257 switch (ACPI_GET_OBJECT_TYPE(info->return_object)) {
258 case ACPI_TYPE_INTEGER:
259 return_btype = ACPI_BTYPE_INTEGER;
262 case ACPI_TYPE_BUFFER:
263 return_btype = ACPI_BTYPE_BUFFER;
266 case ACPI_TYPE_STRING:
267 return_btype = ACPI_BTYPE_STRING;
270 case ACPI_TYPE_PACKAGE:
271 return_btype = ACPI_BTYPE_PACKAGE;
279 if ((acpi_gbl_enable_interpreter_slack) && (!expected_return_btypes)) {
281 * We received a return object, but one was not expected. This can
282 * happen frequently if the "implicit return" feature is enabled.
283 * Just delete the return object and return AE_OK.
285 acpi_ut_remove_reference(info->return_object);
289 /* Is the return object one of the expected types? */
291 if (!(expected_return_btypes & return_btype)) {
292 ACPI_ERROR_METHOD("Return object type is incorrect",
293 prefix_node, path, AE_TYPE);
296 "Type returned from %s was incorrect: %s, expected Btypes: %X",
298 acpi_ut_get_object_type_name(info->return_object),
299 expected_return_btypes));
301 /* On error exit, we must delete the return object */
303 acpi_ut_remove_reference(info->return_object);
308 /* Object type is OK, return it */
310 *return_desc = info->return_object;
314 return_ACPI_STATUS(status);
317 /*******************************************************************************
319 * FUNCTION: acpi_ut_evaluate_numeric_object
321 * PARAMETERS: object_name - Object name to be evaluated
322 * device_node - Node for the device
323 * Address - Where the value is returned
327 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
328 * and stores result in *Address.
330 * NOTE: Internal function, no parameter validation
332 ******************************************************************************/
335 acpi_ut_evaluate_numeric_object(char *object_name,
336 struct acpi_namespace_node *device_node,
337 acpi_integer * address)
339 union acpi_operand_object *obj_desc;
342 ACPI_FUNCTION_TRACE(ut_evaluate_numeric_object);
344 status = acpi_ut_evaluate_object(device_node, object_name,
345 ACPI_BTYPE_INTEGER, &obj_desc);
346 if (ACPI_FAILURE(status)) {
347 return_ACPI_STATUS(status);
350 /* Get the returned Integer */
352 *address = obj_desc->integer.value;
354 /* On exit, we must delete the return object */
356 acpi_ut_remove_reference(obj_desc);
357 return_ACPI_STATUS(status);
360 /*******************************************************************************
362 * FUNCTION: acpi_ut_copy_id_string
364 * PARAMETERS: Destination - Where to copy the string
365 * Source - Source string
366 * max_length - Length of the destination buffer
370 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
371 * Performs removal of a leading asterisk if present -- workaround
372 * for a known issue on a bunch of machines.
374 ******************************************************************************/
377 acpi_ut_copy_id_string(char *destination, char *source, acpi_size max_length)
381 * Workaround for ID strings that have a leading asterisk. This construct
382 * is not allowed by the ACPI specification (ID strings must be
383 * alphanumeric), but enough existing machines have this embedded in their
384 * ID strings that the following code is useful.
386 if (*source == '*') {
390 /* Do the actual copy */
392 ACPI_STRNCPY(destination, source, max_length);
395 /*******************************************************************************
397 * FUNCTION: acpi_ut_execute_HID
399 * PARAMETERS: device_node - Node for the device
400 * Hid - Where the HID is returned
404 * DESCRIPTION: Executes the _HID control method that returns the hardware
407 * NOTE: Internal function, no parameter validation
409 ******************************************************************************/
412 acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
413 struct acpi_device_id *hid)
415 union acpi_operand_object *obj_desc;
418 ACPI_FUNCTION_TRACE(ut_execute_HID);
420 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
421 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
423 if (ACPI_FAILURE(status)) {
424 return_ACPI_STATUS(status);
427 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
429 /* Convert the Numeric HID to string */
431 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
434 /* Copy the String HID from the returned object */
436 acpi_ut_copy_id_string(hid->value, obj_desc->string.pointer,
440 /* On exit, we must delete the return object */
442 acpi_ut_remove_reference(obj_desc);
443 return_ACPI_STATUS(status);
446 /*******************************************************************************
448 * FUNCTION: acpi_ut_translate_one_cid
450 * PARAMETERS: obj_desc - _CID object, must be integer or string
451 * one_cid - Where the CID string is returned
455 * DESCRIPTION: Return a numeric or string _CID value as a string.
458 * NOTE: Assumes a maximum _CID string length of
459 * ACPI_MAX_CID_LENGTH.
461 ******************************************************************************/
464 acpi_ut_translate_one_cid(union acpi_operand_object *obj_desc,
465 struct acpi_compatible_id *one_cid)
468 switch (ACPI_GET_OBJECT_TYPE(obj_desc)) {
469 case ACPI_TYPE_INTEGER:
471 /* Convert the Numeric CID to string */
473 acpi_ex_eisa_id_to_string((u32) obj_desc->integer.value,
477 case ACPI_TYPE_STRING:
479 if (obj_desc->string.length > ACPI_MAX_CID_LENGTH) {
480 return (AE_AML_STRING_LIMIT);
483 /* Copy the String CID from the returned object */
485 acpi_ut_copy_id_string(one_cid->value, obj_desc->string.pointer,
486 ACPI_MAX_CID_LENGTH);
495 /*******************************************************************************
497 * FUNCTION: acpi_ut_execute_CID
499 * PARAMETERS: device_node - Node for the device
500 * return_cid_list - Where the CID list is returned
504 * DESCRIPTION: Executes the _CID control method that returns one or more
505 * compatible hardware IDs for the device.
507 * NOTE: Internal function, no parameter validation
509 ******************************************************************************/
512 acpi_ut_execute_CID(struct acpi_namespace_node * device_node,
513 struct acpi_compatible_id_list ** return_cid_list)
515 union acpi_operand_object *obj_desc;
519 struct acpi_compatible_id_list *cid_list;
522 ACPI_FUNCTION_TRACE(ut_execute_CID);
524 /* Evaluate the _CID method for this device */
526 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
527 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
528 | ACPI_BTYPE_PACKAGE, &obj_desc);
529 if (ACPI_FAILURE(status)) {
530 return_ACPI_STATUS(status);
533 /* Get the number of _CIDs returned */
536 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
537 count = obj_desc->package.count;
540 /* Allocate a worst-case buffer for the _CIDs */
542 size = (((count - 1) * sizeof(struct acpi_compatible_id)) +
543 sizeof(struct acpi_compatible_id_list));
545 cid_list = ACPI_ALLOCATE_ZEROED((acpi_size) size);
547 return_ACPI_STATUS(AE_NO_MEMORY);
552 cid_list->count = count;
553 cid_list->size = size;
556 * A _CID can return either a single compatible ID or a package of
557 * compatible IDs. Each compatible ID can be one of the following:
558 * 1) Integer (32 bit compressed EISA ID) or
559 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
562 /* The _CID object can be either a single CID or a package (list) of CIDs */
564 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_PACKAGE) {
566 /* Translate each package element */
568 for (i = 0; i < count; i++) {
570 acpi_ut_translate_one_cid(obj_desc->package.
573 if (ACPI_FAILURE(status)) {
578 /* Only one CID, translate to a string */
580 status = acpi_ut_translate_one_cid(obj_desc, cid_list->id);
583 /* Cleanup on error */
585 if (ACPI_FAILURE(status)) {
588 *return_cid_list = cid_list;
591 /* On exit, we must delete the _CID return object */
593 acpi_ut_remove_reference(obj_desc);
594 return_ACPI_STATUS(status);
597 /*******************************************************************************
599 * FUNCTION: acpi_ut_execute_UID
601 * PARAMETERS: device_node - Node for the device
602 * Uid - Where the UID is returned
606 * DESCRIPTION: Executes the _UID control method that returns the hardware
609 * NOTE: Internal function, no parameter validation
611 ******************************************************************************/
614 acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
615 struct acpi_device_id *uid)
617 union acpi_operand_object *obj_desc;
620 ACPI_FUNCTION_TRACE(ut_execute_UID);
622 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
623 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
625 if (ACPI_FAILURE(status)) {
626 return_ACPI_STATUS(status);
629 if (ACPI_GET_OBJECT_TYPE(obj_desc) == ACPI_TYPE_INTEGER) {
631 /* Convert the Numeric UID to string */
633 acpi_ex_unsigned_integer_to_string(obj_desc->integer.value,
636 /* Copy the String UID from the returned object */
638 acpi_ut_copy_id_string(uid->value, obj_desc->string.pointer,
642 /* On exit, we must delete the return object */
644 acpi_ut_remove_reference(obj_desc);
645 return_ACPI_STATUS(status);
648 /*******************************************************************************
650 * FUNCTION: acpi_ut_execute_STA
652 * PARAMETERS: device_node - Node for the device
653 * Flags - Where the status flags are returned
657 * DESCRIPTION: Executes _STA for selected device and stores results in
660 * NOTE: Internal function, no parameter validation
662 ******************************************************************************/
665 acpi_ut_execute_STA(struct acpi_namespace_node *device_node, u32 * flags)
667 union acpi_operand_object *obj_desc;
670 ACPI_FUNCTION_TRACE(ut_execute_STA);
672 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__STA,
673 ACPI_BTYPE_INTEGER, &obj_desc);
674 if (ACPI_FAILURE(status)) {
675 if (AE_NOT_FOUND == status) {
676 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
677 "_STA on %4.4s was not found, assuming device is present\n",
678 acpi_ut_get_node_name(device_node)));
680 *flags = ACPI_UINT32_MAX;
684 return_ACPI_STATUS(status);
687 /* Extract the status flags */
689 *flags = (u32) obj_desc->integer.value;
691 /* On exit, we must delete the return object */
693 acpi_ut_remove_reference(obj_desc);
694 return_ACPI_STATUS(status);
697 /*******************************************************************************
699 * FUNCTION: acpi_ut_execute_Sxds
701 * PARAMETERS: device_node - Node for the device
702 * Flags - Where the status flags are returned
706 * DESCRIPTION: Executes _STA for selected device and stores results in
709 * NOTE: Internal function, no parameter validation
711 ******************************************************************************/
714 acpi_ut_execute_sxds(struct acpi_namespace_node *device_node, u8 * highest)
716 union acpi_operand_object *obj_desc;
720 ACPI_FUNCTION_TRACE(ut_execute_sxds);
722 for (i = 0; i < 4; i++) {
724 status = acpi_ut_evaluate_object(device_node,
726 acpi_gbl_highest_dstate_names
728 ACPI_BTYPE_INTEGER, &obj_desc);
729 if (ACPI_FAILURE(status)) {
730 if (status != AE_NOT_FOUND) {
731 ACPI_DEBUG_PRINT((ACPI_DB_EXEC,
732 "%s on Device %4.4s, %s\n",
734 acpi_gbl_highest_dstate_names
736 acpi_ut_get_node_name
738 acpi_format_exception
741 return_ACPI_STATUS(status);
744 /* Extract the Dstate value */
746 highest[i] = (u8) obj_desc->integer.value;
748 /* Delete the return object */
750 acpi_ut_remove_reference(obj_desc);
754 return_ACPI_STATUS(AE_OK);