blob: 8485af340ee1a3c0316e8d5a60dc07d9246572d3 [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
Linus Torvalds1da177e2005-04-16 15:20:36 -070019#include <asm/cpu.h>
20#include <asm/fpu.h>
21#include <asm/mipsregs.h>
22#include <asm/system.h>
23
24/*
25 * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
26 * the implementation of the "wait" feature differs between CPU families. This
27 * points to the function that implements CPU specific wait.
28 * The wait instruction stops the pipeline and reduces the power consumption of
29 * the CPU very much.
30 */
31void (*cpu_wait)(void) = NULL;
32
33static void r3081_wait(void)
34{
35 unsigned long cfg = read_c0_conf();
36 write_c0_conf(cfg | R30XX_CONF_HALT);
37}
38
39static void r39xx_wait(void)
40{
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090041 local_irq_disable();
42 if (!need_resched())
43 write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
44 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070045}
46
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090047/*
48 * There is a race when WAIT instruction executed with interrupt
49 * enabled.
50 * But it is implementation-dependent wheter the pipelie restarts when
51 * a non-enabled interrupt is requested.
52 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070053static void r4k_wait(void)
54{
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090055 __asm__(" .set mips3 \n"
56 " wait \n"
57 " .set mips0 \n");
58}
59
60/*
61 * This variant is preferable as it allows testing need_resched and going to
62 * sleep depending on the outcome atomically. Unfortunately the "It is
63 * implementation-dependent whether the pipeline restarts when a non-enabled
64 * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
65 * using this version a gamble.
66 */
67static void r4k_wait_irqoff(void)
68{
69 local_irq_disable();
70 if (!need_resched())
71 __asm__(" .set mips3 \n"
72 " wait \n"
73 " .set mips0 \n");
74 local_irq_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -070075}
76
Pete Popov494900a2005-04-07 00:42:10 +000077/* The Au1xxx wait is available only if using 32khz counter or
78 * external timer source, but specifically not CP0 Counter. */
Pete Popovfe359bf2005-04-08 08:34:43 +000079int allow_au1k_wait;
Ralf Baechle10f650d2005-05-25 13:32:49 +000080
Pete Popov494900a2005-04-07 00:42:10 +000081static void au1k_wait(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070082{
Linus Torvalds1da177e2005-04-16 15:20:36 -070083 /* using the wait instruction makes CP0 counter unusable */
Atsushi Nemoto60a6c372006-06-08 01:09:01 +090084 __asm__(" .set mips3 \n"
85 " cache 0x14, 0(%0) \n"
86 " cache 0x14, 32(%0) \n"
87 " sync \n"
88 " nop \n"
89 " wait \n"
90 " nop \n"
91 " nop \n"
92 " nop \n"
93 " nop \n"
94 " .set mips0 \n"
Ralf Baechle10f650d2005-05-25 13:32:49 +000095 : : "r" (au1k_wait));
Linus Torvalds1da177e2005-04-16 15:20:36 -070096}
97
Ralf Baechle55d04df2005-07-13 19:22:45 +000098static int __initdata nowait = 0;
99
100int __init wait_disable(char *s)
101{
102 nowait = 1;
103
104 return 1;
105}
106
107__setup("nowait", wait_disable);
108
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static inline void check_wait(void)
110{
111 struct cpuinfo_mips *c = &current_cpu_data;
112
113 printk("Checking for 'wait' instruction... ");
Ralf Baechle55d04df2005-07-13 19:22:45 +0000114 if (nowait) {
115 printk (" disabled.\n");
116 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;
123 printk(" available.\n");
124 break;
125 case CPU_TX3927:
126 cpu_wait = r39xx_wait;
127 printk(" available.\n");
128 break;
129 case CPU_R4200:
130/* case CPU_R4300: */
131 case CPU_R4600:
132 case CPU_R4640:
133 case CPU_R4650:
134 case CPU_R4700:
135 case CPU_R5000:
136 case CPU_NEVADA:
137 case CPU_RM7000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138 case CPU_4KC:
139 case CPU_4KEC:
140 case CPU_4KSC:
141 case CPU_5KC:
142/* case CPU_20KC:*/
143 case CPU_24K:
144 case CPU_25KF:
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000145 case CPU_34K:
Chris Dearmanc6209532006-05-02 14:08:46 +0100146 case CPU_74K:
Pete Popovbdf21b12005-07-14 17:47:57 +0000147 case CPU_PR4450:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 cpu_wait = r4k_wait;
149 printk(" available.\n");
150 break;
Atsushi Nemoto60a6c372006-06-08 01:09:01 +0900151 case CPU_TX49XX:
152 cpu_wait = r4k_wait_irqoff;
153 printk(" available.\n");
154 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700155 case CPU_AU1000:
156 case CPU_AU1100:
157 case CPU_AU1500:
Pete Popove3ad1c22005-03-01 06:33:16 +0000158 case CPU_AU1550:
159 case CPU_AU1200:
Pete Popovfe359bf2005-04-08 08:34:43 +0000160 if (allow_au1k_wait) {
161 cpu_wait = au1k_wait;
162 printk(" available.\n");
163 } else
164 printk(" unavailable.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165 break;
Ralf Baechle441ee342006-06-02 11:48:11 +0100166 case CPU_RM9000:
167 if ((c->processor_id & 0x00ff) >= 0x40) {
168 cpu_wait = r4k_wait;
169 printk(" available.\n");
170 } else {
171 printk(" unavailable.\n");
172 }
173 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174 default:
175 printk(" unavailable.\n");
176 break;
177 }
178}
179
180void __init check_bugs32(void)
181{
182 check_wait();
183}
184
185/*
186 * Probe whether cpu has config register by trying to play with
187 * alternate cache bit and see whether it matters.
188 * It's used by cpu_probe to distinguish between R3000A and R3081.
189 */
190static inline int cpu_has_confreg(void)
191{
192#ifdef CONFIG_CPU_R3000
193 extern unsigned long r3k_cache_size(unsigned long);
194 unsigned long size1, size2;
195 unsigned long cfg = read_c0_conf();
196
197 size1 = r3k_cache_size(ST0_ISC);
198 write_c0_conf(cfg ^ R30XX_CONF_AC);
199 size2 = r3k_cache_size(ST0_ISC);
200 write_c0_conf(cfg);
201 return size1 != size2;
202#else
203 return 0;
204#endif
205}
206
207/*
208 * Get the FPU Implementation/Revision.
209 */
210static inline unsigned long cpu_get_fpu_id(void)
211{
212 unsigned long tmp, fpu_id;
213
214 tmp = read_c0_status();
215 __enable_fpu();
216 fpu_id = read_32bit_cp1_register(CP1_REVISION);
217 write_c0_status(tmp);
218 return fpu_id;
219}
220
221/*
222 * Check the CPU has an FPU the official way.
223 */
224static inline int __cpu_has_fpu(void)
225{
226 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
227}
228
Ralf Baechle02cf2112005-10-01 13:06:32 +0100229#define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700230 | MIPS_CPU_COUNTER)
231
232static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
233{
234 switch (c->processor_id & 0xff00) {
235 case PRID_IMP_R2000:
236 c->cputype = CPU_R2000;
237 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100238 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
239 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240 if (__cpu_has_fpu())
241 c->options |= MIPS_CPU_FPU;
242 c->tlbsize = 64;
243 break;
244 case PRID_IMP_R3000:
245 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
246 if (cpu_has_confreg())
247 c->cputype = CPU_R3081E;
248 else
249 c->cputype = CPU_R3000A;
250 else
251 c->cputype = CPU_R3000;
252 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100253 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
254 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 if (__cpu_has_fpu())
256 c->options |= MIPS_CPU_FPU;
257 c->tlbsize = 64;
258 break;
259 case PRID_IMP_R4000:
260 if (read_c0_config() & CONF_SC) {
261 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
262 c->cputype = CPU_R4400PC;
263 else
264 c->cputype = CPU_R4000PC;
265 } else {
266 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
267 c->cputype = CPU_R4400SC;
268 else
269 c->cputype = CPU_R4000SC;
270 }
271
272 c->isa_level = MIPS_CPU_ISA_III;
273 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
274 MIPS_CPU_WATCH | MIPS_CPU_VCE |
275 MIPS_CPU_LLSC;
276 c->tlbsize = 48;
277 break;
278 case PRID_IMP_VR41XX:
279 switch (c->processor_id & 0xf0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700280 case PRID_REV_VR4111:
281 c->cputype = CPU_VR4111;
282 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700283 case PRID_REV_VR4121:
284 c->cputype = CPU_VR4121;
285 break;
286 case PRID_REV_VR4122:
287 if ((c->processor_id & 0xf) < 0x3)
288 c->cputype = CPU_VR4122;
289 else
290 c->cputype = CPU_VR4181A;
291 break;
292 case PRID_REV_VR4130:
293 if ((c->processor_id & 0xf) < 0x4)
294 c->cputype = CPU_VR4131;
295 else
296 c->cputype = CPU_VR4133;
297 break;
298 default:
299 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
300 c->cputype = CPU_VR41XX;
301 break;
302 }
303 c->isa_level = MIPS_CPU_ISA_III;
304 c->options = R4K_OPTS;
305 c->tlbsize = 32;
306 break;
307 case PRID_IMP_R4300:
308 c->cputype = CPU_R4300;
309 c->isa_level = MIPS_CPU_ISA_III;
310 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
311 MIPS_CPU_LLSC;
312 c->tlbsize = 32;
313 break;
314 case PRID_IMP_R4600:
315 c->cputype = CPU_R4600;
316 c->isa_level = MIPS_CPU_ISA_III;
Thiemo Seufer075e7502005-07-27 21:48:12 +0000317 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
318 MIPS_CPU_LLSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 c->tlbsize = 48;
320 break;
321 #if 0
322 case PRID_IMP_R4650:
323 /*
324 * This processor doesn't have an MMU, so it's not
325 * "real easy" to run Linux on it. It is left purely
326 * for documentation. Commented out because it shares
327 * it's c0_prid id number with the TX3900.
328 */
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000329 c->cputype = CPU_R4650;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330 c->isa_level = MIPS_CPU_ISA_III;
331 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
332 c->tlbsize = 48;
333 break;
334 #endif
335 case PRID_IMP_TX39:
336 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100337 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700338
339 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
340 c->cputype = CPU_TX3927;
341 c->tlbsize = 64;
342 } else {
343 switch (c->processor_id & 0xff) {
344 case PRID_REV_TX3912:
345 c->cputype = CPU_TX3912;
346 c->tlbsize = 32;
347 break;
348 case PRID_REV_TX3922:
349 c->cputype = CPU_TX3922;
350 c->tlbsize = 64;
351 break;
352 default:
353 c->cputype = CPU_UNKNOWN;
354 break;
355 }
356 }
357 break;
358 case PRID_IMP_R4700:
359 c->cputype = CPU_R4700;
360 c->isa_level = MIPS_CPU_ISA_III;
361 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
362 MIPS_CPU_LLSC;
363 c->tlbsize = 48;
364 break;
365 case PRID_IMP_TX49:
366 c->cputype = CPU_TX49XX;
367 c->isa_level = MIPS_CPU_ISA_III;
368 c->options = R4K_OPTS | MIPS_CPU_LLSC;
369 if (!(c->processor_id & 0x08))
370 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
371 c->tlbsize = 48;
372 break;
373 case PRID_IMP_R5000:
374 c->cputype = CPU_R5000;
375 c->isa_level = MIPS_CPU_ISA_IV;
376 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
377 MIPS_CPU_LLSC;
378 c->tlbsize = 48;
379 break;
380 case PRID_IMP_R5432:
381 c->cputype = CPU_R5432;
382 c->isa_level = MIPS_CPU_ISA_IV;
383 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
384 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
385 c->tlbsize = 48;
386 break;
387 case PRID_IMP_R5500:
388 c->cputype = CPU_R5500;
389 c->isa_level = MIPS_CPU_ISA_IV;
390 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
391 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
392 c->tlbsize = 48;
393 break;
394 case PRID_IMP_NEVADA:
395 c->cputype = CPU_NEVADA;
396 c->isa_level = MIPS_CPU_ISA_IV;
397 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
398 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
399 c->tlbsize = 48;
400 break;
401 case PRID_IMP_R6000:
402 c->cputype = CPU_R6000;
403 c->isa_level = MIPS_CPU_ISA_II;
404 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
405 MIPS_CPU_LLSC;
406 c->tlbsize = 32;
407 break;
408 case PRID_IMP_R6000A:
409 c->cputype = CPU_R6000A;
410 c->isa_level = MIPS_CPU_ISA_II;
411 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
412 MIPS_CPU_LLSC;
413 c->tlbsize = 32;
414 break;
415 case PRID_IMP_RM7000:
416 c->cputype = CPU_RM7000;
417 c->isa_level = MIPS_CPU_ISA_IV;
418 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
419 MIPS_CPU_LLSC;
420 /*
421 * Undocumented RM7000: Bit 29 in the info register of
422 * the RM7000 v2.0 indicates if the TLB has 48 or 64
423 * entries.
424 *
425 * 29 1 => 64 entry JTLB
426 * 0 => 48 entry JTLB
427 */
428 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
429 break;
430 case PRID_IMP_RM9000:
431 c->cputype = CPU_RM9000;
432 c->isa_level = MIPS_CPU_ISA_IV;
433 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
434 MIPS_CPU_LLSC;
435 /*
436 * Bit 29 in the info register of the RM9000
437 * indicates if the TLB has 48 or 64 entries.
438 *
439 * 29 1 => 64 entry JTLB
440 * 0 => 48 entry JTLB
441 */
442 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
443 break;
444 case PRID_IMP_R8000:
445 c->cputype = CPU_R8000;
446 c->isa_level = MIPS_CPU_ISA_IV;
447 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
448 MIPS_CPU_FPU | MIPS_CPU_32FPR |
449 MIPS_CPU_LLSC;
450 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
451 break;
452 case PRID_IMP_R10000:
453 c->cputype = CPU_R10000;
454 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000455 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 MIPS_CPU_FPU | MIPS_CPU_32FPR |
457 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
458 MIPS_CPU_LLSC;
459 c->tlbsize = 64;
460 break;
461 case PRID_IMP_R12000:
462 c->cputype = CPU_R12000;
463 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000464 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465 MIPS_CPU_FPU | MIPS_CPU_32FPR |
466 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
467 MIPS_CPU_LLSC;
468 c->tlbsize = 64;
469 break;
Kumba44d921b2006-05-16 22:23:59 -0400470 case PRID_IMP_R14000:
471 c->cputype = CPU_R14000;
472 c->isa_level = MIPS_CPU_ISA_IV;
473 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
474 MIPS_CPU_FPU | MIPS_CPU_32FPR |
475 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
476 MIPS_CPU_LLSC;
477 c->tlbsize = 64;
478 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479 }
480}
481
Ralf Baechleb4672d32005-12-08 14:04:24 +0000482static char unknown_isa[] __initdata = KERN_ERR \
483 "Unsupported ISA type, c0.config0: %d.";
484
Ralf Baechle41943182005-05-05 16:45:59 +0000485static inline unsigned int decode_config0(struct cpuinfo_mips *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700486{
Ralf Baechle41943182005-05-05 16:45:59 +0000487 unsigned int config0;
488 int isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700489
Ralf Baechle41943182005-05-05 16:45:59 +0000490 config0 = read_c0_config();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700491
Ralf Baechle41943182005-05-05 16:45:59 +0000492 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
Ralf Baechle02cf2112005-10-01 13:06:32 +0100493 c->options |= MIPS_CPU_TLB;
Ralf Baechle41943182005-05-05 16:45:59 +0000494 isa = (config0 & MIPS_CONF_AT) >> 13;
495 switch (isa) {
496 case 0:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100497 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000498 case 0:
499 c->isa_level = MIPS_CPU_ISA_M32R1;
500 break;
501 case 1:
502 c->isa_level = MIPS_CPU_ISA_M32R2;
503 break;
504 default:
505 goto unknown;
506 }
Ralf Baechle41943182005-05-05 16:45:59 +0000507 break;
508 case 2:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100509 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000510 case 0:
511 c->isa_level = MIPS_CPU_ISA_M64R1;
512 break;
513 case 1:
514 c->isa_level = MIPS_CPU_ISA_M64R2;
515 break;
516 default:
517 goto unknown;
518 }
Ralf Baechle41943182005-05-05 16:45:59 +0000519 break;
520 default:
Ralf Baechleb4672d32005-12-08 14:04:24 +0000521 goto unknown;
Ralf Baechle41943182005-05-05 16:45:59 +0000522 }
523
524 return config0 & MIPS_CONF_M;
Ralf Baechleb4672d32005-12-08 14:04:24 +0000525
526unknown:
527 panic(unknown_isa, config0);
Ralf Baechle41943182005-05-05 16:45:59 +0000528}
529
530static inline unsigned int decode_config1(struct cpuinfo_mips *c)
531{
532 unsigned int config1;
533
Linus Torvalds1da177e2005-04-16 15:20:36 -0700534 config1 = read_c0_config1();
Ralf Baechle41943182005-05-05 16:45:59 +0000535
536 if (config1 & MIPS_CONF1_MD)
537 c->ases |= MIPS_ASE_MDMX;
538 if (config1 & MIPS_CONF1_WR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539 c->options |= MIPS_CPU_WATCH;
Ralf Baechle41943182005-05-05 16:45:59 +0000540 if (config1 & MIPS_CONF1_CA)
541 c->ases |= MIPS_ASE_MIPS16;
542 if (config1 & MIPS_CONF1_EP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700543 c->options |= MIPS_CPU_EJTAG;
Ralf Baechle41943182005-05-05 16:45:59 +0000544 if (config1 & MIPS_CONF1_FP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 c->options |= MIPS_CPU_FPU;
546 c->options |= MIPS_CPU_32FPR;
547 }
Ralf Baechle41943182005-05-05 16:45:59 +0000548 if (cpu_has_tlb)
549 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
550
551 return config1 & MIPS_CONF_M;
552}
553
554static inline unsigned int decode_config2(struct cpuinfo_mips *c)
555{
556 unsigned int config2;
557
558 config2 = read_c0_config2();
559
560 if (config2 & MIPS_CONF2_SL)
561 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
562
563 return config2 & MIPS_CONF_M;
564}
565
566static inline unsigned int decode_config3(struct cpuinfo_mips *c)
567{
568 unsigned int config3;
569
570 config3 = read_c0_config3();
571
572 if (config3 & MIPS_CONF3_SM)
573 c->ases |= MIPS_ASE_SMARTMIPS;
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000574 if (config3 & MIPS_CONF3_DSP)
575 c->ases |= MIPS_ASE_DSP;
Ralf Baechle8f406112005-07-14 07:34:18 +0000576 if (config3 & MIPS_CONF3_VINT)
577 c->options |= MIPS_CPU_VINT;
578 if (config3 & MIPS_CONF3_VEIC)
579 c->options |= MIPS_CPU_VEIC;
580 if (config3 & MIPS_CONF3_MT)
581 c->ases |= MIPS_ASE_MIPSMT;
Ralf Baechle41943182005-05-05 16:45:59 +0000582
583 return config3 & MIPS_CONF_M;
584}
585
Thiemo Seuferc36cd4b2006-07-03 13:30:01 +0100586static void __init decode_configs(struct cpuinfo_mips *c)
Ralf Baechle41943182005-05-05 16:45:59 +0000587{
588 /* MIPS32 or MIPS64 compliant CPU. */
Ralf Baechle02cf2112005-10-01 13:06:32 +0100589 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
590 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
Ralf Baechle41943182005-05-05 16:45:59 +0000591
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
593
Ralf Baechle41943182005-05-05 16:45:59 +0000594 /* Read Config registers. */
595 if (!decode_config0(c))
596 return; /* actually worth a panic() */
597 if (!decode_config1(c))
598 return;
599 if (!decode_config2(c))
600 return;
601 if (!decode_config3(c))
602 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700603}
604
605static inline void cpu_probe_mips(struct cpuinfo_mips *c)
606{
Ralf Baechle41943182005-05-05 16:45:59 +0000607 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 switch (c->processor_id & 0xff00) {
609 case PRID_IMP_4KC:
610 c->cputype = CPU_4KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 break;
612 case PRID_IMP_4KEC:
613 c->cputype = CPU_4KEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 break;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000615 case PRID_IMP_4KECR2:
616 c->cputype = CPU_4KEC;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000617 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 case PRID_IMP_4KSC:
Ralf Baechle8afcb5d2005-10-04 15:01:26 +0100619 case PRID_IMP_4KSD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 c->cputype = CPU_4KSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
622 case PRID_IMP_5KC:
623 c->cputype = CPU_5KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 break;
625 case PRID_IMP_20KC:
626 c->cputype = CPU_20KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
628 case PRID_IMP_24K:
Ralf Baechlee50c0a82005-05-31 11:49:19 +0000629 case PRID_IMP_24KE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 c->cputype = CPU_24K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700631 break;
632 case PRID_IMP_25KF:
633 c->cputype = CPU_25KF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 break;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000635 case PRID_IMP_34K:
636 c->cputype = CPU_34K;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000637 break;
Chris Dearmanc6209532006-05-02 14:08:46 +0100638 case PRID_IMP_74K:
639 c->cputype = CPU_74K;
640 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700641 }
642}
643
644static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
645{
Ralf Baechle41943182005-05-05 16:45:59 +0000646 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647 switch (c->processor_id & 0xff00) {
648 case PRID_IMP_AU1_REV1:
649 case PRID_IMP_AU1_REV2:
650 switch ((c->processor_id >> 24) & 0xff) {
651 case 0:
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000652 c->cputype = CPU_AU1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 break;
654 case 1:
655 c->cputype = CPU_AU1500;
656 break;
657 case 2:
658 c->cputype = CPU_AU1100;
659 break;
660 case 3:
661 c->cputype = CPU_AU1550;
662 break;
Pete Popove3ad1c22005-03-01 06:33:16 +0000663 case 4:
664 c->cputype = CPU_AU1200;
665 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 default:
667 panic("Unknown Au Core!");
668 break;
669 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700670 break;
671 }
672}
673
674static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
675{
Ralf Baechle41943182005-05-05 16:45:59 +0000676 decode_configs(c);
Ralf Baechle02cf2112005-10-01 13:06:32 +0100677
678 /*
679 * For historical reasons the SB1 comes with it's own variant of
680 * cache code which eventually will be folded into c-r4k.c. Until
681 * then we pretend it's got it's own cache architecture.
682 */
Andrew Isaacsond121ced2005-10-19 23:54:43 -0700683 c->options &= ~MIPS_CPU_4K_CACHE;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100684 c->options |= MIPS_CPU_SB1_CACHE;
685
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686 switch (c->processor_id & 0xff00) {
687 case PRID_IMP_SB1:
688 c->cputype = CPU_SB1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 /* FPU in pass1 is known to have issues. */
Ralf Baechleaa323742006-05-29 00:02:12 +0100690 if ((c->processor_id & 0xff) < 0x02)
Ralf Baechle010b8532006-01-29 18:42:08 +0000691 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 break;
Andrew Isaacson93ce2f522005-10-19 23:56:20 -0700693 case PRID_IMP_SB1A:
694 c->cputype = CPU_SB1A;
695 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 }
697}
698
699static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
700{
Ralf Baechle41943182005-05-05 16:45:59 +0000701 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702 switch (c->processor_id & 0xff00) {
703 case PRID_IMP_SR71000:
704 c->cputype = CPU_SR71000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700705 c->scache.ways = 8;
706 c->tlbsize = 64;
707 break;
708 }
709}
710
Pete Popovbdf21b12005-07-14 17:47:57 +0000711static inline void cpu_probe_philips(struct cpuinfo_mips *c)
712{
713 decode_configs(c);
714 switch (c->processor_id & 0xff00) {
715 case PRID_IMP_PR4450:
716 c->cputype = CPU_PR4450;
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000717 c->isa_level = MIPS_CPU_ISA_M32R1;
Pete Popovbdf21b12005-07-14 17:47:57 +0000718 break;
719 default:
720 panic("Unknown Philips Core!"); /* REVISIT: die? */
721 break;
722 }
723}
724
725
Linus Torvalds1da177e2005-04-16 15:20:36 -0700726__init void cpu_probe(void)
727{
728 struct cpuinfo_mips *c = &current_cpu_data;
729
730 c->processor_id = PRID_IMP_UNKNOWN;
731 c->fpu_id = FPIR_IMP_NONE;
732 c->cputype = CPU_UNKNOWN;
733
734 c->processor_id = read_c0_prid();
735 switch (c->processor_id & 0xff0000) {
736 case PRID_COMP_LEGACY:
737 cpu_probe_legacy(c);
738 break;
739 case PRID_COMP_MIPS:
740 cpu_probe_mips(c);
741 break;
742 case PRID_COMP_ALCHEMY:
743 cpu_probe_alchemy(c);
744 break;
745 case PRID_COMP_SIBYTE:
746 cpu_probe_sibyte(c);
747 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 case PRID_COMP_SANDCRAFT:
749 cpu_probe_sandcraft(c);
750 break;
Pete Popovbdf21b12005-07-14 17:47:57 +0000751 case PRID_COMP_PHILIPS:
752 cpu_probe_philips(c);
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000753 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 default:
755 c->cputype = CPU_UNKNOWN;
756 }
Ralf Baechle41943182005-05-05 16:45:59 +0000757 if (c->options & MIPS_CPU_FPU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758 c->fpu_id = cpu_get_fpu_id();
Ralf Baechle41943182005-05-05 16:45:59 +0000759
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000760 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
Ralf Baechleb4672d32005-12-08 14:04:24 +0000761 c->isa_level == MIPS_CPU_ISA_M32R2 ||
762 c->isa_level == MIPS_CPU_ISA_M64R1 ||
763 c->isa_level == MIPS_CPU_ISA_M64R2) {
Ralf Baechle41943182005-05-05 16:45:59 +0000764 if (c->fpu_id & MIPS_FPIR_3D)
765 c->ases |= MIPS_ASE_MIPS3D;
766 }
767 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700768}
769
770__init void cpu_report(void)
771{
772 struct cpuinfo_mips *c = &current_cpu_data;
773
774 printk("CPU revision is: %08x\n", c->processor_id);
775 if (c->options & MIPS_CPU_FPU)
776 printk("FPU revision is: %08x\n", c->fpu_id);
777}