intel.c 8.8 KB

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