arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 1 | /* This should be done by Eric |
| 2 | 2004.12 yhlu add dual core support |
Uwe Hermann | 607614d | 2010-11-18 20:12:13 +0000 | [diff] [blame] | 3 | 2005.01 yhlu add support move apic before pci_domain in MB devicetree.cb |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 4 | 2005.02 yhlu add e0 memory hole support |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 5 | 2005.11 yhlu add put sb ht chain on bus 0 |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 6 | */ |
| 7 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 8 | #include <console/console.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 9 | #include <arch/io.h> |
| 10 | #include <stdint.h> |
Eric Biederman | 2c018fb | 2003-07-21 20:13:45 +0000 | [diff] [blame] | 11 | #include <device/device.h> |
| 12 | #include <device/pci.h> |
Eric Biederman | 17729a2 | 2003-12-08 21:48:01 +0000 | [diff] [blame] | 13 | #include <device/pci_ids.h> |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 14 | #include <device/hypertransport.h> |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 15 | #include <stdlib.h> |
| 16 | #include <string.h> |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 17 | #include <lib.h> |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 18 | #include <cpu/cpu.h> |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 19 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 20 | #include <arch/acpi.h> |
| 21 | #include "acpi.h" |
| 22 | #endif |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 23 | |
| 24 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 25 | #include <cpu/amd/mtrr.h> |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 26 | |
Stefan Reinauer | 9a16e3e | 2010-03-29 14:45:36 +0000 | [diff] [blame] | 27 | #include <cpu/amd/multicore.h> |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 28 | #if CONFIG_LOGICAL_CPUS |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 29 | #include <pc80/mc146818rtc.h> |
| 30 | #endif |
| 31 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 32 | #include "northbridge.h" |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 33 | |
Eric Biederman | 4ab9f17 | 2003-12-06 00:11:56 +0000 | [diff] [blame] | 34 | #include "amdk8.h" |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 35 | |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 36 | #include <cpu/amd/model_fxx_rev.h> |
Eric Biederman | 8ca8d76 | 2003-04-22 19:02:15 +0000 | [diff] [blame] | 37 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 38 | #include <cpu/amd/amdk8_sysconf.h> |
| 39 | |
| 40 | struct amdk8_sysconf_t sysconf; |
| 41 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 42 | #define MAX_FX_DEVS 8 |
| 43 | static device_t __f0_dev[MAX_FX_DEVS]; |
| 44 | static device_t __f1_dev[MAX_FX_DEVS]; |
| 45 | static unsigned fx_devs=0; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 46 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 47 | static void get_fx_devs(void) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 48 | { |
| 49 | int i; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 50 | for(i = 0; i < MAX_FX_DEVS; i++) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 51 | __f0_dev[i] = dev_find_slot(0, PCI_DEVFN(0x18 + i, 0)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 52 | __f1_dev[i] = dev_find_slot(0, PCI_DEVFN(0x18 + i, 1)); |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 53 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 54 | fx_devs = i+1; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 55 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 56 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 57 | die("Cannot find 0:0x18.[0|1]\n"); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 58 | } |
| 59 | } |
| 60 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 61 | static u32 f1_read_config32(unsigned reg) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 62 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 63 | if (fx_devs == 0) |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 64 | get_fx_devs(); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 65 | return pci_read_config32(__f1_dev[0], reg); |
| 66 | } |
| 67 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 68 | static void f1_write_config32(unsigned reg, u32 value) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 69 | { |
| 70 | int i; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 71 | if (fx_devs == 0) |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 72 | get_fx_devs(); |
| 73 | for(i = 0; i < fx_devs; i++) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 74 | device_t dev; |
| 75 | dev = __f1_dev[i]; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 76 | if (dev && dev->enabled) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 77 | pci_write_config32(dev, reg, value); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
Kyösti Mälkki | 11c79d7 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 82 | static bool is_non_coherent_link(struct device *dev, struct bus *link) |
| 83 | { |
| 84 | u32 link_type; |
| 85 | do { |
| 86 | link_type = pci_read_config32(dev, link->cap + 0x18); |
| 87 | } while (link_type & ConnectionPending); |
| 88 | |
| 89 | if (!(link_type & LinkConnected)) |
| 90 | return false; |
| 91 | |
| 92 | do { |
| 93 | link_type = pci_read_config32(dev, link->cap + 0x18); |
| 94 | } while (!(link_type & InitComplete)); |
| 95 | |
| 96 | return !!(link_type & NonCoherent); |
| 97 | } |
| 98 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 99 | static u32 amdk8_nodeid(device_t dev) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 100 | { |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 101 | return (dev->path.pci.devfn >> 3) - 0x18; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 102 | } |
| 103 | |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 104 | static u32 amdk8_scan_chain(device_t dev, u32 nodeid, struct bus *link, bool is_sblink, |
| 105 | u32 max) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 106 | { |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 107 | int i; |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 108 | unsigned int next_unitid; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 109 | u32 busses, config_busses; |
| 110 | u32 free_reg, config_reg; |
| 111 | u32 ht_unitid_base[4]; // here assume only 4 HT device on chain |
| 112 | u32 max_bus; |
| 113 | u32 min_bus; |
| 114 | u32 max_devfn; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 115 | |
Kyösti Mälkki | 260a6db | 2015-02-04 11:09:52 +0200 | [diff] [blame] | 116 | link->cap = 0x80 + (link->link_num * 0x20); |
Kyösti Mälkki | 11c79d7 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 117 | if (!is_non_coherent_link(dev, link)) |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 118 | return max; |
Kyösti Mälkki | 11c79d7 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 119 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 120 | /* See if there is an available configuration space mapping |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 121 | * register in function 1. |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 122 | */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 123 | free_reg = 0; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 124 | for(config_reg = 0xe0; config_reg <= 0xec; config_reg += 4) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 125 | u32 config; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 126 | config = f1_read_config32(config_reg); |
| 127 | if (!free_reg && ((config & 3) == 0)) { |
| 128 | free_reg = config_reg; |
| 129 | continue; |
| 130 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 131 | if (((config & 3) == 3) && |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 132 | (((config >> 4) & 7) == nodeid) && |
Kyösti Mälkki | 260a6db | 2015-02-04 11:09:52 +0200 | [diff] [blame] | 133 | (((config >> 8) & 3) == link->link_num)) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 134 | break; |
| 135 | } |
| 136 | } |
| 137 | if (free_reg && (config_reg > 0xec)) { |
| 138 | config_reg = free_reg; |
| 139 | } |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 140 | /* If we can't find an available configuration space mapping |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 141 | * register skip this bus |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 142 | */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 143 | if (config_reg > 0xec) { |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 144 | return max; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 145 | } |
| 146 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 147 | /* Set up the primary, secondary and subordinate bus numbers. |
| 148 | * We have no idea how many busses are behind this bridge yet, |
| 149 | * so we set the subordinate bus number to 0xff for the moment. |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 150 | */ |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 151 | #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 0 |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 152 | // first chain will on bus 0 |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 153 | if(is_sblink) { // actually max is 0 here |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 154 | min_bus = max; |
| 155 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 156 | #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 1 |
Yinghai Lu | 653ee54 | 2005-12-08 18:47:33 +0000 | [diff] [blame] | 157 | // second chain will be on 0x40, third 0x80, forth 0xc0 |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 158 | else { |
| 159 | min_bus = ((max>>6) + 1) * 0x40; |
| 160 | } |
| 161 | max = min_bus; |
| 162 | #else |
| 163 | //other ... |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 164 | else { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 165 | min_bus = ++max; |
| 166 | } |
| 167 | #endif |
Yinghai Lu | b3b1b2d | 2005-12-06 23:40:58 +0000 | [diff] [blame] | 168 | #else |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 169 | min_bus = ++max; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 170 | #endif |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 171 | max_bus = 0xff; |
Yinghai Lu | b3b1b2d | 2005-12-06 23:40:58 +0000 | [diff] [blame] | 172 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 173 | link->secondary = min_bus; |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 174 | link->subordinate = link->secondary; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 175 | |
| 176 | /* Read the existing primary/secondary/subordinate bus |
| 177 | * number configuration. |
| 178 | */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 179 | busses = pci_read_config32(dev, link->cap + 0x14); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 180 | config_busses = f1_read_config32(config_reg); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 181 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 182 | /* Configure the bus numbers for this bridge: the configuration |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 183 | * transactions will not be propagates by the bridge if it is |
| 184 | * not correctly configured |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 185 | */ |
| 186 | busses &= 0xff000000; |
| 187 | busses |= (((unsigned int)(dev->bus->secondary) << 0) | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 188 | ((unsigned int)(link->secondary) << 8) | |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 189 | (max_bus << 16)); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 190 | pci_write_config32(dev, link->cap + 0x14, busses); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 191 | |
Eric Biederman | 17729a2 | 2003-12-08 21:48:01 +0000 | [diff] [blame] | 192 | config_busses &= 0x000fc88; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 193 | config_busses |= |
Eric Biederman | 17729a2 | 2003-12-08 21:48:01 +0000 | [diff] [blame] | 194 | (3 << 0) | /* rw enable, no device compare */ |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 195 | (( nodeid & 7) << 4) | |
Kyösti Mälkki | 260a6db | 2015-02-04 11:09:52 +0200 | [diff] [blame] | 196 | ((link->link_num & 3) << 8) | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 197 | ((link->secondary) << 16) | |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 198 | (max_bus << 24); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 199 | f1_write_config32(config_reg, config_busses); |
| 200 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 201 | /* Now we can scan all of the subordinate busses i.e. the |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 202 | * chain on the hypertranport link |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 203 | */ |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 204 | for(i=0;i<4;i++) { |
| 205 | ht_unitid_base[i] = 0x20; |
| 206 | } |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 207 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 208 | if (min_bus == 0) |
Yinghai Lu | 18c70d7 | 2007-09-14 14:58:33 +0000 | [diff] [blame] | 209 | max_devfn = (0x17<<3) | 7; |
| 210 | else |
| 211 | max_devfn = (0x1f<<3) | 7; |
| 212 | |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 213 | next_unitid = hypertransport_scan_chain(link, 0, max_devfn, ht_unitid_base, offset_unit_id(is_sblink)); |
| 214 | |
| 215 | /* Now that nothing is overlapping it is safe to scan the children. */ |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 216 | link->subordinate = pci_scan_bus(link, 0x00, ((next_unitid - 1) << 3) | 7, link->secondary); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 217 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 218 | /* We know the number of busses behind this bridge. Set the |
| 219 | * subordinate bus number to it's real value |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 220 | */ |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 221 | busses = (busses & 0xff00ffff) | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 222 | ((unsigned int) (link->subordinate) << 16); |
| 223 | pci_write_config32(dev, link->cap + 0x14, busses); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 224 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 225 | config_busses = (config_busses & 0x00ffffff) | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 226 | (link->subordinate << 24); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 227 | f1_write_config32(config_reg, config_busses); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 228 | |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 229 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 230 | // use config_reg and ht_unitid_base to update hcdn_reg |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 231 | int index; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 232 | u32 temp = 0; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 233 | index = (config_reg-0xe0) >> 2; |
| 234 | for(i=0;i<4;i++) { |
| 235 | temp |= (ht_unitid_base[i] & 0xff) << (i*8); |
| 236 | } |
| 237 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 238 | sysconf.hcdn_reg[index] = temp; |
Stefan Reinauer | bbdd8f4 | 2005-12-04 21:52:58 +0000 | [diff] [blame] | 239 | |
| 240 | } |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 241 | return link->subordinate; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 242 | } |
| 243 | |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 244 | static unsigned amdk8_scan_chains(device_t dev, unsigned unused) |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 245 | { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 246 | unsigned nodeid; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 247 | struct bus *link; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 248 | unsigned sblink = 0; |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 249 | unsigned int max = dev->bus->subordinate; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 250 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 251 | nodeid = amdk8_nodeid(dev); |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 252 | if (nodeid == 0) |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 253 | sblink = (pci_read_config32(dev, 0x64)>>8) & 3; |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 254 | |
| 255 | // do sb ht chain at first, in case s2885 put sb chain (8131/8111) on link2, but put 8151 on link0 |
| 256 | for (link = dev->link_list; link; link = link->next) { |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 257 | bool is_sblink = (nodeid == 0) && (link->link_num == sblink); |
| 258 | if ((CONFIG_SB_HT_CHAIN_ON_BUS0 > 0) && is_sblink) |
| 259 | max = amdk8_scan_chain(dev, nodeid, link, is_sblink, max); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 260 | } |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 261 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 262 | for (link = dev->link_list; link; link = link->next) { |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 263 | bool is_sblink = (nodeid == 0) && (link->link_num == sblink); |
| 264 | if ((CONFIG_SB_HT_CHAIN_ON_BUS0 > 0) && is_sblink) |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 265 | continue; |
| 266 | |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 267 | max = amdk8_scan_chain(dev, nodeid, link, is_sblink, max); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 268 | } |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 269 | |
| 270 | dev->bus->subordinate = max; |
| 271 | |
| 272 | return unused; |
Stefan Reinauer | 7ce8c54 | 2005-12-02 21:52:30 +0000 | [diff] [blame] | 273 | } |
| 274 | |
| 275 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 276 | static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid, |
| 277 | unsigned goal_link) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 278 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 279 | struct resource *res; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 280 | unsigned nodeid, link = 0; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 281 | int result; |
| 282 | res = 0; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 283 | for(nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 284 | device_t dev; |
| 285 | dev = __f0_dev[nodeid]; |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 286 | if (!dev) |
| 287 | continue; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 288 | for(link = 0; !res && (link < 3); link++) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 289 | res = probe_resource(dev, IOINDEX(0x100 + reg, link)); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 290 | } |
| 291 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 292 | result = 2; |
| 293 | if (res) { |
| 294 | result = 0; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 295 | if ( (goal_link == (link - 1)) && |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 296 | (goal_nodeid == (nodeid - 1)) && |
| 297 | (res->flags <= 1)) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 298 | result = 1; |
| 299 | } |
| 300 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 301 | return result; |
| 302 | } |
| 303 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 304 | static unsigned amdk8_find_reg(device_t dev, unsigned nodeid, unsigned link, |
| 305 | unsigned min, unsigned max) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 306 | { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 307 | unsigned resource; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 308 | unsigned free_reg, reg; |
| 309 | resource = 0; |
| 310 | free_reg = 0; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 311 | for(reg = min; reg <= max; reg += 0x8) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 312 | int result; |
| 313 | result = reg_useable(reg, dev, nodeid, link); |
| 314 | if (result == 1) { |
| 315 | /* I have been allocated this one */ |
| 316 | break; |
| 317 | } |
| 318 | else if (result > 1) { |
| 319 | /* I have a free register pair */ |
| 320 | free_reg = reg; |
| 321 | } |
| 322 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 323 | if (reg > max) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 324 | reg = free_reg; |
| 325 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 326 | if (reg > 0) { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 327 | resource = IOINDEX(0x100 + reg, link); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 328 | } |
| 329 | return resource; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 332 | static unsigned amdk8_find_iopair(device_t dev, unsigned nodeid, unsigned link) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 333 | { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 334 | return amdk8_find_reg(dev, nodeid, link, 0xc0, 0xd8); |
| 335 | } |
| 336 | |
| 337 | static unsigned amdk8_find_mempair(device_t dev, unsigned nodeid, unsigned link) |
| 338 | { |
| 339 | return amdk8_find_reg(dev, nodeid, link, 0x80, 0xb8); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 340 | } |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 341 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 342 | static void amdk8_link_read_bases(device_t dev, unsigned nodeid, unsigned link) |
| 343 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 344 | struct resource *resource; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 345 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 346 | /* Initialize the io space constraints on the current bus */ |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 347 | resource = new_resource(dev, IOINDEX(0, link)); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 348 | if (resource) { |
| 349 | resource->base = 0; |
| 350 | resource->size = 0; |
| 351 | resource->align = log2(HT_IO_HOST_ALIGN); |
| 352 | resource->gran = log2(HT_IO_HOST_ALIGN); |
| 353 | resource->limit = 0xffffUL; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 354 | resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 355 | } |
| 356 | |
| 357 | /* Initialize the prefetchable memory constraints on the current bus */ |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 358 | resource = new_resource(dev, IOINDEX(2, link)); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 359 | if (resource) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 360 | resource->base = 0; |
| 361 | resource->size = 0; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 362 | resource->align = log2(HT_MEM_HOST_ALIGN); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 363 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 364 | resource->limit = 0xffffffffffULL; |
| 365 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 366 | resource->flags |= IORESOURCE_BRIDGE; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 367 | } |
| 368 | |
| 369 | /* Initialize the memory constraints on the current bus */ |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 370 | resource = new_resource(dev, IOINDEX(1, link)); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 371 | if (resource) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 372 | resource->base = 0; |
| 373 | resource->size = 0; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 374 | resource->align = log2(HT_MEM_HOST_ALIGN); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 375 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 376 | resource->limit = 0xffffffffULL; |
| 377 | resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 378 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 379 | } |
| 380 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 381 | static void amdk8_create_vga_resource(device_t dev, unsigned nodeid); |
| 382 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 383 | static void amdk8_read_resources(device_t dev) |
| 384 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 385 | unsigned nodeid; |
| 386 | struct bus *link; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 387 | nodeid = amdk8_nodeid(dev); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 388 | for(link = dev->link_list; link; link = link->next) { |
| 389 | if (link->children) { |
| 390 | amdk8_link_read_bases(dev, nodeid, link->link_num); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 391 | } |
| 392 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 393 | amdk8_create_vga_resource(dev, nodeid); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 394 | } |
| 395 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 396 | static void amdk8_set_resource(device_t dev, struct resource *resource, unsigned nodeid) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 397 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 398 | struct bus *link; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 399 | resource_t rbase, rend; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 400 | unsigned reg, link_num; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 401 | char buf[50]; |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 402 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 403 | /* Make certain the resource has actually been set */ |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 404 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 405 | printk(BIOS_ERR, "%s: can't set unassigned resource @%lx %lx\n", |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 406 | __func__, resource->index, resource->flags); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 407 | return; |
| 408 | } |
| 409 | |
| 410 | /* If I have already stored this resource don't worry about it */ |
| 411 | if (resource->flags & IORESOURCE_STORED) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 412 | printk(BIOS_ERR, "%s: can't set stored resource @%lx %lx\n", __func__, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 413 | resource->index, resource->flags); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 414 | return; |
| 415 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 416 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 417 | /* Only handle PCI memory and IO resources */ |
| 418 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 419 | return; |
| 420 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 421 | /* Ensure I am actually looking at a resource of function 1 */ |
| 422 | if (resource->index < 0x100) { |
| 423 | return; |
| 424 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 425 | |
| 426 | if (resource->size == 0) |
| 427 | return; |
| 428 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 429 | /* Get the base address */ |
| 430 | rbase = resource->base; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 431 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 432 | /* Get the limit (rounded up) */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 433 | rend = resource_end(resource); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 434 | |
| 435 | /* Get the register and link */ |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 436 | reg = resource->index & 0xfc; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 437 | link_num = IOINDEX_LINK(resource->index); |
| 438 | |
| 439 | for (link = dev->link_list; link; link = link->next) |
| 440 | if (link->link_num == link_num) |
| 441 | break; |
| 442 | |
| 443 | if (link == NULL) { |
| 444 | printk(BIOS_ERR, "%s: can't find link %x for %lx\n", __func__, |
| 445 | link_num, resource->index); |
| 446 | return; |
| 447 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 448 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 449 | if (resource->flags & IORESOURCE_IO) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 450 | u32 base, limit; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 451 | base = f1_read_config32(reg); |
| 452 | limit = f1_read_config32(reg + 0x4); |
| 453 | base &= 0xfe000fcc; |
| 454 | base |= rbase & 0x01fff000; |
| 455 | base |= 3; |
| 456 | limit &= 0xfe000fc8; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 457 | limit |= rend & 0x01fff000; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 458 | limit |= (link_num & 3) << 4; |
Li-Ta Lo | 3259784 | 2004-02-23 22:33:10 +0000 | [diff] [blame] | 459 | limit |= (nodeid & 7); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 460 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 461 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 462 | printk(BIOS_SPEW, "%s, enabling legacy VGA IO forwarding for %s link 0x%x\n", |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 463 | __func__, dev_path(dev), link_num); |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 464 | base |= PCI_IO_BASE_VGA_EN; |
David W. Hendricks | 854e452 | 2004-02-09 22:47:38 +0000 | [diff] [blame] | 465 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 466 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_NO_ISA) { |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 467 | base |= PCI_IO_BASE_NO_ISA; |
| 468 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 469 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 470 | f1_write_config32(reg + 0x4, limit); |
| 471 | f1_write_config32(reg, base); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 472 | } |
| 473 | else if (resource->flags & IORESOURCE_MEM) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 474 | u32 base, limit; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 475 | base = f1_read_config32(reg); |
| 476 | limit = f1_read_config32(reg + 0x4); |
| 477 | base &= 0x000000f0; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 478 | base |= (rbase >> 8) & 0xffffff00; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 479 | base |= 3; |
| 480 | limit &= 0x00000048; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 481 | limit |= (rend >> 8) & 0xffffff00; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 482 | limit |= (link_num & 3) << 4; |
Li-Ta Lo | 3259784 | 2004-02-23 22:33:10 +0000 | [diff] [blame] | 483 | limit |= (nodeid & 7); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 484 | f1_write_config32(reg + 0x4, limit); |
| 485 | f1_write_config32(reg, base); |
| 486 | } |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 487 | resource->flags |= IORESOURCE_STORED; |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 488 | snprintf(buf, sizeof (buf), " <node %x link %x>", |
| 489 | nodeid, link_num); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 490 | report_resource_stored(dev, resource, buf); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 491 | } |
| 492 | |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 493 | static void amdk8_create_vga_resource(device_t dev, unsigned nodeid) |
| 494 | { |
| 495 | struct resource *resource; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 496 | struct bus *link; |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 497 | |
| 498 | /* find out which link the VGA card is connected, |
| 499 | * we only deal with the 'first' vga card */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 500 | for (link = dev->link_list; link; link = link->next) { |
| 501 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 502 | #if CONFIG_MULTIPLE_VGA_ADAPTERS |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 503 | extern device_t vga_pri; // the primary vga device, defined in device.c |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 504 | printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d link bus range [%d,%d]\n", vga_pri->bus->secondary, |
| 505 | link->secondary,link->subordinate); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 506 | /* We need to make sure the vga_pri is under the link */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 507 | if((vga_pri->bus->secondary >= link->secondary ) && |
| 508 | (vga_pri->bus->secondary <= link->subordinate ) |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 509 | ) |
| 510 | #endif |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 511 | break; |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 512 | } |
| 513 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 514 | |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 515 | /* no VGA card installed */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 516 | if (link == NULL) |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 517 | return; |
| 518 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 519 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, link->link_num); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 520 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 521 | /* allocate a temp resource for the legacy VGA buffer */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 522 | resource = new_resource(dev, IOINDEX(4, link->link_num)); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 523 | if(!resource){ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 524 | printk(BIOS_DEBUG, "VGA: %s out of resources.\n", dev_path(dev)); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 525 | return; |
| 526 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 527 | resource->base = 0xa0000; |
| 528 | resource->size = 0x20000; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 529 | resource->limit = 0xffffffff; |
| 530 | resource->flags = IORESOURCE_FIXED | IORESOURCE_MEM | |
| 531 | IORESOURCE_ASSIGNED; |
Li-Ta Lo | 3a81285 | 2004-12-03 22:39:34 +0000 | [diff] [blame] | 532 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 533 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 534 | static void amdk8_set_resources(device_t dev) |
| 535 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 536 | unsigned nodeid; |
| 537 | struct bus *bus; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 538 | struct resource *res; |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 539 | |
| 540 | /* Find the nodeid */ |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 541 | nodeid = amdk8_nodeid(dev); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 542 | |
| 543 | /* Set each resource we have found */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 544 | for(res = dev->resource_list; res; res = res->next) { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 545 | struct resource *old = NULL; |
| 546 | unsigned index; |
| 547 | |
| 548 | if (res->size == 0) /* No need to allocate registers. */ |
| 549 | continue; |
| 550 | |
| 551 | if (res->flags & IORESOURCE_IO) |
| 552 | index = amdk8_find_iopair(dev, nodeid, |
| 553 | IOINDEX_LINK(res->index)); |
| 554 | else |
| 555 | index = amdk8_find_mempair(dev, nodeid, |
| 556 | IOINDEX_LINK(res->index)); |
| 557 | |
| 558 | old = probe_resource(dev, index); |
| 559 | if (old) { |
| 560 | res->index = old->index; |
| 561 | old->index = 0; |
| 562 | old->flags = 0; |
| 563 | } |
| 564 | else |
| 565 | res->index = index; |
| 566 | |
| 567 | amdk8_set_resource(dev, res, nodeid); |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 568 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 569 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 570 | compact_resources(dev); |
| 571 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 572 | for(bus = dev->link_list; bus; bus = bus->next) { |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 573 | if (bus->children) { |
| 574 | assign_resources(bus); |
| 575 | } |
| 576 | } |
| 577 | } |
| 578 | |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 579 | static void mcf0_control_init(struct device *dev) |
David W. Hendricks | 854e452 | 2004-02-09 22:47:38 +0000 | [diff] [blame] | 580 | { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 581 | #if 0 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 582 | printk(BIOS_DEBUG, "NB: Function 0 Misc Control.. "); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 583 | #endif |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 584 | #if 0 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 585 | printk(BIOS_DEBUG, "done.\n"); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 586 | #endif |
Li-Ta Lo | e526669 | 2004-03-23 21:28:05 +0000 | [diff] [blame] | 587 | } |
| 588 | |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 589 | static struct device_operations northbridge_operations = { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 590 | .read_resources = amdk8_read_resources, |
| 591 | .set_resources = amdk8_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 592 | .enable_resources = pci_dev_enable_resources, |
Vladimir Serbinenko | f21271e | 2014-10-16 18:00:27 +0200 | [diff] [blame] | 593 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
Vladimir Serbinenko | 6985d4e | 2014-09-21 14:31:19 +0200 | [diff] [blame] | 594 | .acpi_fill_ssdt_generator = k8acpi_write_vars, |
| 595 | .write_acpi_tables = northbridge_write_acpi_tables, |
| 596 | #endif |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 597 | .init = mcf0_control_init, |
| 598 | .scan_bus = amdk8_scan_chains, |
| 599 | .enable = 0, |
| 600 | .ops_pci = 0, |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 601 | }; |
| 602 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 603 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 604 | static const struct pci_driver mcf0_driver __pci_driver = { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 605 | .ops = &northbridge_operations, |
Eric Biederman | 5cd8173 | 2004-03-11 15:01:31 +0000 | [diff] [blame] | 606 | .vendor = PCI_VENDOR_ID_AMD, |
| 607 | .device = 0x1100, |
| 608 | }; |
| 609 | |
Eric Biederman | 8bd5552 | 2004-11-05 07:04:54 +0000 | [diff] [blame] | 610 | struct chip_operations northbridge_amd_amdk8_ops = { |
| 611 | CHIP_NAME("AMD K8 Northbridge") |
| 612 | .enable_dev = 0, |
| 613 | }; |
| 614 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 615 | static void amdk8_domain_read_resources(device_t dev) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 616 | { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 617 | unsigned reg; |
| 618 | |
| 619 | /* Find the already assigned resource pairs */ |
| 620 | get_fx_devs(); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 621 | for(reg = 0x80; reg <= 0xd8; reg+= 0x08) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 622 | u32 base, limit; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 623 | base = f1_read_config32(reg); |
| 624 | limit = f1_read_config32(reg + 0x04); |
| 625 | /* Is this register allocated? */ |
| 626 | if ((base & 3) != 0) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 627 | unsigned nodeid, reg_link; |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 628 | device_t reg_dev; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 629 | nodeid = limit & 7; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 630 | reg_link = (limit >> 4) & 3; |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 631 | reg_dev = __f0_dev[nodeid]; |
| 632 | if (reg_dev) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 633 | /* Reserve the resource */ |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 634 | struct resource *res; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 635 | res = new_resource(reg_dev, IOINDEX(0x100 + reg, reg_link)); |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 636 | if (res) { |
| 637 | res->base = base; |
| 638 | res->limit = limit; |
| 639 | res->flags = 1; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 640 | } |
| 641 | } |
| 642 | } |
| 643 | } |
Li-Ta Lo | e8b1c9d | 2004-12-27 04:25:41 +0000 | [diff] [blame] | 644 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 645 | pci_domain_read_resources(dev); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 646 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 647 | #if CONFIG_PCI_64BIT_PREF_MEM |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 648 | /* Initialize the system wide prefetchable memory resources constraints */ |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 649 | resource = new_resource(dev, 2); |
| 650 | resource->limit = 0xfcffffffffULL; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 651 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 652 | #endif |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 653 | } |
| 654 | |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 655 | static void my_tolm_test(void *gp, struct device *dev, struct resource *new) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 656 | { |
| 657 | struct resource **best_p = gp; |
| 658 | struct resource *best; |
| 659 | best = *best_p; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 660 | /* Skip VGA. */ |
| 661 | if (!best || (best->base > new->base && new->base > 0xa0000)) { |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 662 | best = new; |
| 663 | } |
| 664 | *best_p = best; |
| 665 | } |
| 666 | |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 667 | static u32 my_find_pci_tolm(struct bus *bus) |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 668 | { |
| 669 | struct resource *min; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 670 | u32 tolm; |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 671 | min = 0; |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 672 | search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, my_tolm_test, &min); |
Eric Biederman | f8a2ddd | 2004-10-30 08:05:41 +0000 | [diff] [blame] | 673 | tolm = 0xffffffffUL; |
| 674 | if (min && tolm > min->base) { |
| 675 | tolm = min->base; |
| 676 | } |
| 677 | return tolm; |
| 678 | } |
| 679 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 680 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 681 | |
| 682 | struct hw_mem_hole_info { |
| 683 | unsigned hole_startk; |
| 684 | int node_id; |
| 685 | }; |
| 686 | |
| 687 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
Jason Schildt | 8b26cab | 2005-10-25 21:24:23 +0000 | [diff] [blame] | 688 | { |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 689 | struct hw_mem_hole_info mem_hole; |
| 690 | int i; |
Jason Schildt | 8b26cab | 2005-10-25 21:24:23 +0000 | [diff] [blame] | 691 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 692 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 693 | mem_hole.node_id = -1; |
Jason Schildt | 8b26cab | 2005-10-25 21:24:23 +0000 | [diff] [blame] | 694 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 695 | for (i = 0; i < fx_devs; i++) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 696 | u32 base; |
| 697 | u32 hole; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 698 | base = f1_read_config32(0x40 + (i << 3)); |
| 699 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 700 | continue; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 701 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 702 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 703 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 704 | if(hole & 1) { // we find the hole |
| 705 | mem_hole.hole_startk = (hole & (0xff<<24)) >> 10; |
| 706 | mem_hole.node_id = i; // record the node No with hole |
| 707 | break; // only one hole |
| 708 | } |
| 709 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 710 | |
Kyösti Mälkki | 2f9b3af | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 711 | /* We need to double check if there is special set on base reg and limit reg |
| 712 | * are not continuous instead of hole, it will find out its hole_startk. |
| 713 | */ |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 714 | if(mem_hole.node_id==-1) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 715 | u32 limitk_pri = 0; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 716 | for(i=0; i<8; i++) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 717 | u32 base, limit; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 718 | unsigned base_k, limit_k; |
| 719 | base = f1_read_config32(0x40 + (i << 3)); |
| 720 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 721 | continue; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 722 | } |
| 723 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 724 | base_k = (base & 0xffff0000) >> 2; |
| 725 | if(limitk_pri != base_k) { // we find the hole |
| 726 | mem_hole.hole_startk = limitk_pri; |
| 727 | mem_hole.node_id = i; |
| 728 | break; //only one hole |
| 729 | } |
| 730 | |
| 731 | limit = f1_read_config32(0x44 + (i << 3)); |
| 732 | limit_k = ((limit + 0x00010000) & 0xffff0000) >> 2; |
| 733 | limitk_pri = limit_k; |
| 734 | } |
| 735 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 736 | return mem_hole; |
Jason Schildt | 8b26cab | 2005-10-25 21:24:23 +0000 | [diff] [blame] | 737 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 738 | |
| 739 | static void disable_hoist_memory(unsigned long hole_startk, int node_id) |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 740 | { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 741 | int i; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 742 | device_t dev; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 743 | u32 base, limit; |
| 744 | u32 hoist; |
| 745 | u32 hole_sizek; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 746 | |
| 747 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 748 | //1. find which node has hole |
| 749 | //2. change limit in that node. |
| 750 | //3. change base and limit in later node |
| 751 | //4. clear that node f0 |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 752 | |
| 753 | //if there is not mem hole enabled, we need to change it's base instead |
| 754 | |
| 755 | hole_sizek = (4*1024*1024) - hole_startk; |
| 756 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 757 | for(i=7;i>node_id;i--) { |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 758 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 759 | base = f1_read_config32(0x40 + (i << 3)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 760 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 761 | continue; |
| 762 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 763 | limit = f1_read_config32(0x44 + (i << 3)); |
| 764 | f1_write_config32(0x44 + (i << 3),limit - (hole_sizek << 2)); |
| 765 | f1_write_config32(0x40 + (i << 3),base - (hole_sizek << 2)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 766 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 767 | limit = f1_read_config32(0x44 + (node_id << 3)); |
| 768 | f1_write_config32(0x44 + (node_id << 3),limit - (hole_sizek << 2)); |
| 769 | dev = __f1_dev[node_id]; |
| 770 | if (dev == NULL) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 771 | printk(BIOS_ERR, "%s: node %x is NULL!\n", __func__, node_id); |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 772 | return; |
| 773 | } |
| 774 | hoist = pci_read_config32(dev, 0xf0); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 775 | if(hoist & 1) { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 776 | pci_write_config32(dev, 0xf0, 0); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 777 | } else { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 778 | base = pci_read_config32(dev, 0x40 + (node_id << 3)); |
| 779 | f1_write_config32(0x40 + (node_id << 3),base - (hole_sizek << 2)); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 780 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 781 | } |
| 782 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 783 | static u32 hoist_memory(unsigned long hole_startk, int node_id) |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 784 | { |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 785 | int i; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 786 | u32 carry_over; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 787 | device_t dev; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 788 | u32 base, limit; |
| 789 | u32 basek; |
| 790 | u32 hoist; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 791 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 792 | carry_over = (4*1024*1024) - hole_startk; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 793 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 794 | for(i=7;i>node_id;i--) { |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 795 | |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 796 | base = f1_read_config32(0x40 + (i << 3)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 797 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 798 | continue; |
| 799 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 800 | limit = f1_read_config32(0x44 + (i << 3)); |
| 801 | f1_write_config32(0x44 + (i << 3),limit + (carry_over << 2)); |
| 802 | f1_write_config32(0x40 + (i << 3),base + (carry_over << 2)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 803 | } |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 804 | limit = f1_read_config32(0x44 + (node_id << 3)); |
| 805 | f1_write_config32(0x44 + (node_id << 3),limit + (carry_over << 2)); |
| 806 | dev = __f1_dev[node_id]; |
| 807 | base = pci_read_config32(dev, 0x40 + (node_id << 3)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 808 | basek = (base & 0xffff0000) >> 2; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 809 | if(basek == hole_startk) { |
| 810 | //don't need set memhole here, because hole off set will be 0, overflow |
| 811 | //so need to change base reg instead, new basek will be 4*1024*1024 |
| 812 | base &= 0x0000ffff; |
| 813 | base |= (4*1024*1024)<<2; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 814 | f1_write_config32(0x40 + (node_id<<3), base); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 815 | } |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 816 | else if (dev) |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 817 | { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 818 | hoist = /* hole start address */ |
| 819 | ((hole_startk << 10) & 0xff000000) + |
| 820 | /* hole address to memory controller address */ |
| 821 | (((basek + carry_over) >> 6) & 0x0000ff00) + |
| 822 | /* enable */ |
| 823 | 1; |
| 824 | |
| 825 | pci_write_config32(dev, 0xf0, hoist); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 826 | } |
| 827 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 828 | return carry_over; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 829 | } |
| 830 | #endif |
Jason Schildt | 8b26cab | 2005-10-25 21:24:23 +0000 | [diff] [blame] | 831 | |
Rudolf Marek | bcaea14 | 2010-11-22 22:00:52 +0000 | [diff] [blame] | 832 | #include <cbmem.h> |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 833 | |
Kyösti Mälkki | 6b5eb1c | 2012-07-19 19:26:43 +0300 | [diff] [blame] | 834 | static void setup_uma_memory(void) |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 835 | { |
| 836 | #if CONFIG_GFXUMA |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 837 | uint32_t topmem = (uint32_t) bsp_topmem(); |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 838 | |
| 839 | #if !CONFIG_BOARD_ASROCK_939A785GMH && !CONFIG_BOARD_AMD_MAHOGANY |
| 840 | |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 841 | switch (topmem) { |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 842 | case 0x10000000: /* 256M system memory */ |
| 843 | uma_memory_size = 0x2000000; /* 32M recommended UMA */ |
| 844 | break; |
| 845 | |
| 846 | case 0x18000000: /* 384M system memory */ |
| 847 | uma_memory_size = 0x4000000; /* 64M recommended UMA */ |
| 848 | break; |
| 849 | |
| 850 | case 0x20000000: /* 512M system memory */ |
| 851 | uma_memory_size = 0x4000000; /* 64M recommended UMA */ |
| 852 | break; |
| 853 | |
| 854 | default: /* 1GB and above system memory */ |
| 855 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 856 | break; |
| 857 | } |
| 858 | #else |
| 859 | /* refer to UMA Size Consideration in 780 BDG. */ |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 860 | switch (topmem) { |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 861 | case 0x10000000: /* 256M system memory */ |
| 862 | uma_memory_size = 0x4000000; /* 64M recommended UMA */ |
| 863 | break; |
| 864 | |
| 865 | case 0x20000000: /* 512M system memory */ |
| 866 | uma_memory_size = 0x8000000; /* 128M recommended UMA */ |
| 867 | break; |
| 868 | |
| 869 | default: /* 1GB and above system memory */ |
| 870 | uma_memory_size = 0x10000000; /* 256M recommended UMA */ |
| 871 | break; |
| 872 | } |
| 873 | #endif |
| 874 | |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 875 | uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */ |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 876 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 877 | __func__, uma_memory_size, uma_memory_base); |
Kyösti Mälkki | ba589e3 | 2012-07-11 08:03:13 +0300 | [diff] [blame] | 878 | #endif |
| 879 | } |
| 880 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 881 | static void amdk8_domain_set_resources(device_t dev) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 882 | { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 883 | #if CONFIG_PCI_64BIT_PREF_MEM |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 884 | struct resource *io, *mem1, *mem2; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 885 | struct resource *res; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 886 | #endif |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 887 | unsigned long mmio_basek; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 888 | u32 pci_tolm; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 889 | u64 ramtop = 0; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 890 | int i, idx; |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 891 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 892 | struct hw_mem_hole_info mem_hole; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 893 | u32 reset_memhole = 1; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 894 | #endif |
| 895 | |
| 896 | #if 0 |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 897 | /* Place the IO devices somewhere safe */ |
| 898 | io = find_resource(dev, 0); |
| 899 | io->base = DEVICE_IO_START; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 900 | #endif |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 901 | #if CONFIG_PCI_64BIT_PREF_MEM |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 902 | /* Now reallocate the pci resources memory with the |
| 903 | * highest addresses I can manage. |
| 904 | */ |
| 905 | mem1 = find_resource(dev, 1); |
| 906 | mem2 = find_resource(dev, 2); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 907 | |
| 908 | #if 1 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 909 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 910 | mem1->base, mem1->limit, mem1->size, mem1->align); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 911 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 912 | mem2->base, mem2->limit, mem2->size, mem2->align); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 913 | #endif |
| 914 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 915 | /* See if both resources have roughly the same limits */ |
| 916 | if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff)) || |
| 917 | ((mem1->limit > 0xffffffff) && (mem2->limit > 0xffffffff))) |
| 918 | { |
| 919 | /* If so place the one with the most stringent alignment first |
| 920 | */ |
| 921 | if (mem2->align > mem1->align) { |
| 922 | struct resource *tmp; |
| 923 | tmp = mem1; |
| 924 | mem1 = mem2; |
| 925 | mem2 = tmp; |
| 926 | } |
| 927 | /* Now place the memory as high up as it will go */ |
| 928 | mem2->base = resource_max(mem2); |
| 929 | mem1->limit = mem2->base - 1; |
| 930 | mem1->base = resource_max(mem1); |
| 931 | } |
| 932 | else { |
| 933 | /* Place the resources as high up as they will go */ |
| 934 | mem2->base = resource_max(mem2); |
| 935 | mem1->base = resource_max(mem1); |
| 936 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 937 | |
| 938 | #if 1 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 939 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 940 | mem1->base, mem1->limit, mem1->size, mem1->align); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 941 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 942 | mem2->base, mem2->limit, mem2->size, mem2->align); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 943 | #endif |
| 944 | |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 945 | for(res = dev->resource_list; res; res = res->next) |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 946 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 947 | res->flags |= IORESOURCE_ASSIGNED; |
| 948 | res->flags |= IORESOURCE_STORED; |
| 949 | report_resource_stored(dev, res, ""); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 950 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 951 | #endif |
| 952 | |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 953 | pci_tolm = my_find_pci_tolm(dev->link_list); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 954 | |
Stefan Reinauer | 29ceae2 | 2010-04-20 11:03:41 +0000 | [diff] [blame] | 955 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 956 | // amdfam10, too. |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 957 | mmio_basek = pci_tolm >> 10; |
| 958 | /* Round mmio_basek to something the processor can support */ |
| 959 | mmio_basek &= ~((1 << 6) -1); |
| 960 | |
Stefan Reinauer | 29ceae2 | 2010-04-20 11:03:41 +0000 | [diff] [blame] | 961 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 962 | // MMIO hole. If you fix this here, please fix amdfam10, too. |
Stefan Reinauer | d4f5373 | 2010-04-09 14:46:51 +0000 | [diff] [blame] | 963 | /* Round the mmio hole to 64M */ |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 964 | mmio_basek &= ~((64*1024) - 1); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 965 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 966 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 967 | /* if the hw mem hole is already set in raminit stage, here we will compare mmio_basek and hole_basek |
| 968 | * if mmio_basek is bigger that hole_basek and will use hole_basek as mmio_basek and we don't need to reset hole. |
| 969 | * otherwise We reset the hole to the mmio_basek |
| 970 | */ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 971 | #if !CONFIG_K8_REV_F_SUPPORT |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 972 | if (!is_cpu_pre_e0()) { |
| 973 | #endif |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 974 | |
| 975 | mem_hole = get_hw_mem_hole_info(); |
| 976 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 977 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { //We will use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 978 | mmio_basek = mem_hole.hole_startk; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 979 | reset_memhole = 0; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 980 | } |
| 981 | |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 982 | //mmio_basek = 3*1024*1024; // for debug to meet boundary |
| 983 | |
| 984 | if(reset_memhole) { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 985 | if(mem_hole.node_id!=-1) { // We need to select CONFIG_HW_MEM_HOLE_SIZEK for raminit, it can not make hole_startk to some basek too....! |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 986 | // We need to reset our Mem Hole, because We want more big HOLE than we already set |
| 987 | //Before that We need to disable mem hole at first, becase memhole could already be set on i+1 instead |
| 988 | disable_hoist_memory(mem_hole.hole_startk, mem_hole.node_id); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 989 | } |
| 990 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 991 | #if CONFIG_HW_MEM_HOLE_SIZE_AUTO_INC |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 992 | //We need to double check if the mmio_basek is valid for hole setting, if it is equal to basek, we need to decrease it some |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 993 | u32 basek_pri; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 994 | for (i = 0; i < fx_devs; i++) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 995 | u32 base; |
| 996 | u32 basek; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 997 | base = f1_read_config32(0x40 + (i << 3)); |
| 998 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 999 | continue; |
| 1000 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1001 | |
| 1002 | basek = (base & 0xffff0000) >> 2; |
| 1003 | if(mmio_basek == basek) { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1004 | mmio_basek -= (basek - basek_pri)>>1; // increase mem hole size to make sure it is on middle of pri node |
| 1005 | break; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1006 | } |
| 1007 | basek_pri = basek; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1008 | } |
| 1009 | #endif |
| 1010 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1011 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1012 | #if !CONFIG_K8_REV_F_SUPPORT |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1013 | } // is_cpu_pre_e0 |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1014 | #endif |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1015 | |
| 1016 | #endif |
| 1017 | |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 1018 | idx = 0x10; |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 1019 | for(i = 0; i < fx_devs; i++) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1020 | u32 base, limit; |
| 1021 | u32 basek, limitk, sizek; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1022 | base = f1_read_config32(0x40 + (i << 3)); |
| 1023 | limit = f1_read_config32(0x44 + (i << 3)); |
| 1024 | if ((base & ((1<<1)|(1<<0))) != ((1<<1)|(1<<0))) { |
| 1025 | continue; |
| 1026 | } |
| 1027 | basek = (base & 0xffff0000) >> 2; |
| 1028 | limitk = ((limit + 0x00010000) & 0xffff0000) >> 2; |
| 1029 | sizek = limitk - basek; |
| 1030 | |
| 1031 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 1032 | if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) { |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 1033 | ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek); |
| 1034 | idx += 0x10; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1035 | basek = (8*64)+(16*16); |
| 1036 | sizek = limitk - ((8*64)+(16*16)); |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1037 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1038 | } |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 1039 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1040 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1041 | #if CONFIG_GFXUMA |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 1042 | printk(BIOS_DEBUG, "node %d : uma_memory_base/1024=0x%08llx, mmio_basek=0x%08lx, basek=0x%08x, limitk=0x%08x\n", i, uma_memory_base >> 10, mmio_basek, basek, limitk); |
Stefan Reinauer | 8f3b858 | 2009-10-24 12:40:52 +0000 | [diff] [blame] | 1043 | if ((uma_memory_base >> 10) < mmio_basek) |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1044 | printk(BIOS_ALERT, "node %d: UMA memory starts below mmio_basek\n", i); |
Stefan Reinauer | 8f3b858 | 2009-10-24 12:40:52 +0000 | [diff] [blame] | 1045 | #else |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1046 | // printk(BIOS_DEBUG, "node %d : mmio_basek=%08x, basek=%08x, limitk=%08x\n", i, mmio_basek, basek, limitk); //yhlu |
Stefan Reinauer | 8f3b858 | 2009-10-24 12:40:52 +0000 | [diff] [blame] | 1047 | #endif |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1048 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 1049 | /* See if I need to split the region to accommodate pci memory space */ |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1050 | if ( (basek < 4*1024*1024 ) && (limitk > mmio_basek) ) { |
| 1051 | if (basek <= mmio_basek) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1052 | unsigned pre_sizek; |
| 1053 | pre_sizek = mmio_basek - basek; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1054 | if(pre_sizek>0) { |
| 1055 | ram_resource(dev, (idx | i), basek, pre_sizek); |
| 1056 | idx += 0x10; |
| 1057 | sizek -= pre_sizek; |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 1058 | if (!ramtop) |
| 1059 | ramtop = mmio_basek * 1024; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1060 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1061 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1062 | if(reset_memhole) |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1063 | #if !CONFIG_K8_REV_F_SUPPORT |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1064 | if(!is_cpu_pre_e0() ) |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1065 | #endif |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1066 | sizek += hoist_memory(mmio_basek,i); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1067 | #endif |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1068 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1069 | basek = mmio_basek; |
| 1070 | } |
| 1071 | if ((basek + sizek) <= 4*1024*1024) { |
| 1072 | sizek = 0; |
| 1073 | } |
| 1074 | else { |
| 1075 | basek = 4*1024*1024; |
| 1076 | sizek -= (4*1024*1024 - mmio_basek); |
| 1077 | } |
| 1078 | } |
Kyösti Mälkki | de3dde4 | 2012-07-10 13:10:24 +0300 | [diff] [blame] | 1079 | |
| 1080 | ram_resource(dev, (idx | i), basek, sizek); |
Stefan Reinauer | f622d59 | 2005-11-26 16:56:05 +0000 | [diff] [blame] | 1081 | idx += 0x10; |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1082 | printk(BIOS_DEBUG, "%d: mmio_basek=%08lx, basek=%08x, limitk=%08x\n", |
Myles Watson | 283a494 | 2009-03-10 20:39:27 +0000 | [diff] [blame] | 1083 | i, mmio_basek, basek, limitk); |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 1084 | if (!ramtop) |
| 1085 | ramtop = limitk * 1024; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1086 | } |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 1087 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1088 | #if CONFIG_GFXUMA |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 1089 | set_top_of_ram(uma_memory_base); |
Kyösti Mälkki | 63f8c08 | 2012-07-10 13:27:26 +0300 | [diff] [blame] | 1090 | uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10); |
Kyösti Mälkki | 2b790f6 | 2013-09-03 05:25:57 +0300 | [diff] [blame] | 1091 | #else |
| 1092 | set_top_of_ram(ramtop); |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 1093 | #endif |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1094 | assign_resources(dev->link_list); |
Myles Watson | 283a494 | 2009-03-10 20:39:27 +0000 | [diff] [blame] | 1095 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1096 | } |
| 1097 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1098 | static u32 amdk8_domain_scan_bus(device_t dev, u32 max) |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1099 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1100 | u32 reg; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1101 | int i; |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 1102 | struct bus *link = dev->link_list; |
| 1103 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1104 | /* Unmap all of the HT chains */ |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1105 | for(reg = 0xe0; reg <= 0xec; reg += 4) { |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1106 | f1_write_config32(reg, 0); |
| 1107 | } |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame^] | 1108 | |
| 1109 | link->secondary = dev->bus->subordinate; |
| 1110 | link->subordinate = pci_scan_bus(link, PCI_DEVFN(0x18, 0), 0xff, link->secondary); |
| 1111 | dev->bus->subordinate = link->subordinate; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1112 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1113 | /* Tune the hypertransport transaction for best performance. |
| 1114 | * Including enabling relaxed ordering if it is safe. |
| 1115 | */ |
| 1116 | get_fx_devs(); |
Myles Watson | c7233e0 | 2009-07-02 19:02:33 +0000 | [diff] [blame] | 1117 | for(i = 0; i < fx_devs; i++) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1118 | device_t f0_dev; |
| 1119 | f0_dev = __f0_dev[i]; |
| 1120 | if (f0_dev && f0_dev->enabled) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1121 | u32 httc; |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1122 | httc = pci_read_config32(f0_dev, HT_TRANSACTION_CONTROL); |
| 1123 | httc &= ~HTTC_RSP_PASS_PW; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1124 | if (!dev->link_list->disable_relaxed_ordering) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1125 | httc |= HTTC_RSP_PASS_PW; |
| 1126 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1127 | printk(BIOS_SPEW, "%s passpw: %s\n", |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1128 | dev_path(dev), |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1129 | (!dev->link_list->disable_relaxed_ordering)? |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1130 | "enabled":"disabled"); |
| 1131 | pci_write_config32(f0_dev, HT_TRANSACTION_CONTROL, httc); |
| 1132 | } |
| 1133 | } |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1134 | return max; |
| 1135 | } |
| 1136 | |
| 1137 | static struct device_operations pci_domain_ops = { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1138 | .read_resources = amdk8_domain_read_resources, |
| 1139 | .set_resources = amdk8_domain_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1140 | .enable_resources = NULL, |
| 1141 | .init = NULL, |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1142 | .scan_bus = amdk8_domain_scan_bus, |
Kyösti Mälkki | 33e5df3 | 2013-07-03 10:51:34 +0300 | [diff] [blame] | 1143 | .ops_pci_bus = pci_bus_default_ops, |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1144 | }; |
| 1145 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1146 | static void add_more_links(device_t dev, unsigned total_links) |
| 1147 | { |
| 1148 | struct bus *link, *last = NULL; |
Kyösti Mälkki | c0ee937 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1149 | int link_num = -1; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1150 | |
Kyösti Mälkki | c0ee937 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1151 | for (link = dev->link_list; link; link = link->next) { |
| 1152 | if (link_num < link->link_num) |
| 1153 | link_num = link->link_num; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1154 | last = link; |
Kyösti Mälkki | c0ee937 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1155 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1156 | |
| 1157 | if (last) { |
Kyösti Mälkki | c0ee937 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1158 | int links = total_links - (link_num + 1); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1159 | if (links > 0) { |
| 1160 | link = malloc(links*sizeof(*link)); |
| 1161 | if (!link) |
| 1162 | die("Couldn't allocate more links!\n"); |
| 1163 | memset(link, 0, links*sizeof(*link)); |
| 1164 | last->next = link; |
| 1165 | } |
| 1166 | } |
| 1167 | else { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1168 | link = malloc(total_links*sizeof(*link)); |
| 1169 | memset(link, 0, total_links*sizeof(*link)); |
| 1170 | dev->link_list = link; |
| 1171 | } |
| 1172 | |
| 1173 | for (link_num = link_num + 1; link_num < total_links; link_num++) { |
| 1174 | link->link_num = link_num; |
| 1175 | link->dev = dev; |
| 1176 | link->next = link + 1; |
| 1177 | last = link; |
| 1178 | link = link->next; |
| 1179 | } |
| 1180 | last->next = NULL; |
| 1181 | } |
| 1182 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1183 | static u32 cpu_bus_scan(device_t dev, u32 max) |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1184 | { |
| 1185 | struct bus *cpu_bus; |
Yinghai Lu | 90a04ee | 2005-01-07 21:12:05 +0000 | [diff] [blame] | 1186 | device_t dev_mc; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1187 | int bsp_apicid; |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 1188 | int i,j; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1189 | unsigned nb_cfg_54; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1190 | unsigned siblings; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1191 | int e0_later_single_core; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 1192 | int disable_siblings; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1193 | |
| 1194 | nb_cfg_54 = 0; |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1195 | sysconf.enabled_apic_ext_id = 0; |
| 1196 | sysconf.lift_bsp_apicid = 0; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1197 | siblings = 0; |
| 1198 | |
| 1199 | /* Find the bootstrap processors apicid */ |
| 1200 | bsp_apicid = lapicid(); |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1201 | sysconf.apicid_offset = bsp_apicid; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1202 | |
| 1203 | disable_siblings = !CONFIG_LOGICAL_CPUS; |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1204 | #if CONFIG_LOGICAL_CPUS |
Myles Watson | 4839e2c | 2010-04-08 15:06:44 +0000 | [diff] [blame] | 1205 | get_option(&disable_siblings, "multi_core"); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1206 | #endif |
| 1207 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1208 | // for pre_e0, nb_cfg_54 can not be set, (when you read it still is 0) |
| 1209 | // How can I get the nb_cfg_54 of every node's nb_cfg_54 in bsp??? |
| 1210 | // and differ d0 and e0 single core |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1211 | nb_cfg_54 = read_nb_cfg_54(); |
Yinghai Lu | 90a04ee | 2005-01-07 21:12:05 +0000 | [diff] [blame] | 1212 | |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 1213 | dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0)); |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1214 | if (!dev_mc) { |
| 1215 | die("0:18.0 not found?"); |
| 1216 | } |
arch import user (historical) | ef03afa | 2005-07-06 17:15:30 +0000 | [diff] [blame] | 1217 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1218 | sysconf.nodes = ((pci_read_config32(dev_mc, 0x60)>>4) & 7) + 1; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1219 | |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1220 | |
| 1221 | if (pci_read_config32(dev_mc, 0x68) & (HTTC_APIC_EXT_ID|HTTC_APIC_EXT_BRD_CST)) |
| 1222 | { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1223 | sysconf.enabled_apic_ext_id = 1; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1224 | if(bsp_apicid == 0) { |
| 1225 | /* bsp apic id is not changed */ |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1226 | sysconf.apicid_offset = CONFIG_APIC_ID_OFFSET; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1227 | } else |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1228 | { |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1229 | sysconf.lift_bsp_apicid = 1; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1230 | } |
| 1231 | |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1232 | } |
| 1233 | |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1234 | /* Find which cpus are present */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1235 | cpu_bus = dev->link_list; |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1236 | |
| 1237 | /* Always use the devicetree node with lapic_id 0 for BSP. */ |
| 1238 | remap_bsp_lapic(cpu_bus); |
| 1239 | |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1240 | for(i = 0; i < sysconf.nodes; i++) { |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1241 | device_t cpu_dev; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1242 | |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1243 | /* Find the cpu's pci device */ |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 1244 | cpu_dev = dev_find_slot(0, PCI_DEVFN(0x18 + i, 3)); |
| 1245 | if (!cpu_dev) { |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1246 | /* If I am probing things in a weird order |
| 1247 | * ensure all of the cpu's pci devices are found. |
| 1248 | */ |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 1249 | int local_j; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1250 | device_t dev_f0; |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 1251 | for(local_j = 0; local_j <= 3; local_j++) { |
| 1252 | cpu_dev = pci_probe_dev(NULL, dev_mc->bus, |
| 1253 | PCI_DEVFN(0x18 + i, local_j)); |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1254 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1255 | /* Ok, We need to set the links for that device. |
| 1256 | * otherwise the device under it will not be scanned |
| 1257 | */ |
| 1258 | dev_f0 = dev_find_slot(0, PCI_DEVFN(0x18+i,0)); |
| 1259 | if(dev_f0) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1260 | add_more_links(dev_f0, 3); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1261 | } |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1262 | } |
| 1263 | |
| 1264 | e0_later_single_core = 0; |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1265 | int enable_node = cpu_dev && cpu_dev->enabled; |
| 1266 | if (enable_node) { |
Myles Watson | fa12b67 | 2009-04-30 22:45:41 +0000 | [diff] [blame] | 1267 | j = pci_read_config32(cpu_dev, 0xe8); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1268 | j = (j >> 12) & 3; // dev is func 3 |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1269 | printk(BIOS_DEBUG, " %s siblings=%d\n", dev_path(cpu_dev), j); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1270 | |
| 1271 | if(nb_cfg_54) { |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1272 | // For e0 single core if nb_cfg_54 is set, apicid will be 0, 2, 4.... |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1273 | // ----> you can mixed single core e0 and dual core e0 at any sequence |
| 1274 | // That is the typical case |
| 1275 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1276 | if(j == 0 ){ |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1277 | #if !CONFIG_K8_REV_F_SUPPORT |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1278 | e0_later_single_core = is_e0_later_in_bsp(i); // single core |
Yinghai Lu | d4b278c | 2006-10-04 20:46:15 +0000 | [diff] [blame] | 1279 | #else |
| 1280 | e0_later_single_core = is_cpu_f0_in_bsp(i); // We can read cpuid(1) from Func3 |
| 1281 | #endif |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1282 | } else { |
| 1283 | e0_later_single_core = 0; |
| 1284 | } |
| 1285 | if(e0_later_single_core) { |
Stefan Reinauer | 64ed2b7 | 2010-03-31 14:47:43 +0000 | [diff] [blame] | 1286 | printk(BIOS_DEBUG, "\tFound Rev E or Rev F later single core\n"); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1287 | |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1288 | j=1; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1289 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1290 | |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1291 | if(siblings > j ) { |
| 1292 | } |
| 1293 | else { |
| 1294 | siblings = j; |
| 1295 | } |
| 1296 | } else { |
| 1297 | siblings = j; |
| 1298 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1299 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1300 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1301 | u32 jj; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1302 | if(e0_later_single_core || disable_siblings) { |
| 1303 | jj = 0; |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1304 | } else |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1305 | { |
| 1306 | jj = siblings; |
| 1307 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1308 | |
| 1309 | for (j = 0; j <=jj; j++ ) { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1310 | u32 apic_id = i * (nb_cfg_54?(siblings+1):1) + j * (nb_cfg_54?1:8); |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1311 | if(sysconf.enabled_apic_ext_id) { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1312 | if (apic_id != 0 || sysconf.lift_bsp_apicid) { |
| 1313 | apic_id += sysconf.apicid_offset; |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1314 | } |
Yinghai Lu | 13f1c2a | 2005-07-08 02:49:49 +0000 | [diff] [blame] | 1315 | } |
Myles Watson | d61ada6 | 2008-10-02 19:20:22 +0000 | [diff] [blame] | 1316 | |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1317 | device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
| 1318 | if (cpu) |
| 1319 | amd_cpu_topology(cpu, i, j); |
Stefan Reinauer | f5183cf | 2005-12-01 11:01:01 +0000 | [diff] [blame] | 1320 | } //j |
| 1321 | } |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1322 | return max; |
| 1323 | } |
| 1324 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1325 | static void cpu_bus_init(device_t dev) |
| 1326 | { |
Kyösti Mälkki | 7bdf85b | 2012-07-07 13:42:03 +0300 | [diff] [blame] | 1327 | #if CONFIG_WAIT_BEFORE_CPUS_INIT |
| 1328 | cpus_ready_for_init(); |
| 1329 | #endif |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1330 | initialize_cpus(dev->link_list); |
Eric Biederman | f3ed1cf | 2004-10-16 08:38:58 +0000 | [diff] [blame] | 1331 | } |
| 1332 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1333 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 812d2a4 | 2014-10-31 08:17:23 +1100 | [diff] [blame] | 1334 | .read_resources = DEVICE_NOOP, |
| 1335 | .set_resources = DEVICE_NOOP, |
| 1336 | .enable_resources = DEVICE_NOOP, |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1337 | .init = cpu_bus_init, |
| 1338 | .scan_bus = cpu_bus_scan, |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1339 | }; |
| 1340 | |
Eric Biederman | 8bd5552 | 2004-11-05 07:04:54 +0000 | [diff] [blame] | 1341 | static void root_complex_enable_dev(struct device *dev) |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 1342 | { |
Kyösti Mälkki | 87213b6 | 2012-08-27 20:00:33 +0300 | [diff] [blame] | 1343 | static int done = 0; |
| 1344 | |
| 1345 | /* Do not delay UMA setup, as a device on the PCI bus may evaluate |
| 1346 | the global uma_memory variables already in its enable function. */ |
| 1347 | if (!done) { |
| 1348 | setup_bsp_ramtop(); |
| 1349 | setup_uma_memory(); |
| 1350 | done = 1; |
| 1351 | } |
| 1352 | |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1353 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1354 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1355 | dev->ops = &pci_domain_ops; |
| 1356 | } |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 1357 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Eric Biederman | 7003ba4 | 2004-10-16 06:20:29 +0000 | [diff] [blame] | 1358 | dev->ops = &cpu_bus_ops; |
Eric Biederman | b78c197 | 2004-10-14 20:54:17 +0000 | [diff] [blame] | 1359 | } |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 1360 | } |
| 1361 | |
Eric Biederman | 8bd5552 | 2004-11-05 07:04:54 +0000 | [diff] [blame] | 1362 | struct chip_operations northbridge_amd_amdk8_root_complex_ops = { |
| 1363 | CHIP_NAME("AMD K8 Root Complex") |
| 1364 | .enable_dev = root_complex_enable_dev, |
Eric Biederman | 0ac6b41 | 2003-09-02 17:16:48 +0000 | [diff] [blame] | 1365 | }; |