Home | History | Annotate | Line # | Download | only in namespace
      1       1.1    jruoho /******************************************************************************
      2       1.1    jruoho  *
      3       1.1    jruoho  * Module Name: nsrepair - Repair for objects returned by predefined methods
      4       1.1    jruoho  *
      5       1.1    jruoho  *****************************************************************************/
      6       1.1    jruoho 
      7  1.1.1.17  christos /******************************************************************************
      8  1.1.1.17  christos  *
      9  1.1.1.17  christos  * 1. Copyright Notice
     10  1.1.1.17  christos  *
     11  1.1.1.18  christos  * Some or all of this work - Copyright (c) 1999 - 2025, Intel Corp.
     12       1.1    jruoho  * All rights reserved.
     13       1.1    jruoho  *
     14  1.1.1.17  christos  * 2. License
     15  1.1.1.17  christos  *
     16  1.1.1.17  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1.1.17  christos  * rights. You may have additional license terms from the party that provided
     18  1.1.1.17  christos  * you this software, covering your right to use that party's intellectual
     19  1.1.1.17  christos  * property rights.
     20  1.1.1.17  christos  *
     21  1.1.1.17  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1.1.17  christos  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1.1.17  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1.1.17  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1.1.17  christos  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1.1.17  christos  * Code in any form, with the right to sublicense such rights; and
     27  1.1.1.17  christos  *
     28  1.1.1.17  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1.1.17  christos  * license (with the right to sublicense), under only those claims of Intel
     30  1.1.1.17  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1.1.17  christos  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1.1.17  christos  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1.1.17  christos  * license, and in no event shall the patent license extend to any additions
     34  1.1.1.17  christos  * to or modifications of the Original Intel Code. No other license or right
     35  1.1.1.17  christos  * is granted directly or by implication, estoppel or otherwise;
     36  1.1.1.17  christos  *
     37  1.1.1.17  christos  * The above copyright and patent license is granted only if the following
     38  1.1.1.17  christos  * conditions are met:
     39  1.1.1.17  christos  *
     40  1.1.1.17  christos  * 3. Conditions
     41  1.1.1.17  christos  *
     42  1.1.1.17  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1.1.17  christos  * Redistribution of source code of any substantial portion of the Covered
     44  1.1.1.17  christos  * Code or modification with rights to further distribute source must include
     45  1.1.1.17  christos  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1.1.17  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     47  1.1.1.17  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1.1.17  christos  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1.1.17  christos  * Code and the date of any change. Licensee must include in that file the
     50  1.1.1.17  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     51  1.1.1.17  christos  * must include a prominent statement that the modification is derived,
     52  1.1.1.17  christos  * directly or indirectly, from Original Intel Code.
     53  1.1.1.17  christos  *
     54  1.1.1.17  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1.1.17  christos  * Redistribution of source code of any substantial portion of the Covered
     56  1.1.1.17  christos  * Code or modification without rights to further distribute source must
     57  1.1.1.17  christos  * include the following Disclaimer and Export Compliance provision in the
     58  1.1.1.17  christos  * documentation and/or other materials provided with distribution. In
     59  1.1.1.17  christos  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1.1.17  christos  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1.1.17  christos  * license from Licensee to its licensee is limited to the intellectual
     62  1.1.1.17  christos  * property embodied in the software Licensee provides to its licensee, and
     63  1.1.1.17  christos  * not to intellectual property embodied in modifications its licensee may
     64  1.1.1.17  christos  * make.
     65  1.1.1.17  christos  *
     66  1.1.1.17  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1.1.17  christos  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1.1.17  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1.1.17  christos  * provision in the documentation and/or other materials provided with the
     70  1.1.1.17  christos  * distribution.
     71  1.1.1.17  christos  *
     72  1.1.1.17  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1.1.17  christos  * Intel Code.
     74  1.1.1.17  christos  *
     75  1.1.1.17  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1.1.17  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1.1.17  christos  * other dealings in products derived from or relating to the Covered Code
     78  1.1.1.17  christos  * without prior written authorization from Intel.
     79  1.1.1.17  christos  *
     80  1.1.1.17  christos  * 4. Disclaimer and Export Compliance
     81  1.1.1.17  christos  *
     82  1.1.1.17  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1.1.17  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1.1.17  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     85  1.1.1.17  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     86  1.1.1.17  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1.1.17  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1.1.17  christos  * PARTICULAR PURPOSE.
     89  1.1.1.17  christos  *
     90  1.1.1.17  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1.1.17  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1.1.17  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1.1.17  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1.1.17  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1.1.17  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     96  1.1.1.17  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1.1.17  christos  * LIMITED REMEDY.
     98  1.1.1.17  christos  *
     99  1.1.1.17  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1.1.17  christos  * software or system incorporating such software without first obtaining any
    101  1.1.1.17  christos  * required license or other approval from the U. S. Department of Commerce or
    102  1.1.1.17  christos  * any other agency or department of the United States Government. In the
    103  1.1.1.17  christos  * event Licensee exports any such software from the United States or
    104  1.1.1.17  christos  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1.1.17  christos  * ensure that the distribution and export/re-export of the software is in
    106  1.1.1.17  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1.1.17  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1.1.17  christos  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1.1.17  christos  * software, or service, directly or indirectly, to any country for which the
    110  1.1.1.17  christos  * United States government or any agency thereof requires an export license,
    111  1.1.1.17  christos  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1.1.17  christos  * such license, approval or letter.
    113  1.1.1.17  christos  *
    114  1.1.1.17  christos  *****************************************************************************
    115  1.1.1.17  christos  *
    116  1.1.1.17  christos  * Alternatively, you may choose to be licensed under the terms of the
    117  1.1.1.17  christos  * following license:
    118  1.1.1.17  christos  *
    119   1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
    120   1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
    121   1.1.1.2    jruoho  * are met:
    122   1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
    123   1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
    124   1.1.1.2    jruoho  *    without modification.
    125   1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    126   1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    127   1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    128   1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
    129   1.1.1.2    jruoho  *    binary redistribution.
    130   1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    131   1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
    132   1.1.1.2    jruoho  *    from this software without specific prior written permission.
    133   1.1.1.2    jruoho  *
    134   1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    135   1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    136  1.1.1.14  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    137   1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    138  1.1.1.17  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    139  1.1.1.17  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    140  1.1.1.17  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    141  1.1.1.17  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    142  1.1.1.17  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    143  1.1.1.17  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    144  1.1.1.17  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    145  1.1.1.17  christos  *
    146  1.1.1.17  christos  * Alternatively, you may choose to be licensed under the terms of the
    147  1.1.1.17  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    148  1.1.1.17  christos  * Software Foundation.
    149  1.1.1.17  christos  *
    150  1.1.1.17  christos  *****************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho #include "acpi.h"
    153       1.1    jruoho #include "accommon.h"
    154       1.1    jruoho #include "acnamesp.h"
    155       1.1    jruoho #include "acinterp.h"
    156       1.1    jruoho #include "acpredef.h"
    157   1.1.1.4  christos #include "amlresrc.h"
    158       1.1    jruoho 
    159       1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
    160       1.1    jruoho         ACPI_MODULE_NAME    ("nsrepair")
    161       1.1    jruoho 
    162       1.1    jruoho 
    163       1.1    jruoho /*******************************************************************************
    164       1.1    jruoho  *
    165       1.1    jruoho  * This module attempts to repair or convert objects returned by the
    166       1.1    jruoho  * predefined methods to an object type that is expected, as per the ACPI
    167       1.1    jruoho  * specification. The need for this code is dictated by the many machines that
    168       1.1    jruoho  * return incorrect types for the standard predefined methods. Performing these
    169       1.1    jruoho  * conversions here, in one place, eliminates the need for individual ACPI
    170       1.1    jruoho  * device drivers to do the same. Note: Most of these conversions are different
    171       1.1    jruoho  * than the internal object conversion routines used for implicit object
    172       1.1    jruoho  * conversion.
    173       1.1    jruoho  *
    174       1.1    jruoho  * The following conversions can be performed as necessary:
    175       1.1    jruoho  *
    176       1.1    jruoho  * Integer -> String
    177       1.1    jruoho  * Integer -> Buffer
    178       1.1    jruoho  * String  -> Integer
    179       1.1    jruoho  * String  -> Buffer
    180       1.1    jruoho  * Buffer  -> Integer
    181       1.1    jruoho  * Buffer  -> String
    182       1.1    jruoho  * Buffer  -> Package of Integers
    183       1.1    jruoho  * Package -> Package of one Package
    184       1.1    jruoho  *
    185   1.1.1.4  christos  * Additional conversions that are available:
    186   1.1.1.4  christos  *  Convert a null return or zero return value to an EndTag descriptor
    187   1.1.1.4  christos  *  Convert an ASCII string to a Unicode buffer
    188   1.1.1.4  christos  *
    189   1.1.1.4  christos  * An incorrect standalone object is wrapped with required outer package
    190       1.1    jruoho  *
    191   1.1.1.4  christos  * Additional possible repairs:
    192       1.1    jruoho  * Required package elements that are NULL replaced by Integer/String/Buffer
    193       1.1    jruoho  *
    194       1.1    jruoho  ******************************************************************************/
    195       1.1    jruoho 
    196       1.1    jruoho 
    197       1.1    jruoho /* Local prototypes */
    198       1.1    jruoho 
    199   1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO *
    200   1.1.1.4  christos AcpiNsMatchSimpleRepair (
    201   1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    202   1.1.1.4  christos     UINT32                  ReturnBtype,
    203   1.1.1.4  christos     UINT32                  PackageIndex);
    204       1.1    jruoho 
    205       1.1    jruoho 
    206   1.1.1.4  christos /*
    207   1.1.1.4  christos  * Special but simple repairs for some names.
    208   1.1.1.4  christos  *
    209   1.1.1.4  christos  * 2nd argument: Unexpected types that can be repaired
    210   1.1.1.4  christos  */
    211   1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
    212   1.1.1.4  christos {
    213   1.1.1.4  christos     /* Resource descriptor conversions */
    214       1.1    jruoho 
    215   1.1.1.4  christos     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    216   1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    217   1.1.1.4  christos                 AcpiNsConvertToResource },
    218   1.1.1.4  christos     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    219   1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    220   1.1.1.4  christos                 AcpiNsConvertToResource },
    221   1.1.1.4  christos     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    222   1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    223   1.1.1.4  christos                 AcpiNsConvertToResource },
    224   1.1.1.4  christos 
    225   1.1.1.8  christos     /* Object reference conversions */
    226   1.1.1.8  christos 
    227   1.1.1.8  christos     { "_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
    228   1.1.1.8  christos                 AcpiNsConvertToReference },
    229   1.1.1.8  christos 
    230   1.1.1.4  christos     /* Unicode conversions */
    231   1.1.1.4  christos 
    232   1.1.1.4  christos     { "_MLS", ACPI_RTYPE_STRING, 1,
    233   1.1.1.4  christos                 AcpiNsConvertToUnicode },
    234   1.1.1.4  christos     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
    235   1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    236   1.1.1.4  christos                 AcpiNsConvertToUnicode },
    237   1.1.1.4  christos     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
    238   1.1.1.4  christos };
    239       1.1    jruoho 
    240       1.1    jruoho 
    241       1.1    jruoho /*******************************************************************************
    242       1.1    jruoho  *
    243   1.1.1.4  christos  * FUNCTION:    AcpiNsSimpleRepair
    244       1.1    jruoho  *
    245   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    246       1.1    jruoho  *              ExpectedBtypes      - Object types expected
    247       1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    248       1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    249       1.1    jruoho  *                                    otherwise)
    250       1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    251       1.1    jruoho  *                                    evaluation of a method or object
    252       1.1    jruoho  *
    253       1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    254       1.1    jruoho  *
    255       1.1    jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    256       1.1    jruoho  *              not expected.
    257       1.1    jruoho  *
    258       1.1    jruoho  ******************************************************************************/
    259       1.1    jruoho 
    260       1.1    jruoho ACPI_STATUS
    261   1.1.1.4  christos AcpiNsSimpleRepair (
    262   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    263       1.1    jruoho     UINT32                  ExpectedBtypes,
    264       1.1    jruoho     UINT32                  PackageIndex,
    265       1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    266       1.1    jruoho {
    267       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    268   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *NewObject = NULL;
    269       1.1    jruoho     ACPI_STATUS             Status;
    270   1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
    271   1.1.1.4  christos 
    272       1.1    jruoho 
    273   1.1.1.4  christos     ACPI_FUNCTION_NAME (NsSimpleRepair);
    274   1.1.1.4  christos 
    275   1.1.1.4  christos 
    276   1.1.1.4  christos     /*
    277   1.1.1.4  christos      * Special repairs for certain names that are in the repair table.
    278   1.1.1.4  christos      * Check if this name is in the list of repairable names.
    279   1.1.1.4  christos      */
    280   1.1.1.4  christos     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
    281   1.1.1.4  christos         Info->ReturnBtype, PackageIndex);
    282   1.1.1.4  christos     if (Predefined)
    283   1.1.1.4  christos     {
    284   1.1.1.4  christos         if (!ReturnObject)
    285   1.1.1.4  christos         {
    286   1.1.1.4  christos             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    287   1.1.1.4  christos                 ACPI_WARN_ALWAYS, "Missing expected return value"));
    288   1.1.1.4  christos         }
    289       1.1    jruoho 
    290   1.1.1.8  christos         Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
    291   1.1.1.8  christos             &NewObject);
    292   1.1.1.4  christos         if (ACPI_FAILURE (Status))
    293   1.1.1.4  christos         {
    294   1.1.1.4  christos             /* A fatal error occurred during a conversion */
    295       1.1    jruoho 
    296   1.1.1.4  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    297   1.1.1.4  christos                 "During return object analysis"));
    298   1.1.1.4  christos             return (Status);
    299   1.1.1.4  christos         }
    300   1.1.1.4  christos         if (NewObject)
    301   1.1.1.4  christos         {
    302   1.1.1.4  christos             goto ObjectRepaired;
    303   1.1.1.4  christos         }
    304   1.1.1.4  christos     }
    305   1.1.1.4  christos 
    306   1.1.1.4  christos     /*
    307   1.1.1.4  christos      * Do not perform simple object repair unless the return type is not
    308   1.1.1.4  christos      * expected.
    309   1.1.1.4  christos      */
    310   1.1.1.4  christos     if (Info->ReturnBtype & ExpectedBtypes)
    311   1.1.1.4  christos     {
    312   1.1.1.4  christos         return (AE_OK);
    313   1.1.1.4  christos     }
    314       1.1    jruoho 
    315       1.1    jruoho     /*
    316       1.1    jruoho      * At this point, we know that the type of the returned object was not
    317       1.1    jruoho      * one of the expected types for this predefined name. Attempt to
    318       1.1    jruoho      * repair the object by converting it to one of the expected object
    319       1.1    jruoho      * types for this predefined name.
    320       1.1    jruoho      */
    321   1.1.1.4  christos 
    322   1.1.1.4  christos     /*
    323   1.1.1.4  christos      * If there is no return value, check if we require a return value for
    324   1.1.1.4  christos      * this predefined name. Either one return value is expected, or none,
    325   1.1.1.4  christos      * for both methods and other objects.
    326   1.1.1.4  christos      *
    327   1.1.1.5  christos      * Try to fix if there was no return object. Warning if failed to fix.
    328   1.1.1.4  christos      */
    329   1.1.1.4  christos     if (!ReturnObject)
    330   1.1.1.4  christos     {
    331  1.1.1.16  christos         if (ExpectedBtypes)
    332   1.1.1.4  christos         {
    333  1.1.1.16  christos             if (!(ExpectedBtypes & ACPI_RTYPE_NONE) &&
    334  1.1.1.16  christos                 PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    335   1.1.1.5  christos             {
    336   1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    337   1.1.1.5  christos                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
    338   1.1.1.5  christos 
    339   1.1.1.5  christos                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
    340   1.1.1.8  christos                     PackageIndex, ReturnObjectPtr);
    341   1.1.1.5  christos                 if (ACPI_SUCCESS (Status))
    342   1.1.1.5  christos                 {
    343   1.1.1.5  christos                     return (AE_OK); /* Repair was successful */
    344   1.1.1.5  christos                 }
    345   1.1.1.5  christos             }
    346  1.1.1.16  christos 
    347  1.1.1.16  christos             if (ExpectedBtypes != ACPI_RTYPE_NONE)
    348   1.1.1.5  christos             {
    349   1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    350  1.1.1.16  christos                                        ACPI_WARN_ALWAYS,
    351  1.1.1.16  christos                                        "Missing expected return value"));
    352  1.1.1.16  christos                 return (AE_AML_NO_RETURN_VALUE);
    353   1.1.1.5  christos             }
    354   1.1.1.4  christos         }
    355   1.1.1.4  christos     }
    356   1.1.1.4  christos 
    357       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    358       1.1    jruoho     {
    359       1.1    jruoho         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
    360       1.1    jruoho         if (ACPI_SUCCESS (Status))
    361       1.1    jruoho         {
    362       1.1    jruoho             goto ObjectRepaired;
    363       1.1    jruoho         }
    364       1.1    jruoho     }
    365       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_STRING)
    366       1.1    jruoho     {
    367       1.1    jruoho         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
    368       1.1    jruoho         if (ACPI_SUCCESS (Status))
    369       1.1    jruoho         {
    370       1.1    jruoho             goto ObjectRepaired;
    371       1.1    jruoho         }
    372       1.1    jruoho     }
    373       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    374       1.1    jruoho     {
    375       1.1    jruoho         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
    376       1.1    jruoho         if (ACPI_SUCCESS (Status))
    377       1.1    jruoho         {
    378       1.1    jruoho             goto ObjectRepaired;
    379       1.1    jruoho         }
    380       1.1    jruoho     }
    381       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
    382       1.1    jruoho     {
    383   1.1.1.4  christos         /*
    384   1.1.1.4  christos          * A package is expected. We will wrap the existing object with a
    385   1.1.1.4  christos          * new package object. It is often the case that if a variable-length
    386   1.1.1.4  christos          * package is required, but there is only a single object needed, the
    387   1.1.1.4  christos          * BIOS will return that object instead of wrapping it with a Package
    388   1.1.1.4  christos          * object. Note: after the wrapping, the package will be validated
    389   1.1.1.4  christos          * for correct contents (expected object type or types).
    390   1.1.1.4  christos          */
    391   1.1.1.4  christos         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
    392       1.1    jruoho         if (ACPI_SUCCESS (Status))
    393       1.1    jruoho         {
    394   1.1.1.4  christos             /*
    395   1.1.1.4  christos              * The original object just had its reference count
    396   1.1.1.4  christos              * incremented for being inserted into the new package.
    397   1.1.1.4  christos              */
    398   1.1.1.4  christos             *ReturnObjectPtr = NewObject;       /* New Package object */
    399   1.1.1.4  christos             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    400   1.1.1.4  christos             return (AE_OK);
    401       1.1    jruoho         }
    402       1.1    jruoho     }
    403       1.1    jruoho 
    404       1.1    jruoho     /* We cannot repair this object */
    405       1.1    jruoho 
    406       1.1    jruoho     return (AE_AML_OPERAND_TYPE);
    407       1.1    jruoho 
    408       1.1    jruoho 
    409       1.1    jruoho ObjectRepaired:
    410       1.1    jruoho 
    411       1.1    jruoho     /* Object was successfully repaired */
    412       1.1    jruoho 
    413       1.1    jruoho     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    414       1.1    jruoho     {
    415  1.1.1.10  christos         /* Update reference count of new object */
    416  1.1.1.10  christos 
    417   1.1.1.4  christos         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
    418       1.1    jruoho         {
    419   1.1.1.4  christos             NewObject->Common.ReferenceCount =
    420   1.1.1.4  christos                 ReturnObject->Common.ReferenceCount;
    421       1.1    jruoho         }
    422       1.1    jruoho 
    423       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    424   1.1.1.4  christos             "%s: Converted %s to expected %s at Package index %u\n",
    425   1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    426       1.1    jruoho             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    427       1.1    jruoho     }
    428       1.1    jruoho     else
    429       1.1    jruoho     {
    430       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    431       1.1    jruoho             "%s: Converted %s to expected %s\n",
    432   1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    433       1.1    jruoho             AcpiUtGetObjectTypeName (NewObject)));
    434       1.1    jruoho     }
    435       1.1    jruoho 
    436       1.1    jruoho     /* Delete old object, install the new return object */
    437       1.1    jruoho 
    438       1.1    jruoho     AcpiUtRemoveReference (ReturnObject);
    439       1.1    jruoho     *ReturnObjectPtr = NewObject;
    440   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    441       1.1    jruoho     return (AE_OK);
    442       1.1    jruoho }
    443       1.1    jruoho 
    444       1.1    jruoho 
    445   1.1.1.4  christos /******************************************************************************
    446       1.1    jruoho  *
    447   1.1.1.4  christos  * FUNCTION:    AcpiNsMatchSimpleRepair
    448       1.1    jruoho  *
    449   1.1.1.4  christos  * PARAMETERS:  Node                - Namespace node for the method/object
    450   1.1.1.4  christos  *              ReturnBtype         - Object type that was returned
    451   1.1.1.4  christos  *              PackageIndex        - Index of object within parent package (if
    452   1.1.1.4  christos  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    453   1.1.1.4  christos  *                                    otherwise)
    454       1.1    jruoho  *
    455   1.1.1.4  christos  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
    456       1.1    jruoho  *
    457   1.1.1.4  christos  * DESCRIPTION: Check an object name against the repairable object list.
    458       1.1    jruoho  *
    459   1.1.1.4  christos  *****************************************************************************/
    460       1.1    jruoho 
    461   1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO *
    462   1.1.1.4  christos AcpiNsMatchSimpleRepair (
    463   1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    464   1.1.1.4  christos     UINT32                  ReturnBtype,
    465   1.1.1.4  christos     UINT32                  PackageIndex)
    466       1.1    jruoho {
    467   1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
    468       1.1    jruoho 
    469       1.1    jruoho 
    470   1.1.1.4  christos     /* Search info table for a repairable predefined method/object name */
    471       1.1    jruoho 
    472   1.1.1.4  christos     ThisName = AcpiObjectRepairInfo;
    473   1.1.1.4  christos     while (ThisName->ObjectConverter)
    474       1.1    jruoho     {
    475  1.1.1.12  christos         if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, ThisName->Name))
    476       1.1    jruoho         {
    477   1.1.1.4  christos             /* Check if we can actually repair this name/type combination */
    478       1.1    jruoho 
    479   1.1.1.4  christos             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
    480   1.1.1.8  christos                 (ThisName->PackageIndex == ACPI_ALL_PACKAGE_ELEMENTS ||
    481   1.1.1.8  christos                  PackageIndex == ThisName->PackageIndex))
    482       1.1    jruoho             {
    483   1.1.1.4  christos                 return (ThisName);
    484       1.1    jruoho             }
    485       1.1    jruoho 
    486   1.1.1.4  christos             return (NULL);
    487       1.1    jruoho         }
    488   1.1.1.8  christos 
    489   1.1.1.4  christos         ThisName++;
    490       1.1    jruoho     }
    491       1.1    jruoho 
    492   1.1.1.4  christos     return (NULL); /* Name was not found in the repair table */
    493       1.1    jruoho }
    494       1.1    jruoho 
    495       1.1    jruoho 
    496       1.1    jruoho /*******************************************************************************
    497       1.1    jruoho  *
    498       1.1    jruoho  * FUNCTION:    AcpiNsRepairNullElement
    499       1.1    jruoho  *
    500   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    501       1.1    jruoho  *              ExpectedBtypes      - Object types expected
    502       1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    503       1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    504       1.1    jruoho  *                                    otherwise)
    505       1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    506       1.1    jruoho  *                                    evaluation of a method or object
    507       1.1    jruoho  *
    508       1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    509       1.1    jruoho  *
    510       1.1    jruoho  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
    511       1.1    jruoho  *
    512       1.1    jruoho  ******************************************************************************/
    513       1.1    jruoho 
    514       1.1    jruoho ACPI_STATUS
    515       1.1    jruoho AcpiNsRepairNullElement (
    516   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    517       1.1    jruoho     UINT32                  ExpectedBtypes,
    518       1.1    jruoho     UINT32                  PackageIndex,
    519       1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    520       1.1    jruoho {
    521       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    522       1.1    jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    523       1.1    jruoho 
    524       1.1    jruoho 
    525       1.1    jruoho     ACPI_FUNCTION_NAME (NsRepairNullElement);
    526       1.1    jruoho 
    527       1.1    jruoho 
    528       1.1    jruoho     /* No repair needed if return object is non-NULL */
    529       1.1    jruoho 
    530       1.1    jruoho     if (ReturnObject)
    531       1.1    jruoho     {
    532       1.1    jruoho         return (AE_OK);
    533       1.1    jruoho     }
    534       1.1    jruoho 
    535       1.1    jruoho     /*
    536       1.1    jruoho      * Attempt to repair a NULL element of a Package object. This applies to
    537       1.1    jruoho      * predefined names that return a fixed-length package and each element
    538       1.1    jruoho      * is required. It does not apply to variable-length packages where NULL
    539       1.1    jruoho      * elements are allowed, especially at the end of the package.
    540       1.1    jruoho      */
    541       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    542       1.1    jruoho     {
    543       1.1    jruoho         /* Need an Integer - create a zero-value integer */
    544       1.1    jruoho 
    545   1.1.1.2    jruoho         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
    546       1.1    jruoho     }
    547       1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
    548       1.1    jruoho     {
    549       1.1    jruoho         /* Need a String - create a NULL string */
    550       1.1    jruoho 
    551       1.1    jruoho         NewObject = AcpiUtCreateStringObject (0);
    552       1.1    jruoho     }
    553       1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    554       1.1    jruoho     {
    555       1.1    jruoho         /* Need a Buffer - create a zero-length buffer */
    556       1.1    jruoho 
    557       1.1    jruoho         NewObject = AcpiUtCreateBufferObject (0);
    558       1.1    jruoho     }
    559       1.1    jruoho     else
    560       1.1    jruoho     {
    561       1.1    jruoho         /* Error for all other expected types */
    562       1.1    jruoho 
    563       1.1    jruoho         return (AE_AML_OPERAND_TYPE);
    564       1.1    jruoho     }
    565       1.1    jruoho 
    566       1.1    jruoho     if (!NewObject)
    567       1.1    jruoho     {
    568       1.1    jruoho         return (AE_NO_MEMORY);
    569       1.1    jruoho     }
    570       1.1    jruoho 
    571       1.1    jruoho     /* Set the reference count according to the parent Package object */
    572       1.1    jruoho 
    573   1.1.1.8  christos     NewObject->Common.ReferenceCount =
    574   1.1.1.8  christos         Info->ParentPackage->Common.ReferenceCount;
    575       1.1    jruoho 
    576       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    577       1.1    jruoho         "%s: Converted NULL package element to expected %s at index %u\n",
    578   1.1.1.8  christos         Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
    579   1.1.1.8  christos         PackageIndex));
    580       1.1    jruoho 
    581       1.1    jruoho     *ReturnObjectPtr = NewObject;
    582   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    583       1.1    jruoho     return (AE_OK);
    584       1.1    jruoho }
    585       1.1    jruoho 
    586       1.1    jruoho 
    587       1.1    jruoho /******************************************************************************
    588       1.1    jruoho  *
    589       1.1    jruoho  * FUNCTION:    AcpiNsRemoveNullElements
    590       1.1    jruoho  *
    591   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    592       1.1    jruoho  *              PackageType         - An AcpiReturnPackageTypes value
    593       1.1    jruoho  *              ObjDesc             - A Package object
    594       1.1    jruoho  *
    595       1.1    jruoho  * RETURN:      None.
    596       1.1    jruoho  *
    597       1.1    jruoho  * DESCRIPTION: Remove all NULL package elements from packages that contain
    598   1.1.1.5  christos  *              a variable number of subpackages. For these types of
    599       1.1    jruoho  *              packages, NULL elements can be safely removed.
    600       1.1    jruoho  *
    601       1.1    jruoho  *****************************************************************************/
    602       1.1    jruoho 
    603       1.1    jruoho void
    604       1.1    jruoho AcpiNsRemoveNullElements (
    605   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    606       1.1    jruoho     UINT8                   PackageType,
    607       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc)
    608       1.1    jruoho {
    609       1.1    jruoho     ACPI_OPERAND_OBJECT     **Source;
    610       1.1    jruoho     ACPI_OPERAND_OBJECT     **Dest;
    611       1.1    jruoho     UINT32                  Count;
    612       1.1    jruoho     UINT32                  NewCount;
    613       1.1    jruoho     UINT32                  i;
    614       1.1    jruoho 
    615       1.1    jruoho 
    616       1.1    jruoho     ACPI_FUNCTION_NAME (NsRemoveNullElements);
    617       1.1    jruoho 
    618       1.1    jruoho 
    619       1.1    jruoho     /*
    620   1.1.1.3    jruoho      * We can safely remove all NULL elements from these package types:
    621   1.1.1.3    jruoho      * PTYPE1_VAR packages contain a variable number of simple data types.
    622   1.1.1.5  christos      * PTYPE2 packages contain a variable number of subpackages.
    623       1.1    jruoho      */
    624       1.1    jruoho     switch (PackageType)
    625       1.1    jruoho     {
    626       1.1    jruoho     case ACPI_PTYPE1_VAR:
    627       1.1    jruoho     case ACPI_PTYPE2:
    628       1.1    jruoho     case ACPI_PTYPE2_COUNT:
    629       1.1    jruoho     case ACPI_PTYPE2_PKG_COUNT:
    630       1.1    jruoho     case ACPI_PTYPE2_FIXED:
    631       1.1    jruoho     case ACPI_PTYPE2_MIN:
    632       1.1    jruoho     case ACPI_PTYPE2_REV_FIXED:
    633   1.1.1.4  christos     case ACPI_PTYPE2_FIX_VAR:
    634       1.1    jruoho         break;
    635       1.1    jruoho 
    636       1.1    jruoho     default:
    637   1.1.1.7  christos     case ACPI_PTYPE2_VAR_VAR:
    638   1.1.1.3    jruoho     case ACPI_PTYPE1_FIXED:
    639   1.1.1.3    jruoho     case ACPI_PTYPE1_OPTION:
    640       1.1    jruoho         return;
    641       1.1    jruoho     }
    642       1.1    jruoho 
    643       1.1    jruoho     Count = ObjDesc->Package.Count;
    644       1.1    jruoho     NewCount = Count;
    645       1.1    jruoho 
    646       1.1    jruoho     Source = ObjDesc->Package.Elements;
    647       1.1    jruoho     Dest = Source;
    648       1.1    jruoho 
    649       1.1    jruoho     /* Examine all elements of the package object, remove nulls */
    650       1.1    jruoho 
    651       1.1    jruoho     for (i = 0; i < Count; i++)
    652       1.1    jruoho     {
    653       1.1    jruoho         if (!*Source)
    654       1.1    jruoho         {
    655       1.1    jruoho             NewCount--;
    656       1.1    jruoho         }
    657       1.1    jruoho         else
    658       1.1    jruoho         {
    659       1.1    jruoho             *Dest = *Source;
    660       1.1    jruoho             Dest++;
    661       1.1    jruoho         }
    662   1.1.1.8  christos 
    663       1.1    jruoho         Source++;
    664       1.1    jruoho     }
    665       1.1    jruoho 
    666       1.1    jruoho     /* Update parent package if any null elements were removed */
    667       1.1    jruoho 
    668       1.1    jruoho     if (NewCount < Count)
    669       1.1    jruoho     {
    670       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    671       1.1    jruoho             "%s: Found and removed %u NULL elements\n",
    672   1.1.1.4  christos             Info->FullPathname, (Count - NewCount)));
    673       1.1    jruoho 
    674       1.1    jruoho         /* NULL terminate list and update the package count */
    675       1.1    jruoho 
    676       1.1    jruoho         *Dest = NULL;
    677       1.1    jruoho         ObjDesc->Package.Count = NewCount;
    678       1.1    jruoho     }
    679       1.1    jruoho }
    680       1.1    jruoho 
    681       1.1    jruoho 
    682       1.1    jruoho /*******************************************************************************
    683       1.1    jruoho  *
    684   1.1.1.4  christos  * FUNCTION:    AcpiNsWrapWithPackage
    685       1.1    jruoho  *
    686   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    687   1.1.1.4  christos  *              OriginalObject      - Pointer to the object to repair.
    688   1.1.1.4  christos  *              ObjDescPtr          - The new package object is returned here
    689       1.1    jruoho  *
    690       1.1    jruoho  * RETURN:      Status, new object in *ObjDescPtr
    691       1.1    jruoho  *
    692   1.1.1.4  christos  * DESCRIPTION: Repair a common problem with objects that are defined to
    693   1.1.1.4  christos  *              return a variable-length Package of sub-objects. If there is
    694   1.1.1.4  christos  *              only one sub-object, some BIOS code mistakenly simply declares
    695   1.1.1.4  christos  *              the single object instead of a Package with one sub-object.
    696   1.1.1.4  christos  *              This function attempts to repair this error by wrapping a
    697   1.1.1.4  christos  *              Package object around the original object, creating the
    698   1.1.1.4  christos  *              correct and expected Package with one sub-object.
    699       1.1    jruoho  *
    700       1.1    jruoho  *              Names that can be repaired in this manner include:
    701   1.1.1.4  christos  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
    702   1.1.1.4  christos  *              _BCL, _DOD, _FIX, _Sx
    703       1.1    jruoho  *
    704       1.1    jruoho  ******************************************************************************/
    705       1.1    jruoho 
    706       1.1    jruoho ACPI_STATUS
    707   1.1.1.4  christos AcpiNsWrapWithPackage (
    708   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    709   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    710       1.1    jruoho     ACPI_OPERAND_OBJECT     **ObjDescPtr)
    711       1.1    jruoho {
    712       1.1    jruoho     ACPI_OPERAND_OBJECT     *PkgObjDesc;
    713       1.1    jruoho 
    714       1.1    jruoho 
    715   1.1.1.4  christos     ACPI_FUNCTION_NAME (NsWrapWithPackage);
    716       1.1    jruoho 
    717       1.1    jruoho 
    718       1.1    jruoho     /*
    719   1.1.1.8  christos      * Create the new outer package and populate it. The new
    720   1.1.1.8  christos      * package will have a single element, the lone sub-object.
    721       1.1    jruoho      */
    722       1.1    jruoho     PkgObjDesc = AcpiUtCreatePackageObject (1);
    723       1.1    jruoho     if (!PkgObjDesc)
    724       1.1    jruoho     {
    725       1.1    jruoho         return (AE_NO_MEMORY);
    726       1.1    jruoho     }
    727       1.1    jruoho 
    728   1.1.1.4  christos     PkgObjDesc->Package.Elements[0] = OriginalObject;
    729   1.1.1.4  christos 
    730   1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    731   1.1.1.4  christos         "%s: Wrapped %s with expected Package object\n",
    732   1.1.1.4  christos         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
    733       1.1    jruoho 
    734       1.1    jruoho     /* Return the new object in the object pointer */
    735       1.1    jruoho 
    736       1.1    jruoho     *ObjDescPtr = PkgObjDesc;
    737   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
    738       1.1    jruoho     return (AE_OK);
    739       1.1    jruoho }
    740