blob: 44312926b84934f3b68e12e0bda278f3824cc4ed [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"
Rusty Russell1d8f4302005-12-07 21:40:34 +010040#include "../../include/linux/input.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070041
42#define ADD(str, sep, cond, field) \
43do { \
44 strcat(str, sep); \
45 if (cond) \
46 sprintf(str + strlen(str), \
47 sizeof(field) == 1 ? "%02X" : \
48 sizeof(field) == 2 ? "%04X" : \
49 sizeof(field) == 4 ? "%08X" : "", \
50 field); \
51 else \
52 sprintf(str + strlen(str), "*"); \
53} while(0)
54
Sam Ravnborgfb33d812006-07-09 16:26:07 +020055/**
56 * Check that sizeof(device_id type) are consistent with size of section
57 * in .o file. If in-consistent then userspace and kernel does not agree
58 * on actual size which is a bug.
59 **/
60static void device_id_size_check(const char *modname, const char *device_id,
61 unsigned long size, unsigned long id_size)
62{
63 if (size % id_size || size < id_size) {
64 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
65 "of the size of section __mod_%s_device_table=%lu.\n"
66 "Fix definition of struct %s_device_id "
67 "in mod_devicetable.h\n",
68 modname, device_id, id_size, device_id, size, device_id);
69 }
70}
71
Roman Kaganb19dcd92005-04-22 15:07:01 -070072/* USB is special because the bcdDevice can be matched against a numeric range */
73/* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
74static void do_usb_entry(struct usb_device_id *id,
75 unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
76 unsigned char range_lo, unsigned char range_hi,
77 struct module *mod)
Linus Torvalds1da177e2005-04-16 15:20:36 -070078{
Roman Kaganb19dcd92005-04-22 15:07:01 -070079 char alias[500];
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 strcpy(alias, "usb:");
81 ADD(alias, "v", id->match_flags&USB_DEVICE_ID_MATCH_VENDOR,
82 id->idVendor);
83 ADD(alias, "p", id->match_flags&USB_DEVICE_ID_MATCH_PRODUCT,
84 id->idProduct);
Roman Kaganb19dcd92005-04-22 15:07:01 -070085
86 strcat(alias, "d");
87 if (bcdDevice_initial_digits)
88 sprintf(alias + strlen(alias), "%0*X",
89 bcdDevice_initial_digits, bcdDevice_initial);
90 if (range_lo == range_hi)
91 sprintf(alias + strlen(alias), "%u", range_lo);
92 else if (range_lo > 0 || range_hi < 9)
93 sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi);
94 if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1))
95 strcat(alias, "*");
96
Linus Torvalds1da177e2005-04-16 15:20:36 -070097 ADD(alias, "dc", id->match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS,
98 id->bDeviceClass);
99 ADD(alias, "dsc",
100 id->match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS,
101 id->bDeviceSubClass);
102 ADD(alias, "dp",
103 id->match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL,
104 id->bDeviceProtocol);
105 ADD(alias, "ic",
106 id->match_flags&USB_DEVICE_ID_MATCH_INT_CLASS,
107 id->bInterfaceClass);
108 ADD(alias, "isc",
109 id->match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS,
110 id->bInterfaceSubClass);
111 ADD(alias, "ip",
112 id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL,
113 id->bInterfaceProtocol);
Roman Kaganb19dcd92005-04-22 15:07:01 -0700114
115 /* Always end in a wildcard, for future extension */
116 if (alias[strlen(alias)-1] != '*')
117 strcat(alias, "*");
118 buf_printf(&mod->dev_table_buf,
119 "MODULE_ALIAS(\"%s\");\n", alias);
120}
121
122static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
123{
124 unsigned int devlo, devhi;
125 unsigned char chi, clo;
126 int ndigits;
127
128 id->match_flags = TO_NATIVE(id->match_flags);
129 id->idVendor = TO_NATIVE(id->idVendor);
130 id->idProduct = TO_NATIVE(id->idProduct);
131
132 devlo = id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO ?
133 TO_NATIVE(id->bcdDevice_lo) : 0x0U;
134 devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ?
135 TO_NATIVE(id->bcdDevice_hi) : ~0x0U;
136
137 /*
138 * Some modules (visor) have empty slots as placeholder for
139 * run-time specification that results in catch-all alias
140 */
141 if (!(id->idVendor | id->bDeviceClass | id->bInterfaceClass))
142 return;
143
144 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
145 for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) {
146 clo = devlo & 0xf;
147 chi = devhi & 0xf;
148 if (chi > 9) /* it's bcd not hex */
149 chi = 9;
150 devlo >>= 4;
151 devhi >>= 4;
152
153 if (devlo == devhi || !ndigits) {
154 do_usb_entry(id, devlo, ndigits, clo, chi, mod);
155 break;
156 }
157
158 if (clo > 0)
159 do_usb_entry(id, devlo++, ndigits, clo, 9, mod);
160
161 if (chi < 9)
162 do_usb_entry(id, devhi--, ndigits, 0, chi, mod);
163 }
164}
165
166static void do_usb_table(void *symval, unsigned long size,
167 struct module *mod)
168{
169 unsigned int i;
170 const unsigned long id_size = sizeof(struct usb_device_id);
171
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200172 device_id_size_check(mod->name, "usb", size, id_size);
173
Roman Kaganb19dcd92005-04-22 15:07:01 -0700174 /* Leave last one: it's the terminator. */
175 size -= id_size;
176
177 for (i = 0; i < size; i += id_size)
178 do_usb_entry_multi(symval + i, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700179}
180
181/* Looks like: ieee1394:venNmoNspNverN */
182static int do_ieee1394_entry(const char *filename,
183 struct ieee1394_device_id *id, char *alias)
184{
185 id->match_flags = TO_NATIVE(id->match_flags);
186 id->vendor_id = TO_NATIVE(id->vendor_id);
187 id->model_id = TO_NATIVE(id->model_id);
188 id->specifier_id = TO_NATIVE(id->specifier_id);
189 id->version = TO_NATIVE(id->version);
190
191 strcpy(alias, "ieee1394:");
192 ADD(alias, "ven", id->match_flags & IEEE1394_MATCH_VENDOR_ID,
193 id->vendor_id);
194 ADD(alias, "mo", id->match_flags & IEEE1394_MATCH_MODEL_ID,
195 id->model_id);
196 ADD(alias, "sp", id->match_flags & IEEE1394_MATCH_SPECIFIER_ID,
197 id->specifier_id);
198 ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION,
199 id->version);
200
201 return 1;
202}
203
204/* Looks like: pci:vNdNsvNsdNbcNscNiN. */
205static int do_pci_entry(const char *filename,
206 struct pci_device_id *id, char *alias)
207{
208 /* Class field can be divided into these three. */
209 unsigned char baseclass, subclass, interface,
210 baseclass_mask, subclass_mask, interface_mask;
211
212 id->vendor = TO_NATIVE(id->vendor);
213 id->device = TO_NATIVE(id->device);
214 id->subvendor = TO_NATIVE(id->subvendor);
215 id->subdevice = TO_NATIVE(id->subdevice);
216 id->class = TO_NATIVE(id->class);
217 id->class_mask = TO_NATIVE(id->class_mask);
218
219 strcpy(alias, "pci:");
220 ADD(alias, "v", id->vendor != PCI_ANY_ID, id->vendor);
221 ADD(alias, "d", id->device != PCI_ANY_ID, id->device);
222 ADD(alias, "sv", id->subvendor != PCI_ANY_ID, id->subvendor);
223 ADD(alias, "sd", id->subdevice != PCI_ANY_ID, id->subdevice);
224
225 baseclass = (id->class) >> 16;
226 baseclass_mask = (id->class_mask) >> 16;
227 subclass = (id->class) >> 8;
228 subclass_mask = (id->class_mask) >> 8;
229 interface = id->class;
230 interface_mask = id->class_mask;
231
232 if ((baseclass_mask != 0 && baseclass_mask != 0xFF)
233 || (subclass_mask != 0 && subclass_mask != 0xFF)
234 || (interface_mask != 0 && interface_mask != 0xFF)) {
Sam Ravnborgcb805142006-01-28 16:57:26 +0100235 warn("Can't handle masks in %s:%04X\n",
236 filename, id->class_mask);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237 return 0;
238 }
239
240 ADD(alias, "bc", baseclass_mask == 0xFF, baseclass);
241 ADD(alias, "sc", subclass_mask == 0xFF, subclass);
242 ADD(alias, "i", interface_mask == 0xFF, interface);
243 return 1;
244}
245
Sam Ravnborg62070fa2006-03-03 16:46:04 +0100246/* looks like: "ccw:tNmNdtNdmN" */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247static int do_ccw_entry(const char *filename,
248 struct ccw_device_id *id, char *alias)
249{
250 id->match_flags = TO_NATIVE(id->match_flags);
251 id->cu_type = TO_NATIVE(id->cu_type);
252 id->cu_model = TO_NATIVE(id->cu_model);
253 id->dev_type = TO_NATIVE(id->dev_type);
254 id->dev_model = TO_NATIVE(id->dev_model);
255
256 strcpy(alias, "ccw:");
257 ADD(alias, "t", id->match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE,
258 id->cu_type);
259 ADD(alias, "m", id->match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL,
260 id->cu_model);
261 ADD(alias, "dt", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE,
262 id->dev_type);
Bastian Blankde1d9c02006-03-06 15:43:00 -0800263 ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264 id->dev_model);
265 return 1;
266}
267
268/* Looks like: "serio:tyNprNidNexN" */
269static int do_serio_entry(const char *filename,
270 struct serio_device_id *id, char *alias)
271{
272 id->type = TO_NATIVE(id->type);
273 id->proto = TO_NATIVE(id->proto);
274 id->id = TO_NATIVE(id->id);
275 id->extra = TO_NATIVE(id->extra);
276
277 strcpy(alias, "serio:");
278 ADD(alias, "ty", id->type != SERIO_ANY, id->type);
279 ADD(alias, "pr", id->proto != SERIO_ANY, id->proto);
280 ADD(alias, "id", id->id != SERIO_ANY, id->id);
281 ADD(alias, "ex", id->extra != SERIO_ANY, id->extra);
282
283 return 1;
284}
285
286/* looks like: "pnp:dD" */
287static int do_pnp_entry(const char *filename,
288 struct pnp_device_id *id, char *alias)
289{
290 sprintf(alias, "pnp:d%s", id->id);
291 return 1;
292}
293
294/* looks like: "pnp:cCdD..." */
295static int do_pnp_card_entry(const char *filename,
296 struct pnp_card_device_id *id, char *alias)
297{
298 int i;
299
300 sprintf(alias, "pnp:c%s", id->id);
301 for (i = 0; i < PNP_MAX_DEVICES; i++) {
302 if (! *id->devs[i].id)
303 break;
304 sprintf(alias + strlen(alias), "d%s", id->devs[i].id);
305 }
306 return 1;
307}
308
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700309/* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
310static int do_pcmcia_entry(const char *filename,
311 struct pcmcia_device_id *id, char *alias)
312{
313 unsigned int i;
314
Kars de Jong4fb7edc2005-09-25 14:39:46 +0200315 id->match_flags = TO_NATIVE(id->match_flags);
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700316 id->manf_id = TO_NATIVE(id->manf_id);
317 id->card_id = TO_NATIVE(id->card_id);
318 id->func_id = TO_NATIVE(id->func_id);
319 id->function = TO_NATIVE(id->function);
320 id->device_no = TO_NATIVE(id->device_no);
Kars de Jong4fb7edc2005-09-25 14:39:46 +0200321
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700322 for (i=0; i<4; i++) {
323 id->prod_id_hash[i] = TO_NATIVE(id->prod_id_hash[i]);
324 }
325
326 strcpy(alias, "pcmcia:");
327 ADD(alias, "m", id->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID,
328 id->manf_id);
329 ADD(alias, "c", id->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID,
330 id->card_id);
331 ADD(alias, "f", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID,
332 id->func_id);
333 ADD(alias, "fn", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION,
334 id->function);
335 ADD(alias, "pfn", id->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO,
336 id->device_no);
337 ADD(alias, "pa", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, id->prod_id_hash[0]);
338 ADD(alias, "pb", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, id->prod_id_hash[1]);
339 ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]);
340 ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]);
341
342 return 1;
343}
344
345
346
Jeff Mahoney5e655772005-07-06 15:44:41 -0400347static int do_of_entry (const char *filename, struct of_device_id *of, char *alias)
348{
349 char *tmp;
350 sprintf (alias, "of:N%sT%sC%s",
351 of->name[0] ? of->name : "*",
352 of->type[0] ? of->type : "*",
353 of->compatible[0] ? of->compatible : "*");
354
355 /* Replace all whitespace with underscores */
356 for (tmp = alias; tmp && *tmp; tmp++)
357 if (isspace (*tmp))
358 *tmp = '_';
359
360 return 1;
361}
362
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000363static int do_vio_entry(const char *filename, struct vio_device_id *vio,
364 char *alias)
365{
366 char *tmp;
367
368 sprintf(alias, "vio:T%sS%s", vio->type[0] ? vio->type : "*",
369 vio->compat[0] ? vio->compat : "*");
370
371 /* Replace all whitespace with underscores */
372 for (tmp = alias; tmp && *tmp; tmp++)
373 if (isspace (*tmp))
374 *tmp = '_';
375
376 return 1;
377}
378
Greg Kroah-Hartmana9d1b242005-10-22 00:23:27 +0200379static int do_i2c_entry(const char *filename, struct i2c_device_id *i2c, char *alias)
380{
381 strcpy(alias, "i2c:");
382 ADD(alias, "id", 1, i2c->id);
383 return 1;
384}
385
Rusty Russell1d8f4302005-12-07 21:40:34 +0100386#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
387
388static void do_input(char *alias,
389 kernel_ulong_t *arr, unsigned int min, unsigned int max)
390{
391 unsigned int i;
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400392
393 for (i = min; i < max; i++)
394 if (arr[i / BITS_PER_LONG] & (1 << (i%BITS_PER_LONG)))
395 sprintf(alias + strlen(alias), "%X,*", i);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100396}
397
398/* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
399static int do_input_entry(const char *filename, struct input_device_id *id,
400 char *alias)
401{
402 sprintf(alias, "input:");
403
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400404 ADD(alias, "b", id->flags & INPUT_DEVICE_ID_MATCH_BUS, id->bustype);
405 ADD(alias, "v", id->flags & INPUT_DEVICE_ID_MATCH_VENDOR, id->vendor);
406 ADD(alias, "p", id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT, id->product);
407 ADD(alias, "e", id->flags & INPUT_DEVICE_ID_MATCH_VERSION, id->version);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100408
409 sprintf(alias + strlen(alias), "-e*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400410 if (id->flags & INPUT_DEVICE_ID_MATCH_EVBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100411 do_input(alias, id->evbit, 0, EV_MAX);
412 sprintf(alias + strlen(alias), "k*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400413 if (id->flags & INPUT_DEVICE_ID_MATCH_KEYBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100414 do_input(alias, id->keybit, KEY_MIN_INTERESTING, KEY_MAX);
415 sprintf(alias + strlen(alias), "r*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400416 if (id->flags & INPUT_DEVICE_ID_MATCH_RELBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100417 do_input(alias, id->relbit, 0, REL_MAX);
418 sprintf(alias + strlen(alias), "a*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400419 if (id->flags & INPUT_DEVICE_ID_MATCH_ABSBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100420 do_input(alias, id->absbit, 0, ABS_MAX);
421 sprintf(alias + strlen(alias), "m*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400422 if (id->flags & INPUT_DEVICE_ID_MATCH_MSCIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100423 do_input(alias, id->mscbit, 0, MSC_MAX);
424 sprintf(alias + strlen(alias), "l*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400425 if (id->flags & INPUT_DEVICE_ID_MATCH_LEDBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100426 do_input(alias, id->ledbit, 0, LED_MAX);
427 sprintf(alias + strlen(alias), "s*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400428 if (id->flags & INPUT_DEVICE_ID_MATCH_SNDBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100429 do_input(alias, id->sndbit, 0, SND_MAX);
430 sprintf(alias + strlen(alias), "f*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400431 if (id->flags & INPUT_DEVICE_ID_MATCH_FFBIT)
Brian Gerstcc6fa432006-01-08 10:53:55 -0500432 do_input(alias, id->ffbit, 0, FF_MAX);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100433 sprintf(alias + strlen(alias), "w*");
Dmitry Torokhovddc5d342006-04-26 00:14:19 -0400434 if (id->flags & INPUT_DEVICE_ID_MATCH_SWBIT)
Rusty Russell1d8f4302005-12-07 21:40:34 +0100435 do_input(alias, id->swbit, 0, SW_MAX);
436 return 1;
437}
438
Linus Torvalds1da177e2005-04-16 15:20:36 -0700439/* Ignore any prefix, eg. v850 prepends _ */
440static inline int sym_is(const char *symbol, const char *name)
441{
442 const char *match;
443
444 match = strstr(symbol, name);
445 if (!match)
446 return 0;
447 return match[strlen(symbol)] == '\0';
448}
449
450static void do_table(void *symval, unsigned long size,
451 unsigned long id_size,
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200452 const char *device_id,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700453 void *function,
454 struct module *mod)
455{
456 unsigned int i;
457 char alias[500];
458 int (*do_entry)(const char *, void *entry, char *alias) = function;
459
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200460 device_id_size_check(mod->name, device_id, size, id_size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 /* Leave last one: it's the terminator. */
462 size -= id_size;
463
464 for (i = 0; i < size; i += id_size) {
465 if (do_entry(mod->name, symval+i, alias)) {
466 /* Always end in a wildcard, for future extension */
467 if (alias[strlen(alias)-1] != '*')
468 strcat(alias, "*");
469 buf_printf(&mod->dev_table_buf,
470 "MODULE_ALIAS(\"%s\");\n", alias);
471 }
472 }
473}
474
475/* Create MODULE_ALIAS() statements.
476 * At this time, we cannot write the actual output C source yet,
477 * so we write into the mod->dev_table_buf buffer. */
478void handle_moddevtable(struct module *mod, struct elf_info *info,
479 Elf_Sym *sym, const char *symname)
480{
481 void *symval;
482
483 /* We're looking for a section relative symbol */
484 if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum)
485 return;
486
487 symval = (void *)info->hdr
488 + info->sechdrs[sym->st_shndx].sh_offset
489 + sym->st_value;
490
491 if (sym_is(symname, "__mod_pci_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200492 do_table(symval, sym->st_size,
493 sizeof(struct pci_device_id), "pci",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494 do_pci_entry, mod);
495 else if (sym_is(symname, "__mod_usb_device_table"))
Roman Kaganb19dcd92005-04-22 15:07:01 -0700496 /* special case to handle bcdDevice ranges */
497 do_usb_table(symval, sym->st_size, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498 else if (sym_is(symname, "__mod_ieee1394_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200499 do_table(symval, sym->st_size,
500 sizeof(struct ieee1394_device_id), "ieee1394",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700501 do_ieee1394_entry, mod);
502 else if (sym_is(symname, "__mod_ccw_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200503 do_table(symval, sym->st_size,
504 sizeof(struct ccw_device_id), "ccw",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700505 do_ccw_entry, mod);
506 else if (sym_is(symname, "__mod_serio_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200507 do_table(symval, sym->st_size,
508 sizeof(struct serio_device_id), "serio",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 do_serio_entry, mod);
510 else if (sym_is(symname, "__mod_pnp_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200511 do_table(symval, sym->st_size,
512 sizeof(struct pnp_device_id), "pnp",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700513 do_pnp_entry, mod);
514 else if (sym_is(symname, "__mod_pnp_card_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200515 do_table(symval, sym->st_size,
516 sizeof(struct pnp_card_device_id), "pnp_card",
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 do_pnp_card_entry, mod);
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700518 else if (sym_is(symname, "__mod_pcmcia_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200519 do_table(symval, sym->st_size,
520 sizeof(struct pcmcia_device_id), "pcmcia",
Dominik Brodowski90829cf2005-06-27 16:28:12 -0700521 do_pcmcia_entry, mod);
Jeff Mahoney5e655772005-07-06 15:44:41 -0400522 else if (sym_is(symname, "__mod_of_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200523 do_table(symval, sym->st_size,
524 sizeof(struct of_device_id), "of",
Jeff Mahoney5e655772005-07-06 15:44:41 -0400525 do_of_entry, mod);
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000526 else if (sym_is(symname, "__mod_vio_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200527 do_table(symval, sym->st_size,
528 sizeof(struct vio_device_id), "vio",
Stephen Rothwellfb120da2005-08-17 16:42:59 +1000529 do_vio_entry, mod);
Greg Kroah-Hartmana9d1b242005-10-22 00:23:27 +0200530 else if (sym_is(symname, "__mod_i2c_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200531 do_table(symval, sym->st_size,
532 sizeof(struct i2c_device_id), "i2c",
Greg Kroah-Hartmana9d1b242005-10-22 00:23:27 +0200533 do_i2c_entry, mod);
Rusty Russell1d8f4302005-12-07 21:40:34 +0100534 else if (sym_is(symname, "__mod_input_device_table"))
Sam Ravnborgfb33d812006-07-09 16:26:07 +0200535 do_table(symval, sym->st_size,
536 sizeof(struct input_device_id), "input",
Rusty Russell1d8f4302005-12-07 21:40:34 +0100537 do_input_entry, mod);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538}
539
540/* Now add out buffered information to the generated C source */
541void add_moddevtable(struct buffer *buf, struct module *mod)
542{
543 buf_printf(buf, "\n");
544 buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos);
545 free(mod->dev_table_buf.p);
546}