Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/init.h> |
| 2 | #include <linux/pci.h> |
Robert Richter | d199a04 | 2008-07-02 22:50:26 +0200 | [diff] [blame] | 3 | #include <linux/topology.h> |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 4 | #include <linux/cpu.h> |
Yinghai Lu | 27811d8 | 2010-02-10 01:20:07 -0800 | [diff] [blame] | 5 | #include <linux/range.h> |
| 6 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 7 | #include <asm/amd_nb.h> |
Jaswinder Singh Rajput | 8248771 | 2008-12-27 18:32:28 +0530 | [diff] [blame] | 8 | #include <asm/pci_x86.h> |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 9 | |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 10 | #include <asm/pci-direct.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 11 | |
Yinghai Lu | 99935a7 | 2009-10-04 21:54:24 -0700 | [diff] [blame] | 12 | #include "bus_numa.h" |
| 13 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | /* |
| 15 | * This discovers the pcibus <-> node mapping on AMD K8. |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 16 | * also get peer root bus resource for io,mmio |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | */ |
| 18 | |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 19 | struct pci_hostbridge_probe { |
| 20 | u32 bus; |
| 21 | u32 slot; |
| 22 | u32 vendor; |
| 23 | u32 device; |
| 24 | }; |
| 25 | |
| 26 | static struct pci_hostbridge_probe pci_probes[] __initdata = { |
| 27 | { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1100 }, |
| 28 | { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 }, |
| 29 | { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 }, |
| 30 | { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1300 }, |
| 31 | }; |
| 32 | |
Yinghai Lu | 27811d8 | 2010-02-10 01:20:07 -0800 | [diff] [blame] | 33 | #define RANGE_NUM 16 |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /** |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 36 | * early_fill_mp_bus_to_node() |
| 37 | * called before pcibios_scan_root and pci_scan_bus |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | * fills the mp_bus_to_cpumask array based according to the LDT Bus Number |
| 39 | * Registers found in the K8 northbridge |
| 40 | */ |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 41 | static int __init early_fill_mp_bus_info(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | { |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 43 | int i; |
| 44 | int j; |
| 45 | unsigned bus; |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 46 | unsigned slot; |
Yinghai Lu | 35ddd06 | 2008-02-19 03:15:08 -0800 | [diff] [blame] | 47 | int node; |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 48 | int link; |
| 49 | int def_node; |
| 50 | int def_link; |
| 51 | struct pci_root_info *info; |
| 52 | u32 reg; |
| 53 | struct resource *res; |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 54 | u64 start; |
| 55 | u64 end; |
Yinghai Lu | 27811d8 | 2010-02-10 01:20:07 -0800 | [diff] [blame] | 56 | struct range range[RANGE_NUM]; |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 57 | u64 val; |
| 58 | u32 address; |
Yinghai Lu | 3e3da00 | 2010-02-10 01:20:09 -0800 | [diff] [blame] | 59 | bool found; |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 60 | struct resource fam10h_mmconf_res, *fam10h_mmconf; |
| 61 | u64 fam10h_mmconf_start; |
| 62 | u64 fam10h_mmconf_end; |
Yinghai Lu | 35ddd06 | 2008-02-19 03:15:08 -0800 | [diff] [blame] | 63 | |
Yinghai Lu | 871d5f8 | 2008-02-19 03:20:09 -0800 | [diff] [blame] | 64 | if (!early_pci_allowed()) |
| 65 | return -1; |
| 66 | |
Yinghai Lu | 3e3da00 | 2010-02-10 01:20:09 -0800 | [diff] [blame] | 67 | found = false; |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 68 | for (i = 0; i < ARRAY_SIZE(pci_probes); i++) { |
| 69 | u32 id; |
| 70 | u16 device; |
| 71 | u16 vendor; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 73 | bus = pci_probes[i].bus; |
| 74 | slot = pci_probes[i].slot; |
| 75 | id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID); |
Yinghai Lu | 35ddd06 | 2008-02-19 03:15:08 -0800 | [diff] [blame] | 76 | |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 77 | vendor = id & 0xffff; |
| 78 | device = (id>>16) & 0xffff; |
| 79 | if (pci_probes[i].vendor == vendor && |
| 80 | pci_probes[i].device == device) { |
Yinghai Lu | 3e3da00 | 2010-02-10 01:20:09 -0800 | [diff] [blame] | 81 | found = true; |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 82 | break; |
| 83 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | } |
| 85 | |
Yinghai Lu | 3e3da00 | 2010-02-10 01:20:09 -0800 | [diff] [blame] | 86 | if (!found) |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 87 | return 0; |
| 88 | |
| 89 | pci_root_num = 0; |
| 90 | for (i = 0; i < 4; i++) { |
| 91 | int min_bus; |
| 92 | int max_bus; |
| 93 | reg = read_pci_config(bus, slot, 1, 0xe0 + (i << 2)); |
| 94 | |
| 95 | /* Check if that register is enabled for bus range */ |
| 96 | if ((reg & 7) != 3) |
| 97 | continue; |
| 98 | |
| 99 | min_bus = (reg >> 16) & 0xff; |
| 100 | max_bus = (reg >> 24) & 0xff; |
| 101 | node = (reg >> 4) & 0x07; |
| 102 | #ifdef CONFIG_NUMA |
| 103 | for (j = min_bus; j <= max_bus; j++) |
Jesse Barnes | 2547089 | 2009-07-10 14:04:30 -0700 | [diff] [blame] | 104 | set_mp_bus_to_node(j, node); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 105 | #endif |
| 106 | link = (reg >> 8) & 0x03; |
| 107 | |
| 108 | info = &pci_root_info[pci_root_num]; |
| 109 | info->bus_min = min_bus; |
| 110 | info->bus_max = max_bus; |
| 111 | info->node = node; |
| 112 | info->link = link; |
| 113 | sprintf(info->name, "PCI Bus #%02x", min_bus); |
| 114 | pci_root_num++; |
| 115 | } |
| 116 | |
| 117 | /* get the default node and link for left over res */ |
| 118 | reg = read_pci_config(bus, slot, 0, 0x60); |
| 119 | def_node = (reg >> 8) & 0x07; |
| 120 | reg = read_pci_config(bus, slot, 0, 0x64); |
| 121 | def_link = (reg >> 8) & 0x03; |
| 122 | |
| 123 | memset(range, 0, sizeof(range)); |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 124 | add_range(range, RANGE_NUM, 0, 0, 0xffff + 1); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 125 | /* io port resource */ |
| 126 | for (i = 0; i < 4; i++) { |
| 127 | reg = read_pci_config(bus, slot, 1, 0xc0 + (i << 3)); |
| 128 | if (!(reg & 3)) |
| 129 | continue; |
| 130 | |
| 131 | start = reg & 0xfff000; |
| 132 | reg = read_pci_config(bus, slot, 1, 0xc4 + (i << 3)); |
| 133 | node = reg & 0x07; |
| 134 | link = (reg >> 4) & 0x03; |
| 135 | end = (reg & 0xfff000) | 0xfff; |
| 136 | |
| 137 | /* find the position */ |
| 138 | for (j = 0; j < pci_root_num; j++) { |
| 139 | info = &pci_root_info[j]; |
| 140 | if (info->node == node && info->link == link) |
| 141 | break; |
| 142 | } |
| 143 | if (j == pci_root_num) |
| 144 | continue; /* not found */ |
| 145 | |
| 146 | info = &pci_root_info[j]; |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 147 | printk(KERN_DEBUG "node %d link %d: io port [%llx, %llx]\n", |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 148 | node, link, start, end); |
Yinghai Lu | e8ee6f0 | 2008-04-13 01:41:58 -0700 | [diff] [blame] | 149 | |
| 150 | /* kernel only handle 16 bit only */ |
| 151 | if (end > 0xffff) |
| 152 | end = 0xffff; |
| 153 | update_res(info, start, end, IORESOURCE_IO, 1); |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 154 | subtract_range(range, RANGE_NUM, start, end + 1); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 155 | } |
| 156 | /* add left over io port range to def node/link, [0, 0xffff] */ |
| 157 | /* find the position */ |
| 158 | for (j = 0; j < pci_root_num; j++) { |
| 159 | info = &pci_root_info[j]; |
| 160 | if (info->node == def_node && info->link == def_link) |
| 161 | break; |
| 162 | } |
| 163 | if (j < pci_root_num) { |
| 164 | info = &pci_root_info[j]; |
| 165 | for (i = 0; i < RANGE_NUM; i++) { |
| 166 | if (!range[i].end) |
| 167 | continue; |
| 168 | |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 169 | update_res(info, range[i].start, range[i].end - 1, |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 170 | IORESOURCE_IO, 1); |
| 171 | } |
| 172 | } |
| 173 | |
| 174 | memset(range, 0, sizeof(range)); |
| 175 | /* 0xfd00000000-0xffffffffff for HT */ |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 176 | end = cap_resource((0xfdULL<<32) - 1); |
| 177 | end++; |
| 178 | add_range(range, RANGE_NUM, 0, 0, end); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 179 | |
| 180 | /* need to take out [0, TOM) for RAM*/ |
| 181 | address = MSR_K8_TOP_MEM1; |
| 182 | rdmsrl(address, val); |
Yinghai Lu | 8004dd9 | 2008-05-12 17:40:39 -0700 | [diff] [blame] | 183 | end = (val & 0xffffff800000ULL); |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 184 | printk(KERN_INFO "TOM: %016llx aka %lldM\n", end, end>>20); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 185 | if (end < (1ULL<<32)) |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 186 | subtract_range(range, RANGE_NUM, 0, end); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 187 | |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 188 | /* get mmconfig */ |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 189 | fam10h_mmconf = amd_get_mmconfig_range(&fam10h_mmconf_res); |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 190 | /* need to take out mmconf range */ |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 191 | if (fam10h_mmconf) { |
| 192 | printk(KERN_DEBUG "Fam 10h mmconf %pR\n", fam10h_mmconf); |
| 193 | fam10h_mmconf_start = fam10h_mmconf->start; |
| 194 | fam10h_mmconf_end = fam10h_mmconf->end; |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 195 | subtract_range(range, RANGE_NUM, fam10h_mmconf_start, |
| 196 | fam10h_mmconf_end + 1); |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 197 | } else { |
| 198 | fam10h_mmconf_start = 0; |
| 199 | fam10h_mmconf_end = 0; |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 200 | } |
| 201 | |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 202 | /* mmio resource */ |
| 203 | for (i = 0; i < 8; i++) { |
| 204 | reg = read_pci_config(bus, slot, 1, 0x80 + (i << 3)); |
| 205 | if (!(reg & 3)) |
| 206 | continue; |
| 207 | |
| 208 | start = reg & 0xffffff00; /* 39:16 on 31:8*/ |
| 209 | start <<= 8; |
| 210 | reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3)); |
| 211 | node = reg & 0x07; |
| 212 | link = (reg >> 4) & 0x03; |
| 213 | end = (reg & 0xffffff00); |
| 214 | end <<= 8; |
| 215 | end |= 0xffff; |
| 216 | |
| 217 | /* find the position */ |
| 218 | for (j = 0; j < pci_root_num; j++) { |
| 219 | info = &pci_root_info[j]; |
| 220 | if (info->node == node && info->link == link) |
| 221 | break; |
| 222 | } |
| 223 | if (j == pci_root_num) |
| 224 | continue; /* not found */ |
| 225 | |
| 226 | info = &pci_root_info[j]; |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 227 | |
| 228 | printk(KERN_DEBUG "node %d link %d: mmio [%llx, %llx]", |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 229 | node, link, start, end); |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 230 | /* |
| 231 | * some sick allocation would have range overlap with fam10h |
| 232 | * mmconf range, so need to update start and end. |
| 233 | */ |
| 234 | if (fam10h_mmconf_end) { |
| 235 | int changed = 0; |
| 236 | u64 endx = 0; |
| 237 | if (start >= fam10h_mmconf_start && |
| 238 | start <= fam10h_mmconf_end) { |
| 239 | start = fam10h_mmconf_end + 1; |
| 240 | changed = 1; |
| 241 | } |
| 242 | |
| 243 | if (end >= fam10h_mmconf_start && |
| 244 | end <= fam10h_mmconf_end) { |
| 245 | end = fam10h_mmconf_start - 1; |
| 246 | changed = 1; |
| 247 | } |
| 248 | |
| 249 | if (start < fam10h_mmconf_start && |
| 250 | end > fam10h_mmconf_end) { |
| 251 | /* we got a hole */ |
| 252 | endx = fam10h_mmconf_start - 1; |
| 253 | update_res(info, start, endx, IORESOURCE_MEM, 0); |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 254 | subtract_range(range, RANGE_NUM, start, |
| 255 | endx + 1); |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 256 | printk(KERN_CONT " ==> [%llx, %llx]", start, endx); |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 257 | start = fam10h_mmconf_end + 1; |
| 258 | changed = 1; |
| 259 | } |
| 260 | if (changed) { |
| 261 | if (start <= end) { |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 262 | printk(KERN_CONT " %s [%llx, %llx]", endx ? "and" : "==>", start, end); |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 263 | } else { |
| 264 | printk(KERN_CONT "%s\n", endx?"":" ==> none"); |
| 265 | continue; |
| 266 | } |
| 267 | } |
| 268 | } |
| 269 | |
Yinghai Lu | 9ad3f2c | 2010-02-10 01:20:11 -0800 | [diff] [blame] | 270 | update_res(info, cap_resource(start), cap_resource(end), |
| 271 | IORESOURCE_MEM, 1); |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 272 | subtract_range(range, RANGE_NUM, start, end + 1); |
Yinghai Lu | 6e184f2 | 2008-03-06 01:15:31 -0800 | [diff] [blame] | 273 | printk(KERN_CONT "\n"); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* need to take out [4G, TOM2) for RAM*/ |
| 277 | /* SYS_CFG */ |
| 278 | address = MSR_K8_SYSCFG; |
| 279 | rdmsrl(address, val); |
| 280 | /* TOP_MEM2 is enabled? */ |
| 281 | if (val & (1<<21)) { |
| 282 | /* TOP_MEM2 */ |
| 283 | address = MSR_K8_TOP_MEM2; |
| 284 | rdmsrl(address, val); |
Yinghai Lu | 8004dd9 | 2008-05-12 17:40:39 -0700 | [diff] [blame] | 285 | end = (val & 0xffffff800000ULL); |
Yinghai Lu | 97445c3 | 2010-02-10 01:20:10 -0800 | [diff] [blame] | 286 | printk(KERN_INFO "TOM2: %016llx aka %lldM\n", end, end>>20); |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 287 | subtract_range(range, RANGE_NUM, 1ULL<<32, end); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 288 | } |
| 289 | |
| 290 | /* |
| 291 | * add left over mmio range to def node/link ? |
| 292 | * that is tricky, just record range in from start_min to 4G |
| 293 | */ |
| 294 | for (j = 0; j < pci_root_num; j++) { |
| 295 | info = &pci_root_info[j]; |
| 296 | if (info->node == def_node && info->link == def_link) |
| 297 | break; |
| 298 | } |
| 299 | if (j < pci_root_num) { |
| 300 | info = &pci_root_info[j]; |
| 301 | |
| 302 | for (i = 0; i < RANGE_NUM; i++) { |
| 303 | if (!range[i].end) |
| 304 | continue; |
| 305 | |
Yinghai Lu | 9ad3f2c | 2010-02-10 01:20:11 -0800 | [diff] [blame] | 306 | update_res(info, cap_resource(range[i].start), |
Yinghai Lu | e9a0064 | 2010-02-10 01:20:13 -0800 | [diff] [blame] | 307 | cap_resource(range[i].end - 1), |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 308 | IORESOURCE_MEM, 1); |
| 309 | } |
| 310 | } |
| 311 | |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 312 | for (i = 0; i < pci_root_num; i++) { |
| 313 | int res_num; |
| 314 | int busnum; |
| 315 | |
| 316 | info = &pci_root_info[i]; |
| 317 | res_num = info->res_num; |
| 318 | busnum = info->bus_min; |
Yinghai Lu | 99935a7 | 2009-10-04 21:54:24 -0700 | [diff] [blame] | 319 | printk(KERN_DEBUG "bus: [%02x, %02x] on node %x link %x\n", |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 320 | info->bus_min, info->bus_max, info->node, info->link); |
| 321 | for (j = 0; j < res_num; j++) { |
| 322 | res = &info->res[j]; |
Yinghai Lu | 284f933 | 2010-02-10 01:20:12 -0800 | [diff] [blame] | 323 | printk(KERN_DEBUG "bus: %02x index %x %pR\n", |
| 324 | busnum, j, res); |
Yinghai Lu | 30a18d6 | 2008-02-19 03:21:20 -0800 | [diff] [blame] | 325 | } |
| 326 | } |
| 327 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 328 | return 0; |
| 329 | } |
| 330 | |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 331 | #define ENABLE_CF8_EXT_CFG (1ULL << 46) |
| 332 | |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 333 | static void __cpuinit enable_pci_io_ecs(void *unused) |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 334 | { |
| 335 | u64 reg; |
| 336 | rdmsrl(MSR_AMD64_NB_CFG, reg); |
| 337 | if (!(reg & ENABLE_CF8_EXT_CFG)) { |
| 338 | reg |= ENABLE_CF8_EXT_CFG; |
| 339 | wrmsrl(MSR_AMD64_NB_CFG, reg); |
| 340 | } |
| 341 | } |
| 342 | |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 343 | static int __cpuinit amd_cpu_notify(struct notifier_block *self, |
| 344 | unsigned long action, void *hcpu) |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 345 | { |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 346 | int cpu = (long)hcpu; |
Robert Richter | ed21763 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 347 | switch (action) { |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 348 | case CPU_ONLINE: |
| 349 | case CPU_ONLINE_FROZEN: |
| 350 | smp_call_function_single(cpu, enable_pci_io_ecs, NULL, 0); |
| 351 | break; |
| 352 | default: |
| 353 | break; |
| 354 | } |
| 355 | return NOTIFY_OK; |
| 356 | } |
| 357 | |
| 358 | static struct notifier_block __cpuinitdata amd_cpu_notifier = { |
| 359 | .notifier_call = amd_cpu_notify, |
| 360 | }; |
| 361 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 362 | static void __init pci_enable_pci_io_ecs(void) |
| 363 | { |
| 364 | #ifdef CONFIG_AMD_NB |
| 365 | unsigned int i, n; |
| 366 | |
| 367 | for (n = i = 0; !n && amd_nb_bus_dev_ranges[i].dev_limit; ++i) { |
| 368 | u8 bus = amd_nb_bus_dev_ranges[i].bus; |
| 369 | u8 slot = amd_nb_bus_dev_ranges[i].dev_base; |
| 370 | u8 limit = amd_nb_bus_dev_ranges[i].dev_limit; |
| 371 | |
| 372 | for (; slot < limit; ++slot) { |
| 373 | u32 val = read_pci_config(bus, slot, 3, 0); |
| 374 | |
| 375 | if (!early_is_amd_nb(val)) |
| 376 | continue; |
| 377 | |
| 378 | val = read_pci_config(bus, slot, 3, 0x8c); |
| 379 | if (!(val & (ENABLE_CF8_EXT_CFG >> 32))) { |
| 380 | val |= ENABLE_CF8_EXT_CFG >> 32; |
| 381 | write_pci_config(bus, slot, 3, 0x8c, val); |
| 382 | } |
| 383 | ++n; |
| 384 | } |
| 385 | } |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 386 | #endif |
| 387 | } |
| 388 | |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 389 | static int __init pci_io_ecs_init(void) |
| 390 | { |
| 391 | int cpu; |
| 392 | |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 393 | /* assume all cpus from fam10h have IO ECS */ |
| 394 | if (boot_cpu_data.x86 < 0x10) |
| 395 | return 0; |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 396 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 397 | /* Try the PCI method first. */ |
| 398 | if (early_pci_allowed()) |
| 399 | pci_enable_pci_io_ecs(); |
| 400 | |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 401 | register_cpu_notifier(&amd_cpu_notifier); |
| 402 | for_each_online_cpu(cpu) |
| 403 | amd_cpu_notify(&amd_cpu_notifier, (unsigned long)CPU_ONLINE, |
| 404 | (void *)(long)cpu); |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 405 | pci_probe |= PCI_HAS_IO_ECS; |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 406 | |
Robert Richter | 3a27dd1 | 2008-06-12 20:19:23 +0200 | [diff] [blame] | 407 | return 0; |
| 408 | } |
| 409 | |
Robert Richter | 9b4e27b | 2008-08-22 20:23:37 +0200 | [diff] [blame] | 410 | static int __init amd_postcore_init(void) |
| 411 | { |
| 412 | if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) |
| 413 | return 0; |
| 414 | |
| 415 | early_fill_mp_bus_info(); |
Robert Richter | 91ede00 | 2008-08-22 20:23:38 +0200 | [diff] [blame] | 416 | pci_io_ecs_init(); |
Robert Richter | 9b4e27b | 2008-08-22 20:23:37 +0200 | [diff] [blame] | 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
| 421 | postcore_initcall(amd_postcore_init); |