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