[ARM] pxa: Gumstix Verdex PCMCIA support
[linux-2.6/verdex.git] / drivers / acpi / acpica / utids.c
blob52eaae40455476f02f30be6cbfff0210f026bd23
1 /******************************************************************************
3 * Module Name: utids - support for device IDs - HID, UID, CID
5 *****************************************************************************/
7 /*
8 * Copyright (C) 2000 - 2009, Intel Corp.
9 * All rights reserved.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
13 * are met:
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.
30 * NO WARRANTY
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>
45 #include "accommon.h"
46 #include "acinterp.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);
54 /*******************************************************************************
56 * FUNCTION: acpi_ut_copy_id_string
58 * PARAMETERS: Destination - Where to copy the string
59 * Source - Source string
61 * RETURN: None
63 * DESCRIPTION: Copies an ID string for the _HID, _CID, and _UID methods.
64 * Performs removal of a leading asterisk if present -- workaround
65 * for a known issue on a bunch of machines.
67 ******************************************************************************/
69 static void acpi_ut_copy_id_string(char *destination, char *source)
73 * Workaround for ID strings that have a leading asterisk. This construct
74 * is not allowed by the ACPI specification (ID strings must be
75 * alphanumeric), but enough existing machines have this embedded in their
76 * ID strings that the following code is useful.
78 if (*source == '*') {
79 source++;
82 /* Do the actual copy */
84 ACPI_STRCPY(destination, source);
87 /*******************************************************************************
89 * FUNCTION: acpi_ut_execute_HID
91 * PARAMETERS: device_node - Node for the device
92 * return_id - Where the string HID is returned
94 * RETURN: Status
96 * DESCRIPTION: Executes the _HID control method that returns the hardware
97 * ID of the device. The HID is either an 32-bit encoded EISAID
98 * Integer or a String. A string is always returned. An EISAID
99 * is converted to a string.
101 * NOTE: Internal function, no parameter validation
103 ******************************************************************************/
105 acpi_status
106 acpi_ut_execute_HID(struct acpi_namespace_node *device_node,
107 struct acpica_device_id **return_id)
109 union acpi_operand_object *obj_desc;
110 struct acpica_device_id *hid;
111 u32 length;
112 acpi_status status;
114 ACPI_FUNCTION_TRACE(ut_execute_HID);
116 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__HID,
117 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
118 &obj_desc);
119 if (ACPI_FAILURE(status)) {
120 return_ACPI_STATUS(status);
123 /* Get the size of the String to be returned, includes null terminator */
125 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
126 length = ACPI_EISAID_STRING_SIZE;
127 } else {
128 length = obj_desc->string.length + 1;
131 /* Allocate a buffer for the HID */
133 hid =
134 ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id) +
135 (acpi_size) length);
136 if (!hid) {
137 status = AE_NO_MEMORY;
138 goto cleanup;
141 /* Area for the string starts after DEVICE_ID struct */
143 hid->string = ACPI_ADD_PTR(char, hid, sizeof(struct acpica_device_id));
145 /* Convert EISAID to a string or simply copy existing string */
147 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
148 acpi_ex_eisa_id_to_string(hid->string, obj_desc->integer.value);
149 } else {
150 acpi_ut_copy_id_string(hid->string, obj_desc->string.pointer);
153 hid->length = length;
154 *return_id = hid;
156 cleanup:
158 /* On exit, we must delete the return object */
160 acpi_ut_remove_reference(obj_desc);
161 return_ACPI_STATUS(status);
164 /*******************************************************************************
166 * FUNCTION: acpi_ut_execute_UID
168 * PARAMETERS: device_node - Node for the device
169 * return_id - Where the string UID is returned
171 * RETURN: Status
173 * DESCRIPTION: Executes the _UID control method that returns the unique
174 * ID of the device. The UID is either a 64-bit Integer (NOT an
175 * EISAID) or a string. Always returns a string. A 64-bit integer
176 * is converted to a decimal string.
178 * NOTE: Internal function, no parameter validation
180 ******************************************************************************/
182 acpi_status
183 acpi_ut_execute_UID(struct acpi_namespace_node *device_node,
184 struct acpica_device_id **return_id)
186 union acpi_operand_object *obj_desc;
187 struct acpica_device_id *uid;
188 u32 length;
189 acpi_status status;
191 ACPI_FUNCTION_TRACE(ut_execute_UID);
193 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__UID,
194 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING,
195 &obj_desc);
196 if (ACPI_FAILURE(status)) {
197 return_ACPI_STATUS(status);
200 /* Get the size of the String to be returned, includes null terminator */
202 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
203 length = ACPI_MAX64_DECIMAL_DIGITS + 1;
204 } else {
205 length = obj_desc->string.length + 1;
208 /* Allocate a buffer for the UID */
210 uid =
211 ACPI_ALLOCATE_ZEROED(sizeof(struct acpica_device_id) +
212 (acpi_size) length);
213 if (!uid) {
214 status = AE_NO_MEMORY;
215 goto cleanup;
218 /* Area for the string starts after DEVICE_ID struct */
220 uid->string = ACPI_ADD_PTR(char, uid, sizeof(struct acpica_device_id));
222 /* Convert an Integer to string, or just copy an existing string */
224 if (obj_desc->common.type == ACPI_TYPE_INTEGER) {
225 acpi_ex_integer_to_string(uid->string, obj_desc->integer.value);
226 } else {
227 acpi_ut_copy_id_string(uid->string, obj_desc->string.pointer);
230 uid->length = length;
231 *return_id = uid;
233 cleanup:
235 /* On exit, we must delete the return object */
237 acpi_ut_remove_reference(obj_desc);
238 return_ACPI_STATUS(status);
241 /*******************************************************************************
243 * FUNCTION: acpi_ut_execute_CID
245 * PARAMETERS: device_node - Node for the device
246 * return_cid_list - Where the CID list is returned
248 * RETURN: Status, list of CID strings
250 * DESCRIPTION: Executes the _CID control method that returns one or more
251 * compatible hardware IDs for the device.
253 * NOTE: Internal function, no parameter validation
255 * A _CID method can return either a single compatible ID or a package of
256 * compatible IDs. Each compatible ID can be one of the following:
257 * 1) Integer (32 bit compressed EISA ID) or
258 * 2) String (PCI ID format, e.g. "PCI\VEN_vvvv&DEV_dddd&SUBSYS_ssssssss")
260 * The Integer CIDs are converted to string format by this function.
262 ******************************************************************************/
264 acpi_status
265 acpi_ut_execute_CID(struct acpi_namespace_node *device_node,
266 struct acpica_device_id_list **return_cid_list)
268 union acpi_operand_object **cid_objects;
269 union acpi_operand_object *obj_desc;
270 struct acpica_device_id_list *cid_list;
271 char *next_id_string;
272 u32 string_area_size;
273 u32 length;
274 u32 cid_list_size;
275 acpi_status status;
276 u32 count;
277 u32 i;
279 ACPI_FUNCTION_TRACE(ut_execute_CID);
281 /* Evaluate the _CID method for this device */
283 status = acpi_ut_evaluate_object(device_node, METHOD_NAME__CID,
284 ACPI_BTYPE_INTEGER | ACPI_BTYPE_STRING
285 | ACPI_BTYPE_PACKAGE, &obj_desc);
286 if (ACPI_FAILURE(status)) {
287 return_ACPI_STATUS(status);
291 * Get the count and size of the returned _CIDs. _CID can return either
292 * a Package of Integers/Strings or a single Integer or String.
293 * Note: This section also validates that all CID elements are of the
294 * correct type (Integer or String).
296 if (obj_desc->common.type == ACPI_TYPE_PACKAGE) {
297 count = obj_desc->package.count;
298 cid_objects = obj_desc->package.elements;
299 } else { /* Single Integer or String CID */
301 count = 1;
302 cid_objects = &obj_desc;
305 string_area_size = 0;
306 for (i = 0; i < count; i++) {
308 /* String lengths include null terminator */
310 switch (cid_objects[i]->common.type) {
311 case ACPI_TYPE_INTEGER:
312 string_area_size += ACPI_EISAID_STRING_SIZE;
313 break;
315 case ACPI_TYPE_STRING:
316 string_area_size += cid_objects[i]->string.length + 1;
317 break;
319 default:
320 status = AE_TYPE;
321 goto cleanup;
326 * Now that we know the length of the CIDs, allocate return buffer:
327 * 1) Size of the base structure +
328 * 2) Size of the CID DEVICE_ID array +
329 * 3) Size of the actual CID strings
331 cid_list_size = sizeof(struct acpica_device_id_list) +
332 ((count - 1) * sizeof(struct acpica_device_id)) + string_area_size;
334 cid_list = ACPI_ALLOCATE_ZEROED(cid_list_size);
335 if (!cid_list) {
336 status = AE_NO_MEMORY;
337 goto cleanup;
340 /* Area for CID strings starts after the CID DEVICE_ID array */
342 next_id_string = ACPI_CAST_PTR(char, cid_list->ids) +
343 ((acpi_size) count * sizeof(struct acpica_device_id));
345 /* Copy/convert the CIDs to the return buffer */
347 for (i = 0; i < count; i++) {
348 if (cid_objects[i]->common.type == ACPI_TYPE_INTEGER) {
350 /* Convert the Integer (EISAID) CID to a string */
352 acpi_ex_eisa_id_to_string(next_id_string,
353 cid_objects[i]->integer.
354 value);
355 length = ACPI_EISAID_STRING_SIZE;
356 } else { /* ACPI_TYPE_STRING */
358 /* Copy the String CID from the returned object */
360 acpi_ut_copy_id_string(next_id_string,
361 cid_objects[i]->string.pointer);
362 length = cid_objects[i]->string.length + 1;
365 cid_list->ids[i].string = next_id_string;
366 cid_list->ids[i].length = length;
367 next_id_string += length;
370 /* Finish the CID list */
372 cid_list->count = count;
373 cid_list->list_size = cid_list_size;
374 *return_cid_list = cid_list;
376 cleanup:
378 /* On exit, we must delete the _CID return object */
380 acpi_ut_remove_reference(obj_desc);
381 return_ACPI_STATUS(status);