Back to home page

Quest Cross Reference

 
 

    


Warning, cross-references for /kernel/drivers/acpica/utids.c need to be fixed.

0001 /******************************************************************************
0002  *
0003  * Module Name: utids - support for device IDs - HID, UID, CID
0004  *
0005  *****************************************************************************/
0006 
0007 /******************************************************************************
0008  *
0009  * 1. Copyright Notice
0010  *
0011  * Some or all of this work - Copyright (c) 1999 - 2009, Intel Corp.
0012  * All rights reserved.
0013  *
0014  * 2. License
0015  *
0016  * 2.1. This is your license from Intel Corp. under its intellectual property
0017  * rights.  You may have additional license terms from the party that provided
0018  * you this software, covering your right to use that party's intellectual
0019  * property rights.
0020  *
0021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
0022  * copy of the source code appearing in this file ("Covered Code") an
0023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
0024  * base code distributed originally by Intel ("Original Intel Code") to copy,
0025  * make derivatives, distribute, use and display any portion of the Covered
0026  * Code in any form, with the right to sublicense such rights; and
0027  *
0028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
0029  * license (with the right to sublicense), under only those claims of Intel
0030  * patents that are infringed by the Original Intel Code, to make, use, sell,
0031  * offer to sell, and import the Covered Code and derivative works thereof
0032  * solely to the minimum extent necessary to exercise the above copyright
0033  * license, and in no event shall the patent license extend to any additions
0034  * to or modifications of the Original Intel Code.  No other license or right
0035  * is granted directly or by implication, estoppel or otherwise;
0036  *
0037  * The above copyright and patent license is granted only if the following
0038  * conditions are met:
0039  *
0040  * 3. Conditions
0041  *
0042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
0043  * Redistribution of source code of any substantial portion of the Covered
0044  * Code or modification with rights to further distribute source must include
0045  * the above Copyright Notice, the above License, this list of Conditions,
0046  * and the following Disclaimer and Export Compliance provision.  In addition,
0047  * Licensee must cause all Covered Code to which Licensee contributes to
0048  * contain a file documenting the changes Licensee made to create that Covered
0049  * Code and the date of any change.  Licensee must include in that file the
0050  * documentation of any changes made by any predecessor Licensee.  Licensee
0051  * must include a prominent statement that the modification is derived,
0052  * directly or indirectly, from Original Intel Code.
0053  *
0054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
0055  * Redistribution of source code of any substantial portion of the Covered
0056  * Code or modification without rights to further distribute source must
0057  * include the following Disclaimer and Export Compliance provision in the
0058  * documentation and/or other materials provided with distribution.  In
0059  * addition, Licensee may not authorize further sublicense of source of any
0060  * portion of the Covered Code, and must include terms to the effect that the
0061  * license from Licensee to its licensee is limited to the intellectual
0062  * property embodied in the software Licensee provides to its licensee, and
0063  * not to intellectual property embodied in modifications its licensee may
0064  * make.
0065  *
0066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
0067  * substantial portion of the Covered Code or modification must reproduce the
0068  * above Copyright Notice, and the following Disclaimer and Export Compliance
0069  * provision in the documentation and/or other materials provided with the
0070  * distribution.
0071  *
0072  * 3.4. Intel retains all right, title, and interest in and to the Original
0073  * Intel Code.
0074  *
0075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
0076  * Intel shall be used in advertising or otherwise to promote the sale, use or
0077  * other dealings in products derived from or relating to the Covered Code
0078  * without prior written authorization from Intel.
0079  *
0080  * 4. Disclaimer and Export Compliance
0081  *
0082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
0083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
0084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
0085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
0086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
0087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
0088  * PARTICULAR PURPOSE.
0089  *
0090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
0091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
0092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
0093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
0094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
0095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
0096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
0097  * LIMITED REMEDY.
0098  *
0099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
0100  * software or system incorporating such software without first obtaining any
0101  * required license or other approval from the U. S. Department of Commerce or
0102  * any other agency or department of the United States Government.  In the
0103  * event Licensee exports any such software from the United States or
0104  * re-exports any such software from a foreign destination, Licensee shall
0105  * ensure that the distribution and export/re-export of the software is in
0106  * compliance with all laws, regulations, orders, or other restrictions of the
0107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
0108  * any of its subsidiaries will export/re-export any technical data, process,
0109  * software, or service, directly or indirectly, to any country for which the
0110  * United States government or any agency thereof requires an export license,
0111  * other governmental approval, or letter of assurance, without first obtaining
0112  * such license, approval or letter.
0113  *
0114  *****************************************************************************/
0115 
0116 #define __UTIDS_C__
0117 
0118 #include "acpi.h"
0119 #include "accommon.h"
0120 #include "acinterp.h"
0121 
0122 
0123 #define _COMPONENT          ACPI_UTILITIES
0124         ACPI_MODULE_NAME    ("utids")
0125 
0126 /* Local prototypes */
0127 
0128 static void
0129 AcpiUtCopyIdString (
0130     char                    *Destination,
0131     char                    *Source);
0132 
0133 
0134 /*******************************************************************************
0135  *
0136  * FUNCTION:    AcpiUtCopyIdString
0137  *
0138  * PARAMETERS:  Destination         - Where to copy the string
0139  *              Source              - Source string
0140  *
0141  * RETURN:      None
0142  *
0143  * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
0144  *              Performs removal of a leading asterisk if present -- workaround
0145  *              for a known issue on a bunch of machines.
0146  *
0147  ******************************************************************************/
0148 
0149 static void
0150 AcpiUtCopyIdString (
0151     char                    *Destination,
0152     char                    *Source)
0153 {
0154 
0155     /*
0156      * Workaround for ID strings that have a leading asterisk. This construct
0157      * is not allowed by the ACPI specification  (ID strings must be
0158      * alphanumeric), but enough existing machines have this embedded in their
0159      * ID strings that the following code is useful.
0160      */
0161     if (*Source == '*')
0162     {
0163         Source++;
0164     }
0165 
0166     /* Do the actual copy */
0167 
0168     ACPI_STRCPY (Destination, Source);
0169 }
0170 
0171 
0172 /*******************************************************************************
0173  *
0174  * FUNCTION:    AcpiUtExecute_HID
0175  *
0176  * PARAMETERS:  DeviceNode          - Node for the device
0177  *              ReturnId            - Where the string HID is returned
0178  *
0179  * RETURN:      Status
0180  *
0181  * DESCRIPTION: Executes the _HID control method that returns the hardware
0182  *              ID of the device. The HID is either an 32-bit encoded EISAID
0183  *              Integer or a String. A string is always returned. An EISAID
0184  *              is converted to a string.
0185  *
0186  *              NOTE: Internal function, no parameter validation
0187  *
0188  ******************************************************************************/
0189 
0190 ACPI_STATUS
0191 AcpiUtExecute_HID (
0192     ACPI_NAMESPACE_NODE     *DeviceNode,
0193     ACPI_DEVICE_ID          **ReturnId)
0194 {
0195     ACPI_OPERAND_OBJECT     *ObjDesc;
0196     ACPI_DEVICE_ID          *Hid;
0197     UINT32                  Length;
0198     ACPI_STATUS             Status;
0199 
0200 
0201     ACPI_FUNCTION_TRACE (UtExecute_HID);
0202 
0203 
0204     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
0205                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
0206     if (ACPI_FAILURE (Status))
0207     {
0208         return_ACPI_STATUS (Status);
0209     }
0210 
0211     /* Get the size of the String to be returned, includes null terminator */
0212 
0213     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
0214     {
0215         Length = ACPI_EISAID_STRING_SIZE;
0216     }
0217     else
0218     {
0219         Length = ObjDesc->String.Length + 1;
0220     }
0221 
0222     /* Allocate a buffer for the HID */
0223 
0224     Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
0225     if (!Hid)
0226     {
0227         Status = AE_NO_MEMORY;
0228         goto Cleanup;
0229     }
0230 
0231     /* Area for the string starts after DEVICE_ID struct */
0232 
0233     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_DEVICE_ID));
0234 
0235     /* Convert EISAID to a string or simply copy existing string */
0236 
0237     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
0238     {
0239         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
0240     }
0241     else
0242     {
0243         AcpiUtCopyIdString (Hid->String, ObjDesc->String.Pointer);
0244     }
0245 
0246     Hid->Length = Length;
0247     *ReturnId = Hid;
0248 
0249 
0250 Cleanup:
0251 
0252     /* On exit, we must delete the return object */
0253 
0254     AcpiUtRemoveReference (ObjDesc);
0255     return_ACPI_STATUS (Status);
0256 }
0257 
0258 
0259 /*******************************************************************************
0260  *
0261  * FUNCTION:    AcpiUtExecute_UID
0262  *
0263  * PARAMETERS:  DeviceNode          - Node for the device
0264  *              ReturnId            - Where the string UID is returned
0265  *
0266  * RETURN:      Status
0267  *
0268  * DESCRIPTION: Executes the _UID control method that returns the unique
0269  *              ID of the device. The UID is either a 64-bit Integer (NOT an
0270  *              EISAID) or a string. Always returns a string. A 64-bit integer
0271  *              is converted to a decimal string.
0272  *
0273  *              NOTE: Internal function, no parameter validation
0274  *
0275  ******************************************************************************/
0276 
0277 ACPI_STATUS
0278 AcpiUtExecute_UID (
0279     ACPI_NAMESPACE_NODE     *DeviceNode,
0280     ACPI_DEVICE_ID          **ReturnId)
0281 {
0282     ACPI_OPERAND_OBJECT     *ObjDesc;
0283     ACPI_DEVICE_ID          *Uid;
0284     UINT32                  Length;
0285     ACPI_STATUS             Status;
0286 
0287 
0288     ACPI_FUNCTION_TRACE (UtExecute_UID);
0289 
0290 
0291     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
0292                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
0293     if (ACPI_FAILURE (Status))
0294     {
0295         return_ACPI_STATUS (Status);
0296     }
0297 
0298     /* Get the size of the String to be returned, includes null terminator */
0299 
0300     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
0301     {
0302         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
0303     }
0304     else
0305     {
0306         Length = ObjDesc->String.Length + 1;
0307     }
0308 
0309     /* Allocate a buffer for the UID */
0310 
0311     Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
0312     if (!Uid)
0313     {
0314         Status = AE_NO_MEMORY;
0315         goto Cleanup;
0316     }
0317 
0318     /* Area for the string starts after DEVICE_ID struct */
0319 
0320     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_DEVICE_ID));
0321 
0322     /* Convert an Integer to string, or just copy an existing string */
0323 
0324     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
0325     {
0326         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
0327     }
0328     else
0329     {
0330         AcpiUtCopyIdString (Uid->String, ObjDesc->String.Pointer);
0331     }
0332 
0333     Uid->Length = Length;
0334     *ReturnId = Uid;
0335 
0336 
0337 Cleanup:
0338 
0339     /* On exit, we must delete the return object */
0340 
0341     AcpiUtRemoveReference (ObjDesc);
0342     return_ACPI_STATUS (Status);
0343 }
0344 
0345 
0346 /*******************************************************************************
0347  *
0348  * FUNCTION:    AcpiUtExecute_CID
0349  *
0350  * PARAMETERS:  DeviceNode          - Node for the device
0351  *              ReturnCidList       - Where the CID list is returned
0352  *
0353  * RETURN:      Status, list of CID strings
0354  *
0355  * DESCRIPTION: Executes the _CID control method that returns one or more
0356  *              compatible hardware IDs for the device.
0357  *
0358  *              NOTE: Internal function, no parameter validation
0359  *
0360  * A _CID method can return either a single compatible ID or a package of
0361  * compatible IDs. Each compatible ID can be one of the following:
0362  * 1) Integer (32 bit compressed EISA ID) or
0363  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
0364  *
0365  * The Integer CIDs are converted to string format by this function.
0366  *
0367  ******************************************************************************/
0368 
0369 ACPI_STATUS
0370 AcpiUtExecute_CID (
0371     ACPI_NAMESPACE_NODE     *DeviceNode,
0372     ACPI_DEVICE_ID_LIST     **ReturnCidList)
0373 {
0374     ACPI_OPERAND_OBJECT     **CidObjects;
0375     ACPI_OPERAND_OBJECT     *ObjDesc;
0376     ACPI_DEVICE_ID_LIST     *CidList;
0377     char                    *NextIdString;
0378     UINT32                  StringAreaSize;
0379     UINT32                  Length;
0380     UINT32                  CidListSize;
0381     ACPI_STATUS             Status;
0382     UINT32                  Count;
0383     UINT32                  i;
0384 
0385 
0386     ACPI_FUNCTION_TRACE (UtExecute_CID);
0387 
0388 
0389     /* Evaluate the _CID method for this device */
0390 
0391     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
0392                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
0393                 &ObjDesc);
0394     if (ACPI_FAILURE (Status))
0395     {
0396         return_ACPI_STATUS (Status);
0397     }
0398 
0399     /*
0400      * Get the count and size of the returned _CIDs. _CID can return either
0401      * a Package of Integers/Strings or a single Integer or String.
0402      * Note: This section also validates that all CID elements are of the
0403      * correct type (Integer or String).
0404      */
0405     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
0406     {
0407         Count = ObjDesc->Package.Count;
0408         CidObjects = ObjDesc->Package.Elements;
0409     }
0410     else /* Single Integer or String CID */
0411     {
0412         Count = 1;
0413         CidObjects = &ObjDesc;
0414     }
0415 
0416     StringAreaSize = 0;
0417     for (i = 0; i < Count; i++)
0418     {
0419         /* String lengths include null terminator */
0420 
0421         switch (CidObjects[i]->Common.Type)
0422         {
0423         case ACPI_TYPE_INTEGER:
0424             StringAreaSize += ACPI_EISAID_STRING_SIZE;
0425             break;
0426 
0427         case ACPI_TYPE_STRING:
0428             StringAreaSize += CidObjects[i]->String.Length + 1;
0429             break;
0430 
0431         default:
0432             Status = AE_TYPE;
0433             goto Cleanup;
0434         }
0435     }
0436 
0437     /*
0438      * Now that we know the length of the CIDs, allocate return buffer:
0439      * 1) Size of the base structure +
0440      * 2) Size of the CID DEVICE_ID array +
0441      * 3) Size of the actual CID strings
0442      */
0443     CidListSize = sizeof (ACPI_DEVICE_ID_LIST) +
0444         ((Count - 1) * sizeof (ACPI_DEVICE_ID)) +
0445         StringAreaSize;
0446 
0447     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
0448     if (!CidList)
0449     {
0450         Status = AE_NO_MEMORY;
0451         goto Cleanup;
0452     }
0453 
0454     /* Area for CID strings starts after the CID DEVICE_ID array */
0455 
0456     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
0457         ((ACPI_SIZE) Count * sizeof (ACPI_DEVICE_ID));
0458 
0459     /* Copy/convert the CIDs to the return buffer */
0460 
0461     for (i = 0; i < Count; i++)
0462     {
0463         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
0464         {
0465             /* Convert the Integer (EISAID) CID to a string */
0466 
0467             AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
0468             Length = ACPI_EISAID_STRING_SIZE;
0469         }
0470         else /* ACPI_TYPE_STRING */
0471         {
0472             /* Copy the String CID from the returned object */
0473 
0474             AcpiUtCopyIdString (NextIdString, CidObjects[i]->String.Pointer);
0475             Length = CidObjects[i]->String.Length + 1;
0476         }
0477 
0478         CidList->Ids[i].String = NextIdString;
0479         CidList->Ids[i].Length = Length;
0480         NextIdString += Length;
0481     }
0482 
0483     /* Finish the CID list */
0484 
0485     CidList->Count = Count;
0486     CidList->ListSize = CidListSize;
0487     *ReturnCidList = CidList;
0488 
0489 
0490 Cleanup:
0491 
0492     /* On exit, we must delete the _CID return object */
0493 
0494     AcpiUtRemoveReference (ObjDesc);
0495     return_ACPI_STATUS (Status);
0496 }
0497