Home | History | Annotate | Line # | Download | only in utilities
utids.c revision 1.1.1.6
      1      1.1    jruoho /******************************************************************************
      2      1.1    jruoho  *
      3  1.1.1.6  christos  * Module Name: utids - support for device IDs - HID, UID, CID, SUB, CLS
      4      1.1    jruoho  *
      5      1.1    jruoho  *****************************************************************************/
      6      1.1    jruoho 
      7  1.1.1.2    jruoho /*
      8  1.1.1.5  christos  * Copyright (C) 2000 - 2015, Intel Corp.
      9      1.1    jruoho  * All rights reserved.
     10      1.1    jruoho  *
     11  1.1.1.2    jruoho  * Redistribution and use in source and binary forms, with or without
     12  1.1.1.2    jruoho  * modification, are permitted provided that the following conditions
     13  1.1.1.2    jruoho  * are met:
     14  1.1.1.2    jruoho  * 1. Redistributions of source code must retain the above copyright
     15  1.1.1.2    jruoho  *    notice, this list of conditions, and the following disclaimer,
     16  1.1.1.2    jruoho  *    without modification.
     17  1.1.1.2    jruoho  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
     18  1.1.1.2    jruoho  *    substantially similar to the "NO WARRANTY" disclaimer below
     19  1.1.1.2    jruoho  *    ("Disclaimer") and any redistribution must be conditioned upon
     20  1.1.1.2    jruoho  *    including a substantially similar Disclaimer requirement for further
     21  1.1.1.2    jruoho  *    binary redistribution.
     22  1.1.1.2    jruoho  * 3. Neither the names of the above-listed copyright holders nor the names
     23  1.1.1.2    jruoho  *    of any contributors may be used to endorse or promote products derived
     24  1.1.1.2    jruoho  *    from this software without specific prior written permission.
     25  1.1.1.2    jruoho  *
     26  1.1.1.2    jruoho  * Alternatively, this software may be distributed under the terms of the
     27  1.1.1.2    jruoho  * GNU General Public License ("GPL") version 2 as published by the Free
     28  1.1.1.2    jruoho  * Software Foundation.
     29  1.1.1.2    jruoho  *
     30  1.1.1.2    jruoho  * NO WARRANTY
     31  1.1.1.2    jruoho  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
     32  1.1.1.2    jruoho  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
     33  1.1.1.2    jruoho  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
     34  1.1.1.2    jruoho  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
     35  1.1.1.2    jruoho  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     36  1.1.1.2    jruoho  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     37  1.1.1.2    jruoho  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     38  1.1.1.2    jruoho  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
     39  1.1.1.2    jruoho  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
     40  1.1.1.2    jruoho  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     41  1.1.1.2    jruoho  * POSSIBILITY OF SUCH DAMAGES.
     42  1.1.1.2    jruoho  */
     43      1.1    jruoho 
     44      1.1    jruoho #include "acpi.h"
     45      1.1    jruoho #include "accommon.h"
     46      1.1    jruoho #include "acinterp.h"
     47      1.1    jruoho 
     48      1.1    jruoho 
     49      1.1    jruoho #define _COMPONENT          ACPI_UTILITIES
     50      1.1    jruoho         ACPI_MODULE_NAME    ("utids")
     51      1.1    jruoho 
     52      1.1    jruoho 
     53      1.1    jruoho /*******************************************************************************
     54      1.1    jruoho  *
     55      1.1    jruoho  * FUNCTION:    AcpiUtExecute_HID
     56      1.1    jruoho  *
     57      1.1    jruoho  * PARAMETERS:  DeviceNode          - Node for the device
     58      1.1    jruoho  *              ReturnId            - Where the string HID is returned
     59      1.1    jruoho  *
     60      1.1    jruoho  * RETURN:      Status
     61      1.1    jruoho  *
     62      1.1    jruoho  * DESCRIPTION: Executes the _HID control method that returns the hardware
     63      1.1    jruoho  *              ID of the device. The HID is either an 32-bit encoded EISAID
     64      1.1    jruoho  *              Integer or a String. A string is always returned. An EISAID
     65      1.1    jruoho  *              is converted to a string.
     66      1.1    jruoho  *
     67      1.1    jruoho  *              NOTE: Internal function, no parameter validation
     68      1.1    jruoho  *
     69      1.1    jruoho  ******************************************************************************/
     70      1.1    jruoho 
     71      1.1    jruoho ACPI_STATUS
     72      1.1    jruoho AcpiUtExecute_HID (
     73      1.1    jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
     74  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      **ReturnId)
     75      1.1    jruoho {
     76      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
     77  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      *Hid;
     78      1.1    jruoho     UINT32                  Length;
     79      1.1    jruoho     ACPI_STATUS             Status;
     80      1.1    jruoho 
     81      1.1    jruoho 
     82      1.1    jruoho     ACPI_FUNCTION_TRACE (UtExecute_HID);
     83      1.1    jruoho 
     84      1.1    jruoho 
     85      1.1    jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
     86      1.1    jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
     87      1.1    jruoho     if (ACPI_FAILURE (Status))
     88      1.1    jruoho     {
     89      1.1    jruoho         return_ACPI_STATUS (Status);
     90      1.1    jruoho     }
     91      1.1    jruoho 
     92      1.1    jruoho     /* Get the size of the String to be returned, includes null terminator */
     93      1.1    jruoho 
     94      1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
     95      1.1    jruoho     {
     96      1.1    jruoho         Length = ACPI_EISAID_STRING_SIZE;
     97      1.1    jruoho     }
     98      1.1    jruoho     else
     99      1.1    jruoho     {
    100      1.1    jruoho         Length = ObjDesc->String.Length + 1;
    101      1.1    jruoho     }
    102      1.1    jruoho 
    103      1.1    jruoho     /* Allocate a buffer for the HID */
    104      1.1    jruoho 
    105  1.1.1.3  christos     Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
    106      1.1    jruoho     if (!Hid)
    107      1.1    jruoho     {
    108      1.1    jruoho         Status = AE_NO_MEMORY;
    109      1.1    jruoho         goto Cleanup;
    110      1.1    jruoho     }
    111      1.1    jruoho 
    112  1.1.1.3  christos     /* Area for the string starts after PNP_DEVICE_ID struct */
    113      1.1    jruoho 
    114  1.1.1.3  christos     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_PNP_DEVICE_ID));
    115      1.1    jruoho 
    116      1.1    jruoho     /* Convert EISAID to a string or simply copy existing string */
    117      1.1    jruoho 
    118      1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    119      1.1    jruoho     {
    120      1.1    jruoho         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
    121      1.1    jruoho     }
    122      1.1    jruoho     else
    123      1.1    jruoho     {
    124  1.1.1.6  christos         strcpy (Hid->String, ObjDesc->String.Pointer);
    125      1.1    jruoho     }
    126      1.1    jruoho 
    127      1.1    jruoho     Hid->Length = Length;
    128      1.1    jruoho     *ReturnId = Hid;
    129      1.1    jruoho 
    130      1.1    jruoho 
    131      1.1    jruoho Cleanup:
    132      1.1    jruoho 
    133      1.1    jruoho     /* On exit, we must delete the return object */
    134      1.1    jruoho 
    135      1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    136      1.1    jruoho     return_ACPI_STATUS (Status);
    137      1.1    jruoho }
    138      1.1    jruoho 
    139      1.1    jruoho 
    140      1.1    jruoho /*******************************************************************************
    141      1.1    jruoho  *
    142  1.1.1.3  christos  * FUNCTION:    AcpiUtExecute_SUB
    143  1.1.1.3  christos  *
    144  1.1.1.3  christos  * PARAMETERS:  DeviceNode          - Node for the device
    145  1.1.1.3  christos  *              ReturnId            - Where the _SUB is returned
    146  1.1.1.3  christos  *
    147  1.1.1.3  christos  * RETURN:      Status
    148  1.1.1.3  christos  *
    149  1.1.1.3  christos  * DESCRIPTION: Executes the _SUB control method that returns the subsystem
    150  1.1.1.3  christos  *              ID of the device. The _SUB value is always a string containing
    151  1.1.1.3  christos  *              either a valid PNP or ACPI ID.
    152  1.1.1.3  christos  *
    153  1.1.1.3  christos  *              NOTE: Internal function, no parameter validation
    154  1.1.1.3  christos  *
    155  1.1.1.3  christos  ******************************************************************************/
    156  1.1.1.3  christos 
    157  1.1.1.3  christos ACPI_STATUS
    158  1.1.1.3  christos AcpiUtExecute_SUB (
    159  1.1.1.3  christos     ACPI_NAMESPACE_NODE     *DeviceNode,
    160  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      **ReturnId)
    161  1.1.1.3  christos {
    162  1.1.1.3  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    163  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      *Sub;
    164  1.1.1.3  christos     UINT32                  Length;
    165  1.1.1.3  christos     ACPI_STATUS             Status;
    166  1.1.1.3  christos 
    167  1.1.1.3  christos 
    168  1.1.1.3  christos     ACPI_FUNCTION_TRACE (UtExecute_SUB);
    169  1.1.1.3  christos 
    170  1.1.1.3  christos 
    171  1.1.1.3  christos     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__SUB,
    172  1.1.1.3  christos                 ACPI_BTYPE_STRING, &ObjDesc);
    173  1.1.1.3  christos     if (ACPI_FAILURE (Status))
    174  1.1.1.3  christos     {
    175  1.1.1.3  christos         return_ACPI_STATUS (Status);
    176  1.1.1.3  christos     }
    177  1.1.1.3  christos 
    178  1.1.1.3  christos     /* Get the size of the String to be returned, includes null terminator */
    179  1.1.1.3  christos 
    180  1.1.1.3  christos     Length = ObjDesc->String.Length + 1;
    181  1.1.1.3  christos 
    182  1.1.1.3  christos     /* Allocate a buffer for the SUB */
    183  1.1.1.3  christos 
    184  1.1.1.3  christos     Sub = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
    185  1.1.1.3  christos     if (!Sub)
    186  1.1.1.3  christos     {
    187  1.1.1.3  christos         Status = AE_NO_MEMORY;
    188  1.1.1.3  christos         goto Cleanup;
    189  1.1.1.3  christos     }
    190  1.1.1.3  christos 
    191  1.1.1.3  christos     /* Area for the string starts after PNP_DEVICE_ID struct */
    192  1.1.1.3  christos 
    193  1.1.1.3  christos     Sub->String = ACPI_ADD_PTR (char, Sub, sizeof (ACPI_PNP_DEVICE_ID));
    194  1.1.1.3  christos 
    195  1.1.1.3  christos     /* Simply copy existing string */
    196  1.1.1.3  christos 
    197  1.1.1.6  christos     strcpy (Sub->String, ObjDesc->String.Pointer);
    198  1.1.1.3  christos     Sub->Length = Length;
    199  1.1.1.3  christos     *ReturnId = Sub;
    200  1.1.1.3  christos 
    201  1.1.1.3  christos 
    202  1.1.1.3  christos Cleanup:
    203  1.1.1.3  christos 
    204  1.1.1.3  christos     /* On exit, we must delete the return object */
    205  1.1.1.3  christos 
    206  1.1.1.3  christos     AcpiUtRemoveReference (ObjDesc);
    207  1.1.1.3  christos     return_ACPI_STATUS (Status);
    208  1.1.1.3  christos }
    209  1.1.1.3  christos 
    210  1.1.1.3  christos 
    211  1.1.1.3  christos /*******************************************************************************
    212  1.1.1.3  christos  *
    213      1.1    jruoho  * FUNCTION:    AcpiUtExecute_UID
    214      1.1    jruoho  *
    215      1.1    jruoho  * PARAMETERS:  DeviceNode          - Node for the device
    216      1.1    jruoho  *              ReturnId            - Where the string UID is returned
    217      1.1    jruoho  *
    218      1.1    jruoho  * RETURN:      Status
    219      1.1    jruoho  *
    220      1.1    jruoho  * DESCRIPTION: Executes the _UID control method that returns the unique
    221      1.1    jruoho  *              ID of the device. The UID is either a 64-bit Integer (NOT an
    222      1.1    jruoho  *              EISAID) or a string. Always returns a string. A 64-bit integer
    223      1.1    jruoho  *              is converted to a decimal string.
    224      1.1    jruoho  *
    225      1.1    jruoho  *              NOTE: Internal function, no parameter validation
    226      1.1    jruoho  *
    227      1.1    jruoho  ******************************************************************************/
    228      1.1    jruoho 
    229      1.1    jruoho ACPI_STATUS
    230      1.1    jruoho AcpiUtExecute_UID (
    231      1.1    jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
    232  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      **ReturnId)
    233      1.1    jruoho {
    234      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    235  1.1.1.3  christos     ACPI_PNP_DEVICE_ID      *Uid;
    236      1.1    jruoho     UINT32                  Length;
    237      1.1    jruoho     ACPI_STATUS             Status;
    238      1.1    jruoho 
    239      1.1    jruoho 
    240      1.1    jruoho     ACPI_FUNCTION_TRACE (UtExecute_UID);
    241      1.1    jruoho 
    242      1.1    jruoho 
    243      1.1    jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
    244      1.1    jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
    245      1.1    jruoho     if (ACPI_FAILURE (Status))
    246      1.1    jruoho     {
    247      1.1    jruoho         return_ACPI_STATUS (Status);
    248      1.1    jruoho     }
    249      1.1    jruoho 
    250      1.1    jruoho     /* Get the size of the String to be returned, includes null terminator */
    251      1.1    jruoho 
    252      1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    253      1.1    jruoho     {
    254      1.1    jruoho         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
    255      1.1    jruoho     }
    256      1.1    jruoho     else
    257      1.1    jruoho     {
    258      1.1    jruoho         Length = ObjDesc->String.Length + 1;
    259      1.1    jruoho     }
    260      1.1    jruoho 
    261      1.1    jruoho     /* Allocate a buffer for the UID */
    262      1.1    jruoho 
    263  1.1.1.3  christos     Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
    264      1.1    jruoho     if (!Uid)
    265      1.1    jruoho     {
    266      1.1    jruoho         Status = AE_NO_MEMORY;
    267      1.1    jruoho         goto Cleanup;
    268      1.1    jruoho     }
    269      1.1    jruoho 
    270  1.1.1.3  christos     /* Area for the string starts after PNP_DEVICE_ID struct */
    271      1.1    jruoho 
    272  1.1.1.3  christos     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_PNP_DEVICE_ID));
    273      1.1    jruoho 
    274      1.1    jruoho     /* Convert an Integer to string, or just copy an existing string */
    275      1.1    jruoho 
    276      1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    277      1.1    jruoho     {
    278      1.1    jruoho         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
    279      1.1    jruoho     }
    280      1.1    jruoho     else
    281      1.1    jruoho     {
    282  1.1.1.6  christos         strcpy (Uid->String, ObjDesc->String.Pointer);
    283      1.1    jruoho     }
    284      1.1    jruoho 
    285      1.1    jruoho     Uid->Length = Length;
    286      1.1    jruoho     *ReturnId = Uid;
    287      1.1    jruoho 
    288      1.1    jruoho 
    289      1.1    jruoho Cleanup:
    290      1.1    jruoho 
    291      1.1    jruoho     /* On exit, we must delete the return object */
    292      1.1    jruoho 
    293      1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    294      1.1    jruoho     return_ACPI_STATUS (Status);
    295      1.1    jruoho }
    296      1.1    jruoho 
    297      1.1    jruoho 
    298      1.1    jruoho /*******************************************************************************
    299      1.1    jruoho  *
    300      1.1    jruoho  * FUNCTION:    AcpiUtExecute_CID
    301      1.1    jruoho  *
    302      1.1    jruoho  * PARAMETERS:  DeviceNode          - Node for the device
    303      1.1    jruoho  *              ReturnCidList       - Where the CID list is returned
    304      1.1    jruoho  *
    305      1.1    jruoho  * RETURN:      Status, list of CID strings
    306      1.1    jruoho  *
    307      1.1    jruoho  * DESCRIPTION: Executes the _CID control method that returns one or more
    308      1.1    jruoho  *              compatible hardware IDs for the device.
    309      1.1    jruoho  *
    310      1.1    jruoho  *              NOTE: Internal function, no parameter validation
    311      1.1    jruoho  *
    312      1.1    jruoho  * A _CID method can return either a single compatible ID or a package of
    313      1.1    jruoho  * compatible IDs. Each compatible ID can be one of the following:
    314      1.1    jruoho  * 1) Integer (32 bit compressed EISA ID) or
    315      1.1    jruoho  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
    316      1.1    jruoho  *
    317      1.1    jruoho  * The Integer CIDs are converted to string format by this function.
    318      1.1    jruoho  *
    319      1.1    jruoho  ******************************************************************************/
    320      1.1    jruoho 
    321      1.1    jruoho ACPI_STATUS
    322      1.1    jruoho AcpiUtExecute_CID (
    323      1.1    jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
    324  1.1.1.3  christos     ACPI_PNP_DEVICE_ID_LIST **ReturnCidList)
    325      1.1    jruoho {
    326      1.1    jruoho     ACPI_OPERAND_OBJECT     **CidObjects;
    327      1.1    jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    328  1.1.1.3  christos     ACPI_PNP_DEVICE_ID_LIST *CidList;
    329      1.1    jruoho     char                    *NextIdString;
    330      1.1    jruoho     UINT32                  StringAreaSize;
    331      1.1    jruoho     UINT32                  Length;
    332      1.1    jruoho     UINT32                  CidListSize;
    333      1.1    jruoho     ACPI_STATUS             Status;
    334      1.1    jruoho     UINT32                  Count;
    335      1.1    jruoho     UINT32                  i;
    336      1.1    jruoho 
    337      1.1    jruoho 
    338      1.1    jruoho     ACPI_FUNCTION_TRACE (UtExecute_CID);
    339      1.1    jruoho 
    340      1.1    jruoho 
    341      1.1    jruoho     /* Evaluate the _CID method for this device */
    342      1.1    jruoho 
    343      1.1    jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
    344      1.1    jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
    345      1.1    jruoho                 &ObjDesc);
    346      1.1    jruoho     if (ACPI_FAILURE (Status))
    347      1.1    jruoho     {
    348      1.1    jruoho         return_ACPI_STATUS (Status);
    349      1.1    jruoho     }
    350      1.1    jruoho 
    351      1.1    jruoho     /*
    352      1.1    jruoho      * Get the count and size of the returned _CIDs. _CID can return either
    353      1.1    jruoho      * a Package of Integers/Strings or a single Integer or String.
    354      1.1    jruoho      * Note: This section also validates that all CID elements are of the
    355      1.1    jruoho      * correct type (Integer or String).
    356      1.1    jruoho      */
    357      1.1    jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
    358      1.1    jruoho     {
    359      1.1    jruoho         Count = ObjDesc->Package.Count;
    360      1.1    jruoho         CidObjects = ObjDesc->Package.Elements;
    361      1.1    jruoho     }
    362      1.1    jruoho     else /* Single Integer or String CID */
    363      1.1    jruoho     {
    364      1.1    jruoho         Count = 1;
    365      1.1    jruoho         CidObjects = &ObjDesc;
    366      1.1    jruoho     }
    367      1.1    jruoho 
    368      1.1    jruoho     StringAreaSize = 0;
    369      1.1    jruoho     for (i = 0; i < Count; i++)
    370      1.1    jruoho     {
    371      1.1    jruoho         /* String lengths include null terminator */
    372      1.1    jruoho 
    373      1.1    jruoho         switch (CidObjects[i]->Common.Type)
    374      1.1    jruoho         {
    375      1.1    jruoho         case ACPI_TYPE_INTEGER:
    376  1.1.1.3  christos 
    377      1.1    jruoho             StringAreaSize += ACPI_EISAID_STRING_SIZE;
    378      1.1    jruoho             break;
    379      1.1    jruoho 
    380      1.1    jruoho         case ACPI_TYPE_STRING:
    381  1.1.1.3  christos 
    382      1.1    jruoho             StringAreaSize += CidObjects[i]->String.Length + 1;
    383      1.1    jruoho             break;
    384      1.1    jruoho 
    385      1.1    jruoho         default:
    386  1.1.1.3  christos 
    387      1.1    jruoho             Status = AE_TYPE;
    388      1.1    jruoho             goto Cleanup;
    389      1.1    jruoho         }
    390      1.1    jruoho     }
    391      1.1    jruoho 
    392      1.1    jruoho     /*
    393      1.1    jruoho      * Now that we know the length of the CIDs, allocate return buffer:
    394      1.1    jruoho      * 1) Size of the base structure +
    395  1.1.1.3  christos      * 2) Size of the CID PNP_DEVICE_ID array +
    396      1.1    jruoho      * 3) Size of the actual CID strings
    397      1.1    jruoho      */
    398  1.1.1.3  christos     CidListSize = sizeof (ACPI_PNP_DEVICE_ID_LIST) +
    399  1.1.1.3  christos         ((Count - 1) * sizeof (ACPI_PNP_DEVICE_ID)) +
    400      1.1    jruoho         StringAreaSize;
    401      1.1    jruoho 
    402      1.1    jruoho     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
    403      1.1    jruoho     if (!CidList)
    404      1.1    jruoho     {
    405      1.1    jruoho         Status = AE_NO_MEMORY;
    406      1.1    jruoho         goto Cleanup;
    407      1.1    jruoho     }
    408      1.1    jruoho 
    409  1.1.1.3  christos     /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
    410      1.1    jruoho 
    411      1.1    jruoho     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
    412  1.1.1.3  christos         ((ACPI_SIZE) Count * sizeof (ACPI_PNP_DEVICE_ID));
    413      1.1    jruoho 
    414      1.1    jruoho     /* Copy/convert the CIDs to the return buffer */
    415      1.1    jruoho 
    416      1.1    jruoho     for (i = 0; i < Count; i++)
    417      1.1    jruoho     {
    418      1.1    jruoho         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
    419      1.1    jruoho         {
    420      1.1    jruoho             /* Convert the Integer (EISAID) CID to a string */
    421      1.1    jruoho 
    422      1.1    jruoho             AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
    423      1.1    jruoho             Length = ACPI_EISAID_STRING_SIZE;
    424      1.1    jruoho         }
    425      1.1    jruoho         else /* ACPI_TYPE_STRING */
    426      1.1    jruoho         {
    427      1.1    jruoho             /* Copy the String CID from the returned object */
    428      1.1    jruoho 
    429  1.1.1.6  christos             strcpy (NextIdString, CidObjects[i]->String.Pointer);
    430      1.1    jruoho             Length = CidObjects[i]->String.Length + 1;
    431      1.1    jruoho         }
    432      1.1    jruoho 
    433      1.1    jruoho         CidList->Ids[i].String = NextIdString;
    434      1.1    jruoho         CidList->Ids[i].Length = Length;
    435      1.1    jruoho         NextIdString += Length;
    436      1.1    jruoho     }
    437      1.1    jruoho 
    438      1.1    jruoho     /* Finish the CID list */
    439      1.1    jruoho 
    440      1.1    jruoho     CidList->Count = Count;
    441      1.1    jruoho     CidList->ListSize = CidListSize;
    442      1.1    jruoho     *ReturnCidList = CidList;
    443      1.1    jruoho 
    444      1.1    jruoho 
    445      1.1    jruoho Cleanup:
    446      1.1    jruoho 
    447      1.1    jruoho     /* On exit, we must delete the _CID return object */
    448      1.1    jruoho 
    449      1.1    jruoho     AcpiUtRemoveReference (ObjDesc);
    450      1.1    jruoho     return_ACPI_STATUS (Status);
    451      1.1    jruoho }
    452  1.1.1.6  christos 
    453  1.1.1.6  christos 
    454  1.1.1.6  christos /*******************************************************************************
    455  1.1.1.6  christos  *
    456  1.1.1.6  christos  * FUNCTION:    AcpiUtExecute_CLS
    457  1.1.1.6  christos  *
    458  1.1.1.6  christos  * PARAMETERS:  DeviceNode          - Node for the device
    459  1.1.1.6  christos  *              ReturnId            - Where the _CLS is returned
    460  1.1.1.6  christos  *
    461  1.1.1.6  christos  * RETURN:      Status
    462  1.1.1.6  christos  *
    463  1.1.1.6  christos  * DESCRIPTION: Executes the _CLS control method that returns PCI-defined
    464  1.1.1.6  christos  *              class code of the device. The _CLS value is always a package
    465  1.1.1.6  christos  *              containing PCI class information as a list of integers.
    466  1.1.1.6  christos  *              The returned string has format "BBSSPP", where:
    467  1.1.1.6  christos  *                BB = Base-class code
    468  1.1.1.6  christos  *                SS = Sub-class code
    469  1.1.1.6  christos  *                PP = Programming Interface code
    470  1.1.1.6  christos  *
    471  1.1.1.6  christos  ******************************************************************************/
    472  1.1.1.6  christos 
    473  1.1.1.6  christos ACPI_STATUS
    474  1.1.1.6  christos AcpiUtExecute_CLS (
    475  1.1.1.6  christos     ACPI_NAMESPACE_NODE     *DeviceNode,
    476  1.1.1.6  christos     ACPI_PNP_DEVICE_ID      **ReturnId)
    477  1.1.1.6  christos {
    478  1.1.1.6  christos     ACPI_OPERAND_OBJECT     *ObjDesc;
    479  1.1.1.6  christos     ACPI_OPERAND_OBJECT     **ClsObjects;
    480  1.1.1.6  christos     UINT32                  Count;
    481  1.1.1.6  christos     ACPI_PNP_DEVICE_ID      *Cls;
    482  1.1.1.6  christos     UINT32                  Length;
    483  1.1.1.6  christos     ACPI_STATUS             Status;
    484  1.1.1.6  christos     UINT8                   ClassCode[3] = {0, 0, 0};
    485  1.1.1.6  christos 
    486  1.1.1.6  christos 
    487  1.1.1.6  christos     ACPI_FUNCTION_TRACE (UtExecute_CLS);
    488  1.1.1.6  christos 
    489  1.1.1.6  christos 
    490  1.1.1.6  christos     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CLS,
    491  1.1.1.6  christos                 ACPI_BTYPE_PACKAGE, &ObjDesc);
    492  1.1.1.6  christos     if (ACPI_FAILURE (Status))
    493  1.1.1.6  christos     {
    494  1.1.1.6  christos         return_ACPI_STATUS (Status);
    495  1.1.1.6  christos     }
    496  1.1.1.6  christos 
    497  1.1.1.6  christos     /* Get the size of the String to be returned, includes null terminator */
    498  1.1.1.6  christos 
    499  1.1.1.6  christos     Length = ACPI_PCICLS_STRING_SIZE;
    500  1.1.1.6  christos     ClsObjects = ObjDesc->Package.Elements;
    501  1.1.1.6  christos     Count = ObjDesc->Package.Count;
    502  1.1.1.6  christos 
    503  1.1.1.6  christos     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
    504  1.1.1.6  christos     {
    505  1.1.1.6  christos         if (Count > 0 && ClsObjects[0]->Common.Type == ACPI_TYPE_INTEGER)
    506  1.1.1.6  christos         {
    507  1.1.1.6  christos             ClassCode[0] = (UINT8) ClsObjects[0]->Integer.Value;
    508  1.1.1.6  christos         }
    509  1.1.1.6  christos         if (Count > 1 && ClsObjects[1]->Common.Type == ACPI_TYPE_INTEGER)
    510  1.1.1.6  christos         {
    511  1.1.1.6  christos             ClassCode[1] = (UINT8) ClsObjects[1]->Integer.Value;
    512  1.1.1.6  christos         }
    513  1.1.1.6  christos         if (Count > 2 && ClsObjects[2]->Common.Type == ACPI_TYPE_INTEGER)
    514  1.1.1.6  christos         {
    515  1.1.1.6  christos             ClassCode[2] = (UINT8) ClsObjects[2]->Integer.Value;
    516  1.1.1.6  christos         }
    517  1.1.1.6  christos     }
    518  1.1.1.6  christos 
    519  1.1.1.6  christos     /* Allocate a buffer for the CLS */
    520  1.1.1.6  christos 
    521  1.1.1.6  christos     Cls = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
    522  1.1.1.6  christos     if (!Cls)
    523  1.1.1.6  christos     {
    524  1.1.1.6  christos         Status = AE_NO_MEMORY;
    525  1.1.1.6  christos         goto Cleanup;
    526  1.1.1.6  christos     }
    527  1.1.1.6  christos 
    528  1.1.1.6  christos     /* Area for the string starts after PNP_DEVICE_ID struct */
    529  1.1.1.6  christos 
    530  1.1.1.6  christos     Cls->String = ACPI_ADD_PTR (char, Cls, sizeof (ACPI_PNP_DEVICE_ID));
    531  1.1.1.6  christos 
    532  1.1.1.6  christos     /* Simply copy existing string */
    533  1.1.1.6  christos 
    534  1.1.1.6  christos     AcpiExPciClsToString (Cls->String, ClassCode);
    535  1.1.1.6  christos     Cls->Length = Length;
    536  1.1.1.6  christos     *ReturnId = Cls;
    537  1.1.1.6  christos 
    538  1.1.1.6  christos 
    539  1.1.1.6  christos Cleanup:
    540  1.1.1.6  christos 
    541  1.1.1.6  christos     /* On exit, we must delete the return object */
    542  1.1.1.6  christos 
    543  1.1.1.6  christos     AcpiUtRemoveReference (ObjDesc);
    544  1.1.1.6  christos     return_ACPI_STATUS (Status);
    545  1.1.1.6  christos }
    546