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