ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

utids.c
Go to the documentation of this file.
00001 /******************************************************************************
00002  *
00003  * Module Name: utids - support for device IDs - HID, UID, CID
00004  *
00005  *****************************************************************************/
00006 
00007 /******************************************************************************
00008  *
00009  * 1. Copyright Notice
00010  *
00011  * Some or all of this work - Copyright (c) 1999 - 2011, Intel Corp.
00012  * All rights reserved.
00013  *
00014  * 2. License
00015  *
00016  * 2.1. This is your license from Intel Corp. under its intellectual property
00017  * rights.  You may have additional license terms from the party that provided
00018  * you this software, covering your right to use that party's intellectual
00019  * property rights.
00020  *
00021  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
00022  * copy of the source code appearing in this file ("Covered Code") an
00023  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
00024  * base code distributed originally by Intel ("Original Intel Code") to copy,
00025  * make derivatives, distribute, use and display any portion of the Covered
00026  * Code in any form, with the right to sublicense such rights; and
00027  *
00028  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
00029  * license (with the right to sublicense), under only those claims of Intel
00030  * patents that are infringed by the Original Intel Code, to make, use, sell,
00031  * offer to sell, and import the Covered Code and derivative works thereof
00032  * solely to the minimum extent necessary to exercise the above copyright
00033  * license, and in no event shall the patent license extend to any additions
00034  * to or modifications of the Original Intel Code.  No other license or right
00035  * is granted directly or by implication, estoppel or otherwise;
00036  *
00037  * The above copyright and patent license is granted only if the following
00038  * conditions are met:
00039  *
00040  * 3. Conditions
00041  *
00042  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
00043  * Redistribution of source code of any substantial portion of the Covered
00044  * Code or modification with rights to further distribute source must include
00045  * the above Copyright Notice, the above License, this list of Conditions,
00046  * and the following Disclaimer and Export Compliance provision.  In addition,
00047  * Licensee must cause all Covered Code to which Licensee contributes to
00048  * contain a file documenting the changes Licensee made to create that Covered
00049  * Code and the date of any change.  Licensee must include in that file the
00050  * documentation of any changes made by any predecessor Licensee.  Licensee
00051  * must include a prominent statement that the modification is derived,
00052  * directly or indirectly, from Original Intel Code.
00053  *
00054  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
00055  * Redistribution of source code of any substantial portion of the Covered
00056  * Code or modification without rights to further distribute source must
00057  * include the following Disclaimer and Export Compliance provision in the
00058  * documentation and/or other materials provided with distribution.  In
00059  * addition, Licensee may not authorize further sublicense of source of any
00060  * portion of the Covered Code, and must include terms to the effect that the
00061  * license from Licensee to its licensee is limited to the intellectual
00062  * property embodied in the software Licensee provides to its licensee, and
00063  * not to intellectual property embodied in modifications its licensee may
00064  * make.
00065  *
00066  * 3.3. Redistribution of Executable. Redistribution in executable form of any
00067  * substantial portion of the Covered Code or modification must reproduce the
00068  * above Copyright Notice, and the following Disclaimer and Export Compliance
00069  * provision in the documentation and/or other materials provided with the
00070  * distribution.
00071  *
00072  * 3.4. Intel retains all right, title, and interest in and to the Original
00073  * Intel Code.
00074  *
00075  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
00076  * Intel shall be used in advertising or otherwise to promote the sale, use or
00077  * other dealings in products derived from or relating to the Covered Code
00078  * without prior written authorization from Intel.
00079  *
00080  * 4. Disclaimer and Export Compliance
00081  *
00082  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
00083  * HERE.  ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
00084  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT,  ASSISTANCE,
00085  * INSTALLATION, TRAINING OR OTHER SERVICES.  INTEL WILL NOT PROVIDE ANY
00086  * UPDATES, ENHANCEMENTS OR EXTENSIONS.  INTEL SPECIFICALLY DISCLAIMS ANY
00087  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
00088  * PARTICULAR PURPOSE.
00089  *
00090  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
00091  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
00092  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
00093  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
00094  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
00095  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES.  THESE LIMITATIONS
00096  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
00097  * LIMITED REMEDY.
00098  *
00099  * 4.3. Licensee shall not export, either directly or indirectly, any of this
00100  * software or system incorporating such software without first obtaining any
00101  * required license or other approval from the U. S. Department of Commerce or
00102  * any other agency or department of the United States Government.  In the
00103  * event Licensee exports any such software from the United States or
00104  * re-exports any such software from a foreign destination, Licensee shall
00105  * ensure that the distribution and export/re-export of the software is in
00106  * compliance with all laws, regulations, orders, or other restrictions of the
00107  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
00108  * any of its subsidiaries will export/re-export any technical data, process,
00109  * software, or service, directly or indirectly, to any country for which the
00110  * United States government or any agency thereof requires an export license,
00111  * other governmental approval, or letter of assurance, without first obtaining
00112  * such license, approval or letter.
00113  *
00114  *****************************************************************************/
00115 
00116 #define __UTIDS_C__
00117 
00118 #include "acpi.h"
00119 #include "accommon.h"
00120 #include "acinterp.h"
00121 
00122 
00123 #define _COMPONENT          ACPI_UTILITIES
00124         ACPI_MODULE_NAME    ("utids")
00125 
00126 
00127 /*******************************************************************************
00128  *
00129  * FUNCTION:    AcpiUtExecute_HID
00130  *
00131  * PARAMETERS:  DeviceNode          - Node for the device
00132  *              ReturnId            - Where the string HID is returned
00133  *
00134  * RETURN:      Status
00135  *
00136  * DESCRIPTION: Executes the _HID control method that returns the hardware
00137  *              ID of the device. The HID is either an 32-bit encoded EISAID
00138  *              Integer or a String. A string is always returned. An EISAID
00139  *              is converted to a string.
00140  *
00141  *              NOTE: Internal function, no parameter validation
00142  *
00143  ******************************************************************************/
00144 
00145 ACPI_STATUS
00146 AcpiUtExecute_HID (
00147     ACPI_NAMESPACE_NODE     *DeviceNode,
00148     ACPI_DEVICE_ID          **ReturnId)
00149 {
00150     ACPI_OPERAND_OBJECT     *ObjDesc;
00151     ACPI_DEVICE_ID          *Hid;
00152     UINT32                  Length;
00153     ACPI_STATUS             Status;
00154 
00155 
00156     ACPI_FUNCTION_TRACE (UtExecute_HID);
00157 
00158 
00159     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
00160                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
00161     if (ACPI_FAILURE (Status))
00162     {
00163         return_ACPI_STATUS (Status);
00164     }
00165 
00166     /* Get the size of the String to be returned, includes null terminator */
00167 
00168     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
00169     {
00170         Length = ACPI_EISAID_STRING_SIZE;
00171     }
00172     else
00173     {
00174         Length = ObjDesc->String.Length + 1;
00175     }
00176 
00177     /* Allocate a buffer for the HID */
00178 
00179     Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
00180     if (!Hid)
00181     {
00182         Status = AE_NO_MEMORY;
00183         goto Cleanup;
00184     }
00185 
00186     /* Area for the string starts after DEVICE_ID struct */
00187 
00188     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_DEVICE_ID));
00189 
00190     /* Convert EISAID to a string or simply copy existing string */
00191 
00192     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
00193     {
00194         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
00195     }
00196     else
00197     {
00198         ACPI_STRCPY (Hid->String, ObjDesc->String.Pointer);
00199     }
00200 
00201     Hid->Length = Length;
00202     *ReturnId = Hid;
00203 
00204 
00205 Cleanup:
00206 
00207     /* On exit, we must delete the return object */
00208 
00209     AcpiUtRemoveReference (ObjDesc);
00210     return_ACPI_STATUS (Status);
00211 }
00212 
00213 
00214 /*******************************************************************************
00215  *
00216  * FUNCTION:    AcpiUtExecute_UID
00217  *
00218  * PARAMETERS:  DeviceNode          - Node for the device
00219  *              ReturnId            - Where the string UID is returned
00220  *
00221  * RETURN:      Status
00222  *
00223  * DESCRIPTION: Executes the _UID control method that returns the unique
00224  *              ID of the device. The UID is either a 64-bit Integer (NOT an
00225  *              EISAID) or a string. Always returns a string. A 64-bit integer
00226  *              is converted to a decimal string.
00227  *
00228  *              NOTE: Internal function, no parameter validation
00229  *
00230  ******************************************************************************/
00231 
00232 ACPI_STATUS
00233 AcpiUtExecute_UID (
00234     ACPI_NAMESPACE_NODE     *DeviceNode,
00235     ACPI_DEVICE_ID          **ReturnId)
00236 {
00237     ACPI_OPERAND_OBJECT     *ObjDesc;
00238     ACPI_DEVICE_ID          *Uid;
00239     UINT32                  Length;
00240     ACPI_STATUS             Status;
00241 
00242 
00243     ACPI_FUNCTION_TRACE (UtExecute_UID);
00244 
00245 
00246     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
00247                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
00248     if (ACPI_FAILURE (Status))
00249     {
00250         return_ACPI_STATUS (Status);
00251     }
00252 
00253     /* Get the size of the String to be returned, includes null terminator */
00254 
00255     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
00256     {
00257         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
00258     }
00259     else
00260     {
00261         Length = ObjDesc->String.Length + 1;
00262     }
00263 
00264     /* Allocate a buffer for the UID */
00265 
00266     Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
00267     if (!Uid)
00268     {
00269         Status = AE_NO_MEMORY;
00270         goto Cleanup;
00271     }
00272 
00273     /* Area for the string starts after DEVICE_ID struct */
00274 
00275     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_DEVICE_ID));
00276 
00277     /* Convert an Integer to string, or just copy an existing string */
00278 
00279     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
00280     {
00281         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
00282     }
00283     else
00284     {
00285         ACPI_STRCPY (Uid->String, ObjDesc->String.Pointer);
00286     }
00287 
00288     Uid->Length = Length;
00289     *ReturnId = Uid;
00290 
00291 
00292 Cleanup:
00293 
00294     /* On exit, we must delete the return object */
00295 
00296     AcpiUtRemoveReference (ObjDesc);
00297     return_ACPI_STATUS (Status);
00298 }
00299 
00300 
00301 /*******************************************************************************
00302  *
00303  * FUNCTION:    AcpiUtExecute_CID
00304  *
00305  * PARAMETERS:  DeviceNode          - Node for the device
00306  *              ReturnCidList       - Where the CID list is returned
00307  *
00308  * RETURN:      Status, list of CID strings
00309  *
00310  * DESCRIPTION: Executes the _CID control method that returns one or more
00311  *              compatible hardware IDs for the device.
00312  *
00313  *              NOTE: Internal function, no parameter validation
00314  *
00315  * A _CID method can return either a single compatible ID or a package of
00316  * compatible IDs. Each compatible ID can be one of the following:
00317  * 1) Integer (32 bit compressed EISA ID) or
00318  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
00319  *
00320  * The Integer CIDs are converted to string format by this function.
00321  *
00322  ******************************************************************************/
00323 
00324 ACPI_STATUS
00325 AcpiUtExecute_CID (
00326     ACPI_NAMESPACE_NODE     *DeviceNode,
00327     ACPI_DEVICE_ID_LIST     **ReturnCidList)
00328 {
00329     ACPI_OPERAND_OBJECT     **CidObjects;
00330     ACPI_OPERAND_OBJECT     *ObjDesc;
00331     ACPI_DEVICE_ID_LIST     *CidList;
00332     char                    *NextIdString;
00333     UINT32                  StringAreaSize;
00334     UINT32                  Length;
00335     UINT32                  CidListSize;
00336     ACPI_STATUS             Status;
00337     UINT32                  Count;
00338     UINT32                  i;
00339 
00340 
00341     ACPI_FUNCTION_TRACE (UtExecute_CID);
00342 
00343 
00344     /* Evaluate the _CID method for this device */
00345 
00346     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
00347                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
00348                 &ObjDesc);
00349     if (ACPI_FAILURE (Status))
00350     {
00351         return_ACPI_STATUS (Status);
00352     }
00353 
00354     /*
00355      * Get the count and size of the returned _CIDs. _CID can return either
00356      * a Package of Integers/Strings or a single Integer or String.
00357      * Note: This section also validates that all CID elements are of the
00358      * correct type (Integer or String).
00359      */
00360     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
00361     {
00362         Count = ObjDesc->Package.Count;
00363         CidObjects = ObjDesc->Package.Elements;
00364     }
00365     else /* Single Integer or String CID */
00366     {
00367         Count = 1;
00368         CidObjects = &ObjDesc;
00369     }
00370 
00371     StringAreaSize = 0;
00372     for (i = 0; i < Count; i++)
00373     {
00374         /* String lengths include null terminator */
00375 
00376         switch (CidObjects[i]->Common.Type)
00377         {
00378         case ACPI_TYPE_INTEGER:
00379             StringAreaSize += ACPI_EISAID_STRING_SIZE;
00380             break;
00381 
00382         case ACPI_TYPE_STRING:
00383             StringAreaSize += CidObjects[i]->String.Length + 1;
00384             break;
00385 
00386         default:
00387             Status = AE_TYPE;
00388             goto Cleanup;
00389         }
00390     }
00391 
00392     /*
00393      * Now that we know the length of the CIDs, allocate return buffer:
00394      * 1) Size of the base structure +
00395      * 2) Size of the CID DEVICE_ID array +
00396      * 3) Size of the actual CID strings
00397      */
00398     CidListSize = sizeof (ACPI_DEVICE_ID_LIST) +
00399         ((Count - 1) * sizeof (ACPI_DEVICE_ID)) +
00400         StringAreaSize;
00401 
00402     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
00403     if (!CidList)
00404     {
00405         Status = AE_NO_MEMORY;
00406         goto Cleanup;
00407     }
00408 
00409     /* Area for CID strings starts after the CID DEVICE_ID array */
00410 
00411     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
00412         ((ACPI_SIZE) Count * sizeof (ACPI_DEVICE_ID));
00413 
00414     /* Copy/convert the CIDs to the return buffer */
00415 
00416     for (i = 0; i < Count; i++)
00417     {
00418         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
00419         {
00420             /* Convert the Integer (EISAID) CID to a string */
00421 
00422             AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
00423             Length = ACPI_EISAID_STRING_SIZE;
00424         }
00425         else /* ACPI_TYPE_STRING */
00426         {
00427             /* Copy the String CID from the returned object */
00428 
00429             ACPI_STRCPY (NextIdString, CidObjects[i]->String.Pointer);
00430             Length = CidObjects[i]->String.Length + 1;
00431         }
00432 
00433         CidList->Ids[i].String = NextIdString;
00434         CidList->Ids[i].Length = Length;
00435         NextIdString += Length;
00436     }
00437 
00438     /* Finish the CID list */
00439 
00440     CidList->Count = Count;
00441     CidList->ListSize = CidListSize;
00442     *ReturnCidList = CidList;
00443 
00444 
00445 Cleanup:
00446 
00447     /* On exit, we must delete the _CID return object */
00448 
00449     AcpiUtRemoveReference (ObjDesc);
00450     return_ACPI_STATUS (Status);
00451 }
00452 

Generated on Sun May 27 2012 04:27:23 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.