centaur.c 5.2 KB

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