more fix for vsm, not working yet
[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
241 bug118339(void) {
242         printk_err("This is OPTIONAL BIOS-ENABLED ... ignore for now\n");
243 #if 0
244         PROC NEAR PUBLIC
245         pushad
246
247         mov     cx, TOKEN_VGTEAR_118339_SWAPSIF_ENABLE
248         NOSTACK bx, GetNVRAMValueBX
249         cmp     ax, TVALUE_ENABLE
250         jne     bug118339exit
251
252 ;Disable enable_actions in DIAGCTL while setting up GLCP
253         mov     ecx, MSR_GLCP + 005fh
254         xor     edx, edx
255         xor     eax, eax
256         WRMSR
257
258 ; SET2M fires if VG pri is odd (3, not 2) and Ystate=0
259         mov     ecx, MSR_GLCP + 042h
260 ;       mov     edx, 2d6b8000h
261         mov     edx, 596b8000h
262         mov     eax, 00000a00h
263         WRMSR
264
265 ; SET3M fires if MBUS changed and VG pri is odd
266         mov     ecx, MSR_GLCP + 043h
267         mov     edx, 596b8040h
268         xor     eax, eax
269         WRMSR
270
271 ; Put VG request data on lower diag bus
272         mov     ecx, MSR_GLIU0 + 2005h
273         xor     edx, edx
274         mov     eax, 80338041h
275         WRMSR
276
277 ; Increment Y state if SET3M if true
278         mov     ecx, MSR_GLCP + 074h
279         xor     edx, edx
280         mov     eax, 0000c000h
281         WRMSR
282
283 ; Set up MBUS action to PRI=3 read of MBIU
284         mov     ecx, MSR_GLCP + 020h
285         mov     edx, 0000d863h
286         mov     eax, 20002000h
287         WRMSR
288
289 ; Trigger MBUS action if VG=pri3 and Y=0, this blocks most PCI
290         mov     ecx, MSR_GLCP + 071h
291         xor     edx, edx
292         mov     eax, 00000c00h
293         WRMSR
294
295 ;Writing DIAGCTL
296         mov     ecx, MSR_GLCP + 005fh
297         xor     edx, edx
298         mov     eax, 80004000h
299         WRMSR
300
301         ; Code to enable FS2 even when BTB and VGTEAR SWAPSiFs are enabled
302         ; As per Todd Roberts in PBz1094 and PBz1095
303         ; Moved from CPUREG to CPUBUG per Tom Sylla
304         mov     ecx, 04C000042h ; GLCP SETMCTL Register
305         rdmsr
306         or      edx, 8                  ; Bit 35 = MCP_IN
307         wrmsr
308         
309 bug118339exit:
310         popad
311         ret
312 CPUbug118339    ENDP
313 #endif
314 }
315
316
317
318 /****************************************************************************/
319 /***/
320 /**     DisableMemoryReorder*/
321 /***/
322 /**     PBZ 3659:*/
323 /**      The MC reordered transactions incorrectly and breaks coherency.*/
324 /**      Disable reording and take a potential performance hit.*/
325 /**      This is safe to do here and not in MC init since there is nothing*/
326 /**      to maintain coherency with and the cache is not enabled yet.*/
327 /***/
328 /***/
329 /**     Entry:*/
330 /**     Exit:*/
331 /**     Modified:*/
332 /***/
333 /****************************************************************************/
334 void
335 disablememoryreadorder(void) {  
336         msr_t msr;
337         msr = rdmsr(MC_CF8F_DATA);
338
339         msr.hi |=  CF8F_UPPER_REORDER_DIS_SET;
340         wrmsr(MC_CF8F_DATA, msr);
341 }
342 void
343 cpubug(void){
344         msr_t msr;
345         int rev;
346
347         msr = rdmsr(GLCP_CHIP_REVID);
348
349         rev = msr.lo & 0xff;
350         if (rev < 0x20) {
351                 printk_err("%s: rev < 0x20! bailing!\n");
352                 return;
353         }
354         printk_debug("Doing cpubug fixes for rev 0x%x\n", rev);
355         switch(rev)
356         {
357                 case 0x20:
358                         pcideadlock();
359                         eng1398();
360                         /* cs 5530 bug; ignore 
361                         bug752();
362                         */
363                         break;
364                 case 0x21:
365                         pcideadlock();
366                         eng1398();
367                         eng2900();
368                         bug118339();
369                         break;
370                 case 0x22:
371                 case 0x30: 
372                         break;
373                 default:
374                         printk_err("unknown rev %x, bailing\n", rev);
375                         return;
376         }
377         bug784();
378         bug118253();
379         disablememoryreadorder();
380         printk_debug("Done cpubug fixes \n");
381 }