amd_64.c 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. set_cpu_cap(c, X86_FEATURE_SYSCALL32);
  97. }
  98. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  99. {
  100. unsigned level;
  101. #ifdef CONFIG_SMP
  102. unsigned long value;
  103. /*
  104. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  105. * bit 6 of msr C001_0015
  106. *
  107. * Errata 63 for SH-B3 steppings
  108. * Errata 122 for all steppings (F+ have it disabled by default)
  109. */
  110. if (c->x86 == 0xf) {
  111. rdmsrl(MSR_K8_HWCR, value);
  112. value |= 1 << 6;
  113. wrmsrl(MSR_K8_HWCR, value);
  114. }
  115. #endif
  116. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  117. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  118. clear_cpu_cap(c, 0*32+31);
  119. /* On C+ stepping K8 rep microcode works well for copy/memset */
  120. if (c->x86 == 0xf) {
  121. level = cpuid_eax(1);
  122. if((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58)
  123. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  124. }
  125. if (c->x86 == 0x10 || c->x86 == 0x11)
  126. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  127. /* Enable workaround for FXSAVE leak */
  128. if (c->x86 >= 6)
  129. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  130. level = get_model_name(c);
  131. if (!level) {
  132. switch (c->x86) {
  133. case 0xf:
  134. /* Should distinguish Models here, but this is only
  135. a fallback anyways. */
  136. strcpy(c->x86_model_id, "Hammer");
  137. break;
  138. }
  139. }
  140. display_cacheinfo(c);
  141. /* Multi core CPU? */
  142. if (c->extended_cpuid_level >= 0x80000008)
  143. amd_detect_cmp(c);
  144. if (c->extended_cpuid_level >= 0x80000006 &&
  145. (cpuid_edx(0x80000006) & 0xf000))
  146. num_cache_leaves = 4;
  147. else
  148. num_cache_leaves = 3;
  149. if (c->x86 >= 0xf && c->x86 <= 0x11)
  150. set_cpu_cap(c, X86_FEATURE_K8);
  151. /* MFENCE stops RDTSC speculation */
  152. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  153. if (c->x86 == 0x10) {
  154. /* do this for boot cpu */
  155. if (c == &boot_cpu_data)
  156. check_enable_amd_mmconf_dmi();
  157. fam10h_check_enable_mmcfg();
  158. }
  159. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  160. unsigned long long tseg;
  161. /*
  162. * Split up direct mapping around the TSEG SMM area.
  163. * Don't do it for gbpages because there seems very little
  164. * benefit in doing so.
  165. */
  166. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg)) {
  167. printk(KERN_DEBUG "tseg: %010llx\n", tseg);
  168. if ((tseg>>PMD_SHIFT) <
  169. (max_low_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) ||
  170. ((tseg>>PMD_SHIFT) <
  171. (max_pfn_mapped>>(PMD_SHIFT-PAGE_SHIFT)) &&
  172. (tseg>>PMD_SHIFT) >= (1ULL<<(32 - PMD_SHIFT))))
  173. set_memory_4k((unsigned long)__va(tseg), 1);
  174. }
  175. }
  176. }
  177. static struct cpu_dev amd_cpu_dev __cpuinitdata = {
  178. .c_vendor = "AMD",
  179. .c_ident = { "AuthenticAMD" },
  180. .c_early_init = early_init_amd,
  181. .c_init = init_amd,
  182. };
  183. cpu_vendor_dev_register(X86_VENDOR_AMD, &amd_cpu_dev);