1 /* 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.
5 * Copyright 2002-2003 Rusty Russell, IBM Corporation
6 * 2003 Kai Germaschewski
9 * This software may be used and distributed according to the terms
10 * of the GNU General Public License, incorporated herein by reference.
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
18 typedef Elf32_Addr kernel_ulong_t
;
19 #define BITS_PER_LONG 32
21 typedef Elf64_Addr kernel_ulong_t
;
22 #define BITS_PER_LONG 64
32 typedef uint32_t __u32
;
33 typedef uint16_t __u16
;
34 typedef unsigned char __u8
;
36 /* Big exception to the "don't include kernel headers into userspace, which
37 * even potentially has different endianness and word sizes, since
38 * we handle those differences explicitly below */
39 #include "../../include/linux/mod_devicetable.h"
41 #define ADD(str, sep, cond, field) \
45 sprintf(str + strlen(str), \
46 sizeof(field) == 1 ? "%02X" : \
47 sizeof(field) == 2 ? "%04X" : \
48 sizeof(field) == 4 ? "%08X" : "", \
51 sprintf(str + strlen(str), "*"); \
54 /* Always end in a wildcard, for future extension */
55 static inline void add_wildcard(char *str
)
57 int len
= strlen(str
);
59 if (str
[len
- 1] != '*')
60 strcat(str
+ len
, "*");
63 unsigned int cross_build
= 0;
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.
68 * Also verify that the final entry in the table is all zeros.
69 * Ignore both checks if build host differ from target host and size differs.
71 static void device_id_check(const char *modname
, const char *device_id
,
72 unsigned long size
, unsigned long id_size
,
77 if (size
% id_size
|| size
< id_size
) {
80 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
);
86 /* 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
) );
96 fatal("%s: struct %s_device_id is not terminated "
97 "with a NULL entry!\n", modname
, device_id
);
102 /* USB is special because the bcdDevice can be matched against a numeric range */
103 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
104 static 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 unsigned char max
, struct module
*mod
)
110 strcpy(alias
, "usb:");
111 ADD(alias
, "v", id
->match_flags
&USB_DEVICE_ID_MATCH_VENDOR
,
113 ADD(alias
, "p", id
->match_flags
&USB_DEVICE_ID_MATCH_PRODUCT
,
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
), "%X", range_lo
);
122 else if (range_lo
> 0 || range_hi
< max
) {
123 if (range_lo
> 0x9 || range_hi
< 0xA)
124 sprintf(alias
+ strlen(alias
),
129 sprintf(alias
+ strlen(alias
),
130 range_lo
< 0x9 ? "[%X-9" : "[%X",
132 sprintf(alias
+ strlen(alias
),
133 range_hi
> 0xA ? "a-%X]" : "%X]",
137 if (bcdDevice_initial_digits
< (sizeof(id
->bcdDevice_lo
) * 2 - 1))
140 ADD(alias
, "dc", id
->match_flags
&USB_DEVICE_ID_MATCH_DEV_CLASS
,
143 id
->match_flags
&USB_DEVICE_ID_MATCH_DEV_SUBCLASS
,
144 id
->bDeviceSubClass
);
146 id
->match_flags
&USB_DEVICE_ID_MATCH_DEV_PROTOCOL
,
147 id
->bDeviceProtocol
);
149 id
->match_flags
&USB_DEVICE_ID_MATCH_INT_CLASS
,
150 id
->bInterfaceClass
);
152 id
->match_flags
&USB_DEVICE_ID_MATCH_INT_SUBCLASS
,
153 id
->bInterfaceSubClass
);
155 id
->match_flags
&USB_DEVICE_ID_MATCH_INT_PROTOCOL
,
156 id
->bInterfaceProtocol
);
159 buf_printf(&mod
->dev_table_buf
,
160 "MODULE_ALIAS(\"%s\");\n", alias
);
163 /* Handles increment/decrement of BCD formatted integers */
164 /* Returns the previous value, so it works like i++ or i-- */
165 static unsigned int incbcd(unsigned int *bcd
,
170 unsigned int init
= *bcd
, i
, j
;
171 unsigned long long c
, dec
= 0;
173 /* If bcd is not in BCD format, just increment */
179 /* Convert BCD to Decimal */
180 for (i
=0 ; i
< chars
; i
++) {
181 c
= (*bcd
>> (i
<< 2)) & 0xf;
182 c
= c
> 9 ? 9 : c
; /* force to bcd just in case */
183 for (j
=0 ; j
< i
; j
++)
188 /* Do our increment/decrement */
192 /* Convert back to BCD */
193 for (i
=0 ; i
< chars
; i
++) {
194 for (c
=1,j
=0 ; j
< i
; j
++)
197 *bcd
+= c
<< (i
<< 2);
202 static void do_usb_entry_multi(struct usb_device_id
*id
, struct module
*mod
)
204 unsigned int devlo
, devhi
;
205 unsigned char chi
, clo
, max
;
208 id
->match_flags
= TO_NATIVE(id
->match_flags
);
209 id
->idVendor
= TO_NATIVE(id
->idVendor
);
210 id
->idProduct
= TO_NATIVE(id
->idProduct
);
212 devlo
= id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
?
213 TO_NATIVE(id
->bcdDevice_lo
) : 0x0U
;
214 devhi
= id
->match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
?
215 TO_NATIVE(id
->bcdDevice_hi
) : ~0x0U
;
217 /* Figure out if this entry is in bcd or hex format */
218 max
= 0x9; /* Default to decimal format */
219 for (ndigits
= 0 ; ndigits
< sizeof(id
->bcdDevice_lo
) * 2 ; ndigits
++) {
220 clo
= (devlo
>> (ndigits
<< 2)) & 0xf;
221 chi
= ((devhi
> 0x9999 ? 0x9999 : devhi
) >> (ndigits
<< 2)) & 0xf;
222 if (clo
> max
|| chi
> max
) {
229 * Some modules (visor) have empty slots as placeholder for
230 * run-time specification that results in catch-all alias
232 if (!(id
->idVendor
| id
->idProduct
| id
->bDeviceClass
| id
->bInterfaceClass
))
235 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
236 for (ndigits
= sizeof(id
->bcdDevice_lo
) * 2 - 1; devlo
<= devhi
; ndigits
--) {
239 if (chi
> max
) /* If we are in bcd mode, truncate if necessary */
244 if (devlo
== devhi
|| !ndigits
) {
245 do_usb_entry(id
, devlo
, ndigits
, clo
, chi
, max
, mod
);
251 incbcd(&devlo
, 1, max
,
252 sizeof(id
->bcdDevice_lo
) * 2),
253 ndigits
, clo
, max
, max
, mod
);
257 incbcd(&devhi
, -1, max
,
258 sizeof(id
->bcdDevice_lo
) * 2),
259 ndigits
, 0x0, chi
, max
, mod
);
263 static void do_usb_table(void *symval
, unsigned long size
,
267 const unsigned long id_size
= sizeof(struct usb_device_id
);
269 device_id_check(mod
->name
, "usb", size
, id_size
, symval
);
271 /* Leave last one: it's the terminator. */
274 for (i
= 0; i
< size
; i
+= id_size
)
275 do_usb_entry_multi(symval
+ i
, mod
);
278 /* Looks like: hid:bNvNpN */
279 static int do_hid_entry(const char *filename
,
280 struct hid_device_id
*id
, char *alias
)
282 id
->bus
= TO_NATIVE(id
->bus
);
283 id
->vendor
= TO_NATIVE(id
->vendor
);
284 id
->product
= TO_NATIVE(id
->product
);
286 sprintf(alias
, "hid:b%04X", id
->bus
);
287 ADD(alias
, "v", id
->vendor
!= HID_ANY_ID
, id
->vendor
);
288 ADD(alias
, "p", id
->product
!= HID_ANY_ID
, id
->product
);
293 /* Looks like: ieee1394:venNmoNspNverN */
294 static int do_ieee1394_entry(const char *filename
,
295 struct ieee1394_device_id
*id
, char *alias
)
297 id
->match_flags
= TO_NATIVE(id
->match_flags
);
298 id
->vendor_id
= TO_NATIVE(id
->vendor_id
);
299 id
->model_id
= TO_NATIVE(id
->model_id
);
300 id
->specifier_id
= TO_NATIVE(id
->specifier_id
);
301 id
->version
= TO_NATIVE(id
->version
);
303 strcpy(alias
, "ieee1394:");
304 ADD(alias
, "ven", id
->match_flags
& IEEE1394_MATCH_VENDOR_ID
,
306 ADD(alias
, "mo", id
->match_flags
& IEEE1394_MATCH_MODEL_ID
,
308 ADD(alias
, "sp", id
->match_flags
& IEEE1394_MATCH_SPECIFIER_ID
,
310 ADD(alias
, "ver", id
->match_flags
& IEEE1394_MATCH_VERSION
,
317 /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
318 static int do_pci_entry(const char *filename
,
319 struct pci_device_id
*id
, char *alias
)
321 /* Class field can be divided into these three. */
322 unsigned char baseclass
, subclass
, interface
,
323 baseclass_mask
, subclass_mask
, interface_mask
;
325 id
->vendor
= TO_NATIVE(id
->vendor
);
326 id
->device
= TO_NATIVE(id
->device
);
327 id
->subvendor
= TO_NATIVE(id
->subvendor
);
328 id
->subdevice
= TO_NATIVE(id
->subdevice
);
329 id
->class = TO_NATIVE(id
->class);
330 id
->class_mask
= TO_NATIVE(id
->class_mask
);
332 strcpy(alias
, "pci:");
333 ADD(alias
, "v", id
->vendor
!= PCI_ANY_ID
, id
->vendor
);
334 ADD(alias
, "d", id
->device
!= PCI_ANY_ID
, id
->device
);
335 ADD(alias
, "sv", id
->subvendor
!= PCI_ANY_ID
, id
->subvendor
);
336 ADD(alias
, "sd", id
->subdevice
!= PCI_ANY_ID
, id
->subdevice
);
338 baseclass
= (id
->class) >> 16;
339 baseclass_mask
= (id
->class_mask
) >> 16;
340 subclass
= (id
->class) >> 8;
341 subclass_mask
= (id
->class_mask
) >> 8;
342 interface
= id
->class;
343 interface_mask
= id
->class_mask
;
345 if ((baseclass_mask
!= 0 && baseclass_mask
!= 0xFF)
346 || (subclass_mask
!= 0 && subclass_mask
!= 0xFF)
347 || (interface_mask
!= 0 && interface_mask
!= 0xFF)) {
348 warn("Can't handle masks in %s:%04X\n",
349 filename
, id
->class_mask
);
353 ADD(alias
, "bc", baseclass_mask
== 0xFF, baseclass
);
354 ADD(alias
, "sc", subclass_mask
== 0xFF, subclass
);
355 ADD(alias
, "i", interface_mask
== 0xFF, interface
);
360 /* looks like: "ccw:tNmNdtNdmN" */
361 static int do_ccw_entry(const char *filename
,
362 struct ccw_device_id
*id
, char *alias
)
364 id
->match_flags
= TO_NATIVE(id
->match_flags
);
365 id
->cu_type
= TO_NATIVE(id
->cu_type
);
366 id
->cu_model
= TO_NATIVE(id
->cu_model
);
367 id
->dev_type
= TO_NATIVE(id
->dev_type
);
368 id
->dev_model
= TO_NATIVE(id
->dev_model
);
370 strcpy(alias
, "ccw:");
371 ADD(alias
, "t", id
->match_flags
&CCW_DEVICE_ID_MATCH_CU_TYPE
,
373 ADD(alias
, "m", id
->match_flags
&CCW_DEVICE_ID_MATCH_CU_MODEL
,
375 ADD(alias
, "dt", id
->match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_TYPE
,
377 ADD(alias
, "dm", id
->match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_MODEL
,
383 /* looks like: "ap:tN" */
384 static int do_ap_entry(const char *filename
,
385 struct ap_device_id
*id
, char *alias
)
387 sprintf(alias
, "ap:t%02X*", id
->dev_type
);
391 /* looks like: "css:tN" */
392 static int do_css_entry(const char *filename
,
393 struct css_device_id
*id
, char *alias
)
395 sprintf(alias
, "css:t%01X", id
->type
);
399 /* Looks like: "serio:tyNprNidNexN" */
400 static int do_serio_entry(const char *filename
,
401 struct serio_device_id
*id
, char *alias
)
403 id
->type
= TO_NATIVE(id
->type
);
404 id
->proto
= TO_NATIVE(id
->proto
);
405 id
->id
= TO_NATIVE(id
->id
);
406 id
->extra
= TO_NATIVE(id
->extra
);
408 strcpy(alias
, "serio:");
409 ADD(alias
, "ty", id
->type
!= SERIO_ANY
, id
->type
);
410 ADD(alias
, "pr", id
->proto
!= SERIO_ANY
, id
->proto
);
411 ADD(alias
, "id", id
->id
!= SERIO_ANY
, id
->id
);
412 ADD(alias
, "ex", id
->extra
!= SERIO_ANY
, id
->extra
);
418 /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */
419 static int do_acpi_entry(const char *filename
,
420 struct acpi_device_id
*id
, char *alias
)
422 sprintf(alias
, "acpi*:%s:*", id
->id
);
426 /* looks like: "pnp:dD" */
427 static void do_pnp_device_entry(void *symval
, unsigned long size
,
430 const unsigned long id_size
= sizeof(struct pnp_device_id
);
431 const unsigned int count
= (size
/ id_size
)-1;
432 const struct pnp_device_id
*devs
= symval
;
435 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
437 for (i
= 0; i
< count
; i
++) {
438 const char *id
= (char *)devs
[i
].id
;
439 char acpi_id
[sizeof(devs
[0].id
)];
442 buf_printf(&mod
->dev_table_buf
,
443 "MODULE_ALIAS(\"pnp:d%s*\");\n", id
);
445 /* fix broken pnp bus lowercasing */
446 for (j
= 0; j
< sizeof(acpi_id
); j
++)
447 acpi_id
[j
] = toupper(id
[j
]);
448 buf_printf(&mod
->dev_table_buf
,
449 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
453 /* looks like: "pnp:dD" for every device of the card */
454 static void do_pnp_card_entries(void *symval
, unsigned long size
,
457 const unsigned long id_size
= sizeof(struct pnp_card_device_id
);
458 const unsigned int count
= (size
/ id_size
)-1;
459 const struct pnp_card_device_id
*cards
= symval
;
462 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
464 for (i
= 0; i
< count
; i
++) {
466 const struct pnp_card_device_id
*card
= &cards
[i
];
468 for (j
= 0; j
< PNP_MAX_DEVICES
; j
++) {
469 const char *id
= (char *)card
->devs
[j
].id
;
476 /* find duplicate, already added value */
477 for (i2
= 0; i2
< i
&& !dup
; i2
++) {
478 const struct pnp_card_device_id
*card2
= &cards
[i2
];
480 for (j2
= 0; j2
< PNP_MAX_DEVICES
; j2
++) {
481 const char *id2
= (char *)card2
->devs
[j2
].id
;
486 if (!strcmp(id
, id2
)) {
493 /* add an individual alias for every device entry */
495 char acpi_id
[sizeof(card
->devs
[0].id
)];
498 buf_printf(&mod
->dev_table_buf
,
499 "MODULE_ALIAS(\"pnp:d%s*\");\n", id
);
501 /* fix broken pnp bus lowercasing */
502 for (k
= 0; k
< sizeof(acpi_id
); k
++)
503 acpi_id
[k
] = toupper(id
[k
]);
504 buf_printf(&mod
->dev_table_buf
,
505 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
511 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
512 static int do_pcmcia_entry(const char *filename
,
513 struct pcmcia_device_id
*id
, char *alias
)
517 id
->match_flags
= TO_NATIVE(id
->match_flags
);
518 id
->manf_id
= TO_NATIVE(id
->manf_id
);
519 id
->card_id
= TO_NATIVE(id
->card_id
);
520 id
->func_id
= TO_NATIVE(id
->func_id
);
521 id
->function
= TO_NATIVE(id
->function
);
522 id
->device_no
= TO_NATIVE(id
->device_no
);
524 for (i
=0; i
<4; i
++) {
525 id
->prod_id_hash
[i
] = TO_NATIVE(id
->prod_id_hash
[i
]);
528 strcpy(alias
, "pcmcia:");
529 ADD(alias
, "m", id
->match_flags
& PCMCIA_DEV_ID_MATCH_MANF_ID
,
531 ADD(alias
, "c", id
->match_flags
& PCMCIA_DEV_ID_MATCH_CARD_ID
,
533 ADD(alias
, "f", id
->match_flags
& PCMCIA_DEV_ID_MATCH_FUNC_ID
,
535 ADD(alias
, "fn", id
->match_flags
& PCMCIA_DEV_ID_MATCH_FUNCTION
,
537 ADD(alias
, "pfn", id
->match_flags
& PCMCIA_DEV_ID_MATCH_DEVICE_NO
,
539 ADD(alias
, "pa", id
->match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID1
, id
->prod_id_hash
[0]);
540 ADD(alias
, "pb", id
->match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID2
, id
->prod_id_hash
[1]);
541 ADD(alias
, "pc", id
->match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID3
, id
->prod_id_hash
[2]);
542 ADD(alias
, "pd", id
->match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID4
, id
->prod_id_hash
[3]);
550 static int do_of_entry (const char *filename
, struct of_device_id
*of
, char *alias
)
554 len
= sprintf (alias
, "of:N%sT%s",
555 of
->name
[0] ? of
->name
: "*",
556 of
->type
[0] ? of
->type
: "*");
558 if (of
->compatible
[0])
559 sprintf (&alias
[len
], "%sC%s",
560 of
->type
[0] ? "*" : "",
563 /* Replace all whitespace with underscores */
564 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
572 static int do_vio_entry(const char *filename
, struct vio_device_id
*vio
,
577 sprintf(alias
, "vio:T%sS%s", vio
->type
[0] ? vio
->type
: "*",
578 vio
->compat
[0] ? vio
->compat
: "*");
580 /* Replace all whitespace with underscores */
581 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
589 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
591 static void do_input(char *alias
,
592 kernel_ulong_t
*arr
, unsigned int min
, unsigned int max
)
596 for (i
= min
; i
< max
; i
++)
597 if (arr
[i
/ BITS_PER_LONG
] & (1L << (i
%BITS_PER_LONG
)))
598 sprintf(alias
+ strlen(alias
), "%X,*", i
);
601 /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
602 static int do_input_entry(const char *filename
, struct input_device_id
*id
,
605 sprintf(alias
, "input:");
607 ADD(alias
, "b", id
->flags
& INPUT_DEVICE_ID_MATCH_BUS
, id
->bustype
);
608 ADD(alias
, "v", id
->flags
& INPUT_DEVICE_ID_MATCH_VENDOR
, id
->vendor
);
609 ADD(alias
, "p", id
->flags
& INPUT_DEVICE_ID_MATCH_PRODUCT
, id
->product
);
610 ADD(alias
, "e", id
->flags
& INPUT_DEVICE_ID_MATCH_VERSION
, id
->version
);
612 sprintf(alias
+ strlen(alias
), "-e*");
613 if (id
->flags
& INPUT_DEVICE_ID_MATCH_EVBIT
)
614 do_input(alias
, id
->evbit
, 0, INPUT_DEVICE_ID_EV_MAX
);
615 sprintf(alias
+ strlen(alias
), "k*");
616 if (id
->flags
& INPUT_DEVICE_ID_MATCH_KEYBIT
)
617 do_input(alias
, id
->keybit
,
618 INPUT_DEVICE_ID_KEY_MIN_INTERESTING
,
619 INPUT_DEVICE_ID_KEY_MAX
);
620 sprintf(alias
+ strlen(alias
), "r*");
621 if (id
->flags
& INPUT_DEVICE_ID_MATCH_RELBIT
)
622 do_input(alias
, id
->relbit
, 0, INPUT_DEVICE_ID_REL_MAX
);
623 sprintf(alias
+ strlen(alias
), "a*");
624 if (id
->flags
& INPUT_DEVICE_ID_MATCH_ABSBIT
)
625 do_input(alias
, id
->absbit
, 0, INPUT_DEVICE_ID_ABS_MAX
);
626 sprintf(alias
+ strlen(alias
), "m*");
627 if (id
->flags
& INPUT_DEVICE_ID_MATCH_MSCIT
)
628 do_input(alias
, id
->mscbit
, 0, INPUT_DEVICE_ID_MSC_MAX
);
629 sprintf(alias
+ strlen(alias
), "l*");
630 if (id
->flags
& INPUT_DEVICE_ID_MATCH_LEDBIT
)
631 do_input(alias
, id
->ledbit
, 0, INPUT_DEVICE_ID_LED_MAX
);
632 sprintf(alias
+ strlen(alias
), "s*");
633 if (id
->flags
& INPUT_DEVICE_ID_MATCH_SNDBIT
)
634 do_input(alias
, id
->sndbit
, 0, INPUT_DEVICE_ID_SND_MAX
);
635 sprintf(alias
+ strlen(alias
), "f*");
636 if (id
->flags
& INPUT_DEVICE_ID_MATCH_FFBIT
)
637 do_input(alias
, id
->ffbit
, 0, INPUT_DEVICE_ID_FF_MAX
);
638 sprintf(alias
+ strlen(alias
), "w*");
639 if (id
->flags
& INPUT_DEVICE_ID_MATCH_SWBIT
)
640 do_input(alias
, id
->swbit
, 0, INPUT_DEVICE_ID_SW_MAX
);
644 static int do_eisa_entry(const char *filename
, struct eisa_device_id
*eisa
,
648 sprintf(alias
, EISA_DEVICE_MODALIAS_FMT
"*", eisa
->sig
);
654 /* Looks like: parisc:tNhvNrevNsvN */
655 static int do_parisc_entry(const char *filename
, struct parisc_device_id
*id
,
658 id
->hw_type
= TO_NATIVE(id
->hw_type
);
659 id
->hversion
= TO_NATIVE(id
->hversion
);
660 id
->hversion_rev
= TO_NATIVE(id
->hversion_rev
);
661 id
->sversion
= TO_NATIVE(id
->sversion
);
663 strcpy(alias
, "parisc:");
664 ADD(alias
, "t", id
->hw_type
!= PA_HWTYPE_ANY_ID
, id
->hw_type
);
665 ADD(alias
, "hv", id
->hversion
!= PA_HVERSION_ANY_ID
, id
->hversion
);
666 ADD(alias
, "rev", id
->hversion_rev
!= PA_HVERSION_REV_ANY_ID
, id
->hversion_rev
);
667 ADD(alias
, "sv", id
->sversion
!= PA_SVERSION_ANY_ID
, id
->sversion
);
673 /* Looks like: sdio:cNvNdN. */
674 static int do_sdio_entry(const char *filename
,
675 struct sdio_device_id
*id
, char *alias
)
677 id
->class = TO_NATIVE(id
->class);
678 id
->vendor
= TO_NATIVE(id
->vendor
);
679 id
->device
= TO_NATIVE(id
->device
);
681 strcpy(alias
, "sdio:");
682 ADD(alias
, "c", id
->class != (__u8
)SDIO_ANY_ID
, id
->class);
683 ADD(alias
, "v", id
->vendor
!= (__u16
)SDIO_ANY_ID
, id
->vendor
);
684 ADD(alias
, "d", id
->device
!= (__u16
)SDIO_ANY_ID
, id
->device
);
689 /* Looks like: ssb:vNidNrevN. */
690 static int do_ssb_entry(const char *filename
,
691 struct ssb_device_id
*id
, char *alias
)
693 id
->vendor
= TO_NATIVE(id
->vendor
);
694 id
->coreid
= TO_NATIVE(id
->coreid
);
695 id
->revision
= TO_NATIVE(id
->revision
);
697 strcpy(alias
, "ssb:");
698 ADD(alias
, "v", id
->vendor
!= SSB_ANY_VENDOR
, id
->vendor
);
699 ADD(alias
, "id", id
->coreid
!= SSB_ANY_ID
, id
->coreid
);
700 ADD(alias
, "rev", id
->revision
!= SSB_ANY_REV
, id
->revision
);
705 /* Looks like: virtio:dNvN */
706 static int do_virtio_entry(const char *filename
, struct virtio_device_id
*id
,
709 id
->device
= TO_NATIVE(id
->device
);
710 id
->vendor
= TO_NATIVE(id
->vendor
);
712 strcpy(alias
, "virtio:");
713 ADD(alias
, "d", id
->device
!= VIRTIO_DEV_ANY_ID
, id
->device
);
714 ADD(alias
, "v", id
->vendor
!= VIRTIO_DEV_ANY_ID
, id
->vendor
);
720 /* Looks like: i2c:S */
721 static int do_i2c_entry(const char *filename
, struct i2c_device_id
*id
,
724 sprintf(alias
, I2C_MODULE_PREFIX
"%s", id
->name
);
729 /* Looks like: spi:S */
730 static int do_spi_entry(const char *filename
, struct spi_device_id
*id
,
733 sprintf(alias
, SPI_MODULE_PREFIX
"%s", id
->name
);
738 static const struct dmifield
{
742 { "bvn", DMI_BIOS_VENDOR
},
743 { "bvr", DMI_BIOS_VERSION
},
744 { "bd", DMI_BIOS_DATE
},
745 { "svn", DMI_SYS_VENDOR
},
746 { "pn", DMI_PRODUCT_NAME
},
747 { "pvr", DMI_PRODUCT_VERSION
},
748 { "rvn", DMI_BOARD_VENDOR
},
749 { "rn", DMI_BOARD_NAME
},
750 { "rvr", DMI_BOARD_VERSION
},
751 { "cvn", DMI_CHASSIS_VENDOR
},
752 { "ct", DMI_CHASSIS_TYPE
},
753 { "cvr", DMI_CHASSIS_VERSION
},
757 static void dmi_ascii_filter(char *d
, const char *s
)
759 /* Filter out characters we don't want to see in the modalias string */
761 if (*s
> ' ' && *s
< 127 && *s
!= ':')
768 static int do_dmi_entry(const char *filename
, struct dmi_system_id
*id
,
773 sprintf(alias
, "dmi*");
775 for (i
= 0; i
< ARRAY_SIZE(dmi_fields
); i
++) {
776 for (j
= 0; j
< 4; j
++) {
777 if (id
->matches
[j
].slot
&&
778 id
->matches
[j
].slot
== dmi_fields
[i
].field
) {
779 sprintf(alias
+ strlen(alias
), ":%s*",
780 dmi_fields
[i
].prefix
);
781 dmi_ascii_filter(alias
+ strlen(alias
),
782 id
->matches
[j
].substr
);
792 static int do_platform_entry(const char *filename
,
793 struct platform_device_id
*id
, char *alias
)
795 sprintf(alias
, PLATFORM_MODULE_PREFIX
"%s", id
->name
);
799 /* Looks like: zorro:iN. */
800 static int do_zorro_entry(const char *filename
, struct zorro_device_id
*id
,
803 id
->id
= TO_NATIVE(id
->id
);
804 strcpy(alias
, "zorro:");
805 ADD(alias
, "i", id
->id
!= ZORRO_WILDCARD
, id
->id
);
809 /* Ignore any prefix, eg. some architectures prepend _ */
810 static inline int sym_is(const char *symbol
, const char *name
)
814 match
= strstr(symbol
, name
);
817 return match
[strlen(name
)] == '\0';
820 static void do_table(void *symval
, unsigned long size
,
821 unsigned long id_size
,
822 const char *device_id
,
828 int (*do_entry
)(const char *, void *entry
, char *alias
) = function
;
830 device_id_check(mod
->name
, device_id
, size
, id_size
, symval
);
831 /* Leave last one: it's the terminator. */
834 for (i
= 0; i
< size
; i
+= id_size
) {
835 if (do_entry(mod
->name
, symval
+i
, alias
)) {
836 buf_printf(&mod
->dev_table_buf
,
837 "MODULE_ALIAS(\"%s\");\n", alias
);
842 /* Create MODULE_ALIAS() statements.
843 * At this time, we cannot write the actual output C source yet,
844 * so we write into the mod->dev_table_buf buffer. */
845 void handle_moddevtable(struct module
*mod
, struct elf_info
*info
,
846 Elf_Sym
*sym
, const char *symname
)
851 /* We're looking for a section relative symbol */
852 if (!sym
->st_shndx
|| sym
->st_shndx
>= info
->hdr
->e_shnum
)
855 /* Handle all-NULL symbols allocated into .bss */
856 if (info
->sechdrs
[sym
->st_shndx
].sh_type
& SHT_NOBITS
) {
857 zeros
= calloc(1, sym
->st_size
);
860 symval
= (void *)info
->hdr
861 + info
->sechdrs
[sym
->st_shndx
].sh_offset
865 if (sym_is(symname
, "__mod_pci_device_table"))
866 do_table(symval
, sym
->st_size
,
867 sizeof(struct pci_device_id
), "pci",
869 else if (sym_is(symname
, "__mod_usb_device_table"))
870 /* special case to handle bcdDevice ranges */
871 do_usb_table(symval
, sym
->st_size
, mod
);
872 else if (sym_is(symname
, "__mod_hid_device_table"))
873 do_table(symval
, sym
->st_size
,
874 sizeof(struct hid_device_id
), "hid",
876 else if (sym_is(symname
, "__mod_ieee1394_device_table"))
877 do_table(symval
, sym
->st_size
,
878 sizeof(struct ieee1394_device_id
), "ieee1394",
879 do_ieee1394_entry
, mod
);
880 else if (sym_is(symname
, "__mod_ccw_device_table"))
881 do_table(symval
, sym
->st_size
,
882 sizeof(struct ccw_device_id
), "ccw",
884 else if (sym_is(symname
, "__mod_ap_device_table"))
885 do_table(symval
, sym
->st_size
,
886 sizeof(struct ap_device_id
), "ap",
888 else if (sym_is(symname
, "__mod_css_device_table"))
889 do_table(symval
, sym
->st_size
,
890 sizeof(struct css_device_id
), "css",
892 else if (sym_is(symname
, "__mod_serio_device_table"))
893 do_table(symval
, sym
->st_size
,
894 sizeof(struct serio_device_id
), "serio",
895 do_serio_entry
, mod
);
896 else if (sym_is(symname
, "__mod_acpi_device_table"))
897 do_table(symval
, sym
->st_size
,
898 sizeof(struct acpi_device_id
), "acpi",
900 else if (sym_is(symname
, "__mod_pnp_device_table"))
901 do_pnp_device_entry(symval
, sym
->st_size
, mod
);
902 else if (sym_is(symname
, "__mod_pnp_card_device_table"))
903 do_pnp_card_entries(symval
, sym
->st_size
, mod
);
904 else if (sym_is(symname
, "__mod_pcmcia_device_table"))
905 do_table(symval
, sym
->st_size
,
906 sizeof(struct pcmcia_device_id
), "pcmcia",
907 do_pcmcia_entry
, mod
);
908 else if (sym_is(symname
, "__mod_of_device_table"))
909 do_table(symval
, sym
->st_size
,
910 sizeof(struct of_device_id
), "of",
912 else if (sym_is(symname
, "__mod_vio_device_table"))
913 do_table(symval
, sym
->st_size
,
914 sizeof(struct vio_device_id
), "vio",
916 else if (sym_is(symname
, "__mod_input_device_table"))
917 do_table(symval
, sym
->st_size
,
918 sizeof(struct input_device_id
), "input",
919 do_input_entry
, mod
);
920 else if (sym_is(symname
, "__mod_eisa_device_table"))
921 do_table(symval
, sym
->st_size
,
922 sizeof(struct eisa_device_id
), "eisa",
924 else if (sym_is(symname
, "__mod_parisc_device_table"))
925 do_table(symval
, sym
->st_size
,
926 sizeof(struct parisc_device_id
), "parisc",
927 do_parisc_entry
, mod
);
928 else if (sym_is(symname
, "__mod_sdio_device_table"))
929 do_table(symval
, sym
->st_size
,
930 sizeof(struct sdio_device_id
), "sdio",
932 else if (sym_is(symname
, "__mod_ssb_device_table"))
933 do_table(symval
, sym
->st_size
,
934 sizeof(struct ssb_device_id
), "ssb",
936 else if (sym_is(symname
, "__mod_virtio_device_table"))
937 do_table(symval
, sym
->st_size
,
938 sizeof(struct virtio_device_id
), "virtio",
939 do_virtio_entry
, mod
);
940 else if (sym_is(symname
, "__mod_i2c_device_table"))
941 do_table(symval
, sym
->st_size
,
942 sizeof(struct i2c_device_id
), "i2c",
944 else if (sym_is(symname
, "__mod_spi_device_table"))
945 do_table(symval
, sym
->st_size
,
946 sizeof(struct spi_device_id
), "spi",
948 else if (sym_is(symname
, "__mod_dmi_device_table"))
949 do_table(symval
, sym
->st_size
,
950 sizeof(struct dmi_system_id
), "dmi",
952 else if (sym_is(symname
, "__mod_platform_device_table"))
953 do_table(symval
, sym
->st_size
,
954 sizeof(struct platform_device_id
), "platform",
955 do_platform_entry
, mod
);
956 else if (sym_is(symname
, "__mod_zorro_device_table"))
957 do_table(symval
, sym
->st_size
,
958 sizeof(struct zorro_device_id
), "zorro",
959 do_zorro_entry
, mod
);
963 /* Now add out buffered information to the generated C source */
964 void add_moddevtable(struct buffer
*buf
, struct module
*mod
)
966 buf_printf(buf
, "\n");
967 buf_write(buf
, mod
->dev_table_buf
.p
, mod
->dev_table_buf
.pos
);
968 free(mod
->dev_table_buf
.p
);