centaur.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  1. // SPDX-License-Identifier: GPL-2.0
  2. #include <linux/sched.h>
  3. #include <linux/sched/clock.h>
  4. #include <asm/cpufeature.h>
  5. #include <asm/e820/api.h>
  6. #include <asm/mtrr.h>
  7. #include <asm/msr.h>
  8. #include "cpu.h"
  9. #define ACE_PRESENT (1 << 6)
  10. #define ACE_ENABLED (1 << 7)
  11. #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */
  12. #define RNG_PRESENT (1 << 2)
  13. #define RNG_ENABLED (1 << 3)
  14. #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */
  15. static void init_c3(struct cpuinfo_x86 *c)
  16. {
  17. u32 lo, hi;
  18. /* Test for Centaur Extended Feature Flags presence */
  19. if (cpuid_eax(0xC0000000) >= 0xC0000001) {
  20. u32 tmp = cpuid_edx(0xC0000001);
  21. /* enable ACE unit, if present and disabled */
  22. if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) {
  23. rdmsr(MSR_VIA_FCR, lo, hi);
  24. lo |= ACE_FCR; /* enable ACE unit */
  25. wrmsr(MSR_VIA_FCR, lo, hi);
  26. pr_info("CPU: Enabled ACE h/w crypto\n");
  27. }
  28. /* enable RNG unit, if present and disabled */
  29. if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) {
  30. rdmsr(MSR_VIA_RNG, lo, hi);
  31. lo |= RNG_ENABLE; /* enable RNG unit */
  32. wrmsr(MSR_VIA_RNG, lo, hi);
  33. pr_info("CPU: Enabled h/w RNG\n");
  34. }
  35. /* store Centaur Extended Feature Flags as
  36. * word 5 of the CPU capability bit array
  37. */
  38. c->x86_capability[CPUID_C000_0001_EDX] = cpuid_edx(0xC0000001);
  39. }
  40. #ifdef CONFIG_X86_32
  41. /* Cyrix III family needs CX8 & PGE explicitly enabled. */
  42. if (c->x86_model >= 6 && c->x86_model <= 13) {
  43. rdmsr(MSR_VIA_FCR, lo, hi);
  44. lo |= (1<<1 | 1<<7);
  45. wrmsr(MSR_VIA_FCR, lo, hi);
  46. set_cpu_cap(c, X86_FEATURE_CX8);
  47. }
  48. /* Before Nehemiah, the C3's had 3dNOW! */
  49. if (c->x86_model >= 6 && c->x86_model < 9)
  50. set_cpu_cap(c, X86_FEATURE_3DNOW);
  51. #endif
  52. if (c->x86 == 0x6 && c->x86_model >= 0xf) {
  53. c->x86_cache_alignment = c->x86_clflush_size * 2;
  54. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  55. }
  56. cpu_detect_cache_sizes(c);
  57. }
  58. enum {
  59. ECX8 = 1<<1,
  60. EIERRINT = 1<<2,
  61. DPM = 1<<3,
  62. DMCE = 1<<4,
  63. DSTPCLK = 1<<5,
  64. ELINEAR = 1<<6,
  65. DSMC = 1<<7,
  66. DTLOCK = 1<<8,
  67. EDCTLB = 1<<8,
  68. EMMX = 1<<9,
  69. DPDC = 1<<11,
  70. EBRPRED = 1<<12,
  71. DIC = 1<<13,
  72. DDC = 1<<14,
  73. DNA = 1<<15,
  74. ERETSTK = 1<<16,
  75. E2MMX = 1<<19,
  76. EAMD3D = 1<<20,
  77. };
  78. static void early_init_centaur(struct cpuinfo_x86 *c)
  79. {
  80. switch (c->x86) {
  81. #ifdef CONFIG_X86_32
  82. case 5:
  83. /* Emulate MTRRs using Centaur's MCR. */
  84. set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
  85. break;
  86. #endif
  87. case 6:
  88. if (c->x86_model >= 0xf)
  89. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  90. break;
  91. }
  92. #ifdef CONFIG_X86_64
  93. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  94. #endif
  95. if (c->x86_power & (1 << 8)) {
  96. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  97. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  98. }
  99. }
  100. static void init_centaur(struct cpuinfo_x86 *c)
  101. {
  102. #ifdef CONFIG_X86_32
  103. char *name;
  104. u32 fcr_set = 0;
  105. u32 fcr_clr = 0;
  106. u32 lo, hi, newlo;
  107. u32 aa, bb, cc, dd;
  108. /*
  109. * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  110. * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
  111. */
  112. clear_cpu_cap(c, 0*32+31);
  113. #endif
  114. early_init_centaur(c);
  115. switch (c->x86) {
  116. #ifdef CONFIG_X86_32
  117. case 5:
  118. switch (c->x86_model) {
  119. case 4:
  120. name = "C6";
  121. fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
  122. fcr_clr = DPDC;
  123. pr_notice("Disabling bugged TSC.\n");
  124. clear_cpu_cap(c, X86_FEATURE_TSC);
  125. break;
  126. case 8:
  127. switch (c->x86_stepping) {
  128. default:
  129. name = "2";
  130. break;
  131. case 7 ... 9:
  132. name = "2A";
  133. break;
  134. case 10 ... 15:
  135. name = "2B";
  136. break;
  137. }
  138. fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
  139. E2MMX|EAMD3D;
  140. fcr_clr = DPDC;
  141. break;
  142. case 9:
  143. name = "3";
  144. fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
  145. E2MMX|EAMD3D;
  146. fcr_clr = DPDC;
  147. break;
  148. default:
  149. name = "??";
  150. }
  151. rdmsr(MSR_IDT_FCR1, lo, hi);
  152. newlo = (lo|fcr_set) & (~fcr_clr);
  153. if (newlo != lo) {
  154. pr_info("Centaur FCR was 0x%X now 0x%X\n",
  155. lo, newlo);
  156. wrmsr(MSR_IDT_FCR1, newlo, hi);
  157. } else {
  158. pr_info("Centaur FCR is 0x%X\n", lo);
  159. }
  160. /* Emulate MTRRs using Centaur's MCR. */
  161. set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
  162. /* Report CX8 */
  163. set_cpu_cap(c, X86_FEATURE_CX8);
  164. /* Set 3DNow! on Winchip 2 and above. */
  165. if (c->x86_model >= 8)
  166. set_cpu_cap(c, X86_FEATURE_3DNOW);
  167. /* See if we can find out some more. */
  168. if (cpuid_eax(0x80000000) >= 0x80000005) {
  169. /* Yes, we can. */
  170. cpuid(0x80000005, &aa, &bb, &cc, &dd);
  171. /* Add L1 data and code cache sizes. */
  172. c->x86_cache_size = (cc>>24)+(dd>>24);
  173. }
  174. sprintf(c->x86_model_id, "WinChip %s", name);
  175. break;
  176. #endif
  177. case 6:
  178. init_c3(c);
  179. break;
  180. }
  181. #ifdef CONFIG_X86_64
  182. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  183. #endif
  184. }
  185. #ifdef CONFIG_X86_32
  186. static unsigned int
  187. centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  188. {
  189. /* VIA C3 CPUs (670-68F) need further shifting. */
  190. if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8)))
  191. size >>= 8;
  192. /*
  193. * There's also an erratum in Nehemiah stepping 1, which
  194. * returns '65KB' instead of '64KB'
  195. * - Note, it seems this may only be in engineering samples.
  196. */
  197. if ((c->x86 == 6) && (c->x86_model == 9) &&
  198. (c->x86_stepping == 1) && (size == 65))
  199. size -= 1;
  200. return size;
  201. }
  202. #endif
  203. static const struct cpu_dev centaur_cpu_dev = {
  204. .c_vendor = "Centaur",
  205. .c_ident = { "CentaurHauls" },
  206. .c_early_init = early_init_centaur,
  207. .c_init = init_centaur,
  208. #ifdef CONFIG_X86_32
  209. .legacy_cache_size = centaur_size_cache,
  210. #endif
  211. .c_x86_vendor = X86_VENDOR_CENTAUR,
  212. };
  213. cpu_dev_register(centaur_cpu_dev);