intel.c 8.6 KB

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