intel.c 10 KB

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