PageRenderTime 56ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/arch/x86/kernel/cpu/intel.c

https://github.com/galaxyishere/samsung-kernel-latona
C | 530 lines | 359 code | 65 blank | 106 comment | 125 complexity | cd1739952b7375213a5153d5107a8ef0 MD5 | raw file
  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/sched.h>
  7. #include <linux/thread_info.h>
  8. #include <linux/module.h>
  9. #include <linux/uaccess.h>
  10. #include <asm/processor.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/msr.h>
  13. #include <asm/bugs.h>
  14. #include <asm/cpu.h>
  15. #ifdef CONFIG_X86_64
  16. #include <linux/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. #endif
  24. static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
  25. {
  26. /* Unmask CPUID levels if masked: */
  27. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  28. u64 misc_enable;
  29. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  30. if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) {
  31. misc_enable &= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID;
  32. wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  33. c->cpuid_level = cpuid_eax(0);
  34. }
  35. }
  36. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  37. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  38. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  39. /*
  40. * Atom erratum AAE44/AAF40/AAG38/AAH41:
  41. *
  42. * A race condition between speculative fetches and invalidating
  43. * a large page. This is worked around in microcode, but we
  44. * need the microcode to have already been loaded... so if it is
  45. * not, recommend a BIOS update and disable large pages.
  46. */
  47. if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_mask <= 2) {
  48. u32 ucode, junk;
  49. wrmsr(MSR_IA32_UCODE_REV, 0, 0);
  50. sync_core();
  51. rdmsr(MSR_IA32_UCODE_REV, junk, ucode);
  52. if (ucode < 0x20e) {
  53. printk(KERN_WARNING "Atom PSE erratum detected, BIOS microcode update recommended\n");
  54. clear_cpu_cap(c, X86_FEATURE_PSE);
  55. }
  56. }
  57. #ifdef CONFIG_X86_64
  58. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  59. #else
  60. /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
  61. if (c->x86 == 15 && c->x86_cache_alignment == 64)
  62. c->x86_cache_alignment = 128;
  63. #endif
  64. /* CPUID workaround for 0F33/0F34 CPU */
  65. if (c->x86 == 0xF && c->x86_model == 0x3
  66. && (c->x86_mask == 0x3 || c->x86_mask == 0x4))
  67. c->x86_phys_bits = 36;
  68. /*
  69. * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
  70. * with P/T states and does not stop in deep C-states.
  71. *
  72. * It is also reliable across cores and sockets. (but not across
  73. * cabinets - we turn it off in that case explicitly.)
  74. */
  75. if (c->x86_power & (1 << 8)) {
  76. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  77. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  78. if (!check_tsc_unstable())
  79. sched_clock_stable = 1;
  80. }
  81. /*
  82. * There is a known erratum on Pentium III and Core Solo
  83. * and Core Duo CPUs.
  84. * " Page with PAT set to WC while associated MTRR is UC
  85. * may consolidate to UC "
  86. * Because of this erratum, it is better to stick with
  87. * setting WC in MTRR rather than using PAT on these CPUs.
  88. *
  89. * Enable PAT WC only on P4, Core 2 or later CPUs.
  90. */
  91. if (c->x86 == 6 && c->x86_model < 15)
  92. clear_cpu_cap(c, X86_FEATURE_PAT);
  93. #ifdef CONFIG_KMEMCHECK
  94. /*
  95. * P4s have a "fast strings" feature which causes single-
  96. * stepping REP instructions to only generate a #DB on
  97. * cache-line boundaries.
  98. *
  99. * Ingo Molnar reported a Pentium D (model 6) and a Xeon
  100. * (model 2) with the same problem.
  101. */
  102. if (c->x86 == 15) {
  103. u64 misc_enable;
  104. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  105. if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) {
  106. printk(KERN_INFO "kmemcheck: Disabling fast string operations\n");
  107. misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING;
  108. wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  109. }
  110. }
  111. #endif
  112. }
  113. #ifdef CONFIG_X86_32
  114. /*
  115. * Early probe support logic for ppro memory erratum #50
  116. *
  117. * This is called before we do cpu ident work
  118. */
  119. int __cpuinit ppro_with_ram_bug(void)
  120. {
  121. /* Uses data from early_cpu_detect now */
  122. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  123. boot_cpu_data.x86 == 6 &&
  124. boot_cpu_data.x86_model == 1 &&
  125. boot_cpu_data.x86_mask < 8) {
  126. printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
  127. return 1;
  128. }
  129. return 0;
  130. }
  131. #ifdef CONFIG_X86_F00F_BUG
  132. static void __cpuinit trap_init_f00f_bug(void)
  133. {
  134. __set_fixmap(FIX_F00F_IDT, __pa(&idt_table), PAGE_KERNEL_RO);
  135. /*
  136. * Update the IDT descriptor and reload the IDT so that
  137. * it uses the read-only mapped virtual address.
  138. */
  139. idt_descr.address = fix_to_virt(FIX_F00F_IDT);
  140. load_idt(&idt_descr);
  141. }
  142. #endif
  143. static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c)
  144. {
  145. #ifdef CONFIG_SMP
  146. /* calling is from identify_secondary_cpu() ? */
  147. if (c->cpu_index == boot_cpu_id)
  148. return;
  149. /*
  150. * Mask B, Pentium, but not Pentium MMX
  151. */
  152. if (c->x86 == 5 &&
  153. c->x86_mask >= 1 && c->x86_mask <= 4 &&
  154. c->x86_model <= 3) {
  155. /*
  156. * Remember we have B step Pentia with bugs
  157. */
  158. WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
  159. "with B stepping processors.\n");
  160. }
  161. #endif
  162. }
  163. static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
  164. {
  165. unsigned long lo, hi;
  166. #ifdef CONFIG_X86_F00F_BUG
  167. /*
  168. * All current models of Pentium and Pentium with MMX technology CPUs
  169. * have the F0 0F bug, which lets nonprivileged users lock up the
  170. * system.
  171. * Note that the workaround only should be initialized once...
  172. */
  173. c->f00f_bug = 0;
  174. if (!paravirt_enabled() && c->x86 == 5) {
  175. static int f00f_workaround_enabled;
  176. c->f00f_bug = 1;
  177. if (!f00f_workaround_enabled) {
  178. trap_init_f00f_bug();
  179. printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
  180. f00f_workaround_enabled = 1;
  181. }
  182. }
  183. #endif
  184. /*
  185. * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
  186. * model 3 mask 3
  187. */
  188. if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
  189. clear_cpu_cap(c, X86_FEATURE_SEP);
  190. /*
  191. * P4 Xeon errata 037 workaround.
  192. * Hardware prefetcher may cause stale data to be loaded into the cache.
  193. */
  194. if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
  195. rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
  196. if ((lo & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE) == 0) {
  197. printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
  198. printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
  199. lo |= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE;
  200. wrmsr(MSR_IA32_MISC_ENABLE, lo, hi);
  201. }
  202. }
  203. /*
  204. * See if we have a good local APIC by checking for buggy Pentia,
  205. * i.e. all B steppings and the C2 stepping of P54C when using their
  206. * integrated APIC (see 11AP erratum in "Pentium Processor
  207. * Specification Update").
  208. */
  209. if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
  210. (c->x86_mask < 0x6 || c->x86_mask == 0xb))
  211. set_cpu_cap(c, X86_FEATURE_11AP);
  212. #ifdef CONFIG_X86_INTEL_USERCOPY
  213. /*
  214. * Set up the preferred alignment for movsl bulk memory moves
  215. */
  216. switch (c->x86) {
  217. case 4: /* 486: untested */
  218. break;
  219. case 5: /* Old Pentia: untested */
  220. break;
  221. case 6: /* PII/PIII only like movsl with 8-byte alignment */
  222. movsl_mask.mask = 7;
  223. break;
  224. case 15: /* P4 is OK down to 8-byte alignment */
  225. movsl_mask.mask = 7;
  226. break;
  227. }
  228. #endif
  229. #ifdef CONFIG_X86_NUMAQ
  230. numaq_tsc_disable();
  231. #endif
  232. intel_smp_check(c);
  233. }
  234. #else
  235. static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
  236. {
  237. }
  238. #endif
  239. static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c)
  240. {
  241. #if defined(CONFIG_NUMA) && defined(CONFIG_X86_64)
  242. unsigned node;
  243. int cpu = smp_processor_id();
  244. int apicid = cpu_has_apic ? hard_smp_processor_id() : c->apicid;
  245. /* Don't do the funky fallback heuristics the AMD version employs
  246. for now. */
  247. node = apicid_to_node[apicid];
  248. if (node == NUMA_NO_NODE)
  249. node = first_node(node_online_map);
  250. else if (!node_online(node)) {
  251. /* reuse the value from init_cpu_to_node() */
  252. node = cpu_to_node(cpu);
  253. }
  254. numa_set_node(cpu, node);
  255. #endif
  256. }
  257. /*
  258. * find out the number of processor cores on the die
  259. */
  260. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  261. {
  262. unsigned int eax, ebx, ecx, edx;
  263. if (c->cpuid_level < 4)
  264. return 1;
  265. /* Intel has a non-standard dependency on %ecx for this CPUID level. */
  266. cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
  267. if (eax & 0x1f)
  268. return (eax >> 26) + 1;
  269. else
  270. return 1;
  271. }
  272. static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
  273. {
  274. /* Intel VMX MSR indicated features */
  275. #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
  276. #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
  277. #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
  278. #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
  279. #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
  280. #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
  281. u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
  282. clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  283. clear_cpu_cap(c, X86_FEATURE_VNMI);
  284. clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  285. clear_cpu_cap(c, X86_FEATURE_EPT);
  286. clear_cpu_cap(c, X86_FEATURE_VPID);
  287. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
  288. msr_ctl = vmx_msr_high | vmx_msr_low;
  289. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
  290. set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  291. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
  292. set_cpu_cap(c, X86_FEATURE_VNMI);
  293. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
  294. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
  295. vmx_msr_low, vmx_msr_high);
  296. msr_ctl2 = vmx_msr_high | vmx_msr_low;
  297. if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
  298. (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
  299. set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  300. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
  301. set_cpu_cap(c, X86_FEATURE_EPT);
  302. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
  303. set_cpu_cap(c, X86_FEATURE_VPID);
  304. }
  305. }
  306. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  307. {
  308. unsigned int l2 = 0;
  309. early_init_intel(c);
  310. intel_workarounds(c);
  311. /*
  312. * Detect the extended topology information if available. This
  313. * will reinitialise the initial_apicid which will be used
  314. * in init_intel_cacheinfo()
  315. */
  316. detect_extended_topology(c);
  317. l2 = init_intel_cacheinfo(c);
  318. if (c->cpuid_level > 9) {
  319. unsigned eax = cpuid_eax(10);
  320. /* Check for version and the number of counters */
  321. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  322. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  323. }
  324. if (cpu_has_xmm2)
  325. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  326. if (cpu_has_ds) {
  327. unsigned int l1;
  328. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  329. if (!(l1 & (1<<11)))
  330. set_cpu_cap(c, X86_FEATURE_BTS);
  331. if (!(l1 & (1<<12)))
  332. set_cpu_cap(c, X86_FEATURE_PEBS);
  333. }
  334. if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush)
  335. set_cpu_cap(c, X86_FEATURE_CLFLUSH_MONITOR);
  336. #ifdef CONFIG_X86_64
  337. if (c->x86 == 15)
  338. c->x86_cache_alignment = c->x86_clflush_size * 2;
  339. if (c->x86 == 6)
  340. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  341. #else
  342. /*
  343. * Names for the Pentium II/Celeron processors
  344. * detectable only by also checking the cache size.
  345. * Dixon is NOT a Celeron.
  346. */
  347. if (c->x86 == 6) {
  348. char *p = NULL;
  349. switch (c->x86_model) {
  350. case 5:
  351. if (c->x86_mask == 0) {
  352. if (l2 == 0)
  353. p = "Celeron (Covington)";
  354. else if (l2 == 256)
  355. p = "Mobile Pentium II (Dixon)";
  356. }
  357. break;
  358. case 6:
  359. if (l2 == 128)
  360. p = "Celeron (Mendocino)";
  361. else if (c->x86_mask == 0 || c->x86_mask == 5)
  362. p = "Celeron-A";
  363. break;
  364. case 8:
  365. if (l2 == 128)
  366. p = "Celeron (Coppermine)";
  367. break;
  368. }
  369. if (p)
  370. strcpy(c->x86_model_id, p);
  371. }
  372. if (c->x86 == 15)
  373. set_cpu_cap(c, X86_FEATURE_P4);
  374. if (c->x86 == 6)
  375. set_cpu_cap(c, X86_FEATURE_P3);
  376. #endif
  377. if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
  378. /*
  379. * let's use the legacy cpuid vector 0x1 and 0x4 for topology
  380. * detection.
  381. */
  382. c->x86_max_cores = intel_num_cpu_cores(c);
  383. #ifdef CONFIG_X86_32
  384. detect_ht(c);
  385. #endif
  386. }
  387. /* Work around errata */
  388. srat_detect_node(c);
  389. if (cpu_has(c, X86_FEATURE_VMX))
  390. detect_vmx_virtcap(c);
  391. }
  392. #ifdef CONFIG_X86_32
  393. static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  394. {
  395. /*
  396. * Intel PIII Tualatin. This comes in two flavours.
  397. * One has 256kb of cache, the other 512. We have no way
  398. * to determine which, so we use a boottime override
  399. * for the 512kb model, and assume 256 otherwise.
  400. */
  401. if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
  402. size = 256;
  403. return size;
  404. }
  405. #endif
  406. static const struct cpu_dev __cpuinitconst intel_cpu_dev = {
  407. .c_vendor = "Intel",
  408. .c_ident = { "GenuineIntel" },
  409. #ifdef CONFIG_X86_32
  410. .c_models = {
  411. { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
  412. {
  413. [0] = "486 DX-25/33",
  414. [1] = "486 DX-50",
  415. [2] = "486 SX",
  416. [3] = "486 DX/2",
  417. [4] = "486 SL",
  418. [5] = "486 SX/2",
  419. [7] = "486 DX/2-WB",
  420. [8] = "486 DX/4",
  421. [9] = "486 DX/4-WB"
  422. }
  423. },
  424. { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
  425. {
  426. [0] = "Pentium 60/66 A-step",
  427. [1] = "Pentium 60/66",
  428. [2] = "Pentium 75 - 200",
  429. [3] = "OverDrive PODP5V83",
  430. [4] = "Pentium MMX",
  431. [7] = "Mobile Pentium 75 - 200",
  432. [8] = "Mobile Pentium MMX"
  433. }
  434. },
  435. { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
  436. {
  437. [0] = "Pentium Pro A-step",
  438. [1] = "Pentium Pro",
  439. [3] = "Pentium II (Klamath)",
  440. [4] = "Pentium II (Deschutes)",
  441. [5] = "Pentium II (Deschutes)",
  442. [6] = "Mobile Pentium II",
  443. [7] = "Pentium III (Katmai)",
  444. [8] = "Pentium III (Coppermine)",
  445. [10] = "Pentium III (Cascades)",
  446. [11] = "Pentium III (Tualatin)",
  447. }
  448. },
  449. { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
  450. {
  451. [0] = "Pentium 4 (Unknown)",
  452. [1] = "Pentium 4 (Willamette)",
  453. [2] = "Pentium 4 (Northwood)",
  454. [4] = "Pentium 4 (Foster)",
  455. [5] = "Pentium 4 (Foster)",
  456. }
  457. },
  458. },
  459. .c_size_cache = intel_size_cache,
  460. #endif
  461. .c_early_init = early_init_intel,
  462. .c_init = init_intel,
  463. .c_x86_vendor = X86_VENDOR_INTEL,
  464. };
  465. cpu_dev_register(intel_cpu_dev);