intel.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730
  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. #endif
  18. #include "cpu.h"
  19. #ifdef CONFIG_X86_LOCAL_APIC
  20. #include <asm/mpspec.h>
  21. #include <asm/apic.h>
  22. #endif
  23. static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
  24. {
  25. u64 misc_enable;
  26. /* Unmask CPUID levels if masked: */
  27. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  28. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  29. if (misc_enable & MSR_IA32_MISC_ENABLE_LIMIT_CPUID) {
  30. misc_enable &= ~MSR_IA32_MISC_ENABLE_LIMIT_CPUID;
  31. wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  32. c->cpuid_level = cpuid_eax(0);
  33. get_cpu_cap(c);
  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. if (c->x86 >= 6 && !cpu_has(c, X86_FEATURE_IA64)) {
  40. unsigned lower_word;
  41. wrmsr(MSR_IA32_UCODE_REV, 0, 0);
  42. /* Required by the SDM */
  43. sync_core();
  44. rdmsr(MSR_IA32_UCODE_REV, lower_word, c->microcode);
  45. }
  46. /*
  47. * Atom erratum AAE44/AAF40/AAG38/AAH41:
  48. *
  49. * A race condition between speculative fetches and invalidating
  50. * a large page. This is worked around in microcode, but we
  51. * need the microcode to have already been loaded... so if it is
  52. * not, recommend a BIOS update and disable large pages.
  53. */
  54. if (c->x86 == 6 && c->x86_model == 0x1c && c->x86_mask <= 2 &&
  55. c->microcode < 0x20e) {
  56. printk(KERN_WARNING "Atom PSE erratum detected, BIOS microcode update recommended\n");
  57. clear_cpu_cap(c, X86_FEATURE_PSE);
  58. }
  59. #ifdef CONFIG_X86_64
  60. set_cpu_cap(c, X86_FEATURE_SYSENTER32);
  61. #else
  62. /* Netburst reports 64 bytes clflush size, but does IO in 128 bytes */
  63. if (c->x86 == 15 && c->x86_cache_alignment == 64)
  64. c->x86_cache_alignment = 128;
  65. #endif
  66. /* CPUID workaround for 0F33/0F34 CPU */
  67. if (c->x86 == 0xF && c->x86_model == 0x3
  68. && (c->x86_mask == 0x3 || c->x86_mask == 0x4))
  69. c->x86_phys_bits = 36;
  70. /*
  71. * c->x86_power is 8000_0007 edx. Bit 8 is TSC runs at constant rate
  72. * with P/T states and does not stop in deep C-states.
  73. *
  74. * It is also reliable across cores and sockets. (but not across
  75. * cabinets - we turn it off in that case explicitly.)
  76. */
  77. if (c->x86_power & (1 << 8)) {
  78. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  79. set_cpu_cap(c, X86_FEATURE_NONSTOP_TSC);
  80. if (!check_tsc_unstable())
  81. sched_clock_stable = 1;
  82. }
  83. /*
  84. * There is a known erratum on Pentium III and Core Solo
  85. * and Core Duo CPUs.
  86. * " Page with PAT set to WC while associated MTRR is UC
  87. * may consolidate to UC "
  88. * Because of this erratum, it is better to stick with
  89. * setting WC in MTRR rather than using PAT on these CPUs.
  90. *
  91. * Enable PAT WC only on P4, Core 2 or later CPUs.
  92. */
  93. if (c->x86 == 6 && c->x86_model < 15)
  94. clear_cpu_cap(c, X86_FEATURE_PAT);
  95. #ifdef CONFIG_KMEMCHECK
  96. /*
  97. * P4s have a "fast strings" feature which causes single-
  98. * stepping REP instructions to only generate a #DB on
  99. * cache-line boundaries.
  100. *
  101. * Ingo Molnar reported a Pentium D (model 6) and a Xeon
  102. * (model 2) with the same problem.
  103. */
  104. if (c->x86 == 15) {
  105. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  106. if (misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING) {
  107. printk(KERN_INFO "kmemcheck: Disabling fast string operations\n");
  108. misc_enable &= ~MSR_IA32_MISC_ENABLE_FAST_STRING;
  109. wrmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  110. }
  111. }
  112. #endif
  113. /*
  114. * If fast string is not enabled in IA32_MISC_ENABLE for any reason,
  115. * clear the fast string and enhanced fast string CPU capabilities.
  116. */
  117. if (c->x86 > 6 || (c->x86 == 6 && c->x86_model >= 0xd)) {
  118. rdmsrl(MSR_IA32_MISC_ENABLE, misc_enable);
  119. if (!(misc_enable & MSR_IA32_MISC_ENABLE_FAST_STRING)) {
  120. printk(KERN_INFO "Disabled fast string operations\n");
  121. setup_clear_cpu_cap(X86_FEATURE_REP_GOOD);
  122. setup_clear_cpu_cap(X86_FEATURE_ERMS);
  123. }
  124. }
  125. }
  126. #ifdef CONFIG_X86_32
  127. /*
  128. * Early probe support logic for ppro memory erratum #50
  129. *
  130. * This is called before we do cpu ident work
  131. */
  132. int __cpuinit ppro_with_ram_bug(void)
  133. {
  134. /* Uses data from early_cpu_detect now */
  135. if (boot_cpu_data.x86_vendor == X86_VENDOR_INTEL &&
  136. boot_cpu_data.x86 == 6 &&
  137. boot_cpu_data.x86_model == 1 &&
  138. boot_cpu_data.x86_mask < 8) {
  139. printk(KERN_INFO "Pentium Pro with Errata#50 detected. Taking evasive action.\n");
  140. return 1;
  141. }
  142. return 0;
  143. }
  144. #ifdef CONFIG_X86_F00F_BUG
  145. static void __cpuinit trap_init_f00f_bug(void)
  146. {
  147. __set_fixmap(FIX_F00F_IDT, __pa_symbol(idt_table), PAGE_KERNEL_RO);
  148. /*
  149. * Update the IDT descriptor and reload the IDT so that
  150. * it uses the read-only mapped virtual address.
  151. */
  152. idt_descr.address = fix_to_virt(FIX_F00F_IDT);
  153. load_idt(&idt_descr);
  154. }
  155. #endif
  156. static void __cpuinit intel_smp_check(struct cpuinfo_x86 *c)
  157. {
  158. /* calling is from identify_secondary_cpu() ? */
  159. if (!c->cpu_index)
  160. return;
  161. /*
  162. * Mask B, Pentium, but not Pentium MMX
  163. */
  164. if (c->x86 == 5 &&
  165. c->x86_mask >= 1 && c->x86_mask <= 4 &&
  166. c->x86_model <= 3) {
  167. /*
  168. * Remember we have B step Pentia with bugs
  169. */
  170. WARN_ONCE(1, "WARNING: SMP operation may be unreliable"
  171. "with B stepping processors.\n");
  172. }
  173. }
  174. static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
  175. {
  176. unsigned long lo, hi;
  177. #ifdef CONFIG_X86_F00F_BUG
  178. /*
  179. * All current models of Pentium and Pentium with MMX technology CPUs
  180. * have the F0 0F bug, which lets nonprivileged users lock up the
  181. * system.
  182. * Note that the workaround only should be initialized once...
  183. */
  184. c->f00f_bug = 0;
  185. if (!paravirt_enabled() && c->x86 == 5) {
  186. static int f00f_workaround_enabled;
  187. c->f00f_bug = 1;
  188. if (!f00f_workaround_enabled) {
  189. trap_init_f00f_bug();
  190. printk(KERN_NOTICE "Intel Pentium with F0 0F bug - workaround enabled.\n");
  191. f00f_workaround_enabled = 1;
  192. }
  193. }
  194. #endif
  195. /*
  196. * SEP CPUID bug: Pentium Pro reports SEP but doesn't have it until
  197. * model 3 mask 3
  198. */
  199. if ((c->x86<<8 | c->x86_model<<4 | c->x86_mask) < 0x633)
  200. clear_cpu_cap(c, X86_FEATURE_SEP);
  201. /*
  202. * P4 Xeon errata 037 workaround.
  203. * Hardware prefetcher may cause stale data to be loaded into the cache.
  204. */
  205. if ((c->x86 == 15) && (c->x86_model == 1) && (c->x86_mask == 1)) {
  206. rdmsr(MSR_IA32_MISC_ENABLE, lo, hi);
  207. if ((lo & MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE) == 0) {
  208. printk (KERN_INFO "CPU: C0 stepping P4 Xeon detected.\n");
  209. printk (KERN_INFO "CPU: Disabling hardware prefetching (Errata 037)\n");
  210. lo |= MSR_IA32_MISC_ENABLE_PREFETCH_DISABLE;
  211. wrmsr(MSR_IA32_MISC_ENABLE, lo, hi);
  212. }
  213. }
  214. /*
  215. * See if we have a good local APIC by checking for buggy Pentia,
  216. * i.e. all B steppings and the C2 stepping of P54C when using their
  217. * integrated APIC (see 11AP erratum in "Pentium Processor
  218. * Specification Update").
  219. */
  220. if (cpu_has_apic && (c->x86<<8 | c->x86_model<<4) == 0x520 &&
  221. (c->x86_mask < 0x6 || c->x86_mask == 0xb))
  222. set_cpu_cap(c, X86_FEATURE_11AP);
  223. #ifdef CONFIG_X86_INTEL_USERCOPY
  224. /*
  225. * Set up the preferred alignment for movsl bulk memory moves
  226. */
  227. switch (c->x86) {
  228. case 4: /* 486: untested */
  229. break;
  230. case 5: /* Old Pentia: untested */
  231. break;
  232. case 6: /* PII/PIII only like movsl with 8-byte alignment */
  233. movsl_mask.mask = 7;
  234. break;
  235. case 15: /* P4 is OK down to 8-byte alignment */
  236. movsl_mask.mask = 7;
  237. break;
  238. }
  239. #endif
  240. #ifdef CONFIG_X86_NUMAQ
  241. numaq_tsc_disable();
  242. #endif
  243. intel_smp_check(c);
  244. }
  245. #else
  246. static void __cpuinit intel_workarounds(struct cpuinfo_x86 *c)
  247. {
  248. }
  249. #endif
  250. static void __cpuinit srat_detect_node(struct cpuinfo_x86 *c)
  251. {
  252. #ifdef CONFIG_NUMA
  253. unsigned node;
  254. int cpu = smp_processor_id();
  255. /* Don't do the funky fallback heuristics the AMD version employs
  256. for now. */
  257. node = numa_cpu_node(cpu);
  258. if (node == NUMA_NO_NODE || !node_online(node)) {
  259. /* reuse the value from init_cpu_to_node() */
  260. node = cpu_to_node(cpu);
  261. }
  262. numa_set_node(cpu, node);
  263. #endif
  264. }
  265. /*
  266. * find out the number of processor cores on the die
  267. */
  268. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  269. {
  270. unsigned int eax, ebx, ecx, edx;
  271. if (c->cpuid_level < 4)
  272. return 1;
  273. /* Intel has a non-standard dependency on %ecx for this CPUID level. */
  274. cpuid_count(4, 0, &eax, &ebx, &ecx, &edx);
  275. if (eax & 0x1f)
  276. return (eax >> 26) + 1;
  277. else
  278. return 1;
  279. }
  280. static void __cpuinit detect_vmx_virtcap(struct cpuinfo_x86 *c)
  281. {
  282. /* Intel VMX MSR indicated features */
  283. #define X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW 0x00200000
  284. #define X86_VMX_FEATURE_PROC_CTLS_VNMI 0x00400000
  285. #define X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS 0x80000000
  286. #define X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC 0x00000001
  287. #define X86_VMX_FEATURE_PROC_CTLS2_EPT 0x00000002
  288. #define X86_VMX_FEATURE_PROC_CTLS2_VPID 0x00000020
  289. u32 vmx_msr_low, vmx_msr_high, msr_ctl, msr_ctl2;
  290. clear_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  291. clear_cpu_cap(c, X86_FEATURE_VNMI);
  292. clear_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  293. clear_cpu_cap(c, X86_FEATURE_EPT);
  294. clear_cpu_cap(c, X86_FEATURE_VPID);
  295. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS, vmx_msr_low, vmx_msr_high);
  296. msr_ctl = vmx_msr_high | vmx_msr_low;
  297. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW)
  298. set_cpu_cap(c, X86_FEATURE_TPR_SHADOW);
  299. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_VNMI)
  300. set_cpu_cap(c, X86_FEATURE_VNMI);
  301. if (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_2ND_CTLS) {
  302. rdmsr(MSR_IA32_VMX_PROCBASED_CTLS2,
  303. vmx_msr_low, vmx_msr_high);
  304. msr_ctl2 = vmx_msr_high | vmx_msr_low;
  305. if ((msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VIRT_APIC) &&
  306. (msr_ctl & X86_VMX_FEATURE_PROC_CTLS_TPR_SHADOW))
  307. set_cpu_cap(c, X86_FEATURE_FLEXPRIORITY);
  308. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_EPT)
  309. set_cpu_cap(c, X86_FEATURE_EPT);
  310. if (msr_ctl2 & X86_VMX_FEATURE_PROC_CTLS2_VPID)
  311. set_cpu_cap(c, X86_FEATURE_VPID);
  312. }
  313. }
  314. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  315. {
  316. unsigned int l2 = 0;
  317. early_init_intel(c);
  318. intel_workarounds(c);
  319. /*
  320. * Detect the extended topology information if available. This
  321. * will reinitialise the initial_apicid which will be used
  322. * in init_intel_cacheinfo()
  323. */
  324. detect_extended_topology(c);
  325. l2 = init_intel_cacheinfo(c);
  326. if (c->cpuid_level > 9) {
  327. unsigned eax = cpuid_eax(10);
  328. /* Check for version and the number of counters */
  329. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  330. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  331. }
  332. if (cpu_has_xmm2)
  333. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  334. if (cpu_has_ds) {
  335. unsigned int l1;
  336. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  337. if (!(l1 & (1<<11)))
  338. set_cpu_cap(c, X86_FEATURE_BTS);
  339. if (!(l1 & (1<<12)))
  340. set_cpu_cap(c, X86_FEATURE_PEBS);
  341. }
  342. if (c->x86 == 6 && c->x86_model == 29 && cpu_has_clflush)
  343. set_cpu_cap(c, X86_FEATURE_CLFLUSH_MONITOR);
  344. #ifdef CONFIG_X86_64
  345. if (c->x86 == 15)
  346. c->x86_cache_alignment = c->x86_clflush_size * 2;
  347. if (c->x86 == 6)
  348. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  349. #else
  350. /*
  351. * Names for the Pentium II/Celeron processors
  352. * detectable only by also checking the cache size.
  353. * Dixon is NOT a Celeron.
  354. */
  355. if (c->x86 == 6) {
  356. char *p = NULL;
  357. switch (c->x86_model) {
  358. case 5:
  359. if (l2 == 0)
  360. p = "Celeron (Covington)";
  361. else if (l2 == 256)
  362. p = "Mobile Pentium II (Dixon)";
  363. break;
  364. case 6:
  365. if (l2 == 128)
  366. p = "Celeron (Mendocino)";
  367. else if (c->x86_mask == 0 || c->x86_mask == 5)
  368. p = "Celeron-A";
  369. break;
  370. case 8:
  371. if (l2 == 128)
  372. p = "Celeron (Coppermine)";
  373. break;
  374. }
  375. if (p)
  376. strcpy(c->x86_model_id, p);
  377. }
  378. if (c->x86 == 15)
  379. set_cpu_cap(c, X86_FEATURE_P4);
  380. if (c->x86 == 6)
  381. set_cpu_cap(c, X86_FEATURE_P3);
  382. #endif
  383. if (!cpu_has(c, X86_FEATURE_XTOPOLOGY)) {
  384. /*
  385. * let's use the legacy cpuid vector 0x1 and 0x4 for topology
  386. * detection.
  387. */
  388. c->x86_max_cores = intel_num_cpu_cores(c);
  389. #ifdef CONFIG_X86_32
  390. detect_ht(c);
  391. #endif
  392. }
  393. /* Work around errata */
  394. srat_detect_node(c);
  395. if (cpu_has(c, X86_FEATURE_VMX))
  396. detect_vmx_virtcap(c);
  397. /*
  398. * Initialize MSR_IA32_ENERGY_PERF_BIAS if BIOS did not.
  399. * x86_energy_perf_policy(8) is available to change it at run-time
  400. */
  401. if (cpu_has(c, X86_FEATURE_EPB)) {
  402. u64 epb;
  403. rdmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  404. if ((epb & 0xF) == ENERGY_PERF_BIAS_PERFORMANCE) {
  405. printk_once(KERN_WARNING "ENERGY_PERF_BIAS:"
  406. " Set to 'normal', was 'performance'\n"
  407. "ENERGY_PERF_BIAS: View and update with"
  408. " x86_energy_perf_policy(8)\n");
  409. epb = (epb & ~0xF) | ENERGY_PERF_BIAS_NORMAL;
  410. wrmsrl(MSR_IA32_ENERGY_PERF_BIAS, epb);
  411. }
  412. }
  413. }
  414. #ifdef CONFIG_X86_32
  415. static unsigned int __cpuinit intel_size_cache(struct cpuinfo_x86 *c, unsigned int size)
  416. {
  417. /*
  418. * Intel PIII Tualatin. This comes in two flavours.
  419. * One has 256kb of cache, the other 512. We have no way
  420. * to determine which, so we use a boottime override
  421. * for the 512kb model, and assume 256 otherwise.
  422. */
  423. if ((c->x86 == 6) && (c->x86_model == 11) && (size == 0))
  424. size = 256;
  425. return size;
  426. }
  427. #endif
  428. #define TLB_INST_4K 0x01
  429. #define TLB_INST_4M 0x02
  430. #define TLB_INST_2M_4M 0x03
  431. #define TLB_INST_ALL 0x05
  432. #define TLB_INST_1G 0x06
  433. #define TLB_DATA_4K 0x11
  434. #define TLB_DATA_4M 0x12
  435. #define TLB_DATA_2M_4M 0x13
  436. #define TLB_DATA_4K_4M 0x14
  437. #define TLB_DATA_1G 0x16
  438. #define TLB_DATA0_4K 0x21
  439. #define TLB_DATA0_4M 0x22
  440. #define TLB_DATA0_2M_4M 0x23
  441. #define STLB_4K 0x41
  442. static const struct _tlb_table intel_tlb_table[] __cpuinitconst = {
  443. { 0x01, TLB_INST_4K, 32, " TLB_INST 4 KByte pages, 4-way set associative" },
  444. { 0x02, TLB_INST_4M, 2, " TLB_INST 4 MByte pages, full associative" },
  445. { 0x03, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way set associative" },
  446. { 0x04, TLB_DATA_4M, 8, " TLB_DATA 4 MByte pages, 4-way set associative" },
  447. { 0x05, TLB_DATA_4M, 32, " TLB_DATA 4 MByte pages, 4-way set associative" },
  448. { 0x0b, TLB_INST_4M, 4, " TLB_INST 4 MByte pages, 4-way set associative" },
  449. { 0x4f, TLB_INST_4K, 32, " TLB_INST 4 KByte pages */" },
  450. { 0x50, TLB_INST_ALL, 64, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  451. { 0x51, TLB_INST_ALL, 128, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  452. { 0x52, TLB_INST_ALL, 256, " TLB_INST 4 KByte and 2-MByte or 4-MByte pages" },
  453. { 0x55, TLB_INST_2M_4M, 7, " TLB_INST 2-MByte or 4-MByte pages, fully associative" },
  454. { 0x56, TLB_DATA0_4M, 16, " TLB_DATA0 4 MByte pages, 4-way set associative" },
  455. { 0x57, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, 4-way associative" },
  456. { 0x59, TLB_DATA0_4K, 16, " TLB_DATA0 4 KByte pages, fully associative" },
  457. { 0x5a, TLB_DATA0_2M_4M, 32, " TLB_DATA0 2-MByte or 4 MByte pages, 4-way set associative" },
  458. { 0x5b, TLB_DATA_4K_4M, 64, " TLB_DATA 4 KByte and 4 MByte pages" },
  459. { 0x5c, TLB_DATA_4K_4M, 128, " TLB_DATA 4 KByte and 4 MByte pages" },
  460. { 0x5d, TLB_DATA_4K_4M, 256, " TLB_DATA 4 KByte and 4 MByte pages" },
  461. { 0xb0, TLB_INST_4K, 128, " TLB_INST 4 KByte pages, 4-way set associative" },
  462. { 0xb1, TLB_INST_2M_4M, 4, " TLB_INST 2M pages, 4-way, 8 entries or 4M pages, 4-way entries" },
  463. { 0xb2, TLB_INST_4K, 64, " TLB_INST 4KByte pages, 4-way set associative" },
  464. { 0xb3, TLB_DATA_4K, 128, " TLB_DATA 4 KByte pages, 4-way set associative" },
  465. { 0xb4, TLB_DATA_4K, 256, " TLB_DATA 4 KByte pages, 4-way associative" },
  466. { 0xba, TLB_DATA_4K, 64, " TLB_DATA 4 KByte pages, 4-way associative" },
  467. { 0xc0, TLB_DATA_4K_4M, 8, " TLB_DATA 4 KByte and 4 MByte pages, 4-way associative" },
  468. { 0xca, STLB_4K, 512, " STLB 4 KByte pages, 4-way associative" },
  469. { 0x00, 0, 0 }
  470. };
  471. static void __cpuinit intel_tlb_lookup(const unsigned char desc)
  472. {
  473. unsigned char k;
  474. if (desc == 0)
  475. return;
  476. /* look up this descriptor in the table */
  477. for (k = 0; intel_tlb_table[k].descriptor != desc && \
  478. intel_tlb_table[k].descriptor != 0; k++)
  479. ;
  480. if (intel_tlb_table[k].tlb_type == 0)
  481. return;
  482. switch (intel_tlb_table[k].tlb_type) {
  483. case STLB_4K:
  484. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  485. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  486. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  487. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  488. break;
  489. case TLB_INST_ALL:
  490. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  491. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  492. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  493. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  494. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  495. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  496. break;
  497. case TLB_INST_4K:
  498. if (tlb_lli_4k[ENTRIES] < intel_tlb_table[k].entries)
  499. tlb_lli_4k[ENTRIES] = intel_tlb_table[k].entries;
  500. break;
  501. case TLB_INST_4M:
  502. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  503. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  504. break;
  505. case TLB_INST_2M_4M:
  506. if (tlb_lli_2m[ENTRIES] < intel_tlb_table[k].entries)
  507. tlb_lli_2m[ENTRIES] = intel_tlb_table[k].entries;
  508. if (tlb_lli_4m[ENTRIES] < intel_tlb_table[k].entries)
  509. tlb_lli_4m[ENTRIES] = intel_tlb_table[k].entries;
  510. break;
  511. case TLB_DATA_4K:
  512. case TLB_DATA0_4K:
  513. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  514. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  515. break;
  516. case TLB_DATA_4M:
  517. case TLB_DATA0_4M:
  518. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  519. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  520. break;
  521. case TLB_DATA_2M_4M:
  522. case TLB_DATA0_2M_4M:
  523. if (tlb_lld_2m[ENTRIES] < intel_tlb_table[k].entries)
  524. tlb_lld_2m[ENTRIES] = intel_tlb_table[k].entries;
  525. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  526. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  527. break;
  528. case TLB_DATA_4K_4M:
  529. if (tlb_lld_4k[ENTRIES] < intel_tlb_table[k].entries)
  530. tlb_lld_4k[ENTRIES] = intel_tlb_table[k].entries;
  531. if (tlb_lld_4m[ENTRIES] < intel_tlb_table[k].entries)
  532. tlb_lld_4m[ENTRIES] = intel_tlb_table[k].entries;
  533. break;
  534. }
  535. }
  536. static void __cpuinit intel_tlb_flushall_shift_set(struct cpuinfo_x86 *c)
  537. {
  538. switch ((c->x86 << 8) + c->x86_model) {
  539. case 0x60f: /* original 65 nm celeron/pentium/core2/xeon, "Merom"/"Conroe" */
  540. case 0x616: /* single-core 65 nm celeron/core2solo "Merom-L"/"Conroe-L" */
  541. case 0x617: /* current 45 nm celeron/core2/xeon "Penryn"/"Wolfdale" */
  542. case 0x61d: /* six-core 45 nm xeon "Dunnington" */
  543. tlb_flushall_shift = -1;
  544. break;
  545. case 0x61a: /* 45 nm nehalem, "Bloomfield" */
  546. case 0x61e: /* 45 nm nehalem, "Lynnfield" */
  547. case 0x625: /* 32 nm nehalem, "Clarkdale" */
  548. case 0x62c: /* 32 nm nehalem, "Gulftown" */
  549. case 0x62e: /* 45 nm nehalem-ex, "Beckton" */
  550. case 0x62f: /* 32 nm Xeon E7 */
  551. tlb_flushall_shift = 6;
  552. break;
  553. case 0x62a: /* SandyBridge */
  554. case 0x62d: /* SandyBridge, "Romely-EP" */
  555. tlb_flushall_shift = 5;
  556. break;
  557. case 0x63a: /* Ivybridge */
  558. tlb_flushall_shift = 1;
  559. break;
  560. default:
  561. tlb_flushall_shift = 6;
  562. }
  563. }
  564. static void __cpuinit intel_detect_tlb(struct cpuinfo_x86 *c)
  565. {
  566. int i, j, n;
  567. unsigned int regs[4];
  568. unsigned char *desc = (unsigned char *)regs;
  569. if (c->cpuid_level < 2)
  570. return;
  571. /* Number of times to iterate */
  572. n = cpuid_eax(2) & 0xFF;
  573. for (i = 0 ; i < n ; i++) {
  574. cpuid(2, &regs[0], &regs[1], &regs[2], &regs[3]);
  575. /* If bit 31 is set, this is an unknown format */
  576. for (j = 0 ; j < 3 ; j++)
  577. if (regs[j] & (1 << 31))
  578. regs[j] = 0;
  579. /* Byte 0 is level count, not a descriptor */
  580. for (j = 1 ; j < 16 ; j++)
  581. intel_tlb_lookup(desc[j]);
  582. }
  583. intel_tlb_flushall_shift_set(c);
  584. }
  585. static const struct cpu_dev __cpuinitconst intel_cpu_dev = {
  586. .c_vendor = "Intel",
  587. .c_ident = { "GenuineIntel" },
  588. #ifdef CONFIG_X86_32
  589. .c_models = {
  590. { .vendor = X86_VENDOR_INTEL, .family = 4, .model_names =
  591. {
  592. [0] = "486 DX-25/33",
  593. [1] = "486 DX-50",
  594. [2] = "486 SX",
  595. [3] = "486 DX/2",
  596. [4] = "486 SL",
  597. [5] = "486 SX/2",
  598. [7] = "486 DX/2-WB",
  599. [8] = "486 DX/4",
  600. [9] = "486 DX/4-WB"
  601. }
  602. },
  603. { .vendor = X86_VENDOR_INTEL, .family = 5, .model_names =
  604. {
  605. [0] = "Pentium 60/66 A-step",
  606. [1] = "Pentium 60/66",
  607. [2] = "Pentium 75 - 200",
  608. [3] = "OverDrive PODP5V83",
  609. [4] = "Pentium MMX",
  610. [7] = "Mobile Pentium 75 - 200",
  611. [8] = "Mobile Pentium MMX"
  612. }
  613. },
  614. { .vendor = X86_VENDOR_INTEL, .family = 6, .model_names =
  615. {
  616. [0] = "Pentium Pro A-step",
  617. [1] = "Pentium Pro",
  618. [3] = "Pentium II (Klamath)",
  619. [4] = "Pentium II (Deschutes)",
  620. [5] = "Pentium II (Deschutes)",
  621. [6] = "Mobile Pentium II",
  622. [7] = "Pentium III (Katmai)",
  623. [8] = "Pentium III (Coppermine)",
  624. [10] = "Pentium III (Cascades)",
  625. [11] = "Pentium III (Tualatin)",
  626. }
  627. },
  628. { .vendor = X86_VENDOR_INTEL, .family = 15, .model_names =
  629. {
  630. [0] = "Pentium 4 (Unknown)",
  631. [1] = "Pentium 4 (Willamette)",
  632. [2] = "Pentium 4 (Northwood)",
  633. [4] = "Pentium 4 (Foster)",
  634. [5] = "Pentium 4 (Foster)",
  635. }
  636. },
  637. },
  638. .c_size_cache = intel_size_cache,
  639. #endif
  640. .c_detect_tlb = intel_detect_tlb,
  641. .c_early_init = early_init_intel,
  642. .c_init = init_intel,
  643. .c_x86_vendor = X86_VENDOR_INTEL,
  644. };
  645. cpu_dev_register(intel_cpu_dev);