centaur.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. detect_num_cpu_cores(c);
  115. #ifdef CONFIG_X86_32
  116. detect_ht(c);
  117. #endif
  118. if (c->cpuid_level > 9) {
  119. unsigned int eax = cpuid_eax(10);
  120. /*
  121. * Check for version and the number of counters
  122. * Version(eax[7:0]) can't be 0;
  123. * Counters(eax[15:8]) should be greater than 1;
  124. */
  125. if ((eax & 0xff) && (((eax >> 8) & 0xff) > 1))
  126. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  127. }
  128. #ifdef CONFIG_X86_32
  129. if (c->x86 == 5) {
  130. switch (c->x86_model) {
  131. case 4:
  132. name = "C6";
  133. fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK;
  134. fcr_clr = DPDC;
  135. pr_notice("Disabling bugged TSC.\n");
  136. clear_cpu_cap(c, X86_FEATURE_TSC);
  137. break;
  138. case 8:
  139. switch (c->x86_stepping) {
  140. default:
  141. name = "2";
  142. break;
  143. case 7 ... 9:
  144. name = "2A";
  145. break;
  146. case 10 ... 15:
  147. name = "2B";
  148. break;
  149. }
  150. fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
  151. E2MMX|EAMD3D;
  152. fcr_clr = DPDC;
  153. break;
  154. case 9:
  155. name = "3";
  156. fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|
  157. E2MMX|EAMD3D;
  158. fcr_clr = DPDC;
  159. break;
  160. default:
  161. name = "??";
  162. }
  163. rdmsr(MSR_IDT_FCR1, lo, hi);
  164. newlo = (lo|fcr_set) & (~fcr_clr);
  165. if (newlo != lo) {
  166. pr_info("Centaur FCR was 0x%X now 0x%X\n",
  167. lo, newlo);
  168. wrmsr(MSR_IDT_FCR1, newlo, hi);
  169. } else {
  170. pr_info("Centaur FCR is 0x%X\n", lo);
  171. }
  172. /* Emulate MTRRs using Centaur's MCR. */
  173. set_cpu_cap(c, X86_FEATURE_CENTAUR_MCR);
  174. /* Report CX8 */
  175. set_cpu_cap(c, X86_FEATURE_CX8);
  176. /* Set 3DNow! on Winchip 2 and above. */
  177. if (c->x86_model >= 8)
  178. set_cpu_cap(c, X86_FEATURE_3DNOW);
  179. /* See if we can find out some more. */
  180. if (cpuid_eax(0x80000000) >= 0x80000005) {
  181. /* Yes, we can. */
  182. cpuid(0x80000005, &aa, &bb, &cc, &dd);
  183. /* Add L1 data and code cache sizes. */
  184. c->x86_cache_size = (cc>>24)+(dd>>24);
  185. }
  186. sprintf(c->x86_model_id, "WinChip %s", name);
  187. }
  188. #endif
  189. if (c->x86 == 6 || c->x86 >= 7)
  190. init_c3(c);
  191. #ifdef CONFIG_X86_64
  192. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  193. #endif
  194. init_ia32_feat_ctl(c);
  195. }
  196. #ifdef CONFIG_X86_32
  197. static unsigned int
  198. centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  199. {
  200. /* VIA C3 CPUs (670-68F) need further shifting. */
  201. if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8)))
  202. size >>= 8;
  203. /*
  204. * There's also an erratum in Nehemiah stepping 1, which
  205. * returns '65KB' instead of '64KB'
  206. * - Note, it seems this may only be in engineering samples.
  207. */
  208. if ((c->x86 == 6) && (c->x86_model == 9) &&
  209. (c->x86_stepping == 1) && (size == 65))
  210. size -= 1;
  211. return size;
  212. }
  213. #endif
  214. static const struct cpu_dev centaur_cpu_dev = {
  215. .c_vendor = "Centaur",
  216. .c_ident = { "CentaurHauls" },
  217. .c_early_init = early_init_centaur,
  218. .c_init = init_centaur,
  219. #ifdef CONFIG_X86_32
  220. .legacy_cache_size = centaur_size_cache,
  221. #endif
  222. .c_x86_vendor = X86_VENDOR_CENTAUR,
  223. };
  224. cpu_dev_register(centaur_cpu_dev);