Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
| 4 | * |
| 5 | * Copyright 2002-2003 Rusty Russell, IBM Corporation |
| 6 | * 2003 Kai Germaschewski |
| 7 | * |
| 8 | * |
| 9 | * This software may be used and distributed according to the terms |
| 10 | * of the GNU General Public License, incorporated herein by reference. |
| 11 | */ |
| 12 | |
| 13 | #include "modpost.h" |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 14 | #include "devicetable-offsets.h" |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 15 | |
| 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; |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 20 | #define BITS_PER_LONG 32 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 21 | #else |
| 22 | typedef Elf64_Addr kernel_ulong_t; |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 23 | #define BITS_PER_LONG 64 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 24 | #endif |
| 25 | #ifdef __sun__ |
| 26 | #include <inttypes.h> |
| 27 | #else |
| 28 | #include <stdint.h> |
| 29 | #endif |
| 30 | |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 31 | #include <ctype.h> |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 32 | #include <stdbool.h> |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 33 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | typedef uint32_t __u32; |
| 35 | typedef uint16_t __u16; |
| 36 | typedef unsigned char __u8; |
Greg Kroah-Hartman | b144ce2 | 2015-05-27 17:17:27 -0700 | [diff] [blame] | 37 | typedef struct { |
| 38 | __u8 b[16]; |
Heikki Krogerus | 389c9af | 2019-08-27 14:14:37 +0300 | [diff] [blame] | 39 | } guid_t; |
| 40 | |
| 41 | /* backwards compatibility, don't use in new code */ |
| 42 | typedef struct { |
| 43 | __u8 b[16]; |
Greg Kroah-Hartman | b144ce2 | 2015-05-27 17:17:27 -0700 | [diff] [blame] | 44 | } uuid_le; |
Sumit Garg | 0fc1db9 | 2019-01-29 11:19:35 +0530 | [diff] [blame] | 45 | typedef struct { |
| 46 | __u8 b[16]; |
| 47 | } uuid_t; |
Mattias Jacobsson | eacc95e | 2019-02-19 20:59:49 +0100 | [diff] [blame] | 48 | #define UUID_STRING_LEN 36 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | |
| 50 | /* Big exception to the "don't include kernel headers into userspace, which |
Sam Ravnborg | 62070fa | 2006-03-03 16:46:04 +0100 | [diff] [blame] | 51 | * even potentially has different endianness and word sizes, since |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | * we handle those differences explicitly below */ |
| 53 | #include "../../include/linux/mod_devicetable.h" |
| 54 | |
Rusty Russell | e49ce14 | 2012-01-13 09:32:16 +1030 | [diff] [blame] | 55 | /* This array collects all instances that use the generic do_table */ |
| 56 | struct devtable { |
Tom Gundersen | 21bdd17 | 2014-02-03 11:14:13 +1030 | [diff] [blame] | 57 | const char *device_id; /* name of table, __mod_<name>__*_device_table. */ |
Rusty Russell | e49ce14 | 2012-01-13 09:32:16 +1030 | [diff] [blame] | 58 | unsigned long id_size; |
Masahiro Yamada | f880eea | 2018-11-22 13:28:42 +0900 | [diff] [blame] | 59 | int (*do_entry)(const char *filename, void *symval, char *alias); |
Rusty Russell | e49ce14 | 2012-01-13 09:32:16 +1030 | [diff] [blame] | 60 | }; |
| 61 | |
Mattias Jacobsson | 841f1b8 | 2019-02-07 13:30:22 +0100 | [diff] [blame] | 62 | /* Size of alias provided to do_entry functions */ |
| 63 | #define ALIAS_SIZE 500 |
| 64 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 65 | /* Define a variable f that holds the value of field f of struct devid |
| 66 | * based at address m. |
| 67 | */ |
| 68 | #define DEF_FIELD(m, devid, f) \ |
| 69 | typeof(((struct devid *)0)->f) f = TO_NATIVE(*(typeof(f) *)((m) + OFF_##devid##_##f)) |
Leonardo Bras | c2b1a92 | 2018-10-24 01:03:52 -0300 | [diff] [blame] | 70 | |
| 71 | /* Define a variable v that holds the address of field f of struct devid |
| 72 | * based at address m. Due to the way typeof works, for a field of type |
| 73 | * T[N] the variable has type T(*)[N], _not_ T*. |
| 74 | */ |
| 75 | #define DEF_FIELD_ADDR_VAR(m, devid, f, v) \ |
| 76 | typeof(((struct devid *)0)->f) *v = ((m) + OFF_##devid##_##f) |
| 77 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 78 | /* Define a variable f that holds the address of field f of struct devid |
| 79 | * based at address m. Due to the way typeof works, for a field of type |
| 80 | * T[N] the variable has type T(*)[N], _not_ T*. |
| 81 | */ |
| 82 | #define DEF_FIELD_ADDR(m, devid, f) \ |
Leonardo Bras | c2b1a92 | 2018-10-24 01:03:52 -0300 | [diff] [blame] | 83 | DEF_FIELD_ADDR_VAR(m, devid, f, f) |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 84 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | #define ADD(str, sep, cond, field) \ |
| 86 | do { \ |
| 87 | strcat(str, sep); \ |
| 88 | if (cond) \ |
| 89 | sprintf(str + strlen(str), \ |
| 90 | sizeof(field) == 1 ? "%02X" : \ |
| 91 | sizeof(field) == 2 ? "%04X" : \ |
| 92 | sizeof(field) == 4 ? "%08X" : "", \ |
| 93 | field); \ |
| 94 | else \ |
| 95 | sprintf(str + strlen(str), "*"); \ |
| 96 | } while(0) |
| 97 | |
Javier Martinez Canillas | 2f63236 | 2016-01-14 15:17:02 -0800 | [diff] [blame] | 98 | /* End in a wildcard, for future extension */ |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 99 | static inline void add_wildcard(char *str) |
| 100 | { |
| 101 | int len = strlen(str); |
| 102 | |
| 103 | if (str[len - 1] != '*') |
| 104 | strcat(str + len, "*"); |
| 105 | } |
| 106 | |
Greg Kroah-Hartman | b144ce2 | 2015-05-27 17:17:27 -0700 | [diff] [blame] | 107 | static inline void add_uuid(char *str, uuid_le uuid) |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 108 | { |
| 109 | int len = strlen(str); |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 110 | |
Prarit Bhargava | 59796ed | 2015-09-10 10:17:59 +0300 | [diff] [blame] | 111 | sprintf(str + len, "%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
| 112 | uuid.b[3], uuid.b[2], uuid.b[1], uuid.b[0], |
| 113 | uuid.b[5], uuid.b[4], uuid.b[7], uuid.b[6], |
| 114 | uuid.b[8], uuid.b[9], uuid.b[10], uuid.b[11], |
| 115 | uuid.b[12], uuid.b[13], uuid.b[14], uuid.b[15]); |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 116 | } |
| 117 | |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 118 | /** |
| 119 | * Check that sizeof(device_id type) are consistent with size of section |
| 120 | * in .o file. If in-consistent then userspace and kernel does not agree |
| 121 | * on actual size which is a bug. |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 122 | * Also verify that the final entry in the table is all zeros. |
Sam Ravnborg | 4ce6efe | 2008-03-23 21:38:54 +0100 | [diff] [blame] | 123 | * Ignore both checks if build host differ from target host and size differs. |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 124 | **/ |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 125 | static void device_id_check(const char *modname, const char *device_id, |
| 126 | unsigned long size, unsigned long id_size, |
| 127 | void *symval) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 128 | { |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 129 | int i; |
| 130 | |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 131 | if (size % id_size || size < id_size) { |
| 132 | fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo " |
Tom Gundersen | 21bdd17 | 2014-02-03 11:14:13 +1030 | [diff] [blame] | 133 | "of the size of " |
| 134 | "section __mod_%s__<identifier>_device_table=%lu.\n" |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 135 | "Fix definition of struct %s_device_id " |
| 136 | "in mod_devicetable.h\n", |
| 137 | modname, device_id, id_size, device_id, size, device_id); |
| 138 | } |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 139 | /* Verify last one is a terminator */ |
| 140 | for (i = 0; i < id_size; i++ ) { |
| 141 | if (*(uint8_t*)(symval+size-id_size+i)) { |
| 142 | fprintf(stderr,"%s: struct %s_device_id is %lu bytes. " |
| 143 | "The last of %lu is:\n", |
| 144 | modname, device_id, id_size, size / id_size); |
| 145 | for (i = 0; i < id_size; i++ ) |
| 146 | fprintf(stderr,"0x%02x ", |
| 147 | *(uint8_t*)(symval+size-id_size+i) ); |
| 148 | fprintf(stderr,"\n"); |
| 149 | fatal("%s: struct %s_device_id is not terminated " |
| 150 | "with a NULL entry!\n", modname, device_id); |
| 151 | } |
| 152 | } |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 153 | } |
| 154 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 155 | /* USB is special because the bcdDevice can be matched against a numeric range */ |
Bjørn Mork | 81df2d5 | 2012-05-18 21:27:43 +0200 | [diff] [blame] | 156 | /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 157 | static void do_usb_entry(void *symval, |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 158 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, |
| 159 | unsigned char range_lo, unsigned char range_hi, |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 160 | unsigned char max, struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | { |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 162 | char alias[500]; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 163 | DEF_FIELD(symval, usb_device_id, match_flags); |
| 164 | DEF_FIELD(symval, usb_device_id, idVendor); |
| 165 | DEF_FIELD(symval, usb_device_id, idProduct); |
| 166 | DEF_FIELD(symval, usb_device_id, bcdDevice_lo); |
| 167 | DEF_FIELD(symval, usb_device_id, bDeviceClass); |
| 168 | DEF_FIELD(symval, usb_device_id, bDeviceSubClass); |
| 169 | DEF_FIELD(symval, usb_device_id, bDeviceProtocol); |
| 170 | DEF_FIELD(symval, usb_device_id, bInterfaceClass); |
| 171 | DEF_FIELD(symval, usb_device_id, bInterfaceSubClass); |
| 172 | DEF_FIELD(symval, usb_device_id, bInterfaceProtocol); |
| 173 | DEF_FIELD(symval, usb_device_id, bInterfaceNumber); |
| 174 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | strcpy(alias, "usb:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 176 | ADD(alias, "v", match_flags&USB_DEVICE_ID_MATCH_VENDOR, |
| 177 | idVendor); |
| 178 | ADD(alias, "p", match_flags&USB_DEVICE_ID_MATCH_PRODUCT, |
| 179 | idProduct); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 180 | |
| 181 | strcat(alias, "d"); |
| 182 | if (bcdDevice_initial_digits) |
| 183 | sprintf(alias + strlen(alias), "%0*X", |
| 184 | bcdDevice_initial_digits, bcdDevice_initial); |
| 185 | if (range_lo == range_hi) |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 186 | sprintf(alias + strlen(alias), "%X", range_lo); |
| 187 | else if (range_lo > 0 || range_hi < max) { |
| 188 | if (range_lo > 0x9 || range_hi < 0xA) |
| 189 | sprintf(alias + strlen(alias), |
| 190 | "[%X-%X]", |
| 191 | range_lo, |
| 192 | range_hi); |
| 193 | else { |
| 194 | sprintf(alias + strlen(alias), |
| 195 | range_lo < 0x9 ? "[%X-9" : "[%X", |
| 196 | range_lo); |
| 197 | sprintf(alias + strlen(alias), |
Jan Moskyto Matejka | 03b5632 | 2014-02-07 19:15:11 +0100 | [diff] [blame] | 198 | range_hi > 0xA ? "A-%X]" : "%X]", |
| 199 | range_hi); |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 200 | } |
| 201 | } |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 202 | if (bcdDevice_initial_digits < (sizeof(bcdDevice_lo) * 2 - 1)) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 203 | strcat(alias, "*"); |
| 204 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 205 | ADD(alias, "dc", match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS, |
| 206 | bDeviceClass); |
| 207 | ADD(alias, "dsc", match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS, |
| 208 | bDeviceSubClass); |
| 209 | ADD(alias, "dp", match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL, |
| 210 | bDeviceProtocol); |
| 211 | ADD(alias, "ic", match_flags&USB_DEVICE_ID_MATCH_INT_CLASS, |
| 212 | bInterfaceClass); |
| 213 | ADD(alias, "isc", match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS, |
| 214 | bInterfaceSubClass); |
| 215 | ADD(alias, "ip", match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL, |
| 216 | bInterfaceProtocol); |
| 217 | ADD(alias, "in", match_flags&USB_DEVICE_ID_MATCH_INT_NUMBER, |
| 218 | bInterfaceNumber); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 219 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 220 | add_wildcard(alias); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 221 | buf_printf(&mod->dev_table_buf, |
| 222 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 223 | } |
| 224 | |
Nathaniel McCallum | 55f49f2 | 2009-11-18 20:15:28 -0500 | [diff] [blame] | 225 | /* Handles increment/decrement of BCD formatted integers */ |
| 226 | /* Returns the previous value, so it works like i++ or i-- */ |
| 227 | static unsigned int incbcd(unsigned int *bcd, |
| 228 | int inc, |
| 229 | unsigned char max, |
| 230 | size_t chars) |
| 231 | { |
| 232 | unsigned int init = *bcd, i, j; |
| 233 | unsigned long long c, dec = 0; |
| 234 | |
| 235 | /* If bcd is not in BCD format, just increment */ |
| 236 | if (max > 0x9) { |
| 237 | *bcd += inc; |
| 238 | return init; |
| 239 | } |
| 240 | |
| 241 | /* Convert BCD to Decimal */ |
| 242 | for (i=0 ; i < chars ; i++) { |
| 243 | c = (*bcd >> (i << 2)) & 0xf; |
| 244 | c = c > 9 ? 9 : c; /* force to bcd just in case */ |
| 245 | for (j=0 ; j < i ; j++) |
| 246 | c = c * 10; |
| 247 | dec += c; |
| 248 | } |
| 249 | |
| 250 | /* Do our increment/decrement */ |
| 251 | dec += inc; |
| 252 | *bcd = 0; |
| 253 | |
| 254 | /* Convert back to BCD */ |
| 255 | for (i=0 ; i < chars ; i++) { |
| 256 | for (c=1,j=0 ; j < i ; j++) |
| 257 | c = c * 10; |
| 258 | c = (dec / c) % 10; |
| 259 | *bcd += c << (i << 2); |
| 260 | } |
| 261 | return init; |
| 262 | } |
| 263 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 264 | static void do_usb_entry_multi(void *symval, struct module *mod) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 265 | { |
| 266 | unsigned int devlo, devhi; |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 267 | unsigned char chi, clo, max; |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 268 | int ndigits; |
| 269 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 270 | DEF_FIELD(symval, usb_device_id, match_flags); |
| 271 | DEF_FIELD(symval, usb_device_id, idVendor); |
| 272 | DEF_FIELD(symval, usb_device_id, idProduct); |
| 273 | DEF_FIELD(symval, usb_device_id, bcdDevice_lo); |
| 274 | DEF_FIELD(symval, usb_device_id, bcdDevice_hi); |
| 275 | DEF_FIELD(symval, usb_device_id, bDeviceClass); |
| 276 | DEF_FIELD(symval, usb_device_id, bInterfaceClass); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 277 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 278 | devlo = match_flags & USB_DEVICE_ID_MATCH_DEV_LO ? |
| 279 | bcdDevice_lo : 0x0U; |
| 280 | devhi = match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? |
| 281 | bcdDevice_hi : ~0x0U; |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 282 | |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 283 | /* Figure out if this entry is in bcd or hex format */ |
| 284 | max = 0x9; /* Default to decimal format */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 285 | for (ndigits = 0 ; ndigits < sizeof(bcdDevice_lo) * 2 ; ndigits++) { |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 286 | clo = (devlo >> (ndigits << 2)) & 0xf; |
| 287 | chi = ((devhi > 0x9999 ? 0x9999 : devhi) >> (ndigits << 2)) & 0xf; |
| 288 | if (clo > max || chi > max) { |
| 289 | max = 0xf; |
| 290 | break; |
| 291 | } |
| 292 | } |
| 293 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 294 | /* |
| 295 | * Some modules (visor) have empty slots as placeholder for |
| 296 | * run-time specification that results in catch-all alias |
| 297 | */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 298 | if (!(idVendor | idProduct | bDeviceClass | bInterfaceClass)) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 299 | return; |
| 300 | |
| 301 | /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 302 | for (ndigits = sizeof(bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 303 | clo = devlo & 0xf; |
| 304 | chi = devhi & 0xf; |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 305 | if (chi > max) /* If we are in bcd mode, truncate if necessary */ |
| 306 | chi = max; |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 307 | devlo >>= 4; |
| 308 | devhi >>= 4; |
| 309 | |
| 310 | if (devlo == devhi || !ndigits) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 311 | do_usb_entry(symval, devlo, ndigits, clo, chi, max, mod); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 312 | break; |
| 313 | } |
| 314 | |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 315 | if (clo > 0x0) |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 316 | do_usb_entry(symval, |
Nathaniel McCallum | 55f49f2 | 2009-11-18 20:15:28 -0500 | [diff] [blame] | 317 | incbcd(&devlo, 1, max, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 318 | sizeof(bcdDevice_lo) * 2), |
Nathaniel McCallum | 55f49f2 | 2009-11-18 20:15:28 -0500 | [diff] [blame] | 319 | ndigits, clo, max, max, mod); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 320 | |
Nathaniel McCallum | afe2dab | 2009-11-18 20:11:23 -0500 | [diff] [blame] | 321 | if (chi < max) |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 322 | do_usb_entry(symval, |
Nathaniel McCallum | 55f49f2 | 2009-11-18 20:15:28 -0500 | [diff] [blame] | 323 | incbcd(&devhi, -1, max, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 324 | sizeof(bcdDevice_lo) * 2), |
Nathaniel McCallum | 55f49f2 | 2009-11-18 20:15:28 -0500 | [diff] [blame] | 325 | ndigits, 0x0, chi, max, mod); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 326 | } |
| 327 | } |
| 328 | |
| 329 | static void do_usb_table(void *symval, unsigned long size, |
| 330 | struct module *mod) |
| 331 | { |
| 332 | unsigned int i; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 333 | const unsigned long id_size = SIZE_usb_device_id; |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 334 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 335 | device_id_check(mod->name, "usb", size, id_size, symval); |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 336 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 337 | /* Leave last one: it's the terminator. */ |
| 338 | size -= id_size; |
| 339 | |
| 340 | for (i = 0; i < size; i += id_size) |
| 341 | do_usb_entry_multi(symval + i, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 342 | } |
| 343 | |
Philipp Zabel | acbef7b | 2016-05-05 16:22:29 -0700 | [diff] [blame] | 344 | static void do_of_entry_multi(void *symval, struct module *mod) |
| 345 | { |
| 346 | char alias[500]; |
| 347 | int len; |
| 348 | char *tmp; |
| 349 | |
| 350 | DEF_FIELD_ADDR(symval, of_device_id, name); |
| 351 | DEF_FIELD_ADDR(symval, of_device_id, type); |
| 352 | DEF_FIELD_ADDR(symval, of_device_id, compatible); |
| 353 | |
| 354 | len = sprintf(alias, "of:N%sT%s", (*name)[0] ? *name : "*", |
| 355 | (*type)[0] ? *type : "*"); |
| 356 | |
Wolfram Sang | b3c0a4d | 2016-06-06 18:48:38 +0200 | [diff] [blame] | 357 | if ((*compatible)[0]) |
Philipp Zabel | acbef7b | 2016-05-05 16:22:29 -0700 | [diff] [blame] | 358 | sprintf(&alias[len], "%sC%s", (*type)[0] ? "*" : "", |
| 359 | *compatible); |
| 360 | |
| 361 | /* Replace all whitespace with underscores */ |
| 362 | for (tmp = alias; tmp && *tmp; tmp++) |
| 363 | if (isspace(*tmp)) |
| 364 | *tmp = '_'; |
| 365 | |
| 366 | buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); |
| 367 | strcat(alias, "C"); |
| 368 | add_wildcard(alias); |
| 369 | buf_printf(&mod->dev_table_buf, "MODULE_ALIAS(\"%s\");\n", alias); |
| 370 | } |
| 371 | |
| 372 | static void do_of_table(void *symval, unsigned long size, |
| 373 | struct module *mod) |
| 374 | { |
| 375 | unsigned int i; |
| 376 | const unsigned long id_size = SIZE_of_device_id; |
| 377 | |
| 378 | device_id_check(mod->name, "of", size, id_size, symval); |
| 379 | |
| 380 | /* Leave last one: it's the terminator. */ |
| 381 | size -= id_size; |
| 382 | |
| 383 | for (i = 0; i < size; i += id_size) |
| 384 | do_of_entry_multi(symval + i, mod); |
| 385 | } |
| 386 | |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 387 | /* Looks like: hid:bNvNpN */ |
| 388 | static int do_hid_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 389 | void *symval, char *alias) |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 390 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 391 | DEF_FIELD(symval, hid_device_id, bus); |
| 392 | DEF_FIELD(symval, hid_device_id, group); |
| 393 | DEF_FIELD(symval, hid_device_id, vendor); |
| 394 | DEF_FIELD(symval, hid_device_id, product); |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 395 | |
Henrik Rydberg | 7431fb7 | 2012-04-23 12:07:04 +0200 | [diff] [blame] | 396 | sprintf(alias, "hid:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 397 | ADD(alias, "b", bus != HID_BUS_ANY, bus); |
| 398 | ADD(alias, "g", group != HID_GROUP_ANY, group); |
| 399 | ADD(alias, "v", vendor != HID_ANY_ID, vendor); |
| 400 | ADD(alias, "p", product != HID_ANY_ID, product); |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 401 | |
| 402 | return 1; |
| 403 | } |
| 404 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 405 | /* Looks like: ieee1394:venNmoNspNverN */ |
| 406 | static int do_ieee1394_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 407 | void *symval, char *alias) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 408 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 409 | DEF_FIELD(symval, ieee1394_device_id, match_flags); |
| 410 | DEF_FIELD(symval, ieee1394_device_id, vendor_id); |
| 411 | DEF_FIELD(symval, ieee1394_device_id, model_id); |
| 412 | DEF_FIELD(symval, ieee1394_device_id, specifier_id); |
| 413 | DEF_FIELD(symval, ieee1394_device_id, version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 414 | |
| 415 | strcpy(alias, "ieee1394:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 416 | ADD(alias, "ven", match_flags & IEEE1394_MATCH_VENDOR_ID, |
| 417 | vendor_id); |
| 418 | ADD(alias, "mo", match_flags & IEEE1394_MATCH_MODEL_ID, |
| 419 | model_id); |
| 420 | ADD(alias, "sp", match_flags & IEEE1394_MATCH_SPECIFIER_ID, |
| 421 | specifier_id); |
| 422 | ADD(alias, "ver", match_flags & IEEE1394_MATCH_VERSION, |
| 423 | version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 424 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 425 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | return 1; |
| 427 | } |
| 428 | |
Max Gurtovoy | cc6711b | 2021-08-26 13:39:09 +0300 | [diff] [blame] | 429 | /* Looks like: pci:vNdNsvNsdNbcNscNiN or <prefix>_pci:vNdNsvNsdNbcNscNiN. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | static int do_pci_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 431 | void *symval, char *alias) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | { |
| 433 | /* Class field can be divided into these three. */ |
| 434 | unsigned char baseclass, subclass, interface, |
| 435 | baseclass_mask, subclass_mask, interface_mask; |
| 436 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 437 | DEF_FIELD(symval, pci_device_id, vendor); |
| 438 | DEF_FIELD(symval, pci_device_id, device); |
| 439 | DEF_FIELD(symval, pci_device_id, subvendor); |
| 440 | DEF_FIELD(symval, pci_device_id, subdevice); |
| 441 | DEF_FIELD(symval, pci_device_id, class); |
| 442 | DEF_FIELD(symval, pci_device_id, class_mask); |
Max Gurtovoy | cc6711b | 2021-08-26 13:39:09 +0300 | [diff] [blame] | 443 | DEF_FIELD(symval, pci_device_id, override_only); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | |
Max Gurtovoy | cc6711b | 2021-08-26 13:39:09 +0300 | [diff] [blame] | 445 | switch (override_only) { |
| 446 | case 0: |
| 447 | strcpy(alias, "pci:"); |
| 448 | break; |
| 449 | case PCI_ID_F_VFIO_DRIVER_OVERRIDE: |
| 450 | strcpy(alias, "vfio_pci:"); |
| 451 | break; |
| 452 | default: |
| 453 | warn("Unknown PCI driver_override alias %08X\n", |
| 454 | override_only); |
| 455 | return 0; |
| 456 | } |
| 457 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 458 | ADD(alias, "v", vendor != PCI_ANY_ID, vendor); |
| 459 | ADD(alias, "d", device != PCI_ANY_ID, device); |
| 460 | ADD(alias, "sv", subvendor != PCI_ANY_ID, subvendor); |
| 461 | ADD(alias, "sd", subdevice != PCI_ANY_ID, subdevice); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 463 | baseclass = (class) >> 16; |
| 464 | baseclass_mask = (class_mask) >> 16; |
| 465 | subclass = (class) >> 8; |
| 466 | subclass_mask = (class_mask) >> 8; |
| 467 | interface = class; |
| 468 | interface_mask = class_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | if ((baseclass_mask != 0 && baseclass_mask != 0xFF) |
| 471 | || (subclass_mask != 0 && subclass_mask != 0xFF) |
| 472 | || (interface_mask != 0 && interface_mask != 0xFF)) { |
Sam Ravnborg | cb80514 | 2006-01-28 16:57:26 +0100 | [diff] [blame] | 473 | warn("Can't handle masks in %s:%04X\n", |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 474 | filename, class_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 475 | return 0; |
| 476 | } |
| 477 | |
| 478 | ADD(alias, "bc", baseclass_mask == 0xFF, baseclass); |
| 479 | ADD(alias, "sc", subclass_mask == 0xFF, subclass); |
| 480 | ADD(alias, "i", interface_mask == 0xFF, interface); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 481 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 482 | return 1; |
| 483 | } |
| 484 | |
Sam Ravnborg | 62070fa | 2006-03-03 16:46:04 +0100 | [diff] [blame] | 485 | /* looks like: "ccw:tNmNdtNdmN" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 486 | static int do_ccw_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 487 | void *symval, char *alias) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 488 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 489 | DEF_FIELD(symval, ccw_device_id, match_flags); |
| 490 | DEF_FIELD(symval, ccw_device_id, cu_type); |
| 491 | DEF_FIELD(symval, ccw_device_id, cu_model); |
| 492 | DEF_FIELD(symval, ccw_device_id, dev_type); |
| 493 | DEF_FIELD(symval, ccw_device_id, dev_model); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | strcpy(alias, "ccw:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 496 | ADD(alias, "t", match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE, |
| 497 | cu_type); |
| 498 | ADD(alias, "m", match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL, |
| 499 | cu_model); |
| 500 | ADD(alias, "dt", match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE, |
| 501 | dev_type); |
| 502 | ADD(alias, "dm", match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL, |
| 503 | dev_model); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 504 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 505 | return 1; |
| 506 | } |
| 507 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 508 | /* looks like: "ap:tN" */ |
| 509 | static int do_ap_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 510 | void *symval, char *alias) |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 511 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 512 | DEF_FIELD(symval, ap_device_id, dev_type); |
| 513 | |
| 514 | sprintf(alias, "ap:t%02X*", dev_type); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 515 | return 1; |
| 516 | } |
| 517 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 518 | /* looks like: "css:tN" */ |
| 519 | static int do_css_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 520 | void *symval, char *alias) |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 521 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 522 | DEF_FIELD(symval, css_device_id, type); |
| 523 | |
| 524 | sprintf(alias, "css:t%01X", type); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 525 | return 1; |
| 526 | } |
| 527 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | /* Looks like: "serio:tyNprNidNexN" */ |
| 529 | static int do_serio_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 530 | void *symval, char *alias) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 532 | DEF_FIELD(symval, serio_device_id, type); |
| 533 | DEF_FIELD(symval, serio_device_id, proto); |
| 534 | DEF_FIELD(symval, serio_device_id, id); |
| 535 | DEF_FIELD(symval, serio_device_id, extra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 536 | |
| 537 | strcpy(alias, "serio:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 538 | ADD(alias, "ty", type != SERIO_ANY, type); |
| 539 | ADD(alias, "pr", proto != SERIO_ANY, proto); |
| 540 | ADD(alias, "id", id != SERIO_ANY, id); |
| 541 | ADD(alias, "ex", extra != SERIO_ANY, extra); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 543 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | return 1; |
| 545 | } |
| 546 | |
Suthikulpanit, Suravee | 26095a0 | 2015-07-07 01:55:20 +0200 | [diff] [blame] | 547 | /* looks like: "acpi:ACPI0003" or "acpi:PNP0C0B" or "acpi:LNXVIDEO" or |
| 548 | * "acpi:bbsspp" (bb=base-class, ss=sub-class, pp=prog-if) |
| 549 | * |
| 550 | * NOTE: Each driver should use one of the following : _HID, _CIDs |
| 551 | * or _CLS. Also, bb, ss, and pp can be substituted with ?? |
| 552 | * as don't care byte. |
| 553 | */ |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 554 | static int do_acpi_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 555 | void *symval, char *alias) |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 556 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 557 | DEF_FIELD_ADDR(symval, acpi_device_id, id); |
Suthikulpanit, Suravee | 26095a0 | 2015-07-07 01:55:20 +0200 | [diff] [blame] | 558 | DEF_FIELD_ADDR(symval, acpi_device_id, cls); |
| 559 | DEF_FIELD_ADDR(symval, acpi_device_id, cls_msk); |
| 560 | |
| 561 | if (id && strlen((const char *)*id)) |
| 562 | sprintf(alias, "acpi*:%s:*", *id); |
| 563 | else if (cls) { |
| 564 | int i, byte_shift, cnt = 0; |
| 565 | unsigned int msk; |
| 566 | |
| 567 | sprintf(&alias[cnt], "acpi*:"); |
| 568 | cnt = 6; |
| 569 | for (i = 1; i <= 3; i++) { |
| 570 | byte_shift = 8 * (3-i); |
| 571 | msk = (*cls_msk >> byte_shift) & 0xFF; |
| 572 | if (msk) |
| 573 | sprintf(&alias[cnt], "%02x", |
| 574 | (*cls >> byte_shift) & 0xFF); |
| 575 | else |
| 576 | sprintf(&alias[cnt], "??"); |
| 577 | cnt += 2; |
| 578 | } |
| 579 | sprintf(&alias[cnt], ":*"); |
| 580 | } |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 581 | return 1; |
| 582 | } |
| 583 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | /* looks like: "pnp:dD" */ |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 585 | static void do_pnp_device_entry(void *symval, unsigned long size, |
| 586 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 588 | const unsigned long id_size = SIZE_pnp_device_id; |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 589 | const unsigned int count = (size / id_size)-1; |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 590 | unsigned int i; |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 591 | |
| 592 | device_id_check(mod->name, "pnp", size, id_size, symval); |
| 593 | |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 594 | for (i = 0; i < count; i++) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 595 | DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id); |
| 596 | char acpi_id[sizeof(*id)]; |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 597 | int j; |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 598 | |
| 599 | buf_printf(&mod->dev_table_buf, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 600 | "MODULE_ALIAS(\"pnp:d%s*\");\n", *id); |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 601 | |
| 602 | /* fix broken pnp bus lowercasing */ |
| 603 | for (j = 0; j < sizeof(acpi_id); j++) |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 604 | acpi_id[j] = toupper((*id)[j]); |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 605 | buf_printf(&mod->dev_table_buf, |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 606 | "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 607 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 608 | } |
| 609 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 610 | /* looks like: "pnp:dD" for every device of the card */ |
| 611 | static void do_pnp_card_entries(void *symval, unsigned long size, |
| 612 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 614 | const unsigned long id_size = SIZE_pnp_card_device_id; |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 615 | const unsigned int count = (size / id_size)-1; |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 616 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 618 | device_id_check(mod->name, "pnp", size, id_size, symval); |
| 619 | |
| 620 | for (i = 0; i < count; i++) { |
| 621 | unsigned int j; |
Leonardo Bras | c2b1a92 | 2018-10-24 01:03:52 -0300 | [diff] [blame] | 622 | DEF_FIELD_ADDR(symval + i * id_size, pnp_card_device_id, devs); |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 623 | |
| 624 | for (j = 0; j < PNP_MAX_DEVICES; j++) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 625 | const char *id = (char *)(*devs)[j].id; |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 626 | int i2, j2; |
| 627 | int dup = 0; |
| 628 | |
| 629 | if (!id[0]) |
| 630 | break; |
| 631 | |
| 632 | /* find duplicate, already added value */ |
| 633 | for (i2 = 0; i2 < i && !dup; i2++) { |
Leonardo Bras | c2b1a92 | 2018-10-24 01:03:52 -0300 | [diff] [blame] | 634 | DEF_FIELD_ADDR_VAR(symval + i2 * id_size, |
| 635 | pnp_card_device_id, |
| 636 | devs, devs_dup); |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 637 | |
| 638 | for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { |
Leonardo Bras | c2b1a92 | 2018-10-24 01:03:52 -0300 | [diff] [blame] | 639 | const char *id2 = |
| 640 | (char *)(*devs_dup)[j2].id; |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 641 | |
| 642 | if (!id2[0]) |
| 643 | break; |
| 644 | |
| 645 | if (!strcmp(id, id2)) { |
| 646 | dup = 1; |
| 647 | break; |
| 648 | } |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | /* add an individual alias for every device entry */ |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 653 | if (!dup) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 654 | char acpi_id[PNP_ID_LEN]; |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 655 | int k; |
| 656 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 657 | buf_printf(&mod->dev_table_buf, |
| 658 | "MODULE_ALIAS(\"pnp:d%s*\");\n", id); |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 659 | |
| 660 | /* fix broken pnp bus lowercasing */ |
| 661 | for (k = 0; k < sizeof(acpi_id); k++) |
| 662 | acpi_id[k] = toupper(id[k]); |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 663 | buf_printf(&mod->dev_table_buf, |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 664 | "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 665 | } |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 666 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | } |
| 669 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 670 | /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */ |
| 671 | static int do_pcmcia_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 672 | void *symval, char *alias) |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 673 | { |
| 674 | unsigned int i; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 675 | DEF_FIELD(symval, pcmcia_device_id, match_flags); |
| 676 | DEF_FIELD(symval, pcmcia_device_id, manf_id); |
| 677 | DEF_FIELD(symval, pcmcia_device_id, card_id); |
| 678 | DEF_FIELD(symval, pcmcia_device_id, func_id); |
| 679 | DEF_FIELD(symval, pcmcia_device_id, function); |
| 680 | DEF_FIELD(symval, pcmcia_device_id, device_no); |
| 681 | DEF_FIELD_ADDR(symval, pcmcia_device_id, prod_id_hash); |
Kars de Jong | 4fb7edc | 2005-09-25 14:39:46 +0200 | [diff] [blame] | 682 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 683 | for (i=0; i<4; i++) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 684 | (*prod_id_hash)[i] = TO_NATIVE((*prod_id_hash)[i]); |
| 685 | } |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 686 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 687 | strcpy(alias, "pcmcia:"); |
| 688 | ADD(alias, "m", match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID, |
| 689 | manf_id); |
| 690 | ADD(alias, "c", match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID, |
| 691 | card_id); |
| 692 | ADD(alias, "f", match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID, |
| 693 | func_id); |
| 694 | ADD(alias, "fn", match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION, |
| 695 | function); |
| 696 | ADD(alias, "pfn", match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO, |
| 697 | device_no); |
| 698 | ADD(alias, "pa", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, (*prod_id_hash)[0]); |
| 699 | ADD(alias, "pb", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, (*prod_id_hash)[1]); |
| 700 | ADD(alias, "pc", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, (*prod_id_hash)[2]); |
| 701 | ADD(alias, "pd", match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, (*prod_id_hash)[3]); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 702 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 703 | add_wildcard(alias); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 704 | return 1; |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 705 | } |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 706 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 707 | static int do_vio_entry(const char *filename, void *symval, |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 708 | char *alias) |
| 709 | { |
| 710 | char *tmp; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 711 | DEF_FIELD_ADDR(symval, vio_device_id, type); |
| 712 | DEF_FIELD_ADDR(symval, vio_device_id, compat); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 713 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 714 | sprintf(alias, "vio:T%sS%s", (*type)[0] ? *type : "*", |
| 715 | (*compat)[0] ? *compat : "*"); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 716 | |
| 717 | /* Replace all whitespace with underscores */ |
| 718 | for (tmp = alias; tmp && *tmp; tmp++) |
| 719 | if (isspace (*tmp)) |
| 720 | *tmp = '_'; |
| 721 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 722 | add_wildcard(alias); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 723 | return 1; |
| 724 | } |
| 725 | |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 726 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 727 | |
| 728 | static void do_input(char *alias, |
| 729 | kernel_ulong_t *arr, unsigned int min, unsigned int max) |
| 730 | { |
| 731 | unsigned int i; |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 732 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 733 | for (i = min / BITS_PER_LONG; i < max / BITS_PER_LONG + 1; i++) |
| 734 | arr[i] = TO_NATIVE(arr[i]); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 735 | for (i = min; i < max; i++) |
Hans de Goede | e0e9263 | 2006-08-15 12:09:27 +0200 | [diff] [blame] | 736 | if (arr[i / BITS_PER_LONG] & (1L << (i%BITS_PER_LONG))) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 737 | sprintf(alias + strlen(alias), "%X,*", i); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 738 | } |
| 739 | |
Dmitry Torokhov | 09c3e01 | 2017-10-22 11:42:29 -0700 | [diff] [blame] | 740 | /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 741 | static int do_input_entry(const char *filename, void *symval, |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 742 | char *alias) |
| 743 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 744 | DEF_FIELD(symval, input_device_id, flags); |
| 745 | DEF_FIELD(symval, input_device_id, bustype); |
| 746 | DEF_FIELD(symval, input_device_id, vendor); |
| 747 | DEF_FIELD(symval, input_device_id, product); |
| 748 | DEF_FIELD(symval, input_device_id, version); |
| 749 | DEF_FIELD_ADDR(symval, input_device_id, evbit); |
| 750 | DEF_FIELD_ADDR(symval, input_device_id, keybit); |
| 751 | DEF_FIELD_ADDR(symval, input_device_id, relbit); |
| 752 | DEF_FIELD_ADDR(symval, input_device_id, absbit); |
| 753 | DEF_FIELD_ADDR(symval, input_device_id, mscbit); |
| 754 | DEF_FIELD_ADDR(symval, input_device_id, ledbit); |
| 755 | DEF_FIELD_ADDR(symval, input_device_id, sndbit); |
| 756 | DEF_FIELD_ADDR(symval, input_device_id, ffbit); |
| 757 | DEF_FIELD_ADDR(symval, input_device_id, swbit); |
| 758 | |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 759 | sprintf(alias, "input:"); |
| 760 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 761 | ADD(alias, "b", flags & INPUT_DEVICE_ID_MATCH_BUS, bustype); |
| 762 | ADD(alias, "v", flags & INPUT_DEVICE_ID_MATCH_VENDOR, vendor); |
| 763 | ADD(alias, "p", flags & INPUT_DEVICE_ID_MATCH_PRODUCT, product); |
| 764 | ADD(alias, "e", flags & INPUT_DEVICE_ID_MATCH_VERSION, version); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 765 | |
| 766 | sprintf(alias + strlen(alias), "-e*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 767 | if (flags & INPUT_DEVICE_ID_MATCH_EVBIT) |
| 768 | do_input(alias, *evbit, 0, INPUT_DEVICE_ID_EV_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 769 | sprintf(alias + strlen(alias), "k*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 770 | if (flags & INPUT_DEVICE_ID_MATCH_KEYBIT) |
| 771 | do_input(alias, *keybit, |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 772 | INPUT_DEVICE_ID_KEY_MIN_INTERESTING, |
| 773 | INPUT_DEVICE_ID_KEY_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 774 | sprintf(alias + strlen(alias), "r*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 775 | if (flags & INPUT_DEVICE_ID_MATCH_RELBIT) |
| 776 | do_input(alias, *relbit, 0, INPUT_DEVICE_ID_REL_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 777 | sprintf(alias + strlen(alias), "a*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 778 | if (flags & INPUT_DEVICE_ID_MATCH_ABSBIT) |
| 779 | do_input(alias, *absbit, 0, INPUT_DEVICE_ID_ABS_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 780 | sprintf(alias + strlen(alias), "m*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 781 | if (flags & INPUT_DEVICE_ID_MATCH_MSCIT) |
| 782 | do_input(alias, *mscbit, 0, INPUT_DEVICE_ID_MSC_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 783 | sprintf(alias + strlen(alias), "l*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 784 | if (flags & INPUT_DEVICE_ID_MATCH_LEDBIT) |
| 785 | do_input(alias, *ledbit, 0, INPUT_DEVICE_ID_LED_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 786 | sprintf(alias + strlen(alias), "s*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 787 | if (flags & INPUT_DEVICE_ID_MATCH_SNDBIT) |
| 788 | do_input(alias, *sndbit, 0, INPUT_DEVICE_ID_SND_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 789 | sprintf(alias + strlen(alias), "f*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 790 | if (flags & INPUT_DEVICE_ID_MATCH_FFBIT) |
| 791 | do_input(alias, *ffbit, 0, INPUT_DEVICE_ID_FF_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 792 | sprintf(alias + strlen(alias), "w*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 793 | if (flags & INPUT_DEVICE_ID_MATCH_SWBIT) |
| 794 | do_input(alias, *swbit, 0, INPUT_DEVICE_ID_SW_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 795 | return 1; |
| 796 | } |
| 797 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 798 | static int do_eisa_entry(const char *filename, void *symval, |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 799 | char *alias) |
| 800 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 801 | DEF_FIELD_ADDR(symval, eisa_device_id, sig); |
| 802 | if (sig[0]) |
| 803 | sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", *sig); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 804 | else |
| 805 | strcat(alias, "*"); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 806 | return 1; |
| 807 | } |
| 808 | |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 809 | /* Looks like: parisc:tNhvNrevNsvN */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 810 | static int do_parisc_entry(const char *filename, void *symval, |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 811 | char *alias) |
| 812 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 813 | DEF_FIELD(symval, parisc_device_id, hw_type); |
| 814 | DEF_FIELD(symval, parisc_device_id, hversion); |
| 815 | DEF_FIELD(symval, parisc_device_id, hversion_rev); |
| 816 | DEF_FIELD(symval, parisc_device_id, sversion); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 817 | |
| 818 | strcpy(alias, "parisc:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 819 | ADD(alias, "t", hw_type != PA_HWTYPE_ANY_ID, hw_type); |
| 820 | ADD(alias, "hv", hversion != PA_HVERSION_ANY_ID, hversion); |
| 821 | ADD(alias, "rev", hversion_rev != PA_HVERSION_REV_ANY_ID, hversion_rev); |
| 822 | ADD(alias, "sv", sversion != PA_SVERSION_ANY_ID, sversion); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 823 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 824 | add_wildcard(alias); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 825 | return 1; |
| 826 | } |
| 827 | |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 828 | /* Looks like: sdio:cNvNdN. */ |
| 829 | static int do_sdio_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 830 | void *symval, char *alias) |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 831 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 832 | DEF_FIELD(symval, sdio_device_id, class); |
| 833 | DEF_FIELD(symval, sdio_device_id, vendor); |
| 834 | DEF_FIELD(symval, sdio_device_id, device); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 835 | |
| 836 | strcpy(alias, "sdio:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 837 | ADD(alias, "c", class != (__u8)SDIO_ANY_ID, class); |
| 838 | ADD(alias, "v", vendor != (__u16)SDIO_ANY_ID, vendor); |
| 839 | ADD(alias, "d", device != (__u16)SDIO_ANY_ID, device); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 840 | add_wildcard(alias); |
Linus Torvalds | 038a500 | 2007-10-11 19:40:14 -0700 | [diff] [blame] | 841 | return 1; |
| 842 | } |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 843 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 844 | /* Looks like: ssb:vNidNrevN. */ |
| 845 | static int do_ssb_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 846 | void *symval, char *alias) |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 847 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 848 | DEF_FIELD(symval, ssb_device_id, vendor); |
| 849 | DEF_FIELD(symval, ssb_device_id, coreid); |
| 850 | DEF_FIELD(symval, ssb_device_id, revision); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 851 | |
| 852 | strcpy(alias, "ssb:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 853 | ADD(alias, "v", vendor != SSB_ANY_VENDOR, vendor); |
| 854 | ADD(alias, "id", coreid != SSB_ANY_ID, coreid); |
| 855 | ADD(alias, "rev", revision != SSB_ANY_REV, revision); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 856 | add_wildcard(alias); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 857 | return 1; |
| 858 | } |
| 859 | |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 860 | /* Looks like: bcma:mNidNrevNclN. */ |
| 861 | static int do_bcma_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 862 | void *symval, char *alias) |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 863 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 864 | DEF_FIELD(symval, bcma_device_id, manuf); |
| 865 | DEF_FIELD(symval, bcma_device_id, id); |
| 866 | DEF_FIELD(symval, bcma_device_id, rev); |
| 867 | DEF_FIELD(symval, bcma_device_id, class); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 868 | |
| 869 | strcpy(alias, "bcma:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 870 | ADD(alias, "m", manuf != BCMA_ANY_MANUF, manuf); |
| 871 | ADD(alias, "id", id != BCMA_ANY_ID, id); |
| 872 | ADD(alias, "rev", rev != BCMA_ANY_REV, rev); |
| 873 | ADD(alias, "cl", class != BCMA_ANY_CLASS, class); |
Rafał Miłecki | 8369ae3 | 2011-05-09 18:56:46 +0200 | [diff] [blame] | 874 | add_wildcard(alias); |
| 875 | return 1; |
| 876 | } |
| 877 | |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 878 | /* Looks like: virtio:dNvN */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 879 | static int do_virtio_entry(const char *filename, void *symval, |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 880 | char *alias) |
| 881 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 882 | DEF_FIELD(symval, virtio_device_id, device); |
| 883 | DEF_FIELD(symval, virtio_device_id, vendor); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 884 | |
| 885 | strcpy(alias, "virtio:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 886 | ADD(alias, "d", device != VIRTIO_DEV_ANY_ID, device); |
| 887 | ADD(alias, "v", vendor != VIRTIO_DEV_ANY_ID, vendor); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 888 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 889 | add_wildcard(alias); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 890 | return 1; |
| 891 | } |
| 892 | |
K. Y. Srinivasan | d2ee52a | 2011-08-25 09:48:30 -0700 | [diff] [blame] | 893 | /* |
| 894 | * Looks like: vmbus:guid |
| 895 | * Each byte of the guid will be represented by two hex characters |
| 896 | * in the name. |
| 897 | */ |
| 898 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 899 | static int do_vmbus_entry(const char *filename, void *symval, |
K. Y. Srinivasan | d2ee52a | 2011-08-25 09:48:30 -0700 | [diff] [blame] | 900 | char *alias) |
| 901 | { |
| 902 | int i; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 903 | DEF_FIELD_ADDR(symval, hv_vmbus_device_id, guid); |
| 904 | char guid_name[(sizeof(*guid) + 1) * 2]; |
K. Y. Srinivasan | d2ee52a | 2011-08-25 09:48:30 -0700 | [diff] [blame] | 905 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 906 | for (i = 0; i < (sizeof(*guid) * 2); i += 2) |
K. Y. Srinivasan | af3ff64 | 2015-12-14 16:01:43 -0800 | [diff] [blame] | 907 | sprintf(&guid_name[i], "%02x", TO_NATIVE((guid->b)[i/2])); |
K. Y. Srinivasan | d2ee52a | 2011-08-25 09:48:30 -0700 | [diff] [blame] | 908 | |
| 909 | strcpy(alias, "vmbus:"); |
| 910 | strcat(alias, guid_name); |
| 911 | |
| 912 | return 1; |
| 913 | } |
| 914 | |
Andrew F. Davis | 5b7d127 | 2018-04-21 18:55:29 -0500 | [diff] [blame] | 915 | /* Looks like: rpmsg:S */ |
| 916 | static int do_rpmsg_entry(const char *filename, void *symval, |
| 917 | char *alias) |
| 918 | { |
| 919 | DEF_FIELD_ADDR(symval, rpmsg_device_id, name); |
| 920 | sprintf(alias, RPMSG_DEVICE_MODALIAS_FMT, *name); |
| 921 | |
| 922 | return 1; |
| 923 | } |
Andrew F. Davis | 5b7d127 | 2018-04-21 18:55:29 -0500 | [diff] [blame] | 924 | |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 925 | /* Looks like: i2c:S */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 926 | static int do_i2c_entry(const char *filename, void *symval, |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 927 | char *alias) |
| 928 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 929 | DEF_FIELD_ADDR(symval, i2c_device_id, name); |
| 930 | sprintf(alias, I2C_MODULE_PREFIX "%s", *name); |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 931 | |
| 932 | return 1; |
| 933 | } |
| 934 | |
Boris Brezillon | 1ce589a | 2020-02-27 12:31:08 +0100 | [diff] [blame] | 935 | static int do_i3c_entry(const char *filename, void *symval, |
| 936 | char *alias) |
| 937 | { |
| 938 | DEF_FIELD(symval, i3c_device_id, match_flags); |
| 939 | DEF_FIELD(symval, i3c_device_id, dcr); |
| 940 | DEF_FIELD(symval, i3c_device_id, manuf_id); |
| 941 | DEF_FIELD(symval, i3c_device_id, part_id); |
| 942 | DEF_FIELD(symval, i3c_device_id, extra_info); |
| 943 | |
| 944 | strcpy(alias, "i3c:"); |
| 945 | ADD(alias, "dcr", match_flags & I3C_MATCH_DCR, dcr); |
| 946 | ADD(alias, "manuf", match_flags & I3C_MATCH_MANUF, manuf_id); |
| 947 | ADD(alias, "part", match_flags & I3C_MATCH_PART, part_id); |
| 948 | ADD(alias, "ext", match_flags & I3C_MATCH_EXTRA_INFO, extra_info); |
| 949 | |
| 950 | return 1; |
| 951 | } |
| 952 | |
Anton Vorontsov | e0626e3 | 2009-09-22 16:46:08 -0700 | [diff] [blame] | 953 | /* Looks like: spi:S */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 954 | static int do_spi_entry(const char *filename, void *symval, |
Anton Vorontsov | 75368bf | 2009-09-22 16:46:04 -0700 | [diff] [blame] | 955 | char *alias) |
| 956 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 957 | DEF_FIELD_ADDR(symval, spi_device_id, name); |
| 958 | sprintf(alias, SPI_MODULE_PREFIX "%s", *name); |
Anton Vorontsov | 75368bf | 2009-09-22 16:46:04 -0700 | [diff] [blame] | 959 | |
| 960 | return 1; |
| 961 | } |
| 962 | |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 963 | static const struct dmifield { |
| 964 | const char *prefix; |
| 965 | int field; |
| 966 | } dmi_fields[] = { |
| 967 | { "bvn", DMI_BIOS_VENDOR }, |
| 968 | { "bvr", DMI_BIOS_VERSION }, |
| 969 | { "bd", DMI_BIOS_DATE }, |
Erwan Velu | f5152f4 | 2020-06-06 11:35:50 +0200 | [diff] [blame] | 970 | { "br", DMI_BIOS_RELEASE }, |
| 971 | { "efr", DMI_EC_FIRMWARE_RELEASE }, |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 972 | { "svn", DMI_SYS_VENDOR }, |
| 973 | { "pn", DMI_PRODUCT_NAME }, |
| 974 | { "pvr", DMI_PRODUCT_VERSION }, |
| 975 | { "rvn", DMI_BOARD_VENDOR }, |
| 976 | { "rn", DMI_BOARD_NAME }, |
| 977 | { "rvr", DMI_BOARD_VERSION }, |
| 978 | { "cvn", DMI_CHASSIS_VENDOR }, |
| 979 | { "ct", DMI_CHASSIS_TYPE }, |
| 980 | { "cvr", DMI_CHASSIS_VERSION }, |
| 981 | { NULL, DMI_NONE } |
| 982 | }; |
| 983 | |
| 984 | static void dmi_ascii_filter(char *d, const char *s) |
| 985 | { |
| 986 | /* Filter out characters we don't want to see in the modalias string */ |
| 987 | for (; *s; s++) |
| 988 | if (*s > ' ' && *s < 127 && *s != ':') |
| 989 | *(d++) = *s; |
| 990 | |
| 991 | *d = 0; |
| 992 | } |
| 993 | |
| 994 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 995 | static int do_dmi_entry(const char *filename, void *symval, |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 996 | char *alias) |
| 997 | { |
| 998 | int i, j; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 999 | DEF_FIELD_ADDR(symval, dmi_system_id, matches); |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 1000 | sprintf(alias, "dmi*"); |
| 1001 | |
| 1002 | for (i = 0; i < ARRAY_SIZE(dmi_fields); i++) { |
| 1003 | for (j = 0; j < 4; j++) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1004 | if ((*matches)[j].slot && |
| 1005 | (*matches)[j].slot == dmi_fields[i].field) { |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 1006 | sprintf(alias + strlen(alias), ":%s*", |
| 1007 | dmi_fields[i].prefix); |
| 1008 | dmi_ascii_filter(alias + strlen(alias), |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1009 | (*matches)[j].substr); |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 1010 | strcat(alias, "*"); |
| 1011 | } |
| 1012 | } |
| 1013 | } |
| 1014 | |
| 1015 | strcat(alias, ":"); |
| 1016 | return 1; |
| 1017 | } |
Eric Miao | 57fee4a | 2009-02-04 11:52:40 +0800 | [diff] [blame] | 1018 | |
| 1019 | static int do_platform_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1020 | void *symval, char *alias) |
Eric Miao | 57fee4a | 2009-02-04 11:52:40 +0800 | [diff] [blame] | 1021 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1022 | DEF_FIELD_ADDR(symval, platform_device_id, name); |
| 1023 | sprintf(alias, PLATFORM_MODULE_PREFIX "%s", *name); |
Eric Miao | 57fee4a | 2009-02-04 11:52:40 +0800 | [diff] [blame] | 1024 | return 1; |
| 1025 | } |
| 1026 | |
David Woodhouse | 8626d3b | 2010-04-02 01:05:27 +0000 | [diff] [blame] | 1027 | static int do_mdio_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1028 | void *symval, char *alias) |
David Woodhouse | 8626d3b | 2010-04-02 01:05:27 +0000 | [diff] [blame] | 1029 | { |
| 1030 | int i; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1031 | DEF_FIELD(symval, mdio_device_id, phy_id); |
| 1032 | DEF_FIELD(symval, mdio_device_id, phy_id_mask); |
David Woodhouse | 8626d3b | 2010-04-02 01:05:27 +0000 | [diff] [blame] | 1033 | |
| 1034 | alias += sprintf(alias, MDIO_MODULE_PREFIX); |
| 1035 | |
| 1036 | for (i = 0; i < 32; i++) { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1037 | if (!((phy_id_mask >> (31-i)) & 1)) |
David Woodhouse | 8626d3b | 2010-04-02 01:05:27 +0000 | [diff] [blame] | 1038 | *(alias++) = '?'; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1039 | else if ((phy_id >> (31-i)) & 1) |
David Woodhouse | 8626d3b | 2010-04-02 01:05:27 +0000 | [diff] [blame] | 1040 | *(alias++) = '1'; |
| 1041 | else |
| 1042 | *(alias++) = '0'; |
| 1043 | } |
| 1044 | |
| 1045 | /* Terminate the string */ |
| 1046 | *alias = 0; |
| 1047 | |
| 1048 | return 1; |
| 1049 | } |
| 1050 | |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 1051 | /* Looks like: zorro:iN. */ |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1052 | static int do_zorro_entry(const char *filename, void *symval, |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 1053 | char *alias) |
| 1054 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1055 | DEF_FIELD(symval, zorro_device_id, id); |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 1056 | strcpy(alias, "zorro:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1057 | ADD(alias, "i", id != ZORRO_WILDCARD, id); |
Geert Uytterhoeven | bf54a2b | 2008-11-18 21:13:53 +0100 | [diff] [blame] | 1058 | return 1; |
| 1059 | } |
| 1060 | |
Ondrej Zary | fedb3d2 | 2009-12-18 20:52:39 +0100 | [diff] [blame] | 1061 | /* looks like: "pnp:dD" */ |
| 1062 | static int do_isapnp_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1063 | void *symval, char *alias) |
Ondrej Zary | fedb3d2 | 2009-12-18 20:52:39 +0100 | [diff] [blame] | 1064 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1065 | DEF_FIELD(symval, isapnp_device_id, vendor); |
| 1066 | DEF_FIELD(symval, isapnp_device_id, function); |
Ondrej Zary | fedb3d2 | 2009-12-18 20:52:39 +0100 | [diff] [blame] | 1067 | sprintf(alias, "pnp:d%c%c%c%x%x%x%x*", |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1068 | 'A' + ((vendor >> 2) & 0x3f) - 1, |
| 1069 | 'A' + (((vendor & 3) << 3) | ((vendor >> 13) & 7)) - 1, |
| 1070 | 'A' + ((vendor >> 8) & 0x1f) - 1, |
| 1071 | (function >> 4) & 0x0f, function & 0x0f, |
| 1072 | (function >> 12) & 0x0f, (function >> 8) & 0x0f); |
Ondrej Zary | fedb3d2 | 2009-12-18 20:52:39 +0100 | [diff] [blame] | 1073 | return 1; |
| 1074 | } |
| 1075 | |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 1076 | /* Looks like: "ipack:fNvNdN". */ |
| 1077 | static int do_ipack_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1078 | void *symval, char *alias) |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 1079 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1080 | DEF_FIELD(symval, ipack_device_id, format); |
| 1081 | DEF_FIELD(symval, ipack_device_id, vendor); |
| 1082 | DEF_FIELD(symval, ipack_device_id, device); |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 1083 | strcpy(alias, "ipack:"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1084 | ADD(alias, "f", format != IPACK_ANY_FORMAT, format); |
| 1085 | ADD(alias, "v", vendor != IPACK_ANY_ID, vendor); |
| 1086 | ADD(alias, "d", device != IPACK_ANY_ID, device); |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 1087 | add_wildcard(alias); |
| 1088 | return 1; |
| 1089 | } |
Jens Taprogge | 849e0ad | 2012-09-04 17:01:13 +0200 | [diff] [blame] | 1090 | |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1091 | /* |
| 1092 | * Append a match expression for a single masked hex digit. |
| 1093 | * outp points to a pointer to the character at which to append. |
| 1094 | * *outp is updated on return to point just after the appended text, |
| 1095 | * to facilitate further appending. |
| 1096 | */ |
| 1097 | static void append_nibble_mask(char **outp, |
| 1098 | unsigned int nibble, unsigned int mask) |
| 1099 | { |
| 1100 | char *p = *outp; |
| 1101 | unsigned int i; |
| 1102 | |
| 1103 | switch (mask) { |
| 1104 | case 0: |
| 1105 | *p++ = '?'; |
| 1106 | break; |
| 1107 | |
| 1108 | case 0xf: |
| 1109 | p += sprintf(p, "%X", nibble); |
| 1110 | break; |
| 1111 | |
| 1112 | default: |
| 1113 | /* |
| 1114 | * Dumbly emit a match pattern for all possible matching |
| 1115 | * digits. This could be improved in some cases using ranges, |
| 1116 | * but it has the advantage of being trivially correct, and is |
| 1117 | * often optimal. |
| 1118 | */ |
| 1119 | *p++ = '['; |
| 1120 | for (i = 0; i < 0x10; i++) |
| 1121 | if ((i & mask) == nibble) |
| 1122 | p += sprintf(p, "%X", i); |
| 1123 | *p++ = ']'; |
| 1124 | } |
| 1125 | |
| 1126 | /* Ensure that the string remains NUL-terminated: */ |
| 1127 | *p = '\0'; |
| 1128 | |
| 1129 | /* Advance the caller's end-of-string pointer: */ |
| 1130 | *outp = p; |
| 1131 | } |
| 1132 | |
| 1133 | /* |
| 1134 | * looks like: "amba:dN" |
| 1135 | * |
| 1136 | * N is exactly 8 digits, where each is an upper-case hex digit, or |
| 1137 | * a ? or [] pattern matching exactly one digit. |
| 1138 | */ |
| 1139 | static int do_amba_entry(const char *filename, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1140 | void *symval, char *alias) |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1141 | { |
| 1142 | unsigned int digit; |
| 1143 | char *p = alias; |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1144 | DEF_FIELD(symval, amba_id, id); |
| 1145 | DEF_FIELD(symval, amba_id, mask); |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1146 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1147 | if ((id & mask) != id) |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1148 | fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: " |
| 1149 | "id=0x%08X, mask=0x%08X. Please fix this driver.\n", |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1150 | filename, id, mask); |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1151 | |
| 1152 | p += sprintf(alias, "amba:d"); |
| 1153 | for (digit = 0; digit < 8; digit++) |
| 1154 | append_nibble_mask(&p, |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1155 | (id >> (4 * (7 - digit))) & 0xf, |
| 1156 | (mask >> (4 * (7 - digit))) & 0xf); |
Dave Martin | 523817b | 2011-10-05 14:44:57 +0100 | [diff] [blame] | 1157 | |
| 1158 | return 1; |
| 1159 | } |
| 1160 | |
James Hogan | 8286ae0 | 2015-03-25 15:39:50 +0000 | [diff] [blame] | 1161 | /* |
| 1162 | * looks like: "mipscdmm:tN" |
| 1163 | * |
| 1164 | * N is exactly 2 digits, where each is an upper-case hex digit, or |
| 1165 | * a ? or [] pattern matching exactly one digit. |
| 1166 | */ |
| 1167 | static int do_mips_cdmm_entry(const char *filename, |
| 1168 | void *symval, char *alias) |
| 1169 | { |
| 1170 | DEF_FIELD(symval, mips_cdmm_device_id, type); |
| 1171 | |
| 1172 | sprintf(alias, "mipscdmm:t%02X*", type); |
| 1173 | return 1; |
| 1174 | } |
James Hogan | 8286ae0 | 2015-03-25 15:39:50 +0000 | [diff] [blame] | 1175 | |
Ard Biesheuvel | 2b9c1f0 | 2014-02-08 13:34:10 +0100 | [diff] [blame] | 1176 | /* LOOKS like cpu:type:x86,venVVVVfamFFFFmodMMMM:feature:*,FEAT,* |
Andi Kleen | 644e9cb | 2012-01-26 00:09:05 +0100 | [diff] [blame] | 1177 | * All fields are numbers. It would be nicer to use strings for vendor |
| 1178 | * and feature, but getting those out of the build system here is too |
| 1179 | * complicated. |
| 1180 | */ |
| 1181 | |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1182 | static int do_x86cpu_entry(const char *filename, void *symval, |
Andi Kleen | 644e9cb | 2012-01-26 00:09:05 +0100 | [diff] [blame] | 1183 | char *alias) |
| 1184 | { |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1185 | DEF_FIELD(symval, x86_cpu_id, feature); |
| 1186 | DEF_FIELD(symval, x86_cpu_id, family); |
| 1187 | DEF_FIELD(symval, x86_cpu_id, model); |
| 1188 | DEF_FIELD(symval, x86_cpu_id, vendor); |
Andi Kleen | 644e9cb | 2012-01-26 00:09:05 +0100 | [diff] [blame] | 1189 | |
Ard Biesheuvel | 2b9c1f0 | 2014-02-08 13:34:10 +0100 | [diff] [blame] | 1190 | strcpy(alias, "cpu:type:x86,"); |
| 1191 | ADD(alias, "ven", vendor != X86_VENDOR_ANY, vendor); |
| 1192 | ADD(alias, "fam", family != X86_FAMILY_ANY, family); |
| 1193 | ADD(alias, "mod", model != X86_MODEL_ANY, model); |
Ben Hutchings | 5467bdd | 2012-02-11 22:57:19 +0000 | [diff] [blame] | 1194 | strcat(alias, ":feature:*"); |
Andreas Schwab | 6543bec | 2013-01-20 17:58:47 +0100 | [diff] [blame] | 1195 | if (feature != X86_FEATURE_ANY) |
| 1196 | sprintf(alias + strlen(alias), "%04X*", feature); |
Andi Kleen | 644e9cb | 2012-01-26 00:09:05 +0100 | [diff] [blame] | 1197 | return 1; |
| 1198 | } |
Andi Kleen | 644e9cb | 2012-01-26 00:09:05 +0100 | [diff] [blame] | 1199 | |
Ard Biesheuvel | 67bad2f | 2014-02-08 13:34:09 +0100 | [diff] [blame] | 1200 | /* LOOKS like cpu:type:*:feature:*FEAT* */ |
| 1201 | static int do_cpu_entry(const char *filename, void *symval, char *alias) |
| 1202 | { |
| 1203 | DEF_FIELD(symval, cpu_feature, feature); |
| 1204 | |
| 1205 | sprintf(alias, "cpu:type:*:feature:*%04X*", feature); |
| 1206 | return 1; |
| 1207 | } |
Ard Biesheuvel | 67bad2f | 2014-02-08 13:34:09 +0100 | [diff] [blame] | 1208 | |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 1209 | /* Looks like: mei:S:uuid:N:* */ |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 1210 | static int do_mei_entry(const char *filename, void *symval, |
| 1211 | char *alias) |
| 1212 | { |
| 1213 | DEF_FIELD_ADDR(symval, mei_cl_device_id, name); |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 1214 | DEF_FIELD_ADDR(symval, mei_cl_device_id, uuid); |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 1215 | DEF_FIELD(symval, mei_cl_device_id, version); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 1216 | |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 1217 | sprintf(alias, MEI_CL_MODULE_PREFIX); |
| 1218 | sprintf(alias + strlen(alias), "%s:", (*name)[0] ? *name : "*"); |
| 1219 | add_uuid(alias, *uuid); |
Tomas Winkler | b26864c | 2015-09-10 10:18:01 +0300 | [diff] [blame] | 1220 | ADD(alias, ":", version != MEI_CL_VERSION_ANY, version); |
Tomas Winkler | c93b76b | 2015-05-07 15:54:02 +0300 | [diff] [blame] | 1221 | |
| 1222 | strcat(alias, ":*"); |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 1223 | |
| 1224 | return 1; |
| 1225 | } |
Samuel Ortiz | e535410 | 2013-03-27 17:29:53 +0200 | [diff] [blame] | 1226 | |
Alexandre Bounine | 3bdbb62 | 2013-07-03 15:08:58 -0700 | [diff] [blame] | 1227 | /* Looks like: rapidio:vNdNavNadN */ |
| 1228 | static int do_rio_entry(const char *filename, |
| 1229 | void *symval, char *alias) |
| 1230 | { |
| 1231 | DEF_FIELD(symval, rio_device_id, did); |
| 1232 | DEF_FIELD(symval, rio_device_id, vid); |
| 1233 | DEF_FIELD(symval, rio_device_id, asm_did); |
| 1234 | DEF_FIELD(symval, rio_device_id, asm_vid); |
| 1235 | |
| 1236 | strcpy(alias, "rapidio:"); |
| 1237 | ADD(alias, "v", vid != RIO_ANY_ID, vid); |
| 1238 | ADD(alias, "d", did != RIO_ANY_ID, did); |
| 1239 | ADD(alias, "av", asm_vid != RIO_ANY_ID, asm_vid); |
| 1240 | ADD(alias, "ad", asm_did != RIO_ANY_ID, asm_did); |
| 1241 | |
| 1242 | add_wildcard(alias); |
| 1243 | return 1; |
| 1244 | } |
Alexandre Bounine | 3bdbb62 | 2013-07-03 15:08:58 -0700 | [diff] [blame] | 1245 | |
Heikki Krogerus | 289fcff | 2015-05-13 15:26:42 +0300 | [diff] [blame] | 1246 | /* Looks like: ulpi:vNpN */ |
| 1247 | static int do_ulpi_entry(const char *filename, void *symval, |
| 1248 | char *alias) |
| 1249 | { |
| 1250 | DEF_FIELD(symval, ulpi_device_id, vendor); |
| 1251 | DEF_FIELD(symval, ulpi_device_id, product); |
| 1252 | |
| 1253 | sprintf(alias, "ulpi:v%04xp%04x", vendor, product); |
| 1254 | |
| 1255 | return 1; |
| 1256 | } |
Heikki Krogerus | 289fcff | 2015-05-13 15:26:42 +0300 | [diff] [blame] | 1257 | |
Subhransu S. Prusty | da23ac1 | 2015-09-29 13:56:10 +0530 | [diff] [blame] | 1258 | /* Looks like: hdaudio:vNrNaN */ |
| 1259 | static int do_hda_entry(const char *filename, void *symval, char *alias) |
| 1260 | { |
| 1261 | DEF_FIELD(symval, hda_device_id, vendor_id); |
| 1262 | DEF_FIELD(symval, hda_device_id, rev_id); |
| 1263 | DEF_FIELD(symval, hda_device_id, api_version); |
| 1264 | |
| 1265 | strcpy(alias, "hdaudio:"); |
| 1266 | ADD(alias, "v", vendor_id != 0, vendor_id); |
| 1267 | ADD(alias, "r", rev_id != 0, rev_id); |
| 1268 | ADD(alias, "a", api_version != 0, api_version); |
| 1269 | |
| 1270 | add_wildcard(alias); |
| 1271 | return 1; |
| 1272 | } |
Subhransu S. Prusty | da23ac1 | 2015-09-29 13:56:10 +0530 | [diff] [blame] | 1273 | |
Pierre-Louis Bossart | b592426 | 2020-06-09 04:54:35 +0800 | [diff] [blame] | 1274 | /* Looks like: sdw:mNpNvNcN */ |
Vinod Koul | 9251345 | 2017-12-14 11:19:33 +0530 | [diff] [blame] | 1275 | static int do_sdw_entry(const char *filename, void *symval, char *alias) |
| 1276 | { |
| 1277 | DEF_FIELD(symval, sdw_device_id, mfg_id); |
| 1278 | DEF_FIELD(symval, sdw_device_id, part_id); |
Pierre-Louis Bossart | b592426 | 2020-06-09 04:54:35 +0800 | [diff] [blame] | 1279 | DEF_FIELD(symval, sdw_device_id, sdw_version); |
| 1280 | DEF_FIELD(symval, sdw_device_id, class_id); |
Vinod Koul | 9251345 | 2017-12-14 11:19:33 +0530 | [diff] [blame] | 1281 | |
| 1282 | strcpy(alias, "sdw:"); |
| 1283 | ADD(alias, "m", mfg_id != 0, mfg_id); |
| 1284 | ADD(alias, "p", part_id != 0, part_id); |
Pierre-Louis Bossart | b592426 | 2020-06-09 04:54:35 +0800 | [diff] [blame] | 1285 | ADD(alias, "v", sdw_version != 0, sdw_version); |
| 1286 | ADD(alias, "c", class_id != 0, class_id); |
Vinod Koul | 9251345 | 2017-12-14 11:19:33 +0530 | [diff] [blame] | 1287 | |
| 1288 | add_wildcard(alias); |
| 1289 | return 1; |
| 1290 | } |
Vinod Koul | 9251345 | 2017-12-14 11:19:33 +0530 | [diff] [blame] | 1291 | |
Stuart Yoder | 0afef45 | 2016-06-22 16:40:45 -0500 | [diff] [blame] | 1292 | /* Looks like: fsl-mc:vNdN */ |
| 1293 | static int do_fsl_mc_entry(const char *filename, void *symval, |
| 1294 | char *alias) |
| 1295 | { |
| 1296 | DEF_FIELD(symval, fsl_mc_device_id, vendor); |
| 1297 | DEF_FIELD_ADDR(symval, fsl_mc_device_id, obj_type); |
| 1298 | |
| 1299 | sprintf(alias, "fsl-mc:v%08Xd%s", vendor, *obj_type); |
| 1300 | return 1; |
| 1301 | } |
Stuart Yoder | 0afef45 | 2016-06-22 16:40:45 -0500 | [diff] [blame] | 1302 | |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 1303 | /* Looks like: tbsvc:kSpNvNrN */ |
| 1304 | static int do_tbsvc_entry(const char *filename, void *symval, char *alias) |
| 1305 | { |
| 1306 | DEF_FIELD(symval, tb_service_id, match_flags); |
| 1307 | DEF_FIELD_ADDR(symval, tb_service_id, protocol_key); |
| 1308 | DEF_FIELD(symval, tb_service_id, protocol_id); |
| 1309 | DEF_FIELD(symval, tb_service_id, protocol_version); |
| 1310 | DEF_FIELD(symval, tb_service_id, protocol_revision); |
| 1311 | |
| 1312 | strcpy(alias, "tbsvc:"); |
| 1313 | if (match_flags & TBSVC_MATCH_PROTOCOL_KEY) |
| 1314 | sprintf(alias + strlen(alias), "k%s", *protocol_key); |
| 1315 | else |
| 1316 | strcat(alias + strlen(alias), "k*"); |
| 1317 | ADD(alias, "p", match_flags & TBSVC_MATCH_PROTOCOL_ID, protocol_id); |
| 1318 | ADD(alias, "v", match_flags & TBSVC_MATCH_PROTOCOL_VERSION, |
| 1319 | protocol_version); |
| 1320 | ADD(alias, "r", match_flags & TBSVC_MATCH_PROTOCOL_REVISION, |
| 1321 | protocol_revision); |
| 1322 | |
| 1323 | add_wildcard(alias); |
| 1324 | return 1; |
| 1325 | } |
Mika Westerberg | d1ff702 | 2017-10-02 13:38:34 +0300 | [diff] [blame] | 1326 | |
Heikki Krogerus | 8a37d87 | 2018-06-27 18:19:50 +0300 | [diff] [blame] | 1327 | /* Looks like: typec:idNmN */ |
| 1328 | static int do_typec_entry(const char *filename, void *symval, char *alias) |
| 1329 | { |
| 1330 | DEF_FIELD(symval, typec_device_id, svid); |
| 1331 | DEF_FIELD(symval, typec_device_id, mode); |
| 1332 | |
| 1333 | sprintf(alias, "typec:id%04X", svid); |
| 1334 | ADD(alias, "m", mode != TYPEC_ANY_MODE, mode); |
| 1335 | |
| 1336 | return 1; |
| 1337 | } |
Heikki Krogerus | 8a37d87 | 2018-06-27 18:19:50 +0300 | [diff] [blame] | 1338 | |
Sumit Garg | 0fc1db9 | 2019-01-29 11:19:35 +0530 | [diff] [blame] | 1339 | /* Looks like: tee:uuid */ |
| 1340 | static int do_tee_entry(const char *filename, void *symval, char *alias) |
| 1341 | { |
Masahiro Yamada | 1308e55 | 2023-10-08 02:04:44 +0900 | [diff] [blame] | 1342 | DEF_FIELD_ADDR(symval, tee_client_device_id, uuid); |
Sumit Garg | 0fc1db9 | 2019-01-29 11:19:35 +0530 | [diff] [blame] | 1343 | |
| 1344 | sprintf(alias, "tee:%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", |
Masahiro Yamada | 1308e55 | 2023-10-08 02:04:44 +0900 | [diff] [blame] | 1345 | uuid->b[0], uuid->b[1], uuid->b[2], uuid->b[3], uuid->b[4], |
| 1346 | uuid->b[5], uuid->b[6], uuid->b[7], uuid->b[8], uuid->b[9], |
| 1347 | uuid->b[10], uuid->b[11], uuid->b[12], uuid->b[13], uuid->b[14], |
| 1348 | uuid->b[15]); |
Sumit Garg | 0fc1db9 | 2019-01-29 11:19:35 +0530 | [diff] [blame] | 1349 | |
| 1350 | add_wildcard(alias); |
| 1351 | return 1; |
| 1352 | } |
| 1353 | |
Mattias Jacobsson | 0bc44b2 | 2019-02-19 20:59:50 +0100 | [diff] [blame] | 1354 | /* Looks like: wmi:guid */ |
| 1355 | static int do_wmi_entry(const char *filename, void *symval, char *alias) |
| 1356 | { |
| 1357 | int len; |
| 1358 | DEF_FIELD_ADDR(symval, wmi_device_id, guid_string); |
| 1359 | |
| 1360 | if (strlen(*guid_string) != UUID_STRING_LEN) { |
| 1361 | warn("Invalid WMI device id 'wmi:%s' in '%s'\n", |
| 1362 | *guid_string, filename); |
| 1363 | return 0; |
| 1364 | } |
| 1365 | |
| 1366 | len = snprintf(alias, ALIAS_SIZE, WMI_MODULE_PREFIX "%s", *guid_string); |
| 1367 | if (len < 0 || len >= ALIAS_SIZE) { |
| 1368 | warn("Could not generate all MODULE_ALIAS's in '%s'\n", |
| 1369 | filename); |
| 1370 | return 0; |
| 1371 | } |
| 1372 | return 1; |
| 1373 | } |
| 1374 | |
Manivannan Sadhasivam | e6b0de46 | 2020-02-20 15:28:50 +0530 | [diff] [blame] | 1375 | /* Looks like: mhi:S */ |
| 1376 | static int do_mhi_entry(const char *filename, void *symval, char *alias) |
| 1377 | { |
| 1378 | DEF_FIELD_ADDR(symval, mhi_device_id, chan); |
| 1379 | sprintf(alias, MHI_DEVICE_MODALIAS_FMT, *chan); |
Dave Ertman | 7de3697 | 2020-12-02 16:54:24 -0800 | [diff] [blame] | 1380 | return 1; |
| 1381 | } |
| 1382 | |
| 1383 | static int do_auxiliary_entry(const char *filename, void *symval, char *alias) |
| 1384 | { |
| 1385 | DEF_FIELD_ADDR(symval, auxiliary_device_id, name); |
| 1386 | sprintf(alias, AUXILIARY_MODULE_PREFIX "%s", *name); |
Manivannan Sadhasivam | e6b0de46 | 2020-02-20 15:28:50 +0530 | [diff] [blame] | 1387 | |
| 1388 | return 1; |
| 1389 | } |
| 1390 | |
Maximilian Luz | eb0e90a | 2020-12-21 19:39:56 +0100 | [diff] [blame] | 1391 | /* |
| 1392 | * Looks like: ssam:dNcNtNiNfN |
| 1393 | * |
| 1394 | * N is exactly 2 digits, where each is an upper-case hex digit. |
| 1395 | */ |
| 1396 | static int do_ssam_entry(const char *filename, void *symval, char *alias) |
| 1397 | { |
| 1398 | DEF_FIELD(symval, ssam_device_id, match_flags); |
| 1399 | DEF_FIELD(symval, ssam_device_id, domain); |
| 1400 | DEF_FIELD(symval, ssam_device_id, category); |
| 1401 | DEF_FIELD(symval, ssam_device_id, target); |
| 1402 | DEF_FIELD(symval, ssam_device_id, instance); |
| 1403 | DEF_FIELD(symval, ssam_device_id, function); |
| 1404 | |
| 1405 | sprintf(alias, "ssam:d%02Xc%02X", domain, category); |
| 1406 | ADD(alias, "t", match_flags & SSAM_MATCH_TARGET, target); |
| 1407 | ADD(alias, "i", match_flags & SSAM_MATCH_INSTANCE, instance); |
| 1408 | ADD(alias, "f", match_flags & SSAM_MATCH_FUNCTION, function); |
| 1409 | |
| 1410 | return 1; |
| 1411 | } |
| 1412 | |
Xu Yilun | 4a224ac | 2021-01-06 20:37:11 -0800 | [diff] [blame] | 1413 | /* Looks like: dfl:tNfN */ |
| 1414 | static int do_dfl_entry(const char *filename, void *symval, char *alias) |
| 1415 | { |
| 1416 | DEF_FIELD(symval, dfl_device_id, type); |
| 1417 | DEF_FIELD(symval, dfl_device_id, feature_id); |
| 1418 | |
| 1419 | sprintf(alias, "dfl:t%04Xf%04X", type, feature_id); |
| 1420 | |
| 1421 | add_wildcard(alias); |
| 1422 | return 1; |
| 1423 | } |
| 1424 | |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1425 | /* Does namelen bytes of name exactly match the symbol? */ |
| 1426 | static bool sym_is(const char *name, unsigned namelen, const char *symbol) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1427 | { |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1428 | if (namelen != strlen(symbol)) |
| 1429 | return false; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1431 | return memcmp(name, symbol, namelen) == 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1432 | } |
| 1433 | |
| 1434 | static void do_table(void *symval, unsigned long size, |
| 1435 | unsigned long id_size, |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 1436 | const char *device_id, |
Masahiro Yamada | f880eea | 2018-11-22 13:28:42 +0900 | [diff] [blame] | 1437 | int (*do_entry)(const char *filename, void *symval, char *alias), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1438 | struct module *mod) |
| 1439 | { |
| 1440 | unsigned int i; |
Mattias Jacobsson | 841f1b8 | 2019-02-07 13:30:22 +0100 | [diff] [blame] | 1441 | char alias[ALIAS_SIZE]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1442 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1443 | device_id_check(mod->name, device_id, size, id_size, symval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1444 | /* Leave last one: it's the terminator. */ |
| 1445 | size -= id_size; |
| 1446 | |
| 1447 | for (i = 0; i < size; i += id_size) { |
| 1448 | if (do_entry(mod->name, symval+i, alias)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1449 | buf_printf(&mod->dev_table_buf, |
| 1450 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 1451 | } |
| 1452 | } |
| 1453 | } |
| 1454 | |
Masahiro Yamada | ec91e78d | 2018-11-22 13:28:41 +0900 | [diff] [blame] | 1455 | static const struct devtable devtable[] = { |
| 1456 | {"hid", SIZE_hid_device_id, do_hid_entry}, |
| 1457 | {"ieee1394", SIZE_ieee1394_device_id, do_ieee1394_entry}, |
| 1458 | {"pci", SIZE_pci_device_id, do_pci_entry}, |
| 1459 | {"ccw", SIZE_ccw_device_id, do_ccw_entry}, |
| 1460 | {"ap", SIZE_ap_device_id, do_ap_entry}, |
| 1461 | {"css", SIZE_css_device_id, do_css_entry}, |
| 1462 | {"serio", SIZE_serio_device_id, do_serio_entry}, |
| 1463 | {"acpi", SIZE_acpi_device_id, do_acpi_entry}, |
| 1464 | {"pcmcia", SIZE_pcmcia_device_id, do_pcmcia_entry}, |
| 1465 | {"vio", SIZE_vio_device_id, do_vio_entry}, |
| 1466 | {"input", SIZE_input_device_id, do_input_entry}, |
| 1467 | {"eisa", SIZE_eisa_device_id, do_eisa_entry}, |
| 1468 | {"parisc", SIZE_parisc_device_id, do_parisc_entry}, |
| 1469 | {"sdio", SIZE_sdio_device_id, do_sdio_entry}, |
| 1470 | {"ssb", SIZE_ssb_device_id, do_ssb_entry}, |
| 1471 | {"bcma", SIZE_bcma_device_id, do_bcma_entry}, |
| 1472 | {"virtio", SIZE_virtio_device_id, do_virtio_entry}, |
| 1473 | {"vmbus", SIZE_hv_vmbus_device_id, do_vmbus_entry}, |
| 1474 | {"rpmsg", SIZE_rpmsg_device_id, do_rpmsg_entry}, |
| 1475 | {"i2c", SIZE_i2c_device_id, do_i2c_entry}, |
Boris Brezillon | 1ce589a | 2020-02-27 12:31:08 +0100 | [diff] [blame] | 1476 | {"i3c", SIZE_i3c_device_id, do_i3c_entry}, |
Masahiro Yamada | ec91e78d | 2018-11-22 13:28:41 +0900 | [diff] [blame] | 1477 | {"spi", SIZE_spi_device_id, do_spi_entry}, |
| 1478 | {"dmi", SIZE_dmi_system_id, do_dmi_entry}, |
| 1479 | {"platform", SIZE_platform_device_id, do_platform_entry}, |
| 1480 | {"mdio", SIZE_mdio_device_id, do_mdio_entry}, |
| 1481 | {"zorro", SIZE_zorro_device_id, do_zorro_entry}, |
| 1482 | {"isapnp", SIZE_isapnp_device_id, do_isapnp_entry}, |
| 1483 | {"ipack", SIZE_ipack_device_id, do_ipack_entry}, |
| 1484 | {"amba", SIZE_amba_id, do_amba_entry}, |
| 1485 | {"mipscdmm", SIZE_mips_cdmm_device_id, do_mips_cdmm_entry}, |
| 1486 | {"x86cpu", SIZE_x86_cpu_id, do_x86cpu_entry}, |
| 1487 | {"cpu", SIZE_cpu_feature, do_cpu_entry}, |
| 1488 | {"mei", SIZE_mei_cl_device_id, do_mei_entry}, |
| 1489 | {"rapidio", SIZE_rio_device_id, do_rio_entry}, |
| 1490 | {"ulpi", SIZE_ulpi_device_id, do_ulpi_entry}, |
| 1491 | {"hdaudio", SIZE_hda_device_id, do_hda_entry}, |
| 1492 | {"sdw", SIZE_sdw_device_id, do_sdw_entry}, |
| 1493 | {"fslmc", SIZE_fsl_mc_device_id, do_fsl_mc_entry}, |
| 1494 | {"tbsvc", SIZE_tb_service_id, do_tbsvc_entry}, |
| 1495 | {"typec", SIZE_typec_device_id, do_typec_entry}, |
Sumit Garg | 0fc1db9 | 2019-01-29 11:19:35 +0530 | [diff] [blame] | 1496 | {"tee", SIZE_tee_client_device_id, do_tee_entry}, |
Mattias Jacobsson | 0bc44b2 | 2019-02-19 20:59:50 +0100 | [diff] [blame] | 1497 | {"wmi", SIZE_wmi_device_id, do_wmi_entry}, |
Manivannan Sadhasivam | e6b0de46 | 2020-02-20 15:28:50 +0530 | [diff] [blame] | 1498 | {"mhi", SIZE_mhi_device_id, do_mhi_entry}, |
Dave Ertman | 7de3697 | 2020-12-02 16:54:24 -0800 | [diff] [blame] | 1499 | {"auxiliary", SIZE_auxiliary_device_id, do_auxiliary_entry}, |
Maximilian Luz | eb0e90a | 2020-12-21 19:39:56 +0100 | [diff] [blame] | 1500 | {"ssam", SIZE_ssam_device_id, do_ssam_entry}, |
Xu Yilun | 4a224ac | 2021-01-06 20:37:11 -0800 | [diff] [blame] | 1501 | {"dfl", SIZE_dfl_device_id, do_dfl_entry}, |
Masahiro Yamada | ec91e78d | 2018-11-22 13:28:41 +0900 | [diff] [blame] | 1502 | }; |
| 1503 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1504 | /* Create MODULE_ALIAS() statements. |
| 1505 | * At this time, we cannot write the actual output C source yet, |
| 1506 | * so we write into the mod->dev_table_buf buffer. */ |
| 1507 | void handle_moddevtable(struct module *mod, struct elf_info *info, |
| 1508 | Elf_Sym *sym, const char *symname) |
| 1509 | { |
| 1510 | void *symval; |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1511 | char *zeros = NULL; |
Tom Gundersen | 21bdd17 | 2014-02-03 11:14:13 +1030 | [diff] [blame] | 1512 | const char *name, *identifier; |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1513 | unsigned int namelen; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1514 | |
| 1515 | /* We're looking for a section relative symbol */ |
Denys Vlasenko | 1ce53ad | 2010-07-29 01:47:53 +0200 | [diff] [blame] | 1516 | if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1517 | return; |
| 1518 | |
David Miller | e88aa7b | 2012-04-12 14:37:30 -0400 | [diff] [blame] | 1519 | /* We're looking for an object */ |
| 1520 | if (ELF_ST_TYPE(sym->st_info) != STT_OBJECT) |
| 1521 | return; |
| 1522 | |
Masahiro Yamada | 153e04b | 2018-09-28 15:21:55 +0900 | [diff] [blame] | 1523 | /* All our symbols are of form __mod_<name>__<identifier>_device_table. */ |
| 1524 | if (strncmp(symname, "__mod_", strlen("__mod_"))) |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1525 | return; |
Masahiro Yamada | 153e04b | 2018-09-28 15:21:55 +0900 | [diff] [blame] | 1526 | name = symname + strlen("__mod_"); |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1527 | namelen = strlen(name); |
| 1528 | if (namelen < strlen("_device_table")) |
| 1529 | return; |
| 1530 | if (strcmp(name + namelen - strlen("_device_table"), "_device_table")) |
| 1531 | return; |
Tom Gundersen | 21bdd17 | 2014-02-03 11:14:13 +1030 | [diff] [blame] | 1532 | identifier = strstr(name, "__"); |
| 1533 | if (!identifier) |
| 1534 | return; |
| 1535 | namelen = identifier - name; |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1536 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1537 | /* Handle all-NULL symbols allocated into .bss */ |
Denys Vlasenko | 1ce53ad | 2010-07-29 01:47:53 +0200 | [diff] [blame] | 1538 | if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1539 | zeros = calloc(1, sym->st_size); |
| 1540 | symval = zeros; |
| 1541 | } else { |
| 1542 | symval = (void *)info->hdr |
Denys Vlasenko | 1ce53ad | 2010-07-29 01:47:53 +0200 | [diff] [blame] | 1543 | + info->sechdrs[get_secindex(info, sym)].sh_offset |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1544 | + sym->st_value; |
| 1545 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1546 | |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1547 | /* First handle the "special" cases */ |
| 1548 | if (sym_is(name, namelen, "usb")) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 1549 | do_usb_table(symval, sym->st_size, mod); |
Mauricio Faria de Oliveira | bdb4fcf | 2023-09-28 17:28:07 -0300 | [diff] [blame] | 1550 | else if (sym_is(name, namelen, "of")) |
Philipp Zabel | acbef7b | 2016-05-05 16:22:29 -0700 | [diff] [blame] | 1551 | do_of_table(symval, sym->st_size, mod); |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1552 | else if (sym_is(name, namelen, "pnp")) |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 1553 | do_pnp_device_entry(symval, sym->st_size, mod); |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1554 | else if (sym_is(name, namelen, "pnp_card")) |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 1555 | do_pnp_card_entries(symval, sym->st_size, mod); |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1556 | else { |
Masahiro Yamada | ec91e78d | 2018-11-22 13:28:41 +0900 | [diff] [blame] | 1557 | int i; |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1558 | |
Masahiro Yamada | ec91e78d | 2018-11-22 13:28:41 +0900 | [diff] [blame] | 1559 | for (i = 0; i < ARRAY_SIZE(devtable); i++) { |
| 1560 | const struct devtable *p = &devtable[i]; |
| 1561 | |
| 1562 | if (sym_is(name, namelen, p->device_id)) { |
| 1563 | do_table(symval, sym->st_size, p->id_size, |
Masahiro Yamada | f880eea | 2018-11-22 13:28:42 +0900 | [diff] [blame] | 1564 | p->device_id, p->do_entry, mod); |
Rusty Russell | 626596e | 2012-01-13 09:32:15 +1030 | [diff] [blame] | 1565 | break; |
| 1566 | } |
| 1567 | } |
| 1568 | } |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 1569 | free(zeros); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | } |
| 1571 | |
| 1572 | /* Now add out buffered information to the generated C source */ |
| 1573 | void add_moddevtable(struct buffer *buf, struct module *mod) |
| 1574 | { |
| 1575 | buf_printf(buf, "\n"); |
| 1576 | buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos); |
| 1577 | free(mod->dev_table_buf.p); |
| 1578 | } |