amd_64.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231
  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. /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
  93. static __cpuinit int amd_apic_timer_broken(struct cpuinfo_x86 *c)
  94. {
  95. u32 lo, hi;
  96. if (c->x86 < 0x0F)
  97. return 0;
  98. /* Family 0x0f models < rev F do not have this MSR */
  99. if (c->x86 == 0x0f && c->x86_model < 0x40)
  100. return 0;
  101. rdmsr(MSR_K8_INT_PENDING_MSG, lo, hi);
  102. if (lo & K8_INTP_C1E_ACTIVE_MASK) {
  103. if (smp_processor_id() != boot_cpu_physical_apicid)
  104. printk(KERN_INFO "AMD C1E detected late. "
  105. "Force timer broadcast.\n");
  106. return 1;
  107. }
  108. return 0;
  109. }
  110. void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  111. {
  112. early_init_amd_mc(c);
  113. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  114. if (c->x86_power & (1<<8))
  115. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  116. }
  117. void __cpuinit init_amd(struct cpuinfo_x86 *c)
  118. {
  119. unsigned level;
  120. #ifdef CONFIG_SMP
  121. unsigned long value;
  122. /*
  123. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  124. * bit 6 of msr C001_0015
  125. *
  126. * Errata 63 for SH-B3 steppings
  127. * Errata 122 for all steppings (F+ have it disabled by default)
  128. */
  129. if (c->x86 == 15) {
  130. rdmsrl(MSR_K8_HWCR, value);
  131. value |= 1 << 6;
  132. wrmsrl(MSR_K8_HWCR, value);
  133. }
  134. #endif
  135. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  136. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  137. clear_cpu_cap(c, 0*32+31);
  138. /* On C+ stepping K8 rep microcode works well for copy/memset */
  139. level = cpuid_eax(1);
  140. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
  141. level >= 0x0f58))
  142. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  143. if (c->x86 == 0x10 || c->x86 == 0x11)
  144. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  145. /* Enable workaround for FXSAVE leak */
  146. if (c->x86 >= 6)
  147. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  148. level = get_model_name(c);
  149. if (!level) {
  150. switch (c->x86) {
  151. case 15:
  152. /* Should distinguish Models here, but this is only
  153. a fallback anyways. */
  154. strcpy(c->x86_model_id, "Hammer");
  155. break;
  156. }
  157. }
  158. display_cacheinfo(c);
  159. /* Multi core CPU? */
  160. if (c->extended_cpuid_level >= 0x80000008)
  161. amd_detect_cmp(c);
  162. if (c->extended_cpuid_level >= 0x80000006 &&
  163. (cpuid_edx(0x80000006) & 0xf000))
  164. num_cache_leaves = 4;
  165. else
  166. num_cache_leaves = 3;
  167. if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
  168. set_cpu_cap(c, X86_FEATURE_K8);
  169. /* MFENCE stops RDTSC speculation */
  170. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  171. if (c->x86 == 0x10)
  172. fam10h_check_enable_mmcfg();
  173. if (c->x86 == 0x10)
  174. amd_enable_pci_ext_cfg(c);
  175. if (amd_apic_timer_broken(c))
  176. disable_apic_timer = 1;
  177. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  178. unsigned long long tseg;
  179. /*
  180. * Split up direct mapping around the TSEG SMM area.
  181. * Don't do it for gbpages because there seems very little
  182. * benefit in doing so.
  183. */
  184. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
  185. (tseg >> PMD_SHIFT) <
  186. (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
  187. set_memory_4k((unsigned long)__va(tseg), 1);
  188. }
  189. }