intel.c 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865
  1. #include <linux/kernel.h>
  2. #include <linux/string.h>
  3. #include <linux/bitops.h>
  4. #include <linux/smp.h>
  5. #include <linux/sched.h>
  6. #include <linux/sched/clock.h>
  7. #include <linux/thread_info.h>
  8. #include <linux/init.h>
  9. #include <linux/uaccess.h>
  10. #include <asm/cpufeature.h>
  11. #include <asm/pgtable.h>
  12. #include <asm/msr.h>
  13. #include <asm/bugs.h>
  14. #include <asm/cpu.h>
  15. #include <asm/intel-family.h>
  16. #include <asm/microcode_intel.h>
  17. #include <asm/hwcap2.h>
  18. #include <asm/elf.h>
  19. #ifdef CONFIG_X86_64
  20. #include <linux/topology.h>
  21. #endif
  22. #include "cpu.h"
  23. #ifdef CONFIG_X86_LOCAL_APIC
  24. #include <asm/mpspec.h>
  25. #include <asm/apic.h>
  26. #endif
  27. /*
  28. * Just in case our CPU detection goes bad, or you have a weird system,
  29. * allow a way to override the automatic disabling of MPX.
  30. */
  31. static int forcempx;
  32. static int __init forcempx_setup(char *__unused)
  33. {
  34. forcempx = 1;
  35. return 1;
  36. }
  37. __setup("intel-skd-046-workaround=disable", forcempx_setup);
  38. void check_mpx_erratum(struct cpuinfo_x86 *c)
  39. {
  40. if (forcempx)
  41. return;
  42. /*
  43. * Turn off the MPX feature on CPUs where SMEP is not
  44. * available or disabled.
  45. *
  46. * Works around Intel Erratum SKD046: "Branch Instructions
  47. * May Initialize MPX Bound Registers Incorrectly".
  48. *
  49. * This might falsely disable MPX on systems without
  50. * SMEP, like Atom processors without SMEP. But there
  51. * is no such hardware known at the moment.
  52. */
  53. if (cpu_has(c, X86_FEATURE_MPX) && !cpu_has(c, X86_FEATURE_SMEP)) {
  54. setup_clear_cpu_cap(X86_FEATURE_MPX);
  55. pr_warn("x86/mpx: Disabling MPX since SMEP not present\n");
  56. }
  57. }
  58. static bool ring3mwait_disabled __read_mostly;
  59. static int __init ring3mwait_disable(char *__unused)
  60. {
  61. ring3mwait_disabled = true;
  62. return 0;
  63. }
  64. __setup("ring3mwait=disable", ring3mwait_disable);
  65. static void probe_xeon_phi_r3mwait(struct cpuinfo_x86 *c)
  66. {
  67. /*
  68. * Ring 3 MONITOR/MWAIT feature cannot be detected without
  69. * cpu model and family comparison.
  70. */
  71. if (c->x86 != 6)
  72. return;
  73. switch (c->x86_model) {
  74. case INTEL_FAM6_XEON_PHI_KNL:
  75. case INTEL_FAM6_XEON_PHI_KNM:
  76. break;
  77. default:
  78. return;
  79. }
  80. if (ring3mwait_disabled) {
  81. msr_clear_bit(MSR_MISC_FEATURE_ENABLES,
  82. MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT);
  83. return;
  84. }
  85. msr_set_bit(MSR_MISC_FEATURE_ENABLES,
  86. MSR_MISC_FEATURE_ENABLES_RING3MWAIT_BIT);
  87. set_cpu_cap(c, X86_FEATURE_RING3MWAIT);
  88. if (c == &boot_cpu_data)
  89. ELF_HWCAP2 |= HWCAP2_RING3MWAIT;
  90. }
  91. static void early_init_intel(struct cpuinfo_x86 *c)
  92. {
  93. u64 misc_enable;
  94. /* Unmask CPUID levels if masked: */
  95. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  96. if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
  97. MSR_IA32_MISC_ENABLE_LIMIT_CPUID_BIT) > 0) {
  98. c->cpuid_level = cpuid_eax(0);
  99. get_cpu_cap(c);
  100. }
  101. }
  102. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  103. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  104. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  105. if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64))
  106. c->microcode = intel_get_microcode_revision();
  107. /*
  108. * Atom erratum AAE44/AAF40/AAG38/AAH41:
  109. *
  110. * A race condition between speculative fetches and invalidating
  111. * a large page. This is worked around in microcode, but we
  112. * need the microcode to have already been loaded... so if it is
  113. * not, recommend a BIOS update and disable large pages.
  114. */
  115. if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_mask <= 2 &&
  116. c->microcode < 0x20e) {
  117. pr_warn("Atom PSE erratum detected, BIOS microcode update recommended\n");
  118. clear_cpu_cap(c, X86_FEATURE_PSE);
  119. }
  120. #ifdef CONFIG_X86_64
  121. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  122. #else
  123. /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
  124. if (c->x86 == 15 && c->x86_cache_alignment == 64)
  125. c->x86_cache_alignment = 128;
  126. #endif
  127. /* CPUID workaround for 0F33/0F34 CPU */
  128. if (c->x86 == 0xF && c->x86_model == 0x3
  129. && (c->x86_mask == 0x3 || c->x86_mask == 0x4))
  130. c->x86_phys_bits = 36;
  131. /*
  132. * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
  133. * with P/T states and does not stop in deep C-states.
  134. *
  135. * It is also reliable across cores and sockets. (but not across
  136. * cabinets - we turn it off in that case explicitly.)
  137. */
  138. if (c->x86_power & (1 << 8)) {
  139. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  140. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  141. }
  142. /* Penwell and Cloverview have the TSC which doesn't sleep on S3 */
  143. if (c->x86 == 6) {
  144. switch (c->x86_model) {
  145. case 0x27: /* Penwell */
  146. case 0x35: /* Cloverview */
  147. case 0x4a: /* Merrifield */
  148. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC_S3);
  149. break;
  150. default:
  151. break;
  152. }
  153. }
  154. /*
  155. * There is a known erratum on Pentium III and Core Solo
  156. * and Core Duo CPUs.
  157. * " Page with PAT set to WC while associated MTRR is UC
  158. * may consolidate to UC "
  159. * Because of this erratum, it is better to stick with
  160. * setting WC in MTRR rather than using PAT on these CPUs.
  161. *
  162. * Enable PAT WC only on P4, Core 2 or later CPUs.
  163. */
  164. if (c->x86 == 6 && c->x86_model < 15)
  165. clear_cpu_cap(c, X86_FEATURE_PAT);
  166. #ifdef CONFIG_KMEMCHECK
  167. /*
  168. * P4s have a "fast strings" feature which causes single-
  169. * stepping REP instructions to only generate a #DB on
  170. * cache-line boundaries.
  171. *
  172. * Ingo Molnar reported a Pentium D (model 6) and a Xeon
  173. * (model 2) with the same problem.
  174. */
  175. if (c->x86 == 15)
  176. if (msr_clear_bit(MSR_IA32_MISC_ENABLE,
  177. MSR_IA32_MISC_ENABLE_FAST_STRING_BIT) > 0)
  178. pr_info("kmemcheck: Disabling fast string operations\n");
  179. #endif
  180. /*
  181. * If fast string is not enabled in IA32_MISC_ENABLE for any reason,
  182. * clear the fast string and enhanced fast string CPU capabilities.
  183. */
  184. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  185. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  186. if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
  187. pr_info("Disabled fast string operations\n");
  188. setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
  189. setup_clear_cpu_cap(X86_FEATURE_ERMS);
  190. }
  191. }
  192. /*
  193. * Intel Quark Core DevMan_001.pdf section 6.4.11
  194. * "The operating system also is required to invalidate (i.e., flush)
  195. * the TLB when any changes are made to any of the page table entries.
  196. * The operating system must reload CR3 to cause the TLB to be flushed"
  197. *
  198. * As a result, boot_cpu_has(X86_FEATURE_PGE) in arch/x86/include/asm/tlbflush.h
  199. * should be false so that __flush_tlb_all() causes CR3 insted of CR4.PGE
  200. * to be modified.
  201. */
  202. if (c->x86 == 5 && c->x86_model == 9) {
  203. pr_info("Disabling PGE capability bit\n");
  204. setup_clear_cpu_cap(X86_FEATURE_PGE);
  205. }
  206. if (c->cpuid_level >= 0x00000001) {
  207. u32 eax, ebx, ecx, edx;
  208. cpuid(0x00000001, &eax, &ebx, &ecx, &edx);
  209. /*
  210. * If HTT (EDX[28]) is set EBX[16:23] contain the number of
  211. * apicids which are reserved per package. Store the resulting
  212. * shift value for the package management code.
  213. */
  214. if (edx & (1U << 28))
  215. c->x86_coreid_bits = get_count_order((ebx >> 16) & 0xff);
  216. }
  217. check_mpx_erratum(c);
  218. }
  219. #ifdef CONFIG_X86_32
  220. /*
  221. * Early probe support logic for ppro memory erratum #50
  222. *
  223. * This is called before we do cpu ident work
  224. */
  225. int ppro_with_ram_bug(void)
  226. {
  227. /* Uses data from early_cpu_detect now */
  228. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  229. boot_cpu_data.x86 == 6 &&
  230. boot_cpu_data.x86_model == 1 &&
  231. boot_cpu_data.x86_mask < 8) {
  232. pr_info("Pentium Pro with Errata#50 detected. Taking evasive action.\n");
  233. return 1;
  234. }
  235. return 0;
  236. }
  237. static void intel_smp_check(struct cpuinfo_x86 *c)
  238. {
  239. /* calling is from identify_secondary_cpu() ? */
  240. if (!c->cpu_index)
  241. return;
  242. /*
  243. * Mask B, Pentium, but not Pentium MMX
  244. */
  245. if (c->x86 == 5 &&
  246. c->x86_mask >= 1 && c->x86_mask <= 4 &&
  247. c->x86_model <= 3) {
  248. /*
  249. * Remember we have B step Pentia with bugs
  250. */
  251. WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
  252. "with B stepping processors.\n");
  253. }
  254. }
  255. static int forcepae;
  256. static int __init forcepae_setup(char *__unused)
  257. {
  258. forcepae = 1;
  259. return 1;
  260. }
  261. __setup("forcepae", forcepae_setup);
  262. static void intel_workarounds(struct cpuinfo_x86 *c)
  263. {
  264. #ifdef CONFIG_X86_F00F_BUG
  265. /*
  266. * All models of Pentium and Pentium with MMX technology CPUs
  267. * have the F0 0F bug, which lets nonprivileged users lock up the
  268. * system. Announce that the fault handler will be checking for it.
  269. * The Quark is also family 5, but does not have the same bug.
  270. */
  271. clear_cpu_bug(c, X86_BUG_F00F);
  272. if (c->x86 == 5 && c->x86_model < 9) {
  273. static int f00f_workaround_enabled;
  274. set_cpu_bug(c, X86_BUG_F00F);
  275. if (!f00f_workaround_enabled) {
  276. pr_notice("Intel Pentium with F0 0F bug - workaround enabled.\n");
  277. f00f_workaround_enabled = 1;
  278. }
  279. }
  280. #endif
  281. /*
  282. * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
  283. * model 3 mask 3
  284. */
  285. if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
  286. clear_cpu_cap(c, X86_FEATURE_SEP);
  287. /*
  288. * PAE CPUID issue: many Pentium M report no PAE but may have a
  289. * functionally usable PAE implementation.
  290. * Forcefully enable PAE if kernel parameter "forcepae" is present.
  291. */
  292. if (forcepae) {
  293. pr_warn("PAE forced!\n");
  294. set_cpu_cap(c, X86_FEATURE_PAE);
  295. add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_NOW_UNRELIABLE);
  296. }
  297. /*
  298. * P4 Xeon erratum 037 workaround.
  299. * Hardware prefetcher may cause stale data to be loaded into the cache.
  300. */
  301. if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
  302. if (msr_set_bit(MSR_IA32_MISC_ENABLE,
  303. MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE_BIT) > 0) {
  304. pr_info("CPU: C0 stepping P4 Xeon detected.\n");
  305. pr_info("CPU: Disabling hardware prefetching (Erratum 037)\n");
  306. }
  307. }
  308. /*
  309. * See if we have a good local APIC by checking for buggy Pentia,
  310. * i.e. all B steppings and the C2 stepping of P54C when using their
  311. * integrated APIC (see 11AP erratum in "Pentium Processor
  312. * Specification Update").
  313. */
  314. if (boot_cpu_has(X86_FEATURE_APIC) && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
  315. (c->x86_mask < 0x6 || c->x86_mask == 0xb))
  316. set_cpu_bug(c, X86_BUG_11AP);
  317. #ifdef CONFIG_X86_INTEL_USERCOPY
  318. /*
  319. * Set up the preferred alignment for movsl bulk memory moves
  320. */
  321. switch (c->x86) {
  322. case 4: /* 486: untested */
  323. break;
  324. case 5: /* Old Pentia: untested */
  325. break;
  326. case 6: /* PII/PIII only like movsl with 8-byte alignment */
  327. movsl_mask.mask = 7;
  328. break;
  329. case 15: /* P4 is OK down to 8-byte alignment */
  330. movsl_mask.mask = 7;
  331. break;
  332. }
  333. #endif
  334. intel_smp_check(c);
  335. }
  336. #else
  337. static void intel_workarounds(struct cpuinfo_x86 *c)
  338. {
  339. }
  340. #endif
  341. static void srat_detect_node(struct cpuinfo_x86 *c)
  342. {
  343. #ifdef CONFIG_NUMA
  344. unsigned node;
  345. int cpu = smp_processor_id();
  346. /* Don't do the funky fallback heuristics the AMD version employs
  347. for now. */
  348. node = numa_cpu_node(cpu);
  349. if (node == NUMA_NO_NODE || !node_online(node)) {
  350. /* reuse the value from init_cpu_to_node() */
  351. node = cpu_to_node(cpu);
  352. }
  353. numa_set_node(cpu, node);
  354. #endif
  355. }
  356. /*
  357. * find out the number of processor cores on the die
  358. */
  359. static int intel_num_cpu_cores(struct cpuinfo_x86 *c)
  360. {
  361. unsigned int eax, ebx, ecx, edx;
  362. if (!IS_ENABLED(CONFIG_SMP) || c->cpuid_level < 4)
  363. return 1;
  364. /* Intel has a non-standard dependency on %ecx for this CPUID level. */
  365. cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
  366. if (eax & 0x1f)
  367. return (eax >> 26) + 1;
  368. else
  369. return 1;
  370. }
  371. static void detect_vmx_virtcap(struct cpuinfo_x86 *c)
  372. {
  373. /* Intel VMX MSR indicated features */
  374. #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
  375. #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
  376. #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
  377. #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
  378. #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
  379. #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
  380. u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
  381. clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  382. clear_cpu_cap(c, X86_FEATURE_VNMI);
  383. clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  384. clear_cpu_cap(c, X86_FEATURE_EPT);
  385. clear_cpu_cap(c, X86_FEATURE_VPID);
  386. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
  387. msr_ctl = vmx_msr_high | vmx_msr_low;
  388. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
  389. set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  390. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
  391. set_cpu_cap(c, X86_FEATURE_VNMI);
  392. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
  393. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
  394. vmx_msr_low, vmx_msr_high);
  395. msr_ctl2 = vmx_msr_high | vmx_msr_low;
  396. if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
  397. (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
  398. set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  399. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
  400. set_cpu_cap(c, X86_FEATURE_EPT);
  401. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
  402. set_cpu_cap(c, X86_FEATURE_VPID);
  403. }
  404. }
  405. static void init_intel_energy_perf(struct cpuinfo_x86 *c)
  406. {
  407. u64 epb;
  408. /*
  409. * Initialize MSR_IA32_ENERGY_PERF_BIAS if not already initialized.
  410. * (x86_energy_perf_policy(8) is available to change it at run-time.)
  411. */
  412. if (!cpu_has(c, X86_FEATURE_EPB))
  413. return;
  414. rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  415. if ((epb & 0xF) != ENERGY_PERF_BIAS_PERFORMANCE)
  416. return;
  417. pr_warn_once("ENERGY_PERF_BIAS: Set to 'normal', was 'performance'\n");
  418. pr_warn_once("ENERGY_PERF_BIAS: View and update with x86_energy_perf_policy(8)\n");
  419. epb = (epb & ~0xF) | ENERGY_PERF_BIAS_NORMAL;
  420. wrmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  421. }
  422. static void intel_bsp_resume(struct cpuinfo_x86 *c)
  423. {
  424. /*
  425. * MSR_IA32_ENERGY_PERF_BIAS is lost across suspend/resume,
  426. * so reinitialize it properly like during bootup:
  427. */
  428. init_intel_energy_perf(c);
  429. }
  430. static void init_intel(struct cpuinfo_x86 *c)
  431. {
  432. unsigned int l2 = 0;
  433. early_init_intel(c);
  434. intel_workarounds(c);
  435. /*
  436. * Detect the extended topology information if available. This
  437. * will reinitialise the initial_apicid which will be used
  438. * in init_intel_cacheinfo()
  439. */
  440. detect_extended_topology(c);
  441. if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
  442. /*
  443. * let's use the legacy cpuid vector 0x1 and 0x4 for topology
  444. * detection.
  445. */
  446. c->x86_max_cores = intel_num_cpu_cores(c);
  447. #ifdef CONFIG_X86_32
  448. detect_ht(c);
  449. #endif
  450. }
  451. l2 = init_intel_cacheinfo(c);
  452. /* Detect legacy cache sizes if init_intel_cacheinfo did not */
  453. if (l2 == 0) {
  454. cpu_detect_cache_sizes(c);
  455. l2 = c->x86_cache_size;
  456. }
  457. if (c->cpuid_level > 9) {
  458. unsigned eax = cpuid_eax(10);
  459. /* Check for version and the number of counters */
  460. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  461. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  462. }
  463. if (cpu_has(c, X86_FEATURE_XMM2))
  464. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  465. if (boot_cpu_has(X86_FEATURE_DS)) {
  466. unsigned int l1;
  467. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  468. if (!(l1 & (1<<11)))
  469. set_cpu_cap(c, X86_FEATURE_BTS);
  470. if (!(l1 & (1<<12)))
  471. set_cpu_cap(c, X86_FEATURE_PEBS);
  472. }
  473. if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_CLFLUSH) &&
  474. (c->x86_model == 29 || c->x86_model == 46 || c->x86_model == 47))
  475. set_cpu_bug(c, X86_BUG_CLFLUSH_MONITOR);
  476. if (c->x86 == 6 && boot_cpu_has(X86_FEATURE_MWAIT) &&
  477. ((c->x86_model == INTEL_FAM6_ATOM_GOLDMONT)))
  478. set_cpu_bug(c, X86_BUG_MONITOR);
  479. #ifdef CONFIG_X86_64
  480. if (c->x86 == 15)
  481. c->x86_cache_alignment = c->x86_clflush_size * 2;
  482. if (c->x86 == 6)
  483. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  484. #else
  485. /*
  486. * Names for the Pentium II/Celeron processors
  487. * detectable only by also checking the cache size.
  488. * Dixon is NOT a Celeron.
  489. */
  490. if (c->x86 == 6) {
  491. char *p = NULL;
  492. switch (c->x86_model) {
  493. case 5:
  494. if (l2 == 0)
  495. p = "Celeron (Covington)";
  496. else if (l2 == 256)
  497. p = "Mobile Pentium II (Dixon)";
  498. break;
  499. case 6:
  500. if (l2 == 128)
  501. p = "Celeron (Mendocino)";
  502. else if (c->x86_mask == 0 || c->x86_mask == 5)
  503. p = "Celeron-A";
  504. break;
  505. case 8:
  506. if (l2 == 128)
  507. p = "Celeron (Coppermine)";
  508. break;
  509. }
  510. if (p)
  511. strcpy(c->x86_model_id, p);
  512. }
  513. if (c->x86 == 15)
  514. set_cpu_cap(c, X86_FEATURE_P4);
  515. if (c->x86 == 6)
  516. set_cpu_cap(c, X86_FEATURE_P3);
  517. #endif
  518. /* Work around errata */
  519. srat_detect_node(c);
  520. if (cpu_has(c, X86_FEATURE_VMX))
  521. detect_vmx_virtcap(c);
  522. init_intel_energy_perf(c);
  523. probe_xeon_phi_r3mwait(c);
  524. }
  525. #ifdef CONFIG_X86_32
  526. static unsigned int intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  527. {
  528. /*
  529. * Intel PIII Tualatin. This comes in two flavours.
  530. * One has 256kb of cache, the other 512. We have no way
  531. * to determine which, so we use a boottime override
  532. * for the 512kb model, and assume 256 otherwise.
  533. */
  534. if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
  535. size = 256;
  536. /*
  537. * Intel Quark SoC X1000 contains a 4-way set associative
  538. * 16K cache with a 16 byte cache line and 256 lines per tag
  539. */
  540. if ((c->x86 == 5) && (c->x86_model == 9))
  541. size = 16;
  542. return size;
  543. }
  544. #endif
  545. #define TLB_INST_4K 0x01
  546. #define TLB_INST_4M 0x02
  547. #define TLB_INST_2M_4M 0x03
  548. #define TLB_INST_ALL 0x05
  549. #define TLB_INST_1G 0x06
  550. #define TLB_DATA_4K 0x11
  551. #define TLB_DATA_4M 0x12
  552. #define TLB_DATA_2M_4M 0x13
  553. #define TLB_DATA_4K_4M 0x14
  554. #define TLB_DATA_1G 0x16
  555. #define TLB_DATA0_4K 0x21
  556. #define TLB_DATA0_4M 0x22
  557. #define TLB_DATA0_2M_4M 0x23
  558. #define STLB_4K 0x41
  559. #define STLB_4K_2M 0x42
  560. static const struct _tlb_table intel_tlb_table[] = {
  561. { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative" },
  562. { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" },
  563. { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative" },
  564. { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative" },
  565. { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative" },
  566. { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative" },
  567. { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages */" },
  568. { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  569. { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  570. { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  571. { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
  572. { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associative" },
  573. { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" },
  574. { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" },
  575. { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way set associative" },
  576. { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" },
  577. { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" },
  578. { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" },
  579. { 0x61, TLB_INST_4K, 48, " TLB_INST 4 KByte pages, full associative" },
  580. { 0x63, TLB_DATA_1G, 4, " TLB_DATA 1 GByte pages, 4-way set associative" },
  581. { 0x76, TLB_INST_2M_4M, 8, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
  582. { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associative" },
  583. { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M pages, 4-way entries" },
  584. { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative" },
  585. { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associative" },
  586. { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" },
  587. { 0xb5, TLB_INST_4K, 64, " TLB_INST 4 KByte pages, 8-way set associative" },
  588. { 0xb6, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 8-way set associative" },
  589. { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" },
  590. { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way associative" },
  591. { 0xc1, STLB_4K_2M, 1024, " STLB 4 KByte and 2 MByte pages, 8-way associative" },
  592. { 0xc2, TLB_DATA_2M_4M, 16, " DTLB 2 MByte/4MByte pages, 4-way associative" },
  593. { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" },
  594. { 0x00, 0, 0 }
  595. };
  596. static void intel_tlb_lookup(const unsigned char desc)
  597. {
  598. unsigned char k;
  599. if (desc == 0)
  600. return;
  601. /* look up this descriptor in the table */
  602. for (k = 0; intel_tlb_table[k].descriptor != desc && \
  603. intel_tlb_table[k].descriptor != 0; k++)
  604. ;
  605. if (intel_tlb_table[k].tlb_type == 0)
  606. return;
  607. switch (intel_tlb_table[k].tlb_type) {
  608. case STLB_4K:
  609. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  610. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  611. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  612. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  613. break;
  614. case STLB_4K_2M:
  615. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  616. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  617. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  618. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  619. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  620. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  621. if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
  622. tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
  623. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  624. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  625. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  626. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  627. break;
  628. case TLB_INST_ALL:
  629. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  630. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  631. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  632. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  633. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  634. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  635. break;
  636. case TLB_INST_4K:
  637. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  638. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  639. break;
  640. case TLB_INST_4M:
  641. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  642. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  643. break;
  644. case TLB_INST_2M_4M:
  645. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  646. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  647. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  648. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  649. break;
  650. case TLB_DATA_4K:
  651. case TLB_DATA0_4K:
  652. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  653. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  654. break;
  655. case TLB_DATA_4M:
  656. case TLB_DATA0_4M:
  657. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  658. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  659. break;
  660. case TLB_DATA_2M_4M:
  661. case TLB_DATA0_2M_4M:
  662. if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
  663. tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
  664. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  665. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  666. break;
  667. case TLB_DATA_4K_4M:
  668. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  669. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  670. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  671. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  672. break;
  673. case TLB_DATA_1G:
  674. if (tlb_lld_1g[ENTRIES] < intel_tlb_table[k].entries)
  675. tlb_lld_1g[ENTRIES] = intel_tlb_table[k].entries;
  676. break;
  677. }
  678. }
  679. static void intel_detect_tlb(struct cpuinfo_x86 *c)
  680. {
  681. int i, j, n;
  682. unsigned int regs[4];
  683. unsigned char *desc = (unsigned char *)regs;
  684. if (c->cpuid_level < 2)
  685. return;
  686. /* Number of times to iterate */
  687. n = cpuid_eax(2) & 0xFF;
  688. for (i = 0 ; i < n ; i++) {
  689. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  690. /* If bit 31 is set, this is an unknown format */
  691. for (j = 0 ; j < 3 ; j++)
  692. if (regs[j] & (1 << 31))
  693. regs[j] = 0;
  694. /* Byte 0 is level count, not a descriptor */
  695. for (j = 1 ; j < 16 ; j++)
  696. intel_tlb_lookup(desc[j]);
  697. }
  698. }
  699. static const struct cpu_dev intel_cpu_dev = {
  700. .c_vendor = "Intel",
  701. .c_ident = { "GenuineIntel" },
  702. #ifdef CONFIG_X86_32
  703. .legacy_models = {
  704. { .family = 4, .model_names =
  705. {
  706. [0] = "486 DX-25/33",
  707. [1] = "486 DX-50",
  708. [2] = "486 SX",
  709. [3] = "486 DX/2",
  710. [4] = "486 SL",
  711. [5] = "486 SX/2",
  712. [7] = "486 DX/2-WB",
  713. [8] = "486 DX/4",
  714. [9] = "486 DX/4-WB"
  715. }
  716. },
  717. { .family = 5, .model_names =
  718. {
  719. [0] = "Pentium 60/66 A-step",
  720. [1] = "Pentium 60/66",
  721. [2] = "Pentium 75 - 200",
  722. [3] = "OverDrive PODP5V83",
  723. [4] = "Pentium MMX",
  724. [7] = "Mobile Pentium 75 - 200",
  725. [8] = "Mobile Pentium MMX",
  726. [9] = "Quark SoC X1000",
  727. }
  728. },
  729. { .family = 6, .model_names =
  730. {
  731. [0] = "Pentium Pro A-step",
  732. [1] = "Pentium Pro",
  733. [3] = "Pentium II (Klamath)",
  734. [4] = "Pentium II (Deschutes)",
  735. [5] = "Pentium II (Deschutes)",
  736. [6] = "Mobile Pentium II",
  737. [7] = "Pentium III (Katmai)",
  738. [8] = "Pentium III (Coppermine)",
  739. [10] = "Pentium III (Cascades)",
  740. [11] = "Pentium III (Tualatin)",
  741. }
  742. },
  743. { .family = 15, .model_names =
  744. {
  745. [0] = "Pentium 4 (Unknown)",
  746. [1] = "Pentium 4 (Willamette)",
  747. [2] = "Pentium 4 (Northwood)",
  748. [4] = "Pentium 4 (Foster)",
  749. [5] = "Pentium 4 (Foster)",
  750. }
  751. },
  752. },
  753. .legacy_cache_size = intel_size_cache,
  754. #endif
  755. .c_detect_tlb = intel_detect_tlb,
  756. .c_early_init = early_init_intel,
  757. .c_init = init_intel,
  758. .c_bsp_resume = intel_bsp_resume,
  759. .c_x86_vendor = X86_VENDOR_INTEL,
  760. };
  761. cpu_dev_register(intel_cpu_dev);