setup.c 28 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103
  1. /*
  2. * linux/arch/x86-64/kernel/setup.c
  3. *
  4. * Copyright (C) 1995 Linus Torvalds
  5. *
  6. * Nov 2001 Dave Jones <davej@suse.de>
  7. * Forked from i386 setup code.
  8. */
  9. /*
  10. * This file handles the architecture-dependent parts of initialization
  11. */
  12. #include <linux/errno.h>
  13. #include <linux/sched.h>
  14. #include <linux/kernel.h>
  15. #include <linux/mm.h>
  16. #include <linux/stddef.h>
  17. #include <linux/unistd.h>
  18. #include <linux/ptrace.h>
  19. #include <linux/slab.h>
  20. #include <linux/user.h>
  21. #include <linux/a.out.h>
  22. #include <linux/screen_info.h>
  23. #include <linux/ioport.h>
  24. #include <linux/delay.h>
  25. #include <linux/init.h>
  26. #include <linux/initrd.h>
  27. #include <linux/highmem.h>
  28. #include <linux/bootmem.h>
  29. #include <linux/module.h>
  30. #include <asm/processor.h>
  31. #include <linux/console.h>
  32. #include <linux/seq_file.h>
  33. #include <linux/crash_dump.h>
  34. #include <linux/root_dev.h>
  35. #include <linux/pci.h>
  36. #include <linux/acpi.h>
  37. #include <linux/kallsyms.h>
  38. #include <linux/edd.h>
  39. #include <linux/mmzone.h>
  40. #include <linux/kexec.h>
  41. #include <linux/cpufreq.h>
  42. #include <linux/dmi.h>
  43. #include <linux/dma-mapping.h>
  44. #include <linux/ctype.h>
  45. #include <asm/mtrr.h>
  46. #include <asm/uaccess.h>
  47. #include <asm/system.h>
  48. #include <asm/io.h>
  49. #include <asm/smp.h>
  50. #include <asm/msr.h>
  51. #include <asm/desc.h>
  52. #include <video/edid.h>
  53. #include <asm/e820.h>
  54. #include <asm/dma.h>
  55. #include <asm/mpspec.h>
  56. #include <asm/mmu_context.h>
  57. #include <asm/bootsetup.h>
  58. #include <asm/proto.h>
  59. #include <asm/setup.h>
  60. #include <asm/mach_apic.h>
  61. #include <asm/numa.h>
  62. #include <asm/sections.h>
  63. #include <asm/dmi.h>
  64. /*
  65. * Machine setup..
  66. */
  67. struct cpuinfo_x86 boot_cpu_data __read_mostly;
  68. EXPORT_SYMBOL(boot_cpu_data);
  69. unsigned long mmu_cr4_features;
  70. /* Boot loader ID as an integer, for the benefit of proc_dointvec */
  71. int bootloader_type;
  72. unsigned long saved_video_mode;
  73. int force_mwait __cpuinitdata;
  74. /*
  75. * Early DMI memory
  76. */
  77. int dmi_alloc_index;
  78. char dmi_alloc_data[DMI_MAX_DATA];
  79. /*
  80. * Setup options
  81. */
  82. struct screen_info screen_info;
  83. EXPORT_SYMBOL(screen_info);
  84. struct sys_desc_table_struct {
  85. unsigned short length;
  86. unsigned char table[0];
  87. };
  88. struct edid_info edid_info;
  89. EXPORT_SYMBOL_GPL(edid_info);
  90. extern int root_mountflags;
  91. char __initdata command_line[COMMAND_LINE_SIZE];
  92. struct resource standard_io_resources[] = {
  93. { .name = "dma1", .start = 0x00, .end = 0x1f,
  94. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  95. { .name = "pic1", .start = 0x20, .end = 0x21,
  96. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  97. { .name = "timer0", .start = 0x40, .end = 0x43,
  98. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  99. { .name = "timer1", .start = 0x50, .end = 0x53,
  100. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  101. { .name = "keyboard", .start = 0x60, .end = 0x6f,
  102. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  103. { .name = "dma page reg", .start = 0x80, .end = 0x8f,
  104. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  105. { .name = "pic2", .start = 0xa0, .end = 0xa1,
  106. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  107. { .name = "dma2", .start = 0xc0, .end = 0xdf,
  108. .flags = IORESOURCE_BUSY | IORESOURCE_IO },
  109. { .name = "fpu", .start = 0xf0, .end = 0xff,
  110. .flags = IORESOURCE_BUSY | IORESOURCE_IO }
  111. };
  112. #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
  113. struct resource data_resource = {
  114. .name = "Kernel data",
  115. .start = 0,
  116. .end = 0,
  117. .flags = IORESOURCE_RAM,
  118. };
  119. struct resource code_resource = {
  120. .name = "Kernel code",
  121. .start = 0,
  122. .end = 0,
  123. .flags = IORESOURCE_RAM,
  124. };
  125. #ifdef CONFIG_PROC_VMCORE
  126. /* elfcorehdr= specifies the location of elf core header
  127. * stored by the crashed kernel. This option will be passed
  128. * by kexec loader to the capture kernel.
  129. */
  130. static int __init setup_elfcorehdr(char *arg)
  131. {
  132. char *end;
  133. if (!arg)
  134. return -EINVAL;
  135. elfcorehdr_addr = memparse(arg, &end);
  136. return end > arg ? 0 : -EINVAL;
  137. }
  138. early_param("elfcorehdr", setup_elfcorehdr);
  139. #endif
  140. #ifndef CONFIG_NUMA
  141. static void __init
  142. contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
  143. {
  144. unsigned long bootmap_size, bootmap;
  145. bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
  146. bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size);
  147. if (bootmap == -1L)
  148. panic("Cannot find bootmem map of size %ld\n",bootmap_size);
  149. bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
  150. e820_register_active_regions(0, start_pfn, end_pfn);
  151. free_bootmem_with_active_regions(0, end_pfn);
  152. reserve_bootmem(bootmap, bootmap_size);
  153. }
  154. #endif
  155. #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
  156. struct edd edd;
  157. #ifdef CONFIG_EDD_MODULE
  158. EXPORT_SYMBOL(edd);
  159. #endif
  160. /**
  161. * copy_edd() - Copy the BIOS EDD information
  162. * from boot_params into a safe place.
  163. *
  164. */
  165. static inline void copy_edd(void)
  166. {
  167. memcpy(edd.mbr_signature, EDD_MBR_SIGNATURE, sizeof(edd.mbr_signature));
  168. memcpy(edd.edd_info, EDD_BUF, sizeof(edd.edd_info));
  169. edd.mbr_signature_nr = EDD_MBR_SIG_NR;
  170. edd.edd_info_nr = EDD_NR;
  171. }
  172. #else
  173. static inline void copy_edd(void)
  174. {
  175. }
  176. #endif
  177. #define EBDA_ADDR_POINTER 0x40E
  178. unsigned __initdata ebda_addr;
  179. unsigned __initdata ebda_size;
  180. static void discover_ebda(void)
  181. {
  182. /*
  183. * there is a real-mode segmented pointer pointing to the
  184. * 4K EBDA area at 0x40E
  185. */
  186. ebda_addr = *(unsigned short *)__va(EBDA_ADDR_POINTER);
  187. ebda_addr <<= 4;
  188. ebda_size = *(unsigned short *)__va(ebda_addr);
  189. /* Round EBDA up to pages */
  190. if (ebda_size == 0)
  191. ebda_size = 1;
  192. ebda_size <<= 10;
  193. ebda_size = round_up(ebda_size + (ebda_addr & ~PAGE_MASK), PAGE_SIZE);
  194. if (ebda_size > 64*1024)
  195. ebda_size = 64*1024;
  196. }
  197. void __init setup_arch(char **cmdline_p)
  198. {
  199. printk(KERN_INFO "Command line: %s\n", boot_command_line);
  200. ROOT_DEV = old_decode_dev(ORIG_ROOT_DEV);
  201. screen_info = SCREEN_INFO;
  202. edid_info = EDID_INFO;
  203. saved_video_mode = SAVED_VIDEO_MODE;
  204. bootloader_type = LOADER_TYPE;
  205. #ifdef CONFIG_BLK_DEV_RAM
  206. rd_image_start = RAMDISK_FLAGS & RAMDISK_IMAGE_START_MASK;
  207. rd_prompt = ((RAMDISK_FLAGS & RAMDISK_PROMPT_FLAG) != 0);
  208. rd_doload = ((RAMDISK_FLAGS & RAMDISK_LOAD_FLAG) != 0);
  209. #endif
  210. setup_memory_region();
  211. copy_edd();
  212. if (!MOUNT_ROOT_RDONLY)
  213. root_mountflags &= ~MS_RDONLY;
  214. init_mm.start_code = (unsigned long) &_text;
  215. init_mm.end_code = (unsigned long) &_etext;
  216. init_mm.end_data = (unsigned long) &_edata;
  217. init_mm.brk = (unsigned long) &_end;
  218. init_mm.pgd = __va(__pa_symbol(&init_level4_pgt));
  219. code_resource.start = __pa_symbol(&_text);
  220. code_resource.end = __pa_symbol(&_etext)-1;
  221. data_resource.start = __pa_symbol(&_etext);
  222. data_resource.end = __pa_symbol(&_edata)-1;
  223. early_identify_cpu(&boot_cpu_data);
  224. strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  225. *cmdline_p = command_line;
  226. parse_early_param();
  227. finish_e820_parsing();
  228. e820_register_active_regions(0, 0, -1UL);
  229. /*
  230. * partially used pages are not usable - thus
  231. * we are rounding upwards:
  232. */
  233. end_pfn = e820_end_of_ram();
  234. num_physpages = end_pfn;
  235. check_efer();
  236. discover_ebda();
  237. init_memory_mapping(0, (end_pfn_map << PAGE_SHIFT));
  238. dmi_scan_machine();
  239. #ifdef CONFIG_ACPI
  240. /*
  241. * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
  242. * Call this early for SRAT node setup.
  243. */
  244. acpi_boot_table_init();
  245. #endif
  246. /* How many end-of-memory variables you have, grandma! */
  247. max_low_pfn = end_pfn;
  248. max_pfn = end_pfn;
  249. high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
  250. /* Remove active ranges so rediscovery with NUMA-awareness happens */
  251. remove_all_active_ranges();
  252. #ifdef CONFIG_ACPI_NUMA
  253. /*
  254. * Parse SRAT to discover nodes.
  255. */
  256. acpi_numa_init();
  257. #endif
  258. #ifdef CONFIG_NUMA
  259. numa_initmem_init(0, end_pfn);
  260. #else
  261. contig_initmem_init(0, end_pfn);
  262. #endif
  263. /* Reserve direct mapping */
  264. reserve_bootmem_generic(table_start << PAGE_SHIFT,
  265. (table_end - table_start) << PAGE_SHIFT);
  266. /* reserve kernel */
  267. reserve_bootmem_generic(__pa_symbol(&_text),
  268. __pa_symbol(&_end) - __pa_symbol(&_text));
  269. /*
  270. * reserve physical page 0 - it's a special BIOS page on many boxes,
  271. * enabling clean reboots, SMP operation, laptop functions.
  272. */
  273. reserve_bootmem_generic(0, PAGE_SIZE);
  274. /* reserve ebda region */
  275. if (ebda_addr)
  276. reserve_bootmem_generic(ebda_addr, ebda_size);
  277. #ifdef CONFIG_NUMA
  278. /* reserve nodemap region */
  279. if (nodemap_addr)
  280. reserve_bootmem_generic(nodemap_addr, nodemap_size);
  281. #endif
  282. #ifdef CONFIG_SMP
  283. /* Reserve SMP trampoline */
  284. reserve_bootmem_generic(SMP_TRAMPOLINE_BASE, 2*PAGE_SIZE);
  285. #endif
  286. #ifdef CONFIG_ACPI_SLEEP
  287. /*
  288. * Reserve low memory region for sleep support.
  289. */
  290. acpi_reserve_bootmem();
  291. #endif
  292. /*
  293. * Find and reserve possible boot-time SMP configuration:
  294. */
  295. find_smp_config();
  296. #ifdef CONFIG_BLK_DEV_INITRD
  297. if (LOADER_TYPE && INITRD_START) {
  298. if (INITRD_START + INITRD_SIZE <= (end_pfn << PAGE_SHIFT)) {
  299. reserve_bootmem_generic(INITRD_START, INITRD_SIZE);
  300. initrd_start = INITRD_START + PAGE_OFFSET;
  301. initrd_end = initrd_start+INITRD_SIZE;
  302. }
  303. else {
  304. printk(KERN_ERR "initrd extends beyond end of memory "
  305. "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
  306. (unsigned long)(INITRD_START + INITRD_SIZE),
  307. (unsigned long)(end_pfn << PAGE_SHIFT));
  308. initrd_start = 0;
  309. }
  310. }
  311. #endif
  312. #ifdef CONFIG_KEXEC
  313. if (crashk_res.start != crashk_res.end) {
  314. reserve_bootmem_generic(crashk_res.start,
  315. crashk_res.end - crashk_res.start + 1);
  316. }
  317. #endif
  318. paging_init();
  319. #ifdef CONFIG_PCI
  320. early_quirks();
  321. #endif
  322. /*
  323. * set this early, so we dont allocate cpu0
  324. * if MADT list doesnt list BSP first
  325. * mpparse.c/MP_processor_info() allocates logical cpu numbers.
  326. */
  327. cpu_set(0, cpu_present_map);
  328. #ifdef CONFIG_ACPI
  329. /*
  330. * Read APIC and some other early information from ACPI tables.
  331. */
  332. acpi_boot_init();
  333. #endif
  334. init_cpu_to_node();
  335. /*
  336. * get boot-time SMP configuration:
  337. */
  338. if (smp_found_config)
  339. get_smp_config();
  340. init_apic_mappings();
  341. /*
  342. * We trust e820 completely. No explicit ROM probing in memory.
  343. */
  344. e820_reserve_resources();
  345. e820_mark_nosave_regions();
  346. {
  347. unsigned i;
  348. /* request I/O space for devices used on all i[345]86 PCs */
  349. for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
  350. request_resource(&ioport_resource, &standard_io_resources[i]);
  351. }
  352. e820_setup_gap();
  353. #ifdef CONFIG_VT
  354. #if defined(CONFIG_VGA_CONSOLE)
  355. conswitchp = &vga_con;
  356. #elif defined(CONFIG_DUMMY_CONSOLE)
  357. conswitchp = &dummy_con;
  358. #endif
  359. #endif
  360. }
  361. static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
  362. {
  363. unsigned int *v;
  364. if (c->extended_cpuid_level < 0x80000004)
  365. return 0;
  366. v = (unsigned int *) c->x86_model_id;
  367. cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
  368. cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
  369. cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
  370. c->x86_model_id[48] = 0;
  371. return 1;
  372. }
  373. static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
  374. {
  375. unsigned int n, dummy, eax, ebx, ecx, edx;
  376. n = c->extended_cpuid_level;
  377. if (n >= 0x80000005) {
  378. cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
  379. printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n",
  380. edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
  381. c->x86_cache_size=(ecx>>24)+(edx>>24);
  382. /* On K8 L1 TLB is inclusive, so don't count it */
  383. c->x86_tlbsize = 0;
  384. }
  385. if (n >= 0x80000006) {
  386. cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
  387. ecx = cpuid_ecx(0x80000006);
  388. c->x86_cache_size = ecx >> 16;
  389. c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
  390. printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
  391. c->x86_cache_size, ecx & 0xFF);
  392. }
  393. if (n >= 0x80000007)
  394. cpuid(0x80000007, &dummy, &dummy, &dummy, &c->x86_power);
  395. if (n >= 0x80000008) {
  396. cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
  397. c->x86_virt_bits = (eax >> 8) & 0xff;
  398. c->x86_phys_bits = eax & 0xff;
  399. }
  400. }
  401. #ifdef CONFIG_NUMA
  402. static int nearby_node(int apicid)
  403. {
  404. int i;
  405. for (i = apicid - 1; i >= 0; i--) {
  406. int node = apicid_to_node[i];
  407. if (node != NUMA_NO_NODE && node_online(node))
  408. return node;
  409. }
  410. for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
  411. int node = apicid_to_node[i];
  412. if (node != NUMA_NO_NODE && node_online(node))
  413. return node;
  414. }
  415. return first_node(node_online_map); /* Shouldn't happen */
  416. }
  417. #endif
  418. /*
  419. * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
  420. * Assumes number of cores is a power of two.
  421. */
  422. static void __init amd_detect_cmp(struct cpuinfo_x86 *c)
  423. {
  424. #ifdef CONFIG_SMP
  425. unsigned bits;
  426. #ifdef CONFIG_NUMA
  427. int cpu = smp_processor_id();
  428. int node = 0;
  429. unsigned apicid = hard_smp_processor_id();
  430. #endif
  431. unsigned ecx = cpuid_ecx(0x80000008);
  432. c->x86_max_cores = (ecx & 0xff) + 1;
  433. /* CPU telling us the core id bits shift? */
  434. bits = (ecx >> 12) & 0xF;
  435. /* Otherwise recompute */
  436. if (bits == 0) {
  437. while ((1 << bits) < c->x86_max_cores)
  438. bits++;
  439. }
  440. /* Low order bits define the core id (index of core in socket) */
  441. c->cpu_core_id = c->phys_proc_id & ((1 << bits)-1);
  442. /* Convert the APIC ID into the socket ID */
  443. c->phys_proc_id = phys_pkg_id(bits);
  444. #ifdef CONFIG_NUMA
  445. node = c->phys_proc_id;
  446. if (apicid_to_node[apicid] != NUMA_NO_NODE)
  447. node = apicid_to_node[apicid];
  448. if (!node_online(node)) {
  449. /* Two possibilities here:
  450. - The CPU is missing memory and no node was created.
  451. In that case try picking one from a nearby CPU
  452. - The APIC IDs differ from the HyperTransport node IDs
  453. which the K8 northbridge parsing fills in.
  454. Assume they are all increased by a constant offset,
  455. but in the same order as the HT nodeids.
  456. If that doesn't result in a usable node fall back to the
  457. path for the previous case. */
  458. int ht_nodeid = apicid - (cpu_data[0].phys_proc_id << bits);
  459. if (ht_nodeid >= 0 &&
  460. apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
  461. node = apicid_to_node[ht_nodeid];
  462. /* Pick a nearby node */
  463. if (!node_online(node))
  464. node = nearby_node(apicid);
  465. }
  466. numa_set_node(cpu, node);
  467. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  468. #endif
  469. #endif
  470. }
  471. static void __cpuinit init_amd(struct cpuinfo_x86 *c)
  472. {
  473. unsigned level;
  474. #ifdef CONFIG_SMP
  475. unsigned long value;
  476. /*
  477. * Disable TLB flush filter by setting HWCR.FFDIS on K8
  478. * bit 6 of msr C001_0015
  479. *
  480. * Errata 63 for SH-B3 steppings
  481. * Errata 122 for all steppings (F+ have it disabled by default)
  482. */
  483. if (c->x86 == 15) {
  484. rdmsrl(MSR_K8_HWCR, value);
  485. value |= 1 << 6;
  486. wrmsrl(MSR_K8_HWCR, value);
  487. }
  488. #endif
  489. /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
  490. 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
  491. clear_bit(0*32+31, &c->x86_capability);
  492. /* On C+ stepping K8 rep microcode works well for copy/memset */
  493. level = cpuid_eax(1);
  494. if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) || level >= 0x0f58))
  495. set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
  496. /* Enable workaround for FXSAVE leak */
  497. if (c->x86 >= 6)
  498. set_bit(X86_FEATURE_FXSAVE_LEAK, &c->x86_capability);
  499. level = get_model_name(c);
  500. if (!level) {
  501. switch (c->x86) {
  502. case 15:
  503. /* Should distinguish Models here, but this is only
  504. a fallback anyways. */
  505. strcpy(c->x86_model_id, "Hammer");
  506. break;
  507. }
  508. }
  509. display_cacheinfo(c);
  510. /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
  511. if (c->x86_power & (1<<8))
  512. set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
  513. /* Multi core CPU? */
  514. if (c->extended_cpuid_level >= 0x80000008)
  515. amd_detect_cmp(c);
  516. /* Fix cpuid4 emulation for more */
  517. num_cache_leaves = 3;
  518. /* RDTSC can be speculated around */
  519. clear_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  520. /* Family 10 doesn't support C states in MWAIT so don't use it */
  521. if (c->x86 == 0x10 && !force_mwait)
  522. clear_bit(X86_FEATURE_MWAIT, &c->x86_capability);
  523. }
  524. static void __cpuinit detect_ht(struct cpuinfo_x86 *c)
  525. {
  526. #ifdef CONFIG_SMP
  527. u32 eax, ebx, ecx, edx;
  528. int index_msb, core_bits;
  529. cpuid(1, &eax, &ebx, &ecx, &edx);
  530. if (!cpu_has(c, X86_FEATURE_HT))
  531. return;
  532. if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
  533. goto out;
  534. smp_num_siblings = (ebx & 0xff0000) >> 16;
  535. if (smp_num_siblings == 1) {
  536. printk(KERN_INFO "CPU: Hyper-Threading is disabled\n");
  537. } else if (smp_num_siblings > 1 ) {
  538. if (smp_num_siblings > NR_CPUS) {
  539. printk(KERN_WARNING "CPU: Unsupported number of the siblings %d", smp_num_siblings);
  540. smp_num_siblings = 1;
  541. return;
  542. }
  543. index_msb = get_count_order(smp_num_siblings);
  544. c->phys_proc_id = phys_pkg_id(index_msb);
  545. smp_num_siblings = smp_num_siblings / c->x86_max_cores;
  546. index_msb = get_count_order(smp_num_siblings) ;
  547. core_bits = get_count_order(c->x86_max_cores);
  548. c->cpu_core_id = phys_pkg_id(index_msb) &
  549. ((1 << core_bits) - 1);
  550. }
  551. out:
  552. if ((c->x86_max_cores * smp_num_siblings) > 1) {
  553. printk(KERN_INFO "CPU: Physical Processor ID: %d\n", c->phys_proc_id);
  554. printk(KERN_INFO "CPU: Processor Core ID: %d\n", c->cpu_core_id);
  555. }
  556. #endif
  557. }
  558. /*
  559. * find out the number of processor cores on the die
  560. */
  561. static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
  562. {
  563. unsigned int eax, t;
  564. if (c->cpuid_level < 4)
  565. return 1;
  566. cpuid_count(4, 0, &eax, &t, &t, &t);
  567. if (eax & 0x1f)
  568. return ((eax >> 26) + 1);
  569. else
  570. return 1;
  571. }
  572. static void srat_detect_node(void)
  573. {
  574. #ifdef CONFIG_NUMA
  575. unsigned node;
  576. int cpu = smp_processor_id();
  577. int apicid = hard_smp_processor_id();
  578. /* Don't do the funky fallback heuristics the AMD version employs
  579. for now. */
  580. node = apicid_to_node[apicid];
  581. if (node == NUMA_NO_NODE)
  582. node = first_node(node_online_map);
  583. numa_set_node(cpu, node);
  584. printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
  585. #endif
  586. }
  587. static void __cpuinit init_intel(struct cpuinfo_x86 *c)
  588. {
  589. /* Cache sizes */
  590. unsigned n;
  591. init_intel_cacheinfo(c);
  592. if (c->cpuid_level > 9 ) {
  593. unsigned eax = cpuid_eax(10);
  594. /* Check for version and the number of counters */
  595. if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
  596. set_bit(X86_FEATURE_ARCH_PERFMON, &c->x86_capability);
  597. }
  598. if (cpu_has_ds) {
  599. unsigned int l1, l2;
  600. rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
  601. if (!(l1 & (1<<11)))
  602. set_bit(X86_FEATURE_BTS, c->x86_capability);
  603. if (!(l1 & (1<<12)))
  604. set_bit(X86_FEATURE_PEBS, c->x86_capability);
  605. }
  606. n = c->extended_cpuid_level;
  607. if (n >= 0x80000008) {
  608. unsigned eax = cpuid_eax(0x80000008);
  609. c->x86_virt_bits = (eax >> 8) & 0xff;
  610. c->x86_phys_bits = eax & 0xff;
  611. /* CPUID workaround for Intel 0F34 CPU */
  612. if (c->x86_vendor == X86_VENDOR_INTEL &&
  613. c->x86 == 0xF && c->x86_model == 0x3 &&
  614. c->x86_mask == 0x4)
  615. c->x86_phys_bits = 36;
  616. }
  617. if (c->x86 == 15)
  618. c->x86_cache_alignment = c->x86_clflush_size * 2;
  619. if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
  620. (c->x86 == 0x6 && c->x86_model >= 0x0e))
  621. set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
  622. if (c->x86 == 6)
  623. set_bit(X86_FEATURE_REP_GOOD, &c->x86_capability);
  624. if (c->x86 == 15)
  625. set_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  626. else
  627. clear_bit(X86_FEATURE_SYNC_RDTSC, &c->x86_capability);
  628. c->x86_max_cores = intel_num_cpu_cores(c);
  629. srat_detect_node();
  630. }
  631. static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
  632. {
  633. char *v = c->x86_vendor_id;
  634. if (!strcmp(v, "AuthenticAMD"))
  635. c->x86_vendor = X86_VENDOR_AMD;
  636. else if (!strcmp(v, "GenuineIntel"))
  637. c->x86_vendor = X86_VENDOR_INTEL;
  638. else
  639. c->x86_vendor = X86_VENDOR_UNKNOWN;
  640. }
  641. struct cpu_model_info {
  642. int vendor;
  643. int family;
  644. char *model_names[16];
  645. };
  646. /* Do some early cpuid on the boot CPU to get some parameter that are
  647. needed before check_bugs. Everything advanced is in identify_cpu
  648. below. */
  649. void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
  650. {
  651. u32 tfms;
  652. c->loops_per_jiffy = loops_per_jiffy;
  653. c->x86_cache_size = -1;
  654. c->x86_vendor = X86_VENDOR_UNKNOWN;
  655. c->x86_model = c->x86_mask = 0; /* So far unknown... */
  656. c->x86_vendor_id[0] = '\0'; /* Unset */
  657. c->x86_model_id[0] = '\0'; /* Unset */
  658. c->x86_clflush_size = 64;
  659. c->x86_cache_alignment = c->x86_clflush_size;
  660. c->x86_max_cores = 1;
  661. c->extended_cpuid_level = 0;
  662. memset(&c->x86_capability, 0, sizeof c->x86_capability);
  663. /* Get vendor name */
  664. cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
  665. (unsigned int *)&c->x86_vendor_id[0],
  666. (unsigned int *)&c->x86_vendor_id[8],
  667. (unsigned int *)&c->x86_vendor_id[4]);
  668. get_cpu_vendor(c);
  669. /* Initialize the standard set of capabilities */
  670. /* Note that the vendor-specific code below might override */
  671. /* Intel-defined flags: level 0x00000001 */
  672. if (c->cpuid_level >= 0x00000001) {
  673. __u32 misc;
  674. cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
  675. &c->x86_capability[0]);
  676. c->x86 = (tfms >> 8) & 0xf;
  677. c->x86_model = (tfms >> 4) & 0xf;
  678. c->x86_mask = tfms & 0xf;
  679. if (c->x86 == 0xf)
  680. c->x86 += (tfms >> 20) & 0xff;
  681. if (c->x86 >= 0x6)
  682. c->x86_model += ((tfms >> 16) & 0xF) << 4;
  683. if (c->x86_capability[0] & (1<<19))
  684. c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
  685. } else {
  686. /* Have CPUID level 0 only - unheard of */
  687. c->x86 = 4;
  688. }
  689. #ifdef CONFIG_SMP
  690. c->phys_proc_id = (cpuid_ebx(1) >> 24) & 0xff;
  691. #endif
  692. }
  693. /*
  694. * This does the hard work of actually picking apart the CPU stuff...
  695. */
  696. void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
  697. {
  698. int i;
  699. u32 xlvl;
  700. early_identify_cpu(c);
  701. /* AMD-defined flags: level 0x80000001 */
  702. xlvl = cpuid_eax(0x80000000);
  703. c->extended_cpuid_level = xlvl;
  704. if ((xlvl & 0xffff0000) == 0x80000000) {
  705. if (xlvl >= 0x80000001) {
  706. c->x86_capability[1] = cpuid_edx(0x80000001);
  707. c->x86_capability[6] = cpuid_ecx(0x80000001);
  708. }
  709. if (xlvl >= 0x80000004)
  710. get_model_name(c); /* Default name */
  711. }
  712. /* Transmeta-defined flags: level 0x80860001 */
  713. xlvl = cpuid_eax(0x80860000);
  714. if ((xlvl & 0xffff0000) == 0x80860000) {
  715. /* Don't set x86_cpuid_level here for now to not confuse. */
  716. if (xlvl >= 0x80860001)
  717. c->x86_capability[2] = cpuid_edx(0x80860001);
  718. }
  719. c->apicid = phys_pkg_id(0);
  720. /*
  721. * Vendor-specific initialization. In this section we
  722. * canonicalize the feature flags, meaning if there are
  723. * features a certain CPU supports which CPUID doesn't
  724. * tell us, CPUID claiming incorrect flags, or other bugs,
  725. * we handle them here.
  726. *
  727. * At the end of this section, c->x86_capability better
  728. * indicate the features this CPU genuinely supports!
  729. */
  730. switch (c->x86_vendor) {
  731. case X86_VENDOR_AMD:
  732. init_amd(c);
  733. break;
  734. case X86_VENDOR_INTEL:
  735. init_intel(c);
  736. break;
  737. case X86_VENDOR_UNKNOWN:
  738. default:
  739. display_cacheinfo(c);
  740. break;
  741. }
  742. select_idle_routine(c);
  743. detect_ht(c);
  744. /*
  745. * On SMP, boot_cpu_data holds the common feature set between
  746. * all CPUs; so make sure that we indicate which features are
  747. * common between the CPUs. The first time this routine gets
  748. * executed, c == &boot_cpu_data.
  749. */
  750. if (c != &boot_cpu_data) {
  751. /* AND the already accumulated flags with these */
  752. for (i = 0 ; i < NCAPINTS ; i++)
  753. boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
  754. }
  755. #ifdef CONFIG_X86_MCE
  756. mcheck_init(c);
  757. #endif
  758. if (c == &boot_cpu_data)
  759. mtrr_bp_init();
  760. else
  761. mtrr_ap_init();
  762. #ifdef CONFIG_NUMA
  763. numa_add_cpu(smp_processor_id());
  764. #endif
  765. }
  766. void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
  767. {
  768. if (c->x86_model_id[0])
  769. printk("%s", c->x86_model_id);
  770. if (c->x86_mask || c->cpuid_level >= 0)
  771. printk(" stepping %02x\n", c->x86_mask);
  772. else
  773. printk("\n");
  774. }
  775. /*
  776. * Get CPU information for use by the procfs.
  777. */
  778. static int show_cpuinfo(struct seq_file *m, void *v)
  779. {
  780. struct cpuinfo_x86 *c = v;
  781. /*
  782. * These flag bits must match the definitions in <asm/cpufeature.h>.
  783. * NULL means this bit is undefined or reserved; either way it doesn't
  784. * have meaning as far as Linux is concerned. Note that it's important
  785. * to realize there is a difference between this table and CPUID -- if
  786. * applications want to get the raw CPUID data, they should access
  787. * /dev/cpu/<cpu_nr>/cpuid instead.
  788. */
  789. static char *x86_cap_flags[] = {
  790. /* Intel-defined */
  791. "fpu", "vme", "de", "pse", "tsc", "msr", "pae", "mce",
  792. "cx8", "apic", NULL, "sep", "mtrr", "pge", "mca", "cmov",
  793. "pat", "pse36", "pn", "clflush", NULL, "dts", "acpi", "mmx",
  794. "fxsr", "sse", "sse2", "ss", "ht", "tm", "ia64", NULL,
  795. /* AMD-defined */
  796. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  797. NULL, NULL, NULL, "syscall", NULL, NULL, NULL, NULL,
  798. NULL, NULL, NULL, NULL, "nx", NULL, "mmxext", NULL,
  799. NULL, "fxsr_opt", "pdpe1gb", "rdtscp", NULL, "lm",
  800. "3dnowext", "3dnow",
  801. /* Transmeta-defined */
  802. "recovery", "longrun", NULL, "lrti", NULL, NULL, NULL, NULL,
  803. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  804. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  805. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  806. /* Other (Linux-defined) */
  807. "cxmmx", NULL, "cyrix_arr", "centaur_mcr", NULL,
  808. "constant_tsc", NULL, NULL,
  809. "up", NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  810. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  811. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  812. /* Intel-defined (#2) */
  813. "pni", NULL, NULL, "monitor", "ds_cpl", "vmx", "smx", "est",
  814. "tm2", "ssse3", "cid", NULL, NULL, "cx16", "xtpr", NULL,
  815. NULL, NULL, "dca", NULL, NULL, NULL, NULL, "popcnt",
  816. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  817. /* VIA/Cyrix/Centaur-defined */
  818. NULL, NULL, "rng", "rng_en", NULL, NULL, "ace", "ace_en",
  819. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  820. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  821. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  822. /* AMD-defined (#2) */
  823. "lahf_lm", "cmp_legacy", "svm", "extapic", "cr8_legacy",
  824. "altmovcr8", "abm", "sse4a",
  825. "misalignsse", "3dnowprefetch",
  826. "osvw", "ibs", NULL, NULL, NULL, NULL,
  827. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  828. NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL,
  829. };
  830. static char *x86_power_flags[] = {
  831. "ts", /* temperature sensor */
  832. "fid", /* frequency id control */
  833. "vid", /* voltage id control */
  834. "ttp", /* thermal trip */
  835. "tm",
  836. "stc",
  837. "100mhzsteps",
  838. "hwpstate",
  839. "", /* tsc invariant mapped to constant_tsc */
  840. /* nothing */
  841. };
  842. #ifdef CONFIG_SMP
  843. if (!cpu_online(c-cpu_data))
  844. return 0;
  845. #endif
  846. seq_printf(m,"processor\t: %u\n"
  847. "vendor_id\t: %s\n"
  848. "cpu family\t: %d\n"
  849. "model\t\t: %d\n"
  850. "model name\t: %s\n",
  851. (unsigned)(c-cpu_data),
  852. c->x86_vendor_id[0] ? c->x86_vendor_id : "unknown",
  853. c->x86,
  854. (int)c->x86_model,
  855. c->x86_model_id[0] ? c->x86_model_id : "unknown");
  856. if (c->x86_mask || c->cpuid_level >= 0)
  857. seq_printf(m, "stepping\t: %d\n", c->x86_mask);
  858. else
  859. seq_printf(m, "stepping\t: unknown\n");
  860. if (cpu_has(c,X86_FEATURE_TSC)) {
  861. unsigned int freq = cpufreq_quick_get((unsigned)(c-cpu_data));
  862. if (!freq)
  863. freq = cpu_khz;
  864. seq_printf(m, "cpu MHz\t\t: %u.%03u\n",
  865. freq / 1000, (freq % 1000));
  866. }
  867. /* Cache size */
  868. if (c->x86_cache_size >= 0)
  869. seq_printf(m, "cache size\t: %d KB\n", c->x86_cache_size);
  870. #ifdef CONFIG_SMP
  871. if (smp_num_siblings * c->x86_max_cores > 1) {
  872. int cpu = c - cpu_data;
  873. seq_printf(m, "physical id\t: %d\n", c->phys_proc_id);
  874. seq_printf(m, "siblings\t: %d\n", cpus_weight(cpu_core_map[cpu]));
  875. seq_printf(m, "core id\t\t: %d\n", c->cpu_core_id);
  876. seq_printf(m, "cpu cores\t: %d\n", c->booted_cores);
  877. }
  878. #endif
  879. seq_printf(m,
  880. "fpu\t\t: yes\n"
  881. "fpu_exception\t: yes\n"
  882. "cpuid level\t: %d\n"
  883. "wp\t\t: yes\n"
  884. "flags\t\t:",
  885. c->cpuid_level);
  886. {
  887. int i;
  888. for ( i = 0 ; i < 32*NCAPINTS ; i++ )
  889. if (cpu_has(c, i) && x86_cap_flags[i] != NULL)
  890. seq_printf(m, " %s", x86_cap_flags[i]);
  891. }
  892. seq_printf(m, "\nbogomips\t: %lu.%02lu\n",
  893. c->loops_per_jiffy/(500000/HZ),
  894. (c->loops_per_jiffy/(5000/HZ)) % 100);
  895. if (c->x86_tlbsize > 0)
  896. seq_printf(m, "TLB size\t: %d 4K pages\n", c->x86_tlbsize);
  897. seq_printf(m, "clflush size\t: %d\n", c->x86_clflush_size);
  898. seq_printf(m, "cache_alignment\t: %d\n", c->x86_cache_alignment);
  899. seq_printf(m, "address sizes\t: %u bits physical, %u bits virtual\n",
  900. c->x86_phys_bits, c->x86_virt_bits);
  901. seq_printf(m, "power management:");
  902. {
  903. unsigned i;
  904. for (i = 0; i < 32; i++)
  905. if (c->x86_power & (1 << i)) {
  906. if (i < ARRAY_SIZE(x86_power_flags) &&
  907. x86_power_flags[i])
  908. seq_printf(m, "%s%s",
  909. x86_power_flags[i][0]?" ":"",
  910. x86_power_flags[i]);
  911. else
  912. seq_printf(m, " [%d]", i);
  913. }
  914. }
  915. seq_printf(m, "\n\n");
  916. return 0;
  917. }
  918. static void *c_start(struct seq_file *m, loff_t *pos)
  919. {
  920. return *pos < NR_CPUS ? cpu_data + *pos : NULL;
  921. }
  922. static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  923. {
  924. ++*pos;
  925. return c_start(m, pos);
  926. }
  927. static void c_stop(struct seq_file *m, void *v)
  928. {
  929. }
  930. struct seq_operations cpuinfo_op = {
  931. .start =c_start,
  932. .next = c_next,
  933. .stop = c_stop,
  934. .show = show_cpuinfo,
  935. };