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