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