Home | History | Annotate | Line # | Download | only in utilities
utids.c revision 1.1.1.2
      1      1.1  jruoho /******************************************************************************
      2      1.1  jruoho  *
      3      1.1  jruoho  * Module Name: utids - support for device IDs - HID, UID, CID
      4      1.1  jruoho  *
      5      1.1  jruoho  *****************************************************************************/
      6      1.1  jruoho 
      7  1.1.1.2  jruoho /*
      8  1.1.1.2  jruoho  * Copyright (C) 2000 - 2011, 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 #define __UTIDS_C__
     45      1.1  jruoho 
     46      1.1  jruoho #include "acpi.h"
     47      1.1  jruoho #include "accommon.h"
     48      1.1  jruoho #include "acinterp.h"
     49      1.1  jruoho 
     50      1.1  jruoho 
     51      1.1  jruoho #define _COMPONENT          ACPI_UTILITIES
     52      1.1  jruoho         ACPI_MODULE_NAME    ("utids")
     53      1.1  jruoho 
     54      1.1  jruoho 
     55      1.1  jruoho /*******************************************************************************
     56      1.1  jruoho  *
     57      1.1  jruoho  * FUNCTION:    AcpiUtExecute_HID
     58      1.1  jruoho  *
     59      1.1  jruoho  * PARAMETERS:  DeviceNode          - Node for the device
     60      1.1  jruoho  *              ReturnId            - Where the string HID is returned
     61      1.1  jruoho  *
     62      1.1  jruoho  * RETURN:      Status
     63      1.1  jruoho  *
     64      1.1  jruoho  * DESCRIPTION: Executes the _HID control method that returns the hardware
     65      1.1  jruoho  *              ID of the device. The HID is either an 32-bit encoded EISAID
     66      1.1  jruoho  *              Integer or a String. A string is always returned. An EISAID
     67      1.1  jruoho  *              is converted to a string.
     68      1.1  jruoho  *
     69      1.1  jruoho  *              NOTE: Internal function, no parameter validation
     70      1.1  jruoho  *
     71      1.1  jruoho  ******************************************************************************/
     72      1.1  jruoho 
     73      1.1  jruoho ACPI_STATUS
     74      1.1  jruoho AcpiUtExecute_HID (
     75      1.1  jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
     76      1.1  jruoho     ACPI_DEVICE_ID          **ReturnId)
     77      1.1  jruoho {
     78      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
     79      1.1  jruoho     ACPI_DEVICE_ID          *Hid;
     80      1.1  jruoho     UINT32                  Length;
     81      1.1  jruoho     ACPI_STATUS             Status;
     82      1.1  jruoho 
     83      1.1  jruoho 
     84      1.1  jruoho     ACPI_FUNCTION_TRACE (UtExecute_HID);
     85      1.1  jruoho 
     86      1.1  jruoho 
     87      1.1  jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
     88      1.1  jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
     89      1.1  jruoho     if (ACPI_FAILURE (Status))
     90      1.1  jruoho     {
     91      1.1  jruoho         return_ACPI_STATUS (Status);
     92      1.1  jruoho     }
     93      1.1  jruoho 
     94      1.1  jruoho     /* Get the size of the String to be returned, includes null terminator */
     95      1.1  jruoho 
     96      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
     97      1.1  jruoho     {
     98      1.1  jruoho         Length = ACPI_EISAID_STRING_SIZE;
     99      1.1  jruoho     }
    100      1.1  jruoho     else
    101      1.1  jruoho     {
    102      1.1  jruoho         Length = ObjDesc->String.Length + 1;
    103      1.1  jruoho     }
    104      1.1  jruoho 
    105      1.1  jruoho     /* Allocate a buffer for the HID */
    106      1.1  jruoho 
    107      1.1  jruoho     Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
    108      1.1  jruoho     if (!Hid)
    109      1.1  jruoho     {
    110      1.1  jruoho         Status = AE_NO_MEMORY;
    111      1.1  jruoho         goto Cleanup;
    112      1.1  jruoho     }
    113      1.1  jruoho 
    114      1.1  jruoho     /* Area for the string starts after DEVICE_ID struct */
    115      1.1  jruoho 
    116      1.1  jruoho     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_DEVICE_ID));
    117      1.1  jruoho 
    118      1.1  jruoho     /* Convert EISAID to a string or simply copy existing string */
    119      1.1  jruoho 
    120      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    121      1.1  jruoho     {
    122      1.1  jruoho         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
    123      1.1  jruoho     }
    124      1.1  jruoho     else
    125      1.1  jruoho     {
    126  1.1.1.2  jruoho         ACPI_STRCPY (Hid->String, ObjDesc->String.Pointer);
    127      1.1  jruoho     }
    128      1.1  jruoho 
    129      1.1  jruoho     Hid->Length = Length;
    130      1.1  jruoho     *ReturnId = Hid;
    131      1.1  jruoho 
    132      1.1  jruoho 
    133      1.1  jruoho Cleanup:
    134      1.1  jruoho 
    135      1.1  jruoho     /* On exit, we must delete the return object */
    136      1.1  jruoho 
    137      1.1  jruoho     AcpiUtRemoveReference (ObjDesc);
    138      1.1  jruoho     return_ACPI_STATUS (Status);
    139      1.1  jruoho }
    140      1.1  jruoho 
    141      1.1  jruoho 
    142      1.1  jruoho /*******************************************************************************
    143      1.1  jruoho  *
    144      1.1  jruoho  * FUNCTION:    AcpiUtExecute_UID
    145      1.1  jruoho  *
    146      1.1  jruoho  * PARAMETERS:  DeviceNode          - Node for the device
    147      1.1  jruoho  *              ReturnId            - Where the string UID is returned
    148      1.1  jruoho  *
    149      1.1  jruoho  * RETURN:      Status
    150      1.1  jruoho  *
    151      1.1  jruoho  * DESCRIPTION: Executes the _UID control method that returns the unique
    152      1.1  jruoho  *              ID of the device. The UID is either a 64-bit Integer (NOT an
    153      1.1  jruoho  *              EISAID) or a string. Always returns a string. A 64-bit integer
    154      1.1  jruoho  *              is converted to a decimal string.
    155      1.1  jruoho  *
    156      1.1  jruoho  *              NOTE: Internal function, no parameter validation
    157      1.1  jruoho  *
    158      1.1  jruoho  ******************************************************************************/
    159      1.1  jruoho 
    160      1.1  jruoho ACPI_STATUS
    161      1.1  jruoho AcpiUtExecute_UID (
    162      1.1  jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
    163      1.1  jruoho     ACPI_DEVICE_ID          **ReturnId)
    164      1.1  jruoho {
    165      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    166      1.1  jruoho     ACPI_DEVICE_ID          *Uid;
    167      1.1  jruoho     UINT32                  Length;
    168      1.1  jruoho     ACPI_STATUS             Status;
    169      1.1  jruoho 
    170      1.1  jruoho 
    171      1.1  jruoho     ACPI_FUNCTION_TRACE (UtExecute_UID);
    172      1.1  jruoho 
    173      1.1  jruoho 
    174      1.1  jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
    175      1.1  jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
    176      1.1  jruoho     if (ACPI_FAILURE (Status))
    177      1.1  jruoho     {
    178      1.1  jruoho         return_ACPI_STATUS (Status);
    179      1.1  jruoho     }
    180      1.1  jruoho 
    181      1.1  jruoho     /* Get the size of the String to be returned, includes null terminator */
    182      1.1  jruoho 
    183      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    184      1.1  jruoho     {
    185      1.1  jruoho         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
    186      1.1  jruoho     }
    187      1.1  jruoho     else
    188      1.1  jruoho     {
    189      1.1  jruoho         Length = ObjDesc->String.Length + 1;
    190      1.1  jruoho     }
    191      1.1  jruoho 
    192      1.1  jruoho     /* Allocate a buffer for the UID */
    193      1.1  jruoho 
    194      1.1  jruoho     Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
    195      1.1  jruoho     if (!Uid)
    196      1.1  jruoho     {
    197      1.1  jruoho         Status = AE_NO_MEMORY;
    198      1.1  jruoho         goto Cleanup;
    199      1.1  jruoho     }
    200      1.1  jruoho 
    201      1.1  jruoho     /* Area for the string starts after DEVICE_ID struct */
    202      1.1  jruoho 
    203      1.1  jruoho     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_DEVICE_ID));
    204      1.1  jruoho 
    205      1.1  jruoho     /* Convert an Integer to string, or just copy an existing string */
    206      1.1  jruoho 
    207      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
    208      1.1  jruoho     {
    209      1.1  jruoho         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
    210      1.1  jruoho     }
    211      1.1  jruoho     else
    212      1.1  jruoho     {
    213  1.1.1.2  jruoho         ACPI_STRCPY (Uid->String, ObjDesc->String.Pointer);
    214      1.1  jruoho     }
    215      1.1  jruoho 
    216      1.1  jruoho     Uid->Length = Length;
    217      1.1  jruoho     *ReturnId = Uid;
    218      1.1  jruoho 
    219      1.1  jruoho 
    220      1.1  jruoho Cleanup:
    221      1.1  jruoho 
    222      1.1  jruoho     /* On exit, we must delete the return object */
    223      1.1  jruoho 
    224      1.1  jruoho     AcpiUtRemoveReference (ObjDesc);
    225      1.1  jruoho     return_ACPI_STATUS (Status);
    226      1.1  jruoho }
    227      1.1  jruoho 
    228      1.1  jruoho 
    229      1.1  jruoho /*******************************************************************************
    230      1.1  jruoho  *
    231      1.1  jruoho  * FUNCTION:    AcpiUtExecute_CID
    232      1.1  jruoho  *
    233      1.1  jruoho  * PARAMETERS:  DeviceNode          - Node for the device
    234      1.1  jruoho  *              ReturnCidList       - Where the CID list is returned
    235      1.1  jruoho  *
    236      1.1  jruoho  * RETURN:      Status, list of CID strings
    237      1.1  jruoho  *
    238      1.1  jruoho  * DESCRIPTION: Executes the _CID control method that returns one or more
    239      1.1  jruoho  *              compatible hardware IDs for the device.
    240      1.1  jruoho  *
    241      1.1  jruoho  *              NOTE: Internal function, no parameter validation
    242      1.1  jruoho  *
    243      1.1  jruoho  * A _CID method can return either a single compatible ID or a package of
    244      1.1  jruoho  * compatible IDs. Each compatible ID can be one of the following:
    245      1.1  jruoho  * 1) Integer (32 bit compressed EISA ID) or
    246      1.1  jruoho  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
    247      1.1  jruoho  *
    248      1.1  jruoho  * The Integer CIDs are converted to string format by this function.
    249      1.1  jruoho  *
    250      1.1  jruoho  ******************************************************************************/
    251      1.1  jruoho 
    252      1.1  jruoho ACPI_STATUS
    253      1.1  jruoho AcpiUtExecute_CID (
    254      1.1  jruoho     ACPI_NAMESPACE_NODE     *DeviceNode,
    255      1.1  jruoho     ACPI_DEVICE_ID_LIST     **ReturnCidList)
    256      1.1  jruoho {
    257      1.1  jruoho     ACPI_OPERAND_OBJECT     **CidObjects;
    258      1.1  jruoho     ACPI_OPERAND_OBJECT     *ObjDesc;
    259      1.1  jruoho     ACPI_DEVICE_ID_LIST     *CidList;
    260      1.1  jruoho     char                    *NextIdString;
    261      1.1  jruoho     UINT32                  StringAreaSize;
    262      1.1  jruoho     UINT32                  Length;
    263      1.1  jruoho     UINT32                  CidListSize;
    264      1.1  jruoho     ACPI_STATUS             Status;
    265      1.1  jruoho     UINT32                  Count;
    266      1.1  jruoho     UINT32                  i;
    267      1.1  jruoho 
    268      1.1  jruoho 
    269      1.1  jruoho     ACPI_FUNCTION_TRACE (UtExecute_CID);
    270      1.1  jruoho 
    271      1.1  jruoho 
    272      1.1  jruoho     /* Evaluate the _CID method for this device */
    273      1.1  jruoho 
    274      1.1  jruoho     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
    275      1.1  jruoho                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
    276      1.1  jruoho                 &ObjDesc);
    277      1.1  jruoho     if (ACPI_FAILURE (Status))
    278      1.1  jruoho     {
    279      1.1  jruoho         return_ACPI_STATUS (Status);
    280      1.1  jruoho     }
    281      1.1  jruoho 
    282      1.1  jruoho     /*
    283      1.1  jruoho      * Get the count and size of the returned _CIDs. _CID can return either
    284      1.1  jruoho      * a Package of Integers/Strings or a single Integer or String.
    285      1.1  jruoho      * Note: This section also validates that all CID elements are of the
    286      1.1  jruoho      * correct type (Integer or String).
    287      1.1  jruoho      */
    288      1.1  jruoho     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
    289      1.1  jruoho     {
    290      1.1  jruoho         Count = ObjDesc->Package.Count;
    291      1.1  jruoho         CidObjects = ObjDesc->Package.Elements;
    292      1.1  jruoho     }
    293      1.1  jruoho     else /* Single Integer or String CID */
    294      1.1  jruoho     {
    295      1.1  jruoho         Count = 1;
    296      1.1  jruoho         CidObjects = &ObjDesc;
    297      1.1  jruoho     }
    298      1.1  jruoho 
    299      1.1  jruoho     StringAreaSize = 0;
    300      1.1  jruoho     for (i = 0; i < Count; i++)
    301      1.1  jruoho     {
    302      1.1  jruoho         /* String lengths include null terminator */
    303      1.1  jruoho 
    304      1.1  jruoho         switch (CidObjects[i]->Common.Type)
    305      1.1  jruoho         {
    306      1.1  jruoho         case ACPI_TYPE_INTEGER:
    307      1.1  jruoho             StringAreaSize += ACPI_EISAID_STRING_SIZE;
    308      1.1  jruoho             break;
    309      1.1  jruoho 
    310      1.1  jruoho         case ACPI_TYPE_STRING:
    311      1.1  jruoho             StringAreaSize += CidObjects[i]->String.Length + 1;
    312      1.1  jruoho             break;
    313      1.1  jruoho 
    314      1.1  jruoho         default:
    315      1.1  jruoho             Status = AE_TYPE;
    316      1.1  jruoho             goto Cleanup;
    317      1.1  jruoho         }
    318      1.1  jruoho     }
    319      1.1  jruoho 
    320      1.1  jruoho     /*
    321      1.1  jruoho      * Now that we know the length of the CIDs, allocate return buffer:
    322      1.1  jruoho      * 1) Size of the base structure +
    323      1.1  jruoho      * 2) Size of the CID DEVICE_ID array +
    324      1.1  jruoho      * 3) Size of the actual CID strings
    325      1.1  jruoho      */
    326      1.1  jruoho     CidListSize = sizeof (ACPI_DEVICE_ID_LIST) +
    327      1.1  jruoho         ((Count - 1) * sizeof (ACPI_DEVICE_ID)) +
    328      1.1  jruoho         StringAreaSize;
    329      1.1  jruoho 
    330      1.1  jruoho     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
    331      1.1  jruoho     if (!CidList)
    332      1.1  jruoho     {
    333      1.1  jruoho         Status = AE_NO_MEMORY;
    334      1.1  jruoho         goto Cleanup;
    335      1.1  jruoho     }
    336      1.1  jruoho 
    337      1.1  jruoho     /* Area for CID strings starts after the CID DEVICE_ID array */
    338      1.1  jruoho 
    339      1.1  jruoho     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
    340      1.1  jruoho         ((ACPI_SIZE) Count * sizeof (ACPI_DEVICE_ID));
    341      1.1  jruoho 
    342      1.1  jruoho     /* Copy/convert the CIDs to the return buffer */
    343      1.1  jruoho 
    344      1.1  jruoho     for (i = 0; i < Count; i++)
    345      1.1  jruoho     {
    346      1.1  jruoho         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
    347      1.1  jruoho         {
    348      1.1  jruoho             /* Convert the Integer (EISAID) CID to a string */
    349      1.1  jruoho 
    350      1.1  jruoho             AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
    351      1.1  jruoho             Length = ACPI_EISAID_STRING_SIZE;
    352      1.1  jruoho         }
    353      1.1  jruoho         else /* ACPI_TYPE_STRING */
    354      1.1  jruoho         {
    355      1.1  jruoho             /* Copy the String CID from the returned object */
    356      1.1  jruoho 
    357  1.1.1.2  jruoho             ACPI_STRCPY (NextIdString, CidObjects[i]->String.Pointer);
    358      1.1  jruoho             Length = CidObjects[i]->String.Length + 1;
    359      1.1  jruoho         }
    360      1.1  jruoho 
    361      1.1  jruoho         CidList->Ids[i].String = NextIdString;
    362      1.1  jruoho         CidList->Ids[i].Length = Length;
    363      1.1  jruoho         NextIdString += Length;
    364      1.1  jruoho     }
    365      1.1  jruoho 
    366      1.1  jruoho     /* Finish the CID list */
    367      1.1  jruoho 
    368      1.1  jruoho     CidList->Count = Count;
    369      1.1  jruoho     CidList->ListSize = CidListSize;
    370      1.1  jruoho     *ReturnCidList = CidList;
    371      1.1  jruoho 
    372      1.1  jruoho 
    373      1.1  jruoho Cleanup:
    374      1.1  jruoho 
    375      1.1  jruoho     /* On exit, we must delete the _CID return object */
    376      1.1  jruoho 
    377      1.1  jruoho     AcpiUtRemoveReference (ObjDesc);
    378      1.1  jruoho     return_ACPI_STATUS (Status);
    379      1.1  jruoho }
    380      1.1  jruoho 
    381