setup_64.c 32 KB

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