amd_64.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. extern int __cpuinit get_model_name(struct cpuinfo_x86 *c);
  8. extern void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c);
  9. int force_mwait __cpuinitdata;
  10. #ifdef CONFIG_NUMA
  11. static int __cpuinit nearby_node(int apicid)
  12. {
  13. int i, node;
  14. for (i = apicid - 1; i >= 0; i--) {
  15. node = apicid_to_node[i];
  16. if (node != NUMA_NO_NODE && node_online(node))
  17. return node;
  18. }
  19. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  20. node = apicid_to_node[i];
  21. if (node != NUMA_NO_NODE && node_online(node))
  22. return node;
  23. }
  24. return first_node(node_online_map); /* Shouldn't happen */
  25. }
  26. #endif
  27. /*
  28. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  29. * Assumes number of cores is a power of two.
  30. */
  31. static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
  32. {
  33. #ifdef CONFIG_SMP
  34. unsigned bits;
  35. #ifdef CONFIG_NUMA
  36. int cpu = smp_processor_id();
  37. int node = 0;
  38. unsigned apicid = hard_smp_processor_id();
  39. #endif
  40. bits = c->x86_coreid_bits;
  41. /* Low order bits define the core id (index of core in socket) */
  42. c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
  43. /* Convert the initial APIC ID into the socket ID */
  44. c->phys_proc_id = c->initial_apicid >> bits;
  45. #ifdef CONFIG_NUMA
  46. node = c->phys_proc_id;
  47. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  48. node = apicid_to_node[apicid];
  49. if (!node_online(node)) {
  50. /* Two possibilities here:
  51. - The CPU is missing memory and no node was created.
  52. In that case try picking one from a nearby CPU
  53. - The APIC IDs differ from the HyperTransport node IDs
  54. which the K8 northbridge parsing fills in.
  55. Assume they are all increased by a constant offset,
  56. but in the same order as the HT nodeids.
  57. If that doesn't result in a usable node fall back to the
  58. path for the previous case. */
  59. int ht_nodeid = c->initial_apicid;
  60. if (ht_nodeid >= 0 &&
  61. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  62. node = apicid_to_node[ht_nodeid];
  63. /* Pick a nearby node */
  64. if (!node_online(node))
  65. node = nearby_node(apicid);
  66. }
  67. numa_set_node(cpu, node);
  68. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  69. #endif
  70. #endif
  71. }
  72. static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
  73. {
  74. #ifdef CONFIG_SMP
  75. unsigned bits, ecx;
  76. /* Multi core CPU? */
  77. if (c->extended_cpuid_level < 0x80000008)
  78. return;
  79. ecx = cpuid_ecx(0x80000008);
  80. c->x86_max_cores = (ecx & 0xff) + 1;
  81. /* CPU telling us the core id bits shift? */
  82. bits = (ecx >> 12) & 0xF;
  83. /* Otherwise recompute */
  84. if (bits == 0) {
  85. while ((1 << bits) < c->x86_max_cores)
  86. bits++;
  87. }
  88. c->x86_coreid_bits = bits;
  89. #endif
  90. }
  91. void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  92. {
  93. early_init_amd_mc(c);
  94. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  95. if (c->x86_power & (1<<8))
  96. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  97. }
  98. 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 == 15) {
  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. level = cpuid_eax(1);
  121. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
  122. level >= 0x0f58))
  123. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  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 15:
  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 == 0x10 || 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. fam10h_check_enable_mmcfg();
  154. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  155. unsigned long long tseg;
  156. /*
  157. * Split up direct mapping around the TSEG SMM area.
  158. * Don't do it for gbpages because there seems very little
  159. * benefit in doing so.
  160. */
  161. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
  162. (tseg >> PMD_SHIFT) <
  163. (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
  164. set_memory_4k((unsigned long)__va(tseg), 1);
  165. }
  166. }