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.
20 #include "devicetable-offsets.h"
22 /* We use the ELF typedefs for kernel_ulong_t but bite the bullet and
23 * use either stdint.h or inttypes.h for the rest. */
24 #if KERNEL_ELFCLASS == ELFCLASS32
25 typedef Elf32_Addr kernel_ulong_t
;
26 #define BITS_PER_LONG 32
28 typedef Elf64_Addr kernel_ulong_t
;
29 #define BITS_PER_LONG 64
41 * module_alias_printf - add auto-generated MODULE_ALIAS()
44 * @append_wildcard: append '*' for future extension if not exist yet
45 * @fmt: printf(3)-like format
47 static void __attribute__((format (printf
, 3, 4)))
48 module_alias_printf(struct module
*mod
, bool append_wildcard
,
51 struct module_alias
*new, *als
;
56 /* Determine required size. */
58 n
= vsnprintf(NULL
, 0, fmt
, ap
);
62 error("vsnprintf failed\n");
66 len
= n
+ 1; /* extra byte for '\0' */
69 len
++; /* extra byte for '*' */
71 new = xmalloc(sizeof(*new) + len
);
73 /* Now, really print it to the allocated buffer */
75 n
= vsnprintf(new->str
, len
, fmt
, ap
);
79 error("vsnprintf failed\n");
84 if (append_wildcard
&& (n
== 0 || new->str
[n
- 1] != '*')) {
86 new->str
[n
+ 1] = '\0';
89 /* avoid duplication */
90 list_for_each_entry(als
, &mod
->aliases
, node
) {
91 if (!strcmp(als
->str
, new->str
)) {
97 list_add_tail(&new->node
, &mod
->aliases
);
100 typedef uint32_t __u32
;
101 typedef uint16_t __u16
;
102 typedef unsigned char __u8
;
104 /* UUID types for backward compatibility, don't use in new code */
113 #define UUID_STRING_LEN 36
115 /* MEI UUID type, don't use anywhere else */
120 /* Big exception to the "don't include kernel headers into userspace, which
121 * even potentially has different endianness and word sizes, since
122 * we handle those differences explicitly below */
123 #include "../../include/linux/mod_devicetable.h"
126 const char *device_id
;
127 unsigned long id_size
;
128 void (*do_entry
)(struct module
*mod
, void *symval
);
131 /* Define a variable f that holds the value of field f of struct devid
132 * based at address m.
134 #define DEF_FIELD(m, devid, f) \
135 typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f))
137 /* Define a variable f that holds the address of field f of struct devid
138 * based at address m. Due to the way typeof works, for a field of type
139 * T[N] the variable has type T(*)[N], _not_ T*.
141 #define DEF_FIELD_ADDR(m, devid, f) \
142 typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
144 #define ADD(str, sep, cond, field) \
148 sprintf(str + strlen(str), \
149 sizeof(field) == 1 ? "%02X" : \
150 sizeof(field) == 2 ? "%04X" : \
151 sizeof(field) == 4 ? "%08X" : "", \
154 sprintf(str + strlen(str), "*"); \
157 static inline void add_uuid(char *str
, uuid_le uuid
)
159 int len
= strlen(str
);
161 sprintf(str
+ len
, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
162 uuid
.b
[3], uuid
.b
[2], uuid
.b
[1], uuid
.b
[0],
163 uuid
.b
[5], uuid
.b
[4], uuid
.b
[7], uuid
.b
[6],
164 uuid
.b
[8], uuid
.b
[9], uuid
.b
[10], uuid
.b
[11],
165 uuid
.b
[12], uuid
.b
[13], uuid
.b
[14], uuid
.b
[15]);
168 static inline void add_guid(char *str
, guid_t guid
)
170 int len
= strlen(str
);
172 sprintf(str
+ len
, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
173 guid
.b
[3], guid
.b
[2], guid
.b
[1], guid
.b
[0],
174 guid
.b
[5], guid
.b
[4], guid
.b
[7], guid
.b
[6],
175 guid
.b
[8], guid
.b
[9], guid
.b
[10], guid
.b
[11],
176 guid
.b
[12], guid
.b
[13], guid
.b
[14], guid
.b
[15]);
179 /* USB is special because the bcdDevice can be matched against a numeric range */
180 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
181 static void do_usb_entry(void *symval
,
182 unsigned int bcdDevice_initial
, int bcdDevice_initial_digits
,
183 unsigned char range_lo
, unsigned char range_hi
,
184 unsigned char max
, struct module
*mod
)
187 DEF_FIELD(symval
, usb_device_id
, match_flags
);
188 DEF_FIELD(symval
, usb_device_id
, idVendor
);
189 DEF_FIELD(symval
, usb_device_id
, idProduct
);
190 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
191 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
192 DEF_FIELD(symval
, usb_device_id
, bDeviceSubClass
);
193 DEF_FIELD(symval
, usb_device_id
, bDeviceProtocol
);
194 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
195 DEF_FIELD(symval
, usb_device_id
, bInterfaceSubClass
);
196 DEF_FIELD(symval
, usb_device_id
, bInterfaceProtocol
);
197 DEF_FIELD(symval
, usb_device_id
, bInterfaceNumber
);
199 strcpy(alias
, "usb:");
200 ADD(alias
, "v", match_flags
&USB_DEVICE_ID_MATCH_VENDOR
,
202 ADD(alias
, "p", match_flags
&USB_DEVICE_ID_MATCH_PRODUCT
,
206 if (bcdDevice_initial_digits
)
207 sprintf(alias
+ strlen(alias
), "%0*X",
208 bcdDevice_initial_digits
, bcdDevice_initial
);
209 if (range_lo
== range_hi
)
210 sprintf(alias
+ strlen(alias
), "%X", range_lo
);
211 else if (range_lo
> 0 || range_hi
< max
) {
212 if (range_lo
> 0x9 || range_hi
< 0xA)
213 sprintf(alias
+ strlen(alias
),
218 sprintf(alias
+ strlen(alias
),
219 range_lo
< 0x9 ? "[%X-9" : "[%X",
221 sprintf(alias
+ strlen(alias
),
222 range_hi
> 0xA ? "A-%X]" : "%X]",
226 if (bcdDevice_initial_digits
< (sizeof(bcdDevice_lo
) * 2 - 1))
229 ADD(alias
, "dc", match_flags
&USB_DEVICE_ID_MATCH_DEV_CLASS
,
231 ADD(alias
, "dsc", match_flags
&USB_DEVICE_ID_MATCH_DEV_SUBCLASS
,
233 ADD(alias
, "dp", match_flags
&USB_DEVICE_ID_MATCH_DEV_PROTOCOL
,
235 ADD(alias
, "ic", match_flags
&USB_DEVICE_ID_MATCH_INT_CLASS
,
237 ADD(alias
, "isc", match_flags
&USB_DEVICE_ID_MATCH_INT_SUBCLASS
,
239 ADD(alias
, "ip", match_flags
&USB_DEVICE_ID_MATCH_INT_PROTOCOL
,
241 ADD(alias
, "in", match_flags
&USB_DEVICE_ID_MATCH_INT_NUMBER
,
244 module_alias_printf(mod
, true, "%s", alias
);
247 /* Handles increment/decrement of BCD formatted integers */
248 /* Returns the previous value, so it works like i++ or i-- */
249 static unsigned int incbcd(unsigned int *bcd
,
254 unsigned int init
= *bcd
, i
, j
;
255 unsigned long long c
, dec
= 0;
257 /* If bcd is not in BCD format, just increment */
263 /* Convert BCD to Decimal */
264 for (i
=0 ; i
< chars
; i
++) {
265 c
= (*bcd
>> (i
<< 2)) & 0xf;
266 c
= c
> 9 ? 9 : c
; /* force to bcd just in case */
267 for (j
=0 ; j
< i
; j
++)
272 /* Do our increment/decrement */
276 /* Convert back to BCD */
277 for (i
=0 ; i
< chars
; i
++) {
278 for (c
=1,j
=0 ; j
< i
; j
++)
281 *bcd
+= c
<< (i
<< 2);
286 static void do_usb_entry_multi(struct module
*mod
, void *symval
)
288 unsigned int devlo
, devhi
;
289 unsigned char chi
, clo
, max
;
292 DEF_FIELD(symval
, usb_device_id
, match_flags
);
293 DEF_FIELD(symval
, usb_device_id
, idVendor
);
294 DEF_FIELD(symval
, usb_device_id
, idProduct
);
295 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
296 DEF_FIELD(symval
, usb_device_id
, bcdDevice_hi
);
297 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
298 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
300 devlo
= match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
?
302 devhi
= match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
?
303 bcdDevice_hi
: ~0x0U
;
305 /* Figure out if this entry is in bcd or hex format */
306 max
= 0x9; /* Default to decimal format */
307 for (ndigits
= 0 ; ndigits
< sizeof(bcdDevice_lo
) * 2 ; ndigits
++) {
308 clo
= (devlo
>> (ndigits
<< 2)) & 0xf;
309 chi
= ((devhi
> 0x9999 ? 0x9999 : devhi
) >> (ndigits
<< 2)) & 0xf;
310 if (clo
> max
|| chi
> max
) {
317 * Some modules (visor) have empty slots as placeholder for
318 * run-time specification that results in catch-all alias
320 if (!(idVendor
| idProduct
| bDeviceClass
| bInterfaceClass
))
323 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
324 for (ndigits
= sizeof(bcdDevice_lo
) * 2 - 1; devlo
<= devhi
; ndigits
--) {
327 if (chi
> max
) /* If we are in bcd mode, truncate if necessary */
332 if (devlo
== devhi
|| !ndigits
) {
333 do_usb_entry(symval
, devlo
, ndigits
, clo
, chi
, max
, mod
);
339 incbcd(&devlo
, 1, max
,
340 sizeof(bcdDevice_lo
) * 2),
341 ndigits
, clo
, max
, max
, mod
);
345 incbcd(&devhi
, -1, max
,
346 sizeof(bcdDevice_lo
) * 2),
347 ndigits
, 0x0, chi
, max
, mod
);
351 static void do_of_entry(struct module
*mod
, void *symval
)
357 DEF_FIELD_ADDR(symval
, of_device_id
, name
);
358 DEF_FIELD_ADDR(symval
, of_device_id
, type
);
359 DEF_FIELD_ADDR(symval
, of_device_id
, compatible
);
361 len
= sprintf(alias
, "of:N%sT%s", (*name
)[0] ? *name
: "*",
362 (*type
)[0] ? *type
: "*");
364 if ((*compatible
)[0])
365 sprintf(&alias
[len
], "%sC%s", (*type
)[0] ? "*" : "",
368 /* Replace all whitespace with underscores */
369 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
373 module_alias_printf(mod
, false, "%s", alias
);
374 module_alias_printf(mod
, false, "%sC*", alias
);
377 /* Looks like: hid:bNvNpN */
378 static void do_hid_entry(struct module
*mod
, void *symval
)
380 char alias
[256] = {};
382 DEF_FIELD(symval
, hid_device_id
, bus
);
383 DEF_FIELD(symval
, hid_device_id
, group
);
384 DEF_FIELD(symval
, hid_device_id
, vendor
);
385 DEF_FIELD(symval
, hid_device_id
, product
);
387 ADD(alias
, "b", bus
!= HID_BUS_ANY
, bus
);
388 ADD(alias
, "g", group
!= HID_GROUP_ANY
, group
);
389 ADD(alias
, "v", vendor
!= HID_ANY_ID
, vendor
);
390 ADD(alias
, "p", product
!= HID_ANY_ID
, product
);
392 module_alias_printf(mod
, false, "hid:%s", alias
);
395 /* Looks like: ieee1394:venNmoNspNverN */
396 static void do_ieee1394_entry(struct module
*mod
, void *symval
)
398 char alias
[256] = {};
400 DEF_FIELD(symval
, ieee1394_device_id
, match_flags
);
401 DEF_FIELD(symval
, ieee1394_device_id
, vendor_id
);
402 DEF_FIELD(symval
, ieee1394_device_id
, model_id
);
403 DEF_FIELD(symval
, ieee1394_device_id
, specifier_id
);
404 DEF_FIELD(symval
, ieee1394_device_id
, version
);
406 ADD(alias
, "ven", match_flags
& IEEE1394_MATCH_VENDOR_ID
,
408 ADD(alias
, "mo", match_flags
& IEEE1394_MATCH_MODEL_ID
,
410 ADD(alias
, "sp", match_flags
& IEEE1394_MATCH_SPECIFIER_ID
,
412 ADD(alias
, "ver", match_flags
& IEEE1394_MATCH_VERSION
,
415 module_alias_printf(mod
, true, "ieee1394:%s", alias
);
418 /* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */
419 static void do_pci_entry(struct module
*mod
, void *symval
)
422 /* Class field can be divided into these three. */
423 unsigned char baseclass
, subclass
, interface
,
424 baseclass_mask
, subclass_mask
, interface_mask
;
426 DEF_FIELD(symval
, pci_device_id
, vendor
);
427 DEF_FIELD(symval
, pci_device_id
, device
);
428 DEF_FIELD(symval
, pci_device_id
, subvendor
);
429 DEF_FIELD(symval
, pci_device_id
, subdevice
);
430 DEF_FIELD(symval
, pci_device_id
, class);
431 DEF_FIELD(symval
, pci_device_id
, class_mask
);
432 DEF_FIELD(symval
, pci_device_id
, override_only
);
434 switch (override_only
) {
436 strcpy(alias
, "pci:");
438 case PCI_ID_F_VFIO_DRIVER_OVERRIDE
:
439 strcpy(alias
, "vfio_pci:");
442 warn("Unknown PCI driver_override alias %08X\n",
446 ADD(alias
, "v", vendor
!= PCI_ANY_ID
, vendor
);
447 ADD(alias
, "d", device
!= PCI_ANY_ID
, device
);
448 ADD(alias
, "sv", subvendor
!= PCI_ANY_ID
, subvendor
);
449 ADD(alias
, "sd", subdevice
!= PCI_ANY_ID
, subdevice
);
451 baseclass
= (class) >> 16;
452 baseclass_mask
= (class_mask
) >> 16;
453 subclass
= (class) >> 8;
454 subclass_mask
= (class_mask
) >> 8;
456 interface_mask
= class_mask
;
458 if ((baseclass_mask
!= 0 && baseclass_mask
!= 0xFF)
459 || (subclass_mask
!= 0 && subclass_mask
!= 0xFF)
460 || (interface_mask
!= 0 && interface_mask
!= 0xFF)) {
461 warn("Can't handle masks in %s:%04X\n",
462 mod
->name
, class_mask
);
466 ADD(alias
, "bc", baseclass_mask
== 0xFF, baseclass
);
467 ADD(alias
, "sc", subclass_mask
== 0xFF, subclass
);
468 ADD(alias
, "i", interface_mask
== 0xFF, interface
);
470 module_alias_printf(mod
, true, "%s", alias
);
473 /* looks like: "ccw:tNmNdtNdmN" */
474 static void do_ccw_entry(struct module
*mod
, void *symval
)
476 char alias
[256] = {};
478 DEF_FIELD(symval
, ccw_device_id
, match_flags
);
479 DEF_FIELD(symval
, ccw_device_id
, cu_type
);
480 DEF_FIELD(symval
, ccw_device_id
, cu_model
);
481 DEF_FIELD(symval
, ccw_device_id
, dev_type
);
482 DEF_FIELD(symval
, ccw_device_id
, dev_model
);
484 ADD(alias
, "t", match_flags
&CCW_DEVICE_ID_MATCH_CU_TYPE
,
486 ADD(alias
, "m", match_flags
&CCW_DEVICE_ID_MATCH_CU_MODEL
,
488 ADD(alias
, "dt", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_TYPE
,
490 ADD(alias
, "dm", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_MODEL
,
493 module_alias_printf(mod
, true, "ccw:%s", alias
);
496 /* looks like: "ap:tN" */
497 static void do_ap_entry(struct module
*mod
, void *symval
)
499 DEF_FIELD(symval
, ap_device_id
, dev_type
);
501 module_alias_printf(mod
, false, "ap:t%02X*", dev_type
);
504 /* looks like: "css:tN" */
505 static void do_css_entry(struct module
*mod
, void *symval
)
507 DEF_FIELD(symval
, css_device_id
, type
);
509 module_alias_printf(mod
, false, "css:t%01X", type
);
512 /* Looks like: "serio:tyNprNidNexN" */
513 static void do_serio_entry(struct module
*mod
, void *symval
)
515 char alias
[256] = {};
517 DEF_FIELD(symval
, serio_device_id
, type
);
518 DEF_FIELD(symval
, serio_device_id
, proto
);
519 DEF_FIELD(symval
, serio_device_id
, id
);
520 DEF_FIELD(symval
, serio_device_id
, extra
);
522 ADD(alias
, "ty", type
!= SERIO_ANY
, type
);
523 ADD(alias
, "pr", proto
!= SERIO_ANY
, proto
);
524 ADD(alias
, "id", id
!= SERIO_ANY
, id
);
525 ADD(alias
, "ex", extra
!= SERIO_ANY
, extra
);
527 module_alias_printf(mod
, true, "serio:%s", alias
);
530 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
531 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
533 * NOTE: Each driver should use one of the following : _HID, _CIDs
534 * or _CLS. Also, bb, ss, and pp can be substituted with ??
535 * as don't care byte.
537 static void do_acpi_entry(struct module
*mod
, void *symval
)
539 DEF_FIELD_ADDR(symval
, acpi_device_id
, id
);
540 DEF_FIELD(symval
, acpi_device_id
, cls
);
541 DEF_FIELD(symval
, acpi_device_id
, cls_msk
);
544 module_alias_printf(mod
, false, "acpi*:%s:*", *id
);
547 int i
, byte_shift
, cnt
= 0;
550 for (i
= 1; i
<= 3; i
++) {
551 byte_shift
= 8 * (3-i
);
552 msk
= (cls_msk
>> byte_shift
) & 0xFF;
554 sprintf(&alias
[cnt
], "%02x",
555 (cls
>> byte_shift
) & 0xFF);
557 sprintf(&alias
[cnt
], "??");
560 module_alias_printf(mod
, false, "acpi*:%s:*", alias
);
564 /* looks like: "pnp:dD" */
565 static void do_pnp_device_entry(struct module
*mod
, void *symval
)
567 DEF_FIELD_ADDR(symval
, pnp_device_id
, id
);
568 char acpi_id
[sizeof(*id
)];
570 /* fix broken pnp bus lowercasing */
571 for (unsigned int i
= 0; i
< sizeof(acpi_id
); i
++)
572 acpi_id
[i
] = toupper((*id
)[i
]);
573 module_alias_printf(mod
, false, "pnp:d%s*", *id
);
574 module_alias_printf(mod
, false, "acpi*:%s:*", acpi_id
);
577 /* looks like: "pnp:dD" for every device of the card */
578 static void do_pnp_card_entry(struct module
*mod
, void *symval
)
580 DEF_FIELD_ADDR(symval
, pnp_card_device_id
, devs
);
582 for (unsigned int i
= 0; i
< PNP_MAX_DEVICES
; i
++) {
583 const char *id
= (char *)(*devs
)[i
].id
;
584 char acpi_id
[PNP_ID_LEN
];
589 /* fix broken pnp bus lowercasing */
590 for (unsigned int j
= 0; j
< sizeof(acpi_id
); j
++)
591 acpi_id
[j
] = toupper(id
[j
]);
593 /* add an individual alias for every device entry */
594 module_alias_printf(mod
, false, "pnp:d%s*", id
);
595 module_alias_printf(mod
, false, "acpi*:%s:*", acpi_id
);
599 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
600 static void do_pcmcia_entry(struct module
*mod
, void *symval
)
602 char alias
[256] = {};
604 DEF_FIELD(symval
, pcmcia_device_id
, match_flags
);
605 DEF_FIELD(symval
, pcmcia_device_id
, manf_id
);
606 DEF_FIELD(symval
, pcmcia_device_id
, card_id
);
607 DEF_FIELD(symval
, pcmcia_device_id
, func_id
);
608 DEF_FIELD(symval
, pcmcia_device_id
, function
);
609 DEF_FIELD(symval
, pcmcia_device_id
, device_no
);
610 DEF_FIELD_ADDR(symval
, pcmcia_device_id
, prod_id_hash
);
612 for (i
=0; i
<4; i
++) {
613 (*prod_id_hash
)[i
] = TO_NATIVE((*prod_id_hash
)[i
]);
616 ADD(alias
, "m", match_flags
& PCMCIA_DEV_ID_MATCH_MANF_ID
,
618 ADD(alias
, "c", match_flags
& PCMCIA_DEV_ID_MATCH_CARD_ID
,
620 ADD(alias
, "f", match_flags
& PCMCIA_DEV_ID_MATCH_FUNC_ID
,
622 ADD(alias
, "fn", match_flags
& PCMCIA_DEV_ID_MATCH_FUNCTION
,
624 ADD(alias
, "pfn", match_flags
& PCMCIA_DEV_ID_MATCH_DEVICE_NO
,
626 ADD(alias
, "pa", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID1
, (*prod_id_hash
)[0]);
627 ADD(alias
, "pb", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID2
, (*prod_id_hash
)[1]);
628 ADD(alias
, "pc", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID3
, (*prod_id_hash
)[2]);
629 ADD(alias
, "pd", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID4
, (*prod_id_hash
)[3]);
631 module_alias_printf(mod
, true, "pcmcia:%s", alias
);
634 static void do_vio_entry(struct module
*mod
, void *symval
)
638 DEF_FIELD_ADDR(symval
, vio_device_id
, type
);
639 DEF_FIELD_ADDR(symval
, vio_device_id
, compat
);
641 sprintf(alias
, "vio:T%sS%s", (*type
)[0] ? *type
: "*",
642 (*compat
)[0] ? *compat
: "*");
644 /* Replace all whitespace with underscores */
645 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
649 module_alias_printf(mod
, true, "%s", alias
);
652 static void do_input(char *alias
,
653 kernel_ulong_t
*arr
, unsigned int min
, unsigned int max
)
657 for (i
= min
/ BITS_PER_LONG
; i
< max
/ BITS_PER_LONG
+ 1; i
++)
658 arr
[i
] = TO_NATIVE(arr
[i
]);
659 for (i
= min
; i
< max
; i
++)
660 if (arr
[i
/ BITS_PER_LONG
] & (1ULL << (i
%BITS_PER_LONG
)))
661 sprintf(alias
+ strlen(alias
), "%X,*", i
);
664 /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */
665 static void do_input_entry(struct module
*mod
, void *symval
)
667 char alias
[256] = {};
669 DEF_FIELD(symval
, input_device_id
, flags
);
670 DEF_FIELD(symval
, input_device_id
, bustype
);
671 DEF_FIELD(symval
, input_device_id
, vendor
);
672 DEF_FIELD(symval
, input_device_id
, product
);
673 DEF_FIELD(symval
, input_device_id
, version
);
674 DEF_FIELD_ADDR(symval
, input_device_id
, evbit
);
675 DEF_FIELD_ADDR(symval
, input_device_id
, keybit
);
676 DEF_FIELD_ADDR(symval
, input_device_id
, relbit
);
677 DEF_FIELD_ADDR(symval
, input_device_id
, absbit
);
678 DEF_FIELD_ADDR(symval
, input_device_id
, mscbit
);
679 DEF_FIELD_ADDR(symval
, input_device_id
, ledbit
);
680 DEF_FIELD_ADDR(symval
, input_device_id
, sndbit
);
681 DEF_FIELD_ADDR(symval
, input_device_id
, ffbit
);
682 DEF_FIELD_ADDR(symval
, input_device_id
, swbit
);
684 ADD(alias
, "b", flags
& INPUT_DEVICE_ID_MATCH_BUS
, bustype
);
685 ADD(alias
, "v", flags
& INPUT_DEVICE_ID_MATCH_VENDOR
, vendor
);
686 ADD(alias
, "p", flags
& INPUT_DEVICE_ID_MATCH_PRODUCT
, product
);
687 ADD(alias
, "e", flags
& INPUT_DEVICE_ID_MATCH_VERSION
, version
);
689 sprintf(alias
+ strlen(alias
), "-e*");
690 if (flags
& INPUT_DEVICE_ID_MATCH_EVBIT
)
691 do_input(alias
, *evbit
, 0, INPUT_DEVICE_ID_EV_MAX
);
692 sprintf(alias
+ strlen(alias
), "k*");
693 if (flags
& INPUT_DEVICE_ID_MATCH_KEYBIT
)
694 do_input(alias
, *keybit
,
695 INPUT_DEVICE_ID_KEY_MIN_INTERESTING
,
696 INPUT_DEVICE_ID_KEY_MAX
);
697 sprintf(alias
+ strlen(alias
), "r*");
698 if (flags
& INPUT_DEVICE_ID_MATCH_RELBIT
)
699 do_input(alias
, *relbit
, 0, INPUT_DEVICE_ID_REL_MAX
);
700 sprintf(alias
+ strlen(alias
), "a*");
701 if (flags
& INPUT_DEVICE_ID_MATCH_ABSBIT
)
702 do_input(alias
, *absbit
, 0, INPUT_DEVICE_ID_ABS_MAX
);
703 sprintf(alias
+ strlen(alias
), "m*");
704 if (flags
& INPUT_DEVICE_ID_MATCH_MSCIT
)
705 do_input(alias
, *mscbit
, 0, INPUT_DEVICE_ID_MSC_MAX
);
706 sprintf(alias
+ strlen(alias
), "l*");
707 if (flags
& INPUT_DEVICE_ID_MATCH_LEDBIT
)
708 do_input(alias
, *ledbit
, 0, INPUT_DEVICE_ID_LED_MAX
);
709 sprintf(alias
+ strlen(alias
), "s*");
710 if (flags
& INPUT_DEVICE_ID_MATCH_SNDBIT
)
711 do_input(alias
, *sndbit
, 0, INPUT_DEVICE_ID_SND_MAX
);
712 sprintf(alias
+ strlen(alias
), "f*");
713 if (flags
& INPUT_DEVICE_ID_MATCH_FFBIT
)
714 do_input(alias
, *ffbit
, 0, INPUT_DEVICE_ID_FF_MAX
);
715 sprintf(alias
+ strlen(alias
), "w*");
716 if (flags
& INPUT_DEVICE_ID_MATCH_SWBIT
)
717 do_input(alias
, *swbit
, 0, INPUT_DEVICE_ID_SW_MAX
);
719 module_alias_printf(mod
, false, "input:%s", alias
);
722 static void do_eisa_entry(struct module
*mod
, void *symval
)
724 DEF_FIELD_ADDR(symval
, eisa_device_id
, sig
);
725 module_alias_printf(mod
, false, EISA_DEVICE_MODALIAS_FMT
"*", *sig
);
728 /* Looks like: parisc:tNhvNrevNsvN */
729 static void do_parisc_entry(struct module
*mod
, void *symval
)
731 char alias
[256] = {};
733 DEF_FIELD(symval
, parisc_device_id
, hw_type
);
734 DEF_FIELD(symval
, parisc_device_id
, hversion
);
735 DEF_FIELD(symval
, parisc_device_id
, hversion_rev
);
736 DEF_FIELD(symval
, parisc_device_id
, sversion
);
738 ADD(alias
, "t", hw_type
!= PA_HWTYPE_ANY_ID
, hw_type
);
739 ADD(alias
, "hv", hversion
!= PA_HVERSION_ANY_ID
, hversion
);
740 ADD(alias
, "rev", hversion_rev
!= PA_HVERSION_REV_ANY_ID
, hversion_rev
);
741 ADD(alias
, "sv", sversion
!= PA_SVERSION_ANY_ID
, sversion
);
743 module_alias_printf(mod
, true, "parisc:%s", alias
);
746 /* Looks like: sdio:cNvNdN. */
747 static void do_sdio_entry(struct module
*mod
, void *symval
)
749 char alias
[256] = {};
751 DEF_FIELD(symval
, sdio_device_id
, class);
752 DEF_FIELD(symval
, sdio_device_id
, vendor
);
753 DEF_FIELD(symval
, sdio_device_id
, device
);
755 ADD(alias
, "c", class != (__u8
)SDIO_ANY_ID
, class);
756 ADD(alias
, "v", vendor
!= (__u16
)SDIO_ANY_ID
, vendor
);
757 ADD(alias
, "d", device
!= (__u16
)SDIO_ANY_ID
, device
);
759 module_alias_printf(mod
, true, "sdio:%s", alias
);
762 /* Looks like: ssb:vNidNrevN. */
763 static void do_ssb_entry(struct module
*mod
, void *symval
)
765 char alias
[256] = {};
767 DEF_FIELD(symval
, ssb_device_id
, vendor
);
768 DEF_FIELD(symval
, ssb_device_id
, coreid
);
769 DEF_FIELD(symval
, ssb_device_id
, revision
);
771 ADD(alias
, "v", vendor
!= SSB_ANY_VENDOR
, vendor
);
772 ADD(alias
, "id", coreid
!= SSB_ANY_ID
, coreid
);
773 ADD(alias
, "rev", revision
!= SSB_ANY_REV
, revision
);
775 module_alias_printf(mod
, true, "ssb:%s", alias
);
778 /* Looks like: bcma:mNidNrevNclN. */
779 static void do_bcma_entry(struct module
*mod
, void *symval
)
781 char alias
[256] = {};
783 DEF_FIELD(symval
, bcma_device_id
, manuf
);
784 DEF_FIELD(symval
, bcma_device_id
, id
);
785 DEF_FIELD(symval
, bcma_device_id
, rev
);
786 DEF_FIELD(symval
, bcma_device_id
, class);
788 ADD(alias
, "m", manuf
!= BCMA_ANY_MANUF
, manuf
);
789 ADD(alias
, "id", id
!= BCMA_ANY_ID
, id
);
790 ADD(alias
, "rev", rev
!= BCMA_ANY_REV
, rev
);
791 ADD(alias
, "cl", class != BCMA_ANY_CLASS
, class);
793 module_alias_printf(mod
, true, "bcma:%s", alias
);
796 /* Looks like: virtio:dNvN */
797 static void do_virtio_entry(struct module
*mod
, void *symval
)
799 char alias
[256] = {};
801 DEF_FIELD(symval
, virtio_device_id
, device
);
802 DEF_FIELD(symval
, virtio_device_id
, vendor
);
804 ADD(alias
, "d", device
!= VIRTIO_DEV_ANY_ID
, device
);
805 ADD(alias
, "v", vendor
!= VIRTIO_DEV_ANY_ID
, vendor
);
807 module_alias_printf(mod
, true, "virtio:%s", alias
);
811 * Looks like: vmbus:guid
812 * Each byte of the guid will be represented by two hex characters
816 static void do_vmbus_entry(struct module
*mod
, void *symval
)
819 DEF_FIELD_ADDR(symval
, hv_vmbus_device_id
, guid
);
820 char guid_name
[(sizeof(*guid
) + 1) * 2];
822 for (i
= 0; i
< (sizeof(*guid
) * 2); i
+= 2)
823 sprintf(&guid_name
[i
], "%02x", TO_NATIVE((guid
->b
)[i
/2]));
825 module_alias_printf(mod
, false, "vmbus:%s", guid_name
);
828 /* Looks like: rpmsg:S */
829 static void do_rpmsg_entry(struct module
*mod
, void *symval
)
831 DEF_FIELD_ADDR(symval
, rpmsg_device_id
, name
);
833 module_alias_printf(mod
, false, RPMSG_DEVICE_MODALIAS_FMT
, *name
);
836 /* Looks like: i2c:S */
837 static void do_i2c_entry(struct module
*mod
, void *symval
)
839 DEF_FIELD_ADDR(symval
, i2c_device_id
, name
);
841 module_alias_printf(mod
, false, I2C_MODULE_PREFIX
"%s", *name
);
844 static void do_i3c_entry(struct module
*mod
, void *symval
)
846 char alias
[256] = {};
848 DEF_FIELD(symval
, i3c_device_id
, match_flags
);
849 DEF_FIELD(symval
, i3c_device_id
, dcr
);
850 DEF_FIELD(symval
, i3c_device_id
, manuf_id
);
851 DEF_FIELD(symval
, i3c_device_id
, part_id
);
852 DEF_FIELD(symval
, i3c_device_id
, extra_info
);
854 ADD(alias
, "dcr", match_flags
& I3C_MATCH_DCR
, dcr
);
855 ADD(alias
, "manuf", match_flags
& I3C_MATCH_MANUF
, manuf_id
);
856 ADD(alias
, "part", match_flags
& I3C_MATCH_PART
, part_id
);
857 ADD(alias
, "ext", match_flags
& I3C_MATCH_EXTRA_INFO
, extra_info
);
859 module_alias_printf(mod
, false, "i3c:%s", alias
);
862 static void do_slim_entry(struct module
*mod
, void *symval
)
864 DEF_FIELD(symval
, slim_device_id
, manf_id
);
865 DEF_FIELD(symval
, slim_device_id
, prod_code
);
867 module_alias_printf(mod
, false, "slim:%x:%x:*", manf_id
, prod_code
);
870 /* Looks like: spi:S */
871 static void do_spi_entry(struct module
*mod
, void *symval
)
873 DEF_FIELD_ADDR(symval
, spi_device_id
, name
);
875 module_alias_printf(mod
, false, SPI_MODULE_PREFIX
"%s", *name
);
878 static const struct dmifield
{
882 { "bvn", DMI_BIOS_VENDOR
},
883 { "bvr", DMI_BIOS_VERSION
},
884 { "bd", DMI_BIOS_DATE
},
885 { "br", DMI_BIOS_RELEASE
},
886 { "efr", DMI_EC_FIRMWARE_RELEASE
},
887 { "svn", DMI_SYS_VENDOR
},
888 { "pn", DMI_PRODUCT_NAME
},
889 { "pvr", DMI_PRODUCT_VERSION
},
890 { "rvn", DMI_BOARD_VENDOR
},
891 { "rn", DMI_BOARD_NAME
},
892 { "rvr", DMI_BOARD_VERSION
},
893 { "cvn", DMI_CHASSIS_VENDOR
},
894 { "ct", DMI_CHASSIS_TYPE
},
895 { "cvr", DMI_CHASSIS_VERSION
},
899 static void dmi_ascii_filter(char *d
, const char *s
)
901 /* Filter out characters we don't want to see in the modalias string */
903 if (*s
> ' ' && *s
< 127 && *s
!= ':')
910 static void do_dmi_entry(struct module
*mod
, void *symval
)
912 char alias
[256] = {};
914 DEF_FIELD_ADDR(symval
, dmi_system_id
, matches
);
916 for (i
= 0; i
< ARRAY_SIZE(dmi_fields
); i
++) {
917 for (j
= 0; j
< 4; j
++) {
918 if ((*matches
)[j
].slot
&&
919 (*matches
)[j
].slot
== dmi_fields
[i
].field
) {
920 sprintf(alias
+ strlen(alias
), ":%s*",
921 dmi_fields
[i
].prefix
);
922 dmi_ascii_filter(alias
+ strlen(alias
),
923 (*matches
)[j
].substr
);
929 module_alias_printf(mod
, false, "dmi*%s:", alias
);
932 static void do_platform_entry(struct module
*mod
, void *symval
)
934 DEF_FIELD_ADDR(symval
, platform_device_id
, name
);
936 module_alias_printf(mod
, false, PLATFORM_MODULE_PREFIX
"%s", *name
);
939 static void do_mdio_entry(struct module
*mod
, void *symval
)
943 DEF_FIELD(symval
, mdio_device_id
, phy_id
);
944 DEF_FIELD(symval
, mdio_device_id
, phy_id_mask
);
946 for (i
= 0; i
< 32; i
++) {
947 if (!((phy_id_mask
>> (31-i
)) & 1))
949 else if ((phy_id
>> (31-i
)) & 1)
955 /* Terminate the string */
958 module_alias_printf(mod
, false, MDIO_MODULE_PREFIX
"%s", id
);
961 /* Looks like: zorro:iN. */
962 static void do_zorro_entry(struct module
*mod
, void *symval
)
964 char alias
[256] = {};
965 DEF_FIELD(symval
, zorro_device_id
, id
);
967 ADD(alias
, "i", id
!= ZORRO_WILDCARD
, id
);
969 module_alias_printf(mod
, false, "zorro:%s", alias
);
972 /* looks like: "pnp:dD" */
973 static void do_isapnp_entry(struct module
*mod
, void *symval
)
975 DEF_FIELD(symval
, isapnp_device_id
, vendor
);
976 DEF_FIELD(symval
, isapnp_device_id
, function
);
977 module_alias_printf(mod
, false, "pnp:d%c%c%c%x%x%x%x*",
978 'A' + ((vendor
>> 2) & 0x3f) - 1,
979 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
980 'A' + ((vendor
>> 8) & 0x1f) - 1,
981 (function
>> 4) & 0x0f, function
& 0x0f,
982 (function
>> 12) & 0x0f, (function
>> 8) & 0x0f);
985 /* Looks like: "ipack:fNvNdN". */
986 static void do_ipack_entry(struct module
*mod
, void *symval
)
988 char alias
[256] = {};
989 DEF_FIELD(symval
, ipack_device_id
, format
);
990 DEF_FIELD(symval
, ipack_device_id
, vendor
);
991 DEF_FIELD(symval
, ipack_device_id
, device
);
993 ADD(alias
, "f", format
!= IPACK_ANY_FORMAT
, format
);
994 ADD(alias
, "v", vendor
!= IPACK_ANY_ID
, vendor
);
995 ADD(alias
, "d", device
!= IPACK_ANY_ID
, device
);
997 module_alias_printf(mod
, true, "ipack:%s", alias
);
1001 * Append a match expression for a single masked hex digit.
1002 * outp points to a pointer to the character at which to append.
1003 * *outp is updated on return to point just after the appended text,
1004 * to facilitate further appending.
1006 static void append_nibble_mask(char **outp
,
1007 unsigned int nibble
, unsigned int mask
)
1018 p
+= sprintf(p
, "%X", nibble
);
1023 * Dumbly emit a match pattern for all possible matching
1024 * digits. This could be improved in some cases using ranges,
1025 * but it has the advantage of being trivially correct, and is
1029 for (i
= 0; i
< 0x10; i
++)
1030 if ((i
& mask
) == nibble
)
1031 p
+= sprintf(p
, "%X", i
);
1035 /* Ensure that the string remains NUL-terminated: */
1038 /* Advance the caller's end-of-string pointer: */
1043 * looks like: "amba:dN"
1045 * N is exactly 8 digits, where each is an upper-case hex digit, or
1046 * a ? or [] pattern matching exactly one digit.
1048 static void do_amba_entry(struct module
*mod
, void *symval
)
1053 DEF_FIELD(symval
, amba_id
, id
);
1054 DEF_FIELD(symval
, amba_id
, mask
);
1056 if ((id
& mask
) != id
)
1057 fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1058 mod
->name
, id
, mask
);
1060 for (digit
= 0; digit
< 8; digit
++)
1061 append_nibble_mask(&p
,
1062 (id
>> (4 * (7 - digit
))) & 0xf,
1063 (mask
>> (4 * (7 - digit
))) & 0xf);
1065 module_alias_printf(mod
, false, "amba:d%s", alias
);
1069 * looks like: "mipscdmm:tN"
1071 * N is exactly 2 digits, where each is an upper-case hex digit, or
1072 * a ? or [] pattern matching exactly one digit.
1074 static void do_mips_cdmm_entry(struct module
*mod
, void *symval
)
1076 DEF_FIELD(symval
, mips_cdmm_device_id
, type
);
1078 module_alias_printf(mod
, false, "mipscdmm:t%02X*", type
);
1081 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
1082 * All fields are numbers. It would be nicer to use strings for vendor
1083 * and feature, but getting those out of the build system here is too
1087 static void do_x86cpu_entry(struct module
*mod
, void *symval
)
1089 char alias
[256] = {};
1091 DEF_FIELD(symval
, x86_cpu_id
, feature
);
1092 DEF_FIELD(symval
, x86_cpu_id
, family
);
1093 DEF_FIELD(symval
, x86_cpu_id
, model
);
1094 DEF_FIELD(symval
, x86_cpu_id
, vendor
);
1096 ADD(alias
, "ven", vendor
!= X86_VENDOR_ANY
, vendor
);
1097 ADD(alias
, "fam", family
!= X86_FAMILY_ANY
, family
);
1098 ADD(alias
, "mod", model
!= X86_MODEL_ANY
, model
);
1099 strcat(alias
, ":feature:*");
1100 if (feature
!= X86_FEATURE_ANY
)
1101 sprintf(alias
+ strlen(alias
), "%04X*", feature
);
1103 module_alias_printf(mod
, false, "cpu:type:x86,%s", alias
);
1106 /* LOOKS like cpu:type:*:feature:*FEAT* */
1107 static void do_cpu_entry(struct module
*mod
, void *symval
)
1109 DEF_FIELD(symval
, cpu_feature
, feature
);
1111 module_alias_printf(mod
, false, "cpu:type:*:feature:*%04X*", feature
);
1114 /* Looks like: mei:S:uuid:N:* */
1115 static void do_mei_entry(struct module
*mod
, void *symval
)
1117 char alias
[256] = {};
1119 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, name
);
1120 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, uuid
);
1121 DEF_FIELD(symval
, mei_cl_device_id
, version
);
1123 add_uuid(alias
, *uuid
);
1124 ADD(alias
, ":", version
!= MEI_CL_VERSION_ANY
, version
);
1126 module_alias_printf(mod
, false, MEI_CL_MODULE_PREFIX
"%s:%s:*",
1127 (*name
)[0] ? *name
: "*", alias
);
1130 /* Looks like: rapidio:vNdNavNadN */
1131 static void do_rio_entry(struct module
*mod
, void *symval
)
1133 char alias
[256] = {};
1135 DEF_FIELD(symval
, rio_device_id
, did
);
1136 DEF_FIELD(symval
, rio_device_id
, vid
);
1137 DEF_FIELD(symval
, rio_device_id
, asm_did
);
1138 DEF_FIELD(symval
, rio_device_id
, asm_vid
);
1140 ADD(alias
, "v", vid
!= RIO_ANY_ID
, vid
);
1141 ADD(alias
, "d", did
!= RIO_ANY_ID
, did
);
1142 ADD(alias
, "av", asm_vid
!= RIO_ANY_ID
, asm_vid
);
1143 ADD(alias
, "ad", asm_did
!= RIO_ANY_ID
, asm_did
);
1145 module_alias_printf(mod
, true, "rapidio:%s", alias
);
1148 /* Looks like: ulpi:vNpN */
1149 static void do_ulpi_entry(struct module
*mod
, void *symval
)
1151 DEF_FIELD(symval
, ulpi_device_id
, vendor
);
1152 DEF_FIELD(symval
, ulpi_device_id
, product
);
1154 module_alias_printf(mod
, false, "ulpi:v%04xp%04x", vendor
, product
);
1157 /* Looks like: hdaudio:vNrNaN */
1158 static void do_hda_entry(struct module
*mod
, void *symval
)
1160 char alias
[256] = {};
1162 DEF_FIELD(symval
, hda_device_id
, vendor_id
);
1163 DEF_FIELD(symval
, hda_device_id
, rev_id
);
1164 DEF_FIELD(symval
, hda_device_id
, api_version
);
1166 ADD(alias
, "v", vendor_id
!= 0, vendor_id
);
1167 ADD(alias
, "r", rev_id
!= 0, rev_id
);
1168 ADD(alias
, "a", api_version
!= 0, api_version
);
1170 module_alias_printf(mod
, true, "hdaudio:%s", alias
);
1173 /* Looks like: sdw:mNpNvNcN */
1174 static void do_sdw_entry(struct module
*mod
, void *symval
)
1176 char alias
[256] = {};
1178 DEF_FIELD(symval
, sdw_device_id
, mfg_id
);
1179 DEF_FIELD(symval
, sdw_device_id
, part_id
);
1180 DEF_FIELD(symval
, sdw_device_id
, sdw_version
);
1181 DEF_FIELD(symval
, sdw_device_id
, class_id
);
1183 ADD(alias
, "m", mfg_id
!= 0, mfg_id
);
1184 ADD(alias
, "p", part_id
!= 0, part_id
);
1185 ADD(alias
, "v", sdw_version
!= 0, sdw_version
);
1186 ADD(alias
, "c", class_id
!= 0, class_id
);
1188 module_alias_printf(mod
, true, "sdw:%s", alias
);
1191 /* Looks like: fsl-mc:vNdN */
1192 static void do_fsl_mc_entry(struct module
*mod
, void *symval
)
1194 DEF_FIELD(symval
, fsl_mc_device_id
, vendor
);
1195 DEF_FIELD_ADDR(symval
, fsl_mc_device_id
, obj_type
);
1197 module_alias_printf(mod
, false, "fsl-mc:v%08Xd%s", vendor
, *obj_type
);
1200 /* Looks like: tbsvc:kSpNvNrN */
1201 static void do_tbsvc_entry(struct module
*mod
, void *symval
)
1203 char alias
[256] = {};
1205 DEF_FIELD(symval
, tb_service_id
, match_flags
);
1206 DEF_FIELD_ADDR(symval
, tb_service_id
, protocol_key
);
1207 DEF_FIELD(symval
, tb_service_id
, protocol_id
);
1208 DEF_FIELD(symval
, tb_service_id
, protocol_version
);
1209 DEF_FIELD(symval
, tb_service_id
, protocol_revision
);
1211 if (match_flags
& TBSVC_MATCH_PROTOCOL_KEY
)
1212 sprintf(alias
+ strlen(alias
), "k%s", *protocol_key
);
1214 strcat(alias
+ strlen(alias
), "k*");
1215 ADD(alias
, "p", match_flags
& TBSVC_MATCH_PROTOCOL_ID
, protocol_id
);
1216 ADD(alias
, "v", match_flags
& TBSVC_MATCH_PROTOCOL_VERSION
,
1218 ADD(alias
, "r", match_flags
& TBSVC_MATCH_PROTOCOL_REVISION
,
1221 module_alias_printf(mod
, true, "tbsvc:%s", alias
);
1224 /* Looks like: typec:idNmN */
1225 static void do_typec_entry(struct module
*mod
, void *symval
)
1227 char alias
[256] = {};
1229 DEF_FIELD(symval
, typec_device_id
, svid
);
1230 DEF_FIELD(symval
, typec_device_id
, mode
);
1232 ADD(alias
, "m", mode
!= TYPEC_ANY_MODE
, mode
);
1234 module_alias_printf(mod
, false, "typec:id%04X%s", svid
, alias
);
1237 /* Looks like: tee:uuid */
1238 static void do_tee_entry(struct module
*mod
, void *symval
)
1240 DEF_FIELD_ADDR(symval
, tee_client_device_id
, uuid
);
1242 module_alias_printf(mod
, true,
1243 "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1244 uuid
->b
[0], uuid
->b
[1], uuid
->b
[2], uuid
->b
[3], uuid
->b
[4],
1245 uuid
->b
[5], uuid
->b
[6], uuid
->b
[7], uuid
->b
[8], uuid
->b
[9],
1246 uuid
->b
[10], uuid
->b
[11], uuid
->b
[12], uuid
->b
[13], uuid
->b
[14],
1250 /* Looks like: wmi:guid */
1251 static void do_wmi_entry(struct module
*mod
, void *symval
)
1253 DEF_FIELD_ADDR(symval
, wmi_device_id
, guid_string
);
1255 if (strlen(*guid_string
) != UUID_STRING_LEN
) {
1256 warn("Invalid WMI device id 'wmi:%s' in '%s'\n",
1257 *guid_string
, mod
->name
);
1261 module_alias_printf(mod
, false, WMI_MODULE_PREFIX
"%s", *guid_string
);
1264 /* Looks like: mhi:S */
1265 static void do_mhi_entry(struct module
*mod
, void *symval
)
1267 DEF_FIELD_ADDR(symval
, mhi_device_id
, chan
);
1268 module_alias_printf(mod
, false, MHI_DEVICE_MODALIAS_FMT
, *chan
);
1271 /* Looks like: mhi_ep:S */
1272 static void do_mhi_ep_entry(struct module
*mod
, void *symval
)
1274 DEF_FIELD_ADDR(symval
, mhi_device_id
, chan
);
1276 module_alias_printf(mod
, false, MHI_EP_DEVICE_MODALIAS_FMT
, *chan
);
1279 /* Looks like: ishtp:{guid} */
1280 static void do_ishtp_entry(struct module
*mod
, void *symval
)
1282 char alias
[256] = {};
1283 DEF_FIELD_ADDR(symval
, ishtp_device_id
, guid
);
1285 add_guid(alias
, *guid
);
1287 module_alias_printf(mod
, false, ISHTP_MODULE_PREFIX
"{%s}", alias
);
1290 static void do_auxiliary_entry(struct module
*mod
, void *symval
)
1292 DEF_FIELD_ADDR(symval
, auxiliary_device_id
, name
);
1294 module_alias_printf(mod
, false, AUXILIARY_MODULE_PREFIX
"%s", *name
);
1298 * Looks like: ssam:dNcNtNiNfN
1300 * N is exactly 2 digits, where each is an upper-case hex digit.
1302 static void do_ssam_entry(struct module
*mod
, void *symval
)
1304 char alias
[256] = {};
1306 DEF_FIELD(symval
, ssam_device_id
, match_flags
);
1307 DEF_FIELD(symval
, ssam_device_id
, domain
);
1308 DEF_FIELD(symval
, ssam_device_id
, category
);
1309 DEF_FIELD(symval
, ssam_device_id
, target
);
1310 DEF_FIELD(symval
, ssam_device_id
, instance
);
1311 DEF_FIELD(symval
, ssam_device_id
, function
);
1313 ADD(alias
, "t", match_flags
& SSAM_MATCH_TARGET
, target
);
1314 ADD(alias
, "i", match_flags
& SSAM_MATCH_INSTANCE
, instance
);
1315 ADD(alias
, "f", match_flags
& SSAM_MATCH_FUNCTION
, function
);
1317 module_alias_printf(mod
, false, "ssam:d%02Xc%02X%s",
1318 domain
, category
, alias
);
1321 /* Looks like: dfl:tNfN */
1322 static void do_dfl_entry(struct module
*mod
, void *symval
)
1324 DEF_FIELD(symval
, dfl_device_id
, type
);
1325 DEF_FIELD(symval
, dfl_device_id
, feature_id
);
1327 module_alias_printf(mod
, true, "dfl:t%04Xf%04X", type
, feature_id
);
1330 /* Looks like: cdx:vNdN */
1331 static void do_cdx_entry(struct module
*mod
, void *symval
)
1335 DEF_FIELD(symval
, cdx_device_id
, vendor
);
1336 DEF_FIELD(symval
, cdx_device_id
, device
);
1337 DEF_FIELD(symval
, cdx_device_id
, subvendor
);
1338 DEF_FIELD(symval
, cdx_device_id
, subdevice
);
1339 DEF_FIELD(symval
, cdx_device_id
, class);
1340 DEF_FIELD(symval
, cdx_device_id
, class_mask
);
1341 DEF_FIELD(symval
, cdx_device_id
, override_only
);
1343 switch (override_only
) {
1345 strcpy(alias
, "cdx:");
1347 case CDX_ID_F_VFIO_DRIVER_OVERRIDE
:
1348 strcpy(alias
, "vfio_cdx:");
1351 warn("Unknown CDX driver_override alias %08X\n",
1356 ADD(alias
, "v", vendor
!= CDX_ANY_ID
, vendor
);
1357 ADD(alias
, "d", device
!= CDX_ANY_ID
, device
);
1358 ADD(alias
, "sv", subvendor
!= CDX_ANY_ID
, subvendor
);
1359 ADD(alias
, "sd", subdevice
!= CDX_ANY_ID
, subdevice
);
1360 ADD(alias
, "c", class_mask
== 0xFFFFFF, class);
1362 module_alias_printf(mod
, false, "%s", alias
);
1365 static void do_vchiq_entry(struct module
*mod
, void *symval
)
1367 DEF_FIELD_ADDR(symval
, vchiq_device_id
, name
);
1369 module_alias_printf(mod
, false, "vchiq:%s", *name
);
1372 /* Looks like: coreboot:tN */
1373 static void do_coreboot_entry(struct module
*mod
, void *symval
)
1375 DEF_FIELD(symval
, coreboot_device_id
, tag
);
1377 module_alias_printf(mod
, false, "coreboot:t%08X", tag
);
1380 /* Does namelen bytes of name exactly match the symbol? */
1381 static bool sym_is(const char *name
, unsigned namelen
, const char *symbol
)
1383 if (namelen
!= strlen(symbol
))
1386 return memcmp(name
, symbol
, namelen
) == 0;
1389 static void do_table(const char *name
, void *symval
, unsigned long size
,
1390 unsigned long id_size
,
1391 const char *device_id
,
1392 void (*do_entry
)(struct module
*mod
, void *symval
),
1397 if (size
% id_size
|| size
< id_size
) {
1398 error("%s: type mismatch between %s[] and MODULE_DEVICE_TABLE(%s, ...)\n",
1399 mod
->name
, name
, device_id
);
1403 /* Verify the last entry is a terminator */
1404 for (i
= size
- id_size
; i
< size
; i
++) {
1405 if (*(uint8_t *)(symval
+ i
)) {
1406 error("%s: %s[] is not terminated with a NULL entry\n",
1412 /* Leave last one: it's the terminator. */
1415 for (i
= 0; i
< size
; i
+= id_size
)
1416 do_entry(mod
, symval
+ i
);
1419 static const struct devtable devtable
[] = {
1420 {"hid", SIZE_hid_device_id
, do_hid_entry
},
1421 {"ieee1394", SIZE_ieee1394_device_id
, do_ieee1394_entry
},
1422 {"pci", SIZE_pci_device_id
, do_pci_entry
},
1423 {"ccw", SIZE_ccw_device_id
, do_ccw_entry
},
1424 {"ap", SIZE_ap_device_id
, do_ap_entry
},
1425 {"css", SIZE_css_device_id
, do_css_entry
},
1426 {"serio", SIZE_serio_device_id
, do_serio_entry
},
1427 {"acpi", SIZE_acpi_device_id
, do_acpi_entry
},
1428 {"pcmcia", SIZE_pcmcia_device_id
, do_pcmcia_entry
},
1429 {"vio", SIZE_vio_device_id
, do_vio_entry
},
1430 {"input", SIZE_input_device_id
, do_input_entry
},
1431 {"eisa", SIZE_eisa_device_id
, do_eisa_entry
},
1432 {"parisc", SIZE_parisc_device_id
, do_parisc_entry
},
1433 {"sdio", SIZE_sdio_device_id
, do_sdio_entry
},
1434 {"ssb", SIZE_ssb_device_id
, do_ssb_entry
},
1435 {"bcma", SIZE_bcma_device_id
, do_bcma_entry
},
1436 {"virtio", SIZE_virtio_device_id
, do_virtio_entry
},
1437 {"vmbus", SIZE_hv_vmbus_device_id
, do_vmbus_entry
},
1438 {"rpmsg", SIZE_rpmsg_device_id
, do_rpmsg_entry
},
1439 {"i2c", SIZE_i2c_device_id
, do_i2c_entry
},
1440 {"i3c", SIZE_i3c_device_id
, do_i3c_entry
},
1441 {"slim", SIZE_slim_device_id
, do_slim_entry
},
1442 {"spi", SIZE_spi_device_id
, do_spi_entry
},
1443 {"dmi", SIZE_dmi_system_id
, do_dmi_entry
},
1444 {"platform", SIZE_platform_device_id
, do_platform_entry
},
1445 {"mdio", SIZE_mdio_device_id
, do_mdio_entry
},
1446 {"zorro", SIZE_zorro_device_id
, do_zorro_entry
},
1447 {"isapnp", SIZE_isapnp_device_id
, do_isapnp_entry
},
1448 {"ipack", SIZE_ipack_device_id
, do_ipack_entry
},
1449 {"amba", SIZE_amba_id
, do_amba_entry
},
1450 {"mipscdmm", SIZE_mips_cdmm_device_id
, do_mips_cdmm_entry
},
1451 {"x86cpu", SIZE_x86_cpu_id
, do_x86cpu_entry
},
1452 {"cpu", SIZE_cpu_feature
, do_cpu_entry
},
1453 {"mei", SIZE_mei_cl_device_id
, do_mei_entry
},
1454 {"rapidio", SIZE_rio_device_id
, do_rio_entry
},
1455 {"ulpi", SIZE_ulpi_device_id
, do_ulpi_entry
},
1456 {"hdaudio", SIZE_hda_device_id
, do_hda_entry
},
1457 {"sdw", SIZE_sdw_device_id
, do_sdw_entry
},
1458 {"fslmc", SIZE_fsl_mc_device_id
, do_fsl_mc_entry
},
1459 {"tbsvc", SIZE_tb_service_id
, do_tbsvc_entry
},
1460 {"typec", SIZE_typec_device_id
, do_typec_entry
},
1461 {"tee", SIZE_tee_client_device_id
, do_tee_entry
},
1462 {"wmi", SIZE_wmi_device_id
, do_wmi_entry
},
1463 {"mhi", SIZE_mhi_device_id
, do_mhi_entry
},
1464 {"mhi_ep", SIZE_mhi_device_id
, do_mhi_ep_entry
},
1465 {"auxiliary", SIZE_auxiliary_device_id
, do_auxiliary_entry
},
1466 {"ssam", SIZE_ssam_device_id
, do_ssam_entry
},
1467 {"dfl", SIZE_dfl_device_id
, do_dfl_entry
},
1468 {"ishtp", SIZE_ishtp_device_id
, do_ishtp_entry
},
1469 {"cdx", SIZE_cdx_device_id
, do_cdx_entry
},
1470 {"vchiq", SIZE_vchiq_device_id
, do_vchiq_entry
},
1471 {"coreboot", SIZE_coreboot_device_id
, do_coreboot_entry
},
1472 {"of", SIZE_of_device_id
, do_of_entry
},
1473 {"usb", SIZE_usb_device_id
, do_usb_entry_multi
},
1474 {"pnp", SIZE_pnp_device_id
, do_pnp_device_entry
},
1475 {"pnp_card", SIZE_pnp_card_device_id
, do_pnp_card_entry
},
1478 /* Create MODULE_ALIAS() statements.
1479 * At this time, we cannot write the actual output C source yet,
1480 * so we write into the mod->dev_table_buf buffer. */
1481 void handle_moddevtable(struct module
*mod
, struct elf_info
*info
,
1482 Elf_Sym
*sym
, const char *symname
)
1486 const char *type
, *name
;
1488 static const char *prefix
= "__mod_device_table__";
1490 /* We're looking for a section relative symbol */
1491 if (!sym
->st_shndx
|| get_secindex(info
, sym
) >= info
->num_sections
)
1494 /* We're looking for an object */
1495 if (ELF_ST_TYPE(sym
->st_info
) != STT_OBJECT
)
1498 /* All our symbols are of form __mod_device_table__<type>__<name>. */
1499 if (!strstarts(symname
, prefix
))
1501 type
= symname
+ strlen(prefix
);
1503 name
= strstr(type
, "__");
1506 typelen
= name
- type
;
1507 name
+= strlen("__");
1509 /* Handle all-NULL symbols allocated into .bss */
1510 if (info
->sechdrs
[get_secindex(info
, sym
)].sh_type
& SHT_NOBITS
) {
1511 zeros
= calloc(1, sym
->st_size
);
1514 symval
= sym_get_data(info
, sym
);
1517 for (int i
= 0; i
< ARRAY_SIZE(devtable
); i
++) {
1518 const struct devtable
*p
= &devtable
[i
];
1520 if (sym_is(type
, typelen
, p
->device_id
)) {
1521 do_table(name
, symval
, sym
->st_size
, p
->id_size
,
1522 p
->device_id
, p
->do_entry
, mod
);