amd.c 7.3 KB

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