cyrix.c 12 KB

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