intel_64.c 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/string.h>
  4. #include <linux/bitops.h>
  5. #include <linux/smp.h>
  6. #include <linux/thread_info.h>
  7. #include <linux/module.h>
  8. #include <asm/processor.h>
  9. #include <asm/pgtable.h>
  10. #include <asm/msr.h>
  11. #include <asm/uaccess.h>
  12. #include <asm/ptrace.h>
  13. #include <asm/ds.h>
  14. #include <asm/bugs.h>
  15. #ifdef CONFIG_X86_64
  16. #include <asm/topology.h>
  17. #include <asm/numa_64.h>
  18. #endif
  19. #include "cpu.h"
  20. #ifdef CONFIG_X86_LOCAL_APIC
  21. #include <asm/mpspec.h>
  22. #include <asm/apic.h>
  23. #include <mach_apic.h>
  24. #endif
  25. static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
  26. {
  27. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  28. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  29. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  30. #ifdef CONFIG_X86_64
  31. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  32. #else
  33. /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
  34. if (c->x86 == 15 && c->x86_cache_alignment == 64)
  35. c->x86_cache_alignment = 128;
  36. #endif
  37. }
  38. #ifdef CONFIG_X86_32
  39. /*
  40. * Early probe support logic for ppro memory erratum #50
  41. *
  42. * This is called before we do cpu ident work
  43. */
  44. int __cpuinit ppro_with_ram_bug(void)
  45. {
  46. /* Uses data from early_cpu_detect now */
  47. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  48. boot_cpu_data.x86 == 6 &&
  49. boot_cpu_data.x86_model == 1 &&
  50. boot_cpu_data.x86_mask < 8) {
  51. printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
  52. return 1;
  53. }
  54. return 0;
  55. }
  56. /*
  57. * P4 Xeon errata 037 workaround.
  58. * Hardware prefetcher may cause stale data to be loaded into the cache.
  59. */
  60. static void __cpuinit Intel_errata_workarounds(struct cpuinfo_x86 *c)
  61. {
  62. unsigned long lo, hi;
  63. if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
  64. rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
  65. if ((lo & (1<<9)) == 0) {
  66. printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
  67. printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
  68. lo |= (1<<9); /* Disable hw prefetching */
  69. wrmsr (MSR_IA32_MISC_ENABLE, lo, hi);
  70. }
  71. }
  72. }
  73. #ifdef CONFIG_X86_F00F_BUG
  74. static void __cpuinit trap_init_f00f_bug(void)
  75. {
  76. __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
  77. /*
  78. * Update the IDT descriptor and reload the IDT so that
  79. * it uses the read-only mapped virtual address.
  80. */
  81. idt_descr.address = fix_to_virt(FIX_F00F_IDT);
  82. load_idt(&idt_descr);
  83. }
  84. #endif
  85. #endif
  86. static void __cpuinit srat_detect_node(void)
  87. {
  88. #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
  89. unsigned node;
  90. int cpu = smp_processor_id();
  91. int apicid = hard_smp_processor_id();
  92. /* Don't do the funky fallback heuristics the AMD version employs
  93. for now. */
  94. node = apicid_to_node[apicid];
  95. if (node == NUMA_NO_NODE || !node_online(node))
  96. node = first_node(node_online_map);
  97. numa_set_node(cpu, node);
  98. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  99. #endif
  100. }
  101. /*
  102. * find out the number of processor cores on the die
  103. */
  104. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  105. {
  106. unsigned int eax, ebx, ecx, edx;
  107. if (c->cpuid_level < 4)
  108. return 1;
  109. /* Intel has a non-standard dependency on %ecx for this CPUID level. */
  110. cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
  111. if (eax & 0x1f)
  112. return ((eax >> 26) + 1);
  113. else
  114. return 1;
  115. }
  116. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  117. {
  118. unsigned int l2 = 0;
  119. char *p = NULL;
  120. early_init_intel(c);
  121. #ifdef CONFIG_X86_F00F_BUG
  122. /*
  123. * All current models of Pentium and Pentium with MMX technology CPUs
  124. * have the F0 0F bug, which lets nonprivileged users lock up the system.
  125. * Note that the workaround only should be initialized once...
  126. */
  127. c->f00f_bug = 0;
  128. if (!paravirt_enabled() && c->x86 == 5) {
  129. static int f00f_workaround_enabled;
  130. c->f00f_bug = 1;
  131. if (!f00f_workaround_enabled) {
  132. trap_init_f00f_bug();
  133. printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
  134. f00f_workaround_enabled = 1;
  135. }
  136. }
  137. #endif
  138. l2 = init_intel_cacheinfo(c);
  139. if (c->cpuid_level > 9) {
  140. unsigned eax = cpuid_eax(10);
  141. /* Check for version and the number of counters */
  142. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  143. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  144. }
  145. #ifdef CONFIG_X86_32
  146. /* SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until model 3 mask 3 */
  147. if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
  148. clear_cpu_cap(c, X86_FEATURE_SEP);
  149. /*
  150. * Names for the Pentium II/Celeron processors
  151. * detectable only by also checking the cache size.
  152. * Dixon is NOT a Celeron.
  153. */
  154. if (c->x86 == 6) {
  155. switch (c->x86_model) {
  156. case 5:
  157. if (c->x86_mask == 0) {
  158. if (l2 == 0)
  159. p = "Celeron (Covington)";
  160. else if (l2 == 256)
  161. p = "Mobile Pentium II (Dixon)";
  162. }
  163. break;
  164. case 6:
  165. if (l2 == 128)
  166. p = "Celeron (Mendocino)";
  167. else if (c->x86_mask == 0 || c->x86_mask == 5)
  168. p = "Celeron-A";
  169. break;
  170. case 8:
  171. if (l2 == 128)
  172. p = "Celeron (Coppermine)";
  173. break;
  174. }
  175. }
  176. if (p)
  177. strcpy(c->x86_model_id, p);
  178. Intel_errata_workarounds(c);
  179. #ifdef CONFIG_X86_INTEL_USERCOPY
  180. /*
  181. * Set up the preferred alignment for movsl bulk memory moves
  182. */
  183. switch (c->x86) {
  184. case 4: /* 486: untested */
  185. break;
  186. case 5: /* Old Pentia: untested */
  187. break;
  188. case 6: /* PII/PIII only like movsl with 8-byte alignment */
  189. movsl_mask.mask = 7;
  190. break;
  191. case 15: /* P4 is OK down to 8-byte alignment */
  192. movsl_mask.mask = 7;
  193. break;
  194. }
  195. #endif
  196. #endif
  197. if (cpu_has_xmm2)
  198. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  199. if (cpu_has_ds) {
  200. unsigned int l1;
  201. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  202. if (!(l1 & (1<<11)))
  203. set_cpu_cap(c, X86_FEATURE_BTS);
  204. if (!(l1 & (1<<12)))
  205. set_cpu_cap(c, X86_FEATURE_PEBS);
  206. ds_init_intel(c);
  207. }
  208. #ifdef CONFIG_X86_64
  209. if (c->x86 == 15)
  210. c->x86_cache_alignment = c->x86_clflush_size * 2;
  211. if (c->x86 == 6)
  212. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  213. #else
  214. if (c->x86 == 15)
  215. set_cpu_cap(c, X86_FEATURE_P4);
  216. if (c->x86 == 6)
  217. set_cpu_cap(c, X86_FEATURE_P3);
  218. if (cpu_has_bts)
  219. ptrace_bts_init_intel(c);
  220. /*
  221. * See if we have a good local APIC by checking for buggy Pentia,
  222. * i.e. all B steppings and the C2 stepping of P54C when using their
  223. * integrated APIC (see 11AP erratum in "Pentium Processor
  224. * Specification Update").
  225. */
  226. if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
  227. (c->x86_mask < 0x6 || c->x86_mask == 0xb))
  228. set_cpu_cap(c, X86_FEATURE_11AP);
  229. #ifdef CONFIG_X86_NUMAQ
  230. numaq_tsc_disable();
  231. #endif
  232. #endif
  233. detect_extended_topology(c);
  234. if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
  235. /*
  236. * let's use the legacy cpuid vector 0x1 and 0x4 for topology
  237. * detection.
  238. */
  239. c->x86_max_cores = intel_num_cpu_cores(c);
  240. #ifdef CONFIG_X86_32
  241. detect_ht(c);
  242. #endif
  243. }
  244. /* Work around errata */
  245. srat_detect_node();
  246. }
  247. #ifdef CONFIG_X86_32
  248. static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  249. {
  250. /*
  251. * Intel PIII Tualatin. This comes in two flavours.
  252. * One has 256kb of cache, the other 512. We have no way
  253. * to determine which, so we use a boottime override
  254. * for the 512kb model, and assume 256 otherwise.
  255. */
  256. if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
  257. size = 256;
  258. return size;
  259. }
  260. #endif
  261. static struct cpu_dev intel_cpu_dev __cpuinitdata = {
  262. .c_vendor = "Intel",
  263. .c_ident = { "GenuineIntel" },
  264. #ifdef CONFIG_X86_32
  265. .c_models = {
  266. { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
  267. {
  268. [0] = "486 DX-25/33",
  269. [1] = "486 DX-50",
  270. [2] = "486 SX",
  271. [3] = "486 DX/2",
  272. [4] = "486 SL",
  273. [5] = "486 SX/2",
  274. [7] = "486 DX/2-WB",
  275. [8] = "486 DX/4",
  276. [9] = "486 DX/4-WB"
  277. }
  278. },
  279. { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
  280. {
  281. [0] = "Pentium 60/66 A-step",
  282. [1] = "Pentium 60/66",
  283. [2] = "Pentium 75 - 200",
  284. [3] = "OverDrive PODP5V83",
  285. [4] = "Pentium MMX",
  286. [7] = "Mobile Pentium 75 - 200",
  287. [8] = "Mobile Pentium MMX"
  288. }
  289. },
  290. { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
  291. {
  292. [0] = "Pentium Pro A-step",
  293. [1] = "Pentium Pro",
  294. [3] = "Pentium II (Klamath)",
  295. [4] = "Pentium II (Deschutes)",
  296. [5] = "Pentium II (Deschutes)",
  297. [6] = "Mobile Pentium II",
  298. [7] = "Pentium III (Katmai)",
  299. [8] = "Pentium III (Coppermine)",
  300. [10] = "Pentium III (Cascades)",
  301. [11] = "Pentium III (Tualatin)",
  302. }
  303. },
  304. { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
  305. {
  306. [0] = "Pentium 4 (Unknown)",
  307. [1] = "Pentium 4 (Willamette)",
  308. [2] = "Pentium 4 (Northwood)",
  309. [4] = "Pentium 4 (Foster)",
  310. [5] = "Pentium 4 (Foster)",
  311. }
  312. },
  313. },
  314. .c_size_cache = intel_size_cache,
  315. #endif
  316. .c_early_init = early_init_intel,
  317. .c_init = init_intel,
  318. .c_x86_vendor = X86_VENDOR_INTEL,
  319. };
  320. cpu_dev_register(intel_cpu_dev);