Home | History | Annotate | Line # | Download | only in namespace
nsrepair.c revision 1.1.1.5.2.1
      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.2    jruoho /*
      8  1.1.1.5.2.1     skrll  * Copyright (C) 2000 - 2015, Intel Corp.
      9          1.1    jruoho  * All rights reserved.
     10          1.1    jruoho  *
     11      1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12      1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13      1.1.1.2    jruoho  * are met:
     14      1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15      1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16      1.1.1.2    jruoho  *    without modification.
     17      1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18      1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19      1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20      1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21      1.1.1.2    jruoho  *    binary redistribution.
     22      1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23      1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24      1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25      1.1.1.2    jruoho  *
     26      1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27      1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28      1.1.1.2    jruoho  * Software Foundation.
     29      1.1.1.2    jruoho  *
     30      1.1.1.2    jruoho  * NO WARRANTY
     31      1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32      1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33      1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34      1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35      1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36      1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37      1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38      1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39      1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40      1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41      1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42      1.1.1.2    jruoho  */
     43          1.1    jruoho 
     44          1.1    jruoho #include "acpi.h"
     45          1.1    jruoho #include "accommon.h"
     46          1.1    jruoho #include "acnamesp.h"
     47          1.1    jruoho #include "acinterp.h"
     48          1.1    jruoho #include "acpredef.h"
     49      1.1.1.4  christos #include "amlresrc.h"
     50          1.1    jruoho 
     51          1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
     52          1.1    jruoho         ACPI_MODULE_NAME    ("nsrepair")
     53          1.1    jruoho 
     54          1.1    jruoho 
     55          1.1    jruoho /*******************************************************************************
     56          1.1    jruoho  *
     57          1.1    jruoho  * This module attempts to repair or convert objects returned by the
     58          1.1    jruoho  * predefined methods to an object type that is expected, as per the ACPI
     59          1.1    jruoho  * specification. The need for this code is dictated by the many machines that
     60          1.1    jruoho  * return incorrect types for the standard predefined methods. Performing these
     61          1.1    jruoho  * conversions here, in one place, eliminates the need for individual ACPI
     62          1.1    jruoho  * device drivers to do the same. Note: Most of these conversions are different
     63          1.1    jruoho  * than the internal object conversion routines used for implicit object
     64          1.1    jruoho  * conversion.
     65          1.1    jruoho  *
     66          1.1    jruoho  * The following conversions can be performed as necessary:
     67          1.1    jruoho  *
     68          1.1    jruoho  * Integer -> String
     69          1.1    jruoho  * Integer -> Buffer
     70          1.1    jruoho  * String  -> Integer
     71          1.1    jruoho  * String  -> Buffer
     72          1.1    jruoho  * Buffer  -> Integer
     73          1.1    jruoho  * Buffer  -> String
     74          1.1    jruoho  * Buffer  -> Package of Integers
     75          1.1    jruoho  * Package -> Package of one Package
     76          1.1    jruoho  *
     77      1.1.1.4  christos  * Additional conversions that are available:
     78      1.1.1.4  christos  *  Convert a null return or zero return value to an EndTag descriptor
     79      1.1.1.4  christos  *  Convert an ASCII string to a Unicode buffer
     80      1.1.1.4  christos  *
     81      1.1.1.4  christos  * An incorrect standalone object is wrapped with required outer package
     82          1.1    jruoho  *
     83      1.1.1.4  christos  * Additional possible repairs:
     84          1.1    jruoho  * Required package elements that are NULL replaced by Integer/String/Buffer
     85          1.1    jruoho  *
     86          1.1    jruoho  ******************************************************************************/
     87          1.1    jruoho 
     88          1.1    jruoho 
     89          1.1    jruoho /* Local prototypes */
     90          1.1    jruoho 
     91      1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO *
     92      1.1.1.4  christos AcpiNsMatchSimpleRepair (
     93      1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
     94      1.1.1.4  christos     UINT32                  ReturnBtype,
     95      1.1.1.4  christos     UINT32                  PackageIndex);
     96          1.1    jruoho 
     97          1.1    jruoho 
     98      1.1.1.4  christos /*
     99      1.1.1.4  christos  * Special but simple repairs for some names.
    100      1.1.1.4  christos  *
    101      1.1.1.4  christos  * 2nd argument: Unexpected types that can be repaired
    102      1.1.1.4  christos  */
    103      1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
    104      1.1.1.4  christos {
    105      1.1.1.4  christos     /* Resource descriptor conversions */
    106          1.1    jruoho 
    107      1.1.1.4  christos     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    108      1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    109      1.1.1.4  christos                 AcpiNsConvertToResource },
    110      1.1.1.4  christos     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    111      1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    112      1.1.1.4  christos                 AcpiNsConvertToResource },
    113      1.1.1.4  christos     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
    114      1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    115      1.1.1.4  christos                 AcpiNsConvertToResource },
    116      1.1.1.4  christos 
    117      1.1.1.4  christos     /* Unicode conversions */
    118      1.1.1.4  christos 
    119      1.1.1.4  christos     { "_MLS", ACPI_RTYPE_STRING, 1,
    120      1.1.1.4  christos                 AcpiNsConvertToUnicode },
    121      1.1.1.4  christos     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
    122      1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    123      1.1.1.4  christos                 AcpiNsConvertToUnicode },
    124      1.1.1.4  christos     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
    125      1.1.1.4  christos };
    126          1.1    jruoho 
    127          1.1    jruoho 
    128          1.1    jruoho /*******************************************************************************
    129          1.1    jruoho  *
    130      1.1.1.4  christos  * FUNCTION:    AcpiNsSimpleRepair
    131          1.1    jruoho  *
    132      1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    133          1.1    jruoho  *              ExpectedBtypes      - Object types expected
    134          1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    135          1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    136          1.1    jruoho  *                                    otherwise)
    137          1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    138          1.1    jruoho  *                                    evaluation of a method or object
    139          1.1    jruoho  *
    140          1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    141          1.1    jruoho  *
    142          1.1    jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    143          1.1    jruoho  *              not expected.
    144          1.1    jruoho  *
    145          1.1    jruoho  ******************************************************************************/
    146          1.1    jruoho 
    147          1.1    jruoho ACPI_STATUS
    148      1.1.1.4  christos AcpiNsSimpleRepair (
    149      1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    150          1.1    jruoho     UINT32                  ExpectedBtypes,
    151          1.1    jruoho     UINT32                  PackageIndex,
    152          1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    153          1.1    jruoho {
    154          1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    155      1.1.1.4  christos     ACPI_OPERAND_OBJECT     *NewObject = NULL;
    156          1.1    jruoho     ACPI_STATUS             Status;
    157      1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
    158      1.1.1.4  christos 
    159          1.1    jruoho 
    160      1.1.1.4  christos     ACPI_FUNCTION_NAME (NsSimpleRepair);
    161      1.1.1.4  christos 
    162      1.1.1.4  christos 
    163      1.1.1.4  christos     /*
    164      1.1.1.4  christos      * Special repairs for certain names that are in the repair table.
    165      1.1.1.4  christos      * Check if this name is in the list of repairable names.
    166      1.1.1.4  christos      */
    167      1.1.1.4  christos     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
    168      1.1.1.4  christos         Info->ReturnBtype, PackageIndex);
    169      1.1.1.4  christos     if (Predefined)
    170      1.1.1.4  christos     {
    171      1.1.1.4  christos         if (!ReturnObject)
    172      1.1.1.4  christos         {
    173      1.1.1.4  christos             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    174      1.1.1.4  christos                 ACPI_WARN_ALWAYS, "Missing expected return value"));
    175      1.1.1.4  christos         }
    176          1.1    jruoho 
    177      1.1.1.4  christos         Status = Predefined->ObjectConverter (ReturnObject, &NewObject);
    178      1.1.1.4  christos         if (ACPI_FAILURE (Status))
    179      1.1.1.4  christos         {
    180      1.1.1.4  christos             /* A fatal error occurred during a conversion */
    181          1.1    jruoho 
    182      1.1.1.4  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    183      1.1.1.4  christos                 "During return object analysis"));
    184      1.1.1.4  christos             return (Status);
    185      1.1.1.4  christos         }
    186      1.1.1.4  christos         if (NewObject)
    187      1.1.1.4  christos         {
    188      1.1.1.4  christos             goto ObjectRepaired;
    189      1.1.1.4  christos         }
    190      1.1.1.4  christos     }
    191      1.1.1.4  christos 
    192      1.1.1.4  christos     /*
    193      1.1.1.4  christos      * Do not perform simple object repair unless the return type is not
    194      1.1.1.4  christos      * expected.
    195      1.1.1.4  christos      */
    196      1.1.1.4  christos     if (Info->ReturnBtype & ExpectedBtypes)
    197      1.1.1.4  christos     {
    198      1.1.1.4  christos         return (AE_OK);
    199      1.1.1.4  christos     }
    200          1.1    jruoho 
    201          1.1    jruoho     /*
    202          1.1    jruoho      * At this point, we know that the type of the returned object was not
    203          1.1    jruoho      * one of the expected types for this predefined name. Attempt to
    204          1.1    jruoho      * repair the object by converting it to one of the expected object
    205          1.1    jruoho      * types for this predefined name.
    206          1.1    jruoho      */
    207      1.1.1.4  christos 
    208      1.1.1.4  christos     /*
    209      1.1.1.4  christos      * If there is no return value, check if we require a return value for
    210      1.1.1.4  christos      * this predefined name. Either one return value is expected, or none,
    211      1.1.1.4  christos      * for both methods and other objects.
    212      1.1.1.4  christos      *
    213      1.1.1.5  christos      * Try to fix if there was no return object. Warning if failed to fix.
    214      1.1.1.4  christos      */
    215      1.1.1.4  christos     if (!ReturnObject)
    216      1.1.1.4  christos     {
    217      1.1.1.4  christos         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
    218      1.1.1.4  christos         {
    219      1.1.1.5  christos             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    220      1.1.1.5  christos             {
    221      1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    222      1.1.1.5  christos                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
    223      1.1.1.5  christos 
    224      1.1.1.5  christos                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
    225      1.1.1.5  christos                             PackageIndex, ReturnObjectPtr);
    226      1.1.1.5  christos                 if (ACPI_SUCCESS (Status))
    227      1.1.1.5  christos                 {
    228      1.1.1.5  christos                     return (AE_OK); /* Repair was successful */
    229      1.1.1.5  christos                 }
    230      1.1.1.5  christos             }
    231      1.1.1.5  christos             else
    232      1.1.1.5  christos             {
    233      1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    234      1.1.1.5  christos                     ACPI_WARN_ALWAYS, "Missing expected return value"));
    235      1.1.1.5  christos             }
    236      1.1.1.4  christos 
    237      1.1.1.4  christos             return (AE_AML_NO_RETURN_VALUE);
    238      1.1.1.4  christos         }
    239      1.1.1.4  christos     }
    240      1.1.1.4  christos 
    241          1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    242          1.1    jruoho     {
    243          1.1    jruoho         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
    244          1.1    jruoho         if (ACPI_SUCCESS (Status))
    245          1.1    jruoho         {
    246          1.1    jruoho             goto ObjectRepaired;
    247          1.1    jruoho         }
    248          1.1    jruoho     }
    249          1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_STRING)
    250          1.1    jruoho     {
    251          1.1    jruoho         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
    252          1.1    jruoho         if (ACPI_SUCCESS (Status))
    253          1.1    jruoho         {
    254          1.1    jruoho             goto ObjectRepaired;
    255          1.1    jruoho         }
    256          1.1    jruoho     }
    257          1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    258          1.1    jruoho     {
    259          1.1    jruoho         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
    260          1.1    jruoho         if (ACPI_SUCCESS (Status))
    261          1.1    jruoho         {
    262          1.1    jruoho             goto ObjectRepaired;
    263          1.1    jruoho         }
    264          1.1    jruoho     }
    265          1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
    266          1.1    jruoho     {
    267      1.1.1.4  christos         /*
    268      1.1.1.4  christos          * A package is expected. We will wrap the existing object with a
    269      1.1.1.4  christos          * new package object. It is often the case that if a variable-length
    270      1.1.1.4  christos          * package is required, but there is only a single object needed, the
    271      1.1.1.4  christos          * BIOS will return that object instead of wrapping it with a Package
    272      1.1.1.4  christos          * object. Note: after the wrapping, the package will be validated
    273      1.1.1.4  christos          * for correct contents (expected object type or types).
    274      1.1.1.4  christos          */
    275      1.1.1.4  christos         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
    276          1.1    jruoho         if (ACPI_SUCCESS (Status))
    277          1.1    jruoho         {
    278      1.1.1.4  christos             /*
    279      1.1.1.4  christos              * The original object just had its reference count
    280      1.1.1.4  christos              * incremented for being inserted into the new package.
    281      1.1.1.4  christos              */
    282      1.1.1.4  christos             *ReturnObjectPtr = NewObject;       /* New Package object */
    283      1.1.1.4  christos             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    284      1.1.1.4  christos             return (AE_OK);
    285          1.1    jruoho         }
    286          1.1    jruoho     }
    287          1.1    jruoho 
    288          1.1    jruoho     /* We cannot repair this object */
    289          1.1    jruoho 
    290          1.1    jruoho     return (AE_AML_OPERAND_TYPE);
    291          1.1    jruoho 
    292          1.1    jruoho 
    293          1.1    jruoho ObjectRepaired:
    294          1.1    jruoho 
    295          1.1    jruoho     /* Object was successfully repaired */
    296          1.1    jruoho 
    297          1.1    jruoho     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    298          1.1    jruoho     {
    299      1.1.1.4  christos         /*
    300      1.1.1.4  christos          * The original object is a package element. We need to
    301      1.1.1.4  christos          * decrement the reference count of the original object,
    302      1.1.1.4  christos          * for removing it from the package.
    303      1.1.1.4  christos          *
    304      1.1.1.4  christos          * However, if the original object was just wrapped with a
    305      1.1.1.4  christos          * package object as part of the repair, we don't need to
    306      1.1.1.4  christos          * change the reference count.
    307      1.1.1.4  christos          */
    308      1.1.1.4  christos         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
    309          1.1    jruoho         {
    310      1.1.1.4  christos             NewObject->Common.ReferenceCount =
    311      1.1.1.4  christos                 ReturnObject->Common.ReferenceCount;
    312      1.1.1.4  christos 
    313      1.1.1.4  christos             if (ReturnObject->Common.ReferenceCount > 1)
    314      1.1.1.4  christos             {
    315      1.1.1.4  christos                 ReturnObject->Common.ReferenceCount--;
    316      1.1.1.4  christos             }
    317          1.1    jruoho         }
    318          1.1    jruoho 
    319          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    320      1.1.1.4  christos             "%s: Converted %s to expected %s at Package index %u\n",
    321      1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    322          1.1    jruoho             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    323          1.1    jruoho     }
    324          1.1    jruoho     else
    325          1.1    jruoho     {
    326          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    327          1.1    jruoho             "%s: Converted %s to expected %s\n",
    328      1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    329          1.1    jruoho             AcpiUtGetObjectTypeName (NewObject)));
    330          1.1    jruoho     }
    331          1.1    jruoho 
    332          1.1    jruoho     /* Delete old object, install the new return object */
    333          1.1    jruoho 
    334          1.1    jruoho     AcpiUtRemoveReference (ReturnObject);
    335          1.1    jruoho     *ReturnObjectPtr = NewObject;
    336      1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    337          1.1    jruoho     return (AE_OK);
    338          1.1    jruoho }
    339          1.1    jruoho 
    340          1.1    jruoho 
    341      1.1.1.4  christos /******************************************************************************
    342          1.1    jruoho  *
    343      1.1.1.4  christos  * FUNCTION:    AcpiNsMatchSimpleRepair
    344          1.1    jruoho  *
    345      1.1.1.4  christos  * PARAMETERS:  Node                - Namespace node for the method/object
    346      1.1.1.4  christos  *              ReturnBtype         - Object type that was returned
    347      1.1.1.4  christos  *              PackageIndex        - Index of object within parent package (if
    348      1.1.1.4  christos  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    349      1.1.1.4  christos  *                                    otherwise)
    350          1.1    jruoho  *
    351      1.1.1.4  christos  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
    352          1.1    jruoho  *
    353      1.1.1.4  christos  * DESCRIPTION: Check an object name against the repairable object list.
    354          1.1    jruoho  *
    355      1.1.1.4  christos  *****************************************************************************/
    356          1.1    jruoho 
    357      1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO *
    358      1.1.1.4  christos AcpiNsMatchSimpleRepair (
    359      1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    360      1.1.1.4  christos     UINT32                  ReturnBtype,
    361      1.1.1.4  christos     UINT32                  PackageIndex)
    362          1.1    jruoho {
    363      1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
    364          1.1    jruoho 
    365          1.1    jruoho 
    366      1.1.1.4  christos     /* Search info table for a repairable predefined method/object name */
    367          1.1    jruoho 
    368      1.1.1.4  christos     ThisName = AcpiObjectRepairInfo;
    369      1.1.1.4  christos     while (ThisName->ObjectConverter)
    370          1.1    jruoho     {
    371      1.1.1.4  christos         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
    372          1.1    jruoho         {
    373      1.1.1.4  christos             /* Check if we can actually repair this name/type combination */
    374          1.1    jruoho 
    375      1.1.1.4  christos             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
    376      1.1.1.4  christos                 (PackageIndex == ThisName->PackageIndex))
    377          1.1    jruoho             {
    378      1.1.1.4  christos                 return (ThisName);
    379          1.1    jruoho             }
    380          1.1    jruoho 
    381      1.1.1.4  christos             return (NULL);
    382          1.1    jruoho         }
    383      1.1.1.4  christos         ThisName++;
    384          1.1    jruoho     }
    385          1.1    jruoho 
    386      1.1.1.4  christos     return (NULL); /* Name was not found in the repair table */
    387          1.1    jruoho }
    388          1.1    jruoho 
    389          1.1    jruoho 
    390          1.1    jruoho /*******************************************************************************
    391          1.1    jruoho  *
    392          1.1    jruoho  * FUNCTION:    AcpiNsRepairNullElement
    393          1.1    jruoho  *
    394      1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    395          1.1    jruoho  *              ExpectedBtypes      - Object types expected
    396          1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    397          1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    398          1.1    jruoho  *                                    otherwise)
    399          1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    400          1.1    jruoho  *                                    evaluation of a method or object
    401          1.1    jruoho  *
    402          1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    403          1.1    jruoho  *
    404          1.1    jruoho  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
    405          1.1    jruoho  *
    406          1.1    jruoho  ******************************************************************************/
    407          1.1    jruoho 
    408          1.1    jruoho ACPI_STATUS
    409          1.1    jruoho AcpiNsRepairNullElement (
    410      1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    411          1.1    jruoho     UINT32                  ExpectedBtypes,
    412          1.1    jruoho     UINT32                  PackageIndex,
    413          1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    414          1.1    jruoho {
    415          1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    416          1.1    jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    417          1.1    jruoho 
    418          1.1    jruoho 
    419          1.1    jruoho     ACPI_FUNCTION_NAME (NsRepairNullElement);
    420          1.1    jruoho 
    421          1.1    jruoho 
    422          1.1    jruoho     /* No repair needed if return object is non-NULL */
    423          1.1    jruoho 
    424          1.1    jruoho     if (ReturnObject)
    425          1.1    jruoho     {
    426          1.1    jruoho         return (AE_OK);
    427          1.1    jruoho     }
    428          1.1    jruoho 
    429          1.1    jruoho     /*
    430          1.1    jruoho      * Attempt to repair a NULL element of a Package object. This applies to
    431          1.1    jruoho      * predefined names that return a fixed-length package and each element
    432          1.1    jruoho      * is required. It does not apply to variable-length packages where NULL
    433          1.1    jruoho      * elements are allowed, especially at the end of the package.
    434          1.1    jruoho      */
    435          1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    436          1.1    jruoho     {
    437          1.1    jruoho         /* Need an Integer - create a zero-value integer */
    438          1.1    jruoho 
    439      1.1.1.2    jruoho         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
    440          1.1    jruoho     }
    441          1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
    442          1.1    jruoho     {
    443          1.1    jruoho         /* Need a String - create a NULL string */
    444          1.1    jruoho 
    445          1.1    jruoho         NewObject = AcpiUtCreateStringObject (0);
    446          1.1    jruoho     }
    447          1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    448          1.1    jruoho     {
    449          1.1    jruoho         /* Need a Buffer - create a zero-length buffer */
    450          1.1    jruoho 
    451          1.1    jruoho         NewObject = AcpiUtCreateBufferObject (0);
    452          1.1    jruoho     }
    453          1.1    jruoho     else
    454          1.1    jruoho     {
    455          1.1    jruoho         /* Error for all other expected types */
    456          1.1    jruoho 
    457          1.1    jruoho         return (AE_AML_OPERAND_TYPE);
    458          1.1    jruoho     }
    459          1.1    jruoho 
    460          1.1    jruoho     if (!NewObject)
    461          1.1    jruoho     {
    462          1.1    jruoho         return (AE_NO_MEMORY);
    463          1.1    jruoho     }
    464          1.1    jruoho 
    465          1.1    jruoho     /* Set the reference count according to the parent Package object */
    466          1.1    jruoho 
    467      1.1.1.4  christos     NewObject->Common.ReferenceCount = Info->ParentPackage->Common.ReferenceCount;
    468          1.1    jruoho 
    469          1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    470          1.1    jruoho         "%s: Converted NULL package element to expected %s at index %u\n",
    471      1.1.1.4  christos          Info->FullPathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    472          1.1    jruoho 
    473          1.1    jruoho     *ReturnObjectPtr = NewObject;
    474      1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    475          1.1    jruoho     return (AE_OK);
    476          1.1    jruoho }
    477          1.1    jruoho 
    478          1.1    jruoho 
    479          1.1    jruoho /******************************************************************************
    480          1.1    jruoho  *
    481          1.1    jruoho  * FUNCTION:    AcpiNsRemoveNullElements
    482          1.1    jruoho  *
    483      1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    484          1.1    jruoho  *              PackageType         - An AcpiReturnPackageTypes value
    485          1.1    jruoho  *              ObjDesc             - A Package object
    486          1.1    jruoho  *
    487          1.1    jruoho  * RETURN:      None.
    488          1.1    jruoho  *
    489          1.1    jruoho  * DESCRIPTION: Remove all NULL package elements from packages that contain
    490      1.1.1.5  christos  *              a variable number of subpackages. For these types of
    491          1.1    jruoho  *              packages, NULL elements can be safely removed.
    492          1.1    jruoho  *
    493          1.1    jruoho  *****************************************************************************/
    494          1.1    jruoho 
    495          1.1    jruoho void
    496          1.1    jruoho AcpiNsRemoveNullElements (
    497      1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    498          1.1    jruoho     UINT8                   PackageType,
    499          1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc)
    500          1.1    jruoho {
    501          1.1    jruoho     ACPI_OPERAND_OBJECT     **Source;
    502          1.1    jruoho     ACPI_OPERAND_OBJECT     **Dest;
    503          1.1    jruoho     UINT32                  Count;
    504          1.1    jruoho     UINT32                  NewCount;
    505          1.1    jruoho     UINT32                  i;
    506          1.1    jruoho 
    507          1.1    jruoho 
    508          1.1    jruoho     ACPI_FUNCTION_NAME (NsRemoveNullElements);
    509          1.1    jruoho 
    510          1.1    jruoho 
    511          1.1    jruoho     /*
    512      1.1.1.3    jruoho      * We can safely remove all NULL elements from these package types:
    513      1.1.1.3    jruoho      * PTYPE1_VAR packages contain a variable number of simple data types.
    514      1.1.1.5  christos      * PTYPE2 packages contain a variable number of subpackages.
    515          1.1    jruoho      */
    516          1.1    jruoho     switch (PackageType)
    517          1.1    jruoho     {
    518          1.1    jruoho     case ACPI_PTYPE1_VAR:
    519          1.1    jruoho     case ACPI_PTYPE2:
    520          1.1    jruoho     case ACPI_PTYPE2_COUNT:
    521          1.1    jruoho     case ACPI_PTYPE2_PKG_COUNT:
    522          1.1    jruoho     case ACPI_PTYPE2_FIXED:
    523          1.1    jruoho     case ACPI_PTYPE2_MIN:
    524          1.1    jruoho     case ACPI_PTYPE2_REV_FIXED:
    525      1.1.1.4  christos     case ACPI_PTYPE2_FIX_VAR:
    526      1.1.1.4  christos 
    527          1.1    jruoho         break;
    528          1.1    jruoho 
    529          1.1    jruoho     default:
    530      1.1.1.3    jruoho     case ACPI_PTYPE1_FIXED:
    531      1.1.1.3    jruoho     case ACPI_PTYPE1_OPTION:
    532          1.1    jruoho         return;
    533          1.1    jruoho     }
    534          1.1    jruoho 
    535          1.1    jruoho     Count = ObjDesc->Package.Count;
    536          1.1    jruoho     NewCount = Count;
    537          1.1    jruoho 
    538          1.1    jruoho     Source = ObjDesc->Package.Elements;
    539          1.1    jruoho     Dest = Source;
    540          1.1    jruoho 
    541          1.1    jruoho     /* Examine all elements of the package object, remove nulls */
    542          1.1    jruoho 
    543          1.1    jruoho     for (i = 0; i < Count; i++)
    544          1.1    jruoho     {
    545          1.1    jruoho         if (!*Source)
    546          1.1    jruoho         {
    547          1.1    jruoho             NewCount--;
    548          1.1    jruoho         }
    549          1.1    jruoho         else
    550          1.1    jruoho         {
    551          1.1    jruoho             *Dest = *Source;
    552          1.1    jruoho             Dest++;
    553          1.1    jruoho         }
    554          1.1    jruoho         Source++;
    555          1.1    jruoho     }
    556          1.1    jruoho 
    557          1.1    jruoho     /* Update parent package if any null elements were removed */
    558          1.1    jruoho 
    559          1.1    jruoho     if (NewCount < Count)
    560          1.1    jruoho     {
    561          1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    562          1.1    jruoho             "%s: Found and removed %u NULL elements\n",
    563      1.1.1.4  christos             Info->FullPathname, (Count - NewCount)));
    564          1.1    jruoho 
    565          1.1    jruoho         /* NULL terminate list and update the package count */
    566          1.1    jruoho 
    567          1.1    jruoho         *Dest = NULL;
    568          1.1    jruoho         ObjDesc->Package.Count = NewCount;
    569          1.1    jruoho     }
    570          1.1    jruoho }
    571          1.1    jruoho 
    572          1.1    jruoho 
    573          1.1    jruoho /*******************************************************************************
    574          1.1    jruoho  *
    575      1.1.1.4  christos  * FUNCTION:    AcpiNsWrapWithPackage
    576          1.1    jruoho  *
    577      1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    578      1.1.1.4  christos  *              OriginalObject      - Pointer to the object to repair.
    579      1.1.1.4  christos  *              ObjDescPtr          - The new package object is returned here
    580          1.1    jruoho  *
    581          1.1    jruoho  * RETURN:      Status, new object in *ObjDescPtr
    582          1.1    jruoho  *
    583      1.1.1.4  christos  * DESCRIPTION: Repair a common problem with objects that are defined to
    584      1.1.1.4  christos  *              return a variable-length Package of sub-objects. If there is
    585      1.1.1.4  christos  *              only one sub-object, some BIOS code mistakenly simply declares
    586      1.1.1.4  christos  *              the single object instead of a Package with one sub-object.
    587      1.1.1.4  christos  *              This function attempts to repair this error by wrapping a
    588      1.1.1.4  christos  *              Package object around the original object, creating the
    589      1.1.1.4  christos  *              correct and expected Package with one sub-object.
    590          1.1    jruoho  *
    591          1.1    jruoho  *              Names that can be repaired in this manner include:
    592      1.1.1.4  christos  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
    593      1.1.1.4  christos  *              _BCL, _DOD, _FIX, _Sx
    594          1.1    jruoho  *
    595          1.1    jruoho  ******************************************************************************/
    596          1.1    jruoho 
    597          1.1    jruoho ACPI_STATUS
    598      1.1.1.4  christos AcpiNsWrapWithPackage (
    599      1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    600      1.1.1.4  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    601          1.1    jruoho     ACPI_OPERAND_OBJECT     **ObjDescPtr)
    602          1.1    jruoho {
    603          1.1    jruoho     ACPI_OPERAND_OBJECT     *PkgObjDesc;
    604          1.1    jruoho 
    605          1.1    jruoho 
    606      1.1.1.4  christos     ACPI_FUNCTION_NAME (NsWrapWithPackage);
    607          1.1    jruoho 
    608          1.1    jruoho 
    609          1.1    jruoho     /*
    610          1.1    jruoho      * Create the new outer package and populate it. The new package will
    611      1.1.1.4  christos      * have a single element, the lone sub-object.
    612          1.1    jruoho      */
    613          1.1    jruoho     PkgObjDesc = AcpiUtCreatePackageObject (1);
    614          1.1    jruoho     if (!PkgObjDesc)
    615          1.1    jruoho     {
    616          1.1    jruoho         return (AE_NO_MEMORY);
    617          1.1    jruoho     }
    618          1.1    jruoho 
    619      1.1.1.4  christos     PkgObjDesc->Package.Elements[0] = OriginalObject;
    620      1.1.1.4  christos 
    621      1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    622      1.1.1.4  christos         "%s: Wrapped %s with expected Package object\n",
    623      1.1.1.4  christos         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
    624          1.1    jruoho 
    625          1.1    jruoho     /* Return the new object in the object pointer */
    626          1.1    jruoho 
    627          1.1    jruoho     *ObjDescPtr = PkgObjDesc;
    628      1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
    629          1.1    jruoho     return (AE_OK);
    630          1.1    jruoho }
    631