cyrix.c 12 KB

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