Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Timothy Pearson | cbda504 | 2015-08-02 21:29:20 -0500 | [diff] [blame] | 4 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 5 | * Copyright (C) 2010 Advanced Micro Devices, Inc. |
Timothy Pearson | c3fcdcc | 2015-09-05 17:46:38 -0500 | [diff] [blame] | 6 | * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; version 2 of the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 18 | #include <stdint.h> |
| 19 | #include <arch/cpu.h> |
| 20 | #include <arch/io.h> |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 21 | #include <console/console.h> |
| 22 | #include <cpu/x86/msr.h> |
Timothy Pearson | 44e4a4e | 2015-08-11 17:49:06 -0500 | [diff] [blame] | 23 | #include <option.h> |
| 24 | #include <reset.h> |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 25 | #include "sr5650.h" |
| 26 | #include "cmn.h" |
| 27 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 28 | /* space = 0: AX_INDXC, AX_DATAC |
| 29 | * space = 1: AX_INDXP, AX_DATAP |
| 30 | */ |
| 31 | static void alink_ax_indx(u32 space, u32 axindc, u32 mask, u32 val) |
| 32 | { |
| 33 | u32 tmp; |
| 34 | |
| 35 | /* read axindc to tmp */ |
| 36 | outl(space << 30 | space << 3 | 0x30, AB_INDX); |
| 37 | outl(axindc, AB_DATA); |
| 38 | outl(space << 30 | space << 3 | 0x34, AB_INDX); |
| 39 | tmp = inl(AB_DATA); |
| 40 | |
| 41 | tmp &= ~mask; |
| 42 | tmp |= val; |
| 43 | |
| 44 | /* write tmp */ |
| 45 | outl(space << 30 | space << 3 | 0x30, AB_INDX); |
| 46 | outl(axindc, AB_DATA); |
| 47 | outl(space << 30 | space << 3 | 0x34, AB_INDX); |
| 48 | outl(tmp, AB_DATA); |
| 49 | } |
| 50 | |
| 51 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 52 | /* family 10 only, for reg > 0xFF */ |
Patrick Georgi | f8f0062 | 2012-05-05 15:50:17 +0200 | [diff] [blame] | 53 | #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 54 | static void set_fam10_ext_cfg_enable_bits(device_t fam10_dev, u32 reg_pos, u32 mask, |
| 55 | u32 val) |
| 56 | { |
| 57 | u32 reg_old, reg; |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 58 | reg = reg_old = pci_read_config32(fam10_dev, reg_pos); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 59 | reg &= ~mask; |
| 60 | reg |= val; |
| 61 | if (reg != reg_old) { |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 62 | pci_write_config32(fam10_dev, reg_pos, reg); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 63 | } |
| 64 | } |
| 65 | #else |
| 66 | #define set_fam10_ext_cfg_enable_bits(a, b, c, d) do {} while (0) |
| 67 | #endif |
| 68 | |
| 69 | |
| 70 | /* |
| 71 | * Compliant with CIM_33's ATINB_PrepareInit |
| 72 | */ |
| 73 | static void get_cpu_rev(void) |
| 74 | { |
| 75 | u32 eax; |
| 76 | |
| 77 | eax = cpuid_eax(1); |
| 78 | printk(BIOS_INFO, "get_cpu_rev EAX=0x%x.\n", eax); |
| 79 | if (eax <= 0xfff) |
| 80 | printk(BIOS_INFO, "CPU Rev is K8_Cx.\n"); |
| 81 | else if (eax <= 0x10fff) |
| 82 | printk(BIOS_INFO, "CPU Rev is K8_Dx.\n"); |
| 83 | else if (eax <= 0x20fff) |
| 84 | printk(BIOS_INFO, "CPU Rev is K8_Ex.\n"); |
| 85 | else if (eax <= 0x40fff) |
| 86 | printk(BIOS_INFO, "CPU Rev is K8_Fx.\n"); |
| 87 | else if (eax == 0x60fb1 || eax == 0x60f81) /*These two IDS are exception, they are G1. */ |
| 88 | printk(BIOS_INFO, "CPU Rev is K8_G1.\n"); |
| 89 | else if (eax <= 0X60FF0) |
| 90 | printk(BIOS_INFO, "CPU Rev is K8_G0.\n"); |
| 91 | else if (eax <= 0x100000) |
| 92 | printk(BIOS_INFO, "CPU Rev is K8_G1.\n"); |
Dave Frodin | da52aed | 2012-02-02 15:08:22 -0700 | [diff] [blame] | 93 | else if (eax <= 0x100fa0) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 94 | printk(BIOS_INFO, "CPU Rev is Fam 10.\n"); |
Timothy Pearson | 7a5413a | 2015-09-05 19:30:38 -0500 | [diff] [blame] | 95 | else if (eax <= 0x600f20) |
| 96 | printk(BIOS_INFO, "CPU Rev is Fam 15.\n"); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 97 | else |
| 98 | printk(BIOS_INFO, "CPU Rev is not recognized.\n"); |
| 99 | } |
| 100 | |
| 101 | /* |
| 102 | CIM NB_GetRevisionInfo() |
| 103 | */ |
| 104 | static u8 get_nb_rev(device_t nb_dev) |
| 105 | { |
| 106 | u8 reg; |
| 107 | reg = pci_read_config8(nb_dev, 0x8); /* copy from CIM, can't find in doc */ |
| 108 | switch(reg & 3) |
| 109 | { |
| 110 | case 0x00: |
| 111 | reg = REV_SR5650_A11; |
| 112 | break; |
| 113 | case 0x02: |
| 114 | default: |
| 115 | reg = REV_SR5650_A12; |
| 116 | break; |
| 117 | } |
| 118 | return reg; |
| 119 | } |
| 120 | |
| 121 | /***************************************** |
| 122 | * Compliant with SR5650_CIMX_4_5_0 NBHT_InitHT(). |
| 123 | * Init HT link speed/width for sr5650 -- k8 link |
| 124 | 1: Check CPU Family, Family10? |
| 125 | 2: Get CPU's HT speed and width |
| 126 | 3: Decide HT mode 1 or 3 by HT Speed. >1GHz: HT3, else HT1 |
| 127 | 4: |
| 128 | *****************************************/ |
| 129 | static const u8 sr5650_ibias[] = { |
| 130 | /* 1, 3 are reserved. */ |
Elyes HAOUAS | 0f92f63 | 2014-07-27 19:37:31 +0200 | [diff] [blame] | 131 | [0x0] = 0x44, /* 200MHz HyperTransport 1 only */ |
| 132 | [0x2] = 0x44, /* 400MHz HyperTransport 1 only */ |
| 133 | [0x4] = 0xB6, /* 600MHz HyperTransport 1 only */ |
| 134 | [0x5] = 0x44, /* 800MHz HyperTransport 1 only */ |
| 135 | [0x6] = 0x96, /* 1GHz HyperTransport 1 only */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 136 | /* HT3 for Family 10 */ |
Elyes HAOUAS | 0f92f63 | 2014-07-27 19:37:31 +0200 | [diff] [blame] | 137 | [0x7] = 0xB6, /* 1.2GHz HyperTransport 3 only */ |
| 138 | [0x8] = 0x23, /* 1.4GHz HyperTransport 3 only */ |
| 139 | [0x9] = 0x44, /* 1.6GHz HyperTransport 3 only */ |
| 140 | [0xa] = 0x64, /* 1.8GHz HyperTransport 3 only */ |
| 141 | [0xb] = 0x96, /* 2.0GHz HyperTransport 3 only */ |
| 142 | [0xc] = 0xA6, /* 2.2GHz HyperTransport 3 only */ |
| 143 | [0xd] = 0xB6, /* 2.4GHz HyperTransport 3 only */ |
| 144 | [0xe] = 0xC6, /* 2.6GHz HyperTransport 3 only */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 145 | }; |
| 146 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 147 | void sr5650_htinit(void) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 148 | { |
| 149 | /* |
| 150 | * About HT, it has been done in enumerate_ht_chain(). |
| 151 | */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 152 | device_t cpu_f0, sr5650_f0, clk_f1; |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 153 | u32 reg; |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 154 | u8 cpu_ht_freq, cpu_htfreq_max, ibias; |
| 155 | u8 sbnode; |
| 156 | u8 sblink; |
| 157 | u16 linkfreq_reg; |
| 158 | u16 linkfreqext_reg; |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 159 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 160 | /************************ |
| 161 | * get cpu's ht freq, in cpu's function 0, offset 0x88 |
| 162 | * bit11-8, specifics the maximum operation frequency of the link's transmitter clock. |
| 163 | * The link frequency field (Frq) is cleared by cold reset. SW can write a nonzero |
| 164 | * value to this reg, and that value takes effect on the next warm reset or |
| 165 | * LDTSTOP_L disconnect sequence. |
| 166 | * please see the table sr5650_ibias about the value and its corresponding frequency. |
| 167 | ************************/ |
| 168 | /* Link0, Link1 are for connection between P0 and P1. |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 169 | * TODO: Check the topology of the MP and NB. Or we just read the nbconfig? */ |
| 170 | /* NOTE: In most cases, we only have one CPU. In that case, we should read 0x88. */ |
| 171 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 172 | /* Find out the node ID and the Link ID that |
| 173 | * connects to the Southbridge (system IO hub). |
| 174 | */ |
| 175 | sbnode = (pci_read_config32(PCI_DEV(0, 0x18, 0), 0x60) >> 8) & 7; |
| 176 | sblink = (pci_read_config32(PCI_DEV(0, 0x18, 0), 0x64) >> 8) & 3; /* bit[10] sublink, bit[9,8] link. */ |
| 177 | cpu_f0 = PCI_DEV(0, (0x18 + sbnode), 0); |
| 178 | |
| 179 | /* |
| 180 | * link freq reg of Link0, 1, 2, 3 is 0x88, 0xA8, 0xC8, 0xE8 respectively |
| 181 | * link freq ext reg of Link0, 1, 2, 3 is 0x9C, 0xBC, 0xDC, 0xFC respectively |
| 182 | */ |
| 183 | linkfreq_reg = 0x88 + (sblink << 5); |
| 184 | linkfreqext_reg = 0x9C + (sblink << 5); |
| 185 | reg = pci_read_config32(cpu_f0, linkfreq_reg); |
| 186 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 187 | cpu_ht_freq = (reg & 0xf00) >> 8; |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 188 | |
| 189 | /* Freq[4] is only valid for revision D and later processors */ |
| 190 | if (cpuid_eax(1) >= 0x100F80) { |
| 191 | cpu_htfreq_max = 0x14; |
| 192 | cpu_ht_freq |= ((pci_read_config32(cpu_f0, linkfreqext_reg) & 0x01) << 4); |
| 193 | } else { |
| 194 | cpu_htfreq_max = 0x0F; |
| 195 | } |
| 196 | |
| 197 | printk(BIOS_INFO, "sr5650_htinit: Node %x Link %x, HT freq=%x.\n", |
| 198 | sbnode, sblink, cpu_ht_freq); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 199 | sr5650_f0 = PCI_DEV(0, 0, 0); |
| 200 | |
| 201 | clk_f1 = PCI_DEV(0, 0, 1); /* We need to make sure the F1 is accessible. */ |
| 202 | |
| 203 | ibias = sr5650_ibias[cpu_ht_freq]; |
| 204 | |
| 205 | /* If HT freq>1GHz, we assume the CPU is fam10, else it is K8. |
| 206 | * Is it appropriate? |
| 207 | * Frequency is 1GHz, i.e. cpu_ht_freq is 6, in most cases. |
| 208 | * So we check 6 only, it would be faster. */ |
| 209 | if ((cpu_ht_freq == 0x6) || (cpu_ht_freq == 0x5) || (cpu_ht_freq == 0x4) || |
| 210 | (cpu_ht_freq == 0x2) || (cpu_ht_freq == 0x0)) { |
| 211 | printk(BIOS_INFO, "sr5650_htinit: HT1 mode\n"); |
| 212 | |
| 213 | /* HT1 mode, RPR 5.4.2 */ |
| 214 | /* set IBIAS code */ |
| 215 | set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias); |
| 216 | /* Optimizes chipset HT transmitter drive strength */ |
| 217 | set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x3); |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 218 | } else if ((cpu_ht_freq > 0x6) && (cpu_ht_freq < cpu_htfreq_max)) { |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 219 | printk(BIOS_INFO, "sr5650_htinit: HT3 mode\n"); |
| 220 | |
| 221 | /* Enable Protocol checker */ |
| 222 | set_htiu_enable_bits(sr5650_f0, 0x1E, 0xFFFFFFFF, 0x7FFFFFFC); |
| 223 | |
Patrick Georgi | f8f0062 | 2012-05-05 15:50:17 +0200 | [diff] [blame] | 224 | #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 /* save some spaces */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 225 | /* HT3 mode, RPR 5.4.3 */ |
| 226 | set_nbcfg_enable_bits(sr5650_f0, 0x9c, 0x3 << 16, 0); |
| 227 | |
| 228 | /* set IBIAS code */ |
| 229 | set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias); |
| 230 | /* Optimizes chipset HT transmitter drive strength */ |
| 231 | set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x1); |
| 232 | /* Enables error-retry mode */ |
| 233 | set_nbcfg_enable_bits(sr5650_f0, 0x44, 0x1, 0x1); |
Martin Roth | 55e31a9 | 2014-12-16 20:53:49 -0700 | [diff] [blame] | 234 | /* Enables scrambling and Disables command throttling */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 235 | set_nbcfg_enable_bits(sr5650_f0, 0xac, (1 << 3) | (1 << 14), (1 << 3) | (1 << 14)); |
| 236 | /* Enables transmitter de-emphasis */ |
| 237 | set_nbcfg_enable_bits(sr5650_f0, 0xa4, 1 << 31, 1 << 31); |
Martin Roth | 55e31a9 | 2014-12-16 20:53:49 -0700 | [diff] [blame] | 238 | /* Enables transmitter de-emphasis level */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 239 | /* Sets training 0 time */ |
| 240 | set_nbcfg_enable_bits(sr5650_f0, 0xa0, 0x3F, 0x14); |
| 241 | |
| 242 | /* Enables strict TM4 detection */ |
| 243 | set_htiu_enable_bits(sr5650_f0, 0x15, 0x1 << 22, 0x1 << 22); |
| 244 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 245 | /* Optimizes chipset HT transmitter drive strength */ |
| 246 | set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3 << 0, 0x1 << 0); |
| 247 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 248 | /* HyperTransport 3 Processor register settings to be done in northbridge */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 249 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 250 | /* Enables error-retry mode */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 251 | set_fam10_ext_cfg_enable_bits(cpu_f0, 0x130 + (sblink << 2), 1 << 0, 1 << 0); |
| 252 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 253 | /* Enables scrambling */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 254 | set_fam10_ext_cfg_enable_bits(cpu_f0, 0x170 + (sblink << 2), 1 << 3, 1 << 3); |
| 255 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 256 | /* Enables transmitter de-emphasis |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 257 | * This depends on the PCB design and the trace |
| 258 | */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 259 | /* Disables command throttling */ |
| 260 | set_fam10_ext_cfg_enable_bits(cpu_f0, 0x168, 1 << 10, 1 << 10); |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 261 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 262 | /* Sets Training 0 Time. See T0Time table for encodings */ |
Martin Roth | 55e31a9 | 2014-12-16 20:53:49 -0700 | [diff] [blame] | 263 | /* AGESA have set it to recommended value already |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 264 | * The recommended values are 14h(2us) if F0x[18C:170][LS2En]=0 |
| 265 | * and 26h(12us) if F0x[18C:170][LS2En]=1 |
| 266 | */ |
| 267 | //set_fam10_ext_cfg_enable_bits(cpu_f0, 0x16C, 0x3F, 0x26); |
| 268 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 269 | /* HT Buffer Allocation for Ganged Links!!! */ |
Stefan Reinauer | 8ada152 | 2012-11-16 13:34:48 -0800 | [diff] [blame] | 270 | #endif /* CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 271 | } |
Timothy Pearson | 44e4a4e | 2015-08-11 17:49:06 -0500 | [diff] [blame] | 272 | |
| 273 | } |
| 274 | |
| 275 | /* Must be run immediately after HT setup is complete and first warm reset has occurred (if applicable) |
| 276 | * Attempting to switch the NB into isochronous mode before the CPUs have engaged isochronous mode |
| 277 | * will cause a system hard lockup... |
| 278 | */ |
| 279 | void sr5650_htinit_dect_and_enable_isochronous_link(void) |
| 280 | { |
| 281 | device_t sr5650_f0; |
| 282 | unsigned char iommu; |
| 283 | |
| 284 | sr5650_f0 = PCI_DEV(0, 0, 0); |
| 285 | |
| 286 | iommu = 1; |
| 287 | get_option(&iommu, "iommu"); |
| 288 | |
| 289 | if (iommu) { |
| 290 | /* Enable isochronous mode */ |
| 291 | set_nbcfg_enable_bits(sr5650_f0, 0xc8, 1 << 12, 1 << 12); |
| 292 | |
| 293 | /* Apply pending changes */ |
| 294 | if (!((pci_read_config32(sr5650_f0, 0xc8) >> 12) & 0x1)) { |
| 295 | printk(BIOS_INFO, "...WARM RESET...\n\n\n"); |
| 296 | soft_reset(); |
| 297 | die("After soft_reset_x - shouldn't see this message!!!\n"); |
| 298 | } |
| 299 | } |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Patrick Georgi | f8f0062 | 2012-05-05 15:50:17 +0200 | [diff] [blame] | 302 | #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 /* save some spaces */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 303 | void fam10_optimization(void) |
| 304 | { |
| 305 | device_t cpu_f0, cpu_f2, cpu_f3; |
| 306 | device_t cpu1_f0, cpu1_f2, cpu1_f3; |
| 307 | msr_t msr; |
| 308 | u32 val; |
| 309 | |
| 310 | printk(BIOS_INFO, "fam10_optimization()\n"); |
| 311 | msr = rdmsr(0xC001001F); |
| 312 | msr.hi |= 1 << 14; /* bit 46: EnableCf8ExtCfg */ |
| 313 | wrmsr(0xC001001F, msr); |
| 314 | |
| 315 | cpu_f0 = PCI_DEV(0, 0x18, 0); |
| 316 | cpu_f2 = PCI_DEV(0, 0x18, 2); |
| 317 | cpu_f3 = PCI_DEV(0, 0x18, 3); |
| 318 | cpu1_f0 = PCI_DEV(0, 0x19, 0); |
| 319 | cpu1_f2 = PCI_DEV(0, 0x19, 2); |
| 320 | cpu1_f3 = PCI_DEV(0, 0x19, 3); |
| 321 | |
| 322 | val = pci_read_config32(cpu1_f3, 0x8C); |
| 323 | val |= 1 << 14; |
| 324 | pci_write_config32(cpu1_f3, 0x8C, val); |
| 325 | |
| 326 | /* TODO: HT Buffer Allocation for (un)Ganged Links */ |
| 327 | /* rpr Table 5-11, 5-12 */ |
| 328 | } |
| 329 | #else |
| 330 | #define fam10_optimization() do{}while(0) |
Stefan Reinauer | 8ada152 | 2012-11-16 13:34:48 -0800 | [diff] [blame] | 331 | #endif /* CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 332 | |
| 333 | /***************************************** |
| 334 | * Compliant with CIM_33's ATINB_PCICFG_POR_TABLE |
| 335 | *****************************************/ |
| 336 | static void sr5650_por_pcicfg_init(device_t nb_dev) |
| 337 | { |
| 338 | /* enable PCI Memory Access */ |
| 339 | set_nbcfg_enable_bits_8(nb_dev, 0x04, (u8)(~0xFD), 0x02); |
| 340 | |
| 341 | set_nbcfg_enable_bits(nb_dev, 0x14, ~0, 0x0); |
| 342 | set_nbcfg_enable_bits(nb_dev, 0x18, ~0, 0x0); |
| 343 | set_nbcfg_enable_bits(nb_dev, 0x20, ~0, 0x0); |
| 344 | set_nbcfg_enable_bits(nb_dev, 0x84, ~0, 0x03000010); |
| 345 | |
| 346 | /* Reg4Ch[1]=1 (APIC_ENABLE) force cpu request with address 0xFECx_xxxx to south-bridge |
| 347 | * Reg4Ch[6]=1 (BMMsgEn) enable BM_Set message generation |
| 348 | * BMMsgEn */ |
| 349 | set_nbcfg_enable_bits(nb_dev, 0x4C, (u8)(~0x00), 0x52042); |
| 350 | |
| 351 | set_nbcfg_enable_bits(nb_dev, 0x7C, (u8)(~0), 0x0); |
| 352 | |
| 353 | /* Reg8Ch[10:9] = 0x3 Enables Gfx Debug BAR, |
| 354 | * force this BAR as mem type in sr5650_gfx.c */ |
| 355 | //set_nbcfg_enable_bits_8(nb_dev, 0x8D, (u8)(~0xFF), 0x03); |
| 356 | } |
| 357 | |
| 358 | /***************************************** |
| 359 | * Compliant with CIM_33's ATINB_MISCIND_POR_TABLE |
| 360 | * Compliant with CIM_33's MISC_INIT_TBL |
| 361 | *****************************************/ |
| 362 | static void sr5650_por_misc_index_init(device_t nb_dev) |
| 363 | { |
Timothy Pearson | 44e4a4e | 2015-08-11 17:49:06 -0500 | [diff] [blame] | 364 | unsigned char iommu; |
| 365 | |
| 366 | iommu = 1; |
| 367 | get_option(&iommu, "iommu"); |
| 368 | |
| 369 | if (iommu) { |
| 370 | /* enable IOMMU */ |
| 371 | printk(BIOS_DEBUG, "Enabling IOMMU\n"); |
| 372 | set_nbmisc_enable_bits(nb_dev, 0x75, 0x1, 0x1); |
| 373 | } else { |
| 374 | /* disable IOMMU */ |
| 375 | printk(BIOS_DEBUG, "Disabling IOMMU\n"); |
| 376 | set_nbmisc_enable_bits(nb_dev, 0x75, 0x1, 0x0); |
| 377 | } |
| 378 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 379 | /* NBMISCIND:0x75[29]= 1 Device ID for hotplug and PME message */ |
| 380 | set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 29, 1 << 29); |
| 381 | set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 9, 1 << 9); /* no doc reference, comply with BTS */ |
| 382 | set_nbmisc_enable_bits(nb_dev, 0x46, 1 << 7, 1 << 7); /* bit7 BTS fail*/ |
| 383 | /*P2P*/ |
| 384 | set_nbmisc_enable_bits(nb_dev, 0x48, 1 << 8, 0); |
| 385 | |
| 386 | set_nbmisc_enable_bits(nb_dev, 0x2A, 1 << 15 | 1 << 17, 1 << 17); |
| 387 | set_nbmisc_enable_bits(nb_dev, 0x2B, 1 << 15 | 1 << 27, 1 << 15 | 1 << 27); |
| 388 | set_nbmisc_enable_bits(nb_dev, 0x2C, 1 << 0 | 1 << 1 | 1 << 5 | 1 << 4 | 1 << 10, 1 << 0 | 1 << 1 | 1 << 5); |
| 389 | set_nbmisc_enable_bits(nb_dev, 0x32, 0x3F << 20, 0x2A << 20); |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 390 | set_nbmisc_enable_bits(nb_dev, 0x34, 1 << 7 | 1 << 15 | 1 << 23, 0); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 391 | set_nbmisc_enable_bits(nb_dev, 0x35, 0x3F << 26, 0x2A << 26); |
| 392 | set_nbmisc_enable_bits(nb_dev, 0x37, 0xfff << 20, 0xddd << 20); |
| 393 | set_nbmisc_enable_bits(nb_dev, 0x37, 7 << 11, 0); |
| 394 | /* PCIE CDR setting */ |
| 395 | set_nbmisc_enable_bits(nb_dev, 0x38, 0xFFFFFFFF, 0xC0C0C0); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 396 | set_nbmisc_enable_bits(nb_dev, 0x22, 0xFFFFFFFF, (1 << 27) | (0x8 << 12) | (0x8 << 16) | (0x8 << 20)); |
| 397 | set_nbmisc_enable_bits(nb_dev, 0x22, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7); |
| 398 | |
| 399 | set_nbmisc_enable_bits(nb_dev, 0x07, 0xF << 4 | 1 << 24, 0xF << 4 | 1 << 24); |
| 400 | set_nbmisc_enable_bits(nb_dev, 0x67, 1 << 10 | 1 << 11 | 1 << 26, 1 << 11); |
| 401 | set_nbmisc_enable_bits(nb_dev, 0x67, 3 << 21, 3 << 21); |
| 402 | set_nbmisc_enable_bits(nb_dev, 0x68, 1 << 8 | 1 << 9 | 1 << 19, 1 << 9 | 1 << 19); |
| 403 | set_nbmisc_enable_bits(nb_dev, 0x6B, 3 << 3 | 1 << 15 | 0x1F << 27, 3 << 3 | 1 << 15 | 0x1F << 27); |
| 404 | set_nbmisc_enable_bits(nb_dev, 0x6C, 0xFFFFFFFF, 0x41183000); |
| 405 | |
| 406 | /* NB_MISC_IND_WR_EN + IOC_PCIE_CNTL |
| 407 | * Block non-snoop DMA request if PMArbDis is set. |
| 408 | * Set BMSetDis */ |
| 409 | set_nbmisc_enable_bits(nb_dev, 0x0B, 0xFFFFFFFF, 0x00400180); |
| 410 | set_nbmisc_enable_bits(nb_dev, 0x01, 0xFFFFFFFF, 0x00000310); |
| 411 | |
| 412 | /* NBCFG (NBMISCIND 0x0): NB_CNTL - |
Timothy Pearson | a8c6c7f | 2015-08-13 17:45:12 -0500 | [diff] [blame] | 413 | * HIDE_NB_AGP_CAP ([0], default=1)HIDE |
| 414 | * HIDE_P2P_AGP_CAP ([1], default=1)HIDE |
| 415 | * HIDE_NB_GART_BAR ([2], default=1)HIDE |
| 416 | * HIDE_MMCFG_BAR ([3], default=1)SHOW |
| 417 | * AGPMODE30 ([4], default=0)DISABLE |
| 418 | * AGP30ENCHANCED ([5], default=0)DISABLE |
| 419 | * HIDE_CLKCFG_HEADER ([8], default=0)SHOW */ |
| 420 | set_nbmisc_enable_bits(nb_dev, 0x00, 0x0000FFFF, 0 << 0 | 1 << 1 | 1 << 2 | 0 << 3 | 0 << 6 | 0 << 8); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 421 | |
| 422 | /* IOC_LAT_PERF_CNTR_CNTL */ |
| 423 | set_nbmisc_enable_bits(nb_dev, 0x30, 0xFF, 0x00); |
| 424 | //set_nbmisc_enable_bits(nb_dev, 0x31, 0xFF, 0x00); |
| 425 | |
| 426 | /* IOC_LAT_PERF_CNTR_OUT */ |
| 427 | /* IOC_JTAG_CNTL */ |
| 428 | set_nbmisc_enable_bits(nb_dev, 0x47, 0xFFFFFFFF, 0x0000000B); |
| 429 | |
| 430 | set_nbmisc_enable_bits(nb_dev, 0x12, 0xFFFFFFFF, 0x00FB5555); |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 431 | set_nbmisc_enable_bits(nb_dev, 0x0C, 0xFFFFFFFF, 0x001F37FC); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 432 | set_nbmisc_enable_bits(nb_dev, 0x15, 0xFFFFFFFF, 0x0); |
| 433 | |
| 434 | /* NB_PROG_DEVICE_REMAP */ |
| 435 | set_nbmisc_enable_bits(nb_dev, 0x20, 0xFFFFFFFF, 0x0); |
| 436 | set_nbmisc_enable_bits(nb_dev, 0x21, 0xFFFFFFFF, 0x0); |
| 437 | |
| 438 | /* Compliant with CIM_33's MISC_INIT_TBL, except Hide NB_BAR3_PCIE |
| 439 | * Enable access to DEV8 |
| 440 | * Enable setPower message for all ports |
| 441 | */ |
| 442 | set_nbmisc_enable_bits(nb_dev, 0x51, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 443 | set_nbmisc_enable_bits(nb_dev, 0x53, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 444 | set_nbmisc_enable_bits(nb_dev, 0x55, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 445 | set_nbmisc_enable_bits(nb_dev, 0x57, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 446 | set_nbmisc_enable_bits(nb_dev, 0x59, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 447 | set_nbmisc_enable_bits(nb_dev, 0x5B, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 448 | set_nbmisc_enable_bits(nb_dev, 0x5D, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 449 | set_nbmisc_enable_bits(nb_dev, 0x5F, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 450 | set_nbmisc_enable_bits(nb_dev, 0x61, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 451 | set_nbmisc_enable_bits(nb_dev, 0x63, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8); |
| 452 | |
| 453 | /* Disable bus-master trigger event from SB and Enable set_slot_power message to SB */ |
| 454 | set_nbmisc_enable_bits(nb_dev, 0x0B, 0xffffffff, 0x400180); |
| 455 | } |
| 456 | |
| 457 | /***************************************** |
| 458 | * Some setting is from rpr. Some is from CIMx. |
| 459 | *****************************************/ |
| 460 | static void sr5650_por_htiu_index_init(device_t nb_dev) |
| 461 | { |
| 462 | device_t cpu_f0; |
| 463 | |
| 464 | cpu_f0 = PCI_DEV(0, 0x18, 0); |
| 465 | |
| 466 | set_htiu_enable_bits(nb_dev, 0x1C, 0x1<<17, 0x1<<17); |
| 467 | set_htiu_enable_bits(nb_dev, 0x05, 0x1<<8, 0x1<<8); |
| 468 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<0, 0x0<<0); |
| 469 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<1, 0x1<<1); |
| 470 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<9, 0x1<<9); |
| 471 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<13, 0x1<<13); |
| 472 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<17, 0x1<<17); |
| 473 | set_htiu_enable_bits(nb_dev, 0x06, 0x3<<15, 0x3<<15); |
| 474 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<25, 0x1<<25); |
| 475 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<30, 0x1<<30); |
| 476 | |
| 477 | set_htiu_enable_bits(nb_dev, 0x07, 0x1 << 0 | 0x1 << 1 | 0x1 << 2, 0x1 << 0); |
| 478 | |
| 479 | set_htiu_enable_bits(nb_dev, 0x16, 0x1<<11, 0x1<<11); |
| 480 | |
| 481 | set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<2, 0x1<<2); |
| 482 | set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<4, 0x1<<4); |
| 483 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 484 | axindxc_reg(0x10, 1 << 9, 1 << 9); |
| 485 | set_pcie_enable_bits(nb_dev, 0x10 | 5 << 16, 1 << 9, 1 << 9); |
| 486 | set_htiu_enable_bits(nb_dev, 0x06, 0x1<<26, 0x1<<26); |
| 487 | set_htiu_enable_bits(nb_dev, 0x16, 0x1<<10, 0x1<<10); |
| 488 | |
| 489 | /* Enable BIAS circuit for all lanes. */ |
| 490 | //set_htiu_enable_bits(nb_dev, 0x2B, 0xF<<28, 0xF<<28); |
| 491 | set_htiu_enable_bits(nb_dev, 0x2B, 0xF << 28, 0); |
| 492 | set_htiu_enable_bits(nb_dev, 0x05, 0xFFFFFF, 0xFF558); |
| 493 | set_htiu_enable_bits(nb_dev, 0x06, 0xFFFFFFFE, 0x04203A202); |
| 494 | set_htiu_enable_bits(nb_dev, 0x0C, 0xFFFF, 0x101); |
| 495 | |
| 496 | /* A21 only */ |
| 497 | //if (REV_SR5650_A21 == get_nb_rev(nb_dev)) { |
| 498 | if (get_nb_rev(nb_dev) > REV_SR5650_A11) { |
| 499 | set_htiu_enable_bits(nb_dev, 0x05, 0x3<<3| 1<<6 | 1<<10 | 0xFF<<12, 0x3<<3 | 1<<6 | 1<<10 | 0xFF<<12); |
| 500 | set_htiu_enable_bits(nb_dev, 0x1D, 1 << 2 | 1 << 4, 0); |
| 501 | } |
| 502 | } |
| 503 | |
| 504 | /***************************************** |
| 505 | * Compliant with CIM_33's ATINB_POR_INIT_JMPDI |
| 506 | * Configure SR5650 registers to power-on default RPR. |
| 507 | * POR: Power On Reset |
| 508 | * RPR: Register Programming Requirements |
| 509 | *****************************************/ |
| 510 | static void sr5650_por_init(device_t nb_dev) |
| 511 | { |
| 512 | printk(BIOS_INFO, "sr5650_por_init\n"); |
| 513 | /* ATINB_PCICFG_POR_TABLE, initialize the values for sr5650 PCI Config registers */ |
| 514 | sr5650_por_pcicfg_init(nb_dev); |
| 515 | |
| 516 | /* ATINB_MISCIND_POR_TABLE */ |
| 517 | sr5650_por_misc_index_init(nb_dev); |
| 518 | |
| 519 | /* ATINB_HTIUNBIND_POR_TABLE */ |
| 520 | sr5650_por_htiu_index_init(nb_dev); |
| 521 | |
| 522 | /* ATINB_CLKCFG_PORT_TABLE */ |
| 523 | /* sr5650 A11 SB Link full swing? */ |
| 524 | } |
| 525 | |
| 526 | /* enable CFG access to Dev8, which is the SB P2P Bridge */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 527 | void enable_sr5650_dev8(void) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 528 | { |
| 529 | set_nbmisc_enable_bits(PCI_DEV(0, 0, 0), 0x00, 1 << 6, 1 << 6); |
| 530 | } |
| 531 | |
| 532 | /* |
| 533 | * Compliant with CIM_33's AtiNBInitEarlyPost (AtiInitNBBeforePCIInit). |
| 534 | */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 535 | void sr5650_before_pci_init(void) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 536 | { |
| 537 | } |
| 538 | |
| 539 | /* |
| 540 | * The calling sequence is same as CIM. |
| 541 | */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 542 | void sr5650_early_setup(void) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 543 | { |
| 544 | device_t nb_dev = PCI_DEV(0, 0, 0); |
| 545 | printk(BIOS_INFO, "sr5650_early_setup()\n"); |
| 546 | |
| 547 | /*ATINB_PrepareInit */ |
| 548 | get_cpu_rev(); |
| 549 | |
Timothy Pearson | c3fcdcc | 2015-09-05 17:46:38 -0500 | [diff] [blame] | 550 | uint8_t revno = get_nb_rev(nb_dev); |
| 551 | switch (revno) { /* PCIEMiscInit */ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 552 | case REV_SR5650_A11: |
| 553 | printk(BIOS_INFO, "NB Revision is A11.\n"); |
| 554 | break; |
| 555 | case REV_SR5650_A12: |
| 556 | printk(BIOS_INFO, "NB Revision is A12.\n"); |
| 557 | break; |
| 558 | case REV_SR5650_A21: |
| 559 | printk(BIOS_INFO, "NB Revision is A21.\n"); |
| 560 | break; |
Timothy Pearson | c3fcdcc | 2015-09-05 17:46:38 -0500 | [diff] [blame] | 561 | default: |
| 562 | printk(BIOS_INFO, "NB Revision is %02x (Unrecognized).\n", revno); |
| 563 | break; |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 564 | } |
| 565 | |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 566 | fam10_optimization(); |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 567 | sr5650_por_init(nb_dev); |
| 568 | } |
| 569 | |
| 570 | /** |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 571 | * @brief disable GPP1 Port0,1, GPP2, GPP3a Port0,1,2,3,4,5, GPP3b |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 572 | * |
| 573 | */ |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 574 | void sr5650_disable_pcie_bridge(void) |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 575 | { |
| 576 | u32 mask; |
| 577 | u32 reg; |
| 578 | device_t nb_dev = PCI_DEV(0, 0, 0); |
| 579 | |
efdesign98 | 00c8c4a | 2011-07-20 12:37:58 -0600 | [diff] [blame] | 580 | mask = (1 << 2) | (1 << 3); /*GPP1*/ |
| 581 | mask |= (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 16) | (1 << 17); /*GPP3a*/ |
| 582 | mask |= (1 << 18) | (1 << 19); /*GPP2*/ |
| 583 | mask |= (1 << 20); /*GPP3b*/ |
Zheng Bao | 98fcc09 | 2011-03-27 16:39:58 +0000 | [diff] [blame] | 584 | reg = mask; |
| 585 | set_nbmisc_enable_bits(nb_dev, 0x0c, mask, reg); |
| 586 | } |