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.
14 #include "devicetable-offsets.h"
16 /* We use the ELF typedefs for kernel_ulong_t but bite the bullet and
17 * use either stdint.h or inttypes.h for the rest. */
18 #if KERNEL_ELFCLASS == ELFCLASS32
19 typedef Elf32_Addr kernel_ulong_t
;
20 #define BITS_PER_LONG 32
22 typedef Elf64_Addr kernel_ulong_t
;
23 #define BITS_PER_LONG 64
34 typedef uint32_t __u32
;
35 typedef uint16_t __u16
;
36 typedef unsigned char __u8
;
41 /* Big exception to the "don't include kernel headers into userspace, which
42 * even potentially has different endianness and word sizes, since
43 * we handle those differences explicitly below */
44 #include "../../include/linux/mod_devicetable.h"
46 /* This array collects all instances that use the generic do_table */
48 const char *device_id
; /* name of table, __mod_<name>__*_device_table. */
49 unsigned long id_size
;
53 #define ___cat(a,b) a ## b
54 #define __cat(a,b) ___cat(a,b)
56 /* we need some special handling for this host tool running eventually on
57 * Darwin. The Mach-O section handling is a bit different than ELF section
58 * handling. The differnces in detail are:
59 * a) we have segments which have sections
60 * b) we need a API call to get the respective section symbols */
62 #include <mach-o/getsect.h>
64 #define INIT_SECTION(name) do { \
65 unsigned long name ## _len; \
66 char *__cat(pstart_,name) = getsectdata("__TEXT", \
67 #name, &__cat(name,_len)); \
68 char *__cat(pstop_,name) = __cat(pstart_,name) + \
70 __cat(__start_,name) = (void *)__cat(pstart_,name); \
71 __cat(__stop_,name) = (void *)__cat(pstop_,name); \
73 #define SECTION(name) __attribute__((section("__TEXT, " #name)))
75 struct devtable
**__start___devtable
, **__stop___devtable
;
77 #define INIT_SECTION(name) /* no-op for ELF */
78 #define SECTION(name) __attribute__((section(#name)))
80 /* We construct a table of pointers in an ELF section (pointers generally
81 * go unpadded by gcc). ld creates boundary syms for us. */
82 extern struct devtable
*__start___devtable
[], *__stop___devtable
[];
86 # if __GNUC__ == 3 && __GNUC_MINOR__ < 3
87 # define __used __attribute__((__unused__))
89 # define __used __attribute__((__used__))
93 /* Define a variable f that holds the value of field f of struct devid
96 #define DEF_FIELD(m, devid, f) \
97 typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
98 /* Define a variable f that holds the address of field f of struct devid
99 * based at address m. Due to the way typeof works, for a field of type
100 * T[N] the variable has type T(*)[N], _not_ T*.
102 #define DEF_FIELD_ADDR(m, devid, f) \
103 typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
105 /* Add a table entry. We test function type matches while we're here. */
106 #define ADD_TO_DEVTABLE(device_id, type, function) \
107 static struct devtable __cat(devtable,__LINE__) = { \
108 device_id + 0*sizeof((function)((const char *)NULL, \
111 SIZE_##type, (function) }; \
112 static struct devtable *SECTION(__devtable) __used \
113 __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__)
115 #define ADD(str, sep, cond, field) \
119 sprintf(str + strlen(str), \
120 sizeof(field) == 1 ? "%02X" : \
121 sizeof(field) == 2 ? "%04X" : \
122 sizeof(field) == 4 ? "%08X" : "", \
125 sprintf(str + strlen(str), "*"); \
128 /* Always end in a wildcard, for future extension */
129 static inline void add_wildcard(char *str
)
131 int len
= strlen(str
);
133 if (str
[len
- 1] != '*')
134 strcat(str
+ len
, "*");
137 static inline void add_uuid(char *str
, uuid_le uuid
)
139 int len
= strlen(str
);
142 for (i
= 0; i
< 16; i
++)
143 sprintf(str
+ len
+ (i
<< 1), "%02x", uuid
.b
[i
]);
147 * Check that sizeof(device_id type) are consistent with size of section
148 * in .o file. If in-consistent then userspace and kernel does not agree
149 * on actual size which is a bug.
150 * Also verify that the final entry in the table is all zeros.
151 * Ignore both checks if build host differ from target host and size differs.
153 static void device_id_check(const char *modname
, const char *device_id
,
154 unsigned long size
, unsigned long id_size
,
159 if (size
% id_size
|| size
< id_size
) {
160 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
162 "section __mod_%s__<identifier>_device_table=%lu.\n"
163 "Fix definition of struct %s_device_id "
164 "in mod_devicetable.h\n",
165 modname
, device_id
, id_size
, device_id
, size
, device_id
);
167 /* Verify last one is a terminator */
168 for (i
= 0; i
< id_size
; i
++ ) {
169 if (*(uint8_t*)(symval
+size
-id_size
+i
)) {
170 fprintf(stderr
,"%s: struct %s_device_id is %lu bytes. "
171 "The last of %lu is:\n",
172 modname
, device_id
, id_size
, size
/ id_size
);
173 for (i
= 0; i
< id_size
; i
++ )
174 fprintf(stderr
,"0x%02x ",
175 *(uint8_t*)(symval
+size
-id_size
+i
) );
176 fprintf(stderr
,"\n");
177 fatal("%s: struct %s_device_id is not terminated "
178 "with a NULL entry!\n", modname
, device_id
);
183 /* USB is special because the bcdDevice can be matched against a numeric range */
184 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
185 static void do_usb_entry(void *symval
,
186 unsigned int bcdDevice_initial
, int bcdDevice_initial_digits
,
187 unsigned char range_lo
, unsigned char range_hi
,
188 unsigned char max
, struct module
*mod
)
191 DEF_FIELD(symval
, usb_device_id
, match_flags
);
192 DEF_FIELD(symval
, usb_device_id
, idVendor
);
193 DEF_FIELD(symval
, usb_device_id
, idProduct
);
194 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
195 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
196 DEF_FIELD(symval
, usb_device_id
, bDeviceSubClass
);
197 DEF_FIELD(symval
, usb_device_id
, bDeviceProtocol
);
198 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
199 DEF_FIELD(symval
, usb_device_id
, bInterfaceSubClass
);
200 DEF_FIELD(symval
, usb_device_id
, bInterfaceProtocol
);
201 DEF_FIELD(symval
, usb_device_id
, bInterfaceNumber
);
203 strcpy(alias
, "usb:");
204 ADD(alias
, "v", match_flags
&USB_DEVICE_ID_MATCH_VENDOR
,
206 ADD(alias
, "p", match_flags
&USB_DEVICE_ID_MATCH_PRODUCT
,
210 if (bcdDevice_initial_digits
)
211 sprintf(alias
+ strlen(alias
), "%0*X",
212 bcdDevice_initial_digits
, bcdDevice_initial
);
213 if (range_lo
== range_hi
)
214 sprintf(alias
+ strlen(alias
), "%X", range_lo
);
215 else if (range_lo
> 0 || range_hi
< max
) {
216 if (range_lo
> 0x9 || range_hi
< 0xA)
217 sprintf(alias
+ strlen(alias
),
222 sprintf(alias
+ strlen(alias
),
223 range_lo
< 0x9 ? "[%X-9" : "[%X",
225 sprintf(alias
+ strlen(alias
),
226 range_hi
> 0xA ? "A-%X]" : "%X]",
230 if (bcdDevice_initial_digits
< (sizeof(bcdDevice_lo
) * 2 - 1))
233 ADD(alias
, "dc", match_flags
&USB_DEVICE_ID_MATCH_DEV_CLASS
,
235 ADD(alias
, "dsc", match_flags
&USB_DEVICE_ID_MATCH_DEV_SUBCLASS
,
237 ADD(alias
, "dp", match_flags
&USB_DEVICE_ID_MATCH_DEV_PROTOCOL
,
239 ADD(alias
, "ic", match_flags
&USB_DEVICE_ID_MATCH_INT_CLASS
,
241 ADD(alias
, "isc", match_flags
&USB_DEVICE_ID_MATCH_INT_SUBCLASS
,
243 ADD(alias
, "ip", match_flags
&USB_DEVICE_ID_MATCH_INT_PROTOCOL
,
245 ADD(alias
, "in", match_flags
&USB_DEVICE_ID_MATCH_INT_NUMBER
,
249 buf_printf(&mod
->dev_table_buf
,
250 "MODULE_ALIAS(\"%s\");\n", alias
);
253 /* Handles increment/decrement of BCD formatted integers */
254 /* Returns the previous value, so it works like i++ or i-- */
255 static unsigned int incbcd(unsigned int *bcd
,
260 unsigned int init
= *bcd
, i
, j
;
261 unsigned long long c
, dec
= 0;
263 /* If bcd is not in BCD format, just increment */
269 /* Convert BCD to Decimal */
270 for (i
=0 ; i
< chars
; i
++) {
271 c
= (*bcd
>> (i
<< 2)) & 0xf;
272 c
= c
> 9 ? 9 : c
; /* force to bcd just in case */
273 for (j
=0 ; j
< i
; j
++)
278 /* Do our increment/decrement */
282 /* Convert back to BCD */
283 for (i
=0 ; i
< chars
; i
++) {
284 for (c
=1,j
=0 ; j
< i
; j
++)
287 *bcd
+= c
<< (i
<< 2);
292 static void do_usb_entry_multi(void *symval
, struct module
*mod
)
294 unsigned int devlo
, devhi
;
295 unsigned char chi
, clo
, max
;
298 DEF_FIELD(symval
, usb_device_id
, match_flags
);
299 DEF_FIELD(symval
, usb_device_id
, idVendor
);
300 DEF_FIELD(symval
, usb_device_id
, idProduct
);
301 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
302 DEF_FIELD(symval
, usb_device_id
, bcdDevice_hi
);
303 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
304 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
306 devlo
= match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
?
308 devhi
= match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
?
309 bcdDevice_hi
: ~0x0U
;
311 /* Figure out if this entry is in bcd or hex format */
312 max
= 0x9; /* Default to decimal format */
313 for (ndigits
= 0 ; ndigits
< sizeof(bcdDevice_lo
) * 2 ; ndigits
++) {
314 clo
= (devlo
>> (ndigits
<< 2)) & 0xf;
315 chi
= ((devhi
> 0x9999 ? 0x9999 : devhi
) >> (ndigits
<< 2)) & 0xf;
316 if (clo
> max
|| chi
> max
) {
323 * Some modules (visor) have empty slots as placeholder for
324 * run-time specification that results in catch-all alias
326 if (!(idVendor
| idProduct
| bDeviceClass
| bInterfaceClass
))
329 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
330 for (ndigits
= sizeof(bcdDevice_lo
) * 2 - 1; devlo
<= devhi
; ndigits
--) {
333 if (chi
> max
) /* If we are in bcd mode, truncate if necessary */
338 if (devlo
== devhi
|| !ndigits
) {
339 do_usb_entry(symval
, devlo
, ndigits
, clo
, chi
, max
, mod
);
345 incbcd(&devlo
, 1, max
,
346 sizeof(bcdDevice_lo
) * 2),
347 ndigits
, clo
, max
, max
, mod
);
351 incbcd(&devhi
, -1, max
,
352 sizeof(bcdDevice_lo
) * 2),
353 ndigits
, 0x0, chi
, max
, mod
);
357 static void do_usb_table(void *symval
, unsigned long size
,
361 const unsigned long id_size
= SIZE_usb_device_id
;
363 device_id_check(mod
->name
, "usb", size
, id_size
, symval
);
365 /* Leave last one: it's the terminator. */
368 for (i
= 0; i
< size
; i
+= id_size
)
369 do_usb_entry_multi(symval
+ i
, mod
);
372 /* Looks like: hid:bNvNpN */
373 static int do_hid_entry(const char *filename
,
374 void *symval
, char *alias
)
376 DEF_FIELD(symval
, hid_device_id
, bus
);
377 DEF_FIELD(symval
, hid_device_id
, group
);
378 DEF_FIELD(symval
, hid_device_id
, vendor
);
379 DEF_FIELD(symval
, hid_device_id
, product
);
381 sprintf(alias
, "hid:");
382 ADD(alias
, "b", bus
!= HID_BUS_ANY
, bus
);
383 ADD(alias
, "g", group
!= HID_GROUP_ANY
, group
);
384 ADD(alias
, "v", vendor
!= HID_ANY_ID
, vendor
);
385 ADD(alias
, "p", product
!= HID_ANY_ID
, product
);
389 ADD_TO_DEVTABLE("hid", hid_device_id
, do_hid_entry
);
391 /* Looks like: ieee1394:venNmoNspNverN */
392 static int do_ieee1394_entry(const char *filename
,
393 void *symval
, char *alias
)
395 DEF_FIELD(symval
, ieee1394_device_id
, match_flags
);
396 DEF_FIELD(symval
, ieee1394_device_id
, vendor_id
);
397 DEF_FIELD(symval
, ieee1394_device_id
, model_id
);
398 DEF_FIELD(symval
, ieee1394_device_id
, specifier_id
);
399 DEF_FIELD(symval
, ieee1394_device_id
, version
);
401 strcpy(alias
, "ieee1394:");
402 ADD(alias
, "ven", match_flags
& IEEE1394_MATCH_VENDOR_ID
,
404 ADD(alias
, "mo", match_flags
& IEEE1394_MATCH_MODEL_ID
,
406 ADD(alias
, "sp", match_flags
& IEEE1394_MATCH_SPECIFIER_ID
,
408 ADD(alias
, "ver", match_flags
& IEEE1394_MATCH_VERSION
,
414 ADD_TO_DEVTABLE("ieee1394", ieee1394_device_id
, do_ieee1394_entry
);
416 /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
417 static int do_pci_entry(const char *filename
,
418 void *symval
, char *alias
)
420 /* Class field can be divided into these three. */
421 unsigned char baseclass
, subclass
, interface
,
422 baseclass_mask
, subclass_mask
, interface_mask
;
424 DEF_FIELD(symval
, pci_device_id
, vendor
);
425 DEF_FIELD(symval
, pci_device_id
, device
);
426 DEF_FIELD(symval
, pci_device_id
, subvendor
);
427 DEF_FIELD(symval
, pci_device_id
, subdevice
);
428 DEF_FIELD(symval
, pci_device_id
, class);
429 DEF_FIELD(symval
, pci_device_id
, class_mask
);
431 strcpy(alias
, "pci:");
432 ADD(alias
, "v", vendor
!= PCI_ANY_ID
, vendor
);
433 ADD(alias
, "d", device
!= PCI_ANY_ID
, device
);
434 ADD(alias
, "sv", subvendor
!= PCI_ANY_ID
, subvendor
);
435 ADD(alias
, "sd", subdevice
!= PCI_ANY_ID
, subdevice
);
437 baseclass
= (class) >> 16;
438 baseclass_mask
= (class_mask
) >> 16;
439 subclass
= (class) >> 8;
440 subclass_mask
= (class_mask
) >> 8;
442 interface_mask
= class_mask
;
444 if ((baseclass_mask
!= 0 && baseclass_mask
!= 0xFF)
445 || (subclass_mask
!= 0 && subclass_mask
!= 0xFF)
446 || (interface_mask
!= 0 && interface_mask
!= 0xFF)) {
447 warn("Can't handle masks in %s:%04X\n",
448 filename
, class_mask
);
452 ADD(alias
, "bc", baseclass_mask
== 0xFF, baseclass
);
453 ADD(alias
, "sc", subclass_mask
== 0xFF, subclass
);
454 ADD(alias
, "i", interface_mask
== 0xFF, interface
);
458 ADD_TO_DEVTABLE("pci", pci_device_id
, do_pci_entry
);
460 /* looks like: "ccw:tNmNdtNdmN" */
461 static int do_ccw_entry(const char *filename
,
462 void *symval
, char *alias
)
464 DEF_FIELD(symval
, ccw_device_id
, match_flags
);
465 DEF_FIELD(symval
, ccw_device_id
, cu_type
);
466 DEF_FIELD(symval
, ccw_device_id
, cu_model
);
467 DEF_FIELD(symval
, ccw_device_id
, dev_type
);
468 DEF_FIELD(symval
, ccw_device_id
, dev_model
);
470 strcpy(alias
, "ccw:");
471 ADD(alias
, "t", match_flags
&CCW_DEVICE_ID_MATCH_CU_TYPE
,
473 ADD(alias
, "m", match_flags
&CCW_DEVICE_ID_MATCH_CU_MODEL
,
475 ADD(alias
, "dt", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_TYPE
,
477 ADD(alias
, "dm", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_MODEL
,
482 ADD_TO_DEVTABLE("ccw", ccw_device_id
, do_ccw_entry
);
484 /* looks like: "ap:tN" */
485 static int do_ap_entry(const char *filename
,
486 void *symval
, char *alias
)
488 DEF_FIELD(symval
, ap_device_id
, dev_type
);
490 sprintf(alias
, "ap:t%02X*", dev_type
);
493 ADD_TO_DEVTABLE("ap", ap_device_id
, do_ap_entry
);
495 /* looks like: "css:tN" */
496 static int do_css_entry(const char *filename
,
497 void *symval
, char *alias
)
499 DEF_FIELD(symval
, css_device_id
, type
);
501 sprintf(alias
, "css:t%01X", type
);
504 ADD_TO_DEVTABLE("css", css_device_id
, do_css_entry
);
506 /* Looks like: "serio:tyNprNidNexN" */
507 static int do_serio_entry(const char *filename
,
508 void *symval
, char *alias
)
510 DEF_FIELD(symval
, serio_device_id
, type
);
511 DEF_FIELD(symval
, serio_device_id
, proto
);
512 DEF_FIELD(symval
, serio_device_id
, id
);
513 DEF_FIELD(symval
, serio_device_id
, extra
);
515 strcpy(alias
, "serio:");
516 ADD(alias
, "ty", type
!= SERIO_ANY
, type
);
517 ADD(alias
, "pr", proto
!= SERIO_ANY
, proto
);
518 ADD(alias
, "id", id
!= SERIO_ANY
, id
);
519 ADD(alias
, "ex", extra
!= SERIO_ANY
, extra
);
524 ADD_TO_DEVTABLE("serio", serio_device_id
, do_serio_entry
);
526 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
527 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
529 * NOTE: Each driver should use one of the following : _HID, _CIDs
530 * or _CLS. Also, bb, ss, and pp can be substituted with ??
531 * as don't care byte.
533 static int do_acpi_entry(const char *filename
,
534 void *symval
, char *alias
)
536 DEF_FIELD_ADDR(symval
, acpi_device_id
, id
);
537 DEF_FIELD_ADDR(symval
, acpi_device_id
, cls
);
538 DEF_FIELD_ADDR(symval
, acpi_device_id
, cls_msk
);
540 if (id
&& strlen((const char *)*id
))
541 sprintf(alias
, "acpi*:%s:*", *id
);
543 int i
, byte_shift
, cnt
= 0;
546 sprintf(&alias
[cnt
], "acpi*:");
548 for (i
= 1; i
<= 3; i
++) {
549 byte_shift
= 8 * (3-i
);
550 msk
= (*cls_msk
>> byte_shift
) & 0xFF;
552 sprintf(&alias
[cnt
], "%02x",
553 (*cls
>> byte_shift
) & 0xFF);
555 sprintf(&alias
[cnt
], "??");
558 sprintf(&alias
[cnt
], ":*");
562 ADD_TO_DEVTABLE("acpi", acpi_device_id
, do_acpi_entry
);
564 /* looks like: "pnp:dD" */
565 static void do_pnp_device_entry(void *symval
, unsigned long size
,
568 const unsigned long id_size
= SIZE_pnp_device_id
;
569 const unsigned int count
= (size
/ id_size
)-1;
572 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
574 for (i
= 0; i
< count
; i
++) {
575 DEF_FIELD_ADDR(symval
+ i
*id_size
, pnp_device_id
, id
);
576 char acpi_id
[sizeof(*id
)];
579 buf_printf(&mod
->dev_table_buf
,
580 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id
);
582 /* fix broken pnp bus lowercasing */
583 for (j
= 0; j
< sizeof(acpi_id
); j
++)
584 acpi_id
[j
] = toupper((*id
)[j
]);
585 buf_printf(&mod
->dev_table_buf
,
586 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
590 /* looks like: "pnp:dD" for every device of the card */
591 static void do_pnp_card_entries(void *symval
, unsigned long size
,
594 const unsigned long id_size
= SIZE_pnp_card_device_id
;
595 const unsigned int count
= (size
/ id_size
)-1;
598 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
600 for (i
= 0; i
< count
; i
++) {
602 DEF_FIELD_ADDR(symval
+ i
*id_size
, pnp_card_device_id
, devs
);
604 for (j
= 0; j
< PNP_MAX_DEVICES
; j
++) {
605 const char *id
= (char *)(*devs
)[j
].id
;
612 /* find duplicate, already added value */
613 for (i2
= 0; i2
< i
&& !dup
; i2
++) {
614 DEF_FIELD_ADDR(symval
+ i2
*id_size
, pnp_card_device_id
, devs
);
616 for (j2
= 0; j2
< PNP_MAX_DEVICES
; j2
++) {
617 const char *id2
= (char *)(*devs
)[j2
].id
;
622 if (!strcmp(id
, id2
)) {
629 /* add an individual alias for every device entry */
631 char acpi_id
[PNP_ID_LEN
];
634 buf_printf(&mod
->dev_table_buf
,
635 "MODULE_ALIAS(\"pnp:d%s*\");\n", id
);
637 /* fix broken pnp bus lowercasing */
638 for (k
= 0; k
< sizeof(acpi_id
); k
++)
639 acpi_id
[k
] = toupper(id
[k
]);
640 buf_printf(&mod
->dev_table_buf
,
641 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
647 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
648 static int do_pcmcia_entry(const char *filename
,
649 void *symval
, char *alias
)
652 DEF_FIELD(symval
, pcmcia_device_id
, match_flags
);
653 DEF_FIELD(symval
, pcmcia_device_id
, manf_id
);
654 DEF_FIELD(symval
, pcmcia_device_id
, card_id
);
655 DEF_FIELD(symval
, pcmcia_device_id
, func_id
);
656 DEF_FIELD(symval
, pcmcia_device_id
, function
);
657 DEF_FIELD(symval
, pcmcia_device_id
, device_no
);
658 DEF_FIELD_ADDR(symval
, pcmcia_device_id
, prod_id_hash
);
660 for (i
=0; i
<4; i
++) {
661 (*prod_id_hash
)[i
] = TO_NATIVE((*prod_id_hash
)[i
]);
664 strcpy(alias
, "pcmcia:");
665 ADD(alias
, "m", match_flags
& PCMCIA_DEV_ID_MATCH_MANF_ID
,
667 ADD(alias
, "c", match_flags
& PCMCIA_DEV_ID_MATCH_CARD_ID
,
669 ADD(alias
, "f", match_flags
& PCMCIA_DEV_ID_MATCH_FUNC_ID
,
671 ADD(alias
, "fn", match_flags
& PCMCIA_DEV_ID_MATCH_FUNCTION
,
673 ADD(alias
, "pfn", match_flags
& PCMCIA_DEV_ID_MATCH_DEVICE_NO
,
675 ADD(alias
, "pa", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID1
, (*prod_id_hash
)[0]);
676 ADD(alias
, "pb", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID2
, (*prod_id_hash
)[1]);
677 ADD(alias
, "pc", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID3
, (*prod_id_hash
)[2]);
678 ADD(alias
, "pd", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID4
, (*prod_id_hash
)[3]);
683 ADD_TO_DEVTABLE("pcmcia", pcmcia_device_id
, do_pcmcia_entry
);
685 static int do_of_entry (const char *filename
, void *symval
, char *alias
)
689 DEF_FIELD_ADDR(symval
, of_device_id
, name
);
690 DEF_FIELD_ADDR(symval
, of_device_id
, type
);
691 DEF_FIELD_ADDR(symval
, of_device_id
, compatible
);
693 len
= sprintf(alias
, "of:N%sT%s", (*name
)[0] ? *name
: "*",
694 (*type
)[0] ? *type
: "*");
697 sprintf(&alias
[len
], "%sC%s", (*type
)[0] ? "*" : "",
700 /* Replace all whitespace with underscores */
701 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
708 ADD_TO_DEVTABLE("of", of_device_id
, do_of_entry
);
710 static int do_vio_entry(const char *filename
, void *symval
,
714 DEF_FIELD_ADDR(symval
, vio_device_id
, type
);
715 DEF_FIELD_ADDR(symval
, vio_device_id
, compat
);
717 sprintf(alias
, "vio:T%sS%s", (*type
)[0] ? *type
: "*",
718 (*compat
)[0] ? *compat
: "*");
720 /* Replace all whitespace with underscores */
721 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
728 ADD_TO_DEVTABLE("vio", vio_device_id
, do_vio_entry
);
730 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
732 static void do_input(char *alias
,
733 kernel_ulong_t
*arr
, unsigned int min
, unsigned int max
)
737 for (i
= min
/ BITS_PER_LONG
; i
< max
/ BITS_PER_LONG
+ 1; i
++)
738 arr
[i
] = TO_NATIVE(arr
[i
]);
739 for (i
= min
; i
< max
; i
++)
740 if (arr
[i
/ BITS_PER_LONG
] & (1L << (i
%BITS_PER_LONG
)))
741 sprintf(alias
+ strlen(alias
), "%X,*", i
);
744 /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
745 static int do_input_entry(const char *filename
, void *symval
,
748 DEF_FIELD(symval
, input_device_id
, flags
);
749 DEF_FIELD(symval
, input_device_id
, bustype
);
750 DEF_FIELD(symval
, input_device_id
, vendor
);
751 DEF_FIELD(symval
, input_device_id
, product
);
752 DEF_FIELD(symval
, input_device_id
, version
);
753 DEF_FIELD_ADDR(symval
, input_device_id
, evbit
);
754 DEF_FIELD_ADDR(symval
, input_device_id
, keybit
);
755 DEF_FIELD_ADDR(symval
, input_device_id
, relbit
);
756 DEF_FIELD_ADDR(symval
, input_device_id
, absbit
);
757 DEF_FIELD_ADDR(symval
, input_device_id
, mscbit
);
758 DEF_FIELD_ADDR(symval
, input_device_id
, ledbit
);
759 DEF_FIELD_ADDR(symval
, input_device_id
, sndbit
);
760 DEF_FIELD_ADDR(symval
, input_device_id
, ffbit
);
761 DEF_FIELD_ADDR(symval
, input_device_id
, swbit
);
763 sprintf(alias
, "input:");
765 ADD(alias
, "b", flags
& INPUT_DEVICE_ID_MATCH_BUS
, bustype
);
766 ADD(alias
, "v", flags
& INPUT_DEVICE_ID_MATCH_VENDOR
, vendor
);
767 ADD(alias
, "p", flags
& INPUT_DEVICE_ID_MATCH_PRODUCT
, product
);
768 ADD(alias
, "e", flags
& INPUT_DEVICE_ID_MATCH_VERSION
, version
);
770 sprintf(alias
+ strlen(alias
), "-e*");
771 if (flags
& INPUT_DEVICE_ID_MATCH_EVBIT
)
772 do_input(alias
, *evbit
, 0, INPUT_DEVICE_ID_EV_MAX
);
773 sprintf(alias
+ strlen(alias
), "k*");
774 if (flags
& INPUT_DEVICE_ID_MATCH_KEYBIT
)
775 do_input(alias
, *keybit
,
776 INPUT_DEVICE_ID_KEY_MIN_INTERESTING
,
777 INPUT_DEVICE_ID_KEY_MAX
);
778 sprintf(alias
+ strlen(alias
), "r*");
779 if (flags
& INPUT_DEVICE_ID_MATCH_RELBIT
)
780 do_input(alias
, *relbit
, 0, INPUT_DEVICE_ID_REL_MAX
);
781 sprintf(alias
+ strlen(alias
), "a*");
782 if (flags
& INPUT_DEVICE_ID_MATCH_ABSBIT
)
783 do_input(alias
, *absbit
, 0, INPUT_DEVICE_ID_ABS_MAX
);
784 sprintf(alias
+ strlen(alias
), "m*");
785 if (flags
& INPUT_DEVICE_ID_MATCH_MSCIT
)
786 do_input(alias
, *mscbit
, 0, INPUT_DEVICE_ID_MSC_MAX
);
787 sprintf(alias
+ strlen(alias
), "l*");
788 if (flags
& INPUT_DEVICE_ID_MATCH_LEDBIT
)
789 do_input(alias
, *ledbit
, 0, INPUT_DEVICE_ID_LED_MAX
);
790 sprintf(alias
+ strlen(alias
), "s*");
791 if (flags
& INPUT_DEVICE_ID_MATCH_SNDBIT
)
792 do_input(alias
, *sndbit
, 0, INPUT_DEVICE_ID_SND_MAX
);
793 sprintf(alias
+ strlen(alias
), "f*");
794 if (flags
& INPUT_DEVICE_ID_MATCH_FFBIT
)
795 do_input(alias
, *ffbit
, 0, INPUT_DEVICE_ID_FF_MAX
);
796 sprintf(alias
+ strlen(alias
), "w*");
797 if (flags
& INPUT_DEVICE_ID_MATCH_SWBIT
)
798 do_input(alias
, *swbit
, 0, INPUT_DEVICE_ID_SW_MAX
);
801 ADD_TO_DEVTABLE("input", input_device_id
, do_input_entry
);
803 static int do_eisa_entry(const char *filename
, void *symval
,
806 DEF_FIELD_ADDR(symval
, eisa_device_id
, sig
);
808 sprintf(alias
, EISA_DEVICE_MODALIAS_FMT
"*", *sig
);
813 ADD_TO_DEVTABLE("eisa", eisa_device_id
, do_eisa_entry
);
815 /* Looks like: parisc:tNhvNrevNsvN */
816 static int do_parisc_entry(const char *filename
, void *symval
,
819 DEF_FIELD(symval
, parisc_device_id
, hw_type
);
820 DEF_FIELD(symval
, parisc_device_id
, hversion
);
821 DEF_FIELD(symval
, parisc_device_id
, hversion_rev
);
822 DEF_FIELD(symval
, parisc_device_id
, sversion
);
824 strcpy(alias
, "parisc:");
825 ADD(alias
, "t", hw_type
!= PA_HWTYPE_ANY_ID
, hw_type
);
826 ADD(alias
, "hv", hversion
!= PA_HVERSION_ANY_ID
, hversion
);
827 ADD(alias
, "rev", hversion_rev
!= PA_HVERSION_REV_ANY_ID
, hversion_rev
);
828 ADD(alias
, "sv", sversion
!= PA_SVERSION_ANY_ID
, sversion
);
833 ADD_TO_DEVTABLE("parisc", parisc_device_id
, do_parisc_entry
);
835 /* Looks like: sdio:cNvNdN. */
836 static int do_sdio_entry(const char *filename
,
837 void *symval
, char *alias
)
839 DEF_FIELD(symval
, sdio_device_id
, class);
840 DEF_FIELD(symval
, sdio_device_id
, vendor
);
841 DEF_FIELD(symval
, sdio_device_id
, device
);
843 strcpy(alias
, "sdio:");
844 ADD(alias
, "c", class != (__u8
)SDIO_ANY_ID
, class);
845 ADD(alias
, "v", vendor
!= (__u16
)SDIO_ANY_ID
, vendor
);
846 ADD(alias
, "d", device
!= (__u16
)SDIO_ANY_ID
, device
);
850 ADD_TO_DEVTABLE("sdio", sdio_device_id
, do_sdio_entry
);
852 /* Looks like: ssb:vNidNrevN. */
853 static int do_ssb_entry(const char *filename
,
854 void *symval
, char *alias
)
856 DEF_FIELD(symval
, ssb_device_id
, vendor
);
857 DEF_FIELD(symval
, ssb_device_id
, coreid
);
858 DEF_FIELD(symval
, ssb_device_id
, revision
);
860 strcpy(alias
, "ssb:");
861 ADD(alias
, "v", vendor
!= SSB_ANY_VENDOR
, vendor
);
862 ADD(alias
, "id", coreid
!= SSB_ANY_ID
, coreid
);
863 ADD(alias
, "rev", revision
!= SSB_ANY_REV
, revision
);
867 ADD_TO_DEVTABLE("ssb", ssb_device_id
, do_ssb_entry
);
869 /* Looks like: bcma:mNidNrevNclN. */
870 static int do_bcma_entry(const char *filename
,
871 void *symval
, char *alias
)
873 DEF_FIELD(symval
, bcma_device_id
, manuf
);
874 DEF_FIELD(symval
, bcma_device_id
, id
);
875 DEF_FIELD(symval
, bcma_device_id
, rev
);
876 DEF_FIELD(symval
, bcma_device_id
, class);
878 strcpy(alias
, "bcma:");
879 ADD(alias
, "m", manuf
!= BCMA_ANY_MANUF
, manuf
);
880 ADD(alias
, "id", id
!= BCMA_ANY_ID
, id
);
881 ADD(alias
, "rev", rev
!= BCMA_ANY_REV
, rev
);
882 ADD(alias
, "cl", class != BCMA_ANY_CLASS
, class);
886 ADD_TO_DEVTABLE("bcma", bcma_device_id
, do_bcma_entry
);
888 /* Looks like: virtio:dNvN */
889 static int do_virtio_entry(const char *filename
, void *symval
,
892 DEF_FIELD(symval
, virtio_device_id
, device
);
893 DEF_FIELD(symval
, virtio_device_id
, vendor
);
895 strcpy(alias
, "virtio:");
896 ADD(alias
, "d", device
!= VIRTIO_DEV_ANY_ID
, device
);
897 ADD(alias
, "v", vendor
!= VIRTIO_DEV_ANY_ID
, vendor
);
902 ADD_TO_DEVTABLE("virtio", virtio_device_id
, do_virtio_entry
);
905 * Looks like: vmbus:guid
906 * Each byte of the guid will be represented by two hex characters
910 static int do_vmbus_entry(const char *filename
, void *symval
,
914 DEF_FIELD_ADDR(symval
, hv_vmbus_device_id
, guid
);
915 char guid_name
[(sizeof(*guid
) + 1) * 2];
917 for (i
= 0; i
< (sizeof(*guid
) * 2); i
+= 2)
918 sprintf(&guid_name
[i
], "%02x", TO_NATIVE((*guid
)[i
/2]));
920 strcpy(alias
, "vmbus:");
921 strcat(alias
, guid_name
);
925 ADD_TO_DEVTABLE("vmbus", hv_vmbus_device_id
, do_vmbus_entry
);
927 /* Looks like: i2c:S */
928 static int do_i2c_entry(const char *filename
, void *symval
,
931 DEF_FIELD_ADDR(symval
, i2c_device_id
, name
);
932 sprintf(alias
, I2C_MODULE_PREFIX
"%s", *name
);
936 ADD_TO_DEVTABLE("i2c", i2c_device_id
, do_i2c_entry
);
938 /* Looks like: spi:S */
939 static int do_spi_entry(const char *filename
, void *symval
,
942 DEF_FIELD_ADDR(symval
, spi_device_id
, name
);
943 sprintf(alias
, SPI_MODULE_PREFIX
"%s", *name
);
947 ADD_TO_DEVTABLE("spi", spi_device_id
, do_spi_entry
);
949 static const struct dmifield
{
953 { "bvn", DMI_BIOS_VENDOR
},
954 { "bvr", DMI_BIOS_VERSION
},
955 { "bd", DMI_BIOS_DATE
},
956 { "svn", DMI_SYS_VENDOR
},
957 { "pn", DMI_PRODUCT_NAME
},
958 { "pvr", DMI_PRODUCT_VERSION
},
959 { "rvn", DMI_BOARD_VENDOR
},
960 { "rn", DMI_BOARD_NAME
},
961 { "rvr", DMI_BOARD_VERSION
},
962 { "cvn", DMI_CHASSIS_VENDOR
},
963 { "ct", DMI_CHASSIS_TYPE
},
964 { "cvr", DMI_CHASSIS_VERSION
},
968 static void dmi_ascii_filter(char *d
, const char *s
)
970 /* Filter out characters we don't want to see in the modalias string */
972 if (*s
> ' ' && *s
< 127 && *s
!= ':')
979 static int do_dmi_entry(const char *filename
, void *symval
,
983 DEF_FIELD_ADDR(symval
, dmi_system_id
, matches
);
984 sprintf(alias
, "dmi*");
986 for (i
= 0; i
< ARRAY_SIZE(dmi_fields
); i
++) {
987 for (j
= 0; j
< 4; j
++) {
988 if ((*matches
)[j
].slot
&&
989 (*matches
)[j
].slot
== dmi_fields
[i
].field
) {
990 sprintf(alias
+ strlen(alias
), ":%s*",
991 dmi_fields
[i
].prefix
);
992 dmi_ascii_filter(alias
+ strlen(alias
),
993 (*matches
)[j
].substr
);
1002 ADD_TO_DEVTABLE("dmi", dmi_system_id
, do_dmi_entry
);
1004 static int do_platform_entry(const char *filename
,
1005 void *symval
, char *alias
)
1007 DEF_FIELD_ADDR(symval
, platform_device_id
, name
);
1008 sprintf(alias
, PLATFORM_MODULE_PREFIX
"%s", *name
);
1011 ADD_TO_DEVTABLE("platform", platform_device_id
, do_platform_entry
);
1013 static int do_mdio_entry(const char *filename
,
1014 void *symval
, char *alias
)
1017 DEF_FIELD(symval
, mdio_device_id
, phy_id
);
1018 DEF_FIELD(symval
, mdio_device_id
, phy_id_mask
);
1020 alias
+= sprintf(alias
, MDIO_MODULE_PREFIX
);
1022 for (i
= 0; i
< 32; i
++) {
1023 if (!((phy_id_mask
>> (31-i
)) & 1))
1025 else if ((phy_id
>> (31-i
)) & 1)
1031 /* Terminate the string */
1036 ADD_TO_DEVTABLE("mdio", mdio_device_id
, do_mdio_entry
);
1038 /* Looks like: zorro:iN. */
1039 static int do_zorro_entry(const char *filename
, void *symval
,
1042 DEF_FIELD(symval
, zorro_device_id
, id
);
1043 strcpy(alias
, "zorro:");
1044 ADD(alias
, "i", id
!= ZORRO_WILDCARD
, id
);
1047 ADD_TO_DEVTABLE("zorro", zorro_device_id
, do_zorro_entry
);
1049 /* looks like: "pnp:dD" */
1050 static int do_isapnp_entry(const char *filename
,
1051 void *symval
, char *alias
)
1053 DEF_FIELD(symval
, isapnp_device_id
, vendor
);
1054 DEF_FIELD(symval
, isapnp_device_id
, function
);
1055 sprintf(alias
, "pnp:d%c%c%c%x%x%x%x*",
1056 'A' + ((vendor
>> 2) & 0x3f) - 1,
1057 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
1058 'A' + ((vendor
>> 8) & 0x1f) - 1,
1059 (function
>> 4) & 0x0f, function
& 0x0f,
1060 (function
>> 12) & 0x0f, (function
>> 8) & 0x0f);
1063 ADD_TO_DEVTABLE("isapnp", isapnp_device_id
, do_isapnp_entry
);
1065 /* Looks like: "ipack:fNvNdN". */
1066 static int do_ipack_entry(const char *filename
,
1067 void *symval
, char *alias
)
1069 DEF_FIELD(symval
, ipack_device_id
, format
);
1070 DEF_FIELD(symval
, ipack_device_id
, vendor
);
1071 DEF_FIELD(symval
, ipack_device_id
, device
);
1072 strcpy(alias
, "ipack:");
1073 ADD(alias
, "f", format
!= IPACK_ANY_FORMAT
, format
);
1074 ADD(alias
, "v", vendor
!= IPACK_ANY_ID
, vendor
);
1075 ADD(alias
, "d", device
!= IPACK_ANY_ID
, device
);
1076 add_wildcard(alias
);
1079 ADD_TO_DEVTABLE("ipack", ipack_device_id
, do_ipack_entry
);
1082 * Append a match expression for a single masked hex digit.
1083 * outp points to a pointer to the character at which to append.
1084 * *outp is updated on return to point just after the appended text,
1085 * to facilitate further appending.
1087 static void append_nibble_mask(char **outp
,
1088 unsigned int nibble
, unsigned int mask
)
1099 p
+= sprintf(p
, "%X", nibble
);
1104 * Dumbly emit a match pattern for all possible matching
1105 * digits. This could be improved in some cases using ranges,
1106 * but it has the advantage of being trivially correct, and is
1110 for (i
= 0; i
< 0x10; i
++)
1111 if ((i
& mask
) == nibble
)
1112 p
+= sprintf(p
, "%X", i
);
1116 /* Ensure that the string remains NUL-terminated: */
1119 /* Advance the caller's end-of-string pointer: */
1124 * looks like: "amba:dN"
1126 * N is exactly 8 digits, where each is an upper-case hex digit, or
1127 * a ? or [] pattern matching exactly one digit.
1129 static int do_amba_entry(const char *filename
,
1130 void *symval
, char *alias
)
1134 DEF_FIELD(symval
, amba_id
, id
);
1135 DEF_FIELD(symval
, amba_id
, mask
);
1137 if ((id
& mask
) != id
)
1138 fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
1139 "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1140 filename
, id
, mask
);
1142 p
+= sprintf(alias
, "amba:d");
1143 for (digit
= 0; digit
< 8; digit
++)
1144 append_nibble_mask(&p
,
1145 (id
>> (4 * (7 - digit
))) & 0xf,
1146 (mask
>> (4 * (7 - digit
))) & 0xf);
1150 ADD_TO_DEVTABLE("amba", amba_id
, do_amba_entry
);
1153 * looks like: "mipscdmm:tN"
1155 * N is exactly 2 digits, where each is an upper-case hex digit, or
1156 * a ? or [] pattern matching exactly one digit.
1158 static int do_mips_cdmm_entry(const char *filename
,
1159 void *symval
, char *alias
)
1161 DEF_FIELD(symval
, mips_cdmm_device_id
, type
);
1163 sprintf(alias
, "mipscdmm:t%02X*", type
);
1166 ADD_TO_DEVTABLE("mipscdmm", mips_cdmm_device_id
, do_mips_cdmm_entry
);
1168 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
1169 * All fields are numbers. It would be nicer to use strings for vendor
1170 * and feature, but getting those out of the build system here is too
1174 static int do_x86cpu_entry(const char *filename
, void *symval
,
1177 DEF_FIELD(symval
, x86_cpu_id
, feature
);
1178 DEF_FIELD(symval
, x86_cpu_id
, family
);
1179 DEF_FIELD(symval
, x86_cpu_id
, model
);
1180 DEF_FIELD(symval
, x86_cpu_id
, vendor
);
1182 strcpy(alias
, "cpu:type:x86,");
1183 ADD(alias
, "ven", vendor
!= X86_VENDOR_ANY
, vendor
);
1184 ADD(alias
, "fam", family
!= X86_FAMILY_ANY
, family
);
1185 ADD(alias
, "mod", model
!= X86_MODEL_ANY
, model
);
1186 strcat(alias
, ":feature:*");
1187 if (feature
!= X86_FEATURE_ANY
)
1188 sprintf(alias
+ strlen(alias
), "%04X*", feature
);
1191 ADD_TO_DEVTABLE("x86cpu", x86_cpu_id
, do_x86cpu_entry
);
1193 /* LOOKS like cpu:type:*:feature:*FEAT* */
1194 static int do_cpu_entry(const char *filename
, void *symval
, char *alias
)
1196 DEF_FIELD(symval
, cpu_feature
, feature
);
1198 sprintf(alias
, "cpu:type:*:feature:*%04X*", feature
);
1201 ADD_TO_DEVTABLE("cpu", cpu_feature
, do_cpu_entry
);
1203 /* Looks like: mei:S:uuid */
1204 static int do_mei_entry(const char *filename
, void *symval
,
1207 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, name
);
1208 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, uuid
);
1210 sprintf(alias
, MEI_CL_MODULE_PREFIX
);
1211 sprintf(alias
+ strlen(alias
), "%s:", (*name
)[0] ? *name
: "*");
1212 add_uuid(alias
, *uuid
);
1214 strcat(alias
, ":*");
1218 ADD_TO_DEVTABLE("mei", mei_cl_device_id
, do_mei_entry
);
1220 /* Looks like: rapidio:vNdNavNadN */
1221 static int do_rio_entry(const char *filename
,
1222 void *symval
, char *alias
)
1224 DEF_FIELD(symval
, rio_device_id
, did
);
1225 DEF_FIELD(symval
, rio_device_id
, vid
);
1226 DEF_FIELD(symval
, rio_device_id
, asm_did
);
1227 DEF_FIELD(symval
, rio_device_id
, asm_vid
);
1229 strcpy(alias
, "rapidio:");
1230 ADD(alias
, "v", vid
!= RIO_ANY_ID
, vid
);
1231 ADD(alias
, "d", did
!= RIO_ANY_ID
, did
);
1232 ADD(alias
, "av", asm_vid
!= RIO_ANY_ID
, asm_vid
);
1233 ADD(alias
, "ad", asm_did
!= RIO_ANY_ID
, asm_did
);
1235 add_wildcard(alias
);
1238 ADD_TO_DEVTABLE("rapidio", rio_device_id
, do_rio_entry
);
1240 /* Looks like: ulpi:vNpN */
1241 static int do_ulpi_entry(const char *filename
, void *symval
,
1244 DEF_FIELD(symval
, ulpi_device_id
, vendor
);
1245 DEF_FIELD(symval
, ulpi_device_id
, product
);
1247 sprintf(alias
, "ulpi:v%04xp%04x", vendor
, product
);
1251 ADD_TO_DEVTABLE("ulpi", ulpi_device_id
, do_ulpi_entry
);
1253 /* Does namelen bytes of name exactly match the symbol? */
1254 static bool sym_is(const char *name
, unsigned namelen
, const char *symbol
)
1256 if (namelen
!= strlen(symbol
))
1259 return memcmp(name
, symbol
, namelen
) == 0;
1262 static void do_table(void *symval
, unsigned long size
,
1263 unsigned long id_size
,
1264 const char *device_id
,
1270 int (*do_entry
)(const char *, void *entry
, char *alias
) = function
;
1272 device_id_check(mod
->name
, device_id
, size
, id_size
, symval
);
1273 /* Leave last one: it's the terminator. */
1276 for (i
= 0; i
< size
; i
+= id_size
) {
1277 if (do_entry(mod
->name
, symval
+i
, alias
)) {
1278 buf_printf(&mod
->dev_table_buf
,
1279 "MODULE_ALIAS(\"%s\");\n", alias
);
1284 /* Create MODULE_ALIAS() statements.
1285 * At this time, we cannot write the actual output C source yet,
1286 * so we write into the mod->dev_table_buf buffer. */
1287 void handle_moddevtable(struct module
*mod
, struct elf_info
*info
,
1288 Elf_Sym
*sym
, const char *symname
)
1292 const char *name
, *identifier
;
1293 unsigned int namelen
;
1295 /* We're looking for a section relative symbol */
1296 if (!sym
->st_shndx
|| get_secindex(info
, sym
) >= info
->num_sections
)
1299 /* We're looking for an object */
1300 if (ELF_ST_TYPE(sym
->st_info
) != STT_OBJECT
)
1303 /* All our symbols are of form <prefix>__mod_<name>__<identifier>_device_table. */
1304 name
= strstr(symname
, "__mod_");
1307 name
+= strlen("__mod_");
1308 namelen
= strlen(name
);
1309 if (namelen
< strlen("_device_table"))
1311 if (strcmp(name
+ namelen
- strlen("_device_table"), "_device_table"))
1313 identifier
= strstr(name
, "__");
1316 namelen
= identifier
- name
;
1318 /* Handle all-NULL symbols allocated into .bss */
1319 if (info
->sechdrs
[get_secindex(info
, sym
)].sh_type
& SHT_NOBITS
) {
1320 zeros
= calloc(1, sym
->st_size
);
1323 symval
= (void *)info
->hdr
1324 + info
->sechdrs
[get_secindex(info
, sym
)].sh_offset
1328 /* First handle the "special" cases */
1329 if (sym_is(name
, namelen
, "usb"))
1330 do_usb_table(symval
, sym
->st_size
, mod
);
1331 else if (sym_is(name
, namelen
, "pnp"))
1332 do_pnp_device_entry(symval
, sym
->st_size
, mod
);
1333 else if (sym_is(name
, namelen
, "pnp_card"))
1334 do_pnp_card_entries(symval
, sym
->st_size
, mod
);
1336 struct devtable
**p
;
1337 INIT_SECTION(__devtable
);
1339 for (p
= __start___devtable
; p
< __stop___devtable
; p
++) {
1340 if (sym_is(name
, namelen
, (*p
)->device_id
)) {
1341 do_table(symval
, sym
->st_size
, (*p
)->id_size
,
1342 (*p
)->device_id
, (*p
)->function
, mod
);
1350 /* Now add out buffered information to the generated C source */
1351 void add_moddevtable(struct buffer
*buf
, struct module
*mod
)
1353 buf_printf(buf
, "\n");
1354 buf_write(buf
, mod
->dev_table_buf
.p
, mod
->dev_table_buf
.pos
);
1355 free(mod
->dev_table_buf
.p
);