1 /******************************************************************************
3 * Module Name: utids - support for device IDs - HID, UID, CID
5 *****************************************************************************/
8 * Copyright (C) 2000 - 2010, 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 <acpi/acpi.h>
48 #define _COMPONENT ACPI_UTILITIES
49 ACPI_MODULE_NAME("utids")
51 /* Local prototypes */
52 static void acpi_ut_copy_id_string(char *destination
, char *source
);
55 static void acpi_ut_copy_id_string(char *destination
, char *source
)
62 /* Do the actual copy */
64 ACPI_STRCPY(destination
, source
);
67 /*******************************************************************************
69 * FUNCTION: acpi_ut_execute_HID
71 * PARAMETERS: device_node - Node for the device
72 * return_id - Where the string HID is returned
76 * DESCRIPTION: Executes the _HID control method that returns the hardware
77 * ID of the device. The HID is either an 32-bit encoded EISAID
78 * Integer or a String. A string is always returned. An EISAID
79 * is converted to a string.
81 * NOTE: Internal function, no parameter validation
83 ******************************************************************************/
86 acpi_ut_execute_HID(struct acpi_namespace_node
*device_node
,
87 struct acpica_device_id
**return_id
)
89 union acpi_operand_object
*obj_desc
;
90 struct acpica_device_id
*hid
;
94 ACPI_FUNCTION_TRACE(ut_execute_HID
);
96 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__HID
,
97 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
99 if (ACPI_FAILURE(status
)) {
100 return_ACPI_STATUS(status
);
103 /* Get the size of the String to be returned, includes null terminator */
105 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
106 length
= ACPI_EISAID_STRING_SIZE
;
108 length
= obj_desc
->string
.length
+ 1;
111 /* Allocate a buffer for the HID */
114 ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id
) +
117 status
= AE_NO_MEMORY
;
121 /* Area for the string starts after DEVICE_ID struct */
123 hid
->string
= ACPI_ADD_PTR(char, hid
, sizeof(struct acpica_device_id
));
125 /* Convert EISAID to a string or simply copy existing string */
127 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
128 acpi_ex_eisa_id_to_string(hid
->string
, obj_desc
->integer
.value
);
130 acpi_ut_copy_id_string(hid
->string
, obj_desc
->string
.pointer
);
133 hid
->length
= length
;
138 /* On exit, we must delete the return object */
140 acpi_ut_remove_reference(obj_desc
);
141 return_ACPI_STATUS(status
);
144 /*******************************************************************************
146 * FUNCTION: acpi_ut_execute_UID
148 * PARAMETERS: device_node - Node for the device
149 * return_id - Where the string UID is returned
153 * DESCRIPTION: Executes the _UID control method that returns the unique
154 * ID of the device. The UID is either a 64-bit Integer (NOT an
155 * EISAID) or a string. Always returns a string. A 64-bit integer
156 * is converted to a decimal string.
158 * NOTE: Internal function, no parameter validation
160 ******************************************************************************/
163 acpi_ut_execute_UID(struct acpi_namespace_node
*device_node
,
164 struct acpica_device_id
**return_id
)
166 union acpi_operand_object
*obj_desc
;
167 struct acpica_device_id
*uid
;
171 ACPI_FUNCTION_TRACE(ut_execute_UID
);
173 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__UID
,
174 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
,
176 if (ACPI_FAILURE(status
)) {
177 return_ACPI_STATUS(status
);
180 /* Get the size of the String to be returned, includes null terminator */
182 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
183 length
= ACPI_MAX64_DECIMAL_DIGITS
+ 1;
185 length
= obj_desc
->string
.length
+ 1;
188 /* Allocate a buffer for the UID */
191 ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id
) +
194 status
= AE_NO_MEMORY
;
198 /* Area for the string starts after DEVICE_ID struct */
200 uid
->string
= ACPI_ADD_PTR(char, uid
, sizeof(struct acpica_device_id
));
202 /* Convert an Integer to string, or just copy an existing string */
204 if (obj_desc
->common
.type
== ACPI_TYPE_INTEGER
) {
205 acpi_ex_integer_to_string(uid
->string
, obj_desc
->integer
.value
);
207 acpi_ut_copy_id_string(uid
->string
, obj_desc
->string
.pointer
);
210 uid
->length
= length
;
215 /* On exit, we must delete the return object */
217 acpi_ut_remove_reference(obj_desc
);
218 return_ACPI_STATUS(status
);
221 /*******************************************************************************
223 * FUNCTION: acpi_ut_execute_CID
225 * PARAMETERS: device_node - Node for the device
226 * return_cid_list - Where the CID list is returned
228 * RETURN: Status, list of CID strings
230 * DESCRIPTION: Executes the _CID control method that returns one or more
231 * compatible hardware IDs for the device.
233 * NOTE: Internal function, no parameter validation
235 * A _CID method can return either a single compatible ID or a package of
236 * compatible IDs. Each compatible ID can be one of the following:
237 * 1) Integer (32 bit compressed EISA ID) or
238 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
240 * The Integer CIDs are converted to string format by this function.
242 ******************************************************************************/
245 acpi_ut_execute_CID(struct acpi_namespace_node
*device_node
,
246 struct acpica_device_id_list
**return_cid_list
)
248 union acpi_operand_object
**cid_objects
;
249 union acpi_operand_object
*obj_desc
;
250 struct acpica_device_id_list
*cid_list
;
251 char *next_id_string
;
252 u32 string_area_size
;
259 ACPI_FUNCTION_TRACE(ut_execute_CID
);
261 /* Evaluate the _CID method for this device */
263 status
= acpi_ut_evaluate_object(device_node
, METHOD_NAME__CID
,
264 ACPI_BTYPE_INTEGER
| ACPI_BTYPE_STRING
265 | ACPI_BTYPE_PACKAGE
, &obj_desc
);
266 if (ACPI_FAILURE(status
)) {
267 return_ACPI_STATUS(status
);
271 * Get the count and size of the returned _CIDs. _CID can return either
272 * a Package of Integers/Strings or a single Integer or String.
273 * Note: This section also validates that all CID elements are of the
274 * correct type (Integer or String).
276 if (obj_desc
->common
.type
== ACPI_TYPE_PACKAGE
) {
277 count
= obj_desc
->package
.count
;
278 cid_objects
= obj_desc
->package
.elements
;
279 } else { /* Single Integer or String CID */
282 cid_objects
= &obj_desc
;
285 string_area_size
= 0;
286 for (i
= 0; i
< count
; i
++) {
288 /* String lengths include null terminator */
290 switch (cid_objects
[i
]->common
.type
) {
291 case ACPI_TYPE_INTEGER
:
292 string_area_size
+= ACPI_EISAID_STRING_SIZE
;
295 case ACPI_TYPE_STRING
:
296 string_area_size
+= cid_objects
[i
]->string
.length
+ 1;
306 * Now that we know the length of the CIDs, allocate return buffer:
307 * 1) Size of the base structure +
308 * 2) Size of the CID DEVICE_ID array +
309 * 3) Size of the actual CID strings
311 cid_list_size
= sizeof(struct acpica_device_id_list
) +
312 ((count
- 1) * sizeof(struct acpica_device_id
)) + string_area_size
;
314 cid_list
= ACPI_ALLOCATE_ZEROED(cid_list_size
);
316 status
= AE_NO_MEMORY
;
320 /* Area for CID strings starts after the CID DEVICE_ID array */
322 next_id_string
= ACPI_CAST_PTR(char, cid_list
->ids
) +
323 ((acpi_size
) count
* sizeof(struct acpica_device_id
));
325 /* Copy/convert the CIDs to the return buffer */
327 for (i
= 0; i
< count
; i
++) {
328 if (cid_objects
[i
]->common
.type
== ACPI_TYPE_INTEGER
) {
330 /* Convert the Integer (EISAID) CID to a string */
332 acpi_ex_eisa_id_to_string(next_id_string
,
333 cid_objects
[i
]->integer
.
335 length
= ACPI_EISAID_STRING_SIZE
;
336 } else { /* ACPI_TYPE_STRING */
338 /* Copy the String CID from the returned object */
340 acpi_ut_copy_id_string(next_id_string
,
341 cid_objects
[i
]->string
.pointer
);
342 length
= cid_objects
[i
]->string
.length
+ 1;
345 cid_list
->ids
[i
].string
= next_id_string
;
346 cid_list
->ids
[i
].length
= length
;
347 next_id_string
+= length
;
350 /* Finish the CID list */
352 cid_list
->count
= count
;
353 cid_list
->list_size
= cid_list_size
;
354 *return_cid_list
= cid_list
;
358 /* On exit, we must delete the _CID return object */
360 acpi_ut_remove_reference(obj_desc
);
361 return_ACPI_STATUS(status
);