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