centaur.c 5.7 KB

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