setup_64.c 31 KB

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