157190917SDana Myers /******************************************************************************
257190917SDana Myers  *
37b1019a6SJerry Jelinek  * Module Name: utids - support for device IDs - HID, UID, CID, SUB, CLS
457190917SDana Myers  *
557190917SDana Myers  *****************************************************************************/
657190917SDana Myers 
7*35786f68SRobert Mustacchi /******************************************************************************
8*35786f68SRobert Mustacchi  *
9*35786f68SRobert Mustacchi  * 1. Copyright Notice
10*35786f68SRobert Mustacchi  *
11*35786f68SRobert Mustacchi  * Some or all of this work - Copyright (c) 1999 - 2018, Intel Corp.
1257190917SDana Myers  * All rights reserved.
1357190917SDana Myers  *
14*35786f68SRobert Mustacchi  * 2. License
15*35786f68SRobert Mustacchi  *
16*35786f68SRobert Mustacchi  * 2.1. This is your license from Intel Corp. under its intellectual property
17*35786f68SRobert Mustacchi  * rights. You may have additional license terms from the party that provided
18*35786f68SRobert Mustacchi  * you this software, covering your right to use that party's intellectual
19*35786f68SRobert Mustacchi  * property rights.
20*35786f68SRobert Mustacchi  *
21*35786f68SRobert Mustacchi  * 2.2. Intel grants, free of charge, to any person ("Licensee") obtaining a
22*35786f68SRobert Mustacchi  * copy of the source code appearing in this file ("Covered Code") an
23*35786f68SRobert Mustacchi  * irrevocable, perpetual, worldwide license under Intel's copyrights in the
24*35786f68SRobert Mustacchi  * base code distributed originally by Intel ("Original Intel Code") to copy,
25*35786f68SRobert Mustacchi  * make derivatives, distribute, use and display any portion of the Covered
26*35786f68SRobert Mustacchi  * Code in any form, with the right to sublicense such rights; and
27*35786f68SRobert Mustacchi  *
28*35786f68SRobert Mustacchi  * 2.3. Intel grants Licensee a non-exclusive and non-transferable patent
29*35786f68SRobert Mustacchi  * license (with the right to sublicense), under only those claims of Intel
30*35786f68SRobert Mustacchi  * patents that are infringed by the Original Intel Code, to make, use, sell,
31*35786f68SRobert Mustacchi  * offer to sell, and import the Covered Code and derivative works thereof
32*35786f68SRobert Mustacchi  * solely to the minimum extent necessary to exercise the above copyright
33*35786f68SRobert Mustacchi  * license, and in no event shall the patent license extend to any additions
34*35786f68SRobert Mustacchi  * to or modifications of the Original Intel Code. No other license or right
35*35786f68SRobert Mustacchi  * is granted directly or by implication, estoppel or otherwise;
36*35786f68SRobert Mustacchi  *
37*35786f68SRobert Mustacchi  * The above copyright and patent license is granted only if the following
38*35786f68SRobert Mustacchi  * conditions are met:
39*35786f68SRobert Mustacchi  *
40*35786f68SRobert Mustacchi  * 3. Conditions
41*35786f68SRobert Mustacchi  *
42*35786f68SRobert Mustacchi  * 3.1. Redistribution of Source with Rights to Further Distribute Source.
43*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
44*35786f68SRobert Mustacchi  * Code or modification with rights to further distribute source must include
45*35786f68SRobert Mustacchi  * the above Copyright Notice, the above License, this list of Conditions,
46*35786f68SRobert Mustacchi  * and the following Disclaimer and Export Compliance provision. In addition,
47*35786f68SRobert Mustacchi  * Licensee must cause all Covered Code to which Licensee contributes to
48*35786f68SRobert Mustacchi  * contain a file documenting the changes Licensee made to create that Covered
49*35786f68SRobert Mustacchi  * Code and the date of any change. Licensee must include in that file the
50*35786f68SRobert Mustacchi  * documentation of any changes made by any predecessor Licensee. Licensee
51*35786f68SRobert Mustacchi  * must include a prominent statement that the modification is derived,
52*35786f68SRobert Mustacchi  * directly or indirectly, from Original Intel Code.
53*35786f68SRobert Mustacchi  *
54*35786f68SRobert Mustacchi  * 3.2. Redistribution of Source with no Rights to Further Distribute Source.
55*35786f68SRobert Mustacchi  * Redistribution of source code of any substantial portion of the Covered
56*35786f68SRobert Mustacchi  * Code or modification without rights to further distribute source must
57*35786f68SRobert Mustacchi  * include the following Disclaimer and Export Compliance provision in the
58*35786f68SRobert Mustacchi  * documentation and/or other materials provided with distribution. In
59*35786f68SRobert Mustacchi  * addition, Licensee may not authorize further sublicense of source of any
60*35786f68SRobert Mustacchi  * portion of the Covered Code, and must include terms to the effect that the
61*35786f68SRobert Mustacchi  * license from Licensee to its licensee is limited to the intellectual
62*35786f68SRobert Mustacchi  * property embodied in the software Licensee provides to its licensee, and
63*35786f68SRobert Mustacchi  * not to intellectual property embodied in modifications its licensee may
64*35786f68SRobert Mustacchi  * make.
65*35786f68SRobert Mustacchi  *
66*35786f68SRobert Mustacchi  * 3.3. Redistribution of Executable. Redistribution in executable form of any
67*35786f68SRobert Mustacchi  * substantial portion of the Covered Code or modification must reproduce the
68*35786f68SRobert Mustacchi  * above Copyright Notice, and the following Disclaimer and Export Compliance
69*35786f68SRobert Mustacchi  * provision in the documentation and/or other materials provided with the
70*35786f68SRobert Mustacchi  * distribution.
71*35786f68SRobert Mustacchi  *
72*35786f68SRobert Mustacchi  * 3.4. Intel retains all right, title, and interest in and to the Original
73*35786f68SRobert Mustacchi  * Intel Code.
74*35786f68SRobert Mustacchi  *
75*35786f68SRobert Mustacchi  * 3.5. Neither the name Intel nor any other trademark owned or controlled by
76*35786f68SRobert Mustacchi  * Intel shall be used in advertising or otherwise to promote the sale, use or
77*35786f68SRobert Mustacchi  * other dealings in products derived from or relating to the Covered Code
78*35786f68SRobert Mustacchi  * without prior written authorization from Intel.
79*35786f68SRobert Mustacchi  *
80*35786f68SRobert Mustacchi  * 4. Disclaimer and Export Compliance
81*35786f68SRobert Mustacchi  *
82*35786f68SRobert Mustacchi  * 4.1. INTEL MAKES NO WARRANTY OF ANY KIND REGARDING ANY SOFTWARE PROVIDED
83*35786f68SRobert Mustacchi  * HERE. ANY SOFTWARE ORIGINATING FROM INTEL OR DERIVED FROM INTEL SOFTWARE
84*35786f68SRobert Mustacchi  * IS PROVIDED "AS IS," AND INTEL WILL NOT PROVIDE ANY SUPPORT, ASSISTANCE,
85*35786f68SRobert Mustacchi  * INSTALLATION, TRAINING OR OTHER SERVICES. INTEL WILL NOT PROVIDE ANY
86*35786f68SRobert Mustacchi  * UPDATES, ENHANCEMENTS OR EXTENSIONS. INTEL SPECIFICALLY DISCLAIMS ANY
87*35786f68SRobert Mustacchi  * IMPLIED WARRANTIES OF MERCHANTABILITY, NONINFRINGEMENT AND FITNESS FOR A
88*35786f68SRobert Mustacchi  * PARTICULAR PURPOSE.
89*35786f68SRobert Mustacchi  *
90*35786f68SRobert Mustacchi  * 4.2. IN NO EVENT SHALL INTEL HAVE ANY LIABILITY TO LICENSEE, ITS LICENSEES
91*35786f68SRobert Mustacchi  * OR ANY OTHER THIRD PARTY, FOR ANY LOST PROFITS, LOST DATA, LOSS OF USE OR
92*35786f68SRobert Mustacchi  * COSTS OF PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES, OR FOR ANY INDIRECT,
93*35786f68SRobert Mustacchi  * SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THIS AGREEMENT, UNDER ANY
94*35786f68SRobert Mustacchi  * CAUSE OF ACTION OR THEORY OF LIABILITY, AND IRRESPECTIVE OF WHETHER INTEL
95*35786f68SRobert Mustacchi  * HAS ADVANCE NOTICE OF THE POSSIBILITY OF SUCH DAMAGES. THESE LIMITATIONS
96*35786f68SRobert Mustacchi  * SHALL APPLY NOTWITHSTANDING THE FAILURE OF THE ESSENTIAL PURPOSE OF ANY
97*35786f68SRobert Mustacchi  * LIMITED REMEDY.
98*35786f68SRobert Mustacchi  *
99*35786f68SRobert Mustacchi  * 4.3. Licensee shall not export, either directly or indirectly, any of this
100*35786f68SRobert Mustacchi  * software or system incorporating such software without first obtaining any
101*35786f68SRobert Mustacchi  * required license or other approval from the U. S. Department of Commerce or
102*35786f68SRobert Mustacchi  * any other agency or department of the United States Government. In the
103*35786f68SRobert Mustacchi  * event Licensee exports any such software from the United States or
104*35786f68SRobert Mustacchi  * re-exports any such software from a foreign destination, Licensee shall
105*35786f68SRobert Mustacchi  * ensure that the distribution and export/re-export of the software is in
106*35786f68SRobert Mustacchi  * compliance with all laws, regulations, orders, or other restrictions of the
107*35786f68SRobert Mustacchi  * U.S. Export Administration Regulations. Licensee agrees that neither it nor
108*35786f68SRobert Mustacchi  * any of its subsidiaries will export/re-export any technical data, process,
109*35786f68SRobert Mustacchi  * software, or service, directly or indirectly, to any country for which the
110*35786f68SRobert Mustacchi  * United States government or any agency thereof requires an export license,
111*35786f68SRobert Mustacchi  * other governmental approval, or letter of assurance, without first obtaining
112*35786f68SRobert Mustacchi  * such license, approval or letter.
113*35786f68SRobert Mustacchi  *
114*35786f68SRobert Mustacchi  *****************************************************************************
115*35786f68SRobert Mustacchi  *
116*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
117*35786f68SRobert Mustacchi  * following license:
118*35786f68SRobert Mustacchi  *
11926f3cdf0SGordon Ross  * Redistribution and use in source and binary forms, with or without
12026f3cdf0SGordon Ross  * modification, are permitted provided that the following conditions
12126f3cdf0SGordon Ross  * are met:
12226f3cdf0SGordon Ross  * 1. Redistributions of source code must retain the above copyright
12326f3cdf0SGordon Ross  *    notice, this list of conditions, and the following disclaimer,
12426f3cdf0SGordon Ross  *    without modification.
12526f3cdf0SGordon Ross  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
12626f3cdf0SGordon Ross  *    substantially similar to the "NO WARRANTY" disclaimer below
12726f3cdf0SGordon Ross  *    ("Disclaimer") and any redistribution must be conditioned upon
12826f3cdf0SGordon Ross  *    including a substantially similar Disclaimer requirement for further
12926f3cdf0SGordon Ross  *    binary redistribution.
13026f3cdf0SGordon Ross  * 3. Neither the names of the above-listed copyright holders nor the names
13126f3cdf0SGordon Ross  *    of any contributors may be used to endorse or promote products derived
13226f3cdf0SGordon Ross  *    from this software without specific prior written permission.
13326f3cdf0SGordon Ross  *
13426f3cdf0SGordon Ross  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
13526f3cdf0SGordon Ross  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
136*35786f68SRobert Mustacchi  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
13726f3cdf0SGordon Ross  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
138*35786f68SRobert Mustacchi  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
139*35786f68SRobert Mustacchi  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
140*35786f68SRobert Mustacchi  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
141*35786f68SRobert Mustacchi  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
142*35786f68SRobert Mustacchi  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
143*35786f68SRobert Mustacchi  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
144*35786f68SRobert Mustacchi  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
145*35786f68SRobert Mustacchi  *
146*35786f68SRobert Mustacchi  * Alternatively, you may choose to be licensed under the terms of the
147*35786f68SRobert Mustacchi  * GNU General Public License ("GPL") version 2 as published by the Free
148*35786f68SRobert Mustacchi  * Software Foundation.
149*35786f68SRobert Mustacchi  *
150*35786f68SRobert Mustacchi  *****************************************************************************/
15157190917SDana Myers 
15257190917SDana Myers #include "acpi.h"
15357190917SDana Myers #include "accommon.h"
15457190917SDana Myers #include "acinterp.h"
15557190917SDana Myers 
15657190917SDana Myers 
15757190917SDana Myers #define _COMPONENT          ACPI_UTILITIES
15857190917SDana Myers         ACPI_MODULE_NAME    ("utids")
15957190917SDana Myers 
16057190917SDana Myers 
16157190917SDana Myers /*******************************************************************************
16257190917SDana Myers  *
16357190917SDana Myers  * FUNCTION:    AcpiUtExecute_HID
16457190917SDana Myers  *
16557190917SDana Myers  * PARAMETERS:  DeviceNode          - Node for the device
16657190917SDana Myers  *              ReturnId            - Where the string HID is returned
16757190917SDana Myers  *
16857190917SDana Myers  * RETURN:      Status
16957190917SDana Myers  *
17057190917SDana Myers  * DESCRIPTION: Executes the _HID control method that returns the hardware
17157190917SDana Myers  *              ID of the device. The HID is either an 32-bit encoded EISAID
17257190917SDana Myers  *              Integer or a String. A string is always returned. An EISAID
17357190917SDana Myers  *              is converted to a string.
17457190917SDana Myers  *
17557190917SDana Myers  *              NOTE: Internal function, no parameter validation
17657190917SDana Myers  *
17757190917SDana Myers  ******************************************************************************/
17857190917SDana Myers 
17957190917SDana Myers ACPI_STATUS
AcpiUtExecute_HID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)18057190917SDana Myers AcpiUtExecute_HID (
18157190917SDana Myers     ACPI_NAMESPACE_NODE     *DeviceNode,
1827b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      **ReturnId)
18357190917SDana Myers {
18457190917SDana Myers     ACPI_OPERAND_OBJECT     *ObjDesc;
1857b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      *Hid;
18657190917SDana Myers     UINT32                  Length;
18757190917SDana Myers     ACPI_STATUS             Status;
18857190917SDana Myers 
18957190917SDana Myers 
19057190917SDana Myers     ACPI_FUNCTION_TRACE (UtExecute_HID);
19157190917SDana Myers 
19257190917SDana Myers 
19357190917SDana Myers     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
1947b1019a6SJerry Jelinek         ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
19557190917SDana Myers     if (ACPI_FAILURE (Status))
19657190917SDana Myers     {
19757190917SDana Myers         return_ACPI_STATUS (Status);
19857190917SDana Myers     }
19957190917SDana Myers 
20057190917SDana Myers     /* Get the size of the String to be returned, includes null terminator */
20157190917SDana Myers 
20257190917SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
20357190917SDana Myers     {
20457190917SDana Myers         Length = ACPI_EISAID_STRING_SIZE;
20557190917SDana Myers     }
20657190917SDana Myers     else
20757190917SDana Myers     {
20857190917SDana Myers         Length = ObjDesc->String.Length + 1;
20957190917SDana Myers     }
21057190917SDana Myers 
21157190917SDana Myers     /* Allocate a buffer for the HID */
21257190917SDana Myers 
2137b1019a6SJerry Jelinek     Hid = ACPI_ALLOCATE_ZEROED (
2147b1019a6SJerry Jelinek         sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
21557190917SDana Myers     if (!Hid)
21657190917SDana Myers     {
21757190917SDana Myers         Status = AE_NO_MEMORY;
21857190917SDana Myers         goto Cleanup;
21957190917SDana Myers     }
22057190917SDana Myers 
2217b1019a6SJerry Jelinek     /* Area for the string starts after PNP_DEVICE_ID struct */
22257190917SDana Myers 
2237b1019a6SJerry Jelinek     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_PNP_DEVICE_ID));
22457190917SDana Myers 
22557190917SDana Myers     /* Convert EISAID to a string or simply copy existing string */
22657190917SDana Myers 
22757190917SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
22857190917SDana Myers     {
22957190917SDana Myers         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
23057190917SDana Myers     }
23157190917SDana Myers     else
23257190917SDana Myers     {
2337b1019a6SJerry Jelinek         strcpy (Hid->String, ObjDesc->String.Pointer);
23457190917SDana Myers     }
23557190917SDana Myers 
23657190917SDana Myers     Hid->Length = Length;
23757190917SDana Myers     *ReturnId = Hid;
23857190917SDana Myers 
23957190917SDana Myers 
24057190917SDana Myers Cleanup:
24157190917SDana Myers 
24257190917SDana Myers     /* On exit, we must delete the return object */
24357190917SDana Myers 
24457190917SDana Myers     AcpiUtRemoveReference (ObjDesc);
24557190917SDana Myers     return_ACPI_STATUS (Status);
24657190917SDana Myers }
24757190917SDana Myers 
24857190917SDana Myers 
24957190917SDana Myers /*******************************************************************************
25057190917SDana Myers  *
25157190917SDana Myers  * FUNCTION:    AcpiUtExecute_UID
25257190917SDana Myers  *
25357190917SDana Myers  * PARAMETERS:  DeviceNode          - Node for the device
25457190917SDana Myers  *              ReturnId            - Where the string UID is returned
25557190917SDana Myers  *
25657190917SDana Myers  * RETURN:      Status
25757190917SDana Myers  *
25857190917SDana Myers  * DESCRIPTION: Executes the _UID control method that returns the unique
25957190917SDana Myers  *              ID of the device. The UID is either a 64-bit Integer (NOT an
26057190917SDana Myers  *              EISAID) or a string. Always returns a string. A 64-bit integer
26157190917SDana Myers  *              is converted to a decimal string.
26257190917SDana Myers  *
26357190917SDana Myers  *              NOTE: Internal function, no parameter validation
26457190917SDana Myers  *
26557190917SDana Myers  ******************************************************************************/
26657190917SDana Myers 
26757190917SDana Myers ACPI_STATUS
AcpiUtExecute_UID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)26857190917SDana Myers AcpiUtExecute_UID (
26957190917SDana Myers     ACPI_NAMESPACE_NODE     *DeviceNode,
2707b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      **ReturnId)
27157190917SDana Myers {
27257190917SDana Myers     ACPI_OPERAND_OBJECT     *ObjDesc;
2737b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      *Uid;
27457190917SDana Myers     UINT32                  Length;
27557190917SDana Myers     ACPI_STATUS             Status;
27657190917SDana Myers 
27757190917SDana Myers 
27857190917SDana Myers     ACPI_FUNCTION_TRACE (UtExecute_UID);
27957190917SDana Myers 
28057190917SDana Myers 
28157190917SDana Myers     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
2827b1019a6SJerry Jelinek         ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
28357190917SDana Myers     if (ACPI_FAILURE (Status))
28457190917SDana Myers     {
28557190917SDana Myers         return_ACPI_STATUS (Status);
28657190917SDana Myers     }
28757190917SDana Myers 
28857190917SDana Myers     /* Get the size of the String to be returned, includes null terminator */
28957190917SDana Myers 
29057190917SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
29157190917SDana Myers     {
29257190917SDana Myers         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
29357190917SDana Myers     }
29457190917SDana Myers     else
29557190917SDana Myers     {
29657190917SDana Myers         Length = ObjDesc->String.Length + 1;
29757190917SDana Myers     }
29857190917SDana Myers 
29957190917SDana Myers     /* Allocate a buffer for the UID */
30057190917SDana Myers 
3017b1019a6SJerry Jelinek     Uid = ACPI_ALLOCATE_ZEROED (
3027b1019a6SJerry Jelinek         sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
30357190917SDana Myers     if (!Uid)
30457190917SDana Myers     {
30557190917SDana Myers         Status = AE_NO_MEMORY;
30657190917SDana Myers         goto Cleanup;
30757190917SDana Myers     }
30857190917SDana Myers 
3097b1019a6SJerry Jelinek     /* Area for the string starts after PNP_DEVICE_ID struct */
31057190917SDana Myers 
3117b1019a6SJerry Jelinek     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_PNP_DEVICE_ID));
31257190917SDana Myers 
31357190917SDana Myers     /* Convert an Integer to string, or just copy an existing string */
31457190917SDana Myers 
31557190917SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
31657190917SDana Myers     {
31757190917SDana Myers         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
31857190917SDana Myers     }
31957190917SDana Myers     else
32057190917SDana Myers     {
3217b1019a6SJerry Jelinek         strcpy (Uid->String, ObjDesc->String.Pointer);
32257190917SDana Myers     }
32357190917SDana Myers 
32457190917SDana Myers     Uid->Length = Length;
32557190917SDana Myers     *ReturnId = Uid;
32657190917SDana Myers 
32757190917SDana Myers 
32857190917SDana Myers Cleanup:
32957190917SDana Myers 
33057190917SDana Myers     /* On exit, we must delete the return object */
33157190917SDana Myers 
33257190917SDana Myers     AcpiUtRemoveReference (ObjDesc);
33357190917SDana Myers     return_ACPI_STATUS (Status);
33457190917SDana Myers }
33557190917SDana Myers 
33657190917SDana Myers 
33757190917SDana Myers /*******************************************************************************
33857190917SDana Myers  *
33957190917SDana Myers  * FUNCTION:    AcpiUtExecute_CID
34057190917SDana Myers  *
34157190917SDana Myers  * PARAMETERS:  DeviceNode          - Node for the device
34257190917SDana Myers  *              ReturnCidList       - Where the CID list is returned
34357190917SDana Myers  *
34457190917SDana Myers  * RETURN:      Status, list of CID strings
34557190917SDana Myers  *
34657190917SDana Myers  * DESCRIPTION: Executes the _CID control method that returns one or more
34757190917SDana Myers  *              compatible hardware IDs for the device.
34857190917SDana Myers  *
34957190917SDana Myers  *              NOTE: Internal function, no parameter validation
35057190917SDana Myers  *
35157190917SDana Myers  * A _CID method can return either a single compatible ID or a package of
35257190917SDana Myers  * compatible IDs. Each compatible ID can be one of the following:
35357190917SDana Myers  * 1) Integer (32 bit compressed EISA ID) or
35457190917SDana Myers  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
35557190917SDana Myers  *
35657190917SDana Myers  * The Integer CIDs are converted to string format by this function.
35757190917SDana Myers  *
35857190917SDana Myers  ******************************************************************************/
35957190917SDana Myers 
36057190917SDana Myers ACPI_STATUS
AcpiUtExecute_CID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID_LIST ** ReturnCidList)36157190917SDana Myers AcpiUtExecute_CID (
36257190917SDana Myers     ACPI_NAMESPACE_NODE     *DeviceNode,
3637b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID_LIST **ReturnCidList)
36457190917SDana Myers {
36557190917SDana Myers     ACPI_OPERAND_OBJECT     **CidObjects;
36657190917SDana Myers     ACPI_OPERAND_OBJECT     *ObjDesc;
3677b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID_LIST *CidList;
36857190917SDana Myers     char                    *NextIdString;
36957190917SDana Myers     UINT32                  StringAreaSize;
37057190917SDana Myers     UINT32                  Length;
37157190917SDana Myers     UINT32                  CidListSize;
37257190917SDana Myers     ACPI_STATUS             Status;
37357190917SDana Myers     UINT32                  Count;
37457190917SDana Myers     UINT32                  i;
37557190917SDana Myers 
37657190917SDana Myers 
37757190917SDana Myers     ACPI_FUNCTION_TRACE (UtExecute_CID);
37857190917SDana Myers 
37957190917SDana Myers 
38057190917SDana Myers     /* Evaluate the _CID method for this device */
38157190917SDana Myers 
38257190917SDana Myers     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
3837b1019a6SJerry Jelinek         ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
3847b1019a6SJerry Jelinek         &ObjDesc);
38557190917SDana Myers     if (ACPI_FAILURE (Status))
38657190917SDana Myers     {
38757190917SDana Myers         return_ACPI_STATUS (Status);
38857190917SDana Myers     }
38957190917SDana Myers 
39057190917SDana Myers     /*
39157190917SDana Myers      * Get the count and size of the returned _CIDs. _CID can return either
39257190917SDana Myers      * a Package of Integers/Strings or a single Integer or String.
39357190917SDana Myers      * Note: This section also validates that all CID elements are of the
39457190917SDana Myers      * correct type (Integer or String).
39557190917SDana Myers      */
39657190917SDana Myers     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
39757190917SDana Myers     {
39857190917SDana Myers         Count = ObjDesc->Package.Count;
39957190917SDana Myers         CidObjects = ObjDesc->Package.Elements;
40057190917SDana Myers     }
40157190917SDana Myers     else /* Single Integer or String CID */
40257190917SDana Myers     {
40357190917SDana Myers         Count = 1;
40457190917SDana Myers         CidObjects = &ObjDesc;
40557190917SDana Myers     }
40657190917SDana Myers 
40757190917SDana Myers     StringAreaSize = 0;
40857190917SDana Myers     for (i = 0; i < Count; i++)
40957190917SDana Myers     {
41057190917SDana Myers         /* String lengths include null terminator */
41157190917SDana Myers 
41257190917SDana Myers         switch (CidObjects[i]->Common.Type)
41357190917SDana Myers         {
41457190917SDana Myers         case ACPI_TYPE_INTEGER:
4157b1019a6SJerry Jelinek 
41657190917SDana Myers             StringAreaSize += ACPI_EISAID_STRING_SIZE;
41757190917SDana Myers             break;
41857190917SDana Myers 
41957190917SDana Myers         case ACPI_TYPE_STRING:
4207b1019a6SJerry Jelinek 
42157190917SDana Myers             StringAreaSize += CidObjects[i]->String.Length + 1;
42257190917SDana Myers             break;
42357190917SDana Myers 
42457190917SDana Myers         default:
4257b1019a6SJerry Jelinek 
42657190917SDana Myers             Status = AE_TYPE;
42757190917SDana Myers             goto Cleanup;
42857190917SDana Myers         }
42957190917SDana Myers     }
43057190917SDana Myers 
43157190917SDana Myers     /*
43257190917SDana Myers      * Now that we know the length of the CIDs, allocate return buffer:
43357190917SDana Myers      * 1) Size of the base structure +
4347b1019a6SJerry Jelinek      * 2) Size of the CID PNP_DEVICE_ID array +
43557190917SDana Myers      * 3) Size of the actual CID strings
43657190917SDana Myers      */
4377b1019a6SJerry Jelinek     CidListSize = sizeof (ACPI_PNP_DEVICE_ID_LIST) +
4387b1019a6SJerry Jelinek         ((Count - 1) * sizeof (ACPI_PNP_DEVICE_ID)) +
43957190917SDana Myers         StringAreaSize;
44057190917SDana Myers 
44157190917SDana Myers     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
44257190917SDana Myers     if (!CidList)
44357190917SDana Myers     {
44457190917SDana Myers         Status = AE_NO_MEMORY;
44557190917SDana Myers         goto Cleanup;
44657190917SDana Myers     }
44757190917SDana Myers 
4487b1019a6SJerry Jelinek     /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
44957190917SDana Myers 
45057190917SDana Myers     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
4517b1019a6SJerry Jelinek         ((ACPI_SIZE) Count * sizeof (ACPI_PNP_DEVICE_ID));
45257190917SDana Myers 
45357190917SDana Myers     /* Copy/convert the CIDs to the return buffer */
45457190917SDana Myers 
45557190917SDana Myers     for (i = 0; i < Count; i++)
45657190917SDana Myers     {
45757190917SDana Myers         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
45857190917SDana Myers         {
45957190917SDana Myers             /* Convert the Integer (EISAID) CID to a string */
46057190917SDana Myers 
4617b1019a6SJerry Jelinek             AcpiExEisaIdToString (
4627b1019a6SJerry Jelinek                 NextIdString, CidObjects[i]->Integer.Value);
46357190917SDana Myers             Length = ACPI_EISAID_STRING_SIZE;
46457190917SDana Myers         }
46557190917SDana Myers         else /* ACPI_TYPE_STRING */
46657190917SDana Myers         {
46757190917SDana Myers             /* Copy the String CID from the returned object */
46857190917SDana Myers 
4697b1019a6SJerry Jelinek             strcpy (NextIdString, CidObjects[i]->String.Pointer);
47057190917SDana Myers             Length = CidObjects[i]->String.Length + 1;
47157190917SDana Myers         }
47257190917SDana Myers 
47357190917SDana Myers         CidList->Ids[i].String = NextIdString;
47457190917SDana Myers         CidList->Ids[i].Length = Length;
47557190917SDana Myers         NextIdString += Length;
47657190917SDana Myers     }
47757190917SDana Myers 
47857190917SDana Myers     /* Finish the CID list */
47957190917SDana Myers 
48057190917SDana Myers     CidList->Count = Count;
48157190917SDana Myers     CidList->ListSize = CidListSize;
48257190917SDana Myers     *ReturnCidList = CidList;
48357190917SDana Myers 
48457190917SDana Myers 
48557190917SDana Myers Cleanup:
48657190917SDana Myers 
48757190917SDana Myers     /* On exit, we must delete the _CID return object */
48857190917SDana Myers 
48957190917SDana Myers     AcpiUtRemoveReference (ObjDesc);
49057190917SDana Myers     return_ACPI_STATUS (Status);
49157190917SDana Myers }
49257190917SDana Myers 
4937b1019a6SJerry Jelinek 
4947b1019a6SJerry Jelinek /*******************************************************************************
4957b1019a6SJerry Jelinek  *
4967b1019a6SJerry Jelinek  * FUNCTION:    AcpiUtExecute_CLS
4977b1019a6SJerry Jelinek  *
4987b1019a6SJerry Jelinek  * PARAMETERS:  DeviceNode          - Node for the device
4997b1019a6SJerry Jelinek  *              ReturnId            - Where the _CLS is returned
5007b1019a6SJerry Jelinek  *
5017b1019a6SJerry Jelinek  * RETURN:      Status
5027b1019a6SJerry Jelinek  *
5037b1019a6SJerry Jelinek  * DESCRIPTION: Executes the _CLS control method that returns PCI-defined
5047b1019a6SJerry Jelinek  *              class code of the device. The _CLS value is always a package
5057b1019a6SJerry Jelinek  *              containing PCI class information as a list of integers.
5067b1019a6SJerry Jelinek  *              The returned string has format "BBSSPP", where:
5077b1019a6SJerry Jelinek  *                BB = Base-class code
5087b1019a6SJerry Jelinek  *                SS = Sub-class code
5097b1019a6SJerry Jelinek  *                PP = Programming Interface code
5107b1019a6SJerry Jelinek  *
5117b1019a6SJerry Jelinek  ******************************************************************************/
5127b1019a6SJerry Jelinek 
5137b1019a6SJerry Jelinek ACPI_STATUS
AcpiUtExecute_CLS(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)5147b1019a6SJerry Jelinek AcpiUtExecute_CLS (
5157b1019a6SJerry Jelinek     ACPI_NAMESPACE_NODE     *DeviceNode,
5167b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      **ReturnId)
5177b1019a6SJerry Jelinek {
5187b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     *ObjDesc;
5197b1019a6SJerry Jelinek     ACPI_OPERAND_OBJECT     **ClsObjects;
5207b1019a6SJerry Jelinek     UINT32                  Count;
5217b1019a6SJerry Jelinek     ACPI_PNP_DEVICE_ID      *Cls;
5227b1019a6SJerry Jelinek     UINT32                  Length;
5237b1019a6SJerry Jelinek     ACPI_STATUS             Status;
5247b1019a6SJerry Jelinek     UINT8                   ClassCode[3] = {0, 0, 0};
5257b1019a6SJerry Jelinek 
5267b1019a6SJerry Jelinek 
5277b1019a6SJerry Jelinek     ACPI_FUNCTION_TRACE (UtExecute_CLS);
5287b1019a6SJerry Jelinek 
5297b1019a6SJerry Jelinek 
5307b1019a6SJerry Jelinek     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CLS,
5317b1019a6SJerry Jelinek         ACPI_BTYPE_PACKAGE, &ObjDesc);
5327b1019a6SJerry Jelinek     if (ACPI_FAILURE (Status))
5337b1019a6SJerry Jelinek     {
5347b1019a6SJerry Jelinek         return_ACPI_STATUS (Status);
5357b1019a6SJerry Jelinek     }
5367b1019a6SJerry Jelinek 
5377b1019a6SJerry Jelinek     /* Get the size of the String to be returned, includes null terminator */
5387b1019a6SJerry Jelinek 
5397b1019a6SJerry Jelinek     Length = ACPI_PCICLS_STRING_SIZE;
5407b1019a6SJerry Jelinek     ClsObjects = ObjDesc->Package.Elements;
5417b1019a6SJerry Jelinek     Count = ObjDesc->Package.Count;
5427b1019a6SJerry Jelinek 
5437b1019a6SJerry Jelinek     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
5447b1019a6SJerry Jelinek     {
5457b1019a6SJerry Jelinek         if (Count > 0 && ClsObjects[0]->Common.Type == ACPI_TYPE_INTEGER)
5467b1019a6SJerry Jelinek         {
5477b1019a6SJerry Jelinek             ClassCode[0] = (UINT8) ClsObjects[0]->Integer.Value;
5487b1019a6SJerry Jelinek         }
5497b1019a6SJerry Jelinek         if (Count > 1 && ClsObjects[1]->Common.Type == ACPI_TYPE_INTEGER)
5507b1019a6SJerry Jelinek         {
5517b1019a6SJerry Jelinek             ClassCode[1] = (UINT8) ClsObjects[1]->Integer.Value;
5527b1019a6SJerry Jelinek         }
5537b1019a6SJerry Jelinek         if (Count > 2 && ClsObjects[2]->Common.Type == ACPI_TYPE_INTEGER)
5547b1019a6SJerry Jelinek         {
5557b1019a6SJerry Jelinek             ClassCode[2] = (UINT8) ClsObjects[2]->Integer.Value;
5567b1019a6SJerry Jelinek         }
5577b1019a6SJerry Jelinek     }
5587b1019a6SJerry Jelinek 
5597b1019a6SJerry Jelinek     /* Allocate a buffer for the CLS */
5607b1019a6SJerry Jelinek 
5617b1019a6SJerry Jelinek     Cls = ACPI_ALLOCATE_ZEROED (
5627b1019a6SJerry Jelinek         sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
5637b1019a6SJerry Jelinek     if (!Cls)
5647b1019a6SJerry Jelinek     {
5657b1019a6SJerry Jelinek         Status = AE_NO_MEMORY;
5667b1019a6SJerry Jelinek         goto Cleanup;
5677b1019a6SJerry Jelinek     }
5687b1019a6SJerry Jelinek 
5697b1019a6SJerry Jelinek     /* Area for the string starts after PNP_DEVICE_ID struct */
5707b1019a6SJerry Jelinek 
5717b1019a6SJerry Jelinek     Cls->String = ACPI_ADD_PTR (char, Cls, sizeof (ACPI_PNP_DEVICE_ID));
5727b1019a6SJerry Jelinek 
5737b1019a6SJerry Jelinek     /* Simply copy existing string */
5747b1019a6SJerry Jelinek 
5757b1019a6SJerry Jelinek     AcpiExPciClsToString (Cls->String, ClassCode);
5767b1019a6SJerry Jelinek     Cls->Length = Length;
5777b1019a6SJerry Jelinek     *ReturnId = Cls;
5787b1019a6SJerry Jelinek 
5797b1019a6SJerry Jelinek 
5807b1019a6SJerry Jelinek Cleanup:
5817b1019a6SJerry Jelinek 
5827b1019a6SJerry Jelinek     /* On exit, we must delete the return object */
5837b1019a6SJerry Jelinek 
5847b1019a6SJerry Jelinek     AcpiUtRemoveReference (ObjDesc);
5857b1019a6SJerry Jelinek     return_ACPI_STATUS (Status);
5867b1019a6SJerry Jelinek }
587