1 /******************************************************************************
3 * Module Name: utids - support for device IDs - HID, UID, CID
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2015, Intel Corp.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, and the following disclaimer,
16 * without modification.
17 * 2. Redistributions in binary form must reproduce at minimum a disclaimer
18 * substantially similar to the "NO WARRANTY" disclaimer below
19 * ("Disclaimer") and any redistribution must be conditioned upon
20 * including a substantially similar Disclaimer requirement for further
21 * binary redistribution.
22 * 3. Neither the names of the above-listed copyright holders nor the names
23 * of any contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
26 * Alternatively, this software may be distributed under the terms of the
27 * GNU General Public License ("GPL") version 2 as published by the Free
28 * Software Foundation.
31 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR
34 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35 * HOLDERS OR CONTRIBUTORS BE LIABLE FOR SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
36 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
37 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
38 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
39 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
40 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
41 * POSSIBILITY OF SUCH DAMAGES.
44 #include <contrib/dev/acpica/include/acpi.h>
45 #include <contrib/dev/acpica/include/accommon.h>
46 #include <contrib/dev/acpica/include/acinterp.h>
49 #define _COMPONENT ACPI_UTILITIES
50 ACPI_MODULE_NAME ("utids")
53 /*******************************************************************************
55 * FUNCTION: AcpiUtExecute_HID
57 * PARAMETERS: DeviceNode - Node for the device
58 * ReturnId - Where the string HID is returned
62 * DESCRIPTION: Executes the _HID control method that returns the hardware
63 * ID of the device. The HID is either an 32-bit encoded EISAID
64 * Integer or a String. A string is always returned. An EISAID
65 * is converted to a string.
67 * NOTE: Internal function, no parameter validation
69 ******************************************************************************/
73 ACPI_NAMESPACE_NODE *DeviceNode,
74 ACPI_PNP_DEVICE_ID **ReturnId)
76 ACPI_OPERAND_OBJECT *ObjDesc;
77 ACPI_PNP_DEVICE_ID *Hid;
82 ACPI_FUNCTION_TRACE (UtExecute_HID);
85 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
86 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
87 if (ACPI_FAILURE (Status))
89 return_ACPI_STATUS (Status);
92 /* Get the size of the String to be returned, includes null terminator */
94 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
96 Length = ACPI_EISAID_STRING_SIZE;
100 Length = ObjDesc->String.Length + 1;
103 /* Allocate a buffer for the HID */
105 Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
108 Status = AE_NO_MEMORY;
112 /* Area for the string starts after PNP_DEVICE_ID struct */
114 Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_PNP_DEVICE_ID));
116 /* Convert EISAID to a string or simply copy existing string */
118 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
120 AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
124 ACPI_STRCPY (Hid->String, ObjDesc->String.Pointer);
127 Hid->Length = Length;
133 /* On exit, we must delete the return object */
135 AcpiUtRemoveReference (ObjDesc);
136 return_ACPI_STATUS (Status);
140 /*******************************************************************************
142 * FUNCTION: AcpiUtExecute_SUB
144 * PARAMETERS: DeviceNode - Node for the device
145 * ReturnId - Where the _SUB is returned
149 * DESCRIPTION: Executes the _SUB control method that returns the subsystem
150 * ID of the device. The _SUB value is always a string containing
151 * either a valid PNP or ACPI ID.
153 * NOTE: Internal function, no parameter validation
155 ******************************************************************************/
159 ACPI_NAMESPACE_NODE *DeviceNode,
160 ACPI_PNP_DEVICE_ID **ReturnId)
162 ACPI_OPERAND_OBJECT *ObjDesc;
163 ACPI_PNP_DEVICE_ID *Sub;
168 ACPI_FUNCTION_TRACE (UtExecute_SUB);
171 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__SUB,
172 ACPI_BTYPE_STRING, &ObjDesc);
173 if (ACPI_FAILURE (Status))
175 return_ACPI_STATUS (Status);
178 /* Get the size of the String to be returned, includes null terminator */
180 Length = ObjDesc->String.Length + 1;
182 /* Allocate a buffer for the SUB */
184 Sub = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
187 Status = AE_NO_MEMORY;
191 /* Area for the string starts after PNP_DEVICE_ID struct */
193 Sub->String = ACPI_ADD_PTR (char, Sub, sizeof (ACPI_PNP_DEVICE_ID));
195 /* Simply copy existing string */
197 ACPI_STRCPY (Sub->String, ObjDesc->String.Pointer);
198 Sub->Length = Length;
204 /* On exit, we must delete the return object */
206 AcpiUtRemoveReference (ObjDesc);
207 return_ACPI_STATUS (Status);
211 /*******************************************************************************
213 * FUNCTION: AcpiUtExecute_UID
215 * PARAMETERS: DeviceNode - Node for the device
216 * ReturnId - Where the string UID is returned
220 * DESCRIPTION: Executes the _UID control method that returns the unique
221 * ID of the device. The UID is either a 64-bit Integer (NOT an
222 * EISAID) or a string. Always returns a string. A 64-bit integer
223 * is converted to a decimal string.
225 * NOTE: Internal function, no parameter validation
227 ******************************************************************************/
231 ACPI_NAMESPACE_NODE *DeviceNode,
232 ACPI_PNP_DEVICE_ID **ReturnId)
234 ACPI_OPERAND_OBJECT *ObjDesc;
235 ACPI_PNP_DEVICE_ID *Uid;
240 ACPI_FUNCTION_TRACE (UtExecute_UID);
243 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
244 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
245 if (ACPI_FAILURE (Status))
247 return_ACPI_STATUS (Status);
250 /* Get the size of the String to be returned, includes null terminator */
252 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
254 Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
258 Length = ObjDesc->String.Length + 1;
261 /* Allocate a buffer for the UID */
263 Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_PNP_DEVICE_ID) + (ACPI_SIZE) Length);
266 Status = AE_NO_MEMORY;
270 /* Area for the string starts after PNP_DEVICE_ID struct */
272 Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_PNP_DEVICE_ID));
274 /* Convert an Integer to string, or just copy an existing string */
276 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
278 AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
282 ACPI_STRCPY (Uid->String, ObjDesc->String.Pointer);
285 Uid->Length = Length;
291 /* On exit, we must delete the return object */
293 AcpiUtRemoveReference (ObjDesc);
294 return_ACPI_STATUS (Status);
298 /*******************************************************************************
300 * FUNCTION: AcpiUtExecute_CID
302 * PARAMETERS: DeviceNode - Node for the device
303 * ReturnCidList - Where the CID list is returned
305 * RETURN: Status, list of CID strings
307 * DESCRIPTION: Executes the _CID control method that returns one or more
308 * compatible hardware IDs for the device.
310 * NOTE: Internal function, no parameter validation
312 * A _CID method can return either a single compatible ID or a package of
313 * compatible IDs. Each compatible ID can be one of the following:
314 * 1) Integer (32 bit compressed EISA ID) or
315 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
317 * The Integer CIDs are converted to string format by this function.
319 ******************************************************************************/
323 ACPI_NAMESPACE_NODE *DeviceNode,
324 ACPI_PNP_DEVICE_ID_LIST **ReturnCidList)
326 ACPI_OPERAND_OBJECT **CidObjects;
327 ACPI_OPERAND_OBJECT *ObjDesc;
328 ACPI_PNP_DEVICE_ID_LIST *CidList;
330 UINT32 StringAreaSize;
338 ACPI_FUNCTION_TRACE (UtExecute_CID);
341 /* Evaluate the _CID method for this device */
343 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
344 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
346 if (ACPI_FAILURE (Status))
348 return_ACPI_STATUS (Status);
352 * Get the count and size of the returned _CIDs. _CID can return either
353 * a Package of Integers/Strings or a single Integer or String.
354 * Note: This section also validates that all CID elements are of the
355 * correct type (Integer or String).
357 if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
359 Count = ObjDesc->Package.Count;
360 CidObjects = ObjDesc->Package.Elements;
362 else /* Single Integer or String CID */
365 CidObjects = &ObjDesc;
369 for (i = 0; i < Count; i++)
371 /* String lengths include null terminator */
373 switch (CidObjects[i]->Common.Type)
375 case ACPI_TYPE_INTEGER:
377 StringAreaSize += ACPI_EISAID_STRING_SIZE;
380 case ACPI_TYPE_STRING:
382 StringAreaSize += CidObjects[i]->String.Length + 1;
393 * Now that we know the length of the CIDs, allocate return buffer:
394 * 1) Size of the base structure +
395 * 2) Size of the CID PNP_DEVICE_ID array +
396 * 3) Size of the actual CID strings
398 CidListSize = sizeof (ACPI_PNP_DEVICE_ID_LIST) +
399 ((Count - 1) * sizeof (ACPI_PNP_DEVICE_ID)) +
402 CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
405 Status = AE_NO_MEMORY;
409 /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
411 NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
412 ((ACPI_SIZE) Count * sizeof (ACPI_PNP_DEVICE_ID));
414 /* Copy/convert the CIDs to the return buffer */
416 for (i = 0; i < Count; i++)
418 if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
420 /* Convert the Integer (EISAID) CID to a string */
422 AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
423 Length = ACPI_EISAID_STRING_SIZE;
425 else /* ACPI_TYPE_STRING */
427 /* Copy the String CID from the returned object */
429 ACPI_STRCPY (NextIdString, CidObjects[i]->String.Pointer);
430 Length = CidObjects[i]->String.Length + 1;
433 CidList->Ids[i].String = NextIdString;
434 CidList->Ids[i].Length = Length;
435 NextIdString += Length;
438 /* Finish the CID list */
440 CidList->Count = Count;
441 CidList->ListSize = CidListSize;
442 *ReturnCidList = CidList;
447 /* On exit, we must delete the _CID return object */
449 AcpiUtRemoveReference (ObjDesc);
450 return_ACPI_STATUS (Status);