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