common.c 16 KB

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