common.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. #include <linux/init.h>
  2. #include <linux/string.h>
  3. #include <linux/delay.h>
  4. #include <linux/smp.h>
  5. #include <linux/module.h>
  6. #include <linux/percpu.h>
  7. #include <linux/bootmem.h>
  8. #include <asm/semaphore.h>
  9. #include <asm/processor.h>
  10. #include <asm/i387.h>
  11. #include <asm/msr.h>
  12. #include <asm/io.h>
  13. #include <asm/mmu_context.h>
  14. #include <asm/mtrr.h>
  15. #include <asm/mce.h>
  16. #ifdef CONFIG_X86_LOCAL_APIC
  17. #include <asm/mpspec.h>
  18. #include <asm/apic.h>
  19. #include <mach_apic.h>
  20. #endif
  21. #include <asm/pda.h>
  22. #include "cpu.h"
  23. DEFINE_PER_CPU(struct desc_struct, cpu_gdt[GDT_ENTRIES]) = {
  24. [GDT_ENTRY_KERNEL_CS] = { 0x0000ffff, 0x00cf9a00 },
  25. [GDT_ENTRY_KERNEL_DS] = { 0x0000ffff, 0x00cf9200 },
  26. [GDT_ENTRY_DEFAULT_USER_CS] = { 0x0000ffff, 0x00cffa00 },
  27. [GDT_ENTRY_DEFAULT_USER_DS] = { 0x0000ffff, 0x00cff200 },
  28. /*
  29. * Segments used for calling PnP BIOS have byte granularity.
  30. * They code segments and data segments have fixed 64k limits,
  31. * the transfer segment sizes are set at run time.
  32. */
  33. [GDT_ENTRY_PNPBIOS_CS32] = { 0x0000ffff, 0x00409a00 },/* 32-bit code */
  34. [GDT_ENTRY_PNPBIOS_CS16] = { 0x0000ffff, 0x00009a00 },/* 16-bit code */
  35. [GDT_ENTRY_PNPBIOS_DS] = { 0x0000ffff, 0x00009200 }, /* 16-bit data */
  36. [GDT_ENTRY_PNPBIOS_TS1] = { 0x00000000, 0x00009200 },/* 16-bit data */
  37. [GDT_ENTRY_PNPBIOS_TS2] = { 0x00000000, 0x00009200 },/* 16-bit data */
  38. /*
  39. * The APM segments have byte granularity and their bases
  40. * are set at run time. All have 64k limits.
  41. */
  42. [GDT_ENTRY_APMBIOS_BASE] = { 0x0000ffff, 0x00409a00 },/* 32-bit code */
  43. /* 16-bit code */
  44. [GDT_ENTRY_APMBIOS_BASE+1] = { 0x0000ffff, 0x00009a00 },
  45. [GDT_ENTRY_APMBIOS_BASE+2] = { 0x0000ffff, 0x00409200 }, /* data */
  46. [GDT_ENTRY_ESPFIX_SS] = { 0x00000000, 0x00c09200 },
  47. [GDT_ENTRY_PDA] = { 0x00000000, 0x00c09200 }, /* set in setup_pda */
  48. };
  49. EXPORT_PER_CPU_SYMBOL_GPL(cpu_gdt);
  50. DEFINE_PER_CPU(struct i386_pda, _cpu_pda);
  51. EXPORT_PER_CPU_SYMBOL(_cpu_pda);
  52. static int cachesize_override __cpuinitdata = -1;
  53. static int disable_x86_fxsr __cpuinitdata;
  54. static int disable_x86_serial_nr __cpuinitdata = 1;
  55. static int disable_x86_sep __cpuinitdata;
  56. struct cpu_dev * cpu_devs[X86_VENDOR_NUM] = {};
  57. extern int disable_pse;
  58. static void __cpuinit default_init(struct cpuinfo_x86 * c)
  59. {
  60. /* Not much we can do here... */
  61. /* Check if at least it has cpuid */
  62. if (c->cpuid_level == -1) {
  63. /* No cpuid. It must be an ancient CPU */
  64. if (c->x86 == 4)
  65. strcpy(c->x86_model_id, "486");
  66. else if (c->x86 == 3)
  67. strcpy(c->x86_model_id, "386");
  68. }
  69. }
  70. static struct cpu_dev __cpuinitdata default_cpu = {
  71. .c_init = default_init,
  72. .c_vendor = "Unknown",
  73. };
  74. static struct cpu_dev * this_cpu __cpuinitdata = &default_cpu;
  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. int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  82. {
  83. unsigned int *v;
  84. char *p, *q;
  85. if (cpuid_eax(0x80000000) < 0x80000004)
  86. return 0;
  87. v = (unsigned int *) c->x86_model_id;
  88. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  89. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  90. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  91. c->x86_model_id[48] = 0;
  92. /* Intel chips right-justify this string for some dumb reason;
  93. undo that brain damage */
  94. p = q = &c->x86_model_id[0];
  95. while ( *p == ' ' )
  96. p++;
  97. if ( p != q ) {
  98. while ( *p )
  99. *q++ = *p++;
  100. while ( q <= &c->x86_model_id[48] )
  101. *q++ = '\0'; /* Zero-pad the rest */
  102. }
  103. return 1;
  104. }
  105. void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  106. {
  107. unsigned int n, dummy, ecx, edx, l2size;
  108. n = cpuid_eax(0x80000000);
  109. if (n >= 0x80000005) {
  110. cpuid(0x80000005, &dummy, &dummy, &ecx, &edx);
  111. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
  112. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  113. c->x86_cache_size=(ecx>>24)+(edx>>24);
  114. }
  115. if (n < 0x80000006) /* Some chips just has a large L1. */
  116. return;
  117. ecx = cpuid_ecx(0x80000006);
  118. l2size = ecx >> 16;
  119. /* do processor-specific cache resizing */
  120. if (this_cpu->c_size_cache)
  121. l2size = this_cpu->c_size_cache(c,l2size);
  122. /* Allow user to override all this if necessary. */
  123. if (cachesize_override != -1)
  124. l2size = cachesize_override;
  125. if ( l2size == 0 )
  126. return; /* Again, no L2 cache is possible */
  127. c->x86_cache_size = l2size;
  128. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  129. l2size, ecx & 0xFF);
  130. }
  131. /* Naming convention should be: <Name> [(<Codename>)] */
  132. /* This table only is used unless init_<vendor>() below doesn't set it; */
  133. /* in particular, if CPUID levels 0x80000002..4 are supported, this isn't used */
  134. /* Look up CPU names by table lookup. */
  135. static char __cpuinit *table_lookup_model(struct cpuinfo_x86 *c)
  136. {
  137. struct cpu_model_info *info;
  138. if ( c->x86_model >= 16 )
  139. return NULL; /* Range check */
  140. if (!this_cpu)
  141. return NULL;
  142. info = this_cpu->c_models;
  143. while (info && info->family) {
  144. if (info->family == c->x86)
  145. return info->model_names[c->x86_model];
  146. info++;
  147. }
  148. return NULL; /* Not found */
  149. }
  150. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c, int early)
  151. {
  152. char *v = c->x86_vendor_id;
  153. int i;
  154. static int printed;
  155. for (i = 0; i < X86_VENDOR_NUM; i++) {
  156. if (cpu_devs[i]) {
  157. if (!strcmp(v,cpu_devs[i]->c_ident[0]) ||
  158. (cpu_devs[i]->c_ident[1] &&
  159. !strcmp(v,cpu_devs[i]->c_ident[1]))) {
  160. c->x86_vendor = i;
  161. if (!early)
  162. this_cpu = cpu_devs[i];
  163. return;
  164. }
  165. }
  166. }
  167. if (!printed) {
  168. printed++;
  169. printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
  170. printk(KERN_ERR "CPU: Your system may be unstable.\n");
  171. }
  172. c->x86_vendor = X86_VENDOR_UNKNOWN;
  173. this_cpu = &default_cpu;
  174. }
  175. static int __init x86_fxsr_setup(char * s)
  176. {
  177. /* Tell all the other CPU's to not use it... */
  178. disable_x86_fxsr = 1;
  179. /*
  180. * ... and clear the bits early in the boot_cpu_data
  181. * so that the bootup process doesn't try to do this
  182. * either.
  183. */
  184. clear_bit(X86_FEATURE_FXSR, boot_cpu_data.x86_capability);
  185. clear_bit(X86_FEATURE_XMM, boot_cpu_data.x86_capability);
  186. return 1;
  187. }
  188. __setup("nofxsr", x86_fxsr_setup);
  189. static int __init x86_sep_setup(char * s)
  190. {
  191. disable_x86_sep = 1;
  192. return 1;
  193. }
  194. __setup("nosep", x86_sep_setup);
  195. /* Standard macro to see if a specific flag is changeable */
  196. static inline int flag_is_changeable_p(u32 flag)
  197. {
  198. u32 f1, f2;
  199. asm("pushfl\n\t"
  200. "pushfl\n\t"
  201. "popl %0\n\t"
  202. "movl %0,%1\n\t"
  203. "xorl %2,%0\n\t"
  204. "pushl %0\n\t"
  205. "popfl\n\t"
  206. "pushfl\n\t"
  207. "popl %0\n\t"
  208. "popfl\n\t"
  209. : "=&r" (f1), "=&r" (f2)
  210. : "ir" (flag));
  211. return ((f1^f2) & flag) != 0;
  212. }
  213. /* Probe for the CPUID instruction */
  214. static int __cpuinit have_cpuid_p(void)
  215. {
  216. return flag_is_changeable_p(X86_EFLAGS_ID);
  217. }
  218. void __init cpu_detect(struct cpuinfo_x86 *c)
  219. {
  220. /* Get vendor name */
  221. cpuid(0x00000000, &c->cpuid_level,
  222. (int *)&c->x86_vendor_id[0],
  223. (int *)&c->x86_vendor_id[8],
  224. (int *)&c->x86_vendor_id[4]);
  225. c->x86 = 4;
  226. if (c->cpuid_level >= 0x00000001) {
  227. u32 junk, tfms, cap0, misc;
  228. cpuid(0x00000001, &tfms, &misc, &junk, &cap0);
  229. c->x86 = (tfms >> 8) & 15;
  230. c->x86_model = (tfms >> 4) & 15;
  231. if (c->x86 == 0xf)
  232. c->x86 += (tfms >> 20) & 0xff;
  233. if (c->x86 >= 0x6)
  234. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  235. c->x86_mask = tfms & 15;
  236. if (cap0 & (1<<19))
  237. c->x86_cache_alignment = ((misc >> 8) & 0xff) * 8;
  238. }
  239. }
  240. /* Do minimum CPU detection early.
  241. Fields really needed: vendor, cpuid_level, family, model, mask, cache alignment.
  242. The others are not touched to avoid unwanted side effects.
  243. WARNING: this function is only called on the BP. Don't add code here
  244. that is supposed to run on all CPUs. */
  245. static void __init early_cpu_detect(void)
  246. {
  247. struct cpuinfo_x86 *c = &boot_cpu_data;
  248. c->x86_cache_alignment = 32;
  249. if (!have_cpuid_p())
  250. return;
  251. cpu_detect(c);
  252. get_cpu_vendor(c, 1);
  253. }
  254. static void __cpuinit generic_identify(struct cpuinfo_x86 * c)
  255. {
  256. u32 tfms, xlvl;
  257. int ebx;
  258. if (have_cpuid_p()) {
  259. /* Get vendor name */
  260. cpuid(0x00000000, &c->cpuid_level,
  261. (int *)&c->x86_vendor_id[0],
  262. (int *)&c->x86_vendor_id[8],
  263. (int *)&c->x86_vendor_id[4]);
  264. get_cpu_vendor(c, 0);
  265. /* Initialize the standard set of capabilities */
  266. /* Note that the vendor-specific code below might override */
  267. /* Intel-defined flags: level 0x00000001 */
  268. if ( c->cpuid_level >= 0x00000001 ) {
  269. u32 capability, excap;
  270. cpuid(0x00000001, &tfms, &ebx, &excap, &capability);
  271. c->x86_capability[0] = capability;
  272. c->x86_capability[4] = excap;
  273. c->x86 = (tfms >> 8) & 15;
  274. c->x86_model = (tfms >> 4) & 15;
  275. if (c->x86 == 0xf)
  276. c->x86 += (tfms >> 20) & 0xff;
  277. if (c->x86 >= 0x6)
  278. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  279. c->x86_mask = tfms & 15;
  280. #ifdef CONFIG_X86_HT
  281. c->apicid = phys_pkg_id((ebx >> 24) & 0xFF, 0);
  282. #else
  283. c->apicid = (ebx >> 24) & 0xFF;
  284. #endif
  285. if (c->x86_capability[0] & (1<<19))
  286. c->x86_clflush_size = ((ebx >> 8) & 0xff) * 8;
  287. } else {
  288. /* Have CPUID level 0 only - unheard of */
  289. c->x86 = 4;
  290. }
  291. /* AMD-defined flags: level 0x80000001 */
  292. xlvl = cpuid_eax(0x80000000);
  293. if ( (xlvl & 0xffff0000) == 0x80000000 ) {
  294. if ( xlvl >= 0x80000001 ) {
  295. c->x86_capability[1] = cpuid_edx(0x80000001);
  296. c->x86_capability[6] = cpuid_ecx(0x80000001);
  297. }
  298. if ( xlvl >= 0x80000004 )
  299. get_model_name(c); /* Default name */
  300. }
  301. }
  302. early_intel_workaround(c);
  303. #ifdef CONFIG_X86_HT
  304. c->phys_proc_id = (cpuid_ebx(1) >> 24) & 0xff;
  305. #endif
  306. }
  307. static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c)
  308. {
  309. if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr ) {
  310. /* Disable processor serial number */
  311. unsigned long lo,hi;
  312. rdmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
  313. lo |= 0x200000;
  314. wrmsr(MSR_IA32_BBL_CR_CTL,lo,hi);
  315. printk(KERN_NOTICE "CPU serial number disabled.\n");
  316. clear_bit(X86_FEATURE_PN, c->x86_capability);
  317. /* Disabling the serial number may affect the cpuid level */
  318. c->cpuid_level = cpuid_eax(0);
  319. }
  320. }
  321. static int __init x86_serial_nr_setup(char *s)
  322. {
  323. disable_x86_serial_nr = 0;
  324. return 1;
  325. }
  326. __setup("serialnumber", x86_serial_nr_setup);
  327. /*
  328. * This does the hard work of actually picking apart the CPU stuff...
  329. */
  330. static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  331. {
  332. int i;
  333. c->loops_per_jiffy = loops_per_jiffy;
  334. c->x86_cache_size = -1;
  335. c->x86_vendor = X86_VENDOR_UNKNOWN;
  336. c->cpuid_level = -1; /* CPUID not detected */
  337. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  338. c->x86_vendor_id[0] = '\0'; /* Unset */
  339. c->x86_model_id[0] = '\0'; /* Unset */
  340. c->x86_max_cores = 1;
  341. c->x86_clflush_size = 32;
  342. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  343. if (!have_cpuid_p()) {
  344. /* First of all, decide if this is a 486 or higher */
  345. /* It's a 486 if we can modify the AC flag */
  346. if ( flag_is_changeable_p(X86_EFLAGS_AC) )
  347. c->x86 = 4;
  348. else
  349. c->x86 = 3;
  350. }
  351. generic_identify(c);
  352. printk(KERN_DEBUG "CPU: After generic identify, caps:");
  353. for (i = 0; i < NCAPINTS; i++)
  354. printk(" %08lx", c->x86_capability[i]);
  355. printk("\n");
  356. if (this_cpu->c_identify) {
  357. this_cpu->c_identify(c);
  358. printk(KERN_DEBUG "CPU: After vendor identify, caps:");
  359. for (i = 0; i < NCAPINTS; i++)
  360. printk(" %08lx", c->x86_capability[i]);
  361. printk("\n");
  362. }
  363. /*
  364. * Vendor-specific initialization. In this section we
  365. * canonicalize the feature flags, meaning if there are
  366. * features a certain CPU supports which CPUID doesn't
  367. * tell us, CPUID claiming incorrect flags, or other bugs,
  368. * we handle them here.
  369. *
  370. * At the end of this section, c->x86_capability better
  371. * indicate the features this CPU genuinely supports!
  372. */
  373. if (this_cpu->c_init)
  374. this_cpu->c_init(c);
  375. /* Disable the PN if appropriate */
  376. squash_the_stupid_serial_number(c);
  377. /*
  378. * The vendor-specific functions might have changed features. Now
  379. * we do "generic changes."
  380. */
  381. /* TSC disabled? */
  382. if ( tsc_disable )
  383. clear_bit(X86_FEATURE_TSC, c->x86_capability);
  384. /* FXSR disabled? */
  385. if (disable_x86_fxsr) {
  386. clear_bit(X86_FEATURE_FXSR, c->x86_capability);
  387. clear_bit(X86_FEATURE_XMM, c->x86_capability);
  388. }
  389. /* SEP disabled? */
  390. if (disable_x86_sep)
  391. clear_bit(X86_FEATURE_SEP, c->x86_capability);
  392. if (disable_pse)
  393. clear_bit(X86_FEATURE_PSE, c->x86_capability);
  394. /* If the model name is still unset, do table lookup. */
  395. if ( !c->x86_model_id[0] ) {
  396. char *p;
  397. p = table_lookup_model(c);
  398. if ( p )
  399. strcpy(c->x86_model_id, p);
  400. else
  401. /* Last resort... */
  402. sprintf(c->x86_model_id, "%02x/%02x",
  403. c->x86, c->x86_model);
  404. }
  405. /* Now the feature flags better reflect actual CPU features! */
  406. printk(KERN_DEBUG "CPU: After all inits, caps:");
  407. for (i = 0; i < NCAPINTS; i++)
  408. printk(" %08lx", c->x86_capability[i]);
  409. printk("\n");
  410. /*
  411. * On SMP, boot_cpu_data holds the common feature set between
  412. * all CPUs; so make sure that we indicate which features are
  413. * common between the CPUs. The first time this routine gets
  414. * executed, c == &boot_cpu_data.
  415. */
  416. if ( c != &boot_cpu_data ) {
  417. /* AND the already accumulated flags with these */
  418. for ( i = 0 ; i < NCAPINTS ; i++ )
  419. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  420. }
  421. /* Init Machine Check Exception if available. */
  422. mcheck_init(c);
  423. }
  424. void __init identify_boot_cpu(void)
  425. {
  426. identify_cpu(&boot_cpu_data);
  427. sysenter_setup();
  428. enable_sep_cpu();
  429. mtrr_bp_init();
  430. }
  431. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  432. {
  433. BUG_ON(c == &boot_cpu_data);
  434. identify_cpu(c);
  435. enable_sep_cpu();
  436. mtrr_ap_init();
  437. }
  438. #ifdef CONFIG_X86_HT
  439. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  440. {
  441. u32 eax, ebx, ecx, edx;
  442. int index_msb, core_bits;
  443. cpuid(1, &eax, &ebx, &ecx, &edx);
  444. if (!cpu_has(c, X86_FEATURE_HT) || cpu_has(c, X86_FEATURE_CMP_LEGACY))
  445. return;
  446. smp_num_siblings = (ebx & 0xff0000) >> 16;
  447. if (smp_num_siblings == 1) {
  448. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  449. } else if (smp_num_siblings > 1 ) {
  450. if (smp_num_siblings > NR_CPUS) {
  451. printk(KERN_WARNING "CPU: Unsupported number of the "
  452. "siblings %d", smp_num_siblings);
  453. smp_num_siblings = 1;
  454. return;
  455. }
  456. index_msb = get_count_order(smp_num_siblings);
  457. c->phys_proc_id = phys_pkg_id((ebx >> 24) & 0xFF, index_msb);
  458. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  459. c->phys_proc_id);
  460. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  461. index_msb = get_count_order(smp_num_siblings) ;
  462. core_bits = get_count_order(c->x86_max_cores);
  463. c->cpu_core_id = phys_pkg_id((ebx >> 24) & 0xFF, index_msb) &
  464. ((1 << core_bits) - 1);
  465. if (c->x86_max_cores > 1)
  466. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  467. c->cpu_core_id);
  468. }
  469. }
  470. #endif
  471. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  472. {
  473. char *vendor = NULL;
  474. if (c->x86_vendor < X86_VENDOR_NUM)
  475. vendor = this_cpu->c_vendor;
  476. else if (c->cpuid_level >= 0)
  477. vendor = c->x86_vendor_id;
  478. if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor)))
  479. printk("%s ", vendor);
  480. if (!c->x86_model_id[0])
  481. printk("%d86", c->x86);
  482. else
  483. printk("%s", c->x86_model_id);
  484. if (c->x86_mask || c->cpuid_level >= 0)
  485. printk(" stepping %02x\n", c->x86_mask);
  486. else
  487. printk("\n");
  488. }
  489. cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE;
  490. /* This is hacky. :)
  491. * We're emulating future behavior.
  492. * In the future, the cpu-specific init functions will be called implicitly
  493. * via the magic of initcalls.
  494. * They will insert themselves into the cpu_devs structure.
  495. * Then, when cpu_init() is called, we can just iterate over that array.
  496. */
  497. extern int intel_cpu_init(void);
  498. extern int cyrix_init_cpu(void);
  499. extern int nsc_init_cpu(void);
  500. extern int amd_init_cpu(void);
  501. extern int centaur_init_cpu(void);
  502. extern int transmeta_init_cpu(void);
  503. extern int rise_init_cpu(void);
  504. extern int nexgen_init_cpu(void);
  505. extern int umc_init_cpu(void);
  506. void __init early_cpu_init(void)
  507. {
  508. intel_cpu_init();
  509. cyrix_init_cpu();
  510. nsc_init_cpu();
  511. amd_init_cpu();
  512. centaur_init_cpu();
  513. transmeta_init_cpu();
  514. rise_init_cpu();
  515. nexgen_init_cpu();
  516. umc_init_cpu();
  517. early_cpu_detect();
  518. #ifdef CONFIG_DEBUG_PAGEALLOC
  519. /* pse is not compatible with on-the-fly unmapping,
  520. * disable it even if the cpus claim to support it.
  521. */
  522. clear_bit(X86_FEATURE_PSE, boot_cpu_data.x86_capability);
  523. disable_pse = 1;
  524. #endif
  525. }
  526. /* Make sure %gs is initialized properly in idle threads */
  527. struct pt_regs * __devinit idle_regs(struct pt_regs *regs)
  528. {
  529. memset(regs, 0, sizeof(struct pt_regs));
  530. regs->xfs = __KERNEL_PDA;
  531. return regs;
  532. }
  533. /* Initial PDA used by boot CPU */
  534. struct i386_pda boot_pda = {
  535. ._pda = &boot_pda,
  536. .cpu_number = 0,
  537. .pcurrent = &init_task,
  538. };
  539. /*
  540. * cpu_init() initializes state that is per-CPU. Some data is already
  541. * initialized (naturally) in the bootstrap process, such as the GDT
  542. * and IDT. We reload them nevertheless, this function acts as a
  543. * 'CPU state barrier', nothing should get across.
  544. */
  545. void __cpuinit cpu_init(void)
  546. {
  547. int cpu = smp_processor_id();
  548. struct task_struct *curr = current;
  549. struct tss_struct * t = &per_cpu(init_tss, cpu);
  550. struct thread_struct *thread = &curr->thread;
  551. if (cpu_test_and_set(cpu, cpu_initialized)) {
  552. printk(KERN_WARNING "CPU#%d already initialized!\n", cpu);
  553. for (;;) local_irq_enable();
  554. }
  555. printk(KERN_INFO "Initializing CPU#%d\n", cpu);
  556. if (cpu_has_vme || cpu_has_tsc || cpu_has_de)
  557. clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE);
  558. if (tsc_disable && cpu_has_tsc) {
  559. printk(KERN_NOTICE "Disabling TSC...\n");
  560. /**** FIX-HPA: DOES THIS REALLY BELONG HERE? ****/
  561. clear_bit(X86_FEATURE_TSC, boot_cpu_data.x86_capability);
  562. set_in_cr4(X86_CR4_TSD);
  563. }
  564. load_idt(&idt_descr);
  565. /*
  566. * Set up and load the per-CPU TSS and LDT
  567. */
  568. atomic_inc(&init_mm.mm_count);
  569. curr->active_mm = &init_mm;
  570. if (curr->mm)
  571. BUG();
  572. enter_lazy_tlb(&init_mm, curr);
  573. load_esp0(t, thread);
  574. set_tss_desc(cpu,t);
  575. load_TR_desc();
  576. load_LDT(&init_mm.context);
  577. #ifdef CONFIG_DOUBLEFAULT
  578. /* Set up doublefault TSS pointer in the GDT */
  579. __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss);
  580. #endif
  581. /* Clear %gs. */
  582. asm volatile ("mov %0, %%gs" : : "r" (0));
  583. /* Clear all 6 debug registers: */
  584. set_debugreg(0, 0);
  585. set_debugreg(0, 1);
  586. set_debugreg(0, 2);
  587. set_debugreg(0, 3);
  588. set_debugreg(0, 6);
  589. set_debugreg(0, 7);
  590. /*
  591. * Force FPU initialization:
  592. */
  593. current_thread_info()->status = 0;
  594. clear_used_math();
  595. mxcsr_feature_mask_init();
  596. }
  597. #ifdef CONFIG_HOTPLUG_CPU
  598. void __cpuinit cpu_uninit(void)
  599. {
  600. int cpu = raw_smp_processor_id();
  601. cpu_clear(cpu, cpu_initialized);
  602. /* lazy TLB state */
  603. per_cpu(cpu_tlbstate, cpu).state = 0;
  604. per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm;
  605. }
  606. #endif