cyrix.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431
  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. /*
  118. * Configure later MediaGX and/or Geode processor.
  119. */
  120. static void __cpuinit geode_configure(void)
  121. {
  122. unsigned long flags;
  123. u8 ccr3;
  124. local_irq_save(flags);
  125. /* Suspend on halt power saving and enable #SUSP pin */
  126. setCx86(CX86_CCR2, getCx86(CX86_CCR2) | 0x88);
  127. ccr3 = getCx86(CX86_CCR3);
  128. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
  129. /* FPU fast, DTE cache, Mem bypass */
  130. setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x38);
  131. setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
  132. set_cx86_memwb();
  133. set_cx86_reorder();
  134. local_irq_restore(flags);
  135. }
  136. static void __cpuinit init_cyrix(struct cpuinfo_x86 *c)
  137. {
  138. unsigned char dir0, dir0_msn, dir0_lsn, dir1 = 0;
  139. char *buf = c->x86_model_id;
  140. const char *p = NULL;
  141. /*
  142. * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  143. * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
  144. */
  145. clear_cpu_cap(c, 0*32+31);
  146. /* Cyrix used bit 24 in extended (AMD) CPUID for Cyrix MMX extensions */
  147. if (test_cpu_cap(c, 1*32+24)) {
  148. clear_cpu_cap(c, 1*32+24);
  149. set_cpu_cap(c, X86_FEATURE_CXMMX);
  150. }
  151. do_cyrix_devid(&dir0, &dir1);
  152. check_cx686_slop(c);
  153. Cx86_dir0_msb = dir0_msn = dir0 >> 4; /* identifies CPU "family" */
  154. dir0_lsn = dir0 & 0xf; /* model or clock multiplier */
  155. /* common case step number/rev -- exceptions handled below */
  156. c->x86_model = (dir1 >> 4) + 1;
  157. c->x86_mask = dir1 & 0xf;
  158. /* Now cook; the original recipe is by Channing Corn, from Cyrix.
  159. * We do the same thing for each generation: we work out
  160. * the model, multiplier and stepping. Black magic included,
  161. * to make the silicon step/rev numbers match the printed ones.
  162. */
  163. switch (dir0_msn) {
  164. unsigned char tmp;
  165. case 0: /* Cx486SLC/DLC/SRx/DRx */
  166. p = Cx486_name[dir0_lsn & 7];
  167. break;
  168. case 1: /* Cx486S/DX/DX2/DX4 */
  169. p = (dir0_lsn & 8) ? Cx486D_name[dir0_lsn & 5]
  170. : Cx486S_name[dir0_lsn & 3];
  171. break;
  172. case 2: /* 5x86 */
  173. Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
  174. p = Cx86_cb+2;
  175. break;
  176. case 3: /* 6x86/6x86L */
  177. Cx86_cb[1] = ' ';
  178. Cx86_cb[2] = cyrix_model_mult1[dir0_lsn & 5];
  179. if (dir1 > 0x21) { /* 686L */
  180. Cx86_cb[0] = 'L';
  181. p = Cx86_cb;
  182. (c->x86_model)++;
  183. } else /* 686 */
  184. p = Cx86_cb+1;
  185. /* Emulate MTRRs using Cyrix's ARRs. */
  186. set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
  187. /* 6x86's contain this bug */
  188. c->coma_bug = 1;
  189. break;
  190. case 4: /* MediaGX/GXm or Geode GXM/GXLV/GX1 */
  191. #ifdef CONFIG_PCI
  192. {
  193. u32 vendor, device;
  194. /*
  195. * It isn't really a PCI quirk directly, but the cure is the
  196. * same. The MediaGX has deep magic SMM stuff that handles the
  197. * SB emulation. It throws away the fifo on disable_dma() which
  198. * is wrong and ruins the audio.
  199. *
  200. * Bug2: VSA1 has a wrap bug so that using maximum sized DMA
  201. * causes bad things. According to NatSemi VSA2 has another
  202. * bug to do with 'hlt'. I've not seen any boards using VSA2
  203. * and X doesn't seem to support it either so who cares 8).
  204. * VSA1 we work around however.
  205. */
  206. printk(KERN_INFO "Working around Cyrix MediaGX virtual DMA bugs.\n");
  207. isa_dma_bridge_buggy = 2;
  208. /* We do this before the PCI layer is running. However we
  209. are safe here as we know the bridge must be a Cyrix
  210. companion and must be present */
  211. vendor = read_pci_config_16(0, 0, 0x12, PCI_VENDOR_ID);
  212. device = read_pci_config_16(0, 0, 0x12, PCI_DEVICE_ID);
  213. /*
  214. * The 5510/5520 companion chips have a funky PIT.
  215. */
  216. if (vendor == PCI_VENDOR_ID_CYRIX &&
  217. (device == PCI_DEVICE_ID_CYRIX_5510 || device == PCI_DEVICE_ID_CYRIX_5520))
  218. mark_tsc_unstable("cyrix 5510/5520 detected");
  219. }
  220. #endif
  221. c->x86_cache_size = 16; /* Yep 16K integrated cache thats it */
  222. /* GXm supports extended cpuid levels 'ala' AMD */
  223. if (c->cpuid_level == 2) {
  224. /* Enable cxMMX extensions (GX1 Datasheet 54) */
  225. setCx86(CX86_CCR7, getCx86(CX86_CCR7) | 1);
  226. /*
  227. * GXm : 0x30 ... 0x5f GXm datasheet 51
  228. * GXlv: 0x6x GXlv datasheet 54
  229. * ? : 0x7x
  230. * GX1 : 0x8x GX1 datasheet 56
  231. */
  232. if ((0x30 <= dir1 && dir1 <= 0x6f) || (0x80 <= dir1 && dir1 <= 0x8f))
  233. geode_configure();
  234. get_model_name(c); /* get CPU marketing name */
  235. return;
  236. } else { /* MediaGX */
  237. Cx86_cb[2] = (dir0_lsn & 1) ? '3' : '4';
  238. p = Cx86_cb+2;
  239. c->x86_model = (dir1 & 0x20) ? 1 : 2;
  240. }
  241. break;
  242. case 5: /* 6x86MX/M II */
  243. if (dir1 > 7) {
  244. dir0_msn++; /* M II */
  245. /* Enable MMX extensions (App note 108) */
  246. setCx86(CX86_CCR7, getCx86(CX86_CCR7)|1);
  247. } else {
  248. c->coma_bug = 1; /* 6x86MX, it has the bug. */
  249. }
  250. tmp = (!(dir0_lsn & 7) || dir0_lsn & 1) ? 2 : 0;
  251. Cx86_cb[tmp] = cyrix_model_mult2[dir0_lsn & 7];
  252. p = Cx86_cb+tmp;
  253. if (((dir1 & 0x0f) > 4) || ((dir1 & 0xf0) == 0x20))
  254. (c->x86_model)++;
  255. /* Emulate MTRRs using Cyrix's ARRs. */
  256. set_cpu_cap(c, X86_FEATURE_CYRIX_ARR);
  257. break;
  258. case 0xf: /* Cyrix 486 without DEVID registers */
  259. switch (dir0_lsn) {
  260. case 0xd: /* either a 486SLC or DLC w/o DEVID */
  261. dir0_msn = 0;
  262. p = Cx486_name[(c->hard_math) ? 1 : 0];
  263. break;
  264. case 0xe: /* a 486S A step */
  265. dir0_msn = 0;
  266. p = Cx486S_name[0];
  267. break;
  268. }
  269. break;
  270. default: /* unknown (shouldn't happen, we know everyone ;-) */
  271. dir0_msn = 7;
  272. break;
  273. }
  274. strcpy(buf, Cx86_model[dir0_msn & 7]);
  275. if (p)
  276. strcat(buf, p);
  277. return;
  278. }
  279. /*
  280. * Handle National Semiconductor branded processors
  281. */
  282. static void __cpuinit init_nsc(struct cpuinfo_x86 *c)
  283. {
  284. /*
  285. * There may be GX1 processors in the wild that are branded
  286. * NSC and not Cyrix.
  287. *
  288. * This function only handles the GX processor, and kicks every
  289. * thing else to the Cyrix init function above - that should
  290. * cover any processors that might have been branded differently
  291. * after NSC acquired Cyrix.
  292. *
  293. * If this breaks your GX1 horribly, please e-mail
  294. * info-linux@ldcmail.amd.com to tell us.
  295. */
  296. /* Handle the GX (Formally known as the GX2) */
  297. if (c->x86 == 5 && c->x86_model == 5)
  298. display_cacheinfo(c);
  299. else
  300. init_cyrix(c);
  301. }
  302. /*
  303. * Cyrix CPUs without cpuid or with cpuid not yet enabled can be detected
  304. * by the fact that they preserve the flags across the division of 5/2.
  305. * PII and PPro exhibit this behavior too, but they have cpuid available.
  306. */
  307. /*
  308. * Perform the Cyrix 5/2 test. A Cyrix won't change
  309. * the flags, while other 486 chips will.
  310. */
  311. static inline int test_cyrix_52div(void)
  312. {
  313. unsigned int test;
  314. __asm__ __volatile__(
  315. "sahf\n\t" /* clear flags (%eax = 0x0005) */
  316. "div %b2\n\t" /* divide 5 by 2 */
  317. "lahf" /* store flags into %ah */
  318. : "=a" (test)
  319. : "0" (5), "q" (2)
  320. : "cc");
  321. /* AH is 0x02 on Cyrix after the divide.. */
  322. return (unsigned char) (test >> 8) == 0x02;
  323. }
  324. static void __cpuinit cyrix_identify(struct cpuinfo_x86 *c)
  325. {
  326. /* Detect Cyrix with disabled CPUID */
  327. if (c->x86 == 4 && test_cyrix_52div()) {
  328. unsigned char dir0, dir1;
  329. strcpy(c->x86_vendor_id, "CyrixInstead");
  330. c->x86_vendor = X86_VENDOR_CYRIX;
  331. /* Actually enable cpuid on the older cyrix */
  332. /* Retrieve CPU revisions */
  333. do_cyrix_devid(&dir0, &dir1);
  334. dir0 >>= 4;
  335. /* Check it is an affected model */
  336. if (dir0 == 5 || dir0 == 3) {
  337. unsigned char ccr3;
  338. unsigned long flags;
  339. printk(KERN_INFO "Enabling CPUID on Cyrix processor.\n");
  340. local_irq_save(flags);
  341. ccr3 = getCx86(CX86_CCR3);
  342. setCx86(CX86_CCR3, (ccr3 & 0x0f) | 0x10); /* enable MAPEN */
  343. setCx86(CX86_CCR4, getCx86(CX86_CCR4) | 0x80); /* enable cpuid */
  344. setCx86(CX86_CCR3, ccr3); /* disable MAPEN */
  345. local_irq_restore(flags);
  346. }
  347. }
  348. }
  349. static struct cpu_dev cyrix_cpu_dev __cpuinitdata = {
  350. .c_vendor = "Cyrix",
  351. .c_ident = { "CyrixInstead" },
  352. .c_init = init_cyrix,
  353. .c_identify = cyrix_identify,
  354. };
  355. cpu_vendor_dev_register(X86_VENDOR_CYRIX, &cyrix_cpu_dev);
  356. static struct cpu_dev nsc_cpu_dev __cpuinitdata = {
  357. .c_vendor = "NSC",
  358. .c_ident = { "Geode by NSC" },
  359. .c_init = init_nsc,
  360. };
  361. cpu_vendor_dev_register(X86_VENDOR_NSC, &nsc_cpu_dev);