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