intel.c 22 KB

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