1 // SPDX-License-Identifier: BSD-3-Clause OR GPL-2.0
2 /******************************************************************************
4 * Module Name: utids - support for device Ids - HID, UID, CID, SUB, CLS
6 * Copyright (C) 2000 - 2018, Intel Corp.
8 *****************************************************************************/
10 #include <acpi/acpi.h>
14 #define _COMPONENT ACPI_UTILITIES
15 ACPI_MODULE_NAME("utids")
17 /*******************************************************************************
19 * FUNCTION: acpi_ut_execute_HID
21 * PARAMETERS: device_node - Node for the device
22 * return_id - Where the string HID is returned
26 * DESCRIPTION: Executes the _HID control method that returns the hardware
27 * ID of the device. The HID is either an 32-bit encoded EISAID
28 * Integer or a String. A string is always returned. An EISAID
29 * is converted to a string.
31 * NOTE: Internal function, no parameter validation
33 ******************************************************************************/
35 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
36 struct acpi_pnp_device_id
**return_id
)
38 union acpi_operand_object
*obj_desc
;
39 struct acpi_pnp_device_id
*hid
;
43 ACPI_FUNCTION_TRACE(ut_execute_HID
);
45 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
46 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
48 if (ACPI_FAILURE(status
)) {
49 return_ACPI_STATUS(status
);
52 /* Get the size of the String to be returned, includes null terminator */
54 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
55 length
= ACPI_EISAID_STRING_SIZE
;
57 length
= obj_desc
->string
.length
+ 1;
60 /* Allocate a buffer for the HID */
63 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id
) +
66 status
= AE_NO_MEMORY
;
70 /* Area for the string starts after PNP_DEVICE_ID struct */
73 ACPI_ADD_PTR(char, hid
, sizeof(struct acpi_pnp_device_id
));
75 /* Convert EISAID to a string or simply copy existing string */
77 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
78 acpi_ex_eisa_id_to_string(hid
->string
, obj_desc
->integer
.value
);
80 strcpy(hid
->string
, obj_desc
->string
.pointer
);
88 /* On exit, we must delete the return object */
90 acpi_ut_remove_reference(obj_desc
);
91 return_ACPI_STATUS(status
);
94 /*******************************************************************************
96 * FUNCTION: acpi_ut_execute_UID
98 * PARAMETERS: device_node - Node for the device
99 * return_id - Where the string UID is returned
103 * DESCRIPTION: Executes the _UID control method that returns the unique
104 * ID of the device. The UID is either a 64-bit Integer (NOT an
105 * EISAID) or a string. Always returns a string. A 64-bit integer
106 * is converted to a decimal string.
108 * NOTE: Internal function, no parameter validation
110 ******************************************************************************/
113 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
114 struct acpi_pnp_device_id
**return_id
)
116 union acpi_operand_object
*obj_desc
;
117 struct acpi_pnp_device_id
*uid
;
121 ACPI_FUNCTION_TRACE(ut_execute_UID
);
123 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
124 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
126 if (ACPI_FAILURE(status
)) {
127 return_ACPI_STATUS(status
);
130 /* Get the size of the String to be returned, includes null terminator */
132 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
133 length
= ACPI_MAX64_DECIMAL_DIGITS
+ 1;
135 length
= obj_desc
->string
.length
+ 1;
138 /* Allocate a buffer for the UID */
141 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id
) +
144 status
= AE_NO_MEMORY
;
148 /* Area for the string starts after PNP_DEVICE_ID struct */
151 ACPI_ADD_PTR(char, uid
, sizeof(struct acpi_pnp_device_id
));
153 /* Convert an Integer to string, or just copy an existing string */
155 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
156 acpi_ex_integer_to_string(uid
->string
, obj_desc
->integer
.value
);
158 strcpy(uid
->string
, obj_desc
->string
.pointer
);
161 uid
->length
= length
;
166 /* On exit, we must delete the return object */
168 acpi_ut_remove_reference(obj_desc
);
169 return_ACPI_STATUS(status
);
172 /*******************************************************************************
174 * FUNCTION: acpi_ut_execute_CID
176 * PARAMETERS: device_node - Node for the device
177 * return_cid_list - Where the CID list is returned
179 * RETURN: Status, list of CID strings
181 * DESCRIPTION: Executes the _CID control method that returns one or more
182 * compatible hardware IDs for the device.
184 * NOTE: Internal function, no parameter validation
186 * A _CID method can return either a single compatible ID or a package of
187 * compatible IDs. Each compatible ID can be one of the following:
188 * 1) Integer (32 bit compressed EISA ID) or
189 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
191 * The Integer CIDs are converted to string format by this function.
193 ******************************************************************************/
196 acpi_ut_execute_CID(struct acpi_namespace_node
*device_node
,
197 struct acpi_pnp_device_id_list
**return_cid_list
)
199 union acpi_operand_object
**cid_objects
;
200 union acpi_operand_object
*obj_desc
;
201 struct acpi_pnp_device_id_list
*cid_list
;
202 char *next_id_string
;
203 u32 string_area_size
;
210 ACPI_FUNCTION_TRACE(ut_execute_CID
);
212 /* Evaluate the _CID method for this device */
214 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
215 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
216 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
217 if (ACPI_FAILURE(status
)) {
218 return_ACPI_STATUS(status
);
222 * Get the count and size of the returned _CIDs. _CID can return either
223 * a Package of Integers/Strings or a single Integer or String.
224 * Note: This section also validates that all CID elements are of the
225 * correct type (Integer or String).
227 if (obj_desc
->common
.type
== ACPI_TYPE_PACKAGE
) {
228 count
= obj_desc
->package
.count
;
229 cid_objects
= obj_desc
->package
.elements
;
230 } else { /* Single Integer or String CID */
233 cid_objects
= &obj_desc
;
236 string_area_size
= 0;
237 for (i
= 0; i
< count
; i
++) {
239 /* String lengths include null terminator */
241 switch (cid_objects
[i
]->common
.type
) {
242 case ACPI_TYPE_INTEGER
:
244 string_area_size
+= ACPI_EISAID_STRING_SIZE
;
247 case ACPI_TYPE_STRING
:
249 string_area_size
+= cid_objects
[i
]->string
.length
+ 1;
260 * Now that we know the length of the CIDs, allocate return buffer:
261 * 1) Size of the base structure +
262 * 2) Size of the CID PNP_DEVICE_ID array +
263 * 3) Size of the actual CID strings
265 cid_list_size
= sizeof(struct acpi_pnp_device_id_list
) +
266 ((count
- 1) * sizeof(struct acpi_pnp_device_id
)) +
269 cid_list
= ACPI_ALLOCATE_ZEROED(cid_list_size
);
271 status
= AE_NO_MEMORY
;
275 /* Area for CID strings starts after the CID PNP_DEVICE_ID array */
277 next_id_string
= ACPI_CAST_PTR(char, cid_list
->ids
) +
278 ((acpi_size
)count
* sizeof(struct acpi_pnp_device_id
));
280 /* Copy/convert the CIDs to the return buffer */
282 for (i
= 0; i
< count
; i
++) {
283 if (cid_objects
[i
]->common
.type
== ACPI_TYPE_INTEGER
) {
285 /* Convert the Integer (EISAID) CID to a string */
287 acpi_ex_eisa_id_to_string(next_id_string
,
288 cid_objects
[i
]->integer
.
290 length
= ACPI_EISAID_STRING_SIZE
;
291 } else { /* ACPI_TYPE_STRING */
293 /* Copy the String CID from the returned object */
295 strcpy(next_id_string
, cid_objects
[i
]->string
.pointer
);
296 length
= cid_objects
[i
]->string
.length
+ 1;
299 cid_list
->ids
[i
].string
= next_id_string
;
300 cid_list
->ids
[i
].length
= length
;
301 next_id_string
+= length
;
304 /* Finish the CID list */
306 cid_list
->count
= count
;
307 cid_list
->list_size
= cid_list_size
;
308 *return_cid_list
= cid_list
;
312 /* On exit, we must delete the _CID return object */
314 acpi_ut_remove_reference(obj_desc
);
315 return_ACPI_STATUS(status
);
318 /*******************************************************************************
320 * FUNCTION: acpi_ut_execute_CLS
322 * PARAMETERS: device_node - Node for the device
323 * return_id - Where the _CLS is returned
327 * DESCRIPTION: Executes the _CLS control method that returns PCI-defined
328 * class code of the device. The _CLS value is always a package
329 * containing PCI class information as a list of integers.
330 * The returned string has format "BBSSPP", where:
331 * BB = Base-class code
332 * SS = Sub-class code
333 * PP = Programming Interface code
335 ******************************************************************************/
338 acpi_ut_execute_CLS(struct acpi_namespace_node
*device_node
,
339 struct acpi_pnp_device_id
**return_id
)
341 union acpi_operand_object
*obj_desc
;
342 union acpi_operand_object
**cls_objects
;
344 struct acpi_pnp_device_id
*cls
;
347 u8 class_code
[3] = { 0, 0, 0 };
349 ACPI_FUNCTION_TRACE(ut_execute_CLS
);
351 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CLS
,
352 ACPI_BTYPE_PACKAGE
, &obj_desc
);
353 if (ACPI_FAILURE(status
)) {
354 return_ACPI_STATUS(status
);
357 /* Get the size of the String to be returned, includes null terminator */
359 length
= ACPI_PCICLS_STRING_SIZE
;
360 cls_objects
= obj_desc
->package
.elements
;
361 count
= obj_desc
->package
.count
;
363 if (obj_desc
->common
.type
== ACPI_TYPE_PACKAGE
) {
365 && cls_objects
[0]->common
.type
== ACPI_TYPE_INTEGER
) {
366 class_code
[0] = (u8
)cls_objects
[0]->integer
.value
;
369 && cls_objects
[1]->common
.type
== ACPI_TYPE_INTEGER
) {
370 class_code
[1] = (u8
)cls_objects
[1]->integer
.value
;
373 && cls_objects
[2]->common
.type
== ACPI_TYPE_INTEGER
) {
374 class_code
[2] = (u8
)cls_objects
[2]->integer
.value
;
378 /* Allocate a buffer for the CLS */
381 ACPI_ALLOCATE_ZEROED(sizeof(struct acpi_pnp_device_id
) +
384 status
= AE_NO_MEMORY
;
388 /* Area for the string starts after PNP_DEVICE_ID struct */
391 ACPI_ADD_PTR(char, cls
, sizeof(struct acpi_pnp_device_id
));
393 /* Simply copy existing string */
395 acpi_ex_pci_cls_to_string(cls
->string
, class_code
);
396 cls
->length
= length
;
401 /* On exit, we must delete the return object */
403 acpi_ut_remove_reference(obj_desc
);
404 return_ACPI_STATUS(status
);