blob: 0fc90ba16ae1594d5ad7b9ba2dba771b954f1e05 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Processor capabilities determination functions.
3 *
4 * Copyright (C) xxxx the Anonymous
Ralf Baechle010b8532006-01-29 18:42:08 +00005 * Copyright (C) 1994 - 2006 Ralf Baechle
Ralf Baechle41943182005-05-05 16:45:59 +00006 * Copyright (C) 2003, 2004 Maciej W. Rozycki
Ralf Baechle41943182005-05-05 16:45:59 +00007 * Copyright (C) 2001, 2004 MIPS Inc.
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
13 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070014#include <linux/init.h>
15#include <linux/kernel.h>
16#include <linux/ptrace.h>
17#include <linux/stddef.h>
18
Ralf Baechle57599062007-02-18 19:07:31 +000019#include <asm/bugs.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/cpu.h>
21#include <asm/fpu.h>
22#include <asm/mipsregs.h>
23#include <asm/system.h>
24
25/*
26 * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
27 * the implementation of the "wait" feature differs between CPU families. This
28 * points to the function that implements CPU specific wait.
29 * The wait instruction stops the pipeline and reduces the power consumption of
30 * the CPU very much.
31 */
32void (*cpu_wait)(void) = NULL;
33
34static void r3081_wait(void)
35{
36 unsigned long cfg = read_c0_conf();
37 write_c0_conf(cfg | R30XX_CONF_HALT);
38}
39
40static void r39xx_wait(void)
41{
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090042 local_irq_disable();
43 if (!need_resched())
44 write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
45 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070046}
47
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090048/*
49 * There is a race when WAIT instruction executed with interrupt
50 * enabled.
51 * But it is implementation-dependent wheter the pipelie restarts when
52 * a non-enabled interrupt is requested.
53 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070054static void r4k_wait(void)
55{
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090056 __asm__(" .set mips3 \n"
57 " wait \n"
58 " .set mips0 \n");
59}
60
61/*
62 * This variant is preferable as it allows testing need_resched and going to
63 * sleep depending on the outcome atomically. Unfortunately the "It is
64 * implementation-dependent whether the pipeline restarts when a non-enabled
65 * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
66 * using this version a gamble.
67 */
68static void r4k_wait_irqoff(void)
69{
70 local_irq_disable();
71 if (!need_resched())
72 __asm__(" .set mips3 \n"
73 " wait \n"
74 " .set mips0 \n");
75 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070076}
77
Pete Popov494900a2005-04-07 00:42:10 +000078/* The Au1xxx wait is available only if using 32khz counter or
79 * external timer source, but specifically not CP0 Counter. */
Pete Popovfe359bf2005-04-08 08:34:43 +000080int allow_au1k_wait;
Ralf Baechle10f650d2005-05-25 13:32:49 +000081
Pete Popov494900a2005-04-07 00:42:10 +000082static void au1k_wait(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070083{
Linus Torvalds1da177e2005-04-16 15:20:36 -070084 /* using the wait instruction makes CP0 counter unusable */
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090085 __asm__(" .set mips3 \n"
86 " cache 0x14, 0(%0) \n"
87 " cache 0x14, 32(%0) \n"
88 " sync \n"
89 " nop \n"
90 " wait \n"
91 " nop \n"
92 " nop \n"
93 " nop \n"
94 " nop \n"
95 " .set mips0 \n"
Ralf Baechle10f650d2005-05-25 13:32:49 +000096 : : "r" (au1k_wait));
Linus Torvalds1da177e2005-04-16 15:20:36 -070097}
98
Ralf Baechle55d04df2005-07-13 19:22:45 +000099static int __initdata nowait = 0;
100
Atsushi Nemotof49a7472007-02-18 01:02:14 +0900101static int __init wait_disable(char *s)
Ralf Baechle55d04df2005-07-13 19:22:45 +0000102{
103 nowait = 1;
104
105 return 1;
106}
107
108__setup("nowait", wait_disable);
109
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110static inline void check_wait(void)
111{
112 struct cpuinfo_mips *c = &current_cpu_data;
113
Ralf Baechle55d04df2005-07-13 19:22:45 +0000114 if (nowait) {
Ralf Baechlec2379232006-11-30 01:14:44 +0000115 printk("Wait instruction disabled.\n");
Ralf Baechle55d04df2005-07-13 19:22:45 +0000116 return;
117 }
118
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 switch (c->cputype) {
120 case CPU_R3081:
121 case CPU_R3081E:
122 cpu_wait = r3081_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123 break;
124 case CPU_TX3927:
125 cpu_wait = r39xx_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 break;
127 case CPU_R4200:
128/* case CPU_R4300: */
129 case CPU_R4600:
130 case CPU_R4640:
131 case CPU_R4650:
132 case CPU_R4700:
133 case CPU_R5000:
134 case CPU_NEVADA:
135 case CPU_RM7000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136 case CPU_4KC:
137 case CPU_4KEC:
138 case CPU_4KSC:
139 case CPU_5KC:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700140 case CPU_24K:
141 case CPU_25KF:
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000142 case CPU_34K:
Chris Dearmanc6209532006-05-02 14:08:46 +0100143 case CPU_74K:
Pete Popovbdf21b12005-07-14 17:47:57 +0000144 case CPU_PR4450:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145 cpu_wait = r4k_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146 break;
Atsushi Nemoto60a6c372006-06-08 01:09:01 +0900147 case CPU_TX49XX:
148 cpu_wait = r4k_wait_irqoff;
Atsushi Nemoto60a6c372006-06-08 01:09:01 +0900149 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 case CPU_AU1000:
151 case CPU_AU1100:
152 case CPU_AU1500:
Pete Popove3ad1c22005-03-01 06:33:16 +0000153 case CPU_AU1550:
154 case CPU_AU1200:
Ralf Baechlec2379232006-11-30 01:14:44 +0000155 if (allow_au1k_wait)
Pete Popovfe359bf2005-04-08 08:34:43 +0000156 cpu_wait = au1k_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 break;
Ralf Baechlec8eae712007-06-12 13:04:09 +0100158 case CPU_20KC:
159 /*
160 * WAIT on Rev1.0 has E1, E2, E3 and E16.
161 * WAIT on Rev2.0 and Rev3.0 has E16.
162 * Rev3.1 WAIT is nop, why bother
163 */
164 if ((c->processor_id & 0xff) <= 0x64)
165 break;
166
167 cpu_wait = r4k_wait;
168 break;
Ralf Baechle441ee342006-06-02 11:48:11 +0100169 case CPU_RM9000:
Ralf Baechlec2379232006-11-30 01:14:44 +0000170 if ((c->processor_id & 0x00ff) >= 0x40)
Ralf Baechle441ee342006-06-02 11:48:11 +0100171 cpu_wait = r4k_wait;
Ralf Baechle441ee342006-06-02 11:48:11 +0100172 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 break;
175 }
176}
177
178void __init check_bugs32(void)
179{
180 check_wait();
181}
182
183/*
184 * Probe whether cpu has config register by trying to play with
185 * alternate cache bit and see whether it matters.
186 * It's used by cpu_probe to distinguish between R3000A and R3081.
187 */
188static inline int cpu_has_confreg(void)
189{
190#ifdef CONFIG_CPU_R3000
191 extern unsigned long r3k_cache_size(unsigned long);
192 unsigned long size1, size2;
193 unsigned long cfg = read_c0_conf();
194
195 size1 = r3k_cache_size(ST0_ISC);
196 write_c0_conf(cfg ^ R30XX_CONF_AC);
197 size2 = r3k_cache_size(ST0_ISC);
198 write_c0_conf(cfg);
199 return size1 != size2;
200#else
201 return 0;
202#endif
203}
204
205/*
206 * Get the FPU Implementation/Revision.
207 */
208static inline unsigned long cpu_get_fpu_id(void)
209{
210 unsigned long tmp, fpu_id;
211
212 tmp = read_c0_status();
213 __enable_fpu();
214 fpu_id = read_32bit_cp1_register(CP1_REVISION);
215 write_c0_status(tmp);
216 return fpu_id;
217}
218
219/*
220 * Check the CPU has an FPU the official way.
221 */
222static inline int __cpu_has_fpu(void)
223{
224 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
225}
226
Ralf Baechle02cf2112005-10-01 13:06:32 +0100227#define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700228 | MIPS_CPU_COUNTER)
229
230static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
231{
232 switch (c->processor_id & 0xff00) {
233 case PRID_IMP_R2000:
234 c->cputype = CPU_R2000;
235 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100236 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
237 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700238 if (__cpu_has_fpu())
239 c->options |= MIPS_CPU_FPU;
240 c->tlbsize = 64;
241 break;
242 case PRID_IMP_R3000:
243 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
244 if (cpu_has_confreg())
245 c->cputype = CPU_R3081E;
246 else
247 c->cputype = CPU_R3000A;
248 else
249 c->cputype = CPU_R3000;
250 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100251 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
252 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253 if (__cpu_has_fpu())
254 c->options |= MIPS_CPU_FPU;
255 c->tlbsize = 64;
256 break;
257 case PRID_IMP_R4000:
258 if (read_c0_config() & CONF_SC) {
259 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
260 c->cputype = CPU_R4400PC;
261 else
262 c->cputype = CPU_R4000PC;
263 } else {
264 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
265 c->cputype = CPU_R4400SC;
266 else
267 c->cputype = CPU_R4000SC;
268 }
269
270 c->isa_level = MIPS_CPU_ISA_III;
271 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
272 MIPS_CPU_WATCH | MIPS_CPU_VCE |
273 MIPS_CPU_LLSC;
274 c->tlbsize = 48;
275 break;
276 case PRID_IMP_VR41XX:
277 switch (c->processor_id & 0xf0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700278 case PRID_REV_VR4111:
279 c->cputype = CPU_VR4111;
280 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700281 case PRID_REV_VR4121:
282 c->cputype = CPU_VR4121;
283 break;
284 case PRID_REV_VR4122:
285 if ((c->processor_id & 0xf) < 0x3)
286 c->cputype = CPU_VR4122;
287 else
288 c->cputype = CPU_VR4181A;
289 break;
290 case PRID_REV_VR4130:
291 if ((c->processor_id & 0xf) < 0x4)
292 c->cputype = CPU_VR4131;
293 else
294 c->cputype = CPU_VR4133;
295 break;
296 default:
297 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
298 c->cputype = CPU_VR41XX;
299 break;
300 }
301 c->isa_level = MIPS_CPU_ISA_III;
302 c->options = R4K_OPTS;
303 c->tlbsize = 32;
304 break;
305 case PRID_IMP_R4300:
306 c->cputype = CPU_R4300;
307 c->isa_level = MIPS_CPU_ISA_III;
308 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
309 MIPS_CPU_LLSC;
310 c->tlbsize = 32;
311 break;
312 case PRID_IMP_R4600:
313 c->cputype = CPU_R4600;
314 c->isa_level = MIPS_CPU_ISA_III;
Thiemo Seufer075e7502005-07-27 21:48:12 +0000315 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
316 MIPS_CPU_LLSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 c->tlbsize = 48;
318 break;
319 #if 0
320 case PRID_IMP_R4650:
321 /*
322 * This processor doesn't have an MMU, so it's not
323 * "real easy" to run Linux on it. It is left purely
324 * for documentation. Commented out because it shares
325 * it's c0_prid id number with the TX3900.
326 */
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000327 c->cputype = CPU_R4650;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700328 c->isa_level = MIPS_CPU_ISA_III;
329 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
330 c->tlbsize = 48;
331 break;
332 #endif
333 case PRID_IMP_TX39:
334 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100335 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
338 c->cputype = CPU_TX3927;
339 c->tlbsize = 64;
340 } else {
341 switch (c->processor_id & 0xff) {
342 case PRID_REV_TX3912:
343 c->cputype = CPU_TX3912;
344 c->tlbsize = 32;
345 break;
346 case PRID_REV_TX3922:
347 c->cputype = CPU_TX3922;
348 c->tlbsize = 64;
349 break;
350 default:
351 c->cputype = CPU_UNKNOWN;
352 break;
353 }
354 }
355 break;
356 case PRID_IMP_R4700:
357 c->cputype = CPU_R4700;
358 c->isa_level = MIPS_CPU_ISA_III;
359 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
360 MIPS_CPU_LLSC;
361 c->tlbsize = 48;
362 break;
363 case PRID_IMP_TX49:
364 c->cputype = CPU_TX49XX;
365 c->isa_level = MIPS_CPU_ISA_III;
366 c->options = R4K_OPTS | MIPS_CPU_LLSC;
367 if (!(c->processor_id & 0x08))
368 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
369 c->tlbsize = 48;
370 break;
371 case PRID_IMP_R5000:
372 c->cputype = CPU_R5000;
373 c->isa_level = MIPS_CPU_ISA_IV;
374 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
375 MIPS_CPU_LLSC;
376 c->tlbsize = 48;
377 break;
378 case PRID_IMP_R5432:
379 c->cputype = CPU_R5432;
380 c->isa_level = MIPS_CPU_ISA_IV;
381 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
382 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
383 c->tlbsize = 48;
384 break;
385 case PRID_IMP_R5500:
386 c->cputype = CPU_R5500;
387 c->isa_level = MIPS_CPU_ISA_IV;
388 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
389 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
390 c->tlbsize = 48;
391 break;
392 case PRID_IMP_NEVADA:
393 c->cputype = CPU_NEVADA;
394 c->isa_level = MIPS_CPU_ISA_IV;
395 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
396 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
397 c->tlbsize = 48;
398 break;
399 case PRID_IMP_R6000:
400 c->cputype = CPU_R6000;
401 c->isa_level = MIPS_CPU_ISA_II;
402 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
403 MIPS_CPU_LLSC;
404 c->tlbsize = 32;
405 break;
406 case PRID_IMP_R6000A:
407 c->cputype = CPU_R6000A;
408 c->isa_level = MIPS_CPU_ISA_II;
409 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
410 MIPS_CPU_LLSC;
411 c->tlbsize = 32;
412 break;
413 case PRID_IMP_RM7000:
414 c->cputype = CPU_RM7000;
415 c->isa_level = MIPS_CPU_ISA_IV;
416 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
417 MIPS_CPU_LLSC;
418 /*
419 * Undocumented RM7000: Bit 29 in the info register of
420 * the RM7000 v2.0 indicates if the TLB has 48 or 64
421 * entries.
422 *
423 * 29 1 => 64 entry JTLB
424 * 0 => 48 entry JTLB
425 */
426 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
427 break;
428 case PRID_IMP_RM9000:
429 c->cputype = CPU_RM9000;
430 c->isa_level = MIPS_CPU_ISA_IV;
431 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
432 MIPS_CPU_LLSC;
433 /*
434 * Bit 29 in the info register of the RM9000
435 * indicates if the TLB has 48 or 64 entries.
436 *
437 * 29 1 => 64 entry JTLB
438 * 0 => 48 entry JTLB
439 */
440 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
441 break;
442 case PRID_IMP_R8000:
443 c->cputype = CPU_R8000;
444 c->isa_level = MIPS_CPU_ISA_IV;
445 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
446 MIPS_CPU_FPU | MIPS_CPU_32FPR |
447 MIPS_CPU_LLSC;
448 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
449 break;
450 case PRID_IMP_R10000:
451 c->cputype = CPU_R10000;
452 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000453 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700454 MIPS_CPU_FPU | MIPS_CPU_32FPR |
455 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
456 MIPS_CPU_LLSC;
457 c->tlbsize = 64;
458 break;
459 case PRID_IMP_R12000:
460 c->cputype = CPU_R12000;
461 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000462 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463 MIPS_CPU_FPU | MIPS_CPU_32FPR |
464 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
465 MIPS_CPU_LLSC;
466 c->tlbsize = 64;
467 break;
Kumba44d921b2006-05-16 22:23:59 -0400468 case PRID_IMP_R14000:
469 c->cputype = CPU_R14000;
470 c->isa_level = MIPS_CPU_ISA_IV;
471 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
472 MIPS_CPU_FPU | MIPS_CPU_32FPR |
473 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
474 MIPS_CPU_LLSC;
475 c->tlbsize = 64;
476 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477 }
478}
479
Ralf Baechleb4672d32005-12-08 14:04:24 +0000480static char unknown_isa[] __initdata = KERN_ERR \
481 "Unsupported ISA type, c0.config0: %d.";
482
Ralf Baechle41943182005-05-05 16:45:59 +0000483static inline unsigned int decode_config0(struct cpuinfo_mips *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484{
Ralf Baechle41943182005-05-05 16:45:59 +0000485 unsigned int config0;
486 int isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
Ralf Baechle41943182005-05-05 16:45:59 +0000488 config0 = read_c0_config();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Ralf Baechle41943182005-05-05 16:45:59 +0000490 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
Ralf Baechle02cf2112005-10-01 13:06:32 +0100491 c->options |= MIPS_CPU_TLB;
Ralf Baechle41943182005-05-05 16:45:59 +0000492 isa = (config0 & MIPS_CONF_AT) >> 13;
493 switch (isa) {
494 case 0:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100495 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000496 case 0:
497 c->isa_level = MIPS_CPU_ISA_M32R1;
498 break;
499 case 1:
500 c->isa_level = MIPS_CPU_ISA_M32R2;
501 break;
502 default:
503 goto unknown;
504 }
Ralf Baechle41943182005-05-05 16:45:59 +0000505 break;
506 case 2:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100507 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000508 case 0:
509 c->isa_level = MIPS_CPU_ISA_M64R1;
510 break;
511 case 1:
512 c->isa_level = MIPS_CPU_ISA_M64R2;
513 break;
514 default:
515 goto unknown;
516 }
Ralf Baechle41943182005-05-05 16:45:59 +0000517 break;
518 default:
Ralf Baechleb4672d32005-12-08 14:04:24 +0000519 goto unknown;
Ralf Baechle41943182005-05-05 16:45:59 +0000520 }
521
522 return config0 & MIPS_CONF_M;
Ralf Baechleb4672d32005-12-08 14:04:24 +0000523
524unknown:
525 panic(unknown_isa, config0);
Ralf Baechle41943182005-05-05 16:45:59 +0000526}
527
528static inline unsigned int decode_config1(struct cpuinfo_mips *c)
529{
530 unsigned int config1;
531
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 config1 = read_c0_config1();
Ralf Baechle41943182005-05-05 16:45:59 +0000533
534 if (config1 & MIPS_CONF1_MD)
535 c->ases |= MIPS_ASE_MDMX;
536 if (config1 & MIPS_CONF1_WR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700537 c->options |= MIPS_CPU_WATCH;
Ralf Baechle41943182005-05-05 16:45:59 +0000538 if (config1 & MIPS_CONF1_CA)
539 c->ases |= MIPS_ASE_MIPS16;
540 if (config1 & MIPS_CONF1_EP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541 c->options |= MIPS_CPU_EJTAG;
Ralf Baechle41943182005-05-05 16:45:59 +0000542 if (config1 & MIPS_CONF1_FP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 c->options |= MIPS_CPU_FPU;
544 c->options |= MIPS_CPU_32FPR;
545 }
Ralf Baechle41943182005-05-05 16:45:59 +0000546 if (cpu_has_tlb)
547 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
548
549 return config1 & MIPS_CONF_M;
550}
551
552static inline unsigned int decode_config2(struct cpuinfo_mips *c)
553{
554 unsigned int config2;
555
556 config2 = read_c0_config2();
557
558 if (config2 & MIPS_CONF2_SL)
559 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
560
561 return config2 & MIPS_CONF_M;
562}
563
564static inline unsigned int decode_config3(struct cpuinfo_mips *c)
565{
566 unsigned int config3;
567
568 config3 = read_c0_config3();
569
570 if (config3 & MIPS_CONF3_SM)
571 c->ases |= MIPS_ASE_SMARTMIPS;
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000572 if (config3 & MIPS_CONF3_DSP)
573 c->ases |= MIPS_ASE_DSP;
Ralf Baechle8f406112005-07-14 07:34:18 +0000574 if (config3 & MIPS_CONF3_VINT)
575 c->options |= MIPS_CPU_VINT;
576 if (config3 & MIPS_CONF3_VEIC)
577 c->options |= MIPS_CPU_VEIC;
578 if (config3 & MIPS_CONF3_MT)
Ralf Baechlee0daad42007-02-05 00:10:11 +0000579 c->ases |= MIPS_ASE_MIPSMT;
Ralf Baechle41943182005-05-05 16:45:59 +0000580
581 return config3 & MIPS_CONF_M;
582}
583
Thiemo Seuferc36cd4b2006-07-03 13:30:01 +0100584static void __init decode_configs(struct cpuinfo_mips *c)
Ralf Baechle41943182005-05-05 16:45:59 +0000585{
586 /* MIPS32 or MIPS64 compliant CPU. */
Ralf Baechle02cf2112005-10-01 13:06:32 +0100587 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
588 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
Ralf Baechle41943182005-05-05 16:45:59 +0000589
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
591
Ralf Baechle41943182005-05-05 16:45:59 +0000592 /* Read Config registers. */
593 if (!decode_config0(c))
594 return; /* actually worth a panic() */
595 if (!decode_config1(c))
596 return;
597 if (!decode_config2(c))
598 return;
599 if (!decode_config3(c))
600 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601}
602
603static inline void cpu_probe_mips(struct cpuinfo_mips *c)
604{
Ralf Baechle41943182005-05-05 16:45:59 +0000605 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 switch (c->processor_id & 0xff00) {
607 case PRID_IMP_4KC:
608 c->cputype = CPU_4KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 break;
610 case PRID_IMP_4KEC:
611 c->cputype = CPU_4KEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700612 break;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000613 case PRID_IMP_4KECR2:
614 c->cputype = CPU_4KEC;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000615 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616 case PRID_IMP_4KSC:
Ralf Baechle8afcb5d2005-10-04 15:01:26 +0100617 case PRID_IMP_4KSD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 c->cputype = CPU_4KSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619 break;
620 case PRID_IMP_5KC:
621 c->cputype = CPU_5KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622 break;
623 case PRID_IMP_20KC:
624 c->cputype = CPU_20KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625 break;
626 case PRID_IMP_24K:
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000627 case PRID_IMP_24KE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 c->cputype = CPU_24K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700629 break;
630 case PRID_IMP_25KF:
631 c->cputype = CPU_25KF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700632 break;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000633 case PRID_IMP_34K:
634 c->cputype = CPU_34K;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000635 break;
Chris Dearmanc6209532006-05-02 14:08:46 +0100636 case PRID_IMP_74K:
637 c->cputype = CPU_74K;
638 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 }
640}
641
642static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
643{
Ralf Baechle41943182005-05-05 16:45:59 +0000644 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700645 switch (c->processor_id & 0xff00) {
646 case PRID_IMP_AU1_REV1:
647 case PRID_IMP_AU1_REV2:
648 switch ((c->processor_id >> 24) & 0xff) {
649 case 0:
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000650 c->cputype = CPU_AU1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 break;
652 case 1:
653 c->cputype = CPU_AU1500;
654 break;
655 case 2:
656 c->cputype = CPU_AU1100;
657 break;
658 case 3:
659 c->cputype = CPU_AU1550;
660 break;
Pete Popove3ad1c22005-03-01 06:33:16 +0000661 case 4:
662 c->cputype = CPU_AU1200;
663 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700664 default:
665 panic("Unknown Au Core!");
666 break;
667 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700668 break;
669 }
670}
671
672static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
673{
Ralf Baechle41943182005-05-05 16:45:59 +0000674 decode_configs(c);
Ralf Baechle02cf2112005-10-01 13:06:32 +0100675
676 /*
677 * For historical reasons the SB1 comes with it's own variant of
678 * cache code which eventually will be folded into c-r4k.c. Until
679 * then we pretend it's got it's own cache architecture.
680 */
Andrew Isaacsond121ced2005-10-19 23:54:43 -0700681 c->options &= ~MIPS_CPU_4K_CACHE;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100682 c->options |= MIPS_CPU_SB1_CACHE;
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684 switch (c->processor_id & 0xff00) {
685 case PRID_IMP_SB1:
686 c->cputype = CPU_SB1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700687 /* FPU in pass1 is known to have issues. */
Ralf Baechleaa323742006-05-29 00:02:12 +0100688 if ((c->processor_id & 0xff) < 0x02)
Ralf Baechle010b8532006-01-29 18:42:08 +0000689 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 break;
Andrew Isaacson93ce2f522005-10-19 23:56:20 -0700691 case PRID_IMP_SB1A:
692 c->cputype = CPU_SB1A;
693 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694 }
695}
696
697static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
698{
Ralf Baechle41943182005-05-05 16:45:59 +0000699 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700 switch (c->processor_id & 0xff00) {
701 case PRID_IMP_SR71000:
702 c->cputype = CPU_SR71000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 c->scache.ways = 8;
704 c->tlbsize = 64;
705 break;
706 }
707}
708
Pete Popovbdf21b12005-07-14 17:47:57 +0000709static inline void cpu_probe_philips(struct cpuinfo_mips *c)
710{
711 decode_configs(c);
712 switch (c->processor_id & 0xff00) {
713 case PRID_IMP_PR4450:
714 c->cputype = CPU_PR4450;
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000715 c->isa_level = MIPS_CPU_ISA_M32R1;
Pete Popovbdf21b12005-07-14 17:47:57 +0000716 break;
717 default:
718 panic("Unknown Philips Core!"); /* REVISIT: die? */
719 break;
720 }
721}
722
723
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724__init void cpu_probe(void)
725{
726 struct cpuinfo_mips *c = &current_cpu_data;
727
728 c->processor_id = PRID_IMP_UNKNOWN;
729 c->fpu_id = FPIR_IMP_NONE;
730 c->cputype = CPU_UNKNOWN;
731
732 c->processor_id = read_c0_prid();
733 switch (c->processor_id & 0xff0000) {
734 case PRID_COMP_LEGACY:
735 cpu_probe_legacy(c);
736 break;
737 case PRID_COMP_MIPS:
738 cpu_probe_mips(c);
739 break;
740 case PRID_COMP_ALCHEMY:
741 cpu_probe_alchemy(c);
742 break;
743 case PRID_COMP_SIBYTE:
744 cpu_probe_sibyte(c);
745 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746 case PRID_COMP_SANDCRAFT:
747 cpu_probe_sandcraft(c);
748 break;
Pete Popovbdf21b12005-07-14 17:47:57 +0000749 case PRID_COMP_PHILIPS:
750 cpu_probe_philips(c);
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000751 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752 default:
753 c->cputype = CPU_UNKNOWN;
754 }
Ralf Baechle41943182005-05-05 16:45:59 +0000755 if (c->options & MIPS_CPU_FPU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700756 c->fpu_id = cpu_get_fpu_id();
Ralf Baechle41943182005-05-05 16:45:59 +0000757
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000758 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
Ralf Baechleb4672d32005-12-08 14:04:24 +0000759 c->isa_level == MIPS_CPU_ISA_M32R2 ||
760 c->isa_level == MIPS_CPU_ISA_M64R1 ||
761 c->isa_level == MIPS_CPU_ISA_M64R2) {
Ralf Baechle41943182005-05-05 16:45:59 +0000762 if (c->fpu_id & MIPS_FPIR_3D)
763 c->ases |= MIPS_ASE_MIPS3D;
764 }
765 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766}
767
768__init void cpu_report(void)
769{
770 struct cpuinfo_mips *c = &current_cpu_data;
771
772 printk("CPU revision is: %08x\n", c->processor_id);
773 if (c->options & MIPS_CPU_FPU)
774 printk("FPU revision is: %08x\n", c->fpu_id);
775}