common.c 18 KB

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