cyrix.c 12 KB

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