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