1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2005, 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);
141 /*******************************************************************************
143 * FUNCTION: AcpiUtOsiImplementation
145 * PARAMETERS: WalkState - Current walk state
149 * DESCRIPTION: Implementation of _OSI predefined control method
150 * Supported = _OSI (String)
152 ******************************************************************************/
155 AcpiUtOsiImplementation (
156 ACPI_WALK_STATE *WalkState)
158 ACPI_OPERAND_OBJECT *StringDesc;
159 ACPI_OPERAND_OBJECT *ReturnDesc;
163 ACPI_FUNCTION_TRACE ("UtOsiImplementation");
166 /* Validate the string input argument */
168 StringDesc = WalkState->Arguments[0].Object;
169 if (!StringDesc || (StringDesc->Common.Type != ACPI_TYPE_STRING))
171 return_ACPI_STATUS (AE_TYPE);
174 /* Create a return object (Default value = 0) */
176 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
179 return_ACPI_STATUS (AE_NO_MEMORY);
182 /* Compare input string to table of supported strings */
184 for (i = 0; i < ACPI_NUM_OSI_STRINGS; i++)
186 if (!ACPI_STRCMP (StringDesc->String.Pointer,
187 (char *) (uintptr_t) AcpiGbl_ValidOsiStrings[i]))
189 /* This string is supported */
191 ReturnDesc->Integer.Value = 0xFFFFFFFF;
196 WalkState->ReturnDesc = ReturnDesc;
197 return_ACPI_STATUS (AE_CTRL_TERMINATE);
201 /*******************************************************************************
203 * FUNCTION: AcpiUtEvaluateObject
205 * PARAMETERS: PrefixNode - Starting node
206 * Path - Path to object from starting node
207 * ExpectedReturnTypes - Bitmap of allowed return types
208 * ReturnDesc - Where a return value is stored
212 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
213 * return object. Common code that simplifies accessing objects
214 * that have required return objects of fixed types.
216 * NOTE: Internal function, no parameter validation
218 ******************************************************************************/
221 AcpiUtEvaluateObject (
222 ACPI_NAMESPACE_NODE *PrefixNode,
224 UINT32 ExpectedReturnBtypes,
225 ACPI_OPERAND_OBJECT **ReturnDesc)
227 ACPI_PARAMETER_INFO Info;
232 ACPI_FUNCTION_TRACE ("UtEvaluateObject");
235 Info.Node = PrefixNode;
236 Info.Parameters = NULL;
237 Info.ParameterType = ACPI_PARAM_ARGS;
239 /* Evaluate the object/method */
241 Status = AcpiNsEvaluateRelative (Path, &Info);
242 if (ACPI_FAILURE (Status))
244 if (Status == AE_NOT_FOUND)
246 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
247 AcpiUtGetNodeName (PrefixNode), Path));
251 ACPI_REPORT_METHOD_ERROR ("Method execution failed",
252 PrefixNode, Path, Status);
255 return_ACPI_STATUS (Status);
258 /* Did we get a return object? */
260 if (!Info.ReturnObject)
262 if (ExpectedReturnBtypes)
264 ACPI_REPORT_METHOD_ERROR ("No object was returned from",
265 PrefixNode, Path, AE_NOT_EXIST);
267 return_ACPI_STATUS (AE_NOT_EXIST);
270 return_ACPI_STATUS (AE_OK);
273 /* Map the return object type to the bitmapped type */
275 switch (ACPI_GET_OBJECT_TYPE (Info.ReturnObject))
277 case ACPI_TYPE_INTEGER:
278 ReturnBtype = ACPI_BTYPE_INTEGER;
281 case ACPI_TYPE_BUFFER:
282 ReturnBtype = ACPI_BTYPE_BUFFER;
285 case ACPI_TYPE_STRING:
286 ReturnBtype = ACPI_BTYPE_STRING;
289 case ACPI_TYPE_PACKAGE:
290 ReturnBtype = ACPI_BTYPE_PACKAGE;
298 if ((AcpiGbl_EnableInterpreterSlack) &&
299 (!ExpectedReturnBtypes))
302 * We received a return object, but one was not expected. This can
303 * happen frequently if the "implicit return" feature is enabled.
304 * Just delete the return object and return AE_OK.
306 AcpiUtRemoveReference (Info.ReturnObject);
307 return_ACPI_STATUS (AE_OK);
310 /* Is the return object one of the expected types? */
312 if (!(ExpectedReturnBtypes & ReturnBtype))
314 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
315 PrefixNode, Path, AE_TYPE);
317 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
318 "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
319 Path, AcpiUtGetObjectTypeName (Info.ReturnObject),
320 ExpectedReturnBtypes));
322 /* On error exit, we must delete the return object */
324 AcpiUtRemoveReference (Info.ReturnObject);
325 return_ACPI_STATUS (AE_TYPE);
328 /* Object type is OK, return it */
330 *ReturnDesc = Info.ReturnObject;
331 return_ACPI_STATUS (AE_OK);
335 /*******************************************************************************
337 * FUNCTION: AcpiUtEvaluateNumericObject
339 * PARAMETERS: ObjectName - Object name to be evaluated
340 * DeviceNode - Node for the device
341 * Address - Where the value is returned
345 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
346 * and stores result in *Address.
348 * NOTE: Internal function, no parameter validation
350 ******************************************************************************/
353 AcpiUtEvaluateNumericObject (
355 ACPI_NAMESPACE_NODE *DeviceNode,
356 ACPI_INTEGER *Address)
358 ACPI_OPERAND_OBJECT *ObjDesc;
362 ACPI_FUNCTION_TRACE ("UtEvaluateNumericObject");
365 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
366 ACPI_BTYPE_INTEGER, &ObjDesc);
367 if (ACPI_FAILURE (Status))
369 return_ACPI_STATUS (Status);
372 /* Get the returned Integer */
374 *Address = ObjDesc->Integer.Value;
376 /* On exit, we must delete the return object */
378 AcpiUtRemoveReference (ObjDesc);
379 return_ACPI_STATUS (Status);
383 /*******************************************************************************
385 * FUNCTION: AcpiUtCopyIdString
387 * PARAMETERS: Destination - Where to copy the string
388 * Source - Source string
389 * MaxLength - Length of the destination buffer
393 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
394 * Performs removal of a leading asterisk if present -- workaround
395 * for a known issue on a bunch of machines.
397 ******************************************************************************/
407 * Workaround for ID strings that have a leading asterisk. This construct
408 * is not allowed by the ACPI specification (ID strings must be
409 * alphanumeric), but enough existing machines have this embedded in their
410 * ID strings that the following code is useful.
417 /* Do the actual copy */
419 ACPI_STRNCPY (Destination, Source, MaxLength);
423 /*******************************************************************************
425 * FUNCTION: AcpiUtExecute_HID
427 * PARAMETERS: DeviceNode - Node for the device
428 * Hid - Where the HID is returned
432 * DESCRIPTION: Executes the _HID control method that returns the hardware
435 * NOTE: Internal function, no parameter validation
437 ******************************************************************************/
441 ACPI_NAMESPACE_NODE *DeviceNode,
444 ACPI_OPERAND_OBJECT *ObjDesc;
448 ACPI_FUNCTION_TRACE ("UtExecute_HID");
451 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
452 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
453 if (ACPI_FAILURE (Status))
455 return_ACPI_STATUS (Status);
458 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
460 /* Convert the Numeric HID to string */
462 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, Hid->Value);
466 /* Copy the String HID from the returned object */
468 AcpiUtCopyIdString (Hid->Value, ObjDesc->String.Pointer,
469 sizeof (Hid->Value));
472 /* On exit, we must delete the return object */
474 AcpiUtRemoveReference (ObjDesc);
475 return_ACPI_STATUS (Status);
479 /*******************************************************************************
481 * FUNCTION: AcpiUtTranslateOneCid
483 * PARAMETERS: ObjDesc - _CID object, must be integer or string
484 * OneCid - Where the CID string is returned
488 * DESCRIPTION: Return a numeric or string _CID value as a string.
491 * NOTE: Assumes a maximum _CID string length of
492 * ACPI_MAX_CID_LENGTH.
494 ******************************************************************************/
497 AcpiUtTranslateOneCid (
498 ACPI_OPERAND_OBJECT *ObjDesc,
499 ACPI_COMPATIBLE_ID *OneCid)
503 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
505 case ACPI_TYPE_INTEGER:
507 /* Convert the Numeric CID to string */
509 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, OneCid->Value);
512 case ACPI_TYPE_STRING:
514 if (ObjDesc->String.Length > ACPI_MAX_CID_LENGTH)
516 return (AE_AML_STRING_LIMIT);
519 /* Copy the String CID from the returned object */
521 AcpiUtCopyIdString (OneCid->Value, ObjDesc->String.Pointer,
522 ACPI_MAX_CID_LENGTH);
532 /*******************************************************************************
534 * FUNCTION: AcpiUtExecute_CID
536 * PARAMETERS: DeviceNode - Node for the device
537 * ReturnCidList - Where the CID list is returned
541 * DESCRIPTION: Executes the _CID control method that returns one or more
542 * compatible hardware IDs for the device.
544 * NOTE: Internal function, no parameter validation
546 ******************************************************************************/
550 ACPI_NAMESPACE_NODE *DeviceNode,
551 ACPI_COMPATIBLE_ID_LIST **ReturnCidList)
553 ACPI_OPERAND_OBJECT *ObjDesc;
557 ACPI_COMPATIBLE_ID_LIST *CidList;
561 ACPI_FUNCTION_TRACE ("UtExecute_CID");
564 /* Evaluate the _CID method for this device */
566 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
567 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
569 if (ACPI_FAILURE (Status))
571 return_ACPI_STATUS (Status);
574 /* Get the number of _CIDs returned */
577 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
579 Count = ObjDesc->Package.Count;
582 /* Allocate a worst-case buffer for the _CIDs */
584 Size = (((Count - 1) * sizeof (ACPI_COMPATIBLE_ID)) +
585 sizeof (ACPI_COMPATIBLE_ID_LIST));
587 CidList = ACPI_MEM_CALLOCATE ((ACPI_SIZE) Size);
590 return_ACPI_STATUS (AE_NO_MEMORY);
595 CidList->Count = Count;
596 CidList->Size = Size;
599 * A _CID can return either a single compatible ID or a package of
600 * compatible IDs. Each compatible ID can be one of the following:
601 * 1) Integer (32 bit compressed EISA ID) or
602 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
605 /* The _CID object can be either a single CID or a package (list) of CIDs */
607 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
609 /* Translate each package element */
611 for (i = 0; i < Count; i++)
613 Status = AcpiUtTranslateOneCid (ObjDesc->Package.Elements[i],
615 if (ACPI_FAILURE (Status))
623 /* Only one CID, translate to a string */
625 Status = AcpiUtTranslateOneCid (ObjDesc, CidList->Id);
628 /* Cleanup on error */
630 if (ACPI_FAILURE (Status))
632 ACPI_MEM_FREE (CidList);
636 *ReturnCidList = CidList;
639 /* On exit, we must delete the _CID return object */
641 AcpiUtRemoveReference (ObjDesc);
642 return_ACPI_STATUS (Status);
646 /*******************************************************************************
648 * FUNCTION: AcpiUtExecute_UID
650 * PARAMETERS: DeviceNode - Node for the device
651 * Uid - Where the UID is returned
655 * DESCRIPTION: Executes the _UID control method that returns the hardware
658 * NOTE: Internal function, no parameter validation
660 ******************************************************************************/
664 ACPI_NAMESPACE_NODE *DeviceNode,
667 ACPI_OPERAND_OBJECT *ObjDesc;
671 ACPI_FUNCTION_TRACE ("UtExecute_UID");
674 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
675 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
676 if (ACPI_FAILURE (Status))
678 return_ACPI_STATUS (Status);
681 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
683 /* Convert the Numeric UID to string */
685 AcpiExUnsignedIntegerToString (ObjDesc->Integer.Value, Uid->Value);
689 /* Copy the String UID from the returned object */
691 AcpiUtCopyIdString (Uid->Value, ObjDesc->String.Pointer,
692 sizeof (Uid->Value));
695 /* On exit, we must delete the return object */
697 AcpiUtRemoveReference (ObjDesc);
698 return_ACPI_STATUS (Status);
702 /*******************************************************************************
704 * FUNCTION: AcpiUtExecute_STA
706 * PARAMETERS: DeviceNode - Node for the device
707 * Flags - Where the status flags are returned
711 * DESCRIPTION: Executes _STA for selected device and stores results in
714 * NOTE: Internal function, no parameter validation
716 ******************************************************************************/
720 ACPI_NAMESPACE_NODE *DeviceNode,
723 ACPI_OPERAND_OBJECT *ObjDesc;
727 ACPI_FUNCTION_TRACE ("UtExecute_STA");
730 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
731 ACPI_BTYPE_INTEGER, &ObjDesc);
732 if (ACPI_FAILURE (Status))
734 if (AE_NOT_FOUND == Status)
736 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
737 "_STA on %4.4s was not found, assuming device is present\n",
738 AcpiUtGetNodeName (DeviceNode)));
744 return_ACPI_STATUS (Status);
747 /* Extract the status flags */
749 *Flags = (UINT32) ObjDesc->Integer.Value;
751 /* On exit, we must delete the return object */
753 AcpiUtRemoveReference (ObjDesc);
754 return_ACPI_STATUS (Status);
758 /*******************************************************************************
760 * FUNCTION: AcpiUtExecute_Sxds
762 * PARAMETERS: DeviceNode - Node for the device
763 * Flags - Where the status flags are returned
767 * DESCRIPTION: Executes _STA for selected device and stores results in
770 * NOTE: Internal function, no parameter validation
772 ******************************************************************************/
776 ACPI_NAMESPACE_NODE *DeviceNode,
779 ACPI_OPERAND_OBJECT *ObjDesc;
784 ACPI_FUNCTION_TRACE ("UtExecute_Sxds");
787 for (i = 0; i < 4; i++)
790 Status = AcpiUtEvaluateObject (DeviceNode,
791 (char *) (uintptr_t) AcpiGbl_HighestDstateNames[i],
792 ACPI_BTYPE_INTEGER, &ObjDesc);
793 if (ACPI_FAILURE (Status))
795 if (Status != AE_NOT_FOUND)
797 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
798 "%s on Device %4.4s, %s\n",
799 (char *) (uintptr_t) AcpiGbl_HighestDstateNames[i],
800 AcpiUtGetNodeName (DeviceNode),
801 AcpiFormatException (Status)));
803 return_ACPI_STATUS (Status);
808 /* Extract the Dstate value */
810 Highest[i] = (UINT8) ObjDesc->Integer.Value;
812 /* Delete the return object */
814 AcpiUtRemoveReference (ObjDesc);
818 return_ACPI_STATUS (AE_OK);