diff options
Diffstat (limited to 'scripts/mod/file2alias.c')
| -rw-r--r-- | scripts/mod/file2alias.c | 303 |
1 files changed, 186 insertions, 117 deletions
diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c index f936d1fa969d..b89efe6e4c85 100644 --- a/scripts/mod/file2alias.c +++ b/scripts/mod/file2alias.c | |||
| @@ -28,6 +28,7 @@ typedef Elf64_Addr kernel_ulong_t; | |||
| 28 | #endif | 28 | #endif |
| 29 | 29 | ||
| 30 | #include <ctype.h> | 30 | #include <ctype.h> |
| 31 | #include <stdbool.h> | ||
| 31 | 32 | ||
| 32 | typedef uint32_t __u32; | 33 | typedef uint32_t __u32; |
| 33 | typedef uint16_t __u16; | 34 | typedef uint16_t __u16; |
| @@ -38,6 +39,61 @@ typedef unsigned char __u8; | |||
| 38 | * we handle those differences explicitly below */ | 39 | * we handle those differences explicitly below */ |
| 39 | #include "../../include/linux/mod_devicetable.h" | 40 | #include "../../include/linux/mod_devicetable.h" |
| 40 | 41 | ||
| 42 | /* This array collects all instances that use the generic do_table */ | ||
| 43 | struct devtable { | ||
| 44 | const char *device_id; /* name of table, __mod_<name>_device_table. */ | ||
| 45 | unsigned long id_size; | ||
| 46 | void *function; | ||
| 47 | }; | ||
| 48 | |||
| 49 | #define ___cat(a,b) a ## b | ||
| 50 | #define __cat(a,b) ___cat(a,b) | ||
| 51 | |||
| 52 | /* we need some special handling for this host tool running eventually on | ||
| 53 | * Darwin. The Mach-O section handling is a bit different than ELF section | ||
| 54 | * handling. The differnces in detail are: | ||
| 55 | * a) we have segments which have sections | ||
| 56 | * b) we need a API call to get the respective section symbols */ | ||
| 57 | #if defined(__MACH__) | ||
| 58 | #include <mach-o/getsect.h> | ||
| 59 | |||
| 60 | #define INIT_SECTION(name) do { \ | ||
| 61 | unsigned long name ## _len; \ | ||
| 62 | char *__cat(pstart_,name) = getsectdata("__TEXT", \ | ||
| 63 | #name, &__cat(name,_len)); \ | ||
| 64 | char *__cat(pstop_,name) = __cat(pstart_,name) + \ | ||
| 65 | __cat(name, _len); \ | ||
| 66 | __cat(__start_,name) = (void *)__cat(pstart_,name); \ | ||
| 67 | __cat(__stop_,name) = (void *)__cat(pstop_,name); \ | ||
| 68 | } while (0) | ||
| 69 | #define SECTION(name) __attribute__((section("__TEXT, " #name))) | ||
| 70 | |||
| 71 | struct devtable **__start___devtable, **__stop___devtable; | ||
| 72 | #else | ||
| 73 | #define INIT_SECTION(name) /* no-op for ELF */ | ||
| 74 | #define SECTION(name) __attribute__((section(#name))) | ||
| 75 | |||
| 76 | /* We construct a table of pointers in an ELF section (pointers generally | ||
| 77 | * go unpadded by gcc). ld creates boundary syms for us. */ | ||
| 78 | extern struct devtable *__start___devtable[], *__stop___devtable[]; | ||
| 79 | #endif /* __MACH__ */ | ||
| 80 | |||
| 81 | #if __GNUC__ == 3 && __GNUC_MINOR__ < 3 | ||
| 82 | # define __used __attribute__((__unused__)) | ||
| 83 | #else | ||
| 84 | # define __used __attribute__((__used__)) | ||
| 85 | #endif | ||
| 86 | |||
| 87 | /* Add a table entry. We test function type matches while we're here. */ | ||
| 88 | #define ADD_TO_DEVTABLE(device_id, type, function) \ | ||
| 89 | static struct devtable __cat(devtable,__LINE__) = { \ | ||
| 90 | device_id + 0*sizeof((function)((const char *)NULL, \ | ||
| 91 | (type *)NULL, \ | ||
| 92 | (char *)NULL)), \ | ||
| 93 | sizeof(type), (function) }; \ | ||
| 94 | static struct devtable *SECTION(__devtable) __used \ | ||
| 95 | __cat(devtable_ptr,__LINE__) = &__cat(devtable,__LINE__) | ||
| 96 | |||
| 41 | #define ADD(str, sep, cond, field) \ | 97 | #define ADD(str, sep, cond, field) \ |
| 42 | do { \ | 98 | do { \ |
| 43 | strcat(str, sep); \ | 99 | strcat(str, sep); \ |
| @@ -289,6 +345,7 @@ static int do_hid_entry(const char *filename, | |||
| 289 | 345 | ||
| 290 | return 1; | 346 | return 1; |
| 291 | } | 347 | } |
| 348 | ADD_TO_DEVTABLE("hid", struct hid_device_id, do_hid_entry); | ||
| 292 | 349 | ||
| 293 | /* Looks like: ieee1394:venNmoNspNverN */ | 350 | /* Looks like: ieee1394:venNmoNspNverN */ |
| 294 | static int do_ieee1394_entry(const char *filename, | 351 | static int do_ieee1394_entry(const char *filename, |
| @@ -313,6 +370,7 @@ static int do_ieee1394_entry(const char *filename, | |||
| 313 | add_wildcard(alias); | 370 | add_wildcard(alias); |
| 314 | return 1; | 371 | return 1; |
| 315 | } | 372 | } |
| 373 | ADD_TO_DEVTABLE("ieee1394", struct ieee1394_device_id, do_ieee1394_entry); | ||
| 316 | 374 | ||
| 317 | /* Looks like: pci:vNdNsvNsdNbcNscNiN. */ | 375 | /* Looks like: pci:vNdNsvNsdNbcNscNiN. */ |
| 318 | static int do_pci_entry(const char *filename, | 376 | static int do_pci_entry(const char *filename, |
| @@ -356,6 +414,7 @@ static int do_pci_entry(const char *filename, | |||
| 356 | add_wildcard(alias); | 414 | add_wildcard(alias); |
| 357 | return 1; | 415 | return 1; |
| 358 | } | 416 | } |
| 417 | ADD_TO_DEVTABLE("pci", struct pci_device_id, do_pci_entry); | ||
| 359 | 418 | ||
| 360 | /* looks like: "ccw:tNmNdtNdmN" */ | 419 | /* looks like: "ccw:tNmNdtNdmN" */ |
| 361 | static int do_ccw_entry(const char *filename, | 420 | static int do_ccw_entry(const char *filename, |
| @@ -379,6 +438,7 @@ static int do_ccw_entry(const char *filename, | |||
| 379 | add_wildcard(alias); | 438 | add_wildcard(alias); |
| 380 | return 1; | 439 | return 1; |
| 381 | } | 440 | } |
| 441 | ADD_TO_DEVTABLE("ccw", struct ccw_device_id, do_ccw_entry); | ||
| 382 | 442 | ||
| 383 | /* looks like: "ap:tN" */ | 443 | /* looks like: "ap:tN" */ |
| 384 | static int do_ap_entry(const char *filename, | 444 | static int do_ap_entry(const char *filename, |
| @@ -387,6 +447,7 @@ static int do_ap_entry(const char *filename, | |||
| 387 | sprintf(alias, "ap:t%02X*", id->dev_type); | 447 | sprintf(alias, "ap:t%02X*", id->dev_type); |
| 388 | return 1; | 448 | return 1; |
| 389 | } | 449 | } |
| 450 | ADD_TO_DEVTABLE("ap", struct ap_device_id, do_ap_entry); | ||
| 390 | 451 | ||
| 391 | /* looks like: "css:tN" */ | 452 | /* looks like: "css:tN" */ |
| 392 | static int do_css_entry(const char *filename, | 453 | static int do_css_entry(const char *filename, |
| @@ -395,6 +456,7 @@ static int do_css_entry(const char *filename, | |||
| 395 | sprintf(alias, "css:t%01X", id->type); | 456 | sprintf(alias, "css:t%01X", id->type); |
| 396 | return 1; | 457 | return 1; |
| 397 | } | 458 | } |
| 459 | ADD_TO_DEVTABLE("css", struct css_device_id, do_css_entry); | ||
| 398 | 460 | ||
| 399 | /* Looks like: "serio:tyNprNidNexN" */ | 461 | /* Looks like: "serio:tyNprNidNexN" */ |
| 400 | static int do_serio_entry(const char *filename, | 462 | static int do_serio_entry(const char *filename, |
| @@ -414,6 +476,7 @@ static int do_serio_entry(const char *filename, | |||
| 414 | add_wildcard(alias); | 476 | add_wildcard(alias); |
| 415 | return 1; | 477 | return 1; |
| 416 | } | 478 | } |
| 479 | ADD_TO_DEVTABLE("serio", struct serio_device_id, do_serio_entry); | ||
| 417 | 480 | ||
| 418 | /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */ | 481 | /* looks like: "acpi:ACPI0003 or acpi:PNP0C0B" or "acpi:LNXVIDEO" */ |
| 419 | static int do_acpi_entry(const char *filename, | 482 | static int do_acpi_entry(const char *filename, |
| @@ -422,6 +485,7 @@ static int do_acpi_entry(const char *filename, | |||
| 422 | sprintf(alias, "acpi*:%s:*", id->id); | 485 | sprintf(alias, "acpi*:%s:*", id->id); |
| 423 | return 1; | 486 | return 1; |
| 424 | } | 487 | } |
| 488 | ADD_TO_DEVTABLE("acpi", struct acpi_device_id, do_acpi_entry); | ||
| 425 | 489 | ||
| 426 | /* looks like: "pnp:dD" */ | 490 | /* looks like: "pnp:dD" */ |
| 427 | static void do_pnp_device_entry(void *symval, unsigned long size, | 491 | static void do_pnp_device_entry(void *symval, unsigned long size, |
| @@ -544,8 +608,7 @@ static int do_pcmcia_entry(const char *filename, | |||
| 544 | add_wildcard(alias); | 608 | add_wildcard(alias); |
| 545 | return 1; | 609 | return 1; |
| 546 | } | 610 | } |
| 547 | 611 | ADD_TO_DEVTABLE("pcmcia", struct pcmcia_device_id, do_pcmcia_entry); | |
| 548 | |||
| 549 | 612 | ||
| 550 | static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) | 613 | static int do_of_entry (const char *filename, struct of_device_id *of, char *alias) |
| 551 | { | 614 | { |
| @@ -568,6 +631,7 @@ static int do_of_entry (const char *filename, struct of_device_id *of, char *ali | |||
| 568 | add_wildcard(alias); | 631 | add_wildcard(alias); |
| 569 | return 1; | 632 | return 1; |
| 570 | } | 633 | } |
| 634 | ADD_TO_DEVTABLE("of", struct of_device_id, do_of_entry); | ||
| 571 | 635 | ||
| 572 | static int do_vio_entry(const char *filename, struct vio_device_id *vio, | 636 | static int do_vio_entry(const char *filename, struct vio_device_id *vio, |
| 573 | char *alias) | 637 | char *alias) |
| @@ -585,6 +649,7 @@ static int do_vio_entry(const char *filename, struct vio_device_id *vio, | |||
| 585 | add_wildcard(alias); | 649 | add_wildcard(alias); |
| 586 | return 1; | 650 | return 1; |
| 587 | } | 651 | } |
| 652 | ADD_TO_DEVTABLE("vio", struct vio_device_id, do_vio_entry); | ||
| 588 | 653 | ||
| 589 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) | 654 | #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) |
| 590 | 655 | ||
| @@ -640,6 +705,7 @@ static int do_input_entry(const char *filename, struct input_device_id *id, | |||
| 640 | do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX); | 705 | do_input(alias, id->swbit, 0, INPUT_DEVICE_ID_SW_MAX); |
| 641 | return 1; | 706 | return 1; |
| 642 | } | 707 | } |
| 708 | ADD_TO_DEVTABLE("input", struct input_device_id, do_input_entry); | ||
| 643 | 709 | ||
| 644 | static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, | 710 | static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, |
| 645 | char *alias) | 711 | char *alias) |
| @@ -650,6 +716,7 @@ static int do_eisa_entry(const char *filename, struct eisa_device_id *eisa, | |||
| 650 | strcat(alias, "*"); | 716 | strcat(alias, "*"); |
| 651 | return 1; | 717 | return 1; |
| 652 | } | 718 | } |
| 719 | ADD_TO_DEVTABLE("eisa", struct eisa_device_id, do_eisa_entry); | ||
| 653 | 720 | ||
| 654 | /* Looks like: parisc:tNhvNrevNsvN */ | 721 | /* Looks like: parisc:tNhvNrevNsvN */ |
| 655 | static int do_parisc_entry(const char *filename, struct parisc_device_id *id, | 722 | static int do_parisc_entry(const char *filename, struct parisc_device_id *id, |
| @@ -669,6 +736,7 @@ static int do_parisc_entry(const char *filename, struct parisc_device_id *id, | |||
| 669 | add_wildcard(alias); | 736 | add_wildcard(alias); |
| 670 | return 1; | 737 | return 1; |
| 671 | } | 738 | } |
| 739 | ADD_TO_DEVTABLE("parisc", struct parisc_device_id, do_parisc_entry); | ||
| 672 | 740 | ||
| 673 | /* Looks like: sdio:cNvNdN. */ | 741 | /* Looks like: sdio:cNvNdN. */ |
| 674 | static int do_sdio_entry(const char *filename, | 742 | static int do_sdio_entry(const char *filename, |
| @@ -685,6 +753,7 @@ static int do_sdio_entry(const char *filename, | |||
| 685 | add_wildcard(alias); | 753 | add_wildcard(alias); |
| 686 | return 1; | 754 | return 1; |
| 687 | } | 755 | } |
| 756 | ADD_TO_DEVTABLE("sdio", struct sdio_device_id, do_sdio_entry); | ||
| 688 | 757 | ||
| 689 | /* Looks like: ssb:vNidNrevN. */ | 758 | /* Looks like: ssb:vNidNrevN. */ |
| 690 | static int do_ssb_entry(const char *filename, | 759 | static int do_ssb_entry(const char *filename, |
| @@ -701,6 +770,7 @@ static int do_ssb_entry(const char *filename, | |||
| 701 | add_wildcard(alias); | 770 | add_wildcard(alias); |
| 702 | return 1; | 771 | return 1; |
| 703 | } | 772 | } |
| 773 | ADD_TO_DEVTABLE("ssb", struct ssb_device_id, do_ssb_entry); | ||
| 704 | 774 | ||
| 705 | /* Looks like: bcma:mNidNrevNclN. */ | 775 | /* Looks like: bcma:mNidNrevNclN. */ |
| 706 | static int do_bcma_entry(const char *filename, | 776 | static int do_bcma_entry(const char *filename, |
| @@ -719,6 +789,7 @@ static int do_bcma_entry(const char *filename, | |||
| 719 | add_wildcard(alias); | 789 | add_wildcard(alias); |
| 720 | return 1; | 790 | return 1; |
| 721 | } | 791 | } |
| 792 | ADD_TO_DEVTABLE("bcma", struct bcma_device_id, do_bcma_entry); | ||
| 722 | 793 | ||
| 723 | /* Looks like: virtio:dNvN */ | 794 | /* Looks like: virtio:dNvN */ |
| 724 | static int do_virtio_entry(const char *filename, struct virtio_device_id *id, | 795 | static int do_virtio_entry(const char *filename, struct virtio_device_id *id, |
| @@ -734,6 +805,7 @@ static int do_virtio_entry(const char *filename, struct virtio_device_id *id, | |||
| 734 | add_wildcard(alias); | 805 | add_wildcard(alias); |
| 735 | return 1; | 806 | return 1; |
| 736 | } | 807 | } |
| 808 | ADD_TO_DEVTABLE("virtio", struct virtio_device_id, do_virtio_entry); | ||
| 737 | 809 | ||
| 738 | /* | 810 | /* |
| 739 | * Looks like: vmbus:guid | 811 | * Looks like: vmbus:guid |
| @@ -755,6 +827,7 @@ static int do_vmbus_entry(const char *filename, struct hv_vmbus_device_id *id, | |||
| 755 | 827 | ||
| 756 | return 1; | 828 | return 1; |
| 757 | } | 829 | } |
| 830 | ADD_TO_DEVTABLE("vmbus", struct hv_vmbus_device_id, do_vmbus_entry); | ||
| 758 | 831 | ||
| 759 | /* Looks like: i2c:S */ | 832 | /* Looks like: i2c:S */ |
| 760 | static int do_i2c_entry(const char *filename, struct i2c_device_id *id, | 833 | static int do_i2c_entry(const char *filename, struct i2c_device_id *id, |
| @@ -764,6 +837,7 @@ static int do_i2c_entry(const char *filename, struct i2c_device_id *id, | |||
| 764 | 837 | ||
| 765 | return 1; | 838 | return 1; |
| 766 | } | 839 | } |
| 840 | ADD_TO_DEVTABLE("i2c", struct i2c_device_id, do_i2c_entry); | ||
| 767 | 841 | ||
| 768 | /* Looks like: spi:S */ | 842 | /* Looks like: spi:S */ |
| 769 | static int do_spi_entry(const char *filename, struct spi_device_id *id, | 843 | static int do_spi_entry(const char *filename, struct spi_device_id *id, |
| @@ -773,6 +847,7 @@ static int do_spi_entry(const char *filename, struct spi_device_id *id, | |||
| 773 | 847 | ||
| 774 | return 1; | 848 | return 1; |
| 775 | } | 849 | } |
| 850 | ADD_TO_DEVTABLE("spi", struct spi_device_id, do_spi_entry); | ||
| 776 | 851 | ||
| 777 | static const struct dmifield { | 852 | static const struct dmifield { |
| 778 | const char *prefix; | 853 | const char *prefix; |
| @@ -827,6 +902,7 @@ static int do_dmi_entry(const char *filename, struct dmi_system_id *id, | |||
| 827 | strcat(alias, ":"); | 902 | strcat(alias, ":"); |
| 828 | return 1; | 903 | return 1; |
| 829 | } | 904 | } |
| 905 | ADD_TO_DEVTABLE("dmi", struct dmi_system_id, do_dmi_entry); | ||
| 830 | 906 | ||
| 831 | static int do_platform_entry(const char *filename, | 907 | static int do_platform_entry(const char *filename, |
| 832 | struct platform_device_id *id, char *alias) | 908 | struct platform_device_id *id, char *alias) |
| @@ -834,6 +910,7 @@ static int do_platform_entry(const char *filename, | |||
| 834 | sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name); | 910 | sprintf(alias, PLATFORM_MODULE_PREFIX "%s", id->name); |
| 835 | return 1; | 911 | return 1; |
| 836 | } | 912 | } |
| 913 | ADD_TO_DEVTABLE("platform", struct platform_device_id, do_platform_entry); | ||
| 837 | 914 | ||
| 838 | static int do_mdio_entry(const char *filename, | 915 | static int do_mdio_entry(const char *filename, |
| 839 | struct mdio_device_id *id, char *alias) | 916 | struct mdio_device_id *id, char *alias) |
| @@ -856,6 +933,7 @@ static int do_mdio_entry(const char *filename, | |||
| 856 | 933 | ||
| 857 | return 1; | 934 | return 1; |
| 858 | } | 935 | } |
| 936 | ADD_TO_DEVTABLE("mdio", struct mdio_device_id, do_mdio_entry); | ||
| 859 | 937 | ||
| 860 | /* Looks like: zorro:iN. */ | 938 | /* Looks like: zorro:iN. */ |
| 861 | static int do_zorro_entry(const char *filename, struct zorro_device_id *id, | 939 | static int do_zorro_entry(const char *filename, struct zorro_device_id *id, |
| @@ -866,6 +944,7 @@ static int do_zorro_entry(const char *filename, struct zorro_device_id *id, | |||
| 866 | ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id); | 944 | ADD(alias, "i", id->id != ZORRO_WILDCARD, id->id); |
| 867 | return 1; | 945 | return 1; |
| 868 | } | 946 | } |
| 947 | ADD_TO_DEVTABLE("zorro", struct zorro_device_id, do_zorro_entry); | ||
| 869 | 948 | ||
| 870 | /* looks like: "pnp:dD" */ | 949 | /* looks like: "pnp:dD" */ |
| 871 | static int do_isapnp_entry(const char *filename, | 950 | static int do_isapnp_entry(const char *filename, |
| @@ -879,16 +958,84 @@ static int do_isapnp_entry(const char *filename, | |||
| 879 | (id->function >> 12) & 0x0f, (id->function >> 8) & 0x0f); | 958 | (id->function >> 12) & 0x0f, (id->function >> 8) & 0x0f); |
| 880 | return 1; | 959 | return 1; |
| 881 | } | 960 | } |
| 961 | ADD_TO_DEVTABLE("isapnp", struct isapnp_device_id, do_isapnp_entry); | ||
| 882 | 962 | ||
| 883 | /* Ignore any prefix, eg. some architectures prepend _ */ | 963 | /* |
| 884 | static inline int sym_is(const char *symbol, const char *name) | 964 | * Append a match expression for a single masked hex digit. |
| 965 | * outp points to a pointer to the character at which to append. | ||
| 966 | * *outp is updated on return to point just after the appended text, | ||
| 967 | * to facilitate further appending. | ||
| 968 | */ | ||
| 969 | static void append_nibble_mask(char **outp, | ||
| 970 | unsigned int nibble, unsigned int mask) | ||
| 885 | { | 971 | { |
| 886 | const char *match; | 972 | char *p = *outp; |
| 973 | unsigned int i; | ||
| 887 | 974 | ||
| 888 | match = strstr(symbol, name); | 975 | switch (mask) { |
| 889 | if (!match) | 976 | case 0: |
| 890 | return 0; | 977 | *p++ = '?'; |
| 891 | return match[strlen(name)] == '\0'; | 978 | break; |
| 979 | |||
| 980 | case 0xf: | ||
| 981 | p += sprintf(p, "%X", nibble); | ||
| 982 | break; | ||
| 983 | |||
| 984 | default: | ||
| 985 | /* | ||
| 986 | * Dumbly emit a match pattern for all possible matching | ||
| 987 | * digits. This could be improved in some cases using ranges, | ||
| 988 | * but it has the advantage of being trivially correct, and is | ||
| 989 | * often optimal. | ||
| 990 | */ | ||
| 991 | *p++ = '['; | ||
| 992 | for (i = 0; i < 0x10; i++) | ||
| 993 | if ((i & mask) == nibble) | ||
| 994 | p += sprintf(p, "%X", i); | ||
| 995 | *p++ = ']'; | ||
| 996 | } | ||
| 997 | |||
| 998 | /* Ensure that the string remains NUL-terminated: */ | ||
| 999 | *p = '\0'; | ||
| 1000 | |||
| 1001 | /* Advance the caller's end-of-string pointer: */ | ||
| 1002 | *outp = p; | ||
| 1003 | } | ||
| 1004 | |||
| 1005 | /* | ||
| 1006 | * looks like: "amba:dN" | ||
| 1007 | * | ||
| 1008 | * N is exactly 8 digits, where each is an upper-case hex digit, or | ||
| 1009 | * a ? or [] pattern matching exactly one digit. | ||
| 1010 | */ | ||
| 1011 | static int do_amba_entry(const char *filename, | ||
| 1012 | struct amba_id *id, char *alias) | ||
| 1013 | { | ||
| 1014 | unsigned int digit; | ||
| 1015 | char *p = alias; | ||
| 1016 | |||
| 1017 | if ((id->id & id->mask) != id->id) | ||
| 1018 | fatal("%s: Masked-off bit(s) of AMBA device ID are non-zero: " | ||
| 1019 | "id=0x%08X, mask=0x%08X. Please fix this driver.\n", | ||
| 1020 | filename, id->id, id->mask); | ||
| 1021 | |||
| 1022 | p += sprintf(alias, "amba:d"); | ||
| 1023 | for (digit = 0; digit < 8; digit++) | ||
| 1024 | append_nibble_mask(&p, | ||
| 1025 | (id->id >> (4 * (7 - digit))) & 0xf, | ||
| 1026 | (id->mask >> (4 * (7 - digit))) & 0xf); | ||
| 1027 | |||
| 1028 | return 1; | ||
| 1029 | } | ||
| 1030 | ADD_TO_DEVTABLE("amba", struct amba_id, do_amba_entry); | ||
| 1031 | |||
| 1032 | /* Does namelen bytes of name exactly match the symbol? */ | ||
| 1033 | static bool sym_is(const char *name, unsigned namelen, const char *symbol) | ||
| 1034 | { | ||
| 1035 | if (namelen != strlen(symbol)) | ||
| 1036 | return false; | ||
| 1037 | |||
| 1038 | return memcmp(name, symbol, namelen) == 0; | ||
| 892 | } | 1039 | } |
| 893 | 1040 | ||
| 894 | static void do_table(void *symval, unsigned long size, | 1041 | static void do_table(void *symval, unsigned long size, |
| @@ -921,11 +1068,25 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, | |||
| 921 | { | 1068 | { |
| 922 | void *symval; | 1069 | void *symval; |
| 923 | char *zeros = NULL; | 1070 | char *zeros = NULL; |
| 1071 | const char *name; | ||
| 1072 | unsigned int namelen; | ||
| 924 | 1073 | ||
| 925 | /* We're looking for a section relative symbol */ | 1074 | /* We're looking for a section relative symbol */ |
| 926 | if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) | 1075 | if (!sym->st_shndx || get_secindex(info, sym) >= info->num_sections) |
| 927 | return; | 1076 | return; |
| 928 | 1077 | ||
| 1078 | /* All our symbols are of form <prefix>__mod_XXX_device_table. */ | ||
| 1079 | name = strstr(symname, "__mod_"); | ||
| 1080 | if (!name) | ||
| 1081 | return; | ||
| 1082 | name += strlen("__mod_"); | ||
| 1083 | namelen = strlen(name); | ||
| 1084 | if (namelen < strlen("_device_table")) | ||
| 1085 | return; | ||
| 1086 | if (strcmp(name + namelen - strlen("_device_table"), "_device_table")) | ||
| 1087 | return; | ||
| 1088 | namelen -= strlen("_device_table"); | ||
| 1089 | |||
| 929 | /* Handle all-NULL symbols allocated into .bss */ | 1090 | /* Handle all-NULL symbols allocated into .bss */ |
| 930 | if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { | 1091 | if (info->sechdrs[get_secindex(info, sym)].sh_type & SHT_NOBITS) { |
| 931 | zeros = calloc(1, sym->st_size); | 1092 | zeros = calloc(1, sym->st_size); |
| @@ -936,117 +1097,25 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, | |||
| 936 | + sym->st_value; | 1097 | + sym->st_value; |
| 937 | } | 1098 | } |
| 938 | 1099 | ||
| 939 | if (sym_is(symname, "__mod_pci_device_table")) | 1100 | /* First handle the "special" cases */ |
| 940 | do_table(symval, sym->st_size, | 1101 | if (sym_is(name, namelen, "usb")) |
| 941 | sizeof(struct pci_device_id), "pci", | ||
| 942 | do_pci_entry, mod); | ||
| 943 | else if (sym_is(symname, "__mod_usb_device_table")) | ||
| 944 | /* special case to handle bcdDevice ranges */ | ||
| 945 | do_usb_table(symval, sym->st_size, mod); | 1102 | do_usb_table(symval, sym->st_size, mod); |
| 946 | else if (sym_is(symname, "__mod_hid_device_table")) | 1103 | else if (sym_is(name, namelen, "pnp")) |
| 947 | do_table(symval, sym->st_size, | ||
| 948 | sizeof(struct hid_device_id), "hid", | ||
| 949 | do_hid_entry, mod); | ||
| 950 | else if (sym_is(symname, "__mod_ieee1394_device_table")) | ||
| 951 | do_table(symval, sym->st_size, | ||
| 952 | sizeof(struct ieee1394_device_id), "ieee1394", | ||
| 953 | do_ieee1394_entry, mod); | ||
| 954 | else if (sym_is(symname, "__mod_ccw_device_table")) | ||
| 955 | do_table(symval, sym->st_size, | ||
| 956 | sizeof(struct ccw_device_id), "ccw", | ||
| 957 | do_ccw_entry, mod); | ||
| 958 | else if (sym_is(symname, "__mod_ap_device_table")) | ||
| 959 | do_table(symval, sym->st_size, | ||
| 960 | sizeof(struct ap_device_id), "ap", | ||
| 961 | do_ap_entry, mod); | ||
| 962 | else if (sym_is(symname, "__mod_css_device_table")) | ||
| 963 | do_table(symval, sym->st_size, | ||
| 964 | sizeof(struct css_device_id), "css", | ||
| 965 | do_css_entry, mod); | ||
| 966 | else if (sym_is(symname, "__mod_serio_device_table")) | ||
| 967 | do_table(symval, sym->st_size, | ||
| 968 | sizeof(struct serio_device_id), "serio", | ||
| 969 | do_serio_entry, mod); | ||
| 970 | else if (sym_is(symname, "__mod_acpi_device_table")) | ||
| 971 | do_table(symval, sym->st_size, | ||
| 972 | sizeof(struct acpi_device_id), "acpi", | ||
| 973 | do_acpi_entry, mod); | ||
| 974 | else if (sym_is(symname, "__mod_pnp_device_table")) | ||
| 975 | do_pnp_device_entry(symval, sym->st_size, mod); | 1104 | do_pnp_device_entry(symval, sym->st_size, mod); |
| 976 | else if (sym_is(symname, "__mod_pnp_card_device_table")) | 1105 | else if (sym_is(name, namelen, "pnp_card")) |
| 977 | do_pnp_card_entries(symval, sym->st_size, mod); | 1106 | do_pnp_card_entries(symval, sym->st_size, mod); |
| 978 | else if (sym_is(symname, "__mod_pcmcia_device_table")) | 1107 | else { |
| 979 | do_table(symval, sym->st_size, | 1108 | struct devtable **p; |
| 980 | sizeof(struct pcmcia_device_id), "pcmcia", | 1109 | INIT_SECTION(__devtable); |
| 981 | do_pcmcia_entry, mod); | 1110 | |
| 982 | else if (sym_is(symname, "__mod_of_device_table")) | 1111 | for (p = __start___devtable; p < __stop___devtable; p++) { |
| 983 | do_table(symval, sym->st_size, | 1112 | if (sym_is(name, namelen, (*p)->device_id)) { |
| 984 | sizeof(struct of_device_id), "of", | 1113 | do_table(symval, sym->st_size, (*p)->id_size, |
| 985 | do_of_entry, mod); | 1114 | (*p)->device_id, (*p)->function, mod); |
| 986 | else if (sym_is(symname, "__mod_vio_device_table")) | 1115 | break; |
| 987 | do_table(symval, sym->st_size, | 1116 | } |
| 988 | sizeof(struct vio_device_id), "vio", | 1117 | } |
| 989 | do_vio_entry, mod); | 1118 | } |
| 990 | else if (sym_is(symname, "__mod_input_device_table")) | ||
| 991 | do_table(symval, sym->st_size, | ||
| 992 | sizeof(struct input_device_id), "input", | ||
| 993 | do_input_entry, mod); | ||
| 994 | else if (sym_is(symname, "__mod_eisa_device_table")) | ||
| 995 | do_table(symval, sym->st_size, | ||
| 996 | sizeof(struct eisa_device_id), "eisa", | ||
| 997 | do_eisa_entry, mod); | ||
| 998 | else if (sym_is(symname, "__mod_parisc_device_table")) | ||
| 999 | do_table(symval, sym->st_size, | ||
| 1000 | sizeof(struct parisc_device_id), "parisc", | ||
| 1001 | do_parisc_entry, mod); | ||
| 1002 | else if (sym_is(symname, "__mod_sdio_device_table")) | ||
| 1003 | do_table(symval, sym->st_size, | ||
| 1004 | sizeof(struct sdio_device_id), "sdio", | ||
| 1005 | do_sdio_entry, mod); | ||
| 1006 | else if (sym_is(symname, "__mod_ssb_device_table")) | ||
| 1007 | do_table(symval, sym->st_size, | ||
| 1008 | sizeof(struct ssb_device_id), "ssb", | ||
| 1009 | do_ssb_entry, mod); | ||
| 1010 | else if (sym_is(symname, "__mod_bcma_device_table")) | ||
| 1011 | do_table(symval, sym->st_size, | ||
| 1012 | sizeof(struct bcma_device_id), "bcma", | ||
| 1013 | do_bcma_entry, mod); | ||
| 1014 | else if (sym_is(symname, "__mod_virtio_device_table")) | ||
| 1015 | do_table(symval, sym->st_size, | ||
| 1016 | sizeof(struct virtio_device_id), "virtio", | ||
| 1017 | do_virtio_entry, mod); | ||
| 1018 | else if (sym_is(symname, "__mod_vmbus_device_table")) | ||
| 1019 | do_table(symval, sym->st_size, | ||
| 1020 | sizeof(struct hv_vmbus_device_id), "vmbus", | ||
| 1021 | do_vmbus_entry, mod); | ||
| 1022 | else if (sym_is(symname, "__mod_i2c_device_table")) | ||
| 1023 | do_table(symval, sym->st_size, | ||
| 1024 | sizeof(struct i2c_device_id), "i2c", | ||
| 1025 | do_i2c_entry, mod); | ||
| 1026 | else if (sym_is(symname, "__mod_spi_device_table")) | ||
| 1027 | do_table(symval, sym->st_size, | ||
| 1028 | sizeof(struct spi_device_id), "spi", | ||
| 1029 | do_spi_entry, mod); | ||
| 1030 | else if (sym_is(symname, "__mod_dmi_device_table")) | ||
| 1031 | do_table(symval, sym->st_size, | ||
| 1032 | sizeof(struct dmi_system_id), "dmi", | ||
| 1033 | do_dmi_entry, mod); | ||
| 1034 | else if (sym_is(symname, "__mod_platform_device_table")) | ||
| 1035 | do_table(symval, sym->st_size, | ||
| 1036 | sizeof(struct platform_device_id), "platform", | ||
| 1037 | do_platform_entry, mod); | ||
| 1038 | else if (sym_is(symname, "__mod_mdio_device_table")) | ||
| 1039 | do_table(symval, sym->st_size, | ||
| 1040 | sizeof(struct mdio_device_id), "mdio", | ||
| 1041 | do_mdio_entry, mod); | ||
| 1042 | else if (sym_is(symname, "__mod_zorro_device_table")) | ||
| 1043 | do_table(symval, sym->st_size, | ||
| 1044 | sizeof(struct zorro_device_id), "zorro", | ||
| 1045 | do_zorro_entry, mod); | ||
| 1046 | else if (sym_is(symname, "__mod_isapnp_device_table")) | ||
| 1047 | do_table(symval, sym->st_size, | ||
| 1048 | sizeof(struct isapnp_device_id), "isa", | ||
| 1049 | do_isapnp_entry, mod); | ||
| 1050 | free(zeros); | 1119 | free(zeros); |
| 1051 | } | 1120 | } |
| 1052 | 1121 | ||
