This patch adds support for the AMD LX cpu.
[coreboot.git] / src / cpu / amd / model_lx / 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         
82         //GX3 suspend: what is desired?
83
84         /*  Enable Suspend on Halt*/
85         /*msrnum = CPU_XC_CONFIG;
86         msr = rdmsr(msrnum);
87         msr.lo |=  XC_CONFIG_SUSP_ON_HLT;
88         wrmsr(msrnum, msr);*/
89
90         /*  ENable SUSP and allow TSC to run in Suspend */
91         /*  to keep speed detection happy*/
92         /*msrnum = CPU_BC_CONF_0;
93         msr = rdmsr(msrnum);
94         msr.lo |=  TSC_SUSP_SET | SUSP_EN_SET;
95         wrmsr(msrnum, msr);*/
96
97         /*  Setup throttling to proper mode if it is ever enabled.*/
98         msrnum = 0x04C00001E;
99         msr.hi =  0x000000000;
100         msr.lo =  0x00000603C;
101         wrmsr(msrnum, msr);             // GX3 OK +/-
102
103
104 /*  Only do this if we are building for 5535*/
105 /* */
106 /*  FooGlue Setup*/
107 /* */
108 #if 0
109         /*  Enable CIS mode B in FooGlue*/
110         msrnum = MSR_FG + 0x10;
111         msr = rdmsr(msrnum);
112         msr.lo &= ~3;
113         msr.lo |= 2;                    /*  ModeB*/
114         wrmsr(msrnum, msr);
115 #endif
116
117 /* */
118 /*  Disable DOT PLL. Graphics init will enable it if needed.*/
119 /* */
120
121 // GX3: Disable DOT PLL? No. Lets tick.
122
123 /*      msrnum = GLCP_DOTPLL;
124         msr = rdmsr(msrnum);
125         msr.lo |= DOTPPL_LOWER_PD_SET;
126         wrmsr(msrnum, msr); */
127
128 /* */
129 /*  Enable RSDC*/
130 /* */
131         msrnum = 0x1301 ;
132         msr = rdmsr(msrnum);
133         msr.lo |=  0x08;
134         wrmsr(msrnum, msr);             //GX3 OK
135
136
137 /* */
138 /*  BIST*/
139 /* */
140         /*if (getnvram( TOKEN_BIST_ENABLE) & == TVALUE_DISABLE) {*/
141         {
142 //              BIST();
143         }
144
145
146 /* */
147 /*  Enable BTB*/
148 /* */
149         /*  I hate to put this check here but it doesn't really work in cpubug.asm*/
150
151 //GX3: BTB is enabled by default
152
153 /*      msrnum = MSR_GLCP+0x17;
154         msr = rdmsr(msrnum);
155         if (msr.lo >= CPU_REV_2_1){
156                 msrnum = CPU_PF_BTB_CONF;
157                 msr = rdmsr(msrnum);
158                 msr.lo |= BTB_ENABLE_SET | RETURN_STACK_ENABLE_SET;
159                 wrmsr(msrnum, msr);
160         }
161
162         */
163
164 /* */
165 /*  FPU impercise exceptions bit*/
166 /* */
167         /*if (getnvram( TOKEN_FPU_IE_ENABLE) != TVALUE_DISABLE) {*/
168
169
170
171 // GX3: FPU impercise exceptions bit - what's that?
172 /*      {
173                 msrnum = CPU_FPU_MSR_MODE;
174                 msr = rdmsr(msrnum);
175                 msr.lo |= FPU_IE_SET;
176                 wrmsr(msrnum, msr);
177         }
178
179         */
180
181 #if 0
182         /* */
183         /*  Cache Overides*/
184         /* */
185         /* This code disables the data cache.  Don't execute this
186          * unless you're testing something.
187          */ 
188         /*  Allow NVRam to override DM Setup*/
189         /*if (getnvram( TOKEN_CACHE_DM_MODE) != 1) {*/
190         {
191
192                 msrnum = CPU_DM_CONFIG0;
193                 msr = rdmsr(msrnum);
194                 msr.lo |=  DM_CONFIG0_LOWER_DCDIS_SET;
195                 wrmsr(msrnum, msr);
196         }
197         /* This code disables the instruction cache.  Don't execute
198          * this unless you're testing something.
199         */ 
200         /*  Allow NVRam to override IM Setup*/
201         /*if (getnvram( TOKEN_CACHE_IM_MODE) ==1) {*/
202         {
203                 msrnum = CPU_IM_CONFIG;
204                 msr = rdmsr(msrnum);
205                 msr.lo |=  IM_CONFIG_LOWER_ICD_SET;
206                 wrmsr(msrnum, msr);
207         }
208 #endif
209 }
210
211
212
213
214 /* ***************************************************************************/
215 /* **/
216 /* *    MTestPinCheckBX*/
217 /* **/
218 /* *    Set MTEST pins to expected values from OPTIONS.INC/NVRAM*/
219 /* *  This version is called when there isn't a stack available*/
220 /* **/
221 /* ***************************************************************************/
222 static void
223 MTestPinCheckBX (void){
224         int msrnum;
225         msr_t msr;
226
227         /*if (getnvram( TOKEN_MTEST_ENABLE) ==TVALUE_DISABLE ) {*/
228                         /* return ; */
229         /* } */
230
231         /*  Turn on MTEST*/
232         msrnum = MC_CFCLK_DBUG;
233         msr = rdmsr(msrnum);
234         msr.hi |=  CFCLK_UPPER_MTST_B2B_DIS_SET | CFCLK_UPPER_MTEST_EN_SET;
235         wrmsr(msrnum, msr);
236
237         msrnum = GLCP_SYS_RSTPLL                        /*  Get SDR/DDR mode from GLCP*/;
238         msr = rdmsr(msrnum);
239         msr.lo >>=  RSTPPL_LOWER_SDRMODE_SHIFT;
240         if (msr.lo & 1) {
241                 msrnum = MC_CFCLK_DBUG;                 /*  Turn on SDR MTEST stuff*/
242                 msr = rdmsr(msrnum);
243                 msr.lo |=  CFCLK_LOWER_SDCLK_SET;
244                 msr.hi |=  CFCLK_UPPER_MTST_DQS_EN_SET;
245                 wrmsr(msrnum, msr);
246         }
247
248         /*  Lock the cache down here.*/
249         __asm__("wbinvd\n");
250
251 }