setup_64.c 21 KB

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