diff options
Diffstat (limited to 'arch/x86_64/pci/mmconfig.c')
-rw-r--r-- | arch/x86_64/pci/mmconfig.c | 63 |
1 files changed, 53 insertions, 10 deletions
diff --git a/arch/x86_64/pci/mmconfig.c b/arch/x86_64/pci/mmconfig.c index a0838c4a94e4..9c4f907e301c 100644 --- a/arch/x86_64/pci/mmconfig.c +++ b/arch/x86_64/pci/mmconfig.c | |||
@@ -8,10 +8,13 @@ | |||
8 | #include <linux/pci.h> | 8 | #include <linux/pci.h> |
9 | #include <linux/init.h> | 9 | #include <linux/init.h> |
10 | #include <linux/acpi.h> | 10 | #include <linux/acpi.h> |
11 | #include <linux/bitmap.h> | ||
11 | #include "pci.h" | 12 | #include "pci.h" |
12 | 13 | ||
13 | #define MMCONFIG_APER_SIZE (256*1024*1024) | 14 | #define MMCONFIG_APER_SIZE (256*1024*1024) |
14 | 15 | ||
16 | static DECLARE_BITMAP(fallback_slots, 32); | ||
17 | |||
15 | /* Static virtual mapping of the MMCONFIG aperture */ | 18 | /* Static virtual mapping of the MMCONFIG aperture */ |
16 | struct mmcfg_virt { | 19 | struct mmcfg_virt { |
17 | struct acpi_table_mcfg_config *cfg; | 20 | struct acpi_table_mcfg_config *cfg; |
@@ -19,7 +22,7 @@ struct mmcfg_virt { | |||
19 | }; | 22 | }; |
20 | static struct mmcfg_virt *pci_mmcfg_virt; | 23 | static struct mmcfg_virt *pci_mmcfg_virt; |
21 | 24 | ||
22 | static char *get_virt(unsigned int seg, int bus) | 25 | static char *get_virt(unsigned int seg, unsigned bus) |
23 | { | 26 | { |
24 | int cfg_num = -1; | 27 | int cfg_num = -1; |
25 | struct acpi_table_mcfg_config *cfg; | 28 | struct acpi_table_mcfg_config *cfg; |
@@ -27,10 +30,9 @@ static char *get_virt(unsigned int seg, int bus) | |||
27 | while (1) { | 30 | while (1) { |
28 | ++cfg_num; | 31 | ++cfg_num; |
29 | if (cfg_num >= pci_mmcfg_config_num) { | 32 | if (cfg_num >= pci_mmcfg_config_num) { |
30 | /* something bad is going on, no cfg table is found. */ | 33 | /* Not found - fall back to type 1. This happens |
31 | /* so we fall back to the old way we used to do this */ | 34 | e.g. on the internal devices of a K8 northbridge. */ |
32 | /* and just rely on the first entry to be correct. */ | 35 | return NULL; |
33 | return pci_mmcfg_virt[0].virt; | ||
34 | } | 36 | } |
35 | cfg = pci_mmcfg_virt[cfg_num].cfg; | 37 | cfg = pci_mmcfg_virt[cfg_num].cfg; |
36 | if (cfg->pci_segment_group_number != seg) | 38 | if (cfg->pci_segment_group_number != seg) |
@@ -41,20 +43,30 @@ static char *get_virt(unsigned int seg, int bus) | |||
41 | } | 43 | } |
42 | } | 44 | } |
43 | 45 | ||
44 | static inline char *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) | 46 | static char *pci_dev_base(unsigned int seg, unsigned int bus, unsigned int devfn) |
45 | { | 47 | { |
46 | 48 | char *addr; | |
47 | return get_virt(seg, bus) + ((bus << 20) | (devfn << 12)); | 49 | if (seg == 0 && bus == 0 && test_bit(PCI_SLOT(devfn), &fallback_slots)) |
50 | return NULL; | ||
51 | addr = get_virt(seg, bus); | ||
52 | if (!addr) | ||
53 | return NULL; | ||
54 | return addr + ((bus << 20) | (devfn << 12)); | ||
48 | } | 55 | } |
49 | 56 | ||
50 | static int pci_mmcfg_read(unsigned int seg, unsigned int bus, | 57 | static int pci_mmcfg_read(unsigned int seg, unsigned int bus, |
51 | unsigned int devfn, int reg, int len, u32 *value) | 58 | unsigned int devfn, int reg, int len, u32 *value) |
52 | { | 59 | { |
53 | char *addr = pci_dev_base(seg, bus, devfn); | 60 | char *addr; |
54 | 61 | ||
62 | /* Why do we have this when nobody checks it. How about a BUG()!? -AK */ | ||
55 | if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095))) | 63 | if (unlikely(!value || (bus > 255) || (devfn > 255) || (reg > 4095))) |
56 | return -EINVAL; | 64 | return -EINVAL; |
57 | 65 | ||
66 | addr = pci_dev_base(seg, bus, devfn); | ||
67 | if (!addr) | ||
68 | return pci_conf1_read(seg,bus,devfn,reg,len,value); | ||
69 | |||
58 | switch (len) { | 70 | switch (len) { |
59 | case 1: | 71 | case 1: |
60 | *value = readb(addr + reg); | 72 | *value = readb(addr + reg); |
@@ -73,11 +85,16 @@ static int pci_mmcfg_read(unsigned int seg, unsigned int bus, | |||
73 | static int pci_mmcfg_write(unsigned int seg, unsigned int bus, | 85 | static int pci_mmcfg_write(unsigned int seg, unsigned int bus, |
74 | unsigned int devfn, int reg, int len, u32 value) | 86 | unsigned int devfn, int reg, int len, u32 value) |
75 | { | 87 | { |
76 | char *addr = pci_dev_base(seg, bus, devfn); | 88 | char *addr; |
77 | 89 | ||
90 | /* Why do we have this when nobody checks it. How about a BUG()!? -AK */ | ||
78 | if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) | 91 | if (unlikely((bus > 255) || (devfn > 255) || (reg > 4095))) |
79 | return -EINVAL; | 92 | return -EINVAL; |
80 | 93 | ||
94 | addr = pci_dev_base(seg, bus, devfn); | ||
95 | if (!addr) | ||
96 | return pci_conf1_write(seg,bus,devfn,reg,len,value); | ||
97 | |||
81 | switch (len) { | 98 | switch (len) { |
82 | case 1: | 99 | case 1: |
83 | writeb(value, addr + reg); | 100 | writeb(value, addr + reg); |
@@ -98,6 +115,30 @@ static struct pci_raw_ops pci_mmcfg = { | |||
98 | .write = pci_mmcfg_write, | 115 | .write = pci_mmcfg_write, |
99 | }; | 116 | }; |
100 | 117 | ||
118 | /* K8 systems have some devices (typically in the builtin northbridge) | ||
119 | that are only accessible using type1 | ||
120 | Normally this can be expressed in the MCFG by not listing them | ||
121 | and assigning suitable _SEGs, but this isn't implemented in some BIOS. | ||
122 | Instead try to discover all devices on bus 0 that are unreachable using MM | ||
123 | and fallback for them. | ||
124 | We only do this for bus 0/seg 0 */ | ||
125 | static __init void unreachable_devices(void) | ||
126 | { | ||
127 | int i; | ||
128 | for (i = 0; i < 32; i++) { | ||
129 | u32 val1; | ||
130 | char *addr; | ||
131 | |||
132 | pci_conf1_read(0, 0, PCI_DEVFN(i,0), 0, 4, &val1); | ||
133 | if (val1 == 0xffffffff) | ||
134 | continue; | ||
135 | addr = pci_dev_base(0, 0, PCI_DEVFN(i, 0)); | ||
136 | if (addr == NULL|| readl(addr) != val1) { | ||
137 | set_bit(i, &fallback_slots); | ||
138 | } | ||
139 | } | ||
140 | } | ||
141 | |||
101 | static int __init pci_mmcfg_init(void) | 142 | static int __init pci_mmcfg_init(void) |
102 | { | 143 | { |
103 | int i; | 144 | int i; |
@@ -128,6 +169,8 @@ static int __init pci_mmcfg_init(void) | |||
128 | printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address); | 169 | printk(KERN_INFO "PCI: Using MMCONFIG at %x\n", pci_mmcfg_config[i].base_address); |
129 | } | 170 | } |
130 | 171 | ||
172 | unreachable_devices(); | ||
173 | |||
131 | raw_pci_ops = &pci_mmcfg; | 174 | raw_pci_ops = &pci_mmcfg; |
132 | pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; | 175 | pci_probe = (pci_probe & ~PCI_PROBE_MASK) | PCI_PROBE_MMCONF; |
133 | 176 | ||