minor modification
[coreboot.git] / src / cpu / amd / model_gx2 / cpubug.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 #if 0
16 void
17 bug645(void){
18         msr_t msr;
19         rdmsr(CPU_ID_CONFIG);
20         msr.whatever |= ID_CONFIG_SERIAL_SET;
21         wrmsr(msr);
22 }
23
24 void
25 bug573(void){
26         msr_t msr;
27
28         msr = rdmsr(MC_GLD_MSR_PM);
29         msr.eax &= 0xfff3;
30         wrmsr(MC_GLD_MSR_PM);
31 }
32 #endif
33
34 static void
35 pcideadlock(void)
36 {
37         msr_t msr;
38
39         msr = rdmsr(CPU_DM_CONFIG0);
40         msr.hi &= ~(7<<DM_CONFIG0_UPPER_WSREQ_SHIFT);
41         msr.hi |= (2<<DM_CONFIG0_UPPER_WSREQ_SHIFT);
42         msr.lo |= DM_CONFIG0_LOWER_MISSER_SET;
43         wrmsr(CPU_DM_CONFIG0, msr);
44
45         msr = rdmsr(CPU_IM_CONFIG);
46         msr.lo |= IM_CONFIG_LOWER_QWT_SET;      /* interlock instruction fetches to WS regions with data accesses.
47                                                  * This prevents in instruction fetch from going out to PCI if the 
48                                                  * data side is about to make a request.
49                                                  */
50         wrmsr(CPU_IM_CONFIG, msr);
51         /* write serialize memory hole to PCI. Need to to unWS when something is shadowed regardless of cachablility.*/
52
53         msr.lo = 0x021212121;
54         msr.hi = 0x021212121;
55         wrmsr( CPU_RCONF_A0_BF, msr);
56         wrmsr( CPU_RCONF_C0_DF, msr);
57         wrmsr( CPU_RCONF_E0_FF, msr);
58 }
59
60 /****************************************************************************/
61 /***/
62 /**     CPUbug784*/
63 /***/
64 /**     Bugtool #784 + #792*/
65 /***/
66 /**     Fix CPUID instructions for < 3.0 CPUs*/
67 /***/
68 /**     Entry:*/
69 /**     Exit:*/
70 /**     Modified:*/
71 /***/
72 /****************************************************************************/
73
74 void bug784(void)
75 {
76         msr_t msr;
77         //static char *name = "Geode by NSC";
78
79         /* we'll do this the stupid way, for now, but that's the string they want. NO ONE KNOWS why you
80          * would do this -- the OS can figure this type of stuff out!
81          */
82         msr = rdmsr(0x3006);
83         msr.hi = 0x646f6547;
84         wrmsr(0x3006, msr);
85
86         msr = rdmsr(0x3007);
87         msr.hi = 0x79622065;
88         msr.lo = 0x43534e20;
89         wrmsr(0x3007, msr);
90
91         msr = rdmsr(0x3002);
92         wrmsr(0x3008, msr);
93
94         /* More CPUID to match AMD better. #792*/
95         msr = rdmsr(0x3009);
96         msr.hi = 0x0C0C0A13D;
97         msr.lo = 0x00000000;
98         wrmsr(0x3009, msr);
99 }
100
101 /* cpubug 1398: enable MC if we KNOW we have DDR*/
102 void eng1398(void)
103 {
104         msr_t msr;
105
106         msr = rdmsr(MSR_GLCP+0x17);
107         if ((msr.lo & 0xff) < CPU_REV_2_0) {
108                 msr = rdmsr(GLCP_SYS_RSTPLL);
109                 if (msr.lo & (1<<RSTPPL_LOWER_SDRMODE_SHIFT))
110                         return;
111         }
112
113         /* no bios to check, we just go for it? */
114         msr = rdmsr(MC_GLD_MSR_PM);
115         msr.lo |= 3; /* enable MC clock gating.*/
116         wrmsr(MC_GLD_MSR_PM, msr);
117 }
118
119 void
120 eng2900(void){
121         printk_err(" NOT DOING eng2900: only shown to be a windows problem\n");
122 #if 0
123
124 ;**************************************************************************
125 ;*
126 ;*      CPUbugIAENG2900
127 ;*
128 ;*      Clear Quest IAENG00002900, VSS 118.150
129 ;*
130 ;*      BTB issue causes blue screen in windows.
131 ;*
132 ;*      Entry:
133 ;*      Exit:
134 ;*      Modified:
135 ;*
136 ;**************************************************************************
137 CPUbugIAENG2900 PROC NEAR PUBLIC
138         pushad
139
140 ; Clear bit 43, disables the sysenter/sysexit in CPUID3
141         mov     ecx, 3003h
142         RDMSR
143         and     edx, 0FFFFF7FFh
144         WRMSR
145
146         mov     cx, TOKEN_BTB_2900_SWAPSIF_ENABLE
147         NOSTACK bx, GetNVRAMValueBX
148         cmp     ax, TVALUE_ENABLE
149         jne     bug2900exit
150
151
152 ;Disable enable_actions in DIAGCTL while setting up GLCP
153         mov     ecx, MSR_GLCP + 005fh
154         xor     edx, edx
155         xor     eax, eax
156         WRMSR
157
158 ;Changing DBGCLKCTL register to GeodeLink
159         mov     ecx, MSR_GLCP + 0016h
160         xor     edx, edx
161         xor     eax, eax
162         WRMSR
163
164         mov     ecx, MSR_GLCP + 0016h
165         xor     edx, edx
166         mov     eax, 02h
167         WRMSR
168
169 ;The code below sets up the RedCloud to stall for 4 GeodeLink clocks when CPU is snooped.
170 ;Because setting XSTATE to 0 overrides any other XSTATE action, the code will always
171 ;stall for 4 GeodeLink clocks after a snoop request goes away even if it occured a clock or two 
172 ;later than a different snoop; the stall signal will never 'glitch high' for 
173 ;only one or two CPU clocks with this code.
174
175 ;Send mb0 port 3 requests to upper GeodeLink diag bits [63:32]
176         mov     ecx, MSR_GLIU0 + 2005h
177         xor     edx, edx
178         mov     eax, 80338041h
179         WRMSR
180
181 ;set5m watches request ready from mb0 to CPU (snoop)
182         mov     ecx, MSR_GLCP + 0045h
183         mov     edx, 5ad68000h
184         xor     eax, eax
185         WRMSR
186
187 ;SET4M will be high when state is idle (XSTATE=11)
188         mov     ecx, MSR_GLCP + 0044h
189         xor     edx, edx
190         mov     eax, 0140h
191         WRMSR
192
193 ;SET5n to watch for processor stalled state
194         mov     ecx, MSR_GLCP + 004Dh
195         mov     edx, 2000h
196         xor     eax, eax
197         WRMSR
198
199 ;Writing action number 13: XSTATE=0 to occur when CPU is snooped unless we're stalled
200         mov     ecx, MSR_GLCP + 0075h
201         xor     edx, edx
202         mov     eax, 00400000h
203         WRMSR
204
205 ;Writing action number 11: inc XSTATE every GeodeLink clock unless we're idle
206         mov     ecx, MSR_GLCP + 0073h
207         xor     edx, edx
208         mov     eax, 30000h
209         WRMSR
210
211
212 ;Writing action number 5: STALL_CPU_PIPE when exitting idle state or not in idle state
213         mov     ecx, MSR_GLCP + 006Dh
214         xor     edx, edx
215         mov     eax, 00430000h
216         WRMSR
217
218 ;Writing DIAGCTL Register to enable the stall action and to let set5m watch the upper GeodeLink diag bits.
219         mov     ecx, MSR_GLCP + 005fh
220         xor     edx, edx
221         mov     eax, 80004000h
222         WRMSR
223
224
225 bug2900exit:
226         popad
227         ret
228 CPUbugIAENG2900 ENDP
229 #endif
230 }
231
232 void bug118253(void)
233 {
234         /* GLPCI PIO Post Control shouldn't be enabled */
235         msr_t msr;
236
237         msr = rdmsr(GLPCI_SPARE);
238         msr.lo &= ~GLPCI_SPARE_LOWER_PPC_SET;
239         wrmsr(GLPCI_SPARE, msr);
240 }
241
242 void bug118339(void)
243 {
244         /* per AMD, do this always */
245         msr_t msr = {0,0};
246         int msrnum;
247
248         /* Disable enable_actions in DIAGCTL while setting up GLCP */
249         wrmsr(MSR_GLCP + 0x005f, msr);
250
251         /*  SET2M fires if VG pri is odd (3, not 2) and Ystate=0 */
252         msrnum =  MSR_GLCP + 0x042;
253         /*      msr.hi =  2d6b8000h */;
254         msr.hi =  0x596b8000;
255         msr.lo =  0x00000a00;
256         wrmsr(msrnum, msr);
257
258         /*  SET3M fires if MBUS changed and VG pri is odd */
259         msrnum =  MSR_GLCP + 0x043;
260         msr.hi =  0x596b8040;
261         msr.lo = 0;
262         wrmsr(msrnum, msr);
263
264         /*  Put VG request data on lower diag bus */
265         msrnum =  MSR_GLIU0 + 0x2005;
266         msr.hi = 0;
267         msr.lo =  0x80338041;
268         wrmsr(msrnum, msr);
269
270         /*  Increment Y state if SET3M if true */
271         msrnum =  MSR_GLCP + 0x074;
272         msr.hi = 0;
273         msr.lo =  0x0000c000;
274         wrmsr(msrnum, msr);
275
276         /*  Set up MBUS action to PRI=3 read of MBIU */
277         msrnum =  MSR_GLCP + 0x020;
278         msr.hi =  0x0000d863;
279         msr.lo =  0x20002000;
280         wrmsr(msrnum, msr);
281
282         /*  Trigger MBUS action if VG=pri3 and Y=0, this blocks most PCI */
283         msrnum =  MSR_GLCP + 0x071;
284         msr.hi = 0;
285         msr.lo =  0x00000c00;
286         wrmsr(msrnum, msr);
287
288         /* Writing DIAGCTL */
289         msrnum =  MSR_GLCP + 0x005f;
290         msr.hi = 0;
291         msr.lo =  0x80004000;
292         wrmsr(msrnum, msr);
293
294         /*  Code to enable FS2 even when BTB and VGTEAR SWAPSiFs are enabled */
295         /*  As per Todd Roberts in PBz1094 and PBz1095 */
296         /*  Moved from CPUREG to CPUBUG per Tom Sylla */
297         msrnum =  0x04C000042;          /*  GLCP SETMCTL Register */;
298         msr = rdmsr(msrnum);
299         msr.hi |= 8;                    /*  Bit 35 = MCP_IN */
300         wrmsr(msrnum, msr);
301 }
302
303
304
305 /****************************************************************************/
306 /***/
307 /**     DisableMemoryReorder*/
308 /***/
309 /**     PBZ 3659:*/
310 /**      The MC reordered transactions incorrectly and breaks coherency.*/
311 /**      Disable reording and take a potential performance hit.*/
312 /**      This is safe to do here and not in MC init since there is nothing*/
313 /**      to maintain coherency with and the cache is not enabled yet.*/
314 /***/
315 /***/
316 /**     Entry:*/
317 /**     Exit:*/
318 /**     Modified:*/
319 /***/
320 /****************************************************************************/
321 void disablememoryreadorder(void)
322 {       
323         msr_t msr;
324         msr = rdmsr(MC_CF8F_DATA);
325
326         msr.hi |=  CF8F_UPPER_REORDER_DIS_SET;
327         wrmsr(MC_CF8F_DATA, msr);
328 }
329
330 void
331 cpubug(void)
332 {
333         msr_t msr;
334         int rev;
335
336         msr = rdmsr(GLCP_CHIP_REVID);
337
338         rev = msr.lo & 0xff;
339         if (rev < 0x20) {
340                 printk_err("%s: rev < 0x20! bailing!\n");
341                 return;
342         }
343         printk_debug("Doing cpubug fixes for rev 0x%x\n", rev);
344         switch(rev)
345         {
346                 case 0x20:
347                         pcideadlock();
348                         eng1398();
349                         /* cs 5530 bug; ignore 
350                         bug752();
351                         */
352                         break;
353                 case 0x21:
354                         pcideadlock();
355                         eng1398();
356                         eng2900();
357                         bug118339();
358                         break;
359                 case 0x22:
360                 case 0x30: 
361                         break;
362                 default:
363                         printk_err("unknown rev %x, bailing\n", rev);
364                         return;
365         }
366         bug784();
367         bug118253();
368         disablememoryreadorder();
369         printk_debug("Done cpubug fixes \n");
370 }