blob: 5f7438ce85e733bc12e4fb4b629c21c7089803a2 [file] [log] [blame]
Zheng Bao98fcc092011-03-27 16:39:58 +00001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2010 Advanced Micro Devices, Inc.
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include "sr5650.h"
21#include "cmn.h"
22
23/* family 10 only, for reg > 0xFF */
24#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1
25static void set_fam10_ext_cfg_enable_bits(device_t fam10_dev, u32 reg_pos, u32 mask,
26 u32 val)
27{
28 u32 reg_old, reg;
29 reg = reg_old = Get_NB32(fam10_dev, reg_pos);
30 reg &= ~mask;
31 reg |= val;
32 if (reg != reg_old) {
33 Set_NB32(fam10_dev, reg_pos, reg);
34 }
35}
36#else
37#define set_fam10_ext_cfg_enable_bits(a, b, c, d) do {} while (0)
38#endif
39
40
41/*
42* Compliant with CIM_33's ATINB_PrepareInit
43*/
44static void get_cpu_rev(void)
45{
46 u32 eax;
47
48 eax = cpuid_eax(1);
49 printk(BIOS_INFO, "get_cpu_rev EAX=0x%x.\n", eax);
50 if (eax <= 0xfff)
51 printk(BIOS_INFO, "CPU Rev is K8_Cx.\n");
52 else if (eax <= 0x10fff)
53 printk(BIOS_INFO, "CPU Rev is K8_Dx.\n");
54 else if (eax <= 0x20fff)
55 printk(BIOS_INFO, "CPU Rev is K8_Ex.\n");
56 else if (eax <= 0x40fff)
57 printk(BIOS_INFO, "CPU Rev is K8_Fx.\n");
58 else if (eax == 0x60fb1 || eax == 0x60f81) /*These two IDS are exception, they are G1. */
59 printk(BIOS_INFO, "CPU Rev is K8_G1.\n");
60 else if (eax <= 0X60FF0)
61 printk(BIOS_INFO, "CPU Rev is K8_G0.\n");
62 else if (eax <= 0x100000)
63 printk(BIOS_INFO, "CPU Rev is K8_G1.\n");
64 else if (eax <= 0x100f00)
65 printk(BIOS_INFO, "CPU Rev is Fam 10.\n");
66 else
67 printk(BIOS_INFO, "CPU Rev is not recognized.\n");
68}
69
70/*
71CIM NB_GetRevisionInfo()
72*/
73static u8 get_nb_rev(device_t nb_dev)
74{
75 u8 reg;
76 reg = pci_read_config8(nb_dev, 0x8); /* copy from CIM, can't find in doc */
77 switch(reg & 3)
78 {
79 case 0x00:
80 reg = REV_SR5650_A11;
81 break;
82 case 0x02:
83 default:
84 reg = REV_SR5650_A12;
85 break;
86 }
87 return reg;
88}
89
90/*****************************************
91* Compliant with SR5650_CIMX_4_5_0 NBHT_InitHT().
92* Init HT link speed/width for sr5650 -- k8 link
931: Check CPU Family, Family10?
942: Get CPU's HT speed and width
953: Decide HT mode 1 or 3 by HT Speed. >1GHz: HT3, else HT1
964:
97*****************************************/
98static const u8 sr5650_ibias[] = {
99 /* 1, 3 are reserved. */
100 [0x0] = 0x44, /* 200Mhz HyperTransport 1 only */
101 [0x2] = 0x44, /* 400Mhz HyperTransport 1 only */
102 [0x4] = 0xB6, /* 600Mhz HyperTransport 1 only */
103 [0x5] = 0x44, /* 800Mhz HyperTransport 1 only */
104 [0x6] = 0x96, /* 1Ghz HyperTransport 1 only */
105 /* HT3 for Family 10 */
106 [0x7] = 0xB6, /* 1.2Ghz HyperTransport 3 only */
107 [0x8] = 0x23, /* 1.4Ghz HyperTransport 3 only */
108 [0x9] = 0x44, /* 1.6Ghz HyperTransport 3 only */
109 [0xa] = 0x64, /* 1.8Ghz HyperTransport 3 only */
110 [0xb] = 0x96, /* 2.0Ghz HyperTransport 3 only */
111 [0xc] = 0xA6, /* 2.2Ghz HyperTransport 3 only */
112 [0xd] = 0xB6, /* 2.4Ghz HyperTransport 3 only */
113 [0xe] = 0xC6, /* 2.6Ghz HyperTransport 3 only */
114};
115
116static void sr5650_htinit(void)
117{
118 /*
119 * About HT, it has been done in enumerate_ht_chain().
120 */
121 device_t cpu_f0, sr5650_f0, clk_f1, cpu1_f0;
122 u32 reg;
123 u8 cpu_ht_freq, ibias;
124
125 cpu_f0 = PCI_DEV(0, 0x18, 0);
126 cpu1_f0 = PCI_DEV(0, 0x19, 0);
127 /************************
128 * get cpu's ht freq, in cpu's function 0, offset 0x88
129 * bit11-8, specifics the maximum operation frequency of the link's transmitter clock.
130 * The link frequency field (Frq) is cleared by cold reset. SW can write a nonzero
131 * value to this reg, and that value takes effect on the next warm reset or
132 * LDTSTOP_L disconnect sequence.
133 * please see the table sr5650_ibias about the value and its corresponding frequency.
134 ************************/
135 /* Link0, Link1 are for connection between P0 and P1.
136 * Link2 should be 0xC8?
137 * TODO: Check the topology of the MP and NB. Or we just read the nbconfig? */
138 /* NOTE: In most cases, we only have one CPU. In that case, we should read 0x88. */
139
140 reg = pci_read_config32(cpu1_f0, 0x0);
141 reg = pci_read_config32(cpu_f0,
142 reg == 0 || reg == -1 ? 0x88 : 0xC8
143 );
144 cpu_ht_freq = (reg & 0xf00) >> 8;
145 printk(BIOS_INFO, "sr5650_htinit cpu_ht_freq=%x.\n", cpu_ht_freq);
146 sr5650_f0 = PCI_DEV(0, 0, 0);
147
148 clk_f1 = PCI_DEV(0, 0, 1); /* We need to make sure the F1 is accessible. */
149
150 ibias = sr5650_ibias[cpu_ht_freq];
151
152 /* If HT freq>1GHz, we assume the CPU is fam10, else it is K8.
153 * Is it appropriate?
154 * Frequency is 1GHz, i.e. cpu_ht_freq is 6, in most cases.
155 * So we check 6 only, it would be faster. */
156 if ((cpu_ht_freq == 0x6) || (cpu_ht_freq == 0x5) || (cpu_ht_freq == 0x4) ||
157 (cpu_ht_freq == 0x2) || (cpu_ht_freq == 0x0)) {
158 printk(BIOS_INFO, "sr5650_htinit: HT1 mode\n");
159
160 /* HT1 mode, RPR 5.4.2 */
161 /* set IBIAS code */
162 set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias);
163 /* Optimizes chipset HT transmitter drive strength */
164 set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x3);
165 } else if ((cpu_ht_freq > 0x6) && (cpu_ht_freq < 0xf)) {
166 printk(BIOS_INFO, "sr5650_htinit: HT3 mode\n");
167
168 /* Enable Protocol checker */
169 set_htiu_enable_bits(sr5650_f0, 0x1E, 0xFFFFFFFF, 0x7FFFFFFC);
170
171 #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1 /* save some spaces */
172 /* HT3 mode, RPR 5.4.3 */
173 set_nbcfg_enable_bits(sr5650_f0, 0x9c, 0x3 << 16, 0);
174
175 /* set IBIAS code */
176 set_nbcfg_enable_bits(clk_f1, 0xD8, 0x3FF, ibias);
177 /* Optimizes chipset HT transmitter drive strength */
178 set_htiu_enable_bits(sr5650_f0, 0x2A, 0x3, 0x1);
179 /* Enables error-retry mode */
180 set_nbcfg_enable_bits(sr5650_f0, 0x44, 0x1, 0x1);
181 /* Enables scrambling and Disalbes command throttling */
182 set_nbcfg_enable_bits(sr5650_f0, 0xac, (1 << 3) | (1 << 14), (1 << 3) | (1 << 14));
183 /* Enables transmitter de-emphasis */
184 set_nbcfg_enable_bits(sr5650_f0, 0xa4, 1 << 31, 1 << 31);
185 /* Enabels transmitter de-emphasis level */
186 /* Sets training 0 time */
187 set_nbcfg_enable_bits(sr5650_f0, 0xa0, 0x3F, 0x14);
188
189 /* Enables strict TM4 detection */
190 set_htiu_enable_bits(sr5650_f0, 0x15, 0x1 << 22, 0x1 << 22);
191
192 /* HyperTransport 3 Processor register settings to be done in northbridge */
193 /* Enables error-retry mode */
194 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x130, 1 << 0, 1 << 0);
195 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x134, 1 << 0, 1 << 0); /* TODO: Check if it is needed to set other node. */
196 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x138, 1 << 0, 1 << 0);
197 /* Enables scrambling */
198 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x170, 1 << 3, 1 << 3);
199 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x174, 1 << 3, 1 << 3); /* TODO: Check if it is needed to set other node. */
200 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x178, 1 << 3, 1 << 3);
201 /* Enables transmitter de-emphasis
202 * This depends on the PCB design and the trace */
203 /* Disables command throttling */
204 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x168, 1 << 10, 1 << 10);
205 /* Sets Training 0 Time. See T0Time table for encodings */
206 set_fam10_ext_cfg_enable_bits(cpu_f0, 0x16C, 0x3F, 0x20);
207 /* HT Buffer Allocation for Ganged Links!!! */
208 #endif /* #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1 */
209 }
210}
211
212#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 != 1 /* save some spaces */
213/*******************************************************
214* Optimize k8 with UMA.
215* See BKDG_NPT_0F guide for details.
216* The processor node is addressed by its Node ID on the HT link and can be
217* accessed with a device number in the PCI configuration space on Bus0.
218* The Node ID 0 is mapped to Device 24 (0x18), the Node ID 1 is mapped
219* to Device 25, and so on.
220* The processor implements configuration registers in PCI configuration
221* space using the following four headers
222* Function0: HT technology configuration
223* Function1: Address map configuration
224* Function2: DRAM and HT technology Trace mode configuration
225* Function3: Miscellaneous configuration
226*******************************************************/
227static void k8_optimization(void)
228{
229 device_t k8_f0, k8_f2, k8_f3;
230 msr_t msr;
231
232 printk(BIOS_INFO, "k8_optimization()\n");
233 k8_f0 = PCI_DEV(0, 0x18, 0);
234 k8_f2 = PCI_DEV(0, 0x18, 2);
235 k8_f3 = PCI_DEV(0, 0x18, 3);
236
237 pci_write_config32(k8_f0, 0x90, 0x01700169); /* CIM NPT_Optimization */
238 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 28, 0 << 28);
239 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 26 | 1 << 27,
240 1 << 26 | 1 << 27);
241 set_nbcfg_enable_bits(k8_f0, 0x68, 1 << 11, 1 << 11);
242 /* set_nbcfg_enable_bits(k8_f0, 0x84, 1 << 11 | 1 << 13 | 1 << 15, 1 << 11 | 1 << 13 | 1 << 15); */ /* TODO */
243
244 pci_write_config32(k8_f3, 0x70, 0x51220111); /* CIM NPT_Optimization */
245 pci_write_config32(k8_f3, 0x74, 0x50404021);
246 pci_write_config32(k8_f3, 0x78, 0x08002A00);
247 if (pci_read_config32(k8_f3, 0xE8) & 0x3<<12)
248 pci_write_config32(k8_f3, 0x7C, 0x0000211A); /* dual core */
249 else
250 pci_write_config32(k8_f3, 0x7C, 0x0000212B); /* single core */
251 set_nbcfg_enable_bits_8(k8_f3, 0xDC, 0xFF, 0x25);
252
253 set_nbcfg_enable_bits(k8_f2, 0xA0, 1 << 5, 1 << 5);
254 set_nbcfg_enable_bits(k8_f2, 0x94, 0xF << 24, 7 << 24);
255 set_nbcfg_enable_bits(k8_f2, 0x90, 1 << 10, 0 << 10);
256 set_nbcfg_enable_bits(k8_f2, 0xA0, 3 << 2, 3 << 2);
257 set_nbcfg_enable_bits(k8_f2, 0xA0, 1 << 5, 1 << 5);
258
259 msr = rdmsr(0xC001001F);
260 msr.lo &= ~(1 << 9);
261 msr.hi &= ~(1 << 4);
262 wrmsr(0xC001001F, msr);
263}
264#else
265#define k8_optimization() do{}while(0)
266#endif /* #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 != 1 */
267
268#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1 /* save some spaces */
269void fam10_optimization(void)
270{
271 device_t cpu_f0, cpu_f2, cpu_f3;
272 device_t cpu1_f0, cpu1_f2, cpu1_f3;
273 msr_t msr;
274 u32 val;
275
276 printk(BIOS_INFO, "fam10_optimization()\n");
277 msr = rdmsr(0xC001001F);
278 msr.hi |= 1 << 14; /* bit 46: EnableCf8ExtCfg */
279 wrmsr(0xC001001F, msr);
280
281 cpu_f0 = PCI_DEV(0, 0x18, 0);
282 cpu_f2 = PCI_DEV(0, 0x18, 2);
283 cpu_f3 = PCI_DEV(0, 0x18, 3);
284 cpu1_f0 = PCI_DEV(0, 0x19, 0);
285 cpu1_f2 = PCI_DEV(0, 0x19, 2);
286 cpu1_f3 = PCI_DEV(0, 0x19, 3);
287
288 val = pci_read_config32(cpu1_f3, 0x8C);
289 val |= 1 << 14;
290 pci_write_config32(cpu1_f3, 0x8C, val);
291
292 /* TODO: HT Buffer Allocation for (un)Ganged Links */
293 /* rpr Table 5-11, 5-12 */
294}
295#else
296#define fam10_optimization() do{}while(0)
297#endif /* #if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1 */
298
299/*****************************************
300* Compliant with CIM_33's ATINB_PCICFG_POR_TABLE
301*****************************************/
302static void sr5650_por_pcicfg_init(device_t nb_dev)
303{
304 /* enable PCI Memory Access */
305 set_nbcfg_enable_bits_8(nb_dev, 0x04, (u8)(~0xFD), 0x02);
306
307 set_nbcfg_enable_bits(nb_dev, 0x14, ~0, 0x0);
308 set_nbcfg_enable_bits(nb_dev, 0x18, ~0, 0x0);
309 set_nbcfg_enable_bits(nb_dev, 0x20, ~0, 0x0);
310 set_nbcfg_enable_bits(nb_dev, 0x84, ~0, 0x03000010);
311
312 /* Reg4Ch[1]=1 (APIC_ENABLE) force cpu request with address 0xFECx_xxxx to south-bridge
313 * Reg4Ch[6]=1 (BMMsgEn) enable BM_Set message generation
314 * BMMsgEn */
315 set_nbcfg_enable_bits(nb_dev, 0x4C, (u8)(~0x00), 0x52042);
316
317 set_nbcfg_enable_bits(nb_dev, 0x7C, (u8)(~0), 0x0);
318
319 /* Reg8Ch[10:9] = 0x3 Enables Gfx Debug BAR,
320 * force this BAR as mem type in sr5650_gfx.c */
321 //set_nbcfg_enable_bits_8(nb_dev, 0x8D, (u8)(~0xFF), 0x03);
322}
323
324/*****************************************
325* Compliant with CIM_33's ATINB_MISCIND_POR_TABLE
326* Compliant with CIM_33's MISC_INIT_TBL
327*****************************************/
328static void sr5650_por_misc_index_init(device_t nb_dev)
329{
330 /* disable IOMMU */
331 set_nbmisc_enable_bits(nb_dev, 0x75, 0x1, 0x0);
332 /* NBMISCIND:0x75[29]= 1 Device ID for hotplug and PME message */
333 set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 29, 1 << 29);
334 set_nbmisc_enable_bits(nb_dev, 0x75, 1 << 9, 1 << 9); /* no doc reference, comply with BTS */
335 set_nbmisc_enable_bits(nb_dev, 0x46, 1 << 7, 1 << 7); /* bit7 BTS fail*/
336 /*P2P*/
337 set_nbmisc_enable_bits(nb_dev, 0x48, 1 << 8, 0);
338
339 set_nbmisc_enable_bits(nb_dev, 0x2A, 1 << 15 | 1 << 17, 1 << 17);
340 set_nbmisc_enable_bits(nb_dev, 0x2B, 1 << 15 | 1 << 27, 1 << 15 | 1 << 27);
341 set_nbmisc_enable_bits(nb_dev, 0x2C, 1 << 0 | 1 << 1 | 1 << 5 | 1 << 4 | 1 << 10, 1 << 0 | 1 << 1 | 1 << 5);
342 set_nbmisc_enable_bits(nb_dev, 0x32, 0x3F << 20, 0x2A << 20);
343 set_nbmisc_enable_bits(nb_dev, 0x34, 1 << 7 | 1 << 15 | 1 << 23 | 1 << 31, 0); /* bit31 BTS fail */
344 set_nbmisc_enable_bits(nb_dev, 0x35, 0x3F << 26, 0x2A << 26);
345 set_nbmisc_enable_bits(nb_dev, 0x37, 0xfff << 20, 0xddd << 20);
346 set_nbmisc_enable_bits(nb_dev, 0x37, 7 << 11, 0);
347 /* PCIE CDR setting */
348 set_nbmisc_enable_bits(nb_dev, 0x38, 0xFFFFFFFF, 0xC0C0C0);
349 set_nbmisc_enable_bits(nb_dev, 0x39, 1 << 31, 0); /* bit31 BTS fail */
350 set_nbmisc_enable_bits(nb_dev, 0x22, 0xFFFFFFFF, (1 << 27) | (0x8 << 12) | (0x8 << 16) | (0x8 << 20));
351 set_nbmisc_enable_bits(nb_dev, 0x22, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7, 1 << 1 | 1 << 2 | 1 << 6 | 1 << 7);
352
353 set_nbmisc_enable_bits(nb_dev, 0x07, 0xF << 4 | 1 << 24, 0xF << 4 | 1 << 24);
354 set_nbmisc_enable_bits(nb_dev, 0x67, 1 << 10 | 1 << 11 | 1 << 26, 1 << 11);
355 set_nbmisc_enable_bits(nb_dev, 0x67, 3 << 21, 3 << 21);
356 set_nbmisc_enable_bits(nb_dev, 0x68, 1 << 8 | 1 << 9 | 1 << 19, 1 << 9 | 1 << 19);
357 set_nbmisc_enable_bits(nb_dev, 0x6B, 3 << 3 | 1 << 15 | 0x1F << 27, 3 << 3 | 1 << 15 | 0x1F << 27);
358 set_nbmisc_enable_bits(nb_dev, 0x6C, 0xFFFFFFFF, 0x41183000);
359
360 /* NB_MISC_IND_WR_EN + IOC_PCIE_CNTL
361 * Block non-snoop DMA request if PMArbDis is set.
362 * Set BMSetDis */
363 set_nbmisc_enable_bits(nb_dev, 0x0B, 0xFFFFFFFF, 0x00400180);
364 set_nbmisc_enable_bits(nb_dev, 0x01, 0xFFFFFFFF, 0x00000310);
365
366 /* NBCFG (NBMISCIND 0x0): NB_CNTL -
367 * HIDE_NB_AGP_CAP ([0], default=1)HIDE
368 * HIDE_P2P_AGP_CAP ([1], default=1)HIDE
369 * HIDE_NB_GART_BAR ([2], default=1)HIDE
370 * AGPMODE30 ([4], default=0)DISABLE
371 * AGP30ENCHANCED ([5], default=0)DISABLE
372 * HIDE_AGP_CAP ([8], default=1)ENABLE */
373 set_nbmisc_enable_bits(nb_dev, 0x00, 0x0000FFFF, 0 << 0 | 1 << 1 | 1 << 2 | 0 << 6);
374
375 /* IOC_LAT_PERF_CNTR_CNTL */
376 set_nbmisc_enable_bits(nb_dev, 0x30, 0xFF, 0x00);
377 //set_nbmisc_enable_bits(nb_dev, 0x31, 0xFF, 0x00);
378
379 /* IOC_LAT_PERF_CNTR_OUT */
380 /* IOC_JTAG_CNTL */
381 set_nbmisc_enable_bits(nb_dev, 0x47, 0xFFFFFFFF, 0x0000000B);
382
383 set_nbmisc_enable_bits(nb_dev, 0x12, 0xFFFFFFFF, 0x00FB5555);
384 set_nbmisc_enable_bits(nb_dev, 0x0C, 0xFFFFFFFF, 0x001f37EC);
385 set_nbmisc_enable_bits(nb_dev, 0x15, 0xFFFFFFFF, 0x0);
386
387 /* NB_PROG_DEVICE_REMAP */
388 set_nbmisc_enable_bits(nb_dev, 0x20, 0xFFFFFFFF, 0x0);
389 set_nbmisc_enable_bits(nb_dev, 0x21, 0xFFFFFFFF, 0x0);
390
391 /* Compliant with CIM_33's MISC_INIT_TBL, except Hide NB_BAR3_PCIE
392 * Enable access to DEV8
393 * Enable setPower message for all ports
394 */
395 set_nbmisc_enable_bits(nb_dev, 0x51, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
396 set_nbmisc_enable_bits(nb_dev, 0x53, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
397 set_nbmisc_enable_bits(nb_dev, 0x55, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
398 set_nbmisc_enable_bits(nb_dev, 0x57, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
399 set_nbmisc_enable_bits(nb_dev, 0x59, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
400 set_nbmisc_enable_bits(nb_dev, 0x5B, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
401 set_nbmisc_enable_bits(nb_dev, 0x5D, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
402 set_nbmisc_enable_bits(nb_dev, 0x5F, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
403 set_nbmisc_enable_bits(nb_dev, 0x61, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
404 set_nbmisc_enable_bits(nb_dev, 0x63, 1 << 20 | 1 << 8, 1 << 20 | 1 << 8);
405
406 /* Disable bus-master trigger event from SB and Enable set_slot_power message to SB */
407 set_nbmisc_enable_bits(nb_dev, 0x0B, 0xffffffff, 0x400180);
408}
409
410/*****************************************
411* Some setting is from rpr. Some is from CIMx.
412*****************************************/
413static void sr5650_por_htiu_index_init(device_t nb_dev)
414{
415 device_t cpu_f0;
416
417 cpu_f0 = PCI_DEV(0, 0x18, 0);
418
419 set_htiu_enable_bits(nb_dev, 0x1C, 0x1<<17, 0x1<<17);
420 set_htiu_enable_bits(nb_dev, 0x05, 0x1<<8, 0x1<<8);
421 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<0, 0x0<<0);
422 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<1, 0x1<<1);
423 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<9, 0x1<<9);
424 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<13, 0x1<<13);
425 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<17, 0x1<<17);
426 set_htiu_enable_bits(nb_dev, 0x06, 0x3<<15, 0x3<<15);
427 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<25, 0x1<<25);
428 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<30, 0x1<<30);
429
430 set_htiu_enable_bits(nb_dev, 0x07, 0x1 << 0 | 0x1 << 1 | 0x1 << 2, 0x1 << 0);
431
432 set_htiu_enable_bits(nb_dev, 0x16, 0x1<<11, 0x1<<11);
433
434 set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<2, 0x1<<2);
435 set_htiu_enable_bits(nb_dev, 0x1D, 0x1<<4, 0x1<<4);
436
437 set_nbcfg_enable_bits(cpu_f0, 0x68, 3 << 21, 0 << 21);
438 axindxc_reg(0x10, 1 << 9, 1 << 9);
439 set_pcie_enable_bits(nb_dev, 0x10 | 5 << 16, 1 << 9, 1 << 9);
440 set_htiu_enable_bits(nb_dev, 0x06, 0x1<<26, 0x1<<26);
441 set_htiu_enable_bits(nb_dev, 0x16, 0x1<<10, 0x1<<10);
442
443 /* Enable BIAS circuit for all lanes. */
444 //set_htiu_enable_bits(nb_dev, 0x2B, 0xF<<28, 0xF<<28);
445 set_htiu_enable_bits(nb_dev, 0x2B, 0xF << 28, 0);
446 set_htiu_enable_bits(nb_dev, 0x05, 0xFFFFFF, 0xFF558);
447 set_htiu_enable_bits(nb_dev, 0x06, 0xFFFFFFFE, 0x04203A202);
448 set_htiu_enable_bits(nb_dev, 0x0C, 0xFFFF, 0x101);
449
450 /* A21 only */
451 //if (REV_SR5650_A21 == get_nb_rev(nb_dev)) {
452 if (get_nb_rev(nb_dev) > REV_SR5650_A11) {
453 set_htiu_enable_bits(nb_dev, 0x05, 0x3<<3| 1<<6 | 1<<10 | 0xFF<<12, 0x3<<3 | 1<<6 | 1<<10 | 0xFF<<12);
454 set_htiu_enable_bits(nb_dev, 0x1D, 1 << 2 | 1 << 4, 0);
455 }
456}
457
458/*****************************************
459* Compliant with CIM_33's ATINB_POR_INIT_JMPDI
460* Configure SR5650 registers to power-on default RPR.
461* POR: Power On Reset
462* RPR: Register Programming Requirements
463*****************************************/
464static void sr5650_por_init(device_t nb_dev)
465{
466 printk(BIOS_INFO, "sr5650_por_init\n");
467 /* ATINB_PCICFG_POR_TABLE, initialize the values for sr5650 PCI Config registers */
468 sr5650_por_pcicfg_init(nb_dev);
469
470 /* ATINB_MISCIND_POR_TABLE */
471 sr5650_por_misc_index_init(nb_dev);
472
473 /* ATINB_HTIUNBIND_POR_TABLE */
474 sr5650_por_htiu_index_init(nb_dev);
475
476 /* ATINB_CLKCFG_PORT_TABLE */
477 /* sr5650 A11 SB Link full swing? */
478}
479
480/* enable CFG access to Dev8, which is the SB P2P Bridge */
481static void enable_sr5650_dev8(void)
482{
483 set_nbmisc_enable_bits(PCI_DEV(0, 0, 0), 0x00, 1 << 6, 1 << 6);
484}
485
486/*
487* Compliant with CIM_33's AtiNBInitEarlyPost (AtiInitNBBeforePCIInit).
488*/
489static void sr5650_before_pci_init(void)
490{
491}
492
493/*
494* The calling sequence is same as CIM.
495*/
496static void sr5650_early_setup(void)
497{
498 device_t nb_dev = PCI_DEV(0, 0, 0);
499 printk(BIOS_INFO, "sr5650_early_setup()\n");
500
501 /*ATINB_PrepareInit */
502 get_cpu_rev();
503
504 switch (get_nb_rev(nb_dev)) { /* PCIEMiscInit */
505 case REV_SR5650_A11:
506 printk(BIOS_INFO, "NB Revision is A11.\n");
507 break;
508 case REV_SR5650_A12:
509 printk(BIOS_INFO, "NB Revision is A12.\n");
510 break;
511 case REV_SR5650_A21:
512 printk(BIOS_INFO, "NB Revision is A21.\n");
513 break;
514 }
515
516#if CONFIG_NORTHBRIDGE_AMD_AMDFAM10 == 1
517
518 fam10_optimization();
519#else
520 k8_optimization();
521#endif
522
523 sr5650_por_init(nb_dev);
524}
525
526/**
527 * @brief disable GPP1 Port0,1, GPP3a Port0,1,2,3,4,5
528 *
529 */
530void disable_pcie_bridge(void)
531{
532 u32 mask;
533 u32 reg;
534 device_t nb_dev = PCI_DEV(0, 0, 0);
535
536 mask = (1 << 2) | (1 << 3) | (1 << 4) | (1 << 5) | (1 << 6) | (1 << 7) |
537 (1 << 16) | (1 << 17);
538 reg = mask;
539 set_nbmisc_enable_bits(nb_dev, 0x0c, mask, reg);
540}