amd.c 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. #include <linux/init.h>
  2. #include <linux/bitops.h>
  3. #include <linux/mm.h>
  4. #include <asm/io.h>
  5. #include <asm/processor.h>
  6. #include <asm/apic.h>
  7. #include <mach_apic.h>
  8. #include "cpu.h"
  9. /*
  10. * B step AMD K6 before B 9730xxxx have hardware bugs that can cause
  11. * misexecution of code under Linux. Owners of such processors should
  12. * contact AMD for precise details and a CPU swap.
  13. *
  14. * See http://www.multimania.com/poulot/k6bug.html
  15. * http://www.amd.com/K6/k6docs/revgd.html
  16. *
  17. * The following test is erm.. interesting. AMD neglected to up
  18. * the chip setting when fixing the bug but they also tweaked some
  19. * performance at the same time..
  20. */
  21. extern void vide(void);
  22. __asm__(".align 4\nvide: ret");
  23. int force_mwait __cpuinitdata;
  24. static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  25. {
  26. if (cpuid_eax(0x80000000) >= 0x80000007) {
  27. c->x86_power = cpuid_edx(0x80000007);
  28. if (c->x86_power & (1<<8))
  29. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  30. }
  31. }
  32. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  33. {
  34. u32 l, h;
  35. int mbytes = num_physpages >> (20-PAGE_SHIFT);
  36. int r;
  37. #ifdef CONFIG_SMP
  38. unsigned long long value;
  39. /*
  40. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  41. * bit 6 of msr C001_0015
  42. *
  43. * Errata 63 for SH-B3 steppings
  44. * Errata 122 for all steppings (F+ have it disabled by default)
  45. */
  46. if (c->x86 == 15) {
  47. rdmsrl(MSR_K7_HWCR, value);
  48. value |= 1 << 6;
  49. wrmsrl(MSR_K7_HWCR, value);
  50. }
  51. #endif
  52. early_init_amd(c);
  53. /*
  54. * FIXME: We should handle the K5 here. Set up the write
  55. * range and also turn on MSR 83 bits 4 and 31 (write alloc,
  56. * no bus pipeline)
  57. */
  58. /*
  59. * Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  60. * 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway
  61. */
  62. clear_cpu_cap(c, 0*32+31);
  63. r = get_model_name(c);
  64. switch (c->x86) {
  65. case 4:
  66. /*
  67. * General Systems BIOSen alias the cpu frequency registers
  68. * of the Elan at 0x000df000. Unfortuantly, one of the Linux
  69. * drivers subsequently pokes it, and changes the CPU speed.
  70. * Workaround : Remove the unneeded alias.
  71. */
  72. #define CBAR (0xfffc) /* Configuration Base Address (32-bit) */
  73. #define CBAR_ENB (0x80000000)
  74. #define CBAR_KEY (0X000000CB)
  75. if (c->x86_model == 9 || c->x86_model == 10) {
  76. if (inl (CBAR) & CBAR_ENB)
  77. outl (0 | CBAR_KEY, CBAR);
  78. }
  79. break;
  80. case 5:
  81. if (c->x86_model < 6) {
  82. /* Based on AMD doc 20734R - June 2000 */
  83. if (c->x86_model == 0) {
  84. clear_cpu_cap(c, X86_FEATURE_APIC);
  85. set_cpu_cap(c, X86_FEATURE_PGE);
  86. }
  87. break;
  88. }
  89. if (c->x86_model == 6 && c->x86_mask == 1) {
  90. const int K6_BUG_LOOP = 1000000;
  91. int n;
  92. void (*f_vide)(void);
  93. unsigned long d, d2;
  94. printk(KERN_INFO "AMD K6 stepping B detected - ");
  95. /*
  96. * It looks like AMD fixed the 2.6.2 bug and improved indirect
  97. * calls at the same time.
  98. */
  99. n = K6_BUG_LOOP;
  100. f_vide = vide;
  101. rdtscl(d);
  102. while (n--)
  103. f_vide();
  104. rdtscl(d2);
  105. d = d2-d;
  106. if (d > 20*K6_BUG_LOOP)
  107. printk("system stability may be impaired when more than 32 MB are used.\n");
  108. else
  109. printk("probably OK (after B9730xxxx).\n");
  110. printk(KERN_INFO "Please see http://membres.lycos.fr/poulot/k6bug.html\n");
  111. }
  112. /* K6 with old style WHCR */
  113. if (c->x86_model < 8 ||
  114. (c->x86_model == 8 && c->x86_mask < 8)) {
  115. /* We can only write allocate on the low 508Mb */
  116. if (mbytes > 508)
  117. mbytes = 508;
  118. rdmsr(MSR_K6_WHCR, l, h);
  119. if ((l&0x0000FFFF) == 0) {
  120. unsigned long flags;
  121. l = (1<<0)|((mbytes/4)<<1);
  122. local_irq_save(flags);
  123. wbinvd();
  124. wrmsr(MSR_K6_WHCR, l, h);
  125. local_irq_restore(flags);
  126. printk(KERN_INFO "Enabling old style K6 write allocation for %d Mb\n",
  127. mbytes);
  128. }
  129. break;
  130. }
  131. if ((c->x86_model == 8 && c->x86_mask > 7) ||
  132. c->x86_model == 9 || c->x86_model == 13) {
  133. /* The more serious chips .. */
  134. if (mbytes > 4092)
  135. mbytes = 4092;
  136. rdmsr(MSR_K6_WHCR, l, h);
  137. if ((l&0xFFFF0000) == 0) {
  138. unsigned long flags;
  139. l = ((mbytes>>2)<<22)|(1<<16);
  140. local_irq_save(flags);
  141. wbinvd();
  142. wrmsr(MSR_K6_WHCR, l, h);
  143. local_irq_restore(flags);
  144. printk(KERN_INFO "Enabling new style K6 write allocation for %d Mb\n",
  145. mbytes);
  146. }
  147. /* Set MTRR capability flag if appropriate */
  148. if (c->x86_model == 13 || c->x86_model == 9 ||
  149. (c->x86_model == 8 && c->x86_mask >= 8))
  150. set_cpu_cap(c, X86_FEATURE_K6_MTRR);
  151. break;
  152. }
  153. if (c->x86_model == 10) {
  154. /* AMD Geode LX is model 10 */
  155. /* placeholder for any needed mods */
  156. break;
  157. }
  158. break;
  159. case 6: /* An Athlon/Duron */
  160. /*
  161. * Bit 15 of Athlon specific MSR 15, needs to be 0
  162. * to enable SSE on Palomino/Morgan/Barton CPU's.
  163. * If the BIOS didn't enable it already, enable it here.
  164. */
  165. if (c->x86_model >= 6 && c->x86_model <= 10) {
  166. if (!cpu_has(c, X86_FEATURE_XMM)) {
  167. printk(KERN_INFO "Enabling disabled K7/SSE Support.\n");
  168. rdmsr(MSR_K7_HWCR, l, h);
  169. l &= ~0x00008000;
  170. wrmsr(MSR_K7_HWCR, l, h);
  171. set_cpu_cap(c, X86_FEATURE_XMM);
  172. }
  173. }
  174. /*
  175. * It's been determined by AMD that Athlons since model 8 stepping 1
  176. * are more robust with CLK_CTL set to 200xxxxx instead of 600xxxxx
  177. * As per AMD technical note 27212 0.2
  178. */
  179. if ((c->x86_model == 8 && c->x86_mask >= 1) || (c->x86_model > 8)) {
  180. rdmsr(MSR_K7_CLK_CTL, l, h);
  181. if ((l & 0xfff00000) != 0x20000000) {
  182. printk ("CPU: CLK_CTL MSR was %x. Reprogramming to %x\n", l,
  183. ((l & 0x000fffff)|0x20000000));
  184. wrmsr(MSR_K7_CLK_CTL, (l & 0x000fffff)|0x20000000, h);
  185. }
  186. }
  187. break;
  188. }
  189. switch (c->x86) {
  190. case 15:
  191. /* Use K8 tuning for Fam10h and Fam11h */
  192. case 0x10:
  193. case 0x11:
  194. set_cpu_cap(c, X86_FEATURE_K8);
  195. break;
  196. case 6:
  197. set_cpu_cap(c, X86_FEATURE_K7);
  198. break;
  199. }
  200. if (c->x86 >= 6)
  201. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  202. display_cacheinfo(c);
  203. if (cpuid_eax(0x80000000) >= 0x80000008)
  204. c->x86_max_cores = (cpuid_ecx(0x80000008) & 0xff) + 1;
  205. #ifdef CONFIG_X86_HT
  206. /*
  207. * On a AMD multi core setup the lower bits of the APIC id
  208. * distinguish the cores.
  209. */
  210. if (c->x86_max_cores > 1) {
  211. int cpu = smp_processor_id();
  212. unsigned bits = (cpuid_ecx(0x80000008) >> 12) & 0xf;
  213. if (bits == 0) {
  214. while ((1 << bits) < c->x86_max_cores)
  215. bits++;
  216. }
  217. c->cpu_core_id = c->phys_proc_id & ((1<<bits)-1);
  218. c->phys_proc_id >>= bits;
  219. printk(KERN_INFO "CPU %d(%d) -> Core %d\n",
  220. cpu, c->x86_max_cores, c->cpu_core_id);
  221. }
  222. #endif
  223. if (cpuid_eax(0x80000000) >= 0x80000006) {
  224. if ((c->x86 == 0x10) && (cpuid_edx(0x80000006) & 0xf000))
  225. num_cache_leaves = 4;
  226. else
  227. num_cache_leaves = 3;
  228. }
  229. /* K6s reports MCEs but don't actually have all the MSRs */
  230. if (c->x86 < 6)
  231. clear_cpu_cap(c, X86_FEATURE_MCE);
  232. if (cpu_has_xmm2)
  233. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  234. }
  235. static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  236. {
  237. /* AMD errata T13 (order #21922) */
  238. if ((c->x86 == 6)) {
  239. if (c->x86_model == 3 && c->x86_mask == 0) /* Duron Rev A0 */
  240. size = 64;
  241. if (c->x86_model == 4 &&
  242. (c->x86_mask == 0 || c->x86_mask == 1)) /* Tbird rev A1/A2 */
  243. size = 256;
  244. }
  245. return size;
  246. }
  247. static struct cpu_dev amd_cpu_dev __cpuinitdata = {
  248. .c_vendor = "AMD",
  249. .c_ident = { "AuthenticAMD" },
  250. .c_models = {
  251. { .vendor = X86_VENDOR_AMD, .family = 4, .model_names =
  252. {
  253. [3] = "486 DX/2",
  254. [7] = "486 DX/2-WB",
  255. [8] = "486 DX/4",
  256. [9] = "486 DX/4-WB",
  257. [14] = "Am5x86-WT",
  258. [15] = "Am5x86-WB"
  259. }
  260. },
  261. },
  262. .c_early_init = early_init_amd,
  263. .c_init = init_amd,
  264. .c_size_cache = amd_size_cache,
  265. };
  266. cpu_vendor_dev_register(X86_VENDOR_AMD, &amd_cpu_dev);