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, |
| 107 | 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) |
| 121 | sprintf(alias + strlen(alias), "%u", range_lo); |
| 122 | else if (range_lo > 0 || range_hi < 9) |
| 123 | sprintf(alias + strlen(alias), "[%u-%u]", range_lo, range_hi); |
| 124 | if (bcdDevice_initial_digits < (sizeof(id->bcdDevice_lo) * 2 - 1)) |
| 125 | strcat(alias, "*"); |
| 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | ADD(alias, "dc", id->match_flags&USB_DEVICE_ID_MATCH_DEV_CLASS, |
| 128 | id->bDeviceClass); |
| 129 | ADD(alias, "dsc", |
| 130 | id->match_flags&USB_DEVICE_ID_MATCH_DEV_SUBCLASS, |
| 131 | id->bDeviceSubClass); |
| 132 | ADD(alias, "dp", |
| 133 | id->match_flags&USB_DEVICE_ID_MATCH_DEV_PROTOCOL, |
| 134 | id->bDeviceProtocol); |
| 135 | ADD(alias, "ic", |
| 136 | id->match_flags&USB_DEVICE_ID_MATCH_INT_CLASS, |
| 137 | id->bInterfaceClass); |
| 138 | ADD(alias, "isc", |
| 139 | id->match_flags&USB_DEVICE_ID_MATCH_INT_SUBCLASS, |
| 140 | id->bInterfaceSubClass); |
| 141 | ADD(alias, "ip", |
| 142 | id->match_flags&USB_DEVICE_ID_MATCH_INT_PROTOCOL, |
| 143 | id->bInterfaceProtocol); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 144 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 145 | add_wildcard(alias); |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 146 | buf_printf(&mod->dev_table_buf, |
| 147 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 148 | } |
| 149 | |
| 150 | static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod) |
| 151 | { |
| 152 | unsigned int devlo, devhi; |
| 153 | unsigned char chi, clo; |
| 154 | int ndigits; |
| 155 | |
| 156 | id->match_flags = TO_NATIVE(id->match_flags); |
| 157 | id->idVendor = TO_NATIVE(id->idVendor); |
| 158 | id->idProduct = TO_NATIVE(id->idProduct); |
| 159 | |
| 160 | devlo = id->match_flags & USB_DEVICE_ID_MATCH_DEV_LO ? |
| 161 | TO_NATIVE(id->bcdDevice_lo) : 0x0U; |
| 162 | devhi = id->match_flags & USB_DEVICE_ID_MATCH_DEV_HI ? |
| 163 | TO_NATIVE(id->bcdDevice_hi) : ~0x0U; |
| 164 | |
| 165 | /* |
| 166 | * Some modules (visor) have empty slots as placeholder for |
| 167 | * run-time specification that results in catch-all alias |
| 168 | */ |
Greg Kroah-Hartman | de6f92b | 2008-01-28 09:50:12 -0800 | [diff] [blame] | 169 | if (!(id->idVendor | id->idProduct | id->bDeviceClass | id->bInterfaceClass)) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 170 | return; |
| 171 | |
| 172 | /* Convert numeric bcdDevice range into fnmatch-able pattern(s) */ |
| 173 | for (ndigits = sizeof(id->bcdDevice_lo) * 2 - 1; devlo <= devhi; ndigits--) { |
| 174 | clo = devlo & 0xf; |
| 175 | chi = devhi & 0xf; |
| 176 | if (chi > 9) /* it's bcd not hex */ |
| 177 | chi = 9; |
| 178 | devlo >>= 4; |
| 179 | devhi >>= 4; |
| 180 | |
| 181 | if (devlo == devhi || !ndigits) { |
| 182 | do_usb_entry(id, devlo, ndigits, clo, chi, mod); |
| 183 | break; |
| 184 | } |
| 185 | |
| 186 | if (clo > 0) |
| 187 | do_usb_entry(id, devlo++, ndigits, clo, 9, mod); |
| 188 | |
| 189 | if (chi < 9) |
| 190 | do_usb_entry(id, devhi--, ndigits, 0, chi, mod); |
| 191 | } |
| 192 | } |
| 193 | |
| 194 | static void do_usb_table(void *symval, unsigned long size, |
| 195 | struct module *mod) |
| 196 | { |
| 197 | unsigned int i; |
| 198 | const unsigned long id_size = sizeof(struct usb_device_id); |
| 199 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 200 | device_id_check(mod->name, "usb", size, id_size, symval); |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 201 | |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 202 | /* Leave last one: it's the terminator. */ |
| 203 | size -= id_size; |
| 204 | |
| 205 | for (i = 0; i < size; i += id_size) |
| 206 | do_usb_entry_multi(symval + i, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 209 | /* Looks like: hid:bNvNpN */ |
| 210 | static int do_hid_entry(const char *filename, |
| 211 | struct hid_device_id *id, char *alias) |
| 212 | { |
| 213 | id->vendor = TO_NATIVE(id->vendor); |
| 214 | id->product = TO_NATIVE(id->product); |
| 215 | |
| 216 | sprintf(alias, "hid:b%04X", id->bus); |
| 217 | ADD(alias, "v", id->vendor != HID_ANY_ID, id->vendor); |
| 218 | ADD(alias, "p", id->product != HID_ANY_ID, id->product); |
| 219 | |
| 220 | return 1; |
| 221 | } |
| 222 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | /* Looks like: ieee1394:venNmoNspNverN */ |
| 224 | static int do_ieee1394_entry(const char *filename, |
| 225 | struct ieee1394_device_id *id, char *alias) |
| 226 | { |
| 227 | id->match_flags = TO_NATIVE(id->match_flags); |
| 228 | id->vendor_id = TO_NATIVE(id->vendor_id); |
| 229 | id->model_id = TO_NATIVE(id->model_id); |
| 230 | id->specifier_id = TO_NATIVE(id->specifier_id); |
| 231 | id->version = TO_NATIVE(id->version); |
| 232 | |
| 233 | strcpy(alias, "ieee1394:"); |
| 234 | ADD(alias, "ven", id->match_flags & IEEE1394_MATCH_VENDOR_ID, |
| 235 | id->vendor_id); |
| 236 | ADD(alias, "mo", id->match_flags & IEEE1394_MATCH_MODEL_ID, |
| 237 | id->model_id); |
| 238 | ADD(alias, "sp", id->match_flags & IEEE1394_MATCH_SPECIFIER_ID, |
| 239 | id->specifier_id); |
| 240 | ADD(alias, "ver", id->match_flags & IEEE1394_MATCH_VERSION, |
| 241 | id->version); |
| 242 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 243 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | return 1; |
| 245 | } |
| 246 | |
| 247 | /* Looks like: pci:vNdNsvNsdNbcNscNiN. */ |
| 248 | static int do_pci_entry(const char *filename, |
| 249 | struct pci_device_id *id, char *alias) |
| 250 | { |
| 251 | /* Class field can be divided into these three. */ |
| 252 | unsigned char baseclass, subclass, interface, |
| 253 | baseclass_mask, subclass_mask, interface_mask; |
| 254 | |
| 255 | id->vendor = TO_NATIVE(id->vendor); |
| 256 | id->device = TO_NATIVE(id->device); |
| 257 | id->subvendor = TO_NATIVE(id->subvendor); |
| 258 | id->subdevice = TO_NATIVE(id->subdevice); |
| 259 | id->class = TO_NATIVE(id->class); |
| 260 | id->class_mask = TO_NATIVE(id->class_mask); |
| 261 | |
| 262 | strcpy(alias, "pci:"); |
| 263 | ADD(alias, "v", id->vendor != PCI_ANY_ID, id->vendor); |
| 264 | ADD(alias, "d", id->device != PCI_ANY_ID, id->device); |
| 265 | ADD(alias, "sv", id->subvendor != PCI_ANY_ID, id->subvendor); |
| 266 | ADD(alias, "sd", id->subdevice != PCI_ANY_ID, id->subdevice); |
| 267 | |
| 268 | baseclass = (id->class) >> 16; |
| 269 | baseclass_mask = (id->class_mask) >> 16; |
| 270 | subclass = (id->class) >> 8; |
| 271 | subclass_mask = (id->class_mask) >> 8; |
| 272 | interface = id->class; |
| 273 | interface_mask = id->class_mask; |
| 274 | |
| 275 | if ((baseclass_mask != 0 && baseclass_mask != 0xFF) |
| 276 | || (subclass_mask != 0 && subclass_mask != 0xFF) |
| 277 | || (interface_mask != 0 && interface_mask != 0xFF)) { |
Sam Ravnborg | cb80514 | 2006-01-28 16:57:26 +0100 | [diff] [blame] | 278 | warn("Can't handle masks in %s:%04X\n", |
| 279 | filename, id->class_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | ADD(alias, "bc", baseclass_mask == 0xFF, baseclass); |
| 284 | ADD(alias, "sc", subclass_mask == 0xFF, subclass); |
| 285 | ADD(alias, "i", interface_mask == 0xFF, interface); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 286 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 287 | return 1; |
| 288 | } |
| 289 | |
Sam Ravnborg | 62070fa | 2006-03-03 16:46:04 +0100 | [diff] [blame] | 290 | /* looks like: "ccw:tNmNdtNdmN" */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | static int do_ccw_entry(const char *filename, |
| 292 | struct ccw_device_id *id, char *alias) |
| 293 | { |
| 294 | id->match_flags = TO_NATIVE(id->match_flags); |
| 295 | id->cu_type = TO_NATIVE(id->cu_type); |
| 296 | id->cu_model = TO_NATIVE(id->cu_model); |
| 297 | id->dev_type = TO_NATIVE(id->dev_type); |
| 298 | id->dev_model = TO_NATIVE(id->dev_model); |
| 299 | |
| 300 | strcpy(alias, "ccw:"); |
| 301 | ADD(alias, "t", id->match_flags&CCW_DEVICE_ID_MATCH_CU_TYPE, |
| 302 | id->cu_type); |
| 303 | ADD(alias, "m", id->match_flags&CCW_DEVICE_ID_MATCH_CU_MODEL, |
| 304 | id->cu_model); |
| 305 | ADD(alias, "dt", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_TYPE, |
| 306 | id->dev_type); |
Bastian Blank | de1d9c0 | 2006-03-06 15:43:00 -0800 | [diff] [blame] | 307 | ADD(alias, "dm", id->match_flags&CCW_DEVICE_ID_MATCH_DEVICE_MODEL, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 308 | id->dev_model); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 309 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | return 1; |
| 311 | } |
| 312 | |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 313 | /* looks like: "ap:tN" */ |
| 314 | static int do_ap_entry(const char *filename, |
| 315 | struct ap_device_id *id, char *alias) |
| 316 | { |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 317 | sprintf(alias, "ap:t%02X*", id->dev_type); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 318 | return 1; |
| 319 | } |
| 320 | |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 321 | /* looks like: "css:tN" */ |
| 322 | static int do_css_entry(const char *filename, |
| 323 | struct css_device_id *id, char *alias) |
| 324 | { |
| 325 | sprintf(alias, "css:t%01X", id->type); |
| 326 | return 1; |
| 327 | } |
| 328 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | /* Looks like: "serio:tyNprNidNexN" */ |
| 330 | static int do_serio_entry(const char *filename, |
| 331 | struct serio_device_id *id, char *alias) |
| 332 | { |
| 333 | id->type = TO_NATIVE(id->type); |
| 334 | id->proto = TO_NATIVE(id->proto); |
| 335 | id->id = TO_NATIVE(id->id); |
| 336 | id->extra = TO_NATIVE(id->extra); |
| 337 | |
| 338 | strcpy(alias, "serio:"); |
| 339 | ADD(alias, "ty", id->type != SERIO_ANY, id->type); |
| 340 | ADD(alias, "pr", id->proto != SERIO_ANY, id->proto); |
| 341 | ADD(alias, "id", id->id != SERIO_ANY, id->id); |
| 342 | ADD(alias, "ex", id->extra != SERIO_ANY, id->extra); |
| 343 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 344 | add_wildcard(alias); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | return 1; |
| 346 | } |
| 347 | |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 348 | /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */ |
| 349 | static int do_acpi_entry(const char *filename, |
| 350 | struct acpi_device_id *id, char *alias) |
| 351 | { |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 352 | sprintf(alias, "acpi*:%s:*", id->id); |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 353 | return 1; |
| 354 | } |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | /* looks like: "pnp:dD" */ |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 357 | static void do_pnp_device_entry(void *symval, unsigned long size, |
| 358 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 359 | { |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 360 | const unsigned long id_size = sizeof(struct pnp_device_id); |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 361 | const unsigned int count = (size / id_size)-1; |
| 362 | const struct pnp_device_id *devs = symval; |
| 363 | unsigned int i; |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 364 | |
| 365 | device_id_check(mod->name, "pnp", size, id_size, symval); |
| 366 | |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 367 | for (i = 0; i < count; i++) { |
| 368 | const char *id = (char *)devs[i].id; |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 369 | char acpi_id[sizeof(devs[0].id)]; |
| 370 | int j; |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 371 | |
| 372 | buf_printf(&mod->dev_table_buf, |
| 373 | "MODULE_ALIAS(\"pnp:d%s*\");\n", id); |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 374 | |
| 375 | /* fix broken pnp bus lowercasing */ |
| 376 | for (j = 0; j < sizeof(acpi_id); j++) |
| 377 | acpi_id[j] = toupper(id[j]); |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 378 | buf_printf(&mod->dev_table_buf, |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 379 | "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); |
Kay Sievers | 5e4c656 | 2008-08-21 15:28:56 +0200 | [diff] [blame] | 380 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 381 | } |
| 382 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 383 | /* looks like: "pnp:dD" for every device of the card */ |
| 384 | static void do_pnp_card_entries(void *symval, unsigned long size, |
| 385 | struct module *mod) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | { |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 387 | const unsigned long id_size = sizeof(struct pnp_card_device_id); |
| 388 | const unsigned int count = (size / id_size)-1; |
| 389 | const struct pnp_card_device_id *cards = symval; |
| 390 | unsigned int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 392 | device_id_check(mod->name, "pnp", size, id_size, symval); |
| 393 | |
| 394 | for (i = 0; i < count; i++) { |
| 395 | unsigned int j; |
| 396 | const struct pnp_card_device_id *card = &cards[i]; |
| 397 | |
| 398 | for (j = 0; j < PNP_MAX_DEVICES; j++) { |
| 399 | const char *id = (char *)card->devs[j].id; |
| 400 | int i2, j2; |
| 401 | int dup = 0; |
| 402 | |
| 403 | if (!id[0]) |
| 404 | break; |
| 405 | |
| 406 | /* find duplicate, already added value */ |
| 407 | for (i2 = 0; i2 < i && !dup; i2++) { |
| 408 | const struct pnp_card_device_id *card2 = &cards[i2]; |
| 409 | |
| 410 | for (j2 = 0; j2 < PNP_MAX_DEVICES; j2++) { |
| 411 | const char *id2 = (char *)card2->devs[j2].id; |
| 412 | |
| 413 | if (!id2[0]) |
| 414 | break; |
| 415 | |
| 416 | if (!strcmp(id, id2)) { |
| 417 | dup = 1; |
| 418 | break; |
| 419 | } |
| 420 | } |
| 421 | } |
| 422 | |
| 423 | /* add an individual alias for every device entry */ |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 424 | if (!dup) { |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 425 | char acpi_id[sizeof(card->devs[0].id)]; |
| 426 | int k; |
| 427 | |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 428 | buf_printf(&mod->dev_table_buf, |
| 429 | "MODULE_ALIAS(\"pnp:d%s*\");\n", id); |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 430 | |
| 431 | /* fix broken pnp bus lowercasing */ |
| 432 | for (k = 0; k < sizeof(acpi_id); k++) |
| 433 | acpi_id[k] = toupper(id[k]); |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 434 | buf_printf(&mod->dev_table_buf, |
Kay Sievers | 72638f5 | 2009-01-08 03:06:42 +0100 | [diff] [blame] | 435 | "MODULE_ALIAS(\"acpi*:%s:*\");\n", acpi_id); |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 436 | } |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 437 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | } |
| 440 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 441 | /* Looks like: pcmcia:mNcNfNfnNpfnNvaNvbNvcNvdN. */ |
| 442 | static int do_pcmcia_entry(const char *filename, |
| 443 | struct pcmcia_device_id *id, char *alias) |
| 444 | { |
| 445 | unsigned int i; |
| 446 | |
Kars de Jong | 4fb7edc | 2005-09-25 14:39:46 +0200 | [diff] [blame] | 447 | id->match_flags = TO_NATIVE(id->match_flags); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 448 | id->manf_id = TO_NATIVE(id->manf_id); |
| 449 | id->card_id = TO_NATIVE(id->card_id); |
| 450 | id->func_id = TO_NATIVE(id->func_id); |
| 451 | id->function = TO_NATIVE(id->function); |
| 452 | id->device_no = TO_NATIVE(id->device_no); |
Kars de Jong | 4fb7edc | 2005-09-25 14:39:46 +0200 | [diff] [blame] | 453 | |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 454 | for (i=0; i<4; i++) { |
| 455 | id->prod_id_hash[i] = TO_NATIVE(id->prod_id_hash[i]); |
| 456 | } |
| 457 | |
| 458 | strcpy(alias, "pcmcia:"); |
| 459 | ADD(alias, "m", id->match_flags & PCMCIA_DEV_ID_MATCH_MANF_ID, |
| 460 | id->manf_id); |
| 461 | ADD(alias, "c", id->match_flags & PCMCIA_DEV_ID_MATCH_CARD_ID, |
| 462 | id->card_id); |
| 463 | ADD(alias, "f", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNC_ID, |
| 464 | id->func_id); |
| 465 | ADD(alias, "fn", id->match_flags & PCMCIA_DEV_ID_MATCH_FUNCTION, |
| 466 | id->function); |
| 467 | ADD(alias, "pfn", id->match_flags & PCMCIA_DEV_ID_MATCH_DEVICE_NO, |
| 468 | id->device_no); |
| 469 | ADD(alias, "pa", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID1, id->prod_id_hash[0]); |
| 470 | ADD(alias, "pb", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID2, id->prod_id_hash[1]); |
| 471 | ADD(alias, "pc", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID3, id->prod_id_hash[2]); |
| 472 | ADD(alias, "pd", id->match_flags & PCMCIA_DEV_ID_MATCH_PROD_ID4, id->prod_id_hash[3]); |
| 473 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 474 | add_wildcard(alias); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 475 | return 1; |
| 476 | } |
| 477 | |
| 478 | |
| 479 | |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 480 | static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) |
| 481 | { |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 482 | int len; |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 483 | char *tmp; |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 484 | len = sprintf (alias, "of:N%sT%s", |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 485 | of->name[0] ? of->name : "*", |
Sylvain Munaut | d1ab423 | 2007-05-08 19:59:29 +1000 | [diff] [blame] | 486 | of->type[0] ? of->type : "*"); |
| 487 | |
| 488 | if (of->compatible[0]) |
| 489 | sprintf (&alias[len], "%sC%s", |
| 490 | of->type[0] ? "*" : "", |
| 491 | of->compatible); |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 492 | |
| 493 | /* Replace all whitespace with underscores */ |
| 494 | for (tmp = alias; tmp && *tmp; tmp++) |
| 495 | if (isspace (*tmp)) |
| 496 | *tmp = '_'; |
| 497 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 498 | add_wildcard(alias); |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 499 | return 1; |
| 500 | } |
| 501 | |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 502 | static int do_vio_entry(const char *filename, struct vio_device_id *vio, |
| 503 | char *alias) |
| 504 | { |
| 505 | char *tmp; |
| 506 | |
| 507 | sprintf(alias, "vio:T%sS%s", vio->type[0] ? vio->type : "*", |
| 508 | vio->compat[0] ? vio->compat : "*"); |
| 509 | |
| 510 | /* Replace all whitespace with underscores */ |
| 511 | for (tmp = alias; tmp && *tmp; tmp++) |
| 512 | if (isspace (*tmp)) |
| 513 | *tmp = '_'; |
| 514 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 515 | add_wildcard(alias); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 516 | return 1; |
| 517 | } |
| 518 | |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 519 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 520 | |
| 521 | static void do_input(char *alias, |
| 522 | kernel_ulong_t *arr, unsigned int min, unsigned int max) |
| 523 | { |
| 524 | unsigned int i; |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 525 | |
| 526 | for (i = min; i < max; i++) |
Hans de Goede | e0e9263 | 2006-08-15 12:09:27 +0200 | [diff] [blame] | 527 | if (arr[i / BITS_PER_LONG] & (1L << (i%BITS_PER_LONG))) |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 528 | sprintf(alias + strlen(alias), "%X,*", i); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 529 | } |
| 530 | |
| 531 | /* input:b0v0p0e0-eXkXrXaXmXlXsXfXwX where X is comma-separated %02X. */ |
| 532 | static int do_input_entry(const char *filename, struct input_device_id *id, |
| 533 | char *alias) |
| 534 | { |
| 535 | sprintf(alias, "input:"); |
| 536 | |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 537 | ADD(alias, "b", id->flags & INPUT_DEVICE_ID_MATCH_BUS, id->bustype); |
| 538 | ADD(alias, "v", id->flags & INPUT_DEVICE_ID_MATCH_VENDOR, id->vendor); |
| 539 | ADD(alias, "p", id->flags & INPUT_DEVICE_ID_MATCH_PRODUCT, id->product); |
| 540 | ADD(alias, "e", id->flags & INPUT_DEVICE_ID_MATCH_VERSION, id->version); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 541 | |
| 542 | sprintf(alias + strlen(alias), "-e*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 543 | if (id->flags & INPUT_DEVICE_ID_MATCH_EVBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 544 | do_input(alias, id->evbit, 0, INPUT_DEVICE_ID_EV_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 545 | sprintf(alias + strlen(alias), "k*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 546 | if (id->flags & INPUT_DEVICE_ID_MATCH_KEYBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 547 | do_input(alias, id->keybit, |
| 548 | INPUT_DEVICE_ID_KEY_MIN_INTERESTING, |
| 549 | INPUT_DEVICE_ID_KEY_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 550 | sprintf(alias + strlen(alias), "r*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 551 | if (id->flags & INPUT_DEVICE_ID_MATCH_RELBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 552 | do_input(alias, id->relbit, 0, INPUT_DEVICE_ID_REL_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 553 | sprintf(alias + strlen(alias), "a*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 554 | if (id->flags & INPUT_DEVICE_ID_MATCH_ABSBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 555 | do_input(alias, id->absbit, 0, INPUT_DEVICE_ID_ABS_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 556 | sprintf(alias + strlen(alias), "m*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 557 | if (id->flags & INPUT_DEVICE_ID_MATCH_MSCIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 558 | do_input(alias, id->mscbit, 0, INPUT_DEVICE_ID_MSC_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 559 | sprintf(alias + strlen(alias), "l*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 560 | if (id->flags & INPUT_DEVICE_ID_MATCH_LEDBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 561 | do_input(alias, id->ledbit, 0, INPUT_DEVICE_ID_LED_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 562 | sprintf(alias + strlen(alias), "s*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 563 | if (id->flags & INPUT_DEVICE_ID_MATCH_SNDBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 564 | do_input(alias, id->sndbit, 0, INPUT_DEVICE_ID_SND_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 565 | sprintf(alias + strlen(alias), "f*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 566 | if (id->flags & INPUT_DEVICE_ID_MATCH_FFBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 567 | do_input(alias, id->ffbit, 0, INPUT_DEVICE_ID_FF_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 568 | sprintf(alias + strlen(alias), "w*"); |
Dmitry Torokhov | ddc5d34 | 2006-04-26 00:14:19 -0400 | [diff] [blame] | 569 | if (id->flags & INPUT_DEVICE_ID_MATCH_SWBIT) |
Sam Ravnborg | dc24f0e | 2007-03-09 19:59:06 +0100 | [diff] [blame] | 570 | do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 571 | return 1; |
| 572 | } |
| 573 | |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 574 | static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, |
| 575 | char *alias) |
| 576 | { |
| 577 | if (eisa->sig[0]) |
| 578 | sprintf(alias, EISA_DEVICE_MODALIAS_FMT "*", eisa->sig); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 579 | else |
| 580 | strcat(alias, "*"); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 581 | return 1; |
| 582 | } |
| 583 | |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 584 | /* Looks like: parisc:tNhvNrevNsvN */ |
| 585 | static int do_parisc_entry(const char *filename, struct parisc_device_id *id, |
| 586 | char *alias) |
| 587 | { |
| 588 | id->hw_type = TO_NATIVE(id->hw_type); |
| 589 | id->hversion = TO_NATIVE(id->hversion); |
| 590 | id->hversion_rev = TO_NATIVE(id->hversion_rev); |
| 591 | id->sversion = TO_NATIVE(id->sversion); |
| 592 | |
| 593 | strcpy(alias, "parisc:"); |
Kyle McMartin | f354ef8 | 2007-01-13 15:02:09 -0500 | [diff] [blame] | 594 | ADD(alias, "t", id->hw_type != PA_HWTYPE_ANY_ID, id->hw_type); |
| 595 | ADD(alias, "hv", id->hversion != PA_HVERSION_ANY_ID, id->hversion); |
| 596 | ADD(alias, "rev", id->hversion_rev != PA_HVERSION_REV_ANY_ID, id->hversion_rev); |
| 597 | ADD(alias, "sv", id->sversion != PA_SVERSION_ANY_ID, id->sversion); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 598 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 599 | add_wildcard(alias); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 600 | return 1; |
| 601 | } |
| 602 | |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 603 | /* Looks like: sdio:cNvNdN. */ |
| 604 | static int do_sdio_entry(const char *filename, |
| 605 | struct sdio_device_id *id, char *alias) |
| 606 | { |
| 607 | id->class = TO_NATIVE(id->class); |
| 608 | id->vendor = TO_NATIVE(id->vendor); |
| 609 | id->device = TO_NATIVE(id->device); |
| 610 | |
| 611 | strcpy(alias, "sdio:"); |
| 612 | ADD(alias, "c", id->class != (__u8)SDIO_ANY_ID, id->class); |
| 613 | ADD(alias, "v", id->vendor != (__u16)SDIO_ANY_ID, id->vendor); |
| 614 | ADD(alias, "d", id->device != (__u16)SDIO_ANY_ID, id->device); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 615 | add_wildcard(alias); |
Linus Torvalds | 038a500 | 2007-10-11 19:40:14 -0700 | [diff] [blame] | 616 | return 1; |
| 617 | } |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 618 | |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 619 | /* Looks like: ssb:vNidNrevN. */ |
| 620 | static int do_ssb_entry(const char *filename, |
| 621 | struct ssb_device_id *id, char *alias) |
| 622 | { |
| 623 | id->vendor = TO_NATIVE(id->vendor); |
| 624 | id->coreid = TO_NATIVE(id->coreid); |
| 625 | id->revision = TO_NATIVE(id->revision); |
| 626 | |
| 627 | strcpy(alias, "ssb:"); |
| 628 | ADD(alias, "v", id->vendor != SSB_ANY_VENDOR, id->vendor); |
| 629 | ADD(alias, "id", id->coreid != SSB_ANY_ID, id->coreid); |
| 630 | ADD(alias, "rev", id->revision != SSB_ANY_REV, id->revision); |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 631 | add_wildcard(alias); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 632 | return 1; |
| 633 | } |
| 634 | |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 635 | /* Looks like: virtio:dNvN */ |
| 636 | static int do_virtio_entry(const char *filename, struct virtio_device_id *id, |
| 637 | char *alias) |
| 638 | { |
| 639 | id->device = TO_NATIVE(id->device); |
| 640 | id->vendor = TO_NATIVE(id->vendor); |
| 641 | |
| 642 | strcpy(alias, "virtio:"); |
| 643 | ADD(alias, "d", 1, id->device); |
| 644 | ADD(alias, "v", id->vendor != VIRTIO_DEV_ANY_ID, id->vendor); |
| 645 | |
Jean Delvare | ac55182 | 2008-05-02 20:37:21 +0200 | [diff] [blame] | 646 | add_wildcard(alias); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 647 | return 1; |
| 648 | } |
| 649 | |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 650 | /* Looks like: i2c:S */ |
| 651 | static int do_i2c_entry(const char *filename, struct i2c_device_id *id, |
| 652 | char *alias) |
| 653 | { |
| 654 | sprintf(alias, I2C_MODULE_PREFIX "%s", id->name); |
| 655 | |
| 656 | return 1; |
| 657 | } |
| 658 | |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 659 | static const struct dmifield { |
| 660 | const char *prefix; |
| 661 | int field; |
| 662 | } dmi_fields[] = { |
| 663 | { "bvn", DMI_BIOS_VENDOR }, |
| 664 | { "bvr", DMI_BIOS_VERSION }, |
| 665 | { "bd", DMI_BIOS_DATE }, |
| 666 | { "svn", DMI_SYS_VENDOR }, |
| 667 | { "pn", DMI_PRODUCT_NAME }, |
| 668 | { "pvr", DMI_PRODUCT_VERSION }, |
| 669 | { "rvn", DMI_BOARD_VENDOR }, |
| 670 | { "rn", DMI_BOARD_NAME }, |
| 671 | { "rvr", DMI_BOARD_VERSION }, |
| 672 | { "cvn", DMI_CHASSIS_VENDOR }, |
| 673 | { "ct", DMI_CHASSIS_TYPE }, |
| 674 | { "cvr", DMI_CHASSIS_VERSION }, |
| 675 | { NULL, DMI_NONE } |
| 676 | }; |
| 677 | |
| 678 | static void dmi_ascii_filter(char *d, const char *s) |
| 679 | { |
| 680 | /* Filter out characters we don't want to see in the modalias string */ |
| 681 | for (; *s; s++) |
| 682 | if (*s > ' ' && *s < 127 && *s != ':') |
| 683 | *(d++) = *s; |
| 684 | |
| 685 | *d = 0; |
| 686 | } |
| 687 | |
| 688 | |
| 689 | static int do_dmi_entry(const char *filename, struct dmi_system_id *id, |
| 690 | char *alias) |
| 691 | { |
| 692 | int i, j; |
| 693 | |
| 694 | sprintf(alias, "dmi*"); |
| 695 | |
| 696 | for (i = 0; i < ARRAY_SIZE(dmi_fields); i++) { |
| 697 | for (j = 0; j < 4; j++) { |
| 698 | if (id->matches[j].slot && |
| 699 | id->matches[j].slot == dmi_fields[i].field) { |
| 700 | sprintf(alias + strlen(alias), ":%s*", |
| 701 | dmi_fields[i].prefix); |
| 702 | dmi_ascii_filter(alias + strlen(alias), |
| 703 | id->matches[j].substr); |
| 704 | strcat(alias, "*"); |
| 705 | } |
| 706 | } |
| 707 | } |
| 708 | |
| 709 | strcat(alias, ":"); |
| 710 | return 1; |
| 711 | } |
Adrian Bunk | f606ddf | 2008-07-23 21:28:50 -0700 | [diff] [blame] | 712 | /* Ignore any prefix, eg. some architectures prepend _ */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | static inline int sym_is(const char *symbol, const char *name) |
| 714 | { |
| 715 | const char *match; |
| 716 | |
| 717 | match = strstr(symbol, name); |
| 718 | if (!match) |
| 719 | return 0; |
| 720 | return match[strlen(symbol)] == '\0'; |
| 721 | } |
| 722 | |
| 723 | static void do_table(void *symval, unsigned long size, |
| 724 | unsigned long id_size, |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 725 | const char *device_id, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 726 | void *function, |
| 727 | struct module *mod) |
| 728 | { |
| 729 | unsigned int i; |
| 730 | char alias[500]; |
| 731 | int (*do_entry)(const char *, void *entry, char *alias) = function; |
| 732 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 733 | device_id_check(mod->name, device_id, size, id_size, symval); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 734 | /* Leave last one: it's the terminator. */ |
| 735 | size -= id_size; |
| 736 | |
| 737 | for (i = 0; i < size; i += id_size) { |
| 738 | if (do_entry(mod->name, symval+i, alias)) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | buf_printf(&mod->dev_table_buf, |
| 740 | "MODULE_ALIAS(\"%s\");\n", alias); |
| 741 | } |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /* Create MODULE_ALIAS() statements. |
| 746 | * At this time, we cannot write the actual output C source yet, |
| 747 | * so we write into the mod->dev_table_buf buffer. */ |
| 748 | void handle_moddevtable(struct module *mod, struct elf_info *info, |
| 749 | Elf_Sym *sym, const char *symname) |
| 750 | { |
| 751 | void *symval; |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 752 | char *zeros = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 753 | |
| 754 | /* We're looking for a section relative symbol */ |
| 755 | if (!sym->st_shndx || sym->st_shndx >= info->hdr->e_shnum) |
| 756 | return; |
| 757 | |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 758 | /* Handle all-NULL symbols allocated into .bss */ |
| 759 | if (info->sechdrs[sym->st_shndx].sh_type & SHT_NOBITS) { |
| 760 | zeros = calloc(1, sym->st_size); |
| 761 | symval = zeros; |
| 762 | } else { |
| 763 | symval = (void *)info->hdr |
| 764 | + info->sechdrs[sym->st_shndx].sh_offset |
| 765 | + sym->st_value; |
| 766 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 767 | |
| 768 | if (sym_is(symname, "__mod_pci_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 769 | do_table(symval, sym->st_size, |
| 770 | sizeof(struct pci_device_id), "pci", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 771 | do_pci_entry, mod); |
| 772 | else if (sym_is(symname, "__mod_usb_device_table")) |
Roman Kagan | b19dcd9 | 2005-04-22 15:07:01 -0700 | [diff] [blame] | 773 | /* special case to handle bcdDevice ranges */ |
| 774 | do_usb_table(symval, sym->st_size, mod); |
Jiri Slaby | e8c84f9 | 2008-05-19 15:50:01 +0200 | [diff] [blame] | 775 | else if (sym_is(symname, "__mod_hid_device_table")) |
| 776 | do_table(symval, sym->st_size, |
| 777 | sizeof(struct hid_device_id), "hid", |
| 778 | do_hid_entry, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | else if (sym_is(symname, "__mod_ieee1394_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 780 | do_table(symval, sym->st_size, |
| 781 | sizeof(struct ieee1394_device_id), "ieee1394", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 782 | do_ieee1394_entry, mod); |
| 783 | else if (sym_is(symname, "__mod_ccw_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 784 | do_table(symval, sym->st_size, |
| 785 | sizeof(struct ccw_device_id), "ccw", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | do_ccw_entry, mod); |
Martin Schwidefsky | 1534c38 | 2006-09-20 15:58:25 +0200 | [diff] [blame] | 787 | else if (sym_is(symname, "__mod_ap_device_table")) |
| 788 | do_table(symval, sym->st_size, |
| 789 | sizeof(struct ap_device_id), "ap", |
| 790 | do_ap_entry, mod); |
Cornelia Huck | 7e9db9e | 2008-07-14 09:58:44 +0200 | [diff] [blame] | 791 | else if (sym_is(symname, "__mod_css_device_table")) |
| 792 | do_table(symval, sym->st_size, |
| 793 | sizeof(struct css_device_id), "css", |
| 794 | do_css_entry, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | else if (sym_is(symname, "__mod_serio_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 796 | do_table(symval, sym->st_size, |
| 797 | sizeof(struct serio_device_id), "serio", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | do_serio_entry, mod); |
Thomas Renninger | 29b71a1 | 2007-07-23 14:43:51 +0200 | [diff] [blame] | 799 | else if (sym_is(symname, "__mod_acpi_device_table")) |
| 800 | do_table(symval, sym->st_size, |
| 801 | sizeof(struct acpi_device_id), "acpi", |
| 802 | do_acpi_entry, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 803 | else if (sym_is(symname, "__mod_pnp_device_table")) |
Kay Sievers | 22454cb | 2008-05-28 23:06:47 +0200 | [diff] [blame] | 804 | do_pnp_device_entry(symval, sym->st_size, mod); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 805 | else if (sym_is(symname, "__mod_pnp_card_device_table")) |
Kay Sievers | 0c81eed | 2008-02-21 00:35:54 +0100 | [diff] [blame] | 806 | do_pnp_card_entries(symval, sym->st_size, mod); |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 807 | else if (sym_is(symname, "__mod_pcmcia_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 808 | do_table(symval, sym->st_size, |
| 809 | sizeof(struct pcmcia_device_id), "pcmcia", |
Dominik Brodowski | 90829cf | 2005-06-27 16:28:12 -0700 | [diff] [blame] | 810 | do_pcmcia_entry, mod); |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 811 | else if (sym_is(symname, "__mod_of_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 812 | do_table(symval, sym->st_size, |
| 813 | sizeof(struct of_device_id), "of", |
Jeff Mahoney | 5e65577 | 2005-07-06 15:44:41 -0400 | [diff] [blame] | 814 | do_of_entry, mod); |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 815 | else if (sym_is(symname, "__mod_vio_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 816 | do_table(symval, sym->st_size, |
| 817 | sizeof(struct vio_device_id), "vio", |
Stephen Rothwell | fb120da | 2005-08-17 16:42:59 +1000 | [diff] [blame] | 818 | do_vio_entry, mod); |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 819 | else if (sym_is(symname, "__mod_input_device_table")) |
Sam Ravnborg | fb33d81 | 2006-07-09 16:26:07 +0200 | [diff] [blame] | 820 | do_table(symval, sym->st_size, |
| 821 | sizeof(struct input_device_id), "input", |
Rusty Russell | 1d8f430 | 2005-12-07 21:40:34 +0100 | [diff] [blame] | 822 | do_input_entry, mod); |
Michael Tokarev | 07563c7 | 2006-09-27 01:50:56 -0700 | [diff] [blame] | 823 | else if (sym_is(symname, "__mod_eisa_device_table")) |
| 824 | do_table(symval, sym->st_size, |
| 825 | sizeof(struct eisa_device_id), "eisa", |
| 826 | do_eisa_entry, mod); |
Kyle McMartin | f3cf267 | 2007-01-13 14:58:21 -0500 | [diff] [blame] | 827 | else if (sym_is(symname, "__mod_parisc_device_table")) |
| 828 | do_table(symval, sym->st_size, |
| 829 | sizeof(struct parisc_device_id), "parisc", |
| 830 | do_parisc_entry, mod); |
Pierre Ossman | d59b66c | 2007-06-17 11:34:23 +0200 | [diff] [blame] | 831 | else if (sym_is(symname, "__mod_sdio_device_table")) |
| 832 | do_table(symval, sym->st_size, |
| 833 | sizeof(struct sdio_device_id), "sdio", |
| 834 | do_sdio_entry, mod); |
Michael Buesch | 61e115a | 2007-09-18 15:12:50 -0400 | [diff] [blame] | 835 | else if (sym_is(symname, "__mod_ssb_device_table")) |
| 836 | do_table(symval, sym->st_size, |
| 837 | sizeof(struct ssb_device_id), "ssb", |
| 838 | do_ssb_entry, mod); |
Rusty Russell | b01d9f2 | 2007-10-22 11:03:39 +1000 | [diff] [blame] | 839 | else if (sym_is(symname, "__mod_virtio_device_table")) |
| 840 | do_table(symval, sym->st_size, |
| 841 | sizeof(struct virtio_device_id), "virtio", |
| 842 | do_virtio_entry, mod); |
Jean Delvare | d2653e9 | 2008-04-29 23:11:39 +0200 | [diff] [blame] | 843 | else if (sym_is(symname, "__mod_i2c_device_table")) |
| 844 | do_table(symval, sym->st_size, |
| 845 | sizeof(struct i2c_device_id), "i2c", |
| 846 | do_i2c_entry, mod); |
David Woodhouse | d945b69 | 2008-09-16 16:23:28 -0700 | [diff] [blame] | 847 | else if (sym_is(symname, "__mod_dmi_device_table")) |
| 848 | do_table(symval, sym->st_size, |
| 849 | sizeof(struct dmi_system_id), "dmi", |
| 850 | do_dmi_entry, mod); |
Kees Cook | e004982 | 2007-09-16 11:15:46 +0200 | [diff] [blame] | 851 | free(zeros); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 852 | } |
| 853 | |
| 854 | /* Now add out buffered information to the generated C source */ |
| 855 | void add_moddevtable(struct buffer *buf, struct module *mod) |
| 856 | { |
| 857 | buf_printf(buf, "\n"); |
| 858 | buf_write(buf, mod->dev_table_buf.p, mod->dev_table_buf.pos); |
| 859 | free(mod->dev_table_buf.p); |
| 860 | } |