remove trailing whitespace
[coreboot.git] / src / cpu / amd / model_lx / cpureginit.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2006 Indrek Kruusa <indrek.kruusa@artecdesign.ee>
5  * Copyright (C) 2006 Ronald G. Minnich <rminnich@gmail.com>
6  * Copyright (C) 2007 Advanced Micro Devices, Inc.
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; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
21  */
22
23 /**************************************************************************
24 ;*
25 ;*      SetDelayControl
26 ;*
27 ;*************************************************************************/
28 #include "cpu/x86/msr.h"
29
30
31
32
33 /**
34  * Delay Control Settings table from AMD (MCP 0x4C00000F).
35  */
36 static const msrinit_t delay_msr_table[] = {
37         {CPU_BC_MSS_ARRAY_CTL0, {.hi = 0x00000000, .lo = 0x2814D352}},
38         {CPU_BC_MSS_ARRAY_CTL1, {.hi = 0x00000000, .lo = 0x1068334D}},
39         {CPU_BC_MSS_ARRAY_CTL2, {.hi = 0x00000106, .lo = 0x83104104}},
40 };
41
42
43
44 static const struct delay_controls {
45         u8 dimms;
46         u8 devices;
47         u32 slow_hi;
48         u32 slow_low;
49         u32 fast_hi;
50         u32 fast_low;
51 } delay_control_table[] = {
52         /* DIMMs Devs Slow (<=333MHz)            Fast (>334MHz) */
53         {   1,     4, 0x0837100FF, 0x056960004,  0x0827100FF, 0x056960004 },
54         {   1,     8, 0x0837100AA, 0x056960004,  0x0827100AA, 0x056960004 },
55         {   1,    16, 0x0837100AA, 0x056960004,  0x082710055, 0x056960004 },
56         {   2,     8, 0x0837100A5, 0x056960004,  0x082710000, 0x056960004 },
57         {   2,    16, 0x0937100A5, 0x056960004,  0x0C27100A5, 0x056960004 },
58         {   2,    20, 0x0B37100A5, 0x056960004,  0x0B27100A5, 0x056960004 },
59         {   2,    24, 0x0B37100A5, 0x056960004,  0x0B27100A5, 0x056960004 },
60         {   2,    32, 0x0B37100A5, 0x056960004,  0x0B2710000, 0x056960004 },
61 };
62
63 /*
64  * Bit 55 (disable SDCLK 1,3,5) should be set if there is a single DIMM
65  * in slot 0, but it should be clear for all 2 DIMM settings and if a
66  * single DIMM is in slot 1. Bits 54:52 should always be set to '111'.
67  *
68  * Settings for single DIMM and no VTT termination (like DB800 platform)
69  * 0xF2F100FF 0x56960004
70  * -------------------------------------
71  * ADDR/CTL have 22 ohm series R
72  * DQ/DQM/DQS have 33 ohm series R
73  */
74
75 /**
76  * This is Black Magic DRAM timing juju[1].
77  *
78  * DRAM delay depends on CPU clock, memory bus clock, memory bus loading,
79  * memory bus termination, your middle initial (ha! caught you!), GeodeLink
80  * clock rate, and DRAM timing specifications.
81  *
82  * From this the code computes a number which is "known to work". No,
83  * hardware is not an exact science. And, finally, if an FS2 (JTAG debugger)
84  * is hooked up, then just don't do anything. This code was written by a master
85  * of the Dark Arts at AMD and should not be modified in any way.
86  *
87  * [1] (http://www.thefreedictionary.com/juju)
88  *
89  * @param dimm0 The SMBus address of DIMM 0 (mainboard dependent).
90  * @param dimm1 The SMBus address of DIMM 1 (mainboard dependent).
91  * @param terminated The bus is terminated. (mainboard dependent).
92  */
93 static void SetDelayControl(u8 dimm0, u8 dimm1, int terminated)
94 {
95         u32 glspeed;
96         u8 spdbyte0, spdbyte1, dimms, i;
97         msr_t msr;
98
99         glspeed = GeodeLinkSpeed();
100
101         /* Fix delay controls for DM and IM arrays. */
102         for (i = 0; i < ARRAY_SIZE(delay_msr_table); i++)
103                 wrmsr(delay_msr_table[i].index, delay_msr_table[i].msr);
104
105         msr = rdmsr(GLCP_FIFOCTL);
106         msr.hi = 0x00000005;
107         wrmsr(GLCP_FIFOCTL, msr);
108
109         /* Enable setting. */
110         msr.hi = 0;
111         msr.lo = 0x00000001;
112         wrmsr(CPU_BC_MSS_ARRAY_CTL_ENA, msr);
113
114         /* Debug Delay Control setup check.
115          * Leave it alone if it has been setup. FS2 or something is here.
116          */
117         msr = rdmsr(GLCP_DELAY_CONTROLS);
118         if (msr.lo & ~(DELAY_LOWER_STATUS_MASK))
119                 return;
120
121         /* Delay Controls based on DIMM loading. UGH!
122          * Number of devices = module width (SPD 6) / device width (SPD 13)
123          *                     * physical banks (SPD 5)
124          *
125          * Note: We only support a module width of 64.
126          */
127         dimms = 0;
128         spdbyte0 = spd_read_byte(dimm0, SPD_PRIMARY_SDRAM_WIDTH);
129         if (spdbyte0 != 0xFF) {
130                 dimms++;
131                 spdbyte0 = (u8)64 / spdbyte0 *
132                            (u8)(spd_read_byte(dimm0, SPD_NUM_DIMM_BANKS));
133         } else {
134                 spdbyte0 = 0;
135         }
136
137         spdbyte1 = spd_read_byte(dimm1, SPD_PRIMARY_SDRAM_WIDTH);
138         if (spdbyte1 != 0xFF) {
139                 dimms++;
140                 spdbyte1 = (u8)64 / spdbyte1 *
141                            (u8)(spd_read_byte(dimm1, SPD_NUM_DIMM_BANKS));
142         } else {
143                 spdbyte1 = 0;
144         }
145
146         /* Zero GLCP_DELAY_CONTROLS MSR */
147         msr.hi = msr.lo = 0;
148
149         /* Save some power, disable clock to second DIMM if it is empty. */
150         if (spdbyte1 == 0)
151                 msr.hi |= DELAY_UPPER_DISABLE_CLK135;
152
153         spdbyte0 += spdbyte1;
154
155         if ((dimms == 1) && (terminated == DRAM_TERMINATED)) {
156                 msr.hi = 0xF2F100FF;
157                 msr.lo = 0x56960004;
158         } else for (i = 0; i < ARRAY_SIZE(delay_control_table); i++) {
159                 if ((dimms == delay_control_table[i].dimms) &&
160                     (spdbyte0 <= delay_control_table[i].devices)) {
161                         if (glspeed < 334) {
162                                 msr.hi |= delay_control_table[i].slow_hi;
163                                 msr.lo |= delay_control_table[i].slow_low;
164                         } else {
165                                 msr.hi |= delay_control_table[i].fast_hi;
166                                 msr.lo |= delay_control_table[i].fast_low;
167                         }
168                         break;
169                 }
170         }
171         wrmsr(GLCP_DELAY_CONTROLS, msr);
172 }
173
174 /* ***************************************************************************/
175 /* *    cpuRegInit*/
176 /* ***************************************************************************/
177 void cpuRegInit(int debug_clock_disable, u8 dimm0, u8 dimm1, int terminated)
178 {
179         int msrnum;
180         msr_t msr;
181
182         /* Castle 2.0 BTM periodic sync period. */
183         /*      [40:37] 1 sync record per 256 bytes */
184         print_debug("Castle 2.0 BTM periodic sync period.\n");
185         msrnum = CPU_PF_CONF;
186         msr = rdmsr(msrnum);
187         msr.hi |= (0x8 << 5);
188         wrmsr(msrnum, msr);
189
190         /*
191          * LX performance setting.
192          * Enable Quack for fewer re-RAS on the MC
193          */
194         print_debug("Enable Quack for fewer re-RAS on the MC\n");
195         msrnum = GLIU0_ARB;
196         msr = rdmsr(msrnum);
197         msr.hi &= ~ARB_UPPER_DACK_EN_SET;
198         msr.hi |= ARB_UPPER_QUACK_EN_SET;
199         wrmsr(msrnum, msr);
200
201         msrnum = GLIU1_ARB;
202         msr = rdmsr(msrnum);
203         msr.hi &= ~ARB_UPPER_DACK_EN_SET;
204         msr.hi |= ARB_UPPER_QUACK_EN_SET;
205         wrmsr(msrnum, msr);
206
207         /* GLIU port active enable, limit south pole masters
208          * (AES and PCI) to one outstanding transaction.
209          */
210         print_debug(" GLIU port active enable\n");
211         msrnum = GLIU1_PORT_ACTIVE;
212         msr = rdmsr(msrnum);
213         msr.lo &= ~0x880;
214         wrmsr(msrnum, msr);
215
216         /* Set the Delay Control in GLCP */
217         print_debug("Set the Delay Control in GLCP\n");
218         SetDelayControl(dimm0, dimm1, terminated);
219
220         /*  Enable RSDC */
221         print_debug("Enable RSDC\n");
222         msrnum = CPU_AC_SMM_CTL;
223         msr = rdmsr(msrnum);
224         msr.lo |= SMM_INST_EN_SET;
225         wrmsr(msrnum, msr);
226
227         /* FPU imprecise exceptions bit */
228         print_debug("FPU imprecise exceptions bit\n");
229         msrnum = CPU_FPU_MSR_MODE;
230         msr = rdmsr(msrnum);
231         msr.lo |= FPU_IE_SET;
232         wrmsr(msrnum, msr);
233
234         /* Power Savers (Do after BIST) */
235         /* Enable Suspend on HLT & PAUSE instructions */
236         print_debug("Enable Suspend on HLT & PAUSE instructions\n");
237         msrnum = CPU_XC_CONFIG;
238         msr = rdmsr(msrnum);
239         msr.lo |= XC_CONFIG_SUSP_ON_HLT | XC_CONFIG_SUSP_ON_PAUSE;
240         wrmsr(msrnum, msr);
241
242         /* Enable SUSP and allow TSC to run in Suspend (keep speed detection happy) */
243         print_debug("Enable SUSP and allow TSC to run in Suspend\n");
244         msrnum = CPU_BC_CONF_0;
245         msr = rdmsr(msrnum);
246         msr.lo |= TSC_SUSP_SET | SUSP_EN_SET;
247         msr.lo &= 0x0F0FFFFFF;
248         msr.lo |= 0x002000000;  /* PBZ213: Set PAUSEDLY = 2 */
249         wrmsr(msrnum, msr);
250
251         /* Disable the debug clock to save power. */
252         /* NOTE: leave it enabled for fs2 debug */
253         if (debug_clock_disable && 0) {
254                 msrnum = GLCP_DBGCLKCTL;
255                 msr.hi = 0;
256                 msr.lo = 0;
257                 wrmsr(msrnum, msr);
258         }
259
260         /* Setup throttling delays to proper mode if it is ever enabled. */
261         print_debug("Setup throttling delays to proper mode\n");
262         msrnum = GLCP_TH_OD;
263         msr.hi = 0;
264         msr.lo = 0x00000603C;
265         wrmsr(msrnum, msr);
266         print_debug("Done cpuRegInit\n");
267 }