xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/utilities/uteval.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: uteval - Object evaluation
40174267aSFredrik Holmqvist  *
50174267aSFredrik Holmqvist  *****************************************************************************/
60174267aSFredrik Holmqvist 
70174267aSFredrik Holmqvist /******************************************************************************
80174267aSFredrik Holmqvist  *
90174267aSFredrik Holmqvist  * 1. Copyright Notice
100174267aSFredrik Holmqvist  *
11*6dde014fSPulkoMandy  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
120174267aSFredrik Holmqvist  * All rights reserved.
130174267aSFredrik Holmqvist  *
140174267aSFredrik Holmqvist  * 2. License
150174267aSFredrik Holmqvist  *
160174267aSFredrik Holmqvist  * 2.1. This is your license from Intel Corp. under its intellectual property
170174267aSFredrik Holmqvist  * rights. You may have additional license terms from the party that provided
180174267aSFredrik Holmqvist  * you this software, covering your right to use that party's intellectual
190174267aSFredrik Holmqvist  * property rights.
200174267aSFredrik Holmqvist  *
210174267aSFredrik Holmqvist  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
220174267aSFredrik Holmqvist  * copy of the source code appearing in this file ("Covered Code") an
230174267aSFredrik Holmqvist  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
240174267aSFredrik Holmqvist  * base code distributed originally by Intel ("Original Intel Code") to copy,
250174267aSFredrik Holmqvist  * make derivatives, distribute, use and display any portion of the Covered
260174267aSFredrik Holmqvist  * Code in any form, with the right to sublicense such rights; and
270174267aSFredrik Holmqvist  *
280174267aSFredrik Holmqvist  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
290174267aSFredrik Holmqvist  * license (with the right to sublicense), under only those claims of Intel
300174267aSFredrik Holmqvist  * patents that are infringed by the Original Intel Code, to make, use, sell,
310174267aSFredrik Holmqvist  * offer to sell, and import the Covered Code and derivative works thereof
320174267aSFredrik Holmqvist  * solely to the minimum extent necessary to exercise the above copyright
330174267aSFredrik Holmqvist  * license, and in no event shall the patent license extend to any additions
340174267aSFredrik Holmqvist  * to or modifications of the Original Intel Code. No other license or right
350174267aSFredrik Holmqvist  * is granted directly or by implication, estoppel or otherwise;
360174267aSFredrik Holmqvist  *
370174267aSFredrik Holmqvist  * The above copyright and patent license is granted only if the following
380174267aSFredrik Holmqvist  * conditions are met:
390174267aSFredrik Holmqvist  *
400174267aSFredrik Holmqvist  * 3. Conditions
410174267aSFredrik Holmqvist  *
420174267aSFredrik Holmqvist  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
430174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
440174267aSFredrik Holmqvist  * Code or modification with rights to further distribute source must include
450174267aSFredrik Holmqvist  * the above Copyright Notice, the above License, this list of Conditions,
460174267aSFredrik Holmqvist  * and the following Disclaimer and Export Compliance provision. In addition,
470174267aSFredrik Holmqvist  * Licensee must cause all Covered Code to which Licensee contributes to
480174267aSFredrik Holmqvist  * contain a file documenting the changes Licensee made to create that Covered
490174267aSFredrik Holmqvist  * Code and the date of any change. Licensee must include in that file the
500174267aSFredrik Holmqvist  * documentation of any changes made by any predecessor Licensee. Licensee
510174267aSFredrik Holmqvist  * must include a prominent statement that the modification is derived,
520174267aSFredrik Holmqvist  * directly or indirectly, from Original Intel Code.
530174267aSFredrik Holmqvist  *
540174267aSFredrik Holmqvist  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
550174267aSFredrik Holmqvist  * Redistribution of source code of any substantial portion of the Covered
560174267aSFredrik Holmqvist  * Code or modification without rights to further distribute source must
570174267aSFredrik Holmqvist  * include the following Disclaimer and Export Compliance provision in the
580174267aSFredrik Holmqvist  * documentation and/or other materials provided with distribution. In
590174267aSFredrik Holmqvist  * addition, Licensee may not authorize further sublicense of source of any
600174267aSFredrik Holmqvist  * portion of the Covered Code, and must include terms to the effect that the
610174267aSFredrik Holmqvist  * license from Licensee to its licensee is limited to the intellectual
620174267aSFredrik Holmqvist  * property embodied in the software Licensee provides to its licensee, and
630174267aSFredrik Holmqvist  * not to intellectual property embodied in modifications its licensee may
640174267aSFredrik Holmqvist  * make.
650174267aSFredrik Holmqvist  *
660174267aSFredrik Holmqvist  * 3.3. Redistribution of Executable. Redistribution in executable form of any
670174267aSFredrik Holmqvist  * substantial portion of the Covered Code or modification must reproduce the
680174267aSFredrik Holmqvist  * above Copyright Notice, and the following Disclaimer and Export Compliance
690174267aSFredrik Holmqvist  * provision in the documentation and/or other materials provided with the
700174267aSFredrik Holmqvist  * distribution.
710174267aSFredrik Holmqvist  *
720174267aSFredrik Holmqvist  * 3.4. Intel retains all right, title, and interest in and to the Original
730174267aSFredrik Holmqvist  * Intel Code.
740174267aSFredrik Holmqvist  *
750174267aSFredrik Holmqvist  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
760174267aSFredrik Holmqvist  * Intel shall be used in advertising or otherwise to promote the sale, use or
770174267aSFredrik Holmqvist  * other dealings in products derived from or relating to the Covered Code
780174267aSFredrik Holmqvist  * without prior written authorization from Intel.
790174267aSFredrik Holmqvist  *
800174267aSFredrik Holmqvist  * 4. Disclaimer and Export Compliance
810174267aSFredrik Holmqvist  *
820174267aSFredrik Holmqvist  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
830174267aSFredrik Holmqvist  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
840174267aSFredrik Holmqvist  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
850174267aSFredrik Holmqvist  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
860174267aSFredrik Holmqvist  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
870174267aSFredrik Holmqvist  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
880174267aSFredrik Holmqvist  * PARTICULAR PURPOSE.
890174267aSFredrik Holmqvist  *
900174267aSFredrik Holmqvist  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
910174267aSFredrik Holmqvist  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
920174267aSFredrik Holmqvist  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
930174267aSFredrik Holmqvist  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
940174267aSFredrik Holmqvist  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
950174267aSFredrik Holmqvist  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
960174267aSFredrik Holmqvist  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
970174267aSFredrik Holmqvist  * LIMITED REMEDY.
980174267aSFredrik Holmqvist  *
990174267aSFredrik Holmqvist  * 4.3. Licensee shall not export, either directly or indirectly, any of this
1000174267aSFredrik Holmqvist  * software or system incorporating such software without first obtaining any
1010174267aSFredrik Holmqvist  * required license or other approval from the U. S. Department of Commerce or
1020174267aSFredrik Holmqvist  * any other agency or department of the United States Government. In the
1030174267aSFredrik Holmqvist  * event Licensee exports any such software from the United States or
1040174267aSFredrik Holmqvist  * re-exports any such software from a foreign destination, Licensee shall
1050174267aSFredrik Holmqvist  * ensure that the distribution and export/re-export of the software is in
1060174267aSFredrik Holmqvist  * compliance with all laws, regulations, orders, or other restrictions of the
1070174267aSFredrik Holmqvist  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
1080174267aSFredrik Holmqvist  * any of its subsidiaries will export/re-export any technical data, process,
1090174267aSFredrik Holmqvist  * software, or service, directly or indirectly, to any country for which the
1100174267aSFredrik Holmqvist  * United States government or any agency thereof requires an export license,
1110174267aSFredrik Holmqvist  * other governmental approval, or letter of assurance, without first obtaining
1120174267aSFredrik Holmqvist  * such license, approval or letter.
1130174267aSFredrik Holmqvist  *
114ff2e2f81SFredrik Holmqvist  *****************************************************************************
115ff2e2f81SFredrik Holmqvist  *
116ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
117ff2e2f81SFredrik Holmqvist  * following license:
118ff2e2f81SFredrik Holmqvist  *
119ff2e2f81SFredrik Holmqvist  * Redistribution and use in source and binary forms, with or without
120ff2e2f81SFredrik Holmqvist  * modification, are permitted provided that the following conditions
121ff2e2f81SFredrik Holmqvist  * are met:
122ff2e2f81SFredrik Holmqvist  * 1. Redistributions of source code must retain the above copyright
123ff2e2f81SFredrik Holmqvist  *    notice, this list of conditions, and the following disclaimer,
124ff2e2f81SFredrik Holmqvist  *    without modification.
125ff2e2f81SFredrik Holmqvist  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
126ff2e2f81SFredrik Holmqvist  *    substantially similar to the "NO WARRANTY" disclaimer below
127ff2e2f81SFredrik Holmqvist  *    ("Disclaimer") and any redistribution must be conditioned upon
128ff2e2f81SFredrik Holmqvist  *    including a substantially similar Disclaimer requirement for further
129ff2e2f81SFredrik Holmqvist  *    binary redistribution.
130ff2e2f81SFredrik Holmqvist  * 3. Neither the names of the above-listed copyright holders nor the names
131ff2e2f81SFredrik Holmqvist  *    of any contributors may be used to endorse or promote products derived
132ff2e2f81SFredrik Holmqvist  *    from this software without specific prior written permission.
133ff2e2f81SFredrik Holmqvist  *
134ff2e2f81SFredrik Holmqvist  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
135ff2e2f81SFredrik Holmqvist  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136ff2e2f81SFredrik Holmqvist  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
137ff2e2f81SFredrik Holmqvist  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138ff2e2f81SFredrik Holmqvist  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139ff2e2f81SFredrik Holmqvist  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140ff2e2f81SFredrik Holmqvist  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141ff2e2f81SFredrik Holmqvist  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142ff2e2f81SFredrik Holmqvist  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143ff2e2f81SFredrik Holmqvist  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144ff2e2f81SFredrik Holmqvist  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145ff2e2f81SFredrik Holmqvist  *
146ff2e2f81SFredrik Holmqvist  * Alternatively, you may choose to be licensed under the terms of the
147ff2e2f81SFredrik Holmqvist  * GNU General Public License ("GPL") version 2 as published by the Free
148ff2e2f81SFredrik Holmqvist  * Software Foundation.
149ff2e2f81SFredrik Holmqvist  *
1500174267aSFredrik Holmqvist  *****************************************************************************/
1510174267aSFredrik Holmqvist 
1520174267aSFredrik Holmqvist #include "acpi.h"
1530174267aSFredrik Holmqvist #include "accommon.h"
1540174267aSFredrik Holmqvist #include "acnamesp.h"
1550174267aSFredrik Holmqvist 
1560174267aSFredrik Holmqvist 
1570174267aSFredrik Holmqvist #define _COMPONENT          ACPI_UTILITIES
1580174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("uteval")
1590174267aSFredrik Holmqvist 
1600174267aSFredrik Holmqvist 
1610174267aSFredrik Holmqvist /*******************************************************************************
1620174267aSFredrik Holmqvist  *
1630174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtEvaluateObject
1640174267aSFredrik Holmqvist  *
1650174267aSFredrik Holmqvist  * PARAMETERS:  PrefixNode          - Starting node
1660174267aSFredrik Holmqvist  *              Path                - Path to object from starting node
1670174267aSFredrik Holmqvist  *              ExpectedReturnTypes - Bitmap of allowed return types
1680174267aSFredrik Holmqvist  *              ReturnDesc          - Where a return value is stored
1690174267aSFredrik Holmqvist  *
1700174267aSFredrik Holmqvist  * RETURN:      Status
1710174267aSFredrik Holmqvist  *
1720174267aSFredrik Holmqvist  * DESCRIPTION: Evaluates a namespace object and verifies the type of the
1730174267aSFredrik Holmqvist  *              return object. Common code that simplifies accessing objects
1740174267aSFredrik Holmqvist  *              that have required return objects of fixed types.
1750174267aSFredrik Holmqvist  *
1760174267aSFredrik Holmqvist  *              NOTE: Internal function, no parameter validation
1770174267aSFredrik Holmqvist  *
1780174267aSFredrik Holmqvist  ******************************************************************************/
1790174267aSFredrik Holmqvist 
1800174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtEvaluateObject(ACPI_NAMESPACE_NODE * PrefixNode,const char * Path,UINT32 ExpectedReturnBtypes,ACPI_OPERAND_OBJECT ** ReturnDesc)1810174267aSFredrik Holmqvist AcpiUtEvaluateObject (
1820174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *PrefixNode,
18374ffd18dSFredrik Holmqvist     const char              *Path,
1840174267aSFredrik Holmqvist     UINT32                  ExpectedReturnBtypes,
1850174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     **ReturnDesc)
1860174267aSFredrik Holmqvist {
1870174267aSFredrik Holmqvist     ACPI_EVALUATE_INFO      *Info;
1880174267aSFredrik Holmqvist     ACPI_STATUS             Status;
1890174267aSFredrik Holmqvist     UINT32                  ReturnBtype;
1900174267aSFredrik Holmqvist 
1910174267aSFredrik Holmqvist 
1920174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtEvaluateObject);
1930174267aSFredrik Holmqvist 
1940174267aSFredrik Holmqvist 
1950174267aSFredrik Holmqvist     /* Allocate the evaluation information block */
1960174267aSFredrik Holmqvist 
1970174267aSFredrik Holmqvist     Info = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_EVALUATE_INFO));
1980174267aSFredrik Holmqvist     if (!Info)
1990174267aSFredrik Holmqvist     {
2000174267aSFredrik Holmqvist         return_ACPI_STATUS (AE_NO_MEMORY);
2010174267aSFredrik Holmqvist     }
2020174267aSFredrik Holmqvist 
2030174267aSFredrik Holmqvist     Info->PrefixNode = PrefixNode;
204c70258b7SJérôme Duval     Info->RelativePathname = Path;
2050174267aSFredrik Holmqvist 
2060174267aSFredrik Holmqvist     /* Evaluate the object/method */
2070174267aSFredrik Holmqvist 
2080174267aSFredrik Holmqvist     Status = AcpiNsEvaluate (Info);
2090174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
2100174267aSFredrik Holmqvist     {
2110174267aSFredrik Holmqvist         if (Status == AE_NOT_FOUND)
2120174267aSFredrik Holmqvist         {
2130174267aSFredrik Holmqvist             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "[%4.4s.%s] was not found\n",
2140174267aSFredrik Holmqvist                 AcpiUtGetNodeName (PrefixNode), Path));
2150174267aSFredrik Holmqvist         }
2160174267aSFredrik Holmqvist         else
2170174267aSFredrik Holmqvist         {
2180174267aSFredrik Holmqvist             ACPI_ERROR_METHOD ("Method execution failed",
2190174267aSFredrik Holmqvist                 PrefixNode, Path, Status);
2200174267aSFredrik Holmqvist         }
2210174267aSFredrik Holmqvist 
2220174267aSFredrik Holmqvist         goto Cleanup;
2230174267aSFredrik Holmqvist     }
2240174267aSFredrik Holmqvist 
2250174267aSFredrik Holmqvist     /* Did we get a return object? */
2260174267aSFredrik Holmqvist 
2270174267aSFredrik Holmqvist     if (!Info->ReturnObject)
2280174267aSFredrik Holmqvist     {
2290174267aSFredrik Holmqvist         if (ExpectedReturnBtypes)
2300174267aSFredrik Holmqvist         {
2310174267aSFredrik Holmqvist             ACPI_ERROR_METHOD ("No object was returned from",
2320174267aSFredrik Holmqvist                 PrefixNode, Path, AE_NOT_EXIST);
2330174267aSFredrik Holmqvist 
2340174267aSFredrik Holmqvist             Status = AE_NOT_EXIST;
2350174267aSFredrik Holmqvist         }
2360174267aSFredrik Holmqvist 
2370174267aSFredrik Holmqvist         goto Cleanup;
2380174267aSFredrik Holmqvist     }
2390174267aSFredrik Holmqvist 
2400174267aSFredrik Holmqvist     /* Map the return object type to the bitmapped type */
2410174267aSFredrik Holmqvist 
2420174267aSFredrik Holmqvist     switch ((Info->ReturnObject)->Common.Type)
2430174267aSFredrik Holmqvist     {
2440174267aSFredrik Holmqvist     case ACPI_TYPE_INTEGER:
245c70258b7SJérôme Duval 
2460174267aSFredrik Holmqvist         ReturnBtype = ACPI_BTYPE_INTEGER;
2470174267aSFredrik Holmqvist         break;
2480174267aSFredrik Holmqvist 
2490174267aSFredrik Holmqvist     case ACPI_TYPE_BUFFER:
250c70258b7SJérôme Duval 
2510174267aSFredrik Holmqvist         ReturnBtype = ACPI_BTYPE_BUFFER;
2520174267aSFredrik Holmqvist         break;
2530174267aSFredrik Holmqvist 
2540174267aSFredrik Holmqvist     case ACPI_TYPE_STRING:
255c70258b7SJérôme Duval 
2560174267aSFredrik Holmqvist         ReturnBtype = ACPI_BTYPE_STRING;
2570174267aSFredrik Holmqvist         break;
2580174267aSFredrik Holmqvist 
2590174267aSFredrik Holmqvist     case ACPI_TYPE_PACKAGE:
260c70258b7SJérôme Duval 
2610174267aSFredrik Holmqvist         ReturnBtype = ACPI_BTYPE_PACKAGE;
2620174267aSFredrik Holmqvist         break;
2630174267aSFredrik Holmqvist 
2640174267aSFredrik Holmqvist     default:
265c70258b7SJérôme Duval 
2660174267aSFredrik Holmqvist         ReturnBtype = 0;
2670174267aSFredrik Holmqvist         break;
2680174267aSFredrik Holmqvist     }
2690174267aSFredrik Holmqvist 
2700174267aSFredrik Holmqvist     if ((AcpiGbl_EnableInterpreterSlack) &&
2710174267aSFredrik Holmqvist         (!ExpectedReturnBtypes))
2720174267aSFredrik Holmqvist     {
2730174267aSFredrik Holmqvist         /*
2740174267aSFredrik Holmqvist          * We received a return object, but one was not expected. This can
2750174267aSFredrik Holmqvist          * happen frequently if the "implicit return" feature is enabled.
2760174267aSFredrik Holmqvist          * Just delete the return object and return AE_OK.
2770174267aSFredrik Holmqvist          */
2780174267aSFredrik Holmqvist         AcpiUtRemoveReference (Info->ReturnObject);
2790174267aSFredrik Holmqvist         goto Cleanup;
2800174267aSFredrik Holmqvist     }
2810174267aSFredrik Holmqvist 
2820174267aSFredrik Holmqvist     /* Is the return object one of the expected types? */
2830174267aSFredrik Holmqvist 
2840174267aSFredrik Holmqvist     if (!(ExpectedReturnBtypes & ReturnBtype))
2850174267aSFredrik Holmqvist     {
2860174267aSFredrik Holmqvist         ACPI_ERROR_METHOD ("Return object type is incorrect",
2870174267aSFredrik Holmqvist             PrefixNode, Path, AE_TYPE);
2880174267aSFredrik Holmqvist 
2890174267aSFredrik Holmqvist         ACPI_ERROR ((AE_INFO,
2900174267aSFredrik Holmqvist             "Type returned from %s was incorrect: %s, expected Btypes: 0x%X",
2910174267aSFredrik Holmqvist             Path, AcpiUtGetObjectTypeName (Info->ReturnObject),
2920174267aSFredrik Holmqvist             ExpectedReturnBtypes));
2930174267aSFredrik Holmqvist 
2940174267aSFredrik Holmqvist         /* On error exit, we must delete the return object */
2950174267aSFredrik Holmqvist 
2960174267aSFredrik Holmqvist         AcpiUtRemoveReference (Info->ReturnObject);
2970174267aSFredrik Holmqvist         Status = AE_TYPE;
2980174267aSFredrik Holmqvist         goto Cleanup;
2990174267aSFredrik Holmqvist     }
3000174267aSFredrik Holmqvist 
3010174267aSFredrik Holmqvist     /* Object type is OK, return it */
3020174267aSFredrik Holmqvist 
3030174267aSFredrik Holmqvist     *ReturnDesc = Info->ReturnObject;
3040174267aSFredrik Holmqvist 
3050174267aSFredrik Holmqvist Cleanup:
3060174267aSFredrik Holmqvist     ACPI_FREE (Info);
3070174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
3080174267aSFredrik Holmqvist }
3090174267aSFredrik Holmqvist 
3100174267aSFredrik Holmqvist 
3110174267aSFredrik Holmqvist /*******************************************************************************
3120174267aSFredrik Holmqvist  *
3130174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtEvaluateNumericObject
3140174267aSFredrik Holmqvist  *
3150174267aSFredrik Holmqvist  * PARAMETERS:  ObjectName          - Object name to be evaluated
3160174267aSFredrik Holmqvist  *              DeviceNode          - Node for the device
3170174267aSFredrik Holmqvist  *              Value               - Where the value is returned
3180174267aSFredrik Holmqvist  *
3190174267aSFredrik Holmqvist  * RETURN:      Status
3200174267aSFredrik Holmqvist  *
3210174267aSFredrik Holmqvist  * DESCRIPTION: Evaluates a numeric namespace object for a selected device
3220174267aSFredrik Holmqvist  *              and stores result in *Value.
3230174267aSFredrik Holmqvist  *
3240174267aSFredrik Holmqvist  *              NOTE: Internal function, no parameter validation
3250174267aSFredrik Holmqvist  *
3260174267aSFredrik Holmqvist  ******************************************************************************/
3270174267aSFredrik Holmqvist 
3280174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtEvaluateNumericObject(const char * ObjectName,ACPI_NAMESPACE_NODE * DeviceNode,UINT64 * Value)3290174267aSFredrik Holmqvist AcpiUtEvaluateNumericObject (
33074ffd18dSFredrik Holmqvist     const char              *ObjectName,
3310174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *DeviceNode,
3320174267aSFredrik Holmqvist     UINT64                  *Value)
3330174267aSFredrik Holmqvist {
3340174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
3350174267aSFredrik Holmqvist     ACPI_STATUS             Status;
3360174267aSFredrik Holmqvist 
3370174267aSFredrik Holmqvist 
3380174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtEvaluateNumericObject);
3390174267aSFredrik Holmqvist 
3400174267aSFredrik Holmqvist 
3410174267aSFredrik Holmqvist     Status = AcpiUtEvaluateObject (DeviceNode, ObjectName,
3420174267aSFredrik Holmqvist         ACPI_BTYPE_INTEGER, &ObjDesc);
3430174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3440174267aSFredrik Holmqvist     {
3450174267aSFredrik Holmqvist         return_ACPI_STATUS (Status);
3460174267aSFredrik Holmqvist     }
3470174267aSFredrik Holmqvist 
3480174267aSFredrik Holmqvist     /* Get the returned Integer */
3490174267aSFredrik Holmqvist 
3500174267aSFredrik Holmqvist     *Value = ObjDesc->Integer.Value;
3510174267aSFredrik Holmqvist 
3520174267aSFredrik Holmqvist     /* On exit, we must delete the return object */
3530174267aSFredrik Holmqvist 
3540174267aSFredrik Holmqvist     AcpiUtRemoveReference (ObjDesc);
3550174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
3560174267aSFredrik Holmqvist }
3570174267aSFredrik Holmqvist 
3580174267aSFredrik Holmqvist 
3590174267aSFredrik Holmqvist /*******************************************************************************
3600174267aSFredrik Holmqvist  *
3610174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtExecute_STA
3620174267aSFredrik Holmqvist  *
3630174267aSFredrik Holmqvist  * PARAMETERS:  DeviceNode          - Node for the device
3640174267aSFredrik Holmqvist  *              Flags               - Where the status flags are returned
3650174267aSFredrik Holmqvist  *
3660174267aSFredrik Holmqvist  * RETURN:      Status
3670174267aSFredrik Holmqvist  *
3680174267aSFredrik Holmqvist  * DESCRIPTION: Executes _STA for selected device and stores results in
369c70258b7SJérôme Duval  *              *Flags. If _STA does not exist, then the device is assumed
370c70258b7SJérôme Duval  *              to be present/functional/enabled (as per the ACPI spec).
3710174267aSFredrik Holmqvist  *
3720174267aSFredrik Holmqvist  *              NOTE: Internal function, no parameter validation
3730174267aSFredrik Holmqvist  *
3740174267aSFredrik Holmqvist  ******************************************************************************/
3750174267aSFredrik Holmqvist 
3760174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtExecute_STA(ACPI_NAMESPACE_NODE * DeviceNode,UINT32 * Flags)3770174267aSFredrik Holmqvist AcpiUtExecute_STA (
3780174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *DeviceNode,
3790174267aSFredrik Holmqvist     UINT32                  *Flags)
3800174267aSFredrik Holmqvist {
3810174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
3820174267aSFredrik Holmqvist     ACPI_STATUS             Status;
3830174267aSFredrik Holmqvist 
3840174267aSFredrik Holmqvist 
3850174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtExecute_STA);
3860174267aSFredrik Holmqvist 
3870174267aSFredrik Holmqvist 
3880174267aSFredrik Holmqvist     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__STA,
3890174267aSFredrik Holmqvist         ACPI_BTYPE_INTEGER, &ObjDesc);
3900174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
3910174267aSFredrik Holmqvist     {
3920174267aSFredrik Holmqvist         if (AE_NOT_FOUND == Status)
3930174267aSFredrik Holmqvist         {
394c70258b7SJérôme Duval             /*
395c70258b7SJérôme Duval              * if _STA does not exist, then (as per the ACPI specification),
396c70258b7SJérôme Duval              * the returned flags will indicate that the device is present,
397c70258b7SJérôme Duval              * functional, and enabled.
398c70258b7SJérôme Duval              */
3990174267aSFredrik Holmqvist             ACPI_DEBUG_PRINT ((ACPI_DB_EXEC,
4000174267aSFredrik Holmqvist                 "_STA on %4.4s was not found, assuming device is present\n",
4010174267aSFredrik Holmqvist                 AcpiUtGetNodeName (DeviceNode)));
4020174267aSFredrik Holmqvist 
4030174267aSFredrik Holmqvist             *Flags = ACPI_UINT32_MAX;
4040174267aSFredrik Holmqvist             Status = AE_OK;
4050174267aSFredrik Holmqvist         }
4060174267aSFredrik Holmqvist 
4070174267aSFredrik Holmqvist         return_ACPI_STATUS (Status);
4080174267aSFredrik Holmqvist     }
4090174267aSFredrik Holmqvist 
4100174267aSFredrik Holmqvist     /* Extract the status flags */
4110174267aSFredrik Holmqvist 
4120174267aSFredrik Holmqvist     *Flags = (UINT32) ObjDesc->Integer.Value;
4130174267aSFredrik Holmqvist 
4140174267aSFredrik Holmqvist     /* On exit, we must delete the return object */
4150174267aSFredrik Holmqvist 
4160174267aSFredrik Holmqvist     AcpiUtRemoveReference (ObjDesc);
4170174267aSFredrik Holmqvist     return_ACPI_STATUS (Status);
4180174267aSFredrik Holmqvist }
4190174267aSFredrik Holmqvist 
4200174267aSFredrik Holmqvist 
4210174267aSFredrik Holmqvist /*******************************************************************************
4220174267aSFredrik Holmqvist  *
4230174267aSFredrik Holmqvist  * FUNCTION:    AcpiUtExecutePowerMethods
4240174267aSFredrik Holmqvist  *
4250174267aSFredrik Holmqvist  * PARAMETERS:  DeviceNode          - Node for the device
4260174267aSFredrik Holmqvist  *              MethodNames         - Array of power method names
4270174267aSFredrik Holmqvist  *              MethodCount         - Number of methods to execute
4280174267aSFredrik Holmqvist  *              OutValues           - Where the power method values are returned
4290174267aSFredrik Holmqvist  *
4300174267aSFredrik Holmqvist  * RETURN:      Status, OutValues
4310174267aSFredrik Holmqvist  *
4320174267aSFredrik Holmqvist  * DESCRIPTION: Executes the specified power methods for the device and returns
4330174267aSFredrik Holmqvist  *              the result(s).
4340174267aSFredrik Holmqvist  *
4350174267aSFredrik Holmqvist  *              NOTE: Internal function, no parameter validation
4360174267aSFredrik Holmqvist  *
4370174267aSFredrik Holmqvist  ******************************************************************************/
4380174267aSFredrik Holmqvist 
4390174267aSFredrik Holmqvist ACPI_STATUS
AcpiUtExecutePowerMethods(ACPI_NAMESPACE_NODE * DeviceNode,const char ** MethodNames,UINT8 MethodCount,UINT8 * OutValues)4400174267aSFredrik Holmqvist AcpiUtExecutePowerMethods (
4410174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE     *DeviceNode,
4420174267aSFredrik Holmqvist     const char              **MethodNames,
4430174267aSFredrik Holmqvist     UINT8                   MethodCount,
4440174267aSFredrik Holmqvist     UINT8                   *OutValues)
4450174267aSFredrik Holmqvist {
4460174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT     *ObjDesc;
4470174267aSFredrik Holmqvist     ACPI_STATUS             Status;
4480174267aSFredrik Holmqvist     ACPI_STATUS             FinalStatus = AE_NOT_FOUND;
4490174267aSFredrik Holmqvist     UINT32                  i;
4500174267aSFredrik Holmqvist 
4510174267aSFredrik Holmqvist 
4520174267aSFredrik Holmqvist     ACPI_FUNCTION_TRACE (UtExecutePowerMethods);
4530174267aSFredrik Holmqvist 
4540174267aSFredrik Holmqvist 
4550174267aSFredrik Holmqvist     for (i = 0; i < MethodCount; i++)
4560174267aSFredrik Holmqvist     {
4570174267aSFredrik Holmqvist         /*
4580174267aSFredrik Holmqvist          * Execute the power method (_SxD or _SxW). The only allowable
4590174267aSFredrik Holmqvist          * return type is an Integer.
4600174267aSFredrik Holmqvist          */
4610174267aSFredrik Holmqvist         Status = AcpiUtEvaluateObject (DeviceNode,
4620174267aSFredrik Holmqvist             ACPI_CAST_PTR (char, MethodNames[i]),
4630174267aSFredrik Holmqvist             ACPI_BTYPE_INTEGER, &ObjDesc);
4640174267aSFredrik Holmqvist         if (ACPI_SUCCESS (Status))
4650174267aSFredrik Holmqvist         {
4660174267aSFredrik Holmqvist             OutValues[i] = (UINT8) ObjDesc->Integer.Value;
4670174267aSFredrik Holmqvist 
4680174267aSFredrik Holmqvist             /* Delete the return object */
4690174267aSFredrik Holmqvist 
4700174267aSFredrik Holmqvist             AcpiUtRemoveReference (ObjDesc);
4710174267aSFredrik Holmqvist             FinalStatus = AE_OK;            /* At least one value is valid */
4720174267aSFredrik Holmqvist             continue;
4730174267aSFredrik Holmqvist         }
4740174267aSFredrik Holmqvist 
4750174267aSFredrik Holmqvist         OutValues[i] = ACPI_UINT8_MAX;
4760174267aSFredrik Holmqvist         if (Status == AE_NOT_FOUND)
4770174267aSFredrik Holmqvist         {
4780174267aSFredrik Holmqvist             continue; /* Ignore if not found */
4790174267aSFredrik Holmqvist         }
4800174267aSFredrik Holmqvist 
4810174267aSFredrik Holmqvist         ACPI_DEBUG_PRINT ((ACPI_DB_EXEC, "Failed %s on Device %4.4s, %s\n",
4820174267aSFredrik Holmqvist             ACPI_CAST_PTR (char, MethodNames[i]),
4830174267aSFredrik Holmqvist             AcpiUtGetNodeName (DeviceNode), AcpiFormatException (Status)));
4840174267aSFredrik Holmqvist     }
4850174267aSFredrik Holmqvist 
4860174267aSFredrik Holmqvist     return_ACPI_STATUS (FinalStatus);
4870174267aSFredrik Holmqvist }
488