blob: 69b263f5632a851ef5413df82fe195ac07c12c16 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001#include <linux/init.h>
2#include <linux/bitops.h>
3#include <linux/delay.h>
4#include <linux/pci.h>
5#include <asm/dma.h>
6#include <asm/io.h>
7#include <asm/processor.h>
8#include <asm/timer.h>
9
10#include "cpu.h"
11
12/*
13 * Read NSC/Cyrix DEVID registers (DIR) to get more detailed info. about the CPU
14 */
Magnus Damm5f0f1c12006-09-26 10:52:36 +020015static void __cpuinit do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
Linus Torvalds1da177e2005-04-16 15:20:36 -070016{
17 unsigned char ccr2, ccr3;
18 unsigned long flags;
19
20 /* we test for DEVID by checking whether CCR3 is writable */
21 local_irq_save(flags);
22 ccr3 = getCx86(CX86_CCR3);
23 setCx86(CX86_CCR3, ccr3 ^ 0x80);
24 getCx86(0xc0); /* dummy to change bus */
25
26 if (getCx86(CX86_CCR3) == ccr3) { /* no DEVID regs. */
27 ccr2 = getCx86(CX86_CCR2);
28 setCx86(CX86_CCR2, ccr2 ^ 0x04);
29 getCx86(0xc0); /* dummy */
30
31 if (getCx86(CX86_CCR2) == ccr2) /* old Cx486SLC/DLC */
32 *dir0 = 0xfd;
33 else { /* Cx486S A step */
34 setCx86(CX86_CCR2, ccr2);
35 *dir0 = 0xfe;
36 }
37 }
38 else {
39 setCx86(CX86_CCR3, ccr3); /* restore CCR3 */
40
41 /* read DIR0 and DIR1 CPU registers */
42 *dir0 = getCx86(CX86_DIR0);
43 *dir1 = getCx86(CX86_DIR1);
44 }
45 local_irq_restore(flags);
46}
47
48/*
49 * Cx86_dir0_msb is a HACK needed by check_cx686_cpuid/slop in bugs.h in
50 * order to identify the Cyrix CPU model after we're out of setup.c
51 *
52 * Actually since bugs.h doesn't even reference this perhaps someone should
53 * fix the documentation ???
54 */
Magnus Dammb4af3f72006-09-26 10:52:36 +020055static unsigned char Cx86_dir0_msb __cpuinitdata = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
Magnus Dammb4af3f72006-09-26 10:52:36 +020057static char Cx86_model[][9] __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070058 "Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
59 "M II ", "Unknown"
60};
Magnus Dammb4af3f72006-09-26 10:52:36 +020061static char Cx486_name[][5] __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070062 "SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
63 "SRx2", "DRx2"
64};
Magnus Dammb4af3f72006-09-26 10:52:36 +020065static char Cx486S_name[][4] __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 "S", "S2", "Se", "S2e"
67};
Magnus Dammb4af3f72006-09-26 10:52:36 +020068static char Cx486D_name[][4] __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -070069 "DX", "DX2", "?", "?", "?", "DX4"
70};
Magnus Dammb4af3f72006-09-26 10:52:36 +020071static char Cx86_cb[] __cpuinitdata = "?.5x Core/Bus Clock";
72static char cyrix_model_mult1[] __cpuinitdata = "12??43";
73static char cyrix_model_mult2[] __cpuinitdata = "12233445";
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/*
76 * Reset the slow-loop (SLOP) bit on the 686(L) which is set by some old
77 * BIOSes for compatibility with DOS games. This makes the udelay loop
78 * work correctly, and improves performance.
79 *
80 * FIXME: our newer udelay uses the tsc. We don't need to frob with SLOP
81 */
82
83extern void calibrate_delay(void) __init;
84
Magnus Dammb4af3f72006-09-26 10:52:36 +020085static void __cpuinit check_cx686_slop(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -070086{
87 unsigned long flags;
88
89 if (Cx86_dir0_msb == 3) {
90 unsigned char ccr3, ccr5;
91
92 local_irq_save(flags);
93 ccr3 = getCx86(CX86_CCR3);
94 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
95 ccr5 = getCx86(CX86_CCR5);
96 if (ccr5 & 2)
97 setCx86(CX86_CCR5, ccr5 & 0xfd); /* reset SLOP */
98 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
99 local_irq_restore(flags);
100
101 if (ccr5 & 2) { /* possible wrong calibration done */
102 printk(KERN_INFO "Recalibrating delay loop with SLOP bit reset\n");
103 calibrate_delay();
104 c->loops_per_jiffy = loops_per_jiffy;
105 }
106 }
107}
108
109
Magnus Dammb4af3f72006-09-26 10:52:36 +0200110static void __cpuinit set_cx86_reorder(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111{
112 u8 ccr3;
113
114 printk(KERN_INFO "Enable Memory access reorder on Cyrix/NSC processor.\n");
115 ccr3 = getCx86(CX86_CCR3);
116 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
117
118 /* Load/Store Serialize to mem access disable (=reorder it)  */
119 setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80);
120 /* set load/store serialize from 1GB to 4GB */
121 ccr3 |= 0xe0;
122 setCx86(CX86_CCR3, ccr3);
123}
124
Magnus Dammb4af3f72006-09-26 10:52:36 +0200125static void __cpuinit set_cx86_memwb(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126{
127 u32 cr0;
128
129 printk(KERN_INFO "Enable Memory-Write-back mode on Cyrix/NSC processor.\n");
130
131 /* CCR2 bit 2: unlock NW bit */
132 setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04);
133 /* set 'Not Write-through' */
134 cr0 = 0x20000000;
Zachary Amsden4bb0d3e2005-09-03 15:56:36 -0700135 write_cr0(read_cr0() | cr0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 /* CCR2 bit 2: lock NW bit and set WT1 */
137 setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14 );
138}
139
Magnus Dammb4af3f72006-09-26 10:52:36 +0200140static void __cpuinit set_cx86_inc(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700141{
142 unsigned char ccr3;
143
144 printk(KERN_INFO "Enable Incrementor on Cyrix/NSC processor.\n");
145
146 ccr3 = getCx86(CX86_CCR3);
147 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
148 /* PCR1 -- Performance Control */
149 /* Incrementor on, whatever that is */
150 setCx86(CX86_PCR1, getCx86(CX86_PCR1) | 0x02);
151 /* PCR0 -- Performance Control */
152 /* Incrementor Margin 10 */
153 setCx86(CX86_PCR0, getCx86(CX86_PCR0) | 0x04);
154 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
155}
156
157/*
158 * Configure later MediaGX and/or Geode processor.
159 */
160
Magnus Dammb4af3f72006-09-26 10:52:36 +0200161static void __cpuinit geode_configure(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162{
163 unsigned long flags;
164 u8 ccr3, ccr4;
165 local_irq_save(flags);
166
167 /* Suspend on halt power saving and enable #SUSP pin */
168 setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
169
170 ccr3 = getCx86(CX86_CCR3);
171 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* Enable */
172
173 ccr4 = getCx86(CX86_CCR4);
174 ccr4 |= 0x38; /* FPU fast, DTE cache, Mem bypass */
175
Linus Torvalds435f8a62007-02-02 08:07:42 -0800176 setCx86(CX86_CCR3, ccr3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177
178 set_cx86_memwb();
179 set_cx86_reorder();
180 set_cx86_inc();
181
182 local_irq_restore(flags);
183}
184
185
186#ifdef CONFIG_PCI
Magnus Dammb4af3f72006-09-26 10:52:36 +0200187static struct pci_device_id __cpuinitdata cyrix_55x0[] = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188 { PCI_DEVICE(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510) },
189 { PCI_DEVICE(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520) },
190 { },
191};
192#endif
193
Magnus Dammb4af3f72006-09-26 10:52:36 +0200194static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
196 unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
197 char *buf = c->x86_model_id;
198 const char *p = NULL;
199
200 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
201 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
202 clear_bit(0*32+31, c->x86_capability);
203
204 /* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
205 if ( test_bit(1*32+24, c->x86_capability) ) {
206 clear_bit(1*32+24, c->x86_capability);
207 set_bit(X86_FEATURE_CXMMX, c->x86_capability);
208 }
209
210 do_cyrix_devid(&dir0, &dir1);
211
212 check_cx686_slop(c);
213
214 Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family" */
215 dir0_lsn = dir0 & 0xf; /* model or clock multiplier */
216
217 /* common case step number/rev -- exceptions handled below */
218 c->x86_model = (dir1 >> 4) + 1;
219 c->x86_mask = dir1 & 0xf;
220
221 /* Now cook; the original recipe is by Channing Corn, from Cyrix.
222 * We do the same thing for each generation: we work out
223 * the model, multiplier and stepping. Black magic included,
224 * to make the silicon step/rev numbers match the printed ones.
225 */
226
227 switch (dir0_msn) {
228 unsigned char tmp;
229
230 case 0: /* Cx486SLC/DLC/SRx/DRx */
231 p = Cx486_name[dir0_lsn & 7];
232 break;
233
234 case 1: /* Cx486S/DX/DX2/DX4 */
235 p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
236 : Cx486S_name[dir0_lsn & 3];
237 break;
238
239 case 2: /* 5x86 */
240 Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
241 p = Cx86_cb+2;
242 break;
243
244 case 3: /* 6x86/6x86L */
245 Cx86_cb[1] = ' ';
246 Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
247 if (dir1 > 0x21) { /* 686L */
248 Cx86_cb[0] = 'L';
249 p = Cx86_cb;
250 (c->x86_model)++;
251 } else /* 686 */
252 p = Cx86_cb+1;
253 /* Emulate MTRRs using Cyrix's ARRs. */
254 set_bit(X86_FEATURE_CYRIX_ARR, c->x86_capability);
255 /* 6x86's contain this bug */
256 c->coma_bug = 1;
257 break;
258
259 case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
260#ifdef CONFIG_PCI
261 /* It isn't really a PCI quirk directly, but the cure is the
262 same. The MediaGX has deep magic SMM stuff that handles the
263 SB emulation. It thows away the fifo on disable_dma() which
264 is wrong and ruins the audio.
265
266 Bug2: VSA1 has a wrap bug so that using maximum sized DMA
267 causes bad things. According to NatSemi VSA2 has another
268 bug to do with 'hlt'. I've not seen any boards using VSA2
269 and X doesn't seem to support it either so who cares 8).
270 VSA1 we work around however.
271 */
272
273 printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
274 isa_dma_bridge_buggy = 2;
Andreas Mohrcefc0112006-06-23 02:04:26 -0700275
276
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /*
278 * The 5510/5520 companion chips have a funky PIT.
279 */
280 if (pci_dev_present(cyrix_55x0))
281 pit_latch_buggy = 1;
Andreas Mohrcefc0112006-06-23 02:04:26 -0700282#endif
283 c->x86_cache_size=16; /* Yep 16K integrated cache thats it */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284
285 /* GXm supports extended cpuid levels 'ala' AMD */
286 if (c->cpuid_level == 2) {
287 /* Enable cxMMX extensions (GX1 Datasheet 54) */
takada2632f012007-02-13 13:26:24 +0100288 setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700289
takada2632f012007-02-13 13:26:24 +0100290 /*
291 * GXm : 0x30 ... 0x5f GXm datasheet 51
292 * GXlv: 0x6x GXlv datasheet 54
293 * ? : 0x7x
294 * GX1 : 0x8x GX1 datasheet 56
295 */
296 if((0x30 <= dir1 && dir1 <= 0x6f) || (0x80 <=dir1 && dir1 <= 0x8f))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700297 geode_configure();
298 get_model_name(c); /* get CPU marketing name */
299 return;
300 }
301 else { /* MediaGX */
302 Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
303 p = Cx86_cb+2;
304 c->x86_model = (dir1 & 0x20) ? 1 : 2;
305 }
306 break;
307
308 case 5: /* 6x86MX/M II */
309 if (dir1 > 7)
310 {
311 dir0_msn++; /* M II */
312 /* Enable MMX extensions (App note 108) */
313 setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
314 }
315 else
316 {
317 c->coma_bug = 1; /* 6x86MX, it has the bug. */
318 }
319 tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
320 Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
321 p = Cx86_cb+tmp;
322 if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
323 (c->x86_model)++;
324 /* Emulate MTRRs using Cyrix's ARRs. */
325 set_bit(X86_FEATURE_CYRIX_ARR, c->x86_capability);
326 break;
327
328 case 0xf: /* Cyrix 486 without DEVID registers */
329 switch (dir0_lsn) {
330 case 0xd: /* either a 486SLC or DLC w/o DEVID */
331 dir0_msn = 0;
332 p = Cx486_name[(c->hard_math) ? 1 : 0];
333 break;
334
335 case 0xe: /* a 486S A step */
336 dir0_msn = 0;
337 p = Cx486S_name[0];
338 break;
339 }
340 break;
341
342 default: /* unknown (shouldn't happen, we know everyone ;-) */
343 dir0_msn = 7;
344 break;
345 }
346 strcpy(buf, Cx86_model[dir0_msn & 7]);
347 if (p) strcat(buf, p);
348 return;
349}
350
351/*
Jordan Crousef90b8112006-01-06 00:12:14 -0800352 * Handle National Semiconductor branded processors
353 */
Magnus Dammb4af3f72006-09-26 10:52:36 +0200354static void __cpuinit init_nsc(struct cpuinfo_x86 *c)
Jordan Crousef90b8112006-01-06 00:12:14 -0800355{
356 /* There may be GX1 processors in the wild that are branded
357 * NSC and not Cyrix.
358 *
359 * This function only handles the GX processor, and kicks every
360 * thing else to the Cyrix init function above - that should
361 * cover any processors that might have been branded differently
Andreas Mohrd6e05ed2006-06-26 18:35:02 +0200362 * after NSC acquired Cyrix.
Jordan Crousef90b8112006-01-06 00:12:14 -0800363 *
364 * If this breaks your GX1 horribly, please e-mail
365 * info-linux@ldcmail.amd.com to tell us.
366 */
367
368 /* Handle the GX (Formally known as the GX2) */
369
370 if (c->x86 == 5 && c->x86_model == 5)
371 display_cacheinfo(c);
372 else
373 init_cyrix(c);
374}
375
376/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377 * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
378 * by the fact that they preserve the flags across the division of 5/2.
379 * PII and PPro exhibit this behavior too, but they have cpuid available.
380 */
381
382/*
383 * Perform the Cyrix 5/2 test. A Cyrix won't change
384 * the flags, while other 486 chips will.
385 */
386static inline int test_cyrix_52div(void)
387{
388 unsigned int test;
389
390 __asm__ __volatile__(
391 "sahf\n\t" /* clear flags (%eax = 0x0005) */
392 "div %b2\n\t" /* divide 5 by 2 */
393 "lahf" /* store flags into %ah */
394 : "=a" (test)
395 : "0" (5), "q" (2)
396 : "cc");
397
398 /* AH is 0x02 on Cyrix after the divide.. */
399 return (unsigned char) (test >> 8) == 0x02;
400}
401
Magnus Damm5f0f1c12006-09-26 10:52:36 +0200402static void __cpuinit cyrix_identify(struct cpuinfo_x86 * c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404 /* Detect Cyrix with disabled CPUID */
405 if ( c->x86 == 4 && test_cyrix_52div() ) {
406 unsigned char dir0, dir1;
407
408 strcpy(c->x86_vendor_id, "CyrixInstead");
409 c->x86_vendor = X86_VENDOR_CYRIX;
410
411 /* Actually enable cpuid on the older cyrix */
412
413 /* Retrieve CPU revisions */
414
415 do_cyrix_devid(&dir0, &dir1);
416
417 dir0>>=4;
418
419 /* Check it is an affected model */
420
421 if (dir0 == 5 || dir0 == 3)
422 {
423 unsigned char ccr3, ccr4;
424 unsigned long flags;
425 printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
426 local_irq_save(flags);
427 ccr3 = getCx86(CX86_CCR3);
428 setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
429 ccr4 = getCx86(CX86_CCR4);
430 setCx86(CX86_CCR4, ccr4 | 0x80); /* enable cpuid */
431 setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
432 local_irq_restore(flags);
433 }
434 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700435}
436
Magnus Damm95414932006-09-26 10:52:36 +0200437static struct cpu_dev cyrix_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 .c_vendor = "Cyrix",
439 .c_ident = { "CyrixInstead" },
440 .c_init = init_cyrix,
441 .c_identify = cyrix_identify,
442};
443
444int __init cyrix_init_cpu(void)
445{
446 cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
447 return 0;
448}
449
450//early_arch_initcall(cyrix_init_cpu);
451
Chuck Ebbertfe38d852006-02-04 23:28:03 -0800452static int __init cyrix_exit_cpu(void)
453{
454 cpu_devs[X86_VENDOR_CYRIX] = NULL;
455 return 0;
456}
457
458late_initcall(cyrix_exit_cpu);
459
Magnus Damm95414932006-09-26 10:52:36 +0200460static struct cpu_dev nsc_cpu_dev __cpuinitdata = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 .c_vendor = "NSC",
462 .c_ident = { "Geode by NSC" },
Jordan Crousef90b8112006-01-06 00:12:14 -0800463 .c_init = init_nsc,
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464};
465
466int __init nsc_init_cpu(void)
467{
468 cpu_devs[X86_VENDOR_NSC] = &nsc_cpu_dev;
469 return 0;
470}
471
472//early_arch_initcall(nsc_init_cpu);
Chuck Ebbertfe38d852006-02-04 23:28:03 -0800473
474static int __init nsc_exit_cpu(void)
475{
476 cpu_devs[X86_VENDOR_NSC] = NULL;
477 return 0;
478}
479
480late_initcall(nsc_exit_cpu);