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