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 *****************************************************************************/
120 #include "acnamesp.h"
121 #include "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 *) 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 if ((AcpiGbl_EnableInterpreterSlack
) &&
286 (!ExpectedReturnBtypes
))
289 * We received a return object, but one was not expected. This can
290 * happen frequently if the "implicit return" feature is enabled.
291 * Just delete the return object and return AE_OK.
293 AcpiUtRemoveReference (Info
.ReturnObject
);
294 return_ACPI_STATUS (AE_OK
);
297 /* Is the return object one of the expected types? */
299 if (!(ExpectedReturnBtypes
& ReturnBtype
))
301 ACPI_REPORT_METHOD_ERROR ("Return object type is incorrect",
302 PrefixNode
, Path
, AE_TYPE
);
304 ACPI_DEBUG_PRINT ((ACPI_DB_ERROR
,
305 "Type returned from %s was incorrect: %s, expected Btypes: %X\n",
306 Path
, AcpiUtGetObjectTypeName (Info
.ReturnObject
),
307 ExpectedReturnBtypes
));
309 /* On error exit, we must delete the return object */
311 AcpiUtRemoveReference (Info
.ReturnObject
);
312 return_ACPI_STATUS (AE_TYPE
);
315 /* Object type is OK, return it */
317 *ReturnDesc
= Info
.ReturnObject
;
318 return_ACPI_STATUS (AE_OK
);
322 /*******************************************************************************
324 * FUNCTION: AcpiUtEvaluateNumericObject
326 * PARAMETERS: *ObjectName - Object name to be evaluated
327 * DeviceNode - Node for the device
328 * *Address - Where the value is returned
332 * DESCRIPTION: Evaluates a numeric namespace object for a selected device
333 * and stores result in *Address.
335 * NOTE: Internal function, no parameter validation
337 ******************************************************************************/
340 AcpiUtEvaluateNumericObject (
342 ACPI_NAMESPACE_NODE
*DeviceNode
,
343 ACPI_INTEGER
*Address
)
345 ACPI_OPERAND_OBJECT
*ObjDesc
;
349 ACPI_FUNCTION_TRACE ("UtEvaluateNumericObject");
352 Status
= AcpiUtEvaluateObject (DeviceNode
, ObjectName
,
353 ACPI_BTYPE_INTEGER
, &ObjDesc
);
354 if (ACPI_FAILURE (Status
))
356 return_ACPI_STATUS (Status
);
359 /* Get the returned Integer */
361 *Address
= ObjDesc
->Integer
.Value
;
363 /* On exit, we must delete the return object */
365 AcpiUtRemoveReference (ObjDesc
);
366 return_ACPI_STATUS (Status
);
370 /*******************************************************************************
372 * FUNCTION: AcpiUtCopyIdString
374 * PARAMETERS: Destination - Where to copy the string
375 * Source - Source string
376 * MaxLength - Length of the destination buffer
380 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
381 * Performs removal of a leading asterisk if present -- workaround
382 * for a known issue on a bunch of machines.
384 ******************************************************************************/
395 * Workaround for ID strings that have a leading asterisk. This construct
396 * is not allowed by the ACPI specification (ID strings must be
397 * alphanumeric), but enough existing machines have this embedded in their
398 * ID strings that the following code is useful.
405 /* Do the actual copy */
407 ACPI_STRNCPY (Destination
, Source
, MaxLength
);
411 /*******************************************************************************
413 * FUNCTION: AcpiUtExecute_HID
415 * PARAMETERS: DeviceNode - Node for the device
416 * *Hid - Where the HID is returned
420 * DESCRIPTION: Executes the _HID control method that returns the hardware
423 * NOTE: Internal function, no parameter validation
425 ******************************************************************************/
429 ACPI_NAMESPACE_NODE
*DeviceNode
,
432 ACPI_OPERAND_OBJECT
*ObjDesc
;
436 ACPI_FUNCTION_TRACE ("UtExecute_HID");
439 Status
= AcpiUtEvaluateObject (DeviceNode
, METHOD_NAME__HID
,
440 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &ObjDesc
);
441 if (ACPI_FAILURE (Status
))
443 return_ACPI_STATUS (Status
);
446 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_INTEGER
)
448 /* Convert the Numeric HID to string */
450 AcpiExEisaIdToString ((UINT32
) ObjDesc
->Integer
.Value
, Hid
->Value
);
454 /* Copy the String HID from the returned object */
456 AcpiUtCopyIdString (Hid
->Value
, ObjDesc
->String
.Pointer
,
457 sizeof (Hid
->Value
));
460 /* On exit, we must delete the return object */
462 AcpiUtRemoveReference (ObjDesc
);
463 return_ACPI_STATUS (Status
);
467 /*******************************************************************************
469 * FUNCTION: AcpiUtTranslateOneCid
471 * PARAMETERS: ObjDesc - _CID object, must be integer or string
472 * OneCid - Where the CID string is returned
476 * DESCRIPTION: Return a numeric or string _CID value as a string.
479 * NOTE: Assumes a maximum _CID string length of
480 * ACPI_MAX_CID_LENGTH.
482 ******************************************************************************/
485 AcpiUtTranslateOneCid (
486 ACPI_OPERAND_OBJECT
*ObjDesc
,
487 ACPI_COMPATIBLE_ID
*OneCid
)
491 switch (ACPI_GET_OBJECT_TYPE (ObjDesc
))
493 case ACPI_TYPE_INTEGER
:
495 /* Convert the Numeric CID to string */
497 AcpiExEisaIdToString ((UINT32
) ObjDesc
->Integer
.Value
, OneCid
->Value
);
500 case ACPI_TYPE_STRING
:
502 if (ObjDesc
->String
.Length
> ACPI_MAX_CID_LENGTH
)
504 return (AE_AML_STRING_LIMIT
);
507 /* Copy the String CID from the returned object */
509 AcpiUtCopyIdString (OneCid
->Value
, ObjDesc
->String
.Pointer
,
510 ACPI_MAX_CID_LENGTH
);
520 /*******************************************************************************
522 * FUNCTION: AcpiUtExecute_CID
524 * PARAMETERS: DeviceNode - Node for the device
525 * *Cid - Where the CID is returned
529 * DESCRIPTION: Executes the _CID control method that returns one or more
530 * compatible hardware IDs for the device.
532 * NOTE: Internal function, no parameter validation
534 ******************************************************************************/
538 ACPI_NAMESPACE_NODE
*DeviceNode
,
539 ACPI_COMPATIBLE_ID_LIST
**ReturnCidList
)
541 ACPI_OPERAND_OBJECT
*ObjDesc
;
545 ACPI_COMPATIBLE_ID_LIST
*CidList
;
549 ACPI_FUNCTION_TRACE ("UtExecute_CID");
552 /* Evaluate the _CID method for this device */
554 Status
= AcpiUtEvaluateObject (DeviceNode
, METHOD_NAME__CID
,
555 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
| ACPI_BTYPE_PACKAGE
,
557 if (ACPI_FAILURE (Status
))
559 return_ACPI_STATUS (Status
);
562 /* Get the number of _CIDs returned */
565 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_PACKAGE
)
567 Count
= ObjDesc
->Package
.Count
;
570 /* Allocate a worst-case buffer for the _CIDs */
572 Size
= (((Count
- 1) * sizeof (ACPI_COMPATIBLE_ID
)) +
573 sizeof (ACPI_COMPATIBLE_ID_LIST
));
575 CidList
= ACPI_MEM_CALLOCATE ((ACPI_SIZE
) Size
);
578 return_ACPI_STATUS (AE_NO_MEMORY
);
583 CidList
->Count
= Count
;
584 CidList
->Size
= Size
;
587 * A _CID can return either a single compatible ID or a package of compatible
588 * IDs. Each compatible ID can be one of the following:
589 * -- Number (32 bit compressed EISA ID) or
590 * -- String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss").
593 /* The _CID object can be either a single CID or a package (list) of CIDs */
595 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_PACKAGE
)
597 /* Translate each package element */
599 for (i
= 0; i
< Count
; i
++)
601 Status
= AcpiUtTranslateOneCid (ObjDesc
->Package
.Elements
[i
],
603 if (ACPI_FAILURE (Status
))
611 /* Only one CID, translate to a string */
613 Status
= AcpiUtTranslateOneCid (ObjDesc
, CidList
->Id
);
616 /* Cleanup on error */
618 if (ACPI_FAILURE (Status
))
620 ACPI_MEM_FREE (CidList
);
624 *ReturnCidList
= CidList
;
627 /* On exit, we must delete the _CID return object */
629 AcpiUtRemoveReference (ObjDesc
);
630 return_ACPI_STATUS (Status
);
634 /*******************************************************************************
636 * FUNCTION: AcpiUtExecute_UID
638 * PARAMETERS: DeviceNode - Node for the device
639 * *Uid - Where the UID is returned
643 * DESCRIPTION: Executes the _UID control method that returns the hardware
646 * NOTE: Internal function, no parameter validation
648 ******************************************************************************/
652 ACPI_NAMESPACE_NODE
*DeviceNode
,
655 ACPI_OPERAND_OBJECT
*ObjDesc
;
659 ACPI_FUNCTION_TRACE ("UtExecute_UID");
662 Status
= AcpiUtEvaluateObject (DeviceNode
, METHOD_NAME__UID
,
663 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
, &ObjDesc
);
664 if (ACPI_FAILURE (Status
))
666 return_ACPI_STATUS (Status
);
669 if (ACPI_GET_OBJECT_TYPE (ObjDesc
) == ACPI_TYPE_INTEGER
)
671 /* Convert the Numeric UID to string */
673 AcpiExUnsignedIntegerToString (ObjDesc
->Integer
.Value
, Uid
->Value
);
677 /* Copy the String UID from the returned object */
679 AcpiUtCopyIdString (Uid
->Value
, ObjDesc
->String
.Pointer
,
680 sizeof (Uid
->Value
));
683 /* On exit, we must delete the return object */
685 AcpiUtRemoveReference (ObjDesc
);
686 return_ACPI_STATUS (Status
);
690 /*******************************************************************************
692 * FUNCTION: AcpiUtExecute_STA
694 * PARAMETERS: DeviceNode - Node for the device
695 * *Flags - Where the status flags are returned
699 * DESCRIPTION: Executes _STA for selected device and stores results in
702 * NOTE: Internal function, no parameter validation
704 ******************************************************************************/
708 ACPI_NAMESPACE_NODE
*DeviceNode
,
711 ACPI_OPERAND_OBJECT
*ObjDesc
;
715 ACPI_FUNCTION_TRACE ("UtExecute_STA");
718 Status
= AcpiUtEvaluateObject (DeviceNode
, METHOD_NAME__STA
,
719 ACPI_BTYPE_INTEGER
, &ObjDesc
);
720 if (ACPI_FAILURE (Status
))
722 if (AE_NOT_FOUND
== Status
)
724 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
725 "_STA on %4.4s was not found, assuming device is present\n",
726 AcpiUtGetNodeName (DeviceNode
)));
732 return_ACPI_STATUS (Status
);
735 /* Extract the status flags */
737 *Flags
= (UINT32
) ObjDesc
->Integer
.Value
;
739 /* On exit, we must delete the return object */
741 AcpiUtRemoveReference (ObjDesc
);
742 return_ACPI_STATUS (Status
);
746 /*******************************************************************************
748 * FUNCTION: AcpiUtExecute_Sxds
750 * PARAMETERS: DeviceNode - Node for the device
751 * *Flags - Where the status flags are returned
755 * DESCRIPTION: Executes _STA for selected device and stores results in
758 * NOTE: Internal function, no parameter validation
760 ******************************************************************************/
764 ACPI_NAMESPACE_NODE
*DeviceNode
,
767 ACPI_OPERAND_OBJECT
*ObjDesc
;
772 ACPI_FUNCTION_TRACE ("UtExecute_Sxds");
775 for (i
= 0; i
< 4; i
++)
778 Status
= AcpiUtEvaluateObject (DeviceNode
,
779 (char *) AcpiGbl_HighestDstateNames
[i
],
780 ACPI_BTYPE_INTEGER
, &ObjDesc
);
781 if (ACPI_FAILURE (Status
))
783 if (Status
!= AE_NOT_FOUND
)
785 ACPI_DEBUG_PRINT ((ACPI_DB_EXEC
,
786 "%s on Device %4.4s, %s\n",
787 (char *) AcpiGbl_HighestDstateNames
[i
],
788 AcpiUtGetNodeName (DeviceNode
),
789 AcpiFormatException (Status
)));
791 return_ACPI_STATUS (Status
);
796 /* Extract the Dstate value */
798 Highest
[i
] = (UINT8
) ObjDesc
->Integer
.Value
;
800 /* Delete the return object */
802 AcpiUtRemoveReference (ObjDesc
);
806 return_ACPI_STATUS (AE_OK
);