Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | #include <linux/kernel.h> |
| 2 | #include <linux/init.h> |
| 3 | #include <linux/bitops.h> |
| 4 | #include <asm/processor.h> |
| 5 | #include <asm/msr.h> |
| 6 | #include <asm/e820.h> |
Jesper Juhl | 52f4a91 | 2006-03-23 02:59:50 -0800 | [diff] [blame] | 7 | #include <asm/mtrr.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 8 | #include "cpu.h" |
| 9 | |
| 10 | #ifdef CONFIG_X86_OOSTORE |
| 11 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 12 | static u32 __cpuinit power2(u32 x) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 14 | u32 s = 1; |
| 15 | while(s <= x) |
| 16 | s <<= 1; |
| 17 | return s >>= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 18 | } |
| 19 | |
| 20 | |
| 21 | /* |
| 22 | * Set up an actual MCR |
| 23 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 24 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 25 | static void __cpuinit centaur_mcr_insert(int reg, u32 base, u32 size, int key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | { |
| 27 | u32 lo, hi; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 28 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | hi = base & ~0xFFF; |
| 30 | lo = ~(size-1); /* Size is a power of 2 so this makes a mask */ |
| 31 | lo &= ~0xFFF; /* Remove the ctrl value bits */ |
| 32 | lo |= key; /* Attribute we wish to set */ |
| 33 | wrmsr(reg+MSR_IDT_MCR0, lo, hi); |
| 34 | mtrr_centaur_report_mcr(reg, lo, hi); /* Tell the mtrr driver */ |
| 35 | } |
| 36 | |
| 37 | /* |
| 38 | * Figure what we can cover with MCR's |
| 39 | * |
| 40 | * Shortcut: We know you can't put 4Gig of RAM on a winchip |
| 41 | */ |
| 42 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 43 | static u32 __cpuinit ramtop(void) /* 16388 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 44 | { |
| 45 | int i; |
| 46 | u32 top = 0; |
| 47 | u32 clip = 0xFFFFFFFFUL; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 48 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 49 | for (i = 0; i < e820.nr_map; i++) { |
| 50 | unsigned long start, end; |
| 51 | |
| 52 | if (e820.map[i].addr > 0xFFFFFFFFUL) |
| 53 | continue; |
| 54 | /* |
| 55 | * Don't MCR over reserved space. Ignore the ISA hole |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 56 | * we frob around that catastrophe already |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 57 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 58 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 59 | if (e820.map[i].type == E820_RESERVED) |
| 60 | { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 61 | if (e820.map[i].addr >= 0x100000UL && e820.map[i].addr < clip) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | clip = e820.map[i].addr; |
| 63 | continue; |
| 64 | } |
| 65 | start = e820.map[i].addr; |
| 66 | end = e820.map[i].addr + e820.map[i].size; |
| 67 | if (start >= end) |
| 68 | continue; |
| 69 | if (end > top) |
| 70 | top = end; |
| 71 | } |
| 72 | /* Everything below 'top' should be RAM except for the ISA hole. |
| 73 | Because of the limited MCR's we want to map NV/ACPI into our |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 74 | MCR range for gunk in RAM |
| 75 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 76 | Clip might cause us to MCR insufficient RAM but that is an |
| 77 | acceptable failure mode and should only bite obscure boxes with |
| 78 | a VESA hole at 15Mb |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 79 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | The second case Clip sometimes kicks in is when the EBDA is marked |
| 81 | as reserved. Again we fail safe with reasonable results |
| 82 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 83 | |
| 84 | if(top > clip) |
| 85 | top = clip; |
| 86 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | return top; |
| 88 | } |
| 89 | |
| 90 | /* |
| 91 | * Compute a set of MCR's to give maximum coverage |
| 92 | */ |
| 93 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 94 | static int __cpuinit centaur_mcr_compute(int nr, int key) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 95 | { |
| 96 | u32 mem = ramtop(); |
| 97 | u32 root = power2(mem); |
| 98 | u32 base = root; |
| 99 | u32 top = root; |
| 100 | u32 floor = 0; |
| 101 | int ct = 0; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 102 | |
| 103 | while (ct < nr) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | { |
| 105 | u32 fspace = 0; |
| 106 | |
| 107 | /* |
| 108 | * Find the largest block we will fill going upwards |
| 109 | */ |
| 110 | |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 111 | u32 high = power2(mem-top); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 112 | |
| 113 | /* |
| 114 | * Find the largest block we will fill going downwards |
| 115 | */ |
| 116 | |
| 117 | u32 low = base/2; |
| 118 | |
| 119 | /* |
| 120 | * Don't fill below 1Mb going downwards as there |
| 121 | * is an ISA hole in the way. |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 122 | */ |
| 123 | |
| 124 | if (base <= 1024*1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 125 | low = 0; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 126 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | /* |
| 128 | * See how much space we could cover by filling below |
| 129 | * the ISA hole |
| 130 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 131 | |
| 132 | if (floor == 0) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | fspace = 512*1024; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 134 | else if (floor == 512*1024) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | fspace = 128*1024; |
| 136 | |
| 137 | /* And forget ROM space */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 138 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | /* |
| 140 | * Now install the largest coverage we get |
| 141 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 142 | |
| 143 | if (fspace > high && fspace > low) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | { |
| 145 | centaur_mcr_insert(ct, floor, fspace, key); |
| 146 | floor += fspace; |
| 147 | } |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 148 | else if (high > low) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 149 | centaur_mcr_insert(ct, top, high, key); |
| 150 | top += high; |
| 151 | } |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 152 | else if (low > 0) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 153 | base -= low; |
| 154 | centaur_mcr_insert(ct, base, low, key); |
| 155 | } |
| 156 | else break; |
| 157 | ct++; |
| 158 | } |
| 159 | /* |
| 160 | * We loaded ct values. We now need to set the mask. The caller |
| 161 | * must do this bit. |
| 162 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 163 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | return ct; |
| 165 | } |
| 166 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 167 | static void __cpuinit centaur_create_optimal_mcr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 168 | { |
| 169 | int i; |
| 170 | /* |
| 171 | * Allocate up to 6 mcrs to mark as much of ram as possible |
| 172 | * as write combining and weak write ordered. |
| 173 | * |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 174 | * To experiment with: Linux never uses stack operations for |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 175 | * mmio spaces so we could globally enable stack operation wc |
| 176 | * |
| 177 | * Load the registers with type 31 - full write combining, all |
| 178 | * writes weakly ordered. |
| 179 | */ |
| 180 | int used = centaur_mcr_compute(6, 31); |
| 181 | |
| 182 | /* |
| 183 | * Wipe unused MCRs |
| 184 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 185 | |
| 186 | for (i = used; i < 8; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 187 | wrmsr(MSR_IDT_MCR0+i, 0, 0); |
| 188 | } |
| 189 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 190 | static void __cpuinit winchip2_create_optimal_mcr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | { |
| 192 | u32 lo, hi; |
| 193 | int i; |
| 194 | |
| 195 | /* |
| 196 | * Allocate up to 6 mcrs to mark as much of ram as possible |
| 197 | * as write combining, weak store ordered. |
| 198 | * |
| 199 | * Load the registers with type 25 |
| 200 | * 8 - weak write ordering |
| 201 | * 16 - weak read ordering |
| 202 | * 1 - write combining |
| 203 | */ |
| 204 | |
| 205 | int used = centaur_mcr_compute(6, 25); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 206 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | /* |
| 208 | * Mark the registers we are using. |
| 209 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 210 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | rdmsr(MSR_IDT_MCR_CTRL, lo, hi); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 212 | for (i = 0; i < used; i++) |
| 213 | lo |= 1<<(9+i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 214 | wrmsr(MSR_IDT_MCR_CTRL, lo, hi); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 215 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* |
| 217 | * Wipe unused MCRs |
| 218 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 219 | |
| 220 | for (i = used; i < 8; i++) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 221 | wrmsr(MSR_IDT_MCR0+i, 0, 0); |
| 222 | } |
| 223 | |
| 224 | /* |
| 225 | * Handle the MCR key on the Winchip 2. |
| 226 | */ |
| 227 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 228 | static void __cpuinit winchip2_unprotect_mcr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | { |
| 230 | u32 lo, hi; |
| 231 | u32 key; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 232 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 233 | rdmsr(MSR_IDT_MCR_CTRL, lo, hi); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 234 | lo &= ~0x1C0; /* blank bits 8-6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 235 | key = (lo>>17) & 7; |
| 236 | lo |= key<<6; /* replace with unlock key */ |
| 237 | wrmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 238 | } |
| 239 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 240 | static void __cpuinit winchip2_protect_mcr(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | { |
| 242 | u32 lo, hi; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 243 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 244 | rdmsr(MSR_IDT_MCR_CTRL, lo, hi); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 245 | lo &= ~0x1C0; /* blank bits 8-6 */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 246 | wrmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 247 | } |
| 248 | #endif /* CONFIG_X86_OOSTORE */ |
| 249 | |
| 250 | #define ACE_PRESENT (1 << 6) |
| 251 | #define ACE_ENABLED (1 << 7) |
| 252 | #define ACE_FCR (1 << 28) /* MSR_VIA_FCR */ |
| 253 | |
| 254 | #define RNG_PRESENT (1 << 2) |
| 255 | #define RNG_ENABLED (1 << 3) |
| 256 | #define RNG_ENABLE (1 << 6) /* MSR_VIA_RNG */ |
| 257 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 258 | static void __cpuinit init_c3(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 259 | { |
| 260 | u32 lo, hi; |
| 261 | |
| 262 | /* Test for Centaur Extended Feature Flags presence */ |
| 263 | if (cpuid_eax(0xC0000000) >= 0xC0000001) { |
| 264 | u32 tmp = cpuid_edx(0xC0000001); |
| 265 | |
| 266 | /* enable ACE unit, if present and disabled */ |
| 267 | if ((tmp & (ACE_PRESENT | ACE_ENABLED)) == ACE_PRESENT) { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 268 | rdmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 269 | lo |= ACE_FCR; /* enable ACE unit */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 270 | wrmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | printk(KERN_INFO "CPU: Enabled ACE h/w crypto\n"); |
| 272 | } |
| 273 | |
| 274 | /* enable RNG unit, if present and disabled */ |
| 275 | if ((tmp & (RNG_PRESENT | RNG_ENABLED)) == RNG_PRESENT) { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 276 | rdmsr(MSR_VIA_RNG, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 277 | lo |= RNG_ENABLE; /* enable RNG unit */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 278 | wrmsr(MSR_VIA_RNG, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 279 | printk(KERN_INFO "CPU: Enabled h/w RNG\n"); |
| 280 | } |
| 281 | |
| 282 | /* store Centaur Extended Feature Flags as |
| 283 | * word 5 of the CPU capability bit array |
| 284 | */ |
| 285 | c->x86_capability[5] = cpuid_edx(0xC0000001); |
| 286 | } |
| 287 | |
Simon Arlott | 27b46d7 | 2007-10-20 01:13:56 +0200 | [diff] [blame] | 288 | /* Cyrix III family needs CX8 & PGE explicitly enabled. */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 289 | if (c->x86_model >= 6 && c->x86_model <= 9) { |
| 290 | rdmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | lo |= (1<<1 | 1<<7); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 292 | wrmsr(MSR_VIA_FCR, lo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 293 | set_bit(X86_FEATURE_CX8, c->x86_capability); |
| 294 | } |
| 295 | |
| 296 | /* Before Nehemiah, the C3's had 3dNOW! */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 297 | if (c->x86_model >= 6 && c->x86_model < 9) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | set_bit(X86_FEATURE_3DNOW, c->x86_capability); |
| 299 | |
| 300 | get_model_name(c); |
| 301 | display_cacheinfo(c); |
| 302 | } |
| 303 | |
Magnus Damm | b4af3f7 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 304 | static void __cpuinit init_centaur(struct cpuinfo_x86 *c) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | { |
| 306 | enum { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 307 | ECX8 = 1<<1, |
| 308 | EIERRINT = 1<<2, |
| 309 | DPM = 1<<3, |
| 310 | DMCE = 1<<4, |
| 311 | DSTPCLK = 1<<5, |
| 312 | ELINEAR = 1<<6, |
| 313 | DSMC = 1<<7, |
| 314 | DTLOCK = 1<<8, |
| 315 | EDCTLB = 1<<8, |
| 316 | EMMX = 1<<9, |
| 317 | DPDC = 1<<11, |
| 318 | EBRPRED = 1<<12, |
| 319 | DIC = 1<<13, |
| 320 | DDC = 1<<14, |
| 321 | DNA = 1<<15, |
| 322 | ERETSTK = 1<<16, |
| 323 | E2MMX = 1<<19, |
| 324 | EAMD3D = 1<<20, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 325 | }; |
| 326 | |
| 327 | char *name; |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 328 | u32 fcr_set = 0; |
| 329 | u32 fcr_clr = 0; |
| 330 | u32 lo, hi, newlo; |
| 331 | u32 aa, bb, cc, dd; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 332 | |
| 333 | /* Bit 31 in normal CPUID used for nonstandard 3DNow ID; |
| 334 | 3DNow is IDd by bit 31 in extended CPUID (1*32+31) anyway */ |
| 335 | clear_bit(0*32+31, c->x86_capability); |
| 336 | |
| 337 | switch (c->x86) { |
| 338 | |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 339 | case 5: |
| 340 | switch (c->x86_model) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | case 4: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 342 | name = "C6"; |
| 343 | fcr_set = ECX8|DSMC|EDCTLB|EMMX|ERETSTK; |
| 344 | fcr_clr = DPDC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 345 | printk(KERN_NOTICE "Disabling bugged TSC.\n"); |
| 346 | clear_bit(X86_FEATURE_TSC, c->x86_capability); |
| 347 | #ifdef CONFIG_X86_OOSTORE |
| 348 | centaur_create_optimal_mcr(); |
| 349 | /* Enable |
| 350 | write combining on non-stack, non-string |
| 351 | write combining on string, all types |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 352 | weak write ordering |
| 353 | |
| 354 | The C6 original lacks weak read order |
| 355 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | Note 0x120 is write only on Winchip 1 */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 357 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 358 | wrmsr(MSR_IDT_MCR_CTRL, 0x01F0001F, 0); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 359 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | break; |
| 361 | case 8: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 362 | switch (c->x86_mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | default: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 364 | name = "2"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | break; |
| 366 | case 7 ... 9: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 367 | name = "2A"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 368 | break; |
| 369 | case 10 ... 15: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 370 | name = "2B"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 371 | break; |
| 372 | } |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 373 | fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D; |
| 374 | fcr_clr = DPDC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 375 | #ifdef CONFIG_X86_OOSTORE |
| 376 | winchip2_unprotect_mcr(); |
| 377 | winchip2_create_optimal_mcr(); |
| 378 | rdmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 379 | /* Enable |
| 380 | write combining on non-stack, non-string |
| 381 | write combining on string, all types |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 382 | weak write ordering |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 384 | lo |= 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | wrmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 386 | winchip2_protect_mcr(); |
| 387 | #endif |
| 388 | break; |
| 389 | case 9: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 390 | name = "3"; |
| 391 | fcr_set = ECX8|DSMC|DTLOCK|EMMX|EBRPRED|ERETSTK|E2MMX|EAMD3D; |
| 392 | fcr_clr = DPDC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | #ifdef CONFIG_X86_OOSTORE |
| 394 | winchip2_unprotect_mcr(); |
| 395 | winchip2_create_optimal_mcr(); |
| 396 | rdmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 397 | /* Enable |
| 398 | write combining on non-stack, non-string |
| 399 | write combining on string, all types |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 400 | weak write ordering |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 401 | */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 402 | lo |= 31; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 403 | wrmsr(MSR_IDT_MCR_CTRL, lo, hi); |
| 404 | winchip2_protect_mcr(); |
| 405 | #endif |
| 406 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | default: |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 408 | name = "??"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | } |
| 410 | |
| 411 | rdmsr(MSR_IDT_FCR1, lo, hi); |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 412 | newlo = (lo|fcr_set) & (~fcr_clr); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 413 | |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 414 | if (newlo != lo) { |
| 415 | printk(KERN_INFO "Centaur FCR was 0x%X now 0x%X\n", lo, newlo); |
| 416 | wrmsr(MSR_IDT_FCR1, newlo, hi); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 417 | } else { |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 418 | printk(KERN_INFO "Centaur FCR is 0x%X\n", lo); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | /* Emulate MTRRs using Centaur's MCR. */ |
| 421 | set_bit(X86_FEATURE_CENTAUR_MCR, c->x86_capability); |
| 422 | /* Report CX8 */ |
| 423 | set_bit(X86_FEATURE_CX8, c->x86_capability); |
| 424 | /* Set 3DNow! on Winchip 2 and above. */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 425 | if (c->x86_model >= 8) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 426 | set_bit(X86_FEATURE_3DNOW, c->x86_capability); |
| 427 | /* See if we can find out some more. */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 428 | if (cpuid_eax(0x80000000) >= 0x80000005) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | /* Yes, we can. */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 430 | cpuid(0x80000005, &aa, &bb, &cc, &dd); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 431 | /* Add L1 data and code cache sizes. */ |
| 432 | c->x86_cache_size = (cc>>24)+(dd>>24); |
| 433 | } |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 434 | sprintf(c->x86_model_id, "WinChip %s", name); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | break; |
| 436 | |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 437 | case 6: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 438 | init_c3(c); |
| 439 | break; |
| 440 | } |
| 441 | } |
| 442 | |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 443 | static unsigned int __cpuinit centaur_size_cache(struct cpuinfo_x86 *c, unsigned int size) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 444 | { |
| 445 | /* VIA C3 CPUs (670-68F) need further shifting. */ |
| 446 | if ((c->x86 == 6) && ((c->x86_model == 7) || (c->x86_model == 8))) |
| 447 | size >>= 8; |
| 448 | |
| 449 | /* VIA also screwed up Nehemiah stepping 1, and made |
| 450 | it return '65KB' instead of '64KB' |
| 451 | - Note, it seems this may only be in engineering samples. */ |
Paolo Ciarrocchi | 29a9994 | 2008-02-17 23:30:23 +0100 | [diff] [blame^] | 452 | if ((c->x86 == 6) && (c->x86_model == 9) && (c->x86_mask == 1) && (size == 65)) |
| 453 | size -= 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | return size; |
| 456 | } |
| 457 | |
Magnus Damm | 9541493 | 2006-09-26 10:52:36 +0200 | [diff] [blame] | 458 | static struct cpu_dev centaur_cpu_dev __cpuinitdata = { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | .c_vendor = "Centaur", |
| 460 | .c_ident = { "CentaurHauls" }, |
| 461 | .c_init = init_centaur, |
| 462 | .c_size_cache = centaur_size_cache, |
| 463 | }; |
| 464 | |
Thomas Petazzoni | 03ae576 | 2008-02-15 12:00:23 +0100 | [diff] [blame] | 465 | cpu_vendor_dev_register(X86_VENDOR_CENTAUR, ¢aur_cpu_dev); |