intel.c 7.6 KB

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