common.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821
  1. #include <linux/init.h>
  2. #include <linux/kernel.h>
  3. #include <linux/sched.h>
  4. #include <linux/string.h>
  5. #include <linux/bootmem.h>
  6. #include <linux/bitops.h>
  7. #include <linux/module.h>
  8. #include <linux/kgdb.h>
  9. #include <linux/topology.h>
  10. #include <linux/delay.h>
  11. #include <linux/smp.h>
  12. #include <linux/percpu.h>
  13. #include <asm/i387.h>
  14. #include <asm/msr.h>
  15. #include <asm/io.h>
  16. #include <asm/linkage.h>
  17. #include <asm/mmu_context.h>
  18. #include <asm/mtrr.h>
  19. #include <asm/mce.h>
  20. #include <asm/pat.h>
  21. #include <asm/asm.h>
  22. #include <asm/numa.h>
  23. #ifdef CONFIG_X86_LOCAL_APIC
  24. #include <asm/mpspec.h>
  25. #include <asm/apic.h>
  26. #include <mach_apic.h>
  27. #include <asm/genapic.h>
  28. #endif
  29. #include <asm/pda.h>
  30. #include <asm/pgtable.h>
  31. #include <asm/processor.h>
  32. #include <asm/desc.h>
  33. #include <asm/atomic.h>
  34. #include <asm/proto.h>
  35. #include <asm/sections.h>
  36. #include <asm/setup.h>
  37. #include "cpu.h"
  38. static struct cpu_dev *this_cpu __cpuinitdata;
  39. DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
  40. [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } },
  41. [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } },
  42. [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } },
  43. [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } },
  44. /*
  45. * Segments used for calling PnP BIOS have byte granularity.
  46. * They code segments and data segments have fixed 64k limits,
  47. * the transfer segment sizes are set at run time.
  48. */
  49. /* 32-bit code */
  50. [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } },
  51. /* 16-bit code */
  52. [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } },
  53. /* 16-bit data */
  54. [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } },
  55. /* 16-bit data */
  56. [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } },
  57. /* 16-bit data */
  58. [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } },
  59. /*
  60. * The APM segments have byte granularity and their bases
  61. * are set at run time. All have 64k limits.
  62. */
  63. /* 32-bit code */
  64. [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } },
  65. /* 16-bit code */
  66. [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } },
  67. /* data */
  68. [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } },
  69. [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } },
  70. [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } },
  71. } };
  72. EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
  73. static int cachesize_override __cpuinitdata = -1;
  74. static int disable_x86_serial_nr __cpuinitdata = 1;
  75. static int __init cachesize_setup(char *str)
  76. {
  77. get_option(&str, &cachesize_override);
  78. return 1;
  79. }
  80. __setup("cachesize=", cachesize_setup);
  81. /*
  82. * Naming convention should be: <Name> [(<Codename>)]
  83. * This table only is used unless init_<vendor>() below doesn't set it;
  84. * in particular, if CPUID levels 0x80000002..4 are supported, this isn't used
  85. *
  86. */
  87. /* Look up CPU names by table lookup. */
  88. static char __cpuinit *table_lookup_model(struct cpuinfo_x86 *c)
  89. {
  90. struct cpu_model_info *info;
  91. if (c->x86_model >= 16)
  92. return NULL; /* Range check */
  93. if (!this_cpu)
  94. return NULL;
  95. info = this_cpu->c_models;
  96. while (info && info->family) {
  97. if (info->family == c->x86)
  98. return info->model_names[c->x86_model];
  99. info++;
  100. }
  101. return NULL; /* Not found */
  102. }
  103. static int __init x86_fxsr_setup(char *s)
  104. {
  105. setup_clear_cpu_cap(X86_FEATURE_FXSR);
  106. setup_clear_cpu_cap(X86_FEATURE_XMM);
  107. return 1;
  108. }
  109. __setup("nofxsr", x86_fxsr_setup);
  110. static int __init x86_sep_setup(char *s)
  111. {
  112. setup_clear_cpu_cap(X86_FEATURE_SEP);
  113. return 1;
  114. }
  115. __setup("nosep", x86_sep_setup);
  116. /* Standard macro to see if a specific flag is changeable */
  117. static inline int flag_is_changeable_p(u32 flag)
  118. {
  119. u32 f1, f2;
  120. asm("pushfl\n\t"
  121. "pushfl\n\t"
  122. "popl %0\n\t"
  123. "movl %0,%1\n\t"
  124. "xorl %2,%0\n\t"
  125. "pushl %0\n\t"
  126. "popfl\n\t"
  127. "pushfl\n\t"
  128. "popl %0\n\t"
  129. "popfl\n\t"
  130. : "=&r" (f1), "=&r" (f2)
  131. : "ir" (flag));
  132. return ((f1^f2) & flag) != 0;
  133. }
  134. /* Probe for the CPUID instruction */
  135. static int __cpuinit have_cpuid_p(void)
  136. {
  137. return flag_is_changeable_p(X86_EFLAGS_ID);
  138. }
  139. static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
  140. {
  141. if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr) {
  142. /* Disable processor serial number */
  143. unsigned long lo, hi;
  144. rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
  145. lo |= 0x200000;
  146. wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi);
  147. printk(KERN_NOTICE "CPU serial number disabled.\n");
  148. clear_cpu_cap(c, X86_FEATURE_PN);
  149. /* Disabling the serial number may affect the cpuid level */
  150. c->cpuid_level = cpuid_eax(0);
  151. }
  152. }
  153. static int __init x86_serial_nr_setup(char *s)
  154. {
  155. disable_x86_serial_nr = 0;
  156. return 1;
  157. }
  158. __setup("serialnumber", x86_serial_nr_setup);
  159. __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
  160. /* Current gdt points %fs at the "master" per-cpu area: after this,
  161. * it's on the real one. */
  162. void switch_to_new_gdt(void)
  163. {
  164. struct desc_ptr gdt_descr;
  165. gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
  166. gdt_descr.size = GDT_SIZE - 1;
  167. load_gdt(&gdt_descr);
  168. asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory");
  169. }
  170. static struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
  171. static void __cpuinit default_init(struct cpuinfo_x86 *c)
  172. {
  173. /* Not much we can do here... */
  174. /* Check if at least it has cpuid */
  175. if (c->cpuid_level == -1) {
  176. /* No cpuid. It must be an ancient CPU */
  177. if (c->x86 == 4)
  178. strcpy(c->x86_model_id, "486");
  179. else if (c->x86 == 3)
  180. strcpy(c->x86_model_id, "386");
  181. }
  182. }
  183. static struct cpu_dev __cpuinitdata default_cpu = {
  184. .c_init = default_init,
  185. .c_vendor = "Unknown",
  186. .c_x86_vendor = X86_VENDOR_UNKNOWN,
  187. };
  188. int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  189. {
  190. unsigned int *v;
  191. char *p, *q;
  192. if (c->extended_cpuid_level < 0x80000004)
  193. return 0;
  194. v = (unsigned int *) c->x86_model_id;
  195. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  196. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  197. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  198. c->x86_model_id[48] = 0;
  199. /* Intel chips right-justify this string for some dumb reason;
  200. undo that brain damage */
  201. p = q = &c->x86_model_id[0];
  202. while (*p == ' ')
  203. p++;
  204. if (p != q) {
  205. while (*p)
  206. *q++ = *p++;
  207. while (q <= &c->x86_model_id[48])
  208. *q++ = '\0'; /* Zero-pad the rest */
  209. }
  210. return 1;
  211. }
  212. void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  213. {
  214. unsigned int n, dummy, ebx, ecx, edx, l2size;
  215. n = c->extended_cpuid_level;
  216. if (n >= 0x80000005) {
  217. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  218. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
  219. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  220. c->x86_cache_size = (ecx>>24) + (edx>>24);
  221. }
  222. if (n < 0x80000006) /* Some chips just has a large L1. */
  223. return;
  224. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  225. l2size = ecx >> 16;
  226. /* do processor-specific cache resizing */
  227. if (this_cpu->c_size_cache)
  228. l2size = this_cpu->c_size_cache(c, l2size);
  229. /* Allow user to override all this if necessary. */
  230. if (cachesize_override != -1)
  231. l2size = cachesize_override;
  232. if (l2size == 0)
  233. return; /* Again, no L2 cache is possible */
  234. c->x86_cache_size = l2size;
  235. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  236. l2size, ecx & 0xFF);
  237. }
  238. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  239. {
  240. #ifdef CONFIG_X86_HT
  241. u32 eax, ebx, ecx, edx;
  242. int index_msb, core_bits;
  243. if (!cpu_has(c, X86_FEATURE_HT))
  244. return;
  245. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  246. goto out;
  247. cpuid(1, &eax, &ebx, &ecx, &edx);
  248. smp_num_siblings = (ebx & 0xff0000) >> 16;
  249. if (smp_num_siblings == 1) {
  250. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  251. } else if (smp_num_siblings > 1) {
  252. if (smp_num_siblings > NR_CPUS) {
  253. printk(KERN_WARNING "CPU: Unsupported number of siblings %d",
  254. smp_num_siblings);
  255. smp_num_siblings = 1;
  256. return;
  257. }
  258. index_msb = get_count_order(smp_num_siblings);
  259. c->phys_proc_id = phys_pkg_id(c->initial_apicid, index_msb);
  260. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  261. index_msb = get_count_order(smp_num_siblings);
  262. core_bits = get_count_order(c->x86_max_cores);
  263. c->cpu_core_id = phys_pkg_id(c->initial_apicid, index_msb) &
  264. ((1 << core_bits) - 1);
  265. }
  266. out:
  267. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  268. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  269. c->phys_proc_id);
  270. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  271. c->cpu_core_id);
  272. }
  273. #endif
  274. }
  275. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  276. {
  277. char *v = c->x86_vendor_id;
  278. int i;
  279. static int printed;
  280. for (i = 0; i < X86_VENDOR_NUM; i++) {
  281. if (!cpu_devs[i])
  282. break;
  283. if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
  284. (cpu_devs[i]->c_ident[1] &&
  285. !strcmp(v, cpu_devs[i]->c_ident[1]))) {
  286. this_cpu = cpu_devs[i];
  287. c->x86_vendor = this_cpu->c_x86_vendor;
  288. return;
  289. }
  290. }
  291. if (!printed) {
  292. printed++;
  293. printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
  294. printk(KERN_ERR "CPU: Your system may be unstable.\n");
  295. }
  296. c->x86_vendor = X86_VENDOR_UNKNOWN;
  297. this_cpu = &default_cpu;
  298. }
  299. void __cpuinit cpu_detect(struct cpuinfo_x86 *c)
  300. {
  301. /* Get vendor name */
  302. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  303. (unsigned int *)&c->x86_vendor_id[0],
  304. (unsigned int *)&c->x86_vendor_id[8],
  305. (unsigned int *)&c->x86_vendor_id[4]);
  306. c->x86 = 4;
  307. /* Intel-defined flags: level 0x00000001 */
  308. if (c->cpuid_level >= 0x00000001) {
  309. u32 junk, tfms, cap0, misc;
  310. cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  311. c->x86 = (tfms >> 8) & 0xf;
  312. c->x86_model = (tfms >> 4) & 0xf;
  313. c->x86_mask = tfms & 0xf;
  314. if (c->x86 == 0xf)
  315. c->x86 += (tfms >> 20) & 0xff;
  316. if (c->x86 >= 0x6)
  317. c->x86_model += ((tfms >> 16) & 0xf) << 4;
  318. if (cap0 & (1<<19)) {
  319. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  320. c->x86_cache_alignment = c->x86_clflush_size;
  321. }
  322. }
  323. }
  324. static void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c)
  325. {
  326. u32 tfms, xlvl;
  327. u32 ebx;
  328. /* Intel-defined flags: level 0x00000001 */
  329. if (c->cpuid_level >= 0x00000001) {
  330. u32 capability, excap;
  331. cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
  332. c->x86_capability[0] = capability;
  333. c->x86_capability[4] = excap;
  334. }
  335. /* AMD-defined flags: level 0x80000001 */
  336. xlvl = cpuid_eax(0x80000000);
  337. c->extended_cpuid_level = xlvl;
  338. if ((xlvl & 0xffff0000) == 0x80000000) {
  339. if (xlvl >= 0x80000001) {
  340. c->x86_capability[1] = cpuid_edx(0x80000001);
  341. c->x86_capability[6] = cpuid_ecx(0x80000001);
  342. }
  343. }
  344. }
  345. /*
  346. * Do minimum CPU detection early.
  347. * Fields really needed: vendor, cpuid_level, family, model, mask,
  348. * cache alignment.
  349. * The others are not touched to avoid unwanted side effects.
  350. *
  351. * WARNING: this function is only called on the BP. Don't add code here
  352. * that is supposed to run on all CPUs.
  353. */
  354. static void __init early_identify_cpu(struct cpuinfo_x86 *c)
  355. {
  356. c->x86_clflush_size = 32;
  357. c->x86_cache_alignment = c->x86_clflush_size;
  358. if (!have_cpuid_p())
  359. return;
  360. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  361. c->extended_cpuid_level = 0;
  362. cpu_detect(c);
  363. get_cpu_vendor(c);
  364. get_cpu_cap(c);
  365. if (this_cpu->c_early_init)
  366. this_cpu->c_early_init(c);
  367. validate_pat_support(c);
  368. }
  369. void __init early_cpu_init(void)
  370. {
  371. struct cpu_dev **cdev;
  372. int count = 0;
  373. printk("KERNEL supported cpus:\n");
  374. for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) {
  375. struct cpu_dev *cpudev = *cdev;
  376. unsigned int j;
  377. if (count >= X86_VENDOR_NUM)
  378. break;
  379. cpu_devs[count] = cpudev;
  380. count++;
  381. for (j = 0; j < 2; j++) {
  382. if (!cpudev->c_ident[j])
  383. continue;
  384. printk(" %s %s\n", cpudev->c_vendor,
  385. cpudev->c_ident[j]);
  386. }
  387. }
  388. early_identify_cpu(&boot_cpu_data);
  389. }
  390. /*
  391. * The NOPL instruction is supposed to exist on all CPUs with
  392. * family >= 6, unfortunately, that's not true in practice because
  393. * of early VIA chips and (more importantly) broken virtualizers that
  394. * are not easy to detect. Hence, probe for it based on first
  395. * principles.
  396. */
  397. static void __cpuinit detect_nopl(struct cpuinfo_x86 *c)
  398. {
  399. const u32 nopl_signature = 0x888c53b1; /* Random number */
  400. u32 has_nopl = nopl_signature;
  401. clear_cpu_cap(c, X86_FEATURE_NOPL);
  402. if (c->x86 >= 6) {
  403. asm volatile("\n"
  404. "1: .byte 0x0f,0x1f,0xc0\n" /* nopl %eax */
  405. "2:\n"
  406. " .section .fixup,\"ax\"\n"
  407. "3: xor %0,%0\n"
  408. " jmp 2b\n"
  409. " .previous\n"
  410. _ASM_EXTABLE(1b,3b)
  411. : "+a" (has_nopl));
  412. if (has_nopl == nopl_signature)
  413. set_cpu_cap(c, X86_FEATURE_NOPL);
  414. }
  415. }
  416. static void __cpuinit generic_identify(struct cpuinfo_x86 *c)
  417. {
  418. if (!have_cpuid_p())
  419. return;
  420. c->extended_cpuid_level = 0;
  421. cpu_detect(c);
  422. get_cpu_vendor(c);
  423. get_cpu_cap(c);
  424. if (c->cpuid_level >= 0x00000001) {
  425. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF;
  426. #ifdef CONFIG_X86_HT
  427. c->apicid = phys_pkg_id(c->initial_apicid, 0);
  428. c->phys_proc_id = c->initial_apicid;
  429. #else
  430. c->apicid = c->initial_apicid;
  431. #endif
  432. }
  433. if (c->extended_cpuid_level >= 0x80000004)
  434. get_model_name(c); /* Default name */
  435. init_scattered_cpuid_features(c);
  436. detect_nopl(c);
  437. }
  438. /*
  439. * This does the hard work of actually picking apart the CPU stuff...
  440. */
  441. static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  442. {
  443. int i;
  444. c->loops_per_jiffy = loops_per_jiffy;
  445. c->x86_cache_size = -1;
  446. c->x86_vendor = X86_VENDOR_UNKNOWN;
  447. c->cpuid_level = -1; /* CPUID not detected */
  448. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  449. c->x86_vendor_id[0] = '\0'; /* Unset */
  450. c->x86_model_id[0] = '\0'; /* Unset */
  451. c->x86_max_cores = 1;
  452. c->x86_clflush_size = 32;
  453. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  454. if (!have_cpuid_p()) {
  455. /*
  456. * First of all, decide if this is a 486 or higher
  457. * It's a 486 if we can modify the AC flag
  458. */
  459. if (flag_is_changeable_p(X86_EFLAGS_AC))
  460. c->x86 = 4;
  461. else
  462. c->x86 = 3;
  463. }
  464. generic_identify(c);
  465. if (this_cpu->c_identify)
  466. this_cpu->c_identify(c);
  467. /*
  468. * Vendor-specific initialization. In this section we
  469. * canonicalize the feature flags, meaning if there are
  470. * features a certain CPU supports which CPUID doesn't
  471. * tell us, CPUID claiming incorrect flags, or other bugs,
  472. * we handle them here.
  473. *
  474. * At the end of this section, c->x86_capability better
  475. * indicate the features this CPU genuinely supports!
  476. */
  477. if (this_cpu->c_init)
  478. this_cpu->c_init(c);
  479. /* Disable the PN if appropriate */
  480. squash_the_stupid_serial_number(c);
  481. /*
  482. * The vendor-specific functions might have changed features. Now
  483. * we do "generic changes."
  484. */
  485. /* If the model name is still unset, do table lookup. */
  486. if (!c->x86_model_id[0]) {
  487. char *p;
  488. p = table_lookup_model(c);
  489. if (p)
  490. strcpy(c->x86_model_id, p);
  491. else
  492. /* Last resort... */
  493. sprintf(c->x86_model_id, "%02x/%02x",
  494. c->x86, c->x86_model);
  495. }
  496. /*
  497. * On SMP, boot_cpu_data holds the common feature set between
  498. * all CPUs; so make sure that we indicate which features are
  499. * common between the CPUs. The first time this routine gets
  500. * executed, c == &boot_cpu_data.
  501. */
  502. if (c != &boot_cpu_data) {
  503. /* AND the already accumulated flags with these */
  504. for (i = 0; i < NCAPINTS; i++)
  505. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  506. }
  507. /* Clear all flags overriden by options */
  508. for (i = 0; i < NCAPINTS; i++)
  509. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  510. /* Init Machine Check Exception if available. */
  511. mcheck_init(c);
  512. select_idle_routine(c);
  513. }
  514. void __init identify_boot_cpu(void)
  515. {
  516. identify_cpu(&boot_cpu_data);
  517. sysenter_setup();
  518. enable_sep_cpu();
  519. }
  520. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  521. {
  522. BUG_ON(c == &boot_cpu_data);
  523. identify_cpu(c);
  524. enable_sep_cpu();
  525. mtrr_ap_init();
  526. }
  527. struct msr_range {
  528. unsigned min;
  529. unsigned max;
  530. };
  531. static struct msr_range msr_range_array[] __cpuinitdata = {
  532. { 0x00000000, 0x00000418},
  533. { 0xc0000000, 0xc000040b},
  534. { 0xc0010000, 0xc0010142},
  535. { 0xc0011000, 0xc001103b},
  536. };
  537. static void __cpuinit print_cpu_msr(void)
  538. {
  539. unsigned index;
  540. u64 val;
  541. int i;
  542. unsigned index_min, index_max;
  543. for (i = 0; i < ARRAY_SIZE(msr_range_array); i++) {
  544. index_min = msr_range_array[i].min;
  545. index_max = msr_range_array[i].max;
  546. for (index = index_min; index < index_max; index++) {
  547. if (rdmsrl_amd_safe(index, &val))
  548. continue;
  549. printk(KERN_INFO " MSR%08x: %016llx\n", index, val);
  550. }
  551. }
  552. }
  553. static int show_msr __cpuinitdata;
  554. static __init int setup_show_msr(char *arg)
  555. {
  556. int num;
  557. get_option(&arg, &num);
  558. if (num > 0)
  559. show_msr = num;
  560. return 1;
  561. }
  562. __setup("show_msr=", setup_show_msr);
  563. static __init int setup_noclflush(char *arg)
  564. {
  565. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  566. return 1;
  567. }
  568. __setup("noclflush", setup_noclflush);
  569. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  570. {
  571. char *vendor = NULL;
  572. if (c->x86_vendor < X86_VENDOR_NUM)
  573. vendor = this_cpu->c_vendor;
  574. else if (c->cpuid_level >= 0)
  575. vendor = c->x86_vendor_id;
  576. if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor)))
  577. printk(KERN_CONT "%s ", vendor);
  578. if (c->x86_model_id[0])
  579. printk(KERN_CONT "%s", c->x86_model_id);
  580. else
  581. printk(KERN_CONT "%d86", c->x86);
  582. if (c->x86_mask || c->cpuid_level >= 0)
  583. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  584. else
  585. printk(KERN_CONT "\n");
  586. #ifdef CONFIG_SMP
  587. if (c->cpu_index < show_msr)
  588. print_cpu_msr();
  589. #else
  590. if (show_msr)
  591. print_cpu_msr();
  592. #endif
  593. }
  594. static __init int setup_disablecpuid(char *arg)
  595. {
  596. int bit;
  597. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  598. setup_clear_cpu_cap(bit);
  599. else
  600. return 0;
  601. return 1;
  602. }
  603. __setup("clearcpuid=", setup_disablecpuid);
  604. cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
  605. /* Make sure %fs is initialized properly in idle threads */
  606. struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
  607. {
  608. memset(regs, 0, sizeof(struct pt_regs));
  609. regs->fs = __KERNEL_PERCPU;
  610. return regs;
  611. }
  612. /*
  613. * cpu_init() initializes state that is per-CPU. Some data is already
  614. * initialized (naturally) in the bootstrap process, such as the GDT
  615. * and IDT. We reload them nevertheless, this function acts as a
  616. * 'CPU state barrier', nothing should get across.
  617. */
  618. void __cpuinit cpu_init(void)
  619. {
  620. int cpu = smp_processor_id();
  621. struct task_struct *curr = current;
  622. struct tss_struct *t = &per_cpu(init_tss, cpu);
  623. struct thread_struct *thread = &curr->thread;
  624. if (cpu_test_and_set(cpu, cpu_initialized)) {
  625. printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
  626. for (;;) local_irq_enable();
  627. }
  628. printk(KERN_INFO "Initializing CPU#%d\n", cpu);
  629. if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
  630. clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  631. load_idt(&idt_descr);
  632. switch_to_new_gdt();
  633. /*
  634. * Set up and load the per-CPU TSS and LDT
  635. */
  636. atomic_inc(&init_mm.mm_count);
  637. curr->active_mm = &init_mm;
  638. if (curr->mm)
  639. BUG();
  640. enter_lazy_tlb(&init_mm, curr);
  641. load_sp0(t, thread);
  642. set_tss_desc(cpu, t);
  643. load_TR_desc();
  644. load_LDT(&init_mm.context);
  645. #ifdef CONFIG_DOUBLEFAULT
  646. /* Set up doublefault TSS pointer in the GDT */
  647. __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
  648. #endif
  649. /* Clear %gs. */
  650. asm volatile ("mov %0, %%gs" : : "r" (0));
  651. /* Clear all 6 debug registers: */
  652. set_debugreg(0, 0);
  653. set_debugreg(0, 1);
  654. set_debugreg(0, 2);
  655. set_debugreg(0, 3);
  656. set_debugreg(0, 6);
  657. set_debugreg(0, 7);
  658. /*
  659. * Force FPU initialization:
  660. */
  661. if (cpu_has_xsave)
  662. current_thread_info()->status = TS_XSAVE;
  663. else
  664. current_thread_info()->status = 0;
  665. clear_used_math();
  666. mxcsr_feature_mask_init();
  667. /*
  668. * Boot processor to setup the FP and extended state context info.
  669. */
  670. if (!smp_processor_id())
  671. init_thread_xstate();
  672. xsave_init();
  673. }
  674. #ifdef CONFIG_HOTPLUG_CPU
  675. void __cpuinit cpu_uninit(void)
  676. {
  677. int cpu = raw_smp_processor_id();
  678. cpu_clear(cpu, cpu_initialized);
  679. /* lazy TLB state */
  680. per_cpu(cpu_tlbstate, cpu).state = 0;
  681. per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm;
  682. }
  683. #endif