cyrix.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435
  1. #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. #include "cpu.h"
  10. /*
  11. * Read NSC/Cyrix DEVID registers (DIR) to get more detailed info. about the CPU
  12. */
  13. static void __init do_cyrix_devid(unsigned char *dir0, unsigned char *dir1)
  14. {
  15. unsigned char ccr2, ccr3;
  16. unsigned long flags;
  17. /* we test for DEVID by checking whether CCR3 is writable */
  18. local_irq_save(flags);
  19. ccr3 = getCx86(CX86_CCR3);
  20. setCx86(CX86_CCR3, ccr3 ^ 0x80);
  21. getCx86(0xc0); /* dummy to change bus */
  22. if (getCx86(CX86_CCR3) == ccr3) { /* no DEVID regs. */
  23. ccr2 = getCx86(CX86_CCR2);
  24. setCx86(CX86_CCR2, ccr2 ^ 0x04);
  25. getCx86(0xc0); /* dummy */
  26. if (getCx86(CX86_CCR2) == ccr2) /* old Cx486SLC/DLC */
  27. *dir0 = 0xfd;
  28. else { /* Cx486S A step */
  29. setCx86(CX86_CCR2, ccr2);
  30. *dir0 = 0xfe;
  31. }
  32. }
  33. else {
  34. setCx86(CX86_CCR3, ccr3); /* restore CCR3 */
  35. /* read DIR0 and DIR1 CPU registers */
  36. *dir0 = getCx86(CX86_DIR0);
  37. *dir1 = getCx86(CX86_DIR1);
  38. }
  39. local_irq_restore(flags);
  40. }
  41. /*
  42. * Cx86_dir0_msb is a HACK needed by check_cx686_cpuid/slop in bugs.h in
  43. * order to identify the Cyrix CPU model after we're out of setup.c
  44. *
  45. * Actually since bugs.h doesn't even reference this perhaps someone should
  46. * fix the documentation ???
  47. */
  48. static unsigned char Cx86_dir0_msb __initdata = 0;
  49. static char Cx86_model[][9] __initdata = {
  50. "Cx486", "Cx486", "5x86 ", "6x86", "MediaGX ", "6x86MX ",
  51. "M II ", "Unknown"
  52. };
  53. static char Cx486_name[][5] __initdata = {
  54. "SLC", "DLC", "SLC2", "DLC2", "SRx", "DRx",
  55. "SRx2", "DRx2"
  56. };
  57. static char Cx486S_name[][4] __initdata = {
  58. "S", "S2", "Se", "S2e"
  59. };
  60. static char Cx486D_name[][4] __initdata = {
  61. "DX", "DX2", "?", "?", "?", "DX4"
  62. };
  63. static char Cx86_cb[] __initdata = "?.5x Core/Bus Clock";
  64. static char cyrix_model_mult1[] __initdata = "12??43";
  65. static char cyrix_model_mult2[] __initdata = "12233445";
  66. /*
  67. * Reset the slow-loop (SLOP) bit on the 686(L) which is set by some old
  68. * BIOSes for compatibility with DOS games. This makes the udelay loop
  69. * work correctly, and improves performance.
  70. *
  71. * FIXME: our newer udelay uses the tsc. We don't need to frob with SLOP
  72. */
  73. extern void calibrate_delay(void) __init;
  74. static void __init check_cx686_slop(struct cpuinfo_x86 *c)
  75. {
  76. unsigned long flags;
  77. if (Cx86_dir0_msb == 3) {
  78. unsigned char ccr3, ccr5;
  79. local_irq_save(flags);
  80. ccr3 = getCx86(CX86_CCR3);
  81. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
  82. ccr5 = getCx86(CX86_CCR5);
  83. if (ccr5 & 2)
  84. setCx86(CX86_CCR5, ccr5 & 0xfd); /* reset SLOP */
  85. setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
  86. local_irq_restore(flags);
  87. if (ccr5 & 2) { /* possible wrong calibration done */
  88. printk(KERN_INFO "Recalibrating delay loop with SLOP bit reset\n");
  89. calibrate_delay();
  90. c->loops_per_jiffy = loops_per_jiffy;
  91. }
  92. }
  93. }
  94. static void __init set_cx86_reorder(void)
  95. {
  96. u8 ccr3;
  97. printk(KERN_INFO "Enable Memory access reorder on Cyrix/NSC processor.\n");
  98. ccr3 = getCx86(CX86_CCR3);
  99. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
  100. /* Load/Store Serialize to mem access disable (=reorder it)  */
  101. setCx86(CX86_PCR0, getCx86(CX86_PCR0) & ~0x80);
  102. /* set load/store serialize from 1GB to 4GB */
  103. ccr3 |= 0xe0;
  104. setCx86(CX86_CCR3, ccr3);
  105. }
  106. static void __init set_cx86_memwb(void)
  107. {
  108. u32 cr0;
  109. printk(KERN_INFO "Enable Memory-Write-back mode on Cyrix/NSC processor.\n");
  110. /* CCR2 bit 2: unlock NW bit */
  111. setCx86(CX86_CCR2, getCx86(CX86_CCR2) & ~0x04);
  112. /* set 'Not Write-through' */
  113. cr0 = 0x20000000;
  114. write_cr0(read_cr0() | cr0);
  115. /* CCR2 bit 2: lock NW bit and set WT1 */
  116. setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x14 );
  117. }
  118. static void __init set_cx86_inc(void)
  119. {
  120. unsigned char ccr3;
  121. printk(KERN_INFO "Enable Incrementor on Cyrix/NSC processor.\n");
  122. ccr3 = getCx86(CX86_CCR3);
  123. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN  */
  124. /* PCR1 -- Performance Control */
  125. /* Incrementor on, whatever that is */
  126. setCx86(CX86_PCR1, getCx86(CX86_PCR1) | 0x02);
  127. /* PCR0 -- Performance Control */
  128. /* Incrementor Margin 10 */
  129. setCx86(CX86_PCR0, getCx86(CX86_PCR0) | 0x04);
  130. setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
  131. }
  132. /*
  133. * Configure later MediaGX and/or Geode processor.
  134. */
  135. static void __init geode_configure(void)
  136. {
  137. unsigned long flags;
  138. u8 ccr3, ccr4;
  139. local_irq_save(flags);
  140. /* Suspend on halt power saving and enable #SUSP pin */
  141. setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
  142. ccr3 = getCx86(CX86_CCR3);
  143. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* Enable */
  144. ccr4 = getCx86(CX86_CCR4);
  145. ccr4 |= 0x38; /* FPU fast, DTE cache, Mem bypass */
  146. setCx86(CX86_CCR3, ccr3);
  147. set_cx86_memwb();
  148. set_cx86_reorder();
  149. set_cx86_inc();
  150. local_irq_restore(flags);
  151. }
  152. #ifdef CONFIG_PCI
  153. static struct pci_device_id cyrix_55x0[] = {
  154. { PCI_DEVICE(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5510) },
  155. { PCI_DEVICE(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_5520) },
  156. { },
  157. };
  158. #endif
  159. static void __init init_cyrix(struct cpuinfo_x86 *c)
  160. {
  161. unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
  162. char *buf = c->x86_model_id;
  163. const char *p = NULL;
  164. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  165. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  166. clear_bit(0*32+31, c->x86_capability);
  167. /* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
  168. if ( test_bit(1*32+24, c->x86_capability) ) {
  169. clear_bit(1*32+24, c->x86_capability);
  170. set_bit(X86_FEATURE_CXMMX, c->x86_capability);
  171. }
  172. do_cyrix_devid(&dir0, &dir1);
  173. check_cx686_slop(c);
  174. Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family" */
  175. dir0_lsn = dir0 & 0xf; /* model or clock multiplier */
  176. /* common case step number/rev -- exceptions handled below */
  177. c->x86_model = (dir1 >> 4) + 1;
  178. c->x86_mask = dir1 & 0xf;
  179. /* Now cook; the original recipe is by Channing Corn, from Cyrix.
  180. * We do the same thing for each generation: we work out
  181. * the model, multiplier and stepping. Black magic included,
  182. * to make the silicon step/rev numbers match the printed ones.
  183. */
  184. switch (dir0_msn) {
  185. unsigned char tmp;
  186. case 0: /* Cx486SLC/DLC/SRx/DRx */
  187. p = Cx486_name[dir0_lsn & 7];
  188. break;
  189. case 1: /* Cx486S/DX/DX2/DX4 */
  190. p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
  191. : Cx486S_name[dir0_lsn & 3];
  192. break;
  193. case 2: /* 5x86 */
  194. Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
  195. p = Cx86_cb+2;
  196. break;
  197. case 3: /* 6x86/6x86L */
  198. Cx86_cb[1] = ' ';
  199. Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
  200. if (dir1 > 0x21) { /* 686L */
  201. Cx86_cb[0] = 'L';
  202. p = Cx86_cb;
  203. (c->x86_model)++;
  204. } else /* 686 */
  205. p = Cx86_cb+1;
  206. /* Emulate MTRRs using Cyrix's ARRs. */
  207. set_bit(X86_FEATURE_CYRIX_ARR, c->x86_capability);
  208. /* 6x86's contain this bug */
  209. c->coma_bug = 1;
  210. break;
  211. case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
  212. #ifdef CONFIG_PCI
  213. /* It isn't really a PCI quirk directly, but the cure is the
  214. same. The MediaGX has deep magic SMM stuff that handles the
  215. SB emulation. It thows away the fifo on disable_dma() which
  216. is wrong and ruins the audio.
  217. Bug2: VSA1 has a wrap bug so that using maximum sized DMA
  218. causes bad things. According to NatSemi VSA2 has another
  219. bug to do with 'hlt'. I've not seen any boards using VSA2
  220. and X doesn't seem to support it either so who cares 8).
  221. VSA1 we work around however.
  222. */
  223. printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
  224. isa_dma_bridge_buggy = 2;
  225. #endif
  226. c->x86_cache_size=16; /* Yep 16K integrated cache thats it */
  227. /*
  228. * The 5510/5520 companion chips have a funky PIT.
  229. */
  230. if (pci_dev_present(cyrix_55x0))
  231. pit_latch_buggy = 1;
  232. /* GXm supports extended cpuid levels 'ala' AMD */
  233. if (c->cpuid_level == 2) {
  234. /* Enable cxMMX extensions (GX1 Datasheet 54) */
  235. setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
  236. /* GXlv/GXm/GX1 */
  237. if((dir1 >= 0x50 && dir1 <= 0x54) || dir1 >= 0x63)
  238. geode_configure();
  239. get_model_name(c); /* get CPU marketing name */
  240. return;
  241. }
  242. else { /* MediaGX */
  243. Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
  244. p = Cx86_cb+2;
  245. c->x86_model = (dir1 & 0x20) ? 1 : 2;
  246. }
  247. break;
  248. case 5: /* 6x86MX/M II */
  249. if (dir1 > 7)
  250. {
  251. dir0_msn++; /* M II */
  252. /* Enable MMX extensions (App note 108) */
  253. setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
  254. }
  255. else
  256. {
  257. c->coma_bug = 1; /* 6x86MX, it has the bug. */
  258. }
  259. tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
  260. Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
  261. p = Cx86_cb+tmp;
  262. if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
  263. (c->x86_model)++;
  264. /* Emulate MTRRs using Cyrix's ARRs. */
  265. set_bit(X86_FEATURE_CYRIX_ARR, c->x86_capability);
  266. break;
  267. case 0xf: /* Cyrix 486 without DEVID registers */
  268. switch (dir0_lsn) {
  269. case 0xd: /* either a 486SLC or DLC w/o DEVID */
  270. dir0_msn = 0;
  271. p = Cx486_name[(c->hard_math) ? 1 : 0];
  272. break;
  273. case 0xe: /* a 486S A step */
  274. dir0_msn = 0;
  275. p = Cx486S_name[0];
  276. break;
  277. }
  278. break;
  279. default: /* unknown (shouldn't happen, we know everyone ;-) */
  280. dir0_msn = 7;
  281. break;
  282. }
  283. strcpy(buf, Cx86_model[dir0_msn & 7]);
  284. if (p) strcat(buf, p);
  285. return;
  286. }
  287. /*
  288. * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
  289. * by the fact that they preserve the flags across the division of 5/2.
  290. * PII and PPro exhibit this behavior too, but they have cpuid available.
  291. */
  292. /*
  293. * Perform the Cyrix 5/2 test. A Cyrix won't change
  294. * the flags, while other 486 chips will.
  295. */
  296. static inline int test_cyrix_52div(void)
  297. {
  298. unsigned int test;
  299. __asm__ __volatile__(
  300. "sahf\n\t" /* clear flags (%eax = 0x0005) */
  301. "div %b2\n\t" /* divide 5 by 2 */
  302. "lahf" /* store flags into %ah */
  303. : "=a" (test)
  304. : "0" (5), "q" (2)
  305. : "cc");
  306. /* AH is 0x02 on Cyrix after the divide.. */
  307. return (unsigned char) (test >> 8) == 0x02;
  308. }
  309. static void cyrix_identify(struct cpuinfo_x86 * c)
  310. {
  311. /* Detect Cyrix with disabled CPUID */
  312. if ( c->x86 == 4 && test_cyrix_52div() ) {
  313. unsigned char dir0, dir1;
  314. strcpy(c->x86_vendor_id, "CyrixInstead");
  315. c->x86_vendor = X86_VENDOR_CYRIX;
  316. /* Actually enable cpuid on the older cyrix */
  317. /* Retrieve CPU revisions */
  318. do_cyrix_devid(&dir0, &dir1);
  319. dir0>>=4;
  320. /* Check it is an affected model */
  321. if (dir0 == 5 || dir0 == 3)
  322. {
  323. unsigned char ccr3, ccr4;
  324. unsigned long flags;
  325. printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
  326. local_irq_save(flags);
  327. ccr3 = getCx86(CX86_CCR3);
  328. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
  329. ccr4 = getCx86(CX86_CCR4);
  330. setCx86(CX86_CCR4, ccr4 | 0x80); /* enable cpuid */
  331. setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
  332. local_irq_restore(flags);
  333. }
  334. }
  335. generic_identify(c);
  336. }
  337. static struct cpu_dev cyrix_cpu_dev __initdata = {
  338. .c_vendor = "Cyrix",
  339. .c_ident = { "CyrixInstead" },
  340. .c_init = init_cyrix,
  341. .c_identify = cyrix_identify,
  342. };
  343. int __init cyrix_init_cpu(void)
  344. {
  345. cpu_devs[X86_VENDOR_CYRIX] = &cyrix_cpu_dev;
  346. return 0;
  347. }
  348. //early_arch_initcall(cyrix_init_cpu);
  349. static struct cpu_dev nsc_cpu_dev __initdata = {
  350. .c_vendor = "NSC",
  351. .c_ident = { "Geode by NSC" },
  352. .c_init = init_cyrix,
  353. .c_identify = generic_identify,
  354. };
  355. int __init nsc_init_cpu(void)
  356. {
  357. cpu_devs[X86_VENDOR_NSC] = &nsc_cpu_dev;
  358. return 0;
  359. }
  360. //early_arch_initcall(nsc_init_cpu);