add bug support for 2.1
[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         msr_t msr;
234
235         msr = rdmsr(GLPCI_SPARE);
236         msr.lo &= ~GLPCI_SPARE_LOWER_PPC_SET;
237         wrmsr(GLPCI_SPARE, msr);
238 }
239
240 void bug118339(void)
241 {
242         /* per AMD, do this always */
243         msr_t msr = {0,0};
244         int msrnum;
245
246         /* Disable enable_actions in DIAGCTL while setting up GLCP */
247         wrmsr(MSR_GLCP + 0x005f, msr);
248
249         /*  SET2M fires if VG pri is odd (3, not 2) and Ystate=0 */
250         msrnum =  MSR_GLCP + 0x042;
251         /*      msr.hi =  2d6b8000h */;
252         msr.hi =  0x596b8000;
253         msr.lo =  0x00000a00;
254         wrmsr(msrnum, msr);
255
256         /*  SET3M fires if MBUS changed and VG pri is odd */
257         msrnum =  MSR_GLCP + 0x043;
258         msr.hi =  0x596b8040;
259         msr.lo = 0;
260         wrmsr(msrnum, msr);
261
262         /*  Put VG request data on lower diag bus */
263         msrnum =  MSR_GLIU0 + 0x2005;
264         msr.hi = 0;
265         msr.lo =  0x80338041;
266         wrmsr(msrnum, msr);
267
268         /*  Increment Y state if SET3M if true */
269         msrnum =  MSR_GLCP + 0x074;
270         msr.hi = 0;
271         msr.lo =  0x0000c000;
272         wrmsr(msrnum, msr);
273
274         /*  Set up MBUS action to PRI=3 read of MBIU */
275         msrnum =  MSR_GLCP + 0x020;
276         msr.hi =  0x0000d863;
277         msr.lo =  0x20002000;
278         wrmsr(msrnum, msr);
279
280         /*  Trigger MBUS action if VG=pri3 and Y=0, this blocks most PCI */
281         msrnum =  MSR_GLCP + 0x071;
282         msr.hi = 0;
283         msr.lo =  0x00000c00;
284         wrmsr(msrnum, msr);
285
286         /* Writing DIAGCTL */
287         msrnum =  MSR_GLCP + 0x005f;
288         msr.hi = 0;
289         msr.lo =  0x80004000;
290         wrmsr(msrnum, msr);
291
292                 /*  Code to enable FS2 even when BTB and VGTEAR SWAPSiFs are enabled */
293                 /*  As per Todd Roberts in PBz1094 and PBz1095 */
294                 /*  Moved from CPUREG to CPUBUG per Tom Sylla */
295         msrnum =  0x04C000042;          /*  GLCP SETMCTL Register */;
296         msr = rdmsr(msrnum);
297         msr.hi |= 8;                                    /*  Bit 35 = MCP_IN */
298         wrmsr(msrnum, msr);
299         
300 }
301
302
303
304 /****************************************************************************/
305 /***/
306 /**     DisableMemoryReorder*/
307 /***/
308 /**     PBZ 3659:*/
309 /**      The MC reordered transactions incorrectly and breaks coherency.*/
310 /**      Disable reording and take a potential performance hit.*/
311 /**      This is safe to do here and not in MC init since there is nothing*/
312 /**      to maintain coherency with and the cache is not enabled yet.*/
313 /***/
314 /***/
315 /**     Entry:*/
316 /**     Exit:*/
317 /**     Modified:*/
318 /***/
319 /****************************************************************************/
320 void disablememoryreadorder(void)
321 {       
322         msr_t msr;
323         msr = rdmsr(MC_CF8F_DATA);
324
325         msr.hi |=  CF8F_UPPER_REORDER_DIS_SET;
326         wrmsr(MC_CF8F_DATA, msr);
327 }
328
329 void
330 cpubug(void)
331 {
332         msr_t msr;
333         int rev;
334
335         msr = rdmsr(GLCP_CHIP_REVID);
336
337         rev = msr.lo & 0xff;
338         if (rev < 0x20) {
339                 printk_err("%s: rev < 0x20! bailing!\n");
340                 return;
341         }
342         printk_debug("Doing cpubug fixes for rev 0x%x\n", rev);
343         switch(rev)
344         {
345                 case 0x20:
346                         pcideadlock();
347                         eng1398();
348                         /* cs 5530 bug; ignore 
349                         bug752();
350                         */
351                         break;
352                 case 0x21:
353                         pcideadlock();
354                         eng1398();
355                         eng2900();
356                         bug118339();
357                         break;
358                 case 0x22:
359                 case 0x30: 
360                         break;
361                 default:
362                         printk_err("unknown rev %x, bailing\n", rev);
363                         return;
364         }
365         bug784();
366         bug118253();
367         disablememoryreadorder();
368         printk_debug("Done cpubug fixes \n");
369 }