Home | History | Annotate | Line # | Download | only in namespace
nsrepair2.c revision 1.21
      1   1.1    jruoho /******************************************************************************
      2   1.1    jruoho  *
      3   1.1    jruoho  * Module Name: nsrepair2 - Repair for objects returned by specific
      4   1.1    jruoho  *                          predefined methods
      5   1.1    jruoho  *
      6   1.1    jruoho  *****************************************************************************/
      7   1.1    jruoho 
      8  1.21  christos /******************************************************************************
      9  1.21  christos  *
     10  1.21  christos  * 1. Copyright Notice
     11  1.21  christos  *
     12  1.21  christos  * Some or all of this work - Copyright (c) 1999 - 2024, Intel Corp.
     13   1.1    jruoho  * All rights reserved.
     14   1.1    jruoho  *
     15  1.21  christos  * 2. License
     16  1.21  christos  *
     17  1.21  christos  * 2.1. This is your license from Intel Corp. under its intellectual property
     18  1.21  christos  * rights. You may have additional license terms from the party that provided
     19  1.21  christos  * you this software, covering your right to use that party's intellectual
     20  1.21  christos  * property rights.
     21  1.21  christos  *
     22  1.21  christos  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
     23  1.21  christos  * copy of the source code appearing in this file ("Covered Code") an
     24  1.21  christos  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
     25  1.21  christos  * base code distributed originally by Intel ("Original Intel Code") to copy,
     26  1.21  christos  * make derivatives, distribute, use and display any portion of the Covered
     27  1.21  christos  * Code in any form, with the right to sublicense such rights; and
     28  1.21  christos  *
     29  1.21  christos  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
     30  1.21  christos  * license (with the right to sublicense), under only those claims of Intel
     31  1.21  christos  * patents that are infringed by the Original Intel Code, to make, use, sell,
     32  1.21  christos  * offer to sell, and import the Covered Code and derivative works thereof
     33  1.21  christos  * solely to the minimum extent necessary to exercise the above copyright
     34  1.21  christos  * license, and in no event shall the patent license extend to any additions
     35  1.21  christos  * to or modifications of the Original Intel Code. No other license or right
     36  1.21  christos  * is granted directly or by implication, estoppel or otherwise;
     37  1.21  christos  *
     38  1.21  christos  * The above copyright and patent license is granted only if the following
     39  1.21  christos  * conditions are met:
     40  1.21  christos  *
     41  1.21  christos  * 3. Conditions
     42  1.21  christos  *
     43  1.21  christos  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
     44  1.21  christos  * Redistribution of source code of any substantial portion of the Covered
     45  1.21  christos  * Code or modification with rights to further distribute source must include
     46  1.21  christos  * the above Copyright Notice, the above License, this list of Conditions,
     47  1.21  christos  * and the following Disclaimer and Export Compliance provision. In addition,
     48  1.21  christos  * Licensee must cause all Covered Code to which Licensee contributes to
     49  1.21  christos  * contain a file documenting the changes Licensee made to create that Covered
     50  1.21  christos  * Code and the date of any change. Licensee must include in that file the
     51  1.21  christos  * documentation of any changes made by any predecessor Licensee. Licensee
     52  1.21  christos  * must include a prominent statement that the modification is derived,
     53  1.21  christos  * directly or indirectly, from Original Intel Code.
     54  1.21  christos  *
     55  1.21  christos  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
     56  1.21  christos  * Redistribution of source code of any substantial portion of the Covered
     57  1.21  christos  * Code or modification without rights to further distribute source must
     58  1.21  christos  * include the following Disclaimer and Export Compliance provision in the
     59  1.21  christos  * documentation and/or other materials provided with distribution. In
     60  1.21  christos  * addition, Licensee may not authorize further sublicense of source of any
     61  1.21  christos  * portion of the Covered Code, and must include terms to the effect that the
     62  1.21  christos  * license from Licensee to its licensee is limited to the intellectual
     63  1.21  christos  * property embodied in the software Licensee provides to its licensee, and
     64  1.21  christos  * not to intellectual property embodied in modifications its licensee may
     65  1.21  christos  * make.
     66  1.21  christos  *
     67  1.21  christos  * 3.3. Redistribution of Executable. Redistribution in executable form of any
     68  1.21  christos  * substantial portion of the Covered Code or modification must reproduce the
     69  1.21  christos  * above Copyright Notice, and the following Disclaimer and Export Compliance
     70  1.21  christos  * provision in the documentation and/or other materials provided with the
     71  1.21  christos  * distribution.
     72  1.21  christos  *
     73  1.21  christos  * 3.4. Intel retains all right, title, and interest in and to the Original
     74  1.21  christos  * Intel Code.
     75  1.21  christos  *
     76  1.21  christos  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
     77  1.21  christos  * Intel shall be used in advertising or otherwise to promote the sale, use or
     78  1.21  christos  * other dealings in products derived from or relating to the Covered Code
     79  1.21  christos  * without prior written authorization from Intel.
     80  1.21  christos  *
     81  1.21  christos  * 4. Disclaimer and Export Compliance
     82  1.21  christos  *
     83  1.21  christos  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
     84  1.21  christos  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
     85  1.21  christos  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
     86  1.21  christos  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
     87  1.21  christos  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
     88  1.21  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
     89  1.21  christos  * PARTICULAR PURPOSE.
     90  1.21  christos  *
     91  1.21  christos  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
     92  1.21  christos  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
     93  1.21  christos  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
     94  1.21  christos  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
     95  1.21  christos  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
     96  1.21  christos  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
     97  1.21  christos  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
     98  1.21  christos  * LIMITED REMEDY.
     99  1.21  christos  *
    100  1.21  christos  * 4.3. Licensee shall not export, either directly or indirectly, any of this
    101  1.21  christos  * software or system incorporating such software without first obtaining any
    102  1.21  christos  * required license or other approval from the U. S. Department of Commerce or
    103  1.21  christos  * any other agency or department of the United States Government. In the
    104  1.21  christos  * event Licensee exports any such software from the United States or
    105  1.21  christos  * re-exports any such software from a foreign destination, Licensee shall
    106  1.21  christos  * ensure that the distribution and export/re-export of the software is in
    107  1.21  christos  * compliance with all laws, regulations, orders, or other restrictions of the
    108  1.21  christos  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
    109  1.21  christos  * any of its subsidiaries will export/re-export any technical data, process,
    110  1.21  christos  * software, or service, directly or indirectly, to any country for which the
    111  1.21  christos  * United States government or any agency thereof requires an export license,
    112  1.21  christos  * other governmental approval, or letter of assurance, without first obtaining
    113  1.21  christos  * such license, approval or letter.
    114  1.21  christos  *
    115  1.21  christos  *****************************************************************************
    116  1.21  christos  *
    117  1.21  christos  * Alternatively, you may choose to be licensed under the terms of the
    118  1.21  christos  * following license:
    119  1.21  christos  *
    120   1.3    jruoho  * Redistribution and use in source and binary forms, with or without
    121   1.3    jruoho  * modification, are permitted provided that the following conditions
    122   1.3    jruoho  * are met:
    123   1.3    jruoho  * 1. Redistributions of source code must retain the above copyright
    124   1.3    jruoho  *    notice, this list of conditions, and the following disclaimer,
    125   1.3    jruoho  *    without modification.
    126   1.3    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
    127   1.3    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
    128   1.3    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
    129   1.3    jruoho  *    including a substantially similar Disclaimer requirement for further
    130   1.3    jruoho  *    binary redistribution.
    131   1.3    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
    132   1.3    jruoho  *    of any contributors may be used to endorse or promote products derived
    133   1.3    jruoho  *    from this software without specific prior written permission.
    134   1.3    jruoho  *
    135   1.3    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
    136   1.3    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
    137  1.17  christos  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
    138   1.3    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
    139  1.21  christos  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
    140  1.21  christos  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
    141  1.21  christos  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    142  1.21  christos  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
    143  1.21  christos  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
    144  1.21  christos  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
    145  1.21  christos  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    146  1.21  christos  *
    147  1.21  christos  * Alternatively, you may choose to be licensed under the terms of the
    148  1.21  christos  * GNU General Public License ("GPL") version 2 as published by the Free
    149  1.21  christos  * Software Foundation.
    150  1.21  christos  *
    151  1.21  christos  *****************************************************************************/
    152   1.1    jruoho 
    153   1.1    jruoho #include "acpi.h"
    154   1.1    jruoho #include "accommon.h"
    155   1.1    jruoho #include "acnamesp.h"
    156   1.1    jruoho 
    157   1.1    jruoho #define _COMPONENT          ACPI_NAMESPACE
    158   1.1    jruoho         ACPI_MODULE_NAME    ("nsrepair2")
    159   1.1    jruoho 
    160   1.1    jruoho 
    161   1.1    jruoho /*
    162   1.1    jruoho  * Information structure and handler for ACPI predefined names that can
    163   1.1    jruoho  * be repaired on a per-name basis.
    164   1.1    jruoho  */
    165   1.1    jruoho typedef
    166   1.1    jruoho ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
    167   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    168   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    169   1.1    jruoho 
    170   1.1    jruoho typedef struct acpi_repair_info
    171   1.1    jruoho {
    172  1.13  christos     char                    Name[ACPI_NAMESEG_SIZE];
    173   1.1    jruoho     ACPI_REPAIR_FUNCTION    RepairFunction;
    174   1.1    jruoho 
    175   1.1    jruoho } ACPI_REPAIR_INFO;
    176   1.1    jruoho 
    177   1.1    jruoho 
    178   1.1    jruoho /* Local prototypes */
    179   1.1    jruoho 
    180   1.1    jruoho static const ACPI_REPAIR_INFO *
    181   1.5  christos AcpiNsMatchComplexRepair (
    182   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node);
    183   1.1    jruoho 
    184   1.1    jruoho static ACPI_STATUS
    185   1.1    jruoho AcpiNsRepair_ALR (
    186   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    187   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    188   1.1    jruoho 
    189   1.1    jruoho static ACPI_STATUS
    190   1.3    jruoho AcpiNsRepair_CID (
    191   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    192   1.5  christos     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    193   1.5  christos 
    194   1.5  christos static ACPI_STATUS
    195   1.5  christos AcpiNsRepair_CST (
    196   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    197   1.3    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    198   1.3    jruoho 
    199   1.3    jruoho static ACPI_STATUS
    200   1.1    jruoho AcpiNsRepair_FDE (
    201   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    202   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    203   1.1    jruoho 
    204   1.1    jruoho static ACPI_STATUS
    205   1.3    jruoho AcpiNsRepair_HID (
    206   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    207   1.5  christos     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    208   1.5  christos 
    209   1.5  christos static ACPI_STATUS
    210   1.5  christos AcpiNsRepair_PRT (
    211   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    212   1.3    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    213   1.3    jruoho 
    214   1.3    jruoho static ACPI_STATUS
    215   1.1    jruoho AcpiNsRepair_PSS (
    216   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    217   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    218   1.1    jruoho 
    219   1.1    jruoho static ACPI_STATUS
    220   1.1    jruoho AcpiNsRepair_TSS (
    221   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    222   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    223   1.1    jruoho 
    224   1.1    jruoho static ACPI_STATUS
    225   1.1    jruoho AcpiNsCheckSortedList (
    226   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    227   1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject,
    228   1.5  christos     UINT32                  StartIndex,
    229   1.1    jruoho     UINT32                  ExpectedCount,
    230   1.1    jruoho     UINT32                  SortIndex,
    231   1.1    jruoho     UINT8                   SortDirection,
    232   1.9  christos     const char              *SortKeyName);
    233   1.1    jruoho 
    234   1.5  christos /* Values for SortDirection above */
    235   1.5  christos 
    236   1.5  christos #define ACPI_SORT_ASCENDING     0
    237   1.5  christos #define ACPI_SORT_DESCENDING    1
    238   1.5  christos 
    239   1.5  christos static void
    240   1.5  christos AcpiNsRemoveElement (
    241   1.5  christos     ACPI_OPERAND_OBJECT     *ObjDesc,
    242   1.5  christos     UINT32                  Index);
    243   1.5  christos 
    244   1.1    jruoho static void
    245   1.1    jruoho AcpiNsSortList (
    246   1.1    jruoho     ACPI_OPERAND_OBJECT     **Elements,
    247   1.1    jruoho     UINT32                  Count,
    248   1.1    jruoho     UINT32                  Index,
    249   1.1    jruoho     UINT8                   SortDirection);
    250   1.1    jruoho 
    251   1.1    jruoho 
    252   1.1    jruoho /*
    253   1.1    jruoho  * This table contains the names of the predefined methods for which we can
    254   1.1    jruoho  * perform more complex repairs.
    255   1.1    jruoho  *
    256   1.1    jruoho  * As necessary:
    257   1.1    jruoho  *
    258   1.1    jruoho  * _ALR: Sort the list ascending by AmbientIlluminance
    259   1.3    jruoho  * _CID: Strings: uppercase all, remove any leading asterisk
    260   1.5  christos  * _CST: Sort the list ascending by C state type
    261   1.1    jruoho  * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
    262   1.1    jruoho  * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
    263   1.3    jruoho  * _HID: Strings: uppercase all, remove any leading asterisk
    264   1.5  christos  * _PRT: Fix reversed SourceName and SourceIndex
    265   1.1    jruoho  * _PSS: Sort the list descending by Power
    266   1.1    jruoho  * _TSS: Sort the list descending by Power
    267   1.1    jruoho  *
    268   1.1    jruoho  * Names that must be packages, but cannot be sorted:
    269   1.1    jruoho  *
    270   1.1    jruoho  * _BCL: Values are tied to the Package index where they appear, and cannot
    271   1.1    jruoho  * be moved or sorted. These index values are used for _BQC and _BCM.
    272   1.1    jruoho  * However, we can fix the case where a buffer is returned, by converting
    273   1.1    jruoho  * it to a Package of integers.
    274   1.1    jruoho  */
    275   1.1    jruoho static const ACPI_REPAIR_INFO       AcpiNsRepairableNames[] =
    276   1.1    jruoho {
    277   1.1    jruoho     {"_ALR", AcpiNsRepair_ALR},
    278   1.3    jruoho     {"_CID", AcpiNsRepair_CID},
    279   1.5  christos     {"_CST", AcpiNsRepair_CST},
    280   1.1    jruoho     {"_FDE", AcpiNsRepair_FDE},
    281   1.1    jruoho     {"_GTM", AcpiNsRepair_FDE},     /* _GTM has same repair as _FDE */
    282   1.3    jruoho     {"_HID", AcpiNsRepair_HID},
    283   1.5  christos     {"_PRT", AcpiNsRepair_PRT},
    284   1.1    jruoho     {"_PSS", AcpiNsRepair_PSS},
    285   1.1    jruoho     {"_TSS", AcpiNsRepair_TSS},
    286   1.1    jruoho     {{0,0,0,0}, NULL}               /* Table terminator */
    287   1.1    jruoho };
    288   1.1    jruoho 
    289   1.1    jruoho 
    290   1.1    jruoho #define ACPI_FDE_FIELD_COUNT        5
    291   1.1    jruoho #define ACPI_FDE_BYTE_BUFFER_SIZE   5
    292  1.14  christos #define ACPI_FDE_DWORD_BUFFER_SIZE  (ACPI_FDE_FIELD_COUNT * (UINT32) sizeof (UINT32))
    293   1.1    jruoho 
    294   1.1    jruoho 
    295   1.1    jruoho /******************************************************************************
    296   1.1    jruoho  *
    297   1.1    jruoho  * FUNCTION:    AcpiNsComplexRepairs
    298   1.1    jruoho  *
    299   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    300   1.1    jruoho  *              Node                - Namespace node for the method/object
    301   1.1    jruoho  *              ValidateStatus      - Original status of earlier validation
    302   1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    303   1.1    jruoho  *                                    evaluation of a method or object
    304   1.1    jruoho  *
    305   1.1    jruoho  * RETURN:      Status. AE_OK if repair was successful. If name is not
    306   1.1    jruoho  *              matched, ValidateStatus is returned.
    307   1.1    jruoho  *
    308   1.1    jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    309   1.1    jruoho  *              not expected.
    310   1.1    jruoho  *
    311   1.1    jruoho  *****************************************************************************/
    312   1.1    jruoho 
    313   1.1    jruoho ACPI_STATUS
    314   1.1    jruoho AcpiNsComplexRepairs (
    315   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    316   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node,
    317   1.1    jruoho     ACPI_STATUS             ValidateStatus,
    318   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    319   1.1    jruoho {
    320   1.1    jruoho     const ACPI_REPAIR_INFO  *Predefined;
    321   1.1    jruoho     ACPI_STATUS             Status;
    322   1.1    jruoho 
    323   1.1    jruoho 
    324  1.16  christos     ACPI_FUNCTION_TRACE (NsComplexRepairs);
    325  1.16  christos 
    326   1.1    jruoho     /* Check if this name is in the list of repairable names */
    327   1.1    jruoho 
    328   1.5  christos     Predefined = AcpiNsMatchComplexRepair (Node);
    329   1.1    jruoho     if (!Predefined)
    330   1.1    jruoho     {
    331  1.16  christos         return_ACPI_STATUS (ValidateStatus);
    332   1.1    jruoho     }
    333   1.1    jruoho 
    334   1.5  christos     Status = Predefined->RepairFunction (Info, ReturnObjectPtr);
    335  1.16  christos     return_ACPI_STATUS (Status);
    336   1.1    jruoho }
    337   1.1    jruoho 
    338   1.1    jruoho 
    339   1.1    jruoho /******************************************************************************
    340   1.1    jruoho  *
    341   1.5  christos  * FUNCTION:    AcpiNsMatchComplexRepair
    342   1.1    jruoho  *
    343   1.1    jruoho  * PARAMETERS:  Node                - Namespace node for the method/object
    344   1.1    jruoho  *
    345   1.1    jruoho  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
    346   1.1    jruoho  *
    347   1.1    jruoho  * DESCRIPTION: Check an object name against the repairable object list.
    348   1.1    jruoho  *
    349   1.1    jruoho  *****************************************************************************/
    350   1.1    jruoho 
    351   1.1    jruoho static const ACPI_REPAIR_INFO *
    352   1.5  christos AcpiNsMatchComplexRepair (
    353   1.1    jruoho     ACPI_NAMESPACE_NODE     *Node)
    354   1.1    jruoho {
    355   1.1    jruoho     const ACPI_REPAIR_INFO  *ThisName;
    356   1.1    jruoho 
    357   1.1    jruoho 
    358   1.1    jruoho     /* Search info table for a repairable predefined method/object name */
    359   1.1    jruoho 
    360   1.1    jruoho     ThisName = AcpiNsRepairableNames;
    361   1.1    jruoho     while (ThisName->RepairFunction)
    362   1.1    jruoho     {
    363  1.13  christos         if (ACPI_COMPARE_NAMESEG (Node->Name.Ascii, ThisName->Name))
    364   1.1    jruoho         {
    365   1.1    jruoho             return (ThisName);
    366   1.1    jruoho         }
    367   1.9  christos 
    368   1.1    jruoho         ThisName++;
    369   1.1    jruoho     }
    370   1.1    jruoho 
    371   1.1    jruoho     return (NULL); /* Not found */
    372   1.1    jruoho }
    373   1.1    jruoho 
    374   1.1    jruoho 
    375   1.1    jruoho /******************************************************************************
    376   1.1    jruoho  *
    377   1.1    jruoho  * FUNCTION:    AcpiNsRepair_ALR
    378   1.1    jruoho  *
    379   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    380   1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    381   1.1    jruoho  *                                    evaluation of a method or object
    382   1.1    jruoho  *
    383   1.1    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    384   1.1    jruoho  *
    385   1.1    jruoho  * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
    386   1.1    jruoho  *              ascending by the ambient illuminance values.
    387   1.1    jruoho  *
    388   1.1    jruoho  *****************************************************************************/
    389   1.1    jruoho 
    390   1.1    jruoho static ACPI_STATUS
    391   1.1    jruoho AcpiNsRepair_ALR (
    392   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    393   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    394   1.1    jruoho {
    395   1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    396   1.1    jruoho     ACPI_STATUS             Status;
    397   1.1    jruoho 
    398   1.1    jruoho 
    399   1.5  christos     Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 2, 1,
    400   1.9  christos         ACPI_SORT_ASCENDING, "AmbientIlluminance");
    401   1.1    jruoho 
    402   1.1    jruoho     return (Status);
    403   1.1    jruoho }
    404   1.1    jruoho 
    405   1.1    jruoho 
    406   1.1    jruoho /******************************************************************************
    407   1.1    jruoho  *
    408   1.1    jruoho  * FUNCTION:    AcpiNsRepair_FDE
    409   1.1    jruoho  *
    410   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    411   1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    412   1.1    jruoho  *                                    evaluation of a method or object
    413   1.1    jruoho  *
    414   1.1    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    415   1.1    jruoho  *
    416   1.1    jruoho  * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
    417   1.1    jruoho  *              value is a Buffer of 5 DWORDs. This function repairs a common
    418   1.1    jruoho  *              problem where the return value is a Buffer of BYTEs, not
    419   1.1    jruoho  *              DWORDs.
    420   1.1    jruoho  *
    421   1.1    jruoho  *****************************************************************************/
    422   1.1    jruoho 
    423   1.1    jruoho static ACPI_STATUS
    424   1.1    jruoho AcpiNsRepair_FDE (
    425   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    426   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    427   1.1    jruoho {
    428   1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    429   1.1    jruoho     ACPI_OPERAND_OBJECT     *BufferObject;
    430   1.1    jruoho     UINT8                   *ByteBuffer;
    431   1.1    jruoho     UINT32                  *DwordBuffer;
    432   1.1    jruoho     UINT32                  i;
    433   1.1    jruoho 
    434   1.1    jruoho 
    435   1.1    jruoho     ACPI_FUNCTION_NAME (NsRepair_FDE);
    436   1.1    jruoho 
    437   1.1    jruoho 
    438   1.1    jruoho     switch (ReturnObject->Common.Type)
    439   1.1    jruoho     {
    440   1.1    jruoho     case ACPI_TYPE_BUFFER:
    441   1.1    jruoho 
    442   1.1    jruoho         /* This is the expected type. Length should be (at least) 5 DWORDs */
    443   1.1    jruoho 
    444   1.1    jruoho         if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
    445   1.1    jruoho         {
    446   1.1    jruoho             return (AE_OK);
    447   1.1    jruoho         }
    448   1.1    jruoho 
    449   1.1    jruoho         /* We can only repair if we have exactly 5 BYTEs */
    450   1.1    jruoho 
    451   1.1    jruoho         if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
    452   1.1    jruoho         {
    453   1.9  christos             ACPI_WARN_PREDEFINED ((AE_INFO,
    454   1.9  christos                 Info->FullPathname, Info->NodeFlags,
    455   1.1    jruoho                 "Incorrect return buffer length %u, expected %u",
    456   1.1    jruoho                 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
    457   1.1    jruoho 
    458   1.1    jruoho             return (AE_AML_OPERAND_TYPE);
    459   1.1    jruoho         }
    460   1.1    jruoho 
    461   1.1    jruoho         /* Create the new (larger) buffer object */
    462   1.1    jruoho 
    463   1.9  christos         BufferObject = AcpiUtCreateBufferObject (
    464   1.9  christos             ACPI_FDE_DWORD_BUFFER_SIZE);
    465   1.1    jruoho         if (!BufferObject)
    466   1.1    jruoho         {
    467   1.1    jruoho             return (AE_NO_MEMORY);
    468   1.1    jruoho         }
    469   1.1    jruoho 
    470   1.1    jruoho         /* Expand each byte to a DWORD */
    471   1.1    jruoho 
    472   1.1    jruoho         ByteBuffer = ReturnObject->Buffer.Pointer;
    473   1.9  christos         DwordBuffer = ACPI_CAST_PTR (UINT32,
    474   1.9  christos             BufferObject->Buffer.Pointer);
    475   1.1    jruoho 
    476   1.1    jruoho         for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
    477   1.1    jruoho         {
    478   1.1    jruoho             *DwordBuffer = (UINT32) *ByteBuffer;
    479   1.1    jruoho             DwordBuffer++;
    480   1.1    jruoho             ByteBuffer++;
    481   1.1    jruoho         }
    482   1.1    jruoho 
    483   1.1    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    484   1.1    jruoho             "%s Expanded Byte Buffer to expected DWord Buffer\n",
    485   1.5  christos             Info->FullPathname));
    486   1.1    jruoho         break;
    487   1.1    jruoho 
    488   1.1    jruoho     default:
    489   1.5  christos 
    490   1.1    jruoho         return (AE_AML_OPERAND_TYPE);
    491   1.1    jruoho     }
    492   1.1    jruoho 
    493   1.1    jruoho     /* Delete the original return object, return the new buffer object */
    494   1.1    jruoho 
    495   1.1    jruoho     AcpiUtRemoveReference (ReturnObject);
    496   1.1    jruoho     *ReturnObjectPtr = BufferObject;
    497   1.1    jruoho 
    498   1.5  christos     Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    499   1.1    jruoho     return (AE_OK);
    500   1.1    jruoho }
    501   1.1    jruoho 
    502   1.1    jruoho 
    503   1.1    jruoho /******************************************************************************
    504   1.1    jruoho  *
    505   1.3    jruoho  * FUNCTION:    AcpiNsRepair_CID
    506   1.3    jruoho  *
    507   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    508   1.3    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    509   1.3    jruoho  *                                    evaluation of a method or object
    510   1.3    jruoho  *
    511   1.3    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    512   1.3    jruoho  *
    513   1.3    jruoho  * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
    514   1.3    jruoho  *              letters are uppercase and that there is no leading asterisk.
    515   1.3    jruoho  *              If a Package, ensure same for all string elements.
    516   1.3    jruoho  *
    517   1.3    jruoho  *****************************************************************************/
    518   1.3    jruoho 
    519   1.3    jruoho static ACPI_STATUS
    520   1.3    jruoho AcpiNsRepair_CID (
    521   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    522   1.3    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    523   1.3    jruoho {
    524   1.3    jruoho     ACPI_STATUS             Status;
    525   1.3    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    526   1.3    jruoho     ACPI_OPERAND_OBJECT     **ElementPtr;
    527   1.3    jruoho     ACPI_OPERAND_OBJECT     *OriginalElement;
    528   1.3    jruoho     UINT16                  OriginalRefCount;
    529   1.3    jruoho     UINT32                  i;
    530   1.3    jruoho 
    531  1.16  christos     ACPI_FUNCTION_TRACE (NsRepair_CID);
    532   1.3    jruoho 
    533   1.3    jruoho     /* Check for _CID as a simple string */
    534   1.3    jruoho 
    535   1.3    jruoho     if (ReturnObject->Common.Type == ACPI_TYPE_STRING)
    536   1.3    jruoho     {
    537   1.5  christos         Status = AcpiNsRepair_HID (Info, ReturnObjectPtr);
    538  1.16  christos         return_ACPI_STATUS (Status);
    539   1.3    jruoho     }
    540   1.3    jruoho 
    541   1.3    jruoho     /* Exit if not a Package */
    542   1.3    jruoho 
    543   1.3    jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
    544   1.3    jruoho     {
    545  1.16  christos         return_ACPI_STATUS (AE_OK);
    546   1.3    jruoho     }
    547   1.3    jruoho 
    548   1.3    jruoho     /* Examine each element of the _CID package */
    549   1.3    jruoho 
    550   1.3    jruoho     ElementPtr = ReturnObject->Package.Elements;
    551   1.3    jruoho     for (i = 0; i < ReturnObject->Package.Count; i++)
    552   1.3    jruoho     {
    553   1.3    jruoho         OriginalElement = *ElementPtr;
    554   1.3    jruoho         OriginalRefCount = OriginalElement->Common.ReferenceCount;
    555   1.3    jruoho 
    556   1.5  christos         Status = AcpiNsRepair_HID (Info, ElementPtr);
    557   1.3    jruoho         if (ACPI_FAILURE (Status))
    558   1.3    jruoho         {
    559  1.16  christos             return_ACPI_STATUS (Status);
    560   1.3    jruoho         }
    561   1.3    jruoho 
    562   1.3    jruoho         if (OriginalElement != *ElementPtr)
    563   1.3    jruoho         {
    564  1.11  christos             /* Update reference count of new object */
    565   1.3    jruoho 
    566   1.3    jruoho             (*ElementPtr)->Common.ReferenceCount =
    567   1.3    jruoho                 OriginalRefCount;
    568   1.3    jruoho         }
    569   1.3    jruoho 
    570   1.3    jruoho         ElementPtr++;
    571   1.3    jruoho     }
    572   1.3    jruoho 
    573  1.16  christos     return_ACPI_STATUS (AE_OK);
    574   1.3    jruoho }
    575   1.3    jruoho 
    576   1.3    jruoho 
    577   1.3    jruoho /******************************************************************************
    578   1.3    jruoho  *
    579   1.5  christos  * FUNCTION:    AcpiNsRepair_CST
    580   1.5  christos  *
    581   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    582   1.5  christos  *              ReturnObjectPtr     - Pointer to the object returned from the
    583   1.5  christos  *                                    evaluation of a method or object
    584   1.5  christos  *
    585   1.5  christos  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    586   1.5  christos  *
    587   1.5  christos  * DESCRIPTION: Repair for the _CST object:
    588   1.5  christos  *              1. Sort the list ascending by C state type
    589   1.5  christos  *              2. Ensure type cannot be zero
    590   1.6  christos  *              3. A subpackage count of zero means _CST is meaningless
    591   1.6  christos  *              4. Count must match the number of C state subpackages
    592   1.5  christos  *
    593   1.5  christos  *****************************************************************************/
    594   1.5  christos 
    595   1.5  christos static ACPI_STATUS
    596   1.5  christos AcpiNsRepair_CST (
    597   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    598   1.5  christos     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    599   1.5  christos {
    600   1.5  christos     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    601   1.5  christos     ACPI_OPERAND_OBJECT     **OuterElements;
    602   1.5  christos     UINT32                  OuterElementCount;
    603   1.5  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    604   1.5  christos     ACPI_STATUS             Status;
    605   1.5  christos     BOOLEAN                 Removing;
    606   1.5  christos     UINT32                  i;
    607   1.5  christos 
    608   1.5  christos 
    609   1.5  christos     ACPI_FUNCTION_NAME (NsRepair_CST);
    610   1.5  christos 
    611   1.5  christos 
    612   1.5  christos     /*
    613   1.5  christos      * Check if the C-state type values are proportional.
    614   1.5  christos      */
    615   1.5  christos     OuterElementCount = ReturnObject->Package.Count - 1;
    616   1.5  christos     i = 0;
    617   1.5  christos     while (i < OuterElementCount)
    618   1.5  christos     {
    619   1.5  christos         OuterElements = &ReturnObject->Package.Elements[i + 1];
    620   1.5  christos         Removing = FALSE;
    621   1.5  christos 
    622   1.5  christos         if ((*OuterElements)->Package.Count == 0)
    623   1.5  christos         {
    624   1.9  christos             ACPI_WARN_PREDEFINED ((AE_INFO,
    625   1.9  christos                 Info->FullPathname, Info->NodeFlags,
    626   1.5  christos                 "SubPackage[%u] - removing entry due to zero count", i));
    627   1.5  christos             Removing = TRUE;
    628   1.5  christos             goto RemoveElement;
    629   1.5  christos         }
    630   1.5  christos 
    631   1.5  christos         ObjDesc = (*OuterElements)->Package.Elements[1]; /* Index1 = Type */
    632   1.5  christos         if ((UINT32) ObjDesc->Integer.Value == 0)
    633   1.5  christos         {
    634   1.9  christos             ACPI_WARN_PREDEFINED ((AE_INFO,
    635   1.9  christos                 Info->FullPathname, Info->NodeFlags,
    636   1.5  christos                 "SubPackage[%u] - removing entry due to invalid Type(0)", i));
    637   1.5  christos             Removing = TRUE;
    638   1.5  christos         }
    639   1.5  christos 
    640   1.5  christos RemoveElement:
    641   1.5  christos         if (Removing)
    642   1.5  christos         {
    643   1.5  christos             AcpiNsRemoveElement (ReturnObject, i + 1);
    644   1.5  christos             OuterElementCount--;
    645   1.5  christos         }
    646   1.5  christos         else
    647   1.5  christos         {
    648   1.5  christos             i++;
    649   1.5  christos         }
    650   1.5  christos     }
    651   1.5  christos 
    652   1.5  christos     /* Update top-level package count, Type "Integer" checked elsewhere */
    653   1.5  christos 
    654   1.5  christos     ObjDesc = ReturnObject->Package.Elements[0];
    655   1.5  christos     ObjDesc->Integer.Value = OuterElementCount;
    656   1.5  christos 
    657   1.5  christos     /*
    658   1.5  christos      * Entries (subpackages) in the _CST Package must be sorted by the
    659   1.5  christos      * C-state type, in ascending order.
    660   1.5  christos      */
    661   1.5  christos     Status = AcpiNsCheckSortedList (Info, ReturnObject, 1, 4, 1,
    662   1.9  christos         ACPI_SORT_ASCENDING, "C-State Type");
    663   1.5  christos     if (ACPI_FAILURE (Status))
    664   1.5  christos     {
    665   1.5  christos         return (Status);
    666   1.5  christos     }
    667   1.5  christos 
    668   1.5  christos     return (AE_OK);
    669   1.5  christos }
    670   1.5  christos 
    671   1.5  christos 
    672   1.5  christos /******************************************************************************
    673   1.5  christos  *
    674   1.3    jruoho  * FUNCTION:    AcpiNsRepair_HID
    675   1.3    jruoho  *
    676   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    677   1.3    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    678   1.3    jruoho  *                                    evaluation of a method or object
    679   1.3    jruoho  *
    680   1.3    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    681   1.3    jruoho  *
    682   1.3    jruoho  * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
    683   1.3    jruoho  *              letters are uppercase and that there is no leading asterisk.
    684   1.3    jruoho  *
    685   1.3    jruoho  *****************************************************************************/
    686   1.3    jruoho 
    687   1.3    jruoho static ACPI_STATUS
    688   1.3    jruoho AcpiNsRepair_HID (
    689   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    690   1.3    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    691   1.3    jruoho {
    692   1.3    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    693  1.17  christos     ACPI_OPERAND_OBJECT     *NewString;
    694  1.17  christos     char                    *Source;
    695  1.16  christos     char                    *Dest;
    696   1.3    jruoho 
    697   1.3    jruoho 
    698  1.20  christos     ACPI_FUNCTION_TRACE (NsRepair_HID);
    699   1.3    jruoho 
    700   1.3    jruoho 
    701   1.3    jruoho     /* We only care about string _HID objects (not integers) */
    702   1.3    jruoho 
    703   1.3    jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_STRING)
    704   1.3    jruoho     {
    705  1.16  christos         return_ACPI_STATUS (AE_OK);
    706   1.3    jruoho     }
    707   1.3    jruoho 
    708   1.3    jruoho     if (ReturnObject->String.Length == 0)
    709   1.3    jruoho     {
    710   1.9  christos         ACPI_WARN_PREDEFINED ((AE_INFO,
    711   1.9  christos             Info->FullPathname, Info->NodeFlags,
    712   1.3    jruoho             "Invalid zero-length _HID or _CID string"));
    713   1.3    jruoho 
    714   1.3    jruoho         /* Return AE_OK anyway, let driver handle it */
    715   1.3    jruoho 
    716   1.5  christos         Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    717  1.16  christos         return_ACPI_STATUS (AE_OK);
    718   1.3    jruoho     }
    719   1.3    jruoho 
    720  1.17  christos     /* It is simplest to always create a new string object */
    721  1.17  christos 
    722  1.17  christos     NewString = AcpiUtCreateStringObject (ReturnObject->String.Length);
    723  1.17  christos     if (!NewString)
    724  1.17  christos     {
    725  1.17  christos         return_ACPI_STATUS (AE_NO_MEMORY);
    726  1.17  christos     }
    727  1.17  christos 
    728   1.3    jruoho     /*
    729   1.3    jruoho      * Remove a leading asterisk if present. For some unknown reason, there
    730   1.3    jruoho      * are many machines in the field that contains IDs like this.
    731   1.3    jruoho      *
    732   1.3    jruoho      * Examples: "*PNP0C03", "*ACPI0003"
    733   1.3    jruoho      */
    734   1.3    jruoho     Source = ReturnObject->String.Pointer;
    735   1.3    jruoho     if (*Source == '*')
    736   1.3    jruoho     {
    737   1.3    jruoho         Source++;
    738  1.17  christos         NewString->String.Length--;
    739   1.3    jruoho 
    740   1.3    jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    741   1.5  christos             "%s: Removed invalid leading asterisk\n", Info->FullPathname));
    742   1.3    jruoho     }
    743   1.3    jruoho 
    744   1.3    jruoho     /*
    745   1.5  christos      * Copy and uppercase the string. From the ACPI 5.0 specification:
    746   1.3    jruoho      *
    747   1.3    jruoho      * A valid PNP ID must be of the form "AAA####" where A is an uppercase
    748   1.3    jruoho      * letter and # is a hex digit. A valid ACPI ID must be of the form
    749   1.5  christos      * "NNNN####" where N is an uppercase letter or decimal digit, and
    750   1.5  christos      * # is a hex digit.
    751   1.3    jruoho      */
    752  1.17  christos     for (Dest = NewString->String.Pointer; *Source; Dest++, Source++)
    753   1.3    jruoho     {
    754   1.8  christos         *Dest = (char) toupper ((int) *Source);
    755   1.3    jruoho     }
    756   1.3    jruoho 
    757  1.17  christos     AcpiUtRemoveReference (ReturnObject);
    758  1.17  christos     *ReturnObjectPtr = NewString;
    759  1.16  christos     return_ACPI_STATUS (AE_OK);
    760   1.3    jruoho }
    761   1.3    jruoho 
    762   1.3    jruoho 
    763   1.3    jruoho /******************************************************************************
    764   1.3    jruoho  *
    765   1.5  christos  * FUNCTION:    AcpiNsRepair_PRT
    766   1.1    jruoho  *
    767   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    768   1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    769   1.1    jruoho  *                                    evaluation of a method or object
    770   1.1    jruoho  *
    771   1.1    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    772   1.1    jruoho  *
    773   1.5  christos  * DESCRIPTION: Repair for the _PRT object. If necessary, fix reversed
    774   1.5  christos  *              SourceName and SourceIndex field, a common BIOS bug.
    775   1.1    jruoho  *
    776   1.1    jruoho  *****************************************************************************/
    777   1.1    jruoho 
    778   1.1    jruoho static ACPI_STATUS
    779   1.5  christos AcpiNsRepair_PRT (
    780   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    781   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    782   1.1    jruoho {
    783   1.5  christos     ACPI_OPERAND_OBJECT     *PackageObject = *ReturnObjectPtr;
    784   1.5  christos     ACPI_OPERAND_OBJECT     **TopObjectList;
    785   1.5  christos     ACPI_OPERAND_OBJECT     **SubObjectList;
    786   1.5  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    787   1.6  christos     ACPI_OPERAND_OBJECT     *SubPackage;
    788   1.5  christos     UINT32                  ElementCount;
    789   1.5  christos     UINT32                  Index;
    790   1.5  christos 
    791   1.5  christos 
    792   1.5  christos     /* Each element in the _PRT package is a subpackage */
    793   1.1    jruoho 
    794   1.5  christos     TopObjectList = PackageObject->Package.Elements;
    795   1.5  christos     ElementCount = PackageObject->Package.Count;
    796   1.1    jruoho 
    797   1.6  christos     /* Examine each subpackage */
    798   1.6  christos 
    799   1.6  christos     for (Index = 0; Index < ElementCount; Index++, TopObjectList++)
    800   1.4    jruoho     {
    801   1.6  christos         SubPackage = *TopObjectList;
    802   1.6  christos         SubObjectList = SubPackage->Package.Elements;
    803   1.6  christos 
    804   1.6  christos         /* Check for minimum required element count */
    805   1.6  christos 
    806   1.6  christos         if (SubPackage->Package.Count < 4)
    807   1.6  christos         {
    808   1.6  christos             continue;
    809   1.6  christos         }
    810   1.5  christos 
    811   1.5  christos         /*
    812   1.5  christos          * If the BIOS has erroneously reversed the _PRT SourceName (index 2)
    813   1.5  christos          * and the SourceIndex (index 3), fix it. _PRT is important enough to
    814   1.5  christos          * workaround this BIOS error. This also provides compatibility with
    815   1.5  christos          * other ACPI implementations.
    816   1.5  christos          */
    817   1.5  christos         ObjDesc = SubObjectList[3];
    818   1.5  christos         if (!ObjDesc || (ObjDesc->Common.Type != ACPI_TYPE_INTEGER))
    819   1.5  christos         {
    820   1.5  christos             SubObjectList[3] = SubObjectList[2];
    821   1.5  christos             SubObjectList[2] = ObjDesc;
    822   1.5  christos             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
    823   1.5  christos 
    824   1.6  christos             ACPI_WARN_PREDEFINED ((AE_INFO,
    825   1.6  christos                 Info->FullPathname, Info->NodeFlags,
    826   1.5  christos                 "PRT[%X]: Fixed reversed SourceName and SourceIndex",
    827   1.5  christos                 Index));
    828   1.5  christos         }
    829   1.4    jruoho     }
    830   1.4    jruoho 
    831   1.5  christos     return (AE_OK);
    832   1.1    jruoho }
    833   1.1    jruoho 
    834   1.1    jruoho 
    835   1.1    jruoho /******************************************************************************
    836   1.1    jruoho  *
    837   1.1    jruoho  * FUNCTION:    AcpiNsRepair_PSS
    838   1.1    jruoho  *
    839   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    840   1.1    jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    841   1.1    jruoho  *                                    evaluation of a method or object
    842   1.1    jruoho  *
    843   1.1    jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    844   1.1    jruoho  *
    845   1.1    jruoho  * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
    846   1.1    jruoho  *              by the CPU frequencies. Check that the power dissipation values
    847   1.1    jruoho  *              are all proportional to CPU frequency (i.e., sorting by
    848   1.1    jruoho  *              frequency should be the same as sorting by power.)
    849   1.1    jruoho  *
    850   1.1    jruoho  *****************************************************************************/
    851   1.1    jruoho 
    852   1.1    jruoho static ACPI_STATUS
    853   1.1    jruoho AcpiNsRepair_PSS (
    854   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    855   1.1    jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    856   1.1    jruoho {
    857   1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    858   1.1    jruoho     ACPI_OPERAND_OBJECT     **OuterElements;
    859   1.1    jruoho     UINT32                  OuterElementCount;
    860   1.1    jruoho     ACPI_OPERAND_OBJECT     **Elements;
    861   1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    862   1.1    jruoho     UINT32                  PreviousValue;
    863   1.1    jruoho     ACPI_STATUS             Status;
    864   1.1    jruoho     UINT32                  i;
    865   1.1    jruoho 
    866   1.1    jruoho 
    867   1.1    jruoho     /*
    868   1.6  christos      * Entries (subpackages) in the _PSS Package must be sorted by power
    869   1.1    jruoho      * dissipation, in descending order. If it appears that the list is
    870   1.1    jruoho      * incorrectly sorted, sort it. We sort by CpuFrequency, since this
    871   1.1    jruoho      * should be proportional to the power.
    872   1.1    jruoho      */
    873   1.9  christos     Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 6, 0,
    874   1.9  christos         ACPI_SORT_DESCENDING, "CpuFrequency");
    875   1.1    jruoho     if (ACPI_FAILURE (Status))
    876   1.1    jruoho     {
    877   1.1    jruoho         return (Status);
    878   1.1    jruoho     }
    879   1.1    jruoho 
    880   1.1    jruoho     /*
    881   1.1    jruoho      * We now know the list is correctly sorted by CPU frequency. Check if
    882   1.1    jruoho      * the power dissipation values are proportional.
    883   1.1    jruoho      */
    884   1.1    jruoho     PreviousValue = ACPI_UINT32_MAX;
    885   1.1    jruoho     OuterElements = ReturnObject->Package.Elements;
    886   1.1    jruoho     OuterElementCount = ReturnObject->Package.Count;
    887   1.1    jruoho 
    888   1.1    jruoho     for (i = 0; i < OuterElementCount; i++)
    889   1.1    jruoho     {
    890   1.1    jruoho         Elements = (*OuterElements)->Package.Elements;
    891   1.1    jruoho         ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
    892   1.1    jruoho 
    893   1.1    jruoho         if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
    894   1.1    jruoho         {
    895   1.9  christos             ACPI_WARN_PREDEFINED ((AE_INFO,
    896   1.9  christos                 Info->FullPathname, Info->NodeFlags,
    897   1.1    jruoho                 "SubPackage[%u,%u] - suspicious power dissipation values",
    898   1.1    jruoho                 i-1, i));
    899   1.1    jruoho         }
    900   1.1    jruoho 
    901   1.1    jruoho         PreviousValue = (UINT32) ObjDesc->Integer.Value;
    902   1.1    jruoho         OuterElements++;
    903   1.1    jruoho     }
    904   1.1    jruoho 
    905   1.1    jruoho     return (AE_OK);
    906   1.1    jruoho }
    907   1.1    jruoho 
    908   1.1    jruoho 
    909   1.1    jruoho /******************************************************************************
    910   1.1    jruoho  *
    911   1.5  christos  * FUNCTION:    AcpiNsRepair_TSS
    912   1.5  christos  *
    913   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    914   1.5  christos  *              ReturnObjectPtr     - Pointer to the object returned from the
    915   1.5  christos  *                                    evaluation of a method or object
    916   1.5  christos  *
    917   1.5  christos  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    918   1.5  christos  *
    919   1.5  christos  * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
    920   1.5  christos  *              descending by the power dissipation values.
    921   1.5  christos  *
    922   1.5  christos  *****************************************************************************/
    923   1.5  christos 
    924   1.5  christos static ACPI_STATUS
    925   1.5  christos AcpiNsRepair_TSS (
    926   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    927   1.5  christos     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    928   1.5  christos {
    929   1.5  christos     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    930   1.5  christos     ACPI_STATUS             Status;
    931   1.5  christos     ACPI_NAMESPACE_NODE     *Node;
    932   1.5  christos 
    933   1.5  christos 
    934   1.5  christos     /*
    935   1.5  christos      * We can only sort the _TSS return package if there is no _PSS in the
    936   1.5  christos      * same scope. This is because if _PSS is present, the ACPI specification
    937   1.5  christos      * dictates that the _TSS Power Dissipation field is to be ignored, and
    938   1.5  christos      * therefore some BIOSs leave garbage values in the _TSS Power field(s).
    939   1.5  christos      * In this case, it is best to just return the _TSS package as-is.
    940   1.5  christos      * (May, 2011)
    941   1.5  christos      */
    942   1.5  christos     Status = AcpiNsGetNode (Info->Node, "^_PSS",
    943   1.5  christos         ACPI_NS_NO_UPSEARCH, &Node);
    944   1.5  christos     if (ACPI_SUCCESS (Status))
    945   1.5  christos     {
    946   1.5  christos         return (AE_OK);
    947   1.5  christos     }
    948   1.5  christos 
    949   1.5  christos     Status = AcpiNsCheckSortedList (Info, ReturnObject, 0, 5, 1,
    950   1.9  christos         ACPI_SORT_DESCENDING, "PowerDissipation");
    951   1.5  christos 
    952   1.5  christos     return (Status);
    953   1.5  christos }
    954   1.5  christos 
    955   1.5  christos 
    956   1.5  christos /******************************************************************************
    957   1.5  christos  *
    958   1.1    jruoho  * FUNCTION:    AcpiNsCheckSortedList
    959   1.1    jruoho  *
    960   1.5  christos  * PARAMETERS:  Info                - Method execution information block
    961   1.1    jruoho  *              ReturnObject        - Pointer to the top-level returned object
    962   1.6  christos  *              StartIndex          - Index of the first subpackage
    963   1.6  christos  *              ExpectedCount       - Minimum length of each subpackage
    964   1.6  christos  *              SortIndex           - Subpackage entry to sort on
    965   1.1    jruoho  *              SortDirection       - Ascending or descending
    966   1.1    jruoho  *              SortKeyName         - Name of the SortIndex field
    967   1.1    jruoho  *
    968   1.1    jruoho  * RETURN:      Status. AE_OK if the list is valid and is sorted correctly or
    969   1.1    jruoho  *              has been repaired by sorting the list.
    970   1.1    jruoho  *
    971   1.1    jruoho  * DESCRIPTION: Check if the package list is valid and sorted correctly by the
    972   1.1    jruoho  *              SortIndex. If not, then sort the list.
    973   1.1    jruoho  *
    974   1.1    jruoho  *****************************************************************************/
    975   1.1    jruoho 
    976   1.1    jruoho static ACPI_STATUS
    977   1.1    jruoho AcpiNsCheckSortedList (
    978   1.5  christos     ACPI_EVALUATE_INFO      *Info,
    979   1.1    jruoho     ACPI_OPERAND_OBJECT     *ReturnObject,
    980   1.5  christos     UINT32                  StartIndex,
    981   1.1    jruoho     UINT32                  ExpectedCount,
    982   1.1    jruoho     UINT32                  SortIndex,
    983   1.1    jruoho     UINT8                   SortDirection,
    984   1.9  christos     const char              *SortKeyName)
    985   1.1    jruoho {
    986   1.1    jruoho     UINT32                  OuterElementCount;
    987   1.1    jruoho     ACPI_OPERAND_OBJECT     **OuterElements;
    988   1.1    jruoho     ACPI_OPERAND_OBJECT     **Elements;
    989   1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    990   1.1    jruoho     UINT32                  i;
    991   1.1    jruoho     UINT32                  PreviousValue;
    992   1.1    jruoho 
    993   1.1    jruoho 
    994   1.1    jruoho     ACPI_FUNCTION_NAME (NsCheckSortedList);
    995   1.1    jruoho 
    996   1.1    jruoho 
    997   1.1    jruoho     /* The top-level object must be a package */
    998   1.1    jruoho 
    999   1.1    jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
   1000   1.1    jruoho     {
   1001   1.1    jruoho         return (AE_AML_OPERAND_TYPE);
   1002   1.1    jruoho     }
   1003   1.1    jruoho 
   1004   1.1    jruoho     /*
   1005   1.6  christos      * NOTE: assumes list of subpackages contains no NULL elements.
   1006   1.1    jruoho      * Any NULL elements should have been removed by earlier call
   1007   1.1    jruoho      * to AcpiNsRemoveNullElements.
   1008   1.1    jruoho      */
   1009   1.1    jruoho     OuterElementCount = ReturnObject->Package.Count;
   1010   1.5  christos     if (!OuterElementCount || StartIndex >= OuterElementCount)
   1011   1.1    jruoho     {
   1012   1.1    jruoho         return (AE_AML_PACKAGE_LIMIT);
   1013   1.1    jruoho     }
   1014   1.1    jruoho 
   1015   1.5  christos     OuterElements = &ReturnObject->Package.Elements[StartIndex];
   1016   1.5  christos     OuterElementCount -= StartIndex;
   1017   1.5  christos 
   1018   1.1    jruoho     PreviousValue = 0;
   1019   1.1    jruoho     if (SortDirection == ACPI_SORT_DESCENDING)
   1020   1.1    jruoho     {
   1021   1.1    jruoho         PreviousValue = ACPI_UINT32_MAX;
   1022   1.1    jruoho     }
   1023   1.1    jruoho 
   1024   1.1    jruoho     /* Examine each subpackage */
   1025   1.1    jruoho 
   1026   1.1    jruoho     for (i = 0; i < OuterElementCount; i++)
   1027   1.1    jruoho     {
   1028   1.1    jruoho         /* Each element of the top-level package must also be a package */
   1029   1.1    jruoho 
   1030   1.1    jruoho         if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
   1031   1.1    jruoho         {
   1032   1.1    jruoho             return (AE_AML_OPERAND_TYPE);
   1033   1.1    jruoho         }
   1034   1.1    jruoho 
   1035   1.6  christos         /* Each subpackage must have the minimum length */
   1036   1.1    jruoho 
   1037   1.1    jruoho         if ((*OuterElements)->Package.Count < ExpectedCount)
   1038   1.1    jruoho         {
   1039   1.1    jruoho             return (AE_AML_PACKAGE_LIMIT);
   1040   1.1    jruoho         }
   1041   1.1    jruoho 
   1042   1.1    jruoho         Elements = (*OuterElements)->Package.Elements;
   1043   1.1    jruoho         ObjDesc = Elements[SortIndex];
   1044   1.1    jruoho 
   1045   1.1    jruoho         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
   1046   1.1    jruoho         {
   1047   1.1    jruoho             return (AE_AML_OPERAND_TYPE);
   1048   1.1    jruoho         }
   1049   1.1    jruoho 
   1050   1.1    jruoho         /*
   1051   1.1    jruoho          * The list must be sorted in the specified order. If we detect a
   1052   1.1    jruoho          * discrepancy, sort the entire list.
   1053   1.1    jruoho          */
   1054   1.1    jruoho         if (((SortDirection == ACPI_SORT_ASCENDING) &&
   1055   1.1    jruoho                 (ObjDesc->Integer.Value < PreviousValue)) ||
   1056   1.1    jruoho             ((SortDirection == ACPI_SORT_DESCENDING) &&
   1057   1.1    jruoho                 (ObjDesc->Integer.Value > PreviousValue)))
   1058   1.1    jruoho         {
   1059   1.5  christos             AcpiNsSortList (&ReturnObject->Package.Elements[StartIndex],
   1060   1.1    jruoho                 OuterElementCount, SortIndex, SortDirection);
   1061   1.1    jruoho 
   1062   1.5  christos             Info->ReturnFlags |= ACPI_OBJECT_REPAIRED;
   1063   1.1    jruoho 
   1064   1.1    jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
   1065   1.1    jruoho                 "%s: Repaired unsorted list - now sorted by %s\n",
   1066   1.5  christos                 Info->FullPathname, SortKeyName));
   1067   1.1    jruoho             return (AE_OK);
   1068   1.1    jruoho         }
   1069   1.1    jruoho 
   1070   1.1    jruoho         PreviousValue = (UINT32) ObjDesc->Integer.Value;
   1071   1.1    jruoho         OuterElements++;
   1072   1.1    jruoho     }
   1073   1.1    jruoho 
   1074   1.1    jruoho     return (AE_OK);
   1075   1.1    jruoho }
   1076   1.1    jruoho 
   1077   1.1    jruoho 
   1078   1.1    jruoho /******************************************************************************
   1079   1.1    jruoho  *
   1080   1.1    jruoho  * FUNCTION:    AcpiNsSortList
   1081   1.1    jruoho  *
   1082   1.1    jruoho  * PARAMETERS:  Elements            - Package object element list
   1083   1.1    jruoho  *              Count               - Element count for above
   1084   1.1    jruoho  *              Index               - Sort by which package element
   1085   1.1    jruoho  *              SortDirection       - Ascending or Descending sort
   1086   1.1    jruoho  *
   1087   1.1    jruoho  * RETURN:      None
   1088   1.1    jruoho  *
   1089   1.1    jruoho  * DESCRIPTION: Sort the objects that are in a package element list.
   1090   1.1    jruoho  *
   1091   1.1    jruoho  * NOTE: Assumes that all NULL elements have been removed from the package,
   1092   1.1    jruoho  *       and that all elements have been verified to be of type Integer.
   1093   1.1    jruoho  *
   1094   1.1    jruoho  *****************************************************************************/
   1095   1.1    jruoho 
   1096   1.1    jruoho static void
   1097   1.1    jruoho AcpiNsSortList (
   1098   1.1    jruoho     ACPI_OPERAND_OBJECT     **Elements,
   1099   1.1    jruoho     UINT32                  Count,
   1100   1.1    jruoho     UINT32                  Index,
   1101   1.1    jruoho     UINT8                   SortDirection)
   1102   1.1    jruoho {
   1103   1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc1;
   1104   1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc2;
   1105   1.1    jruoho     ACPI_OPERAND_OBJECT     *TempObj;
   1106   1.1    jruoho     UINT32                  i;
   1107   1.1    jruoho     UINT32                  j;
   1108   1.1    jruoho 
   1109   1.1    jruoho 
   1110   1.1    jruoho     /* Simple bubble sort */
   1111   1.1    jruoho 
   1112   1.1    jruoho     for (i = 1; i < Count; i++)
   1113   1.1    jruoho     {
   1114   1.1    jruoho         for (j = (Count - 1); j >= i; j--)
   1115   1.1    jruoho         {
   1116   1.1    jruoho             ObjDesc1 = Elements[j-1]->Package.Elements[Index];
   1117   1.1    jruoho             ObjDesc2 = Elements[j]->Package.Elements[Index];
   1118   1.1    jruoho 
   1119   1.1    jruoho             if (((SortDirection == ACPI_SORT_ASCENDING) &&
   1120   1.1    jruoho                     (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
   1121   1.1    jruoho 
   1122   1.1    jruoho                 ((SortDirection == ACPI_SORT_DESCENDING) &&
   1123   1.1    jruoho                     (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
   1124   1.1    jruoho             {
   1125   1.1    jruoho                 TempObj = Elements[j-1];
   1126   1.1    jruoho                 Elements[j-1] = Elements[j];
   1127   1.1    jruoho                 Elements[j] = TempObj;
   1128   1.1    jruoho             }
   1129   1.1    jruoho         }
   1130   1.1    jruoho     }
   1131   1.1    jruoho }
   1132   1.5  christos 
   1133   1.5  christos 
   1134   1.5  christos /******************************************************************************
   1135   1.5  christos  *
   1136   1.5  christos  * FUNCTION:    AcpiNsRemoveElement
   1137   1.5  christos  *
   1138   1.5  christos  * PARAMETERS:  ObjDesc             - Package object element list
   1139   1.5  christos  *              Index               - Index of element to remove
   1140   1.5  christos  *
   1141   1.5  christos  * RETURN:      None
   1142   1.5  christos  *
   1143   1.5  christos  * DESCRIPTION: Remove the requested element of a package and delete it.
   1144   1.5  christos  *
   1145   1.5  christos  *****************************************************************************/
   1146   1.5  christos 
   1147   1.5  christos static void
   1148   1.5  christos AcpiNsRemoveElement (
   1149   1.5  christos     ACPI_OPERAND_OBJECT     *ObjDesc,
   1150   1.5  christos     UINT32                  Index)
   1151   1.5  christos {
   1152   1.5  christos     ACPI_OPERAND_OBJECT     **Source;
   1153   1.5  christos     ACPI_OPERAND_OBJECT     **Dest;
   1154   1.5  christos     UINT32                  Count;
   1155   1.5  christos     UINT32                  NewCount;
   1156   1.5  christos     UINT32                  i;
   1157   1.5  christos 
   1158   1.5  christos 
   1159   1.5  christos     ACPI_FUNCTION_NAME (NsRemoveElement);
   1160   1.5  christos 
   1161   1.5  christos 
   1162   1.5  christos     Count = ObjDesc->Package.Count;
   1163   1.5  christos     NewCount = Count - 1;
   1164   1.5  christos 
   1165   1.5  christos     Source = ObjDesc->Package.Elements;
   1166   1.5  christos     Dest = Source;
   1167   1.5  christos 
   1168   1.5  christos     /* Examine all elements of the package object, remove matched index */
   1169   1.5  christos 
   1170   1.5  christos     for (i = 0; i < Count; i++)
   1171   1.5  christos     {
   1172   1.5  christos         if (i == Index)
   1173   1.5  christos         {
   1174   1.5  christos             AcpiUtRemoveReference (*Source); /* Remove one ref for being in pkg */
   1175   1.5  christos             AcpiUtRemoveReference (*Source);
   1176   1.5  christos         }
   1177   1.5  christos         else
   1178   1.5  christos         {
   1179   1.5  christos             *Dest = *Source;
   1180   1.5  christos             Dest++;
   1181   1.5  christos         }
   1182   1.9  christos 
   1183   1.5  christos         Source++;
   1184   1.5  christos     }
   1185   1.5  christos 
   1186   1.5  christos     /* NULL terminate list and update the package count */
   1187   1.5  christos 
   1188   1.5  christos     *Dest = NULL;
   1189   1.5  christos     ObjDesc->Package.Count = NewCount;
   1190   1.5  christos }
   1191