Home | History | Annotate | Line # | Download | only in namespace
nsrepair.c revision 1.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  jruoho /******************************************************************************
      8  1.1  jruoho  *
      9  1.1  jruoho  * 1. Copyright Notice
     10  1.1  jruoho  *
     11  1.1  jruoho  * Some or all of this work - Copyright (c) 1999 - 2010, Intel Corp.
     12  1.1  jruoho  * All rights reserved.
     13  1.1  jruoho  *
     14  1.1  jruoho  * 2. License
     15  1.1  jruoho  *
     16  1.1  jruoho  * 2.1. This is your license from Intel Corp. under its intellectual property
     17  1.1  jruoho  * rights.  You may have additional license terms from the party that provided
     18  1.1  jruoho  * you this software, covering your right to use that party's intellectual
     19  1.1  jruoho  * property rights.
     20  1.1  jruoho  *
     21  1.1  jruoho  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     22  1.1  jruoho  * copy of the source code appearing in this file ("Covered Code") an
     23  1.1  jruoho  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     24  1.1  jruoho  * base code distributed originally by Intel ("Original Intel Code") to copy,
     25  1.1  jruoho  * make derivatives, distribute, use and display any portion of the Covered
     26  1.1  jruoho  * Code in any form, with the right to sublicense such rights; and
     27  1.1  jruoho  *
     28  1.1  jruoho  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     29  1.1  jruoho  * license (with the right to sublicense), under only those claims of Intel
     30  1.1  jruoho  * patents that are infringed by the Original Intel Code, to make, use, sell,
     31  1.1  jruoho  * offer to sell, and import the Covered Code and derivative works thereof
     32  1.1  jruoho  * solely to the minimum extent necessary to exercise the above copyright
     33  1.1  jruoho  * license, and in no event shall the patent license extend to any additions
     34  1.1  jruoho  * to or modifications of the Original Intel Code.  No other license or right
     35  1.1  jruoho  * is granted directly or by implication, estoppel or otherwise;
     36  1.1  jruoho  *
     37  1.1  jruoho  * The above copyright and patent license is granted only if the following
     38  1.1  jruoho  * conditions are met:
     39  1.1  jruoho  *
     40  1.1  jruoho  * 3. Conditions
     41  1.1  jruoho  *
     42  1.1  jruoho  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     43  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     44  1.1  jruoho  * Code or modification with rights to further distribute source must include
     45  1.1  jruoho  * the above Copyright Notice, the above License, this list of Conditions,
     46  1.1  jruoho  * and the following Disclaimer and Export Compliance provision.  In addition,
     47  1.1  jruoho  * Licensee must cause all Covered Code to which Licensee contributes to
     48  1.1  jruoho  * contain a file documenting the changes Licensee made to create that Covered
     49  1.1  jruoho  * Code and the date of any change.  Licensee must include in that file the
     50  1.1  jruoho  * documentation of any changes made by any predecessor Licensee.  Licensee
     51  1.1  jruoho  * must include a prominent statement that the modification is derived,
     52  1.1  jruoho  * directly or indirectly, from Original Intel Code.
     53  1.1  jruoho  *
     54  1.1  jruoho  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     55  1.1  jruoho  * Redistribution of source code of any substantial portion of the Covered
     56  1.1  jruoho  * Code or modification without rights to further distribute source must
     57  1.1  jruoho  * include the following Disclaimer and Export Compliance provision in the
     58  1.1  jruoho  * documentation and/or other materials provided with distribution.  In
     59  1.1  jruoho  * addition, Licensee may not authorize further sublicense of source of any
     60  1.1  jruoho  * portion of the Covered Code, and must include terms to the effect that the
     61  1.1  jruoho  * license from Licensee to its licensee is limited to the intellectual
     62  1.1  jruoho  * property embodied in the software Licensee provides to its licensee, and
     63  1.1  jruoho  * not to intellectual property embodied in modifications its licensee may
     64  1.1  jruoho  * make.
     65  1.1  jruoho  *
     66  1.1  jruoho  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     67  1.1  jruoho  * substantial portion of the Covered Code or modification must reproduce the
     68  1.1  jruoho  * above Copyright Notice, and the following Disclaimer and Export Compliance
     69  1.1  jruoho  * provision in the documentation and/or other materials provided with the
     70  1.1  jruoho  * distribution.
     71  1.1  jruoho  *
     72  1.1  jruoho  * 3.4. Intel retains all right, title, and interest in and to the Original
     73  1.1  jruoho  * Intel Code.
     74  1.1  jruoho  *
     75  1.1  jruoho  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     76  1.1  jruoho  * Intel shall be used in advertising or otherwise to promote the sale, use or
     77  1.1  jruoho  * other dealings in products derived from or relating to the Covered Code
     78  1.1  jruoho  * without prior written authorization from Intel.
     79  1.1  jruoho  *
     80  1.1  jruoho  * 4. Disclaimer and Export Compliance
     81  1.1  jruoho  *
     82  1.1  jruoho  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     83  1.1  jruoho  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     84  1.1  jruoho  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
     85  1.1  jruoho  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
     86  1.1  jruoho  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
     87  1.1  jruoho  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     88  1.1  jruoho  * PARTICULAR PURPOSE.
     89  1.1  jruoho  *
     90  1.1  jruoho  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     91  1.1  jruoho  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     92  1.1  jruoho  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     93  1.1  jruoho  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     94  1.1  jruoho  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     95  1.1  jruoho  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
     96  1.1  jruoho  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     97  1.1  jruoho  * LIMITED REMEDY.
     98  1.1  jruoho  *
     99  1.1  jruoho  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    100  1.1  jruoho  * software or system incorporating such software without first obtaining any
    101  1.1  jruoho  * required license or other approval from the U. S. Department of Commerce or
    102  1.1  jruoho  * any other agency or department of the United States Government.  In the
    103  1.1  jruoho  * event Licensee exports any such software from the United States or
    104  1.1  jruoho  * re-exports any such software from a foreign destination, Licensee shall
    105  1.1  jruoho  * ensure that the distribution and export/re-export of the software is in
    106  1.1  jruoho  * compliance with all laws, regulations, orders, or other restrictions of the
    107  1.1  jruoho  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    108  1.1  jruoho  * any of its subsidiaries will export/re-export any technical data, process,
    109  1.1  jruoho  * software, or service, directly or indirectly, to any country for which the
    110  1.1  jruoho  * United States government or any agency thereof requires an export license,
    111  1.1  jruoho  * other governmental approval, or letter of assurance, without first obtaining
    112  1.1  jruoho  * such license, approval or letter.
    113  1.1  jruoho  *
    114  1.1  jruoho  *****************************************************************************/
    115  1.1  jruoho 
    116  1.1  jruoho #define __NSREPAIR_C__
    117  1.1  jruoho 
    118  1.1  jruoho #include "acpi.h"
    119  1.1  jruoho #include "accommon.h"
    120  1.1  jruoho #include "acnamesp.h"
    121  1.1  jruoho #include "acinterp.h"
    122  1.1  jruoho #include "acpredef.h"
    123  1.1  jruoho 
    124  1.1  jruoho #define _COMPONENT          ACPI_NAMESPACE
    125  1.1  jruoho         ACPI_MODULE_NAME    ("nsrepair")
    126  1.1  jruoho 
    127  1.1  jruoho 
    128  1.1  jruoho /*******************************************************************************
    129  1.1  jruoho  *
    130  1.1  jruoho  * This module attempts to repair or convert objects returned by the
    131  1.1  jruoho  * predefined methods to an object type that is expected, as per the ACPI
    132  1.1  jruoho  * specification. The need for this code is dictated by the many machines that
    133  1.1  jruoho  * return incorrect types for the standard predefined methods. Performing these
    134  1.1  jruoho  * conversions here, in one place, eliminates the need for individual ACPI
    135  1.1  jruoho  * device drivers to do the same. Note: Most of these conversions are different
    136  1.1  jruoho  * than the internal object conversion routines used for implicit object
    137  1.1  jruoho  * conversion.
    138  1.1  jruoho  *
    139  1.1  jruoho  * The following conversions can be performed as necessary:
    140  1.1  jruoho  *
    141  1.1  jruoho  * Integer -> String
    142  1.1  jruoho  * Integer -> Buffer
    143  1.1  jruoho  * String  -> Integer
    144  1.1  jruoho  * String  -> Buffer
    145  1.1  jruoho  * Buffer  -> Integer
    146  1.1  jruoho  * Buffer  -> String
    147  1.1  jruoho  * Buffer  -> Package of Integers
    148  1.1  jruoho  * Package -> Package of one Package
    149  1.1  jruoho  *
    150  1.1  jruoho  * Additional possible repairs:
    151  1.1  jruoho  *
    152  1.1  jruoho  * Optional/unnecessary NULL package elements removed
    153  1.1  jruoho  * Required package elements that are NULL replaced by Integer/String/Buffer
    154  1.1  jruoho  * Incorrect standalone package wrapped with required outer package
    155  1.1  jruoho  *
    156  1.1  jruoho  ******************************************************************************/
    157  1.1  jruoho 
    158  1.1  jruoho 
    159  1.1  jruoho /* Local prototypes */
    160  1.1  jruoho 
    161  1.1  jruoho static ACPI_STATUS
    162  1.1  jruoho AcpiNsConvertToInteger (
    163  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    164  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject);
    165  1.1  jruoho 
    166  1.1  jruoho static ACPI_STATUS
    167  1.1  jruoho AcpiNsConvertToString (
    168  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    169  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject);
    170  1.1  jruoho 
    171  1.1  jruoho static ACPI_STATUS
    172  1.1  jruoho AcpiNsConvertToBuffer (
    173  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    174  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject);
    175  1.1  jruoho 
    176  1.1  jruoho static ACPI_STATUS
    177  1.1  jruoho AcpiNsConvertToPackage (
    178  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    179  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject);
    180  1.1  jruoho 
    181  1.1  jruoho 
    182  1.1  jruoho /*******************************************************************************
    183  1.1  jruoho  *
    184  1.1  jruoho  * FUNCTION:    AcpiNsRepairObject
    185  1.1  jruoho  *
    186  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    187  1.1  jruoho  *              ExpectedBtypes      - Object types expected
    188  1.1  jruoho  *              PackageIndex        - Index of object within parent package (if
    189  1.1  jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    190  1.1  jruoho  *                                    otherwise)
    191  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    192  1.1  jruoho  *                                    evaluation of a method or object
    193  1.1  jruoho  *
    194  1.1  jruoho  * RETURN:      Status. AE_OK if repair was successful.
    195  1.1  jruoho  *
    196  1.1  jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    197  1.1  jruoho  *              not expected.
    198  1.1  jruoho  *
    199  1.1  jruoho  ******************************************************************************/
    200  1.1  jruoho 
    201  1.1  jruoho ACPI_STATUS
    202  1.1  jruoho AcpiNsRepairObject (
    203  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    204  1.1  jruoho     UINT32                  ExpectedBtypes,
    205  1.1  jruoho     UINT32                  PackageIndex,
    206  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    207  1.1  jruoho {
    208  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    209  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    210  1.1  jruoho     ACPI_STATUS             Status;
    211  1.1  jruoho 
    212  1.1  jruoho 
    213  1.1  jruoho     ACPI_FUNCTION_NAME (NsRepairObject);
    214  1.1  jruoho 
    215  1.1  jruoho 
    216  1.1  jruoho     /*
    217  1.1  jruoho      * At this point, we know that the type of the returned object was not
    218  1.1  jruoho      * one of the expected types for this predefined name. Attempt to
    219  1.1  jruoho      * repair the object by converting it to one of the expected object
    220  1.1  jruoho      * types for this predefined name.
    221  1.1  jruoho      */
    222  1.1  jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    223  1.1  jruoho     {
    224  1.1  jruoho         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
    225  1.1  jruoho         if (ACPI_SUCCESS (Status))
    226  1.1  jruoho         {
    227  1.1  jruoho             goto ObjectRepaired;
    228  1.1  jruoho         }
    229  1.1  jruoho     }
    230  1.1  jruoho     if (ExpectedBtypes & ACPI_RTYPE_STRING)
    231  1.1  jruoho     {
    232  1.1  jruoho         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
    233  1.1  jruoho         if (ACPI_SUCCESS (Status))
    234  1.1  jruoho         {
    235  1.1  jruoho             goto ObjectRepaired;
    236  1.1  jruoho         }
    237  1.1  jruoho     }
    238  1.1  jruoho     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    239  1.1  jruoho     {
    240  1.1  jruoho         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
    241  1.1  jruoho         if (ACPI_SUCCESS (Status))
    242  1.1  jruoho         {
    243  1.1  jruoho             goto ObjectRepaired;
    244  1.1  jruoho         }
    245  1.1  jruoho     }
    246  1.1  jruoho     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
    247  1.1  jruoho     {
    248  1.1  jruoho         Status = AcpiNsConvertToPackage (ReturnObject, &NewObject);
    249  1.1  jruoho         if (ACPI_SUCCESS (Status))
    250  1.1  jruoho         {
    251  1.1  jruoho             goto ObjectRepaired;
    252  1.1  jruoho         }
    253  1.1  jruoho     }
    254  1.1  jruoho 
    255  1.1  jruoho     /* We cannot repair this object */
    256  1.1  jruoho 
    257  1.1  jruoho     return (AE_AML_OPERAND_TYPE);
    258  1.1  jruoho 
    259  1.1  jruoho 
    260  1.1  jruoho ObjectRepaired:
    261  1.1  jruoho 
    262  1.1  jruoho     /* Object was successfully repaired */
    263  1.1  jruoho 
    264  1.1  jruoho     /*
    265  1.1  jruoho      * If the original object is a package element, we need to:
    266  1.1  jruoho      * 1. Set the reference count of the new object to match the
    267  1.1  jruoho      *    reference count of the old object.
    268  1.1  jruoho      * 2. Decrement the reference count of the original object.
    269  1.1  jruoho      */
    270  1.1  jruoho     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
    271  1.1  jruoho     {
    272  1.1  jruoho         NewObject->Common.ReferenceCount =
    273  1.1  jruoho             ReturnObject->Common.ReferenceCount;
    274  1.1  jruoho 
    275  1.1  jruoho         if (ReturnObject->Common.ReferenceCount > 1)
    276  1.1  jruoho         {
    277  1.1  jruoho             ReturnObject->Common.ReferenceCount--;
    278  1.1  jruoho         }
    279  1.1  jruoho 
    280  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    281  1.1  jruoho             "%s: Converted %s to expected %s at index %u\n",
    282  1.1  jruoho             Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
    283  1.1  jruoho             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    284  1.1  jruoho     }
    285  1.1  jruoho     else
    286  1.1  jruoho     {
    287  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    288  1.1  jruoho             "%s: Converted %s to expected %s\n",
    289  1.1  jruoho             Data->Pathname, AcpiUtGetObjectTypeName (ReturnObject),
    290  1.1  jruoho             AcpiUtGetObjectTypeName (NewObject)));
    291  1.1  jruoho     }
    292  1.1  jruoho 
    293  1.1  jruoho     /* Delete old object, install the new return object */
    294  1.1  jruoho 
    295  1.1  jruoho     AcpiUtRemoveReference (ReturnObject);
    296  1.1  jruoho     *ReturnObjectPtr = NewObject;
    297  1.1  jruoho     Data->Flags |= ACPI_OBJECT_REPAIRED;
    298  1.1  jruoho     return (AE_OK);
    299  1.1  jruoho }
    300  1.1  jruoho 
    301  1.1  jruoho 
    302  1.1  jruoho /*******************************************************************************
    303  1.1  jruoho  *
    304  1.1  jruoho  * FUNCTION:    AcpiNsConvertToInteger
    305  1.1  jruoho  *
    306  1.1  jruoho  * PARAMETERS:  OriginalObject      - Object to be converted
    307  1.1  jruoho  *              ReturnObject        - Where the new converted object is returned
    308  1.1  jruoho  *
    309  1.1  jruoho  * RETURN:      Status. AE_OK if conversion was successful.
    310  1.1  jruoho  *
    311  1.1  jruoho  * DESCRIPTION: Attempt to convert a String/Buffer object to an Integer.
    312  1.1  jruoho  *
    313  1.1  jruoho  ******************************************************************************/
    314  1.1  jruoho 
    315  1.1  jruoho static ACPI_STATUS
    316  1.1  jruoho AcpiNsConvertToInteger (
    317  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    318  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject)
    319  1.1  jruoho {
    320  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    321  1.1  jruoho     ACPI_STATUS             Status;
    322  1.1  jruoho     UINT64                  Value = 0;
    323  1.1  jruoho     UINT32                  i;
    324  1.1  jruoho 
    325  1.1  jruoho 
    326  1.1  jruoho     switch (OriginalObject->Common.Type)
    327  1.1  jruoho     {
    328  1.1  jruoho     case ACPI_TYPE_STRING:
    329  1.1  jruoho 
    330  1.1  jruoho         /* String-to-Integer conversion */
    331  1.1  jruoho 
    332  1.1  jruoho         Status = AcpiUtStrtoul64 (OriginalObject->String.Pointer,
    333  1.1  jruoho                     ACPI_ANY_BASE, &Value);
    334  1.1  jruoho         if (ACPI_FAILURE (Status))
    335  1.1  jruoho         {
    336  1.1  jruoho             return (Status);
    337  1.1  jruoho         }
    338  1.1  jruoho         break;
    339  1.1  jruoho 
    340  1.1  jruoho     case ACPI_TYPE_BUFFER:
    341  1.1  jruoho 
    342  1.1  jruoho         /* Buffer-to-Integer conversion. Max buffer size is 64 bits. */
    343  1.1  jruoho 
    344  1.1  jruoho         if (OriginalObject->Buffer.Length > 8)
    345  1.1  jruoho         {
    346  1.1  jruoho             return (AE_AML_OPERAND_TYPE);
    347  1.1  jruoho         }
    348  1.1  jruoho 
    349  1.1  jruoho         /* Extract each buffer byte to create the integer */
    350  1.1  jruoho 
    351  1.1  jruoho         for (i = 0; i < OriginalObject->Buffer.Length; i++)
    352  1.1  jruoho         {
    353  1.1  jruoho             Value |= ((UINT64) OriginalObject->Buffer.Pointer[i] << (i * 8));
    354  1.1  jruoho         }
    355  1.1  jruoho         break;
    356  1.1  jruoho 
    357  1.1  jruoho     default:
    358  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    359  1.1  jruoho     }
    360  1.1  jruoho 
    361  1.1  jruoho     NewObject = AcpiUtCreateIntegerObject (Value);
    362  1.1  jruoho     if (!NewObject)
    363  1.1  jruoho     {
    364  1.1  jruoho         return (AE_NO_MEMORY);
    365  1.1  jruoho     }
    366  1.1  jruoho 
    367  1.1  jruoho     *ReturnObject = NewObject;
    368  1.1  jruoho     return (AE_OK);
    369  1.1  jruoho }
    370  1.1  jruoho 
    371  1.1  jruoho 
    372  1.1  jruoho /*******************************************************************************
    373  1.1  jruoho  *
    374  1.1  jruoho  * FUNCTION:    AcpiNsConvertToString
    375  1.1  jruoho  *
    376  1.1  jruoho  * PARAMETERS:  OriginalObject      - Object to be converted
    377  1.1  jruoho  *              ReturnObject        - Where the new converted object is returned
    378  1.1  jruoho  *
    379  1.1  jruoho  * RETURN:      Status. AE_OK if conversion was successful.
    380  1.1  jruoho  *
    381  1.1  jruoho  * DESCRIPTION: Attempt to convert a Integer/Buffer object to a String.
    382  1.1  jruoho  *
    383  1.1  jruoho  ******************************************************************************/
    384  1.1  jruoho 
    385  1.1  jruoho static ACPI_STATUS
    386  1.1  jruoho AcpiNsConvertToString (
    387  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    388  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject)
    389  1.1  jruoho {
    390  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    391  1.1  jruoho     ACPI_SIZE               Length;
    392  1.1  jruoho     ACPI_STATUS             Status;
    393  1.1  jruoho 
    394  1.1  jruoho 
    395  1.1  jruoho     switch (OriginalObject->Common.Type)
    396  1.1  jruoho     {
    397  1.1  jruoho     case ACPI_TYPE_INTEGER:
    398  1.1  jruoho         /*
    399  1.1  jruoho          * Integer-to-String conversion. Commonly, convert
    400  1.1  jruoho          * an integer of value 0 to a NULL string. The last element of
    401  1.1  jruoho          * _BIF and _BIX packages occasionally need this fix.
    402  1.1  jruoho          */
    403  1.1  jruoho         if (OriginalObject->Integer.Value == 0)
    404  1.1  jruoho         {
    405  1.1  jruoho             /* Allocate a new NULL string object */
    406  1.1  jruoho 
    407  1.1  jruoho             NewObject = AcpiUtCreateStringObject (0);
    408  1.1  jruoho             if (!NewObject)
    409  1.1  jruoho             {
    410  1.1  jruoho                 return (AE_NO_MEMORY);
    411  1.1  jruoho             }
    412  1.1  jruoho         }
    413  1.1  jruoho         else
    414  1.1  jruoho         {
    415  1.1  jruoho             Status = AcpiExConvertToString (OriginalObject, &NewObject,
    416  1.1  jruoho                         ACPI_IMPLICIT_CONVERT_HEX);
    417  1.1  jruoho             if (ACPI_FAILURE (Status))
    418  1.1  jruoho             {
    419  1.1  jruoho                 return (Status);
    420  1.1  jruoho             }
    421  1.1  jruoho         }
    422  1.1  jruoho         break;
    423  1.1  jruoho 
    424  1.1  jruoho     case ACPI_TYPE_BUFFER:
    425  1.1  jruoho         /*
    426  1.1  jruoho          * Buffer-to-String conversion. Use a ToString
    427  1.1  jruoho          * conversion, no transform performed on the buffer data. The best
    428  1.1  jruoho          * example of this is the _BIF method, where the string data from
    429  1.1  jruoho          * the battery is often (incorrectly) returned as buffer object(s).
    430  1.1  jruoho          */
    431  1.1  jruoho         Length = 0;
    432  1.1  jruoho         while ((Length < OriginalObject->Buffer.Length) &&
    433  1.1  jruoho                 (OriginalObject->Buffer.Pointer[Length]))
    434  1.1  jruoho         {
    435  1.1  jruoho             Length++;
    436  1.1  jruoho         }
    437  1.1  jruoho 
    438  1.1  jruoho         /* Allocate a new string object */
    439  1.1  jruoho 
    440  1.1  jruoho         NewObject = AcpiUtCreateStringObject (Length);
    441  1.1  jruoho         if (!NewObject)
    442  1.1  jruoho         {
    443  1.1  jruoho             return (AE_NO_MEMORY);
    444  1.1  jruoho         }
    445  1.1  jruoho 
    446  1.1  jruoho         /*
    447  1.1  jruoho          * Copy the raw buffer data with no transform. String is already NULL
    448  1.1  jruoho          * terminated at Length+1.
    449  1.1  jruoho          */
    450  1.1  jruoho         ACPI_MEMCPY (NewObject->String.Pointer,
    451  1.1  jruoho             OriginalObject->Buffer.Pointer, Length);
    452  1.1  jruoho         break;
    453  1.1  jruoho 
    454  1.1  jruoho     default:
    455  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    456  1.1  jruoho     }
    457  1.1  jruoho 
    458  1.1  jruoho     *ReturnObject = NewObject;
    459  1.1  jruoho     return (AE_OK);
    460  1.1  jruoho }
    461  1.1  jruoho 
    462  1.1  jruoho 
    463  1.1  jruoho /*******************************************************************************
    464  1.1  jruoho  *
    465  1.1  jruoho  * FUNCTION:    AcpiNsConvertToBuffer
    466  1.1  jruoho  *
    467  1.1  jruoho  * PARAMETERS:  OriginalObject      - Object to be converted
    468  1.1  jruoho  *              ReturnObject        - Where the new converted object is returned
    469  1.1  jruoho  *
    470  1.1  jruoho  * RETURN:      Status. AE_OK if conversion was successful.
    471  1.1  jruoho  *
    472  1.1  jruoho  * DESCRIPTION: Attempt to convert a Integer/String/Package object to a Buffer.
    473  1.1  jruoho  *
    474  1.1  jruoho  ******************************************************************************/
    475  1.1  jruoho 
    476  1.1  jruoho static ACPI_STATUS
    477  1.1  jruoho AcpiNsConvertToBuffer (
    478  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    479  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject)
    480  1.1  jruoho {
    481  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    482  1.1  jruoho     ACPI_STATUS             Status;
    483  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements;
    484  1.1  jruoho     UINT32                  *DwordBuffer;
    485  1.1  jruoho     UINT32                  Count;
    486  1.1  jruoho     UINT32                  i;
    487  1.1  jruoho 
    488  1.1  jruoho 
    489  1.1  jruoho     switch (OriginalObject->Common.Type)
    490  1.1  jruoho     {
    491  1.1  jruoho     case ACPI_TYPE_INTEGER:
    492  1.1  jruoho         /*
    493  1.1  jruoho          * Integer-to-Buffer conversion.
    494  1.1  jruoho          * Convert the Integer to a packed-byte buffer. _MAT and other
    495  1.1  jruoho          * objects need this sometimes, if a read has been performed on a
    496  1.1  jruoho          * Field object that is less than or equal to the global integer
    497  1.1  jruoho          * size (32 or 64 bits).
    498  1.1  jruoho          */
    499  1.1  jruoho         Status = AcpiExConvertToBuffer (OriginalObject, &NewObject);
    500  1.1  jruoho         if (ACPI_FAILURE (Status))
    501  1.1  jruoho         {
    502  1.1  jruoho             return (Status);
    503  1.1  jruoho         }
    504  1.1  jruoho         break;
    505  1.1  jruoho 
    506  1.1  jruoho     case ACPI_TYPE_STRING:
    507  1.1  jruoho 
    508  1.1  jruoho         /* String-to-Buffer conversion. Simple data copy */
    509  1.1  jruoho 
    510  1.1  jruoho         NewObject = AcpiUtCreateBufferObject (OriginalObject->String.Length);
    511  1.1  jruoho         if (!NewObject)
    512  1.1  jruoho         {
    513  1.1  jruoho             return (AE_NO_MEMORY);
    514  1.1  jruoho         }
    515  1.1  jruoho 
    516  1.1  jruoho         ACPI_MEMCPY (NewObject->Buffer.Pointer,
    517  1.1  jruoho             OriginalObject->String.Pointer, OriginalObject->String.Length);
    518  1.1  jruoho         break;
    519  1.1  jruoho 
    520  1.1  jruoho     case ACPI_TYPE_PACKAGE:
    521  1.1  jruoho         /*
    522  1.1  jruoho          * This case is often seen for predefined names that must return a
    523  1.1  jruoho          * Buffer object with multiple DWORD integers within. For example,
    524  1.1  jruoho          * _FDE and _GTM. The Package can be converted to a Buffer.
    525  1.1  jruoho          */
    526  1.1  jruoho 
    527  1.1  jruoho         /* All elements of the Package must be integers */
    528  1.1  jruoho 
    529  1.1  jruoho         Elements = OriginalObject->Package.Elements;
    530  1.1  jruoho         Count = OriginalObject->Package.Count;
    531  1.1  jruoho 
    532  1.1  jruoho         for (i = 0; i < Count; i++)
    533  1.1  jruoho         {
    534  1.1  jruoho             if ((!*Elements) ||
    535  1.1  jruoho                 ((*Elements)->Common.Type != ACPI_TYPE_INTEGER))
    536  1.1  jruoho             {
    537  1.1  jruoho                 return (AE_AML_OPERAND_TYPE);
    538  1.1  jruoho             }
    539  1.1  jruoho             Elements++;
    540  1.1  jruoho         }
    541  1.1  jruoho 
    542  1.1  jruoho         /* Create the new buffer object to replace the Package */
    543  1.1  jruoho 
    544  1.1  jruoho         NewObject = AcpiUtCreateBufferObject (ACPI_MUL_4 (Count));
    545  1.1  jruoho         if (!NewObject)
    546  1.1  jruoho         {
    547  1.1  jruoho             return (AE_NO_MEMORY);
    548  1.1  jruoho         }
    549  1.1  jruoho 
    550  1.1  jruoho         /* Copy the package elements (integers) to the buffer as DWORDs */
    551  1.1  jruoho 
    552  1.1  jruoho         Elements = OriginalObject->Package.Elements;
    553  1.1  jruoho         DwordBuffer = ACPI_CAST_PTR (UINT32, NewObject->Buffer.Pointer);
    554  1.1  jruoho 
    555  1.1  jruoho         for (i = 0; i < Count; i++)
    556  1.1  jruoho         {
    557  1.1  jruoho             *DwordBuffer = (UINT32) (*Elements)->Integer.Value;
    558  1.1  jruoho             DwordBuffer++;
    559  1.1  jruoho             Elements++;
    560  1.1  jruoho         }
    561  1.1  jruoho         break;
    562  1.1  jruoho 
    563  1.1  jruoho     default:
    564  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    565  1.1  jruoho     }
    566  1.1  jruoho 
    567  1.1  jruoho     *ReturnObject = NewObject;
    568  1.1  jruoho     return (AE_OK);
    569  1.1  jruoho }
    570  1.1  jruoho 
    571  1.1  jruoho 
    572  1.1  jruoho /*******************************************************************************
    573  1.1  jruoho  *
    574  1.1  jruoho  * FUNCTION:    AcpiNsConvertToPackage
    575  1.1  jruoho  *
    576  1.1  jruoho  * PARAMETERS:  OriginalObject      - Object to be converted
    577  1.1  jruoho  *              ReturnObject        - Where the new converted object is returned
    578  1.1  jruoho  *
    579  1.1  jruoho  * RETURN:      Status. AE_OK if conversion was successful.
    580  1.1  jruoho  *
    581  1.1  jruoho  * DESCRIPTION: Attempt to convert a Buffer object to a Package. Each byte of
    582  1.1  jruoho  *              the buffer is converted to a single integer package element.
    583  1.1  jruoho  *
    584  1.1  jruoho  ******************************************************************************/
    585  1.1  jruoho 
    586  1.1  jruoho static ACPI_STATUS
    587  1.1  jruoho AcpiNsConvertToPackage (
    588  1.1  jruoho     ACPI_OPERAND_OBJECT     *OriginalObject,
    589  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObject)
    590  1.1  jruoho {
    591  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    592  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements;
    593  1.1  jruoho     UINT32                  Length;
    594  1.1  jruoho     UINT8                   *Buffer;
    595  1.1  jruoho 
    596  1.1  jruoho 
    597  1.1  jruoho     switch (OriginalObject->Common.Type)
    598  1.1  jruoho     {
    599  1.1  jruoho     case ACPI_TYPE_BUFFER:
    600  1.1  jruoho 
    601  1.1  jruoho         /* Buffer-to-Package conversion */
    602  1.1  jruoho 
    603  1.1  jruoho         Length = OriginalObject->Buffer.Length;
    604  1.1  jruoho         NewObject = AcpiUtCreatePackageObject (Length);
    605  1.1  jruoho         if (!NewObject)
    606  1.1  jruoho         {
    607  1.1  jruoho             return (AE_NO_MEMORY);
    608  1.1  jruoho         }
    609  1.1  jruoho 
    610  1.1  jruoho         /* Convert each buffer byte to an integer package element */
    611  1.1  jruoho 
    612  1.1  jruoho         Elements = NewObject->Package.Elements;
    613  1.1  jruoho         Buffer = OriginalObject->Buffer.Pointer;
    614  1.1  jruoho 
    615  1.1  jruoho         while (Length--)
    616  1.1  jruoho         {
    617  1.1  jruoho             *Elements = AcpiUtCreateIntegerObject ((UINT64) *Buffer);
    618  1.1  jruoho             if (!*Elements)
    619  1.1  jruoho             {
    620  1.1  jruoho                 AcpiUtRemoveReference (NewObject);
    621  1.1  jruoho                 return (AE_NO_MEMORY);
    622  1.1  jruoho             }
    623  1.1  jruoho             Elements++;
    624  1.1  jruoho             Buffer++;
    625  1.1  jruoho         }
    626  1.1  jruoho         break;
    627  1.1  jruoho 
    628  1.1  jruoho     default:
    629  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    630  1.1  jruoho     }
    631  1.1  jruoho 
    632  1.1  jruoho     *ReturnObject = NewObject;
    633  1.1  jruoho     return (AE_OK);
    634  1.1  jruoho }
    635  1.1  jruoho 
    636  1.1  jruoho 
    637  1.1  jruoho /*******************************************************************************
    638  1.1  jruoho  *
    639  1.1  jruoho  * FUNCTION:    AcpiNsRepairNullElement
    640  1.1  jruoho  *
    641  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    642  1.1  jruoho  *              ExpectedBtypes      - Object types expected
    643  1.1  jruoho  *              PackageIndex        - Index of object within parent package (if
    644  1.1  jruoho  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
    645  1.1  jruoho  *                                    otherwise)
    646  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    647  1.1  jruoho  *                                    evaluation of a method or object
    648  1.1  jruoho  *
    649  1.1  jruoho  * RETURN:      Status. AE_OK if repair was successful.
    650  1.1  jruoho  *
    651  1.1  jruoho  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
    652  1.1  jruoho  *
    653  1.1  jruoho  ******************************************************************************/
    654  1.1  jruoho 
    655  1.1  jruoho ACPI_STATUS
    656  1.1  jruoho AcpiNsRepairNullElement (
    657  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    658  1.1  jruoho     UINT32                  ExpectedBtypes,
    659  1.1  jruoho     UINT32                  PackageIndex,
    660  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    661  1.1  jruoho {
    662  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    663  1.1  jruoho     ACPI_OPERAND_OBJECT     *NewObject;
    664  1.1  jruoho 
    665  1.1  jruoho 
    666  1.1  jruoho     ACPI_FUNCTION_NAME (NsRepairNullElement);
    667  1.1  jruoho 
    668  1.1  jruoho 
    669  1.1  jruoho     /* No repair needed if return object is non-NULL */
    670  1.1  jruoho 
    671  1.1  jruoho     if (ReturnObject)
    672  1.1  jruoho     {
    673  1.1  jruoho         return (AE_OK);
    674  1.1  jruoho     }
    675  1.1  jruoho 
    676  1.1  jruoho     /*
    677  1.1  jruoho      * Attempt to repair a NULL element of a Package object. This applies to
    678  1.1  jruoho      * predefined names that return a fixed-length package and each element
    679  1.1  jruoho      * is required. It does not apply to variable-length packages where NULL
    680  1.1  jruoho      * elements are allowed, especially at the end of the package.
    681  1.1  jruoho      */
    682  1.1  jruoho     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
    683  1.1  jruoho     {
    684  1.1  jruoho         /* Need an Integer - create a zero-value integer */
    685  1.1  jruoho 
    686  1.1  jruoho         NewObject = AcpiUtCreateIntegerObject (0);
    687  1.1  jruoho     }
    688  1.1  jruoho     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
    689  1.1  jruoho     {
    690  1.1  jruoho         /* Need a String - create a NULL string */
    691  1.1  jruoho 
    692  1.1  jruoho         NewObject = AcpiUtCreateStringObject (0);
    693  1.1  jruoho     }
    694  1.1  jruoho     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
    695  1.1  jruoho     {
    696  1.1  jruoho         /* Need a Buffer - create a zero-length buffer */
    697  1.1  jruoho 
    698  1.1  jruoho         NewObject = AcpiUtCreateBufferObject (0);
    699  1.1  jruoho     }
    700  1.1  jruoho     else
    701  1.1  jruoho     {
    702  1.1  jruoho         /* Error for all other expected types */
    703  1.1  jruoho 
    704  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    705  1.1  jruoho     }
    706  1.1  jruoho 
    707  1.1  jruoho     if (!NewObject)
    708  1.1  jruoho     {
    709  1.1  jruoho         return (AE_NO_MEMORY);
    710  1.1  jruoho     }
    711  1.1  jruoho 
    712  1.1  jruoho     /* Set the reference count according to the parent Package object */
    713  1.1  jruoho 
    714  1.1  jruoho     NewObject->Common.ReferenceCount = Data->ParentPackage->Common.ReferenceCount;
    715  1.1  jruoho 
    716  1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    717  1.1  jruoho         "%s: Converted NULL package element to expected %s at index %u\n",
    718  1.1  jruoho          Data->Pathname, AcpiUtGetObjectTypeName (NewObject), PackageIndex));
    719  1.1  jruoho 
    720  1.1  jruoho     *ReturnObjectPtr = NewObject;
    721  1.1  jruoho     Data->Flags |= ACPI_OBJECT_REPAIRED;
    722  1.1  jruoho     return (AE_OK);
    723  1.1  jruoho }
    724  1.1  jruoho 
    725  1.1  jruoho 
    726  1.1  jruoho /******************************************************************************
    727  1.1  jruoho  *
    728  1.1  jruoho  * FUNCTION:    AcpiNsRemoveNullElements
    729  1.1  jruoho  *
    730  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    731  1.1  jruoho  *              PackageType         - An AcpiReturnPackageTypes value
    732  1.1  jruoho  *              ObjDesc             - A Package object
    733  1.1  jruoho  *
    734  1.1  jruoho  * RETURN:      None.
    735  1.1  jruoho  *
    736  1.1  jruoho  * DESCRIPTION: Remove all NULL package elements from packages that contain
    737  1.1  jruoho  *              a variable number of sub-packages. For these types of
    738  1.1  jruoho  *              packages, NULL elements can be safely removed.
    739  1.1  jruoho  *
    740  1.1  jruoho  *****************************************************************************/
    741  1.1  jruoho 
    742  1.1  jruoho void
    743  1.1  jruoho AcpiNsRemoveNullElements (
    744  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    745  1.1  jruoho     UINT8                   PackageType,
    746  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc)
    747  1.1  jruoho {
    748  1.1  jruoho     ACPI_OPERAND_OBJECT     **Source;
    749  1.1  jruoho     ACPI_OPERAND_OBJECT     **Dest;
    750  1.1  jruoho     UINT32                  Count;
    751  1.1  jruoho     UINT32                  NewCount;
    752  1.1  jruoho     UINT32                  i;
    753  1.1  jruoho 
    754  1.1  jruoho 
    755  1.1  jruoho     ACPI_FUNCTION_NAME (NsRemoveNullElements);
    756  1.1  jruoho 
    757  1.1  jruoho 
    758  1.1  jruoho     /*
    759  1.1  jruoho      * PTYPE1 packages contain no subpackages.
    760  1.1  jruoho      * PTYPE2 packages contain a variable number of sub-packages. We can
    761  1.1  jruoho      * safely remove all NULL elements from the PTYPE2 packages.
    762  1.1  jruoho      */
    763  1.1  jruoho     switch (PackageType)
    764  1.1  jruoho     {
    765  1.1  jruoho     case ACPI_PTYPE1_FIXED:
    766  1.1  jruoho     case ACPI_PTYPE1_VAR:
    767  1.1  jruoho     case ACPI_PTYPE1_OPTION:
    768  1.1  jruoho         return;
    769  1.1  jruoho 
    770  1.1  jruoho     case ACPI_PTYPE2:
    771  1.1  jruoho     case ACPI_PTYPE2_COUNT:
    772  1.1  jruoho     case ACPI_PTYPE2_PKG_COUNT:
    773  1.1  jruoho     case ACPI_PTYPE2_FIXED:
    774  1.1  jruoho     case ACPI_PTYPE2_MIN:
    775  1.1  jruoho     case ACPI_PTYPE2_REV_FIXED:
    776  1.1  jruoho         break;
    777  1.1  jruoho 
    778  1.1  jruoho     default:
    779  1.1  jruoho         return;
    780  1.1  jruoho     }
    781  1.1  jruoho 
    782  1.1  jruoho     Count = ObjDesc->Package.Count;
    783  1.1  jruoho     NewCount = Count;
    784  1.1  jruoho 
    785  1.1  jruoho     Source = ObjDesc->Package.Elements;
    786  1.1  jruoho     Dest = Source;
    787  1.1  jruoho 
    788  1.1  jruoho     /* Examine all elements of the package object, remove nulls */
    789  1.1  jruoho 
    790  1.1  jruoho     for (i = 0; i < Count; i++)
    791  1.1  jruoho     {
    792  1.1  jruoho         if (!*Source)
    793  1.1  jruoho         {
    794  1.1  jruoho             NewCount--;
    795  1.1  jruoho         }
    796  1.1  jruoho         else
    797  1.1  jruoho         {
    798  1.1  jruoho             *Dest = *Source;
    799  1.1  jruoho             Dest++;
    800  1.1  jruoho         }
    801  1.1  jruoho         Source++;
    802  1.1  jruoho     }
    803  1.1  jruoho 
    804  1.1  jruoho     /* Update parent package if any null elements were removed */
    805  1.1  jruoho 
    806  1.1  jruoho     if (NewCount < Count)
    807  1.1  jruoho     {
    808  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    809  1.1  jruoho             "%s: Found and removed %u NULL elements\n",
    810  1.1  jruoho             Data->Pathname, (Count - NewCount)));
    811  1.1  jruoho 
    812  1.1  jruoho         /* NULL terminate list and update the package count */
    813  1.1  jruoho 
    814  1.1  jruoho         *Dest = NULL;
    815  1.1  jruoho         ObjDesc->Package.Count = NewCount;
    816  1.1  jruoho     }
    817  1.1  jruoho }
    818  1.1  jruoho 
    819  1.1  jruoho 
    820  1.1  jruoho /*******************************************************************************
    821  1.1  jruoho  *
    822  1.1  jruoho  * FUNCTION:    AcpiNsRepairPackageList
    823  1.1  jruoho  *
    824  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    825  1.1  jruoho  *              ObjDescPtr          - Pointer to the object to repair. The new
    826  1.1  jruoho  *                                    package object is returned here,
    827  1.1  jruoho  *                                    overwriting the old object.
    828  1.1  jruoho  *
    829  1.1  jruoho  * RETURN:      Status, new object in *ObjDescPtr
    830  1.1  jruoho  *
    831  1.1  jruoho  * DESCRIPTION: Repair a common problem with objects that are defined to return
    832  1.1  jruoho  *              a variable-length Package of Packages. If the variable-length
    833  1.1  jruoho  *              is one, some BIOS code mistakenly simply declares a single
    834  1.1  jruoho  *              Package instead of a Package with one sub-Package. This
    835  1.1  jruoho  *              function attempts to repair this error by wrapping a Package
    836  1.1  jruoho  *              object around the original Package, creating the correct
    837  1.1  jruoho  *              Package with one sub-Package.
    838  1.1  jruoho  *
    839  1.1  jruoho  *              Names that can be repaired in this manner include:
    840  1.1  jruoho  *              _ALR, _CSD, _HPX, _MLS, _PRT, _PSS, _TRT, TSS
    841  1.1  jruoho  *
    842  1.1  jruoho  ******************************************************************************/
    843  1.1  jruoho 
    844  1.1  jruoho ACPI_STATUS
    845  1.1  jruoho AcpiNsRepairPackageList (
    846  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    847  1.1  jruoho     ACPI_OPERAND_OBJECT     **ObjDescPtr)
    848  1.1  jruoho {
    849  1.1  jruoho     ACPI_OPERAND_OBJECT     *PkgObjDesc;
    850  1.1  jruoho 
    851  1.1  jruoho 
    852  1.1  jruoho     ACPI_FUNCTION_NAME (NsRepairPackageList);
    853  1.1  jruoho 
    854  1.1  jruoho 
    855  1.1  jruoho     /*
    856  1.1  jruoho      * Create the new outer package and populate it. The new package will
    857  1.1  jruoho      * have a single element, the lone subpackage.
    858  1.1  jruoho      */
    859  1.1  jruoho     PkgObjDesc = AcpiUtCreatePackageObject (1);
    860  1.1  jruoho     if (!PkgObjDesc)
    861  1.1  jruoho     {
    862  1.1  jruoho         return (AE_NO_MEMORY);
    863  1.1  jruoho     }
    864  1.1  jruoho 
    865  1.1  jruoho     PkgObjDesc->Package.Elements[0] = *ObjDescPtr;
    866  1.1  jruoho 
    867  1.1  jruoho     /* Return the new object in the object pointer */
    868  1.1  jruoho 
    869  1.1  jruoho     *ObjDescPtr = PkgObjDesc;
    870  1.1  jruoho     Data->Flags |= ACPI_OBJECT_REPAIRED;
    871  1.1  jruoho 
    872  1.1  jruoho     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    873  1.1  jruoho         "%s: Repaired incorrectly formed Package\n", Data->Pathname));
    874  1.1  jruoho 
    875  1.1  jruoho     return (AE_OK);
    876  1.1  jruoho }
    877