Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/init.h> |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 2 | #include <linux/kernel.h> |
| 3 | #include <linux/sched.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 4 | #include <linux/string.h> |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 5 | #include <linux/bootmem.h> |
| 6 | #include <linux/bitops.h> |
| 7 | #include <linux/module.h> |
| 8 | #include <linux/kgdb.h> |
| 9 | #include <linux/topology.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 10 | #include <linux/delay.h> |
| 11 | #include <linux/smp.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 12 | #include <linux/percpu.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #include <asm/i387.h> |
| 14 | #include <asm/msr.h> |
| 15 | #include <asm/io.h> |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 16 | #include <asm/linkage.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 17 | #include <asm/mmu_context.h> |
Alexey Dobriyan | 27b07da | 2006-06-23 02:04:18 -0700 | [diff] [blame] | 18 | #include <asm/mtrr.h> |
Alexey Dobriyan | a03a3e2 | 2006-06-23 02:04:20 -0700 | [diff] [blame] | 19 | #include <asm/mce.h> |
Thomas Gleixner | 8d4a430 | 2008-05-08 09:18:43 +0200 | [diff] [blame] | 20 | #include <asm/pat.h> |
H. Peter Anvin | 7e00df5 | 2008-08-18 17:39:32 -0700 | [diff] [blame] | 21 | #include <asm/asm.h> |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 22 | #include <asm/numa.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | #ifdef CONFIG_X86_LOCAL_APIC |
| 24 | #include <asm/mpspec.h> |
| 25 | #include <asm/apic.h> |
| 26 | #include <mach_apic.h> |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 27 | #include <asm/genapic.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 28 | #endif |
| 29 | |
Yinghai Lu | f0fc4af | 2008-09-04 20:09:00 -0700 | [diff] [blame^] | 30 | #include <asm/pda.h> |
| 31 | #include <asm/pgtable.h> |
| 32 | #include <asm/processor.h> |
| 33 | #include <asm/desc.h> |
| 34 | #include <asm/atomic.h> |
| 35 | #include <asm/proto.h> |
| 36 | #include <asm/sections.h> |
| 37 | #include <asm/setup.h> |
| 38 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 39 | #include "cpu.h" |
| 40 | |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 41 | static struct cpu_dev *this_cpu __cpuinitdata; |
| 42 | |
Eric Dumazet | 63cc8c7 | 2008-05-12 15:44:40 +0200 | [diff] [blame] | 43 | DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = { |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 44 | [GDT_ENTRY_KERNEL_CS] = { { { 0x0000ffff, 0x00cf9a00 } } }, |
| 45 | [GDT_ENTRY_KERNEL_DS] = { { { 0x0000ffff, 0x00cf9200 } } }, |
| 46 | [GDT_ENTRY_DEFAULT_USER_CS] = { { { 0x0000ffff, 0x00cffa00 } } }, |
| 47 | [GDT_ENTRY_DEFAULT_USER_DS] = { { { 0x0000ffff, 0x00cff200 } } }, |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 48 | /* |
| 49 | * Segments used for calling PnP BIOS have byte granularity. |
| 50 | * They code segments and data segments have fixed 64k limits, |
| 51 | * the transfer segment sizes are set at run time. |
| 52 | */ |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 53 | /* 32-bit code */ |
| 54 | [GDT_ENTRY_PNPBIOS_CS32] = { { { 0x0000ffff, 0x00409a00 } } }, |
| 55 | /* 16-bit code */ |
| 56 | [GDT_ENTRY_PNPBIOS_CS16] = { { { 0x0000ffff, 0x00009a00 } } }, |
| 57 | /* 16-bit data */ |
| 58 | [GDT_ENTRY_PNPBIOS_DS] = { { { 0x0000ffff, 0x00009200 } } }, |
| 59 | /* 16-bit data */ |
| 60 | [GDT_ENTRY_PNPBIOS_TS1] = { { { 0x00000000, 0x00009200 } } }, |
| 61 | /* 16-bit data */ |
| 62 | [GDT_ENTRY_PNPBIOS_TS2] = { { { 0x00000000, 0x00009200 } } }, |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 63 | /* |
| 64 | * The APM segments have byte granularity and their bases |
| 65 | * are set at run time. All have 64k limits. |
| 66 | */ |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 67 | /* 32-bit code */ |
| 68 | [GDT_ENTRY_APMBIOS_BASE] = { { { 0x0000ffff, 0x00409a00 } } }, |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 69 | /* 16-bit code */ |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 70 | [GDT_ENTRY_APMBIOS_BASE+1] = { { { 0x0000ffff, 0x00009a00 } } }, |
| 71 | /* data */ |
| 72 | [GDT_ENTRY_APMBIOS_BASE+2] = { { { 0x0000ffff, 0x00409200 } } }, |
Rusty Russell | bf504672 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 73 | |
Glauber de Oliveira Costa | 6842ef0 | 2008-01-30 13:31:11 +0100 | [diff] [blame] | 74 | [GDT_ENTRY_ESPFIX_SS] = { { { 0x00000000, 0x00c09200 } } }, |
| 75 | [GDT_ENTRY_PERCPU] = { { { 0x00000000, 0x00000000 } } }, |
Jeremy Fitzhardinge | 7a61d35 | 2007-05-02 19:27:15 +0200 | [diff] [blame] | 76 | } }; |
| 77 | EXPORT_PER_CPU_SYMBOL_GPL(gdt_page); |
Rusty Russell | ae1ee11 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 78 | |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 79 | static int cachesize_override __cpuinitdata = -1; |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 80 | static int disable_x86_serial_nr __cpuinitdata = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | static int __init cachesize_setup(char *str) |
| 83 | { |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 84 | get_option(&str, &cachesize_override); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | return 1; |
| 86 | } |
| 87 | __setup("cachesize=", cachesize_setup); |
| 88 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 89 | /* |
| 90 | * Naming convention should be: <Name> [(<Codename>)] |
| 91 | * This table only is used unless init_<vendor>() below doesn't set it; |
| 92 | * in particular, if CPUID levels 0x80000002..4 are supported, this isn't used |
| 93 | * |
| 94 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | |
| 96 | /* Look up CPU names by table lookup. */ |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 97 | static char __cpuinit *table_lookup_model(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | struct cpu_model_info *info; |
| 100 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 101 | if (c->x86_model >= 16) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 102 | return NULL; /* Range check */ |
| 103 | |
| 104 | if (!this_cpu) |
| 105 | return NULL; |
| 106 | |
| 107 | info = this_cpu->c_models; |
| 108 | |
| 109 | while (info && info->family) { |
| 110 | if (info->family == c->x86) |
| 111 | return info->model_names[c->x86_model]; |
| 112 | info++; |
| 113 | } |
| 114 | return NULL; /* Not found */ |
| 115 | } |
| 116 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 117 | static int __init x86_fxsr_setup(char *s) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | { |
Andi Kleen | 1353025 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 119 | setup_clear_cpu_cap(X86_FEATURE_FXSR); |
| 120 | setup_clear_cpu_cap(X86_FEATURE_XMM); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | return 1; |
| 122 | } |
| 123 | __setup("nofxsr", x86_fxsr_setup); |
| 124 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 125 | static int __init x86_sep_setup(char *s) |
Chuck Ebbert | 4f88651 | 2006-03-23 02:59:34 -0800 | [diff] [blame] | 126 | { |
Andi Kleen | 1353025 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 127 | setup_clear_cpu_cap(X86_FEATURE_SEP); |
Chuck Ebbert | 4f88651 | 2006-03-23 02:59:34 -0800 | [diff] [blame] | 128 | return 1; |
| 129 | } |
| 130 | __setup("nosep", x86_sep_setup); |
| 131 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 132 | /* Standard macro to see if a specific flag is changeable */ |
| 133 | static inline int flag_is_changeable_p(u32 flag) |
| 134 | { |
| 135 | u32 f1, f2; |
| 136 | |
| 137 | asm("pushfl\n\t" |
| 138 | "pushfl\n\t" |
| 139 | "popl %0\n\t" |
| 140 | "movl %0,%1\n\t" |
| 141 | "xorl %2,%0\n\t" |
| 142 | "pushl %0\n\t" |
| 143 | "popfl\n\t" |
| 144 | "pushfl\n\t" |
| 145 | "popl %0\n\t" |
| 146 | "popfl\n\t" |
| 147 | : "=&r" (f1), "=&r" (f2) |
| 148 | : "ir" (flag)); |
| 149 | |
| 150 | return ((f1^f2) & flag) != 0; |
| 151 | } |
| 152 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | /* Probe for the CPUID instruction */ |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 154 | static int __cpuinit have_cpuid_p(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 155 | { |
| 156 | return flag_is_changeable_p(X86_EFLAGS_ID); |
| 157 | } |
| 158 | |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 159 | static void __cpuinit squash_the_stupid_serial_number(struct cpuinfo_x86 *c) |
| 160 | { |
| 161 | if (cpu_has(c, X86_FEATURE_PN) && disable_x86_serial_nr) { |
| 162 | /* Disable processor serial number */ |
| 163 | unsigned long lo, hi; |
| 164 | rdmsr(MSR_IA32_BBL_CR_CTL, lo, hi); |
| 165 | lo |= 0x200000; |
| 166 | wrmsr(MSR_IA32_BBL_CR_CTL, lo, hi); |
| 167 | printk(KERN_NOTICE "CPU serial number disabled.\n"); |
| 168 | clear_cpu_cap(c, X86_FEATURE_PN); |
| 169 | |
| 170 | /* Disabling the serial number may affect the cpuid level */ |
| 171 | c->cpuid_level = cpuid_eax(0); |
| 172 | } |
| 173 | } |
| 174 | |
| 175 | static int __init x86_serial_nr_setup(char *s) |
| 176 | { |
| 177 | disable_x86_serial_nr = 0; |
| 178 | return 1; |
| 179 | } |
| 180 | __setup("serialnumber", x86_serial_nr_setup); |
| 181 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 182 | __u32 cleared_cpu_caps[NCAPINTS] __cpuinitdata; |
| 183 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 184 | /* Current gdt points %fs at the "master" per-cpu area: after this, |
| 185 | * it's on the real one. */ |
| 186 | void switch_to_new_gdt(void) |
| 187 | { |
| 188 | struct desc_ptr gdt_descr; |
| 189 | |
| 190 | gdt_descr.address = (long)get_cpu_gdt_table(smp_processor_id()); |
| 191 | gdt_descr.size = GDT_SIZE - 1; |
| 192 | load_gdt(&gdt_descr); |
| 193 | asm("mov %0, %%fs" : : "r" (__KERNEL_PERCPU) : "memory"); |
| 194 | } |
| 195 | |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 196 | static struct cpu_dev *cpu_devs[X86_VENDOR_NUM] = {}; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 197 | |
| 198 | static void __cpuinit default_init(struct cpuinfo_x86 *c) |
| 199 | { |
| 200 | /* Not much we can do here... */ |
| 201 | /* Check if at least it has cpuid */ |
| 202 | if (c->cpuid_level == -1) { |
| 203 | /* No cpuid. It must be an ancient CPU */ |
| 204 | if (c->x86 == 4) |
| 205 | strcpy(c->x86_model_id, "486"); |
| 206 | else if (c->x86 == 3) |
| 207 | strcpy(c->x86_model_id, "386"); |
| 208 | } |
| 209 | } |
| 210 | |
| 211 | static struct cpu_dev __cpuinitdata default_cpu = { |
| 212 | .c_init = default_init, |
| 213 | .c_vendor = "Unknown", |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 214 | .c_x86_vendor = X86_VENDOR_UNKNOWN, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | }; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | |
| 217 | int __cpuinit get_model_name(struct cpuinfo_x86 *c) |
| 218 | { |
| 219 | unsigned int *v; |
| 220 | char *p, *q; |
| 221 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 222 | if (c->extended_cpuid_level < 0x80000004) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 223 | return 0; |
| 224 | |
| 225 | v = (unsigned int *) c->x86_model_id; |
| 226 | cpuid(0x80000002, &v[0], &v[1], &v[2], &v[3]); |
| 227 | cpuid(0x80000003, &v[4], &v[5], &v[6], &v[7]); |
| 228 | cpuid(0x80000004, &v[8], &v[9], &v[10], &v[11]); |
| 229 | c->x86_model_id[48] = 0; |
| 230 | |
| 231 | /* Intel chips right-justify this string for some dumb reason; |
| 232 | undo that brain damage */ |
| 233 | p = q = &c->x86_model_id[0]; |
| 234 | while (*p == ' ') |
| 235 | p++; |
| 236 | if (p != q) { |
| 237 | while (*p) |
| 238 | *q++ = *p++; |
| 239 | while (q <= &c->x86_model_id[48]) |
| 240 | *q++ = '\0'; /* Zero-pad the rest */ |
| 241 | } |
| 242 | |
| 243 | return 1; |
| 244 | } |
| 245 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | void __cpuinit display_cacheinfo(struct cpuinfo_x86 *c) |
| 247 | { |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 248 | unsigned int n, dummy, ebx, ecx, edx, l2size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 250 | n = c->extended_cpuid_level; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 251 | |
| 252 | if (n >= 0x80000005) { |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 253 | cpuid(0x80000005, &dummy, &ebx, &ecx, &edx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 254 | printk(KERN_INFO "CPU: L1 I Cache: %dK (%d bytes/line), D cache %dK (%d bytes/line)\n", |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 255 | edx>>24, edx&0xFF, ecx>>24, ecx&0xFF); |
| 256 | c->x86_cache_size = (ecx>>24) + (edx>>24); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | } |
| 258 | |
| 259 | if (n < 0x80000006) /* Some chips just has a large L1. */ |
| 260 | return; |
| 261 | |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 262 | cpuid(0x80000006, &dummy, &ebx, &ecx, &edx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | l2size = ecx >> 16; |
| 264 | |
| 265 | /* do processor-specific cache resizing */ |
| 266 | if (this_cpu->c_size_cache) |
| 267 | l2size = this_cpu->c_size_cache(c, l2size); |
| 268 | |
| 269 | /* Allow user to override all this if necessary. */ |
| 270 | if (cachesize_override != -1) |
| 271 | l2size = cachesize_override; |
| 272 | |
| 273 | if (l2size == 0) |
| 274 | return; /* Again, no L2 cache is possible */ |
| 275 | |
| 276 | c->x86_cache_size = l2size; |
| 277 | |
| 278 | printk(KERN_INFO "CPU: L2 Cache: %dK (%d bytes/line)\n", |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 279 | l2size, ecx & 0xFF); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 280 | } |
| 281 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 282 | void __cpuinit detect_ht(struct cpuinfo_x86 *c) |
| 283 | { |
Yinghai Lu | 97e4db7 | 2008-09-04 20:08:59 -0700 | [diff] [blame] | 284 | #ifdef CONFIG_X86_HT |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 285 | u32 eax, ebx, ecx, edx; |
| 286 | int index_msb, core_bits; |
| 287 | |
| 288 | if (!cpu_has(c, X86_FEATURE_HT)) |
| 289 | return; |
| 290 | |
| 291 | if (cpu_has(c, X86_FEATURE_CMP_LEGACY)) |
| 292 | goto out; |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 293 | |
| 294 | cpuid(1, &eax, &ebx, &ecx, &edx); |
| 295 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 296 | smp_num_siblings = (ebx & 0xff0000) >> 16; |
| 297 | |
| 298 | if (smp_num_siblings == 1) { |
| 299 | printk(KERN_INFO "CPU: Hyper-Threading is disabled\n"); |
| 300 | } else if (smp_num_siblings > 1) { |
| 301 | |
| 302 | if (smp_num_siblings > NR_CPUS) { |
| 303 | printk(KERN_WARNING "CPU: Unsupported number of siblings %d", |
| 304 | smp_num_siblings); |
| 305 | smp_num_siblings = 1; |
| 306 | return; |
| 307 | } |
| 308 | |
| 309 | index_msb = get_count_order(smp_num_siblings); |
| 310 | c->phys_proc_id = phys_pkg_id(c->initial_apicid, index_msb); |
| 311 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 312 | |
| 313 | smp_num_siblings = smp_num_siblings / c->x86_max_cores; |
| 314 | |
| 315 | index_msb = get_count_order(smp_num_siblings); |
| 316 | |
| 317 | core_bits = get_count_order(c->x86_max_cores); |
| 318 | |
| 319 | c->cpu_core_id = phys_pkg_id(c->initial_apicid, index_msb) & |
| 320 | ((1 << core_bits) - 1); |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 321 | } |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 322 | |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 323 | out: |
| 324 | if ((c->x86_max_cores * smp_num_siblings) > 1) { |
| 325 | printk(KERN_INFO "CPU: Physical Processor ID: %d\n", |
| 326 | c->phys_proc_id); |
| 327 | printk(KERN_INFO "CPU: Processor Core ID: %d\n", |
| 328 | c->cpu_core_id); |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 329 | } |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 330 | #endif |
Yinghai Lu | 97e4db7 | 2008-09-04 20:08:59 -0700 | [diff] [blame] | 331 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 333 | static void __cpuinit get_cpu_vendor(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | { |
| 335 | char *v = c->x86_vendor_id; |
| 336 | int i; |
| 337 | static int printed; |
| 338 | |
| 339 | for (i = 0; i < X86_VENDOR_NUM; i++) { |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 340 | if (!cpu_devs[i]) |
| 341 | break; |
| 342 | |
| 343 | if (!strcmp(v, cpu_devs[i]->c_ident[0]) || |
| 344 | (cpu_devs[i]->c_ident[1] && |
| 345 | !strcmp(v, cpu_devs[i]->c_ident[1]))) { |
| 346 | this_cpu = cpu_devs[i]; |
| 347 | c->x86_vendor = this_cpu->c_x86_vendor; |
| 348 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 349 | } |
| 350 | } |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 351 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | if (!printed) { |
| 353 | printed++; |
| 354 | printk(KERN_ERR "CPU: Vendor unknown, using generic init.\n"); |
| 355 | printk(KERN_ERR "CPU: Your system may be unstable.\n"); |
| 356 | } |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | c->x86_vendor = X86_VENDOR_UNKNOWN; |
| 359 | this_cpu = &default_cpu; |
| 360 | } |
| 361 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 362 | void __cpuinit cpu_detect(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | /* Get vendor name */ |
Harvey Harrison | 4a14851 | 2008-02-01 17:49:43 +0100 | [diff] [blame] | 365 | cpuid(0x00000000, (unsigned int *)&c->cpuid_level, |
| 366 | (unsigned int *)&c->x86_vendor_id[0], |
| 367 | (unsigned int *)&c->x86_vendor_id[8], |
| 368 | (unsigned int *)&c->x86_vendor_id[4]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 369 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | c->x86 = 4; |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 371 | /* Intel-defined flags: level 0x00000001 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 372 | if (c->cpuid_level >= 0x00000001) { |
| 373 | u32 junk, tfms, cap0, misc; |
| 374 | cpuid(0x00000001, &tfms, &misc, &junk, &cap0); |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 375 | c->x86 = (tfms >> 8) & 0xf; |
| 376 | c->x86_model = (tfms >> 4) & 0xf; |
| 377 | c->x86_mask = tfms & 0xf; |
Suresh Siddha | f5f786d | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 378 | if (c->x86 == 0xf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 379 | c->x86 += (tfms >> 20) & 0xff; |
Suresh Siddha | f5f786d | 2005-11-05 17:25:53 +0100 | [diff] [blame] | 380 | if (c->x86 >= 0x6) |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 381 | c->x86_model += ((tfms >> 16) & 0xf) << 4; |
Huang, Ying | d4387bd | 2008-01-31 22:05:45 +0100 | [diff] [blame] | 382 | if (cap0 & (1<<19)) { |
Huang, Ying | d4387bd | 2008-01-31 22:05:45 +0100 | [diff] [blame] | 383 | c->x86_clflush_size = ((misc >> 8) & 0xff) * 8; |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 384 | c->x86_cache_alignment = c->x86_clflush_size; |
Huang, Ying | d4387bd | 2008-01-31 22:05:45 +0100 | [diff] [blame] | 385 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 386 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 387 | } |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 388 | |
| 389 | static void __cpuinit get_cpu_cap(struct cpuinfo_x86 *c) |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 390 | { |
| 391 | u32 tfms, xlvl; |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 392 | u32 ebx; |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 393 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 394 | /* Intel-defined flags: level 0x00000001 */ |
| 395 | if (c->cpuid_level >= 0x00000001) { |
| 396 | u32 capability, excap; |
| 397 | cpuid(0x00000001, &tfms, &ebx, &excap, &capability); |
| 398 | c->x86_capability[0] = capability; |
| 399 | c->x86_capability[4] = excap; |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 400 | } |
| 401 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 402 | /* AMD-defined flags: level 0x80000001 */ |
| 403 | xlvl = cpuid_eax(0x80000000); |
| 404 | c->extended_cpuid_level = xlvl; |
| 405 | if ((xlvl & 0xffff0000) == 0x80000000) { |
| 406 | if (xlvl >= 0x80000001) { |
| 407 | c->x86_capability[1] = cpuid_edx(0x80000001); |
| 408 | c->x86_capability[6] = cpuid_ecx(0x80000001); |
| 409 | } |
| 410 | } |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 411 | } |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 412 | /* |
| 413 | * Do minimum CPU detection early. |
| 414 | * Fields really needed: vendor, cpuid_level, family, model, mask, |
| 415 | * cache alignment. |
| 416 | * The others are not touched to avoid unwanted side effects. |
| 417 | * |
| 418 | * WARNING: this function is only called on the BP. Don't add code here |
| 419 | * that is supposed to run on all CPUs. |
| 420 | */ |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 421 | static void __init early_identify_cpu(struct cpuinfo_x86 *c) |
Rusty Russell | d7cd561 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 422 | { |
Huang, Ying | d4387bd | 2008-01-31 22:05:45 +0100 | [diff] [blame] | 423 | c->x86_clflush_size = 32; |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 424 | c->x86_cache_alignment = c->x86_clflush_size; |
Rusty Russell | d7cd561 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 425 | |
| 426 | if (!have_cpuid_p()) |
| 427 | return; |
| 428 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 429 | memset(&c->x86_capability, 0, sizeof c->x86_capability); |
| 430 | |
Yinghai Lu | 0a488a5 | 2008-09-04 21:09:47 +0200 | [diff] [blame] | 431 | c->extended_cpuid_level = 0; |
| 432 | |
Rusty Russell | d7cd561 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 433 | cpu_detect(c); |
| 434 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 435 | get_cpu_vendor(c); |
Andi Kleen | 2b16a23 | 2008-01-30 13:32:40 +0100 | [diff] [blame] | 436 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 437 | get_cpu_cap(c); |
Yinghai Lu | 093af8d | 2008-01-30 13:33:32 +0100 | [diff] [blame] | 438 | |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 439 | if (this_cpu->c_early_init) |
| 440 | this_cpu->c_early_init(c); |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 441 | |
| 442 | validate_pat_support(c); |
Rusty Russell | d7cd561 | 2006-12-07 02:14:08 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 445 | void __init early_cpu_init(void) |
| 446 | { |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 447 | struct cpu_dev **cdev; |
| 448 | int count = 0; |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 449 | |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 450 | printk("KERNEL supported cpus:\n"); |
| 451 | for (cdev = __x86_cpu_dev_start; cdev < __x86_cpu_dev_end; cdev++) { |
| 452 | struct cpu_dev *cpudev = *cdev; |
| 453 | unsigned int j; |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 454 | |
Yinghai Lu | 10a434f | 2008-09-04 21:09:45 +0200 | [diff] [blame] | 455 | if (count >= X86_VENDOR_NUM) |
| 456 | break; |
| 457 | cpu_devs[count] = cpudev; |
| 458 | count++; |
| 459 | |
| 460 | for (j = 0; j < 2; j++) { |
| 461 | if (!cpudev->c_ident[j]) |
| 462 | continue; |
| 463 | printk(" %s %s\n", cpudev->c_vendor, |
| 464 | cpudev->c_ident[j]); |
| 465 | } |
| 466 | } |
| 467 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 468 | early_identify_cpu(&boot_cpu_data); |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 469 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 470 | |
H. Peter Anvin | 7e00df5 | 2008-08-18 17:39:32 -0700 | [diff] [blame] | 471 | /* |
| 472 | * The NOPL instruction is supposed to exist on all CPUs with |
| 473 | * family >= 6, unfortunately, that's not true in practice because |
| 474 | * of early VIA chips and (more importantly) broken virtualizers that |
| 475 | * are not easy to detect. Hence, probe for it based on first |
| 476 | * principles. |
| 477 | */ |
| 478 | static void __cpuinit detect_nopl(struct cpuinfo_x86 *c) |
| 479 | { |
| 480 | const u32 nopl_signature = 0x888c53b1; /* Random number */ |
| 481 | u32 has_nopl = nopl_signature; |
| 482 | |
| 483 | clear_cpu_cap(c, X86_FEATURE_NOPL); |
| 484 | if (c->x86 >= 6) { |
| 485 | asm volatile("\n" |
| 486 | "1: .byte 0x0f,0x1f,0xc0\n" /* nopl %eax */ |
| 487 | "2:\n" |
| 488 | " .section .fixup,\"ax\"\n" |
| 489 | "3: xor %0,%0\n" |
| 490 | " jmp 2b\n" |
| 491 | " .previous\n" |
| 492 | _ASM_EXTABLE(1b,3b) |
| 493 | : "+a" (has_nopl)); |
| 494 | |
| 495 | if (has_nopl == nopl_signature) |
| 496 | set_cpu_cap(c, X86_FEATURE_NOPL); |
| 497 | } |
| 498 | } |
| 499 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 500 | static void __cpuinit generic_identify(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 501 | { |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 502 | if (!have_cpuid_p()) |
| 503 | return; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 504 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 505 | c->extended_cpuid_level = 0; |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 506 | |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 507 | cpu_detect(c); |
| 508 | |
| 509 | get_cpu_vendor(c); |
| 510 | |
| 511 | get_cpu_cap(c); |
| 512 | |
| 513 | if (c->cpuid_level >= 0x00000001) { |
| 514 | c->initial_apicid = (cpuid_ebx(1) >> 24) & 0xFF; |
James Bottomley | 96c5274 | 2006-06-27 02:53:49 -0700 | [diff] [blame] | 515 | #ifdef CONFIG_X86_HT |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 516 | c->apicid = phys_pkg_id(c->initial_apicid, 0); |
| 517 | c->phys_proc_id = c->initial_apicid; |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 518 | #else |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 519 | c->apicid = c->initial_apicid; |
Siddha, Suresh B | 1e9f28f | 2006-03-27 01:15:22 -0800 | [diff] [blame] | 520 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 521 | } |
Yinghai Lu | 3da99c9 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 522 | |
| 523 | if (c->extended_cpuid_level >= 0x80000004) |
| 524 | get_model_name(c); /* Default name */ |
| 525 | |
| 526 | init_scattered_cpuid_features(c); |
| 527 | detect_nopl(c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 528 | } |
| 529 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 530 | /* |
| 531 | * This does the hard work of actually picking apart the CPU stuff... |
| 532 | */ |
Yinghai Lu | 9a25034 | 2008-06-21 03:24:00 -0700 | [diff] [blame] | 533 | static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | { |
| 535 | int i; |
| 536 | |
| 537 | c->loops_per_jiffy = loops_per_jiffy; |
| 538 | c->x86_cache_size = -1; |
| 539 | c->x86_vendor = X86_VENDOR_UNKNOWN; |
| 540 | c->cpuid_level = -1; /* CPUID not detected */ |
| 541 | c->x86_model = c->x86_mask = 0; /* So far unknown... */ |
| 542 | c->x86_vendor_id[0] = '\0'; /* Unset */ |
| 543 | c->x86_model_id[0] = '\0'; /* Unset */ |
Siddha, Suresh B | 94605ef | 2005-11-05 17:25:54 +0100 | [diff] [blame] | 544 | c->x86_max_cores = 1; |
Andi Kleen | 770d132 | 2006-12-07 02:14:05 +0100 | [diff] [blame] | 545 | c->x86_clflush_size = 32; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 546 | memset(&c->x86_capability, 0, sizeof c->x86_capability); |
| 547 | |
| 548 | if (!have_cpuid_p()) { |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 549 | /* |
| 550 | * First of all, decide if this is a 486 or higher |
| 551 | * It's a 486 if we can modify the AC flag |
| 552 | */ |
| 553 | if (flag_is_changeable_p(X86_EFLAGS_AC)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 554 | c->x86 = 4; |
| 555 | else |
| 556 | c->x86 = 3; |
| 557 | } |
| 558 | |
| 559 | generic_identify(c); |
| 560 | |
Andi Kleen | 3898534 | 2008-01-30 13:32:49 +0100 | [diff] [blame] | 561 | if (this_cpu->c_identify) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | this_cpu->c_identify(c); |
| 563 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 564 | /* |
| 565 | * Vendor-specific initialization. In this section we |
| 566 | * canonicalize the feature flags, meaning if there are |
| 567 | * features a certain CPU supports which CPUID doesn't |
| 568 | * tell us, CPUID claiming incorrect flags, or other bugs, |
| 569 | * we handle them here. |
| 570 | * |
| 571 | * At the end of this section, c->x86_capability better |
| 572 | * indicate the features this CPU genuinely supports! |
| 573 | */ |
| 574 | if (this_cpu->c_init) |
| 575 | this_cpu->c_init(c); |
| 576 | |
| 577 | /* Disable the PN if appropriate */ |
| 578 | squash_the_stupid_serial_number(c); |
| 579 | |
| 580 | /* |
| 581 | * The vendor-specific functions might have changed features. Now |
| 582 | * we do "generic changes." |
| 583 | */ |
| 584 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 585 | /* If the model name is still unset, do table lookup. */ |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 586 | if (!c->x86_model_id[0]) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 587 | char *p; |
| 588 | p = table_lookup_model(c); |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 589 | if (p) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | strcpy(c->x86_model_id, p); |
| 591 | else |
| 592 | /* Last resort... */ |
| 593 | sprintf(c->x86_model_id, "%02x/%02x", |
Chuck Ebbert | 54a20f8 | 2006-03-23 02:59:36 -0800 | [diff] [blame] | 594 | c->x86, c->x86_model); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 595 | } |
| 596 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 597 | /* |
| 598 | * On SMP, boot_cpu_data holds the common feature set between |
| 599 | * all CPUs; so make sure that we indicate which features are |
| 600 | * common between the CPUs. The first time this routine gets |
| 601 | * executed, c == &boot_cpu_data. |
| 602 | */ |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 603 | if (c != &boot_cpu_data) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 604 | /* AND the already accumulated flags with these */ |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 605 | for (i = 0; i < NCAPINTS; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | boot_cpu_data.x86_capability[i] &= c->x86_capability[i]; |
| 607 | } |
| 608 | |
Andi Kleen | 7d851c8 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 609 | /* Clear all flags overriden by options */ |
| 610 | for (i = 0; i < NCAPINTS; i++) |
Mikael Pettersson | 12c247a | 2008-02-24 18:27:03 +0100 | [diff] [blame] | 611 | c->x86_capability[i] &= ~cleared_cpu_caps[i]; |
Andi Kleen | 7d851c8 | 2008-01-30 13:33:20 +0100 | [diff] [blame] | 612 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | /* Init Machine Check Exception if available. */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | mcheck_init(c); |
Andi Kleen | 30d432d | 2008-01-30 13:33:16 +0100 | [diff] [blame] | 615 | |
| 616 | select_idle_routine(c); |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 617 | } |
Shaohua Li | 31ab269 | 2005-11-07 00:58:42 -0800 | [diff] [blame] | 618 | |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 619 | void __init identify_boot_cpu(void) |
| 620 | { |
| 621 | identify_cpu(&boot_cpu_data); |
| 622 | sysenter_setup(); |
Li Shaohua | 6fe940d | 2005-06-25 14:54:53 -0700 | [diff] [blame] | 623 | enable_sep_cpu(); |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 624 | } |
Shaohua Li | 3b520b2 | 2005-07-07 17:56:38 -0700 | [diff] [blame] | 625 | |
Jeremy Fitzhardinge | a6c4e07 | 2007-05-02 19:27:12 +0200 | [diff] [blame] | 626 | void __cpuinit identify_secondary_cpu(struct cpuinfo_x86 *c) |
| 627 | { |
| 628 | BUG_ON(c == &boot_cpu_data); |
| 629 | identify_cpu(c); |
| 630 | enable_sep_cpu(); |
| 631 | mtrr_ap_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 632 | } |
| 633 | |
Yinghai Lu | a0854a4 | 2008-09-04 21:09:46 +0200 | [diff] [blame] | 634 | struct msr_range { |
| 635 | unsigned min; |
| 636 | unsigned max; |
| 637 | }; |
| 638 | |
| 639 | static struct msr_range msr_range_array[] __cpuinitdata = { |
| 640 | { 0x00000000, 0x00000418}, |
| 641 | { 0xc0000000, 0xc000040b}, |
| 642 | { 0xc0010000, 0xc0010142}, |
| 643 | { 0xc0011000, 0xc001103b}, |
| 644 | }; |
| 645 | |
| 646 | static void __cpuinit print_cpu_msr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 647 | { |
Yinghai Lu | a0854a4 | 2008-09-04 21:09:46 +0200 | [diff] [blame] | 648 | unsigned index; |
| 649 | u64 val; |
| 650 | int i; |
| 651 | unsigned index_min, index_max; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 652 | |
Yinghai Lu | a0854a4 | 2008-09-04 21:09:46 +0200 | [diff] [blame] | 653 | for (i = 0; i < ARRAY_SIZE(msr_range_array); i++) { |
| 654 | index_min = msr_range_array[i].min; |
| 655 | index_max = msr_range_array[i].max; |
| 656 | for (index = index_min; index < index_max; index++) { |
| 657 | if (rdmsrl_amd_safe(index, &val)) |
| 658 | continue; |
| 659 | printk(KERN_INFO " MSR%08x: %016llx\n", index, val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 661 | } |
| 662 | } |
Yinghai Lu | a0854a4 | 2008-09-04 21:09:46 +0200 | [diff] [blame] | 663 | |
| 664 | static int show_msr __cpuinitdata; |
| 665 | static __init int setup_show_msr(char *arg) |
| 666 | { |
| 667 | int num; |
| 668 | |
| 669 | get_option(&arg, &num); |
| 670 | |
| 671 | if (num > 0) |
| 672 | show_msr = num; |
| 673 | return 1; |
| 674 | } |
| 675 | __setup("show_msr=", setup_show_msr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 676 | |
Andi Kleen | 191679f | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 677 | static __init int setup_noclflush(char *arg) |
| 678 | { |
| 679 | setup_clear_cpu_cap(X86_FEATURE_CLFLSH); |
| 680 | return 1; |
| 681 | } |
| 682 | __setup("noclflush", setup_noclflush); |
| 683 | |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 684 | void __cpuinit print_cpu_info(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 685 | { |
| 686 | char *vendor = NULL; |
| 687 | |
| 688 | if (c->x86_vendor < X86_VENDOR_NUM) |
| 689 | vendor = this_cpu->c_vendor; |
| 690 | else if (c->cpuid_level >= 0) |
| 691 | vendor = c->x86_vendor_id; |
| 692 | |
| 693 | if (vendor && strncmp(c->x86_model_id, vendor, strlen(vendor))) |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 694 | printk(KERN_CONT "%s ", vendor); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 695 | |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 696 | if (c->x86_model_id[0]) |
| 697 | printk(KERN_CONT "%s", c->x86_model_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 698 | else |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 699 | printk(KERN_CONT "%d86", c->x86); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 700 | |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 701 | if (c->x86_mask || c->cpuid_level >= 0) |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 702 | printk(KERN_CONT " stepping %02x\n", c->x86_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 703 | else |
Yinghai Lu | 9d31d35 | 2008-09-04 21:09:44 +0200 | [diff] [blame] | 704 | printk(KERN_CONT "\n"); |
Yinghai Lu | a0854a4 | 2008-09-04 21:09:46 +0200 | [diff] [blame] | 705 | |
| 706 | #ifdef CONFIG_SMP |
| 707 | if (c->cpu_index < show_msr) |
| 708 | print_cpu_msr(); |
| 709 | #else |
| 710 | if (show_msr) |
| 711 | print_cpu_msr(); |
| 712 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 713 | } |
| 714 | |
Andi Kleen | ac72e78 | 2008-01-30 13:33:21 +0100 | [diff] [blame] | 715 | static __init int setup_disablecpuid(char *arg) |
| 716 | { |
| 717 | int bit; |
| 718 | if (get_option(&arg, &bit) && bit < NCAPINTS*32) |
| 719 | setup_clear_cpu_cap(bit); |
| 720 | else |
| 721 | return 0; |
| 722 | return 1; |
| 723 | } |
| 724 | __setup("clearcpuid=", setup_disablecpuid); |
| 725 | |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 726 | cpumask_t cpu_initialized __cpuinitdata = CPU_MASK_NONE; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Jeremy Fitzhardinge | 7c3576d | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 728 | /* Make sure %fs is initialized properly in idle threads */ |
Adrian Bunk | 6b2fb3c | 2008-02-06 01:37:55 -0800 | [diff] [blame] | 729 | struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs) |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 730 | { |
| 731 | memset(regs, 0, sizeof(struct pt_regs)); |
H. Peter Anvin | 65ea5b0 | 2008-01-30 13:30:56 +0100 | [diff] [blame] | 732 | regs->fs = __KERNEL_PERCPU; |
Jeremy Fitzhardinge | f95d47c | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 733 | return regs; |
| 734 | } |
| 735 | |
Rusty Russell | d2cbcc4 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 736 | /* |
| 737 | * cpu_init() initializes state that is per-CPU. Some data is already |
| 738 | * initialized (naturally) in the bootstrap process, such as the GDT |
| 739 | * and IDT. We reload them nevertheless, this function acts as a |
| 740 | * 'CPU state barrier', nothing should get across. |
| 741 | */ |
| 742 | void __cpuinit cpu_init(void) |
James Bottomley | 9ee79a3 | 2007-01-22 09:18:31 -0600 | [diff] [blame] | 743 | { |
Rusty Russell | d2cbcc4 | 2007-05-02 19:27:10 +0200 | [diff] [blame] | 744 | int cpu = smp_processor_id(); |
| 745 | struct task_struct *curr = current; |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 746 | struct tss_struct *t = &per_cpu(init_tss, cpu); |
James Bottomley | 9ee79a3 | 2007-01-22 09:18:31 -0600 | [diff] [blame] | 747 | struct thread_struct *thread = &curr->thread; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | |
| 749 | if (cpu_test_and_set(cpu, cpu_initialized)) { |
| 750 | printk(KERN_WARNING "CPU#%d already initialized!\n", cpu); |
| 751 | for (;;) local_irq_enable(); |
| 752 | } |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 753 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | printk(KERN_INFO "Initializing CPU#%d\n", cpu); |
| 755 | |
| 756 | if (cpu_has_vme || cpu_has_tsc || cpu_has_de) |
| 757 | clear_in_cr4(X86_CR4_VME|X86_CR4_PVI|X86_CR4_TSD|X86_CR4_DE); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 758 | |
Zachary Amsden | 4d37e7e | 2005-09-03 15:56:38 -0700 | [diff] [blame] | 759 | load_idt(&idt_descr); |
Jeremy Fitzhardinge | c5413fb | 2007-05-02 19:27:16 +0200 | [diff] [blame] | 760 | switch_to_new_gdt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
| 762 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 763 | * Set up and load the per-CPU TSS and LDT |
| 764 | */ |
| 765 | atomic_inc(&init_mm.mm_count); |
Jeremy Fitzhardinge | 6211119 | 2006-12-07 02:14:02 +0100 | [diff] [blame] | 766 | curr->active_mm = &init_mm; |
| 767 | if (curr->mm) |
| 768 | BUG(); |
| 769 | enter_lazy_tlb(&init_mm, curr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
H. Peter Anvin | faca622 | 2008-01-30 13:31:02 +0100 | [diff] [blame] | 771 | load_sp0(t, thread); |
Paolo Ciarrocchi | 34048c9 | 2008-02-24 11:58:13 +0100 | [diff] [blame] | 772 | set_tss_desc(cpu, t); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 773 | load_TR_desc(); |
| 774 | load_LDT(&init_mm.context); |
| 775 | |
Matt Mackall | 22c4e30 | 2006-01-08 01:05:24 -0800 | [diff] [blame] | 776 | #ifdef CONFIG_DOUBLEFAULT |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | /* Set up doublefault TSS pointer in the GDT */ |
| 778 | __set_tss_desc(cpu, GDT_ENTRY_DOUBLEFAULT_TSS, &doublefault_tss); |
Matt Mackall | 22c4e30 | 2006-01-08 01:05:24 -0800 | [diff] [blame] | 779 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | |
Jeremy Fitzhardinge | 464d1a7 | 2007-02-13 13:26:20 +0100 | [diff] [blame] | 781 | /* Clear %gs. */ |
| 782 | asm volatile ("mov %0, %%gs" : : "r" (0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 783 | |
| 784 | /* Clear all 6 debug registers: */ |
Zachary Amsden | 4bb0d3e | 2005-09-03 15:56:36 -0700 | [diff] [blame] | 785 | set_debugreg(0, 0); |
| 786 | set_debugreg(0, 1); |
| 787 | set_debugreg(0, 2); |
| 788 | set_debugreg(0, 3); |
| 789 | set_debugreg(0, 6); |
| 790 | set_debugreg(0, 7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 791 | |
| 792 | /* |
| 793 | * Force FPU initialization: |
| 794 | */ |
Suresh Siddha | b359e8a | 2008-07-29 10:29:20 -0700 | [diff] [blame] | 795 | if (cpu_has_xsave) |
| 796 | current_thread_info()->status = TS_XSAVE; |
| 797 | else |
| 798 | current_thread_info()->status = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | clear_used_math(); |
| 800 | mxcsr_feature_mask_init(); |
Suresh Siddha | dc1e35c | 2008-07-29 10:29:19 -0700 | [diff] [blame] | 801 | |
| 802 | /* |
| 803 | * Boot processor to setup the FP and extended state context info. |
| 804 | */ |
| 805 | if (!smp_processor_id()) |
| 806 | init_thread_xstate(); |
| 807 | |
| 808 | xsave_init(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 809 | } |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 810 | |
| 811 | #ifdef CONFIG_HOTPLUG_CPU |
Chuck Ebbert | 3bc9b76 | 2006-03-23 02:59:33 -0800 | [diff] [blame] | 812 | void __cpuinit cpu_uninit(void) |
Li Shaohua | e1367da | 2005-06-25 14:54:56 -0700 | [diff] [blame] | 813 | { |
| 814 | int cpu = raw_smp_processor_id(); |
| 815 | cpu_clear(cpu, cpu_initialized); |
| 816 | |
| 817 | /* lazy TLB state */ |
| 818 | per_cpu(cpu_tlbstate, cpu).state = 0; |
| 819 | per_cpu(cpu_tlbstate, cpu).active_mm = &init_mm; |
| 820 | } |
| 821 | #endif |