intel.c 8.6 KB

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