aboutsummaryrefslogtreecommitdiffstats
path: root/arch/i386/pci/mmconfig.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/i386/pci/mmconfig.c')
-rw-r--r--arch/i386/pci/mmconfig.c65
1 files changed, 56 insertions, 9 deletions
diff --git a/arch/i386/pci/mmconfig.c b/arch/i386/pci/mmconfig.c
index dfbf80cff834..4bb4d4b0f73a 100644
--- a/arch/i386/pci/mmconfig.c
+++ b/arch/i386/pci/mmconfig.c
@@ -19,21 +19,25 @@
19/* The base address of the last MMCONFIG device accessed */ 19/* The base address of the last MMCONFIG device accessed */
20static u32 mmcfg_last_accessed_device; 20static u32 mmcfg_last_accessed_device;
21 21
22static DECLARE_BITMAP(fallback_slots, 32);
23
22/* 24/*
23 * Functions for accessing PCI configuration space with MMCONFIG accesses 25 * Functions for accessing PCI configuration space with MMCONFIG accesses
24 */ 26 */
25static u32 get_base_addr(unsigned int seg, int bus) 27static u32 get_base_addr(unsigned int seg, int bus, unsigned devfn)
26{ 28{
27 int cfg_num = -1; 29 int cfg_num = -1;
28 struct acpi_table_mcfg_config *cfg; 30 struct acpi_table_mcfg_config *cfg;
29 31
32 if (seg == 0 && bus == 0 &&
33 test_bit(PCI_SLOT(devfn), fallback_slots))
34 return 0;
35
30 while (1) { 36 while (1) {
31 ++cfg_num; 37 ++cfg_num;
32 if (cfg_num >= pci_mmcfg_config_num) { 38 if (cfg_num >= pci_mmcfg_config_num) {
33 /* something bad is going on, no cfg table is found. */ 39 /* Not found - fallback to type 1 */
34 /* so we fall back to the old way we used to do this */ 40 return 0;
35 /* and just rely on the first entry to be correct. */
36 return pci_mmcfg_config[0].base_address;
37 } 41 }
38 cfg = &pci_mmcfg_config[cfg_num]; 42 cfg = &pci_mmcfg_config[cfg_num];
39 if (cfg->pci_segment_group_number != seg) 43 if (cfg->pci_segment_group_number != seg)
@@ -44,9 +48,9 @@ static u32 get_base_addr(unsigned int seg, int bus)
44 } 48 }
45} 49}
46 50
47static inline void pci_exp_set_dev_base(unsigned int seg, int bus, int devfn) 51static inline void pci_exp_set_dev_base(unsigned int base, int bus, int devfn)
48{ 52{
49 u32 dev_base = get_base_addr(seg, bus) | (bus << 20) | (devfn << 12); 53 u32 dev_base = base | (bus << 20) | (devfn << 12);
50 if (dev_base != mmcfg_last_accessed_device) { 54 if (dev_base != mmcfg_last_accessed_device) {
51 mmcfg_last_accessed_device = dev_base; 55 mmcfg_last_accessed_device = dev_base;
52 set_fixmap_nocache(FIX_PCIE_MCFG, dev_base); 56 set_fixmap_nocache(FIX_PCIE_MCFG, dev_base);
@@ -57,13 +61,18 @@ static int pci_mmcfg_read(unsigned int seg, unsigned int bus,
57 unsigned int devfn, int reg, int len, u32 *value) 61 unsigned int devfn, int reg, int len, u32 *value)
58{ 62{
59 unsigned long flags; 63 unsigned long flags;
64 u32 base;
60 65
61 if (!value || (bus > 255) || (devfn > 255) || (reg > 4095)) 66 if (!value || (bus > 255) || (devfn > 255) || (reg > 4095))
62 return -EINVAL; 67 return -EINVAL;
63 68
69 base = get_base_addr(seg, bus, devfn);
70 if (!base)
71 return pci_conf1_read(seg,bus,devfn,reg,len,value);
72
64 spin_lock_irqsave(&pci_config_lock, flags); 73 spin_lock_irqsave(&pci_config_lock, flags);
65 74
66 pci_exp_set_dev_base(seg, bus, devfn); 75 pci_exp_set_dev_base(base, bus, devfn);
67 76
68 switch (len) { 77 switch (len) {
69 case 1: 78 case 1:
@@ -86,13 +95,18 @@ static int pci_mmcfg_write(unsigned int seg, unsigned int bus,
86 unsigned int devfn, int reg, int len, u32 value) 95 unsigned int devfn, int reg, int len, u32 value)
87{ 96{
88 unsigned long flags; 97 unsigned long flags;
98 u32 base;
89 99
90 if ((bus > 255) || (devfn > 255) || (reg > 4095)) 100 if ((bus > 255) || (devfn > 255) || (reg > 4095))
91 return -EINVAL; 101 return -EINVAL;
92 102
103 base = get_base_addr(seg, bus, devfn);
104 if (!base)
105 return pci_conf1_write(seg,bus,devfn,reg,len,value);
106
93 spin_lock_irqsave(&pci_config_lock, flags); 107 spin_lock_irqsave(&pci_config_lock, flags);
94 108
95 pci_exp_set_dev_base(seg, bus, devfn); 109 pci_exp_set_dev_base(base, bus, devfn);
96 110
97 switch (len) { 111 switch (len) {
98 case 1: 112 case 1:
@@ -116,6 +130,37 @@ static struct pci_raw_ops pci_mmcfg = {
116 .write = pci_mmcfg_write, 130 .write = pci_mmcfg_write,
117}; 131};
118 132
133/* K8 systems have some devices (typically in the builtin northbridge)
134 that are only accessible using type1
135 Normally this can be expressed in the MCFG by not listing them
136 and assigning suitable _SEGs, but this isn't implemented in some BIOS.
137 Instead try to discover all devices on bus 0 that are unreachable using MM
138 and fallback for them.
139 We only do this for bus 0/seg 0 */
140static __init void unreachable_devices(void)
141{
142 int i;
143 unsigned long flags;
144
145 for (i = 0; i < 32; i++) {
146 u32 val1;
147 u32 addr;
148
149 pci_conf1_read(0, 0, PCI_DEVFN(i, 0), 0, 4, &val1);
150 if (val1 == 0xffffffff)
151 continue;
152
153 /* Locking probably not needed, but safer */
154 spin_lock_irqsave(&pci_config_lock, flags);
155 addr = get_base_addr(0, 0, PCI_DEVFN(i, 0));
156 if (addr != 0)
157 pci_exp_set_dev_base(addr, 0, PCI_DEVFN(i, 0));
158 if (addr == 0 || readl((u32 __iomem *)mmcfg_virt_addr) != val1)
159 set_bit(i, fallback_slots);
160 spin_unlock_irqrestore(&pci_config_lock, flags);
161 }
162}
163
119static int __init pci_mmcfg_init(void) 164static int __init pci_mmcfg_init(void)
120{ 165{
121 if ((pci_probe & PCI_PROBE_MMCONF) == 0) 166 if ((pci_probe & PCI_PROBE_MMCONF) == 0)
@@ -131,6 +176,8 @@ static int __init pci_mmcfg_init(void)
131 raw_pci_ops = &pci_mmcfg; 176 raw_pci_ops = &pci_mmcfg;
132 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; 177 pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF;
133 178
179 unreachable_devices();
180
134 out: 181 out:
135 return 0; 182 return 0;
136} 183}