intel.c 9.0 KB

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