common.c 17 KB

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