xref: /haiku/src/add-ons/kernel/bus_managers/acpi/acpica/components/namespace/nspredef.c (revision 6dde014f768e0ee49bae871ed857cf433837b9ff)
10174267aSFredrik Holmqvist /******************************************************************************
20174267aSFredrik Holmqvist  *
30174267aSFredrik Holmqvist  * Module Name: nspredef - Validation of ACPI predefined methods and objects
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 #define ACPI_CREATE_PREDEFINED_TABLE
1530174267aSFredrik Holmqvist 
1540174267aSFredrik Holmqvist #include "acpi.h"
1550174267aSFredrik Holmqvist #include "accommon.h"
1560174267aSFredrik Holmqvist #include "acnamesp.h"
1570174267aSFredrik Holmqvist #include "acpredef.h"
1580174267aSFredrik Holmqvist 
1590174267aSFredrik Holmqvist 
1600174267aSFredrik Holmqvist #define _COMPONENT          ACPI_NAMESPACE
1610174267aSFredrik Holmqvist         ACPI_MODULE_NAME    ("nspredef")
1620174267aSFredrik Holmqvist 
1630174267aSFredrik Holmqvist 
1640174267aSFredrik Holmqvist /*******************************************************************************
1650174267aSFredrik Holmqvist  *
1660174267aSFredrik Holmqvist  * This module validates predefined ACPI objects that appear in the namespace,
1670174267aSFredrik Holmqvist  * at the time they are evaluated (via AcpiEvaluateObject). The purpose of this
1680174267aSFredrik Holmqvist  * validation is to detect problems with BIOS-exposed predefined ACPI objects
1690174267aSFredrik Holmqvist  * before the results are returned to the ACPI-related drivers.
1700174267aSFredrik Holmqvist  *
1710174267aSFredrik Holmqvist  * There are several areas that are validated:
1720174267aSFredrik Holmqvist  *
1730174267aSFredrik Holmqvist  *  1) The number of input arguments as defined by the method/object in the
1740174267aSFredrik Holmqvist  *     ASL is validated against the ACPI specification.
1750174267aSFredrik Holmqvist  *  2) The type of the return object (if any) is validated against the ACPI
1760174267aSFredrik Holmqvist  *     specification.
1770174267aSFredrik Holmqvist  *  3) For returned package objects, the count of package elements is
1780174267aSFredrik Holmqvist  *     validated, as well as the type of each package element. Nested
1790174267aSFredrik Holmqvist  *     packages are supported.
1800174267aSFredrik Holmqvist  *
1810174267aSFredrik Holmqvist  * For any problems found, a warning message is issued.
1820174267aSFredrik Holmqvist  *
1830174267aSFredrik Holmqvist  ******************************************************************************/
1840174267aSFredrik Holmqvist 
1850174267aSFredrik Holmqvist 
1860174267aSFredrik Holmqvist /* Local prototypes */
1870174267aSFredrik Holmqvist 
1880174267aSFredrik Holmqvist static ACPI_STATUS
1890174267aSFredrik Holmqvist AcpiNsCheckReference (
190c70258b7SJérôme Duval     ACPI_EVALUATE_INFO          *Info,
1910174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT         *ReturnObject);
1920174267aSFredrik Holmqvist 
193c70258b7SJérôme Duval static UINT32
194c70258b7SJérôme Duval AcpiNsGetBitmappedType (
195c70258b7SJérôme Duval     ACPI_OPERAND_OBJECT         *ReturnObject);
1960174267aSFredrik Holmqvist 
1970174267aSFredrik Holmqvist 
1980174267aSFredrik Holmqvist /*******************************************************************************
1990174267aSFredrik Holmqvist  *
200c70258b7SJérôme Duval  * FUNCTION:    AcpiNsCheckReturnValue
2010174267aSFredrik Holmqvist  *
2020174267aSFredrik Holmqvist  * PARAMETERS:  Node            - Namespace node for the method/object
203c70258b7SJérôme Duval  *              Info            - Method execution information block
2040174267aSFredrik Holmqvist  *              UserParamCount  - Number of parameters actually passed
2050174267aSFredrik Holmqvist  *              ReturnStatus    - Status from the object evaluation
2060174267aSFredrik Holmqvist  *              ReturnObjectPtr - Pointer to the object returned from the
2070174267aSFredrik Holmqvist  *                                evaluation of a method or object
2080174267aSFredrik Holmqvist  *
2090174267aSFredrik Holmqvist  * RETURN:      Status
2100174267aSFredrik Holmqvist  *
211c70258b7SJérôme Duval  * DESCRIPTION: Check the value returned from a predefined name.
2120174267aSFredrik Holmqvist  *
2130174267aSFredrik Holmqvist  ******************************************************************************/
2140174267aSFredrik Holmqvist 
2150174267aSFredrik Holmqvist ACPI_STATUS
AcpiNsCheckReturnValue(ACPI_NAMESPACE_NODE * Node,ACPI_EVALUATE_INFO * Info,UINT32 UserParamCount,ACPI_STATUS ReturnStatus,ACPI_OPERAND_OBJECT ** ReturnObjectPtr)216c70258b7SJérôme Duval AcpiNsCheckReturnValue (
2170174267aSFredrik Holmqvist     ACPI_NAMESPACE_NODE         *Node,
218c70258b7SJérôme Duval     ACPI_EVALUATE_INFO          *Info,
2190174267aSFredrik Holmqvist     UINT32                      UserParamCount,
2200174267aSFredrik Holmqvist     ACPI_STATUS                 ReturnStatus,
2210174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT         **ReturnObjectPtr)
2220174267aSFredrik Holmqvist {
223c70258b7SJérôme Duval     ACPI_STATUS                 Status;
2240174267aSFredrik Holmqvist     const ACPI_PREDEFINED_INFO  *Predefined;
2250174267aSFredrik Holmqvist 
2260ffed378SFredrik Holmqvist     ACPI_FUNCTION_TRACE (NsCheckReturnValue);
2270174267aSFredrik Holmqvist 
2280174267aSFredrik Holmqvist     /* If not a predefined name, we cannot validate the return object */
2290174267aSFredrik Holmqvist 
230c70258b7SJérôme Duval     Predefined = Info->Predefined;
2310174267aSFredrik Holmqvist     if (!Predefined)
2320174267aSFredrik Holmqvist     {
2330ffed378SFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
2340174267aSFredrik Holmqvist     }
2350174267aSFredrik Holmqvist 
2360174267aSFredrik Holmqvist     /*
2370174267aSFredrik Holmqvist      * If the method failed or did not actually return an object, we cannot
2380174267aSFredrik Holmqvist      * validate the return object
2390174267aSFredrik Holmqvist      */
240c70258b7SJérôme Duval     if ((ReturnStatus != AE_OK) &&
241c70258b7SJérôme Duval         (ReturnStatus != AE_CTRL_RETURN_VALUE))
2420174267aSFredrik Holmqvist     {
2430ffed378SFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
2440174267aSFredrik Holmqvist     }
2450174267aSFredrik Holmqvist 
2460174267aSFredrik Holmqvist     /*
2470174267aSFredrik Holmqvist      * Return value validation and possible repair.
2480174267aSFredrik Holmqvist      *
2490174267aSFredrik Holmqvist      * 1) Don't perform return value validation/repair if this feature
2500174267aSFredrik Holmqvist      * has been disabled via a global option.
2510174267aSFredrik Holmqvist      *
2520174267aSFredrik Holmqvist      * 2) We have a return value, but if one wasn't expected, just exit,
2530174267aSFredrik Holmqvist      * this is not a problem. For example, if the "Implicit Return"
2540174267aSFredrik Holmqvist      * feature is enabled, methods will always return a value.
2550174267aSFredrik Holmqvist      *
2560174267aSFredrik Holmqvist      * 3) If the return value can be of any type, then we cannot perform
2570174267aSFredrik Holmqvist      * any validation, just exit.
2580174267aSFredrik Holmqvist      */
2590174267aSFredrik Holmqvist     if (AcpiGbl_DisableAutoRepair ||
2600174267aSFredrik Holmqvist         (!Predefined->Info.ExpectedBtypes) ||
2610174267aSFredrik Holmqvist         (Predefined->Info.ExpectedBtypes == ACPI_RTYPE_ALL))
2620174267aSFredrik Holmqvist     {
2630ffed378SFredrik Holmqvist         return_ACPI_STATUS (AE_OK);
2640174267aSFredrik Holmqvist     }
2650174267aSFredrik Holmqvist 
2660174267aSFredrik Holmqvist     /*
2670174267aSFredrik Holmqvist      * Check that the type of the main return object is what is expected
2680174267aSFredrik Holmqvist      * for this predefined name
2690174267aSFredrik Holmqvist      */
270c70258b7SJérôme Duval     Status = AcpiNsCheckObjectType (Info, ReturnObjectPtr,
2710174267aSFredrik Holmqvist         Predefined->Info.ExpectedBtypes, ACPI_NOT_PACKAGE_ELEMENT);
2720174267aSFredrik Holmqvist     if (ACPI_FAILURE (Status))
2730174267aSFredrik Holmqvist     {
2740174267aSFredrik Holmqvist         goto Exit;
2750174267aSFredrik Holmqvist     }
2760174267aSFredrik Holmqvist 
2770174267aSFredrik Holmqvist     /*
278c70258b7SJérôme Duval      *
279c70258b7SJérôme Duval      * 4) If there is no return value and it is optional, just return
280c70258b7SJérôme Duval      * AE_OK (_WAK).
281c70258b7SJérôme Duval      */
282c70258b7SJérôme Duval     if (!(*ReturnObjectPtr))
283c70258b7SJérôme Duval     {
284c70258b7SJérôme Duval         goto Exit;
285c70258b7SJérôme Duval     }
286c70258b7SJérôme Duval 
287c70258b7SJérôme Duval     /*
2880174267aSFredrik Holmqvist      * For returned Package objects, check the type of all sub-objects.
2890174267aSFredrik Holmqvist      * Note: Package may have been newly created by call above.
2900174267aSFredrik Holmqvist      */
2910174267aSFredrik Holmqvist     if ((*ReturnObjectPtr)->Common.Type == ACPI_TYPE_PACKAGE)
2920174267aSFredrik Holmqvist     {
293c70258b7SJérôme Duval         Info->ParentPackage = *ReturnObjectPtr;
294c70258b7SJérôme Duval         Status = AcpiNsCheckPackage (Info, ReturnObjectPtr);
2950174267aSFredrik Holmqvist         if (ACPI_FAILURE (Status))
2960174267aSFredrik Holmqvist         {
297c70258b7SJérôme Duval             /* We might be able to fix some errors */
298c70258b7SJérôme Duval 
299c70258b7SJérôme Duval             if ((Status != AE_AML_OPERAND_TYPE) &&
300c70258b7SJérôme Duval                 (Status != AE_AML_OPERAND_VALUE))
301c70258b7SJérôme Duval             {
3020174267aSFredrik Holmqvist                 goto Exit;
3030174267aSFredrik Holmqvist             }
3040174267aSFredrik Holmqvist         }
305c70258b7SJérôme Duval     }
3060174267aSFredrik Holmqvist 
3070174267aSFredrik Holmqvist     /*
3080174267aSFredrik Holmqvist      * The return object was OK, or it was successfully repaired above.
3090174267aSFredrik Holmqvist      * Now make some additional checks such as verifying that package
3100174267aSFredrik Holmqvist      * objects are sorted correctly (if required) or buffer objects have
3110174267aSFredrik Holmqvist      * the correct data width (bytes vs. dwords). These repairs are
3120174267aSFredrik Holmqvist      * performed on a per-name basis, i.e., the code is specific to
3130174267aSFredrik Holmqvist      * particular predefined names.
3140174267aSFredrik Holmqvist      */
315c70258b7SJérôme Duval     Status = AcpiNsComplexRepairs (Info, Node, Status, ReturnObjectPtr);
3160174267aSFredrik Holmqvist 
3170174267aSFredrik Holmqvist Exit:
3180174267aSFredrik Holmqvist     /*
3190174267aSFredrik Holmqvist      * If the object validation failed or if we successfully repaired one
3200174267aSFredrik Holmqvist      * or more objects, mark the parent node to suppress further warning
3210174267aSFredrik Holmqvist      * messages during the next evaluation of the same method/object.
3220174267aSFredrik Holmqvist      */
323c70258b7SJérôme Duval     if (ACPI_FAILURE (Status) ||
324c70258b7SJérôme Duval        (Info->ReturnFlags & ACPI_OBJECT_REPAIRED))
3250174267aSFredrik Holmqvist     {
3260174267aSFredrik Holmqvist         Node->Flags |= ANOBJ_EVALUATED;
3270174267aSFredrik Holmqvist     }
3280174267aSFredrik Holmqvist 
3290ffed378SFredrik Holmqvist     return_ACPI_STATUS (Status);
3300174267aSFredrik Holmqvist }
3310174267aSFredrik Holmqvist 
3320174267aSFredrik Holmqvist 
3330174267aSFredrik Holmqvist /*******************************************************************************
3340174267aSFredrik Holmqvist  *
3350174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsCheckObjectType
3360174267aSFredrik Holmqvist  *
337c70258b7SJérôme Duval  * PARAMETERS:  Info            - Method execution information block
3380174267aSFredrik Holmqvist  *              ReturnObjectPtr - Pointer to the object returned from the
3390174267aSFredrik Holmqvist  *                                evaluation of a method or object
3400174267aSFredrik Holmqvist  *              ExpectedBtypes  - Bitmap of expected return type(s)
3410174267aSFredrik Holmqvist  *              PackageIndex    - Index of object within parent package (if
3420174267aSFredrik Holmqvist  *                                applicable - ACPI_NOT_PACKAGE_ELEMENT
3430174267aSFredrik Holmqvist  *                                otherwise)
3440174267aSFredrik Holmqvist  *
3450174267aSFredrik Holmqvist  * RETURN:      Status
3460174267aSFredrik Holmqvist  *
3470174267aSFredrik Holmqvist  * DESCRIPTION: Check the type of the return object against the expected object
3480174267aSFredrik Holmqvist  *              type(s). Use of Btype allows multiple expected object types.
3490174267aSFredrik Holmqvist  *
3500174267aSFredrik Holmqvist  ******************************************************************************/
3510174267aSFredrik Holmqvist 
352c70258b7SJérôme Duval ACPI_STATUS
AcpiNsCheckObjectType(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT ** ReturnObjectPtr,UINT32 ExpectedBtypes,UINT32 PackageIndex)3530174267aSFredrik Holmqvist AcpiNsCheckObjectType (
354c70258b7SJérôme Duval     ACPI_EVALUATE_INFO          *Info,
3550174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT         **ReturnObjectPtr,
3560174267aSFredrik Holmqvist     UINT32                      ExpectedBtypes,
3570174267aSFredrik Holmqvist     UINT32                      PackageIndex)
3580174267aSFredrik Holmqvist {
3590174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT         *ReturnObject = *ReturnObjectPtr;
3600174267aSFredrik Holmqvist     ACPI_STATUS                 Status = AE_OK;
361b64e8511SFredrik Holmqvist     char                        TypeBuffer[96]; /* Room for 10 types */
3620174267aSFredrik Holmqvist 
3630174267aSFredrik Holmqvist 
3640174267aSFredrik Holmqvist     /* A Namespace node should not get here, but make sure */
3650174267aSFredrik Holmqvist 
366c70258b7SJérôme Duval     if (ReturnObject &&
367c70258b7SJérôme Duval         ACPI_GET_DESCRIPTOR_TYPE (ReturnObject) == ACPI_DESC_TYPE_NAMED)
3680174267aSFredrik Holmqvist     {
369c70258b7SJérôme Duval         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
3700174267aSFredrik Holmqvist             "Invalid return type - Found a Namespace node [%4.4s] type %s",
3710174267aSFredrik Holmqvist             ReturnObject->Node.Name.Ascii,
3720174267aSFredrik Holmqvist             AcpiUtGetTypeName (ReturnObject->Node.Type)));
3730174267aSFredrik Holmqvist         return (AE_AML_OPERAND_TYPE);
3740174267aSFredrik Holmqvist     }
3750174267aSFredrik Holmqvist 
3760174267aSFredrik Holmqvist     /*
3770174267aSFredrik Holmqvist      * Convert the object type (ACPI_TYPE_xxx) to a bitmapped object type.
3780174267aSFredrik Holmqvist      * The bitmapped type allows multiple possible return types.
3790174267aSFredrik Holmqvist      *
3800174267aSFredrik Holmqvist      * Note, the cases below must handle all of the possible types returned
3810174267aSFredrik Holmqvist      * from all of the predefined names (including elements of returned
3820174267aSFredrik Holmqvist      * packages)
3830174267aSFredrik Holmqvist      */
384c70258b7SJérôme Duval     Info->ReturnBtype = AcpiNsGetBitmappedType (ReturnObject);
385c70258b7SJérôme Duval     if (Info->ReturnBtype == ACPI_RTYPE_ANY)
3860174267aSFredrik Holmqvist     {
3870174267aSFredrik Holmqvist         /* Not one of the supported objects, must be incorrect */
3880174267aSFredrik Holmqvist         goto TypeErrorExit;
3890174267aSFredrik Holmqvist     }
3900174267aSFredrik Holmqvist 
3910174267aSFredrik Holmqvist     /* For reference objects, check that the reference type is correct */
3920174267aSFredrik Holmqvist 
393c70258b7SJérôme Duval     if ((Info->ReturnBtype & ExpectedBtypes) == ACPI_RTYPE_REFERENCE)
3940174267aSFredrik Holmqvist     {
395c70258b7SJérôme Duval         Status = AcpiNsCheckReference (Info, ReturnObject);
3960174267aSFredrik Holmqvist         return (Status);
3970174267aSFredrik Holmqvist     }
3980174267aSFredrik Holmqvist 
399c70258b7SJérôme Duval     /* Attempt simple repair of the returned object if necessary */
4000174267aSFredrik Holmqvist 
401c70258b7SJérôme Duval     Status = AcpiNsSimpleRepair (Info, ExpectedBtypes,
4020174267aSFredrik Holmqvist         PackageIndex, ReturnObjectPtr);
4030174267aSFredrik Holmqvist     if (ACPI_SUCCESS (Status))
4040174267aSFredrik Holmqvist     {
405c70258b7SJérôme Duval         return (AE_OK); /* Successful repair */
4060174267aSFredrik Holmqvist     }
4070174267aSFredrik Holmqvist 
4080174267aSFredrik Holmqvist 
4090174267aSFredrik Holmqvist TypeErrorExit:
4100174267aSFredrik Holmqvist 
4110174267aSFredrik Holmqvist     /* Create a string with all expected types for this predefined object */
4120174267aSFredrik Holmqvist 
413c70258b7SJérôme Duval     AcpiUtGetExpectedReturnTypes (TypeBuffer, ExpectedBtypes);
4140174267aSFredrik Holmqvist 
415c70258b7SJérôme Duval     if (!ReturnObject)
4160174267aSFredrik Holmqvist     {
417c70258b7SJérôme Duval         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
418c70258b7SJérôme Duval             "Expected return object of type %s",
419c70258b7SJérôme Duval             TypeBuffer));
420c70258b7SJérôme Duval     }
421c70258b7SJérôme Duval     else if (PackageIndex == ACPI_NOT_PACKAGE_ELEMENT)
422c70258b7SJérôme Duval     {
423c70258b7SJérôme Duval         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
4240174267aSFredrik Holmqvist             "Return type mismatch - found %s, expected %s",
4250174267aSFredrik Holmqvist             AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
4260174267aSFredrik Holmqvist     }
4270174267aSFredrik Holmqvist     else
4280174267aSFredrik Holmqvist     {
429c70258b7SJérôme Duval         ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
4300174267aSFredrik Holmqvist             "Return Package type mismatch at index %u - "
4310174267aSFredrik Holmqvist             "found %s, expected %s", PackageIndex,
4320174267aSFredrik Holmqvist             AcpiUtGetObjectTypeName (ReturnObject), TypeBuffer));
4330174267aSFredrik Holmqvist     }
4340174267aSFredrik Holmqvist 
4350174267aSFredrik Holmqvist     return (AE_AML_OPERAND_TYPE);
4360174267aSFredrik Holmqvist }
4370174267aSFredrik Holmqvist 
4380174267aSFredrik Holmqvist 
4390174267aSFredrik Holmqvist /*******************************************************************************
4400174267aSFredrik Holmqvist  *
4410174267aSFredrik Holmqvist  * FUNCTION:    AcpiNsCheckReference
4420174267aSFredrik Holmqvist  *
443c70258b7SJérôme Duval  * PARAMETERS:  Info            - Method execution information block
4440174267aSFredrik Holmqvist  *              ReturnObject    - Object returned from the evaluation of a
4450174267aSFredrik Holmqvist  *                                method or object
4460174267aSFredrik Holmqvist  *
4470174267aSFredrik Holmqvist  * RETURN:      Status
4480174267aSFredrik Holmqvist  *
4490174267aSFredrik Holmqvist  * DESCRIPTION: Check a returned reference object for the correct reference
4500174267aSFredrik Holmqvist  *              type. The only reference type that can be returned from a
4510174267aSFredrik Holmqvist  *              predefined method is a named reference. All others are invalid.
4520174267aSFredrik Holmqvist  *
4530174267aSFredrik Holmqvist  ******************************************************************************/
4540174267aSFredrik Holmqvist 
4550174267aSFredrik Holmqvist static ACPI_STATUS
AcpiNsCheckReference(ACPI_EVALUATE_INFO * Info,ACPI_OPERAND_OBJECT * ReturnObject)4560174267aSFredrik Holmqvist AcpiNsCheckReference (
457c70258b7SJérôme Duval     ACPI_EVALUATE_INFO          *Info,
4580174267aSFredrik Holmqvist     ACPI_OPERAND_OBJECT         *ReturnObject)
4590174267aSFredrik Holmqvist {
4600174267aSFredrik Holmqvist 
4610174267aSFredrik Holmqvist     /*
4620174267aSFredrik Holmqvist      * Check the reference object for the correct reference type (opcode).
4630174267aSFredrik Holmqvist      * The only type of reference that can be converted to an ACPI_OBJECT is
4640174267aSFredrik Holmqvist      * a reference to a named object (reference class: NAME)
4650174267aSFredrik Holmqvist      */
4660174267aSFredrik Holmqvist     if (ReturnObject->Reference.Class == ACPI_REFCLASS_NAME)
4670174267aSFredrik Holmqvist     {
4680174267aSFredrik Holmqvist         return (AE_OK);
4690174267aSFredrik Holmqvist     }
4700174267aSFredrik Holmqvist 
471c70258b7SJérôme Duval     ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname, Info->NodeFlags,
4720174267aSFredrik Holmqvist         "Return type mismatch - unexpected reference object type [%s] %2.2X",
4730174267aSFredrik Holmqvist         AcpiUtGetReferenceName (ReturnObject),
4740174267aSFredrik Holmqvist         ReturnObject->Reference.Class));
4750174267aSFredrik Holmqvist 
4760174267aSFredrik Holmqvist     return (AE_AML_OPERAND_TYPE);
4770174267aSFredrik Holmqvist }
4780174267aSFredrik Holmqvist 
4790174267aSFredrik Holmqvist 
4800174267aSFredrik Holmqvist /*******************************************************************************
4810174267aSFredrik Holmqvist  *
482c70258b7SJérôme Duval  * FUNCTION:    AcpiNsGetBitmappedType
4830174267aSFredrik Holmqvist  *
484c70258b7SJérôme Duval  * PARAMETERS:  ReturnObject    - Object returned from method/obj evaluation
4850174267aSFredrik Holmqvist  *
486c70258b7SJérôme Duval  * RETURN:      Object return type. ACPI_RTYPE_ANY indicates that the object
487c70258b7SJérôme Duval  *              type is not supported. ACPI_RTYPE_NONE indicates that no
488c70258b7SJérôme Duval  *              object was returned (ReturnObject is NULL).
4890174267aSFredrik Holmqvist  *
490c70258b7SJérôme Duval  * DESCRIPTION: Convert object type into a bitmapped object return type.
4910174267aSFredrik Holmqvist  *
4920174267aSFredrik Holmqvist  ******************************************************************************/
4930174267aSFredrik Holmqvist 
494c70258b7SJérôme Duval static UINT32
AcpiNsGetBitmappedType(ACPI_OPERAND_OBJECT * ReturnObject)495c70258b7SJérôme Duval AcpiNsGetBitmappedType (
496c70258b7SJérôme Duval     ACPI_OPERAND_OBJECT         *ReturnObject)
4970174267aSFredrik Holmqvist {
498c70258b7SJérôme Duval     UINT32                      ReturnBtype;
4990174267aSFredrik Holmqvist 
5000174267aSFredrik Holmqvist 
501c70258b7SJérôme Duval     if (!ReturnObject)
5020174267aSFredrik Holmqvist     {
503c70258b7SJérôme Duval         return (ACPI_RTYPE_NONE);
5040174267aSFredrik Holmqvist     }
505c70258b7SJérôme Duval 
506c70258b7SJérôme Duval     /* Map ACPI_OBJECT_TYPE to internal bitmapped type */
507c70258b7SJérôme Duval 
508c70258b7SJérôme Duval     switch (ReturnObject->Common.Type)
509c70258b7SJérôme Duval     {
510c70258b7SJérôme Duval     case ACPI_TYPE_INTEGER:
511c70258b7SJérôme Duval 
512c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_INTEGER;
513c70258b7SJérôme Duval         break;
514c70258b7SJérôme Duval 
515c70258b7SJérôme Duval     case ACPI_TYPE_BUFFER:
516c70258b7SJérôme Duval 
517c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_BUFFER;
518c70258b7SJérôme Duval         break;
519c70258b7SJérôme Duval 
520c70258b7SJérôme Duval     case ACPI_TYPE_STRING:
521c70258b7SJérôme Duval 
522c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_STRING;
523c70258b7SJérôme Duval         break;
524c70258b7SJérôme Duval 
525c70258b7SJérôme Duval     case ACPI_TYPE_PACKAGE:
526c70258b7SJérôme Duval 
527c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_PACKAGE;
528c70258b7SJérôme Duval         break;
529c70258b7SJérôme Duval 
530c70258b7SJérôme Duval     case ACPI_TYPE_LOCAL_REFERENCE:
531c70258b7SJérôme Duval 
532c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_REFERENCE;
533c70258b7SJérôme Duval         break;
534c70258b7SJérôme Duval 
535c70258b7SJérôme Duval     default:
536c70258b7SJérôme Duval 
537c70258b7SJérôme Duval         /* Not one of the supported objects, must be incorrect */
538c70258b7SJérôme Duval 
539c70258b7SJérôme Duval         ReturnBtype = ACPI_RTYPE_ANY;
540c70258b7SJérôme Duval         break;
5410174267aSFredrik Holmqvist     }
542c70258b7SJérôme Duval 
543c70258b7SJérôme Duval     return (ReturnBtype);
5440174267aSFredrik Holmqvist }
545