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