Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:03

0001 /******************************************************************************
0002  *
0003  * Module Name: nsrepair - Repair for objects returned by predefined methods
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights. You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code. No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision. In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change. Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee. Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution. In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government. In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************
0115  *
0116  * Alternatively, you may choose to be licensed under the terms of the
0117  * following license:
0118  *
0119  * Redistribution and use in source and binary forms, with or without
0120  * modification, are permitted provided that the following conditions
0121  * are met:
0122  * 1. Redistributions of source code must retain the above copyright
0123  *    notice, this list of conditions, and the following disclaimer,
0124  *    without modification.
0125  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
0126  *    substantially similar to the "NO WARRANTY" disclaimer below
0127  *    ("Disclaimer") and any redistribution must be conditioned upon
0128  *    including a substantially similar Disclaimer requirement for further
0129  *    binary redistribution.
0130  * 3. Neither the names of the above-listed copyright holders nor the names
0131  *    of any contributors may be used to endorse or promote products derived
0132  *    from this software without specific prior written permission.
0133  *
0134  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
0135  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
0136  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
0137  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
0138  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
0139  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
0140  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
0141  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
0142  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
0143  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
0144  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0145  *
0146  * Alternatively, you may choose to be licensed under the terms of the
0147  * GNU General Public License ("GPL") version 2 as published by the Free
0148  * Software Foundation.
0149  *
0150  *****************************************************************************/
0151 
0152 #include "acpi.h"
0153 #include "accommon.h"
0154 #include "acnamesp.h"
0155 #include "acinterp.h"
0156 #include "acpredef.h"
0157 #include "amlresrc.h"
0158 
0159 #define _COMPONENT          ACPI_NAMESPACE
0160         ACPI_MODULE_NAME    ("nsrepair")
0161 
0162 
0163 /*******************************************************************************
0164  *
0165  * This module attempts to repair or convert objects returned by the
0166  * predefined methods to an object type that is expected, as per the ACPI
0167  * specification. The need for this code is dictated by the many machines that
0168  * return incorrect types for the standard predefined methods. Performing these
0169  * conversions here, in one place, eliminates the need for individual ACPI
0170  * device drivers to do the same. Note: Most of these conversions are different
0171  * than the internal object conversion routines used for implicit object
0172  * conversion.
0173  *
0174  * The following conversions can be performed as necessary:
0175  *
0176  * Integer -> String
0177  * Integer -> Buffer
0178  * String  -> Integer
0179  * String  -> Buffer
0180  * Buffer  -> Integer
0181  * Buffer  -> String
0182  * Buffer  -> Package of Integers
0183  * Package -> Package of one Package
0184  *
0185  * Additional conversions that are available:
0186  *  Convert a null return or zero return value to an EndTag descriptor
0187  *  Convert an ASCII string to a Unicode buffer
0188  *
0189  * An incorrect standalone object is wrapped with required outer package
0190  *
0191  * Additional possible repairs:
0192  * Required package elements that are NULL replaced by Integer/String/Buffer
0193  *
0194  ******************************************************************************/
0195 
0196 
0197 /* Local prototypes */
0198 
0199 static const ACPI_SIMPLE_REPAIR_INFO *
0200 AcpiNsMatchSimpleRepair (
0201     ACPI_NAMESPACE_NODE     *Node,
0202     UINT32                  ReturnBtype,
0203     UINT32                  PackageIndex);
0204 
0205 
0206 /*
0207  * Special but simple repairs for some names.
0208  *
0209  * 2nd argument: Unexpected types that can be repaired
0210  */
0211 static const ACPI_SIMPLE_REPAIR_INFO    AcpiObjectRepairInfo[] =
0212 {
0213     /* Resource descriptor conversions */
0214 
0215     { "_CRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
0216                 ACPI_NOT_PACKAGE_ELEMENT,
0217                 AcpiNsConvertToResource },
0218     { "_DMA", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
0219                 ACPI_NOT_PACKAGE_ELEMENT,
0220                 AcpiNsConvertToResource },
0221     { "_PRS", ACPI_RTYPE_INTEGER | ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER | ACPI_RTYPE_NONE,
0222                 ACPI_NOT_PACKAGE_ELEMENT,
0223                 AcpiNsConvertToResource },
0224 
0225     /* Object reference conversions */
0226 
0227     { "_DEP", ACPI_RTYPE_STRING, ACPI_ALL_PACKAGE_ELEMENTS,
0228                 AcpiNsConvertToReference },
0229 
0230     /* Unicode conversions */
0231 
0232     { "_MLS", ACPI_RTYPE_STRING, 1,
0233                 AcpiNsConvertToUnicode },
0234     { "_STR", ACPI_RTYPE_STRING | ACPI_RTYPE_BUFFER,
0235                 ACPI_NOT_PACKAGE_ELEMENT,
0236                 AcpiNsConvertToUnicode },
0237     { {0,0,0,0}, 0, 0, NULL } /* Table terminator */
0238 };
0239 
0240 
0241 /*******************************************************************************
0242  *
0243  * FUNCTION:    AcpiNsSimpleRepair
0244  *
0245  * PARAMETERS:  Info                - Method execution information block
0246  *              ExpectedBtypes      - Object types expected
0247  *              PackageIndex        - Index of object within parent package (if
0248  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
0249  *                                    otherwise)
0250  *              ReturnObjectPtr     - Pointer to the object returned from the
0251  *                                    evaluation of a method or object
0252  *
0253  * RETURN:      Status. AE_OK if repair was successful.
0254  *
0255  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
0256  *              not expected.
0257  *
0258  ******************************************************************************/
0259 
0260 ACPI_STATUS
0261 AcpiNsSimpleRepair (
0262     ACPI_EVALUATE_INFO      *Info,
0263     UINT32                  ExpectedBtypes,
0264     UINT32                  PackageIndex,
0265     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
0266 {
0267     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
0268     ACPI_OPERAND_OBJECT     *NewObject = NULL;
0269     ACPI_STATUS             Status;
0270     const ACPI_SIMPLE_REPAIR_INFO   *Predefined;
0271 
0272 
0273     ACPI_FUNCTION_NAME (NsSimpleRepair);
0274 
0275 
0276     /*
0277      * Special repairs for certain names that are in the repair table.
0278      * Check if this name is in the list of repairable names.
0279      */
0280     Predefined = AcpiNsMatchSimpleRepair (Info->Node,
0281         Info->ReturnBtype, PackageIndex);
0282     if (Predefined)
0283     {
0284         if (!ReturnObject)
0285         {
0286             ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
0287                 ACPI_WARN_ALWAYS, "Missing expected return value"));
0288         }
0289 
0290         Status = Predefined->ObjectConverter (Info->Node, ReturnObject,
0291             &NewObject);
0292         if (ACPI_FAILURE (Status))
0293         {
0294             /* A fatal error occurred during a conversion */
0295 
0296             ACPI_EXCEPTION ((AE_INFO, Status,
0297                 "During return object analysis"));
0298             return (Status);
0299         }
0300         if (NewObject)
0301         {
0302             goto ObjectRepaired;
0303         }
0304     }
0305 
0306     /*
0307      * Do not perform simple object repair unless the return type is not
0308      * expected.
0309      */
0310     if (Info->ReturnBtype & ExpectedBtypes)
0311     {
0312         return (AE_OK);
0313     }
0314 
0315     /*
0316      * At this point, we know that the type of the returned object was not
0317      * one of the expected types for this predefined name. Attempt to
0318      * repair the object by converting it to one of the expected object
0319      * types for this predefined name.
0320      */
0321 
0322     /*
0323      * If there is no return value, check if we require a return value for
0324      * this predefined name. Either one return value is expected, or none,
0325      * for both methods and other objects.
0326      *
0327      * Try to fix if there was no return object. Warning if failed to fix.
0328      */
0329     if (!ReturnObject)
0330     {
0331         if (ExpectedBtypes)
0332         {
0333             if (!(ExpectedBtypes & ACPI_RTYPE_NONE) &&
0334                 PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
0335             {
0336                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
0337                     ACPI_WARN_ALWAYS, "Found unexpected NULL package element"));
0338 
0339                 Status = AcpiNsRepairNullElement (Info, ExpectedBtypes,
0340                     PackageIndex, ReturnObjectPtr);
0341                 if (ACPI_SUCCESS (Status))
0342                 {
0343                     return (AE_OK); /* Repair was successful */
0344                 }
0345             }
0346 
0347             if (ExpectedBtypes != ACPI_RTYPE_NONE)
0348             {
0349                 ACPI_WARN_PREDEFINED ((AE_INFO, Info->FullPathname,
0350                                        ACPI_WARN_ALWAYS,
0351                                        "Missing expected return value"));
0352                 return (AE_AML_NO_RETURN_VALUE);
0353             }
0354         }
0355     }
0356 
0357     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
0358     {
0359         Status = AcpiNsConvertToInteger (ReturnObject, &NewObject);
0360         if (ACPI_SUCCESS (Status))
0361         {
0362             goto ObjectRepaired;
0363         }
0364     }
0365     if (ExpectedBtypes & ACPI_RTYPE_STRING)
0366     {
0367         Status = AcpiNsConvertToString (ReturnObject, &NewObject);
0368         if (ACPI_SUCCESS (Status))
0369         {
0370             goto ObjectRepaired;
0371         }
0372     }
0373     if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
0374     {
0375         Status = AcpiNsConvertToBuffer (ReturnObject, &NewObject);
0376         if (ACPI_SUCCESS (Status))
0377         {
0378             goto ObjectRepaired;
0379         }
0380     }
0381     if (ExpectedBtypes & ACPI_RTYPE_PACKAGE)
0382     {
0383         /*
0384          * A package is expected. We will wrap the existing object with a
0385          * new package object. It is often the case that if a variable-length
0386          * package is required, but there is only a single object needed, the
0387          * BIOS will return that object instead of wrapping it with a Package
0388          * object. Note: after the wrapping, the package will be validated
0389          * for correct contents (expected object type or types).
0390          */
0391         Status = AcpiNsWrapWithPackage (Info, ReturnObject, &NewObject);
0392         if (ACPI_SUCCESS (Status))
0393         {
0394             /*
0395              * The original object just had its reference count
0396              * incremented for being inserted into the new package.
0397              */
0398             *ReturnObjectPtr = NewObject;       /* New Package object */
0399             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
0400             return (AE_OK);
0401         }
0402     }
0403 
0404     /* We cannot repair this object */
0405 
0406     return (AE_AML_OPERAND_TYPE);
0407 
0408 
0409 ObjectRepaired:
0410 
0411     /* Object was successfully repaired */
0412 
0413     if (PackageIndex != ACPI_NOT_PACKAGE_ELEMENT)
0414     {
0415         /* Update reference count of new object */
0416 
0417         if (!(Info->ReturnFlags & ACPI_OBJECT_WRAPPED))
0418         {
0419             NewObject->Common.ReferenceCount =
0420                 ReturnObject->Common.ReferenceCount;
0421         }
0422 
0423         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
0424             "%s: Converted %s to expected %s at Package index %u\n",
0425             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
0426             AcpiUtGetObjectTypeName (NewObject), PackageIndex));
0427     }
0428     else
0429     {
0430         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
0431             "%s: Converted %s to expected %s\n",
0432             Info->FullPathname, AcpiUtGetObjectTypeName (ReturnObject),
0433             AcpiUtGetObjectTypeName (NewObject)));
0434     }
0435 
0436     /* Delete old object, install the new return object */
0437 
0438     AcpiUtRemoveReference (ReturnObject);
0439     *ReturnObjectPtr = NewObject;
0440     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
0441     return (AE_OK);
0442 }
0443 
0444 
0445 /******************************************************************************
0446  *
0447  * FUNCTION:    AcpiNsMatchSimpleRepair
0448  *
0449  * PARAMETERS:  Node                - Namespace node for the method/object
0450  *              ReturnBtype         - Object type that was returned
0451  *              PackageIndex        - Index of object within parent package (if
0452  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
0453  *                                    otherwise)
0454  *
0455  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
0456  *
0457  * DESCRIPTION: Check an object name against the repairable object list.
0458  *
0459  *****************************************************************************/
0460 
0461 static const ACPI_SIMPLE_REPAIR_INFO *
0462 AcpiNsMatchSimpleRepair (
0463     ACPI_NAMESPACE_NODE     *Node,
0464     UINT32                  ReturnBtype,
0465     UINT32                  PackageIndex)
0466 {
0467     const ACPI_SIMPLE_REPAIR_INFO   *ThisName;
0468 
0469 
0470     /* Search info table for a repairable predefined method/object name */
0471 
0472     ThisName = AcpiObjectRepairInfo;
0473     while (ThisName->ObjectConverter)
0474     {
0475         if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, ThisName->Name))
0476         {
0477             /* Check if we can actually repair this name/type combination */
0478 
0479             if ((ReturnBtype & ThisName->UnexpectedBtypes) &&
0480                 (ThisName->PackageIndex == ACPI_ALL_PACKAGE_ELEMENTS ||
0481                  PackageIndex == ThisName->PackageIndex))
0482             {
0483                 return (ThisName);
0484             }
0485 
0486             return (NULL);
0487         }
0488 
0489         ThisName++;
0490     }
0491 
0492     return (NULL); /* Name was not found in the repair table */
0493 }
0494 
0495 
0496 /*******************************************************************************
0497  *
0498  * FUNCTION:    AcpiNsRepairNullElement
0499  *
0500  * PARAMETERS:  Info                - Method execution information block
0501  *              ExpectedBtypes      - Object types expected
0502  *              PackageIndex        - Index of object within parent package (if
0503  *                                    applicable - ACPI_NOT_PACKAGE_ELEMENT
0504  *                                    otherwise)
0505  *              ReturnObjectPtr     - Pointer to the object returned from the
0506  *                                    evaluation of a method or object
0507  *
0508  * RETURN:      Status. AE_OK if repair was successful.
0509  *
0510  * DESCRIPTION: Attempt to repair a NULL element of a returned Package object.
0511  *
0512  ******************************************************************************/
0513 
0514 ACPI_STATUS
0515 AcpiNsRepairNullElement (
0516     ACPI_EVALUATE_INFO      *Info,
0517     UINT32                  ExpectedBtypes,
0518     UINT32                  PackageIndex,
0519     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
0520 {
0521     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
0522     ACPI_OPERAND_OBJECT     *NewObject;
0523 
0524 
0525     ACPI_FUNCTION_NAME (NsRepairNullElement);
0526 
0527 
0528     /* No repair needed if return object is non-NULL */
0529 
0530     if (ReturnObject)
0531     {
0532         return (AE_OK);
0533     }
0534 
0535     /*
0536      * Attempt to repair a NULL element of a Package object. This applies to
0537      * predefined names that return a fixed-length package and each element
0538      * is required. It does not apply to variable-length packages where NULL
0539      * elements are allowed, especially at the end of the package.
0540      */
0541     if (ExpectedBtypes & ACPI_RTYPE_INTEGER)
0542     {
0543         /* Need an Integer - create a zero-value integer */
0544 
0545         NewObject = AcpiUtCreateIntegerObject ((UINT64) 0);
0546     }
0547     else if (ExpectedBtypes & ACPI_RTYPE_STRING)
0548     {
0549         /* Need a String - create a NULL string */
0550 
0551         NewObject = AcpiUtCreateStringObject (0);
0552     }
0553     else if (ExpectedBtypes & ACPI_RTYPE_BUFFER)
0554     {
0555         /* Need a Buffer - create a zero-length buffer */
0556 
0557         NewObject = AcpiUtCreateBufferObject (0);
0558     }
0559     else
0560     {
0561         /* Error for all other expected types */
0562 
0563         return (AE_AML_OPERAND_TYPE);
0564     }
0565 
0566     if (!NewObject)
0567     {
0568         return (AE_NO_MEMORY);
0569     }
0570 
0571     /* Set the reference count according to the parent Package object */
0572 
0573     NewObject->Common.ReferenceCount =
0574         Info->ParentPackage->Common.ReferenceCount;
0575 
0576     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
0577         "%s: Converted NULL package element to expected %s at index %u\n",
0578         Info->FullPathname, AcpiUtGetObjectTypeName (NewObject),
0579         PackageIndex));
0580 
0581     *ReturnObjectPtr = NewObject;
0582     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
0583     return (AE_OK);
0584 }
0585 
0586 
0587 /******************************************************************************
0588  *
0589  * FUNCTION:    AcpiNsRemoveNullElements
0590  *
0591  * PARAMETERS:  Info                - Method execution information block
0592  *              PackageType         - An AcpiReturnPackageTypes value
0593  *              ObjDesc             - A Package object
0594  *
0595  * RETURN:      None.
0596  *
0597  * DESCRIPTION: Remove all NULL package elements from packages that contain
0598  *              a variable number of subpackages. For these types of
0599  *              packages, NULL elements can be safely removed.
0600  *
0601  *****************************************************************************/
0602 
0603 void
0604 AcpiNsRemoveNullElements (
0605     ACPI_EVALUATE_INFO      *Info,
0606     UINT8                   PackageType,
0607     ACPI_OPERAND_OBJECT     *ObjDesc)
0608 {
0609     ACPI_OPERAND_OBJECT     **Source;
0610     ACPI_OPERAND_OBJECT     **Dest;
0611     UINT32                  Count;
0612     UINT32                  NewCount;
0613     UINT32                  i;
0614 
0615 
0616     ACPI_FUNCTION_NAME (NsRemoveNullElements);
0617 
0618 
0619     /*
0620      * We can safely remove all NULL elements from these package types:
0621      * PTYPE1_VAR packages contain a variable number of simple data types.
0622      * PTYPE2 packages contain a variable number of subpackages.
0623      */
0624     switch (PackageType)
0625     {
0626     case ACPI_PTYPE1_VAR:
0627     case ACPI_PTYPE2:
0628     case ACPI_PTYPE2_COUNT:
0629     case ACPI_PTYPE2_PKG_COUNT:
0630     case ACPI_PTYPE2_FIXED:
0631     case ACPI_PTYPE2_MIN:
0632     case ACPI_PTYPE2_REV_FIXED:
0633     case ACPI_PTYPE2_FIX_VAR:
0634         break;
0635 
0636     default:
0637     case ACPI_PTYPE2_VAR_VAR:
0638     case ACPI_PTYPE1_FIXED:
0639     case ACPI_PTYPE1_OPTION:
0640         return;
0641     }
0642 
0643     Count = ObjDesc->Package.Count;
0644     NewCount = Count;
0645 
0646     Source = ObjDesc->Package.Elements;
0647     Dest = Source;
0648 
0649     /* Examine all elements of the package object, remove nulls */
0650 
0651     for (i = 0; i < Count; i++)
0652     {
0653         if (!*Source)
0654         {
0655             NewCount--;
0656         }
0657         else
0658         {
0659             *Dest = *Source;
0660             Dest++;
0661         }
0662 
0663         Source++;
0664     }
0665 
0666     /* Update parent package if any null elements were removed */
0667 
0668     if (NewCount < Count)
0669     {
0670         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
0671             "%s: Found and removed %u NULL elements\n",
0672             Info->FullPathname, (Count - NewCount)));
0673 
0674         /* NULL terminate list and update the package count */
0675 
0676         *Dest = NULL;
0677         ObjDesc->Package.Count = NewCount;
0678     }
0679 }
0680 
0681 
0682 /*******************************************************************************
0683  *
0684  * FUNCTION:    AcpiNsWrapWithPackage
0685  *
0686  * PARAMETERS:  Info                - Method execution information block
0687  *              OriginalObject      - Pointer to the object to repair.
0688  *              ObjDescPtr          - The new package object is returned here
0689  *
0690  * RETURN:      Status, new object in *ObjDescPtr
0691  *
0692  * DESCRIPTION: Repair a common problem with objects that are defined to
0693  *              return a variable-length Package of sub-objects. If there is
0694  *              only one sub-object, some BIOS code mistakenly simply declares
0695  *              the single object instead of a Package with one sub-object.
0696  *              This function attempts to repair this error by wrapping a
0697  *              Package object around the original object, creating the
0698  *              correct and expected Package with one sub-object.
0699  *
0700  *              Names that can be repaired in this manner include:
0701  *              _ALR, _CSD, _HPX, _MLS, _PLD, _PRT, _PSS, _TRT, _TSS,
0702  *              _BCL, _DOD, _FIX, _Sx
0703  *
0704  ******************************************************************************/
0705 
0706 ACPI_STATUS
0707 AcpiNsWrapWithPackage (
0708     ACPI_EVALUATE_INFO      *Info,
0709     ACPI_OPERAND_OBJECT     *OriginalObject,
0710     ACPI_OPERAND_OBJECT     **ObjDescPtr)
0711 {
0712     ACPI_OPERAND_OBJECT     *PkgObjDesc;
0713 
0714 
0715     ACPI_FUNCTION_NAME (NsWrapWithPackage);
0716 
0717 
0718     /*
0719      * Create the new outer package and populate it. The new
0720      * package will have a single element, the lone sub-object.
0721      */
0722     PkgObjDesc = AcpiUtCreatePackageObject (1);
0723     if (!PkgObjDesc)
0724     {
0725         return (AE_NO_MEMORY);
0726     }
0727 
0728     PkgObjDesc->Package.Elements[0] = OriginalObject;
0729 
0730     ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
0731         "%s: Wrapped %s with expected Package object\n",
0732         Info->FullPathname, AcpiUtGetObjectTypeName (OriginalObject)));
0733 
0734     /* Return the new object in the object pointer */
0735 
0736     *ObjDescPtr = PkgObjDesc;
0737     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED | ACPI_OBJECT_WRAPPED;
0738     return (AE_OK);
0739 }