setup.c 28 KB

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