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 | 88d213a | 2015-01-23 20:28:13 -0600 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Marc Jones | da4ce6b | 2008-04-22 22:11:31 +0000 | [diff] [blame] | 5 | * Copyright (C) 2007-2008 Advanced Micro Devices, Inc. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 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. |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Patrick Georgi | 3d5bb23 | 2010-05-09 21:15:13 +0000 | [diff] [blame] | 17 | #include <cpu/x86/msr.h> |
| 18 | #include <console/console.h> |
| 19 | #include <northbridge/amd/amdfam10/amdfam10.h> |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 20 | |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 21 | #include "ht_wrapper.h" |
| 22 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 23 | /*---------------------------------------------------------------------------- |
| 24 | * TYPEDEFS, DEFINITIONS AND MACROS |
| 25 | * |
| 26 | *---------------------------------------------------------------------------- |
| 27 | */ |
| 28 | |
| 29 | /* Single CPU system? */ |
Timothy Pearson | 88d213a | 2015-01-23 20:28:13 -0600 | [diff] [blame] | 30 | #if (CONFIG_MAX_PHYSICAL_CPUS == 1) |
| 31 | /* FIXME |
| 32 | * This #define is used by other #included .c files |
| 33 | * When set, multiprocessor support is completely disabled |
| 34 | */ |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 35 | #define HT_BUILD_NC_ONLY 1 |
| 36 | #endif |
| 37 | |
| 38 | /* Debugging Options */ |
| 39 | #define AMD_DEBUG 1 |
| 40 | //#define AMD_DEBUG_ERROR_STOP 1 |
| 41 | |
| 42 | /*---------------------------------------------------------------------------- |
| 43 | * MODULES USED |
| 44 | * |
| 45 | *---------------------------------------------------------------------------- |
| 46 | */ |
| 47 | |
| 48 | #undef FILECODE |
| 49 | #define FILECODE 0xFF01 |
| 50 | #include "comlib.h" |
| 51 | #include "h3gtopo.h" |
| 52 | #include "h3finit.h" |
| 53 | |
| 54 | /* include the main HT source file */ |
| 55 | #include "h3finit.c" |
| 56 | |
| 57 | |
| 58 | /*---------------------------------------------------------------------------- |
| 59 | * LOCAL FUNCTIONS |
| 60 | * |
| 61 | *---------------------------------------------------------------------------- |
| 62 | */ |
| 63 | |
| 64 | /* FIXME: Find a better place for these pre-ram functions. */ |
| 65 | #define NODE_HT(x) NODE_PCI(x,0) |
| 66 | #define NODE_MP(x) NODE_PCI(x,1) |
| 67 | #define NODE_MC(x) NODE_PCI(x,3) |
| 68 | #define NODE_LC(x) NODE_PCI(x,4) |
Marc Jones | da4ce6b | 2008-04-22 22:11:31 +0000 | [diff] [blame] | 69 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 70 | static u32 get_nodes(void) |
| 71 | { |
| 72 | device_t dev; |
| 73 | u32 nodes; |
| 74 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 75 | dev = PCI_DEV(CONFIG_CBB, CONFIG_CDB, 0); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 76 | nodes = ((pci_read_config32(dev, 0x60)>>4) & 7) ; |
| 77 | #if CONFIG_MAX_PHYSICAL_CPUS > 8 |
| 78 | nodes += (((pci_read_config32(dev, 0x160)>>4) & 7)<<3); |
| 79 | #endif |
| 80 | nodes++; |
| 81 | |
| 82 | return nodes; |
| 83 | } |
| 84 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 85 | |
| 86 | /** |
| 87 | * void AMD_CB_EventNotify (u8 evtClass, u16 event, const u8 *pEventData0) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 88 | */ |
Myles Watson | 075fbe8 | 2010-04-15 05:19:29 +0000 | [diff] [blame] | 89 | static void AMD_CB_EventNotify (u8 evtClass, u16 event, const u8 *pEventData0) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 90 | { |
Marc Jones | eafcedd | 2008-07-17 19:54:06 +0000 | [diff] [blame] | 91 | u8 i; |
| 92 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 93 | printk(BIOS_DEBUG, "AMD_CB_EventNotify()\n"); |
| 94 | printk(BIOS_DEBUG, " event class: %02x\n event: %04x\n data: ", evtClass, event); |
Marc Jones | eafcedd | 2008-07-17 19:54:06 +0000 | [diff] [blame] | 95 | |
| 96 | for (i = 0; i < *pEventData0; i++) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 97 | printk(BIOS_DEBUG, " %02x ", *(pEventData0 + i)); |
Marc Jones | eafcedd | 2008-07-17 19:54:06 +0000 | [diff] [blame] | 98 | } |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 99 | printk(BIOS_DEBUG, "\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 100 | |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * void getAmdTopolist(u8 ***p) |
| 105 | * |
| 106 | * point to the stock topo list array |
| 107 | * |
| 108 | */ |
| 109 | void getAmdTopolist(u8 ***p) |
| 110 | { |
| 111 | *p = (u8 **)amd_topo_list; |
| 112 | } |
| 113 | |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 114 | /** |
| 115 | * BOOL AMD_CB_IgnoreLink(u8 Node, u8 Link) |
| 116 | * Description: |
| 117 | * This routine is used to ignore connected yet faulty HT links, |
| 118 | * such as those present in a G34 processor package. |
| 119 | * |
| 120 | * Parameters: |
| 121 | * @param[in] node = The node on which this chain is located |
| 122 | * @param[in] link = The link on the host for this chain |
| 123 | */ |
| 124 | static BOOL AMD_CB_IgnoreLink (u8 node, u8 link) |
| 125 | { |
| 126 | return 0; |
| 127 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 128 | |
| 129 | /** |
| 130 | * void amd_ht_init(struct sys_info *sysinfo) |
| 131 | * |
Stefan Reinauer | f8ee180 | 2008-01-18 15:08:58 +0000 | [diff] [blame] | 132 | * AMD HT init coreboot wrapper |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 133 | * |
| 134 | */ |
Myles Watson | 075fbe8 | 2010-04-15 05:19:29 +0000 | [diff] [blame] | 135 | static void amd_ht_init(struct sys_info *sysinfo) |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 136 | { |
Marc Jones | eafcedd | 2008-07-17 19:54:06 +0000 | [diff] [blame] | 137 | |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 138 | AMD_HTBLOCK ht_wrapper = { |
| 139 | NULL, // u8 **topolist; |
| 140 | 0, // u8 AutoBusStart; |
| 141 | 32, // u8 AutoBusMax; |
| 142 | 6, // u8 AutoBusIncrement; |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 143 | AMD_CB_IgnoreLink, // BOOL (*AMD_CB_IgnoreLink)(); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 144 | NULL, // BOOL (*AMD_CB_OverrideBusNumbers)(); |
Marc Jones | eafcedd | 2008-07-17 19:54:06 +0000 | [diff] [blame] | 145 | AMD_CB_ManualBUIDSwapList, // BOOL (*AMD_CB_ManualBUIDSwapList)(); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 146 | NULL, // void (*AMD_CB_DeviceCapOverride)(); |
| 147 | NULL, // void (*AMD_CB_Cpu2CpuPCBLimits)(); |
| 148 | NULL, // void (*AMD_CB_IOPCBLimits)(); |
| 149 | NULL, // BOOL (*AMD_CB_SkipRegang)(); |
| 150 | NULL, // BOOL (*AMD_CB_CustomizeTrafficDistribution)(); |
| 151 | NULL, // BOOL (*AMD_CB_CustomizeBuffers)(); |
| 152 | NULL, // void (*AMD_CB_OverrideDevicePort)(); |
| 153 | NULL, // void (*AMD_CB_OverrideCpuPort)(); |
Timothy Pearson | 586d6e2 | 2015-02-16 14:57:06 -0600 | [diff] [blame] | 154 | AMD_CB_EventNotify, // void (*AMD_CB_EventNotify) (); |
| 155 | &sysinfo->ht_link_cfg // struct ht_link_config* |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 156 | }; |
| 157 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 158 | printk(BIOS_DEBUG, "Enter amd_ht_init()\n"); |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 159 | amdHtInitialize(&ht_wrapper); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 160 | printk(BIOS_DEBUG, "Exit amd_ht_init()\n"); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 161 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 162 | |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 163 | /** |
| 164 | * void amd_ht_fixup(struct sys_info *sysinfo) |
| 165 | * |
| 166 | * AMD HT fixup |
| 167 | * |
| 168 | */ |
| 169 | void amd_ht_fixup(struct sys_info *sysinfo) { |
| 170 | printk(BIOS_DEBUG, "amd_ht_fixup()\n"); |
| 171 | if (IS_ENABLED(CONFIG_CPU_AMD_MODEL_10XXX)) { |
| 172 | uint8_t rev_gte_d = 0; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 173 | uint8_t fam15h = 0; |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 174 | uint8_t dual_node = 0; |
| 175 | uint32_t f3xe8; |
| 176 | uint32_t family; |
| 177 | uint32_t model; |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 178 | |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 179 | family = model = cpuid_eax(0x80000001); |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 180 | model = ((model & 0xf0000) >> 12) | ((model & 0xf0) >> 4); |
| 181 | family = ((family & 0xf00000) >> 16) | ((family & 0xf00) >> 8); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 182 | |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 183 | if (family >= 0x6f) |
| 184 | /* Family 15h or later */ |
| 185 | fam15h = 1; |
| 186 | |
| 187 | if ((model >= 0x8) || fam15h) |
| 188 | /* Family 10h Revision D or later */ |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 189 | rev_gte_d = 1; |
| 190 | |
| 191 | if (rev_gte_d) { |
| 192 | f3xe8 = pci_read_config32(NODE_PCI(0, 3), 0xe8); |
| 193 | |
| 194 | /* Check for dual node capability */ |
| 195 | if (f3xe8 & 0x20000000) |
| 196 | dual_node = 1; |
| 197 | |
| 198 | if (dual_node) { |
| 199 | /* Each G34 processor contains a defective HT link. |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 200 | * See the Family 10h BKDG Rev 3.62 section 2.7.1.5 for details |
| 201 | * For Family 15h see the BKDG Rev. 3.14 section 2.12.1.5 for details. |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 202 | */ |
| 203 | uint8_t node; |
| 204 | uint8_t node_count = get_nodes(); |
| 205 | uint32_t dword; |
| 206 | for (node = 0; node < node_count; node++) { |
| 207 | f3xe8 = pci_read_config32(NODE_PCI(node, 3), 0xe8); |
| 208 | uint8_t internal_node_number = ((f3xe8 & 0xc0000000) >> 30); |
| 209 | printk(BIOS_DEBUG, "amd_ht_fixup(): node %d (internal node ID %d): disabling defective HT link\n", node, internal_node_number); |
| 210 | if (internal_node_number == 0) { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 211 | uint8_t package_link_3_connected = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0x98:0xd8) & 0x1; |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 212 | if (package_link_3_connected) { |
| 213 | /* Set WidthIn and WidthOut to 0 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 214 | dword = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0x84:0xc4); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 215 | dword &= ~0x77000000; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 216 | pci_write_config32(NODE_PCI(node, 0), (fam15h)?0x84:0xc4, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 217 | /* Set Ganged to 1 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 218 | dword = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0x170:0x178); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 219 | dword |= 0x00000001; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 220 | pci_write_config32(NODE_PCI(node, 0), (fam15h)?0x170:0x178, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 221 | } else { |
| 222 | /* Set ConnDly to 1 */ |
| 223 | dword = pci_read_config32(NODE_PCI(node, 0), 0x16c); |
| 224 | dword |= 0x00000100; |
| 225 | pci_write_config32(NODE_PCI(node, 0), 0x16c, dword); |
| 226 | /* Set TransOff and EndOfChain to 1 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 227 | dword = pci_read_config32(NODE_PCI(node, 4), (fam15h)?0x84:0xc4); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 228 | dword |= 0x000000c0; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 229 | pci_write_config32(NODE_PCI(node, 4), (fam15h)?0x84:0xc4, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 230 | } |
| 231 | } else if (internal_node_number == 1) { |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 232 | uint8_t package_link_3_connected = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0xf8:0xb8) & 0x1; |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 233 | if (package_link_3_connected) { |
| 234 | /* Set WidthIn and WidthOut to 0 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 235 | dword = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0xe4:0xa4); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 236 | dword &= ~0x77000000; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 237 | pci_write_config32(NODE_PCI(node, 0), (fam15h)?0xe4:0xa4, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 238 | /* Set Ganged to 1 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 239 | dword = pci_read_config32(NODE_PCI(node, 0), (fam15h)?0x18c:0x174); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 240 | dword |= 0x00000001; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 241 | pci_write_config32(NODE_PCI(node, 0), (fam15h)?0x18c:0x174, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 242 | } else { |
| 243 | /* Set ConnDly to 1 */ |
| 244 | dword = pci_read_config32(NODE_PCI(node, 0), 0x16c); |
| 245 | dword |= 0x00000100; |
| 246 | pci_write_config32(NODE_PCI(node, 0), 0x16c, dword); |
| 247 | /* Set TransOff and EndOfChain to 1 */ |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 248 | dword = pci_read_config32(NODE_PCI(node, 4), (fam15h)?0xe4:0xa4); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 249 | dword |= 0x000000c0; |
Timothy Pearson | 730a043 | 2015-10-16 13:51:51 -0500 | [diff] [blame^] | 250 | pci_write_config32(NODE_PCI(node, 4), (fam15h)?0xe4:0xa4, dword); |
Timothy Pearson | 1c4508e | 2015-09-05 17:50:29 -0500 | [diff] [blame] | 251 | } |
| 252 | } |
| 253 | } |
| 254 | } |
| 255 | } |
| 256 | } |
Marc Jones | 8ae8c88 | 2007-12-19 01:32:08 +0000 | [diff] [blame] | 257 | } |