Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 1 | /* |
| 2 | * Shared support code for AMD K8 northbridges and derivates. |
| 3 | * Copyright 2006 Andi Kleen, SUSE Labs. Subject to GPLv2. |
| 4 | */ |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 5 | |
| 6 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 7 | |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 8 | #include <linux/types.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 9 | #include <linux/slab.h> |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 10 | #include <linux/init.h> |
| 11 | #include <linux/errno.h> |
Paul Gortmaker | 186f436 | 2016-07-13 20:18:56 -0400 | [diff] [blame] | 12 | #include <linux/export.h> |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 13 | #include <linux/spinlock.h> |
Andreas Herrmann | 23ac4ae | 2010-09-17 18:03:43 +0200 | [diff] [blame] | 14 | #include <asm/amd_nb.h> |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 15 | |
Yazen Ghannam | b791c6b | 2016-11-10 15:10:55 -0600 | [diff] [blame^] | 16 | #define PCI_DEVICE_ID_AMD_17H_DF_F3 0x1463 |
| 17 | #define PCI_DEVICE_ID_AMD_17H_DF_F4 0x1464 |
| 18 | |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 19 | static u32 *flush_words; |
| 20 | |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 21 | const struct pci_device_id amd_nb_misc_ids[] = { |
Joerg Roedel | cf16970 | 2008-09-02 13:13:40 +0200 | [diff] [blame] | 22 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_K8_NB_MISC) }, |
| 23 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_10H_NB_MISC) }, |
Borislav Petkov | cb29325 | 2011-01-19 18:22:11 +0100 | [diff] [blame] | 24 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F3) }, |
Borislav Petkov | 2421444 | 2012-05-04 18:28:21 +0200 | [diff] [blame] | 25 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M10H_F3) }, |
Aravind Gopalakrishnan | 7d64ac6 | 2013-08-02 17:43:03 -0500 | [diff] [blame] | 26 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F3) }, |
Aravind Gopalakrishnan | 15895a7 | 2014-09-18 14:56:45 -0500 | [diff] [blame] | 27 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F3) }, |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 28 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F3) }, |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 29 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F3) }, |
Yazen Ghannam | b791c6b | 2016-11-10 15:10:55 -0600 | [diff] [blame^] | 30 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F3) }, |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 31 | {} |
| 32 | }; |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 33 | EXPORT_SYMBOL_GPL(amd_nb_misc_ids); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 34 | |
Jan Beulich | c391c78 | 2013-03-11 09:56:05 +0000 | [diff] [blame] | 35 | static const struct pci_device_id amd_nb_link_ids[] = { |
Borislav Petkov | cb6c852 | 2011-03-30 20:34:47 +0200 | [diff] [blame] | 36 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_NB_F4) }, |
Aravind Gopalakrishnan | 7d64ac6 | 2013-08-02 17:43:03 -0500 | [diff] [blame] | 37 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M30H_NB_F4) }, |
Aravind Gopalakrishnan | 15895a7 | 2014-09-18 14:56:45 -0500 | [diff] [blame] | 38 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_15H_M60H_NB_F4) }, |
Aravind Gopalakrishnan | 94c1acf | 2013-04-17 14:57:13 -0500 | [diff] [blame] | 39 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_NB_F4) }, |
Aravind Gopalakrishnan | 85a8885 | 2014-02-20 10:28:46 -0600 | [diff] [blame] | 40 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_16H_M30H_NB_F4) }, |
Yazen Ghannam | b791c6b | 2016-11-10 15:10:55 -0600 | [diff] [blame^] | 41 | { PCI_DEVICE(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_17H_DF_F4) }, |
Hans Rosenfeld | 41b2610 | 2011-01-24 16:05:42 +0100 | [diff] [blame] | 42 | {} |
| 43 | }; |
| 44 | |
Jan Beulich | 24d9b70 | 2011-01-10 16:20:23 +0000 | [diff] [blame] | 45 | const struct amd_nb_bus_dev_range amd_nb_bus_dev_ranges[] __initconst = { |
| 46 | { 0x00, 0x18, 0x20 }, |
| 47 | { 0xff, 0x00, 0x20 }, |
| 48 | { 0xfe, 0x00, 0x20 }, |
| 49 | { } |
| 50 | }; |
| 51 | |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 52 | static struct amd_northbridge_info amd_northbridges; |
| 53 | |
| 54 | u16 amd_nb_num(void) |
| 55 | { |
| 56 | return amd_northbridges.num; |
| 57 | } |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 58 | EXPORT_SYMBOL_GPL(amd_nb_num); |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 59 | |
| 60 | bool amd_nb_has_feature(unsigned int feature) |
| 61 | { |
| 62 | return ((amd_northbridges.flags & feature) == feature); |
| 63 | } |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 64 | EXPORT_SYMBOL_GPL(amd_nb_has_feature); |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 65 | |
| 66 | struct amd_northbridge *node_to_amd_nb(int node) |
| 67 | { |
| 68 | return (node < amd_northbridges.num) ? &amd_northbridges.nb[node] : NULL; |
| 69 | } |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 70 | EXPORT_SYMBOL_GPL(node_to_amd_nb); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 71 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 72 | static struct pci_dev *next_northbridge(struct pci_dev *dev, |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 73 | const struct pci_device_id *ids) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 74 | { |
| 75 | do { |
| 76 | dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev); |
| 77 | if (!dev) |
| 78 | break; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 79 | } while (!pci_match_id(ids, dev)); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 80 | return dev; |
| 81 | } |
| 82 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 83 | int amd_cache_northbridges(void) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 84 | { |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 85 | u16 i = 0; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 86 | struct amd_northbridge *nb; |
Hans Rosenfeld | 41b2610 | 2011-01-24 16:05:42 +0100 | [diff] [blame] | 87 | struct pci_dev *misc, *link; |
Ben Collins | 3c6df2a | 2007-05-23 13:57:43 -0700 | [diff] [blame] | 88 | |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 89 | if (amd_northbridges.num) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 90 | return 0; |
| 91 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 92 | misc = NULL; |
| 93 | while ((misc = next_northbridge(misc, amd_nb_misc_ids)) != NULL) |
| 94 | i++; |
| 95 | |
Borislav Petkov | 1ead852 | 2016-06-16 19:13:49 +0200 | [diff] [blame] | 96 | if (!i) |
| 97 | return -ENODEV; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 98 | |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 99 | nb = kcalloc(i, sizeof(struct amd_northbridge), GFP_KERNEL); |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 100 | if (!nb) |
| 101 | return -ENOMEM; |
| 102 | |
| 103 | amd_northbridges.nb = nb; |
| 104 | amd_northbridges.num = i; |
| 105 | |
Hans Rosenfeld | 41b2610 | 2011-01-24 16:05:42 +0100 | [diff] [blame] | 106 | link = misc = NULL; |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 107 | for (i = 0; i != amd_northbridges.num; i++) { |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 108 | node_to_amd_nb(i)->misc = misc = |
| 109 | next_northbridge(misc, amd_nb_misc_ids); |
Hans Rosenfeld | 41b2610 | 2011-01-24 16:05:42 +0100 | [diff] [blame] | 110 | node_to_amd_nb(i)->link = link = |
| 111 | next_northbridge(link, amd_nb_link_ids); |
Aravind Gopalakrishnan | 7d64ac6 | 2013-08-02 17:43:03 -0500 | [diff] [blame] | 112 | } |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 113 | |
Aravind Gopalakrishnan | 1b45742 | 2015-04-07 16:46:37 -0500 | [diff] [blame] | 114 | if (amd_gart_present()) |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 115 | amd_northbridges.flags |= AMD_NB_GART; |
Andreas Herrmann | 900f9ac | 2010-09-17 18:02:54 +0200 | [diff] [blame] | 116 | |
Hans Rosenfeld | f658bcf | 2010-10-29 17:14:32 +0200 | [diff] [blame] | 117 | /* |
Aravind Gopalakrishnan | 7d64ac6 | 2013-08-02 17:43:03 -0500 | [diff] [blame] | 118 | * Check for L3 cache presence. |
| 119 | */ |
| 120 | if (!cpuid_edx(0x80000006)) |
| 121 | return 0; |
| 122 | |
| 123 | /* |
Hans Rosenfeld | f658bcf | 2010-10-29 17:14:32 +0200 | [diff] [blame] | 124 | * Some CPU families support L3 Cache Index Disable. There are some |
| 125 | * limitations because of E382 and E388 on family 0x10. |
| 126 | */ |
| 127 | if (boot_cpu_data.x86 == 0x10 && |
| 128 | boot_cpu_data.x86_model >= 0x8 && |
| 129 | (boot_cpu_data.x86_model > 0x9 || |
| 130 | boot_cpu_data.x86_mask >= 0x1)) |
| 131 | amd_northbridges.flags |= AMD_NB_L3_INDEX_DISABLE; |
| 132 | |
Hans Rosenfeld | b453de0 | 2011-01-24 16:05:41 +0100 | [diff] [blame] | 133 | if (boot_cpu_data.x86 == 0x15) |
| 134 | amd_northbridges.flags |= AMD_NB_L3_INDEX_DISABLE; |
| 135 | |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 136 | /* L3 cache partitioning is supported on family 0x15 */ |
| 137 | if (boot_cpu_data.x86 == 0x15) |
| 138 | amd_northbridges.flags |= AMD_NB_L3_PARTITIONING; |
| 139 | |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 140 | return 0; |
| 141 | } |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 142 | EXPORT_SYMBOL_GPL(amd_cache_northbridges); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 143 | |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 144 | /* |
| 145 | * Ignores subdevice/subvendor but as far as I can figure out |
| 146 | * they're useless anyways |
| 147 | */ |
| 148 | bool __init early_is_amd_nb(u32 device) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 149 | { |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 150 | const struct pci_device_id *id; |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 151 | u32 vendor = device & 0xffff; |
Jan Beulich | 691269f | 2011-02-09 08:26:53 +0000 | [diff] [blame] | 152 | |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 153 | device >>= 16; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 154 | for (id = amd_nb_misc_ids; id->vendor; id++) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 155 | if (vendor == id->vendor && device == id->device) |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 156 | return true; |
| 157 | return false; |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 158 | } |
| 159 | |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 160 | struct resource *amd_get_mmconfig_range(struct resource *res) |
| 161 | { |
| 162 | u32 address; |
| 163 | u64 base, msr; |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 164 | unsigned int segn_busn_bits; |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 165 | |
| 166 | if (boot_cpu_data.x86_vendor != X86_VENDOR_AMD) |
| 167 | return NULL; |
| 168 | |
| 169 | /* assume all cpus from fam10h have mmconfig */ |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 170 | if (boot_cpu_data.x86 < 0x10) |
Bjorn Helgaas | 24d25db | 2012-01-05 14:27:19 -0700 | [diff] [blame] | 171 | return NULL; |
| 172 | |
| 173 | address = MSR_FAM10H_MMIO_CONF_BASE; |
| 174 | rdmsrl(address, msr); |
| 175 | |
| 176 | /* mmconfig is not enabled */ |
| 177 | if (!(msr & FAM10H_MMIO_CONF_ENABLE)) |
| 178 | return NULL; |
| 179 | |
| 180 | base = msr & (FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT); |
| 181 | |
| 182 | segn_busn_bits = (msr >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) & |
| 183 | FAM10H_MMIO_CONF_BUSRANGE_MASK; |
| 184 | |
| 185 | res->flags = IORESOURCE_MEM; |
| 186 | res->start = base; |
| 187 | res->end = base + (1ULL<<(segn_busn_bits + 20)) - 1; |
| 188 | return res; |
| 189 | } |
| 190 | |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 191 | int amd_get_subcaches(int cpu) |
| 192 | { |
| 193 | struct pci_dev *link = node_to_amd_nb(amd_get_nb_id(cpu))->link; |
| 194 | unsigned int mask; |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 195 | |
| 196 | if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING)) |
| 197 | return 0; |
| 198 | |
| 199 | pci_read_config_dword(link, 0x1d4, &mask); |
| 200 | |
Borislav Petkov | 8196dab | 2016-03-25 15:52:36 +0100 | [diff] [blame] | 201 | return (mask >> (4 * cpu_data(cpu).cpu_core_id)) & 0xf; |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 202 | } |
| 203 | |
Dan Carpenter | 2993ae3 | 2014-01-21 10:22:09 +0300 | [diff] [blame] | 204 | int amd_set_subcaches(int cpu, unsigned long mask) |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 205 | { |
| 206 | static unsigned int reset, ban; |
| 207 | struct amd_northbridge *nb = node_to_amd_nb(amd_get_nb_id(cpu)); |
| 208 | unsigned int reg; |
Kevin Winchester | 141168c | 2011-12-20 20:52:22 -0400 | [diff] [blame] | 209 | int cuid; |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 210 | |
| 211 | if (!amd_nb_has_feature(AMD_NB_L3_PARTITIONING) || mask > 0xf) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | /* if necessary, collect reset state of L3 partitioning and BAN mode */ |
| 215 | if (reset == 0) { |
| 216 | pci_read_config_dword(nb->link, 0x1d4, &reset); |
| 217 | pci_read_config_dword(nb->misc, 0x1b8, &ban); |
| 218 | ban &= 0x180000; |
| 219 | } |
| 220 | |
| 221 | /* deactivate BAN mode if any subcaches are to be disabled */ |
| 222 | if (mask != 0xf) { |
| 223 | pci_read_config_dword(nb->misc, 0x1b8, ®); |
| 224 | pci_write_config_dword(nb->misc, 0x1b8, reg & ~0x180000); |
| 225 | } |
| 226 | |
Borislav Petkov | 8196dab | 2016-03-25 15:52:36 +0100 | [diff] [blame] | 227 | cuid = cpu_data(cpu).cpu_core_id; |
Hans Rosenfeld | cabb5bd | 2011-02-07 18:10:39 +0100 | [diff] [blame] | 228 | mask <<= 4 * cuid; |
| 229 | mask |= (0xf ^ (1 << cuid)) << 26; |
| 230 | |
| 231 | pci_write_config_dword(nb->link, 0x1d4, mask); |
| 232 | |
| 233 | /* reset BAN mode if L3 partitioning returned to reset state */ |
| 234 | pci_read_config_dword(nb->link, 0x1d4, ®); |
| 235 | if (reg == reset) { |
| 236 | pci_read_config_dword(nb->misc, 0x1b8, ®); |
| 237 | reg &= ~0x180000; |
| 238 | pci_write_config_dword(nb->misc, 0x1b8, reg | ban); |
| 239 | } |
| 240 | |
| 241 | return 0; |
| 242 | } |
| 243 | |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 244 | static void amd_cache_gart(void) |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 245 | { |
Borislav Petkov | 84fd1d3 | 2011-03-03 12:59:32 +0100 | [diff] [blame] | 246 | u16 i; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 247 | |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 248 | if (!amd_nb_has_feature(AMD_NB_GART)) |
| 249 | return; |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 250 | |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 251 | flush_words = kmalloc_array(amd_northbridges.num, sizeof(u32), GFP_KERNEL); |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 252 | if (!flush_words) { |
| 253 | amd_northbridges.flags &= ~AMD_NB_GART; |
| 254 | pr_notice("Cannot initialize GART flush words, GART support disabled\n"); |
| 255 | return; |
| 256 | } |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 257 | |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 258 | for (i = 0; i != amd_northbridges.num; i++) |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 259 | pci_read_config_dword(node_to_amd_nb(i)->misc, 0x9c, &flush_words[i]); |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 260 | } |
| 261 | |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 262 | void amd_flush_garts(void) |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 263 | { |
| 264 | int flushed, i; |
| 265 | unsigned long flags; |
| 266 | static DEFINE_SPINLOCK(gart_lock); |
| 267 | |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 268 | if (!amd_nb_has_feature(AMD_NB_GART)) |
Andreas Herrmann | 900f9ac | 2010-09-17 18:02:54 +0200 | [diff] [blame] | 269 | return; |
| 270 | |
Yazen Ghannam | de6bd08 | 2016-11-10 15:10:54 -0600 | [diff] [blame] | 271 | /* |
| 272 | * Avoid races between AGP and IOMMU. In theory it's not needed |
| 273 | * but I'm not sure if the hardware won't lose flush requests |
| 274 | * when another is pending. This whole thing is so expensive anyways |
| 275 | * that it doesn't matter to serialize more. -AK |
| 276 | */ |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 277 | spin_lock_irqsave(&gart_lock, flags); |
| 278 | flushed = 0; |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 279 | for (i = 0; i < amd_northbridges.num; i++) { |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 280 | pci_write_config_dword(node_to_amd_nb(i)->misc, 0x9c, |
| 281 | flush_words[i] | 1); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 282 | flushed++; |
| 283 | } |
Yazen Ghannam | c799389 | 2016-11-10 15:10:53 -0600 | [diff] [blame] | 284 | for (i = 0; i < amd_northbridges.num; i++) { |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 285 | u32 w; |
| 286 | /* Make sure the hardware actually executed the flush*/ |
| 287 | for (;;) { |
Hans Rosenfeld | 9653a5c | 2010-10-29 17:14:31 +0200 | [diff] [blame] | 288 | pci_read_config_dword(node_to_amd_nb(i)->misc, |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 289 | 0x9c, &w); |
| 290 | if (!(w & 1)) |
| 291 | break; |
| 292 | cpu_relax(); |
| 293 | } |
| 294 | } |
| 295 | spin_unlock_irqrestore(&gart_lock, flags); |
| 296 | if (!flushed) |
Joe Perches | c767a54 | 2012-05-21 19:50:07 -0700 | [diff] [blame] | 297 | pr_notice("nothing to flush?\n"); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 298 | } |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 299 | EXPORT_SYMBOL_GPL(amd_flush_garts); |
Andi Kleen | a32073b | 2006-06-26 13:56:40 +0200 | [diff] [blame] | 300 | |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 301 | static __init int init_amd_nbs(void) |
Borislav Petkov | 0e152cd | 2010-03-12 15:43:03 +0100 | [diff] [blame] | 302 | { |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 303 | amd_cache_northbridges(); |
| 304 | amd_cache_gart(); |
Borislav Petkov | 0e152cd | 2010-03-12 15:43:03 +0100 | [diff] [blame] | 305 | |
Borislav Petkov | 09c6c30 | 2016-06-16 19:13:50 +0200 | [diff] [blame] | 306 | return 0; |
Borislav Petkov | 0e152cd | 2010-03-12 15:43:03 +0100 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | /* This has to go after the PCI subsystem */ |
Hans Rosenfeld | eec1d4f | 2010-10-29 17:14:30 +0200 | [diff] [blame] | 310 | fs_initcall(init_amd_nbs); |