Home | History | Annotate | Line # | Download | only in namespace
nsrepair2.c revision 1.3
      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.3  jruoho  * Copyright (C) 2000 - 2011, 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 #define __NSREPAIR2_C__
     46  1.1  jruoho 
     47  1.1  jruoho #include "acpi.h"
     48  1.1  jruoho #include "accommon.h"
     49  1.1  jruoho #include "acnamesp.h"
     50  1.1  jruoho 
     51  1.1  jruoho #define _COMPONENT          ACPI_NAMESPACE
     52  1.1  jruoho         ACPI_MODULE_NAME    ("nsrepair2")
     53  1.1  jruoho 
     54  1.1  jruoho 
     55  1.1  jruoho /*
     56  1.1  jruoho  * Information structure and handler for ACPI predefined names that can
     57  1.1  jruoho  * be repaired on a per-name basis.
     58  1.1  jruoho  */
     59  1.1  jruoho typedef
     60  1.1  jruoho ACPI_STATUS (*ACPI_REPAIR_FUNCTION) (
     61  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
     62  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
     63  1.1  jruoho 
     64  1.1  jruoho typedef struct acpi_repair_info
     65  1.1  jruoho {
     66  1.1  jruoho     char                    Name[ACPI_NAME_SIZE];
     67  1.1  jruoho     ACPI_REPAIR_FUNCTION    RepairFunction;
     68  1.1  jruoho 
     69  1.1  jruoho } ACPI_REPAIR_INFO;
     70  1.1  jruoho 
     71  1.1  jruoho 
     72  1.1  jruoho /* Local prototypes */
     73  1.1  jruoho 
     74  1.1  jruoho static const ACPI_REPAIR_INFO *
     75  1.1  jruoho AcpiNsMatchRepairableName (
     76  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node);
     77  1.1  jruoho 
     78  1.1  jruoho static ACPI_STATUS
     79  1.1  jruoho AcpiNsRepair_ALR (
     80  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
     81  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
     82  1.1  jruoho 
     83  1.1  jruoho static ACPI_STATUS
     84  1.3  jruoho AcpiNsRepair_CID (
     85  1.3  jruoho     ACPI_PREDEFINED_DATA    *Data,
     86  1.3  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
     87  1.3  jruoho 
     88  1.3  jruoho static ACPI_STATUS
     89  1.1  jruoho AcpiNsRepair_FDE (
     90  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
     91  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
     92  1.1  jruoho 
     93  1.1  jruoho static ACPI_STATUS
     94  1.3  jruoho AcpiNsRepair_HID (
     95  1.3  jruoho     ACPI_PREDEFINED_DATA    *Data,
     96  1.3  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
     97  1.3  jruoho 
     98  1.3  jruoho static ACPI_STATUS
     99  1.1  jruoho AcpiNsRepair_PSS (
    100  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    101  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    102  1.1  jruoho 
    103  1.1  jruoho static ACPI_STATUS
    104  1.1  jruoho AcpiNsRepair_TSS (
    105  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    106  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr);
    107  1.1  jruoho 
    108  1.1  jruoho static ACPI_STATUS
    109  1.1  jruoho AcpiNsCheckSortedList (
    110  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    111  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject,
    112  1.1  jruoho     UINT32                  ExpectedCount,
    113  1.1  jruoho     UINT32                  SortIndex,
    114  1.1  jruoho     UINT8                   SortDirection,
    115  1.1  jruoho     char                    *SortKeyName);
    116  1.1  jruoho 
    117  1.1  jruoho static void
    118  1.1  jruoho AcpiNsSortList (
    119  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements,
    120  1.1  jruoho     UINT32                  Count,
    121  1.1  jruoho     UINT32                  Index,
    122  1.1  jruoho     UINT8                   SortDirection);
    123  1.1  jruoho 
    124  1.1  jruoho /* Values for SortDirection above */
    125  1.1  jruoho 
    126  1.1  jruoho #define ACPI_SORT_ASCENDING     0
    127  1.1  jruoho #define ACPI_SORT_DESCENDING    1
    128  1.1  jruoho 
    129  1.1  jruoho 
    130  1.1  jruoho /*
    131  1.1  jruoho  * This table contains the names of the predefined methods for which we can
    132  1.1  jruoho  * perform more complex repairs.
    133  1.1  jruoho  *
    134  1.1  jruoho  * As necessary:
    135  1.1  jruoho  *
    136  1.1  jruoho  * _ALR: Sort the list ascending by AmbientIlluminance
    137  1.3  jruoho  * _CID: Strings: uppercase all, remove any leading asterisk
    138  1.1  jruoho  * _FDE: Convert Buffer of BYTEs to a Buffer of DWORDs
    139  1.1  jruoho  * _GTM: Convert Buffer of BYTEs to a Buffer of DWORDs
    140  1.3  jruoho  * _HID: Strings: uppercase all, remove any leading asterisk
    141  1.1  jruoho  * _PSS: Sort the list descending by Power
    142  1.1  jruoho  * _TSS: Sort the list descending by Power
    143  1.1  jruoho  *
    144  1.1  jruoho  * Names that must be packages, but cannot be sorted:
    145  1.1  jruoho  *
    146  1.1  jruoho  * _BCL: Values are tied to the Package index where they appear, and cannot
    147  1.1  jruoho  * be moved or sorted. These index values are used for _BQC and _BCM.
    148  1.1  jruoho  * However, we can fix the case where a buffer is returned, by converting
    149  1.1  jruoho  * it to a Package of integers.
    150  1.1  jruoho  */
    151  1.1  jruoho static const ACPI_REPAIR_INFO       AcpiNsRepairableNames[] =
    152  1.1  jruoho {
    153  1.1  jruoho     {"_ALR", AcpiNsRepair_ALR},
    154  1.3  jruoho     {"_CID", AcpiNsRepair_CID},
    155  1.1  jruoho     {"_FDE", AcpiNsRepair_FDE},
    156  1.1  jruoho     {"_GTM", AcpiNsRepair_FDE},     /* _GTM has same repair as _FDE */
    157  1.3  jruoho     {"_HID", AcpiNsRepair_HID},
    158  1.1  jruoho     {"_PSS", AcpiNsRepair_PSS},
    159  1.1  jruoho     {"_TSS", AcpiNsRepair_TSS},
    160  1.1  jruoho     {{0,0,0,0}, NULL}               /* Table terminator */
    161  1.1  jruoho };
    162  1.1  jruoho 
    163  1.1  jruoho 
    164  1.1  jruoho #define ACPI_FDE_FIELD_COUNT        5
    165  1.1  jruoho #define ACPI_FDE_BYTE_BUFFER_SIZE   5
    166  1.1  jruoho #define ACPI_FDE_DWORD_BUFFER_SIZE  (ACPI_FDE_FIELD_COUNT * sizeof (UINT32))
    167  1.1  jruoho 
    168  1.1  jruoho 
    169  1.1  jruoho /******************************************************************************
    170  1.1  jruoho  *
    171  1.1  jruoho  * FUNCTION:    AcpiNsComplexRepairs
    172  1.1  jruoho  *
    173  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    174  1.1  jruoho  *              Node                - Namespace node for the method/object
    175  1.1  jruoho  *              ValidateStatus      - Original status of earlier validation
    176  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    177  1.1  jruoho  *                                    evaluation of a method or object
    178  1.1  jruoho  *
    179  1.1  jruoho  * RETURN:      Status. AE_OK if repair was successful. If name is not
    180  1.1  jruoho  *              matched, ValidateStatus is returned.
    181  1.1  jruoho  *
    182  1.1  jruoho  * DESCRIPTION: Attempt to repair/convert a return object of a type that was
    183  1.1  jruoho  *              not expected.
    184  1.1  jruoho  *
    185  1.1  jruoho  *****************************************************************************/
    186  1.1  jruoho 
    187  1.1  jruoho ACPI_STATUS
    188  1.1  jruoho AcpiNsComplexRepairs (
    189  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    190  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node,
    191  1.1  jruoho     ACPI_STATUS             ValidateStatus,
    192  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    193  1.1  jruoho {
    194  1.1  jruoho     const ACPI_REPAIR_INFO  *Predefined;
    195  1.1  jruoho     ACPI_STATUS             Status;
    196  1.1  jruoho 
    197  1.1  jruoho 
    198  1.1  jruoho     /* Check if this name is in the list of repairable names */
    199  1.1  jruoho 
    200  1.1  jruoho     Predefined = AcpiNsMatchRepairableName (Node);
    201  1.1  jruoho     if (!Predefined)
    202  1.1  jruoho     {
    203  1.1  jruoho         return (ValidateStatus);
    204  1.1  jruoho     }
    205  1.1  jruoho 
    206  1.1  jruoho     Status = Predefined->RepairFunction (Data, ReturnObjectPtr);
    207  1.1  jruoho     return (Status);
    208  1.1  jruoho }
    209  1.1  jruoho 
    210  1.1  jruoho 
    211  1.1  jruoho /******************************************************************************
    212  1.1  jruoho  *
    213  1.1  jruoho  * FUNCTION:    AcpiNsMatchRepairableName
    214  1.1  jruoho  *
    215  1.1  jruoho  * PARAMETERS:  Node                - Namespace node for the method/object
    216  1.1  jruoho  *
    217  1.1  jruoho  * RETURN:      Pointer to entry in repair table. NULL indicates not found.
    218  1.1  jruoho  *
    219  1.1  jruoho  * DESCRIPTION: Check an object name against the repairable object list.
    220  1.1  jruoho  *
    221  1.1  jruoho  *****************************************************************************/
    222  1.1  jruoho 
    223  1.1  jruoho static const ACPI_REPAIR_INFO *
    224  1.1  jruoho AcpiNsMatchRepairableName (
    225  1.1  jruoho     ACPI_NAMESPACE_NODE     *Node)
    226  1.1  jruoho {
    227  1.1  jruoho     const ACPI_REPAIR_INFO  *ThisName;
    228  1.1  jruoho 
    229  1.1  jruoho 
    230  1.1  jruoho     /* Search info table for a repairable predefined method/object name */
    231  1.1  jruoho 
    232  1.1  jruoho     ThisName = AcpiNsRepairableNames;
    233  1.1  jruoho     while (ThisName->RepairFunction)
    234  1.1  jruoho     {
    235  1.1  jruoho         if (ACPI_COMPARE_NAME (Node->Name.Ascii, ThisName->Name))
    236  1.1  jruoho         {
    237  1.1  jruoho             return (ThisName);
    238  1.1  jruoho         }
    239  1.1  jruoho         ThisName++;
    240  1.1  jruoho     }
    241  1.1  jruoho 
    242  1.1  jruoho     return (NULL); /* Not found */
    243  1.1  jruoho }
    244  1.1  jruoho 
    245  1.1  jruoho 
    246  1.1  jruoho /******************************************************************************
    247  1.1  jruoho  *
    248  1.1  jruoho  * FUNCTION:    AcpiNsRepair_ALR
    249  1.1  jruoho  *
    250  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    251  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    252  1.1  jruoho  *                                    evaluation of a method or object
    253  1.1  jruoho  *
    254  1.1  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    255  1.1  jruoho  *
    256  1.1  jruoho  * DESCRIPTION: Repair for the _ALR object. If necessary, sort the object list
    257  1.1  jruoho  *              ascending by the ambient illuminance values.
    258  1.1  jruoho  *
    259  1.1  jruoho  *****************************************************************************/
    260  1.1  jruoho 
    261  1.1  jruoho static ACPI_STATUS
    262  1.1  jruoho AcpiNsRepair_ALR (
    263  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    264  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    265  1.1  jruoho {
    266  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    267  1.1  jruoho     ACPI_STATUS             Status;
    268  1.1  jruoho 
    269  1.1  jruoho 
    270  1.1  jruoho     Status = AcpiNsCheckSortedList (Data, ReturnObject, 2, 1,
    271  1.2  jruoho 	ACPI_SORT_ASCENDING, __UNCONST("AmbientIlluminance"));
    272  1.1  jruoho 
    273  1.1  jruoho     return (Status);
    274  1.1  jruoho }
    275  1.1  jruoho 
    276  1.1  jruoho 
    277  1.1  jruoho /******************************************************************************
    278  1.1  jruoho  *
    279  1.1  jruoho  * FUNCTION:    AcpiNsRepair_FDE
    280  1.1  jruoho  *
    281  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    282  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    283  1.1  jruoho  *                                    evaluation of a method or object
    284  1.1  jruoho  *
    285  1.1  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    286  1.1  jruoho  *
    287  1.1  jruoho  * DESCRIPTION: Repair for the _FDE and _GTM objects. The expected return
    288  1.1  jruoho  *              value is a Buffer of 5 DWORDs. This function repairs a common
    289  1.1  jruoho  *              problem where the return value is a Buffer of BYTEs, not
    290  1.1  jruoho  *              DWORDs.
    291  1.1  jruoho  *
    292  1.1  jruoho  *****************************************************************************/
    293  1.1  jruoho 
    294  1.1  jruoho static ACPI_STATUS
    295  1.1  jruoho AcpiNsRepair_FDE (
    296  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    297  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    298  1.1  jruoho {
    299  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    300  1.1  jruoho     ACPI_OPERAND_OBJECT     *BufferObject;
    301  1.1  jruoho     UINT8                   *ByteBuffer;
    302  1.1  jruoho     UINT32                  *DwordBuffer;
    303  1.1  jruoho     UINT32                  i;
    304  1.1  jruoho 
    305  1.1  jruoho 
    306  1.1  jruoho     ACPI_FUNCTION_NAME (NsRepair_FDE);
    307  1.1  jruoho 
    308  1.1  jruoho 
    309  1.1  jruoho     switch (ReturnObject->Common.Type)
    310  1.1  jruoho     {
    311  1.1  jruoho     case ACPI_TYPE_BUFFER:
    312  1.1  jruoho 
    313  1.1  jruoho         /* This is the expected type. Length should be (at least) 5 DWORDs */
    314  1.1  jruoho 
    315  1.1  jruoho         if (ReturnObject->Buffer.Length >= ACPI_FDE_DWORD_BUFFER_SIZE)
    316  1.1  jruoho         {
    317  1.1  jruoho             return (AE_OK);
    318  1.1  jruoho         }
    319  1.1  jruoho 
    320  1.1  jruoho         /* We can only repair if we have exactly 5 BYTEs */
    321  1.1  jruoho 
    322  1.1  jruoho         if (ReturnObject->Buffer.Length != ACPI_FDE_BYTE_BUFFER_SIZE)
    323  1.1  jruoho         {
    324  1.1  jruoho             ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
    325  1.1  jruoho                 "Incorrect return buffer length %u, expected %u",
    326  1.1  jruoho                 ReturnObject->Buffer.Length, ACPI_FDE_DWORD_BUFFER_SIZE));
    327  1.1  jruoho 
    328  1.1  jruoho             return (AE_AML_OPERAND_TYPE);
    329  1.1  jruoho         }
    330  1.1  jruoho 
    331  1.1  jruoho         /* Create the new (larger) buffer object */
    332  1.1  jruoho 
    333  1.1  jruoho         BufferObject = AcpiUtCreateBufferObject (ACPI_FDE_DWORD_BUFFER_SIZE);
    334  1.1  jruoho         if (!BufferObject)
    335  1.1  jruoho         {
    336  1.1  jruoho             return (AE_NO_MEMORY);
    337  1.1  jruoho         }
    338  1.1  jruoho 
    339  1.1  jruoho         /* Expand each byte to a DWORD */
    340  1.1  jruoho 
    341  1.1  jruoho         ByteBuffer = ReturnObject->Buffer.Pointer;
    342  1.1  jruoho         DwordBuffer = ACPI_CAST_PTR (UINT32, BufferObject->Buffer.Pointer);
    343  1.1  jruoho 
    344  1.1  jruoho         for (i = 0; i < ACPI_FDE_FIELD_COUNT; i++)
    345  1.1  jruoho         {
    346  1.1  jruoho             *DwordBuffer = (UINT32) *ByteBuffer;
    347  1.1  jruoho             DwordBuffer++;
    348  1.1  jruoho             ByteBuffer++;
    349  1.1  jruoho         }
    350  1.1  jruoho 
    351  1.1  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    352  1.1  jruoho             "%s Expanded Byte Buffer to expected DWord Buffer\n",
    353  1.1  jruoho             Data->Pathname));
    354  1.1  jruoho         break;
    355  1.1  jruoho 
    356  1.1  jruoho     default:
    357  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    358  1.1  jruoho     }
    359  1.1  jruoho 
    360  1.1  jruoho     /* Delete the original return object, return the new buffer object */
    361  1.1  jruoho 
    362  1.1  jruoho     AcpiUtRemoveReference (ReturnObject);
    363  1.1  jruoho     *ReturnObjectPtr = BufferObject;
    364  1.1  jruoho 
    365  1.1  jruoho     Data->Flags |= ACPI_OBJECT_REPAIRED;
    366  1.1  jruoho     return (AE_OK);
    367  1.1  jruoho }
    368  1.1  jruoho 
    369  1.1  jruoho 
    370  1.1  jruoho /******************************************************************************
    371  1.1  jruoho  *
    372  1.3  jruoho  * FUNCTION:    AcpiNsRepair_CID
    373  1.3  jruoho  *
    374  1.3  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    375  1.3  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    376  1.3  jruoho  *                                    evaluation of a method or object
    377  1.3  jruoho  *
    378  1.3  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    379  1.3  jruoho  *
    380  1.3  jruoho  * DESCRIPTION: Repair for the _CID object. If a string, ensure that all
    381  1.3  jruoho  *              letters are uppercase and that there is no leading asterisk.
    382  1.3  jruoho  *              If a Package, ensure same for all string elements.
    383  1.3  jruoho  *
    384  1.3  jruoho  *****************************************************************************/
    385  1.3  jruoho 
    386  1.3  jruoho static ACPI_STATUS
    387  1.3  jruoho AcpiNsRepair_CID (
    388  1.3  jruoho     ACPI_PREDEFINED_DATA    *Data,
    389  1.3  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    390  1.3  jruoho {
    391  1.3  jruoho     ACPI_STATUS             Status;
    392  1.3  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    393  1.3  jruoho     ACPI_OPERAND_OBJECT     **ElementPtr;
    394  1.3  jruoho     ACPI_OPERAND_OBJECT     *OriginalElement;
    395  1.3  jruoho     UINT16                  OriginalRefCount;
    396  1.3  jruoho     UINT32                  i;
    397  1.3  jruoho 
    398  1.3  jruoho 
    399  1.3  jruoho     /* Check for _CID as a simple string */
    400  1.3  jruoho 
    401  1.3  jruoho     if (ReturnObject->Common.Type == ACPI_TYPE_STRING)
    402  1.3  jruoho     {
    403  1.3  jruoho         Status = AcpiNsRepair_HID (Data, ReturnObjectPtr);
    404  1.3  jruoho         return (Status);
    405  1.3  jruoho     }
    406  1.3  jruoho 
    407  1.3  jruoho     /* Exit if not a Package */
    408  1.3  jruoho 
    409  1.3  jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
    410  1.3  jruoho     {
    411  1.3  jruoho         return (AE_OK);
    412  1.3  jruoho     }
    413  1.3  jruoho 
    414  1.3  jruoho     /* Examine each element of the _CID package */
    415  1.3  jruoho 
    416  1.3  jruoho     ElementPtr = ReturnObject->Package.Elements;
    417  1.3  jruoho     for (i = 0; i < ReturnObject->Package.Count; i++)
    418  1.3  jruoho     {
    419  1.3  jruoho         OriginalElement = *ElementPtr;
    420  1.3  jruoho         OriginalRefCount = OriginalElement->Common.ReferenceCount;
    421  1.3  jruoho 
    422  1.3  jruoho         Status = AcpiNsRepair_HID (Data, ElementPtr);
    423  1.3  jruoho         if (ACPI_FAILURE (Status))
    424  1.3  jruoho         {
    425  1.3  jruoho             return (Status);
    426  1.3  jruoho         }
    427  1.3  jruoho 
    428  1.3  jruoho         /* Take care with reference counts */
    429  1.3  jruoho 
    430  1.3  jruoho         if (OriginalElement != *ElementPtr)
    431  1.3  jruoho         {
    432  1.3  jruoho             /* Element was replaced */
    433  1.3  jruoho 
    434  1.3  jruoho             (*ElementPtr)->Common.ReferenceCount =
    435  1.3  jruoho                 OriginalRefCount;
    436  1.3  jruoho 
    437  1.3  jruoho             AcpiUtRemoveReference (OriginalElement);
    438  1.3  jruoho         }
    439  1.3  jruoho 
    440  1.3  jruoho         ElementPtr++;
    441  1.3  jruoho     }
    442  1.3  jruoho 
    443  1.3  jruoho     return (AE_OK);
    444  1.3  jruoho }
    445  1.3  jruoho 
    446  1.3  jruoho 
    447  1.3  jruoho /******************************************************************************
    448  1.3  jruoho  *
    449  1.3  jruoho  * FUNCTION:    AcpiNsRepair_HID
    450  1.3  jruoho  *
    451  1.3  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    452  1.3  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    453  1.3  jruoho  *                                    evaluation of a method or object
    454  1.3  jruoho  *
    455  1.3  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    456  1.3  jruoho  *
    457  1.3  jruoho  * DESCRIPTION: Repair for the _HID object. If a string, ensure that all
    458  1.3  jruoho  *              letters are uppercase and that there is no leading asterisk.
    459  1.3  jruoho  *
    460  1.3  jruoho  *****************************************************************************/
    461  1.3  jruoho 
    462  1.3  jruoho static ACPI_STATUS
    463  1.3  jruoho AcpiNsRepair_HID (
    464  1.3  jruoho     ACPI_PREDEFINED_DATA    *Data,
    465  1.3  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    466  1.3  jruoho {
    467  1.3  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    468  1.3  jruoho     ACPI_OPERAND_OBJECT     *NewString;
    469  1.3  jruoho     char                    *Source;
    470  1.3  jruoho     char                    *Dest;
    471  1.3  jruoho 
    472  1.3  jruoho 
    473  1.3  jruoho     ACPI_FUNCTION_NAME (NsRepair_HID);
    474  1.3  jruoho 
    475  1.3  jruoho 
    476  1.3  jruoho     /* We only care about string _HID objects (not integers) */
    477  1.3  jruoho 
    478  1.3  jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_STRING)
    479  1.3  jruoho     {
    480  1.3  jruoho         return (AE_OK);
    481  1.3  jruoho     }
    482  1.3  jruoho 
    483  1.3  jruoho     if (ReturnObject->String.Length == 0)
    484  1.3  jruoho     {
    485  1.3  jruoho         ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
    486  1.3  jruoho             "Invalid zero-length _HID or _CID string"));
    487  1.3  jruoho 
    488  1.3  jruoho         /* Return AE_OK anyway, let driver handle it */
    489  1.3  jruoho 
    490  1.3  jruoho         Data->Flags |= ACPI_OBJECT_REPAIRED;
    491  1.3  jruoho         return (AE_OK);
    492  1.3  jruoho     }
    493  1.3  jruoho 
    494  1.3  jruoho     /* It is simplest to always create a new string object */
    495  1.3  jruoho 
    496  1.3  jruoho     NewString = AcpiUtCreateStringObject (ReturnObject->String.Length);
    497  1.3  jruoho     if (!NewString)
    498  1.3  jruoho     {
    499  1.3  jruoho         return (AE_NO_MEMORY);
    500  1.3  jruoho     }
    501  1.3  jruoho 
    502  1.3  jruoho     /*
    503  1.3  jruoho      * Remove a leading asterisk if present. For some unknown reason, there
    504  1.3  jruoho      * are many machines in the field that contains IDs like this.
    505  1.3  jruoho      *
    506  1.3  jruoho      * Examples: "*PNP0C03", "*ACPI0003"
    507  1.3  jruoho      */
    508  1.3  jruoho     Source = ReturnObject->String.Pointer;
    509  1.3  jruoho     if (*Source == '*')
    510  1.3  jruoho     {
    511  1.3  jruoho         Source++;
    512  1.3  jruoho         NewString->String.Length--;
    513  1.3  jruoho 
    514  1.3  jruoho         ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    515  1.3  jruoho             "%s: Removed invalid leading asterisk\n", Data->Pathname));
    516  1.3  jruoho     }
    517  1.3  jruoho 
    518  1.3  jruoho     /*
    519  1.3  jruoho      * Copy and uppercase the string. From the ACPI specification:
    520  1.3  jruoho      *
    521  1.3  jruoho      * A valid PNP ID must be of the form "AAA####" where A is an uppercase
    522  1.3  jruoho      * letter and # is a hex digit. A valid ACPI ID must be of the form
    523  1.3  jruoho      * "ACPI####" where # is a hex digit.
    524  1.3  jruoho      */
    525  1.3  jruoho     for (Dest = NewString->String.Pointer; *Source; Dest++, Source++)
    526  1.3  jruoho     {
    527  1.3  jruoho         *Dest = (char) ACPI_TOUPPER (*Source);
    528  1.3  jruoho     }
    529  1.3  jruoho 
    530  1.3  jruoho     AcpiUtRemoveReference (ReturnObject);
    531  1.3  jruoho     *ReturnObjectPtr = NewString;
    532  1.3  jruoho     return (AE_OK);
    533  1.3  jruoho }
    534  1.3  jruoho 
    535  1.3  jruoho 
    536  1.3  jruoho /******************************************************************************
    537  1.3  jruoho  *
    538  1.1  jruoho  * FUNCTION:    AcpiNsRepair_TSS
    539  1.1  jruoho  *
    540  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    541  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    542  1.1  jruoho  *                                    evaluation of a method or object
    543  1.1  jruoho  *
    544  1.1  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    545  1.1  jruoho  *
    546  1.1  jruoho  * DESCRIPTION: Repair for the _TSS object. If necessary, sort the object list
    547  1.1  jruoho  *              descending by the power dissipation values.
    548  1.1  jruoho  *
    549  1.1  jruoho  *****************************************************************************/
    550  1.1  jruoho 
    551  1.1  jruoho static ACPI_STATUS
    552  1.1  jruoho AcpiNsRepair_TSS (
    553  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    554  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    555  1.1  jruoho {
    556  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    557  1.1  jruoho     ACPI_STATUS             Status;
    558  1.1  jruoho 
    559  1.1  jruoho 
    560  1.1  jruoho     Status = AcpiNsCheckSortedList (Data, ReturnObject, 5, 1,
    561  1.2  jruoho 	ACPI_SORT_DESCENDING, __UNCONST("PowerDissipation"));
    562  1.1  jruoho 
    563  1.1  jruoho     return (Status);
    564  1.1  jruoho }
    565  1.1  jruoho 
    566  1.1  jruoho 
    567  1.1  jruoho /******************************************************************************
    568  1.1  jruoho  *
    569  1.1  jruoho  * FUNCTION:    AcpiNsRepair_PSS
    570  1.1  jruoho  *
    571  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    572  1.1  jruoho  *              ReturnObjectPtr     - Pointer to the object returned from the
    573  1.1  jruoho  *                                    evaluation of a method or object
    574  1.1  jruoho  *
    575  1.1  jruoho  * RETURN:      Status. AE_OK if object is OK or was repaired successfully
    576  1.1  jruoho  *
    577  1.1  jruoho  * DESCRIPTION: Repair for the _PSS object. If necessary, sort the object list
    578  1.1  jruoho  *              by the CPU frequencies. Check that the power dissipation values
    579  1.1  jruoho  *              are all proportional to CPU frequency (i.e., sorting by
    580  1.1  jruoho  *              frequency should be the same as sorting by power.)
    581  1.1  jruoho  *
    582  1.1  jruoho  *****************************************************************************/
    583  1.1  jruoho 
    584  1.1  jruoho static ACPI_STATUS
    585  1.1  jruoho AcpiNsRepair_PSS (
    586  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    587  1.1  jruoho     ACPI_OPERAND_OBJECT     **ReturnObjectPtr)
    588  1.1  jruoho {
    589  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject = *ReturnObjectPtr;
    590  1.1  jruoho     ACPI_OPERAND_OBJECT     **OuterElements;
    591  1.1  jruoho     UINT32                  OuterElementCount;
    592  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements;
    593  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    594  1.1  jruoho     UINT32                  PreviousValue;
    595  1.1  jruoho     ACPI_STATUS             Status;
    596  1.1  jruoho     UINT32                  i;
    597  1.1  jruoho 
    598  1.1  jruoho 
    599  1.1  jruoho     /*
    600  1.1  jruoho      * Entries (sub-packages) in the _PSS Package must be sorted by power
    601  1.1  jruoho      * dissipation, in descending order. If it appears that the list is
    602  1.1  jruoho      * incorrectly sorted, sort it. We sort by CpuFrequency, since this
    603  1.1  jruoho      * should be proportional to the power.
    604  1.1  jruoho      */
    605  1.1  jruoho     Status =AcpiNsCheckSortedList (Data, ReturnObject, 6, 0,
    606  1.2  jruoho 	ACPI_SORT_DESCENDING, __UNCONST("CpuFrequency"));
    607  1.1  jruoho     if (ACPI_FAILURE (Status))
    608  1.1  jruoho     {
    609  1.1  jruoho         return (Status);
    610  1.1  jruoho     }
    611  1.1  jruoho 
    612  1.1  jruoho     /*
    613  1.1  jruoho      * We now know the list is correctly sorted by CPU frequency. Check if
    614  1.1  jruoho      * the power dissipation values are proportional.
    615  1.1  jruoho      */
    616  1.1  jruoho     PreviousValue = ACPI_UINT32_MAX;
    617  1.1  jruoho     OuterElements = ReturnObject->Package.Elements;
    618  1.1  jruoho     OuterElementCount = ReturnObject->Package.Count;
    619  1.1  jruoho 
    620  1.1  jruoho     for (i = 0; i < OuterElementCount; i++)
    621  1.1  jruoho     {
    622  1.1  jruoho         Elements = (*OuterElements)->Package.Elements;
    623  1.1  jruoho         ObjDesc = Elements[1]; /* Index1 = PowerDissipation */
    624  1.1  jruoho 
    625  1.1  jruoho         if ((UINT32) ObjDesc->Integer.Value > PreviousValue)
    626  1.1  jruoho         {
    627  1.1  jruoho             ACPI_WARN_PREDEFINED ((AE_INFO, Data->Pathname, Data->NodeFlags,
    628  1.1  jruoho                 "SubPackage[%u,%u] - suspicious power dissipation values",
    629  1.1  jruoho                 i-1, i));
    630  1.1  jruoho         }
    631  1.1  jruoho 
    632  1.1  jruoho         PreviousValue = (UINT32) ObjDesc->Integer.Value;
    633  1.1  jruoho         OuterElements++;
    634  1.1  jruoho     }
    635  1.1  jruoho 
    636  1.1  jruoho     return (AE_OK);
    637  1.1  jruoho }
    638  1.1  jruoho 
    639  1.1  jruoho 
    640  1.1  jruoho /******************************************************************************
    641  1.1  jruoho  *
    642  1.1  jruoho  * FUNCTION:    AcpiNsCheckSortedList
    643  1.1  jruoho  *
    644  1.1  jruoho  * PARAMETERS:  Data                - Pointer to validation data structure
    645  1.1  jruoho  *              ReturnObject        - Pointer to the top-level returned object
    646  1.1  jruoho  *              ExpectedCount       - Minimum length of each sub-package
    647  1.1  jruoho  *              SortIndex           - Sub-package entry to sort on
    648  1.1  jruoho  *              SortDirection       - Ascending or descending
    649  1.1  jruoho  *              SortKeyName         - Name of the SortIndex field
    650  1.1  jruoho  *
    651  1.1  jruoho  * RETURN:      Status. AE_OK if the list is valid and is sorted correctly or
    652  1.1  jruoho  *              has been repaired by sorting the list.
    653  1.1  jruoho  *
    654  1.1  jruoho  * DESCRIPTION: Check if the package list is valid and sorted correctly by the
    655  1.1  jruoho  *              SortIndex. If not, then sort the list.
    656  1.1  jruoho  *
    657  1.1  jruoho  *****************************************************************************/
    658  1.1  jruoho 
    659  1.1  jruoho static ACPI_STATUS
    660  1.1  jruoho AcpiNsCheckSortedList (
    661  1.1  jruoho     ACPI_PREDEFINED_DATA    *Data,
    662  1.1  jruoho     ACPI_OPERAND_OBJECT     *ReturnObject,
    663  1.1  jruoho     UINT32                  ExpectedCount,
    664  1.1  jruoho     UINT32                  SortIndex,
    665  1.1  jruoho     UINT8                   SortDirection,
    666  1.1  jruoho     char                    *SortKeyName)
    667  1.1  jruoho {
    668  1.1  jruoho     UINT32                  OuterElementCount;
    669  1.1  jruoho     ACPI_OPERAND_OBJECT     **OuterElements;
    670  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements;
    671  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    672  1.1  jruoho     UINT32                  i;
    673  1.1  jruoho     UINT32                  PreviousValue;
    674  1.1  jruoho 
    675  1.1  jruoho 
    676  1.1  jruoho     ACPI_FUNCTION_NAME (NsCheckSortedList);
    677  1.1  jruoho 
    678  1.1  jruoho 
    679  1.1  jruoho     /* The top-level object must be a package */
    680  1.1  jruoho 
    681  1.1  jruoho     if (ReturnObject->Common.Type != ACPI_TYPE_PACKAGE)
    682  1.1  jruoho     {
    683  1.1  jruoho         return (AE_AML_OPERAND_TYPE);
    684  1.1  jruoho     }
    685  1.1  jruoho 
    686  1.1  jruoho     /*
    687  1.1  jruoho      * NOTE: assumes list of sub-packages contains no NULL elements.
    688  1.1  jruoho      * Any NULL elements should have been removed by earlier call
    689  1.1  jruoho      * to AcpiNsRemoveNullElements.
    690  1.1  jruoho      */
    691  1.1  jruoho     OuterElements = ReturnObject->Package.Elements;
    692  1.1  jruoho     OuterElementCount = ReturnObject->Package.Count;
    693  1.1  jruoho     if (!OuterElementCount)
    694  1.1  jruoho     {
    695  1.1  jruoho         return (AE_AML_PACKAGE_LIMIT);
    696  1.1  jruoho     }
    697  1.1  jruoho 
    698  1.1  jruoho     PreviousValue = 0;
    699  1.1  jruoho     if (SortDirection == ACPI_SORT_DESCENDING)
    700  1.1  jruoho     {
    701  1.1  jruoho         PreviousValue = ACPI_UINT32_MAX;
    702  1.1  jruoho     }
    703  1.1  jruoho 
    704  1.1  jruoho     /* Examine each subpackage */
    705  1.1  jruoho 
    706  1.1  jruoho     for (i = 0; i < OuterElementCount; i++)
    707  1.1  jruoho     {
    708  1.1  jruoho         /* Each element of the top-level package must also be a package */
    709  1.1  jruoho 
    710  1.1  jruoho         if ((*OuterElements)->Common.Type != ACPI_TYPE_PACKAGE)
    711  1.1  jruoho         {
    712  1.1  jruoho             return (AE_AML_OPERAND_TYPE);
    713  1.1  jruoho         }
    714  1.1  jruoho 
    715  1.1  jruoho         /* Each sub-package must have the minimum length */
    716  1.1  jruoho 
    717  1.1  jruoho         if ((*OuterElements)->Package.Count < ExpectedCount)
    718  1.1  jruoho         {
    719  1.1  jruoho             return (AE_AML_PACKAGE_LIMIT);
    720  1.1  jruoho         }
    721  1.1  jruoho 
    722  1.1  jruoho         Elements = (*OuterElements)->Package.Elements;
    723  1.1  jruoho         ObjDesc = Elements[SortIndex];
    724  1.1  jruoho 
    725  1.1  jruoho         if (ObjDesc->Common.Type != ACPI_TYPE_INTEGER)
    726  1.1  jruoho         {
    727  1.1  jruoho             return (AE_AML_OPERAND_TYPE);
    728  1.1  jruoho         }
    729  1.1  jruoho 
    730  1.1  jruoho         /*
    731  1.1  jruoho          * The list must be sorted in the specified order. If we detect a
    732  1.1  jruoho          * discrepancy, sort the entire list.
    733  1.1  jruoho          */
    734  1.1  jruoho         if (((SortDirection == ACPI_SORT_ASCENDING) &&
    735  1.1  jruoho                 (ObjDesc->Integer.Value < PreviousValue)) ||
    736  1.1  jruoho             ((SortDirection == ACPI_SORT_DESCENDING) &&
    737  1.1  jruoho                 (ObjDesc->Integer.Value > PreviousValue)))
    738  1.1  jruoho         {
    739  1.1  jruoho             AcpiNsSortList (ReturnObject->Package.Elements,
    740  1.1  jruoho                 OuterElementCount, SortIndex, SortDirection);
    741  1.1  jruoho 
    742  1.1  jruoho             Data->Flags |= ACPI_OBJECT_REPAIRED;
    743  1.1  jruoho 
    744  1.1  jruoho             ACPI_DEBUG_PRINT ((ACPI_DB_REPAIR,
    745  1.1  jruoho                 "%s: Repaired unsorted list - now sorted by %s\n",
    746  1.1  jruoho                 Data->Pathname, SortKeyName));
    747  1.1  jruoho             return (AE_OK);
    748  1.1  jruoho         }
    749  1.1  jruoho 
    750  1.1  jruoho         PreviousValue = (UINT32) ObjDesc->Integer.Value;
    751  1.1  jruoho         OuterElements++;
    752  1.1  jruoho     }
    753  1.1  jruoho 
    754  1.1  jruoho     return (AE_OK);
    755  1.1  jruoho }
    756  1.1  jruoho 
    757  1.1  jruoho 
    758  1.1  jruoho /******************************************************************************
    759  1.1  jruoho  *
    760  1.1  jruoho  * FUNCTION:    AcpiNsSortList
    761  1.1  jruoho  *
    762  1.1  jruoho  * PARAMETERS:  Elements            - Package object element list
    763  1.1  jruoho  *              Count               - Element count for above
    764  1.1  jruoho  *              Index               - Sort by which package element
    765  1.1  jruoho  *              SortDirection       - Ascending or Descending sort
    766  1.1  jruoho  *
    767  1.1  jruoho  * RETURN:      None
    768  1.1  jruoho  *
    769  1.1  jruoho  * DESCRIPTION: Sort the objects that are in a package element list.
    770  1.1  jruoho  *
    771  1.1  jruoho  * NOTE: Assumes that all NULL elements have been removed from the package,
    772  1.1  jruoho  *       and that all elements have been verified to be of type Integer.
    773  1.1  jruoho  *
    774  1.1  jruoho  *****************************************************************************/
    775  1.1  jruoho 
    776  1.1  jruoho static void
    777  1.1  jruoho AcpiNsSortList (
    778  1.1  jruoho     ACPI_OPERAND_OBJECT     **Elements,
    779  1.1  jruoho     UINT32                  Count,
    780  1.1  jruoho     UINT32                  Index,
    781  1.1  jruoho     UINT8                   SortDirection)
    782  1.1  jruoho {
    783  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc1;
    784  1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc2;
    785  1.1  jruoho     ACPI_OPERAND_OBJECT     *TempObj;
    786  1.1  jruoho     UINT32                  i;
    787  1.1  jruoho     UINT32                  j;
    788  1.1  jruoho 
    789  1.1  jruoho 
    790  1.1  jruoho     /* Simple bubble sort */
    791  1.1  jruoho 
    792  1.1  jruoho     for (i = 1; i < Count; i++)
    793  1.1  jruoho     {
    794  1.1  jruoho         for (j = (Count - 1); j >= i; j--)
    795  1.1  jruoho         {
    796  1.1  jruoho             ObjDesc1 = Elements[j-1]->Package.Elements[Index];
    797  1.1  jruoho             ObjDesc2 = Elements[j]->Package.Elements[Index];
    798  1.1  jruoho 
    799  1.1  jruoho             if (((SortDirection == ACPI_SORT_ASCENDING) &&
    800  1.1  jruoho                     (ObjDesc1->Integer.Value > ObjDesc2->Integer.Value)) ||
    801  1.1  jruoho 
    802  1.1  jruoho                 ((SortDirection == ACPI_SORT_DESCENDING) &&
    803  1.1  jruoho                     (ObjDesc1->Integer.Value < ObjDesc2->Integer.Value)))
    804  1.1  jruoho             {
    805  1.1  jruoho                 TempObj = Elements[j-1];
    806  1.1  jruoho                 Elements[j-1] = Elements[j];
    807  1.1  jruoho                 Elements[j] = TempObj;
    808  1.1  jruoho             }
    809  1.1  jruoho         }
    810  1.1  jruoho     }
    811  1.1  jruoho }
    812