cyrix.c 12 KB

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