Home | History | Annotate | Line # | Download | only in namespace
nsrepair.c revision 1.1.1.10
      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.9  christos  * Copyright (C) 2000 - 2017, 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.8  christos     /* Object reference conversions */
    118   1.1.1.8  christos 
    119   1.1.1.8  christos     { "_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
    120   1.1.1.8  christos                 AcpiNsConvertToReference },
    121   1.1.1.8  christos 
    122   1.1.1.4  christos     /* Unicode conversions */
    123   1.1.1.4  christos 
    124   1.1.1.4  christos     { "_MLS", ACPI_RTYPE_STRING, 1,
    125   1.1.1.4  christos                 AcpiNsConvertToUnicode },
    126   1.1.1.4  christos     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
    127   1.1.1.4  christos                 ACPI_NOT_PACKAGE_ELEMENT,
    128   1.1.1.4  christos                 AcpiNsConvertToUnicode },
    129   1.1.1.4  christos     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
    130   1.1.1.4  christos };
    131       1.1    jruoho 
    132       1.1    jruoho 
    133       1.1    jruoho /*******************************************************************************
    134       1.1    jruoho  *
    135   1.1.1.4  christos  * FUNCTION:    AcpiNsSimpleRepair
    136       1.1    jruoho  *
    137   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    138       1.1    jruoho  *              ExpectedBtypes      - Object types expected
    139       1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    140       1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    141       1.1    jruoho  *                                    otherwise)
    142       1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    143       1.1    jruoho  *                                    evaluation of a method or object
    144       1.1    jruoho  *
    145       1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    146       1.1    jruoho  *
    147       1.1    jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    148       1.1    jruoho  *              not expected.
    149       1.1    jruoho  *
    150       1.1    jruoho  ******************************************************************************/
    151       1.1    jruoho 
    152       1.1    jruoho ACPI_STATUS
    153   1.1.1.4  christos AcpiNsSimpleRepair (
    154   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    155       1.1    jruoho     UINT32                  ExpectedBtypes,
    156       1.1    jruoho     UINT32                  PackageIndex,
    157       1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    158       1.1    jruoho {
    159       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    160   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *NewObject = NULL;
    161       1.1    jruoho     ACPI_STATUS             Status;
    162   1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
    163   1.1.1.4  christos 
    164       1.1    jruoho 
    165   1.1.1.4  christos     ACPI_FUNCTION_NAME (NsSimpleRepair);
    166   1.1.1.4  christos 
    167   1.1.1.4  christos 
    168   1.1.1.4  christos     /*
    169   1.1.1.4  christos      * Special repairs for certain names that are in the repair table.
    170   1.1.1.4  christos      * Check if this name is in the list of repairable names.
    171   1.1.1.4  christos      */
    172   1.1.1.4  christos     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
    173   1.1.1.4  christos         Info->ReturnBtype, PackageIndex);
    174   1.1.1.4  christos     if (Predefined)
    175   1.1.1.4  christos     {
    176   1.1.1.4  christos         if (!ReturnObject)
    177   1.1.1.4  christos         {
    178   1.1.1.4  christos             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    179   1.1.1.4  christos                 ACPI_WARN_ALWAYS, "Missing expected return value"));
    180   1.1.1.4  christos         }
    181       1.1    jruoho 
    182   1.1.1.8  christos         Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
    183   1.1.1.8  christos             &NewObject);
    184   1.1.1.4  christos         if (ACPI_FAILURE (Status))
    185   1.1.1.4  christos         {
    186   1.1.1.4  christos             /* A fatal error occurred during a conversion */
    187       1.1    jruoho 
    188   1.1.1.4  christos             ACPI_EXCEPTION ((AE_INFO, Status,
    189   1.1.1.4  christos                 "During return object analysis"));
    190   1.1.1.4  christos             return (Status);
    191   1.1.1.4  christos         }
    192   1.1.1.4  christos         if (NewObject)
    193   1.1.1.4  christos         {
    194   1.1.1.4  christos             goto ObjectRepaired;
    195   1.1.1.4  christos         }
    196   1.1.1.4  christos     }
    197   1.1.1.4  christos 
    198   1.1.1.4  christos     /*
    199   1.1.1.4  christos      * Do not perform simple object repair unless the return type is not
    200   1.1.1.4  christos      * expected.
    201   1.1.1.4  christos      */
    202   1.1.1.4  christos     if (Info->ReturnBtype & ExpectedBtypes)
    203   1.1.1.4  christos     {
    204   1.1.1.4  christos         return (AE_OK);
    205   1.1.1.4  christos     }
    206       1.1    jruoho 
    207       1.1    jruoho     /*
    208       1.1    jruoho      * At this point, we know that the type of the returned object was not
    209       1.1    jruoho      * one of the expected types for this predefined name. Attempt to
    210       1.1    jruoho      * repair the object by converting it to one of the expected object
    211       1.1    jruoho      * types for this predefined name.
    212       1.1    jruoho      */
    213   1.1.1.4  christos 
    214   1.1.1.4  christos     /*
    215   1.1.1.4  christos      * If there is no return value, check if we require a return value for
    216   1.1.1.4  christos      * this predefined name. Either one return value is expected, or none,
    217   1.1.1.4  christos      * for both methods and other objects.
    218   1.1.1.4  christos      *
    219   1.1.1.5  christos      * Try to fix if there was no return object. Warning if failed to fix.
    220   1.1.1.4  christos      */
    221   1.1.1.4  christos     if (!ReturnObject)
    222   1.1.1.4  christos     {
    223   1.1.1.4  christos         if (ExpectedBtypes && (!(ExpectedBtypes & ACPI_RTYPE_NONE)))
    224   1.1.1.4  christos         {
    225   1.1.1.5  christos             if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    226   1.1.1.5  christos             {
    227   1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    228   1.1.1.5  christos                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
    229   1.1.1.5  christos 
    230   1.1.1.5  christos                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
    231   1.1.1.8  christos                     PackageIndex, ReturnObjectPtr);
    232   1.1.1.5  christos                 if (ACPI_SUCCESS (Status))
    233   1.1.1.5  christos                 {
    234   1.1.1.5  christos                     return (AE_OK); /* Repair was successful */
    235   1.1.1.5  christos                 }
    236   1.1.1.5  christos             }
    237   1.1.1.5  christos             else
    238   1.1.1.5  christos             {
    239   1.1.1.5  christos                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
    240   1.1.1.5  christos                     ACPI_WARN_ALWAYS, "Missing expected return value"));
    241   1.1.1.5  christos             }
    242   1.1.1.4  christos 
    243   1.1.1.4  christos             return (AE_AML_NO_RETURN_VALUE);
    244   1.1.1.4  christos         }
    245   1.1.1.4  christos     }
    246   1.1.1.4  christos 
    247       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    248       1.1    jruoho     {
    249       1.1    jruoho         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
    250       1.1    jruoho         if (ACPI_SUCCESS (Status))
    251       1.1    jruoho         {
    252       1.1    jruoho             goto ObjectRepaired;
    253       1.1    jruoho         }
    254       1.1    jruoho     }
    255       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_STRING)
    256       1.1    jruoho     {
    257       1.1    jruoho         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
    258       1.1    jruoho         if (ACPI_SUCCESS (Status))
    259       1.1    jruoho         {
    260       1.1    jruoho             goto ObjectRepaired;
    261       1.1    jruoho         }
    262       1.1    jruoho     }
    263       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    264       1.1    jruoho     {
    265       1.1    jruoho         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
    266       1.1    jruoho         if (ACPI_SUCCESS (Status))
    267       1.1    jruoho         {
    268       1.1    jruoho             goto ObjectRepaired;
    269       1.1    jruoho         }
    270       1.1    jruoho     }
    271       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
    272       1.1    jruoho     {
    273   1.1.1.4  christos         /*
    274   1.1.1.4  christos          * A package is expected. We will wrap the existing object with a
    275   1.1.1.4  christos          * new package object. It is often the case that if a variable-length
    276   1.1.1.4  christos          * package is required, but there is only a single object needed, the
    277   1.1.1.4  christos          * BIOS will return that object instead of wrapping it with a Package
    278   1.1.1.4  christos          * object. Note: after the wrapping, the package will be validated
    279   1.1.1.4  christos          * for correct contents (expected object type or types).
    280   1.1.1.4  christos          */
    281   1.1.1.4  christos         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
    282       1.1    jruoho         if (ACPI_SUCCESS (Status))
    283       1.1    jruoho         {
    284   1.1.1.4  christos             /*
    285   1.1.1.4  christos              * The original object just had its reference count
    286   1.1.1.4  christos              * incremented for being inserted into the new package.
    287   1.1.1.4  christos              */
    288   1.1.1.4  christos             *ReturnObjectPtr = NewObject;       /* New Package object */
    289   1.1.1.4  christos             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    290   1.1.1.4  christos             return (AE_OK);
    291       1.1    jruoho         }
    292       1.1    jruoho     }
    293       1.1    jruoho 
    294       1.1    jruoho     /* We cannot repair this object */
    295       1.1    jruoho 
    296       1.1    jruoho     return (AE_AML_OPERAND_TYPE);
    297       1.1    jruoho 
    298       1.1    jruoho 
    299       1.1    jruoho ObjectRepaired:
    300       1.1    jruoho 
    301       1.1    jruoho     /* Object was successfully repaired */
    302       1.1    jruoho 
    303       1.1    jruoho     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    304       1.1    jruoho     {
    305  1.1.1.10  christos         /* Update reference count of new object */
    306  1.1.1.10  christos 
    307   1.1.1.4  christos         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
    308       1.1    jruoho         {
    309   1.1.1.4  christos             NewObject->Common.ReferenceCount =
    310   1.1.1.4  christos                 ReturnObject->Common.ReferenceCount;
    311       1.1    jruoho         }
    312       1.1    jruoho 
    313       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    314   1.1.1.4  christos             "%s: Converted %s to expected %s at Package index %u\n",
    315   1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    316       1.1    jruoho             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    317       1.1    jruoho     }
    318       1.1    jruoho     else
    319       1.1    jruoho     {
    320       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    321       1.1    jruoho             "%s: Converted %s to expected %s\n",
    322   1.1.1.4  christos             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
    323       1.1    jruoho             AcpiUtGetObjectTypeName (NewObject)));
    324       1.1    jruoho     }
    325       1.1    jruoho 
    326       1.1    jruoho     /* Delete old object, install the new return object */
    327       1.1    jruoho 
    328       1.1    jruoho     AcpiUtRemoveReference (ReturnObject);
    329       1.1    jruoho     *ReturnObjectPtr = NewObject;
    330   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    331       1.1    jruoho     return (AE_OK);
    332       1.1    jruoho }
    333       1.1    jruoho 
    334       1.1    jruoho 
    335   1.1.1.4  christos /******************************************************************************
    336       1.1    jruoho  *
    337   1.1.1.4  christos  * FUNCTION:    AcpiNsMatchSimpleRepair
    338       1.1    jruoho  *
    339   1.1.1.4  christos  * PARAMETERS:  Node                - Namespace node for the method/object
    340   1.1.1.4  christos  *              ReturnBtype         - Object type that was returned
    341   1.1.1.4  christos  *              PackageIndex        - Index of object within parent package (if
    342   1.1.1.4  christos  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    343   1.1.1.4  christos  *                                    otherwise)
    344       1.1    jruoho  *
    345   1.1.1.4  christos  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
    346       1.1    jruoho  *
    347   1.1.1.4  christos  * DESCRIPTION: Check an object name against the repairable object list.
    348       1.1    jruoho  *
    349   1.1.1.4  christos  *****************************************************************************/
    350       1.1    jruoho 
    351   1.1.1.4  christos static const ACPI_SIMPLE_REPAIR_INFO *
    352   1.1.1.4  christos AcpiNsMatchSimpleRepair (
    353   1.1.1.4  christos     ACPI_NAMESPACE_NODE     *Node,
    354   1.1.1.4  christos     UINT32                  ReturnBtype,
    355   1.1.1.4  christos     UINT32                  PackageIndex)
    356       1.1    jruoho {
    357   1.1.1.4  christos     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
    358       1.1    jruoho 
    359       1.1    jruoho 
    360   1.1.1.4  christos     /* Search info table for a repairable predefined method/object name */
    361       1.1    jruoho 
    362   1.1.1.4  christos     ThisName = AcpiObjectRepairInfo;
    363   1.1.1.4  christos     while (ThisName->ObjectConverter)
    364       1.1    jruoho     {
    365   1.1.1.4  christos         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
    366       1.1    jruoho         {
    367   1.1.1.4  christos             /* Check if we can actually repair this name/type combination */
    368       1.1    jruoho 
    369   1.1.1.4  christos             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
    370   1.1.1.8  christos                 (ThisName->PackageIndex == ACPI_ALL_PACKAGE_ELEMENTS ||
    371   1.1.1.8  christos                  PackageIndex == ThisName->PackageIndex))
    372       1.1    jruoho             {
    373   1.1.1.4  christos                 return (ThisName);
    374       1.1    jruoho             }
    375       1.1    jruoho 
    376   1.1.1.4  christos             return (NULL);
    377       1.1    jruoho         }
    378   1.1.1.8  christos 
    379   1.1.1.4  christos         ThisName++;
    380       1.1    jruoho     }
    381       1.1    jruoho 
    382   1.1.1.4  christos     return (NULL); /* Name was not found in the repair table */
    383       1.1    jruoho }
    384       1.1    jruoho 
    385       1.1    jruoho 
    386       1.1    jruoho /*******************************************************************************
    387       1.1    jruoho  *
    388       1.1    jruoho  * FUNCTION:    AcpiNsRepairNullElement
    389       1.1    jruoho  *
    390   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    391       1.1    jruoho  *              ExpectedBtypes      - Object types expected
    392       1.1    jruoho  *              PackageIndex        - Index of object within parent package (if
    393       1.1    jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    394       1.1    jruoho  *                                    otherwise)
    395       1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    396       1.1    jruoho  *                                    evaluation of a method or object
    397       1.1    jruoho  *
    398       1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful.
    399       1.1    jruoho  *
    400       1.1    jruoho  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
    401       1.1    jruoho  *
    402       1.1    jruoho  ******************************************************************************/
    403       1.1    jruoho 
    404       1.1    jruoho ACPI_STATUS
    405       1.1    jruoho AcpiNsRepairNullElement (
    406   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    407       1.1    jruoho     UINT32                  ExpectedBtypes,
    408       1.1    jruoho     UINT32                  PackageIndex,
    409       1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    410       1.1    jruoho {
    411       1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    412       1.1    jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    413       1.1    jruoho 
    414       1.1    jruoho 
    415       1.1    jruoho     ACPI_FUNCTION_NAME (NsRepairNullElement);
    416       1.1    jruoho 
    417       1.1    jruoho 
    418       1.1    jruoho     /* No repair needed if return object is non-NULL */
    419       1.1    jruoho 
    420       1.1    jruoho     if (ReturnObject)
    421       1.1    jruoho     {
    422       1.1    jruoho         return (AE_OK);
    423       1.1    jruoho     }
    424       1.1    jruoho 
    425       1.1    jruoho     /*
    426       1.1    jruoho      * Attempt to repair a NULL element of a Package object. This applies to
    427       1.1    jruoho      * predefined names that return a fixed-length package and each element
    428       1.1    jruoho      * is required. It does not apply to variable-length packages where NULL
    429       1.1    jruoho      * elements are allowed, especially at the end of the package.
    430       1.1    jruoho      */
    431       1.1    jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    432       1.1    jruoho     {
    433       1.1    jruoho         /* Need an Integer - create a zero-value integer */
    434       1.1    jruoho 
    435   1.1.1.2    jruoho         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
    436       1.1    jruoho     }
    437       1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
    438       1.1    jruoho     {
    439       1.1    jruoho         /* Need a String - create a NULL string */
    440       1.1    jruoho 
    441       1.1    jruoho         NewObject = AcpiUtCreateStringObject (0);
    442       1.1    jruoho     }
    443       1.1    jruoho     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    444       1.1    jruoho     {
    445       1.1    jruoho         /* Need a Buffer - create a zero-length buffer */
    446       1.1    jruoho 
    447       1.1    jruoho         NewObject = AcpiUtCreateBufferObject (0);
    448       1.1    jruoho     }
    449       1.1    jruoho     else
    450       1.1    jruoho     {
    451       1.1    jruoho         /* Error for all other expected types */
    452       1.1    jruoho 
    453       1.1    jruoho         return (AE_AML_OPERAND_TYPE);
    454       1.1    jruoho     }
    455       1.1    jruoho 
    456       1.1    jruoho     if (!NewObject)
    457       1.1    jruoho     {
    458       1.1    jruoho         return (AE_NO_MEMORY);
    459       1.1    jruoho     }
    460       1.1    jruoho 
    461       1.1    jruoho     /* Set the reference count according to the parent Package object */
    462       1.1    jruoho 
    463   1.1.1.8  christos     NewObject->Common.ReferenceCount =
    464   1.1.1.8  christos         Info->ParentPackage->Common.ReferenceCount;
    465       1.1    jruoho 
    466       1.1    jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    467       1.1    jruoho         "%s: Converted NULL package element to expected %s at index %u\n",
    468   1.1.1.8  christos         Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
    469   1.1.1.8  christos         PackageIndex));
    470       1.1    jruoho 
    471       1.1    jruoho     *ReturnObjectPtr = NewObject;
    472   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    473       1.1    jruoho     return (AE_OK);
    474       1.1    jruoho }
    475       1.1    jruoho 
    476       1.1    jruoho 
    477       1.1    jruoho /******************************************************************************
    478       1.1    jruoho  *
    479       1.1    jruoho  * FUNCTION:    AcpiNsRemoveNullElements
    480       1.1    jruoho  *
    481   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    482       1.1    jruoho  *              PackageType         - An AcpiReturnPackageTypes value
    483       1.1    jruoho  *              ObjDesc             - A Package object
    484       1.1    jruoho  *
    485       1.1    jruoho  * RETURN:      None.
    486       1.1    jruoho  *
    487       1.1    jruoho  * DESCRIPTION: Remove all NULL package elements from packages that contain
    488   1.1.1.5  christos  *              a variable number of subpackages. For these types of
    489       1.1    jruoho  *              packages, NULL elements can be safely removed.
    490       1.1    jruoho  *
    491       1.1    jruoho  *****************************************************************************/
    492       1.1    jruoho 
    493       1.1    jruoho void
    494       1.1    jruoho AcpiNsRemoveNullElements (
    495   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    496       1.1    jruoho     UINT8                   PackageType,
    497       1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc)
    498       1.1    jruoho {
    499       1.1    jruoho     ACPI_OPERAND_OBJECT     **Source;
    500       1.1    jruoho     ACPI_OPERAND_OBJECT     **Dest;
    501       1.1    jruoho     UINT32                  Count;
    502       1.1    jruoho     UINT32                  NewCount;
    503       1.1    jruoho     UINT32                  i;
    504       1.1    jruoho 
    505       1.1    jruoho 
    506       1.1    jruoho     ACPI_FUNCTION_NAME (NsRemoveNullElements);
    507       1.1    jruoho 
    508       1.1    jruoho 
    509       1.1    jruoho     /*
    510   1.1.1.3    jruoho      * We can safely remove all NULL elements from these package types:
    511   1.1.1.3    jruoho      * PTYPE1_VAR packages contain a variable number of simple data types.
    512   1.1.1.5  christos      * PTYPE2 packages contain a variable number of subpackages.
    513       1.1    jruoho      */
    514       1.1    jruoho     switch (PackageType)
    515       1.1    jruoho     {
    516       1.1    jruoho     case ACPI_PTYPE1_VAR:
    517       1.1    jruoho     case ACPI_PTYPE2:
    518       1.1    jruoho     case ACPI_PTYPE2_COUNT:
    519       1.1    jruoho     case ACPI_PTYPE2_PKG_COUNT:
    520       1.1    jruoho     case ACPI_PTYPE2_FIXED:
    521       1.1    jruoho     case ACPI_PTYPE2_MIN:
    522       1.1    jruoho     case ACPI_PTYPE2_REV_FIXED:
    523   1.1.1.4  christos     case ACPI_PTYPE2_FIX_VAR:
    524       1.1    jruoho         break;
    525       1.1    jruoho 
    526       1.1    jruoho     default:
    527   1.1.1.7  christos     case ACPI_PTYPE2_VAR_VAR:
    528   1.1.1.3    jruoho     case ACPI_PTYPE1_FIXED:
    529   1.1.1.3    jruoho     case ACPI_PTYPE1_OPTION:
    530       1.1    jruoho         return;
    531       1.1    jruoho     }
    532       1.1    jruoho 
    533       1.1    jruoho     Count = ObjDesc->Package.Count;
    534       1.1    jruoho     NewCount = Count;
    535       1.1    jruoho 
    536       1.1    jruoho     Source = ObjDesc->Package.Elements;
    537       1.1    jruoho     Dest = Source;
    538       1.1    jruoho 
    539       1.1    jruoho     /* Examine all elements of the package object, remove nulls */
    540       1.1    jruoho 
    541       1.1    jruoho     for (i = 0; i < Count; i++)
    542       1.1    jruoho     {
    543       1.1    jruoho         if (!*Source)
    544       1.1    jruoho         {
    545       1.1    jruoho             NewCount--;
    546       1.1    jruoho         }
    547       1.1    jruoho         else
    548       1.1    jruoho         {
    549       1.1    jruoho             *Dest = *Source;
    550       1.1    jruoho             Dest++;
    551       1.1    jruoho         }
    552   1.1.1.8  christos 
    553       1.1    jruoho         Source++;
    554       1.1    jruoho     }
    555       1.1    jruoho 
    556       1.1    jruoho     /* Update parent package if any null elements were removed */
    557       1.1    jruoho 
    558       1.1    jruoho     if (NewCount < Count)
    559       1.1    jruoho     {
    560       1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    561       1.1    jruoho             "%s: Found and removed %u NULL elements\n",
    562   1.1.1.4  christos             Info->FullPathname, (Count - NewCount)));
    563       1.1    jruoho 
    564       1.1    jruoho         /* NULL terminate list and update the package count */
    565       1.1    jruoho 
    566       1.1    jruoho         *Dest = NULL;
    567       1.1    jruoho         ObjDesc->Package.Count = NewCount;
    568       1.1    jruoho     }
    569       1.1    jruoho }
    570       1.1    jruoho 
    571       1.1    jruoho 
    572       1.1    jruoho /*******************************************************************************
    573       1.1    jruoho  *
    574   1.1.1.4  christos  * FUNCTION:    AcpiNsWrapWithPackage
    575       1.1    jruoho  *
    576   1.1.1.4  christos  * PARAMETERS:  Info                - Method execution information block
    577   1.1.1.4  christos  *              OriginalObject      - Pointer to the object to repair.
    578   1.1.1.4  christos  *              ObjDescPtr          - The new package object is returned here
    579       1.1    jruoho  *
    580       1.1    jruoho  * RETURN:      Status, new object in *ObjDescPtr
    581       1.1    jruoho  *
    582   1.1.1.4  christos  * DESCRIPTION: Repair a common problem with objects that are defined to
    583   1.1.1.4  christos  *              return a variable-length Package of sub-objects. If there is
    584   1.1.1.4  christos  *              only one sub-object, some BIOS code mistakenly simply declares
    585   1.1.1.4  christos  *              the single object instead of a Package with one sub-object.
    586   1.1.1.4  christos  *              This function attempts to repair this error by wrapping a
    587   1.1.1.4  christos  *              Package object around the original object, creating the
    588   1.1.1.4  christos  *              correct and expected Package with one sub-object.
    589       1.1    jruoho  *
    590       1.1    jruoho  *              Names that can be repaired in this manner include:
    591   1.1.1.4  christos  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
    592   1.1.1.4  christos  *              _BCL, _DOD, _FIX, _Sx
    593       1.1    jruoho  *
    594       1.1    jruoho  ******************************************************************************/
    595       1.1    jruoho 
    596       1.1    jruoho ACPI_STATUS
    597   1.1.1.4  christos AcpiNsWrapWithPackage (
    598   1.1.1.4  christos     ACPI_EVALUATE_INFO      *Info,
    599   1.1.1.4  christos     ACPI_OPERAND_OBJECT     *OriginalObject,
    600       1.1    jruoho     ACPI_OPERAND_OBJECT     **ObjDescPtr)
    601       1.1    jruoho {
    602       1.1    jruoho     ACPI_OPERAND_OBJECT     *PkgObjDesc;
    603       1.1    jruoho 
    604       1.1    jruoho 
    605   1.1.1.4  christos     ACPI_FUNCTION_NAME (NsWrapWithPackage);
    606       1.1    jruoho 
    607       1.1    jruoho 
    608       1.1    jruoho     /*
    609   1.1.1.8  christos      * Create the new outer package and populate it. The new
    610   1.1.1.8  christos      * package will have a single element, the lone sub-object.
    611       1.1    jruoho      */
    612       1.1    jruoho     PkgObjDesc = AcpiUtCreatePackageObject (1);
    613       1.1    jruoho     if (!PkgObjDesc)
    614       1.1    jruoho     {
    615       1.1    jruoho         return (AE_NO_MEMORY);
    616       1.1    jruoho     }
    617       1.1    jruoho 
    618   1.1.1.4  christos     PkgObjDesc->Package.Elements[0] = OriginalObject;
    619   1.1.1.4  christos 
    620   1.1.1.4  christos     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    621   1.1.1.4  christos         "%s: Wrapped %s with expected Package object\n",
    622   1.1.1.4  christos         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
    623       1.1    jruoho 
    624       1.1    jruoho     /* Return the new object in the object pointer */
    625       1.1    jruoho 
    626       1.1    jruoho     *ObjDescPtr = PkgObjDesc;
    627   1.1.1.4  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
    628       1.1    jruoho     return (AE_OK);
    629       1.1    jruoho }
    630