cyrix.c 12 KB

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