Subversion Repositories Kolibri OS

Rev

Rev 3764 | Rev 5271 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3764 Rev 5078
Line 6... Line 6...
6
#include 
6
#include 
7
#include 
7
#include 
8
#include 
8
#include 
9
 
9
 
Line -... Line 10...
-
 
10
static inline __attribute__((const))
-
 
11
bool is_power_of_2(unsigned long n)
-
 
12
{
-
 
13
    return (n != 0 && ((n & (n - 1)) == 0));
-
 
14
}
-
 
15
 
10
extern int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn);
16
extern int pci_scan_filter(u32_t id, u32_t busnr, u32_t devfn);
Line 11... Line 17...
11
 
17
 
Line 12... Line 18...
12
static LIST_HEAD(devices);
18
static LIST_HEAD(devices);
Line 1049... Line 1055...
1049
    return pci_write_config_dword(dev, pci_pcie_cap(dev) + pos, val);
1055
    return pci_write_config_dword(dev, pci_pcie_cap(dev) + pos, val);
1050
}
1056
}
1051
EXPORT_SYMBOL(pcie_capability_write_dword);
1057
EXPORT_SYMBOL(pcie_capability_write_dword);
Line -... Line 1058...
-
 
1058
 
-
 
1059
int pcie_capability_clear_and_set_word(struct pci_dev *dev, int pos,
-
 
1060
                                       u16 clear, u16 set)
-
 
1061
{
-
 
1062
        int ret;
-
 
1063
        u16 val;
-
 
1064
 
-
 
1065
        ret = pcie_capability_read_word(dev, pos, &val);
-
 
1066
        if (!ret) {
-
 
1067
                val &= ~clear;
-
 
1068
                val |= set;
-
 
1069
                ret = pcie_capability_write_word(dev, pos, val);
-
 
1070
        }
-
 
1071
 
-
 
1072
        return ret;
-
 
1073
}
-
 
1074
 
-
 
1075
 
-
 
1076
 
-
 
1077
int pcie_get_readrq(struct pci_dev *dev)
-
 
1078
{
-
 
1079
        u16 ctl;
-
 
1080
 
-
 
1081
        pcie_capability_read_word(dev, PCI_EXP_DEVCTL, &ctl);
-
 
1082
 
-
 
1083
        return 128 << ((ctl & PCI_EXP_DEVCTL_READRQ) >> 12);
-
 
1084
}
-
 
1085
EXPORT_SYMBOL(pcie_get_readrq);
-
 
1086
 
-
 
1087
/**
-
 
1088
 * pcie_set_readrq - set PCI Express maximum memory read request
-
 
1089
 * @dev: PCI device to query
-
 
1090
 * @rq: maximum memory read count in bytes
-
 
1091
 *    valid values are 128, 256, 512, 1024, 2048, 4096
-
 
1092
 *
-
 
1093
 * If possible sets maximum memory read request in bytes
-
 
1094
 */
-
 
1095
int pcie_set_readrq(struct pci_dev *dev, int rq)
-
 
1096
{
-
 
1097
        u16 v;
-
 
1098
 
-
 
1099
        if (rq < 128 || rq > 4096 || !is_power_of_2(rq))
-
 
1100
                return -EINVAL;
-
 
1101
 
-
 
1102
        v = (ffs(rq) - 8) << 12;
-
 
1103
 
-
 
1104
        return pcie_capability_clear_and_set_word(dev, PCI_EXP_DEVCTL,
-
 
1105
                                                  PCI_EXP_DEVCTL_READRQ, v);
-
 
1106
}