setup_64.c 21 KB

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