1 /******************************************************************************
3 * Module Name: utids - support for device IDs - HID, UID, CID
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2011, 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.
46 #include <contrib/dev/acpica/include/acpi.h>
47 #include <contrib/dev/acpica/include/accommon.h>
48 #include <contrib/dev/acpica/include/acinterp.h>
51 #define _COMPONENT ACPI_UTILITIES
52 ACPI_MODULE_NAME ("utids")
55 /*******************************************************************************
57 * FUNCTION: AcpiUtExecute_HID
59 * PARAMETERS: DeviceNode - Node for the device
60 * ReturnId - Where the string HID is returned
64 * DESCRIPTION: Executes the _HID control method that returns the hardware
65 * ID of the device. The HID is either an 32-bit encoded EISAID
66 * Integer or a String. A string is always returned. An EISAID
67 * is converted to a string.
69 * NOTE: Internal function, no parameter validation
71 ******************************************************************************/
75 ACPI_NAMESPACE_NODE *DeviceNode,
76 ACPI_DEVICE_ID **ReturnId)
78 ACPI_OPERAND_OBJECT *ObjDesc;
84 ACPI_FUNCTION_TRACE (UtExecute_HID);
87 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__HID,
88 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
89 if (ACPI_FAILURE (Status))
91 return_ACPI_STATUS (Status);
94 /* Get the size of the String to be returned, includes null terminator */
96 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
98 Length = ACPI_EISAID_STRING_SIZE;
102 Length = ObjDesc->String.Length + 1;
105 /* Allocate a buffer for the HID */
107 Hid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
110 Status = AE_NO_MEMORY;
114 /* Area for the string starts after DEVICE_ID struct */
116 Hid->String = ACPI_ADD_PTR (char, Hid, sizeof (ACPI_DEVICE_ID));
118 /* Convert EISAID to a string or simply copy existing string */
120 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
122 AcpiExEisaIdToString (Hid->String, ObjDesc->Integer.Value);
126 ACPI_STRCPY (Hid->String, ObjDesc->String.Pointer);
129 Hid->Length = Length;
135 /* On exit, we must delete the return object */
137 AcpiUtRemoveReference (ObjDesc);
138 return_ACPI_STATUS (Status);
142 /*******************************************************************************
144 * FUNCTION: AcpiUtExecute_UID
146 * PARAMETERS: DeviceNode - Node for the device
147 * ReturnId - Where the string UID is returned
151 * DESCRIPTION: Executes the _UID control method that returns the unique
152 * ID of the device. The UID is either a 64-bit Integer (NOT an
153 * EISAID) or a string. Always returns a string. A 64-bit integer
154 * is converted to a decimal string.
156 * NOTE: Internal function, no parameter validation
158 ******************************************************************************/
162 ACPI_NAMESPACE_NODE *DeviceNode,
163 ACPI_DEVICE_ID **ReturnId)
165 ACPI_OPERAND_OBJECT *ObjDesc;
171 ACPI_FUNCTION_TRACE (UtExecute_UID);
174 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__UID,
175 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING, &ObjDesc);
176 if (ACPI_FAILURE (Status))
178 return_ACPI_STATUS (Status);
181 /* Get the size of the String to be returned, includes null terminator */
183 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
185 Length = ACPI_MAX64_DECIMAL_DIGITS + 1;
189 Length = ObjDesc->String.Length + 1;
192 /* Allocate a buffer for the UID */
194 Uid = ACPI_ALLOCATE_ZEROED (sizeof (ACPI_DEVICE_ID) + (ACPI_SIZE) Length);
197 Status = AE_NO_MEMORY;
201 /* Area for the string starts after DEVICE_ID struct */
203 Uid->String = ACPI_ADD_PTR (char, Uid, sizeof (ACPI_DEVICE_ID));
205 /* Convert an Integer to string, or just copy an existing string */
207 if (ObjDesc->Common.Type == ACPI_TYPE_INTEGER)
209 AcpiExIntegerToString (Uid->String, ObjDesc->Integer.Value);
213 ACPI_STRCPY (Uid->String, ObjDesc->String.Pointer);
216 Uid->Length = Length;
222 /* On exit, we must delete the return object */
224 AcpiUtRemoveReference (ObjDesc);
225 return_ACPI_STATUS (Status);
229 /*******************************************************************************
231 * FUNCTION: AcpiUtExecute_CID
233 * PARAMETERS: DeviceNode - Node for the device
234 * ReturnCidList - Where the CID list is returned
236 * RETURN: Status, list of CID strings
238 * DESCRIPTION: Executes the _CID control method that returns one or more
239 * compatible hardware IDs for the device.
241 * NOTE: Internal function, no parameter validation
243 * A _CID method can return either a single compatible ID or a package of
244 * compatible IDs. Each compatible ID can be one of the following:
245 * 1) Integer (32 bit compressed EISA ID) or
246 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
248 * The Integer CIDs are converted to string format by this function.
250 ******************************************************************************/
254 ACPI_NAMESPACE_NODE *DeviceNode,
255 ACPI_DEVICE_ID_LIST **ReturnCidList)
257 ACPI_OPERAND_OBJECT **CidObjects;
258 ACPI_OPERAND_OBJECT *ObjDesc;
259 ACPI_DEVICE_ID_LIST *CidList;
261 UINT32 StringAreaSize;
269 ACPI_FUNCTION_TRACE (UtExecute_CID);
272 /* Evaluate the _CID method for this device */
274 Status = AcpiUtEvaluateObject (DeviceNode, METHOD_NAME__CID,
275 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING | ACPI_BTYPE_PACKAGE,
277 if (ACPI_FAILURE (Status))
279 return_ACPI_STATUS (Status);
283 * Get the count and size of the returned _CIDs. _CID can return either
284 * a Package of Integers/Strings or a single Integer or String.
285 * Note: This section also validates that all CID elements are of the
286 * correct type (Integer or String).
288 if (ObjDesc->Common.Type == ACPI_TYPE_PACKAGE)
290 Count = ObjDesc->Package.Count;
291 CidObjects = ObjDesc->Package.Elements;
293 else /* Single Integer or String CID */
296 CidObjects = &ObjDesc;
300 for (i = 0; i < Count; i++)
302 /* String lengths include null terminator */
304 switch (CidObjects[i]->Common.Type)
306 case ACPI_TYPE_INTEGER:
307 StringAreaSize += ACPI_EISAID_STRING_SIZE;
310 case ACPI_TYPE_STRING:
311 StringAreaSize += CidObjects[i]->String.Length + 1;
321 * Now that we know the length of the CIDs, allocate return buffer:
322 * 1) Size of the base structure +
323 * 2) Size of the CID DEVICE_ID array +
324 * 3) Size of the actual CID strings
326 CidListSize = sizeof (ACPI_DEVICE_ID_LIST) +
327 ((Count - 1) * sizeof (ACPI_DEVICE_ID)) +
330 CidList = ACPI_ALLOCATE_ZEROED (CidListSize);
333 Status = AE_NO_MEMORY;
337 /* Area for CID strings starts after the CID DEVICE_ID array */
339 NextIdString = ACPI_CAST_PTR (char, CidList->Ids) +
340 ((ACPI_SIZE) Count * sizeof (ACPI_DEVICE_ID));
342 /* Copy/convert the CIDs to the return buffer */
344 for (i = 0; i < Count; i++)
346 if (CidObjects[i]->Common.Type == ACPI_TYPE_INTEGER)
348 /* Convert the Integer (EISAID) CID to a string */
350 AcpiExEisaIdToString (NextIdString, CidObjects[i]->Integer.Value);
351 Length = ACPI_EISAID_STRING_SIZE;
353 else /* ACPI_TYPE_STRING */
355 /* Copy the String CID from the returned object */
357 ACPI_STRCPY (NextIdString, CidObjects[i]->String.Pointer);
358 Length = CidObjects[i]->String.Length + 1;
361 CidList->Ids[i].String = NextIdString;
362 CidList->Ids[i].Length = Length;
363 NextIdString += Length;
366 /* Finish the CID list */
368 CidList->Count = Count;
369 CidList->ListSize = CidListSize;
370 *ReturnCidList = CidList;
375 /* On exit, we must delete the _CID return object */
377 AcpiUtRemoveReference (ObjDesc);
378 return_ACPI_STATUS (Status);