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