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