cyrix.c 12 KB

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