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 | |
Sam Ravnborg | 4ce6efe | 2008-03-23 21:38:54 +0100 | [diff] [blame] | 54 | unsigned int cross_build = 0; |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 55 | /** |
| 56 | * Check that sizeof(device_id type) are consistent with size of section |
| 57 | * in .o file. If in-consistent then userspace and kernel does not agree |
| 58 | * on actual size which is a bug. |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 59 | * Also verify that the final entry in the table is all zeros. |
Sam Ravnborg | 4ce6efe | 2008-03-23 21:38:54 +0100 | [diff] [blame] | 60 | * 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] | 61 | **/ |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 62 | static void device_id_check(const char *modname, const char *device_id, |
| 63 | unsigned long size, unsigned long id_size, |
| 64 | void *symval) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 65 | { |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 66 | int i; |
| 67 | |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 68 | if (size % id_size || size < id_size) { |
Sam Ravnborg | 4ce6efe | 2008-03-23 21:38:54 +0100 | [diff] [blame] | 69 | if (cross_build != 0) |
| 70 | return; |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 71 | fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo " |
| 72 | "of the size of section __mod_%s_device_table=%lu.\n" |
| 73 | "Fix definition of struct %s_device_id " |
| 74 | "in mod_devicetable.h\n", |
| 75 | modname, device_id, id_size, device_id, size, device_id); |
| 76 | } |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 77 | /* Verify last one is a terminator */ |
| 78 | for (i = 0; i < id_size; i++ ) { |
| 79 | if (*(uint8_t*)(symval+size-id_size+i)) { |
| 80 | fprintf(stderr,"%s: struct %s_device_id is %lu bytes. " |
| 81 | "The last of %lu is:\n", |
| 82 | modname, device_id, id_size, size / id_size); |
| 83 | for (i = 0; i < id_size; i++ ) |
| 84 | fprintf(stderr,"0x%02x ", |
| 85 | *(uint8_t*)(symval+size-id_size+i) ); |
| 86 | fprintf(stderr,"\n"); |
| 87 | fatal("%s: struct %s_device_id is not terminated " |
| 88 | "with a NULL entry!\n", modname, device_id); |
| 89 | } |
| 90 | } |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 91 | } |
| 92 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 93 | /* USB is special because the bcdDevice can be matched against a numeric range */ |
| 94 | /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */ |
| 95 | static void do_usb_entry(struct usb_device_id *id, |
| 96 | unsigned int bcdDevice_initial, int bcdDevice_initial_digits, |
| 97 | unsigned char range_lo, unsigned char range_hi, |
| 98 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 99 | { |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 100 | char alias[500]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | strcpy(alias, "usb:"); |
| 102 | ADD(alias, "v", id->match_flags&USB_DEVICE_ID_MATCH_VENDOR, |
| 103 | id->idVendor); |
| 104 | ADD(alias, "p", id->match_flags&USB_DEVICE_ID_MATCH_PRODUCT, |
| 105 | id->idProduct); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 106 | |
| 107 | strcat(alias, "d"); |
| 108 | if (bcdDevice_initial_digits) |
| 109 | sprintf(alias + strlen(alias), "%0*X", |
| 110 | bcdDevice_initial_digits, bcdDevice_initial); |
| 111 | if (range_lo == range_hi) |
| 112 | sprintf(alias + strlen(alias), "%u", range_lo); |
| 113 | else if (range_lo > 0 || range_hi < 9) |
| 114 | sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi); |
| 115 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) |
| 116 | strcat(alias, "*"); |
| 117 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | ADD(alias, "dc", id->match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS, |
| 119 | id->bDeviceClass); |
| 120 | ADD(alias, "dsc", |
| 121 | id->match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS, |
| 122 | id->bDeviceSubClass); |
| 123 | ADD(alias, "dp", |
| 124 | id->match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL, |
| 125 | id->bDeviceProtocol); |
| 126 | ADD(alias, "ic", |
| 127 | id->match_flags&USB_DEVICE_ID_MATCH_INT_CLASS, |
| 128 | id->bInterfaceClass); |
| 129 | ADD(alias, "isc", |
| 130 | id->match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS, |
| 131 | id->bInterfaceSubClass); |
| 132 | ADD(alias, "ip", |
| 133 | id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL, |
| 134 | id->bInterfaceProtocol); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 135 | |
| 136 | /* Always end in a wildcard, for future extension */ |
| 137 | if (alias[strlen(alias)-1] != '*') |
| 138 | strcat(alias, "*"); |
| 139 | buf_printf(&mod->dev_table_buf, |
| 140 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 141 | } |
| 142 | |
| 143 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) |
| 144 | { |
| 145 | unsigned int devlo, devhi; |
| 146 | unsigned char chi, clo; |
| 147 | int ndigits; |
| 148 | |
| 149 | id->match_flags = TO_NATIVE(id->match_flags); |
| 150 | id->idVendor = TO_NATIVE(id->idVendor); |
| 151 | id->idProduct = TO_NATIVE(id->idProduct); |
| 152 | |
| 153 | devlo = id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO ? |
| 154 | TO_NATIVE(id->bcdDevice_lo) : 0x0U; |
| 155 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? |
| 156 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; |
| 157 | |
| 158 | /* |
| 159 | * Some modules (visor) have empty slots as placeholder for |
| 160 | * run-time specification that results in catch-all alias |
| 161 | */ |
Greg Kroah-Hartman | de6f92b | 2008-01-28 09:50:12 -0800 | [diff] [blame] | 162 | if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass)) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 163 | return; |
| 164 | |
| 165 | /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */ |
| 166 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { |
| 167 | clo = devlo & 0xf; |
| 168 | chi = devhi & 0xf; |
| 169 | if (chi > 9) /* it's bcd not hex */ |
| 170 | chi = 9; |
| 171 | devlo >>= 4; |
| 172 | devhi >>= 4; |
| 173 | |
| 174 | if (devlo == devhi || !ndigits) { |
| 175 | do_usb_entry(id, devlo, ndigits, clo, chi, mod); |
| 176 | break; |
| 177 | } |
| 178 | |
| 179 | if (clo > 0) |
| 180 | do_usb_entry(id, devlo++, ndigits, clo, 9, mod); |
| 181 | |
| 182 | if (chi < 9) |
| 183 | do_usb_entry(id, devhi--, ndigits, 0, chi, mod); |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | static void do_usb_table(void *symval, unsigned long size, |
| 188 | struct module *mod) |
| 189 | { |
| 190 | unsigned int i; |
| 191 | const unsigned long id_size = sizeof(struct usb_device_id); |
| 192 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 193 | device_id_check(mod->name, "usb", size, id_size, symval); |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 194 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 195 | /* Leave last one: it's the terminator. */ |
| 196 | size -= id_size; |
| 197 | |
| 198 | for (i = 0; i < size; i += id_size) |
| 199 | do_usb_entry_multi(symval + i, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 200 | } |
| 201 | |
| 202 | /* Looks like: ieee1394:venNmoNspNverN */ |
| 203 | static int do_ieee1394_entry(const char *filename, |
| 204 | struct ieee1394_device_id *id, char *alias) |
| 205 | { |
| 206 | id->match_flags = TO_NATIVE(id->match_flags); |
| 207 | id->vendor_id = TO_NATIVE(id->vendor_id); |
| 208 | id->model_id = TO_NATIVE(id->model_id); |
| 209 | id->specifier_id = TO_NATIVE(id->specifier_id); |
| 210 | id->version = TO_NATIVE(id->version); |
| 211 | |
| 212 | strcpy(alias, "ieee1394:"); |
| 213 | ADD(alias, "ven", id->match_flags & IEEE1394_MATCH_VENDOR_ID, |
| 214 | id->vendor_id); |
| 215 | ADD(alias, "mo", id->match_flags & IEEE1394_MATCH_MODEL_ID, |
| 216 | id->model_id); |
| 217 | ADD(alias, "sp", id->match_flags & IEEE1394_MATCH_SPECIFIER_ID, |
| 218 | id->specifier_id); |
| 219 | ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION, |
| 220 | id->version); |
| 221 | |
| 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | /* Looks like: pci:vNdNsvNsdNbcNscNiN. */ |
| 226 | static int do_pci_entry(const char *filename, |
| 227 | struct pci_device_id *id, char *alias) |
| 228 | { |
| 229 | /* Class field can be divided into these three. */ |
| 230 | unsigned char baseclass, subclass, interface, |
| 231 | baseclass_mask, subclass_mask, interface_mask; |
| 232 | |
| 233 | id->vendor = TO_NATIVE(id->vendor); |
| 234 | id->device = TO_NATIVE(id->device); |
| 235 | id->subvendor = TO_NATIVE(id->subvendor); |
| 236 | id->subdevice = TO_NATIVE(id->subdevice); |
| 237 | id->class = TO_NATIVE(id->class); |
| 238 | id->class_mask = TO_NATIVE(id->class_mask); |
| 239 | |
| 240 | strcpy(alias, "pci:"); |
| 241 | ADD(alias, "v", id->vendor != PCI_ANY_ID, id->vendor); |
| 242 | ADD(alias, "d", id->device != PCI_ANY_ID, id->device); |
| 243 | ADD(alias, "sv", id->subvendor != PCI_ANY_ID, id->subvendor); |
| 244 | ADD(alias, "sd", id->subdevice != PCI_ANY_ID, id->subdevice); |
| 245 | |
| 246 | baseclass = (id->class) >> 16; |
| 247 | baseclass_mask = (id->class_mask) >> 16; |
| 248 | subclass = (id->class) >> 8; |
| 249 | subclass_mask = (id->class_mask) >> 8; |
| 250 | interface = id->class; |
| 251 | interface_mask = id->class_mask; |
| 252 | |
| 253 | if ((baseclass_mask != 0 && baseclass_mask != 0xFF) |
| 254 | || (subclass_mask != 0 && subclass_mask != 0xFF) |
| 255 | || (interface_mask != 0 && interface_mask != 0xFF)) { |
Sam Ravnborg | cb80514 | 2006-01-28 16:57:26 +0100 | [diff] [blame] | 256 | warn("Can't handle masks in %s:%04X\n", |
| 257 | filename, id->class_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 258 | return 0; |
| 259 | } |
| 260 | |
| 261 | ADD(alias, "bc", baseclass_mask == 0xFF, baseclass); |
| 262 | ADD(alias, "sc", subclass_mask == 0xFF, subclass); |
| 263 | ADD(alias, "i", interface_mask == 0xFF, interface); |
| 264 | return 1; |
| 265 | } |
| 266 | |
Sam Ravnborg | 62070fa | 2006-03-03 16:46:04 +0100 | [diff] [blame] | 267 | /* looks like: "ccw:tNmNdtNdmN" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | static int do_ccw_entry(const char *filename, |
| 269 | struct ccw_device_id *id, char *alias) |
| 270 | { |
| 271 | id->match_flags = TO_NATIVE(id->match_flags); |
| 272 | id->cu_type = TO_NATIVE(id->cu_type); |
| 273 | id->cu_model = TO_NATIVE(id->cu_model); |
| 274 | id->dev_type = TO_NATIVE(id->dev_type); |
| 275 | id->dev_model = TO_NATIVE(id->dev_model); |
| 276 | |
| 277 | strcpy(alias, "ccw:"); |
| 278 | ADD(alias, "t", id->match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE, |
| 279 | id->cu_type); |
| 280 | ADD(alias, "m", id->match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL, |
| 281 | id->cu_model); |
| 282 | ADD(alias, "dt", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE, |
| 283 | id->dev_type); |
Bastian Blank | de1d9c0 | 2006-03-06 15:43:00 -0800 | [diff] [blame] | 284 | ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 285 | id->dev_model); |
| 286 | return 1; |
| 287 | } |
| 288 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 289 | /* looks like: "ap:tN" */ |
| 290 | static int do_ap_entry(const char *filename, |
| 291 | struct ap_device_id *id, char *alias) |
| 292 | { |
| 293 | sprintf(alias, "ap:t%02X", id->dev_type); |
| 294 | return 1; |
| 295 | } |
| 296 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | /* Looks like: "serio:tyNprNidNexN" */ |
| 298 | static int do_serio_entry(const char *filename, |
| 299 | struct serio_device_id *id, char *alias) |
| 300 | { |
| 301 | id->type = TO_NATIVE(id->type); |
| 302 | id->proto = TO_NATIVE(id->proto); |
| 303 | id->id = TO_NATIVE(id->id); |
| 304 | id->extra = TO_NATIVE(id->extra); |
| 305 | |
| 306 | strcpy(alias, "serio:"); |
| 307 | ADD(alias, "ty", id->type != SERIO_ANY, id->type); |
| 308 | ADD(alias, "pr", id->proto != SERIO_ANY, id->proto); |
| 309 | ADD(alias, "id", id->id != SERIO_ANY, id->id); |
| 310 | ADD(alias, "ex", id->extra != SERIO_ANY, id->extra); |
| 311 | |
| 312 | return 1; |
| 313 | } |
| 314 | |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 315 | /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */ |
| 316 | static int do_acpi_entry(const char *filename, |
| 317 | struct acpi_device_id *id, char *alias) |
| 318 | { |
| 319 | sprintf(alias, "acpi*:%s:", id->id); |
| 320 | return 1; |
| 321 | } |
| 322 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | /* looks like: "pnp:dD" */ |
| 324 | static int do_pnp_entry(const char *filename, |
| 325 | struct pnp_device_id *id, char *alias) |
| 326 | { |
| 327 | sprintf(alias, "pnp:d%s", id->id); |
| 328 | return 1; |
| 329 | } |
| 330 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame^] | 331 | /* looks like: "pnp:dD" for every device of the card */ |
| 332 | static void do_pnp_card_entries(void *symval, unsigned long size, |
| 333 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame^] | 335 | const unsigned long id_size = sizeof(struct pnp_card_device_id); |
| 336 | const unsigned int count = (size / id_size)-1; |
| 337 | const struct pnp_card_device_id *cards = symval; |
| 338 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame^] | 340 | device_id_check(mod->name, "pnp", size, id_size, symval); |
| 341 | |
| 342 | for (i = 0; i < count; i++) { |
| 343 | unsigned int j; |
| 344 | const struct pnp_card_device_id *card = &cards[i]; |
| 345 | |
| 346 | for (j = 0; j < PNP_MAX_DEVICES; j++) { |
| 347 | const char *id = (char *)card->devs[j].id; |
| 348 | int i2, j2; |
| 349 | int dup = 0; |
| 350 | |
| 351 | if (!id[0]) |
| 352 | break; |
| 353 | |
| 354 | /* find duplicate, already added value */ |
| 355 | for (i2 = 0; i2 < i && !dup; i2++) { |
| 356 | const struct pnp_card_device_id *card2 = &cards[i2]; |
| 357 | |
| 358 | for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { |
| 359 | const char *id2 = (char *)card2->devs[j2].id; |
| 360 | |
| 361 | if (!id2[0]) |
| 362 | break; |
| 363 | |
| 364 | if (!strcmp(id, id2)) { |
| 365 | dup = 1; |
| 366 | break; |
| 367 | } |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | /* add an individual alias for every device entry */ |
| 372 | if (!dup) |
| 373 | buf_printf(&mod->dev_table_buf, |
| 374 | "MODULE_ALIAS(\"pnp:d%s*\");\n", id); |
| 375 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 376 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 379 | /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */ |
| 380 | static int do_pcmcia_entry(const char *filename, |
| 381 | struct pcmcia_device_id *id, char *alias) |
| 382 | { |
| 383 | unsigned int i; |
| 384 | |
Kars de Jong | 4fb7edc | 2005-09-25 14:39:46 +0200 | [diff] [blame] | 385 | id->match_flags = TO_NATIVE(id->match_flags); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 386 | id->manf_id = TO_NATIVE(id->manf_id); |
| 387 | id->card_id = TO_NATIVE(id->card_id); |
| 388 | id->func_id = TO_NATIVE(id->func_id); |
| 389 | id->function = TO_NATIVE(id->function); |
| 390 | id->device_no = TO_NATIVE(id->device_no); |
Kars de Jong | 4fb7edc | 2005-09-25 14:39:46 +0200 | [diff] [blame] | 391 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 392 | for (i=0; i<4; i++) { |
| 393 | id->prod_id_hash[i] = TO_NATIVE(id->prod_id_hash[i]); |
| 394 | } |
| 395 | |
| 396 | strcpy(alias, "pcmcia:"); |
| 397 | ADD(alias, "m", id->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID, |
| 398 | id->manf_id); |
| 399 | ADD(alias, "c", id->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID, |
| 400 | id->card_id); |
| 401 | ADD(alias, "f", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID, |
| 402 | id->func_id); |
| 403 | ADD(alias, "fn", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION, |
| 404 | id->function); |
| 405 | ADD(alias, "pfn", id->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO, |
| 406 | id->device_no); |
| 407 | ADD(alias, "pa", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, id->prod_id_hash[0]); |
| 408 | ADD(alias, "pb", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, id->prod_id_hash[1]); |
| 409 | ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]); |
| 410 | ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]); |
| 411 | |
| 412 | return 1; |
| 413 | } |
| 414 | |
| 415 | |
| 416 | |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 417 | static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) |
| 418 | { |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 419 | int len; |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 420 | char *tmp; |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 421 | len = sprintf (alias, "of:N%sT%s", |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 422 | of->name[0] ? of->name : "*", |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 423 | of->type[0] ? of->type : "*"); |
| 424 | |
| 425 | if (of->compatible[0]) |
| 426 | sprintf (&alias[len], "%sC%s", |
| 427 | of->type[0] ? "*" : "", |
| 428 | of->compatible); |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 429 | |
| 430 | /* Replace all whitespace with underscores */ |
| 431 | for (tmp = alias; tmp && *tmp; tmp++) |
| 432 | if (isspace (*tmp)) |
| 433 | *tmp = '_'; |
| 434 | |
| 435 | return 1; |
| 436 | } |
| 437 | |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 438 | static int do_vio_entry(const char *filename, struct vio_device_id *vio, |
| 439 | char *alias) |
| 440 | { |
| 441 | char *tmp; |
| 442 | |
| 443 | sprintf(alias, "vio:T%sS%s", vio->type[0] ? vio->type : "*", |
| 444 | vio->compat[0] ? vio->compat : "*"); |
| 445 | |
| 446 | /* Replace all whitespace with underscores */ |
| 447 | for (tmp = alias; tmp && *tmp; tmp++) |
| 448 | if (isspace (*tmp)) |
| 449 | *tmp = '_'; |
| 450 | |
| 451 | return 1; |
| 452 | } |
| 453 | |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 454 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 455 | |
| 456 | static void do_input(char *alias, |
| 457 | kernel_ulong_t *arr, unsigned int min, unsigned int max) |
| 458 | { |
| 459 | unsigned int i; |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 460 | |
| 461 | for (i = min; i < max; i++) |
Hans de Goede | e0e9263 | 2006-08-15 12:09:27 +0200 | [diff] [blame] | 462 | if (arr[i / BITS_PER_LONG] & (1L << (i%BITS_PER_LONG))) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 463 | sprintf(alias + strlen(alias), "%X,*", i); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 464 | } |
| 465 | |
| 466 | /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */ |
| 467 | static int do_input_entry(const char *filename, struct input_device_id *id, |
| 468 | char *alias) |
| 469 | { |
| 470 | sprintf(alias, "input:"); |
| 471 | |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 472 | ADD(alias, "b", id->flags & INPUT_DEVICE_ID_MATCH_BUS, id->bustype); |
| 473 | ADD(alias, "v", id->flags & INPUT_DEVICE_ID_MATCH_VENDOR, id->vendor); |
| 474 | ADD(alias, "p", id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT, id->product); |
| 475 | ADD(alias, "e", id->flags & INPUT_DEVICE_ID_MATCH_VERSION, id->version); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 476 | |
| 477 | sprintf(alias + strlen(alias), "-e*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 478 | if (id->flags & INPUT_DEVICE_ID_MATCH_EVBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 479 | do_input(alias, id->evbit, 0, INPUT_DEVICE_ID_EV_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 480 | sprintf(alias + strlen(alias), "k*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 481 | if (id->flags & INPUT_DEVICE_ID_MATCH_KEYBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 482 | do_input(alias, id->keybit, |
| 483 | INPUT_DEVICE_ID_KEY_MIN_INTERESTING, |
| 484 | INPUT_DEVICE_ID_KEY_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 485 | sprintf(alias + strlen(alias), "r*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 486 | if (id->flags & INPUT_DEVICE_ID_MATCH_RELBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 487 | do_input(alias, id->relbit, 0, INPUT_DEVICE_ID_REL_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 488 | sprintf(alias + strlen(alias), "a*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 489 | if (id->flags & INPUT_DEVICE_ID_MATCH_ABSBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 490 | do_input(alias, id->absbit, 0, INPUT_DEVICE_ID_ABS_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 491 | sprintf(alias + strlen(alias), "m*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 492 | if (id->flags & INPUT_DEVICE_ID_MATCH_MSCIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 493 | do_input(alias, id->mscbit, 0, INPUT_DEVICE_ID_MSC_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 494 | sprintf(alias + strlen(alias), "l*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 495 | if (id->flags & INPUT_DEVICE_ID_MATCH_LEDBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 496 | do_input(alias, id->ledbit, 0, INPUT_DEVICE_ID_LED_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 497 | sprintf(alias + strlen(alias), "s*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 498 | if (id->flags & INPUT_DEVICE_ID_MATCH_SNDBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 499 | do_input(alias, id->sndbit, 0, INPUT_DEVICE_ID_SND_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 500 | sprintf(alias + strlen(alias), "f*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 501 | if (id->flags & INPUT_DEVICE_ID_MATCH_FFBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 502 | do_input(alias, id->ffbit, 0, INPUT_DEVICE_ID_FF_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 503 | sprintf(alias + strlen(alias), "w*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 504 | if (id->flags & INPUT_DEVICE_ID_MATCH_SWBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 505 | do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 506 | return 1; |
| 507 | } |
| 508 | |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 509 | static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, |
| 510 | char *alias) |
| 511 | { |
| 512 | if (eisa->sig[0]) |
| 513 | sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig); |
| 514 | return 1; |
| 515 | } |
| 516 | |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 517 | /* Looks like: parisc:tNhvNrevNsvN */ |
| 518 | static int do_parisc_entry(const char *filename, struct parisc_device_id *id, |
| 519 | char *alias) |
| 520 | { |
| 521 | id->hw_type = TO_NATIVE(id->hw_type); |
| 522 | id->hversion = TO_NATIVE(id->hversion); |
| 523 | id->hversion_rev = TO_NATIVE(id->hversion_rev); |
| 524 | id->sversion = TO_NATIVE(id->sversion); |
| 525 | |
| 526 | strcpy(alias, "parisc:"); |
Kyle McMartin | f354ef8 | 2007-01-13 15:02:09 -0500 | [diff] [blame] | 527 | ADD(alias, "t", id->hw_type != PA_HWTYPE_ANY_ID, id->hw_type); |
| 528 | ADD(alias, "hv", id->hversion != PA_HVERSION_ANY_ID, id->hversion); |
| 529 | ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev); |
| 530 | ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 531 | |
| 532 | return 1; |
| 533 | } |
| 534 | |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 535 | /* Looks like: sdio:cNvNdN. */ |
| 536 | static int do_sdio_entry(const char *filename, |
| 537 | struct sdio_device_id *id, char *alias) |
| 538 | { |
| 539 | id->class = TO_NATIVE(id->class); |
| 540 | id->vendor = TO_NATIVE(id->vendor); |
| 541 | id->device = TO_NATIVE(id->device); |
| 542 | |
| 543 | strcpy(alias, "sdio:"); |
| 544 | ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class); |
| 545 | ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor); |
| 546 | ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device); |
Linus Torvalds | 038a500 | 2007-10-11 19:40:14 -0700 | [diff] [blame] | 547 | return 1; |
| 548 | } |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 549 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 550 | /* Looks like: ssb:vNidNrevN. */ |
| 551 | static int do_ssb_entry(const char *filename, |
| 552 | struct ssb_device_id *id, char *alias) |
| 553 | { |
| 554 | id->vendor = TO_NATIVE(id->vendor); |
| 555 | id->coreid = TO_NATIVE(id->coreid); |
| 556 | id->revision = TO_NATIVE(id->revision); |
| 557 | |
| 558 | strcpy(alias, "ssb:"); |
| 559 | ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor); |
| 560 | ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid); |
| 561 | ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 562 | return 1; |
| 563 | } |
| 564 | |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 565 | /* Looks like: virtio:dNvN */ |
| 566 | static int do_virtio_entry(const char *filename, struct virtio_device_id *id, |
| 567 | char *alias) |
| 568 | { |
| 569 | id->device = TO_NATIVE(id->device); |
| 570 | id->vendor = TO_NATIVE(id->vendor); |
| 571 | |
| 572 | strcpy(alias, "virtio:"); |
| 573 | ADD(alias, "d", 1, id->device); |
| 574 | ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); |
| 575 | |
| 576 | return 1; |
| 577 | } |
| 578 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 579 | /* Ignore any prefix, eg. v850 prepends _ */ |
| 580 | static inline int sym_is(const char *symbol, const char *name) |
| 581 | { |
| 582 | const char *match; |
| 583 | |
| 584 | match = strstr(symbol, name); |
| 585 | if (!match) |
| 586 | return 0; |
| 587 | return match[strlen(symbol)] == '\0'; |
| 588 | } |
| 589 | |
| 590 | static void do_table(void *symval, unsigned long size, |
| 591 | unsigned long id_size, |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 592 | const char *device_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 593 | void *function, |
| 594 | struct module *mod) |
| 595 | { |
| 596 | unsigned int i; |
| 597 | char alias[500]; |
| 598 | int (*do_entry)(const char *, void *entry, char *alias) = function; |
| 599 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 600 | device_id_check(mod->name, device_id, size, id_size, symval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 601 | /* Leave last one: it's the terminator. */ |
| 602 | size -= id_size; |
| 603 | |
| 604 | for (i = 0; i < size; i += id_size) { |
| 605 | if (do_entry(mod->name, symval+i, alias)) { |
| 606 | /* Always end in a wildcard, for future extension */ |
| 607 | if (alias[strlen(alias)-1] != '*') |
| 608 | strcat(alias, "*"); |
| 609 | buf_printf(&mod->dev_table_buf, |
| 610 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 611 | } |
| 612 | } |
| 613 | } |
| 614 | |
| 615 | /* Create MODULE_ALIAS() statements. |
| 616 | * At this time, we cannot write the actual output C source yet, |
| 617 | * so we write into the mod->dev_table_buf buffer. */ |
| 618 | void handle_moddevtable(struct module *mod, struct elf_info *info, |
| 619 | Elf_Sym *sym, const char *symname) |
| 620 | { |
| 621 | void *symval; |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 622 | char *zeros = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | |
| 624 | /* We're looking for a section relative symbol */ |
| 625 | if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum) |
| 626 | return; |
| 627 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 628 | /* Handle all-NULL symbols allocated into .bss */ |
| 629 | if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) { |
| 630 | zeros = calloc(1, sym->st_size); |
| 631 | symval = zeros; |
| 632 | } else { |
| 633 | symval = (void *)info->hdr |
| 634 | + info->sechdrs[sym->st_shndx].sh_offset |
| 635 | + sym->st_value; |
| 636 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 637 | |
| 638 | if (sym_is(symname, "__mod_pci_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 639 | do_table(symval, sym->st_size, |
| 640 | sizeof(struct pci_device_id), "pci", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | do_pci_entry, mod); |
| 642 | else if (sym_is(symname, "__mod_usb_device_table")) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 643 | /* special case to handle bcdDevice ranges */ |
| 644 | do_usb_table(symval, sym->st_size, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 645 | else if (sym_is(symname, "__mod_ieee1394_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 646 | do_table(symval, sym->st_size, |
| 647 | sizeof(struct ieee1394_device_id), "ieee1394", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | do_ieee1394_entry, mod); |
| 649 | else if (sym_is(symname, "__mod_ccw_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 650 | do_table(symval, sym->st_size, |
| 651 | sizeof(struct ccw_device_id), "ccw", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | do_ccw_entry, mod); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 653 | else if (sym_is(symname, "__mod_ap_device_table")) |
| 654 | do_table(symval, sym->st_size, |
| 655 | sizeof(struct ap_device_id), "ap", |
| 656 | do_ap_entry, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 657 | else if (sym_is(symname, "__mod_serio_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 658 | do_table(symval, sym->st_size, |
| 659 | sizeof(struct serio_device_id), "serio", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | do_serio_entry, mod); |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 661 | else if (sym_is(symname, "__mod_acpi_device_table")) |
| 662 | do_table(symval, sym->st_size, |
| 663 | sizeof(struct acpi_device_id), "acpi", |
| 664 | do_acpi_entry, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 665 | else if (sym_is(symname, "__mod_pnp_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 666 | do_table(symval, sym->st_size, |
| 667 | sizeof(struct pnp_device_id), "pnp", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 668 | do_pnp_entry, mod); |
| 669 | else if (sym_is(symname, "__mod_pnp_card_device_table")) |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame^] | 670 | do_pnp_card_entries(symval, sym->st_size, mod); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 671 | else if (sym_is(symname, "__mod_pcmcia_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 672 | do_table(symval, sym->st_size, |
| 673 | sizeof(struct pcmcia_device_id), "pcmcia", |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 674 | do_pcmcia_entry, mod); |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 675 | else if (sym_is(symname, "__mod_of_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 676 | do_table(symval, sym->st_size, |
| 677 | sizeof(struct of_device_id), "of", |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 678 | do_of_entry, mod); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 679 | else if (sym_is(symname, "__mod_vio_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 680 | do_table(symval, sym->st_size, |
| 681 | sizeof(struct vio_device_id), "vio", |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 682 | do_vio_entry, mod); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 683 | else if (sym_is(symname, "__mod_input_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 684 | do_table(symval, sym->st_size, |
| 685 | sizeof(struct input_device_id), "input", |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 686 | do_input_entry, mod); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 687 | else if (sym_is(symname, "__mod_eisa_device_table")) |
| 688 | do_table(symval, sym->st_size, |
| 689 | sizeof(struct eisa_device_id), "eisa", |
| 690 | do_eisa_entry, mod); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 691 | else if (sym_is(symname, "__mod_parisc_device_table")) |
| 692 | do_table(symval, sym->st_size, |
| 693 | sizeof(struct parisc_device_id), "parisc", |
| 694 | do_parisc_entry, mod); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 695 | else if (sym_is(symname, "__mod_sdio_device_table")) |
| 696 | do_table(symval, sym->st_size, |
| 697 | sizeof(struct sdio_device_id), "sdio", |
| 698 | do_sdio_entry, mod); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 699 | else if (sym_is(symname, "__mod_ssb_device_table")) |
| 700 | do_table(symval, sym->st_size, |
| 701 | sizeof(struct ssb_device_id), "ssb", |
| 702 | do_ssb_entry, mod); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 703 | else if (sym_is(symname, "__mod_virtio_device_table")) |
| 704 | do_table(symval, sym->st_size, |
| 705 | sizeof(struct virtio_device_id), "virtio", |
| 706 | do_virtio_entry, mod); |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 707 | free(zeros); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 708 | } |
| 709 | |
| 710 | /* Now add out buffered information to the generated C source */ |
| 711 | void add_moddevtable(struct buffer *buf, struct module *mod) |
| 712 | { |
| 713 | buf_printf(buf, "\n"); |
| 714 | buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos); |
| 715 | free(mod->dev_table_buf.p); |
| 716 | } |