2 * Copyright (C) 1995 Linus Torvalds
6 * This file handles the architecture-dependent parts of initialization
9 #include <linux/errno.h>
10 #include <linux/sched.h>
11 #include <linux/kernel.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>
49 #include <asm/uaccess.h>
50 #include <asm/system.h>
51 #include <asm/vsyscall.h>
56 #include <video/edid.h>
60 #include <asm/mpspec.h>
61 #include <asm/mmu_context.h>
62 #include <asm/proto.h>
63 #include <asm/setup.h>
65 #include <asm/sections.h>
67 #include <asm/cacheflush.h>
70 #include <asm/topology.h>
71 #include <asm/trampoline.h>
73 #include <mach_apic.h>
74 #ifdef CONFIG_PARAVIRT
75 #include <asm/paravirt.h>
84 struct cpuinfo_x86 boot_cpu_data __read_mostly
;
85 EXPORT_SYMBOL(boot_cpu_data
);
87 __u32 cleared_cpu_caps
[NCAPINTS
] __cpuinitdata
;
89 unsigned long mmu_cr4_features
;
91 /* Boot loader ID as an integer, for the benefit of proc_dointvec */
94 unsigned long saved_video_mode
;
96 int force_mwait __cpuinitdata
;
102 char dmi_alloc_data
[DMI_MAX_DATA
];
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];
114 struct edid_info edid_info
;
115 EXPORT_SYMBOL_GPL(edid_info
);
117 extern int root_mountflags
;
119 char __initdata command_line
[COMMAND_LINE_SIZE
];
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
}
142 #define IORESOURCE_RAM (IORESOURCE_BUSY | IORESOURCE_MEM)
144 static struct resource data_resource
= {
145 .name
= "Kernel data",
148 .flags
= IORESOURCE_RAM
,
150 static struct resource code_resource
= {
151 .name
= "Kernel code",
154 .flags
= IORESOURCE_RAM
,
156 static struct resource bss_resource
= {
157 .name
= "Kernel bss",
160 .flags
= IORESOURCE_RAM
,
163 static void __cpuinit
early_identify_cpu(struct cpuinfo_x86
*c
);
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.
170 static int __init
setup_elfcorehdr(char *arg
)
175 elfcorehdr_addr
= memparse(arg
, &end
);
176 return end
> arg
? 0 : -EINVAL
;
178 early_param("elfcorehdr", setup_elfcorehdr
);
183 contig_initmem_init(unsigned long start_pfn
, unsigned long end_pfn
)
185 unsigned long bootmap_size
, bootmap
;
187 bootmap_size
= bootmem_bootmap_pages(end_pfn
)<<PAGE_SHIFT
;
188 bootmap
= find_e820_area(0, end_pfn
<<PAGE_SHIFT
, bootmap_size
,
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
);
200 #if defined(CONFIG_EDD) || defined(CONFIG_EDD_MODULE)
202 #ifdef CONFIG_EDD_MODULE
206 * copy_edd() - Copy the BIOS EDD information
207 * from boot_params into a safe place.
210 static inline void copy_edd(void)
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
;
219 static inline void copy_edd(void)
225 static void __init
reserve_crashkernel(void)
227 unsigned long long total_mem
;
228 unsigned long long crash_size
, crash_base
;
231 total_mem
= ((unsigned long long)max_low_pfn
- min_low_pfn
) << PAGE_SHIFT
;
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");
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");
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
);
260 static inline void __init
reserve_crashkernel(void)
264 /* Overridden in paravirt.c if CONFIG_PARAVIRT */
265 void __attribute__((weak
)) __init
memory_setup(void)
267 machine_specific_memory_setup();
270 static void __init
parse_setup_data(void)
272 struct setup_data
*data
;
273 unsigned long pa_data
;
275 if (boot_params
.hdr
.version
< 0x0209)
277 pa_data
= boot_params
.hdr
.setup_data
;
279 data
= early_ioremap(pa_data
, PAGE_SIZE
);
280 switch (data
->type
) {
284 #ifndef CONFIG_DEBUG_BOOT_PARAMS
285 free_early(pa_data
, pa_data
+sizeof(*data
)+data
->len
);
287 pa_data
= data
->next
;
288 early_iounmap(data
, PAGE_SIZE
);
293 * setup_arch - architecture-specific boot-time initializations
295 * Note: On x86_64, fixmaps are ready for use even before this is called.
297 void __init
setup_arch(char **cmdline_p
)
301 printk(KERN_INFO
"Command line: %s\n", boot_command_line
);
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
;
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);
315 if (!strncmp((char *)&boot_params
.efi_info
.efi_loader_signature
,
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
;
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;
339 early_identify_cpu(&boot_cpu_data
);
341 strlcpy(command_line
, boot_command_line
, COMMAND_LINE_SIZE
);
342 *cmdline_p
= command_line
;
348 #ifdef CONFIG_PROVIDE_OHCI1394_DMA_INIT
349 if (init_ohci1394_dma_early
)
350 init_ohci1394_dma_on_all_controllers();
353 finish_e820_parsing();
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
);
360 early_gart_iommu_check();
362 e820_register_active_regions(0, 0, -1UL);
364 * partially used pages are not usable - thus
365 * we are rounding upwards:
367 end_pfn
= e820_end_of_ram();
368 /* update e820 for memory not covered by WB MTRRs */
370 if (mtrr_trim_uncached_memory(end_pfn
)) {
371 e820_register_active_regions(0, 0, -1UL);
372 end_pfn
= e820_end_of_ram();
375 num_physpages
= end_pfn
;
379 max_pfn_mapped
= init_memory_mapping(0, (max_pfn_mapped
<< PAGE_SHIFT
));
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
;
394 x86_cpu_to_node_map_early_ptr
= (void *)x86_cpu_to_node_map_init
;
400 * Initialize the ACPI boot-time table parser (gets the RSDP and SDT).
401 * Call this early for SRAT node setup.
403 acpi_boot_table_init();
406 /* How many end-of-memory variables you have, grandma! */
407 max_low_pfn
= end_pfn
;
409 high_memory
= (void *)__va(end_pfn
* PAGE_SIZE
- 1) + 1;
411 /* Remove active ranges so rediscovery with NUMA-awareness happens */
412 remove_all_active_ranges();
414 #ifdef CONFIG_ACPI_NUMA
416 * Parse SRAT to discover nodes.
422 numa_initmem_init(0, end_pfn
);
424 contig_initmem_init(0, end_pfn
);
427 dma32_reserve_bootmem();
429 #ifdef CONFIG_ACPI_SLEEP
431 * Reserve low memory region for sleep support.
433 acpi_reserve_bootmem();
437 efi_reserve_bootmem();
440 * Find and reserve possible boot-time SMP configuration:
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
;
450 if (ramdisk_end
<= end_of_mem
) {
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
456 initrd_start
= ramdisk_image
+ PAGE_OFFSET
;
457 initrd_end
= initrd_start
+ramdisk_size
;
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
);
467 reserve_crashkernel();
469 reserve_ibft_region();
478 * Read APIC and some other early information from ACPI tables.
486 * get boot-time SMP configuration:
488 if (smp_found_config
)
490 init_apic_mappings();
491 ioapic_init_mappings();
494 * We trust e820 completely. No explicit ROM probing in memory.
496 e820_reserve_resources();
497 e820_mark_nosave_regions();
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
]);
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
;
515 static int __cpuinit
get_model_name(struct cpuinfo_x86
*c
)
519 if (c
->extended_cpuid_level
< 0x80000004)
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;
531 static void __cpuinit
display_cacheinfo(struct cpuinfo_x86
*c
)
533 unsigned int n
, dummy
, eax
, ebx
, ecx
, edx
;
535 n
= c
->extended_cpuid_level
;
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 */
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);
553 printk(KERN_INFO
"CPU: L2 Cache: %dK (%d bytes/line)\n",
554 c
->x86_cache_size
, ecx
& 0xFF);
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;
564 static int __cpuinit
nearby_node(int apicid
)
568 for (i
= apicid
- 1; i
>= 0; i
--) {
569 node
= apicid_to_node
[i
];
570 if (node
!= NUMA_NO_NODE
&& node_online(node
))
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
))
578 return first_node(node_online_map
); /* Shouldn't happen */
582 #ifdef CONFIG_PCI_MMCONFIG
583 struct pci_hostbridge_probe
{
590 static u64 __cpuinitdata fam10h_pci_mmconf_base
;
591 static int __cpuinitdata fam10h_pci_mmconf_base_status
;
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 },
603 static int __cpuinit
cmp_range(const void *x1
, const void *x2
)
605 const struct range
*r1
= x1
;
606 const struct range
*r2
= x2
;
609 start1
= r1
->start
>> 32;
610 start2
= r2
->start
>> 32;
612 return start1
- start2
;
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)
629 u64 base
= FAM10H_PCI_MMCONF_BASE
;
632 struct range range
[8];
634 /* only try to get setting from BSP */
636 if (fam10h_pci_mmconf_base_status
)
639 if (!early_pci_allowed())
643 for (i
= 0; i
< ARRAY_SIZE(pci_probes
); i
++) {
648 bus
= pci_probes
[i
].bus
;
649 slot
= pci_probes
[i
].slot
;
650 id
= read_pci_config(bus
, slot
, 0, PCI_VENDOR_ID
);
652 vendor
= id
& 0xffff;
653 device
= (id
>>16) & 0xffff;
654 if (pci_probes
[i
].vendor
== vendor
&&
655 pci_probes
[i
].device
== device
) {
665 address
= MSR_K8_SYSCFG
;
666 rdmsrl(address
, val
);
668 /* TOP_MEM2 is not enabled? */
669 if (!(val
& (1<<21))) {
673 address
= MSR_K8_TOP_MEM2
;
674 rdmsrl(address
, val
);
675 tom2
= val
& (0xffffULL
<<32);
679 base
= tom2
+ (1ULL<<32);
682 * need to check if the range is in the high mmio range that is
686 for (i
= 0; i
< 8; i
++) {
690 reg
= read_pci_config(bus
, slot
, 1, 0x80 + (i
<< 3));
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*/
701 range
[hi_mmio_num
].start
= start
;
702 range
[hi_mmio_num
].end
= end
;
710 sort(range
, hi_mmio_num
, sizeof(struct range
), cmp_range
, NULL
);
712 if (range
[hi_mmio_num
- 1].end
< base
)
714 if (range
[0].start
> base
)
717 /* need to find one window */
718 base
= range
[0].start
- (1ULL << 32);
719 if ((base
> tom2
) && BASE_VALID(base
))
721 base
= range
[hi_mmio_num
- 1].end
+ (1ULL << 32);
722 if ((base
> tom2
) && BASE_VALID(base
))
724 /* need to find window between ranges */
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
))
735 fam10h_pci_mmconf_base_status
= -1;
738 fam10h_pci_mmconf_base
= base
;
739 fam10h_pci_mmconf_base_status
= 1;
743 static void __cpuinit
fam10h_check_enable_mmcfg(struct cpuinfo_x86
*c
)
745 #ifdef CONFIG_PCI_MMCONFIG
749 address
= MSR_FAM10H_MMIO_CONF_BASE
;
750 rdmsrl(address
, val
);
752 /* try to make sure that AP's setting is identical to BSP setting */
753 if (val
& FAM10H_MMIO_CONF_ENABLE
) {
755 base
= val
& (0xffffULL
<< 32);
756 if (fam10h_pci_mmconf_base_status
<= 0) {
757 fam10h_pci_mmconf_base
= base
;
758 fam10h_pci_mmconf_base_status
= 1;
760 } else if (fam10h_pci_mmconf_base
== base
)
765 * if it is not enabled, try to enable it and assume only one segment
768 get_fam10h_pci_mmconf_base();
769 if (fam10h_pci_mmconf_base_status
<= 0)
772 printk(KERN_INFO
"Enable MMCONFIG on AMD Family 10h\n");
773 val
&= ~((FAM10H_MMIO_CONF_BASE_MASK
<<FAM10H_MMIO_CONF_BASE_SHIFT
) |
774 (FAM10H_MMIO_CONF_BUSRANGE_MASK
<<FAM10H_MMIO_CONF_BUSRANGE_SHIFT
));
775 val
|= fam10h_pci_mmconf_base
| (8 << FAM10H_MMIO_CONF_BUSRANGE_SHIFT
) |
776 FAM10H_MMIO_CONF_ENABLE
;
777 wrmsrl(address
, val
);
782 * On a AMD dual core setup the lower bits of the APIC id distingush the cores.
783 * Assumes number of cores is a power of two.
785 static void __cpuinit
amd_detect_cmp(struct cpuinfo_x86
*c
)
790 int cpu
= smp_processor_id();
792 unsigned apicid
= hard_smp_processor_id();
794 bits
= c
->x86_coreid_bits
;
796 /* Low order bits define the core id (index of core in socket) */
797 c
->cpu_core_id
= c
->initial_apicid
& ((1 << bits
)-1);
798 /* Convert the initial APIC ID into the socket ID */
799 c
->phys_proc_id
= c
->initial_apicid
>> bits
;
802 node
= c
->phys_proc_id
;
803 if (apicid_to_node
[apicid
] != NUMA_NO_NODE
)
804 node
= apicid_to_node
[apicid
];
805 if (!node_online(node
)) {
806 /* Two possibilities here:
807 - The CPU is missing memory and no node was created.
808 In that case try picking one from a nearby CPU
809 - The APIC IDs differ from the HyperTransport node IDs
810 which the K8 northbridge parsing fills in.
811 Assume they are all increased by a constant offset,
812 but in the same order as the HT nodeids.
813 If that doesn't result in a usable node fall back to the
814 path for the previous case. */
816 int ht_nodeid
= c
->initial_apicid
;
818 if (ht_nodeid
>= 0 &&
819 apicid_to_node
[ht_nodeid
] != NUMA_NO_NODE
)
820 node
= apicid_to_node
[ht_nodeid
];
821 /* Pick a nearby node */
822 if (!node_online(node
))
823 node
= nearby_node(apicid
);
825 numa_set_node(cpu
, node
);
827 printk(KERN_INFO
"CPU %d/%x -> Node %d\n", cpu
, apicid
, node
);
832 static void __cpuinit
early_init_amd_mc(struct cpuinfo_x86
*c
)
837 /* Multi core CPU? */
838 if (c
->extended_cpuid_level
< 0x80000008)
841 ecx
= cpuid_ecx(0x80000008);
843 c
->x86_max_cores
= (ecx
& 0xff) + 1;
845 /* CPU telling us the core id bits shift? */
846 bits
= (ecx
>> 12) & 0xF;
848 /* Otherwise recompute */
850 while ((1 << bits
) < c
->x86_max_cores
)
854 c
->x86_coreid_bits
= bits
;
859 #define ENABLE_C1E_MASK 0x18000000
860 #define CPUID_PROCESSOR_SIGNATURE 1
861 #define CPUID_XFAM 0x0ff00000
862 #define CPUID_XFAM_K8 0x00000000
863 #define CPUID_XFAM_10H 0x00100000
864 #define CPUID_XFAM_11H 0x00200000
865 #define CPUID_XMOD 0x000f0000
866 #define CPUID_XMOD_REV_F 0x00040000
868 /* AMD systems with C1E don't have a working lAPIC timer. Check for that. */
869 static __cpuinit
int amd_apic_timer_broken(void)
871 u32 lo
, hi
, eax
= cpuid_eax(CPUID_PROCESSOR_SIGNATURE
);
873 switch (eax
& CPUID_XFAM
) {
875 if ((eax
& CPUID_XMOD
) < CPUID_XMOD_REV_F
)
879 rdmsr(MSR_K8_ENABLE_C1E
, lo
, hi
);
880 if (lo
& ENABLE_C1E_MASK
)
884 /* err on the side of caution */
890 static void __cpuinit
early_init_amd(struct cpuinfo_x86
*c
)
892 early_init_amd_mc(c
);
894 /* c->x86_power is 8000_0007 edx. Bit 8 is constant TSC */
895 if (c
->x86_power
& (1<<8))
896 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
899 static void __cpuinit
init_amd(struct cpuinfo_x86
*c
)
907 * Disable TLB flush filter by setting HWCR.FFDIS on K8
908 * bit 6 of msr C001_0015
910 * Errata 63 for SH-B3 steppings
911 * Errata 122 for all steppings (F+ have it disabled by default)
914 rdmsrl(MSR_K8_HWCR
, value
);
916 wrmsrl(MSR_K8_HWCR
, value
);
920 /* Bit 31 in normal CPUID used for nonstandard 3DNow ID;
921 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */
922 clear_cpu_cap(c
, 0*32+31);
924 /* On C+ stepping K8 rep microcode works well for copy/memset */
925 level
= cpuid_eax(1);
926 if (c
->x86
== 15 && ((level
>= 0x0f48 && level
< 0x0f50) ||
928 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
929 if (c
->x86
== 0x10 || c
->x86
== 0x11)
930 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
932 /* Enable workaround for FXSAVE leak */
934 set_cpu_cap(c
, X86_FEATURE_FXSAVE_LEAK
);
936 level
= get_model_name(c
);
940 /* Should distinguish Models here, but this is only
941 a fallback anyways. */
942 strcpy(c
->x86_model_id
, "Hammer");
946 display_cacheinfo(c
);
948 /* Multi core CPU? */
949 if (c
->extended_cpuid_level
>= 0x80000008)
952 if (c
->extended_cpuid_level
>= 0x80000006 &&
953 (cpuid_edx(0x80000006) & 0xf000))
954 num_cache_leaves
= 4;
956 num_cache_leaves
= 3;
958 if (c
->x86
== 0xf || c
->x86
== 0x10 || c
->x86
== 0x11)
959 set_cpu_cap(c
, X86_FEATURE_K8
);
961 /* MFENCE stops RDTSC speculation */
962 set_cpu_cap(c
, X86_FEATURE_MFENCE_RDTSC
);
965 fam10h_check_enable_mmcfg(c
);
967 if (amd_apic_timer_broken())
968 disable_apic_timer
= 1;
970 if (c
== &boot_cpu_data
&& c
->x86
>= 0xf && c
->x86
<= 0x11) {
971 unsigned long long tseg
;
974 * Split up direct mapping around the TSEG SMM area.
975 * Don't do it for gbpages because there seems very little
976 * benefit in doing so.
978 if (!rdmsrl_safe(MSR_K8_TSEG_ADDR
, &tseg
) &&
979 (tseg
>> PMD_SHIFT
) < (max_pfn_mapped
>> (PMD_SHIFT
-PAGE_SHIFT
)))
980 set_memory_4k((unsigned long)__va(tseg
), 1);
984 void __cpuinit
detect_ht(struct cpuinfo_x86
*c
)
987 u32 eax
, ebx
, ecx
, edx
;
988 int index_msb
, core_bits
;
990 cpuid(1, &eax
, &ebx
, &ecx
, &edx
);
993 if (!cpu_has(c
, X86_FEATURE_HT
))
995 if (cpu_has(c
, X86_FEATURE_CMP_LEGACY
))
998 smp_num_siblings
= (ebx
& 0xff0000) >> 16;
1000 if (smp_num_siblings
== 1) {
1001 printk(KERN_INFO
"CPU: Hyper-Threading is disabled\n");
1002 } else if (smp_num_siblings
> 1) {
1004 if (smp_num_siblings
> NR_CPUS
) {
1005 printk(KERN_WARNING
"CPU: Unsupported number of "
1006 "siblings %d", smp_num_siblings
);
1007 smp_num_siblings
= 1;
1011 index_msb
= get_count_order(smp_num_siblings
);
1012 c
->phys_proc_id
= phys_pkg_id(index_msb
);
1014 smp_num_siblings
= smp_num_siblings
/ c
->x86_max_cores
;
1016 index_msb
= get_count_order(smp_num_siblings
);
1018 core_bits
= get_count_order(c
->x86_max_cores
);
1020 c
->cpu_core_id
= phys_pkg_id(index_msb
) &
1021 ((1 << core_bits
) - 1);
1024 if ((c
->x86_max_cores
* smp_num_siblings
) > 1) {
1025 printk(KERN_INFO
"CPU: Physical Processor ID: %d\n",
1027 printk(KERN_INFO
"CPU: Processor Core ID: %d\n",
1035 * find out the number of processor cores on the die
1037 static int __cpuinit
intel_num_cpu_cores(struct cpuinfo_x86
*c
)
1039 unsigned int eax
, t
;
1041 if (c
->cpuid_level
< 4)
1044 cpuid_count(4, 0, &eax
, &t
, &t
, &t
);
1047 return ((eax
>> 26) + 1);
1052 static void __cpuinit
srat_detect_node(void)
1056 int cpu
= smp_processor_id();
1057 int apicid
= hard_smp_processor_id();
1059 /* Don't do the funky fallback heuristics the AMD version employs
1061 node
= apicid_to_node
[apicid
];
1062 if (node
== NUMA_NO_NODE
|| !node_online(node
))
1063 node
= first_node(node_online_map
);
1064 numa_set_node(cpu
, node
);
1066 printk(KERN_INFO
"CPU %d/%x -> Node %d\n", cpu
, apicid
, node
);
1070 static void __cpuinit
early_init_intel(struct cpuinfo_x86
*c
)
1072 if ((c
->x86
== 0xf && c
->x86_model
>= 0x03) ||
1073 (c
->x86
== 0x6 && c
->x86_model
>= 0x0e))
1074 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
1077 static void __cpuinit
init_intel(struct cpuinfo_x86
*c
)
1082 init_intel_cacheinfo(c
);
1083 if (c
->cpuid_level
> 9) {
1084 unsigned eax
= cpuid_eax(10);
1085 /* Check for version and the number of counters */
1086 if ((eax
& 0xff) && (((eax
>>8) & 0xff) > 1))
1087 set_cpu_cap(c
, X86_FEATURE_ARCH_PERFMON
);
1091 unsigned int l1
, l2
;
1092 rdmsr(MSR_IA32_MISC_ENABLE
, l1
, l2
);
1093 if (!(l1
& (1<<11)))
1094 set_cpu_cap(c
, X86_FEATURE_BTS
);
1095 if (!(l1
& (1<<12)))
1096 set_cpu_cap(c
, X86_FEATURE_PEBS
);
1103 n
= c
->extended_cpuid_level
;
1104 if (n
>= 0x80000008) {
1105 unsigned eax
= cpuid_eax(0x80000008);
1106 c
->x86_virt_bits
= (eax
>> 8) & 0xff;
1107 c
->x86_phys_bits
= eax
& 0xff;
1108 /* CPUID workaround for Intel 0F34 CPU */
1109 if (c
->x86_vendor
== X86_VENDOR_INTEL
&&
1110 c
->x86
== 0xF && c
->x86_model
== 0x3 &&
1112 c
->x86_phys_bits
= 36;
1116 c
->x86_cache_alignment
= c
->x86_clflush_size
* 2;
1118 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
1119 set_cpu_cap(c
, X86_FEATURE_LFENCE_RDTSC
);
1120 c
->x86_max_cores
= intel_num_cpu_cores(c
);
1125 static void __cpuinit
early_init_centaur(struct cpuinfo_x86
*c
)
1127 if (c
->x86
== 0x6 && c
->x86_model
>= 0xf)
1128 set_bit(X86_FEATURE_CONSTANT_TSC
, &c
->x86_capability
);
1131 static void __cpuinit
init_centaur(struct cpuinfo_x86
*c
)
1136 n
= c
->extended_cpuid_level
;
1137 if (n
>= 0x80000008) {
1138 unsigned eax
= cpuid_eax(0x80000008);
1139 c
->x86_virt_bits
= (eax
>> 8) & 0xff;
1140 c
->x86_phys_bits
= eax
& 0xff;
1143 if (c
->x86
== 0x6 && c
->x86_model
>= 0xf) {
1144 c
->x86_cache_alignment
= c
->x86_clflush_size
* 2;
1145 set_cpu_cap(c
, X86_FEATURE_CONSTANT_TSC
);
1146 set_cpu_cap(c
, X86_FEATURE_REP_GOOD
);
1148 set_cpu_cap(c
, X86_FEATURE_LFENCE_RDTSC
);
1151 static void __cpuinit
get_cpu_vendor(struct cpuinfo_x86
*c
)
1153 char *v
= c
->x86_vendor_id
;
1155 if (!strcmp(v
, "AuthenticAMD"))
1156 c
->x86_vendor
= X86_VENDOR_AMD
;
1157 else if (!strcmp(v
, "GenuineIntel"))
1158 c
->x86_vendor
= X86_VENDOR_INTEL
;
1159 else if (!strcmp(v
, "CentaurHauls"))
1160 c
->x86_vendor
= X86_VENDOR_CENTAUR
;
1162 c
->x86_vendor
= X86_VENDOR_UNKNOWN
;
1165 /* Do some early cpuid on the boot CPU to get some parameter that are
1166 needed before check_bugs. Everything advanced is in identify_cpu
1168 static void __cpuinit
early_identify_cpu(struct cpuinfo_x86
*c
)
1172 c
->loops_per_jiffy
= loops_per_jiffy
;
1173 c
->x86_cache_size
= -1;
1174 c
->x86_vendor
= X86_VENDOR_UNKNOWN
;
1175 c
->x86_model
= c
->x86_mask
= 0; /* So far unknown... */
1176 c
->x86_vendor_id
[0] = '\0'; /* Unset */
1177 c
->x86_model_id
[0] = '\0'; /* Unset */
1178 c
->x86_clflush_size
= 64;
1179 c
->x86_cache_alignment
= c
->x86_clflush_size
;
1180 c
->x86_max_cores
= 1;
1181 c
->x86_coreid_bits
= 0;
1182 c
->extended_cpuid_level
= 0;
1183 memset(&c
->x86_capability
, 0, sizeof c
->x86_capability
);
1185 /* Get vendor name */
1186 cpuid(0x00000000, (unsigned int *)&c
->cpuid_level
,
1187 (unsigned int *)&c
->x86_vendor_id
[0],
1188 (unsigned int *)&c
->x86_vendor_id
[8],
1189 (unsigned int *)&c
->x86_vendor_id
[4]);
1193 /* Initialize the standard set of capabilities */
1194 /* Note that the vendor-specific code below might override */
1196 /* Intel-defined flags: level 0x00000001 */
1197 if (c
->cpuid_level
>= 0x00000001) {
1199 cpuid(0x00000001, &tfms
, &misc
, &c
->x86_capability
[4],
1200 &c
->x86_capability
[0]);
1201 c
->x86
= (tfms
>> 8) & 0xf;
1202 c
->x86_model
= (tfms
>> 4) & 0xf;
1203 c
->x86_mask
= tfms
& 0xf;
1205 c
->x86
+= (tfms
>> 20) & 0xff;
1207 c
->x86_model
+= ((tfms
>> 16) & 0xF) << 4;
1208 if (test_cpu_cap(c
, X86_FEATURE_CLFLSH
))
1209 c
->x86_clflush_size
= ((misc
>> 8) & 0xff) * 8;
1211 /* Have CPUID level 0 only - unheard of */
1215 c
->initial_apicid
= (cpuid_ebx(1) >> 24) & 0xff;
1217 c
->phys_proc_id
= c
->initial_apicid
;
1219 /* AMD-defined flags: level 0x80000001 */
1220 xlvl
= cpuid_eax(0x80000000);
1221 c
->extended_cpuid_level
= xlvl
;
1222 if ((xlvl
& 0xffff0000) == 0x80000000) {
1223 if (xlvl
>= 0x80000001) {
1224 c
->x86_capability
[1] = cpuid_edx(0x80000001);
1225 c
->x86_capability
[6] = cpuid_ecx(0x80000001);
1227 if (xlvl
>= 0x80000004)
1228 get_model_name(c
); /* Default name */
1231 /* Transmeta-defined flags: level 0x80860001 */
1232 xlvl
= cpuid_eax(0x80860000);
1233 if ((xlvl
& 0xffff0000) == 0x80860000) {
1234 /* Don't set x86_cpuid_level here for now to not confuse. */
1235 if (xlvl
>= 0x80860001)
1236 c
->x86_capability
[2] = cpuid_edx(0x80860001);
1239 c
->extended_cpuid_level
= cpuid_eax(0x80000000);
1240 if (c
->extended_cpuid_level
>= 0x80000007)
1241 c
->x86_power
= cpuid_edx(0x80000007);
1244 clear_cpu_cap(c
, X86_FEATURE_PAT
);
1246 switch (c
->x86_vendor
) {
1247 case X86_VENDOR_AMD
:
1249 if (c
->x86
>= 0xf && c
->x86
<= 0x11)
1250 set_cpu_cap(c
, X86_FEATURE_PAT
);
1252 case X86_VENDOR_INTEL
:
1253 early_init_intel(c
);
1254 if (c
->x86
== 0xF || (c
->x86
== 6 && c
->x86_model
>= 15))
1255 set_cpu_cap(c
, X86_FEATURE_PAT
);
1257 case X86_VENDOR_CENTAUR
:
1258 early_init_centaur(c
);
1265 * This does the hard work of actually picking apart the CPU stuff...
1267 void __cpuinit
identify_cpu(struct cpuinfo_x86
*c
)
1271 early_identify_cpu(c
);
1273 init_scattered_cpuid_features(c
);
1275 c
->apicid
= phys_pkg_id(0);
1278 * Vendor-specific initialization. In this section we
1279 * canonicalize the feature flags, meaning if there are
1280 * features a certain CPU supports which CPUID doesn't
1281 * tell us, CPUID claiming incorrect flags, or other bugs,
1282 * we handle them here.
1284 * At the end of this section, c->x86_capability better
1285 * indicate the features this CPU genuinely supports!
1287 switch (c
->x86_vendor
) {
1288 case X86_VENDOR_AMD
:
1292 case X86_VENDOR_INTEL
:
1296 case X86_VENDOR_CENTAUR
:
1300 case X86_VENDOR_UNKNOWN
:
1302 display_cacheinfo(c
);
1309 * On SMP, boot_cpu_data holds the common feature set between
1310 * all CPUs; so make sure that we indicate which features are
1311 * common between the CPUs. The first time this routine gets
1312 * executed, c == &boot_cpu_data.
1314 if (c
!= &boot_cpu_data
) {
1315 /* AND the already accumulated flags with these */
1316 for (i
= 0; i
< NCAPINTS
; i
++)
1317 boot_cpu_data
.x86_capability
[i
] &= c
->x86_capability
[i
];
1320 /* Clear all flags overriden by options */
1321 for (i
= 0; i
< NCAPINTS
; i
++)
1322 c
->x86_capability
[i
] &= ~cleared_cpu_caps
[i
];
1324 #ifdef CONFIG_X86_MCE
1327 select_idle_routine(c
);
1330 numa_add_cpu(smp_processor_id());
1335 void __cpuinit
identify_boot_cpu(void)
1337 identify_cpu(&boot_cpu_data
);
1340 void __cpuinit
identify_secondary_cpu(struct cpuinfo_x86
*c
)
1342 BUG_ON(c
== &boot_cpu_data
);
1347 static __init
int setup_noclflush(char *arg
)
1349 setup_clear_cpu_cap(X86_FEATURE_CLFLSH
);
1352 __setup("noclflush", setup_noclflush
);
1354 void __cpuinit
print_cpu_info(struct cpuinfo_x86
*c
)
1356 if (c
->x86_model_id
[0])
1357 printk(KERN_CONT
"%s", c
->x86_model_id
);
1359 if (c
->x86_mask
|| c
->cpuid_level
>= 0)
1360 printk(KERN_CONT
" stepping %02x\n", c
->x86_mask
);
1362 printk(KERN_CONT
"\n");
1365 static __init
int setup_disablecpuid(char *arg
)
1368 if (get_option(&arg
, &bit
) && bit
< NCAPINTS
*32)
1369 setup_clear_cpu_cap(bit
);
1374 __setup("clearcpuid=", setup_disablecpuid
);