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