setup_64.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202
  1. /*
  2. * Copyright (C) 1995 Linus Torvalds
  3. */
  4. /*
  5. * This file handles the architecture-dependent parts of initialization
  6. */
  7. #include <linux/errno.h>
  8. #include <linux/sched.h>
  9. #include <linux/kernel.h>
  10. #include <linux/mm.h>
  11. #include <linux/stddef.h>
  12. #include <linux/unistd.h>
  13. #include <linux/ptrace.h>
  14. #include <linux/slab.h>
  15. #include <linux/user.h>
  16. #include <linux/screen_info.h>
  17. #include <linux/ioport.h>
  18. #include <linux/delay.h>
  19. #include <linux/init.h>
  20. #include <linux/initrd.h>
  21. #include <linux/highmem.h>
  22. #include <linux/bootmem.h>
  23. #include <linux/module.h>
  24. #include <asm/processor.h>
  25. #include <linux/console.h>
  26. #include <linux/seq_file.h>
  27. #include <linux/crash_dump.h>
  28. #include <linux/root_dev.h>
  29. #include <linux/pci.h>
  30. #include <asm/pci-direct.h>
  31. #include <linux/efi.h>
  32. #include <linux/acpi.h>
  33. #include <linux/kallsyms.h>
  34. #include <linux/edd.h>
  35. #include <linux/iscsi_ibft.h>
  36. #include <linux/mmzone.h>
  37. #include <linux/kexec.h>
  38. #include <linux/cpufreq.h>
  39. #include <linux/dmi.h>
  40. #include <linux/dma-mapping.h>
  41. #include <linux/ctype.h>
  42. #include <linux/sort.h>
  43. #include <linux/uaccess.h>
  44. #include <linux/init_ohci1394_dma.h>
  45. #include <linux/kvm_para.h>
  46. #include <asm/mtrr.h>
  47. #include <asm/uaccess.h>
  48. #include <asm/system.h>
  49. #include <asm/vsyscall.h>
  50. #include <asm/io.h>
  51. #include <asm/smp.h>
  52. #include <asm/msr.h>
  53. #include <asm/desc.h>
  54. #include <video/edid.h>
  55. #include <asm/e820.h>
  56. #include <asm/mpspec.h>
  57. #include <asm/dma.h>
  58. #include <asm/gart.h>
  59. #include <asm/mpspec.h>
  60. #include <asm/mmu_context.h>
  61. #include <asm/proto.h>
  62. #include <asm/setup.h>
  63. #include <asm/numa.h>
  64. #include <asm/sections.h>
  65. #include <asm/dmi.h>
  66. #include <asm/cacheflush.h>
  67. #include <asm/mce.h>
  68. #include <asm/ds.h>
  69. #include <asm/topology.h>
  70. #include <asm/trampoline.h>
  71. #include <asm/pat.h>
  72. #include <mach_apic.h>
  73. #ifdef CONFIG_PARAVIRT
  74. #include <asm/paravirt.h>
  75. #else
  76. #define ARCH_SETUP
  77. #endif
  78. /*
  79. * Machine setup..
  80. */
  81. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  82. EXPORT_SYMBOL(boot_cpu_data);
  83. __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
  84. unsigned long mmu_cr4_features;
  85. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  86. int bootloader_type;
  87. unsigned long saved_video_mode;
  88. int force_mwait __cpuinitdata;
  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. #ifdef CONFIG_PCI_MMCONFIG
  265. extern void __cpuinit fam10h_check_enable_mmcfg(void);
  266. extern void __init check_enable_amd_mmconf_dmi(void);
  267. #else
  268. void __cpuinit fam10h_check_enable_mmcfg(void)
  269. {
  270. }
  271. void __init check_enable_amd_mmconf_dmi(void)
  272. {
  273. }
  274. #endif
  275. /*
  276. * setup_arch - architecture-specific boot-time initializations
  277. *
  278. * Note: On x86_64, fixmaps are ready for use even before this is called.
  279. */
  280. void __init setup_arch(char **cmdline_p)
  281. {
  282. unsigned i;
  283. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  284. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  285. screen_info = boot_params.screen_info;
  286. edid_info = boot_params.edid_info;
  287. saved_video_mode = boot_params.hdr.vid_mode;
  288. bootloader_type = boot_params.hdr.type_of_loader;
  289. #ifdef CONFIG_BLK_DEV_RAM
  290. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  291. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  292. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  293. #endif
  294. #ifdef CONFIG_EFI
  295. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  296. "EL64", 4))
  297. efi_enabled = 1;
  298. #endif
  299. ARCH_SETUP
  300. memory_setup();
  301. copy_edd();
  302. if (!boot_params.hdr.root_flags)
  303. root_mountflags &= ~MS_RDONLY;
  304. init_mm.start_code = (unsigned long) &_text;
  305. init_mm.end_code = (unsigned long) &_etext;
  306. init_mm.end_data = (unsigned long) &_edata;
  307. init_mm.brk = (unsigned long) &_end;
  308. code_resource.start = virt_to_phys(&_text);
  309. code_resource.end = virt_to_phys(&_etext)-1;
  310. data_resource.start = virt_to_phys(&_etext);
  311. data_resource.end = virt_to_phys(&_edata)-1;
  312. bss_resource.start = virt_to_phys(&__bss_start);
  313. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  314. early_identify_cpu(&boot_cpu_data);
  315. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  316. *cmdline_p = command_line;
  317. parse_setup_data();
  318. parse_early_param();
  319. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  320. if (init_ohci1394_dma_early)
  321. init_ohci1394_dma_on_all_controllers();
  322. #endif
  323. finish_e820_parsing();
  324. /* after parse_early_param, so could debug it */
  325. insert_resource(&iomem_resource, &code_resource);
  326. insert_resource(&iomem_resource, &data_resource);
  327. insert_resource(&iomem_resource, &bss_resource);
  328. early_gart_iommu_check();
  329. e820_register_active_regions(0, 0, -1UL);
  330. /*
  331. * partially used pages are not usable - thus
  332. * we are rounding upwards:
  333. */
  334. end_pfn = e820_end_of_ram();
  335. /* pre allocte 4k for mptable mpc */
  336. early_reserve_e820_mpc_new();
  337. /* update e820 for memory not covered by WB MTRRs */
  338. mtrr_bp_init();
  339. if (mtrr_trim_uncached_memory(end_pfn)) {
  340. e820_register_active_regions(0, 0, -1UL);
  341. end_pfn = e820_end_of_ram();
  342. }
  343. num_physpages = end_pfn;
  344. check_efer();
  345. max_pfn_mapped = init_memory_mapping(0, (end_pfn << PAGE_SHIFT));
  346. if (efi_enabled)
  347. efi_init();
  348. vsmp_init();
  349. dmi_scan_machine();
  350. io_delay_init();
  351. #ifdef CONFIG_KVM_CLOCK
  352. kvmclock_init();
  353. #endif
  354. #ifdef CONFIG_SMP
  355. /* setup to use the early static init tables during kernel startup */
  356. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  357. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  358. #ifdef CONFIG_NUMA
  359. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  360. #endif
  361. #endif
  362. #ifdef CONFIG_ACPI
  363. /*
  364. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  365. * Call this early for SRAT node setup.
  366. */
  367. acpi_boot_table_init();
  368. #endif
  369. /* How many end-of-memory variables you have, grandma! */
  370. max_low_pfn = end_pfn;
  371. max_pfn = end_pfn;
  372. high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
  373. /* Remove active ranges so rediscovery with NUMA-awareness happens */
  374. remove_all_active_ranges();
  375. #ifdef CONFIG_ACPI_NUMA
  376. /*
  377. * Parse SRAT to discover nodes.
  378. */
  379. acpi_numa_init();
  380. #endif
  381. #ifdef CONFIG_NUMA
  382. numa_initmem_init(0, end_pfn);
  383. #else
  384. contig_initmem_init(0, end_pfn);
  385. #endif
  386. dma32_reserve_bootmem();
  387. #ifdef CONFIG_ACPI_SLEEP
  388. /*
  389. * Reserve low memory region for sleep support.
  390. */
  391. acpi_reserve_bootmem();
  392. #endif
  393. if (efi_enabled)
  394. efi_reserve_bootmem();
  395. #ifdef CONFIG_X86_MPPARSE
  396. /*
  397. * Find and reserve possible boot-time SMP configuration:
  398. */
  399. find_smp_config();
  400. #endif
  401. #ifdef CONFIG_BLK_DEV_INITRD
  402. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  403. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  404. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  405. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  406. unsigned long end_of_mem = end_pfn << PAGE_SHIFT;
  407. if (ramdisk_end <= end_of_mem) {
  408. /*
  409. * don't need to reserve again, already reserved early
  410. * in x86_64_start_kernel, and early_res_to_bootmem
  411. * convert that to reserved in bootmem
  412. */
  413. initrd_start = ramdisk_image + PAGE_OFFSET;
  414. initrd_end = initrd_start+ramdisk_size;
  415. } else {
  416. free_bootmem(ramdisk_image, ramdisk_size);
  417. printk(KERN_ERR "initrd extends beyond end of memory "
  418. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  419. ramdisk_end, end_of_mem);
  420. initrd_start = 0;
  421. }
  422. }
  423. #endif
  424. reserve_crashkernel();
  425. reserve_ibft_region();
  426. paging_init();
  427. map_vsyscall();
  428. early_quirks();
  429. #ifdef CONFIG_ACPI
  430. /*
  431. * Read APIC and some other early information from ACPI tables.
  432. */
  433. acpi_boot_init();
  434. #endif
  435. init_cpu_to_node();
  436. #ifdef CONFIG_X86_MPPARSE
  437. /*
  438. * get boot-time SMP configuration:
  439. */
  440. if (smp_found_config)
  441. get_smp_config();
  442. #endif
  443. init_apic_mappings();
  444. ioapic_init_mappings();
  445. kvm_guest_init();
  446. /*
  447. * We trust e820 completely. No explicit ROM probing in memory.
  448. */
  449. e820_reserve_resources();
  450. e820_mark_nosave_regions(end_pfn);
  451. /* request I/O space for devices used on all i[345]86 PCs */
  452. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  453. request_resource(&ioport_resource, &standard_io_resources[i]);
  454. e820_setup_gap();
  455. #ifdef CONFIG_VT
  456. #if defined(CONFIG_VGA_CONSOLE)
  457. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  458. conswitchp = &vga_con;
  459. #elif defined(CONFIG_DUMMY_CONSOLE)
  460. conswitchp = &dummy_con;
  461. #endif
  462. #endif
  463. /* do this before identify_cpu for boot cpu */
  464. check_enable_amd_mmconf_dmi();
  465. }
  466. static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  467. {
  468. unsigned int *v;
  469. if (c->extended_cpuid_level < 0x80000004)
  470. return 0;
  471. v = (unsigned int *) c->x86_model_id;
  472. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  473. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  474. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  475. c->x86_model_id[48] = 0;
  476. return 1;
  477. }
  478. static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  479. {
  480. unsigned int n, dummy, eax, ebx, ecx, edx;
  481. n = c->extended_cpuid_level;
  482. if (n >= 0x80000005) {
  483. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  484. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
  485. "D cache %dK (%d bytes/line)\n",
  486. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  487. c->x86_cache_size = (ecx>>24) + (edx>>24);
  488. /* On K8 L1 TLB is inclusive, so don't count it */
  489. c->x86_tlbsize = 0;
  490. }
  491. if (n >= 0x80000006) {
  492. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  493. ecx = cpuid_ecx(0x80000006);
  494. c->x86_cache_size = ecx >> 16;
  495. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  496. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  497. c->x86_cache_size, ecx & 0xFF);
  498. }
  499. if (n >= 0x80000008) {
  500. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  501. c->x86_virt_bits = (eax >> 8) & 0xff;
  502. c->x86_phys_bits = eax & 0xff;
  503. }
  504. }
  505. #ifdef CONFIG_NUMA
  506. static int __cpuinit nearby_node(int apicid)
  507. {
  508. int i, node;
  509. for (i = apicid - 1; i >= 0; i--) {
  510. node = apicid_to_node[i];
  511. if (node != NUMA_NO_NODE && node_online(node))
  512. return node;
  513. }
  514. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  515. node = apicid_to_node[i];
  516. if (node != NUMA_NO_NODE && node_online(node))
  517. return node;
  518. }
  519. return first_node(node_online_map); /* Shouldn't happen */
  520. }
  521. #endif
  522. /*
  523. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  524. * Assumes number of cores is a power of two.
  525. */
  526. static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
  527. {
  528. #ifdef CONFIG_SMP
  529. unsigned bits;
  530. #ifdef CONFIG_NUMA
  531. int cpu = smp_processor_id();
  532. int node = 0;
  533. unsigned apicid = hard_smp_processor_id();
  534. #endif
  535. bits = c->x86_coreid_bits;
  536. /* Low order bits define the core id (index of core in socket) */
  537. c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
  538. /* Convert the initial APIC ID into the socket ID */
  539. c->phys_proc_id = c->initial_apicid >> bits;
  540. #ifdef CONFIG_NUMA
  541. node = c->phys_proc_id;
  542. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  543. node = apicid_to_node[apicid];
  544. if (!node_online(node)) {
  545. /* Two possibilities here:
  546. - The CPU is missing memory and no node was created.
  547. In that case try picking one from a nearby CPU
  548. - The APIC IDs differ from the HyperTransport node IDs
  549. which the K8 northbridge parsing fills in.
  550. Assume they are all increased by a constant offset,
  551. but in the same order as the HT nodeids.
  552. If that doesn't result in a usable node fall back to the
  553. path for the previous case. */
  554. int ht_nodeid = c->initial_apicid;
  555. if (ht_nodeid >= 0 &&
  556. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  557. node = apicid_to_node[ht_nodeid];
  558. /* Pick a nearby node */
  559. if (!node_online(node))
  560. node = nearby_node(apicid);
  561. }
  562. numa_set_node(cpu, node);
  563. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  564. #endif
  565. #endif
  566. }
  567. static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
  568. {
  569. #ifdef CONFIG_SMP
  570. unsigned bits, ecx;
  571. /* Multi core CPU? */
  572. if (c->extended_cpuid_level < 0x80000008)
  573. return;
  574. ecx = cpuid_ecx(0x80000008);
  575. c->x86_max_cores = (ecx & 0xff) + 1;
  576. /* CPU telling us the core id bits shift? */
  577. bits = (ecx >> 12) & 0xF;
  578. /* Otherwise recompute */
  579. if (bits == 0) {
  580. while ((1 << bits) < c->x86_max_cores)
  581. bits++;
  582. }
  583. c->x86_coreid_bits = bits;
  584. #endif
  585. }
  586. #define ENABLE_C1E_MASK 0x18000000
  587. #define CPUID_PROCESSOR_SIGNATURE 1
  588. #define CPUID_XFAM 0x0ff00000
  589. #define CPUID_XFAM_K8 0x00000000
  590. #define CPUID_XFAM_10H 0x00100000
  591. #define CPUID_XFAM_11H 0x00200000
  592. #define CPUID_XMOD 0x000f0000
  593. #define CPUID_XMOD_REV_F 0x00040000
  594. /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
  595. static __cpuinit int amd_apic_timer_broken(void)
  596. {
  597. u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
  598. switch (eax & CPUID_XFAM) {
  599. case CPUID_XFAM_K8:
  600. if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
  601. break;
  602. case CPUID_XFAM_10H:
  603. case CPUID_XFAM_11H:
  604. rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
  605. if (lo & ENABLE_C1E_MASK)
  606. return 1;
  607. break;
  608. default:
  609. /* err on the side of caution */
  610. return 1;
  611. }
  612. return 0;
  613. }
  614. static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  615. {
  616. early_init_amd_mc(c);
  617. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  618. if (c->x86_power & (1<<8))
  619. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  620. }
  621. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  622. {
  623. unsigned level;
  624. #ifdef CONFIG_SMP
  625. unsigned long value;
  626. /*
  627. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  628. * bit 6 of msr C001_0015
  629. *
  630. * Errata 63 for SH-B3 steppings
  631. * Errata 122 for all steppings (F+ have it disabled by default)
  632. */
  633. if (c->x86 == 15) {
  634. rdmsrl(MSR_K8_HWCR, value);
  635. value |= 1 << 6;
  636. wrmsrl(MSR_K8_HWCR, value);
  637. }
  638. #endif
  639. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  640. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  641. clear_cpu_cap(c, 0*32+31);
  642. /* On C+ stepping K8 rep microcode works well for copy/memset */
  643. level = cpuid_eax(1);
  644. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
  645. level >= 0x0f58))
  646. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  647. if (c->x86 == 0x10 || c->x86 == 0x11)
  648. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  649. /* Enable workaround for FXSAVE leak */
  650. if (c->x86 >= 6)
  651. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  652. level = get_model_name(c);
  653. if (!level) {
  654. switch (c->x86) {
  655. case 15:
  656. /* Should distinguish Models here, but this is only
  657. a fallback anyways. */
  658. strcpy(c->x86_model_id, "Hammer");
  659. break;
  660. }
  661. }
  662. display_cacheinfo(c);
  663. /* Multi core CPU? */
  664. if (c->extended_cpuid_level >= 0x80000008)
  665. amd_detect_cmp(c);
  666. if (c->extended_cpuid_level >= 0x80000006 &&
  667. (cpuid_edx(0x80000006) & 0xf000))
  668. num_cache_leaves = 4;
  669. else
  670. num_cache_leaves = 3;
  671. if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
  672. set_cpu_cap(c, X86_FEATURE_K8);
  673. /* MFENCE stops RDTSC speculation */
  674. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  675. if (c->x86 == 0x10)
  676. fam10h_check_enable_mmcfg();
  677. if (amd_apic_timer_broken())
  678. disable_apic_timer = 1;
  679. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  680. unsigned long long tseg;
  681. /*
  682. * Split up direct mapping around the TSEG SMM area.
  683. * Don't do it for gbpages because there seems very little
  684. * benefit in doing so.
  685. */
  686. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
  687. (tseg >> PMD_SHIFT) < (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
  688. set_memory_4k((unsigned long)__va(tseg), 1);
  689. }
  690. }
  691. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  692. {
  693. #ifdef CONFIG_SMP
  694. u32 eax, ebx, ecx, edx;
  695. int index_msb, core_bits;
  696. cpuid(1, &eax, &ebx, &ecx, &edx);
  697. if (!cpu_has(c, X86_FEATURE_HT))
  698. return;
  699. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  700. goto out;
  701. smp_num_siblings = (ebx & 0xff0000) >> 16;
  702. if (smp_num_siblings == 1) {
  703. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  704. } else if (smp_num_siblings > 1) {
  705. if (smp_num_siblings > NR_CPUS) {
  706. printk(KERN_WARNING "CPU: Unsupported number of "
  707. "siblings %d", smp_num_siblings);
  708. smp_num_siblings = 1;
  709. return;
  710. }
  711. index_msb = get_count_order(smp_num_siblings);
  712. c->phys_proc_id = phys_pkg_id(index_msb);
  713. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  714. index_msb = get_count_order(smp_num_siblings);
  715. core_bits = get_count_order(c->x86_max_cores);
  716. c->cpu_core_id = phys_pkg_id(index_msb) &
  717. ((1 << core_bits) - 1);
  718. }
  719. out:
  720. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  721. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  722. c->phys_proc_id);
  723. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  724. c->cpu_core_id);
  725. }
  726. #endif
  727. }
  728. /*
  729. * find out the number of processor cores on the die
  730. */
  731. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  732. {
  733. unsigned int eax, t;
  734. if (c->cpuid_level < 4)
  735. return 1;
  736. cpuid_count(4, 0, &eax, &t, &t, &t);
  737. if (eax & 0x1f)
  738. return ((eax >> 26) + 1);
  739. else
  740. return 1;
  741. }
  742. static void __cpuinit srat_detect_node(void)
  743. {
  744. #ifdef CONFIG_NUMA
  745. unsigned node;
  746. int cpu = smp_processor_id();
  747. int apicid = hard_smp_processor_id();
  748. /* Don't do the funky fallback heuristics the AMD version employs
  749. for now. */
  750. node = apicid_to_node[apicid];
  751. if (node == NUMA_NO_NODE || !node_online(node))
  752. node = first_node(node_online_map);
  753. numa_set_node(cpu, node);
  754. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  755. #endif
  756. }
  757. static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
  758. {
  759. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  760. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  761. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  762. }
  763. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  764. {
  765. /* Cache sizes */
  766. unsigned n;
  767. init_intel_cacheinfo(c);
  768. if (c->cpuid_level > 9) {
  769. unsigned eax = cpuid_eax(10);
  770. /* Check for version and the number of counters */
  771. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  772. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  773. }
  774. if (cpu_has_ds) {
  775. unsigned int l1, l2;
  776. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  777. if (!(l1 & (1<<11)))
  778. set_cpu_cap(c, X86_FEATURE_BTS);
  779. if (!(l1 & (1<<12)))
  780. set_cpu_cap(c, X86_FEATURE_PEBS);
  781. }
  782. if (cpu_has_bts)
  783. ds_init_intel(c);
  784. n = c->extended_cpuid_level;
  785. if (n >= 0x80000008) {
  786. unsigned eax = cpuid_eax(0x80000008);
  787. c->x86_virt_bits = (eax >> 8) & 0xff;
  788. c->x86_phys_bits = eax & 0xff;
  789. /* CPUID workaround for Intel 0F34 CPU */
  790. if (c->x86_vendor == X86_VENDOR_INTEL &&
  791. c->x86 == 0xF && c->x86_model == 0x3 &&
  792. c->x86_mask == 0x4)
  793. c->x86_phys_bits = 36;
  794. }
  795. if (c->x86 == 15)
  796. c->x86_cache_alignment = c->x86_clflush_size * 2;
  797. if (c->x86 == 6)
  798. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  799. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  800. c->x86_max_cores = intel_num_cpu_cores(c);
  801. srat_detect_node();
  802. }
  803. static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
  804. {
  805. if (c->x86 == 0x6 && c->x86_model >= 0xf)
  806. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  807. }
  808. static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
  809. {
  810. /* Cache sizes */
  811. unsigned n;
  812. n = c->extended_cpuid_level;
  813. if (n >= 0x80000008) {
  814. unsigned eax = cpuid_eax(0x80000008);
  815. c->x86_virt_bits = (eax >> 8) & 0xff;
  816. c->x86_phys_bits = eax & 0xff;
  817. }
  818. if (c->x86 == 0x6 && c->x86_model >= 0xf) {
  819. c->x86_cache_alignment = c->x86_clflush_size * 2;
  820. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  821. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  822. }
  823. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  824. }
  825. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  826. {
  827. char *v = c->x86_vendor_id;
  828. if (!strcmp(v, "AuthenticAMD"))
  829. c->x86_vendor = X86_VENDOR_AMD;
  830. else if (!strcmp(v, "GenuineIntel"))
  831. c->x86_vendor = X86_VENDOR_INTEL;
  832. else if (!strcmp(v, "CentaurHauls"))
  833. c->x86_vendor = X86_VENDOR_CENTAUR;
  834. else
  835. c->x86_vendor = X86_VENDOR_UNKNOWN;
  836. }
  837. /* Do some early cpuid on the boot CPU to get some parameter that are
  838. needed before check_bugs. Everything advanced is in identify_cpu
  839. below. */
  840. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  841. {
  842. u32 tfms, xlvl;
  843. c->loops_per_jiffy = loops_per_jiffy;
  844. c->x86_cache_size = -1;
  845. c->x86_vendor = X86_VENDOR_UNKNOWN;
  846. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  847. c->x86_vendor_id[0] = '\0'; /* Unset */
  848. c->x86_model_id[0] = '\0'; /* Unset */
  849. c->x86_clflush_size = 64;
  850. c->x86_cache_alignment = c->x86_clflush_size;
  851. c->x86_max_cores = 1;
  852. c->x86_coreid_bits = 0;
  853. c->extended_cpuid_level = 0;
  854. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  855. /* Get vendor name */
  856. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  857. (unsigned int *)&c->x86_vendor_id[0],
  858. (unsigned int *)&c->x86_vendor_id[8],
  859. (unsigned int *)&c->x86_vendor_id[4]);
  860. get_cpu_vendor(c);
  861. /* Initialize the standard set of capabilities */
  862. /* Note that the vendor-specific code below might override */
  863. /* Intel-defined flags: level 0x00000001 */
  864. if (c->cpuid_level >= 0x00000001) {
  865. __u32 misc;
  866. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  867. &c->x86_capability[0]);
  868. c->x86 = (tfms >> 8) & 0xf;
  869. c->x86_model = (tfms >> 4) & 0xf;
  870. c->x86_mask = tfms & 0xf;
  871. if (c->x86 == 0xf)
  872. c->x86 += (tfms >> 20) & 0xff;
  873. if (c->x86 >= 0x6)
  874. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  875. if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
  876. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  877. } else {
  878. /* Have CPUID level 0 only - unheard of */
  879. c->x86 = 4;
  880. }
  881. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
  882. #ifdef CONFIG_SMP
  883. c->phys_proc_id = c->initial_apicid;
  884. #endif
  885. /* AMD-defined flags: level 0x80000001 */
  886. xlvl = cpuid_eax(0x80000000);
  887. c->extended_cpuid_level = xlvl;
  888. if ((xlvl & 0xffff0000) == 0x80000000) {
  889. if (xlvl >= 0x80000001) {
  890. c->x86_capability[1] = cpuid_edx(0x80000001);
  891. c->x86_capability[6] = cpuid_ecx(0x80000001);
  892. }
  893. if (xlvl >= 0x80000004)
  894. get_model_name(c); /* Default name */
  895. }
  896. /* Transmeta-defined flags: level 0x80860001 */
  897. xlvl = cpuid_eax(0x80860000);
  898. if ((xlvl & 0xffff0000) == 0x80860000) {
  899. /* Don't set x86_cpuid_level here for now to not confuse. */
  900. if (xlvl >= 0x80860001)
  901. c->x86_capability[2] = cpuid_edx(0x80860001);
  902. }
  903. c->extended_cpuid_level = cpuid_eax(0x80000000);
  904. if (c->extended_cpuid_level >= 0x80000007)
  905. c->x86_power = cpuid_edx(0x80000007);
  906. switch (c->x86_vendor) {
  907. case X86_VENDOR_AMD:
  908. early_init_amd(c);
  909. break;
  910. case X86_VENDOR_INTEL:
  911. early_init_intel(c);
  912. break;
  913. case X86_VENDOR_CENTAUR:
  914. early_init_centaur(c);
  915. break;
  916. }
  917. validate_pat_support(c);
  918. }
  919. /*
  920. * This does the hard work of actually picking apart the CPU stuff...
  921. */
  922. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  923. {
  924. int i;
  925. early_identify_cpu(c);
  926. init_scattered_cpuid_features(c);
  927. c->apicid = phys_pkg_id(0);
  928. /*
  929. * Vendor-specific initialization. In this section we
  930. * canonicalize the feature flags, meaning if there are
  931. * features a certain CPU supports which CPUID doesn't
  932. * tell us, CPUID claiming incorrect flags, or other bugs,
  933. * we handle them here.
  934. *
  935. * At the end of this section, c->x86_capability better
  936. * indicate the features this CPU genuinely supports!
  937. */
  938. switch (c->x86_vendor) {
  939. case X86_VENDOR_AMD:
  940. init_amd(c);
  941. break;
  942. case X86_VENDOR_INTEL:
  943. init_intel(c);
  944. break;
  945. case X86_VENDOR_CENTAUR:
  946. init_centaur(c);
  947. break;
  948. case X86_VENDOR_UNKNOWN:
  949. default:
  950. display_cacheinfo(c);
  951. break;
  952. }
  953. detect_ht(c);
  954. /*
  955. * On SMP, boot_cpu_data holds the common feature set between
  956. * all CPUs; so make sure that we indicate which features are
  957. * common between the CPUs. The first time this routine gets
  958. * executed, c == &boot_cpu_data.
  959. */
  960. if (c != &boot_cpu_data) {
  961. /* AND the already accumulated flags with these */
  962. for (i = 0; i < NCAPINTS; i++)
  963. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  964. }
  965. /* Clear all flags overriden by options */
  966. for (i = 0; i < NCAPINTS; i++)
  967. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  968. #ifdef CONFIG_X86_MCE
  969. mcheck_init(c);
  970. #endif
  971. select_idle_routine(c);
  972. #ifdef CONFIG_NUMA
  973. numa_add_cpu(smp_processor_id());
  974. #endif
  975. }
  976. void __cpuinit identify_boot_cpu(void)
  977. {
  978. identify_cpu(&boot_cpu_data);
  979. }
  980. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  981. {
  982. BUG_ON(c == &boot_cpu_data);
  983. identify_cpu(c);
  984. mtrr_ap_init();
  985. }
  986. static __init int setup_noclflush(char *arg)
  987. {
  988. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  989. return 1;
  990. }
  991. __setup("noclflush", setup_noclflush);
  992. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  993. {
  994. if (c->x86_model_id[0])
  995. printk(KERN_CONT "%s", c->x86_model_id);
  996. if (c->x86_mask || c->cpuid_level >= 0)
  997. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  998. else
  999. printk(KERN_CONT "\n");
  1000. }
  1001. static __init int setup_disablecpuid(char *arg)
  1002. {
  1003. int bit;
  1004. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  1005. setup_clear_cpu_cap(bit);
  1006. else
  1007. return 0;
  1008. return 1;
  1009. }
  1010. __setup("clearcpuid=", setup_disablecpuid);