x86: if acpi=off, force setting the mmconf for fam10h
[safe/jmp/linux-2.6] / arch / x86 / kernel / setup_64.c
1 /*
2  *  Copyright (C) 1995  Linus Torvalds
3  */
4
5 /*
6  * This file handles the architecture-dependent parts of initialization
7  */
8
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.h>
12 #include <linux/mm.h>
13 #include <linux/stddef.h>
14 #include <linux/unistd.h>
15 #include <linux/ptrace.h>
16 #include <linux/slab.h>
17 #include <linux/user.h>
18 #include <linux/screen_info.h>
19 #include <linux/ioport.h>
20 #include <linux/delay.h>
21 #include <linux/init.h>
22 #include <linux/initrd.h>
23 #include <linux/highmem.h>
24 #include <linux/bootmem.h>
25 #include <linux/module.h>
26 #include <asm/processor.h>
27 #include <linux/console.h>
28 #include <linux/seq_file.h>
29 #include <linux/crash_dump.h>
30 #include <linux/root_dev.h>
31 #include <linux/pci.h>
32 #include <asm/pci-direct.h>
33 #include <linux/efi.h>
34 #include <linux/acpi.h>
35 #include <linux/kallsyms.h>
36 #include <linux/edd.h>
37 #include <linux/iscsi_ibft.h>
38 #include <linux/mmzone.h>
39 #include <linux/kexec.h>
40 #include <linux/cpufreq.h>
41 #include <linux/dmi.h>
42 #include <linux/dma-mapping.h>
43 #include <linux/ctype.h>
44 #include <linux/sort.h>
45 #include <linux/uaccess.h>
46 #include <linux/init_ohci1394_dma.h>
47
48 #include <asm/mtrr.h>
49 #include <asm/uaccess.h>
50 #include <asm/system.h>
51 #include <asm/vsyscall.h>
52 #include <asm/io.h>
53 #include <asm/smp.h>
54 #include <asm/msr.h>
55 #include <asm/desc.h>
56 #include <video/edid.h>
57 #include <asm/e820.h>
58 #include <asm/dma.h>
59 #include <asm/gart.h>
60 #include <asm/mpspec.h>
61 #include <asm/mmu_context.h>
62 #include <asm/proto.h>
63 #include <asm/setup.h>
64 #include <asm/numa.h>
65 #include <asm/sections.h>
66 #include <asm/dmi.h>
67 #include <asm/cacheflush.h>
68 #include <asm/mce.h>
69 #include <asm/ds.h>
70 #include <asm/topology.h>
71 #include <asm/trampoline.h>
72
73 #include <mach_apic.h>
74 #ifdef CONFIG_PARAVIRT
75 #include <asm/paravirt.h>
76 #else
77 #define ARCH_SETUP
78 #endif
79
80 /*
81  * Machine setup..
82  */
83
84 struct cpuinfo_x86 boot_cpu_data __read_mostly;
85 EXPORT_SYMBOL(boot_cpu_data);
86
87 __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata;
88
89 unsigned long mmu_cr4_features;
90
91 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
92 int bootloader_type;
93
94 unsigned long saved_video_mode;
95
96 int force_mwait __cpuinitdata;
97
98 /*
99  * Early DMI memory
100  */
101 int dmi_alloc_index;
102 char dmi_alloc_data[DMI_MAX_DATA];
103
104 /*
105  * Setup options
106  */
107 struct screen_info screen_info;
108 EXPORT_SYMBOL(screen_info);
109 struct sys_desc_table_struct {
110         unsigned short length;
111         unsigned char table[0];
112 };
113
114 struct edid_info edid_info;
115 EXPORT_SYMBOL_GPL(edid_info);
116
117 extern int root_mountflags;
118
119 char __initdata command_line[COMMAND_LINE_SIZE];
120
121 static struct resource standard_io_resources[] = {
122         { .name = "dma1", .start = 0x00, .end = 0x1f,
123                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
124         { .name = "pic1", .start = 0x20, .end = 0x21,
125                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
126         { .name = "timer0", .start = 0x40, .end = 0x43,
127                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
128         { .name = "timer1", .start = 0x50, .end = 0x53,
129                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
130         { .name = "keyboard", .start = 0x60, .end = 0x6f,
131                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
132         { .name = "dma page reg", .start = 0x80, .end = 0x8f,
133                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
134         { .name = "pic2", .start = 0xa0, .end = 0xa1,
135                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
136         { .name = "dma2", .start = 0xc0, .end = 0xdf,
137                 .flags = IORESOURCE_BUSY | IORESOURCE_IO },
138         { .name = "fpu", .start = 0xf0, .end = 0xff,
139                 .flags = IORESOURCE_BUSY | IORESOURCE_IO }
140 };
141
142 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
143
144 static struct resource data_resource = {
145         .name = "Kernel data",
146         .start = 0,
147         .end = 0,
148         .flags = IORESOURCE_RAM,
149 };
150 static struct resource code_resource = {
151         .name = "Kernel code",
152         .start = 0,
153         .end = 0,
154         .flags = IORESOURCE_RAM,
155 };
156 static struct resource bss_resource = {
157         .name = "Kernel bss",
158         .start = 0,
159         .end = 0,
160         .flags = IORESOURCE_RAM,
161 };
162
163 static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c);
164
165 #ifdef CONFIG_PROC_VMCORE
166 /* elfcorehdr= specifies the location of elf core header
167  * stored by the crashed kernel. This option will be passed
168  * by kexec loader to the capture kernel.
169  */
170 static int __init setup_elfcorehdr(char *arg)
171 {
172         char *end;
173         if (!arg)
174                 return -EINVAL;
175         elfcorehdr_addr = memparse(arg, &end);
176         return end > arg ? 0 : -EINVAL;
177 }
178 early_param("elfcorehdr", setup_elfcorehdr);
179 #endif
180
181 #ifndef CONFIG_NUMA
182 static void __init
183 contig_initmem_init(unsigned long start_pfn, unsigned long end_pfn)
184 {
185         unsigned long bootmap_size, bootmap;
186
187         bootmap_size = bootmem_bootmap_pages(end_pfn)<<PAGE_SHIFT;
188         bootmap = find_e820_area(0, end_pfn<<PAGE_SHIFT, bootmap_size,
189                                  PAGE_SIZE);
190         if (bootmap == -1L)
191                 panic("Cannot find bootmem map of size %ld\n", bootmap_size);
192         bootmap_size = init_bootmem(bootmap >> PAGE_SHIFT, end_pfn);
193         e820_register_active_regions(0, start_pfn, end_pfn);
194         free_bootmem_with_active_regions(0, end_pfn);
195         early_res_to_bootmem(0, end_pfn<<PAGE_SHIFT);
196         reserve_bootmem(bootmap, bootmap_size, BOOTMEM_DEFAULT);
197 }
198 #endif
199
200 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
201 struct edd edd;
202 #ifdef CONFIG_EDD_MODULE
203 EXPORT_SYMBOL(edd);
204 #endif
205 /**
206  * copy_edd() - Copy the BIOS EDD information
207  *              from boot_params into a safe place.
208  *
209  */
210 static inline void copy_edd(void)
211 {
212      memcpy(edd.mbr_signature, boot_params.edd_mbr_sig_buffer,
213             sizeof(edd.mbr_signature));
214      memcpy(edd.edd_info, boot_params.eddbuf, sizeof(edd.edd_info));
215      edd.mbr_signature_nr = boot_params.edd_mbr_sig_buf_entries;
216      edd.edd_info_nr = boot_params.eddbuf_entries;
217 }
218 #else
219 static inline void copy_edd(void)
220 {
221 }
222 #endif
223
224 #ifdef CONFIG_KEXEC
225 static void __init reserve_crashkernel(void)
226 {
227         unsigned long long total_mem;
228         unsigned long long crash_size, crash_base;
229         int ret;
230
231         total_mem = ((unsigned long long)max_low_pfn - min_low_pfn) << PAGE_SHIFT;
232
233         ret = parse_crashkernel(boot_command_line, total_mem,
234                         &crash_size, &crash_base);
235         if (ret == 0 && crash_size) {
236                 if (crash_base <= 0) {
237                         printk(KERN_INFO "crashkernel reservation failed - "
238                                         "you have to specify a base address\n");
239                         return;
240                 }
241
242                 if (reserve_bootmem(crash_base, crash_size,
243                                         BOOTMEM_EXCLUSIVE) < 0) {
244                         printk(KERN_INFO "crashkernel reservation failed - "
245                                         "memory is in use\n");
246                         return;
247                 }
248
249                 printk(KERN_INFO "Reserving %ldMB of memory at %ldMB "
250                                 "for crashkernel (System RAM: %ldMB)\n",
251                                 (unsigned long)(crash_size >> 20),
252                                 (unsigned long)(crash_base >> 20),
253                                 (unsigned long)(total_mem >> 20));
254                 crashk_res.start = crash_base;
255                 crashk_res.end   = crash_base + crash_size - 1;
256                 insert_resource(&iomem_resource, &crashk_res);
257         }
258 }
259 #else
260 static inline void __init reserve_crashkernel(void)
261 {}
262 #endif
263
264 /* Overridden in paravirt.c if CONFIG_PARAVIRT */
265 void __attribute__((weak)) __init memory_setup(void)
266 {
267        machine_specific_memory_setup();
268 }
269
270 static void __init parse_setup_data(void)
271 {
272         struct setup_data *data;
273         unsigned long pa_data;
274
275         if (boot_params.hdr.version < 0x0209)
276                 return;
277         pa_data = boot_params.hdr.setup_data;
278         while (pa_data) {
279                 data = early_ioremap(pa_data, PAGE_SIZE);
280                 switch (data->type) {
281                 default:
282                         break;
283                 }
284 #ifndef CONFIG_DEBUG_BOOT_PARAMS
285                 free_early(pa_data, pa_data+sizeof(*data)+data->len);
286 #endif
287                 pa_data = data->next;
288                 early_iounmap(data, PAGE_SIZE);
289         }
290 }
291
292 /*
293  * setup_arch - architecture-specific boot-time initializations
294  *
295  * Note: On x86_64, fixmaps are ready for use even before this is called.
296  */
297 void __init setup_arch(char **cmdline_p)
298 {
299         unsigned i;
300
301         printk(KERN_INFO "Command line: %s\n", boot_command_line);
302
303         ROOT_DEV = old_decode_dev(boot_params.hdr.root_dev);
304         screen_info = boot_params.screen_info;
305         edid_info = boot_params.edid_info;
306         saved_video_mode = boot_params.hdr.vid_mode;
307         bootloader_type = boot_params.hdr.type_of_loader;
308
309 #ifdef CONFIG_BLK_DEV_RAM
310         rd_image_start = boot_params.hdr.ram_size & RAMDISK_IMAGE_START_MASK;
311         rd_prompt = ((boot_params.hdr.ram_size & RAMDISK_PROMPT_FLAG) != 0);
312         rd_doload = ((boot_params.hdr.ram_size & RAMDISK_LOAD_FLAG) != 0);
313 #endif
314 #ifdef CONFIG_EFI
315         if (!strncmp((char *)&boot_params.efi_info.efi_loader_signature,
316                      "EL64", 4))
317                 efi_enabled = 1;
318 #endif
319
320         ARCH_SETUP
321
322         memory_setup();
323         copy_edd();
324
325         if (!boot_params.hdr.root_flags)
326                 root_mountflags &= ~MS_RDONLY;
327         init_mm.start_code = (unsigned long) &_text;
328         init_mm.end_code = (unsigned long) &_etext;
329         init_mm.end_data = (unsigned long) &_edata;
330         init_mm.brk = (unsigned long) &_end;
331
332         code_resource.start = virt_to_phys(&_text);
333         code_resource.end = virt_to_phys(&_etext)-1;
334         data_resource.start = virt_to_phys(&_etext);
335         data_resource.end = virt_to_phys(&_edata)-1;
336         bss_resource.start = virt_to_phys(&__bss_start);
337         bss_resource.end = virt_to_phys(&__bss_stop)-1;
338
339         early_identify_cpu(&boot_cpu_data);
340
341         strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
342         *cmdline_p = command_line;
343
344         parse_setup_data();
345
346         parse_early_param();
347
348 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
349         if (init_ohci1394_dma_early)
350                 init_ohci1394_dma_on_all_controllers();
351 #endif
352
353         finish_e820_parsing();
354
355         /* after parse_early_param, so could debug it */
356         insert_resource(&iomem_resource, &code_resource);
357         insert_resource(&iomem_resource, &data_resource);
358         insert_resource(&iomem_resource, &bss_resource);
359
360         early_gart_iommu_check();
361
362         e820_register_active_regions(0, 0, -1UL);
363         /*
364          * partially used pages are not usable - thus
365          * we are rounding upwards:
366          */
367         end_pfn = e820_end_of_ram();
368         /* update e820 for memory not covered by WB MTRRs */
369         mtrr_bp_init();
370         if (mtrr_trim_uncached_memory(end_pfn)) {
371                 e820_register_active_regions(0, 0, -1UL);
372                 end_pfn = e820_end_of_ram();
373         }
374
375         num_physpages = end_pfn;
376
377         check_efer();
378
379         max_pfn_mapped = init_memory_mapping(0, (max_pfn_mapped << PAGE_SHIFT));
380         if (efi_enabled)
381                 efi_init();
382
383         vsmp_init();
384
385         dmi_scan_machine();
386
387         io_delay_init();
388
389 #ifdef CONFIG_SMP
390         /* setup to use the early static init tables during kernel startup */
391         x86_cpu_to_apicid_early_ptr = (void *)x86_cpu_to_apicid_init;
392         x86_bios_cpu_apicid_early_ptr = (void *)x86_bios_cpu_apicid_init;
393 #ifdef CONFIG_NUMA
394         x86_cpu_to_node_map_early_ptr = (void *)x86_cpu_to_node_map_init;
395 #endif
396 #endif
397
398 #ifdef CONFIG_ACPI
399         /*
400          * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
401          * Call this early for SRAT node setup.
402          */
403         acpi_boot_table_init();
404 #endif
405
406         /* How many end-of-memory variables you have, grandma! */
407         max_low_pfn = end_pfn;
408         max_pfn = end_pfn;
409         high_memory = (void *)__va(end_pfn * PAGE_SIZE - 1) + 1;
410
411         /* Remove active ranges so rediscovery with NUMA-awareness happens */
412         remove_all_active_ranges();
413
414 #ifdef CONFIG_ACPI_NUMA
415         /*
416          * Parse SRAT to discover nodes.
417          */
418         acpi_numa_init();
419 #endif
420
421 #ifdef CONFIG_NUMA
422         numa_initmem_init(0, end_pfn);
423 #else
424         contig_initmem_init(0, end_pfn);
425 #endif
426
427         dma32_reserve_bootmem();
428
429 #ifdef CONFIG_ACPI_SLEEP
430         /*
431          * Reserve low memory region for sleep support.
432          */
433        acpi_reserve_bootmem();
434 #endif
435
436         if (efi_enabled)
437                 efi_reserve_bootmem();
438
439        /*
440         * Find and reserve possible boot-time SMP configuration:
441         */
442         find_smp_config();
443 #ifdef CONFIG_BLK_DEV_INITRD
444         if (boot_params.hdr.type_of_loader && boot_params.hdr.ramdisk_image) {
445                 unsigned long ramdisk_image = boot_params.hdr.ramdisk_image;
446                 unsigned long ramdisk_size  = boot_params.hdr.ramdisk_size;
447                 unsigned long ramdisk_end   = ramdisk_image + ramdisk_size;
448                 unsigned long end_of_mem    = end_pfn << PAGE_SHIFT;
449
450                 if (ramdisk_end <= end_of_mem) {
451                         /*
452                          * don't need to reserve again, already reserved early
453                          * in x86_64_start_kernel, and early_res_to_bootmem
454                          * convert that to reserved in bootmem
455                          */
456                         initrd_start = ramdisk_image + PAGE_OFFSET;
457                         initrd_end = initrd_start+ramdisk_size;
458                 } else {
459                         free_bootmem(ramdisk_image, ramdisk_size);
460                         printk(KERN_ERR "initrd extends beyond end of memory "
461                                "(0x%08lx > 0x%08lx)\ndisabling initrd\n",
462                                ramdisk_end, end_of_mem);
463                         initrd_start = 0;
464                 }
465         }
466 #endif
467         reserve_crashkernel();
468
469         reserve_ibft_region();
470
471         paging_init();
472         map_vsyscall();
473
474         early_quirks();
475
476 #ifdef CONFIG_ACPI
477         /*
478          * Read APIC and some other early information from ACPI tables.
479          */
480         acpi_boot_init();
481 #endif
482
483         init_cpu_to_node();
484
485         /*
486          * get boot-time SMP configuration:
487          */
488         if (smp_found_config)
489                 get_smp_config();
490         init_apic_mappings();
491         ioapic_init_mappings();
492
493         /*
494          * We trust e820 completely. No explicit ROM probing in memory.
495          */
496         e820_reserve_resources();
497         e820_mark_nosave_regions();
498
499         /* request I/O space for devices used on all i[345]86 PCs */
500         for (i = 0; i < ARRAY_SIZE(standard_io_resources); i++)
501                 request_resource(&ioport_resource, &standard_io_resources[i]);
502
503         e820_setup_gap();
504
505 #ifdef CONFIG_VT
506 #if defined(CONFIG_VGA_CONSOLE)
507         if (!efi_enabled || (efi_mem_type(0xa0000) != EFI_CONVENTIONAL_MEMORY))
508                 conswitchp = &vga_con;
509 #elif defined(CONFIG_DUMMY_CONSOLE)
510         conswitchp = &dummy_con;
511 #endif
512 #endif
513 }
514
515 static int __cpuinit get_model_name(struct cpuinfo_x86 *c)
516 {
517         unsigned int *v;
518
519         if (c->extended_cpuid_level < 0x80000004)
520                 return 0;
521
522         v = (unsigned int *) c->x86_model_id;
523         cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]);
524         cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]);
525         cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]);
526         c->x86_model_id[48] = 0;
527         return 1;
528 }
529
530
531 static void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c)
532 {
533         unsigned int n, dummy, eax, ebx, ecx, edx;
534
535         n = c->extended_cpuid_level;
536
537         if (n >= 0x80000005) {
538                 cpuid(0x80000005, &dummy, &ebx, &ecx, &edx);
539                 printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), "
540                        "D cache %dK (%d bytes/line)\n",
541                        edx>>24, edx&0xFF, ecx>>24, ecx&0xFF);
542                 c->x86_cache_size = (ecx>>24) + (edx>>24);
543                 /* On K8 L1 TLB is inclusive, so don't count it */
544                 c->x86_tlbsize = 0;
545         }
546
547         if (n >= 0x80000006) {
548                 cpuid(0x80000006, &dummy, &ebx, &ecx, &edx);
549                 ecx = cpuid_ecx(0x80000006);
550                 c->x86_cache_size = ecx >> 16;
551                 c->x86_tlbsize += ((ebx >> 16) & 0xfff) + (ebx & 0xfff);
552
553                 printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n",
554                 c->x86_cache_size, ecx & 0xFF);
555         }
556         if (n >= 0x80000008) {
557                 cpuid(0x80000008, &eax, &dummy, &dummy, &dummy);
558                 c->x86_virt_bits = (eax >> 8) & 0xff;
559                 c->x86_phys_bits = eax & 0xff;
560         }
561 }
562
563 #ifdef CONFIG_NUMA
564 static int __cpuinit nearby_node(int apicid)
565 {
566         int i, node;
567
568         for (i = apicid - 1; i >= 0; i--) {
569                 node = apicid_to_node[i];
570                 if (node != NUMA_NO_NODE && node_online(node))
571                         return node;
572         }
573         for (i = apicid + 1; i < MAX_LOCAL_APIC; i++) {
574                 node = apicid_to_node[i];
575                 if (node != NUMA_NO_NODE && node_online(node))
576                         return node;
577         }
578         return first_node(node_online_map); /* Shouldn't happen */
579 }
580 #endif
581
582 #ifdef CONFIG_PCI_MMCONFIG
583 struct pci_hostbridge_probe {
584         u32 bus;
585         u32 slot;
586         u32 vendor;
587         u32 device;
588 };
589
590 static u64 __cpuinitdata fam10h_pci_mmconf_base;
591 static int __cpuinitdata fam10h_pci_mmconf_base_status;
592
593 static struct pci_hostbridge_probe pci_probes[] __cpuinitdata = {
594         { 0, 0x18, PCI_VENDOR_ID_AMD, 0x1200 },
595         { 0xff, 0, PCI_VENDOR_ID_AMD, 0x1200 },
596 };
597
598 struct range {
599         u64 start;
600         u64 end;
601 };
602
603 static int __cpuinit cmp_range(const void *x1, const void *x2)
604 {
605         const struct range *r1 = x1;
606         const struct range *r2 = x2;
607         int start1, start2;
608
609         start1 = r1->start >> 32;
610         start2 = r2->start >> 32;
611
612         return start1 - start2;
613 }
614
615 /*[47:0] */
616 /* need to avoid (0xfd<<32) and (0xfe<<32), ht used space */
617 #define FAM10H_PCI_MMCONF_BASE (0xfcULL<<32)
618 #define BASE_VALID(b) ((b != (0xfdULL << 32)) && (b != (0xfeULL << 32)))
619 static void __cpuinit get_fam10h_pci_mmconf_base(void)
620 {
621         int i;
622         unsigned bus;
623         unsigned slot;
624         int found;
625
626         u64 val;
627         u32 address;
628         u64 tom2;
629         u64 base = FAM10H_PCI_MMCONF_BASE;
630
631         int hi_mmio_num;
632         struct range range[8];
633
634         /* only try to get setting from BSP */
635         /* -1 or 1 */
636         if (fam10h_pci_mmconf_base_status)
637                 return;
638
639         if (!early_pci_allowed())
640                 goto fail;
641
642         found = 0;
643         for (i = 0; i < ARRAY_SIZE(pci_probes); i++) {
644                 u32 id;
645                 u16 device;
646                 u16 vendor;
647
648                 bus = pci_probes[i].bus;
649                 slot = pci_probes[i].slot;
650                 id = read_pci_config(bus, slot, 0, PCI_VENDOR_ID);
651
652                 vendor = id & 0xffff;
653                 device = (id>>16) & 0xffff;
654                 if (pci_probes[i].vendor == vendor &&
655                     pci_probes[i].device == device) {
656                         found = 1;
657                         break;
658                 }
659         }
660
661         if (!found)
662                 goto fail;
663
664         /* SYS_CFG */
665         address = MSR_K8_SYSCFG;
666         rdmsrl(address, val);
667
668         /* TOP_MEM2 is not enabled? */
669         if (!(val & (1<<21))) {
670                 tom2 = 0;
671         } else {
672                 /* TOP_MEM2 */
673                 address = MSR_K8_TOP_MEM2;
674                 rdmsrl(address, val);
675                 tom2 = val & (0xffffULL<<32);
676         }
677
678         if (base <= tom2)
679                 base = tom2 + (1ULL<<32);
680
681         /*
682          * need to check if the range is in the high mmio range that is
683          * above 4G
684          */
685         hi_mmio_num = 0;
686         for (i = 0; i < 8; i++) {
687                 u32 reg;
688                 u64 start;
689                 u64 end;
690                 reg = read_pci_config(bus, slot, 1, 0x80 + (i << 3));
691                 if (!(reg & 3))
692                         continue;
693
694                 start = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/
695                 reg = read_pci_config(bus, slot, 1, 0x84 + (i << 3));
696                 end = (((u64)reg) << 8) & (0xffULL << 32); /* 39:16 on 31:8*/
697
698                 if (!end)
699                         continue;
700
701                 range[hi_mmio_num].start = start;
702                 range[hi_mmio_num].end = end;
703                 hi_mmio_num++;
704         }
705
706         if (!hi_mmio_num)
707                 goto out;
708
709         /* sort the range */
710         sort(range, hi_mmio_num, sizeof(struct range), cmp_range, NULL);
711
712         if (range[hi_mmio_num - 1].end < base)
713                 goto out;
714         if (range[0].start > base)
715                 goto out;
716
717         /* need to find one window */
718         base = range[0].start - (1ULL << 32);
719         if ((base > tom2) && BASE_VALID(base))
720                 goto out;
721         base = range[hi_mmio_num - 1].end + (1ULL << 32);
722         if ((base > tom2) && BASE_VALID(base))
723                 goto out;
724         /* need to find window between ranges */
725         if (hi_mmio_num > 1)
726         for (i = 0; i < hi_mmio_num - 1; i++) {
727                 if (range[i + 1].start > (range[i].end + (1ULL << 32))) {
728                         base = range[i].end + (1ULL << 32);
729                         if ((base > tom2) && BASE_VALID(base))
730                                 goto out;
731                 }
732         }
733
734 fail:
735         fam10h_pci_mmconf_base_status = -1;
736         return;
737 out:
738         fam10h_pci_mmconf_base = base;
739         fam10h_pci_mmconf_base_status = 1;
740 }
741 #endif
742
743 static void __cpuinit fam10h_check_enable_mmcfg(struct cpuinfo_x86 *c)
744 {
745 #ifdef CONFIG_PCI_MMCONFIG
746         u64 val;
747         u32 address;
748
749         address = MSR_FAM10H_MMIO_CONF_BASE;
750         rdmsrl(address, val);
751
752         /* try to make sure that AP's setting is identical to BSP setting */
753         if (val & FAM10H_MMIO_CONF_ENABLE) {
754                 unsigned busnbits;
755                 busnbits = (val >> FAM10H_MMIO_CONF_BUSRANGE_SHIFT) &
756                         FAM10H_MMIO_CONF_BUSRANGE_MASK;
757
758                 /* only trust the one handle 256 buses, if acpi=off */
759                 if (!acpi_pci_disabled || busnbits >= 8) {
760                         u64 base;
761                         base = val & (0xffffULL << 32);
762                         if (fam10h_pci_mmconf_base_status <= 0) {
763                                 fam10h_pci_mmconf_base = base;
764                                 fam10h_pci_mmconf_base_status = 1;
765                                 return;
766                         } else if (fam10h_pci_mmconf_base ==  base)
767                                 return;
768                 }
769         }
770
771         /*
772          * if it is not enabled, try to enable it and assume only one segment
773          * with 256 buses
774          */
775         get_fam10h_pci_mmconf_base();
776         if (fam10h_pci_mmconf_base_status <= 0)
777                 return;
778
779         printk(KERN_INFO "Enable MMCONFIG on AMD Family 10h\n");
780         val &= ~((FAM10H_MMIO_CONF_BASE_MASK<<FAM10H_MMIO_CONF_BASE_SHIFT) |
781              (FAM10H_MMIO_CONF_BUSRANGE_MASK<<FAM10H_MMIO_CONF_BUSRANGE_SHIFT));
782         val |= fam10h_pci_mmconf_base | (8 << FAM10H_MMIO_CONF_BUSRANGE_SHIFT) |
783                FAM10H_MMIO_CONF_ENABLE;
784         wrmsrl(address, val);
785 #endif
786 }
787
788 /*
789  * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
790  * Assumes number of cores is a power of two.
791  */
792 static void __cpuinit amd_detect_cmp(struct cpuinfo_x86 *c)
793 {
794 #ifdef CONFIG_SMP
795         unsigned bits;
796 #ifdef CONFIG_NUMA
797         int cpu = smp_processor_id();
798         int node = 0;
799         unsigned apicid = hard_smp_processor_id();
800 #endif
801         bits = c->x86_coreid_bits;
802
803         /* Low order bits define the core id (index of core in socket) */
804         c->cpu_core_id = c->initial_apicid & ((1 << bits)-1);
805         /* Convert the initial APIC ID into the socket ID */
806         c->phys_proc_id = c->initial_apicid >> bits;
807
808 #ifdef CONFIG_NUMA
809         node = c->phys_proc_id;
810         if (apicid_to_node[apicid] != NUMA_NO_NODE)
811                 node = apicid_to_node[apicid];
812         if (!node_online(node)) {
813                 /* Two possibilities here:
814                    - The CPU is missing memory and no node was created.
815                    In that case try picking one from a nearby CPU
816                    - The APIC IDs differ from the HyperTransport node IDs
817                    which the K8 northbridge parsing fills in.
818                    Assume they are all increased by a constant offset,
819                    but in the same order as the HT nodeids.
820                    If that doesn't result in a usable node fall back to the
821                    path for the previous case.  */
822
823                 int ht_nodeid = c->initial_apicid;
824
825                 if (ht_nodeid >= 0 &&
826                     apicid_to_node[ht_nodeid] != NUMA_NO_NODE)
827                         node = apicid_to_node[ht_nodeid];
828                 /* Pick a nearby node */
829                 if (!node_online(node))
830                         node = nearby_node(apicid);
831         }
832         numa_set_node(cpu, node);
833
834         printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
835 #endif
836 #endif
837 }
838
839 static void __cpuinit early_init_amd_mc(struct cpuinfo_x86 *c)
840 {
841 #ifdef CONFIG_SMP
842         unsigned bits, ecx;
843
844         /* Multi core CPU? */
845         if (c->extended_cpuid_level < 0x80000008)
846                 return;
847
848         ecx = cpuid_ecx(0x80000008);
849
850         c->x86_max_cores = (ecx & 0xff) + 1;
851
852         /* CPU telling us the core id bits shift? */
853         bits = (ecx >> 12) & 0xF;
854
855         /* Otherwise recompute */
856         if (bits == 0) {
857                 while ((1 << bits) < c->x86_max_cores)
858                         bits++;
859         }
860
861         c->x86_coreid_bits = bits;
862
863 #endif
864 }
865
866 #define ENABLE_C1E_MASK         0x18000000
867 #define CPUID_PROCESSOR_SIGNATURE       1
868 #define CPUID_XFAM              0x0ff00000
869 #define CPUID_XFAM_K8           0x00000000
870 #define CPUID_XFAM_10H          0x00100000
871 #define CPUID_XFAM_11H          0x00200000
872 #define CPUID_XMOD              0x000f0000
873 #define CPUID_XMOD_REV_F        0x00040000
874
875 /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
876 static __cpuinit int amd_apic_timer_broken(void)
877 {
878         u32 lo, hi, eax = cpuid_eax(CPUID_PROCESSOR_SIGNATURE);
879
880         switch (eax & CPUID_XFAM) {
881         case CPUID_XFAM_K8:
882                 if ((eax & CPUID_XMOD) < CPUID_XMOD_REV_F)
883                         break;
884         case CPUID_XFAM_10H:
885         case CPUID_XFAM_11H:
886                 rdmsr(MSR_K8_ENABLE_C1E, lo, hi);
887                 if (lo & ENABLE_C1E_MASK)
888                         return 1;
889                 break;
890         default:
891                 /* err on the side of caution */
892                 return 1;
893         }
894         return 0;
895 }
896
897 static void __cpuinit early_init_amd(struct cpuinfo_x86 *c)
898 {
899         early_init_amd_mc(c);
900
901         /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
902         if (c->x86_power & (1<<8))
903                 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
904 }
905
906 static void __cpuinit init_amd(struct cpuinfo_x86 *c)
907 {
908         unsigned level;
909
910 #ifdef CONFIG_SMP
911         unsigned long value;
912
913         /*
914          * Disable TLB flush filter by setting HWCR.FFDIS on K8
915          * bit 6 of msr C001_0015
916          *
917          * Errata 63 for SH-B3 steppings
918          * Errata 122 for all steppings (F+ have it disabled by default)
919          */
920         if (c->x86 == 15) {
921                 rdmsrl(MSR_K8_HWCR, value);
922                 value |= 1 << 6;
923                 wrmsrl(MSR_K8_HWCR, value);
924         }
925 #endif
926
927         /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
928            3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
929         clear_cpu_cap(c, 0*32+31);
930
931         /* On C+ stepping K8 rep microcode works well for copy/memset */
932         level = cpuid_eax(1);
933         if (c->x86 == 15 && ((level >= 0x0f48 && level < 0x0f50) ||
934                              level >= 0x0f58))
935                 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
936         if (c->x86 == 0x10 || c->x86 == 0x11)
937                 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
938
939         /* Enable workaround for FXSAVE leak */
940         if (c->x86 >= 6)
941                 set_cpu_cap(c, X86_FEATURE_FXSAVE_LEAK);
942
943         level = get_model_name(c);
944         if (!level) {
945                 switch (c->x86) {
946                 case 15:
947                         /* Should distinguish Models here, but this is only
948                            a fallback anyways. */
949                         strcpy(c->x86_model_id, "Hammer");
950                         break;
951                 }
952         }
953         display_cacheinfo(c);
954
955         /* Multi core CPU? */
956         if (c->extended_cpuid_level >= 0x80000008)
957                 amd_detect_cmp(c);
958
959         if (c->extended_cpuid_level >= 0x80000006 &&
960                 (cpuid_edx(0x80000006) & 0xf000))
961                 num_cache_leaves = 4;
962         else
963                 num_cache_leaves = 3;
964
965         if (c->x86 == 0xf || c->x86 == 0x10 || c->x86 == 0x11)
966                 set_cpu_cap(c, X86_FEATURE_K8);
967
968         /* MFENCE stops RDTSC speculation */
969         set_cpu_cap(c, X86_FEATURE_MFENCE_RDTSC);
970
971         if (c->x86 == 0x10)
972                 fam10h_check_enable_mmcfg(c);
973
974         if (amd_apic_timer_broken())
975                 disable_apic_timer = 1;
976
977         if (c == &boot_cpu_data && c->x86 >= 0xf && c->x86 <= 0x11) {
978                 unsigned long long tseg;
979
980                 /*
981                  * Split up direct mapping around the TSEG SMM area.
982                  * Don't do it for gbpages because there seems very little
983                  * benefit in doing so.
984                  */
985                 if (!rdmsrl_safe(MSR_K8_TSEG_ADDR, &tseg) &&
986                 (tseg >> PMD_SHIFT) < (max_pfn_mapped >> (PMD_SHIFT-PAGE_SHIFT)))
987                         set_memory_4k((unsigned long)__va(tseg), 1);
988         }
989 }
990
991 void __cpuinit detect_ht(struct cpuinfo_x86 *c)
992 {
993 #ifdef CONFIG_SMP
994         u32 eax, ebx, ecx, edx;
995         int index_msb, core_bits;
996
997         cpuid(1, &eax, &ebx, &ecx, &edx);
998
999
1000         if (!cpu_has(c, X86_FEATURE_HT))
1001                 return;
1002         if (cpu_has(c, X86_FEATURE_CMP_LEGACY))
1003                 goto out;
1004
1005         smp_num_siblings = (ebx & 0xff0000) >> 16;
1006
1007         if (smp_num_siblings == 1) {
1008                 printk(KERN_INFO  "CPU: Hyper-Threading is disabled\n");
1009         } else if (smp_num_siblings > 1) {
1010
1011                 if (smp_num_siblings > NR_CPUS) {
1012                         printk(KERN_WARNING "CPU: Unsupported number of "
1013                                "siblings %d", smp_num_siblings);
1014                         smp_num_siblings = 1;
1015                         return;
1016                 }
1017
1018                 index_msb = get_count_order(smp_num_siblings);
1019                 c->phys_proc_id = phys_pkg_id(index_msb);
1020
1021                 smp_num_siblings = smp_num_siblings / c->x86_max_cores;
1022
1023                 index_msb = get_count_order(smp_num_siblings);
1024
1025                 core_bits = get_count_order(c->x86_max_cores);
1026
1027                 c->cpu_core_id = phys_pkg_id(index_msb) &
1028                                                ((1 << core_bits) - 1);
1029         }
1030 out:
1031         if ((c->x86_max_cores * smp_num_siblings) > 1) {
1032                 printk(KERN_INFO  "CPU: Physical Processor ID: %d\n",
1033                        c->phys_proc_id);
1034                 printk(KERN_INFO  "CPU: Processor Core ID: %d\n",
1035                        c->cpu_core_id);
1036         }
1037
1038 #endif
1039 }
1040
1041 /*
1042  * find out the number of processor cores on the die
1043  */
1044 static int __cpuinit intel_num_cpu_cores(struct cpuinfo_x86 *c)
1045 {
1046         unsigned int eax, t;
1047
1048         if (c->cpuid_level < 4)
1049                 return 1;
1050
1051         cpuid_count(4, 0, &eax, &t, &t, &t);
1052
1053         if (eax & 0x1f)
1054                 return ((eax >> 26) + 1);
1055         else
1056                 return 1;
1057 }
1058
1059 static void __cpuinit srat_detect_node(void)
1060 {
1061 #ifdef CONFIG_NUMA
1062         unsigned node;
1063         int cpu = smp_processor_id();
1064         int apicid = hard_smp_processor_id();
1065
1066         /* Don't do the funky fallback heuristics the AMD version employs
1067            for now. */
1068         node = apicid_to_node[apicid];
1069         if (node == NUMA_NO_NODE || !node_online(node))
1070                 node = first_node(node_online_map);
1071         numa_set_node(cpu, node);
1072
1073         printk(KERN_INFO "CPU %d/%x -> Node %d\n", cpu, apicid, node);
1074 #endif
1075 }
1076
1077 static void __cpuinit early_init_intel(struct cpuinfo_x86 *c)
1078 {
1079         if ((c->x86 == 0xf && c->x86_model >= 0x03) ||
1080             (c->x86 == 0x6 && c->x86_model >= 0x0e))
1081                 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
1082 }
1083
1084 static void __cpuinit init_intel(struct cpuinfo_x86 *c)
1085 {
1086         /* Cache sizes */
1087         unsigned n;
1088
1089         init_intel_cacheinfo(c);
1090         if (c->cpuid_level > 9) {
1091                 unsigned eax = cpuid_eax(10);
1092                 /* Check for version and the number of counters */
1093                 if ((eax & 0xff) && (((eax>>8) & 0xff) > 1))
1094                         set_cpu_cap(c, X86_FEATURE_ARCH_PERFMON);
1095         }
1096
1097         if (cpu_has_ds) {
1098                 unsigned int l1, l2;
1099                 rdmsr(MSR_IA32_MISC_ENABLE, l1, l2);
1100                 if (!(l1 & (1<<11)))
1101                         set_cpu_cap(c, X86_FEATURE_BTS);
1102                 if (!(l1 & (1<<12)))
1103                         set_cpu_cap(c, X86_FEATURE_PEBS);
1104         }
1105
1106
1107         if (cpu_has_bts)
1108                 ds_init_intel(c);
1109
1110         n = c->extended_cpuid_level;
1111         if (n >= 0x80000008) {
1112                 unsigned eax = cpuid_eax(0x80000008);
1113                 c->x86_virt_bits = (eax >> 8) & 0xff;
1114                 c->x86_phys_bits = eax & 0xff;
1115                 /* CPUID workaround for Intel 0F34 CPU */
1116                 if (c->x86_vendor == X86_VENDOR_INTEL &&
1117                     c->x86 == 0xF && c->x86_model == 0x3 &&
1118                     c->x86_mask == 0x4)
1119                         c->x86_phys_bits = 36;
1120         }
1121
1122         if (c->x86 == 15)
1123                 c->x86_cache_alignment = c->x86_clflush_size * 2;
1124         if (c->x86 == 6)
1125                 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
1126         set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
1127         c->x86_max_cores = intel_num_cpu_cores(c);
1128
1129         srat_detect_node();
1130 }
1131
1132 static void __cpuinit early_init_centaur(struct cpuinfo_x86 *c)
1133 {
1134         if (c->x86 == 0x6 && c->x86_model >= 0xf)
1135                 set_bit(X86_FEATURE_CONSTANT_TSC, &c->x86_capability);
1136 }
1137
1138 static void __cpuinit init_centaur(struct cpuinfo_x86 *c)
1139 {
1140         /* Cache sizes */
1141         unsigned n;
1142
1143         n = c->extended_cpuid_level;
1144         if (n >= 0x80000008) {
1145                 unsigned eax = cpuid_eax(0x80000008);
1146                 c->x86_virt_bits = (eax >> 8) & 0xff;
1147                 c->x86_phys_bits = eax & 0xff;
1148         }
1149
1150         if (c->x86 == 0x6 && c->x86_model >= 0xf) {
1151                 c->x86_cache_alignment = c->x86_clflush_size * 2;
1152                 set_cpu_cap(c, X86_FEATURE_CONSTANT_TSC);
1153                 set_cpu_cap(c, X86_FEATURE_REP_GOOD);
1154         }
1155         set_cpu_cap(c, X86_FEATURE_LFENCE_RDTSC);
1156 }
1157
1158 static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c)
1159 {
1160         char *v = c->x86_vendor_id;
1161
1162         if (!strcmp(v, "AuthenticAMD"))
1163                 c->x86_vendor = X86_VENDOR_AMD;
1164         else if (!strcmp(v, "GenuineIntel"))
1165                 c->x86_vendor = X86_VENDOR_INTEL;
1166         else if (!strcmp(v, "CentaurHauls"))
1167                 c->x86_vendor = X86_VENDOR_CENTAUR;
1168         else
1169                 c->x86_vendor = X86_VENDOR_UNKNOWN;
1170 }
1171
1172 /* Do some early cpuid on the boot CPU to get some parameter that are
1173    needed before check_bugs. Everything advanced is in identify_cpu
1174    below. */
1175 static void __cpuinit early_identify_cpu(struct cpuinfo_x86 *c)
1176 {
1177         u32 tfms, xlvl;
1178
1179         c->loops_per_jiffy = loops_per_jiffy;
1180         c->x86_cache_size = -1;
1181         c->x86_vendor = X86_VENDOR_UNKNOWN;
1182         c->x86_model = c->x86_mask = 0; /* So far unknown... */
1183         c->x86_vendor_id[0] = '\0'; /* Unset */
1184         c->x86_model_id[0] = '\0';  /* Unset */
1185         c->x86_clflush_size = 64;
1186         c->x86_cache_alignment = c->x86_clflush_size;
1187         c->x86_max_cores = 1;
1188         c->x86_coreid_bits = 0;
1189         c->extended_cpuid_level = 0;
1190         memset(&c->x86_capability, 0, sizeof c->x86_capability);
1191
1192         /* Get vendor name */
1193         cpuid(0x00000000, (unsigned int *)&c->cpuid_level,
1194               (unsigned int *)&c->x86_vendor_id[0],
1195               (unsigned int *)&c->x86_vendor_id[8],
1196               (unsigned int *)&c->x86_vendor_id[4]);
1197
1198         get_cpu_vendor(c);
1199
1200         /* Initialize the standard set of capabilities */
1201         /* Note that the vendor-specific code below might override */
1202
1203         /* Intel-defined flags: level 0x00000001 */
1204         if (c->cpuid_level >= 0x00000001) {
1205                 __u32 misc;
1206                 cpuid(0x00000001, &tfms, &misc, &c->x86_capability[4],
1207                       &c->x86_capability[0]);
1208                 c->x86 = (tfms >> 8) & 0xf;
1209                 c->x86_model = (tfms >> 4) & 0xf;
1210                 c->x86_mask = tfms & 0xf;
1211                 if (c->x86 == 0xf)
1212                         c->x86 += (tfms >> 20) & 0xff;
1213                 if (c->x86 >= 0x6)
1214                         c->x86_model += ((tfms >> 16) & 0xF) << 4;
1215                 if (test_cpu_cap(c, X86_FEATURE_CLFLSH))
1216                         c->x86_clflush_size = ((misc >> 8) & 0xff) * 8;
1217         } else {
1218                 /* Have CPUID level 0 only - unheard of */
1219                 c->x86 = 4;
1220         }
1221
1222         c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xff;
1223 #ifdef CONFIG_SMP
1224         c->phys_proc_id = c->initial_apicid;
1225 #endif
1226         /* AMD-defined flags: level 0x80000001 */
1227         xlvl = cpuid_eax(0x80000000);
1228         c->extended_cpuid_level = xlvl;
1229         if ((xlvl & 0xffff0000) == 0x80000000) {
1230                 if (xlvl >= 0x80000001) {
1231                         c->x86_capability[1] = cpuid_edx(0x80000001);
1232                         c->x86_capability[6] = cpuid_ecx(0x80000001);
1233                 }
1234                 if (xlvl >= 0x80000004)
1235                         get_model_name(c); /* Default name */
1236         }
1237
1238         /* Transmeta-defined flags: level 0x80860001 */
1239         xlvl = cpuid_eax(0x80860000);
1240         if ((xlvl & 0xffff0000) == 0x80860000) {
1241                 /* Don't set x86_cpuid_level here for now to not confuse. */
1242                 if (xlvl >= 0x80860001)
1243                         c->x86_capability[2] = cpuid_edx(0x80860001);
1244         }
1245
1246         c->extended_cpuid_level = cpuid_eax(0x80000000);
1247         if (c->extended_cpuid_level >= 0x80000007)
1248                 c->x86_power = cpuid_edx(0x80000007);
1249
1250
1251         clear_cpu_cap(c, X86_FEATURE_PAT);
1252
1253         switch (c->x86_vendor) {
1254         case X86_VENDOR_AMD:
1255                 early_init_amd(c);
1256                 if (c->x86 >= 0xf && c->x86 <= 0x11)
1257                         set_cpu_cap(c, X86_FEATURE_PAT);
1258                 break;
1259         case X86_VENDOR_INTEL:
1260                 early_init_intel(c);
1261                 if (c->x86 == 0xF || (c->x86 == 6 && c->x86_model >= 15))
1262                         set_cpu_cap(c, X86_FEATURE_PAT);
1263                 break;
1264         case X86_VENDOR_CENTAUR:
1265                 early_init_centaur(c);
1266                 break;
1267         }
1268
1269 }
1270
1271 /*
1272  * This does the hard work of actually picking apart the CPU stuff...
1273  */
1274 void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
1275 {
1276         int i;
1277
1278         early_identify_cpu(c);
1279
1280         init_scattered_cpuid_features(c);
1281
1282         c->apicid = phys_pkg_id(0);
1283
1284         /*
1285          * Vendor-specific initialization.  In this section we
1286          * canonicalize the feature flags, meaning if there are
1287          * features a certain CPU supports which CPUID doesn't
1288          * tell us, CPUID claiming incorrect flags, or other bugs,
1289          * we handle them here.
1290          *
1291          * At the end of this section, c->x86_capability better
1292          * indicate the features this CPU genuinely supports!
1293          */
1294         switch (c->x86_vendor) {
1295         case X86_VENDOR_AMD:
1296                 init_amd(c);
1297                 break;
1298
1299         case X86_VENDOR_INTEL:
1300                 init_intel(c);
1301                 break;
1302
1303         case X86_VENDOR_CENTAUR:
1304                 init_centaur(c);
1305                 break;
1306
1307         case X86_VENDOR_UNKNOWN:
1308         default:
1309                 display_cacheinfo(c);
1310                 break;
1311         }
1312
1313         detect_ht(c);
1314
1315         /*
1316          * On SMP, boot_cpu_data holds the common feature set between
1317          * all CPUs; so make sure that we indicate which features are
1318          * common between the CPUs.  The first time this routine gets
1319          * executed, c == &boot_cpu_data.
1320          */
1321         if (c != &boot_cpu_data) {
1322                 /* AND the already accumulated flags with these */
1323                 for (i = 0; i < NCAPINTS; i++)
1324                         boot_cpu_data.x86_capability[i] &= c->x86_capability[i];
1325         }
1326
1327         /* Clear all flags overriden by options */
1328         for (i = 0; i < NCAPINTS; i++)
1329                 c->x86_capability[i] &= ~cleared_cpu_caps[i];
1330
1331 #ifdef CONFIG_X86_MCE
1332         mcheck_init(c);
1333 #endif
1334         select_idle_routine(c);
1335
1336 #ifdef CONFIG_NUMA
1337         numa_add_cpu(smp_processor_id());
1338 #endif
1339
1340 }
1341
1342 void __cpuinit identify_boot_cpu(void)
1343 {
1344         identify_cpu(&boot_cpu_data);
1345 }
1346
1347 void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c)
1348 {
1349         BUG_ON(c == &boot_cpu_data);
1350         identify_cpu(c);
1351         mtrr_ap_init();
1352 }
1353
1354 static __init int setup_noclflush(char *arg)
1355 {
1356         setup_clear_cpu_cap(X86_FEATURE_CLFLSH);
1357         return 1;
1358 }
1359 __setup("noclflush", setup_noclflush);
1360
1361 void __cpuinit print_cpu_info(struct cpuinfo_x86 *c)
1362 {
1363         if (c->x86_model_id[0])
1364                 printk(KERN_CONT "%s", c->x86_model_id);
1365
1366         if (c->x86_mask || c->cpuid_level >= 0)
1367                 printk(KERN_CONT " stepping %02x\n", c->x86_mask);
1368         else
1369                 printk(KERN_CONT "\n");
1370 }
1371
1372 static __init int setup_disablecpuid(char *arg)
1373 {
1374         int bit;
1375         if (get_option(&arg, &bit) && bit < NCAPINTS*32)
1376                 setup_clear_cpu_cap(bit);
1377         else
1378                 return 0;
1379         return 1;
1380 }
1381 __setup("clearcpuid=", setup_disablecpuid);