amd_64.c 5.3 KB

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