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 = \
136 get_unaligned_native((typeof(f) *)((m) + OFF_##devid##_##f))
138 /* Define a variable f that holds the address of field f of struct devid
139 * based at address m. Due to the way typeof works, for a field of type
140 * T[N] the variable has type T(*)[N], _not_ T*.
142 #define DEF_FIELD_ADDR(m, devid, f) \
143 typeof(((struct devid *)0)->f) *f = ((m) + OFF_##devid##_##f)
145 #define ADD(str, sep, cond, field) \
149 sprintf(str + strlen(str), \
150 sizeof(field) == 1 ? "%02X" : \
151 sizeof(field) == 2 ? "%04X" : \
152 sizeof(field) == 4 ? "%08X" : "", \
155 sprintf(str + strlen(str), "*"); \
158 static inline void add_uuid(char *str
, uuid_le uuid
)
160 int len
= strlen(str
);
162 sprintf(str
+ len
, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
163 uuid
.b
[3], uuid
.b
[2], uuid
.b
[1], uuid
.b
[0],
164 uuid
.b
[5], uuid
.b
[4], uuid
.b
[7], uuid
.b
[6],
165 uuid
.b
[8], uuid
.b
[9], uuid
.b
[10], uuid
.b
[11],
166 uuid
.b
[12], uuid
.b
[13], uuid
.b
[14], uuid
.b
[15]);
169 static inline void add_guid(char *str
, guid_t guid
)
171 int len
= strlen(str
);
173 sprintf(str
+ len
, "%02X%02X%02X%02X-%02X%02X-%02X%02X-%02X%02X-%02X%02X%02X%02X%02X%02X",
174 guid
.b
[3], guid
.b
[2], guid
.b
[1], guid
.b
[0],
175 guid
.b
[5], guid
.b
[4], guid
.b
[7], guid
.b
[6],
176 guid
.b
[8], guid
.b
[9], guid
.b
[10], guid
.b
[11],
177 guid
.b
[12], guid
.b
[13], guid
.b
[14], guid
.b
[15]);
180 /* USB is special because the bcdDevice can be matched against a numeric range */
181 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
182 static void do_usb_entry(void *symval
,
183 unsigned int bcdDevice_initial
, int bcdDevice_initial_digits
,
184 unsigned char range_lo
, unsigned char range_hi
,
185 unsigned char max
, struct module
*mod
)
188 DEF_FIELD(symval
, usb_device_id
, match_flags
);
189 DEF_FIELD(symval
, usb_device_id
, idVendor
);
190 DEF_FIELD(symval
, usb_device_id
, idProduct
);
191 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
192 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
193 DEF_FIELD(symval
, usb_device_id
, bDeviceSubClass
);
194 DEF_FIELD(symval
, usb_device_id
, bDeviceProtocol
);
195 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
196 DEF_FIELD(symval
, usb_device_id
, bInterfaceSubClass
);
197 DEF_FIELD(symval
, usb_device_id
, bInterfaceProtocol
);
198 DEF_FIELD(symval
, usb_device_id
, bInterfaceNumber
);
200 strcpy(alias
, "usb:");
201 ADD(alias
, "v", match_flags
&USB_DEVICE_ID_MATCH_VENDOR
,
203 ADD(alias
, "p", match_flags
&USB_DEVICE_ID_MATCH_PRODUCT
,
207 if (bcdDevice_initial_digits
)
208 sprintf(alias
+ strlen(alias
), "%0*X",
209 bcdDevice_initial_digits
, bcdDevice_initial
);
210 if (range_lo
== range_hi
)
211 sprintf(alias
+ strlen(alias
), "%X", range_lo
);
212 else if (range_lo
> 0 || range_hi
< max
) {
213 if (range_lo
> 0x9 || range_hi
< 0xA)
214 sprintf(alias
+ strlen(alias
),
219 sprintf(alias
+ strlen(alias
),
220 range_lo
< 0x9 ? "[%X-9" : "[%X",
222 sprintf(alias
+ strlen(alias
),
223 range_hi
> 0xA ? "A-%X]" : "%X]",
227 if (bcdDevice_initial_digits
< (sizeof(bcdDevice_lo
) * 2 - 1))
230 ADD(alias
, "dc", match_flags
&USB_DEVICE_ID_MATCH_DEV_CLASS
,
232 ADD(alias
, "dsc", match_flags
&USB_DEVICE_ID_MATCH_DEV_SUBCLASS
,
234 ADD(alias
, "dp", match_flags
&USB_DEVICE_ID_MATCH_DEV_PROTOCOL
,
236 ADD(alias
, "ic", match_flags
&USB_DEVICE_ID_MATCH_INT_CLASS
,
238 ADD(alias
, "isc", match_flags
&USB_DEVICE_ID_MATCH_INT_SUBCLASS
,
240 ADD(alias
, "ip", match_flags
&USB_DEVICE_ID_MATCH_INT_PROTOCOL
,
242 ADD(alias
, "in", match_flags
&USB_DEVICE_ID_MATCH_INT_NUMBER
,
245 module_alias_printf(mod
, true, "%s", alias
);
248 /* Handles increment/decrement of BCD formatted integers */
249 /* Returns the previous value, so it works like i++ or i-- */
250 static unsigned int incbcd(unsigned int *bcd
,
255 unsigned int init
= *bcd
, i
, j
;
256 unsigned long long c
, dec
= 0;
258 /* If bcd is not in BCD format, just increment */
264 /* Convert BCD to Decimal */
265 for (i
=0 ; i
< chars
; i
++) {
266 c
= (*bcd
>> (i
<< 2)) & 0xf;
267 c
= c
> 9 ? 9 : c
; /* force to bcd just in case */
268 for (j
=0 ; j
< i
; j
++)
273 /* Do our increment/decrement */
277 /* Convert back to BCD */
278 for (i
=0 ; i
< chars
; i
++) {
279 for (c
=1,j
=0 ; j
< i
; j
++)
282 *bcd
+= c
<< (i
<< 2);
287 static void do_usb_entry_multi(struct module
*mod
, void *symval
)
289 unsigned int devlo
, devhi
;
290 unsigned char chi
, clo
, max
;
293 DEF_FIELD(symval
, usb_device_id
, match_flags
);
294 DEF_FIELD(symval
, usb_device_id
, idVendor
);
295 DEF_FIELD(symval
, usb_device_id
, idProduct
);
296 DEF_FIELD(symval
, usb_device_id
, bcdDevice_lo
);
297 DEF_FIELD(symval
, usb_device_id
, bcdDevice_hi
);
298 DEF_FIELD(symval
, usb_device_id
, bDeviceClass
);
299 DEF_FIELD(symval
, usb_device_id
, bInterfaceClass
);
301 devlo
= match_flags
& USB_DEVICE_ID_MATCH_DEV_LO
?
303 devhi
= match_flags
& USB_DEVICE_ID_MATCH_DEV_HI
?
304 bcdDevice_hi
: ~0x0U
;
306 /* Figure out if this entry is in bcd or hex format */
307 max
= 0x9; /* Default to decimal format */
308 for (ndigits
= 0 ; ndigits
< sizeof(bcdDevice_lo
) * 2 ; ndigits
++) {
309 clo
= (devlo
>> (ndigits
<< 2)) & 0xf;
310 chi
= ((devhi
> 0x9999 ? 0x9999 : devhi
) >> (ndigits
<< 2)) & 0xf;
311 if (clo
> max
|| chi
> max
) {
318 * Some modules (visor) have empty slots as placeholder for
319 * run-time specification that results in catch-all alias
321 if (!(idVendor
| idProduct
| bDeviceClass
| bInterfaceClass
))
324 /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */
325 for (ndigits
= sizeof(bcdDevice_lo
) * 2 - 1; devlo
<= devhi
; ndigits
--) {
328 if (chi
> max
) /* If we are in bcd mode, truncate if necessary */
333 if (devlo
== devhi
|| !ndigits
) {
334 do_usb_entry(symval
, devlo
, ndigits
, clo
, chi
, max
, mod
);
340 incbcd(&devlo
, 1, max
,
341 sizeof(bcdDevice_lo
) * 2),
342 ndigits
, clo
, max
, max
, mod
);
346 incbcd(&devhi
, -1, max
,
347 sizeof(bcdDevice_lo
) * 2),
348 ndigits
, 0x0, chi
, max
, mod
);
352 static void do_of_entry(struct module
*mod
, void *symval
)
358 DEF_FIELD_ADDR(symval
, of_device_id
, name
);
359 DEF_FIELD_ADDR(symval
, of_device_id
, type
);
360 DEF_FIELD_ADDR(symval
, of_device_id
, compatible
);
362 len
= sprintf(alias
, "of:N%sT%s", (*name
)[0] ? *name
: "*",
363 (*type
)[0] ? *type
: "*");
365 if ((*compatible
)[0])
366 sprintf(&alias
[len
], "%sC%s", (*type
)[0] ? "*" : "",
369 /* Replace all whitespace with underscores */
370 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
374 module_alias_printf(mod
, false, "%s", alias
);
375 module_alias_printf(mod
, false, "%sC*", alias
);
378 /* Looks like: hid:bNvNpN */
379 static void do_hid_entry(struct module
*mod
, void *symval
)
381 char alias
[256] = {};
383 DEF_FIELD(symval
, hid_device_id
, bus
);
384 DEF_FIELD(symval
, hid_device_id
, group
);
385 DEF_FIELD(symval
, hid_device_id
, vendor
);
386 DEF_FIELD(symval
, hid_device_id
, product
);
388 ADD(alias
, "b", bus
!= HID_BUS_ANY
, bus
);
389 ADD(alias
, "g", group
!= HID_GROUP_ANY
, group
);
390 ADD(alias
, "v", vendor
!= HID_ANY_ID
, vendor
);
391 ADD(alias
, "p", product
!= HID_ANY_ID
, product
);
393 module_alias_printf(mod
, false, "hid:%s", alias
);
396 /* Looks like: ieee1394:venNmoNspNverN */
397 static void do_ieee1394_entry(struct module
*mod
, void *symval
)
399 char alias
[256] = {};
401 DEF_FIELD(symval
, ieee1394_device_id
, match_flags
);
402 DEF_FIELD(symval
, ieee1394_device_id
, vendor_id
);
403 DEF_FIELD(symval
, ieee1394_device_id
, model_id
);
404 DEF_FIELD(symval
, ieee1394_device_id
, specifier_id
);
405 DEF_FIELD(symval
, ieee1394_device_id
, version
);
407 ADD(alias
, "ven", match_flags
& IEEE1394_MATCH_VENDOR_ID
,
409 ADD(alias
, "mo", match_flags
& IEEE1394_MATCH_MODEL_ID
,
411 ADD(alias
, "sp", match_flags
& IEEE1394_MATCH_SPECIFIER_ID
,
413 ADD(alias
, "ver", match_flags
& IEEE1394_MATCH_VERSION
,
416 module_alias_printf(mod
, true, "ieee1394:%s", alias
);
419 /* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */
420 static void do_pci_entry(struct module
*mod
, void *symval
)
423 /* Class field can be divided into these three. */
424 unsigned char baseclass
, subclass
, interface
,
425 baseclass_mask
, subclass_mask
, interface_mask
;
427 DEF_FIELD(symval
, pci_device_id
, vendor
);
428 DEF_FIELD(symval
, pci_device_id
, device
);
429 DEF_FIELD(symval
, pci_device_id
, subvendor
);
430 DEF_FIELD(symval
, pci_device_id
, subdevice
);
431 DEF_FIELD(symval
, pci_device_id
, class);
432 DEF_FIELD(symval
, pci_device_id
, class_mask
);
433 DEF_FIELD(symval
, pci_device_id
, override_only
);
435 switch (override_only
) {
437 strcpy(alias
, "pci:");
439 case PCI_ID_F_VFIO_DRIVER_OVERRIDE
:
440 strcpy(alias
, "vfio_pci:");
443 warn("Unknown PCI driver_override alias %08X\n",
447 ADD(alias
, "v", vendor
!= PCI_ANY_ID
, vendor
);
448 ADD(alias
, "d", device
!= PCI_ANY_ID
, device
);
449 ADD(alias
, "sv", subvendor
!= PCI_ANY_ID
, subvendor
);
450 ADD(alias
, "sd", subdevice
!= PCI_ANY_ID
, subdevice
);
452 baseclass
= (class) >> 16;
453 baseclass_mask
= (class_mask
) >> 16;
454 subclass
= (class) >> 8;
455 subclass_mask
= (class_mask
) >> 8;
457 interface_mask
= class_mask
;
459 if ((baseclass_mask
!= 0 && baseclass_mask
!= 0xFF)
460 || (subclass_mask
!= 0 && subclass_mask
!= 0xFF)
461 || (interface_mask
!= 0 && interface_mask
!= 0xFF)) {
462 warn("Can't handle masks in %s:%04X\n",
463 mod
->name
, class_mask
);
467 ADD(alias
, "bc", baseclass_mask
== 0xFF, baseclass
);
468 ADD(alias
, "sc", subclass_mask
== 0xFF, subclass
);
469 ADD(alias
, "i", interface_mask
== 0xFF, interface
);
471 module_alias_printf(mod
, true, "%s", alias
);
474 /* looks like: "ccw:tNmNdtNdmN" */
475 static void do_ccw_entry(struct module
*mod
, void *symval
)
477 char alias
[256] = {};
479 DEF_FIELD(symval
, ccw_device_id
, match_flags
);
480 DEF_FIELD(symval
, ccw_device_id
, cu_type
);
481 DEF_FIELD(symval
, ccw_device_id
, cu_model
);
482 DEF_FIELD(symval
, ccw_device_id
, dev_type
);
483 DEF_FIELD(symval
, ccw_device_id
, dev_model
);
485 ADD(alias
, "t", match_flags
&CCW_DEVICE_ID_MATCH_CU_TYPE
,
487 ADD(alias
, "m", match_flags
&CCW_DEVICE_ID_MATCH_CU_MODEL
,
489 ADD(alias
, "dt", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_TYPE
,
491 ADD(alias
, "dm", match_flags
&CCW_DEVICE_ID_MATCH_DEVICE_MODEL
,
494 module_alias_printf(mod
, true, "ccw:%s", alias
);
497 /* looks like: "ap:tN" */
498 static void do_ap_entry(struct module
*mod
, void *symval
)
500 DEF_FIELD(symval
, ap_device_id
, dev_type
);
502 module_alias_printf(mod
, false, "ap:t%02X*", dev_type
);
505 /* looks like: "css:tN" */
506 static void do_css_entry(struct module
*mod
, void *symval
)
508 DEF_FIELD(symval
, css_device_id
, type
);
510 module_alias_printf(mod
, false, "css:t%01X", type
);
513 /* Looks like: "serio:tyNprNidNexN" */
514 static void do_serio_entry(struct module
*mod
, void *symval
)
516 char alias
[256] = {};
518 DEF_FIELD(symval
, serio_device_id
, type
);
519 DEF_FIELD(symval
, serio_device_id
, proto
);
520 DEF_FIELD(symval
, serio_device_id
, id
);
521 DEF_FIELD(symval
, serio_device_id
, extra
);
523 ADD(alias
, "ty", type
!= SERIO_ANY
, type
);
524 ADD(alias
, "pr", proto
!= SERIO_ANY
, proto
);
525 ADD(alias
, "id", id
!= SERIO_ANY
, id
);
526 ADD(alias
, "ex", extra
!= SERIO_ANY
, extra
);
528 module_alias_printf(mod
, true, "serio:%s", alias
);
531 /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or
532 * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if)
534 * NOTE: Each driver should use one of the following : _HID, _CIDs
535 * or _CLS. Also, bb, ss, and pp can be substituted with ??
536 * as don't care byte.
538 static void do_acpi_entry(struct module
*mod
, void *symval
)
540 DEF_FIELD_ADDR(symval
, acpi_device_id
, id
);
541 DEF_FIELD(symval
, acpi_device_id
, cls
);
542 DEF_FIELD(symval
, acpi_device_id
, cls_msk
);
545 module_alias_printf(mod
, false, "acpi*:%s:*", *id
);
548 int i
, byte_shift
, cnt
= 0;
551 for (i
= 1; i
<= 3; i
++) {
552 byte_shift
= 8 * (3-i
);
553 msk
= (cls_msk
>> byte_shift
) & 0xFF;
555 sprintf(&alias
[cnt
], "%02x",
556 (cls
>> byte_shift
) & 0xFF);
558 sprintf(&alias
[cnt
], "??");
561 module_alias_printf(mod
, false, "acpi*:%s:*", alias
);
565 /* looks like: "pnp:dD" */
566 static void do_pnp_device_entry(struct module
*mod
, void *symval
)
568 DEF_FIELD_ADDR(symval
, pnp_device_id
, id
);
569 char acpi_id
[sizeof(*id
)];
571 /* fix broken pnp bus lowercasing */
572 for (unsigned int i
= 0; i
< sizeof(acpi_id
); i
++)
573 acpi_id
[i
] = toupper((*id
)[i
]);
574 module_alias_printf(mod
, false, "pnp:d%s*", *id
);
575 module_alias_printf(mod
, false, "acpi*:%s:*", acpi_id
);
578 /* looks like: "pnp:dD" for every device of the card */
579 static void do_pnp_card_entry(struct module
*mod
, void *symval
)
581 DEF_FIELD_ADDR(symval
, pnp_card_device_id
, devs
);
583 for (unsigned int i
= 0; i
< PNP_MAX_DEVICES
; i
++) {
584 const char *id
= (char *)(*devs
)[i
].id
;
585 char acpi_id
[PNP_ID_LEN
];
590 /* fix broken pnp bus lowercasing */
591 for (unsigned int j
= 0; j
< sizeof(acpi_id
); j
++)
592 acpi_id
[j
] = toupper(id
[j
]);
594 /* add an individual alias for every device entry */
595 module_alias_printf(mod
, false, "pnp:d%s*", id
);
596 module_alias_printf(mod
, false, "acpi*:%s:*", acpi_id
);
600 /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */
601 static void do_pcmcia_entry(struct module
*mod
, void *symval
)
603 char alias
[256] = {};
605 DEF_FIELD(symval
, pcmcia_device_id
, match_flags
);
606 DEF_FIELD(symval
, pcmcia_device_id
, manf_id
);
607 DEF_FIELD(symval
, pcmcia_device_id
, card_id
);
608 DEF_FIELD(symval
, pcmcia_device_id
, func_id
);
609 DEF_FIELD(symval
, pcmcia_device_id
, function
);
610 DEF_FIELD(symval
, pcmcia_device_id
, device_no
);
611 DEF_FIELD_ADDR(symval
, pcmcia_device_id
, prod_id_hash
);
613 ADD(alias
, "m", match_flags
& PCMCIA_DEV_ID_MATCH_MANF_ID
,
615 ADD(alias
, "c", match_flags
& PCMCIA_DEV_ID_MATCH_CARD_ID
,
617 ADD(alias
, "f", match_flags
& PCMCIA_DEV_ID_MATCH_FUNC_ID
,
619 ADD(alias
, "fn", match_flags
& PCMCIA_DEV_ID_MATCH_FUNCTION
,
621 ADD(alias
, "pfn", match_flags
& PCMCIA_DEV_ID_MATCH_DEVICE_NO
,
623 ADD(alias
, "pa", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID1
,
624 get_unaligned_native(*prod_id_hash
+ 0));
625 ADD(alias
, "pb", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID2
,
626 get_unaligned_native(*prod_id_hash
+ 1));
627 ADD(alias
, "pc", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID3
,
628 get_unaligned_native(*prod_id_hash
+ 2));
629 ADD(alias
, "pd", match_flags
& PCMCIA_DEV_ID_MATCH_PROD_ID4
,
630 get_unaligned_native(*prod_id_hash
+ 3));
632 module_alias_printf(mod
, true, "pcmcia:%s", alias
);
635 static void do_vio_entry(struct module
*mod
, void *symval
)
639 DEF_FIELD_ADDR(symval
, vio_device_id
, type
);
640 DEF_FIELD_ADDR(symval
, vio_device_id
, compat
);
642 sprintf(alias
, "vio:T%sS%s", (*type
)[0] ? *type
: "*",
643 (*compat
)[0] ? *compat
: "*");
645 /* Replace all whitespace with underscores */
646 for (tmp
= alias
; tmp
&& *tmp
; tmp
++)
650 module_alias_printf(mod
, true, "%s", alias
);
653 static void do_input(char *alias
,
654 kernel_ulong_t
*arr
, unsigned int min
, unsigned int max
)
658 for (i
= min
; i
<= max
; i
++)
659 if (get_unaligned_native(arr
+ i
/ BITS_PER_LONG
) &
660 (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
815 static void do_vmbus_entry(struct module
*mod
, void *symval
)
817 DEF_FIELD_ADDR(symval
, hv_vmbus_device_id
, guid
);
818 char guid_name
[sizeof(*guid
) * 2 + 1];
820 for (int i
= 0; i
< sizeof(*guid
); i
++)
821 sprintf(&guid_name
[i
* 2], "%02x", guid
->b
[i
]);
823 module_alias_printf(mod
, false, "vmbus:%s", guid_name
);
826 /* Looks like: rpmsg:S */
827 static void do_rpmsg_entry(struct module
*mod
, void *symval
)
829 DEF_FIELD_ADDR(symval
, rpmsg_device_id
, name
);
831 module_alias_printf(mod
, false, RPMSG_DEVICE_MODALIAS_FMT
, *name
);
834 /* Looks like: i2c:S */
835 static void do_i2c_entry(struct module
*mod
, void *symval
)
837 DEF_FIELD_ADDR(symval
, i2c_device_id
, name
);
839 module_alias_printf(mod
, false, I2C_MODULE_PREFIX
"%s", *name
);
842 static void do_i3c_entry(struct module
*mod
, void *symval
)
844 char alias
[256] = {};
846 DEF_FIELD(symval
, i3c_device_id
, match_flags
);
847 DEF_FIELD(symval
, i3c_device_id
, dcr
);
848 DEF_FIELD(symval
, i3c_device_id
, manuf_id
);
849 DEF_FIELD(symval
, i3c_device_id
, part_id
);
850 DEF_FIELD(symval
, i3c_device_id
, extra_info
);
852 ADD(alias
, "dcr", match_flags
& I3C_MATCH_DCR
, dcr
);
853 ADD(alias
, "manuf", match_flags
& I3C_MATCH_MANUF
, manuf_id
);
854 ADD(alias
, "part", match_flags
& I3C_MATCH_PART
, part_id
);
855 ADD(alias
, "ext", match_flags
& I3C_MATCH_EXTRA_INFO
, extra_info
);
857 module_alias_printf(mod
, false, "i3c:%s", alias
);
860 static void do_slim_entry(struct module
*mod
, void *symval
)
862 DEF_FIELD(symval
, slim_device_id
, manf_id
);
863 DEF_FIELD(symval
, slim_device_id
, prod_code
);
865 module_alias_printf(mod
, false, "slim:%x:%x:*", manf_id
, prod_code
);
868 /* Looks like: spi:S */
869 static void do_spi_entry(struct module
*mod
, void *symval
)
871 DEF_FIELD_ADDR(symval
, spi_device_id
, name
);
873 module_alias_printf(mod
, false, SPI_MODULE_PREFIX
"%s", *name
);
876 static const struct dmifield
{
880 { "bvn", DMI_BIOS_VENDOR
},
881 { "bvr", DMI_BIOS_VERSION
},
882 { "bd", DMI_BIOS_DATE
},
883 { "br", DMI_BIOS_RELEASE
},
884 { "efr", DMI_EC_FIRMWARE_RELEASE
},
885 { "svn", DMI_SYS_VENDOR
},
886 { "pn", DMI_PRODUCT_NAME
},
887 { "pvr", DMI_PRODUCT_VERSION
},
888 { "rvn", DMI_BOARD_VENDOR
},
889 { "rn", DMI_BOARD_NAME
},
890 { "rvr", DMI_BOARD_VERSION
},
891 { "cvn", DMI_CHASSIS_VENDOR
},
892 { "ct", DMI_CHASSIS_TYPE
},
893 { "cvr", DMI_CHASSIS_VERSION
},
897 static void dmi_ascii_filter(char *d
, const char *s
)
899 /* Filter out characters we don't want to see in the modalias string */
901 if (*s
> ' ' && *s
< 127 && *s
!= ':')
908 static void do_dmi_entry(struct module
*mod
, void *symval
)
910 char alias
[256] = {};
912 DEF_FIELD_ADDR(symval
, dmi_system_id
, matches
);
914 for (i
= 0; i
< ARRAY_SIZE(dmi_fields
); i
++) {
915 for (j
= 0; j
< 4; j
++) {
916 if ((*matches
)[j
].slot
&&
917 (*matches
)[j
].slot
== dmi_fields
[i
].field
) {
918 sprintf(alias
+ strlen(alias
), ":%s*",
919 dmi_fields
[i
].prefix
);
920 dmi_ascii_filter(alias
+ strlen(alias
),
921 (*matches
)[j
].substr
);
927 module_alias_printf(mod
, false, "dmi*%s:", alias
);
930 static void do_platform_entry(struct module
*mod
, void *symval
)
932 DEF_FIELD_ADDR(symval
, platform_device_id
, name
);
934 module_alias_printf(mod
, false, PLATFORM_MODULE_PREFIX
"%s", *name
);
937 static void do_mdio_entry(struct module
*mod
, void *symval
)
941 DEF_FIELD(symval
, mdio_device_id
, phy_id
);
942 DEF_FIELD(symval
, mdio_device_id
, phy_id_mask
);
944 for (i
= 0; i
< 32; i
++) {
945 if (!((phy_id_mask
>> (31-i
)) & 1))
947 else if ((phy_id
>> (31-i
)) & 1)
953 /* Terminate the string */
956 module_alias_printf(mod
, false, MDIO_MODULE_PREFIX
"%s", id
);
959 /* Looks like: zorro:iN. */
960 static void do_zorro_entry(struct module
*mod
, void *symval
)
962 char alias
[256] = {};
963 DEF_FIELD(symval
, zorro_device_id
, id
);
965 ADD(alias
, "i", id
!= ZORRO_WILDCARD
, id
);
967 module_alias_printf(mod
, false, "zorro:%s", alias
);
970 /* looks like: "pnp:dD" */
971 static void do_isapnp_entry(struct module
*mod
, void *symval
)
973 DEF_FIELD(symval
, isapnp_device_id
, vendor
);
974 DEF_FIELD(symval
, isapnp_device_id
, function
);
975 module_alias_printf(mod
, false, "pnp:d%c%c%c%x%x%x%x*",
976 'A' + ((vendor
>> 2) & 0x3f) - 1,
977 'A' + (((vendor
& 3) << 3) | ((vendor
>> 13) & 7)) - 1,
978 'A' + ((vendor
>> 8) & 0x1f) - 1,
979 (function
>> 4) & 0x0f, function
& 0x0f,
980 (function
>> 12) & 0x0f, (function
>> 8) & 0x0f);
983 /* Looks like: "ipack:fNvNdN". */
984 static void do_ipack_entry(struct module
*mod
, void *symval
)
986 char alias
[256] = {};
987 DEF_FIELD(symval
, ipack_device_id
, format
);
988 DEF_FIELD(symval
, ipack_device_id
, vendor
);
989 DEF_FIELD(symval
, ipack_device_id
, device
);
991 ADD(alias
, "f", format
!= IPACK_ANY_FORMAT
, format
);
992 ADD(alias
, "v", vendor
!= IPACK_ANY_ID
, vendor
);
993 ADD(alias
, "d", device
!= IPACK_ANY_ID
, device
);
995 module_alias_printf(mod
, true, "ipack:%s", alias
);
999 * Append a match expression for a single masked hex digit.
1000 * outp points to a pointer to the character at which to append.
1001 * *outp is updated on return to point just after the appended text,
1002 * to facilitate further appending.
1004 static void append_nibble_mask(char **outp
,
1005 unsigned int nibble
, unsigned int mask
)
1016 p
+= sprintf(p
, "%X", nibble
);
1021 * Dumbly emit a match pattern for all possible matching
1022 * digits. This could be improved in some cases using ranges,
1023 * but it has the advantage of being trivially correct, and is
1027 for (i
= 0; i
< 0x10; i
++)
1028 if ((i
& mask
) == nibble
)
1029 p
+= sprintf(p
, "%X", i
);
1033 /* Ensure that the string remains NUL-terminated: */
1036 /* Advance the caller's end-of-string pointer: */
1041 * looks like: "amba:dN"
1043 * N is exactly 8 digits, where each is an upper-case hex digit, or
1044 * a ? or [] pattern matching exactly one digit.
1046 static void do_amba_entry(struct module
*mod
, void *symval
)
1051 DEF_FIELD(symval
, amba_id
, id
);
1052 DEF_FIELD(symval
, amba_id
, mask
);
1054 if ((id
& mask
) != id
)
1055 fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: id=0x%08X, mask=0x%08X. Please fix this driver.\n",
1056 mod
->name
, id
, mask
);
1058 for (digit
= 0; digit
< 8; digit
++)
1059 append_nibble_mask(&p
,
1060 (id
>> (4 * (7 - digit
))) & 0xf,
1061 (mask
>> (4 * (7 - digit
))) & 0xf);
1063 module_alias_printf(mod
, false, "amba:d%s", alias
);
1067 * looks like: "mipscdmm:tN"
1069 * N is exactly 2 digits, where each is an upper-case hex digit, or
1070 * a ? or [] pattern matching exactly one digit.
1072 static void do_mips_cdmm_entry(struct module
*mod
, void *symval
)
1074 DEF_FIELD(symval
, mips_cdmm_device_id
, type
);
1076 module_alias_printf(mod
, false, "mipscdmm:t%02X*", type
);
1079 /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,*
1080 * All fields are numbers. It would be nicer to use strings for vendor
1081 * and feature, but getting those out of the build system here is too
1085 static void do_x86cpu_entry(struct module
*mod
, void *symval
)
1087 char alias
[256] = {};
1089 DEF_FIELD(symval
, x86_cpu_id
, feature
);
1090 DEF_FIELD(symval
, x86_cpu_id
, family
);
1091 DEF_FIELD(symval
, x86_cpu_id
, model
);
1092 DEF_FIELD(symval
, x86_cpu_id
, vendor
);
1094 ADD(alias
, "ven", vendor
!= X86_VENDOR_ANY
, vendor
);
1095 ADD(alias
, "fam", family
!= X86_FAMILY_ANY
, family
);
1096 ADD(alias
, "mod", model
!= X86_MODEL_ANY
, model
);
1097 strcat(alias
, ":feature:*");
1098 if (feature
!= X86_FEATURE_ANY
)
1099 sprintf(alias
+ strlen(alias
), "%04X*", feature
);
1101 module_alias_printf(mod
, false, "cpu:type:x86,%s", alias
);
1104 /* LOOKS like cpu:type:*:feature:*FEAT* */
1105 static void do_cpu_entry(struct module
*mod
, void *symval
)
1107 DEF_FIELD(symval
, cpu_feature
, feature
);
1109 module_alias_printf(mod
, false, "cpu:type:*:feature:*%04X*", feature
);
1112 /* Looks like: mei:S:uuid:N:* */
1113 static void do_mei_entry(struct module
*mod
, void *symval
)
1115 char alias
[256] = {};
1117 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, name
);
1118 DEF_FIELD_ADDR(symval
, mei_cl_device_id
, uuid
);
1119 DEF_FIELD(symval
, mei_cl_device_id
, version
);
1121 add_uuid(alias
, *uuid
);
1122 ADD(alias
, ":", version
!= MEI_CL_VERSION_ANY
, version
);
1124 module_alias_printf(mod
, false, MEI_CL_MODULE_PREFIX
"%s:%s:*",
1125 (*name
)[0] ? *name
: "*", alias
);
1128 /* Looks like: rapidio:vNdNavNadN */
1129 static void do_rio_entry(struct module
*mod
, void *symval
)
1131 char alias
[256] = {};
1133 DEF_FIELD(symval
, rio_device_id
, did
);
1134 DEF_FIELD(symval
, rio_device_id
, vid
);
1135 DEF_FIELD(symval
, rio_device_id
, asm_did
);
1136 DEF_FIELD(symval
, rio_device_id
, asm_vid
);
1138 ADD(alias
, "v", vid
!= RIO_ANY_ID
, vid
);
1139 ADD(alias
, "d", did
!= RIO_ANY_ID
, did
);
1140 ADD(alias
, "av", asm_vid
!= RIO_ANY_ID
, asm_vid
);
1141 ADD(alias
, "ad", asm_did
!= RIO_ANY_ID
, asm_did
);
1143 module_alias_printf(mod
, true, "rapidio:%s", alias
);
1146 /* Looks like: ulpi:vNpN */
1147 static void do_ulpi_entry(struct module
*mod
, void *symval
)
1149 DEF_FIELD(symval
, ulpi_device_id
, vendor
);
1150 DEF_FIELD(symval
, ulpi_device_id
, product
);
1152 module_alias_printf(mod
, false, "ulpi:v%04xp%04x", vendor
, product
);
1155 /* Looks like: hdaudio:vNrNaN */
1156 static void do_hda_entry(struct module
*mod
, void *symval
)
1158 char alias
[256] = {};
1160 DEF_FIELD(symval
, hda_device_id
, vendor_id
);
1161 DEF_FIELD(symval
, hda_device_id
, rev_id
);
1162 DEF_FIELD(symval
, hda_device_id
, api_version
);
1164 ADD(alias
, "v", vendor_id
!= 0, vendor_id
);
1165 ADD(alias
, "r", rev_id
!= 0, rev_id
);
1166 ADD(alias
, "a", api_version
!= 0, api_version
);
1168 module_alias_printf(mod
, true, "hdaudio:%s", alias
);
1171 /* Looks like: sdw:mNpNvNcN */
1172 static void do_sdw_entry(struct module
*mod
, void *symval
)
1174 char alias
[256] = {};
1176 DEF_FIELD(symval
, sdw_device_id
, mfg_id
);
1177 DEF_FIELD(symval
, sdw_device_id
, part_id
);
1178 DEF_FIELD(symval
, sdw_device_id
, sdw_version
);
1179 DEF_FIELD(symval
, sdw_device_id
, class_id
);
1181 ADD(alias
, "m", mfg_id
!= 0, mfg_id
);
1182 ADD(alias
, "p", part_id
!= 0, part_id
);
1183 ADD(alias
, "v", sdw_version
!= 0, sdw_version
);
1184 ADD(alias
, "c", class_id
!= 0, class_id
);
1186 module_alias_printf(mod
, true, "sdw:%s", alias
);
1189 /* Looks like: fsl-mc:vNdN */
1190 static void do_fsl_mc_entry(struct module
*mod
, void *symval
)
1192 DEF_FIELD(symval
, fsl_mc_device_id
, vendor
);
1193 DEF_FIELD_ADDR(symval
, fsl_mc_device_id
, obj_type
);
1195 module_alias_printf(mod
, false, "fsl-mc:v%08Xd%s", vendor
, *obj_type
);
1198 /* Looks like: tbsvc:kSpNvNrN */
1199 static void do_tbsvc_entry(struct module
*mod
, void *symval
)
1201 char alias
[256] = {};
1203 DEF_FIELD(symval
, tb_service_id
, match_flags
);
1204 DEF_FIELD_ADDR(symval
, tb_service_id
, protocol_key
);
1205 DEF_FIELD(symval
, tb_service_id
, protocol_id
);
1206 DEF_FIELD(symval
, tb_service_id
, protocol_version
);
1207 DEF_FIELD(symval
, tb_service_id
, protocol_revision
);
1209 if (match_flags
& TBSVC_MATCH_PROTOCOL_KEY
)
1210 sprintf(alias
+ strlen(alias
), "k%s", *protocol_key
);
1212 strcat(alias
+ strlen(alias
), "k*");
1213 ADD(alias
, "p", match_flags
& TBSVC_MATCH_PROTOCOL_ID
, protocol_id
);
1214 ADD(alias
, "v", match_flags
& TBSVC_MATCH_PROTOCOL_VERSION
,
1216 ADD(alias
, "r", match_flags
& TBSVC_MATCH_PROTOCOL_REVISION
,
1219 module_alias_printf(mod
, true, "tbsvc:%s", alias
);
1222 /* Looks like: typec:idN */
1223 static void do_typec_entry(struct module
*mod
, void *symval
)
1225 DEF_FIELD(symval
, typec_device_id
, svid
);
1227 module_alias_printf(mod
, false, "typec:id%04X", svid
);
1230 /* Looks like: tee:uuid */
1231 static void do_tee_entry(struct module
*mod
, void *symval
)
1233 DEF_FIELD_ADDR(symval
, tee_client_device_id
, uuid
);
1235 module_alias_printf(mod
, true,
1236 "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x",
1237 uuid
->b
[0], uuid
->b
[1], uuid
->b
[2], uuid
->b
[3], uuid
->b
[4],
1238 uuid
->b
[5], uuid
->b
[6], uuid
->b
[7], uuid
->b
[8], uuid
->b
[9],
1239 uuid
->b
[10], uuid
->b
[11], uuid
->b
[12], uuid
->b
[13], uuid
->b
[14],
1243 /* Looks like: wmi:guid */
1244 static void do_wmi_entry(struct module
*mod
, void *symval
)
1246 DEF_FIELD_ADDR(symval
, wmi_device_id
, guid_string
);
1248 if (strlen(*guid_string
) != UUID_STRING_LEN
) {
1249 warn("Invalid WMI device id 'wmi:%s' in '%s'\n",
1250 *guid_string
, mod
->name
);
1254 module_alias_printf(mod
, false, WMI_MODULE_PREFIX
"%s", *guid_string
);
1257 /* Looks like: mhi:S */
1258 static void do_mhi_entry(struct module
*mod
, void *symval
)
1260 DEF_FIELD_ADDR(symval
, mhi_device_id
, chan
);
1261 module_alias_printf(mod
, false, MHI_DEVICE_MODALIAS_FMT
, *chan
);
1264 /* Looks like: mhi_ep:S */
1265 static void do_mhi_ep_entry(struct module
*mod
, void *symval
)
1267 DEF_FIELD_ADDR(symval
, mhi_device_id
, chan
);
1269 module_alias_printf(mod
, false, MHI_EP_DEVICE_MODALIAS_FMT
, *chan
);
1272 /* Looks like: ishtp:{guid} */
1273 static void do_ishtp_entry(struct module
*mod
, void *symval
)
1275 char alias
[256] = {};
1276 DEF_FIELD_ADDR(symval
, ishtp_device_id
, guid
);
1278 add_guid(alias
, *guid
);
1280 module_alias_printf(mod
, false, ISHTP_MODULE_PREFIX
"{%s}", alias
);
1283 static void do_auxiliary_entry(struct module
*mod
, void *symval
)
1285 DEF_FIELD_ADDR(symval
, auxiliary_device_id
, name
);
1287 module_alias_printf(mod
, false, AUXILIARY_MODULE_PREFIX
"%s", *name
);
1291 * Looks like: ssam:dNcNtNiNfN
1293 * N is exactly 2 digits, where each is an upper-case hex digit.
1295 static void do_ssam_entry(struct module
*mod
, void *symval
)
1297 char alias
[256] = {};
1299 DEF_FIELD(symval
, ssam_device_id
, match_flags
);
1300 DEF_FIELD(symval
, ssam_device_id
, domain
);
1301 DEF_FIELD(symval
, ssam_device_id
, category
);
1302 DEF_FIELD(symval
, ssam_device_id
, target
);
1303 DEF_FIELD(symval
, ssam_device_id
, instance
);
1304 DEF_FIELD(symval
, ssam_device_id
, function
);
1306 ADD(alias
, "t", match_flags
& SSAM_MATCH_TARGET
, target
);
1307 ADD(alias
, "i", match_flags
& SSAM_MATCH_INSTANCE
, instance
);
1308 ADD(alias
, "f", match_flags
& SSAM_MATCH_FUNCTION
, function
);
1310 module_alias_printf(mod
, false, "ssam:d%02Xc%02X%s",
1311 domain
, category
, alias
);
1314 /* Looks like: dfl:tNfN */
1315 static void do_dfl_entry(struct module
*mod
, void *symval
)
1317 DEF_FIELD(symval
, dfl_device_id
, type
);
1318 DEF_FIELD(symval
, dfl_device_id
, feature_id
);
1320 module_alias_printf(mod
, true, "dfl:t%04Xf%04X", type
, feature_id
);
1323 /* Looks like: cdx:vNdN */
1324 static void do_cdx_entry(struct module
*mod
, void *symval
)
1328 DEF_FIELD(symval
, cdx_device_id
, vendor
);
1329 DEF_FIELD(symval
, cdx_device_id
, device
);
1330 DEF_FIELD(symval
, cdx_device_id
, subvendor
);
1331 DEF_FIELD(symval
, cdx_device_id
, subdevice
);
1332 DEF_FIELD(symval
, cdx_device_id
, class);
1333 DEF_FIELD(symval
, cdx_device_id
, class_mask
);
1334 DEF_FIELD(symval
, cdx_device_id
, override_only
);
1336 switch (override_only
) {
1338 strcpy(alias
, "cdx:");
1340 case CDX_ID_F_VFIO_DRIVER_OVERRIDE
:
1341 strcpy(alias
, "vfio_cdx:");
1344 warn("Unknown CDX driver_override alias %08X\n",
1349 ADD(alias
, "v", vendor
!= CDX_ANY_ID
, vendor
);
1350 ADD(alias
, "d", device
!= CDX_ANY_ID
, device
);
1351 ADD(alias
, "sv", subvendor
!= CDX_ANY_ID
, subvendor
);
1352 ADD(alias
, "sd", subdevice
!= CDX_ANY_ID
, subdevice
);
1353 ADD(alias
, "c", class_mask
== 0xFFFFFF, class);
1355 module_alias_printf(mod
, false, "%s", alias
);
1358 static void do_vchiq_entry(struct module
*mod
, void *symval
)
1360 DEF_FIELD_ADDR(symval
, vchiq_device_id
, name
);
1362 module_alias_printf(mod
, false, "vchiq:%s", *name
);
1365 /* Looks like: coreboot:tN */
1366 static void do_coreboot_entry(struct module
*mod
, void *symval
)
1368 DEF_FIELD(symval
, coreboot_device_id
, tag
);
1370 module_alias_printf(mod
, false, "coreboot:t%08X", tag
);
1373 /* Does namelen bytes of name exactly match the symbol? */
1374 static bool sym_is(const char *name
, unsigned namelen
, const char *symbol
)
1376 if (namelen
!= strlen(symbol
))
1379 return memcmp(name
, symbol
, namelen
) == 0;
1382 static void do_table(const char *name
, void *symval
, unsigned long size
,
1383 unsigned long id_size
,
1384 const char *device_id
,
1385 void (*do_entry
)(struct module
*mod
, void *symval
),
1390 if (size
% id_size
|| size
< id_size
) {
1391 error("%s: type mismatch between %s[] and MODULE_DEVICE_TABLE(%s, ...)\n",
1392 mod
->name
, name
, device_id
);
1396 /* Verify the last entry is a terminator */
1397 for (i
= size
- id_size
; i
< size
; i
++) {
1398 if (*(uint8_t *)(symval
+ i
)) {
1399 error("%s: %s[] is not terminated with a NULL entry\n",
1405 /* Leave last one: it's the terminator. */
1408 for (i
= 0; i
< size
; i
+= id_size
)
1409 do_entry(mod
, symval
+ i
);
1412 static const struct devtable devtable
[] = {
1413 {"hid", SIZE_hid_device_id
, do_hid_entry
},
1414 {"ieee1394", SIZE_ieee1394_device_id
, do_ieee1394_entry
},
1415 {"pci", SIZE_pci_device_id
, do_pci_entry
},
1416 {"ccw", SIZE_ccw_device_id
, do_ccw_entry
},
1417 {"ap", SIZE_ap_device_id
, do_ap_entry
},
1418 {"css", SIZE_css_device_id
, do_css_entry
},
1419 {"serio", SIZE_serio_device_id
, do_serio_entry
},
1420 {"acpi", SIZE_acpi_device_id
, do_acpi_entry
},
1421 {"pcmcia", SIZE_pcmcia_device_id
, do_pcmcia_entry
},
1422 {"vio", SIZE_vio_device_id
, do_vio_entry
},
1423 {"input", SIZE_input_device_id
, do_input_entry
},
1424 {"eisa", SIZE_eisa_device_id
, do_eisa_entry
},
1425 {"parisc", SIZE_parisc_device_id
, do_parisc_entry
},
1426 {"sdio", SIZE_sdio_device_id
, do_sdio_entry
},
1427 {"ssb", SIZE_ssb_device_id
, do_ssb_entry
},
1428 {"bcma", SIZE_bcma_device_id
, do_bcma_entry
},
1429 {"virtio", SIZE_virtio_device_id
, do_virtio_entry
},
1430 {"vmbus", SIZE_hv_vmbus_device_id
, do_vmbus_entry
},
1431 {"rpmsg", SIZE_rpmsg_device_id
, do_rpmsg_entry
},
1432 {"i2c", SIZE_i2c_device_id
, do_i2c_entry
},
1433 {"i3c", SIZE_i3c_device_id
, do_i3c_entry
},
1434 {"slim", SIZE_slim_device_id
, do_slim_entry
},
1435 {"spi", SIZE_spi_device_id
, do_spi_entry
},
1436 {"dmi", SIZE_dmi_system_id
, do_dmi_entry
},
1437 {"platform", SIZE_platform_device_id
, do_platform_entry
},
1438 {"mdio", SIZE_mdio_device_id
, do_mdio_entry
},
1439 {"zorro", SIZE_zorro_device_id
, do_zorro_entry
},
1440 {"isapnp", SIZE_isapnp_device_id
, do_isapnp_entry
},
1441 {"ipack", SIZE_ipack_device_id
, do_ipack_entry
},
1442 {"amba", SIZE_amba_id
, do_amba_entry
},
1443 {"mipscdmm", SIZE_mips_cdmm_device_id
, do_mips_cdmm_entry
},
1444 {"x86cpu", SIZE_x86_cpu_id
, do_x86cpu_entry
},
1445 {"cpu", SIZE_cpu_feature
, do_cpu_entry
},
1446 {"mei", SIZE_mei_cl_device_id
, do_mei_entry
},
1447 {"rapidio", SIZE_rio_device_id
, do_rio_entry
},
1448 {"ulpi", SIZE_ulpi_device_id
, do_ulpi_entry
},
1449 {"hdaudio", SIZE_hda_device_id
, do_hda_entry
},
1450 {"sdw", SIZE_sdw_device_id
, do_sdw_entry
},
1451 {"fslmc", SIZE_fsl_mc_device_id
, do_fsl_mc_entry
},
1452 {"tbsvc", SIZE_tb_service_id
, do_tbsvc_entry
},
1453 {"typec", SIZE_typec_device_id
, do_typec_entry
},
1454 {"tee", SIZE_tee_client_device_id
, do_tee_entry
},
1455 {"wmi", SIZE_wmi_device_id
, do_wmi_entry
},
1456 {"mhi", SIZE_mhi_device_id
, do_mhi_entry
},
1457 {"mhi_ep", SIZE_mhi_device_id
, do_mhi_ep_entry
},
1458 {"auxiliary", SIZE_auxiliary_device_id
, do_auxiliary_entry
},
1459 {"ssam", SIZE_ssam_device_id
, do_ssam_entry
},
1460 {"dfl", SIZE_dfl_device_id
, do_dfl_entry
},
1461 {"ishtp", SIZE_ishtp_device_id
, do_ishtp_entry
},
1462 {"cdx", SIZE_cdx_device_id
, do_cdx_entry
},
1463 {"vchiq", SIZE_vchiq_device_id
, do_vchiq_entry
},
1464 {"coreboot", SIZE_coreboot_device_id
, do_coreboot_entry
},
1465 {"of", SIZE_of_device_id
, do_of_entry
},
1466 {"usb", SIZE_usb_device_id
, do_usb_entry_multi
},
1467 {"pnp", SIZE_pnp_device_id
, do_pnp_device_entry
},
1468 {"pnp_card", SIZE_pnp_card_device_id
, do_pnp_card_entry
},
1471 /* Create MODULE_ALIAS() statements.
1472 * At this time, we cannot write the actual output C source yet,
1473 * so we write into the mod->dev_table_buf buffer. */
1474 void handle_moddevtable(struct module
*mod
, struct elf_info
*info
,
1475 Elf_Sym
*sym
, const char *symname
)
1479 const char *type
, *name
;
1481 static const char *prefix
= "__mod_device_table__";
1483 /* We're looking for a section relative symbol */
1484 if (!sym
->st_shndx
|| get_secindex(info
, sym
) >= info
->num_sections
)
1487 /* We're looking for an object */
1488 if (ELF_ST_TYPE(sym
->st_info
) != STT_OBJECT
)
1491 /* All our symbols are of form __mod_device_table__<type>__<name>. */
1492 if (!strstarts(symname
, prefix
))
1494 type
= symname
+ strlen(prefix
);
1496 name
= strstr(type
, "__");
1499 typelen
= name
- type
;
1500 name
+= strlen("__");
1502 /* Handle all-NULL symbols allocated into .bss */
1503 if (info
->sechdrs
[get_secindex(info
, sym
)].sh_type
& SHT_NOBITS
) {
1504 zeros
= calloc(1, sym
->st_size
);
1507 symval
= sym_get_data(info
, sym
);
1510 for (int i
= 0; i
< ARRAY_SIZE(devtable
); i
++) {
1511 const struct devtable
*p
= &devtable
[i
];
1513 if (sym_is(type
, typelen
, p
->device_id
)) {
1514 do_table(name
, symval
, sym
->st_size
, p
->id_size
,
1515 p
->device_id
, p
->do_entry
, mod
);