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