setup_64.c 29 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199
  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 <mach_apic.h>
  72. #ifdef CONFIG_PARAVIRT
  73. #include <asm/paravirt.h>
  74. #else
  75. #define ARCH_SETUP
  76. #endif
  77. /*
  78. * Machine setup..
  79. */
  80. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  81. EXPORT_SYMBOL(boot_cpu_data);
  82. __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
  83. unsigned long mmu_cr4_features;
  84. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  85. int bootloader_type;
  86. unsigned long saved_video_mode;
  87. int force_mwait __cpuinitdata;
  88. /*
  89. * Early DMI memory
  90. */
  91. int dmi_alloc_index;
  92. char dmi_alloc_data[DMI_MAX_DATA];
  93. /*
  94. * Setup options
  95. */
  96. struct screen_info screen_info;
  97. EXPORT_SYMBOL(screen_info);
  98. struct sys_desc_table_struct {
  99. unsigned short length;
  100. unsigned char table[0];
  101. };
  102. struct edid_info edid_info;
  103. EXPORT_SYMBOL_GPL(edid_info);
  104. extern int root_mountflags;
  105. char __initdata command_line[COMMAND_LINE_SIZE];
  106. static struct resource standard_io_resources[] = {
  107. { .name = "dma1", .start = 0x00, .end = 0x1f,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  109. { .name = "pic1", .start = 0x20, .end = 0x21,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  111. { .name = "timer0", .start = 0x40, .end = 0x43,
  112. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  113. { .name = "timer1", .start = 0x50, .end = 0x53,
  114. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  115. { .name = "keyboard", .start = 0x60, .end = 0x60,
  116. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  117. { .name = "keyboard", .start = 0x64, .end = 0x64,
  118. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  119. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  120. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  121. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  122. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  123. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  124. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  125. { .name = "fpu", .start = 0xf0, .end = 0xff,
  126. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  127. };
  128. #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
  129. static struct resource data_resource = {
  130. .name = "Kernel data",
  131. .start = 0,
  132. .end = 0,
  133. .flags = IORESOURCE_RAM,
  134. };
  135. static struct resource code_resource = {
  136. .name = "Kernel code",
  137. .start = 0,
  138. .end = 0,
  139. .flags = IORESOURCE_RAM,
  140. };
  141. static struct resource bss_resource = {
  142. .name = "Kernel bss",
  143. .start = 0,
  144. .end = 0,
  145. .flags = IORESOURCE_RAM,
  146. };
  147. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
  148. #ifdef CONFIG_PROC_VMCORE
  149. /* elfcorehdr= specifies the location of elf core header
  150. * stored by the crashed kernel. This option will be passed
  151. * by kexec loader to the capture kernel.
  152. */
  153. static int __init setup_elfcorehdr(char *arg)
  154. {
  155. char *end;
  156. if (!arg)
  157. return -EINVAL;
  158. elfcorehdr_addr = memparse(arg, &end);
  159. return end > arg ? 0 : -EINVAL;
  160. }
  161. early_param("elfcorehdr", setup_elfcorehdr);
  162. #endif
  163. #ifndef CONFIG_NUMA
  164. static void __init
  165. contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  166. {
  167. unsigned long bootmap_size, bootmap;
  168. bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
  169. bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
  170. PAGE_SIZE);
  171. if (bootmap == -1L)
  172. panic("Cannot find bootmem map of size %ld\n", bootmap_size);
  173. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
  174. e820_register_active_regions(0, start_pfn, end_pfn);
  175. free_bootmem_with_active_regions(0, end_pfn);
  176. early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
  177. reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
  178. }
  179. #endif
  180. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  181. struct edd edd;
  182. #ifdef CONFIG_EDD_MODULE
  183. EXPORT_SYMBOL(edd);
  184. #endif
  185. /**
  186. * copy_edd() - Copy the BIOS EDD information
  187. * from boot_params into a safe place.
  188. *
  189. */
  190. static inline void copy_edd(void)
  191. {
  192. memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
  193. sizeof(edd.mbr_signature));
  194. memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
  195. edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
  196. edd.edd_info_nr = boot_params.eddbuf_entries;
  197. }
  198. #else
  199. static inline void copy_edd(void)
  200. {
  201. }
  202. #endif
  203. #ifdef CONFIG_KEXEC
  204. static void __init reserve_crashkernel(void)
  205. {
  206. unsigned long long total_mem;
  207. unsigned long long crash_size, crash_base;
  208. int ret;
  209. total_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
  210. ret = parse_crashkernel(boot_command_line, total_mem,
  211. &crash_size, &crash_base);
  212. if (ret == 0 && crash_size) {
  213. if (crash_base <= 0) {
  214. printk(KERN_INFO "crashkernel reservation failed - "
  215. "you have to specify a base address\n");
  216. return;
  217. }
  218. if (reserve_bootmem(crash_base, crash_size,
  219. BOOTMEM_EXCLUSIVE) < 0) {
  220. printk(KERN_INFO "crashkernel reservation failed - "
  221. "memory is in use\n");
  222. return;
  223. }
  224. printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
  225. "for crashkernel (System RAM: %ldMB)\n",
  226. (unsigned long)(crash_size >> 20),
  227. (unsigned long)(crash_base >> 20),
  228. (unsigned long)(total_mem >> 20));
  229. crashk_res.start = crash_base;
  230. crashk_res.end = crash_base + crash_size - 1;
  231. insert_resource(&iomem_resource, &crashk_res);
  232. }
  233. }
  234. #else
  235. static inline void __init reserve_crashkernel(void)
  236. {}
  237. #endif
  238. /* Overridden in paravirt.c if CONFIG_PARAVIRT */
  239. void __attribute__((weak)) __init memory_setup(void)
  240. {
  241. machine_specific_memory_setup();
  242. }
  243. static void __init parse_setup_data(void)
  244. {
  245. struct setup_data *data;
  246. unsigned long pa_data;
  247. if (boot_params.hdr.version < 0x0209)
  248. return;
  249. pa_data = boot_params.hdr.setup_data;
  250. while (pa_data) {
  251. data = early_ioremap(pa_data, PAGE_SIZE);
  252. switch (data->type) {
  253. default:
  254. break;
  255. }
  256. #ifndef CONFIG_DEBUG_BOOT_PARAMS
  257. free_early(pa_data, pa_data+sizeof(*data)+data->len);
  258. #endif
  259. pa_data = data->next;
  260. early_iounmap(data, PAGE_SIZE);
  261. }
  262. }
  263. #ifdef CONFIG_PCI_MMCONFIG
  264. extern void __cpuinit fam10h_check_enable_mmcfg(void);
  265. extern void __init check_enable_amd_mmconf_dmi(void);
  266. #else
  267. void __cpuinit fam10h_check_enable_mmcfg(void)
  268. {
  269. }
  270. void __init check_enable_amd_mmconf_dmi(void)
  271. {
  272. }
  273. #endif
  274. /*
  275. * setup_arch - architecture-specific boot-time initializations
  276. *
  277. * Note: On x86_64, fixmaps are ready for use even before this is called.
  278. */
  279. void __init setup_arch(char **cmdline_p)
  280. {
  281. unsigned i;
  282. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  283. ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
  284. screen_info = boot_params.screen_info;
  285. edid_info = boot_params.edid_info;
  286. saved_video_mode = boot_params.hdr.vid_mode;
  287. bootloader_type = boot_params.hdr.type_of_loader;
  288. #ifdef CONFIG_BLK_DEV_RAM
  289. rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
  290. rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
  291. rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
  292. #endif
  293. #ifdef CONFIG_EFI
  294. if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
  295. "EL64", 4))
  296. efi_enabled = 1;
  297. #endif
  298. ARCH_SETUP
  299. memory_setup();
  300. copy_edd();
  301. if (!boot_params.hdr.root_flags)
  302. root_mountflags &= ~MS_RDONLY;
  303. init_mm.start_code = (unsigned long) &_text;
  304. init_mm.end_code = (unsigned long) &_etext;
  305. init_mm.end_data = (unsigned long) &_edata;
  306. init_mm.brk = (unsigned long) &_end;
  307. code_resource.start = virt_to_phys(&_text);
  308. code_resource.end = virt_to_phys(&_etext)-1;
  309. data_resource.start = virt_to_phys(&_etext);
  310. data_resource.end = virt_to_phys(&_edata)-1;
  311. bss_resource.start = virt_to_phys(&__bss_start);
  312. bss_resource.end = virt_to_phys(&__bss_stop)-1;
  313. early_identify_cpu(&boot_cpu_data);
  314. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  315. *cmdline_p = command_line;
  316. parse_setup_data();
  317. parse_early_param();
  318. #ifdef CONFIG_PCI
  319. if (pci_early_dump_regs)
  320. early_dump_pci_devices();
  321. #endif
  322. #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
  323. if (init_ohci1394_dma_early)
  324. init_ohci1394_dma_on_all_controllers();
  325. #endif
  326. finish_e820_parsing();
  327. /* after parse_early_param, so could debug it */
  328. insert_resource(&iomem_resource, &code_resource);
  329. insert_resource(&iomem_resource, &data_resource);
  330. insert_resource(&iomem_resource, &bss_resource);
  331. early_gart_iommu_check();
  332. e820_register_active_regions(0, 0, -1UL);
  333. /*
  334. * partially used pages are not usable - thus
  335. * we are rounding upwards:
  336. */
  337. end_pfn = e820_end_of_ram();
  338. /* update e820 for memory not covered by WB MTRRs */
  339. mtrr_bp_init();
  340. if (mtrr_trim_uncached_memory(end_pfn)) {
  341. e820_register_active_regions(0, 0, -1UL);
  342. end_pfn = e820_end_of_ram();
  343. }
  344. num_physpages = end_pfn;
  345. check_efer();
  346. max_pfn_mapped = init_memory_mapping(0, (max_pfn_mapped << PAGE_SHIFT));
  347. if (efi_enabled)
  348. efi_init();
  349. vsmp_init();
  350. dmi_scan_machine();
  351. io_delay_init();
  352. #ifdef CONFIG_KVM_CLOCK
  353. kvmclock_init();
  354. #endif
  355. #ifdef CONFIG_SMP
  356. /* setup to use the early static init tables during kernel startup */
  357. x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
  358. x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
  359. #ifdef CONFIG_NUMA
  360. x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
  361. #endif
  362. #endif
  363. #ifdef CONFIG_ACPI
  364. /*
  365. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  366. * Call this early for SRAT node setup.
  367. */
  368. acpi_boot_table_init();
  369. #endif
  370. /* How many end-of-memory variables you have, grandma! */
  371. max_low_pfn = end_pfn;
  372. max_pfn = end_pfn;
  373. high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
  374. /* Remove active ranges so rediscovery with NUMA-awareness happens */
  375. remove_all_active_ranges();
  376. #ifdef CONFIG_ACPI_NUMA
  377. /*
  378. * Parse SRAT to discover nodes.
  379. */
  380. acpi_numa_init();
  381. #endif
  382. #ifdef CONFIG_NUMA
  383. numa_initmem_init(0, end_pfn);
  384. #else
  385. contig_initmem_init(0, end_pfn);
  386. #endif
  387. dma32_reserve_bootmem();
  388. #ifdef CONFIG_ACPI_SLEEP
  389. /*
  390. * Reserve low memory region for sleep support.
  391. */
  392. acpi_reserve_bootmem();
  393. #endif
  394. if (efi_enabled)
  395. efi_reserve_bootmem();
  396. /*
  397. * Find and reserve possible boot-time SMP configuration:
  398. */
  399. find_smp_config();
  400. #ifdef CONFIG_BLK_DEV_INITRD
  401. if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
  402. unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
  403. unsigned long ramdisk_size = boot_params.hdr.ramdisk_size;
  404. unsigned long ramdisk_end = ramdisk_image + ramdisk_size;
  405. unsigned long end_of_mem = end_pfn << PAGE_SHIFT;
  406. if (ramdisk_end <= end_of_mem) {
  407. /*
  408. * don't need to reserve again, already reserved early
  409. * in x86_64_start_kernel, and early_res_to_bootmem
  410. * convert that to reserved in bootmem
  411. */
  412. initrd_start = ramdisk_image + PAGE_OFFSET;
  413. initrd_end = initrd_start+ramdisk_size;
  414. } else {
  415. free_bootmem(ramdisk_image, ramdisk_size);
  416. printk(KERN_ERR "initrd extends beyond end of memory "
  417. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  418. ramdisk_end, end_of_mem);
  419. initrd_start = 0;
  420. }
  421. }
  422. #endif
  423. reserve_crashkernel();
  424. reserve_ibft_region();
  425. paging_init();
  426. map_vsyscall();
  427. early_quirks();
  428. #ifdef CONFIG_ACPI
  429. /*
  430. * Read APIC and some other early information from ACPI tables.
  431. */
  432. acpi_boot_init();
  433. #endif
  434. init_cpu_to_node();
  435. /*
  436. * get boot-time SMP configuration:
  437. */
  438. if (smp_found_config)
  439. get_smp_config();
  440. init_apic_mappings();
  441. ioapic_init_mappings();
  442. kvm_guest_init();
  443. /*
  444. * We trust e820 completely. No explicit ROM probing in memory.
  445. */
  446. e820_reserve_resources();
  447. e820_mark_nosave_regions();
  448. /* request I/O space for devices used on all i[345]86 PCs */
  449. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  450. request_resource(&ioport_resource, &standard_io_resources[i]);
  451. e820_setup_gap();
  452. #ifdef CONFIG_VT
  453. #if defined(CONFIG_VGA_CONSOLE)
  454. if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
  455. conswitchp = &vga_con;
  456. #elif defined(CONFIG_DUMMY_CONSOLE)
  457. conswitchp = &dummy_con;
  458. #endif
  459. #endif
  460. /* do this before identify_cpu for boot cpu */
  461. check_enable_amd_mmconf_dmi();
  462. }
  463. static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  464. {
  465. unsigned int *v;
  466. if (c->extended_cpuid_level < 0x80000004)
  467. return 0;
  468. v = (unsigned int *) c->x86_model_id;
  469. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  470. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  471. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  472. c->x86_model_id[48] = 0;
  473. return 1;
  474. }
  475. static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  476. {
  477. unsigned int n, dummy, eax, ebx, ecx, edx;
  478. n = c->extended_cpuid_level;
  479. if (n >= 0x80000005) {
  480. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  481. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
  482. "D cache %dK (%d bytes/line)\n",
  483. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  484. c->x86_cache_size = (ecx>>24) + (edx>>24);
  485. /* On K8 L1 TLB is inclusive, so don't count it */
  486. c->x86_tlbsize = 0;
  487. }
  488. if (n >= 0x80000006) {
  489. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  490. ecx = cpuid_ecx(0x80000006);
  491. c->x86_cache_size = ecx >> 16;
  492. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  493. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  494. c->x86_cache_size, ecx & 0xFF);
  495. }
  496. if (n >= 0x80000008) {
  497. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  498. c->x86_virt_bits = (eax >> 8) & 0xff;
  499. c->x86_phys_bits = eax & 0xff;
  500. }
  501. }
  502. #ifdef CONFIG_NUMA
  503. static int __cpuinit nearby_node(int apicid)
  504. {
  505. int i, node;
  506. for (i = apicid - 1; i >= 0; i--) {
  507. node = apicid_to_node[i];
  508. if (node != NUMA_NO_NODE && node_online(node))
  509. return node;
  510. }
  511. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  512. node = apicid_to_node[i];
  513. if (node != NUMA_NO_NODE && node_online(node))
  514. return node;
  515. }
  516. return first_node(node_online_map); /* Shouldn't happen */
  517. }
  518. #endif
  519. /*
  520. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  521. * Assumes number of cores is a power of two.
  522. */
  523. static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
  524. {
  525. #ifdef CONFIG_SMP
  526. unsigned bits;
  527. #ifdef CONFIG_NUMA
  528. int cpu = smp_processor_id();
  529. int node = 0;
  530. unsigned apicid = hard_smp_processor_id();
  531. #endif
  532. bits = c->x86_coreid_bits;
  533. /* Low order bits define the core id (index of core in socket) */
  534. c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
  535. /* Convert the initial APIC ID into the socket ID */
  536. c->phys_proc_id = c->initial_apicid >> bits;
  537. #ifdef CONFIG_NUMA
  538. node = c->phys_proc_id;
  539. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  540. node = apicid_to_node[apicid];
  541. if (!node_online(node)) {
  542. /* Two possibilities here:
  543. - The CPU is missing memory and no node was created.
  544. In that case try picking one from a nearby CPU
  545. - The APIC IDs differ from the HyperTransport node IDs
  546. which the K8 northbridge parsing fills in.
  547. Assume they are all increased by a constant offset,
  548. but in the same order as the HT nodeids.
  549. If that doesn't result in a usable node fall back to the
  550. path for the previous case. */
  551. int ht_nodeid = c->initial_apicid;
  552. if (ht_nodeid >= 0 &&
  553. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  554. node = apicid_to_node[ht_nodeid];
  555. /* Pick a nearby node */
  556. if (!node_online(node))
  557. node = nearby_node(apicid);
  558. }
  559. numa_set_node(cpu, node);
  560. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  561. #endif
  562. #endif
  563. }
  564. static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
  565. {
  566. #ifdef CONFIG_SMP
  567. unsigned bits, ecx;
  568. /* Multi core CPU? */
  569. if (c->extended_cpuid_level < 0x80000008)
  570. return;
  571. ecx = cpuid_ecx(0x80000008);
  572. c->x86_max_cores = (ecx & 0xff) + 1;
  573. /* CPU telling us the core id bits shift? */
  574. bits = (ecx >> 12) & 0xF;
  575. /* Otherwise recompute */
  576. if (bits == 0) {
  577. while ((1 << bits) < c->x86_max_cores)
  578. bits++;
  579. }
  580. c->x86_coreid_bits = bits;
  581. #endif
  582. }
  583. #define ENABLE_C1E_MASK 0x18000000
  584. #define CPUID_PROCESSOR_SIGNATURE 1
  585. #define CPUID_XFAM 0x0ff00000
  586. #define CPUID_XFAM_K8 0x00000000
  587. #define CPUID_XFAM_10H 0x00100000
  588. #define CPUID_XFAM_11H 0x00200000
  589. #define CPUID_XMOD 0x000f0000
  590. #define CPUID_XMOD_REV_F 0x00040000
  591. /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
  592. static __cpuinit int amd_apic_timer_broken(void)
  593. {
  594. u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
  595. switch (eax & CPUID_XFAM) {
  596. case CPUID_XFAM_K8:
  597. if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
  598. break;
  599. case CPUID_XFAM_10H:
  600. case CPUID_XFAM_11H:
  601. rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
  602. if (lo & ENABLE_C1E_MASK)
  603. return 1;
  604. break;
  605. default:
  606. /* err on the side of caution */
  607. return 1;
  608. }
  609. return 0;
  610. }
  611. static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
  612. {
  613. early_init_amd_mc(c);
  614. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  615. if (c->x86_power & (1<<8))
  616. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  617. }
  618. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  619. {
  620. unsigned level;
  621. #ifdef CONFIG_SMP
  622. unsigned long value;
  623. /*
  624. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  625. * bit 6 of msr C001_0015
  626. *
  627. * Errata 63 for SH-B3 steppings
  628. * Errata 122 for all steppings (F+ have it disabled by default)
  629. */
  630. if (c->x86 == 15) {
  631. rdmsrl(MSR_K8_HWCR, value);
  632. value |= 1 << 6;
  633. wrmsrl(MSR_K8_HWCR, value);
  634. }
  635. #endif
  636. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  637. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  638. clear_cpu_cap(c, 0*32+31);
  639. /* On C+ stepping K8 rep microcode works well for copy/memset */
  640. level = cpuid_eax(1);
  641. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
  642. level >= 0x0f58))
  643. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  644. if (c->x86 == 0x10 || c->x86 == 0x11)
  645. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  646. /* Enable workaround for FXSAVE leak */
  647. if (c->x86 >= 6)
  648. set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
  649. level = get_model_name(c);
  650. if (!level) {
  651. switch (c->x86) {
  652. case 15:
  653. /* Should distinguish Models here, but this is only
  654. a fallback anyways. */
  655. strcpy(c->x86_model_id, "Hammer");
  656. break;
  657. }
  658. }
  659. display_cacheinfo(c);
  660. /* Multi core CPU? */
  661. if (c->extended_cpuid_level >= 0x80000008)
  662. amd_detect_cmp(c);
  663. if (c->extended_cpuid_level >= 0x80000006 &&
  664. (cpuid_edx(0x80000006) & 0xf000))
  665. num_cache_leaves = 4;
  666. else
  667. num_cache_leaves = 3;
  668. if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
  669. set_cpu_cap(c, X86_FEATURE_K8);
  670. /* MFENCE stops RDTSC speculation */
  671. set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
  672. if (c->x86 == 0x10)
  673. fam10h_check_enable_mmcfg();
  674. if (amd_apic_timer_broken())
  675. disable_apic_timer = 1;
  676. if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
  677. unsigned long long tseg;
  678. /*
  679. * Split up direct mapping around the TSEG SMM area.
  680. * Don't do it for gbpages because there seems very little
  681. * benefit in doing so.
  682. */
  683. if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
  684. (tseg >> PMD_SHIFT) < (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
  685. set_memory_4k((unsigned long)__va(tseg), 1);
  686. }
  687. }
  688. void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  689. {
  690. #ifdef CONFIG_SMP
  691. u32 eax, ebx, ecx, edx;
  692. int index_msb, core_bits;
  693. cpuid(1, &eax, &ebx, &ecx, &edx);
  694. if (!cpu_has(c, X86_FEATURE_HT))
  695. return;
  696. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  697. goto out;
  698. smp_num_siblings = (ebx & 0xff0000) >> 16;
  699. if (smp_num_siblings == 1) {
  700. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  701. } else if (smp_num_siblings > 1) {
  702. if (smp_num_siblings > NR_CPUS) {
  703. printk(KERN_WARNING "CPU: Unsupported number of "
  704. "siblings %d", smp_num_siblings);
  705. smp_num_siblings = 1;
  706. return;
  707. }
  708. index_msb = get_count_order(smp_num_siblings);
  709. c->phys_proc_id = phys_pkg_id(index_msb);
  710. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  711. index_msb = get_count_order(smp_num_siblings);
  712. core_bits = get_count_order(c->x86_max_cores);
  713. c->cpu_core_id = phys_pkg_id(index_msb) &
  714. ((1 << core_bits) - 1);
  715. }
  716. out:
  717. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  718. printk(KERN_INFO "CPU: Physical Processor ID: %d\n",
  719. c->phys_proc_id);
  720. printk(KERN_INFO "CPU: Processor Core ID: %d\n",
  721. c->cpu_core_id);
  722. }
  723. #endif
  724. }
  725. /*
  726. * find out the number of processor cores on the die
  727. */
  728. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  729. {
  730. unsigned int eax, t;
  731. if (c->cpuid_level < 4)
  732. return 1;
  733. cpuid_count(4, 0, &eax, &t, &t, &t);
  734. if (eax & 0x1f)
  735. return ((eax >> 26) + 1);
  736. else
  737. return 1;
  738. }
  739. static void __cpuinit srat_detect_node(void)
  740. {
  741. #ifdef CONFIG_NUMA
  742. unsigned node;
  743. int cpu = smp_processor_id();
  744. int apicid = hard_smp_processor_id();
  745. /* Don't do the funky fallback heuristics the AMD version employs
  746. for now. */
  747. node = apicid_to_node[apicid];
  748. if (node == NUMA_NO_NODE || !node_online(node))
  749. node = first_node(node_online_map);
  750. numa_set_node(cpu, node);
  751. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  752. #endif
  753. }
  754. static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
  755. {
  756. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  757. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  758. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  759. }
  760. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  761. {
  762. /* Cache sizes */
  763. unsigned n;
  764. init_intel_cacheinfo(c);
  765. if (c->cpuid_level > 9) {
  766. unsigned eax = cpuid_eax(10);
  767. /* Check for version and the number of counters */
  768. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  769. set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
  770. }
  771. if (cpu_has_ds) {
  772. unsigned int l1, l2;
  773. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  774. if (!(l1 & (1<<11)))
  775. set_cpu_cap(c, X86_FEATURE_BTS);
  776. if (!(l1 & (1<<12)))
  777. set_cpu_cap(c, X86_FEATURE_PEBS);
  778. }
  779. if (cpu_has_bts)
  780. ds_init_intel(c);
  781. n = c->extended_cpuid_level;
  782. if (n >= 0x80000008) {
  783. unsigned eax = cpuid_eax(0x80000008);
  784. c->x86_virt_bits = (eax >> 8) & 0xff;
  785. c->x86_phys_bits = eax & 0xff;
  786. /* CPUID workaround for Intel 0F34 CPU */
  787. if (c->x86_vendor == X86_VENDOR_INTEL &&
  788. c->x86 == 0xF && c->x86_model == 0x3 &&
  789. c->x86_mask == 0x4)
  790. c->x86_phys_bits = 36;
  791. }
  792. if (c->x86 == 15)
  793. c->x86_cache_alignment = c->x86_clflush_size * 2;
  794. if (c->x86 == 6)
  795. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  796. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  797. c->x86_max_cores = intel_num_cpu_cores(c);
  798. srat_detect_node();
  799. }
  800. static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
  801. {
  802. if (c->x86 == 0x6 && c->x86_model >= 0xf)
  803. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  804. }
  805. static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
  806. {
  807. /* Cache sizes */
  808. unsigned n;
  809. n = c->extended_cpuid_level;
  810. if (n >= 0x80000008) {
  811. unsigned eax = cpuid_eax(0x80000008);
  812. c->x86_virt_bits = (eax >> 8) & 0xff;
  813. c->x86_phys_bits = eax & 0xff;
  814. }
  815. if (c->x86 == 0x6 && c->x86_model >= 0xf) {
  816. c->x86_cache_alignment = c->x86_clflush_size * 2;
  817. set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
  818. set_cpu_cap(c, X86_FEATURE_REP_GOOD);
  819. }
  820. set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
  821. }
  822. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  823. {
  824. char *v = c->x86_vendor_id;
  825. if (!strcmp(v, "AuthenticAMD"))
  826. c->x86_vendor = X86_VENDOR_AMD;
  827. else if (!strcmp(v, "GenuineIntel"))
  828. c->x86_vendor = X86_VENDOR_INTEL;
  829. else if (!strcmp(v, "CentaurHauls"))
  830. c->x86_vendor = X86_VENDOR_CENTAUR;
  831. else
  832. c->x86_vendor = X86_VENDOR_UNKNOWN;
  833. }
  834. /* Do some early cpuid on the boot CPU to get some parameter that are
  835. needed before check_bugs. Everything advanced is in identify_cpu
  836. below. */
  837. static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  838. {
  839. u32 tfms, xlvl;
  840. c->loops_per_jiffy = loops_per_jiffy;
  841. c->x86_cache_size = -1;
  842. c->x86_vendor = X86_VENDOR_UNKNOWN;
  843. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  844. c->x86_vendor_id[0] = '\0'; /* Unset */
  845. c->x86_model_id[0] = '\0'; /* Unset */
  846. c->x86_clflush_size = 64;
  847. c->x86_cache_alignment = c->x86_clflush_size;
  848. c->x86_max_cores = 1;
  849. c->x86_coreid_bits = 0;
  850. c->extended_cpuid_level = 0;
  851. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  852. /* Get vendor name */
  853. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  854. (unsigned int *)&c->x86_vendor_id[0],
  855. (unsigned int *)&c->x86_vendor_id[8],
  856. (unsigned int *)&c->x86_vendor_id[4]);
  857. get_cpu_vendor(c);
  858. /* Initialize the standard set of capabilities */
  859. /* Note that the vendor-specific code below might override */
  860. /* Intel-defined flags: level 0x00000001 */
  861. if (c->cpuid_level >= 0x00000001) {
  862. __u32 misc;
  863. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  864. &c->x86_capability[0]);
  865. c->x86 = (tfms >> 8) & 0xf;
  866. c->x86_model = (tfms >> 4) & 0xf;
  867. c->x86_mask = tfms & 0xf;
  868. if (c->x86 == 0xf)
  869. c->x86 += (tfms >> 20) & 0xff;
  870. if (c->x86 >= 0x6)
  871. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  872. if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
  873. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  874. } else {
  875. /* Have CPUID level 0 only - unheard of */
  876. c->x86 = 4;
  877. }
  878. c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
  879. #ifdef CONFIG_SMP
  880. c->phys_proc_id = c->initial_apicid;
  881. #endif
  882. /* AMD-defined flags: level 0x80000001 */
  883. xlvl = cpuid_eax(0x80000000);
  884. c->extended_cpuid_level = xlvl;
  885. if ((xlvl & 0xffff0000) == 0x80000000) {
  886. if (xlvl >= 0x80000001) {
  887. c->x86_capability[1] = cpuid_edx(0x80000001);
  888. c->x86_capability[6] = cpuid_ecx(0x80000001);
  889. }
  890. if (xlvl >= 0x80000004)
  891. get_model_name(c); /* Default name */
  892. }
  893. /* Transmeta-defined flags: level 0x80860001 */
  894. xlvl = cpuid_eax(0x80860000);
  895. if ((xlvl & 0xffff0000) == 0x80860000) {
  896. /* Don't set x86_cpuid_level here for now to not confuse. */
  897. if (xlvl >= 0x80860001)
  898. c->x86_capability[2] = cpuid_edx(0x80860001);
  899. }
  900. c->extended_cpuid_level = cpuid_eax(0x80000000);
  901. if (c->extended_cpuid_level >= 0x80000007)
  902. c->x86_power = cpuid_edx(0x80000007);
  903. switch (c->x86_vendor) {
  904. case X86_VENDOR_AMD:
  905. early_init_amd(c);
  906. break;
  907. case X86_VENDOR_INTEL:
  908. early_init_intel(c);
  909. break;
  910. case X86_VENDOR_CENTAUR:
  911. early_init_centaur(c);
  912. break;
  913. }
  914. validate_pat_support(c);
  915. }
  916. /*
  917. * This does the hard work of actually picking apart the CPU stuff...
  918. */
  919. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  920. {
  921. int i;
  922. early_identify_cpu(c);
  923. init_scattered_cpuid_features(c);
  924. c->apicid = phys_pkg_id(0);
  925. /*
  926. * Vendor-specific initialization. In this section we
  927. * canonicalize the feature flags, meaning if there are
  928. * features a certain CPU supports which CPUID doesn't
  929. * tell us, CPUID claiming incorrect flags, or other bugs,
  930. * we handle them here.
  931. *
  932. * At the end of this section, c->x86_capability better
  933. * indicate the features this CPU genuinely supports!
  934. */
  935. switch (c->x86_vendor) {
  936. case X86_VENDOR_AMD:
  937. init_amd(c);
  938. break;
  939. case X86_VENDOR_INTEL:
  940. init_intel(c);
  941. break;
  942. case X86_VENDOR_CENTAUR:
  943. init_centaur(c);
  944. break;
  945. case X86_VENDOR_UNKNOWN:
  946. default:
  947. display_cacheinfo(c);
  948. break;
  949. }
  950. detect_ht(c);
  951. /*
  952. * On SMP, boot_cpu_data holds the common feature set between
  953. * all CPUs; so make sure that we indicate which features are
  954. * common between the CPUs. The first time this routine gets
  955. * executed, c == &boot_cpu_data.
  956. */
  957. if (c != &boot_cpu_data) {
  958. /* AND the already accumulated flags with these */
  959. for (i = 0; i < NCAPINTS; i++)
  960. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  961. }
  962. /* Clear all flags overriden by options */
  963. for (i = 0; i < NCAPINTS; i++)
  964. c->x86_capability[i] &= ~cleared_cpu_caps[i];
  965. #ifdef CONFIG_X86_MCE
  966. mcheck_init(c);
  967. #endif
  968. select_idle_routine(c);
  969. #ifdef CONFIG_NUMA
  970. numa_add_cpu(smp_processor_id());
  971. #endif
  972. }
  973. void __cpuinit identify_boot_cpu(void)
  974. {
  975. identify_cpu(&boot_cpu_data);
  976. }
  977. void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
  978. {
  979. BUG_ON(c == &boot_cpu_data);
  980. identify_cpu(c);
  981. mtrr_ap_init();
  982. }
  983. static __init int setup_noclflush(char *arg)
  984. {
  985. setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
  986. return 1;
  987. }
  988. __setup("noclflush", setup_noclflush);
  989. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  990. {
  991. if (c->x86_model_id[0])
  992. printk(KERN_CONT "%s", c->x86_model_id);
  993. if (c->x86_mask || c->cpuid_level >= 0)
  994. printk(KERN_CONT " stepping %02x\n", c->x86_mask);
  995. else
  996. printk(KERN_CONT "\n");
  997. }
  998. static __init int setup_disablecpuid(char *arg)
  999. {
  1000. int bit;
  1001. if (get_option(&arg, &bit) && bit < NCAPINTS*32)
  1002. setup_clear_cpu_cap(bit);
  1003. else
  1004. return 0;
  1005. return 1;
  1006. }
  1007. __setup("clearcpuid=", setup_disablecpuid);