intel.c 8.2 KB

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