xref: /minix3/minix/drivers/power/acpi/utilities/utids.c (revision 29492bb71c7148a089a5afafa0c99409161218df)
1433d6423SLionel Sambuc /******************************************************************************
2433d6423SLionel Sambuc  *
3433d6423SLionel Sambuc  * Module Name: utids - support for device IDs - HID, UID, CID
4433d6423SLionel Sambuc  *
5433d6423SLionel Sambuc  *****************************************************************************/
6433d6423SLionel Sambuc 
7*29492bb7SDavid van Moolenbroek /*
8*29492bb7SDavid van Moolenbroek  * Copyright (C) 2000 - 2014, Intel Corp.
9433d6423SLionel Sambuc  * All rights reserved.
10433d6423SLionel Sambuc  *
11*29492bb7SDavid van Moolenbroek  * Redistribution and use in source and binary forms, with or without
12*29492bb7SDavid van Moolenbroek  * modification, are permitted provided that the following conditions
13*29492bb7SDavid van Moolenbroek  * are met:
14*29492bb7SDavid van Moolenbroek  * 1. Redistributions of source code must retain the above copyright
15*29492bb7SDavid van Moolenbroek  *    notice, this list of conditions, and the following disclaimer,
16*29492bb7SDavid van Moolenbroek  *    without modification.
17*29492bb7SDavid van Moolenbroek  * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18*29492bb7SDavid van Moolenbroek  *    substantially similar to the "NO WARRANTY" disclaimer below
19*29492bb7SDavid van Moolenbroek  *    ("Disclaimer") and any redistribution must be conditioned upon
20*29492bb7SDavid van Moolenbroek  *    including a substantially similar Disclaimer requirement for further
21*29492bb7SDavid van Moolenbroek  *    binary redistribution.
22*29492bb7SDavid van Moolenbroek  * 3. Neither the names of the above-listed copyright holders nor the names
23*29492bb7SDavid van Moolenbroek  *    of any contributors may be used to endorse or promote products derived
24*29492bb7SDavid van Moolenbroek  *    from this software without specific prior written permission.
25433d6423SLionel Sambuc  *
26*29492bb7SDavid van Moolenbroek  * Alternatively, this software may be distributed under the terms of the
27*29492bb7SDavid van Moolenbroek  * GNU General Public License ("GPL") version 2 as published by the Free
28*29492bb7SDavid van Moolenbroek  * Software Foundation.
29433d6423SLionel Sambuc  *
30*29492bb7SDavid van Moolenbroek  * NO WARRANTY
31*29492bb7SDavid van Moolenbroek  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32*29492bb7SDavid van Moolenbroek  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33*29492bb7SDavid van Moolenbroek  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34*29492bb7SDavid van Moolenbroek  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35*29492bb7SDavid van Moolenbroek  * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36*29492bb7SDavid van Moolenbroek  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37*29492bb7SDavid van Moolenbroek  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38*29492bb7SDavid van Moolenbroek  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39*29492bb7SDavid van Moolenbroek  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40*29492bb7SDavid van Moolenbroek  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41*29492bb7SDavid van Moolenbroek  * POSSIBILITY OF SUCH DAMAGES.
42*29492bb7SDavid van Moolenbroek  */
43433d6423SLionel Sambuc 
44433d6423SLionel Sambuc #include "acpi.h"
45433d6423SLionel Sambuc #include "accommon.h"
46433d6423SLionel Sambuc #include "acinterp.h"
47433d6423SLionel Sambuc 
48433d6423SLionel Sambuc 
49433d6423SLionel Sambuc #define _COMPONENT          ACPI_UTILITIES
50433d6423SLionel Sambuc         ACPI_MODULE_NAME    ("utids")
51433d6423SLionel Sambuc 
52433d6423SLionel Sambuc 
53433d6423SLionel Sambuc /*******************************************************************************
54433d6423SLionel Sambuc  *
55433d6423SLionel Sambuc  * FUNCTION:    AcpiUtExecute_HID
56433d6423SLionel Sambuc  *
57433d6423SLionel Sambuc  * PARAMETERS:  DeviceNode          - Node for the device
58433d6423SLionel Sambuc  *              ReturnId            - Where the string HID is returned
59433d6423SLionel Sambuc  *
60433d6423SLionel Sambuc  * RETURN:      Status
61433d6423SLionel Sambuc  *
62433d6423SLionel Sambuc  * DESCRIPTION: Executes the _HID control method that returns the hardware
63433d6423SLionel Sambuc  *              ID of the device. The HID is either an 32-bit encoded EISAID
64433d6423SLionel Sambuc  *              Integer or a String. A string is always returned. An EISAID
65433d6423SLionel Sambuc  *              is converted to a string.
66433d6423SLionel Sambuc  *
67433d6423SLionel Sambuc  *              NOTE: Internal function, no parameter validation
68433d6423SLionel Sambuc  *
69433d6423SLionel Sambuc  ******************************************************************************/
70433d6423SLionel Sambuc 
71433d6423SLionel Sambuc ACPI_STATUS
AcpiUtExecute_HID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)72433d6423SLionel Sambuc AcpiUtExecute_HID (
73433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *DeviceNode,
74*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      **ReturnId)
75433d6423SLionel Sambuc {
76433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
77*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      *Hid;
78433d6423SLionel Sambuc     UINT32                  Length;
79433d6423SLionel Sambuc     ACPI_STATUS             Status;
80433d6423SLionel Sambuc 
81433d6423SLionel Sambuc 
82433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (UtExecute_HID);
83433d6423SLionel Sambuc 
84433d6423SLionel Sambuc 
85433d6423SLionel Sambuc     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
86433d6423SLionel Sambuc                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
87433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
88433d6423SLionel Sambuc     {
89433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
90433d6423SLionel Sambuc     }
91433d6423SLionel Sambuc 
92433d6423SLionel Sambuc     /* Get the size of the String to be returned, includes null terminator */
93433d6423SLionel Sambuc 
94433d6423SLionel Sambuc     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
95433d6423SLionel Sambuc     {
96433d6423SLionel Sambuc         Length = ACPI_EISAID_STRING_SIZE;
97433d6423SLionel Sambuc     }
98433d6423SLionel Sambuc     else
99433d6423SLionel Sambuc     {
100433d6423SLionel Sambuc         Length = ObjDesc->String.Length + 1;
101433d6423SLionel Sambuc     }
102433d6423SLionel Sambuc 
103433d6423SLionel Sambuc     /* Allocate a buffer for the HID */
104433d6423SLionel Sambuc 
105*29492bb7SDavid van Moolenbroek     Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
106433d6423SLionel Sambuc     if (!Hid)
107433d6423SLionel Sambuc     {
108433d6423SLionel Sambuc         Status = AE_NO_MEMORY;
109433d6423SLionel Sambuc         goto Cleanup;
110433d6423SLionel Sambuc     }
111433d6423SLionel Sambuc 
112*29492bb7SDavid van Moolenbroek     /* Area for the string starts after PNP_DEVICE_ID struct */
113433d6423SLionel Sambuc 
114*29492bb7SDavid van Moolenbroek     Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_PNP_DEVICE_ID));
115433d6423SLionel Sambuc 
116433d6423SLionel Sambuc     /* Convert EISAID to a string or simply copy existing string */
117433d6423SLionel Sambuc 
118433d6423SLionel Sambuc     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
119433d6423SLionel Sambuc     {
120433d6423SLionel Sambuc         AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
121433d6423SLionel Sambuc     }
122433d6423SLionel Sambuc     else
123433d6423SLionel Sambuc     {
124*29492bb7SDavid van Moolenbroek         ACPI_STRCPY (Hid->String, ObjDesc->String.Pointer);
125433d6423SLionel Sambuc     }
126433d6423SLionel Sambuc 
127433d6423SLionel Sambuc     Hid->Length = Length;
128433d6423SLionel Sambuc     *ReturnId = Hid;
129433d6423SLionel Sambuc 
130433d6423SLionel Sambuc 
131433d6423SLionel Sambuc Cleanup:
132433d6423SLionel Sambuc 
133433d6423SLionel Sambuc     /* On exit, we must delete the return object */
134433d6423SLionel Sambuc 
135433d6423SLionel Sambuc     AcpiUtRemoveReference (ObjDesc);
136433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
137433d6423SLionel Sambuc }
138433d6423SLionel Sambuc 
139433d6423SLionel Sambuc 
140433d6423SLionel Sambuc /*******************************************************************************
141433d6423SLionel Sambuc  *
142*29492bb7SDavid van Moolenbroek  * FUNCTION:    AcpiUtExecute_SUB
143*29492bb7SDavid van Moolenbroek  *
144*29492bb7SDavid van Moolenbroek  * PARAMETERS:  DeviceNode          - Node for the device
145*29492bb7SDavid van Moolenbroek  *              ReturnId            - Where the _SUB is returned
146*29492bb7SDavid van Moolenbroek  *
147*29492bb7SDavid van Moolenbroek  * RETURN:      Status
148*29492bb7SDavid van Moolenbroek  *
149*29492bb7SDavid van Moolenbroek  * DESCRIPTION: Executes the _SUB control method that returns the subsystem
150*29492bb7SDavid van Moolenbroek  *              ID of the device. The _SUB value is always a string containing
151*29492bb7SDavid van Moolenbroek  *              either a valid PNP or ACPI ID.
152*29492bb7SDavid van Moolenbroek  *
153*29492bb7SDavid van Moolenbroek  *              NOTE: Internal function, no parameter validation
154*29492bb7SDavid van Moolenbroek  *
155*29492bb7SDavid van Moolenbroek  ******************************************************************************/
156*29492bb7SDavid van Moolenbroek 
157*29492bb7SDavid van Moolenbroek ACPI_STATUS
AcpiUtExecute_SUB(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)158*29492bb7SDavid van Moolenbroek AcpiUtExecute_SUB (
159*29492bb7SDavid van Moolenbroek     ACPI_NAMESPACE_NODE     *DeviceNode,
160*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      **ReturnId)
161*29492bb7SDavid van Moolenbroek {
162*29492bb7SDavid van Moolenbroek     ACPI_OPERAND_OBJECT     *ObjDesc;
163*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      *Sub;
164*29492bb7SDavid van Moolenbroek     UINT32                  Length;
165*29492bb7SDavid van Moolenbroek     ACPI_STATUS             Status;
166*29492bb7SDavid van Moolenbroek 
167*29492bb7SDavid van Moolenbroek 
168*29492bb7SDavid van Moolenbroek     ACPI_FUNCTION_TRACE (UtExecute_SUB);
169*29492bb7SDavid van Moolenbroek 
170*29492bb7SDavid van Moolenbroek 
171*29492bb7SDavid van Moolenbroek     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__SUB,
172*29492bb7SDavid van Moolenbroek                 ACPI_BTYPE_STRING, &ObjDesc);
173*29492bb7SDavid van Moolenbroek     if (ACPI_FAILURE (Status))
174*29492bb7SDavid van Moolenbroek     {
175*29492bb7SDavid van Moolenbroek         return_ACPI_STATUS (Status);
176*29492bb7SDavid van Moolenbroek     }
177*29492bb7SDavid van Moolenbroek 
178*29492bb7SDavid van Moolenbroek     /* Get the size of the String to be returned, includes null terminator */
179*29492bb7SDavid van Moolenbroek 
180*29492bb7SDavid van Moolenbroek     Length = ObjDesc->String.Length + 1;
181*29492bb7SDavid van Moolenbroek 
182*29492bb7SDavid van Moolenbroek     /* Allocate a buffer for the SUB */
183*29492bb7SDavid van Moolenbroek 
184*29492bb7SDavid van Moolenbroek     Sub = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
185*29492bb7SDavid van Moolenbroek     if (!Sub)
186*29492bb7SDavid van Moolenbroek     {
187*29492bb7SDavid van Moolenbroek         Status = AE_NO_MEMORY;
188*29492bb7SDavid van Moolenbroek         goto Cleanup;
189*29492bb7SDavid van Moolenbroek     }
190*29492bb7SDavid van Moolenbroek 
191*29492bb7SDavid van Moolenbroek     /* Area for the string starts after PNP_DEVICE_ID struct */
192*29492bb7SDavid van Moolenbroek 
193*29492bb7SDavid van Moolenbroek     Sub->String = ACPI_ADD_PTR (char, Sub, sizeof (ACPI_PNP_DEVICE_ID));
194*29492bb7SDavid van Moolenbroek 
195*29492bb7SDavid van Moolenbroek     /* Simply copy existing string */
196*29492bb7SDavid van Moolenbroek 
197*29492bb7SDavid van Moolenbroek     ACPI_STRCPY (Sub->String, ObjDesc->String.Pointer);
198*29492bb7SDavid van Moolenbroek     Sub->Length = Length;
199*29492bb7SDavid van Moolenbroek     *ReturnId = Sub;
200*29492bb7SDavid van Moolenbroek 
201*29492bb7SDavid van Moolenbroek 
202*29492bb7SDavid van Moolenbroek Cleanup:
203*29492bb7SDavid van Moolenbroek 
204*29492bb7SDavid van Moolenbroek     /* On exit, we must delete the return object */
205*29492bb7SDavid van Moolenbroek 
206*29492bb7SDavid van Moolenbroek     AcpiUtRemoveReference (ObjDesc);
207*29492bb7SDavid van Moolenbroek     return_ACPI_STATUS (Status);
208*29492bb7SDavid van Moolenbroek }
209*29492bb7SDavid van Moolenbroek 
210*29492bb7SDavid van Moolenbroek 
211*29492bb7SDavid van Moolenbroek /*******************************************************************************
212*29492bb7SDavid van Moolenbroek  *
213433d6423SLionel Sambuc  * FUNCTION:    AcpiUtExecute_UID
214433d6423SLionel Sambuc  *
215433d6423SLionel Sambuc  * PARAMETERS:  DeviceNode          - Node for the device
216433d6423SLionel Sambuc  *              ReturnId            - Where the string UID is returned
217433d6423SLionel Sambuc  *
218433d6423SLionel Sambuc  * RETURN:      Status
219433d6423SLionel Sambuc  *
220433d6423SLionel Sambuc  * DESCRIPTION: Executes the _UID control method that returns the unique
221433d6423SLionel Sambuc  *              ID of the device. The UID is either a 64-bit Integer (NOT an
222433d6423SLionel Sambuc  *              EISAID) or a string. Always returns a string. A 64-bit integer
223433d6423SLionel Sambuc  *              is converted to a decimal string.
224433d6423SLionel Sambuc  *
225433d6423SLionel Sambuc  *              NOTE: Internal function, no parameter validation
226433d6423SLionel Sambuc  *
227433d6423SLionel Sambuc  ******************************************************************************/
228433d6423SLionel Sambuc 
229433d6423SLionel Sambuc ACPI_STATUS
AcpiUtExecute_UID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID ** ReturnId)230433d6423SLionel Sambuc AcpiUtExecute_UID (
231433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *DeviceNode,
232*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      **ReturnId)
233433d6423SLionel Sambuc {
234433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
235*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID      *Uid;
236433d6423SLionel Sambuc     UINT32                  Length;
237433d6423SLionel Sambuc     ACPI_STATUS             Status;
238433d6423SLionel Sambuc 
239433d6423SLionel Sambuc 
240433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (UtExecute_UID);
241433d6423SLionel Sambuc 
242433d6423SLionel Sambuc 
243433d6423SLionel Sambuc     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
244433d6423SLionel Sambuc                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
245433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
246433d6423SLionel Sambuc     {
247433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
248433d6423SLionel Sambuc     }
249433d6423SLionel Sambuc 
250433d6423SLionel Sambuc     /* Get the size of the String to be returned, includes null terminator */
251433d6423SLionel Sambuc 
252433d6423SLionel Sambuc     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
253433d6423SLionel Sambuc     {
254433d6423SLionel Sambuc         Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
255433d6423SLionel Sambuc     }
256433d6423SLionel Sambuc     else
257433d6423SLionel Sambuc     {
258433d6423SLionel Sambuc         Length = ObjDesc->String.Length + 1;
259433d6423SLionel Sambuc     }
260433d6423SLionel Sambuc 
261433d6423SLionel Sambuc     /* Allocate a buffer for the UID */
262433d6423SLionel Sambuc 
263*29492bb7SDavid van Moolenbroek     Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
264433d6423SLionel Sambuc     if (!Uid)
265433d6423SLionel Sambuc     {
266433d6423SLionel Sambuc         Status = AE_NO_MEMORY;
267433d6423SLionel Sambuc         goto Cleanup;
268433d6423SLionel Sambuc     }
269433d6423SLionel Sambuc 
270*29492bb7SDavid van Moolenbroek     /* Area for the string starts after PNP_DEVICE_ID struct */
271433d6423SLionel Sambuc 
272*29492bb7SDavid van Moolenbroek     Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_PNP_DEVICE_ID));
273433d6423SLionel Sambuc 
274433d6423SLionel Sambuc     /* Convert an Integer to string, or just copy an existing string */
275433d6423SLionel Sambuc 
276433d6423SLionel Sambuc     if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
277433d6423SLionel Sambuc     {
278433d6423SLionel Sambuc         AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
279433d6423SLionel Sambuc     }
280433d6423SLionel Sambuc     else
281433d6423SLionel Sambuc     {
282*29492bb7SDavid van Moolenbroek         ACPI_STRCPY (Uid->String, ObjDesc->String.Pointer);
283433d6423SLionel Sambuc     }
284433d6423SLionel Sambuc 
285433d6423SLionel Sambuc     Uid->Length = Length;
286433d6423SLionel Sambuc     *ReturnId = Uid;
287433d6423SLionel Sambuc 
288433d6423SLionel Sambuc 
289433d6423SLionel Sambuc Cleanup:
290433d6423SLionel Sambuc 
291433d6423SLionel Sambuc     /* On exit, we must delete the return object */
292433d6423SLionel Sambuc 
293433d6423SLionel Sambuc     AcpiUtRemoveReference (ObjDesc);
294433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
295433d6423SLionel Sambuc }
296433d6423SLionel Sambuc 
297433d6423SLionel Sambuc 
298433d6423SLionel Sambuc /*******************************************************************************
299433d6423SLionel Sambuc  *
300433d6423SLionel Sambuc  * FUNCTION:    AcpiUtExecute_CID
301433d6423SLionel Sambuc  *
302433d6423SLionel Sambuc  * PARAMETERS:  DeviceNode          - Node for the device
303433d6423SLionel Sambuc  *              ReturnCidList       - Where the CID list is returned
304433d6423SLionel Sambuc  *
305433d6423SLionel Sambuc  * RETURN:      Status, list of CID strings
306433d6423SLionel Sambuc  *
307433d6423SLionel Sambuc  * DESCRIPTION: Executes the _CID control method that returns one or more
308433d6423SLionel Sambuc  *              compatible hardware IDs for the device.
309433d6423SLionel Sambuc  *
310433d6423SLionel Sambuc  *              NOTE: Internal function, no parameter validation
311433d6423SLionel Sambuc  *
312433d6423SLionel Sambuc  * A _CID method can return either a single compatible ID or a package of
313433d6423SLionel Sambuc  * compatible IDs. Each compatible ID can be one of the following:
314433d6423SLionel Sambuc  * 1) Integer (32 bit compressed EISA ID) or
315433d6423SLionel Sambuc  * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
316433d6423SLionel Sambuc  *
317433d6423SLionel Sambuc  * The Integer CIDs are converted to string format by this function.
318433d6423SLionel Sambuc  *
319433d6423SLionel Sambuc  ******************************************************************************/
320433d6423SLionel Sambuc 
321433d6423SLionel Sambuc ACPI_STATUS
AcpiUtExecute_CID(ACPI_NAMESPACE_NODE * DeviceNode,ACPI_PNP_DEVICE_ID_LIST ** ReturnCidList)322433d6423SLionel Sambuc AcpiUtExecute_CID (
323433d6423SLionel Sambuc     ACPI_NAMESPACE_NODE     *DeviceNode,
324*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID_LIST **ReturnCidList)
325433d6423SLionel Sambuc {
326433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     **CidObjects;
327433d6423SLionel Sambuc     ACPI_OPERAND_OBJECT     *ObjDesc;
328*29492bb7SDavid van Moolenbroek     ACPI_PNP_DEVICE_ID_LIST *CidList;
329433d6423SLionel Sambuc     char                    *NextIdString;
330433d6423SLionel Sambuc     UINT32                  StringAreaSize;
331433d6423SLionel Sambuc     UINT32                  Length;
332433d6423SLionel Sambuc     UINT32                  CidListSize;
333433d6423SLionel Sambuc     ACPI_STATUS             Status;
334433d6423SLionel Sambuc     UINT32                  Count;
335433d6423SLionel Sambuc     UINT32                  i;
336433d6423SLionel Sambuc 
337433d6423SLionel Sambuc 
338433d6423SLionel Sambuc     ACPI_FUNCTION_TRACE (UtExecute_CID);
339433d6423SLionel Sambuc 
340433d6423SLionel Sambuc 
341433d6423SLionel Sambuc     /* Evaluate the _CID method for this device */
342433d6423SLionel Sambuc 
343433d6423SLionel Sambuc     Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
344433d6423SLionel Sambuc                 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
345433d6423SLionel Sambuc                 &ObjDesc);
346433d6423SLionel Sambuc     if (ACPI_FAILURE (Status))
347433d6423SLionel Sambuc     {
348433d6423SLionel Sambuc         return_ACPI_STATUS (Status);
349433d6423SLionel Sambuc     }
350433d6423SLionel Sambuc 
351433d6423SLionel Sambuc     /*
352433d6423SLionel Sambuc      * Get the count and size of the returned _CIDs. _CID can return either
353433d6423SLionel Sambuc      * a Package of Integers/Strings or a single Integer or String.
354433d6423SLionel Sambuc      * Note: This section also validates that all CID elements are of the
355433d6423SLionel Sambuc      * correct type (Integer or String).
356433d6423SLionel Sambuc      */
357433d6423SLionel Sambuc     if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
358433d6423SLionel Sambuc     {
359433d6423SLionel Sambuc         Count = ObjDesc->Package.Count;
360433d6423SLionel Sambuc         CidObjects = ObjDesc->Package.Elements;
361433d6423SLionel Sambuc     }
362433d6423SLionel Sambuc     else /* Single Integer or String CID */
363433d6423SLionel Sambuc     {
364433d6423SLionel Sambuc         Count = 1;
365433d6423SLionel Sambuc         CidObjects = &ObjDesc;
366433d6423SLionel Sambuc     }
367433d6423SLionel Sambuc 
368433d6423SLionel Sambuc     StringAreaSize = 0;
369433d6423SLionel Sambuc     for (i = 0; i < Count; i++)
370433d6423SLionel Sambuc     {
371433d6423SLionel Sambuc         /* String lengths include null terminator */
372433d6423SLionel Sambuc 
373433d6423SLionel Sambuc         switch (CidObjects[i]->Common.Type)
374433d6423SLionel Sambuc         {
375433d6423SLionel Sambuc         case ACPI_TYPE_INTEGER:
376*29492bb7SDavid van Moolenbroek 
377433d6423SLionel Sambuc             StringAreaSize += ACPI_EISAID_STRING_SIZE;
378433d6423SLionel Sambuc             break;
379433d6423SLionel Sambuc 
380433d6423SLionel Sambuc         case ACPI_TYPE_STRING:
381*29492bb7SDavid van Moolenbroek 
382433d6423SLionel Sambuc             StringAreaSize += CidObjects[i]->String.Length + 1;
383433d6423SLionel Sambuc             break;
384433d6423SLionel Sambuc 
385433d6423SLionel Sambuc         default:
386*29492bb7SDavid van Moolenbroek 
387433d6423SLionel Sambuc             Status = AE_TYPE;
388433d6423SLionel Sambuc             goto Cleanup;
389433d6423SLionel Sambuc         }
390433d6423SLionel Sambuc     }
391433d6423SLionel Sambuc 
392433d6423SLionel Sambuc     /*
393433d6423SLionel Sambuc      * Now that we know the length of the CIDs, allocate return buffer:
394433d6423SLionel Sambuc      * 1) Size of the base structure +
395*29492bb7SDavid van Moolenbroek      * 2) Size of the CID PNP_DEVICE_ID array +
396433d6423SLionel Sambuc      * 3) Size of the actual CID strings
397433d6423SLionel Sambuc      */
398*29492bb7SDavid van Moolenbroek     CidListSize = sizeof (ACPI_PNP_DEVICE_ID_LIST) +
399*29492bb7SDavid van Moolenbroek         ((Count - 1) * sizeof (ACPI_PNP_DEVICE_ID)) +
400433d6423SLionel Sambuc         StringAreaSize;
401433d6423SLionel Sambuc 
402433d6423SLionel Sambuc     CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
403433d6423SLionel Sambuc     if (!CidList)
404433d6423SLionel Sambuc     {
405433d6423SLionel Sambuc         Status = AE_NO_MEMORY;
406433d6423SLionel Sambuc         goto Cleanup;
407433d6423SLionel Sambuc     }
408433d6423SLionel Sambuc 
409*29492bb7SDavid van Moolenbroek     /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
410433d6423SLionel Sambuc 
411433d6423SLionel Sambuc     NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
412*29492bb7SDavid van Moolenbroek         ((ACPI_SIZE) Count * sizeof (ACPI_PNP_DEVICE_ID));
413433d6423SLionel Sambuc 
414433d6423SLionel Sambuc     /* Copy/convert the CIDs to the return buffer */
415433d6423SLionel Sambuc 
416433d6423SLionel Sambuc     for (i = 0; i < Count; i++)
417433d6423SLionel Sambuc     {
418433d6423SLionel Sambuc         if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
419433d6423SLionel Sambuc         {
420433d6423SLionel Sambuc             /* Convert the Integer (EISAID) CID to a string */
421433d6423SLionel Sambuc 
422433d6423SLionel Sambuc             AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
423433d6423SLionel Sambuc             Length = ACPI_EISAID_STRING_SIZE;
424433d6423SLionel Sambuc         }
425433d6423SLionel Sambuc         else /* ACPI_TYPE_STRING */
426433d6423SLionel Sambuc         {
427433d6423SLionel Sambuc             /* Copy the String CID from the returned object */
428433d6423SLionel Sambuc 
429*29492bb7SDavid van Moolenbroek             ACPI_STRCPY (NextIdString, CidObjects[i]->String.Pointer);
430433d6423SLionel Sambuc             Length = CidObjects[i]->String.Length + 1;
431433d6423SLionel Sambuc         }
432433d6423SLionel Sambuc 
433433d6423SLionel Sambuc         CidList->Ids[i].String = NextIdString;
434433d6423SLionel Sambuc         CidList->Ids[i].Length = Length;
435433d6423SLionel Sambuc         NextIdString += Length;
436433d6423SLionel Sambuc     }
437433d6423SLionel Sambuc 
438433d6423SLionel Sambuc     /* Finish the CID list */
439433d6423SLionel Sambuc 
440433d6423SLionel Sambuc     CidList->Count = Count;
441433d6423SLionel Sambuc     CidList->ListSize = CidListSize;
442433d6423SLionel Sambuc     *ReturnCidList = CidList;
443433d6423SLionel Sambuc 
444433d6423SLionel Sambuc 
445433d6423SLionel Sambuc Cleanup:
446433d6423SLionel Sambuc 
447433d6423SLionel Sambuc     /* On exit, we must delete the _CID return object */
448433d6423SLionel Sambuc 
449433d6423SLionel Sambuc     AcpiUtRemoveReference (ObjDesc);
450433d6423SLionel Sambuc     return_ACPI_STATUS (Status);
451433d6423SLionel Sambuc }
452