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