common.c 17 KB

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