1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2007, Intel Corp.
13 * All rights reserved.
17 * 2.1. This is your license from Intel Corp. under its intellectual property
18 * rights. You may have additional license terms from the party that provided
19 * you this software, covering your right to use that party's intellectual
22 * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
23 * copy of the source code appearing in this file ("Covered Code") an
24 * irrevocable, perpetual, worldwide license under Intel's copyrights in the
25 * base code distributed originally by Intel ("Original Intel Code") to copy,
26 * make derivatives, distribute, use and display any portion of the Covered
27 * Code in any form, with the right to sublicense such rights; and
29 * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
30 * license (with the right to sublicense), under only those claims of Intel
31 * patents that are infringed by the Original Intel Code, to make, use, sell,
32 * offer to sell, and import the Covered Code and derivative works thereof
33 * solely to the minimum extent necessary to exercise the above copyright
34 * license, and in no event shall the patent license extend to any additions
35 * to or modifications of the Original Intel Code. No other license or right
36 * is granted directly or by implication, estoppel or otherwise;
38 * The above copyright and patent license is granted only if the following
43 * 3.1. Redistribution of Source with Rights to Further Distribute Source.
44 * Redistribution of source code of any substantial portion of the Covered
45 * Code or modification with rights to further distribute source must include
46 * the above Copyright Notice, the above License, this list of Conditions,
47 * and the following Disclaimer and Export Compliance provision. In addition,
48 * Licensee must cause all Covered Code to which Licensee contributes to
49 * contain a file documenting the changes Licensee made to create that Covered
50 * Code and the date of any change. Licensee must include in that file the
51 * documentation of any changes made by any predecessor Licensee. Licensee
52 * must include a prominent statement that the modification is derived,
53 * directly or indirectly, from Original Intel Code.
55 * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
56 * Redistribution of source code of any substantial portion of the Covered
57 * Code or modification without rights to further distribute source must
58 * include the following Disclaimer and Export Compliance provision in the
59 * documentation and/or other materials provided with distribution. In
60 * addition, Licensee may not authorize further sublicense of source of any
61 * portion of the Covered Code, and must include terms to the effect that the
62 * license from Licensee to its licensee is limited to the intellectual
63 * property embodied in the software Licensee provides to its licensee, and
64 * not to intellectual property embodied in modifications its licensee may
67 * 3.3. Redistribution of Executable. Redistribution in executable form of any
68 * substantial portion of the Covered Code or modification must reproduce the
69 * above Copyright Notice, and the following Disclaimer and Export Compliance
70 * provision in the documentation and/or other materials provided with the
73 * 3.4. Intel retains all right, title, and interest in and to the Original
76 * 3.5. Neither the name Intel nor any other trademark owned or controlled by
77 * Intel shall be used in advertising or otherwise to promote the sale, use or
78 * other dealings in products derived from or relating to the Covered Code
79 * without prior written authorization from Intel.
81 * 4. Disclaimer and Export Compliance
83 * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
84 * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
85 * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
86 * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
87 * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
88 * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
91 * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
92 * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
93 * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
94 * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
95 * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
96 * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
97 * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
100 * 4.3. Licensee shall not export, either directly or indirectly, any of this
101 * software or system incorporating such software without first obtaining any
102 * required license or other approval from the U. S. Department of Commerce or
103 * any other agency or department of the United States Government. In the
104 * event Licensee exports any such software from the United States or
105 * re-exports any such software from a foreign destination, Licensee shall
106 * ensure that the distribution and export/re-export of the software is in
107 * compliance with all laws, regulations, orders, or other restrictions of the
108 * U.S. Export Administration Regulations. Licensee agrees that neither it nor
109 * any of its subsidiaries will export/re-export any technical data, process,
110 * software, or service, directly or indirectly, to any country for which the
111 * United States government or any agency thereof requires an export license,
112 * other governmental approval, or letter of assurance, without first obtaining
113 * such license, approval or letter.
115 *****************************************************************************/
119 #include <contrib/dev/acpica/acpi.h>
120 #include <contrib/dev/acpica/acnamesp.h>
121 #include <contrib/dev/acpica/acinterp.h>
124 #define _COMPONENT ACPI_UTILITIES
125 ACPI_MODULE_NAME ("uteval")
127 /* Local prototypes */
133 ACPI_SIZE MaxLength);
136 AcpiUtTranslateOneCid (
137 ACPI_OPERAND_OBJECT *ObjDesc,
138 ACPI_COMPATIBLE_ID *OneCid);
142 * Strings supported by the _OSI predefined (internal) method.
144 static const char *AcpiInterfacesSupported[] =
146 /* Operating System Vendor Strings */
157 "Windows 2001.1 SP1", /* Added 03/2006 */
158 "Windows 2006", /* Added 03/2006 */
160 /* Feature Group Strings */
162 "Extended Address Space Descriptor"
165 * All "optional" feature group strings (features that are implemented
166 * by the host) should be implemented in the host version of
167 * AcpiOsValidateInterface and should not be added here.
172 /*******************************************************************************
174 * FUNCTION: AcpiUtOsiImplementation
176 * PARAMETERS: WalkState - Current walk state
180 * DESCRIPTION: Implementation of the _OSI predefined control method
182 ******************************************************************************/
185 AcpiUtOsiImplementation (
186 ACPI_WALK_STATE *WalkState)
189 ACPI_OPERAND_OBJECT *StringDesc;
190 ACPI_OPERAND_OBJECT *ReturnDesc;
194 ACPI_FUNCTION_TRACE (UtOsiImplementation);
197 /* Validate the string input argument */
199 StringDesc = WalkState->Arguments[0].Object;
200 if (!StringDesc || (StringDesc->Common.Type != ACPI_TYPE_STRING))
202 return_ACPI_STATUS (AE_TYPE);
205 /* Create a return object */
207 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
210 return_ACPI_STATUS (AE_NO_MEMORY);
213 /* Default return value is SUPPORTED */
215 ReturnDesc->Integer.Value = ACPI_UINT32_MAX;
216 WalkState->ReturnDesc = ReturnDesc;
218 /* Compare input string to static table of supported interfaces */
220 for (i = 0; i < ACPI_ARRAY_LENGTH (AcpiInterfacesSupported); i++)
222 if (!ACPI_STRCMP (StringDesc->String.Pointer, AcpiInterfacesSupported[i]))
224 /* The interface is supported */
226 return_ACPI_STATUS (AE_CTRL_TERMINATE);
231 * Did not match the string in the static table, call the host OSL to
232 * check for a match with one of the optional strings (such as
233 * "Module Device", "3.0 Thermal Model", etc.)
235 Status = AcpiOsValidateInterface (StringDesc->String.Pointer);
236 if (ACPI_SUCCESS (Status))
238 /* The interface is supported */
240 return_ACPI_STATUS (AE_CTRL_TERMINATE);
243 /* The interface is not supported */
245 ReturnDesc->Integer.Value = 0;
246 return_ACPI_STATUS (AE_CTRL_TERMINATE);
250 /*******************************************************************************
252 * FUNCTION: AcpiUtEvaluateObject
254 * PARAMETERS: PrefixNode - Starting node
255 * Path - Path to object from starting node
256 * ExpectedReturnTypes - Bitmap of allowed return types
257 * ReturnDesc - Where a return value is stored
261 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
262 * return object. Common code that simplifies accessing objects
263 * that have required return objects of fixed types.
265 * NOTE: Internal function, no parameter validation
267 ******************************************************************************/
270 AcpiUtEvaluateObject (
271 ACPI_NAMESPACE_NODE *PrefixNode,
273 UINT32 ExpectedReturnBtypes,
274 ACPI_OPERAND_OBJECT **ReturnDesc)
276 ACPI_EVALUATE_INFO *Info;
281 ACPI_FUNCTION_TRACE (UtEvaluateObject);
284 /* Allocate the evaluation information block */
286 Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
289 return_ACPI_STATUS (AE_NO_MEMORY);
292 Info->PrefixNode = PrefixNode;
293 Info->Pathname = Path;
294 Info->ParameterType = ACPI_PARAM_ARGS;
296 /* Evaluate the object/method */
298 Status = AcpiNsEvaluate (Info);
299 if (ACPI_FAILURE (Status))
301 if (Status == AE_NOT_FOUND)
303 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
304 AcpiUtGetNodeName (PrefixNode), Path));
308 ACPI_ERROR_METHOD ("Method execution failed",
309 PrefixNode, Path, Status);
315 /* Did we get a return object? */
317 if (!Info->ReturnObject)
319 if (ExpectedReturnBtypes)
321 ACPI_ERROR_METHOD ("No object was returned from",
322 PrefixNode, Path, AE_NOT_EXIST);
324 Status = AE_NOT_EXIST;
330 /* Map the return object type to the bitmapped type */
332 switch (ACPI_GET_OBJECT_TYPE (Info->ReturnObject))
334 case ACPI_TYPE_INTEGER:
335 ReturnBtype = ACPI_BTYPE_INTEGER;
338 case ACPI_TYPE_BUFFER:
339 ReturnBtype = ACPI_BTYPE_BUFFER;
342 case ACPI_TYPE_STRING:
343 ReturnBtype = ACPI_BTYPE_STRING;
346 case ACPI_TYPE_PACKAGE:
347 ReturnBtype = ACPI_BTYPE_PACKAGE;
355 if ((AcpiGbl_EnableInterpreterSlack) &&
356 (!ExpectedReturnBtypes))
359 * We received a return object, but one was not expected. This can
360 * happen frequently if the "implicit return" feature is enabled.
361 * Just delete the return object and return AE_OK.
363 AcpiUtRemoveReference (Info->ReturnObject);
367 /* Is the return object one of the expected types? */
369 if (!(ExpectedReturnBtypes & ReturnBtype))
371 ACPI_ERROR_METHOD ("Return object type is incorrect",
372 PrefixNode, Path, AE_TYPE);
374 ACPI_ERROR ((AE_INFO,
375 "Type returned from %s was incorrect: %s, expected Btypes: %X",
376 Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
377 ExpectedReturnBtypes));
379 /* On error exit, we must delete the return object */
381 AcpiUtRemoveReference (Info->ReturnObject);
386 /* Object type is OK, return it */
388 *ReturnDesc = Info->ReturnObject;
392 return_ACPI_STATUS (Status);
396 /*******************************************************************************
398 * FUNCTION: AcpiUtEvaluateNumericObject
400 * PARAMETERS: ObjectName - Object name to be evaluated
401 * DeviceNode - Node for the device
402 * Address - Where the value is returned
406 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
407 * and stores result in *Address.
409 * NOTE: Internal function, no parameter validation
411 ******************************************************************************/
414 AcpiUtEvaluateNumericObject (
416 ACPI_NAMESPACE_NODE *DeviceNode,
417 ACPI_INTEGER *Address)
419 ACPI_OPERAND_OBJECT *ObjDesc;
423 ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
426 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
427 ACPI_BTYPE_INTEGER, &ObjDesc);
428 if (ACPI_FAILURE (Status))
430 return_ACPI_STATUS (Status);
433 /* Get the returned Integer */
435 *Address = ObjDesc->Integer.Value;
437 /* On exit, we must delete the return object */
439 AcpiUtRemoveReference (ObjDesc);
440 return_ACPI_STATUS (Status);
444 /*******************************************************************************
446 * FUNCTION: AcpiUtCopyIdString
448 * PARAMETERS: Destination - Where to copy the string
449 * Source - Source string
450 * MaxLength - Length of the destination buffer
454 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
455 * Performs removal of a leading asterisk if present -- workaround
456 * for a known issue on a bunch of machines.
458 ******************************************************************************/
468 * Workaround for ID strings that have a leading asterisk. This construct
469 * is not allowed by the ACPI specification (ID strings must be
470 * alphanumeric), but enough existing machines have this embedded in their
471 * ID strings that the following code is useful.
478 /* Do the actual copy */
480 ACPI_STRNCPY (Destination, Source, MaxLength);
484 /*******************************************************************************
486 * FUNCTION: AcpiUtExecute_HID
488 * PARAMETERS: DeviceNode - Node for the device
489 * Hid - Where the HID is returned
493 * DESCRIPTION: Executes the _HID control method that returns the hardware
496 * NOTE: Internal function, no parameter validation
498 ******************************************************************************/
502 ACPI_NAMESPACE_NODE *DeviceNode,
505 ACPI_OPERAND_OBJECT *ObjDesc;
509 ACPI_FUNCTION_TRACE (UtExecute_HID);
512 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
513 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
514 if (ACPI_FAILURE (Status))
516 return_ACPI_STATUS (Status);
519 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
521 /* Convert the Numeric HID to string */
523 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, Hid->Value);
527 /* Copy the String HID from the returned object */
529 AcpiUtCopyIdString (Hid->Value, ObjDesc->String.Pointer,
530 sizeof (Hid->Value));
533 /* On exit, we must delete the return object */
535 AcpiUtRemoveReference (ObjDesc);
536 return_ACPI_STATUS (Status);
540 /*******************************************************************************
542 * FUNCTION: AcpiUtTranslateOneCid
544 * PARAMETERS: ObjDesc - _CID object, must be integer or string
545 * OneCid - Where the CID string is returned
549 * DESCRIPTION: Return a numeric or string _CID value as a string.
552 * NOTE: Assumes a maximum _CID string length of
553 * ACPI_MAX_CID_LENGTH.
555 ******************************************************************************/
558 AcpiUtTranslateOneCid (
559 ACPI_OPERAND_OBJECT *ObjDesc,
560 ACPI_COMPATIBLE_ID *OneCid)
564 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
566 case ACPI_TYPE_INTEGER:
568 /* Convert the Numeric CID to string */
570 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, OneCid->Value);
573 case ACPI_TYPE_STRING:
575 if (ObjDesc->String.Length > ACPI_MAX_CID_LENGTH)
577 return (AE_AML_STRING_LIMIT);
580 /* Copy the String CID from the returned object */
582 AcpiUtCopyIdString (OneCid->Value, ObjDesc->String.Pointer,
583 ACPI_MAX_CID_LENGTH);
593 /*******************************************************************************
595 * FUNCTION: AcpiUtExecute_CID
597 * PARAMETERS: DeviceNode - Node for the device
598 * ReturnCidList - Where the CID list is returned
602 * DESCRIPTION: Executes the _CID control method that returns one or more
603 * compatible hardware IDs for the device.
605 * NOTE: Internal function, no parameter validation
607 ******************************************************************************/
611 ACPI_NAMESPACE_NODE *DeviceNode,
612 ACPI_COMPATIBLE_ID_LIST **ReturnCidList)
614 ACPI_OPERAND_OBJECT *ObjDesc;
618 ACPI_COMPATIBLE_ID_LIST *CidList;
622 ACPI_FUNCTION_TRACE (UtExecute_CID);
625 /* Evaluate the _CID method for this device */
627 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
628 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
630 if (ACPI_FAILURE (Status))
632 return_ACPI_STATUS (Status);
635 /* Get the number of _CIDs returned */
638 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
640 Count = ObjDesc->Package.Count;
643 /* Allocate a worst-case buffer for the _CIDs */
645 Size = (((Count - 1) * sizeof (ACPI_COMPATIBLE_ID)) +
646 sizeof (ACPI_COMPATIBLE_ID_LIST));
648 CidList = ACPI_ALLOCATE_ZEROED ((ACPI_SIZE) Size);
651 return_ACPI_STATUS (AE_NO_MEMORY);
656 CidList->Count = Count;
657 CidList->Size = Size;
660 * A _CID can return either a single compatible ID or a package of
661 * compatible IDs. Each compatible ID can be one of the following:
662 * 1) Integer (32 bit compressed EISA ID) or
663 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
666 /* The _CID object can be either a single CID or a package (list) of CIDs */
668 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
670 /* Translate each package element */
672 for (i = 0; i < Count; i++)
674 Status = AcpiUtTranslateOneCid (ObjDesc->Package.Elements[i],
676 if (ACPI_FAILURE (Status))
684 /* Only one CID, translate to a string */
686 Status = AcpiUtTranslateOneCid (ObjDesc, CidList->Id);
689 /* Cleanup on error */
691 if (ACPI_FAILURE (Status))
697 *ReturnCidList = CidList;
700 /* On exit, we must delete the _CID return object */
702 AcpiUtRemoveReference (ObjDesc);
703 return_ACPI_STATUS (Status);
707 /*******************************************************************************
709 * FUNCTION: AcpiUtExecute_UID
711 * PARAMETERS: DeviceNode - Node for the device
712 * Uid - Where the UID is returned
716 * DESCRIPTION: Executes the _UID control method that returns the hardware
719 * NOTE: Internal function, no parameter validation
721 ******************************************************************************/
725 ACPI_NAMESPACE_NODE *DeviceNode,
728 ACPI_OPERAND_OBJECT *ObjDesc;
732 ACPI_FUNCTION_TRACE (UtExecute_UID);
735 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
736 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
737 if (ACPI_FAILURE (Status))
739 return_ACPI_STATUS (Status);
742 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
744 /* Convert the Numeric UID to string */
746 AcpiExUnsignedIntegerToString (ObjDesc->Integer.Value, Uid->Value);
750 /* Copy the String UID from the returned object */
752 AcpiUtCopyIdString (Uid->Value, ObjDesc->String.Pointer,
753 sizeof (Uid->Value));
756 /* On exit, we must delete the return object */
758 AcpiUtRemoveReference (ObjDesc);
759 return_ACPI_STATUS (Status);
763 /*******************************************************************************
765 * FUNCTION: AcpiUtExecute_STA
767 * PARAMETERS: DeviceNode - Node for the device
768 * Flags - Where the status flags are returned
772 * DESCRIPTION: Executes _STA for selected device and stores results in
775 * NOTE: Internal function, no parameter validation
777 ******************************************************************************/
781 ACPI_NAMESPACE_NODE *DeviceNode,
784 ACPI_OPERAND_OBJECT *ObjDesc;
788 ACPI_FUNCTION_TRACE (UtExecute_STA);
791 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
792 ACPI_BTYPE_INTEGER, &ObjDesc);
793 if (ACPI_FAILURE (Status))
795 if (AE_NOT_FOUND == Status)
797 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
798 "_STA on %4.4s was not found, assuming device is present\n",
799 AcpiUtGetNodeName (DeviceNode)));
801 *Flags = ACPI_UINT32_MAX;
805 return_ACPI_STATUS (Status);
808 /* Extract the status flags */
810 *Flags = (UINT32) ObjDesc->Integer.Value;
812 /* On exit, we must delete the return object */
814 AcpiUtRemoveReference (ObjDesc);
815 return_ACPI_STATUS (Status);
819 /*******************************************************************************
821 * FUNCTION: AcpiUtExecute_Sxds
823 * PARAMETERS: DeviceNode - Node for the device
824 * Flags - Where the status flags are returned
828 * DESCRIPTION: Executes _STA for selected device and stores results in
831 * NOTE: Internal function, no parameter validation
833 ******************************************************************************/
837 ACPI_NAMESPACE_NODE *DeviceNode,
840 ACPI_OPERAND_OBJECT *ObjDesc;
845 ACPI_FUNCTION_TRACE (UtExecute_Sxds);
848 for (i = 0; i < 4; i++)
851 Status = AcpiUtEvaluateObject (DeviceNode,
852 ACPI_CAST_PTR (char, AcpiGbl_HighestDstateNames[i]),
853 ACPI_BTYPE_INTEGER, &ObjDesc);
854 if (ACPI_FAILURE (Status))
856 if (Status != AE_NOT_FOUND)
858 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
859 "%s on Device %4.4s, %s\n",
860 ACPI_CAST_PTR (char, AcpiGbl_HighestDstateNames[i]),
861 AcpiUtGetNodeName (DeviceNode),
862 AcpiFormatException (Status)));
864 return_ACPI_STATUS (Status);
869 /* Extract the Dstate value */
871 Highest[i] = (UINT8) ObjDesc->Integer.Value;
873 /* Delete the return object */
875 AcpiUtRemoveReference (ObjDesc);
879 return_ACPI_STATUS (AE_OK);