clean up gx2def.h a bit.
[coreboot.git] / src / cpu / amd / model_gx2 / cpureginit.c
1 #include <console/console.h>
2 #include <arch/io.h>
3 #include <stdint.h>
4 #include <device/device.h>
5 #include <device/pci.h>
6 #include <device/pci_ids.h>
7 #include <stdlib.h>
8 #include <string.h>
9 #include <bitops.h>
10 #include <cpu/amd/gx2def.h>
11 #include <cpu/x86/msr.h>
12 #include <cpu/x86/cache.h>
13
14 /* ***************************************************************************/
15 /* **/
16 /* *    BIST */
17 /* **/
18 /* *    GX2 BISTs need to be run before BTB or caches are enabled.*/
19 /* *    BIST result left in registers on failure to be checked with FS2.*/
20 /* **/
21 /* ***************************************************************************/
22 static void
23 BIST(void){
24         int msrnum;
25         msr_t msr;
26
27         /* DM*/
28         msrnum = CPU_DM_CONFIG0;
29         msr = rdmsr(msrnum);
30         msr.lo |=  DM_CONFIG0_LOWER_DCDIS_SET;
31         wrmsr(msrnum, msr);
32         
33         msr.lo =  0x00000003F;
34         msr.hi =  0x000000000;
35         msrnum = CPU_DM_BIST;
36         wrmsr(msrnum, msr);
37
38         outb(POST_CPU_DM_BIST_FAILURE   , 0x80);                                /* 0x29*/
39         msr = rdmsr(msrnum);                                                    /* read back for pass fail*/
40         msr.lo &= 0x0F3FF0000;
41         if (msr.lo != 0xfeff0000)
42                 goto BISTFail;
43  
44         msrnum = CPU_DM_CONFIG0;
45         msr = rdmsr(msrnum);
46         msr.lo &=  ~ DM_CONFIG0_LOWER_DCDIS_SET;
47         wrmsr(msrnum, msr);
48
49         /* FPU*/
50         msr.lo =  0x000000131;
51         msr.hi = 0;
52         msrnum = CPU_FP_UROM_BIST;
53         wrmsr(msrnum, msr);
54
55         outb(POST_CPU_FPU_BIST_FAILURE, 0x80);                          /* 0x89*/
56         inb(0x80);                                                                      /*  IO delay*/
57         msr = rdmsr(msrnum);                                                    /* read back for pass fail*/
58         while ((msr.lo&0x884) != 0x884)
59                 msr = rdmsr(msrnum);                                    /*  Endless loop if BIST is broken*/
60         if ((msr.lo&0x642) != 0x642)
61                 goto BISTFail;
62
63         msr.lo = msr.hi = 0;                            /*  clear FPU BIST bits*/
64         msrnum = CPU_FP_UROM_BIST;
65         wrmsr(msrnum, msr);
66
67
68         /* BTB*/
69         msr.lo =  0x000000303;
70         msr.hi =  0x000000000;
71         msrnum = CPU_PF_BTBRMA_BIST;
72         wrmsr(msrnum, msr);
73
74         outb(POST_CPU_BTB_BIST_FAILURE  , 0x80);                                /* 0x8A*/
75         msr = rdmsr(msrnum);                                                    /* read back for pass fail*/
76         if ((msr.lo & 0x3030) != 0x3030)
77                 goto BISTFail;
78
79         return;
80
81 BISTFail:
82         printk_err("BIST failed!\n");
83         while(1);
84 }
85 /* ***************************************************************************/
86 /* *    cpuRegInit*/
87 /* ***************************************************************************/
88 void
89 cpuRegInit (int diagmode){
90         int msrnum;
91         msr_t msr;
92         /*  Turn on BTM for early debug based on setup. */
93         /*if (getnvram( TOKEN_BTM_DIAG_MODE) & 3) {*/
94         {
95                 /*  Set Diagnostic Mode */
96                 msrnum = CPU_GLD_MSR_DIAG;
97                 msr.hi =  0;
98                 msr.lo = DIAG_SEL1_SET | DIAG_SET0_SET;
99                 wrmsr(msrnum, msr);
100         
101                 /*  Set up GLCP to grab BTM data.*/
102                 msrnum = 0x04C00000C;           /*  GLCP_DBGOUT MSR*/
103                 msr.hi =  0x0;
104                 msr.lo =  0x08;                 /*  reset value (SCOPE_SEL = 0) causes FIFO toshift out,*/
105                 wrmsr(msrnum, msr);                                     /*  exchange it to anything else to prevent this*/
106         
107                 /* ;Turn off debug clock*/
108                 msrnum = 0x04C000016;           /* DBG_CLK_CTL*/
109                 msr.lo =  0x00;                 /* No clock*/
110                 msr.hi =  0x00;
111                 wrmsr(msrnum, msr);
112         
113                 /* ;Set debug clock to CPU*/
114                 msrnum = 0x04C000016;           /* DBG_CLK_CTL*/
115                 msr.lo =  0x01;                 /* CPU CLOCK*/
116                 msr.hi =  0x00;
117                 wrmsr(msrnum, msr);
118         
119                 /* ;Set fifo ctl to BTM bits wide*/
120                 msrnum = 0x04C00005E;           /*  FIFO_CTL*/
121                 msr.lo =  0x003880000;          /*  Bit [25:24] are size (11=BTM, 10 = 64 bit, 01= 32 bit, 00 = 16bit)*/
122                 wrmsr(msrnum, msr);             /*  Bit [23:21] are position (100 = CPU downto0)*/
123                                                                 /*  Bit [19] sets it up in slow data mode.*/
124         
125                 /* ;enable fifo loading - BTM sizing will constrain*/
126                 /* ; only valid BTM packets to load - this action should always be on*/
127         
128                 msrnum = 0x04C00006F;           /*  GLCP ACTION7 - load fifo*/
129                 msr.lo =  0x00000F000;          /*    Any nibble all 1's will always trigger*/
130                 msr.hi =  0x000000000;          /* */
131                 wrmsr(msrnum, msr);
132         
133                 /* ;start storing diag data in the fifo*/
134                 msrnum = 0x04C00005F;           /* DIAG CTL*/
135                 msr.lo =  0x080000000;          /*  enable actions*/
136                 msr.hi =  0x000000000;
137                 wrmsr(msrnum, msr);
138         
139                 /*  Set up delay on data lines, so that the hold time*/
140                 /*  is 1 ns.*/
141                 msrnum = 0x04C00000D ;  /*  GLCP IO DELAY CONTROLS*/
142                 msr.lo =  0x082b5ad68;
143                 msr.hi =  0x080ad6b57;  /*  RGB delay = 0x07*/
144                 wrmsr(msrnum, msr);
145         
146                 /*  Set up DF to output diag information on DF pins.*/
147                 msrnum = DF_GLD_MSR_MASTER_CONF;
148                 msr.lo =  0x0220;
149                 msr.hi = 0;
150                 wrmsr(msrnum, msr);
151         
152                 msrnum = 0x04C00000C ;  /*  GLCP_DBGOUT MSR*/
153                 msr.hi =  0x0;
154                 msr.lo =  0x0;                          /*  reset value (SCOPE_SEL = 0) causes FIFO to shift out,*/
155                 wrmsr(msrnum, msr);
156                 /* end of code for BTM */
157         }
158
159         /*  Enable Suspend on Halt*/
160         msrnum = CPU_XC_CONFIG;
161         msr = rdmsr(msrnum);
162         msr.lo |=  XC_CONFIG_SUSP_ON_HLT;
163         wrmsr(msrnum, msr);
164
165         /*  ENable SUSP and allow TSC to run in Suspend */
166         /*  to keep speed detection happy*/
167         msrnum = CPU_BC_CONF_0;
168         msr = rdmsr(msrnum);
169         msr.lo |=  TSC_SUSP_SET | SUSP_EN_SET;
170         wrmsr(msrnum, msr);
171
172         /*  Setup throttling to proper mode if it is ever enabled.*/
173         msrnum = 0x04C00001E;
174         msr.hi =  0x000000000;
175         msr.lo =  0x00000603C;
176         wrmsr(msrnum, msr);
177
178
179 /*  Only do this if we are building for 5535*/
180 /* */
181 /*  FooGlue Setup*/
182 /* */
183         /*  Enable CIS mode B in FooGlue*/
184         msrnum = MSR_FG + 0x10;
185         msr = rdmsr(msrnum);
186         msr.lo &= ~3;
187         msr.lo |= 2;                    /*  ModeB*/
188         wrmsr(msrnum, msr);
189
190
191 /* */
192 /*  Disable DOT PLL. Graphics init will enable it if needed.*/
193 /* */
194         msrnum = GLCP_DOTPLL;
195         msr = rdmsr(msrnum);
196         msr.lo |= DOTPPL_LOWER_PD_SET;
197         wrmsr(msrnum, msr);
198
199 /* */
200 /*  Set the Delay Control in GLCP*/
201 /* */
202 /*      SetDelayControl();*/
203
204 /* */
205 /*  Enable RSDC*/
206 /* */
207         msrnum = 0x1301 ;
208         msr = rdmsr(msrnum);
209         msr.lo |=  0x08;
210         wrmsr(msrnum, msr);
211
212
213 /* */
214 /*  BIST*/
215 /* */
216         /*if (getnvram( TOKEN_BIST_ENABLE) & == TVALUE_DISABLE) {*/
217         {
218                 BIST();
219         }
220
221
222 /* */
223 /*  Enable BTB*/
224 /* */
225         /*  I hate to put this check here but it doesn't really work in cpubug.asm*/
226         msrnum = MSR_GLCP+0x17;
227         msr = rdmsr(msrnum);
228         if (msr.lo < CPU_REV_2_1){
229                 msrnum = CPU_PF_BTB_CONF;
230                 msr = rdmsr(msrnum);
231                 msr.lo |= BTB_ENABLE_SET | RETURN_STACK_ENABLE_SET;
232                 wrmsr(msrnum, msr);
233         }
234
235 /* */
236 /*  FPU impercise exceptions bit*/
237 /* */
238         /*if (getnvram( TOKEN_FPU_IE_ENABLE) != TVALUE_DISABLE) {*/
239         {
240                 msrnum = CPU_FPU_MSR_MODE;
241                 msr = rdmsr(msrnum);
242                 msr.lo |= FPU_IE_SET;
243                 wrmsr(msrnum, msr);
244         }
245
246 /* */
247 /*  Cache Overides*/
248 /* */
249         /*  Allow NVRam to override DM Setup*/
250         /*if (getnvram( TOKEN_CACHE_DM_MODE) != 1) {*/
251         {
252
253                 msrnum = CPU_DM_CONFIG0;
254                 msr = rdmsr(msrnum);
255                 msr.lo |=  DM_CONFIG0_LOWER_DCDIS_SET;
256                 wrmsr(msrnum, msr);
257         }
258         /*  Allow NVRam to override IM Setup*/
259         /*if (getnvram( TOKEN_CACHE_IM_MODE) ==1) {*/
260         {
261                 msrnum = CPU_IM_CONFIG;
262                 msr = rdmsr(msrnum);
263                 msr.lo |=  IM_CONFIG_LOWER_ICD_SET;
264                 wrmsr(msrnum, msr);
265         }
266 }
267
268
269
270
271 /* ***************************************************************************/
272 /* **/
273 /* *    MTestPinCheckBX*/
274 /* **/
275 /* *    Set MTEST pins to expected values from OPTIONS.INC/NVRAM*/
276 /* *  This version is called when there isn't a stack available*/
277 /* **/
278 /* ***************************************************************************/
279 static void
280 MTestPinCheckBX (void){
281         int msrnum;
282         msr_t msr;
283
284         /*if (getnvram( TOKEN_MTEST_ENABLE) ==TVALUE_DISABLE ) {*/
285                         /* return ; */
286         /* } */
287
288         /*  Turn on MTEST*/
289         msrnum = MC_CFCLK_DBUG;
290         msr = rdmsr(msrnum);
291         msr.hi |=  CFCLK_UPPER_MTST_B2B_DIS_SET | CFCLK_UPPER_MTEST_EN_SET;
292         wrmsr(msrnum, msr);
293
294         msrnum = GLCP_SYS_RSTPLL                        /*  Get SDR/DDR mode from GLCP*/;
295         msr = rdmsr(msrnum);
296         msr.lo >>=  RSTPPL_LOWER_SDRMODE_SHIFT;
297         if (msr.lo & 1) {
298                 msrnum = MC_CFCLK_DBUG;                 /*  Turn on SDR MTEST stuff*/
299                 msr = rdmsr(msrnum);
300                 msr.lo |=  CFCLK_LOWER_SDCLK_SET;
301                 msr.hi |=  CFCLK_UPPER_MTST_DQS_EN_SET;
302                 wrmsr(msrnum, msr);
303         }
304
305         /*  Lock the cache down here.*/
306         wbinvd();
307
308 }