amd.c 6.6 KB

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