Rev 6084 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6084 | Rev 6131 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | #include |
|
Line 1... | Line 2... | ||
1 | #include |
2 | |
2 | #include |
3 | #include |
3 | #include |
4 | #include |
4 | #include |
5 | #include |
- | 6 | #include |
|
- | 7 | #include |
|
5 | #include |
8 | |
6 | #include |
- | |
Line 7... | Line 9... | ||
7 | 9 | #include |
|
Line 8... | Line 10... | ||
8 | extern int pci_scan_filter(u32 id, u32 busnr, u32 devfn); |
10 | |
Line 370... | Line 372... | ||
370 | 372 | }; |
|
Line 371... | Line 373... | ||
371 | 373 | ||
372 | 374 | ||
373 | 375 | ||
Line 374... | Line 376... | ||
374 | int pci_scan_slot(u32 bus, int devfn) |
376 | |
375 | { |
377 | int _pci_scan_slot(u32 bus, int devfn) |
Line 491... | Line 493... | ||
491 | 493 | return -1; |
|
Line 492... | Line 494... | ||
492 | for(;bus <= last_bus; bus++) |
494 | |
493 | { |
495 | for(;bus <= last_bus; bus++) |
494 | for (devfn = 0; devfn < 0x100; devfn += 8) |
496 | { |
495 | pci_scan_slot(bus, devfn); |
497 | for (devfn = 0; devfn < 0x100; devfn += 8) |
Line 496... | Line 498... | ||
496 | 498 | _pci_scan_slot(bus, devfn); |
|
497 | 499 | ||
498 | } |
500 | |
Line 569... | Line 571... | ||
569 | return NULL; |
571 | } |
570 | }; |
572 | return NULL; |
571 | 573 | }; |
|
Line 572... | Line 574... | ||
572 | 574 | ||
573 | struct pci_dev * pci_get_bus_and_slot(unsigned int bus, unsigned int devfn) |
575 | |
574 | { |
576 | struct pci_dev * _pci_get_bus_and_slot(unsigned int bus, unsigned int devfn) |
Line 575... | Line 577... | ||
575 | pci_dev_t *dev; |
577 | { |
576 | 578 | pci_dev_t *dev; |
|
Line 662... | Line 664... | ||
662 | IO_COND(addr, /* nothing */, iounmap(addr)); |
664 | { |
663 | } |
665 | IO_COND(addr, /* nothing */, iounmap(addr)); |
664 | 666 | } |
|
Line 665... | Line -... | ||
665 | - | ||
666 | static inline void |
- | |
667 | pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region, |
- | |
668 | struct resource *res) |
- | |
669 | { |
- | |
670 | region->start = res->start; |
- | |
671 | region->end = res->end; |
- | |
Line 672... | Line 667... | ||
672 | } |
667 | |
673 | 668 | ||
674 | 669 | ||
Line 680... | Line 675... | ||
680 | 675 | u32 rom_addr; |
|
Line 681... | Line 676... | ||
681 | if (!res->flags) |
676 | |
682 | return -1; |
677 | if (!res->flags) |
Line 683... | Line 678... | ||
683 | 678 | return -1; |
|
684 | pcibios_resource_to_bus(pdev, ®ion, res); |
679 | |
685 | pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr); |
680 | _pcibios_resource_to_bus(pdev, ®ion, res); |
686 | rom_addr &= ~PCI_ROM_ADDRESS_MASK; |
681 | pci_read_config_dword(pdev, pdev->rom_base_reg, &rom_addr); |
687 | rom_addr |= region.start | PCI_ROM_ADDRESS_ENABLE; |
682 | rom_addr &= ~PCI_ROM_ADDRESS_MASK; |
688 | pci_write_config_dword(pdev, pdev->rom_base_reg, rom_addr); |
683 | rom_addr |= region.start | PCI_ROM_ADDRESS_ENABLE; |
Line 815... | Line 810... | ||
815 | if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW))) |
810 | /* Disable again before continuing, leave enabled if pci=rom */ |
816 | pci_disable_rom(pdev); |
811 | if (!(res->flags & (IORESOURCE_ROM_ENABLE | IORESOURCE_ROM_SHADOW))) |
817 | } |
812 | pci_disable_rom(pdev); |
818 | 813 | } |
|
Line 819... | Line -... | ||
819 | #if 0 |
- | |
820 | void pcibios_set_master(struct pci_dev *dev) |
- | |
821 | { |
- | |
822 | u8 lat; |
- | |
823 | - | ||
824 | /* The latency timer doesn't apply to PCIe (either Type 0 or Type 1) */ |
- | |
825 | if (pci_is_pcie(dev)) |
- | |
826 | return; |
- | |
827 | - | ||
828 | pci_read_config_byte(dev, PCI_LATENCY_TIMER, &lat); |
- | |
829 | if (lat < 16) |
- | |
830 | lat = (64 <= pcibios_max_latency) ? 64 : pcibios_max_latency; |
- | |
831 | else if (lat > pcibios_max_latency) |
- | |
832 | lat = pcibios_max_latency; |
- | |
833 | else |
- | |
834 | return; |
- | |
835 | dev_printk(KERN_DEBUG, &dev->dev, "setting latency timer to %d\n", lat); |
- | |
836 | pci_write_config_byte(dev, PCI_LATENCY_TIMER, lat); |
- | |
837 | } |
- | |
838 | #endif |
- | |
839 | - | ||
840 | - | ||
841 | static void __pci_set_master(struct pci_dev *dev, bool enable) |
814 | |
842 | { |
815 | static void __pci_set_master(struct pci_dev *dev, bool enable) |
843 | u16 old_cmd, cmd; |
816 | { |
Line 844... | Line 817... | ||
844 | 817 | u16 old_cmd, cmd; |
|
Line 854... | Line 827... | ||
854 | } |
827 | pci_write_config_word(dev, PCI_COMMAND, cmd); |
855 | dev->is_busmaster = enable; |
828 | } |
856 | } |
829 | dev->is_busmaster = enable; |
857 | 830 | } |
|
Line -... | Line 831... | ||
- | 831 | ||
- | 832 | ||
- | 833 | /* pci_set_master - enables bus-mastering for device dev |
|
- | 834 | * @dev: the PCI device to enable |
|
- | 835 | * |
|
- | 836 | * Enables bus-mastering on the device and calls pcibios_set_master() |
|
- | 837 | * to do the needed arch specific settings. |
|
858 | void pci_set_master(struct pci_dev *dev) |
838 | */ |
859 | { |
839 | void pci_set_master(struct pci_dev *dev) |
860 | __pci_set_master(dev, true); |
840 | { |
861 | // pcibios_set_master(dev); |
841 | __pci_set_master(dev, true); |
862 | }=>>>=>>>><>><>><>>4)><4)> |
842 | // pcibios_set_master(dev); |
Line -... | Line 843... | ||
- | 843 | } |
|
- | 844 | ||
- | 845 | /** |
|
- | 846 | * pci_clear_master - disables bus-mastering for device dev |
|
- | 847 | * @dev: the PCI device to disable |
|
- | 848 | */ |
|
- | 849 | void pci_clear_master(struct pci_dev *dev) |
|
- | 850 | { |
|
- | 851 | __pci_set_master(dev, false); |
|
- | 852 | } |
|
- | 853 | ||
- | 854 | ||
- | 855 | static inline int pcie_cap_version(const struct pci_dev *dev) |
|
- | 856 | { |
|
- | 857 | return dev->pcie_flags_reg & PCI_EXP_FLAGS_VERS; |
|
- | 858 | } |
|
- | 859 | ||
- | 860 | static inline bool pcie_cap_has_devctl(const struct pci_dev *dev) |
|
- | 861 | { |
|
- | 862 | return true; |
|
- | 863 | } |
|
- | 864 | ||
- | 865 | static inline bool pcie_cap_has_lnkctl(const struct pci_dev *dev) |
|
- | 866 | { |
|
- | 867 | int type = pci_pcie_type(dev); |
|
- | 868 | ||
- | 869 | return pcie_cap_version(dev) > 1 || |
|
- | 870 | type == PCI_EXP_TYPE_ROOT_PORT || |
|
- | 871 | type == PCI_EXP_TYPE_ENDPOINT || |
|
- | 872 | type == PCI_EXP_TYPE_LEG_END; |
|
- | 873 | } |
|
- | 874 | ||
- | 875 | static inline bool pcie_cap_has_sltctl(const struct pci_dev *dev) |
|
- | 876 | { |
|
- | 877 | int type = pci_pcie_type(dev); |
|
- | 878 | ||
- | 879 | return pcie_cap_version(dev) > 1 || |
|
- | 880 | type == PCI_EXP_TYPE_ROOT_PORT || |
|
- | 881 | (type == PCI_EXP_TYPE_DOWNSTREAM && |
|
- | 882 | dev->pcie_flags_reg & PCI_EXP_FLAGS_SLOT); |
|
- | 883 | } |
|
- | 884 | ||
- | 885 | static inline bool pcie_cap_has_rtctl(const struct pci_dev *dev) |
|
- | 886 | { |
|
- | 887 | int type = pci_pcie_type(dev); |
|
- | 888 | ||
- | 889 | return pcie_cap_version(dev) > 1 || |
|
- | 890 | type == PCI_EXP_TYPE_ROOT_PORT || |
|
- | 891 | type == PCI_EXP_TYPE_RC_EC; |
|
- | 892 | } |
|
- | 893 | ||
- | 894 | static bool pcie_capability_reg_implemented(struct pci_dev *dev, int pos) |
|
- | 895 | { |
|
- | 896 | if (!pci_is_pcie(dev)) |
|
- | 897 | return false; |
|
- | 898 | ||
- | 899 | switch (pos) { |
|
- | 900 | case PCI_EXP_FLAGS_TYPE: |
|
- | 901 | return true; |
|
- | 902 | case PCI_EXP_DEVCAP: |
|
- | 903 | case PCI_EXP_DEVCTL: |
|
- | 904 | case PCI_EXP_DEVSTA: |
|
- | 905 | return pcie_cap_has_devctl(dev); |
|
- | 906 | case PCI_EXP_LNKCAP: |
|
- | 907 | case PCI_EXP_LNKCTL: |
|
- | 908 | case PCI_EXP_LNKSTA: |
|
- | 909 | return pcie_cap_has_lnkctl(dev); |
|
- | 910 | case PCI_EXP_SLTCAP: |
|
- | 911 | case PCI_EXP_SLTCTL: |
|
- | 912 | case PCI_EXP_SLTSTA: |
|
- | 913 | return pcie_cap_has_sltctl(dev); |
|
- | 914 | case PCI_EXP_RTCTL: |
|
- | 915 | case PCI_EXP_RTCAP: |
|
- | 916 | case PCI_EXP_RTSTA: |
|
- | 917 | return pcie_cap_has_rtctl(dev); |
|
- | 918 | case PCI_EXP_DEVCAP2: |
|
- | 919 | case PCI_EXP_DEVCTL2: |
|
- | 920 | case PCI_EXP_LNKCAP2: |
|
- | 921 | case PCI_EXP_LNKCTL2: |
|
- | 922 | case PCI_EXP_LNKSTA2: |
|
- | 923 | return pcie_cap_version(dev) > 1; |
|
- | 924 | default: |
|
- | 925 | return false; |
|
- | 926 | } |
|
- | 927 | } |
|
- | 928 | ||
- | 929 | /* |
|
- | 930 | * Note that these accessor functions are only for the "PCI Express |
|
- | 931 | * Capability" (see PCIe spec r3.0, sec 7.8). They do not apply to the |
|
- | 932 | * other "PCI Express Extended Capabilities" (AER, VC, ACS, MFVC, etc.) |
|
- | 933 | */ |
|
- | 934 | int pcie_capability_read_word(struct pci_dev *dev, int pos, u16 *val) |
|
- | 935 | { |
|
- | 936 | int ret; |
|
- | 937 | ||
- | 938 | *val = 0; |
|
- | 939 | if (pos & 1) |
|
- | 940 | return -EINVAL; |
|
- | 941 | ||
- | 942 | if (pcie_capability_reg_implemented(dev, pos)) { |
|
- | 943 | ret = pci_read_config_word(dev, pci_pcie_cap(dev) + pos, val); |
|
- | 944 | /* |
|
- | 945 | * Reset *val to 0 if pci_read_config_word() fails, it may |
|
- | 946 | * have been written as 0xFFFF if hardware error happens |
|
- | 947 | * during pci_read_config_word(). |
|
- | 948 | */ |
|
- | 949 | if (ret) |
|
- | 950 | *val = 0; |
|
- | 951 | return ret; |
|
- | 952 | } |
|
- | 953 | ||
- | 954 | /* |
|
- | 955 | * For Functions that do not implement the Slot Capabilities, |
|
- | 956 | * Slot Status, and Slot Control registers, these spaces must |
|
- | 957 | * be hardwired to 0b, with the exception of the Presence Detect |
|
- | 958 | * State bit in the Slot Status register of Downstream Ports, |
|
- | 959 | * which must be hardwired to 1b. (PCIe Base Spec 3.0, sec 7.8) |
|
- | 960 | */ |
|
- | 961 | if (pci_is_pcie(dev) && pos == PCI_EXP_SLTSTA && |
|
- | 962 | pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) { |
|
- | 963 | *val = PCI_EXP_SLTSTA_PDS; |
|
- | 964 | } |
|
- | 965 | ||
- | 966 | return 0; |
|
- | 967 | } |
|
- | 968 | EXPORT_SYMBOL(pcie_capability_read_word); |
|
- | 969 | ||
- | 970 | int pcie_capability_read_dword(struct pci_dev *dev, int pos, u32 *val) |
|
- | 971 | { |
|
- | 972 | int ret; |
|
- | 973 | ||
- | 974 | *val = 0; |
|
- | 975 | if (pos & 3) |
|
- | 976 | return -EINVAL; |
|
- | 977 | ||
- | 978 | if (pcie_capability_reg_implemented(dev, pos)) { |
|
- | 979 | ret = pci_read_config_dword(dev, pci_pcie_cap(dev) + pos, val); |
|
- | 980 | /* |
|
- | 981 | * Reset *val to 0 if pci_read_config_dword() fails, it may |
|
- | 982 | * have been written as 0xFFFFFFFF if hardware error happens |
|
- | 983 | * during pci_read_config_dword(). |
|
- | 984 | */ |
|
- | 985 | if (ret) |
|
- | 986 | *val = 0; |
|
- | 987 | return ret; |
|
- | 988 | } |
|
- | 989 | ||
- | 990 | if (pci_is_pcie(dev) && pos == PCI_EXP_SLTCTL && |
|
- | 991 | pci_pcie_type(dev) == PCI_EXP_TYPE_DOWNSTREAM) { |
|
- | 992 | *val = PCI_EXP_SLTSTA_PDS; |
|
- | 993 | } |
|
- | 994 | ||
- | 995 | return 0; |
|
- | 996 | } |
|
- | 997 | EXPORT_SYMBOL(pcie_capability_read_dword); |
|
- | 998 | ||
- | 999 | int pcie_capability_write_word(struct pci_dev *dev, int pos, u16 val) |
|
- | 1000 | { |
|
- | 1001 | if (pos & 1) |
|
- | 1002 | return -EINVAL; |
|
- | 1003 | ||
- | 1004 | if (!pcie_capability_reg_implemented(dev, pos)) |
|
- | 1005 | return 0; |
|
- | 1006 | ||
- | 1007 | return pci_write_config_word(dev, pci_pcie_cap(dev) + pos, val); |
|
- | 1008 | } |
|
- | 1009 | EXPORT_SYMBOL(pcie_capability_write_word); |
|
- | 1010 | ||
- | 1011 | int pcie_capability_write_dword(struct pci_dev *dev, int pos, u32 val) |
|
- | 1012 | { |
|
- | 1013 | if (pos & 3) |
|
- | 1014 | return -EINVAL; |
|
- | 1015 | ||
- | 1016 | if (!pcie_capability_reg_implemented(dev, pos)) |
|
- | 1017 | return 0; |
|
- | 1018 | ||
- | 1019 | return pci_write_config_dword(dev, pci_pcie_cap(dev) + pos, val); |
|
- | 1020 | } |
|
- | 1021 | EXPORT_SYMBOL(pcie_capability_write_dword); |
|
- | 1022 | ||
- | 1023 | int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos, |
|
- | 1024 | u16 clear, u16 set) |
|
- | 1025 | { |
|
- | 1026 | int ret; |
|
- | 1027 | u16 val; |
|
- | 1028 | ||
- | 1029 | ret = pcie_capability_read_word(dev, pos, &val); |
|
- | 1030 | if (!ret) { |
|
- | 1031 | val &= ~clear; |
|
- | 1032 | val |= set; |
|
- | 1033 | ret = pcie_capability_write_word(dev, pos, val); |
|
- | 1034 | } |
|
- | 1035 | ||
- | 1036 | return ret; |
|
- | 1037 | } |
|
Line -... | Line 1038... | ||
- | 1038 | ||
- | 1039 | ||
- | 1040 | ||
- | 1041 | int pcie_get_readrq(struct pci_dev *dev) |
|
- | 1042 | { |
|
- | 1043 | u16 ctl; |
|
- | 1044 | ||
- | 1045 | pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl); |
|
- | 1046 | ||
- | 1047 | return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12); |
|
- | 1048 | } |
|
- | 1049 | EXPORT_SYMBOL(pcie_get_readrq); |
|
- | 1050 | ||
- | 1051 | /** |
|
- | 1052 | * pcie_set_readrq - set PCI Express maximum memory read request |
|
- | 1053 | * @dev: PCI device to query |
|
- | 1054 | * @rq: maximum memory read count in bytes |
|
- | 1055 | * valid values are 128, 256, 512, 1024, 2048, 4096 |
|
- | 1056 | * |
|
- | 1057 | * If possible sets maximum memory read request in bytes |
|
- | 1058 | */ |
|
- | 1059 | int pcie_set_readrq(struct pci_dev *dev, int rq) |
|
- | 1060 | { |
|
- | 1061 | u16 v; |
|
- | 1062 | ||
- | 1063 | if (rq < 128 || rq > 4096 || !is_power_of_2(rq)) |
|
- | 1064 | return -EINVAL; |
|
- | 1065 | ||
- | 1066 | v = (ffs(rq) - 8) << 12; |
|
- | 1067 |