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