blob: 62b0dab930e054508d3d9429a6cffb26ba606e59 [file] [log] [blame]
Zheng Bao98fcc092011-03-27 16:39:58 +00001/*
2 * This file is part of the coreboot project.
3 *
Timothy Pearsoncbda5042015-08-02 21:29:20 -05004 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Zheng Bao98fcc092011-03-27 16:39:58 +00005 * Copyright (C) 2010 Advanced Micro Devices, Inc.
Timothy Pearsonc3fcdcc2015-09-05 17:46:38 -05006 * Copyright (C) 2015 Timothy Pearson <tpearson@raptorengineeringinc.com>, Raptor Engineering
Zheng Bao98fcc092011-03-27 16:39:58 +00007 *
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.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010019 * Foundation, Inc.
Zheng Bao98fcc092011-03-27 16:39:58 +000020 */
21
efdesign9800c8c4a2011-07-20 12:37:58 -060022#include <stdint.h>
23#include <arch/cpu.h>
24#include <arch/io.h>
efdesign9800c8c4a2011-07-20 12:37:58 -060025#include <console/console.h>
26#include <cpu/x86/msr.h>
Zheng Bao98fcc092011-03-27 16:39:58 +000027#include "sr5650.h"
28#include "cmn.h"
29
efdesign9800c8c4a2011-07-20 12:37:58 -060030/* space = 0: AX_INDXC, AX_DATAC
31 * space = 1: AX_INDXP, AX_DATAP
32 */
33static void alink_ax_indx(u32 space, u32 axindc, u32 mask, u32 val)
34{
35 u32 tmp;
36
37 /* read axindc to tmp */
38 outl(space << 30 | space << 3 | 0x30, AB_INDX);
39 outl(axindc, AB_DATA);
40 outl(space << 30 | space << 3 | 0x34, AB_INDX);
41 tmp = inl(AB_DATA);
42
43 tmp &= ~mask;
44 tmp |= val;
45
46 /* write tmp */
47 outl(space << 30 | space << 3 | 0x30, AB_INDX);
48 outl(axindc, AB_DATA);
49 outl(space << 30 | space << 3 | 0x34, AB_INDX);
50 outl(tmp, AB_DATA);
51}
52
53
Zheng Bao98fcc092011-03-27 16:39:58 +000054/* family 10 only, for reg > 0xFF */
Patrick Georgif8f00622012-05-05 15:50:17 +020055#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10
Zheng Bao98fcc092011-03-27 16:39:58 +000056static void set_fam10_ext_cfg_enable_bits(device_t fam10_dev, u32 reg_pos, u32 mask,
57 u32 val)
58{
59 u32 reg_old, reg;
efdesign9800c8c4a2011-07-20 12:37:58 -060060 reg = reg_old = pci_read_config32(fam10_dev, reg_pos);
Zheng Bao98fcc092011-03-27 16:39:58 +000061 reg &= ~mask;
62 reg |= val;
63 if (reg != reg_old) {
efdesign9800c8c4a2011-07-20 12:37:58 -060064 pci_write_config32(fam10_dev, reg_pos, reg);
Zheng Bao98fcc092011-03-27 16:39:58 +000065 }
66}
67#else
68#define set_fam10_ext_cfg_enable_bits(a, b, c, d) do {} while (0)
69#endif
70
71
72/*
73* Compliant with CIM_33's ATINB_PrepareInit
74*/
75static void get_cpu_rev(void)
76{
77 u32 eax;
78
79 eax = cpuid_eax(1);
80 printk(BIOS_INFO, "get_cpu_rev EAX=0x%x.\n", eax);
81 if (eax <= 0xfff)
82 printk(BIOS_INFO, "CPU Rev is K8_Cx.\n");
83 else if (eax <= 0x10fff)
84 printk(BIOS_INFO, "CPU Rev is K8_Dx.\n");
85 else if (eax <= 0x20fff)
86 printk(BIOS_INFO, "CPU Rev is K8_Ex.\n");
87 else if (eax <= 0x40fff)
88 printk(BIOS_INFO, "CPU Rev is K8_Fx.\n");
89 else if (eax == 0x60fb1 || eax == 0x60f81) /*These two IDS are exception, they are G1. */
90 printk(BIOS_INFO, "CPU Rev is K8_G1.\n");
91 else if (eax <= 0X60FF0)
92 printk(BIOS_INFO, "CPU Rev is K8_G0.\n");
93 else if (eax <= 0x100000)
94 printk(BIOS_INFO, "CPU Rev is K8_G1.\n");
Dave Frodinda52aed2012-02-02 15:08:22 -070095 else if (eax <= 0x100fa0)
Zheng Bao98fcc092011-03-27 16:39:58 +000096 printk(BIOS_INFO, "CPU Rev is Fam 10.\n");
Timothy Pearson7a5413a2015-09-05 19:30:38 -050097 else if (eax <= 0x600f20)
98 printk(BIOS_INFO, "CPU Rev is Fam 15.\n");
Zheng Bao98fcc092011-03-27 16:39:58 +000099 else
100 printk(BIOS_INFO, "CPU Rev is not recognized.\n");
101}
102
103/*
104CIM NB_GetRevisionInfo()
105*/
106static u8 get_nb_rev(device_t nb_dev)
107{
108 u8 reg;
109 reg = pci_read_config8(nb_dev, 0x8); /* copy from CIM, can't find in doc */
110 switch(reg & 3)
111 {
112 case 0x00:
113 reg = REV_SR5650_A11;
114 break;
115 case 0x02:
116 default:
117 reg = REV_SR5650_A12;
118 break;
119 }
120 return reg;
121}
122
123/*****************************************
124* Compliant with SR5650_CIMX_4_5_0 NBHT_InitHT().
125* Init HT link speed/width for sr5650 -- k8 link
1261: Check CPU Family, Family10?
1272: Get CPU's HT speed and width
1283: Decide HT mode 1 or 3 by HT Speed. >1GHz: HT3, else HT1
1294:
130*****************************************/
131static const u8 sr5650_ibias[] = {
132 /* 1, 3 are reserved. */
Elyes HAOUAS0f92f632014-07-27 19:37:31 +0200133 [0x0] = 0x44, /* 200MHz HyperTransport 1 only */
134 [0x2] = 0x44, /* 400MHz HyperTransport 1 only */
135 [0x4] = 0xB6, /* 600MHz HyperTransport 1 only */
136 [0x5] = 0x44, /* 800MHz HyperTransport 1 only */
137 [0x6] = 0x96, /* 1GHz HyperTransport 1 only */
Zheng Bao98fcc092011-03-27 16:39:58 +0000138 /* HT3 for Family 10 */
Elyes HAOUAS0f92f632014-07-27 19:37:31 +0200139 [0x7] = 0xB6, /* 1.2GHz HyperTransport 3 only */
140 [0x8] = 0x23, /* 1.4GHz HyperTransport 3 only */
141 [0x9] = 0x44, /* 1.6GHz HyperTransport 3 only */
142 [0xa] = 0x64, /* 1.8GHz HyperTransport 3 only */
143 [0xb] = 0x96, /* 2.0GHz HyperTransport 3 only */
144 [0xc] = 0xA6, /* 2.2GHz HyperTransport 3 only */
145 [0xd] = 0xB6, /* 2.4GHz HyperTransport 3 only */
146 [0xe] = 0xC6, /* 2.6GHz HyperTransport 3 only */
Zheng Bao98fcc092011-03-27 16:39:58 +0000147};
148
efdesign9800c8c4a2011-07-20 12:37:58 -0600149void sr5650_htinit(void)
Zheng Bao98fcc092011-03-27 16:39:58 +0000150{
151 /*
152 * About HT, it has been done in enumerate_ht_chain().
153 */
efdesign9800c8c4a2011-07-20 12:37:58 -0600154 device_t cpu_f0, sr5650_f0, clk_f1;
Zheng Bao98fcc092011-03-27 16:39:58 +0000155 u32 reg;
efdesign9800c8c4a2011-07-20 12:37:58 -0600156 u8 cpu_ht_freq, cpu_htfreq_max, ibias;
157 u8 sbnode;
158 u8 sblink;
159 u16 linkfreq_reg;
160 u16 linkfreqext_reg;
Zheng Bao98fcc092011-03-27 16:39:58 +0000161
Zheng Bao98fcc092011-03-27 16:39:58 +0000162 /************************
163 * get cpu's ht freq, in cpu's function 0, offset 0x88
164 * bit11-8, specifics the maximum operation frequency of the link's transmitter clock.
165 * The link frequency field (Frq) is cleared by cold reset. SW can write a nonzero
166 * value to this reg, and that value takes effect on the next warm reset or
167 * LDTSTOP_L disconnect sequence.
168 * please see the table sr5650_ibias about the value and its corresponding frequency.
169 ************************/
170 /* Link0, Link1 are for connection between P0 and P1.
Zheng Bao98fcc092011-03-27 16:39:58 +0000171 * TODO: Check the topology of the MP and NB. Or we just read the nbconfig? */
172 /* NOTE: In most cases, we only have one CPU. In that case, we should read 0x88. */
173
efdesign9800c8c4a2011-07-20 12:37:58 -0600174 /* Find out the node ID and the Link ID that
175 * connects to the Southbridge (system IO hub).
176 */
177 sbnode = (pci_read_config32(PCI_DEV(0, 0x18, 0), 0x60) >> 8) & 7;
178 sblink = (pci_read_config32(PCI_DEV(0, 0x18, 0), 0x64) >> 8) & 3; /* bit[10] sublink, bit[9,8] link. */
179 cpu_f0 = PCI_DEV(0, (0x18 + sbnode), 0);
180
181 /*
182 * link freq reg of Link0, 1, 2, 3 is 0x88, 0xA8, 0xC8, 0xE8 respectively
183 * link freq ext reg of Link0, 1, 2, 3 is 0x9C, 0xBC, 0xDC, 0xFC respectively
184 */
185 linkfreq_reg = 0x88 + (sblink << 5);
186 linkfreqext_reg = 0x9C + (sblink << 5);
187 reg = pci_read_config32(cpu_f0, linkfreq_reg);
188
Zheng Bao98fcc092011-03-27 16:39:58 +0000189 cpu_ht_freq = (reg & 0xf00) >> 8;
efdesign9800c8c4a2011-07-20 12:37:58 -0600190
191 /* Freq[4] is only valid for revision D and later processors */
192 if (cpuid_eax(1) >= 0x100F80) {
193 cpu_htfreq_max = 0x14;
194 cpu_ht_freq |= ((pci_read_config32(cpu_f0, linkfreqext_reg) & 0x01) << 4);
195 } else {
196 cpu_htfreq_max = 0x0F;
197 }
198
199 printk(BIOS_INFO, "sr5650_htinit: Node %x Link %x, HT freq=%x.\n",
200 sbnode, sblink, cpu_ht_freq);
Zheng Bao98fcc092011-03-27 16:39:58 +0000201 sr5650_f0 = PCI_DEV(0, 0, 0);
202
203 clk_f1 = PCI_DEV(0, 0, 1); /* We need to make sure the F1 is accessible. */
204
205 ibias = sr5650_ibias[cpu_ht_freq];
206
207 /* If HT freq>1GHz, we assume the CPU is fam10, else it is K8.
208 * Is it appropriate?
209 * Frequency is 1GHz, i.e. cpu_ht_freq is 6, in most cases.
210 * So we check 6 only, it would be faster. */
211 if ((cpu_ht_freq == 0x6) || (cpu_ht_freq == 0x5) || (cpu_ht_freq == 0x4) ||
212 (cpu_ht_freq == 0x2) || (cpu_ht_freq == 0x0)) {
213 printk(BIOS_INFO, "sr5650_htinit: HT1 mode\n");
214
215 /* HT1 mode, RPR 5.4.2 */
216 /* set IBIAS code */
217 set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias);
218 /* Optimizes chipset HT transmitter drive strength */
219 set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x3);
efdesign9800c8c4a2011-07-20 12:37:58 -0600220 } else if ((cpu_ht_freq > 0x6) && (cpu_ht_freq < cpu_htfreq_max)) {
Zheng Bao98fcc092011-03-27 16:39:58 +0000221 printk(BIOS_INFO, "sr5650_htinit: HT3 mode\n");
222
223 /* Enable Protocol checker */
224 set_htiu_enable_bits(sr5650_f0, 0x1E, 0xFFFFFFFF, 0x7FFFFFFC);
225
Patrick Georgif8f00622012-05-05 15:50:17 +0200226#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 /* save some spaces */
Zheng Bao98fcc092011-03-27 16:39:58 +0000227 /* HT3 mode, RPR 5.4.3 */
228 set_nbcfg_enable_bits(sr5650_f0, 0x9c, 0x3 << 16, 0);
229
230 /* set IBIAS code */
231 set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias);
232 /* Optimizes chipset HT transmitter drive strength */
233 set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x1);
234 /* Enables error-retry mode */
235 set_nbcfg_enable_bits(sr5650_f0, 0x44, 0x1, 0x1);
Martin Roth55e31a92014-12-16 20:53:49 -0700236 /* Enables scrambling and Disables command throttling */
Zheng Bao98fcc092011-03-27 16:39:58 +0000237 set_nbcfg_enable_bits(sr5650_f0, 0xac, (1 << 3) | (1 << 14), (1 << 3) | (1 << 14));
238 /* Enables transmitter de-emphasis */
239 set_nbcfg_enable_bits(sr5650_f0, 0xa4, 1 << 31, 1 << 31);
Martin Roth55e31a92014-12-16 20:53:49 -0700240 /* Enables transmitter de-emphasis level */
Zheng Bao98fcc092011-03-27 16:39:58 +0000241 /* Sets training 0 time */
242 set_nbcfg_enable_bits(sr5650_f0, 0xa0, 0x3F, 0x14);
243
244 /* Enables strict TM4 detection */
245 set_htiu_enable_bits(sr5650_f0, 0x15, 0x1 << 22, 0x1 << 22);
246
efdesign9800c8c4a2011-07-20 12:37:58 -0600247 /* Optimizes chipset HT transmitter drive strength */
248 set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3 << 0, 0x1 << 0);
249
Zheng Bao98fcc092011-03-27 16:39:58 +0000250 /* HyperTransport 3 Processor register settings to be done in northbridge */
efdesign9800c8c4a2011-07-20 12:37:58 -0600251
Zheng Bao98fcc092011-03-27 16:39:58 +0000252 /* Enables error-retry mode */
efdesign9800c8c4a2011-07-20 12:37:58 -0600253 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x130 + (sblink << 2), 1 << 0, 1 << 0);
254
Zheng Bao98fcc092011-03-27 16:39:58 +0000255 /* Enables scrambling */
efdesign9800c8c4a2011-07-20 12:37:58 -0600256 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x170 + (sblink << 2), 1 << 3, 1 << 3);
257
Zheng Bao98fcc092011-03-27 16:39:58 +0000258 /* Enables transmitter de-emphasis
efdesign9800c8c4a2011-07-20 12:37:58 -0600259 * This depends on the PCB design and the trace
260 */
Zheng Bao98fcc092011-03-27 16:39:58 +0000261 /* Disables command throttling */
262 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x168, 1 << 10, 1 << 10);
efdesign9800c8c4a2011-07-20 12:37:58 -0600263
Zheng Bao98fcc092011-03-27 16:39:58 +0000264 /* Sets Training 0 Time. See T0Time table for encodings */
Martin Roth55e31a92014-12-16 20:53:49 -0700265 /* AGESA have set it to recommended value already
efdesign9800c8c4a2011-07-20 12:37:58 -0600266 * The recommended values are 14h(2us) if F0x[18C:170][LS2En]=0
267 * and 26h(12us) if F0x[18C:170][LS2En]=1
268 */
269 //set_fam10_ext_cfg_enable_bits(cpu_f0, 0x16C, 0x3F, 0x26);
270
Zheng Bao98fcc092011-03-27 16:39:58 +0000271 /* HT Buffer Allocation for Ganged Links!!! */
Stefan Reinauer8ada1522012-11-16 13:34:48 -0800272#endif /* CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 */
Zheng Bao98fcc092011-03-27 16:39:58 +0000273 }
274}
275
Patrick Georgif8f00622012-05-05 15:50:17 +0200276#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 /* save some spaces */
Zheng Bao98fcc092011-03-27 16:39:58 +0000277void fam10_optimization(void)
278{
279 device_t cpu_f0, cpu_f2, cpu_f3;
280 device_t cpu1_f0, cpu1_f2, cpu1_f3;
281 msr_t msr;
282 u32 val;
283
284 printk(BIOS_INFO, "fam10_optimization()\n");
285 msr = rdmsr(0xC001001F);
286 msr.hi |= 1 << 14; /* bit 46: EnableCf8ExtCfg */
287 wrmsr(0xC001001F, msr);
288
289 cpu_f0 = PCI_DEV(0, 0x18, 0);
290 cpu_f2 = PCI_DEV(0, 0x18, 2);
291 cpu_f3 = PCI_DEV(0, 0x18, 3);
292 cpu1_f0 = PCI_DEV(0, 0x19, 0);
293 cpu1_f2 = PCI_DEV(0, 0x19, 2);
294 cpu1_f3 = PCI_DEV(0, 0x19, 3);
295
296 val = pci_read_config32(cpu1_f3, 0x8C);
297 val |= 1 << 14;
298 pci_write_config32(cpu1_f3, 0x8C, val);
299
300 /* TODO: HT Buffer Allocation for (un)Ganged Links */
301 /* rpr Table 5-11, 5-12 */
302}
303#else
304#define fam10_optimization() do{}while(0)
Stefan Reinauer8ada1522012-11-16 13:34:48 -0800305#endif /* CONFIG_NORTHBRIDGE_AMD_AMDFAM10 || CONFIG_NORTHBRIDGE_AMD_AGESA_FAMILY10 */
Zheng Bao98fcc092011-03-27 16:39:58 +0000306
307/*****************************************
308* Compliant with CIM_33's ATINB_PCICFG_POR_TABLE
309*****************************************/
310static void sr5650_por_pcicfg_init(device_t nb_dev)
311{
312 /* enable PCI Memory Access */
313 set_nbcfg_enable_bits_8(nb_dev, 0x04, (u8)(~0xFD), 0x02);
314
315 set_nbcfg_enable_bits(nb_dev, 0x14, ~0, 0x0);
316 set_nbcfg_enable_bits(nb_dev, 0x18, ~0, 0x0);
317 set_nbcfg_enable_bits(nb_dev, 0x20, ~0, 0x0);
318 set_nbcfg_enable_bits(nb_dev, 0x84, ~0, 0x03000010);
319
320 /* Reg4Ch[1]=1 (APIC_ENABLE) force cpu request with address 0xFECx_xxxx to south-bridge
321 * Reg4Ch[6]=1 (BMMsgEn) enable BM_Set message generation
322 * BMMsgEn */
323 set_nbcfg_enable_bits(nb_dev, 0x4C, (u8)(~0x00), 0x52042);
324
325 set_nbcfg_enable_bits(nb_dev, 0x7C, (u8)(~0), 0x0);
326
327 /* Reg8Ch[10:9] = 0x3 Enables Gfx Debug BAR,
328 * force this BAR as mem type in sr5650_gfx.c */
329 //set_nbcfg_enable_bits_8(nb_dev, 0x8D, (u8)(~0xFF), 0x03);
330}
331
332/*****************************************
333* Compliant with CIM_33's ATINB_MISCIND_POR_TABLE
334* Compliant with CIM_33's MISC_INIT_TBL
335*****************************************/
336static void sr5650_por_misc_index_init(device_t nb_dev)
337{
338 /* disable IOMMU */
339 set_nbmisc_enable_bits(nb_dev, 0x75, 0x1, 0x0);
340 /* NBMISCIND:0x75[29]= 1 Device ID for hotplug and PME message */
341 set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 29, 1 << 29);
342 set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 9, 1 << 9); /* no doc reference, comply with BTS */
343 set_nbmisc_enable_bits(nb_dev, 0x46, 1 << 7, 1 << 7); /* bit7 BTS fail*/
344 /*P2P*/
345 set_nbmisc_enable_bits(nb_dev, 0x48, 1 << 8, 0);
346
347 set_nbmisc_enable_bits(nb_dev, 0x2A, 1 << 15 | 1 << 17, 1 << 17);
348 set_nbmisc_enable_bits(nb_dev, 0x2B, 1 << 15 | 1 << 27, 1 << 15 | 1 << 27);
349 set_nbmisc_enable_bits(nb_dev, 0x2C, 1 << 0 | 1 << 1 | 1 << 5 | 1 << 4 | 1 << 10, 1 << 0 | 1 << 1 | 1 << 5);
350 set_nbmisc_enable_bits(nb_dev, 0x32, 0x3F << 20, 0x2A << 20);
efdesign9800c8c4a2011-07-20 12:37:58 -0600351 set_nbmisc_enable_bits(nb_dev, 0x34, 1 << 7 | 1 << 15 | 1 << 23, 0);
Zheng Bao98fcc092011-03-27 16:39:58 +0000352 set_nbmisc_enable_bits(nb_dev, 0x35, 0x3F << 26, 0x2A << 26);
353 set_nbmisc_enable_bits(nb_dev, 0x37, 0xfff << 20, 0xddd << 20);
354 set_nbmisc_enable_bits(nb_dev, 0x37, 7 << 11, 0);
355 /* PCIE CDR setting */
356 set_nbmisc_enable_bits(nb_dev, 0x38, 0xFFFFFFFF, 0xC0C0C0);
Zheng Bao98fcc092011-03-27 16:39:58 +0000357 set_nbmisc_enable_bits(nb_dev, 0x22, 0xFFFFFFFF, (1 << 27) | (0x8 << 12) | (0x8 << 16) | (0x8 << 20));
358 set_nbmisc_enable_bits(nb_dev, 0x22, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7);
359
360 set_nbmisc_enable_bits(nb_dev, 0x07, 0xF << 4 | 1 << 24, 0xF << 4 | 1 << 24);
361 set_nbmisc_enable_bits(nb_dev, 0x67, 1 << 10 | 1 << 11 | 1 << 26, 1 << 11);
362 set_nbmisc_enable_bits(nb_dev, 0x67, 3 << 21, 3 << 21);
363 set_nbmisc_enable_bits(nb_dev, 0x68, 1 << 8 | 1 << 9 | 1 << 19, 1 << 9 | 1 << 19);
364 set_nbmisc_enable_bits(nb_dev, 0x6B, 3 << 3 | 1 << 15 | 0x1F << 27, 3 << 3 | 1 << 15 | 0x1F << 27);
365 set_nbmisc_enable_bits(nb_dev, 0x6C, 0xFFFFFFFF, 0x41183000);
366
367 /* NB_MISC_IND_WR_EN + IOC_PCIE_CNTL
368 * Block non-snoop DMA request if PMArbDis is set.
369 * Set BMSetDis */
370 set_nbmisc_enable_bits(nb_dev, 0x0B, 0xFFFFFFFF, 0x00400180);
371 set_nbmisc_enable_bits(nb_dev, 0x01, 0xFFFFFFFF, 0x00000310);
372
373 /* NBCFG (NBMISCIND 0x0): NB_CNTL -
374 * HIDE_NB_AGP_CAP ([0], default=1)HIDE
375 * HIDE_P2P_AGP_CAP ([1], default=1)HIDE
376 * HIDE_NB_GART_BAR ([2], default=1)HIDE
377 * AGPMODE30 ([4], default=0)DISABLE
378 * AGP30ENCHANCED ([5], default=0)DISABLE
379 * HIDE_AGP_CAP ([8], default=1)ENABLE */
380 set_nbmisc_enable_bits(nb_dev, 0x00, 0x0000FFFF, 0 << 0 | 1 << 1 | 1 << 2 | 0 << 6);
381
382 /* IOC_LAT_PERF_CNTR_CNTL */
383 set_nbmisc_enable_bits(nb_dev, 0x30, 0xFF, 0x00);
384 //set_nbmisc_enable_bits(nb_dev, 0x31, 0xFF, 0x00);
385
386 /* IOC_LAT_PERF_CNTR_OUT */
387 /* IOC_JTAG_CNTL */
388 set_nbmisc_enable_bits(nb_dev, 0x47, 0xFFFFFFFF, 0x0000000B);
389
390 set_nbmisc_enable_bits(nb_dev, 0x12, 0xFFFFFFFF, 0x00FB5555);
efdesign9800c8c4a2011-07-20 12:37:58 -0600391 set_nbmisc_enable_bits(nb_dev, 0x0C, 0xFFFFFFFF, 0x001F37FC);
Zheng Bao98fcc092011-03-27 16:39:58 +0000392 set_nbmisc_enable_bits(nb_dev, 0x15, 0xFFFFFFFF, 0x0);
393
394 /* NB_PROG_DEVICE_REMAP */
395 set_nbmisc_enable_bits(nb_dev, 0x20, 0xFFFFFFFF, 0x0);
396 set_nbmisc_enable_bits(nb_dev, 0x21, 0xFFFFFFFF, 0x0);
397
398 /* Compliant with CIM_33's MISC_INIT_TBL, except Hide NB_BAR3_PCIE
399 * Enable access to DEV8
400 * Enable setPower message for all ports
401 */
402 set_nbmisc_enable_bits(nb_dev, 0x51, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
403 set_nbmisc_enable_bits(nb_dev, 0x53, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
404 set_nbmisc_enable_bits(nb_dev, 0x55, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
405 set_nbmisc_enable_bits(nb_dev, 0x57, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
406 set_nbmisc_enable_bits(nb_dev, 0x59, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
407 set_nbmisc_enable_bits(nb_dev, 0x5B, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
408 set_nbmisc_enable_bits(nb_dev, 0x5D, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
409 set_nbmisc_enable_bits(nb_dev, 0x5F, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
410 set_nbmisc_enable_bits(nb_dev, 0x61, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
411 set_nbmisc_enable_bits(nb_dev, 0x63, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
412
413 /* Disable bus-master trigger event from SB and Enable set_slot_power message to SB */
414 set_nbmisc_enable_bits(nb_dev, 0x0B, 0xffffffff, 0x400180);
415}
416
417/*****************************************
418* Some setting is from rpr. Some is from CIMx.
419*****************************************/
420static void sr5650_por_htiu_index_init(device_t nb_dev)
421{
422 device_t cpu_f0;
423
424 cpu_f0 = PCI_DEV(0, 0x18, 0);
425
426 set_htiu_enable_bits(nb_dev, 0x1C, 0x1<<17, 0x1<<17);
427 set_htiu_enable_bits(nb_dev, 0x05, 0x1<<8, 0x1<<8);
428 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<0, 0x0<<0);
429 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<1, 0x1<<1);
430 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<9, 0x1<<9);
431 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<13, 0x1<<13);
432 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<17, 0x1<<17);
433 set_htiu_enable_bits(nb_dev, 0x06, 0x3<<15, 0x3<<15);
434 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<25, 0x1<<25);
435 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<30, 0x1<<30);
436
437 set_htiu_enable_bits(nb_dev, 0x07, 0x1 << 0 | 0x1 << 1 | 0x1 << 2, 0x1 << 0);
438
439 set_htiu_enable_bits(nb_dev, 0x16, 0x1<<11, 0x1<<11);
440
441 set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<2, 0x1<<2);
442 set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<4, 0x1<<4);
443
Zheng Bao98fcc092011-03-27 16:39:58 +0000444 axindxc_reg(0x10, 1 << 9, 1 << 9);
445 set_pcie_enable_bits(nb_dev, 0x10 | 5 << 16, 1 << 9, 1 << 9);
446 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<26, 0x1<<26);
447 set_htiu_enable_bits(nb_dev, 0x16, 0x1<<10, 0x1<<10);
448
449 /* Enable BIAS circuit for all lanes. */
450 //set_htiu_enable_bits(nb_dev, 0x2B, 0xF<<28, 0xF<<28);
451 set_htiu_enable_bits(nb_dev, 0x2B, 0xF << 28, 0);
452 set_htiu_enable_bits(nb_dev, 0x05, 0xFFFFFF, 0xFF558);
453 set_htiu_enable_bits(nb_dev, 0x06, 0xFFFFFFFE, 0x04203A202);
454 set_htiu_enable_bits(nb_dev, 0x0C, 0xFFFF, 0x101);
455
456 /* A21 only */
457 //if (REV_SR5650_A21 == get_nb_rev(nb_dev)) {
458 if (get_nb_rev(nb_dev) > REV_SR5650_A11) {
459 set_htiu_enable_bits(nb_dev, 0x05, 0x3<<3| 1<<6 | 1<<10 | 0xFF<<12, 0x3<<3 | 1<<6 | 1<<10 | 0xFF<<12);
460 set_htiu_enable_bits(nb_dev, 0x1D, 1 << 2 | 1 << 4, 0);
461 }
462}
463
464/*****************************************
465* Compliant with CIM_33's ATINB_POR_INIT_JMPDI
466* Configure SR5650 registers to power-on default RPR.
467* POR: Power On Reset
468* RPR: Register Programming Requirements
469*****************************************/
470static void sr5650_por_init(device_t nb_dev)
471{
472 printk(BIOS_INFO, "sr5650_por_init\n");
473 /* ATINB_PCICFG_POR_TABLE, initialize the values for sr5650 PCI Config registers */
474 sr5650_por_pcicfg_init(nb_dev);
475
476 /* ATINB_MISCIND_POR_TABLE */
477 sr5650_por_misc_index_init(nb_dev);
478
479 /* ATINB_HTIUNBIND_POR_TABLE */
480 sr5650_por_htiu_index_init(nb_dev);
481
482 /* ATINB_CLKCFG_PORT_TABLE */
483 /* sr5650 A11 SB Link full swing? */
484}
485
486/* enable CFG access to Dev8, which is the SB P2P Bridge */
efdesign9800c8c4a2011-07-20 12:37:58 -0600487void enable_sr5650_dev8(void)
Zheng Bao98fcc092011-03-27 16:39:58 +0000488{
489 set_nbmisc_enable_bits(PCI_DEV(0, 0, 0), 0x00, 1 << 6, 1 << 6);
490}
491
492/*
493* Compliant with CIM_33's AtiNBInitEarlyPost (AtiInitNBBeforePCIInit).
494*/
efdesign9800c8c4a2011-07-20 12:37:58 -0600495void sr5650_before_pci_init(void)
Zheng Bao98fcc092011-03-27 16:39:58 +0000496{
497}
498
499/*
500* The calling sequence is same as CIM.
501*/
efdesign9800c8c4a2011-07-20 12:37:58 -0600502void sr5650_early_setup(void)
Zheng Bao98fcc092011-03-27 16:39:58 +0000503{
504 device_t nb_dev = PCI_DEV(0, 0, 0);
505 printk(BIOS_INFO, "sr5650_early_setup()\n");
506
507 /*ATINB_PrepareInit */
508 get_cpu_rev();
509
Timothy Pearsonc3fcdcc2015-09-05 17:46:38 -0500510 uint8_t revno = get_nb_rev(nb_dev);
511 switch (revno) { /* PCIEMiscInit */
Zheng Bao98fcc092011-03-27 16:39:58 +0000512 case REV_SR5650_A11:
513 printk(BIOS_INFO, "NB Revision is A11.\n");
514 break;
515 case REV_SR5650_A12:
516 printk(BIOS_INFO, "NB Revision is A12.\n");
517 break;
518 case REV_SR5650_A21:
519 printk(BIOS_INFO, "NB Revision is A21.\n");
520 break;
Timothy Pearsonc3fcdcc2015-09-05 17:46:38 -0500521 default:
522 printk(BIOS_INFO, "NB Revision is %02x (Unrecognized).\n", revno);
523 break;
Zheng Bao98fcc092011-03-27 16:39:58 +0000524 }
525
Zheng Bao98fcc092011-03-27 16:39:58 +0000526 fam10_optimization();
Zheng Bao98fcc092011-03-27 16:39:58 +0000527 sr5650_por_init(nb_dev);
528}
529
530/**
efdesign9800c8c4a2011-07-20 12:37:58 -0600531 * @brief disable GPP1 Port0,1, GPP2, GPP3a Port0,1,2,3,4,5, GPP3b
Zheng Bao98fcc092011-03-27 16:39:58 +0000532 *
533 */
efdesign9800c8c4a2011-07-20 12:37:58 -0600534void sr5650_disable_pcie_bridge(void)
Zheng Bao98fcc092011-03-27 16:39:58 +0000535{
536 u32 mask;
537 u32 reg;
538 device_t nb_dev = PCI_DEV(0, 0, 0);
539
efdesign9800c8c4a2011-07-20 12:37:58 -0600540 mask = (1 << 2) | (1 << 3); /*GPP1*/
541 mask |= (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) | (1 << 16) | (1 << 17); /*GPP3a*/
542 mask |= (1 << 18) | (1 << 19); /*GPP2*/
543 mask |= (1 << 20); /*GPP3b*/
Zheng Bao98fcc092011-03-27 16:39:58 +0000544 reg = mask;
545 set_nbmisc_enable_bits(nb_dev, 0x0c, mask, reg);
546}