setup_64.c 20 KB

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