setup_64.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. */
  4. /*
  5. * This file handles the architecture-dependent parts of initialization
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/sched.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mm.h>
  11. #include <linux/stddef.h>
  12. #include <linux/unistd.h>
  13. #include <linux/ptrace.h>
  14. #include <linux/slab.h>
  15. #include <linux/user.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/ioport.h>
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #include <linux/initrd.h>
  21. #include <linux/highmem.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/module.h>
  24. #include <asm/processor.h>
  25. #include <linux/console.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/crash_dump.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/pci.h>
  30. #include <asm/pci-direct.h>
  31. #include <linux/efi.h>
  32. #include <linux/acpi.h>
  33. #include <linux/kallsyms.h>
  34. #include <linux/edd.h>
  35. #include <linux/iscsi_ibft.h>
  36. #include <linux/mmzone.h>
  37. #include <linux/kexec.h>
  38. #include <linux/cpufreq.h>
  39. #include <linux/dmi.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/ctype.h>
  42. #include <linux/sort.h>
  43. #include <linux/uaccess.h>
  44. #include <linux/init_ohci1394_dma.h>
  45. #include <linux/kvm_para.h>
  46. #include <asm/mtrr.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/system.h>
  49. #include <asm/vsyscall.h>
  50. #include <asm/io.h>
  51. #include <asm/smp.h>
  52. #include <asm/msr.h>
  53. #include <asm/desc.h>
  54. #include <video/edid.h>
  55. #include <asm/e820.h>
  56. #include <asm/mpspec.h>
  57. #include <asm/dma.h>
  58. #include <asm/gart.h>
  59. #include <asm/mpspec.h>
  60. #include <asm/mmu_context.h>
  61. #include <asm/proto.h>
  62. #include <asm/setup.h>
  63. #include <asm/numa.h>
  64. #include <asm/sections.h>
  65. #include <asm/dmi.h>
  66. #include <asm/cacheflush.h>
  67. #include <asm/mce.h>
  68. #include <asm/ds.h>
  69. #include <asm/topology.h>
  70. #include <asm/trampoline.h>
  71. #include <asm/pat.h>
  72. #include <mach_apic.h>
  73. #ifdef CONFIG_PARAVIRT
  74. #include <asm/paravirt.h>
  75. #else
  76. #define ARCH_SETUP
  77. #endif
  78. /*
  79. * Machine setup..
  80. */
  81. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  82. EXPORT_SYMBOL(boot_cpu_data);
  83. __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
  84. unsigned long mmu_cr4_features;
  85. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  86. int bootloader_type;
  87. unsigned long saved_video_mode;
  88. /*
  89. * Early DMI memory
  90. */
  91. int dmi_alloc_index;
  92. char dmi_alloc_data[DMI_MAX_DATA];
  93. /*
  94. * Setup options
  95. */
  96. struct screen_info screen_info;
  97. EXPORT_SYMBOL(screen_info);
  98. struct sys_desc_table_struct {
  99. unsigned short length;
  100. unsigned char table[0];
  101. };
  102. struct edid_info edid_info;
  103. EXPORT_SYMBOL_GPL(edid_info);
  104. extern int root_mountflags;
  105. static char __initdata command_line[COMMAND_LINE_SIZE];
  106. static struct resource standard_io_resources[] = {
  107. { .name = "dma1", .start = 0x00, .end = 0x1f,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  109. { .name = "pic1", .start = 0x20, .end = 0x21,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  111. { .name = "timer0", .start = 0x40, .end = 0x43,
  112. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  113. { .name = "timer1", .start = 0x50, .end = 0x53,
  114. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  115. { .name = "keyboard", .start = 0x60, .end = 0x60,
  116. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  117. { .name = "keyboard", .start = 0x64, .end = 0x64,
  118. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  119. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  120. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  121. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  122. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  123. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  124. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  125. { .name = "fpu", .start = 0xf0, .end = 0xff,
  126. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  127. };
  128. #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
  129. static struct resource data_resource = {
  130. .name = "Kernel data",
  131. .start = 0,
  132. .end = 0,
  133. .flags = IORESOURCE_RAM,
  134. };
  135. static struct resource code_resource = {
  136. .name = "Kernel code",
  137. .start = 0,
  138. .end = 0,
  139. .flags = IORESOURCE_RAM,
  140. };
  141. static struct resource bss_resource = {
  142. .name = "Kernel bss",
  143. .start = 0,
  144. .end = 0,
  145. .flags = IORESOURCE_RAM,
  146. };
  147. static void __init early_cpu_init(void);
  148. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
  149. #ifdef CONFIG_PROC_VMCORE
  150. /* elfcorehdr= specifies the location of elf core header
  151. * stored by the crashed kernel. This option will be passed
  152. * by kexec loader to the capture kernel.
  153. */
  154. static int __init setup_elfcorehdr(char *arg)
  155. {
  156. char *end;
  157. if (!arg)
  158. return -EINVAL;
  159. elfcorehdr_addr = memparse(arg, &end);
  160. return end > arg ? 0 : -EINVAL;
  161. }
  162. early_param("elfcorehdr", setup_elfcorehdr);
  163. #endif
  164. #ifndef CONFIG_NUMA
  165. static void __init
  166. contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  167. {
  168. unsigned long bootmap_size, bootmap;
  169. bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
  170. bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
  171. PAGE_SIZE);
  172. if (bootmap == -1L)
  173. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  174. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
  175. e820_register_active_regions(0, start_pfn, end_pfn);
  176. free_bootmem_with_active_regions(0, end_pfn);
  177. early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
  178. reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
  179. }
  180. #endif
  181. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  182. struct edd edd;
  183. #ifdef CONFIG_EDD_MODULE
  184. EXPORT_SYMBOL(edd);
  185. #endif
  186. /**
  187. * copy_edd() - Copy the BIOS EDD information
  188. * from boot_params into a safe place.
  189. *
  190. */
  191. static inline void copy_edd(void)
  192. {
  193. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  194. sizeof(edd.mbr_signature));
  195. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  196. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  197. edd.edd_info_nr = boot_params.eddbuf_entries;
  198. }
  199. #else
  200. static inline void copy_edd(void)
  201. {
  202. }
  203. #endif
  204. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  205. void __attribute__((weak)) __init memory_setup(void)
  206. {
  207. machine_specific_memory_setup();
  208. }
  209. /* Current gdt points %fs at the "master" per-cpu area: after this,
  210. * it's on the real one. */
  211. void switch_to_new_gdt(void)
  212. {
  213. struct desc_ptr gdt_descr;
  214. gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id());
  215. gdt_descr.size = GDT_SIZE - 1;
  216. load_gdt(&gdt_descr);
  217. }
  218. /*
  219. * setup_arch - architecture-specific boot-time initializations
  220. *
  221. * Note: On x86_64, fixmaps are ready for use even before this is called.
  222. */
  223. void __init setup_arch(char **cmdline_p)
  224. {
  225. unsigned i;
  226. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  227. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  228. screen_info = boot_params.screen_info;
  229. edid_info = boot_params.edid_info;
  230. saved_video_mode = boot_params.hdr.vid_mode;
  231. bootloader_type = boot_params.hdr.type_of_loader;
  232. #ifdef CONFIG_BLK_DEV_RAM
  233. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  234. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  235. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  236. #endif
  237. #ifdef CONFIG_EFI
  238. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  239. "EL64", 4)) {
  240. efi_enabled = 1;
  241. efi_reserve_early();
  242. }
  243. #endif
  244. ARCH_SETUP
  245. setup_memory_map();
  246. copy_edd();
  247. if (!boot_params.hdr.root_flags)
  248. root_mountflags &= ~MS_RDONLY;
  249. init_mm.start_code = (unsigned long) &_text;
  250. init_mm.end_code = (unsigned long) &_etext;
  251. init_mm.end_data = (unsigned long) &_edata;
  252. init_mm.brk = (unsigned long) &_end;
  253. code_resource.start = virt_to_phys(&_text);
  254. code_resource.end = virt_to_phys(&_etext)-1;
  255. data_resource.start = virt_to_phys(&_etext);
  256. data_resource.end = virt_to_phys(&_edata)-1;
  257. bss_resource.start = virt_to_phys(&__bss_start);
  258. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  259. early_cpu_init();
  260. early_identify_cpu(&boot_cpu_data);
  261. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  262. *cmdline_p = command_line;
  263. parse_setup_data();
  264. parse_early_param();
  265. if (acpi_mps_check()) {
  266. disable_apic = 1;
  267. clear_cpu_cap(&boot_cpu_data, X86_FEATURE_APIC);
  268. }
  269. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  270. if (init_ohci1394_dma_early)
  271. init_ohci1394_dma_on_all_controllers();
  272. #endif
  273. finish_e820_parsing();
  274. /* after parse_early_param, so could debug it */
  275. insert_resource(&iomem_resource, &code_resource);
  276. insert_resource(&iomem_resource, &data_resource);
  277. insert_resource(&iomem_resource, &bss_resource);
  278. early_gart_iommu_check();
  279. e820_register_active_regions(0, 0, -1UL);
  280. /*
  281. * partially used pages are not usable - thus
  282. * we are rounding upwards:
  283. */
  284. end_pfn = e820_end_of_ram();
  285. /* pre allocte 4k for mptable mpc */
  286. early_reserve_e820_mpc_new();
  287. /* update e820 for memory not covered by WB MTRRs */
  288. mtrr_bp_init();
  289. if (mtrr_trim_uncached_memory(end_pfn)) {
  290. remove_all_active_ranges();
  291. e820_register_active_regions(0, 0, -1UL);
  292. end_pfn = e820_end_of_ram();
  293. }
  294. num_physpages = end_pfn;
  295. check_efer();
  296. max_pfn_mapped = init_memory_mapping(0, (end_pfn << PAGE_SHIFT));
  297. if (efi_enabled)
  298. efi_init();
  299. vsmp_init();
  300. dmi_scan_machine();
  301. io_delay_init();
  302. #ifdef CONFIG_KVM_CLOCK
  303. kvmclock_init();
  304. #endif
  305. #ifdef CONFIG_ACPI
  306. /*
  307. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  308. * Call this early for SRAT node setup.
  309. */
  310. acpi_boot_table_init();
  311. #endif
  312. /* How many end-of-memory variables you have, grandma! */
  313. max_low_pfn = end_pfn;
  314. max_pfn = end_pfn;
  315. high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
  316. /* Remove active ranges so rediscovery with NUMA-awareness happens */
  317. remove_all_active_ranges();
  318. #ifdef CONFIG_ACPI_NUMA
  319. /*
  320. * Parse SRAT to discover nodes.
  321. */
  322. acpi_numa_init();
  323. #endif
  324. #ifdef CONFIG_NUMA
  325. numa_initmem_init(0, end_pfn);
  326. #else
  327. contig_initmem_init(0, end_pfn);
  328. #endif
  329. dma32_reserve_bootmem();
  330. #ifdef CONFIG_ACPI_SLEEP
  331. /*
  332. * Reserve low memory region for sleep support.
  333. */
  334. acpi_reserve_bootmem();
  335. #endif
  336. #ifdef CONFIG_X86_MPPARSE
  337. /*
  338. * Find and reserve possible boot-time SMP configuration:
  339. */
  340. find_smp_config();
  341. #endif
  342. #ifdef CONFIG_BLK_DEV_INITRD
  343. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  344. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  345. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  346. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  347. unsigned long end_of_mem = end_pfn << PAGE_SHIFT;
  348. if (ramdisk_end <= end_of_mem) {
  349. /*
  350. * don't need to reserve again, already reserved early
  351. * in x86_64_start_kernel, and early_res_to_bootmem
  352. * convert that to reserved in bootmem
  353. */
  354. initrd_start = ramdisk_image + PAGE_OFFSET;
  355. initrd_end = initrd_start+ramdisk_size;
  356. } else {
  357. free_bootmem(ramdisk_image, ramdisk_size);
  358. printk(KERN_ERR "initrd extends beyond end of memory "
  359. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  360. ramdisk_end, end_of_mem);
  361. initrd_start = 0;
  362. }
  363. }
  364. #endif
  365. reserve_crashkernel();
  366. reserve_ibft_region();
  367. paging_init();
  368. map_vsyscall();
  369. early_quirks();
  370. #ifdef CONFIG_ACPI
  371. /*
  372. * Read APIC and some other early information from ACPI tables.
  373. */
  374. acpi_boot_init();
  375. #endif
  376. init_cpu_to_node();
  377. #ifdef CONFIG_X86_MPPARSE
  378. /*
  379. * get boot-time SMP configuration:
  380. */
  381. if (smp_found_config)
  382. get_smp_config();
  383. #endif
  384. init_apic_mappings();
  385. ioapic_init_mappings();
  386. kvm_guest_init();
  387. /*
  388. * We trust e820 completely. No explicit ROM probing in memory.
  389. */
  390. e820_reserve_resources();
  391. e820_mark_nosave_regions(end_pfn);
  392. /* request I/O space for devices used on all i[345]86 PCs */
  393. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  394. request_resource(&ioport_resource, &standard_io_resources[i]);
  395. e820_setup_gap();
  396. #ifdef CONFIG_VT
  397. #if defined(CONFIG_VGA_CONSOLE)
  398. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  399. conswitchp = &vga_con;
  400. #elif defined(CONFIG_DUMMY_CONSOLE)
  401. conswitchp = &dummy_con;
  402. #endif
  403. #endif
  404. }
  405. struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
  406. static void __cpuinit default_init(struct cpuinfo_x86 *c)
  407. {
  408. display_cacheinfo(c);
  409. }
  410. static struct cpu_dev __cpuinitdata default_cpu = {
  411. .c_init = default_init,
  412. .c_vendor = "Unknown",
  413. };
  414. static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
  415. int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  416. {
  417. unsigned int *v;
  418. if (c->extended_cpuid_level < 0x80000004)
  419. return 0;
  420. v = (unsigned int *) c->x86_model_id;
  421. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  422. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  423. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  424. c->x86_model_id[48] = 0;
  425. return 1;
  426. }
  427. void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  428. {
  429. unsigned int n, dummy, eax, ebx, ecx, edx;
  430. n = c->extended_cpuid_level;
  431. if (n >= 0x80000005) {
  432. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  433. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
  434. "D cache %dK (%d bytes/line)\n",
  435. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  436. c->x86_cache_size = (ecx>>24) + (edx>>24);
  437. /* On K8 L1 TLB is inclusive, so don't count it */
  438. c->x86_tlbsize = 0;
  439. }
  440. if (n >= 0x80000006) {
  441. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  442. ecx = cpuid_ecx(0x80000006);
  443. c->x86_cache_size = ecx >> 16;
  444. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  445. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  446. c->x86_cache_size, ecx & 0xFF);
  447. }
  448. if (n >= 0x80000008) {
  449. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  450. c->x86_virt_bits = (eax >> 8) & 0xff;
  451. c->x86_phys_bits = eax & 0xff;
  452. }
  453. }
  454. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  455. {
  456. #ifdef CONFIG_SMP
  457. u32 eax, ebx, ecx, edx;
  458. int index_msb, core_bits;
  459. cpuid(1, &eax, &ebx, &ecx, &edx);
  460. if (!cpu_has(c, X86_FEATURE_HT))
  461. return;
  462. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  463. goto out;
  464. smp_num_siblings = (ebx & 0xff0000) >> 16;
  465. if (smp_num_siblings == 1) {
  466. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  467. } else if (smp_num_siblings > 1) {
  468. if (smp_num_siblings > NR_CPUS) {
  469. printk(KERN_WARNING "CPU: Unsupported number of "
  470. "siblings %d", smp_num_siblings);
  471. smp_num_siblings = 1;
  472. return;
  473. }
  474. index_msb = get_count_order(smp_num_siblings);
  475. c->phys_proc_id = phys_pkg_id(index_msb);
  476. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  477. index_msb = get_count_order(smp_num_siblings);
  478. core_bits = get_count_order(c->x86_max_cores);
  479. c->cpu_core_id = phys_pkg_id(index_msb) &
  480. ((1 << core_bits) - 1);
  481. }
  482. out:
  483. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  484. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  485. c->phys_proc_id);
  486. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  487. c->cpu_core_id);
  488. }
  489. #endif
  490. }
  491. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  492. {
  493. char *v = c->x86_vendor_id;
  494. int i;
  495. static int printed;
  496. for (i = 0; i < X86_VENDOR_NUM; i++) {
  497. if (cpu_devs[i]) {
  498. if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
  499. (cpu_devs[i]->c_ident[1] &&
  500. !strcmp(v, cpu_devs[i]->c_ident[1]))) {
  501. c->x86_vendor = i;
  502. this_cpu = cpu_devs[i];
  503. return;
  504. }
  505. }
  506. }
  507. if (!printed) {
  508. printed++;
  509. printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
  510. printk(KERN_ERR "CPU: Your system may be unstable.\n");
  511. }
  512. c->x86_vendor = X86_VENDOR_UNKNOWN;
  513. }
  514. static void __init early_cpu_support_print(void)
  515. {
  516. int i,j;
  517. struct cpu_dev *cpu_devx;
  518. printk("KERNEL supported cpus:\n");
  519. for (i = 0; i < X86_VENDOR_NUM; i++) {
  520. cpu_devx = cpu_devs[i];
  521. if (!cpu_devx)
  522. continue;
  523. for (j = 0; j < 2; j++) {
  524. if (!cpu_devx->c_ident[j])
  525. continue;
  526. printk(" %s %s\n", cpu_devx->c_vendor,
  527. cpu_devx->c_ident[j]);
  528. }
  529. }
  530. }
  531. static void __init early_cpu_init(void)
  532. {
  533. struct cpu_vendor_dev *cvdev;
  534. for (cvdev = __x86cpuvendor_start ;
  535. cvdev < __x86cpuvendor_end ;
  536. cvdev++)
  537. cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
  538. early_cpu_support_print();
  539. }
  540. /* Do some early cpuid on the boot CPU to get some parameter that are
  541. needed before check_bugs. Everything advanced is in identify_cpu
  542. below. */
  543. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  544. {
  545. u32 tfms, xlvl;
  546. c->loops_per_jiffy = loops_per_jiffy;
  547. c->x86_cache_size = -1;
  548. c->x86_vendor = X86_VENDOR_UNKNOWN;
  549. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  550. c->x86_vendor_id[0] = '\0'; /* Unset */
  551. c->x86_model_id[0] = '\0'; /* Unset */
  552. c->x86_clflush_size = 64;
  553. c->x86_cache_alignment = c->x86_clflush_size;
  554. c->x86_max_cores = 1;
  555. c->x86_coreid_bits = 0;
  556. c->extended_cpuid_level = 0;
  557. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  558. /* Get vendor name */
  559. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  560. (unsigned int *)&c->x86_vendor_id[0],
  561. (unsigned int *)&c->x86_vendor_id[8],
  562. (unsigned int *)&c->x86_vendor_id[4]);
  563. get_cpu_vendor(c);
  564. /* Initialize the standard set of capabilities */
  565. /* Note that the vendor-specific code below might override */
  566. /* Intel-defined flags: level 0x00000001 */
  567. if (c->cpuid_level >= 0x00000001) {
  568. __u32 misc;
  569. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  570. &c->x86_capability[0]);
  571. c->x86 = (tfms >> 8) & 0xf;
  572. c->x86_model = (tfms >> 4) & 0xf;
  573. c->x86_mask = tfms & 0xf;
  574. if (c->x86 == 0xf)
  575. c->x86 += (tfms >> 20) & 0xff;
  576. if (c->x86 >= 0x6)
  577. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  578. if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
  579. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  580. } else {
  581. /* Have CPUID level 0 only - unheard of */
  582. c->x86 = 4;
  583. }
  584. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
  585. #ifdef CONFIG_SMP
  586. c->phys_proc_id = c->initial_apicid;
  587. #endif
  588. /* AMD-defined flags: level 0x80000001 */
  589. xlvl = cpuid_eax(0x80000000);
  590. c->extended_cpuid_level = xlvl;
  591. if ((xlvl & 0xffff0000) == 0x80000000) {
  592. if (xlvl >= 0x80000001) {
  593. c->x86_capability[1] = cpuid_edx(0x80000001);
  594. c->x86_capability[6] = cpuid_ecx(0x80000001);
  595. }
  596. if (xlvl >= 0x80000004)
  597. get_model_name(c); /* Default name */
  598. }
  599. /* Transmeta-defined flags: level 0x80860001 */
  600. xlvl = cpuid_eax(0x80860000);
  601. if ((xlvl & 0xffff0000) == 0x80860000) {
  602. /* Don't set x86_cpuid_level here for now to not confuse. */
  603. if (xlvl >= 0x80860001)
  604. c->x86_capability[2] = cpuid_edx(0x80860001);
  605. }
  606. c->extended_cpuid_level = cpuid_eax(0x80000000);
  607. if (c->extended_cpuid_level >= 0x80000007)
  608. c->x86_power = cpuid_edx(0x80000007);
  609. if (c->x86_vendor != X86_VENDOR_UNKNOWN &&
  610. cpu_devs[c->x86_vendor]->c_early_init)
  611. cpu_devs[c->x86_vendor]->c_early_init(c);
  612. validate_pat_support(c);
  613. /* early_param could clear that, but recall get it set again */
  614. if (disable_apic)
  615. clear_cpu_cap(c, X86_FEATURE_APIC);
  616. }
  617. /*
  618. * This does the hard work of actually picking apart the CPU stuff...
  619. */
  620. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  621. {
  622. int i;
  623. early_identify_cpu(c);
  624. init_scattered_cpuid_features(c);
  625. c->apicid = phys_pkg_id(0);
  626. /*
  627. * Vendor-specific initialization. In this section we
  628. * canonicalize the feature flags, meaning if there are
  629. * features a certain CPU supports which CPUID doesn't
  630. * tell us, CPUID claiming incorrect flags, or other bugs,
  631. * we handle them here.
  632. *
  633. * At the end of this section, c->x86_capability better
  634. * indicate the features this CPU genuinely supports!
  635. */
  636. if (this_cpu->c_init)
  637. this_cpu->c_init(c);
  638. detect_ht(c);
  639. /*
  640. * On SMP, boot_cpu_data holds the common feature set between
  641. * all CPUs; so make sure that we indicate which features are
  642. * common between the CPUs. The first time this routine gets
  643. * executed, c == &boot_cpu_data.
  644. */
  645. if (c != &boot_cpu_data) {
  646. /* AND the already accumulated flags with these */
  647. for (i = 0; i < NCAPINTS; i++)
  648. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  649. }
  650. /* Clear all flags overriden by options */
  651. for (i = 0; i < NCAPINTS; i++)
  652. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  653. #ifdef CONFIG_X86_MCE
  654. mcheck_init(c);
  655. #endif
  656. select_idle_routine(c);
  657. #ifdef CONFIG_NUMA
  658. numa_add_cpu(smp_processor_id());
  659. #endif
  660. }
  661. void __cpuinit identify_boot_cpu(void)
  662. {
  663. identify_cpu(&boot_cpu_data);
  664. }
  665. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  666. {
  667. BUG_ON(c == &boot_cpu_data);
  668. identify_cpu(c);
  669. mtrr_ap_init();
  670. }
  671. static __init int setup_noclflush(char *arg)
  672. {
  673. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  674. return 1;
  675. }
  676. __setup("noclflush", setup_noclflush);
  677. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  678. {
  679. if (c->x86_model_id[0])
  680. printk(KERN_CONT "%s", c->x86_model_id);
  681. if (c->x86_mask || c->cpuid_level >= 0)
  682. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  683. else
  684. printk(KERN_CONT "\n");
  685. }
  686. static __init int setup_disablecpuid(char *arg)
  687. {
  688. int bit;
  689. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  690. setup_clear_cpu_cap(bit);
  691. else
  692. return 0;
  693. return 1;
  694. }
  695. __setup("clearcpuid=", setup_disablecpuid);