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
;
50 int (*do_entry
)(const char *filename
, void *symval
, char *alias
);
53 /* Define a variable f that holds the value of field f of struct devid
56 #define DEF_FIELD(m, devid, f) \
57 typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
58 /* Define a variable f that holds the address of field f of struct devid
59 * based at address m. Due to the way typeof works, for a field of type
60 * T[N] the variable has type T(*)[N], _not_ T*.
62 #define DEF_FIELD_ADDR(m, devid, f) \
63 typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
65 #define ADD(str, sep, cond, field) \
69 sprintf(str + strlen(str), \
70 sizeof(field) == 1 ? "%02X" : \
71 sizeof(field) == 2 ? "%04X" : \
72 sizeof(field) == 4 ? "%08X" : "", \
75 sprintf(str + strlen(str), "*"); \
78 /* End in a wildcard, for future extension */
79 static inline void add_wildcard(char *str
)
81 int len
= strlen(str
);
83 if (str
[len
- 1] != '*')
84 strcat(str
+ len
, "*");
87 static inline void add_uuid(char *str
, uuid_le uuid
)
89 int len
= strlen(str
);
91 sprintf(str
+ len
, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
92 uuid
.b
[3], uuid
.b
[2], uuid
.b
[1], uuid
.b
[0],
93 uuid
.b
[5], uuid
.b
[4], uuid
.b
[7], uuid
.b
[6],
94 uuid
.b
[8], uuid
.b
[9], uuid
.b
[10], uuid
.b
[11],
95 uuid
.b
[12], uuid
.b
[13], uuid
.b
[14], uuid
.b
[15]);
99 * Check that sizeof(device_id type) are consistent with size of section
100 * in .o file. If in-consistent then userspace and kernel does not agree
101 * on actual size which is a bug.
102 * Also verify that the final entry in the table is all zeros.
103 * Ignore both checks if build host differ from target host and size differs.
105 static void device_id_check(const char *modname
, const char *device_id
,
106 unsigned long size
, unsigned long id_size
,
111 if (size
% id_size
|| size
< id_size
) {
112 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
114 "section __mod_%s__<identifier>_device_table=%lu.\n"
115 "Fix definition of struct %s_device_id "
116 "in mod_devicetable.h\n",
117 modname
, device_id
, id_size
, device_id
, size
, device_id
);
119 /* Verify last one is a terminator */
120 for (i
= 0; i
< id_size
; i
++ ) {
121 if (*(uint8_t*)(symval
+size
-id_size
+i
)) {
122 fprintf(stderr
,"%s: struct %s_device_id is %lu bytes. "
123 "The last of %lu is:\n",
124 modname
, device_id
, id_size
, size
/ id_size
);
125 for (i
= 0; i
< id_size
; i
++ )
126 fprintf(stderr
,"0x%02x ",
127 *(uint8_t*)(symval
+size
-id_size
+i
) );
128 fprintf(stderr
,"\n");
129 fatal("%s: struct %s_device_id is not terminated "
130 "with a NULL entry!\n", modname
, device_id
);
135 /* USB is special because the bcdDevice can be matched against a numeric range */
136 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
137 static void do_usb_entry(void *symval
,
138 unsigned int bcdDevice_initial
, int bcdDevice_initial_digits
,
139 unsigned char range_lo
, unsigned char range_hi
,
140 unsigned char max
, struct module
*mod
)
143 DEF_FIELD(symval
, usb_device_id
, match_flags
);
144 DEF_FIELD(symval
, usb_device_id
, idVendor
);
145 DEF_FIELD(symval
, usb_device_id
, idProduct
);
146 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
147 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
148 DEF_FIELD(symval
, usb_device_id
, bDeviceSubClass
);
149 DEF_FIELD(symval
, usb_device_id
, bDeviceProtocol
);
150 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
151 DEF_FIELD(symval
, usb_device_id
, bInterfaceSubClass
);
152 DEF_FIELD(symval
, usb_device_id
, bInterfaceProtocol
);
153 DEF_FIELD(symval
, usb_device_id
, bInterfaceNumber
);
155 strcpy(alias
, "usb:");
156 ADD(alias
, "v", match_flags
&USB_DEVICE_ID_MATCH_VENDOR
,
158 ADD(alias
, "p", match_flags
&USB_DEVICE_ID_MATCH_PRODUCT
,
162 if (bcdDevice_initial_digits
)
163 sprintf(alias
+ strlen(alias
), "%0*X",
164 bcdDevice_initial_digits
, bcdDevice_initial
);
165 if (range_lo
== range_hi
)
166 sprintf(alias
+ strlen(alias
), "%X", range_lo
);
167 else if (range_lo
> 0 || range_hi
< max
) {
168 if (range_lo
> 0x9 || range_hi
< 0xA)
169 sprintf(alias
+ strlen(alias
),
174 sprintf(alias
+ strlen(alias
),
175 range_lo
< 0x9 ? "[%X-9" : "[%X",
177 sprintf(alias
+ strlen(alias
),
178 range_hi
> 0xA ? "A-%X]" : "%X]",
182 if (bcdDevice_initial_digits
< (sizeof(bcdDevice_lo
) * 2 - 1))
185 ADD(alias
, "dc", match_flags
&USB_DEVICE_ID_MATCH_DEV_CLASS
,
187 ADD(alias
, "dsc", match_flags
&USB_DEVICE_ID_MATCH_DEV_SUBCLASS
,
189 ADD(alias
, "dp", match_flags
&USB_DEVICE_ID_MATCH_DEV_PROTOCOL
,
191 ADD(alias
, "ic", match_flags
&USB_DEVICE_ID_MATCH_INT_CLASS
,
193 ADD(alias
, "isc", match_flags
&USB_DEVICE_ID_MATCH_INT_SUBCLASS
,
195 ADD(alias
, "ip", match_flags
&USB_DEVICE_ID_MATCH_INT_PROTOCOL
,
197 ADD(alias
, "in", match_flags
&USB_DEVICE_ID_MATCH_INT_NUMBER
,
201 buf_printf(&mod
->dev_table_buf
,
202 "MODULE_ALIAS(\"%s\");\n", alias
);
205 /* Handles increment/decrement of BCD formatted integers */
206 /* Returns the previous value, so it works like i++ or i-- */
207 static unsigned int incbcd(unsigned int *bcd
,
212 unsigned int init
= *bcd
, i
, j
;
213 unsigned long long c
, dec
= 0;
215 /* If bcd is not in BCD format, just increment */
221 /* Convert BCD to Decimal */
222 for (i
=0 ; i
< chars
; i
++) {
223 c
= (*bcd
>> (i
<< 2)) & 0xf;
224 c
= c
> 9 ? 9 : c
; /* force to bcd just in case */
225 for (j
=0 ; j
< i
; j
++)
230 /* Do our increment/decrement */
234 /* Convert back to BCD */
235 for (i
=0 ; i
< chars
; i
++) {
236 for (c
=1,j
=0 ; j
< i
; j
++)
239 *bcd
+= c
<< (i
<< 2);
244 static void do_usb_entry_multi(void *symval
, struct module
*mod
)
246 unsigned int devlo
, devhi
;
247 unsigned char chi
, clo
, max
;
250 DEF_FIELD(symval
, usb_device_id
, match_flags
);
251 DEF_FIELD(symval
, usb_device_id
, idVendor
);
252 DEF_FIELD(symval
, usb_device_id
, idProduct
);
253 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
254 DEF_FIELD(symval
, usb_device_id
, bcdDevice_hi
);
255 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
256 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
258 devlo
= match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
?
260 devhi
= match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
?
261 bcdDevice_hi
: ~0x0U
;
263 /* Figure out if this entry is in bcd or hex format */
264 max
= 0x9; /* Default to decimal format */
265 for (ndigits
= 0 ; ndigits
< sizeof(bcdDevice_lo
) * 2 ; ndigits
++) {
266 clo
= (devlo
>> (ndigits
<< 2)) & 0xf;
267 chi
= ((devhi
> 0x9999 ? 0x9999 : devhi
) >> (ndigits
<< 2)) & 0xf;
268 if (clo
> max
|| chi
> max
) {
275 * Some modules (visor) have empty slots as placeholder for
276 * run-time specification that results in catch-all alias
278 if (!(idVendor
| idProduct
| bDeviceClass
| bInterfaceClass
))
281 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
282 for (ndigits
= sizeof(bcdDevice_lo
) * 2 - 1; devlo
<= devhi
; ndigits
--) {
285 if (chi
> max
) /* If we are in bcd mode, truncate if necessary */
290 if (devlo
== devhi
|| !ndigits
) {
291 do_usb_entry(symval
, devlo
, ndigits
, clo
, chi
, max
, mod
);
297 incbcd(&devlo
, 1, max
,
298 sizeof(bcdDevice_lo
) * 2),
299 ndigits
, clo
, max
, max
, mod
);
303 incbcd(&devhi
, -1, max
,
304 sizeof(bcdDevice_lo
) * 2),
305 ndigits
, 0x0, chi
, max
, mod
);
309 static void do_usb_table(void *symval
, unsigned long size
,
313 const unsigned long id_size
= SIZE_usb_device_id
;
315 device_id_check(mod
->name
, "usb", size
, id_size
, symval
);
317 /* Leave last one: it's the terminator. */
320 for (i
= 0; i
< size
; i
+= id_size
)
321 do_usb_entry_multi(symval
+ i
, mod
);
324 static void do_of_entry_multi(void *symval
, struct module
*mod
)
330 DEF_FIELD_ADDR(symval
, of_device_id
, name
);
331 DEF_FIELD_ADDR(symval
, of_device_id
, type
);
332 DEF_FIELD_ADDR(symval
, of_device_id
, compatible
);
334 len
= sprintf(alias
, "of:N%sT%s", (*name
)[0] ? *name
: "*",
335 (*type
)[0] ? *type
: "*");
337 if ((*compatible
)[0])
338 sprintf(&alias
[len
], "%sC%s", (*type
)[0] ? "*" : "",
341 /* Replace all whitespace with underscores */
342 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
346 buf_printf(&mod
->dev_table_buf
, "MODULE_ALIAS(\"%s\");\n", alias
);
349 buf_printf(&mod
->dev_table_buf
, "MODULE_ALIAS(\"%s\");\n", alias
);
352 static void do_of_table(void *symval
, unsigned long size
,
356 const unsigned long id_size
= SIZE_of_device_id
;
358 device_id_check(mod
->name
, "of", size
, id_size
, symval
);
360 /* Leave last one: it's the terminator. */
363 for (i
= 0; i
< size
; i
+= id_size
)
364 do_of_entry_multi(symval
+ i
, mod
);
367 /* Looks like: hid:bNvNpN */
368 static int do_hid_entry(const char *filename
,
369 void *symval
, char *alias
)
371 DEF_FIELD(symval
, hid_device_id
, bus
);
372 DEF_FIELD(symval
, hid_device_id
, group
);
373 DEF_FIELD(symval
, hid_device_id
, vendor
);
374 DEF_FIELD(symval
, hid_device_id
, product
);
376 sprintf(alias
, "hid:");
377 ADD(alias
, "b", bus
!= HID_BUS_ANY
, bus
);
378 ADD(alias
, "g", group
!= HID_GROUP_ANY
, group
);
379 ADD(alias
, "v", vendor
!= HID_ANY_ID
, vendor
);
380 ADD(alias
, "p", product
!= HID_ANY_ID
, product
);
385 /* Looks like: ieee1394:venNmoNspNverN */
386 static int do_ieee1394_entry(const char *filename
,
387 void *symval
, char *alias
)
389 DEF_FIELD(symval
, ieee1394_device_id
, match_flags
);
390 DEF_FIELD(symval
, ieee1394_device_id
, vendor_id
);
391 DEF_FIELD(symval
, ieee1394_device_id
, model_id
);
392 DEF_FIELD(symval
, ieee1394_device_id
, specifier_id
);
393 DEF_FIELD(symval
, ieee1394_device_id
, version
);
395 strcpy(alias
, "ieee1394:");
396 ADD(alias
, "ven", match_flags
& IEEE1394_MATCH_VENDOR_ID
,
398 ADD(alias
, "mo", match_flags
& IEEE1394_MATCH_MODEL_ID
,
400 ADD(alias
, "sp", match_flags
& IEEE1394_MATCH_SPECIFIER_ID
,
402 ADD(alias
, "ver", match_flags
& IEEE1394_MATCH_VERSION
,
409 /* Looks like: pci:vNdNsvNsdNbcNscNiN. */
410 static int do_pci_entry(const char *filename
,
411 void *symval
, char *alias
)
413 /* Class field can be divided into these three. */
414 unsigned char baseclass
, subclass
, interface
,
415 baseclass_mask
, subclass_mask
, interface_mask
;
417 DEF_FIELD(symval
, pci_device_id
, vendor
);
418 DEF_FIELD(symval
, pci_device_id
, device
);
419 DEF_FIELD(symval
, pci_device_id
, subvendor
);
420 DEF_FIELD(symval
, pci_device_id
, subdevice
);
421 DEF_FIELD(symval
, pci_device_id
, class);
422 DEF_FIELD(symval
, pci_device_id
, class_mask
);
424 strcpy(alias
, "pci:");
425 ADD(alias
, "v", vendor
!= PCI_ANY_ID
, vendor
);
426 ADD(alias
, "d", device
!= PCI_ANY_ID
, device
);
427 ADD(alias
, "sv", subvendor
!= PCI_ANY_ID
, subvendor
);
428 ADD(alias
, "sd", subdevice
!= PCI_ANY_ID
, subdevice
);
430 baseclass
= (class) >> 16;
431 baseclass_mask
= (class_mask
) >> 16;
432 subclass
= (class) >> 8;
433 subclass_mask
= (class_mask
) >> 8;
435 interface_mask
= class_mask
;
437 if ((baseclass_mask
!= 0 && baseclass_mask
!= 0xFF)
438 || (subclass_mask
!= 0 && subclass_mask
!= 0xFF)
439 || (interface_mask
!= 0 && interface_mask
!= 0xFF)) {
440 warn("Can't handle masks in %s:%04X\n",
441 filename
, class_mask
);
445 ADD(alias
, "bc", baseclass_mask
== 0xFF, baseclass
);
446 ADD(alias
, "sc", subclass_mask
== 0xFF, subclass
);
447 ADD(alias
, "i", interface_mask
== 0xFF, interface
);
452 /* looks like: "ccw:tNmNdtNdmN" */
453 static int do_ccw_entry(const char *filename
,
454 void *symval
, char *alias
)
456 DEF_FIELD(symval
, ccw_device_id
, match_flags
);
457 DEF_FIELD(symval
, ccw_device_id
, cu_type
);
458 DEF_FIELD(symval
, ccw_device_id
, cu_model
);
459 DEF_FIELD(symval
, ccw_device_id
, dev_type
);
460 DEF_FIELD(symval
, ccw_device_id
, dev_model
);
462 strcpy(alias
, "ccw:");
463 ADD(alias
, "t", match_flags
&CCW_DEVICE_ID_MATCH_CU_TYPE
,
465 ADD(alias
, "m", match_flags
&CCW_DEVICE_ID_MATCH_CU_MODEL
,
467 ADD(alias
, "dt", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_TYPE
,
469 ADD(alias
, "dm", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_MODEL
,
475 /* looks like: "ap:tN" */
476 static int do_ap_entry(const char *filename
,
477 void *symval
, char *alias
)
479 DEF_FIELD(symval
, ap_device_id
, dev_type
);
481 sprintf(alias
, "ap:t%02X*", dev_type
);
485 /* looks like: "css:tN" */
486 static int do_css_entry(const char *filename
,
487 void *symval
, char *alias
)
489 DEF_FIELD(symval
, css_device_id
, type
);
491 sprintf(alias
, "css:t%01X", type
);
495 /* Looks like: "serio:tyNprNidNexN" */
496 static int do_serio_entry(const char *filename
,
497 void *symval
, char *alias
)
499 DEF_FIELD(symval
, serio_device_id
, type
);
500 DEF_FIELD(symval
, serio_device_id
, proto
);
501 DEF_FIELD(symval
, serio_device_id
, id
);
502 DEF_FIELD(symval
, serio_device_id
, extra
);
504 strcpy(alias
, "serio:");
505 ADD(alias
, "ty", type
!= SERIO_ANY
, type
);
506 ADD(alias
, "pr", proto
!= SERIO_ANY
, proto
);
507 ADD(alias
, "id", id
!= SERIO_ANY
, id
);
508 ADD(alias
, "ex", extra
!= SERIO_ANY
, extra
);
514 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
515 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
517 * NOTE: Each driver should use one of the following : _HID, _CIDs
518 * or _CLS. Also, bb, ss, and pp can be substituted with ??
519 * as don't care byte.
521 static int do_acpi_entry(const char *filename
,
522 void *symval
, char *alias
)
524 DEF_FIELD_ADDR(symval
, acpi_device_id
, id
);
525 DEF_FIELD_ADDR(symval
, acpi_device_id
, cls
);
526 DEF_FIELD_ADDR(symval
, acpi_device_id
, cls_msk
);
528 if (id
&& strlen((const char *)*id
))
529 sprintf(alias
, "acpi*:%s:*", *id
);
531 int i
, byte_shift
, cnt
= 0;
534 sprintf(&alias
[cnt
], "acpi*:");
536 for (i
= 1; i
<= 3; i
++) {
537 byte_shift
= 8 * (3-i
);
538 msk
= (*cls_msk
>> byte_shift
) & 0xFF;
540 sprintf(&alias
[cnt
], "%02x",
541 (*cls
>> byte_shift
) & 0xFF);
543 sprintf(&alias
[cnt
], "??");
546 sprintf(&alias
[cnt
], ":*");
551 /* looks like: "pnp:dD" */
552 static void do_pnp_device_entry(void *symval
, unsigned long size
,
555 const unsigned long id_size
= SIZE_pnp_device_id
;
556 const unsigned int count
= (size
/ id_size
)-1;
559 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
561 for (i
= 0; i
< count
; i
++) {
562 DEF_FIELD_ADDR(symval
+ i
*id_size
, pnp_device_id
, id
);
563 char acpi_id
[sizeof(*id
)];
566 buf_printf(&mod
->dev_table_buf
,
567 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id
);
569 /* fix broken pnp bus lowercasing */
570 for (j
= 0; j
< sizeof(acpi_id
); j
++)
571 acpi_id
[j
] = toupper((*id
)[j
]);
572 buf_printf(&mod
->dev_table_buf
,
573 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
577 /* looks like: "pnp:dD" for every device of the card */
578 static void do_pnp_card_entries(void *symval
, unsigned long size
,
581 const unsigned long id_size
= SIZE_pnp_card_device_id
;
582 const unsigned int count
= (size
/ id_size
)-1;
585 device_id_check(mod
->name
, "pnp", size
, id_size
, symval
);
587 for (i
= 0; i
< count
; i
++) {
589 DEF_FIELD_ADDR(symval
+ i
*id_size
, pnp_card_device_id
, devs
);
591 for (j
= 0; j
< PNP_MAX_DEVICES
; j
++) {
592 const char *id
= (char *)(*devs
)[j
].id
;
599 /* find duplicate, already added value */
600 for (i2
= 0; i2
< i
&& !dup
; i2
++) {
601 DEF_FIELD_ADDR(symval
+ i2
*id_size
, pnp_card_device_id
, devs
);
603 for (j2
= 0; j2
< PNP_MAX_DEVICES
; j2
++) {
604 const char *id2
= (char *)(*devs
)[j2
].id
;
609 if (!strcmp(id
, id2
)) {
616 /* add an individual alias for every device entry */
618 char acpi_id
[PNP_ID_LEN
];
621 buf_printf(&mod
->dev_table_buf
,
622 "MODULE_ALIAS(\"pnp:d%s*\");\n", id
);
624 /* fix broken pnp bus lowercasing */
625 for (k
= 0; k
< sizeof(acpi_id
); k
++)
626 acpi_id
[k
] = toupper(id
[k
]);
627 buf_printf(&mod
->dev_table_buf
,
628 "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id
);
634 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
635 static int do_pcmcia_entry(const char *filename
,
636 void *symval
, char *alias
)
639 DEF_FIELD(symval
, pcmcia_device_id
, match_flags
);
640 DEF_FIELD(symval
, pcmcia_device_id
, manf_id
);
641 DEF_FIELD(symval
, pcmcia_device_id
, card_id
);
642 DEF_FIELD(symval
, pcmcia_device_id
, func_id
);
643 DEF_FIELD(symval
, pcmcia_device_id
, function
);
644 DEF_FIELD(symval
, pcmcia_device_id
, device_no
);
645 DEF_FIELD_ADDR(symval
, pcmcia_device_id
, prod_id_hash
);
647 for (i
=0; i
<4; i
++) {
648 (*prod_id_hash
)[i
] = TO_NATIVE((*prod_id_hash
)[i
]);
651 strcpy(alias
, "pcmcia:");
652 ADD(alias
, "m", match_flags
& PCMCIA_DEV_ID_MATCH_MANF_ID
,
654 ADD(alias
, "c", match_flags
& PCMCIA_DEV_ID_MATCH_CARD_ID
,
656 ADD(alias
, "f", match_flags
& PCMCIA_DEV_ID_MATCH_FUNC_ID
,
658 ADD(alias
, "fn", match_flags
& PCMCIA_DEV_ID_MATCH_FUNCTION
,
660 ADD(alias
, "pfn", match_flags
& PCMCIA_DEV_ID_MATCH_DEVICE_NO
,
662 ADD(alias
, "pa", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID1
, (*prod_id_hash
)[0]);
663 ADD(alias
, "pb", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID2
, (*prod_id_hash
)[1]);
664 ADD(alias
, "pc", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID3
, (*prod_id_hash
)[2]);
665 ADD(alias
, "pd", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID4
, (*prod_id_hash
)[3]);
671 static int do_vio_entry(const char *filename
, void *symval
,
675 DEF_FIELD_ADDR(symval
, vio_device_id
, type
);
676 DEF_FIELD_ADDR(symval
, vio_device_id
, compat
);
678 sprintf(alias
, "vio:T%sS%s", (*type
)[0] ? *type
: "*",
679 (*compat
)[0] ? *compat
: "*");
681 /* Replace all whitespace with underscores */
682 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
690 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
692 static void do_input(char *alias
,
693 kernel_ulong_t
*arr
, unsigned int min
, unsigned int max
)
697 for (i
= min
/ BITS_PER_LONG
; i
< max
/ BITS_PER_LONG
+ 1; i
++)
698 arr
[i
] = TO_NATIVE(arr
[i
]);
699 for (i
= min
; i
< max
; i
++)
700 if (arr
[i
/ BITS_PER_LONG
] & (1L << (i
%BITS_PER_LONG
)))
701 sprintf(alias
+ strlen(alias
), "%X,*", i
);
704 /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
705 static int do_input_entry(const char *filename
, void *symval
,
708 DEF_FIELD(symval
, input_device_id
, flags
);
709 DEF_FIELD(symval
, input_device_id
, bustype
);
710 DEF_FIELD(symval
, input_device_id
, vendor
);
711 DEF_FIELD(symval
, input_device_id
, product
);
712 DEF_FIELD(symval
, input_device_id
, version
);
713 DEF_FIELD_ADDR(symval
, input_device_id
, evbit
);
714 DEF_FIELD_ADDR(symval
, input_device_id
, keybit
);
715 DEF_FIELD_ADDR(symval
, input_device_id
, relbit
);
716 DEF_FIELD_ADDR(symval
, input_device_id
, absbit
);
717 DEF_FIELD_ADDR(symval
, input_device_id
, mscbit
);
718 DEF_FIELD_ADDR(symval
, input_device_id
, ledbit
);
719 DEF_FIELD_ADDR(symval
, input_device_id
, sndbit
);
720 DEF_FIELD_ADDR(symval
, input_device_id
, ffbit
);
721 DEF_FIELD_ADDR(symval
, input_device_id
, swbit
);
723 sprintf(alias
, "input:");
725 ADD(alias
, "b", flags
& INPUT_DEVICE_ID_MATCH_BUS
, bustype
);
726 ADD(alias
, "v", flags
& INPUT_DEVICE_ID_MATCH_VENDOR
, vendor
);
727 ADD(alias
, "p", flags
& INPUT_DEVICE_ID_MATCH_PRODUCT
, product
);
728 ADD(alias
, "e", flags
& INPUT_DEVICE_ID_MATCH_VERSION
, version
);
730 sprintf(alias
+ strlen(alias
), "-e*");
731 if (flags
& INPUT_DEVICE_ID_MATCH_EVBIT
)
732 do_input(alias
, *evbit
, 0, INPUT_DEVICE_ID_EV_MAX
);
733 sprintf(alias
+ strlen(alias
), "k*");
734 if (flags
& INPUT_DEVICE_ID_MATCH_KEYBIT
)
735 do_input(alias
, *keybit
,
736 INPUT_DEVICE_ID_KEY_MIN_INTERESTING
,
737 INPUT_DEVICE_ID_KEY_MAX
);
738 sprintf(alias
+ strlen(alias
), "r*");
739 if (flags
& INPUT_DEVICE_ID_MATCH_RELBIT
)
740 do_input(alias
, *relbit
, 0, INPUT_DEVICE_ID_REL_MAX
);
741 sprintf(alias
+ strlen(alias
), "a*");
742 if (flags
& INPUT_DEVICE_ID_MATCH_ABSBIT
)
743 do_input(alias
, *absbit
, 0, INPUT_DEVICE_ID_ABS_MAX
);
744 sprintf(alias
+ strlen(alias
), "m*");
745 if (flags
& INPUT_DEVICE_ID_MATCH_MSCIT
)
746 do_input(alias
, *mscbit
, 0, INPUT_DEVICE_ID_MSC_MAX
);
747 sprintf(alias
+ strlen(alias
), "l*");
748 if (flags
& INPUT_DEVICE_ID_MATCH_LEDBIT
)
749 do_input(alias
, *ledbit
, 0, INPUT_DEVICE_ID_LED_MAX
);
750 sprintf(alias
+ strlen(alias
), "s*");
751 if (flags
& INPUT_DEVICE_ID_MATCH_SNDBIT
)
752 do_input(alias
, *sndbit
, 0, INPUT_DEVICE_ID_SND_MAX
);
753 sprintf(alias
+ strlen(alias
), "f*");
754 if (flags
& INPUT_DEVICE_ID_MATCH_FFBIT
)
755 do_input(alias
, *ffbit
, 0, INPUT_DEVICE_ID_FF_MAX
);
756 sprintf(alias
+ strlen(alias
), "w*");
757 if (flags
& INPUT_DEVICE_ID_MATCH_SWBIT
)
758 do_input(alias
, *swbit
, 0, INPUT_DEVICE_ID_SW_MAX
);
762 static int do_eisa_entry(const char *filename
, void *symval
,
765 DEF_FIELD_ADDR(symval
, eisa_device_id
, sig
);
767 sprintf(alias
, EISA_DEVICE_MODALIAS_FMT
"*", *sig
);
773 /* Looks like: parisc:tNhvNrevNsvN */
774 static int do_parisc_entry(const char *filename
, void *symval
,
777 DEF_FIELD(symval
, parisc_device_id
, hw_type
);
778 DEF_FIELD(symval
, parisc_device_id
, hversion
);
779 DEF_FIELD(symval
, parisc_device_id
, hversion_rev
);
780 DEF_FIELD(symval
, parisc_device_id
, sversion
);
782 strcpy(alias
, "parisc:");
783 ADD(alias
, "t", hw_type
!= PA_HWTYPE_ANY_ID
, hw_type
);
784 ADD(alias
, "hv", hversion
!= PA_HVERSION_ANY_ID
, hversion
);
785 ADD(alias
, "rev", hversion_rev
!= PA_HVERSION_REV_ANY_ID
, hversion_rev
);
786 ADD(alias
, "sv", sversion
!= PA_SVERSION_ANY_ID
, sversion
);
792 /* Looks like: sdio:cNvNdN. */
793 static int do_sdio_entry(const char *filename
,
794 void *symval
, char *alias
)
796 DEF_FIELD(symval
, sdio_device_id
, class);
797 DEF_FIELD(symval
, sdio_device_id
, vendor
);
798 DEF_FIELD(symval
, sdio_device_id
, device
);
800 strcpy(alias
, "sdio:");
801 ADD(alias
, "c", class != (__u8
)SDIO_ANY_ID
, class);
802 ADD(alias
, "v", vendor
!= (__u16
)SDIO_ANY_ID
, vendor
);
803 ADD(alias
, "d", device
!= (__u16
)SDIO_ANY_ID
, device
);
808 /* Looks like: ssb:vNidNrevN. */
809 static int do_ssb_entry(const char *filename
,
810 void *symval
, char *alias
)
812 DEF_FIELD(symval
, ssb_device_id
, vendor
);
813 DEF_FIELD(symval
, ssb_device_id
, coreid
);
814 DEF_FIELD(symval
, ssb_device_id
, revision
);
816 strcpy(alias
, "ssb:");
817 ADD(alias
, "v", vendor
!= SSB_ANY_VENDOR
, vendor
);
818 ADD(alias
, "id", coreid
!= SSB_ANY_ID
, coreid
);
819 ADD(alias
, "rev", revision
!= SSB_ANY_REV
, revision
);
824 /* Looks like: bcma:mNidNrevNclN. */
825 static int do_bcma_entry(const char *filename
,
826 void *symval
, char *alias
)
828 DEF_FIELD(symval
, bcma_device_id
, manuf
);
829 DEF_FIELD(symval
, bcma_device_id
, id
);
830 DEF_FIELD(symval
, bcma_device_id
, rev
);
831 DEF_FIELD(symval
, bcma_device_id
, class);
833 strcpy(alias
, "bcma:");
834 ADD(alias
, "m", manuf
!= BCMA_ANY_MANUF
, manuf
);
835 ADD(alias
, "id", id
!= BCMA_ANY_ID
, id
);
836 ADD(alias
, "rev", rev
!= BCMA_ANY_REV
, rev
);
837 ADD(alias
, "cl", class != BCMA_ANY_CLASS
, class);
842 /* Looks like: virtio:dNvN */
843 static int do_virtio_entry(const char *filename
, void *symval
,
846 DEF_FIELD(symval
, virtio_device_id
, device
);
847 DEF_FIELD(symval
, virtio_device_id
, vendor
);
849 strcpy(alias
, "virtio:");
850 ADD(alias
, "d", device
!= VIRTIO_DEV_ANY_ID
, device
);
851 ADD(alias
, "v", vendor
!= VIRTIO_DEV_ANY_ID
, vendor
);
858 * Looks like: vmbus:guid
859 * Each byte of the guid will be represented by two hex characters
863 static int do_vmbus_entry(const char *filename
, void *symval
,
867 DEF_FIELD_ADDR(symval
, hv_vmbus_device_id
, guid
);
868 char guid_name
[(sizeof(*guid
) + 1) * 2];
870 for (i
= 0; i
< (sizeof(*guid
) * 2); i
+= 2)
871 sprintf(&guid_name
[i
], "%02x", TO_NATIVE((guid
->b
)[i
/2]));
873 strcpy(alias
, "vmbus:");
874 strcat(alias
, guid_name
);
879 /* Looks like: i2c:S */
880 static int do_i2c_entry(const char *filename
, void *symval
,
883 DEF_FIELD_ADDR(symval
, i2c_device_id
, name
);
884 sprintf(alias
, I2C_MODULE_PREFIX
"%s", *name
);
889 /* Looks like: spi:S */
890 static int do_spi_entry(const char *filename
, void *symval
,
893 DEF_FIELD_ADDR(symval
, spi_device_id
, name
);
894 sprintf(alias
, SPI_MODULE_PREFIX
"%s", *name
);
899 static const struct dmifield
{
903 { "bvn", DMI_BIOS_VENDOR
},
904 { "bvr", DMI_BIOS_VERSION
},
905 { "bd", DMI_BIOS_DATE
},
906 { "svn", DMI_SYS_VENDOR
},
907 { "pn", DMI_PRODUCT_NAME
},
908 { "pvr", DMI_PRODUCT_VERSION
},
909 { "rvn", DMI_BOARD_VENDOR
},
910 { "rn", DMI_BOARD_NAME
},
911 { "rvr", DMI_BOARD_VERSION
},
912 { "cvn", DMI_CHASSIS_VENDOR
},
913 { "ct", DMI_CHASSIS_TYPE
},
914 { "cvr", DMI_CHASSIS_VERSION
},
918 static void dmi_ascii_filter(char *d
, const char *s
)
920 /* Filter out characters we don't want to see in the modalias string */
922 if (*s
> ' ' && *s
< 127 && *s
!= ':')
929 static int do_dmi_entry(const char *filename
, void *symval
,
933 DEF_FIELD_ADDR(symval
, dmi_system_id
, matches
);
934 sprintf(alias
, "dmi*");
936 for (i
= 0; i
< ARRAY_SIZE(dmi_fields
); i
++) {
937 for (j
= 0; j
< 4; j
++) {
938 if ((*matches
)[j
].slot
&&
939 (*matches
)[j
].slot
== dmi_fields
[i
].field
) {
940 sprintf(alias
+ strlen(alias
), ":%s*",
941 dmi_fields
[i
].prefix
);
942 dmi_ascii_filter(alias
+ strlen(alias
),
943 (*matches
)[j
].substr
);
953 static int do_platform_entry(const char *filename
,
954 void *symval
, char *alias
)
956 DEF_FIELD_ADDR(symval
, platform_device_id
, name
);
957 sprintf(alias
, PLATFORM_MODULE_PREFIX
"%s", *name
);
961 static int do_mdio_entry(const char *filename
,
962 void *symval
, char *alias
)
965 DEF_FIELD(symval
, mdio_device_id
, phy_id
);
966 DEF_FIELD(symval
, mdio_device_id
, phy_id_mask
);
968 alias
+= sprintf(alias
, MDIO_MODULE_PREFIX
);
970 for (i
= 0; i
< 32; i
++) {
971 if (!((phy_id_mask
>> (31-i
)) & 1))
973 else if ((phy_id
>> (31-i
)) & 1)
979 /* Terminate the string */
985 /* Looks like: zorro:iN. */
986 static int do_zorro_entry(const char *filename
, void *symval
,
989 DEF_FIELD(symval
, zorro_device_id
, id
);
990 strcpy(alias
, "zorro:");
991 ADD(alias
, "i", id
!= ZORRO_WILDCARD
, id
);
995 /* looks like: "pnp:dD" */
996 static int do_isapnp_entry(const char *filename
,
997 void *symval
, char *alias
)
999 DEF_FIELD(symval
, isapnp_device_id
, vendor
);
1000 DEF_FIELD(symval
, isapnp_device_id
, function
);
1001 sprintf(alias
, "pnp:d%c%c%c%x%x%x%x*",
1002 'A' + ((vendor
>> 2) & 0x3f) - 1,
1003 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
1004 'A' + ((vendor
>> 8) & 0x1f) - 1,
1005 (function
>> 4) & 0x0f, function
& 0x0f,
1006 (function
>> 12) & 0x0f, (function
>> 8) & 0x0f);
1010 /* Looks like: "ipack:fNvNdN". */
1011 static int do_ipack_entry(const char *filename
,
1012 void *symval
, char *alias
)
1014 DEF_FIELD(symval
, ipack_device_id
, format
);
1015 DEF_FIELD(symval
, ipack_device_id
, vendor
);
1016 DEF_FIELD(symval
, ipack_device_id
, device
);
1017 strcpy(alias
, "ipack:");
1018 ADD(alias
, "f", format
!= IPACK_ANY_FORMAT
, format
);
1019 ADD(alias
, "v", vendor
!= IPACK_ANY_ID
, vendor
);
1020 ADD(alias
, "d", device
!= IPACK_ANY_ID
, device
);
1021 add_wildcard(alias
);
1026 * Append a match expression for a single masked hex digit.
1027 * outp points to a pointer to the character at which to append.
1028 * *outp is updated on return to point just after the appended text,
1029 * to facilitate further appending.
1031 static void append_nibble_mask(char **outp
,
1032 unsigned int nibble
, unsigned int mask
)
1043 p
+= sprintf(p
, "%X", nibble
);
1048 * Dumbly emit a match pattern for all possible matching
1049 * digits. This could be improved in some cases using ranges,
1050 * but it has the advantage of being trivially correct, and is
1054 for (i
= 0; i
< 0x10; i
++)
1055 if ((i
& mask
) == nibble
)
1056 p
+= sprintf(p
, "%X", i
);
1060 /* Ensure that the string remains NUL-terminated: */
1063 /* Advance the caller's end-of-string pointer: */
1068 * looks like: "amba:dN"
1070 * N is exactly 8 digits, where each is an upper-case hex digit, or
1071 * a ? or [] pattern matching exactly one digit.
1073 static int do_amba_entry(const char *filename
,
1074 void *symval
, char *alias
)
1078 DEF_FIELD(symval
, amba_id
, id
);
1079 DEF_FIELD(symval
, amba_id
, mask
);
1081 if ((id
& mask
) != id
)
1082 fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: "
1083 "id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1084 filename
, id
, mask
);
1086 p
+= sprintf(alias
, "amba:d");
1087 for (digit
= 0; digit
< 8; digit
++)
1088 append_nibble_mask(&p
,
1089 (id
>> (4 * (7 - digit
))) & 0xf,
1090 (mask
>> (4 * (7 - digit
))) & 0xf);
1096 * looks like: "mipscdmm:tN"
1098 * N is exactly 2 digits, where each is an upper-case hex digit, or
1099 * a ? or [] pattern matching exactly one digit.
1101 static int do_mips_cdmm_entry(const char *filename
,
1102 void *symval
, char *alias
)
1104 DEF_FIELD(symval
, mips_cdmm_device_id
, type
);
1106 sprintf(alias
, "mipscdmm:t%02X*", type
);
1110 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
1111 * All fields are numbers. It would be nicer to use strings for vendor
1112 * and feature, but getting those out of the build system here is too
1116 static int do_x86cpu_entry(const char *filename
, void *symval
,
1119 DEF_FIELD(symval
, x86_cpu_id
, feature
);
1120 DEF_FIELD(symval
, x86_cpu_id
, family
);
1121 DEF_FIELD(symval
, x86_cpu_id
, model
);
1122 DEF_FIELD(symval
, x86_cpu_id
, vendor
);
1124 strcpy(alias
, "cpu:type:x86,");
1125 ADD(alias
, "ven", vendor
!= X86_VENDOR_ANY
, vendor
);
1126 ADD(alias
, "fam", family
!= X86_FAMILY_ANY
, family
);
1127 ADD(alias
, "mod", model
!= X86_MODEL_ANY
, model
);
1128 strcat(alias
, ":feature:*");
1129 if (feature
!= X86_FEATURE_ANY
)
1130 sprintf(alias
+ strlen(alias
), "%04X*", feature
);
1134 /* LOOKS like cpu:type:*:feature:*FEAT* */
1135 static int do_cpu_entry(const char *filename
, void *symval
, char *alias
)
1137 DEF_FIELD(symval
, cpu_feature
, feature
);
1139 sprintf(alias
, "cpu:type:*:feature:*%04X*", feature
);
1143 /* Looks like: mei:S:uuid:N:* */
1144 static int do_mei_entry(const char *filename
, void *symval
,
1147 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, name
);
1148 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, uuid
);
1149 DEF_FIELD(symval
, mei_cl_device_id
, version
);
1151 sprintf(alias
, MEI_CL_MODULE_PREFIX
);
1152 sprintf(alias
+ strlen(alias
), "%s:", (*name
)[0] ? *name
: "*");
1153 add_uuid(alias
, *uuid
);
1154 ADD(alias
, ":", version
!= MEI_CL_VERSION_ANY
, version
);
1156 strcat(alias
, ":*");
1161 /* Looks like: rapidio:vNdNavNadN */
1162 static int do_rio_entry(const char *filename
,
1163 void *symval
, char *alias
)
1165 DEF_FIELD(symval
, rio_device_id
, did
);
1166 DEF_FIELD(symval
, rio_device_id
, vid
);
1167 DEF_FIELD(symval
, rio_device_id
, asm_did
);
1168 DEF_FIELD(symval
, rio_device_id
, asm_vid
);
1170 strcpy(alias
, "rapidio:");
1171 ADD(alias
, "v", vid
!= RIO_ANY_ID
, vid
);
1172 ADD(alias
, "d", did
!= RIO_ANY_ID
, did
);
1173 ADD(alias
, "av", asm_vid
!= RIO_ANY_ID
, asm_vid
);
1174 ADD(alias
, "ad", asm_did
!= RIO_ANY_ID
, asm_did
);
1176 add_wildcard(alias
);
1180 /* Looks like: ulpi:vNpN */
1181 static int do_ulpi_entry(const char *filename
, void *symval
,
1184 DEF_FIELD(symval
, ulpi_device_id
, vendor
);
1185 DEF_FIELD(symval
, ulpi_device_id
, product
);
1187 sprintf(alias
, "ulpi:v%04xp%04x", vendor
, product
);
1192 /* Looks like: hdaudio:vNrNaN */
1193 static int do_hda_entry(const char *filename
, void *symval
, char *alias
)
1195 DEF_FIELD(symval
, hda_device_id
, vendor_id
);
1196 DEF_FIELD(symval
, hda_device_id
, rev_id
);
1197 DEF_FIELD(symval
, hda_device_id
, api_version
);
1199 strcpy(alias
, "hdaudio:");
1200 ADD(alias
, "v", vendor_id
!= 0, vendor_id
);
1201 ADD(alias
, "r", rev_id
!= 0, rev_id
);
1202 ADD(alias
, "a", api_version
!= 0, api_version
);
1204 add_wildcard(alias
);
1208 /* Looks like: fsl-mc:vNdN */
1209 static int do_fsl_mc_entry(const char *filename
, void *symval
,
1212 DEF_FIELD(symval
, fsl_mc_device_id
, vendor
);
1213 DEF_FIELD_ADDR(symval
, fsl_mc_device_id
, obj_type
);
1215 sprintf(alias
, "fsl-mc:v%08Xd%s", vendor
, *obj_type
);
1219 /* Does namelen bytes of name exactly match the symbol? */
1220 static bool sym_is(const char *name
, unsigned namelen
, const char *symbol
)
1222 if (namelen
!= strlen(symbol
))
1225 return memcmp(name
, symbol
, namelen
) == 0;
1228 static void do_table(void *symval
, unsigned long size
,
1229 unsigned long id_size
,
1230 const char *device_id
,
1231 int (*do_entry
)(const char *filename
, void *symval
, char *alias
),
1237 device_id_check(mod
->name
, device_id
, size
, id_size
, symval
);
1238 /* Leave last one: it's the terminator. */
1241 for (i
= 0; i
< size
; i
+= id_size
) {
1242 if (do_entry(mod
->name
, symval
+i
, alias
)) {
1243 buf_printf(&mod
->dev_table_buf
,
1244 "MODULE_ALIAS(\"%s\");\n", alias
);
1249 static const struct devtable devtable
[] = {
1250 {"hid", SIZE_hid_device_id
, do_hid_entry
},
1251 {"ieee1394", SIZE_ieee1394_device_id
, do_ieee1394_entry
},
1252 {"pci", SIZE_pci_device_id
, do_pci_entry
},
1253 {"ccw", SIZE_ccw_device_id
, do_ccw_entry
},
1254 {"ap", SIZE_ap_device_id
, do_ap_entry
},
1255 {"css", SIZE_css_device_id
, do_css_entry
},
1256 {"serio", SIZE_serio_device_id
, do_serio_entry
},
1257 {"acpi", SIZE_acpi_device_id
, do_acpi_entry
},
1258 {"pcmcia", SIZE_pcmcia_device_id
, do_pcmcia_entry
},
1259 {"vio", SIZE_vio_device_id
, do_vio_entry
},
1260 {"input", SIZE_input_device_id
, do_input_entry
},
1261 {"eisa", SIZE_eisa_device_id
, do_eisa_entry
},
1262 {"parisc", SIZE_parisc_device_id
, do_parisc_entry
},
1263 {"sdio", SIZE_sdio_device_id
, do_sdio_entry
},
1264 {"ssb", SIZE_ssb_device_id
, do_ssb_entry
},
1265 {"bcma", SIZE_bcma_device_id
, do_bcma_entry
},
1266 {"virtio", SIZE_virtio_device_id
, do_virtio_entry
},
1267 {"vmbus", SIZE_hv_vmbus_device_id
, do_vmbus_entry
},
1268 {"i2c", SIZE_i2c_device_id
, do_i2c_entry
},
1269 {"spi", SIZE_spi_device_id
, do_spi_entry
},
1270 {"dmi", SIZE_dmi_system_id
, do_dmi_entry
},
1271 {"platform", SIZE_platform_device_id
, do_platform_entry
},
1272 {"mdio", SIZE_mdio_device_id
, do_mdio_entry
},
1273 {"zorro", SIZE_zorro_device_id
, do_zorro_entry
},
1274 {"isapnp", SIZE_isapnp_device_id
, do_isapnp_entry
},
1275 {"ipack", SIZE_ipack_device_id
, do_ipack_entry
},
1276 {"amba", SIZE_amba_id
, do_amba_entry
},
1277 {"mipscdmm", SIZE_mips_cdmm_device_id
, do_mips_cdmm_entry
},
1278 {"x86cpu", SIZE_x86_cpu_id
, do_x86cpu_entry
},
1279 {"cpu", SIZE_cpu_feature
, do_cpu_entry
},
1280 {"mei", SIZE_mei_cl_device_id
, do_mei_entry
},
1281 {"rapidio", SIZE_rio_device_id
, do_rio_entry
},
1282 {"ulpi", SIZE_ulpi_device_id
, do_ulpi_entry
},
1283 {"hdaudio", SIZE_hda_device_id
, do_hda_entry
},
1284 {"fslmc", SIZE_fsl_mc_device_id
, do_fsl_mc_entry
},
1287 /* Create MODULE_ALIAS() statements.
1288 * At this time, we cannot write the actual output C source yet,
1289 * so we write into the mod->dev_table_buf buffer. */
1290 void handle_moddevtable(struct module
*mod
, struct elf_info
*info
,
1291 Elf_Sym
*sym
, const char *symname
)
1295 const char *name
, *identifier
;
1296 unsigned int namelen
;
1298 /* We're looking for a section relative symbol */
1299 if (!sym
->st_shndx
|| get_secindex(info
, sym
) >= info
->num_sections
)
1302 /* We're looking for an object */
1303 if (ELF_ST_TYPE(sym
->st_info
) != STT_OBJECT
)
1306 /* All our symbols are of form <prefix>__mod_<name>__<identifier>_device_table. */
1307 name
= strstr(symname
, "__mod_");
1310 name
+= strlen("__mod_");
1311 namelen
= strlen(name
);
1312 if (namelen
< strlen("_device_table"))
1314 if (strcmp(name
+ namelen
- strlen("_device_table"), "_device_table"))
1316 identifier
= strstr(name
, "__");
1319 namelen
= identifier
- name
;
1321 /* Handle all-NULL symbols allocated into .bss */
1322 if (info
->sechdrs
[get_secindex(info
, sym
)].sh_type
& SHT_NOBITS
) {
1323 zeros
= calloc(1, sym
->st_size
);
1326 symval
= (void *)info
->hdr
1327 + info
->sechdrs
[get_secindex(info
, sym
)].sh_offset
1331 /* First handle the "special" cases */
1332 if (sym_is(name
, namelen
, "usb"))
1333 do_usb_table(symval
, sym
->st_size
, mod
);
1334 if (sym_is(name
, namelen
, "of"))
1335 do_of_table(symval
, sym
->st_size
, mod
);
1336 else if (sym_is(name
, namelen
, "pnp"))
1337 do_pnp_device_entry(symval
, sym
->st_size
, mod
);
1338 else if (sym_is(name
, namelen
, "pnp_card"))
1339 do_pnp_card_entries(symval
, sym
->st_size
, mod
);
1343 for (i
= 0; i
< ARRAY_SIZE(devtable
); i
++) {
1344 const struct devtable
*p
= &devtable
[i
];
1346 if (sym_is(name
, namelen
, p
->device_id
)) {
1347 do_table(symval
, sym
->st_size
, p
->id_size
,
1348 p
->device_id
, p
->do_entry
, mod
);
1356 /* Now add out buffered information to the generated C source */
1357 void add_moddevtable(struct buffer
*buf
, struct module
*mod
)
1359 buf_printf(buf
, "\n");
1360 buf_write(buf
, mod
->dev_table_buf
.p
, mod
->dev_table_buf
.pos
);
1361 free(mod
->dev_table_buf
.p
);