1 /******************************************************************************
3 * Module Name: uteval - Object evaluation
6 *****************************************************************************/
8 /******************************************************************************
12 * Some or all of this work - Copyright (c) 1999 - 2004, 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")
128 /*******************************************************************************
130 * FUNCTION: AcpiUtOsiImplementation
132 * PARAMETERS: WalkState - Current walk state
136 * DESCRIPTION: Implementation of _OSI predefined control method
137 * Supported = _OSI (String)
139 ******************************************************************************/
142 AcpiUtOsiImplementation (
143 ACPI_WALK_STATE *WalkState)
145 ACPI_OPERAND_OBJECT *StringDesc;
146 ACPI_OPERAND_OBJECT *ReturnDesc;
150 ACPI_FUNCTION_TRACE ("UtOsiImplementation");
153 /* Validate the string input argument */
155 StringDesc = WalkState->Arguments[0].Object;
156 if (!StringDesc || (StringDesc->Common.Type != ACPI_TYPE_STRING))
158 return_ACPI_STATUS (AE_TYPE);
161 /* Create a return object (Default value = 0) */
163 ReturnDesc = AcpiUtCreateInternalObject (ACPI_TYPE_INTEGER);
166 return_ACPI_STATUS (AE_NO_MEMORY);
169 /* Compare input string to table of supported strings */
171 for (i = 0; i < ACPI_NUM_OSI_STRINGS; i++)
173 if (!ACPI_STRCMP (StringDesc->String.Pointer,
174 (char *) (uintptr_t) AcpiGbl_ValidOsiStrings[i]))
176 /* This string is supported */
178 ReturnDesc->Integer.Value = 0xFFFFFFFF;
183 WalkState->ReturnDesc = ReturnDesc;
184 return_ACPI_STATUS (AE_CTRL_TERMINATE);
188 /*******************************************************************************
190 * FUNCTION: AcpiUtEvaluateObject
192 * PARAMETERS: PrefixNode - Starting node
193 * Path - Path to object from starting node
194 * ExpectedReturnTypes - Bitmap of allowed return types
195 * ReturnDesc - Where a return value is stored
199 * DESCRIPTION: Evaluates a namespace object and verifies the type of the
200 * return object. Common code that simplifies accessing objects
201 * that have required return objects of fixed types.
203 * NOTE: Internal function, no parameter validation
205 ******************************************************************************/
208 AcpiUtEvaluateObject (
209 ACPI_NAMESPACE_NODE *PrefixNode,
211 UINT32 ExpectedReturnBtypes,
212 ACPI_OPERAND_OBJECT **ReturnDesc)
214 ACPI_PARAMETER_INFO Info;
219 ACPI_FUNCTION_TRACE ("UtEvaluateObject");
222 Info.Node = PrefixNode;
223 Info.Parameters = NULL;
224 Info.ParameterType = ACPI_PARAM_ARGS;
226 /* Evaluate the object/method */
228 Status = AcpiNsEvaluateRelative (Path, &Info);
229 if (ACPI_FAILURE (Status))
231 if (Status == AE_NOT_FOUND)
233 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
234 AcpiUtGetNodeName (PrefixNode), Path));
238 ACPI_REPORT_METHOD_ERROR ("Method execution failed",
239 PrefixNode, Path, Status);
242 return_ACPI_STATUS (Status);
245 /* Did we get a return object? */
247 if (!Info.ReturnObject)
249 if (ExpectedReturnBtypes)
251 ACPI_REPORT_METHOD_ERROR ("No object was returned from",
252 PrefixNode, Path, AE_NOT_EXIST);
254 return_ACPI_STATUS (AE_NOT_EXIST);
257 return_ACPI_STATUS (AE_OK);
260 /* Map the return object type to the bitmapped type */
262 switch (ACPI_GET_OBJECT_TYPE (Info.ReturnObject))
264 case ACPI_TYPE_INTEGER:
265 ReturnBtype = ACPI_BTYPE_INTEGER;
268 case ACPI_TYPE_BUFFER:
269 ReturnBtype = ACPI_BTYPE_BUFFER;
272 case ACPI_TYPE_STRING:
273 ReturnBtype = ACPI_BTYPE_STRING;
276 case ACPI_TYPE_PACKAGE:
277 ReturnBtype = ACPI_BTYPE_PACKAGE;
285 /* Is the return object one of the expected types? */
287 if (!(ExpectedReturnBtypes & ReturnBtype))
289 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
290 PrefixNode, Path, AE_TYPE);
292 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
293 "Type returned from %s was incorrect: %X\n",
294 Path, ACPI_GET_OBJECT_TYPE (Info.ReturnObject)));
296 /* On error exit, we must delete the return object */
298 AcpiUtRemoveReference (Info.ReturnObject);
299 return_ACPI_STATUS (AE_TYPE);
302 /* Object type is OK, return it */
304 *ReturnDesc = Info.ReturnObject;
305 return_ACPI_STATUS (AE_OK);
309 /*******************************************************************************
311 * FUNCTION: AcpiUtEvaluateNumericObject
313 * PARAMETERS: *ObjectName - Object name to be evaluated
314 * DeviceNode - Node for the device
315 * *Address - Where the value is returned
319 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
320 * and stores result in *Address.
322 * NOTE: Internal function, no parameter validation
324 ******************************************************************************/
327 AcpiUtEvaluateNumericObject (
329 ACPI_NAMESPACE_NODE *DeviceNode,
330 ACPI_INTEGER *Address)
332 ACPI_OPERAND_OBJECT *ObjDesc;
336 ACPI_FUNCTION_TRACE ("UtEvaluateNumericObject");
339 Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
340 ACPI_BTYPE_INTEGER, &ObjDesc);
341 if (ACPI_FAILURE (Status))
343 return_ACPI_STATUS (Status);
346 /* Get the returned Integer */
348 *Address = ObjDesc->Integer.Value;
350 /* On exit, we must delete the return object */
352 AcpiUtRemoveReference (ObjDesc);
353 return_ACPI_STATUS (Status);
357 /*******************************************************************************
359 * FUNCTION: AcpiUtCopyIdString
361 * PARAMETERS: Destination - Where to copy the string
362 * Source - Source string
363 * MaxLength - Length of the destination buffer
367 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
368 * Performs removal of a leading asterisk if present -- workaround
369 * for a known issue on a bunch of machines.
371 ******************************************************************************/
382 * Workaround for ID strings that have a leading asterisk. This construct
383 * is not allowed by the ACPI specification (ID strings must be
384 * alphanumeric), but enough existing machines have this embedded in their
385 * ID strings that the following code is useful.
392 /* Do the actual copy */
394 ACPI_STRNCPY (Destination, Source, MaxLength);
398 /*******************************************************************************
400 * FUNCTION: AcpiUtExecute_HID
402 * PARAMETERS: DeviceNode - Node for the device
403 * *Hid - Where the HID is returned
407 * DESCRIPTION: Executes the _HID control method that returns the hardware
410 * NOTE: Internal function, no parameter validation
412 ******************************************************************************/
416 ACPI_NAMESPACE_NODE *DeviceNode,
419 ACPI_OPERAND_OBJECT *ObjDesc;
423 ACPI_FUNCTION_TRACE ("UtExecute_HID");
426 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
427 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
428 if (ACPI_FAILURE (Status))
430 return_ACPI_STATUS (Status);
433 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
435 /* Convert the Numeric HID to string */
437 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, Hid->Value);
441 /* Copy the String HID from the returned object */
443 AcpiUtCopyIdString (Hid->Value, ObjDesc->String.Pointer,
444 sizeof (Hid->Value));
447 /* On exit, we must delete the return object */
449 AcpiUtRemoveReference (ObjDesc);
450 return_ACPI_STATUS (Status);
454 /*******************************************************************************
456 * FUNCTION: AcpiUtTranslateOneCid
458 * PARAMETERS: ObjDesc - _CID object, must be integer or string
459 * OneCid - Where the CID string is returned
463 * DESCRIPTION: Return a numeric or string _CID value as a string.
466 * NOTE: Assumes a maximum _CID string length of
467 * ACPI_MAX_CID_LENGTH.
469 ******************************************************************************/
472 AcpiUtTranslateOneCid (
473 ACPI_OPERAND_OBJECT *ObjDesc,
474 ACPI_COMPATIBLE_ID *OneCid)
478 switch (ACPI_GET_OBJECT_TYPE (ObjDesc))
480 case ACPI_TYPE_INTEGER:
482 /* Convert the Numeric CID to string */
484 AcpiExEisaIdToString ((UINT32) ObjDesc->Integer.Value, OneCid->Value);
487 case ACPI_TYPE_STRING:
489 if (ObjDesc->String.Length > ACPI_MAX_CID_LENGTH)
491 return (AE_AML_STRING_LIMIT);
494 /* Copy the String CID from the returned object */
496 AcpiUtCopyIdString (OneCid->Value, ObjDesc->String.Pointer,
497 ACPI_MAX_CID_LENGTH);
507 /*******************************************************************************
509 * FUNCTION: AcpiUtExecute_CID
511 * PARAMETERS: DeviceNode - Node for the device
512 * *Cid - Where the CID is returned
516 * DESCRIPTION: Executes the _CID control method that returns one or more
517 * compatible hardware IDs for the device.
519 * NOTE: Internal function, no parameter validation
521 ******************************************************************************/
525 ACPI_NAMESPACE_NODE *DeviceNode,
526 ACPI_COMPATIBLE_ID_LIST **ReturnCidList)
528 ACPI_OPERAND_OBJECT *ObjDesc;
532 ACPI_COMPATIBLE_ID_LIST *CidList;
536 ACPI_FUNCTION_TRACE ("UtExecute_CID");
539 /* Evaluate the _CID method for this device */
541 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
542 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
544 if (ACPI_FAILURE (Status))
546 return_ACPI_STATUS (Status);
549 /* Get the number of _CIDs returned */
552 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
554 Count = ObjDesc->Package.Count;
557 /* Allocate a worst-case buffer for the _CIDs */
559 Size = (((Count - 1) * sizeof (ACPI_COMPATIBLE_ID)) +
560 sizeof (ACPI_COMPATIBLE_ID_LIST));
562 CidList = ACPI_MEM_CALLOCATE ((ACPI_SIZE) Size);
565 return_ACPI_STATUS (AE_NO_MEMORY);
570 CidList->Count = Count;
571 CidList->Size = Size;
574 * A _CID can return either a single compatible ID or a package of compatible
575 * IDs. Each compatible ID can be one of the following:
576 * -- Number (32 bit compressed EISA ID) or
577 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss").
580 /* The _CID object can be either a single CID or a package (list) of CIDs */
582 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_PACKAGE)
584 /* Translate each package element */
586 for (i = 0; i < Count; i++)
588 Status = AcpiUtTranslateOneCid (ObjDesc->Package.Elements[i],
590 if (ACPI_FAILURE (Status))
598 /* Only one CID, translate to a string */
600 Status = AcpiUtTranslateOneCid (ObjDesc, CidList->Id);
603 /* Cleanup on error */
605 if (ACPI_FAILURE (Status))
607 ACPI_MEM_FREE (CidList);
611 *ReturnCidList = CidList;
614 /* On exit, we must delete the _CID return object */
616 AcpiUtRemoveReference (ObjDesc);
617 return_ACPI_STATUS (Status);
621 /*******************************************************************************
623 * FUNCTION: AcpiUtExecute_UID
625 * PARAMETERS: DeviceNode - Node for the device
626 * *Uid - Where the UID is returned
630 * DESCRIPTION: Executes the _UID control method that returns the hardware
633 * NOTE: Internal function, no parameter validation
635 ******************************************************************************/
639 ACPI_NAMESPACE_NODE *DeviceNode,
642 ACPI_OPERAND_OBJECT *ObjDesc;
646 ACPI_FUNCTION_TRACE ("UtExecute_UID");
649 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
650 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
651 if (ACPI_FAILURE (Status))
653 return_ACPI_STATUS (Status);
656 if (ACPI_GET_OBJECT_TYPE (ObjDesc) == ACPI_TYPE_INTEGER)
658 /* Convert the Numeric UID to string */
660 AcpiExUnsignedIntegerToString (ObjDesc->Integer.Value, Uid->Value);
664 /* Copy the String UID from the returned object */
666 AcpiUtCopyIdString (Uid->Value, ObjDesc->String.Pointer,
667 sizeof (Uid->Value));
670 /* On exit, we must delete the return object */
672 AcpiUtRemoveReference (ObjDesc);
673 return_ACPI_STATUS (Status);
677 /*******************************************************************************
679 * FUNCTION: AcpiUtExecute_STA
681 * PARAMETERS: DeviceNode - Node for the device
682 * *Flags - Where the status flags are returned
686 * DESCRIPTION: Executes _STA for selected device and stores results in
689 * NOTE: Internal function, no parameter validation
691 ******************************************************************************/
695 ACPI_NAMESPACE_NODE *DeviceNode,
698 ACPI_OPERAND_OBJECT *ObjDesc;
702 ACPI_FUNCTION_TRACE ("UtExecute_STA");
705 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
706 ACPI_BTYPE_INTEGER, &ObjDesc);
707 if (ACPI_FAILURE (Status))
709 if (AE_NOT_FOUND == Status)
711 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
712 "_STA on %4.4s was not found, assuming device is present\n",
713 AcpiUtGetNodeName (DeviceNode)));
719 return_ACPI_STATUS (Status);
722 /* Extract the status flags */
724 *Flags = (UINT32) ObjDesc->Integer.Value;
726 /* On exit, we must delete the return object */
728 AcpiUtRemoveReference (ObjDesc);
729 return_ACPI_STATUS (Status);
733 /*******************************************************************************
735 * FUNCTION: AcpiUtExecute_Sxds
737 * PARAMETERS: DeviceNode - Node for the device
738 * *Flags - Where the status flags are returned
742 * DESCRIPTION: Executes _STA for selected device and stores results in
745 * NOTE: Internal function, no parameter validation
747 ******************************************************************************/
751 ACPI_NAMESPACE_NODE *DeviceNode,
754 ACPI_OPERAND_OBJECT *ObjDesc;
759 ACPI_FUNCTION_TRACE ("UtExecute_Sxds");
762 for (i = 0; i < 4; i++)
765 Status = AcpiUtEvaluateObject (DeviceNode,
766 (char *) (uintptr_t) AcpiGbl_HighestDstateNames[i],
767 ACPI_BTYPE_INTEGER, &ObjDesc);
768 if (ACPI_FAILURE (Status))
770 if (Status != AE_NOT_FOUND)
772 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
773 "%s on Device %4.4s, %s\n",
774 (char *) (uintptr_t) AcpiGbl_HighestDstateNames[i],
775 AcpiUtGetNodeName (DeviceNode),
776 AcpiFormatException (Status)));
778 return_ACPI_STATUS (Status);
783 /* Extract the Dstate value */
785 Highest[i] = (UINT8) ObjDesc->Integer.Value;
787 /* Delete the return object */
789 AcpiUtRemoveReference (ObjDesc);
793 return_ACPI_STATUS (AE_OK);