Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 3 | * |
Timothy Pearson | e538dae | 2015-01-23 20:26:03 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007 Advanced Micro Devices, Inc. |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <arch/io.h> |
| 23 | #include <stdint.h> |
| 24 | #include <device/device.h> |
| 25 | #include <device/pci.h> |
| 26 | #include <device/pci_ids.h> |
| 27 | #include <device/hypertransport.h> |
| 28 | #include <stdlib.h> |
| 29 | #include <string.h> |
Ronald G. Minnich | 5079a0d | 2012-11-27 11:32:38 -0800 | [diff] [blame] | 30 | #include <lib.h> |
Timothy Pearson | 6e523a6 | 2015-03-27 22:58:45 -0500 | [diff] [blame] | 31 | #include <smbios.h> |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 32 | #include <cpu/cpu.h> |
| 33 | |
| 34 | #include <cpu/x86/lapic.h> |
Kyösti Mälkki | 231f261 | 2012-07-11 08:02:57 +0300 | [diff] [blame] | 35 | #include <cpu/amd/mtrr.h> |
Kyösti Mälkki | 991a71d | 2015-02-22 00:12:43 +0200 | [diff] [blame] | 36 | #include <cpu/amd/amdfam10_sysconf.h> |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 37 | #include <cpu/amd/model_10xxx/ram_calc.h> |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 38 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 39 | #if CONFIG_LOGICAL_CPUS |
Stefan Reinauer | 9a16e3e | 2010-03-29 14:45:36 +0000 | [diff] [blame] | 40 | #include <cpu/amd/multicore.h> |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 41 | #include <pc80/mc146818rtc.h> |
| 42 | #endif |
| 43 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 44 | #include "northbridge.h" |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 45 | #include "amdfam10.h" |
Kyösti Mälkki | 991a71d | 2015-02-22 00:12:43 +0200 | [diff] [blame] | 46 | #include "ht_config.h" |
Timothy Pearson | 6e523a6 | 2015-03-27 22:58:45 -0500 | [diff] [blame] | 47 | #include "chip.h" |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 49 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 50 | #include <cpu/amd/model_10xxx_rev.h> |
| 51 | #endif |
| 52 | |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 53 | #if CONFIG_AMD_SB_CIMX |
| 54 | #include <sb_cimx.h> |
| 55 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 56 | |
| 57 | struct amdfam10_sysconf_t sysconf; |
| 58 | |
| 59 | #define FX_DEVS NODE_NUMS |
| 60 | static device_t __f0_dev[FX_DEVS]; |
Kyösti Mälkki | 991a71d | 2015-02-22 00:12:43 +0200 | [diff] [blame] | 61 | device_t __f1_dev[FX_DEVS]; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 62 | static device_t __f2_dev[FX_DEVS]; |
| 63 | static device_t __f4_dev[FX_DEVS]; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 64 | static unsigned fx_devs=0; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 65 | |
| 66 | device_t get_node_pci(u32 nodeid, u32 fn) |
| 67 | { |
zbao | 49bb26a4 | 2012-08-03 15:44:42 +0800 | [diff] [blame] | 68 | #if NODE_NUMS + CONFIG_CDB >= 32 |
| 69 | if((CONFIG_CDB + nodeid) < 32) { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 70 | return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 71 | } else { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 72 | return dev_find_slot(CONFIG_CBB-1, PCI_DEVFN(CONFIG_CDB + nodeid - 32, fn)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | #else |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 76 | return dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB + nodeid, fn)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 77 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 78 | } |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 79 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 80 | static void get_fx_devs(void) |
| 81 | { |
| 82 | int i; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 83 | for(i = 0; i < FX_DEVS; i++) { |
| 84 | __f0_dev[i] = get_node_pci(i, 0); |
| 85 | __f1_dev[i] = get_node_pci(i, 1); |
| 86 | __f2_dev[i] = get_node_pci(i, 2); |
| 87 | __f4_dev[i] = get_node_pci(i, 4); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 88 | if (__f0_dev[i] != NULL && __f1_dev[i] != NULL) |
| 89 | fx_devs = i+1; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 90 | } |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 91 | if (__f1_dev[0] == NULL || __f0_dev[0] == NULL || fx_devs == 0) { |
| 92 | die("Cannot find 0:0x18.[0|1]\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 93 | } |
| 94 | } |
| 95 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 96 | static u32 f1_read_config32(unsigned reg) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 97 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 98 | if (fx_devs == 0) |
| 99 | get_fx_devs(); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 100 | return pci_read_config32(__f1_dev[0], reg); |
| 101 | } |
| 102 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 103 | static void f1_write_config32(unsigned reg, u32 value) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 104 | { |
| 105 | int i; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 106 | if (fx_devs == 0) |
| 107 | get_fx_devs(); |
| 108 | for(i = 0; i < fx_devs; i++) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 109 | device_t dev; |
| 110 | dev = __f1_dev[i]; |
| 111 | if (dev && dev->enabled) { |
| 112 | pci_write_config32(dev, reg, value); |
| 113 | } |
| 114 | } |
| 115 | } |
| 116 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 117 | static u32 amdfam10_nodeid(device_t dev) |
| 118 | { |
| 119 | #if NODE_NUMS == 64 |
| 120 | unsigned busn; |
| 121 | busn = dev->bus->secondary; |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 122 | if(busn != CONFIG_CBB) { |
| 123 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB + 32; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 124 | } else { |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 125 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | #else |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 129 | return (dev->path.pci.devfn >> 3) - CONFIG_CDB; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 130 | #endif |
| 131 | } |
| 132 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 133 | static void set_vga_enable_reg(u32 nodeid, u32 linkn) |
| 134 | { |
| 135 | u32 val; |
| 136 | |
| 137 | val = 1 | (nodeid<<4) | (linkn<<12); |
| 138 | /* it will routing (1)mmio 0xa0000:0xbffff (2) io 0x3b0:0x3bb, |
| 139 | 0x3c0:0x3df */ |
| 140 | f1_write_config32(0xf4, val); |
| 141 | |
| 142 | } |
| 143 | |
Kyösti Mälkki | e40beb1 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 144 | static bool is_non_coherent_link(struct device *dev, struct bus *link) |
| 145 | { |
| 146 | u32 link_type; |
| 147 | do { |
| 148 | link_type = pci_read_config32(dev, link->cap + 0x18); |
| 149 | } while (link_type & ConnectionPending); |
| 150 | |
| 151 | if (!(link_type & LinkConnected)) |
| 152 | return false; |
| 153 | |
| 154 | do { |
| 155 | link_type = pci_read_config32(dev, link->cap + 0x18); |
| 156 | } while (!(link_type & InitComplete)); |
| 157 | |
| 158 | return !!(link_type & NonCoherent); |
| 159 | } |
| 160 | |
Kyösti Mälkki | 20968c9 | 2015-02-23 12:05:33 +0200 | [diff] [blame^] | 161 | typedef enum { |
| 162 | HT_ROUTE_CLOSE, |
| 163 | HT_ROUTE_SCAN, |
| 164 | HT_ROUTE_FINAL, |
| 165 | } scan_state; |
| 166 | |
| 167 | static void ht_route_link(struct bus *link, scan_state mode) |
| 168 | { |
| 169 | struct bus *parent = link->dev->bus; |
| 170 | u32 busses; |
| 171 | |
| 172 | /* Configure the bus numbers for this bridge: the configuration |
| 173 | * transactions will not be propagated by the bridge if it is |
| 174 | * not correctly configured |
| 175 | */ |
| 176 | busses = pci_read_config32(link->dev, link->cap + 0x14); |
| 177 | busses &= 0xff000000; |
| 178 | busses |= parent->secondary & 0xff; |
| 179 | if (mode == HT_ROUTE_CLOSE) { |
| 180 | busses |= 0xfeff << 8; |
| 181 | } else if (mode == HT_ROUTE_SCAN) { |
| 182 | busses |= ((u32) link->secondary & 0xff) << 8; |
| 183 | busses |= 0xfc << 16; |
| 184 | } else if (mode == HT_ROUTE_FINAL) { |
| 185 | busses |= ((u32) link->secondary & 0xff) << 8; |
| 186 | busses |= ((u32) link->subordinate & 0xff) << 16; |
| 187 | } |
| 188 | pci_write_config32(link->dev, link->cap + 0x14, busses); |
| 189 | |
| 190 | } |
| 191 | |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 192 | static u32 amdfam10_scan_chain(device_t dev, u32 nodeid, struct bus *link, bool is_sblink, |
| 193 | u32 max) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 194 | { |
| 195 | // I want to put sb chain in bus 0 can I? |
| 196 | |
| 197 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 198 | int i; |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 199 | unsigned int next_unitid; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 200 | u32 ht_c_index; |
| 201 | u32 ht_unitid_base[4]; // here assume only 4 HT device on chain |
| 202 | u32 max_bus; |
| 203 | u32 min_bus; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 204 | #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 1 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 205 | u32 busn = max&0xff; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 206 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 207 | u32 max_devfn; |
| 208 | |
Kyösti Mälkki | e40beb1 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 209 | /* Check for connected link. */ |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 210 | link->cap = 0x80 + (link->link_num * 0x20); |
Kyösti Mälkki | 7255062 | 2015-02-04 15:37:45 +0200 | [diff] [blame] | 211 | if (!is_non_coherent_link(dev, link)) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 212 | return max; |
Kyösti Mälkki | e40beb1 | 2015-02-04 15:23:03 +0200 | [diff] [blame] | 213 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 214 | /* See if there is an available configuration space mapping |
| 215 | * register in function 1. |
| 216 | */ |
Kyösti Mälkki | 260a6db | 2015-02-04 11:09:52 +0200 | [diff] [blame] | 217 | ht_c_index = get_ht_c_index(nodeid, link->link_num, &sysconf); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 218 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 219 | if(ht_c_index>=4) return max; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 220 | |
| 221 | /* Set up the primary, secondary and subordinate bus numbers. |
| 222 | * We have no idea how many busses are behind this bridge yet, |
| 223 | * so we set the subordinate bus number to 0xff for the moment. |
| 224 | */ |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 225 | #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 226 | // first chain will on bus 0 |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 227 | if (is_sblink) { // actually max is 0 here |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 228 | min_bus = max; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 229 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 230 | #if CONFIG_SB_HT_CHAIN_ON_BUS0 > 1 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 231 | // second chain will be on 0x40, third 0x80, forth 0xc0 |
| 232 | // i would refined that to 2, 3, 4 ==> 0, 0x, 40, 0x80, 0xc0 |
| 233 | // >4 will use more segments, We can have 16 segmment and every segment have 256 bus, For that case need the kernel support mmio pci config. |
| 234 | else { |
| 235 | min_bus = ((busn>>3) + 1) << 3; // one node can have 8 link and segn is the same |
| 236 | } |
Kyösti Mälkki | bf62b2d | 2015-02-21 12:42:51 +0200 | [diff] [blame] | 237 | max = min_bus; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 238 | #else |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 239 | //other ... |
| 240 | else { |
| 241 | min_bus = ++max; |
| 242 | } |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 243 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 244 | #else |
| 245 | min_bus = ++max; |
| 246 | #endif |
Kyösti Mälkki | bf62b2d | 2015-02-21 12:42:51 +0200 | [diff] [blame] | 247 | max_bus = 0xfc; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 248 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 249 | link->secondary = min_bus; |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 250 | link->subordinate = link->secondary; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 251 | |
Kyösti Mälkki | 20968c9 | 2015-02-23 12:05:33 +0200 | [diff] [blame^] | 252 | ht_route_link(link, HT_ROUTE_SCAN); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 253 | |
| 254 | /* set the config map space */ |
| 255 | |
Kyösti Mälkki | 20968c9 | 2015-02-23 12:05:33 +0200 | [diff] [blame^] | 256 | set_config_map_reg(nodeid, link->link_num, ht_c_index, link->secondary, link->subordinate, sysconf.segbit, sysconf.nodes); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 257 | |
| 258 | /* Now we can scan all of the subordinate busses i.e. the |
| 259 | * chain on the hypertranport link |
| 260 | */ |
| 261 | for(i=0;i<4;i++) { |
| 262 | ht_unitid_base[i] = 0x20; |
| 263 | } |
| 264 | |
| 265 | //if ext conf is enabled, only need use 0x1f |
| 266 | if (min_bus == 0) |
| 267 | max_devfn = (0x17<<3) | 7; |
| 268 | else |
| 269 | max_devfn = (0x1f<<3) | 7; |
| 270 | |
Kyösti Mälkki | b39714e | 2015-03-12 16:16:59 +0200 | [diff] [blame] | 271 | next_unitid = hypertransport_scan_chain(link, 0, max_devfn, ht_unitid_base, offset_unit_id(is_sblink)); |
| 272 | |
| 273 | /* 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] | 274 | pci_scan_bus(link, 0x00, ((next_unitid - 1) << 3) | 7); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 275 | |
Kyösti Mälkki | 20968c9 | 2015-02-23 12:05:33 +0200 | [diff] [blame^] | 276 | ht_route_link(link, HT_ROUTE_FINAL); |
| 277 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 278 | /* We know the number of busses behind this bridge. Set the |
| 279 | * subordinate bus number to it's real value |
| 280 | */ |
Kyösti Mälkki | 260a6db | 2015-02-04 11:09:52 +0200 | [diff] [blame] | 281 | set_config_map_reg(nodeid, link->link_num, ht_c_index, link->secondary, link->subordinate, sysconf.segbit, sysconf.nodes); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 282 | sysconf.ht_c_num++; |
| 283 | |
| 284 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 285 | // use ht_unitid_base to update hcdn_reg |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 286 | u32 temp = 0; |
| 287 | for(i=0;i<4;i++) { |
| 288 | temp |= (ht_unitid_base[i] & 0xff) << (i*8); |
| 289 | } |
| 290 | |
| 291 | sysconf.hcdn_reg[ht_c_index] = temp; |
| 292 | |
| 293 | } |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 294 | store_ht_c_conf_bus(nodeid, link->link_num, ht_c_index, link->secondary, link->subordinate, &sysconf); |
| 295 | return link->subordinate; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 296 | } |
| 297 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 298 | static void amdfam10_scan_chains(device_t dev) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 299 | { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 300 | unsigned nodeid; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 301 | struct bus *link; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 302 | unsigned sblink = sysconf.sblk; |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 303 | unsigned int max = dev->bus->subordinate; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 304 | |
| 305 | nodeid = amdfam10_nodeid(dev); |
| 306 | |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 307 | /* Do sb ht chain at first, in case s2885 put sb chain (8131/8111) on link2, but put 8151 on link0 */ |
| 308 | for (link = dev->link_list; link; link = link->next) { |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 309 | bool is_sblink = (nodeid == 0) && (link->link_num == sblink); |
| 310 | if ((CONFIG_SB_HT_CHAIN_ON_BUS0 > 0) && is_sblink) |
| 311 | max = amdfam10_scan_chain(dev, nodeid, link, is_sblink, max); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 312 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 313 | |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 314 | for (link = dev->link_list; link; link = link->next) { |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 315 | bool is_sblink = (nodeid == 0) && (link->link_num == sblink); |
| 316 | if ((CONFIG_SB_HT_CHAIN_ON_BUS0 > 0) && is_sblink) |
Kyösti Mälkki | fe57eeb | 2015-02-02 20:07:58 +0200 | [diff] [blame] | 317 | continue; |
| 318 | |
Kyösti Mälkki | 26c6647 | 2015-02-04 13:09:06 +0200 | [diff] [blame] | 319 | max = amdfam10_scan_chain(dev, nodeid, link, is_sblink, max); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 320 | } |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 321 | |
| 322 | dev->bus->subordinate = max; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 323 | } |
| 324 | |
| 325 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 326 | static int reg_useable(unsigned reg, device_t goal_dev, unsigned goal_nodeid, |
| 327 | unsigned goal_link) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 328 | { |
| 329 | struct resource *res; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 330 | unsigned nodeid, link = 0; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 331 | int result; |
| 332 | res = 0; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 333 | for(nodeid = 0; !res && (nodeid < fx_devs); nodeid++) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 334 | device_t dev; |
| 335 | dev = __f0_dev[nodeid]; |
Rudolf Marek | 3a8565a | 2009-03-26 21:45:26 +0000 | [diff] [blame] | 336 | if (!dev) |
| 337 | continue; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 338 | for(link = 0; !res && (link < 8); link++) { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 339 | res = probe_resource(dev, IOINDEX(0x1000 + reg, link)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 340 | } |
| 341 | } |
| 342 | result = 2; |
| 343 | if (res) { |
| 344 | result = 0; |
| 345 | if ( (goal_link == (link - 1)) && |
| 346 | (goal_nodeid == (nodeid - 1)) && |
| 347 | (res->flags <= 1)) { |
| 348 | result = 1; |
| 349 | } |
| 350 | } |
| 351 | return result; |
| 352 | } |
| 353 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 354 | static struct resource *amdfam10_find_iopair(device_t dev, unsigned nodeid, unsigned link) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 355 | { |
| 356 | struct resource *resource; |
| 357 | u32 free_reg, reg; |
| 358 | resource = 0; |
| 359 | free_reg = 0; |
| 360 | for(reg = 0xc0; reg <= 0xd8; reg += 0x8) { |
| 361 | int result; |
| 362 | result = reg_useable(reg, dev, nodeid, link); |
| 363 | if (result == 1) { |
| 364 | /* I have been allocated this one */ |
| 365 | break; |
| 366 | } |
| 367 | else if (result > 1) { |
| 368 | /* I have a free register pair */ |
| 369 | free_reg = reg; |
| 370 | } |
| 371 | } |
| 372 | if (reg > 0xd8) { |
| 373 | reg = free_reg; // if no free, the free_reg still be 0 |
| 374 | } |
| 375 | |
| 376 | //Ext conf space |
| 377 | if(!reg) { |
| 378 | //because of Extend conf space, we will never run out of reg, but we need one index to differ them. so same node and same link can have multi range |
| 379 | u32 index = get_io_addr_index(nodeid, link); |
| 380 | reg = 0x110+ (index<<24) + (4<<20); // index could be 0, 255 |
| 381 | } |
| 382 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 383 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 384 | |
| 385 | return resource; |
| 386 | } |
| 387 | |
| 388 | static struct resource *amdfam10_find_mempair(device_t dev, u32 nodeid, u32 link) |
| 389 | { |
| 390 | struct resource *resource; |
| 391 | u32 free_reg, reg; |
| 392 | resource = 0; |
| 393 | free_reg = 0; |
| 394 | for(reg = 0x80; reg <= 0xb8; reg += 0x8) { |
| 395 | int result; |
| 396 | result = reg_useable(reg, dev, nodeid, link); |
| 397 | if (result == 1) { |
| 398 | /* I have been allocated this one */ |
| 399 | break; |
| 400 | } |
| 401 | else if (result > 1) { |
| 402 | /* I have a free register pair */ |
| 403 | free_reg = reg; |
| 404 | } |
| 405 | } |
| 406 | if (reg > 0xb8) { |
| 407 | reg = free_reg; |
| 408 | } |
| 409 | |
| 410 | //Ext conf space |
| 411 | if(!reg) { |
| 412 | //because of Extend conf space, we will never run out of reg, |
| 413 | // but we need one index to differ them. so same node and |
| 414 | // same link can have multi range |
| 415 | u32 index = get_mmio_addr_index(nodeid, link); |
| 416 | reg = 0x110+ (index<<24) + (6<<20); // index could be 0, 63 |
| 417 | |
| 418 | } |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 419 | resource = new_resource(dev, IOINDEX(0x1000 + reg, link)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 420 | return resource; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | static void amdfam10_link_read_bases(device_t dev, u32 nodeid, u32 link) |
| 425 | { |
| 426 | struct resource *resource; |
| 427 | |
| 428 | /* Initialize the io space constraints on the current bus */ |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 429 | resource = amdfam10_find_iopair(dev, nodeid, link); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 430 | if (resource) { |
| 431 | u32 align; |
Kyösti Mälkki | 4503359 | 2014-12-14 08:35:29 +0200 | [diff] [blame] | 432 | align = log2(HT_IO_HOST_ALIGN); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 433 | resource->base = 0; |
| 434 | resource->size = 0; |
| 435 | resource->align = align; |
| 436 | resource->gran = align; |
| 437 | resource->limit = 0xffffUL; |
Myles Watson | 280df10 | 2009-07-07 13:26:35 +0000 | [diff] [blame] | 438 | resource->flags = IORESOURCE_IO | IORESOURCE_BRIDGE; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 439 | } |
| 440 | |
| 441 | /* Initialize the prefetchable memory constraints on the current bus */ |
| 442 | resource = amdfam10_find_mempair(dev, nodeid, link); |
| 443 | if (resource) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 444 | resource->base = 0; |
| 445 | resource->size = 0; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 446 | resource->align = log2(HT_MEM_HOST_ALIGN); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 447 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 448 | resource->limit = 0xffffffffffULL; |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 449 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
| 450 | resource->flags |= IORESOURCE_BRIDGE; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 451 | } |
| 452 | |
| 453 | /* Initialize the memory constraints on the current bus */ |
| 454 | resource = amdfam10_find_mempair(dev, nodeid, link); |
| 455 | if (resource) { |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 456 | resource->base = 0; |
| 457 | resource->size = 0; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 458 | resource->align = log2(HT_MEM_HOST_ALIGN); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 459 | resource->gran = log2(HT_MEM_HOST_ALIGN); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 460 | resource->limit = 0xffffffffffULL; |
Myles Watson | 280df10 | 2009-07-07 13:26:35 +0000 | [diff] [blame] | 461 | resource->flags = IORESOURCE_MEM | IORESOURCE_BRIDGE; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 462 | } |
| 463 | } |
| 464 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 465 | static void amdfam10_read_resources(device_t dev) |
| 466 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 467 | u32 nodeid; |
| 468 | struct bus *link; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 469 | nodeid = amdfam10_nodeid(dev); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 470 | for(link = dev->link_list; link; link = link->next) { |
| 471 | if (link->children) { |
| 472 | amdfam10_link_read_bases(dev, nodeid, link->link_num); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 473 | } |
| 474 | } |
| 475 | } |
| 476 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 477 | static void amdfam10_set_resource(device_t dev, struct resource *resource, |
| 478 | u32 nodeid) |
| 479 | { |
| 480 | resource_t rbase, rend; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 481 | unsigned reg, link_num; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 482 | char buf[50]; |
| 483 | |
| 484 | /* Make certain the resource has actually been set */ |
| 485 | if (!(resource->flags & IORESOURCE_ASSIGNED)) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | /* If I have already stored this resource don't worry about it */ |
| 490 | if (resource->flags & IORESOURCE_STORED) { |
| 491 | return; |
| 492 | } |
| 493 | |
| 494 | /* Only handle PCI memory and IO resources */ |
| 495 | if (!(resource->flags & (IORESOURCE_MEM | IORESOURCE_IO))) |
| 496 | return; |
| 497 | |
| 498 | /* Ensure I am actually looking at a resource of function 1 */ |
| 499 | if ((resource->index & 0xffff) < 0x1000) { |
| 500 | return; |
| 501 | } |
| 502 | /* Get the base address */ |
| 503 | rbase = resource->base; |
| 504 | |
| 505 | /* Get the limit (rounded up) */ |
| 506 | rend = resource_end(resource); |
| 507 | |
| 508 | /* Get the register and link */ |
| 509 | reg = resource->index & 0xfff; // 4k |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 510 | link_num = IOINDEX_LINK(resource->index); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 511 | |
| 512 | if (resource->flags & IORESOURCE_IO) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 513 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 514 | set_io_addr_reg(dev, nodeid, link_num, reg, rbase>>8, rend>>8); |
| 515 | store_conf_io_addr(nodeid, link_num, reg, (resource->index >> 24), rbase>>8, rend>>8); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 516 | } |
| 517 | else if (resource->flags & IORESOURCE_MEM) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 518 | set_mmio_addr_reg(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8, sysconf.nodes) ;// [39:8] |
| 519 | store_conf_mmio_addr(nodeid, link_num, reg, (resource->index >>24), rbase>>8, rend>>8); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 520 | } |
| 521 | resource->flags |= IORESOURCE_STORED; |
Vladimir Serbinenko | a37383d | 2013-11-26 02:41:26 +0100 | [diff] [blame] | 522 | snprintf(buf, sizeof (buf), " <node %x link %x>", |
| 523 | nodeid, link_num); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 524 | report_resource_stored(dev, resource, buf); |
| 525 | } |
| 526 | |
| 527 | /** |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 528 | * I tried to reuse the resource allocation code in amdfam10_set_resource() |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 529 | * but it is too difficult to deal with the resource allocation magic. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 530 | */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 531 | |
| 532 | static void amdfam10_create_vga_resource(device_t dev, unsigned nodeid) |
| 533 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 534 | struct bus *link; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 535 | |
| 536 | /* find out which link the VGA card is connected, |
| 537 | * we only deal with the 'first' vga card */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 538 | for (link = dev->link_list; link; link = link->next) { |
| 539 | if (link->bridge_ctrl & PCI_BRIDGE_CTL_VGA) { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 540 | #if CONFIG_MULTIPLE_VGA_ADAPTERS |
Stefan Reinauer | abc0c85 | 2010-11-22 08:09:50 +0000 | [diff] [blame] | 541 | 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] | 542 | printk(BIOS_DEBUG, "VGA: vga_pri bus num = %d bus range [%d,%d]\n", vga_pri->bus->secondary, |
| 543 | link->secondary,link->subordinate); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 544 | /* We need to make sure the vga_pri is under the link */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 545 | if((vga_pri->bus->secondary >= link->secondary ) && |
| 546 | (vga_pri->bus->secondary <= link->subordinate ) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 547 | ) |
| 548 | #endif |
| 549 | break; |
| 550 | } |
| 551 | } |
| 552 | |
| 553 | /* no VGA card installed */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 554 | if (link == NULL) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 555 | return; |
| 556 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 557 | printk(BIOS_DEBUG, "VGA: %s (aka node %d) link %d has VGA device\n", dev_path(dev), nodeid, link->link_num); |
| 558 | set_vga_enable_reg(nodeid, link->link_num); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 559 | } |
| 560 | |
| 561 | static void amdfam10_set_resources(device_t dev) |
| 562 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 563 | unsigned nodeid; |
| 564 | struct bus *bus; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 565 | struct resource *res; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 566 | |
| 567 | /* Find the nodeid */ |
| 568 | nodeid = amdfam10_nodeid(dev); |
| 569 | |
| 570 | amdfam10_create_vga_resource(dev, nodeid); |
| 571 | |
| 572 | /* Set each resource we have found */ |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 573 | for(res = dev->resource_list; res; res = res->next) { |
| 574 | amdfam10_set_resource(dev, res, nodeid); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 575 | } |
| 576 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 577 | for(bus = dev->link_list; bus; bus = bus->next) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 578 | if (bus->children) { |
| 579 | assign_resources(bus); |
| 580 | } |
| 581 | } |
| 582 | } |
| 583 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 584 | static void mcf0_control_init(struct device *dev) |
| 585 | { |
| 586 | } |
| 587 | |
| 588 | static struct device_operations northbridge_operations = { |
| 589 | .read_resources = amdfam10_read_resources, |
| 590 | .set_resources = amdfam10_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 591 | .enable_resources = pci_dev_enable_resources, |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 592 | .init = mcf0_control_init, |
| 593 | .scan_bus = amdfam10_scan_chains, |
Vladimir Serbinenko | 2a19fb1 | 2014-10-02 20:09:19 +0200 | [diff] [blame] | 594 | #if IS_ENABLED(CONFIG_HAVE_ACPI_TABLES) |
| 595 | .write_acpi_tables = northbridge_write_acpi_tables, |
| 596 | .acpi_fill_ssdt_generator = northbridge_acpi_write_vars, |
| 597 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 598 | .enable = 0, |
| 599 | .ops_pci = 0, |
| 600 | }; |
| 601 | |
| 602 | |
Stefan Reinauer | 8e96ba2 | 2010-03-16 23:33:29 +0000 | [diff] [blame] | 603 | static const struct pci_driver mcf0_driver __pci_driver = { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 604 | .ops = &northbridge_operations, |
| 605 | .vendor = PCI_VENDOR_ID_AMD, |
| 606 | .device = 0x1200, |
| 607 | }; |
| 608 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 609 | struct chip_operations northbridge_amd_amdfam10_ops = { |
| 610 | CHIP_NAME("AMD FAM10 Northbridge") |
| 611 | .enable_dev = 0, |
| 612 | }; |
| 613 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 614 | static void amdfam10_domain_read_resources(device_t dev) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 615 | { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 616 | unsigned reg; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 617 | |
| 618 | /* Find the already assigned resource pairs */ |
| 619 | get_fx_devs(); |
| 620 | for(reg = 0x80; reg <= 0xd8; reg+= 0x08) { |
| 621 | u32 base, limit; |
| 622 | base = f1_read_config32(reg); |
| 623 | limit = f1_read_config32(reg + 0x04); |
| 624 | /* Is this register allocated? */ |
| 625 | if ((base & 3) != 0) { |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 626 | unsigned nodeid, reg_link; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 627 | device_t reg_dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 628 | if(reg<0xc0) { // mmio |
| 629 | nodeid = (limit & 0xf) + (base&0x30); |
| 630 | } else { // io |
| 631 | nodeid = (limit & 0xf) + ((base>>4)&0x30); |
| 632 | } |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 633 | reg_link = (limit >> 4) & 7; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 634 | reg_dev = __f0_dev[nodeid]; |
| 635 | if (reg_dev) { |
| 636 | /* Reserve the resource */ |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 637 | struct resource *res; |
| 638 | res = new_resource(reg_dev, IOINDEX(0x1000 + reg, reg_link)); |
| 639 | if (res) { |
| 640 | res->flags = 1; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 641 | } |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | /* FIXME: do we need to check extend conf space? |
| 646 | I don't believe that much preset value */ |
| 647 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 648 | #if !CONFIG_PCI_64BIT_PREF_MEM |
Myles Watson | 280df10 | 2009-07-07 13:26:35 +0000 | [diff] [blame] | 649 | pci_domain_read_resources(dev); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 650 | #else |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 651 | struct bus *link; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 652 | struct resource *resource; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 653 | for(link=dev->link_list; link; link = link->next) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 654 | /* Initialize the system wide io space constraints */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 655 | resource = new_resource(dev, 0|(link->link_num<<2)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 656 | resource->base = 0x400; |
| 657 | resource->limit = 0xffffUL; |
| 658 | resource->flags = IORESOURCE_IO; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 659 | |
| 660 | /* Initialize the system wide prefetchable memory resources constraints */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 661 | resource = new_resource(dev, 1|(link->link_num<<2)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 662 | resource->limit = 0xfcffffffffULL; |
| 663 | resource->flags = IORESOURCE_MEM | IORESOURCE_PREFETCH; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 664 | |
| 665 | /* Initialize the system wide memory resources constraints */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 666 | resource = new_resource(dev, 2|(link->link_num<<2)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 667 | resource->limit = 0xfcffffffffULL; |
| 668 | resource->flags = IORESOURCE_MEM; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 669 | } |
| 670 | #endif |
Myles Watson | 1bc5cca | 2010-12-07 19:34:01 +0000 | [diff] [blame] | 671 | #if CONFIG_MMCONF_SUPPORT |
| 672 | struct resource *res = new_resource(dev, 0xc0010058); |
| 673 | res->base = CONFIG_MMCONF_BASE_ADDRESS; |
| 674 | res->size = CONFIG_MMCONF_BUS_NUMBER * 4096*256; |
| 675 | res->flags = IORESOURCE_MEM | IORESOURCE_RESERVE | |
| 676 | IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED; |
Timothy Pearson | a6f669e | 2015-01-23 20:20:56 -0600 | [diff] [blame] | 677 | |
| 678 | /* Reserve lower DRAM region to force PCI MMIO region to correct location above 0xefffffff */ |
| 679 | ram_resource(dev, 7, 0, rdmsr(TOP_MEM).lo >> 10); |
Myles Watson | 1bc5cca | 2010-12-07 19:34:01 +0000 | [diff] [blame] | 680 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 681 | } |
| 682 | |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 683 | static u32 my_find_pci_tolm(struct bus *bus, u32 tolm) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 684 | { |
| 685 | struct resource *min; |
| 686 | min = 0; |
| 687 | search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test, &min); |
| 688 | if (min && tolm > min->base) { |
| 689 | tolm = min->base; |
| 690 | } |
| 691 | return tolm; |
| 692 | } |
| 693 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 694 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 695 | |
| 696 | struct hw_mem_hole_info { |
| 697 | unsigned hole_startk; |
| 698 | int node_id; |
| 699 | }; |
| 700 | |
| 701 | static struct hw_mem_hole_info get_hw_mem_hole_info(void) |
| 702 | { |
| 703 | struct hw_mem_hole_info mem_hole; |
| 704 | int i; |
| 705 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 706 | mem_hole.hole_startk = CONFIG_HW_MEM_HOLE_SIZEK; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 707 | mem_hole.node_id = -1; |
| 708 | |
| 709 | for (i = 0; i < sysconf.nodes; i++) { |
| 710 | struct dram_base_mask_t d; |
| 711 | u32 hole; |
| 712 | d = get_dram_base_mask(i); |
| 713 | if(!(d.mask & 1)) continue; // no memory on this node |
| 714 | |
| 715 | hole = pci_read_config32(__f1_dev[i], 0xf0); |
| 716 | if(hole & 1) { // we find the hole |
| 717 | mem_hole.hole_startk = (hole & (0xff<<24)) >> 10; |
| 718 | mem_hole.node_id = i; // record the node No with hole |
| 719 | break; // only one hole |
| 720 | } |
| 721 | } |
| 722 | |
Kyösti Mälkki | 2f9b3af | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 723 | /* We need to double check if there is special set on base reg and limit reg |
| 724 | * are not continuous instead of hole, it will find out its hole_startk. |
| 725 | */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 726 | if(mem_hole.node_id==-1) { |
| 727 | resource_t limitk_pri = 0; |
| 728 | for(i=0; i<sysconf.nodes; i++) { |
| 729 | struct dram_base_mask_t d; |
| 730 | resource_t base_k, limit_k; |
| 731 | d = get_dram_base_mask(i); |
| 732 | if(!(d.base & 1)) continue; |
| 733 | |
| 734 | base_k = ((resource_t)(d.base & 0x1fffff00)) <<9; |
| 735 | if(base_k > 4 *1024 * 1024) break; // don't need to go to check |
| 736 | if(limitk_pri != base_k) { // we find the hole |
| 737 | mem_hole.hole_startk = (unsigned)limitk_pri; // must beblow 4G |
| 738 | mem_hole.node_id = i; |
| 739 | break; //only one hole |
| 740 | } |
| 741 | |
| 742 | limit_k = ((resource_t)((d.mask + 0x00000100) & 0x1fffff00)) << 9; |
| 743 | limitk_pri = limit_k; |
| 744 | } |
| 745 | } |
| 746 | return mem_hole; |
| 747 | } |
| 748 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 749 | #endif |
| 750 | |
Rudolf Marek | 97be27e | 2010-12-13 19:50:25 +0000 | [diff] [blame] | 751 | #include <cbmem.h> |
Myles Watson | 6c029e6 | 2010-09-13 14:50:20 +0000 | [diff] [blame] | 752 | |
Kyösti Mälkki | 6b5eb1c | 2012-07-19 19:26:43 +0300 | [diff] [blame] | 753 | static void setup_uma_memory(void) |
Kyösti Mälkki | 231f261 | 2012-07-11 08:02:57 +0300 | [diff] [blame] | 754 | { |
| 755 | #if CONFIG_GFXUMA |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 756 | uint32_t topmem = (uint32_t) bsp_topmem(); |
Timothy Pearson | 4916880 | 2015-03-13 12:48:31 -0500 | [diff] [blame] | 757 | uma_memory_size = get_uma_memory_size(topmem); |
Kyösti Mälkki | dbc4739 | 2012-08-05 12:11:40 +0300 | [diff] [blame] | 758 | uma_memory_base = topmem - uma_memory_size; /* TOP_MEM1 */ |
Kyösti Mälkki | 231f261 | 2012-07-11 08:02:57 +0300 | [diff] [blame] | 759 | printk(BIOS_INFO, "%s: uma size 0x%08llx, memory start 0x%08llx\n", |
| 760 | __func__, uma_memory_size, uma_memory_base); |
Kyösti Mälkki | 231f261 | 2012-07-11 08:02:57 +0300 | [diff] [blame] | 761 | #endif |
| 762 | } |
| 763 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 764 | static void amdfam10_domain_set_resources(device_t dev) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 765 | { |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 766 | #if CONFIG_PCI_64BIT_PREF_MEM |
Timothy Pearson | e538dae | 2015-01-23 20:26:03 -0600 | [diff] [blame] | 767 | struct resource *mem1, *mem2; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 768 | struct resource *res; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 769 | #endif |
| 770 | unsigned long mmio_basek; |
| 771 | u32 pci_tolm; |
| 772 | int i, idx; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 773 | struct bus *link; |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 774 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 775 | struct hw_mem_hole_info mem_hole; |
| 776 | u32 reset_memhole = 1; |
| 777 | #endif |
| 778 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 779 | #if CONFIG_PCI_64BIT_PREF_MEM |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 780 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 781 | for(link = dev->link_list; link; link = link->next) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 782 | /* Now reallocate the pci resources memory with the |
| 783 | * highest addresses I can manage. |
| 784 | */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 785 | mem1 = find_resource(dev, 1|(link->link_num<<2)); |
| 786 | mem2 = find_resource(dev, 2|(link->link_num<<2)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 787 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 788 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 789 | mem1->base, mem1->limit, mem1->size, mem1->align); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 790 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 791 | mem2->base, mem2->limit, mem2->size, mem2->align); |
| 792 | |
| 793 | /* See if both resources have roughly the same limits */ |
| 794 | if (((mem1->limit <= 0xffffffff) && (mem2->limit <= 0xffffffff)) || |
| 795 | ((mem1->limit > 0xffffffff) && (mem2->limit > 0xffffffff))) |
| 796 | { |
| 797 | /* If so place the one with the most stringent alignment first |
| 798 | */ |
| 799 | if (mem2->align > mem1->align) { |
| 800 | struct resource *tmp; |
| 801 | tmp = mem1; |
| 802 | mem1 = mem2; |
| 803 | mem2 = tmp; |
| 804 | } |
| 805 | /* Now place the memory as high up as it will go */ |
| 806 | mem2->base = resource_max(mem2); |
| 807 | mem1->limit = mem2->base - 1; |
| 808 | mem1->base = resource_max(mem1); |
| 809 | } |
| 810 | else { |
| 811 | /* Place the resources as high up as they will go */ |
| 812 | mem2->base = resource_max(mem2); |
| 813 | mem1->base = resource_max(mem1); |
| 814 | } |
| 815 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 816 | printk(BIOS_DEBUG, "base1: 0x%08Lx limit1: 0x%08Lx size: 0x%08Lx align: %d\n", |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 817 | mem1->base, mem1->limit, mem1->size, mem1->align); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 818 | printk(BIOS_DEBUG, "base2: 0x%08Lx limit2: 0x%08Lx size: 0x%08Lx align: %d\n", |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 819 | mem2->base, mem2->limit, mem2->size, mem2->align); |
| 820 | } |
| 821 | |
Timothy Pearson | e538dae | 2015-01-23 20:26:03 -0600 | [diff] [blame] | 822 | for(res = dev->resource_list; res; res = res->next) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 823 | { |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 824 | res->flags |= IORESOURCE_ASSIGNED; |
Myles Watson | c25cc11 | 2010-05-21 14:33:48 +0000 | [diff] [blame] | 825 | res->flags |= IORESOURCE_STORED; |
| 826 | report_resource_stored(dev, res, ""); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 827 | } |
| 828 | #endif |
| 829 | |
| 830 | pci_tolm = 0xffffffffUL; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 831 | for(link = dev->link_list; link; link = link->next) { |
Uwe Hermann | 4b42a62 | 2010-10-11 19:36:13 +0000 | [diff] [blame] | 832 | pci_tolm = my_find_pci_tolm(link, pci_tolm); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 833 | } |
| 834 | |
Stefan Reinauer | 29ceae2 | 2010-04-20 11:03:41 +0000 | [diff] [blame] | 835 | // FIXME handle interleaved nodes. If you fix this here, please fix |
| 836 | // amdk8, too. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 837 | mmio_basek = pci_tolm >> 10; |
| 838 | /* Round mmio_basek to something the processor can support */ |
| 839 | mmio_basek &= ~((1 << 6) -1); |
| 840 | |
Stefan Reinauer | 29ceae2 | 2010-04-20 11:03:41 +0000 | [diff] [blame] | 841 | // FIXME improve mtrr.c so we don't use up all of the mtrrs with a 64M |
| 842 | // MMIO hole. If you fix this here, please fix amdk8, too. |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 843 | /* Round the mmio hole to 64M */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 844 | mmio_basek &= ~((64*1024) - 1); |
| 845 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 846 | #if CONFIG_HW_MEM_HOLE_SIZEK != 0 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 847 | /* if the hw mem hole is already set in raminit stage, here we will compare |
| 848 | * mmio_basek and hole_basek. if mmio_basek is bigger that hole_basek and will |
| 849 | * use hole_basek as mmio_basek and we don't need to reset hole. |
| 850 | * otherwise We reset the hole to the mmio_basek |
| 851 | */ |
| 852 | |
| 853 | mem_hole = get_hw_mem_hole_info(); |
| 854 | |
| 855 | // Use hole_basek as mmio_basek, and we don't need to reset hole anymore |
| 856 | if ((mem_hole.node_id != -1) && (mmio_basek > mem_hole.hole_startk)) { |
| 857 | mmio_basek = mem_hole.hole_startk; |
| 858 | reset_memhole = 0; |
| 859 | } |
| 860 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 861 | #endif |
| 862 | |
| 863 | idx = 0x10; |
| 864 | for(i = 0; i < sysconf.nodes; i++) { |
| 865 | struct dram_base_mask_t d; |
| 866 | resource_t basek, limitk, sizek; // 4 1T |
| 867 | d = get_dram_base_mask(i); |
| 868 | |
| 869 | if(!(d.mask & 1)) continue; |
| 870 | basek = ((resource_t)(d.base & 0x1fffff00)) << 9; // could overflow, we may lost 6 bit here |
| 871 | limitk = ((resource_t)((d.mask + 0x00000100) & 0x1fffff00)) << 9 ; |
| 872 | sizek = limitk - basek; |
| 873 | |
| 874 | /* see if we need a hole from 0xa0000 to 0xbffff */ |
| 875 | if ((basek < ((8*64)+(8*16))) && (sizek > ((8*64)+(16*16)))) { |
| 876 | ram_resource(dev, (idx | i), basek, ((8*64)+(8*16)) - basek); |
| 877 | idx += 0x10; |
| 878 | basek = (8*64)+(16*16); |
| 879 | sizek = limitk - ((8*64)+(16*16)); |
| 880 | |
| 881 | } |
| 882 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 883 | // printk(BIOS_DEBUG, "node %d : mmio_basek=%08x, basek=%08x, limitk=%08x\n", i, mmio_basek, basek, limitk); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 884 | |
Kyösti Mälkki | 26c6543 | 2014-06-26 05:30:54 +0300 | [diff] [blame] | 885 | /* split the region to accommodate pci memory space */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 886 | if ( (basek < 4*1024*1024 ) && (limitk > mmio_basek) ) { |
| 887 | if (basek <= mmio_basek) { |
| 888 | unsigned pre_sizek; |
| 889 | pre_sizek = mmio_basek - basek; |
| 890 | if(pre_sizek>0) { |
| 891 | ram_resource(dev, (idx | i), basek, pre_sizek); |
| 892 | idx += 0x10; |
| 893 | sizek -= pre_sizek; |
| 894 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 895 | basek = mmio_basek; |
| 896 | } |
| 897 | if ((basek + sizek) <= 4*1024*1024) { |
| 898 | sizek = 0; |
| 899 | } |
| 900 | else { |
| 901 | basek = 4*1024*1024; |
| 902 | sizek -= (4*1024*1024 - mmio_basek); |
| 903 | } |
| 904 | } |
Scott Duplichan | f3cce2f | 2010-11-13 19:07:59 +0000 | [diff] [blame] | 905 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 906 | ram_resource(dev, (idx | i), basek, sizek); |
| 907 | idx += 0x10; |
Myles Watson | 08e0fb8 | 2010-03-22 16:33:25 +0000 | [diff] [blame] | 908 | printk(BIOS_DEBUG, "%d: mmio_basek=%08lx, basek=%08llx, limitk=%08llx\n", |
Stefan Reinauer | b5fb0c5 | 2009-04-30 13:58:42 +0000 | [diff] [blame] | 909 | i, mmio_basek, basek, limitk); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 910 | } |
| 911 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 912 | #if CONFIG_GFXUMA |
Kyösti Mälkki | 63f8c08 | 2012-07-10 13:27:26 +0300 | [diff] [blame] | 913 | uma_resource(dev, 7, uma_memory_base >> 10, uma_memory_size >> 10); |
Myles Watson | 6c029e6 | 2010-09-13 14:50:20 +0000 | [diff] [blame] | 914 | #endif |
| 915 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 916 | for(link = dev->link_list; link; link = link->next) { |
| 917 | if (link->children) { |
| 918 | assign_resources(link); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 919 | } |
| 920 | } |
| 921 | } |
| 922 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 923 | static void amdfam10_domain_scan_bus(device_t dev) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 924 | { |
| 925 | u32 reg; |
| 926 | int i; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 927 | struct bus *link; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 928 | /* Unmap all of the HT chains */ |
| 929 | for(reg = 0xe0; reg <= 0xec; reg += 4) { |
| 930 | f1_write_config32(reg, 0); |
| 931 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 932 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 933 | for(link = dev->link_list; link; link = link->next) { |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 934 | link->secondary = dev->bus->subordinate; |
Kyösti Mälkki | de271a8 | 2015-03-18 13:09:47 +0200 | [diff] [blame] | 935 | pci_scan_bus(link, PCI_DEVFN(CONFIG_CDB, 0), 0xff); |
Kyösti Mälkki | 6ccf119 | 2015-03-12 05:56:22 +0200 | [diff] [blame] | 936 | dev->bus->subordinate = link->subordinate; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 937 | } |
| 938 | |
| 939 | /* Tune the hypertransport transaction for best performance. |
| 940 | * Including enabling relaxed ordering if it is safe. |
| 941 | */ |
| 942 | get_fx_devs(); |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 943 | for(i = 0; i < fx_devs; i++) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 944 | device_t f0_dev; |
| 945 | f0_dev = __f0_dev[i]; |
| 946 | if (f0_dev && f0_dev->enabled) { |
| 947 | u32 httc; |
| 948 | httc = pci_read_config32(f0_dev, HT_TRANSACTION_CONTROL); |
| 949 | httc &= ~HTTC_RSP_PASS_PW; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 950 | if (!dev->link_list->disable_relaxed_ordering) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 951 | httc |= HTTC_RSP_PASS_PW; |
| 952 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 953 | printk(BIOS_SPEW, "%s passpw: %s\n", |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 954 | dev_path(dev), |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 955 | (!dev->link_list->disable_relaxed_ordering)? |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 956 | "enabled":"disabled"); |
| 957 | pci_write_config32(f0_dev, HT_TRANSACTION_CONTROL, httc); |
| 958 | } |
| 959 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 960 | } |
| 961 | |
Timothy Pearson | 6e523a6 | 2015-03-27 22:58:45 -0500 | [diff] [blame] | 962 | #if IS_ENABLED(CONFIG_GENERATE_SMBIOS_TABLES) |
| 963 | static int amdfam10_get_smbios_data16(int* count, int handle, unsigned long *current) |
| 964 | { |
| 965 | struct amdmct_memory_info *mem_info; |
| 966 | mem_info = cbmem_find(CBMEM_ID_AMDMCT_MEMINFO); |
| 967 | if (mem_info == NULL) |
| 968 | return 0; /* can't find amdmct information in cbmem */ |
| 969 | |
| 970 | struct device *dev = get_node_pci(0, 0); |
| 971 | struct northbridge_amd_amdfam10_config *config = dev->chip_info; |
| 972 | |
| 973 | int node; |
| 974 | int slot; |
| 975 | |
| 976 | struct smbios_type16 *t = (struct smbios_type16 *)*current; |
| 977 | int len = sizeof(struct smbios_type16); |
| 978 | |
| 979 | memset(t, 0, sizeof(struct smbios_type16)); |
| 980 | t->type = SMBIOS_PHYS_MEMORY_ARRAY; |
| 981 | t->handle = handle; |
| 982 | t->length = len - 2; |
| 983 | t->location = MEMORY_ARRAY_LOCATION_SYSTEM_BOARD; |
| 984 | t->use = MEMORY_ARRAY_USE_SYSTEM; |
| 985 | t->memory_error_correction = MEMORY_ARRAY_ECC_NONE; |
| 986 | if ((mem_info->ecc_enabled) |
| 987 | && (mem_info->mct_stat.GStatus & (1 << GSB_ECCDIMMs)) |
| 988 | && !(mem_info->mct_stat.GStatus & (1 << GSB_DramECCDis))) |
| 989 | /* Single-bit ECC enabled */ |
| 990 | t->memory_error_correction = MEMORY_ARRAY_ECC_SINGLE_BIT; |
| 991 | t->maximum_capacity = config->maximum_memory_capacity / 1024; /* Convert to kilobytes */ |
| 992 | t->memory_error_information_handle = 0xFFFE; /* no error information handle available */ |
| 993 | |
| 994 | t->number_of_memory_devices = 0; |
| 995 | /* Check all nodes for installed DIMMs */ |
| 996 | for (node = 0; node < MAX_NODES_SUPPORTED; node++) |
| 997 | /* Check all slots for installed DIMMs */ |
| 998 | for (slot = 0; slot < MAX_DIMMS_SUPPORTED; slot++) |
| 999 | if (mem_info->dct_stat[node].DIMMPresent & (1 << slot)) |
| 1000 | /* Found an installed DIMM; increment count */ |
| 1001 | t->number_of_memory_devices++; |
| 1002 | |
| 1003 | *current += len; |
| 1004 | *count += 1; |
| 1005 | return len; |
| 1006 | } |
| 1007 | |
| 1008 | static uint16_t amdmct_mct_speed_enum_to_mhz(uint8_t speed) |
| 1009 | { |
| 1010 | switch (speed) { |
| 1011 | case 1: |
| 1012 | return 200; |
| 1013 | case 2: |
| 1014 | return 266; |
| 1015 | case 3: |
| 1016 | return 333; |
| 1017 | case 4: |
| 1018 | return 400; |
| 1019 | case 5: |
| 1020 | return 533; |
| 1021 | default: |
| 1022 | return 0; |
| 1023 | } |
| 1024 | } |
| 1025 | |
| 1026 | static int amdfam10_get_smbios_data17(int* count, int handle, int parent_handle, unsigned long *current) |
| 1027 | { |
| 1028 | struct amdmct_memory_info *mem_info; |
| 1029 | mem_info = cbmem_find(CBMEM_ID_AMDMCT_MEMINFO); |
| 1030 | if (mem_info == NULL) |
| 1031 | return 0; /* can't find amdmct information in cbmem */ |
| 1032 | |
| 1033 | int single_len; |
| 1034 | int len = 0; |
| 1035 | int node; |
| 1036 | int slot; |
| 1037 | |
| 1038 | /* Check all nodes for installed DIMMs */ |
| 1039 | for (node = 0; node < MAX_NODES_SUPPORTED; node++) { |
| 1040 | /* Get configured RAM bus speed */ |
| 1041 | uint16_t speed; |
| 1042 | speed = amdmct_mct_speed_enum_to_mhz(mem_info->dct_stat[node].Speed); |
| 1043 | |
| 1044 | /* Get maximum RAM bus speed */ |
| 1045 | uint16_t max_speed; |
| 1046 | max_speed = amdmct_mct_speed_enum_to_mhz(mem_info->dct_stat[node].DIMMAutoSpeed); |
| 1047 | |
| 1048 | /* Check all slots for installed DIMMs */ |
| 1049 | for (slot = 0; slot < MAX_DIMMS_SUPPORTED; slot++) { |
| 1050 | if (mem_info->dct_stat[node].DIMMPresent & (1 << slot)) { |
| 1051 | /* Found an installed DIMM; populate tables */ |
| 1052 | struct smbios_type17 *t = (struct smbios_type17 *)*current; |
| 1053 | char string_buffer[256]; |
| 1054 | |
| 1055 | /* Initialize structure */ |
| 1056 | memset(t, 0, sizeof(struct smbios_type17)); |
| 1057 | |
| 1058 | /* Calculate the total module size in bytes: |
| 1059 | * Primary data width * 2^(#rows) * 2^(#cols) * #banks * #ranks |
| 1060 | */ |
| 1061 | uint8_t width, rows, cols, banks, ranks; |
| 1062 | width = 8; |
| 1063 | rows = mem_info->dct_stat[node].DimmRows[slot]; |
| 1064 | cols = mem_info->dct_stat[node].DimmCols[slot]; |
| 1065 | ranks = mem_info->dct_stat[node].DimmRanks[slot]; |
| 1066 | banks = mem_info->dct_stat[node].DimmBanks[slot]; |
| 1067 | uint64_t dimm_size_bytes = width * (1ULL << rows) * (1ULL << cols) * banks * ranks; |
| 1068 | |
| 1069 | memset(t, 0, sizeof(struct smbios_type17)); |
| 1070 | t->type = SMBIOS_MEMORY_DEVICE; |
| 1071 | t->handle = handle; |
| 1072 | t->phys_memory_array_handle = parent_handle; |
| 1073 | t->length = sizeof(struct smbios_type17) - 2; |
| 1074 | if (dimm_size_bytes > 0x800000000) { |
| 1075 | t->size = 0x7FFF; |
| 1076 | t->extended_size = dimm_size_bytes; |
| 1077 | } |
| 1078 | else { |
| 1079 | t->size = dimm_size_bytes / (1024*1024); |
| 1080 | t->size &= (~0x8000); /* size specified in megabytes */ |
| 1081 | } |
| 1082 | t->total_width = t->data_width = 64; |
| 1083 | if (mem_info->dct_stat[node].DimmECCPresent & (1 << slot)) |
| 1084 | t->total_width += 8; |
| 1085 | t->attributes = 0; |
| 1086 | t->attributes |= ranks & 0xf; /* rank number is stored in the lowest 4 bits of the attributes field */ |
| 1087 | t->form_factor = MEMORY_FORMFACTOR_DIMM; |
| 1088 | snprintf(string_buffer, sizeof (string_buffer), "NODE %d DIMM_%s%d", node, (slot & 0x1)?"B":"A", (slot >> 1) + 1); |
| 1089 | t->device_locator = smbios_add_string(t->eos, string_buffer); |
| 1090 | if (IS_ENABLED(CONFIG_DIMM_DDR2)) |
| 1091 | t->memory_type = MEMORY_TYPE_DDR2; |
| 1092 | else if (IS_ENABLED(CONFIG_DIMM_DDR3)) |
| 1093 | t->memory_type = MEMORY_TYPE_DDR3; |
| 1094 | t->type_detail = MEMORY_TYPE_DETAIL_SYNCHRONOUS; |
| 1095 | if (mem_info->dct_stat[node].DimmRegistered[slot]) |
| 1096 | t->type_detail |= MEMORY_TYPE_DETAIL_REGISTERED; |
| 1097 | else |
| 1098 | t->type_detail |= MEMORY_TYPE_DETAIL_UNBUFFERED; |
| 1099 | t->speed = max_speed; |
| 1100 | t->clock_speed = speed; |
| 1101 | smbios_fill_dimm_manufacturer_from_id(mem_info->dct_stat[node].DimmManufacturerID[slot], t); |
| 1102 | t->part_number = smbios_add_string(t->eos, mem_info->dct_stat[node].DimmPartNumber[slot]); |
| 1103 | if (mem_info->dct_stat[node].DimmSerialNumber[slot] == 0) { |
| 1104 | t->serial_number = smbios_add_string(t->eos, "None"); |
| 1105 | } |
| 1106 | else { |
| 1107 | snprintf(string_buffer, sizeof (string_buffer), "%08X", mem_info->dct_stat[node].DimmSerialNumber[slot]); |
| 1108 | t->serial_number = smbios_add_string(t->eos, string_buffer); |
| 1109 | } |
| 1110 | t->memory_error_information_handle = 0xFFFE; /* no error information handle available */ |
| 1111 | single_len = t->length + smbios_string_table_len(t->eos); |
| 1112 | len += single_len; |
| 1113 | *current += single_len; |
| 1114 | handle++; |
| 1115 | *count += 1; |
| 1116 | } |
| 1117 | } |
| 1118 | } |
| 1119 | |
| 1120 | return len; |
| 1121 | } |
| 1122 | |
| 1123 | static int amdfam10_get_smbios_data(device_t dev, int *handle, unsigned long *current) |
| 1124 | { |
| 1125 | int len; |
| 1126 | int count = 0; |
| 1127 | len = amdfam10_get_smbios_data16(&count, *handle, current); |
| 1128 | len += amdfam10_get_smbios_data17(&count, *handle + 1, *handle, current); |
| 1129 | *handle += count; |
| 1130 | return len; |
| 1131 | } |
| 1132 | #endif |
| 1133 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1134 | static struct device_operations pci_domain_ops = { |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1135 | .read_resources = amdfam10_domain_read_resources, |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1136 | .set_resources = amdfam10_domain_set_resources, |
Myles Watson | 7eac445 | 2010-06-17 16:16:56 +0000 | [diff] [blame] | 1137 | .enable_resources = NULL, |
| 1138 | .init = NULL, |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 1139 | .scan_bus = amdfam10_domain_scan_bus, |
Kyösti Mälkki | 872c922 | 2013-07-03 09:44:28 +0300 | [diff] [blame] | 1140 | .ops_pci_bus = pci_bus_default_ops, |
Timothy Pearson | 6e523a6 | 2015-03-27 22:58:45 -0500 | [diff] [blame] | 1141 | #if CONFIG_GENERATE_SMBIOS_TABLES |
| 1142 | .get_smbios_data = amdfam10_get_smbios_data, |
| 1143 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1144 | }; |
| 1145 | |
| 1146 | static void sysconf_init(device_t dev) // first node |
| 1147 | { |
| 1148 | sysconf.sblk = (pci_read_config32(dev, 0x64)>>8) & 7; // don't forget sublink1 |
| 1149 | sysconf.segbit = 0; |
| 1150 | sysconf.ht_c_num = 0; |
| 1151 | |
| 1152 | unsigned ht_c_index; |
| 1153 | |
| 1154 | for(ht_c_index=0; ht_c_index<32; ht_c_index++) { |
| 1155 | sysconf.ht_c_conf_bus[ht_c_index] = 0; |
| 1156 | } |
| 1157 | |
| 1158 | sysconf.nodes = ((pci_read_config32(dev, 0x60)>>4) & 7) + 1; |
| 1159 | #if CONFIG_MAX_PHYSICAL_CPUS > 8 |
| 1160 | sysconf.nodes += (((pci_read_config32(dev, 0x160)>>4) & 7)<<3); |
| 1161 | #endif |
| 1162 | |
| 1163 | sysconf.enabled_apic_ext_id = 0; |
| 1164 | sysconf.lift_bsp_apicid = 0; |
| 1165 | |
| 1166 | /* Find the bootstrap processors apicid */ |
| 1167 | sysconf.bsp_apicid = lapicid(); |
| 1168 | sysconf.apicid_offset = sysconf.bsp_apicid; |
| 1169 | |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1170 | #if CONFIG_ENABLE_APIC_EXT_ID |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1171 | if (pci_read_config32(dev, 0x68) & (HTTC_APIC_EXT_ID|HTTC_APIC_EXT_BRD_CST)) |
| 1172 | { |
| 1173 | sysconf.enabled_apic_ext_id = 1; |
| 1174 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1175 | #if (CONFIG_APIC_ID_OFFSET>0) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1176 | if(sysconf.enabled_apic_ext_id) { |
| 1177 | if(sysconf.bsp_apicid == 0) { |
| 1178 | /* bsp apic id is not changed */ |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1179 | sysconf.apicid_offset = CONFIG_APIC_ID_OFFSET; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1180 | } else { |
| 1181 | sysconf.lift_bsp_apicid = 1; |
| 1182 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1183 | } |
| 1184 | #endif |
| 1185 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1186 | } |
| 1187 | |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1188 | static void add_more_links(device_t dev, unsigned total_links) |
| 1189 | { |
| 1190 | struct bus *link, *last = NULL; |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1191 | int link_num = -1; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1192 | |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1193 | for (link = dev->link_list; link; link = link->next) { |
| 1194 | if (link_num < link->link_num) |
| 1195 | link_num = link->link_num; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1196 | last = link; |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1197 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1198 | |
| 1199 | if (last) { |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1200 | int links = total_links - (link_num + 1); |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1201 | if (links > 0) { |
| 1202 | link = malloc(links*sizeof(*link)); |
| 1203 | if (!link) |
| 1204 | die("Couldn't allocate more links!\n"); |
| 1205 | memset(link, 0, links*sizeof(*link)); |
| 1206 | last->next = link; |
| 1207 | } |
| 1208 | } |
| 1209 | else { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1210 | link = malloc(total_links*sizeof(*link)); |
| 1211 | memset(link, 0, total_links*sizeof(*link)); |
| 1212 | dev->link_list = link; |
| 1213 | } |
| 1214 | |
| 1215 | for (link_num = link_num + 1; link_num < total_links; link_num++) { |
| 1216 | link->link_num = link_num; |
| 1217 | link->dev = dev; |
| 1218 | link->next = link + 1; |
| 1219 | last = link; |
| 1220 | link = link->next; |
| 1221 | } |
| 1222 | last->next = NULL; |
| 1223 | } |
| 1224 | |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 1225 | static void cpu_bus_scan(device_t dev) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1226 | { |
| 1227 | struct bus *cpu_bus; |
| 1228 | device_t dev_mc; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1229 | #if CONFIG_CBB |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1230 | device_t pci_domain; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1231 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1232 | int i,j; |
| 1233 | int nodes; |
| 1234 | unsigned nb_cfg_54; |
| 1235 | unsigned siblings; |
| 1236 | int cores_found; |
Luc Verhaegen | a9c5ea0 | 2009-06-03 14:19:33 +0000 | [diff] [blame] | 1237 | int disable_siblings; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1238 | unsigned ApicIdCoreIdSize; |
| 1239 | |
| 1240 | nb_cfg_54 = 0; |
| 1241 | ApicIdCoreIdSize = (cpuid_ecx(0x80000008)>>12 & 0xf); |
| 1242 | if(ApicIdCoreIdSize) { |
| 1243 | siblings = (1<<ApicIdCoreIdSize)-1; |
| 1244 | } else { |
| 1245 | siblings = 3; //quad core |
| 1246 | } |
| 1247 | |
| 1248 | disable_siblings = !CONFIG_LOGICAL_CPUS; |
Patrick Georgi | e166782 | 2012-05-05 15:29:32 +0200 | [diff] [blame] | 1249 | #if CONFIG_LOGICAL_CPUS |
Myles Watson | 4839e2c | 2010-04-08 15:06:44 +0000 | [diff] [blame] | 1250 | get_option(&disable_siblings, "multi_core"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1251 | #endif |
| 1252 | |
Myles Watson | 6507b39 | 2010-06-09 22:39:00 +0000 | [diff] [blame] | 1253 | // How can I get the nb_cfg_54 of every node's nb_cfg_54 in bsp??? |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1254 | nb_cfg_54 = read_nb_cfg_54(); |
| 1255 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1256 | #if CONFIG_CBB |
| 1257 | dev_mc = dev_find_slot(0, PCI_DEVFN(CONFIG_CDB, 0)); //0x00 |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1258 | if(dev_mc && dev_mc->bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1259 | printk(BIOS_DEBUG, "%s found", dev_path(dev_mc)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1260 | pci_domain = dev_mc->bus->dev; |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1261 | if(pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1262 | printk(BIOS_DEBUG, "\n%s move to ",dev_path(dev_mc)); |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1263 | dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1264 | printk(BIOS_DEBUG, "%s",dev_path(dev_mc)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1265 | |
| 1266 | } else { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1267 | printk(BIOS_DEBUG, " but it is not under pci_domain directly "); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1268 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1269 | printk(BIOS_DEBUG, "\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1270 | } |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1271 | dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1272 | if(!dev_mc) { |
| 1273 | dev_mc = dev_find_slot(0, PCI_DEVFN(0x18, 0)); |
| 1274 | if (dev_mc && dev_mc->bus) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1275 | printk(BIOS_DEBUG, "%s found\n", dev_path(dev_mc)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1276 | pci_domain = dev_mc->bus->dev; |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1277 | if(pci_domain && (pci_domain->path.type == DEVICE_PATH_DOMAIN)) { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1278 | if((pci_domain->link_list) && (pci_domain->link_list->children == dev_mc)) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1279 | printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc)); |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1280 | dev_mc->bus->secondary = CONFIG_CBB; // move to 0xff |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1281 | printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1282 | while(dev_mc){ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1283 | printk(BIOS_DEBUG, "%s move to ",dev_path(dev_mc)); |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 1284 | dev_mc->path.pci.devfn -= PCI_DEVFN(0x18,0); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1285 | printk(BIOS_DEBUG, "%s\n",dev_path(dev_mc)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1286 | dev_mc = dev_mc->sibling; |
| 1287 | } |
| 1288 | } |
| 1289 | } |
| 1290 | } |
| 1291 | } |
| 1292 | |
| 1293 | #endif |
| 1294 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1295 | dev_mc = dev_find_slot(CONFIG_CBB, PCI_DEVFN(CONFIG_CDB, 0)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1296 | if (!dev_mc) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 1297 | printk(BIOS_ERR, "%02x:%02x.0 not found", CONFIG_CBB, CONFIG_CDB); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1298 | die(""); |
| 1299 | } |
| 1300 | |
| 1301 | sysconf_init(dev_mc); |
| 1302 | |
| 1303 | nodes = sysconf.nodes; |
| 1304 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1305 | #if CONFIG_CBB && (NODE_NUMS > 32) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1306 | if(nodes>32) { // need to put node 32 to node 63 to bus 0xfe |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1307 | if(pci_domain->link_list && !pci_domain->link_list->next) { |
| 1308 | struct bus *new_link = new_link(pci_domain); |
| 1309 | pci_domain->link_list->next = new_link; |
| 1310 | new_link->link_num = 1; |
| 1311 | new_link->dev = pci_domain; |
| 1312 | new_link->children = 0; |
| 1313 | printk(BIOS_DEBUG, "%s links now 2\n", dev_path(pci_domain)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1314 | } |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1315 | pci_domain->link_list->next->secondary = CONFIG_CBB - 1; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1316 | } |
| 1317 | #endif |
| 1318 | /* Find which cpus are present */ |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1319 | cpu_bus = dev->link_list; |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1320 | |
| 1321 | /* Always use the devicetree node with lapic_id 0 for BSP. */ |
| 1322 | remap_bsp_lapic(cpu_bus); |
| 1323 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1324 | for(i = 0; i < nodes; i++) { |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1325 | device_t cdb_dev; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1326 | unsigned busn, devn; |
| 1327 | struct bus *pbus; |
| 1328 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1329 | busn = CONFIG_CBB; |
| 1330 | devn = CONFIG_CDB+i; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1331 | pbus = dev_mc->bus; |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 1332 | #if CONFIG_CBB && (NODE_NUMS > 32) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1333 | if(i>=32) { |
| 1334 | busn--; |
| 1335 | devn-=32; |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1336 | pbus = pci_domain->link_list->next); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1337 | } |
| 1338 | #endif |
| 1339 | |
| 1340 | /* Find the cpu's pci device */ |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1341 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0)); |
| 1342 | if (!cdb_dev) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1343 | /* If I am probing things in a weird order |
| 1344 | * ensure all of the cpu's pci devices are found. |
| 1345 | */ |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1346 | int fn; |
| 1347 | for(fn = 0; fn <= 5; fn++) { //FBDIMM? |
| 1348 | cdb_dev = pci_probe_dev(NULL, pbus, |
| 1349 | PCI_DEVFN(devn, fn)); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1350 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1351 | } |
Kyösti Mälkki | 59d6092 | 2015-02-21 23:56:07 +0200 | [diff] [blame] | 1352 | |
| 1353 | /* Ok, We need to set the links for that device. |
| 1354 | * otherwise the device under it will not be scanned |
| 1355 | */ |
| 1356 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 0)); |
| 1357 | if (cdb_dev) |
| 1358 | add_more_links(cdb_dev, 4); |
| 1359 | |
| 1360 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 4)); |
| 1361 | if (cdb_dev) |
| 1362 | add_more_links(cdb_dev, 4); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1363 | |
| 1364 | cores_found = 0; // one core |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1365 | cdb_dev = dev_find_slot(busn, PCI_DEVFN(devn, 3)); |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1366 | int enable_node = cdb_dev && cdb_dev->enabled; |
| 1367 | if (enable_node) { |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1368 | j = pci_read_config32(cdb_dev, 0xe8); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1369 | cores_found = (j >> 12) & 3; // dev is func 3 |
Arne Georg Gleditsch | bc259d0 | 2010-03-10 03:43:05 +0000 | [diff] [blame] | 1370 | if (siblings > 3) |
| 1371 | cores_found |= (j >> 13) & 4; |
Myles Watson | 362db61 | 2010-04-08 15:12:18 +0000 | [diff] [blame] | 1372 | printk(BIOS_DEBUG, " %s siblings=%d\n", dev_path(cdb_dev), cores_found); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1373 | } |
| 1374 | |
| 1375 | u32 jj; |
| 1376 | if(disable_siblings) { |
| 1377 | jj = 0; |
| 1378 | } else |
| 1379 | { |
| 1380 | jj = cores_found; |
| 1381 | } |
| 1382 | |
| 1383 | for (j = 0; j <=jj; j++ ) { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1384 | u32 apic_id = i * (nb_cfg_54?(siblings+1):1) + j * (nb_cfg_54?1:64); // ? |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1385 | |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1386 | #if CONFIG_ENABLE_APIC_EXT_ID && (CONFIG_APIC_ID_OFFSET>0) |
| 1387 | if(sysconf.enabled_apic_ext_id) { |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1388 | if (apic_id != 0 || sysconf.lift_bsp_apicid) { |
| 1389 | apic_id += sysconf.apicid_offset; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1390 | } |
| 1391 | } |
Kyösti Mälkki | cd9fc1a | 2012-07-06 19:02:56 +0300 | [diff] [blame] | 1392 | #endif |
Kyösti Mälkki | c33f1e9 | 2012-08-07 17:12:11 +0300 | [diff] [blame] | 1393 | device_t cpu = add_cpu_device(cpu_bus, apic_id, enable_node); |
| 1394 | if (cpu) |
| 1395 | amd_cpu_topology(cpu, i, j); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1396 | } //j |
| 1397 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1398 | } |
| 1399 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1400 | static void cpu_bus_init(device_t dev) |
| 1401 | { |
Myles Watson | 894a347 | 2010-06-09 22:41:35 +0000 | [diff] [blame] | 1402 | initialize_cpus(dev->link_list); |
Kerry She | feed329 | 2011-08-18 18:03:44 +0800 | [diff] [blame] | 1403 | #if CONFIG_AMD_SB_CIMX |
| 1404 | sb_After_Pci_Init(); |
| 1405 | sb_Mid_Post_Init(); |
| 1406 | #endif |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1407 | } |
| 1408 | |
Edward O'Callaghan | 2837ab2 | 2014-11-06 08:57:40 +1100 | [diff] [blame] | 1409 | static void cpu_bus_set_resources(struct device *dev) |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 1410 | { |
| 1411 | struct resource *resource = find_resource(dev, 0xc0010058); |
| 1412 | if (resource) { |
| 1413 | report_resource_stored(dev, resource, " <mmconfig>"); |
| 1414 | } |
| 1415 | pci_dev_set_resources(dev); |
| 1416 | } |
| 1417 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1418 | static struct device_operations cpu_bus_ops = { |
Edward O'Callaghan | 2837ab2 | 2014-11-06 08:57:40 +1100 | [diff] [blame] | 1419 | .read_resources = DEVICE_NOOP, |
Arne Georg Gleditsch | d6689ed | 2010-09-09 14:54:07 +0000 | [diff] [blame] | 1420 | .set_resources = cpu_bus_set_resources, |
Edward O'Callaghan | 812d2a4 | 2014-10-31 08:17:23 +1100 | [diff] [blame] | 1421 | .enable_resources = DEVICE_NOOP, |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1422 | .init = cpu_bus_init, |
| 1423 | .scan_bus = cpu_bus_scan, |
| 1424 | }; |
| 1425 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1426 | static void root_complex_enable_dev(struct device *dev) |
| 1427 | { |
Kyösti Mälkki | 87213b6 | 2012-08-27 20:00:33 +0300 | [diff] [blame] | 1428 | static int done = 0; |
| 1429 | |
| 1430 | /* Do not delay UMA setup, as a device on the PCI bus may evaluate |
| 1431 | the global uma_memory variables already in its enable function. */ |
| 1432 | if (!done) { |
| 1433 | setup_bsp_ramtop(); |
| 1434 | setup_uma_memory(); |
| 1435 | done = 1; |
| 1436 | } |
| 1437 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1438 | /* Set the operations if it is a special bus type */ |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 1439 | if (dev->path.type == DEVICE_PATH_DOMAIN) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1440 | dev->ops = &pci_domain_ops; |
| 1441 | } |
Stefan Reinauer | 0aa37c4 | 2013-02-12 15:20:54 -0800 | [diff] [blame] | 1442 | else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) { |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 1443 | dev->ops = &cpu_bus_ops; |
| 1444 | } |
| 1445 | } |
| 1446 | |
| 1447 | struct chip_operations northbridge_amd_amdfam10_root_complex_ops = { |
| 1448 | CHIP_NAME("AMD FAM10 Root Complex") |
| 1449 | .enable_dev = root_complex_enable_dev, |
| 1450 | }; |