blob: 40e0045876ee4fa954039dc1bed7c88a1db1d5d2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* Simple code to turn various tables in an ELF file into alias definitions.
2 * This deals with kernel datastructures where they should be
3 * dealt with: in the kernel source.
4 *
5 * Copyright 2002-2003 Rusty Russell, IBM Corporation
6 * 2003 Kai Germaschewski
7 *
8 *
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
11 */
12
13#include "modpost.h"
14
15/* We use the ELF typedefs for kernel_ulong_t but bite the bullet and
16 * use either stdint.h or inttypes.h for the rest. */
17#if KERNEL_ELFCLASS == ELFCLASS32
18typedef Elf32_Addr kernel_ulong_t;
Rusty Russell1d8f4302005-12-07 21:40:34 +010019#define BITS_PER_LONG 32
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#else
21typedef Elf64_Addr kernel_ulong_t;
Rusty Russell1d8f4302005-12-07 21:40:34 +010022#define BITS_PER_LONG 64
Linus Torvalds1da177e2005-04-16 15:20:36 -070023#endif
24#ifdef __sun__
25#include <inttypes.h>
26#else
27#include <stdint.h>
28#endif
29
Jeff Mahoney5e655772005-07-06 15:44:41 -040030#include <ctype.h>
31
Linus Torvalds1da177e2005-04-16 15:20:36 -070032typedef uint32_t __u32;
33typedef uint16_t __u16;
34typedef unsigned char __u8;
35
36/* Big exception to the "don't include kernel headers into userspace, which
Sam Ravnborg62070fa2006-03-03 16:46:04 +010037 * even potentially has different endianness and word sizes, since
Linus Torvalds1da177e2005-04-16 15:20:36 -070038 * we handle those differences explicitly below */
39#include "../../include/linux/mod_devicetable.h"
40
41#define ADD(str, sep, cond, field) \
42do { \
43 strcat(str, sep); \
44 if (cond) \
45 sprintf(str + strlen(str), \
46 sizeof(field) == 1 ? "%02X" : \
47 sizeof(field) == 2 ? "%04X" : \
48 sizeof(field) == 4 ? "%08X" : "", \
49 field); \
50 else \
51 sprintf(str + strlen(str), "*"); \
52} while(0)
53
Jean Delvareac551822008-05-02 20:37:21 +020054/* Always end in a wildcard, for future extension */
55static inline void add_wildcard(char *str)
56{
57 int len = strlen(str);
58
59 if (str[len - 1] != '*')
60 strcat(str + len, "*");
61}
62
Sam Ravnborg4ce6efe2008-03-23 21:38:54 +010063unsigned int cross_build = 0;
Sam Ravnborgfb33d812006-07-09 16:26:07 +020064/**
65 * Check that sizeof(device_id type) are consistent with size of section
66 * in .o file. If in-consistent then userspace and kernel does not agree
67 * on actual size which is a bug.
Kees Cooke0049822007-09-16 11:15:46 +020068 * Also verify that the final entry in the table is all zeros.
Sam Ravnborg4ce6efe2008-03-23 21:38:54 +010069 * Ignore both checks if build host differ from target host and size differs.
Sam Ravnborgfb33d812006-07-09 16:26:07 +020070 **/
Kees Cooke0049822007-09-16 11:15:46 +020071static void device_id_check(const char *modname, const char *device_id,
72 unsigned long size, unsigned long id_size,
73 void *symval)
Sam Ravnborgfb33d812006-07-09 16:26:07 +020074{
Kees Cooke0049822007-09-16 11:15:46 +020075 int i;
76
Sam Ravnborgfb33d812006-07-09 16:26:07 +020077 if (size % id_size || size < id_size) {
Sam Ravnborg4ce6efe2008-03-23 21:38:54 +010078 if (cross_build != 0)
79 return;
Sam Ravnborgfb33d812006-07-09 16:26:07 +020080 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
81 "of the size of section __mod_%s_device_table=%lu.\n"
82 "Fix definition of struct %s_device_id "
83 "in mod_devicetable.h\n",
84 modname, device_id, id_size, device_id, size, device_id);
85 }
Kees Cooke0049822007-09-16 11:15:46 +020086 /* Verify last one is a terminator */
87 for (i = 0; i < id_size; i++ ) {
88 if (*(uint8_t*)(symval+size-id_size+i)) {
89 fprintf(stderr,"%s: struct %s_device_id is %lu bytes. "
90 "The last of %lu is:\n",
91 modname, device_id, id_size, size / id_size);
92 for (i = 0; i < id_size; i++ )
93 fprintf(stderr,"0x%02x ",
94 *(uint8_t*)(symval+size-id_size+i) );
95 fprintf(stderr,"\n");
96 fatal("%s: struct %s_device_id is not terminated "
97 "with a NULL entry!\n", modname, device_id);
98 }
99 }
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200100}
101
Roman Kaganb19dcd92005-04-22 15:07:01 -0700102/* USB is special because the bcdDevice can be matched against a numeric range */
103/* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
104static void do_usb_entry(struct usb_device_id *id,
105 unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
106 unsigned char range_lo, unsigned char range_hi,
107 struct module *mod)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700108{
Roman Kaganb19dcd92005-04-22 15:07:01 -0700109 char alias[500];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 strcpy(alias, "usb:");
111 ADD(alias, "v", id->match_flags&USB_DEVICE_ID_MATCH_VENDOR,
112 id->idVendor);
113 ADD(alias, "p", id->match_flags&USB_DEVICE_ID_MATCH_PRODUCT,
114 id->idProduct);
Roman Kaganb19dcd92005-04-22 15:07:01 -0700115
116 strcat(alias, "d");
117 if (bcdDevice_initial_digits)
118 sprintf(alias + strlen(alias), "%0*X",
119 bcdDevice_initial_digits, bcdDevice_initial);
120 if (range_lo == range_hi)
121 sprintf(alias + strlen(alias), "%u", range_lo);
122 else if (range_lo > 0 || range_hi < 9)
123 sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi);
124 if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1))
125 strcat(alias, "*");
126
Linus Torvalds1da177e2005-04-16 15:20:36 -0700127 ADD(alias, "dc", id->match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS,
128 id->bDeviceClass);
129 ADD(alias, "dsc",
130 id->match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS,
131 id->bDeviceSubClass);
132 ADD(alias, "dp",
133 id->match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL,
134 id->bDeviceProtocol);
135 ADD(alias, "ic",
136 id->match_flags&USB_DEVICE_ID_MATCH_INT_CLASS,
137 id->bInterfaceClass);
138 ADD(alias, "isc",
139 id->match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS,
140 id->bInterfaceSubClass);
141 ADD(alias, "ip",
142 id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL,
143 id->bInterfaceProtocol);
Roman Kaganb19dcd92005-04-22 15:07:01 -0700144
Jean Delvareac551822008-05-02 20:37:21 +0200145 add_wildcard(alias);
Roman Kaganb19dcd92005-04-22 15:07:01 -0700146 buf_printf(&mod->dev_table_buf,
147 "MODULE_ALIAS(\"%s\");\n", alias);
148}
149
150static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
151{
152 unsigned int devlo, devhi;
153 unsigned char chi, clo;
154 int ndigits;
155
156 id->match_flags = TO_NATIVE(id->match_flags);
157 id->idVendor = TO_NATIVE(id->idVendor);
158 id->idProduct = TO_NATIVE(id->idProduct);
159
160 devlo = id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO ?
161 TO_NATIVE(id->bcdDevice_lo) : 0x0U;
162 devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ?
163 TO_NATIVE(id->bcdDevice_hi) : ~0x0U;
164
165 /*
166 * Some modules (visor) have empty slots as placeholder for
167 * run-time specification that results in catch-all alias
168 */
Greg Kroah-Hartmande6f92b2008-01-28 09:50:12 -0800169 if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass))
Roman Kaganb19dcd92005-04-22 15:07:01 -0700170 return;
171
172 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
173 for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) {
174 clo = devlo & 0xf;
175 chi = devhi & 0xf;
176 if (chi > 9) /* it's bcd not hex */
177 chi = 9;
178 devlo >>= 4;
179 devhi >>= 4;
180
181 if (devlo == devhi || !ndigits) {
182 do_usb_entry(id, devlo, ndigits, clo, chi, mod);
183 break;
184 }
185
186 if (clo > 0)
187 do_usb_entry(id, devlo++, ndigits, clo, 9, mod);
188
189 if (chi < 9)
190 do_usb_entry(id, devhi--, ndigits, 0, chi, mod);
191 }
192}
193
194static void do_usb_table(void *symval, unsigned long size,
195 struct module *mod)
196{
197 unsigned int i;
198 const unsigned long id_size = sizeof(struct usb_device_id);
199
Kees Cooke0049822007-09-16 11:15:46 +0200200 device_id_check(mod->name, "usb", size, id_size, symval);
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200201
Roman Kaganb19dcd92005-04-22 15:07:01 -0700202 /* Leave last one: it's the terminator. */
203 size -= id_size;
204
205 for (i = 0; i < size; i += id_size)
206 do_usb_entry_multi(symval + i, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207}
208
Jiri Slabye8c84f92008-05-19 15:50:01 +0200209/* Looks like: hid:bNvNpN */
210static int do_hid_entry(const char *filename,
211 struct hid_device_id *id, char *alias)
212{
Jiri Slaby2b639382009-02-17 12:38:36 +0100213 id->bus = TO_NATIVE(id->bus);
Jiri Slabye8c84f92008-05-19 15:50:01 +0200214 id->vendor = TO_NATIVE(id->vendor);
215 id->product = TO_NATIVE(id->product);
216
217 sprintf(alias, "hid:b%04X", id->bus);
218 ADD(alias, "v", id->vendor != HID_ANY_ID, id->vendor);
219 ADD(alias, "p", id->product != HID_ANY_ID, id->product);
220
221 return 1;
222}
223
Linus Torvalds1da177e2005-04-16 15:20:36 -0700224/* Looks like: ieee1394:venNmoNspNverN */
225static int do_ieee1394_entry(const char *filename,
226 struct ieee1394_device_id *id, char *alias)
227{
228 id->match_flags = TO_NATIVE(id->match_flags);
229 id->vendor_id = TO_NATIVE(id->vendor_id);
230 id->model_id = TO_NATIVE(id->model_id);
231 id->specifier_id = TO_NATIVE(id->specifier_id);
232 id->version = TO_NATIVE(id->version);
233
234 strcpy(alias, "ieee1394:");
235 ADD(alias, "ven", id->match_flags & IEEE1394_MATCH_VENDOR_ID,
236 id->vendor_id);
237 ADD(alias, "mo", id->match_flags & IEEE1394_MATCH_MODEL_ID,
238 id->model_id);
239 ADD(alias, "sp", id->match_flags & IEEE1394_MATCH_SPECIFIER_ID,
240 id->specifier_id);
241 ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION,
242 id->version);
243
Jean Delvareac551822008-05-02 20:37:21 +0200244 add_wildcard(alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 return 1;
246}
247
248/* Looks like: pci:vNdNsvNsdNbcNscNiN. */
249static int do_pci_entry(const char *filename,
250 struct pci_device_id *id, char *alias)
251{
252 /* Class field can be divided into these three. */
253 unsigned char baseclass, subclass, interface,
254 baseclass_mask, subclass_mask, interface_mask;
255
256 id->vendor = TO_NATIVE(id->vendor);
257 id->device = TO_NATIVE(id->device);
258 id->subvendor = TO_NATIVE(id->subvendor);
259 id->subdevice = TO_NATIVE(id->subdevice);
260 id->class = TO_NATIVE(id->class);
261 id->class_mask = TO_NATIVE(id->class_mask);
262
263 strcpy(alias, "pci:");
264 ADD(alias, "v", id->vendor != PCI_ANY_ID, id->vendor);
265 ADD(alias, "d", id->device != PCI_ANY_ID, id->device);
266 ADD(alias, "sv", id->subvendor != PCI_ANY_ID, id->subvendor);
267 ADD(alias, "sd", id->subdevice != PCI_ANY_ID, id->subdevice);
268
269 baseclass = (id->class) >> 16;
270 baseclass_mask = (id->class_mask) >> 16;
271 subclass = (id->class) >> 8;
272 subclass_mask = (id->class_mask) >> 8;
273 interface = id->class;
274 interface_mask = id->class_mask;
275
276 if ((baseclass_mask != 0 && baseclass_mask != 0xFF)
277 || (subclass_mask != 0 && subclass_mask != 0xFF)
278 || (interface_mask != 0 && interface_mask != 0xFF)) {
Sam Ravnborgcb805142006-01-28 16:57:26 +0100279 warn("Can't handle masks in %s:%04X\n",
280 filename, id->class_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 return 0;
282 }
283
284 ADD(alias, "bc", baseclass_mask == 0xFF, baseclass);
285 ADD(alias, "sc", subclass_mask == 0xFF, subclass);
286 ADD(alias, "i", interface_mask == 0xFF, interface);
Jean Delvareac551822008-05-02 20:37:21 +0200287 add_wildcard(alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700288 return 1;
289}
290
Sam Ravnborg62070fa2006-03-03 16:46:04 +0100291/* looks like: "ccw:tNmNdtNdmN" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292static int do_ccw_entry(const char *filename,
293 struct ccw_device_id *id, char *alias)
294{
295 id->match_flags = TO_NATIVE(id->match_flags);
296 id->cu_type = TO_NATIVE(id->cu_type);
297 id->cu_model = TO_NATIVE(id->cu_model);
298 id->dev_type = TO_NATIVE(id->dev_type);
299 id->dev_model = TO_NATIVE(id->dev_model);
300
301 strcpy(alias, "ccw:");
302 ADD(alias, "t", id->match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE,
303 id->cu_type);
304 ADD(alias, "m", id->match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL,
305 id->cu_model);
306 ADD(alias, "dt", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE,
307 id->dev_type);
Bastian Blankde1d9c02006-03-06 15:43:00 -0800308 ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 id->dev_model);
Jean Delvareac551822008-05-02 20:37:21 +0200310 add_wildcard(alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700311 return 1;
312}
313
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200314/* looks like: "ap:tN" */
315static int do_ap_entry(const char *filename,
316 struct ap_device_id *id, char *alias)
317{
Jean Delvareac551822008-05-02 20:37:21 +0200318 sprintf(alias, "ap:t%02X*", id->dev_type);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200319 return 1;
320}
321
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200322/* looks like: "css:tN" */
323static int do_css_entry(const char *filename,
324 struct css_device_id *id, char *alias)
325{
326 sprintf(alias, "css:t%01X", id->type);
327 return 1;
328}
329
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330/* Looks like: "serio:tyNprNidNexN" */
331static int do_serio_entry(const char *filename,
332 struct serio_device_id *id, char *alias)
333{
334 id->type = TO_NATIVE(id->type);
335 id->proto = TO_NATIVE(id->proto);
336 id->id = TO_NATIVE(id->id);
337 id->extra = TO_NATIVE(id->extra);
338
339 strcpy(alias, "serio:");
340 ADD(alias, "ty", id->type != SERIO_ANY, id->type);
341 ADD(alias, "pr", id->proto != SERIO_ANY, id->proto);
342 ADD(alias, "id", id->id != SERIO_ANY, id->id);
343 ADD(alias, "ex", id->extra != SERIO_ANY, id->extra);
344
Jean Delvareac551822008-05-02 20:37:21 +0200345 add_wildcard(alias);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 return 1;
347}
348
Thomas Renninger29b71a12007-07-23 14:43:51 +0200349/* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
350static int do_acpi_entry(const char *filename,
351 struct acpi_device_id *id, char *alias)
352{
Jean Delvareac551822008-05-02 20:37:21 +0200353 sprintf(alias, "acpi*:%s:*", id->id);
Thomas Renninger29b71a12007-07-23 14:43:51 +0200354 return 1;
355}
356
Linus Torvalds1da177e2005-04-16 15:20:36 -0700357/* looks like: "pnp:dD" */
Kay Sievers22454cb2008-05-28 23:06:47 +0200358static void do_pnp_device_entry(void *symval, unsigned long size,
359 struct module *mod)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700360{
Kay Sievers22454cb2008-05-28 23:06:47 +0200361 const unsigned long id_size = sizeof(struct pnp_device_id);
Kay Sievers5e4c6562008-08-21 15:28:56 +0200362 const unsigned int count = (size / id_size)-1;
363 const struct pnp_device_id *devs = symval;
364 unsigned int i;
Kay Sievers22454cb2008-05-28 23:06:47 +0200365
366 device_id_check(mod->name, "pnp", size, id_size, symval);
367
Kay Sievers5e4c6562008-08-21 15:28:56 +0200368 for (i = 0; i < count; i++) {
369 const char *id = (char *)devs[i].id;
Kay Sievers72638f52009-01-08 03:06:42 +0100370 char acpi_id[sizeof(devs[0].id)];
371 int j;
Kay Sievers5e4c6562008-08-21 15:28:56 +0200372
373 buf_printf(&mod->dev_table_buf,
374 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
Kay Sievers72638f52009-01-08 03:06:42 +0100375
376 /* fix broken pnp bus lowercasing */
377 for (j = 0; j < sizeof(acpi_id); j++)
378 acpi_id[j] = toupper(id[j]);
Kay Sievers5e4c6562008-08-21 15:28:56 +0200379 buf_printf(&mod->dev_table_buf,
Kay Sievers72638f52009-01-08 03:06:42 +0100380 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
Kay Sievers5e4c6562008-08-21 15:28:56 +0200381 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700382}
383
Kay Sievers0c81eed2008-02-21 00:35:54 +0100384/* looks like: "pnp:dD" for every device of the card */
385static void do_pnp_card_entries(void *symval, unsigned long size,
386 struct module *mod)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700387{
Kay Sievers0c81eed2008-02-21 00:35:54 +0100388 const unsigned long id_size = sizeof(struct pnp_card_device_id);
389 const unsigned int count = (size / id_size)-1;
390 const struct pnp_card_device_id *cards = symval;
391 unsigned int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
Kay Sievers0c81eed2008-02-21 00:35:54 +0100393 device_id_check(mod->name, "pnp", size, id_size, symval);
394
395 for (i = 0; i < count; i++) {
396 unsigned int j;
397 const struct pnp_card_device_id *card = &cards[i];
398
399 for (j = 0; j < PNP_MAX_DEVICES; j++) {
400 const char *id = (char *)card->devs[j].id;
401 int i2, j2;
402 int dup = 0;
403
404 if (!id[0])
405 break;
406
407 /* find duplicate, already added value */
408 for (i2 = 0; i2 < i && !dup; i2++) {
409 const struct pnp_card_device_id *card2 = &cards[i2];
410
411 for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) {
412 const char *id2 = (char *)card2->devs[j2].id;
413
414 if (!id2[0])
415 break;
416
417 if (!strcmp(id, id2)) {
418 dup = 1;
419 break;
420 }
421 }
422 }
423
424 /* add an individual alias for every device entry */
Kay Sievers22454cb2008-05-28 23:06:47 +0200425 if (!dup) {
Kay Sievers72638f52009-01-08 03:06:42 +0100426 char acpi_id[sizeof(card->devs[0].id)];
427 int k;
428
Kay Sievers0c81eed2008-02-21 00:35:54 +0100429 buf_printf(&mod->dev_table_buf,
430 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
Kay Sievers72638f52009-01-08 03:06:42 +0100431
432 /* fix broken pnp bus lowercasing */
433 for (k = 0; k < sizeof(acpi_id); k++)
434 acpi_id[k] = toupper(id[k]);
Kay Sievers22454cb2008-05-28 23:06:47 +0200435 buf_printf(&mod->dev_table_buf,
Kay Sievers72638f52009-01-08 03:06:42 +0100436 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id);
Kay Sievers22454cb2008-05-28 23:06:47 +0200437 }
Kay Sievers0c81eed2008-02-21 00:35:54 +0100438 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440}
441
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700442/* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
443static int do_pcmcia_entry(const char *filename,
444 struct pcmcia_device_id *id, char *alias)
445{
446 unsigned int i;
447
Kars de Jong4fb7edc2005-09-25 14:39:46 +0200448 id->match_flags = TO_NATIVE(id->match_flags);
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700449 id->manf_id = TO_NATIVE(id->manf_id);
450 id->card_id = TO_NATIVE(id->card_id);
451 id->func_id = TO_NATIVE(id->func_id);
452 id->function = TO_NATIVE(id->function);
453 id->device_no = TO_NATIVE(id->device_no);
Kars de Jong4fb7edc2005-09-25 14:39:46 +0200454
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700455 for (i=0; i<4; i++) {
456 id->prod_id_hash[i] = TO_NATIVE(id->prod_id_hash[i]);
457 }
458
459 strcpy(alias, "pcmcia:");
460 ADD(alias, "m", id->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID,
461 id->manf_id);
462 ADD(alias, "c", id->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID,
463 id->card_id);
464 ADD(alias, "f", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID,
465 id->func_id);
466 ADD(alias, "fn", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION,
467 id->function);
468 ADD(alias, "pfn", id->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO,
469 id->device_no);
470 ADD(alias, "pa", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, id->prod_id_hash[0]);
471 ADD(alias, "pb", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, id->prod_id_hash[1]);
472 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]);
473 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]);
474
Jean Delvareac551822008-05-02 20:37:21 +0200475 add_wildcard(alias);
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700476 return 1;
477}
478
479
480
Jeff Mahoney5e655772005-07-06 15:44:41 -0400481static int do_of_entry (const char *filename, struct of_device_id *of, char *alias)
482{
Sylvain Munautd1ab4232007-05-08 19:59:29 +1000483 int len;
Jeff Mahoney5e655772005-07-06 15:44:41 -0400484 char *tmp;
Sylvain Munautd1ab4232007-05-08 19:59:29 +1000485 len = sprintf (alias, "of:N%sT%s",
Jeff Mahoney5e655772005-07-06 15:44:41 -0400486 of->name[0] ? of->name : "*",
Sylvain Munautd1ab4232007-05-08 19:59:29 +1000487 of->type[0] ? of->type : "*");
488
489 if (of->compatible[0])
490 sprintf (&alias[len], "%sC%s",
491 of->type[0] ? "*" : "",
492 of->compatible);
Jeff Mahoney5e655772005-07-06 15:44:41 -0400493
494 /* Replace all whitespace with underscores */
495 for (tmp = alias; tmp && *tmp; tmp++)
496 if (isspace (*tmp))
497 *tmp = '_';
498
Jean Delvareac551822008-05-02 20:37:21 +0200499 add_wildcard(alias);
Jeff Mahoney5e655772005-07-06 15:44:41 -0400500 return 1;
501}
502
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000503static int do_vio_entry(const char *filename, struct vio_device_id *vio,
504 char *alias)
505{
506 char *tmp;
507
508 sprintf(alias, "vio:T%sS%s", vio->type[0] ? vio->type : "*",
509 vio->compat[0] ? vio->compat : "*");
510
511 /* Replace all whitespace with underscores */
512 for (tmp = alias; tmp && *tmp; tmp++)
513 if (isspace (*tmp))
514 *tmp = '_';
515
Jean Delvareac551822008-05-02 20:37:21 +0200516 add_wildcard(alias);
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000517 return 1;
518}
519
Rusty Russell1d8f4302005-12-07 21:40:34 +0100520#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
521
522static void do_input(char *alias,
523 kernel_ulong_t *arr, unsigned int min, unsigned int max)
524{
525 unsigned int i;
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400526
527 for (i = min; i < max; i++)
Hans de Goedee0e92632006-08-15 12:09:27 +0200528 if (arr[i / BITS_PER_LONG] & (1L << (i%BITS_PER_LONG)))
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400529 sprintf(alias + strlen(alias), "%X,*", i);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100530}
531
532/* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
533static int do_input_entry(const char *filename, struct input_device_id *id,
534 char *alias)
535{
536 sprintf(alias, "input:");
537
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400538 ADD(alias, "b", id->flags & INPUT_DEVICE_ID_MATCH_BUS, id->bustype);
539 ADD(alias, "v", id->flags & INPUT_DEVICE_ID_MATCH_VENDOR, id->vendor);
540 ADD(alias, "p", id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT, id->product);
541 ADD(alias, "e", id->flags & INPUT_DEVICE_ID_MATCH_VERSION, id->version);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100542
543 sprintf(alias + strlen(alias), "-e*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400544 if (id->flags & INPUT_DEVICE_ID_MATCH_EVBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100545 do_input(alias, id->evbit, 0, INPUT_DEVICE_ID_EV_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100546 sprintf(alias + strlen(alias), "k*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400547 if (id->flags & INPUT_DEVICE_ID_MATCH_KEYBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100548 do_input(alias, id->keybit,
549 INPUT_DEVICE_ID_KEY_MIN_INTERESTING,
550 INPUT_DEVICE_ID_KEY_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100551 sprintf(alias + strlen(alias), "r*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400552 if (id->flags & INPUT_DEVICE_ID_MATCH_RELBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100553 do_input(alias, id->relbit, 0, INPUT_DEVICE_ID_REL_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100554 sprintf(alias + strlen(alias), "a*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400555 if (id->flags & INPUT_DEVICE_ID_MATCH_ABSBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100556 do_input(alias, id->absbit, 0, INPUT_DEVICE_ID_ABS_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100557 sprintf(alias + strlen(alias), "m*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400558 if (id->flags & INPUT_DEVICE_ID_MATCH_MSCIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100559 do_input(alias, id->mscbit, 0, INPUT_DEVICE_ID_MSC_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100560 sprintf(alias + strlen(alias), "l*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400561 if (id->flags & INPUT_DEVICE_ID_MATCH_LEDBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100562 do_input(alias, id->ledbit, 0, INPUT_DEVICE_ID_LED_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100563 sprintf(alias + strlen(alias), "s*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400564 if (id->flags & INPUT_DEVICE_ID_MATCH_SNDBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100565 do_input(alias, id->sndbit, 0, INPUT_DEVICE_ID_SND_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100566 sprintf(alias + strlen(alias), "f*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400567 if (id->flags & INPUT_DEVICE_ID_MATCH_FFBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100568 do_input(alias, id->ffbit, 0, INPUT_DEVICE_ID_FF_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100569 sprintf(alias + strlen(alias), "w*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400570 if (id->flags & INPUT_DEVICE_ID_MATCH_SWBIT)
Sam Ravnborgdc24f0e2007-03-09 19:59:06 +0100571 do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100572 return 1;
573}
574
Michael Tokarev07563c72006-09-27 01:50:56 -0700575static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa,
576 char *alias)
577{
578 if (eisa->sig[0])
579 sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig);
Jean Delvareac551822008-05-02 20:37:21 +0200580 else
581 strcat(alias, "*");
Michael Tokarev07563c72006-09-27 01:50:56 -0700582 return 1;
583}
584
Kyle McMartinf3cf2672007-01-13 14:58:21 -0500585/* Looks like: parisc:tNhvNrevNsvN */
586static int do_parisc_entry(const char *filename, struct parisc_device_id *id,
587 char *alias)
588{
589 id->hw_type = TO_NATIVE(id->hw_type);
590 id->hversion = TO_NATIVE(id->hversion);
591 id->hversion_rev = TO_NATIVE(id->hversion_rev);
592 id->sversion = TO_NATIVE(id->sversion);
593
594 strcpy(alias, "parisc:");
Kyle McMartinf354ef82007-01-13 15:02:09 -0500595 ADD(alias, "t", id->hw_type != PA_HWTYPE_ANY_ID, id->hw_type);
596 ADD(alias, "hv", id->hversion != PA_HVERSION_ANY_ID, id->hversion);
597 ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev);
598 ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion);
Kyle McMartinf3cf2672007-01-13 14:58:21 -0500599
Jean Delvareac551822008-05-02 20:37:21 +0200600 add_wildcard(alias);
Kyle McMartinf3cf2672007-01-13 14:58:21 -0500601 return 1;
602}
603
Pierre Ossmand59b66c2007-06-17 11:34:23 +0200604/* Looks like: sdio:cNvNdN. */
605static int do_sdio_entry(const char *filename,
606 struct sdio_device_id *id, char *alias)
607{
608 id->class = TO_NATIVE(id->class);
609 id->vendor = TO_NATIVE(id->vendor);
610 id->device = TO_NATIVE(id->device);
611
612 strcpy(alias, "sdio:");
613 ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class);
614 ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor);
615 ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device);
Jean Delvareac551822008-05-02 20:37:21 +0200616 add_wildcard(alias);
Linus Torvalds038a5002007-10-11 19:40:14 -0700617 return 1;
618}
Pierre Ossmand59b66c2007-06-17 11:34:23 +0200619
Michael Buesch61e115a2007-09-18 15:12:50 -0400620/* Looks like: ssb:vNidNrevN. */
621static int do_ssb_entry(const char *filename,
622 struct ssb_device_id *id, char *alias)
623{
624 id->vendor = TO_NATIVE(id->vendor);
625 id->coreid = TO_NATIVE(id->coreid);
626 id->revision = TO_NATIVE(id->revision);
627
628 strcpy(alias, "ssb:");
629 ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor);
630 ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid);
631 ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision);
Jean Delvareac551822008-05-02 20:37:21 +0200632 add_wildcard(alias);
Pierre Ossmand59b66c2007-06-17 11:34:23 +0200633 return 1;
634}
635
Rusty Russellb01d9f22007-10-22 11:03:39 +1000636/* Looks like: virtio:dNvN */
637static int do_virtio_entry(const char *filename, struct virtio_device_id *id,
638 char *alias)
639{
640 id->device = TO_NATIVE(id->device);
641 id->vendor = TO_NATIVE(id->vendor);
642
643 strcpy(alias, "virtio:");
Christian Borntraegere3353852009-05-26 15:46:10 +0200644 ADD(alias, "d", id->device != VIRTIO_DEV_ANY_ID, id->device);
Rusty Russellb01d9f22007-10-22 11:03:39 +1000645 ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor);
646
Jean Delvareac551822008-05-02 20:37:21 +0200647 add_wildcard(alias);
Rusty Russellb01d9f22007-10-22 11:03:39 +1000648 return 1;
649}
650
Jean Delvared2653e92008-04-29 23:11:39 +0200651/* Looks like: i2c:S */
652static int do_i2c_entry(const char *filename, struct i2c_device_id *id,
653 char *alias)
654{
655 sprintf(alias, I2C_MODULE_PREFIX "%s", id->name);
656
657 return 1;
658}
659
David Woodhoused945b692008-09-16 16:23:28 -0700660static const struct dmifield {
661 const char *prefix;
662 int field;
663} dmi_fields[] = {
664 { "bvn", DMI_BIOS_VENDOR },
665 { "bvr", DMI_BIOS_VERSION },
666 { "bd", DMI_BIOS_DATE },
667 { "svn", DMI_SYS_VENDOR },
668 { "pn", DMI_PRODUCT_NAME },
669 { "pvr", DMI_PRODUCT_VERSION },
670 { "rvn", DMI_BOARD_VENDOR },
671 { "rn", DMI_BOARD_NAME },
672 { "rvr", DMI_BOARD_VERSION },
673 { "cvn", DMI_CHASSIS_VENDOR },
674 { "ct", DMI_CHASSIS_TYPE },
675 { "cvr", DMI_CHASSIS_VERSION },
676 { NULL, DMI_NONE }
677};
678
679static void dmi_ascii_filter(char *d, const char *s)
680{
681 /* Filter out characters we don't want to see in the modalias string */
682 for (; *s; s++)
683 if (*s > ' ' && *s < 127 && *s != ':')
684 *(d++) = *s;
685
686 *d = 0;
687}
688
689
690static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
691 char *alias)
692{
693 int i, j;
694
695 sprintf(alias, "dmi*");
696
697 for (i = 0; i < ARRAY_SIZE(dmi_fields); i++) {
698 for (j = 0; j < 4; j++) {
699 if (id->matches[j].slot &&
700 id->matches[j].slot == dmi_fields[i].field) {
701 sprintf(alias + strlen(alias), ":%s*",
702 dmi_fields[i].prefix);
703 dmi_ascii_filter(alias + strlen(alias),
704 id->matches[j].substr);
705 strcat(alias, "*");
706 }
707 }
708 }
709
710 strcat(alias, ":");
711 return 1;
712}
Eric Miao57fee4a2009-02-04 11:52:40 +0800713
714static int do_platform_entry(const char *filename,
715 struct platform_device_id *id, char *alias)
716{
717 sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name);
718 return 1;
719}
720
Adrian Bunkf606ddf2008-07-23 21:28:50 -0700721/* Ignore any prefix, eg. some architectures prepend _ */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722static inline int sym_is(const char *symbol, const char *name)
723{
724 const char *match;
725
726 match = strstr(symbol, name);
727 if (!match)
728 return 0;
729 return match[strlen(symbol)] == '\0';
730}
731
732static void do_table(void *symval, unsigned long size,
733 unsigned long id_size,
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200734 const char *device_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 void *function,
736 struct module *mod)
737{
738 unsigned int i;
739 char alias[500];
740 int (*do_entry)(const char *, void *entry, char *alias) = function;
741
Kees Cooke0049822007-09-16 11:15:46 +0200742 device_id_check(mod->name, device_id, size, id_size, symval);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 /* Leave last one: it's the terminator. */
744 size -= id_size;
745
746 for (i = 0; i < size; i += id_size) {
747 if (do_entry(mod->name, symval+i, alias)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 buf_printf(&mod->dev_table_buf,
749 "MODULE_ALIAS(\"%s\");\n", alias);
750 }
751 }
752}
753
754/* Create MODULE_ALIAS() statements.
755 * At this time, we cannot write the actual output C source yet,
756 * so we write into the mod->dev_table_buf buffer. */
757void handle_moddevtable(struct module *mod, struct elf_info *info,
758 Elf_Sym *sym, const char *symname)
759{
760 void *symval;
Kees Cooke0049822007-09-16 11:15:46 +0200761 char *zeros = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700762
763 /* We're looking for a section relative symbol */
764 if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum)
765 return;
766
Kees Cooke0049822007-09-16 11:15:46 +0200767 /* Handle all-NULL symbols allocated into .bss */
768 if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) {
769 zeros = calloc(1, sym->st_size);
770 symval = zeros;
771 } else {
772 symval = (void *)info->hdr
773 + info->sechdrs[sym->st_shndx].sh_offset
774 + sym->st_value;
775 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700776
777 if (sym_is(symname, "__mod_pci_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200778 do_table(symval, sym->st_size,
779 sizeof(struct pci_device_id), "pci",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780 do_pci_entry, mod);
781 else if (sym_is(symname, "__mod_usb_device_table"))
Roman Kaganb19dcd92005-04-22 15:07:01 -0700782 /* special case to handle bcdDevice ranges */
783 do_usb_table(symval, sym->st_size, mod);
Jiri Slabye8c84f92008-05-19 15:50:01 +0200784 else if (sym_is(symname, "__mod_hid_device_table"))
785 do_table(symval, sym->st_size,
786 sizeof(struct hid_device_id), "hid",
787 do_hid_entry, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788 else if (sym_is(symname, "__mod_ieee1394_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200789 do_table(symval, sym->st_size,
790 sizeof(struct ieee1394_device_id), "ieee1394",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791 do_ieee1394_entry, mod);
792 else if (sym_is(symname, "__mod_ccw_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200793 do_table(symval, sym->st_size,
794 sizeof(struct ccw_device_id), "ccw",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 do_ccw_entry, mod);
Martin Schwidefsky1534c382006-09-20 15:58:25 +0200796 else if (sym_is(symname, "__mod_ap_device_table"))
797 do_table(symval, sym->st_size,
798 sizeof(struct ap_device_id), "ap",
799 do_ap_entry, mod);
Cornelia Huck7e9db9e2008-07-14 09:58:44 +0200800 else if (sym_is(symname, "__mod_css_device_table"))
801 do_table(symval, sym->st_size,
802 sizeof(struct css_device_id), "css",
803 do_css_entry, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 else if (sym_is(symname, "__mod_serio_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200805 do_table(symval, sym->st_size,
806 sizeof(struct serio_device_id), "serio",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700807 do_serio_entry, mod);
Thomas Renninger29b71a12007-07-23 14:43:51 +0200808 else if (sym_is(symname, "__mod_acpi_device_table"))
809 do_table(symval, sym->st_size,
810 sizeof(struct acpi_device_id), "acpi",
811 do_acpi_entry, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 else if (sym_is(symname, "__mod_pnp_device_table"))
Kay Sievers22454cb2008-05-28 23:06:47 +0200813 do_pnp_device_entry(symval, sym->st_size, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814 else if (sym_is(symname, "__mod_pnp_card_device_table"))
Kay Sievers0c81eed2008-02-21 00:35:54 +0100815 do_pnp_card_entries(symval, sym->st_size, mod);
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700816 else if (sym_is(symname, "__mod_pcmcia_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200817 do_table(symval, sym->st_size,
818 sizeof(struct pcmcia_device_id), "pcmcia",
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700819 do_pcmcia_entry, mod);
Jeff Mahoney5e655772005-07-06 15:44:41 -0400820 else if (sym_is(symname, "__mod_of_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200821 do_table(symval, sym->st_size,
822 sizeof(struct of_device_id), "of",
Jeff Mahoney5e655772005-07-06 15:44:41 -0400823 do_of_entry, mod);
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000824 else if (sym_is(symname, "__mod_vio_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200825 do_table(symval, sym->st_size,
826 sizeof(struct vio_device_id), "vio",
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000827 do_vio_entry, mod);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100828 else if (sym_is(symname, "__mod_input_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200829 do_table(symval, sym->st_size,
830 sizeof(struct input_device_id), "input",
Rusty Russell1d8f4302005-12-07 21:40:34 +0100831 do_input_entry, mod);
Michael Tokarev07563c72006-09-27 01:50:56 -0700832 else if (sym_is(symname, "__mod_eisa_device_table"))
833 do_table(symval, sym->st_size,
834 sizeof(struct eisa_device_id), "eisa",
835 do_eisa_entry, mod);
Kyle McMartinf3cf2672007-01-13 14:58:21 -0500836 else if (sym_is(symname, "__mod_parisc_device_table"))
837 do_table(symval, sym->st_size,
838 sizeof(struct parisc_device_id), "parisc",
839 do_parisc_entry, mod);
Pierre Ossmand59b66c2007-06-17 11:34:23 +0200840 else if (sym_is(symname, "__mod_sdio_device_table"))
841 do_table(symval, sym->st_size,
842 sizeof(struct sdio_device_id), "sdio",
843 do_sdio_entry, mod);
Michael Buesch61e115a2007-09-18 15:12:50 -0400844 else if (sym_is(symname, "__mod_ssb_device_table"))
845 do_table(symval, sym->st_size,
846 sizeof(struct ssb_device_id), "ssb",
847 do_ssb_entry, mod);
Rusty Russellb01d9f22007-10-22 11:03:39 +1000848 else if (sym_is(symname, "__mod_virtio_device_table"))
849 do_table(symval, sym->st_size,
850 sizeof(struct virtio_device_id), "virtio",
851 do_virtio_entry, mod);
Jean Delvared2653e92008-04-29 23:11:39 +0200852 else if (sym_is(symname, "__mod_i2c_device_table"))
853 do_table(symval, sym->st_size,
854 sizeof(struct i2c_device_id), "i2c",
855 do_i2c_entry, mod);
David Woodhoused945b692008-09-16 16:23:28 -0700856 else if (sym_is(symname, "__mod_dmi_device_table"))
857 do_table(symval, sym->st_size,
858 sizeof(struct dmi_system_id), "dmi",
859 do_dmi_entry, mod);
Eric Miao57fee4a2009-02-04 11:52:40 +0800860 else if (sym_is(symname, "__mod_platform_device_table"))
861 do_table(symval, sym->st_size,
862 sizeof(struct platform_device_id), "platform",
863 do_platform_entry, mod);
Kees Cooke0049822007-09-16 11:15:46 +0200864 free(zeros);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865}
866
867/* Now add out buffered information to the generated C source */
868void add_moddevtable(struct buffer *buf, struct module *mod)
869{
870 buf_printf(buf, "\n");
871 buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos);
872 free(mod->dev_table_buf.p);
873}