setup_64.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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/dma.h>
  57. #include <asm/gart.h>
  58. #include <asm/mpspec.h>
  59. #include <asm/mmu_context.h>
  60. #include <asm/proto.h>
  61. #include <asm/setup.h>
  62. #include <asm/numa.h>
  63. #include <asm/sections.h>
  64. #include <asm/dmi.h>
  65. #include <asm/cacheflush.h>
  66. #include <asm/mce.h>
  67. #include <asm/ds.h>
  68. #include <asm/topology.h>
  69. #include <asm/trampoline.h>
  70. #include <asm/pat.h>
  71. #include <asm/mmconfig.h>
  72. #include <mach_apic.h>
  73. #ifdef CONFIG_PARAVIRT
  74. #include <asm/paravirt.h>
  75. #else
  76. #define ARCH_SETUP
  77. #endif
  78. #include "cpu/cpu.h"
  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. 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. #ifdef CONFIG_KEXEC
  206. static void __init reserve_crashkernel(void)
  207. {
  208. unsigned long long total_mem;
  209. unsigned long long crash_size, crash_base;
  210. int ret;
  211. total_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
  212. ret = parse_crashkernel(boot_command_line, total_mem,
  213. &crash_size, &crash_base);
  214. if (ret == 0 && crash_size) {
  215. if (crash_base <= 0) {
  216. printk(KERN_INFO "crashkernel reservation failed - "
  217. "you have to specify a base address\n");
  218. return;
  219. }
  220. if (reserve_bootmem(crash_base, crash_size,
  221. BOOTMEM_EXCLUSIVE) < 0) {
  222. printk(KERN_INFO "crashkernel reservation failed - "
  223. "memory is in use\n");
  224. return;
  225. }
  226. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  227. "for crashkernel (System RAM: %ldMB)\n",
  228. (unsigned long)(crash_size >> 20),
  229. (unsigned long)(crash_base >> 20),
  230. (unsigned long)(total_mem >> 20));
  231. crashk_res.start = crash_base;
  232. crashk_res.end = crash_base + crash_size - 1;
  233. insert_resource(&iomem_resource, &crashk_res);
  234. }
  235. }
  236. #else
  237. static inline void __init reserve_crashkernel(void)
  238. {}
  239. #endif
  240. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  241. void __attribute__((weak)) __init memory_setup(void)
  242. {
  243. machine_specific_memory_setup();
  244. }
  245. static void __init parse_setup_data(void)
  246. {
  247. struct setup_data *data;
  248. unsigned long pa_data;
  249. if (boot_params.hdr.version < 0x0209)
  250. return;
  251. pa_data = boot_params.hdr.setup_data;
  252. while (pa_data) {
  253. data = early_ioremap(pa_data, PAGE_SIZE);
  254. switch (data->type) {
  255. default:
  256. break;
  257. }
  258. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  259. free_early(pa_data, pa_data+sizeof(*data)+data->len);
  260. #endif
  261. pa_data = data->next;
  262. early_iounmap(data, PAGE_SIZE);
  263. }
  264. }
  265. /*
  266. * setup_arch - architecture-specific boot-time initializations
  267. *
  268. * Note: On x86_64, fixmaps are ready for use even before this is called.
  269. */
  270. void __init setup_arch(char **cmdline_p)
  271. {
  272. unsigned i;
  273. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  274. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  275. screen_info = boot_params.screen_info;
  276. edid_info = boot_params.edid_info;
  277. saved_video_mode = boot_params.hdr.vid_mode;
  278. bootloader_type = boot_params.hdr.type_of_loader;
  279. #ifdef CONFIG_BLK_DEV_RAM
  280. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  281. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  282. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  283. #endif
  284. #ifdef CONFIG_EFI
  285. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  286. "EL64", 4))
  287. efi_enabled = 1;
  288. #endif
  289. ARCH_SETUP
  290. memory_setup();
  291. copy_edd();
  292. if (!boot_params.hdr.root_flags)
  293. root_mountflags &= ~MS_RDONLY;
  294. init_mm.start_code = (unsigned long) &_text;
  295. init_mm.end_code = (unsigned long) &_etext;
  296. init_mm.end_data = (unsigned long) &_edata;
  297. init_mm.brk = (unsigned long) &_end;
  298. code_resource.start = virt_to_phys(&_text);
  299. code_resource.end = virt_to_phys(&_etext)-1;
  300. data_resource.start = virt_to_phys(&_etext);
  301. data_resource.end = virt_to_phys(&_edata)-1;
  302. bss_resource.start = virt_to_phys(&__bss_start);
  303. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  304. early_cpu_init();
  305. early_identify_cpu(&boot_cpu_data);
  306. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  307. *cmdline_p = command_line;
  308. parse_setup_data();
  309. parse_early_param();
  310. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  311. if (init_ohci1394_dma_early)
  312. init_ohci1394_dma_on_all_controllers();
  313. #endif
  314. finish_e820_parsing();
  315. /* after parse_early_param, so could debug it */
  316. insert_resource(&iomem_resource, &code_resource);
  317. insert_resource(&iomem_resource, &data_resource);
  318. insert_resource(&iomem_resource, &bss_resource);
  319. early_gart_iommu_check();
  320. e820_register_active_regions(0, 0, -1UL);
  321. /*
  322. * partially used pages are not usable - thus
  323. * we are rounding upwards:
  324. */
  325. end_pfn = e820_end_of_ram();
  326. /* update e820 for memory not covered by WB MTRRs */
  327. mtrr_bp_init();
  328. if (mtrr_trim_uncached_memory(end_pfn)) {
  329. e820_register_active_regions(0, 0, -1UL);
  330. end_pfn = e820_end_of_ram();
  331. }
  332. num_physpages = end_pfn;
  333. check_efer();
  334. max_pfn_mapped = init_memory_mapping(0, (max_pfn_mapped << PAGE_SHIFT));
  335. if (efi_enabled)
  336. efi_init();
  337. vsmp_init();
  338. dmi_scan_machine();
  339. io_delay_init();
  340. #ifdef CONFIG_KVM_CLOCK
  341. kvmclock_init();
  342. #endif
  343. #ifdef CONFIG_SMP
  344. /* setup to use the early static init tables during kernel startup */
  345. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  346. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  347. #ifdef CONFIG_NUMA
  348. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  349. #endif
  350. #endif
  351. #ifdef CONFIG_ACPI
  352. /*
  353. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  354. * Call this early for SRAT node setup.
  355. */
  356. acpi_boot_table_init();
  357. #endif
  358. /* How many end-of-memory variables you have, grandma! */
  359. max_low_pfn = end_pfn;
  360. max_pfn = end_pfn;
  361. high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
  362. /* Remove active ranges so rediscovery with NUMA-awareness happens */
  363. remove_all_active_ranges();
  364. #ifdef CONFIG_ACPI_NUMA
  365. /*
  366. * Parse SRAT to discover nodes.
  367. */
  368. acpi_numa_init();
  369. #endif
  370. #ifdef CONFIG_NUMA
  371. numa_initmem_init(0, end_pfn);
  372. #else
  373. contig_initmem_init(0, end_pfn);
  374. #endif
  375. dma32_reserve_bootmem();
  376. #ifdef CONFIG_ACPI_SLEEP
  377. /*
  378. * Reserve low memory region for sleep support.
  379. */
  380. acpi_reserve_bootmem();
  381. #endif
  382. if (efi_enabled)
  383. efi_reserve_bootmem();
  384. /*
  385. * Find and reserve possible boot-time SMP configuration:
  386. */
  387. find_smp_config();
  388. #ifdef CONFIG_BLK_DEV_INITRD
  389. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  390. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  391. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  392. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  393. unsigned long end_of_mem = end_pfn << PAGE_SHIFT;
  394. if (ramdisk_end <= end_of_mem) {
  395. /*
  396. * don't need to reserve again, already reserved early
  397. * in x86_64_start_kernel, and early_res_to_bootmem
  398. * convert that to reserved in bootmem
  399. */
  400. initrd_start = ramdisk_image + PAGE_OFFSET;
  401. initrd_end = initrd_start+ramdisk_size;
  402. } else {
  403. free_bootmem(ramdisk_image, ramdisk_size);
  404. printk(KERN_ERR "initrd extends beyond end of memory "
  405. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  406. ramdisk_end, end_of_mem);
  407. initrd_start = 0;
  408. }
  409. }
  410. #endif
  411. reserve_crashkernel();
  412. reserve_ibft_region();
  413. paging_init();
  414. map_vsyscall();
  415. early_quirks();
  416. #ifdef CONFIG_ACPI
  417. /*
  418. * Read APIC and some other early information from ACPI tables.
  419. */
  420. acpi_boot_init();
  421. #endif
  422. init_cpu_to_node();
  423. /*
  424. * get boot-time SMP configuration:
  425. */
  426. if (smp_found_config)
  427. get_smp_config();
  428. init_apic_mappings();
  429. ioapic_init_mappings();
  430. kvm_guest_init();
  431. /*
  432. * We trust e820 completely. No explicit ROM probing in memory.
  433. */
  434. e820_reserve_resources();
  435. e820_mark_nosave_regions();
  436. /* request I/O space for devices used on all i[345]86 PCs */
  437. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  438. request_resource(&ioport_resource, &standard_io_resources[i]);
  439. e820_setup_gap();
  440. #ifdef CONFIG_VT
  441. #if defined(CONFIG_VGA_CONSOLE)
  442. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  443. conswitchp = &vga_con;
  444. #elif defined(CONFIG_DUMMY_CONSOLE)
  445. conswitchp = &dummy_con;
  446. #endif
  447. #endif
  448. /* do this before identify_cpu for boot cpu */
  449. check_enable_amd_mmconf_dmi();
  450. }
  451. struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {};
  452. static void __cpuinit default_init(struct cpuinfo_x86 *c)
  453. {
  454. display_cacheinfo(c);
  455. }
  456. static struct cpu_dev __cpuinitdata default_cpu = {
  457. .c_init = default_init,
  458. .c_vendor = "Unknown",
  459. };
  460. static struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
  461. int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  462. {
  463. unsigned int *v;
  464. if (c->extended_cpuid_level < 0x80000004)
  465. return 0;
  466. v = (unsigned int *) c->x86_model_id;
  467. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  468. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  469. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  470. c->x86_model_id[48] = 0;
  471. return 1;
  472. }
  473. void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  474. {
  475. unsigned int n, dummy, eax, ebx, ecx, edx;
  476. n = c->extended_cpuid_level;
  477. if (n >= 0x80000005) {
  478. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  479. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
  480. "D cache %dK (%d bytes/line)\n",
  481. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  482. c->x86_cache_size = (ecx>>24) + (edx>>24);
  483. /* On K8 L1 TLB is inclusive, so don't count it */
  484. c->x86_tlbsize = 0;
  485. }
  486. if (n >= 0x80000006) {
  487. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  488. ecx = cpuid_ecx(0x80000006);
  489. c->x86_cache_size = ecx >> 16;
  490. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  491. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  492. c->x86_cache_size, ecx & 0xFF);
  493. }
  494. if (n >= 0x80000008) {
  495. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  496. c->x86_virt_bits = (eax >> 8) & 0xff;
  497. c->x86_phys_bits = eax & 0xff;
  498. }
  499. }
  500. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  501. {
  502. #ifdef CONFIG_SMP
  503. u32 eax, ebx, ecx, edx;
  504. int index_msb, core_bits;
  505. cpuid(1, &eax, &ebx, &ecx, &edx);
  506. if (!cpu_has(c, X86_FEATURE_HT))
  507. return;
  508. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  509. goto out;
  510. smp_num_siblings = (ebx & 0xff0000) >> 16;
  511. if (smp_num_siblings == 1) {
  512. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  513. } else if (smp_num_siblings > 1) {
  514. if (smp_num_siblings > NR_CPUS) {
  515. printk(KERN_WARNING "CPU: Unsupported number of "
  516. "siblings %d", smp_num_siblings);
  517. smp_num_siblings = 1;
  518. return;
  519. }
  520. index_msb = get_count_order(smp_num_siblings);
  521. c->phys_proc_id = phys_pkg_id(index_msb);
  522. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  523. index_msb = get_count_order(smp_num_siblings);
  524. core_bits = get_count_order(c->x86_max_cores);
  525. c->cpu_core_id = phys_pkg_id(index_msb) &
  526. ((1 << core_bits) - 1);
  527. }
  528. out:
  529. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  530. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  531. c->phys_proc_id);
  532. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  533. c->cpu_core_id);
  534. }
  535. #endif
  536. }
  537. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  538. {
  539. char *v = c->x86_vendor_id;
  540. int i;
  541. static int printed;
  542. for (i = 0; i < X86_VENDOR_NUM; i++) {
  543. if (cpu_devs[i]) {
  544. if (!strcmp(v, cpu_devs[i]->c_ident[0]) ||
  545. (cpu_devs[i]->c_ident[1] &&
  546. !strcmp(v, cpu_devs[i]->c_ident[1]))) {
  547. c->x86_vendor = i;
  548. this_cpu = cpu_devs[i];
  549. return;
  550. }
  551. }
  552. }
  553. if (!printed) {
  554. printed++;
  555. printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n");
  556. printk(KERN_ERR "CPU: Your system may be unstable.\n");
  557. }
  558. c->x86_vendor = X86_VENDOR_UNKNOWN;
  559. }
  560. static void __init early_cpu_init(void)
  561. {
  562. struct cpu_vendor_dev *cvdev;
  563. for (cvdev = __x86cpuvendor_start ;
  564. cvdev < __x86cpuvendor_end ;
  565. cvdev++)
  566. cpu_devs[cvdev->vendor] = cvdev->cpu_dev;
  567. }
  568. /* Do some early cpuid on the boot CPU to get some parameter that are
  569. needed before check_bugs. Everything advanced is in identify_cpu
  570. below. */
  571. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  572. {
  573. u32 tfms, xlvl;
  574. c->loops_per_jiffy = loops_per_jiffy;
  575. c->x86_cache_size = -1;
  576. c->x86_vendor = X86_VENDOR_UNKNOWN;
  577. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  578. c->x86_vendor_id[0] = '\0'; /* Unset */
  579. c->x86_model_id[0] = '\0'; /* Unset */
  580. c->x86_clflush_size = 64;
  581. c->x86_cache_alignment = c->x86_clflush_size;
  582. c->x86_max_cores = 1;
  583. c->x86_coreid_bits = 0;
  584. c->extended_cpuid_level = 0;
  585. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  586. /* Get vendor name */
  587. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  588. (unsigned int *)&c->x86_vendor_id[0],
  589. (unsigned int *)&c->x86_vendor_id[8],
  590. (unsigned int *)&c->x86_vendor_id[4]);
  591. get_cpu_vendor(c);
  592. /* Initialize the standard set of capabilities */
  593. /* Note that the vendor-specific code below might override */
  594. /* Intel-defined flags: level 0x00000001 */
  595. if (c->cpuid_level >= 0x00000001) {
  596. __u32 misc;
  597. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  598. &c->x86_capability[0]);
  599. c->x86 = (tfms >> 8) & 0xf;
  600. c->x86_model = (tfms >> 4) & 0xf;
  601. c->x86_mask = tfms & 0xf;
  602. if (c->x86 == 0xf)
  603. c->x86 += (tfms >> 20) & 0xff;
  604. if (c->x86 >= 0x6)
  605. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  606. if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
  607. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  608. } else {
  609. /* Have CPUID level 0 only - unheard of */
  610. c->x86 = 4;
  611. }
  612. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
  613. #ifdef CONFIG_SMP
  614. c->phys_proc_id = c->initial_apicid;
  615. #endif
  616. /* AMD-defined flags: level 0x80000001 */
  617. xlvl = cpuid_eax(0x80000000);
  618. c->extended_cpuid_level = xlvl;
  619. if ((xlvl & 0xffff0000) == 0x80000000) {
  620. if (xlvl >= 0x80000001) {
  621. c->x86_capability[1] = cpuid_edx(0x80000001);
  622. c->x86_capability[6] = cpuid_ecx(0x80000001);
  623. }
  624. if (xlvl >= 0x80000004)
  625. get_model_name(c); /* Default name */
  626. }
  627. /* Transmeta-defined flags: level 0x80860001 */
  628. xlvl = cpuid_eax(0x80860000);
  629. if ((xlvl & 0xffff0000) == 0x80860000) {
  630. /* Don't set x86_cpuid_level here for now to not confuse. */
  631. if (xlvl >= 0x80860001)
  632. c->x86_capability[2] = cpuid_edx(0x80860001);
  633. }
  634. c->extended_cpuid_level = cpuid_eax(0x80000000);
  635. if (c->extended_cpuid_level >= 0x80000007)
  636. c->x86_power = cpuid_edx(0x80000007);
  637. if (c->x86_vendor != X86_VENDOR_UNKNOWN &&
  638. cpu_devs[c->x86_vendor]->c_early_init)
  639. cpu_devs[c->x86_vendor]->c_early_init(c);
  640. validate_pat_support(c);
  641. }
  642. /*
  643. * This does the hard work of actually picking apart the CPU stuff...
  644. */
  645. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  646. {
  647. int i;
  648. early_identify_cpu(c);
  649. init_scattered_cpuid_features(c);
  650. c->apicid = phys_pkg_id(0);
  651. /*
  652. * Vendor-specific initialization. In this section we
  653. * canonicalize the feature flags, meaning if there are
  654. * features a certain CPU supports which CPUID doesn't
  655. * tell us, CPUID claiming incorrect flags, or other bugs,
  656. * we handle them here.
  657. *
  658. * At the end of this section, c->x86_capability better
  659. * indicate the features this CPU genuinely supports!
  660. */
  661. if (this_cpu->c_init)
  662. this_cpu->c_init(c);
  663. detect_ht(c);
  664. /*
  665. * On SMP, boot_cpu_data holds the common feature set between
  666. * all CPUs; so make sure that we indicate which features are
  667. * common between the CPUs. The first time this routine gets
  668. * executed, c == &boot_cpu_data.
  669. */
  670. if (c != &boot_cpu_data) {
  671. /* AND the already accumulated flags with these */
  672. for (i = 0; i < NCAPINTS; i++)
  673. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  674. }
  675. /* Clear all flags overriden by options */
  676. for (i = 0; i < NCAPINTS; i++)
  677. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  678. #ifdef CONFIG_X86_MCE
  679. mcheck_init(c);
  680. #endif
  681. select_idle_routine(c);
  682. #ifdef CONFIG_NUMA
  683. numa_add_cpu(smp_processor_id());
  684. #endif
  685. }
  686. void __cpuinit identify_boot_cpu(void)
  687. {
  688. identify_cpu(&boot_cpu_data);
  689. }
  690. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  691. {
  692. BUG_ON(c == &boot_cpu_data);
  693. identify_cpu(c);
  694. mtrr_ap_init();
  695. }
  696. static __init int setup_noclflush(char *arg)
  697. {
  698. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  699. return 1;
  700. }
  701. __setup("noclflush", setup_noclflush);
  702. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  703. {
  704. if (c->x86_model_id[0])
  705. printk(KERN_CONT "%s", c->x86_model_id);
  706. if (c->x86_mask || c->cpuid_level >= 0)
  707. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  708. else
  709. printk(KERN_CONT "\n");
  710. }
  711. static __init int setup_disablecpuid(char *arg)
  712. {
  713. int bit;
  714. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  715. setup_clear_cpu_cap(bit);
  716. else
  717. return 0;
  718. return 1;
  719. }
  720. __setup("clearcpuid=", setup_disablecpuid);