amd_64.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. #include <linux/init.h>
  2. #include <linux/mm.h>
  3. #include <asm/numa_64.h>
  4. #include <asm/mmconfig.h>
  5. #include <asm/cacheflush.h>
  6. #include <mach_apic.h>
  7. #include "cpu.h"
  8. extern int __cpuinit get_model_name(struct cpuinfo_x86 *c);
  9. extern void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c);
  10. int force_mwait __cpuinitdata;
  11. #ifdef CONFIG_NUMA
  12. static int __cpuinit nearby_node(int apicid)
  13. {
  14. int i, node;
  15. for (i = apicid - 1; i >= 0; i--) {
  16. node = apicid_to_node[i];
  17. if (node != NUMA_NO_NODE && node_online(node))
  18. return node;
  19. }
  20. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  21. node = apicid_to_node[i];
  22. if (node != NUMA_NO_NODE && node_online(node))
  23. return node;
  24. }
  25. return first_node(node_online_map); /* Shouldn't happen */
  26. }
  27. #endif
  28. /*
  29. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  30. * Assumes number of cores is a power of two.
  31. */
  32. static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
  33. {
  34. #ifdef CONFIG_SMP
  35. unsigned bits;
  36. #ifdef CONFIG_NUMA
  37. int cpu = smp_processor_id();
  38. int node = 0;
  39. unsigned apicid = hard_smp_processor_id();
  40. #endif
  41. bits = c->x86_coreid_bits;
  42. /* Low order bits define the core id (index of core in socket) */
  43. c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
  44. /* Convert the initial APIC ID into the socket ID */
  45. c->phys_proc_id = c->initial_apicid >> bits;
  46. #ifdef CONFIG_NUMA
  47. node = c->phys_proc_id;
  48. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  49. node = apicid_to_node[apicid];
  50. if (!node_online(node)) {
  51. /* Two possibilities here:
  52. - The CPU is missing memory and no node was created.
  53. In that case try picking one from a nearby CPU
  54. - The APIC IDs differ from the HyperTransport node IDs
  55. which the K8 northbridge parsing fills in.
  56. Assume they are all increased by a constant offset,
  57. but in the same order as the HT nodeids.
  58. If that doesn't result in a usable node fall back to the
  59. path for the previous case. */
  60. int ht_nodeid = c->initial_apicid;
  61. if (ht_nodeid >= 0 &&
  62. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  63. node = apicid_to_node[ht_nodeid];
  64. /* Pick a nearby node */
  65. if (!node_online(node))
  66. node = nearby_node(apicid);
  67. }
  68. numa_set_node(cpu, node);
  69. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  70. #endif
  71. #endif
  72. }
  73. static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
  74. {
  75. #ifdef CONFIG_SMP
  76. unsigned bits, ecx;
  77. /* Multi core CPU? */
  78. if (c->extended_cpuid_level < 0x80000008)
  79. return;
  80. ecx = cpuid_ecx(0x80000008);
  81. c->x86_max_cores = (ecx & 0xff) + 1;
  82. /* CPU telling us the core id bits shift? */
  83. bits = (ecx >> 12) & 0xF;
  84. /* Otherwise recompute */
  85. if (bits == 0) {
  86. while ((1 << bits) < c->x86_max_cores)
  87. bits++;
  88. }
  89. c->x86_coreid_bits = bits;
  90. #endif
  91. }
  92. #define ENABLE_C1E_MASK 0x18000000
  93. #define CPUID_PROCESSOR_SIGNATURE 1
  94. #define CPUID_XFAM 0x0ff00000
  95. #define CPUID_XFAM_K8 0x00000000
  96. #define CPUID_XFAM_10H 0x00100000
  97. #define CPUID_XFAM_11H 0x00200000
  98. #define CPUID_XMOD 0x000f0000
  99. #define CPUID_XMOD_REV_F 0x00040000
  100. /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
  101. static __cpuinit int amd_apic_timer_broken(void)
  102. {
  103. u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
  104. switch (eax & CPUID_XFAM) {
  105. case CPUID_XFAM_K8:
  106. if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
  107. break;
  108. case CPUID_XFAM_10H:
  109. case CPUID_XFAM_11H:
  110. rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
  111. if (lo & ENABLE_C1E_MASK)
  112. return 1;
  113. break;
  114. default:
  115. /* err on the side of caution */
  116. return 1;
  117. }
  118. return 0;
  119. }
  120. void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  121. {
  122. early_init_amd_mc(c);
  123. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  124. if (c->x86_power & (1<<8))
  125. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  126. }
  127. void __cpuinit init_amd(struct cpuinfo_x86 *c)
  128. {
  129. unsigned level;
  130. #ifdef CONFIG_SMP
  131. unsigned long value;
  132. /*
  133. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  134. * bit 6 of msr C001_0015
  135. *
  136. * Errata 63 for SH-B3 steppings
  137. * Errata 122 for all steppings (F+ have it disabled by default)
  138. */
  139. if (c->x86 == 15) {
  140. rdmsrl(MSR_K8_HWCR, value);
  141. value |= 1 << 6;
  142. wrmsrl(MSR_K8_HWCR, value);
  143. }
  144. #endif
  145. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  146. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  147. clear_cpu_cap(c, 0*32+31);
  148. /* On C+ stepping K8 rep microcode works well for copy/memset */
  149. level = cpuid_eax(1);
  150. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
  151. level >= 0x0f58))
  152. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  153. if (c->x86 == 0x10 || c->x86 == 0x11)
  154. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  155. /* Enable workaround for FXSAVE leak */
  156. if (c->x86 >= 6)
  157. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  158. level = get_model_name(c);
  159. if (!level) {
  160. switch (c->x86) {
  161. case 15:
  162. /* Should distinguish Models here, but this is only
  163. a fallback anyways. */
  164. strcpy(c->x86_model_id, "Hammer");
  165. break;
  166. }
  167. }
  168. display_cacheinfo(c);
  169. /* Multi core CPU? */
  170. if (c->extended_cpuid_level >= 0x80000008)
  171. amd_detect_cmp(c);
  172. if (c->extended_cpuid_level >= 0x80000006 &&
  173. (cpuid_edx(0x80000006) & 0xf000))
  174. num_cache_leaves = 4;
  175. else
  176. num_cache_leaves = 3;
  177. if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
  178. set_cpu_cap(c, X86_FEATURE_K8);
  179. /* MFENCE stops RDTSC speculation */
  180. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  181. if (c->x86 == 0x10)
  182. fam10h_check_enable_mmcfg();
  183. if (c->x86 == 0x10)
  184. amd_enable_pci_ext_cfg(c);
  185. if (amd_apic_timer_broken())
  186. disable_apic_timer = 1;
  187. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  188. unsigned long long tseg;
  189. /*
  190. * Split up direct mapping around the TSEG SMM area.
  191. * Don't do it for gbpages because there seems very little
  192. * benefit in doing so.
  193. */
  194. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
  195. (tseg >> PMD_SHIFT) <
  196. (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
  197. set_memory_4k((unsigned long)__va(tseg), 1);
  198. }
  199. }