blob: 9fbf8430c8499972ab80047026c803e64306a253 [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:
138 case CPU_RM9000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139 case CPU_4KC:
140 case CPU_4KEC:
141 case CPU_4KSC:
142 case CPU_5KC:
143/* case CPU_20KC:*/
144 case CPU_24K:
145 case CPU_25KF:
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000146 case CPU_34K:
Chris Dearmanc6209532006-05-02 14:08:46 +0100147 case CPU_74K:
Pete Popovbdf21b12005-07-14 17:47:57 +0000148 case CPU_PR4450:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 cpu_wait = r4k_wait;
150 printk(" available.\n");
151 break;
Atsushi Nemoto60a6c372006-06-08 01:09:01 +0900152 case CPU_TX49XX:
153 cpu_wait = r4k_wait_irqoff;
154 printk(" available.\n");
155 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156 case CPU_AU1000:
157 case CPU_AU1100:
158 case CPU_AU1500:
Pete Popove3ad1c22005-03-01 06:33:16 +0000159 case CPU_AU1550:
160 case CPU_AU1200:
Pete Popovfe359bf2005-04-08 08:34:43 +0000161 if (allow_au1k_wait) {
162 cpu_wait = au1k_wait;
163 printk(" available.\n");
164 } else
165 printk(" unavailable.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700166 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167 default:
168 printk(" unavailable.\n");
169 break;
170 }
171}
172
173void __init check_bugs32(void)
174{
175 check_wait();
176}
177
178/*
179 * Probe whether cpu has config register by trying to play with
180 * alternate cache bit and see whether it matters.
181 * It's used by cpu_probe to distinguish between R3000A and R3081.
182 */
183static inline int cpu_has_confreg(void)
184{
185#ifdef CONFIG_CPU_R3000
186 extern unsigned long r3k_cache_size(unsigned long);
187 unsigned long size1, size2;
188 unsigned long cfg = read_c0_conf();
189
190 size1 = r3k_cache_size(ST0_ISC);
191 write_c0_conf(cfg ^ R30XX_CONF_AC);
192 size2 = r3k_cache_size(ST0_ISC);
193 write_c0_conf(cfg);
194 return size1 != size2;
195#else
196 return 0;
197#endif
198}
199
200/*
201 * Get the FPU Implementation/Revision.
202 */
203static inline unsigned long cpu_get_fpu_id(void)
204{
205 unsigned long tmp, fpu_id;
206
207 tmp = read_c0_status();
208 __enable_fpu();
209 fpu_id = read_32bit_cp1_register(CP1_REVISION);
210 write_c0_status(tmp);
211 return fpu_id;
212}
213
214/*
215 * Check the CPU has an FPU the official way.
216 */
217static inline int __cpu_has_fpu(void)
218{
219 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
220}
221
Ralf Baechle02cf2112005-10-01 13:06:32 +0100222#define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700223 | MIPS_CPU_COUNTER)
224
225static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
226{
227 switch (c->processor_id & 0xff00) {
228 case PRID_IMP_R2000:
229 c->cputype = CPU_R2000;
230 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100231 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
232 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233 if (__cpu_has_fpu())
234 c->options |= MIPS_CPU_FPU;
235 c->tlbsize = 64;
236 break;
237 case PRID_IMP_R3000:
238 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
239 if (cpu_has_confreg())
240 c->cputype = CPU_R3081E;
241 else
242 c->cputype = CPU_R3000A;
243 else
244 c->cputype = CPU_R3000;
245 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100246 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
247 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248 if (__cpu_has_fpu())
249 c->options |= MIPS_CPU_FPU;
250 c->tlbsize = 64;
251 break;
252 case PRID_IMP_R4000:
253 if (read_c0_config() & CONF_SC) {
254 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
255 c->cputype = CPU_R4400PC;
256 else
257 c->cputype = CPU_R4000PC;
258 } else {
259 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
260 c->cputype = CPU_R4400SC;
261 else
262 c->cputype = CPU_R4000SC;
263 }
264
265 c->isa_level = MIPS_CPU_ISA_III;
266 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
267 MIPS_CPU_WATCH | MIPS_CPU_VCE |
268 MIPS_CPU_LLSC;
269 c->tlbsize = 48;
270 break;
271 case PRID_IMP_VR41XX:
272 switch (c->processor_id & 0xf0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700273 case PRID_REV_VR4111:
274 c->cputype = CPU_VR4111;
275 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276 case PRID_REV_VR4121:
277 c->cputype = CPU_VR4121;
278 break;
279 case PRID_REV_VR4122:
280 if ((c->processor_id & 0xf) < 0x3)
281 c->cputype = CPU_VR4122;
282 else
283 c->cputype = CPU_VR4181A;
284 break;
285 case PRID_REV_VR4130:
286 if ((c->processor_id & 0xf) < 0x4)
287 c->cputype = CPU_VR4131;
288 else
289 c->cputype = CPU_VR4133;
290 break;
291 default:
292 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
293 c->cputype = CPU_VR41XX;
294 break;
295 }
296 c->isa_level = MIPS_CPU_ISA_III;
297 c->options = R4K_OPTS;
298 c->tlbsize = 32;
299 break;
300 case PRID_IMP_R4300:
301 c->cputype = CPU_R4300;
302 c->isa_level = MIPS_CPU_ISA_III;
303 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
304 MIPS_CPU_LLSC;
305 c->tlbsize = 32;
306 break;
307 case PRID_IMP_R4600:
308 c->cputype = CPU_R4600;
309 c->isa_level = MIPS_CPU_ISA_III;
Thiemo Seufer075e7502005-07-27 21:48:12 +0000310 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
311 MIPS_CPU_LLSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700312 c->tlbsize = 48;
313 break;
314 #if 0
315 case PRID_IMP_R4650:
316 /*
317 * This processor doesn't have an MMU, so it's not
318 * "real easy" to run Linux on it. It is left purely
319 * for documentation. Commented out because it shares
320 * it's c0_prid id number with the TX3900.
321 */
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000322 c->cputype = CPU_R4650;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700323 c->isa_level = MIPS_CPU_ISA_III;
324 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
325 c->tlbsize = 48;
326 break;
327 #endif
328 case PRID_IMP_TX39:
329 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100330 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700331
332 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
333 c->cputype = CPU_TX3927;
334 c->tlbsize = 64;
335 } else {
336 switch (c->processor_id & 0xff) {
337 case PRID_REV_TX3912:
338 c->cputype = CPU_TX3912;
339 c->tlbsize = 32;
340 break;
341 case PRID_REV_TX3922:
342 c->cputype = CPU_TX3922;
343 c->tlbsize = 64;
344 break;
345 default:
346 c->cputype = CPU_UNKNOWN;
347 break;
348 }
349 }
350 break;
351 case PRID_IMP_R4700:
352 c->cputype = CPU_R4700;
353 c->isa_level = MIPS_CPU_ISA_III;
354 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
355 MIPS_CPU_LLSC;
356 c->tlbsize = 48;
357 break;
358 case PRID_IMP_TX49:
359 c->cputype = CPU_TX49XX;
360 c->isa_level = MIPS_CPU_ISA_III;
361 c->options = R4K_OPTS | MIPS_CPU_LLSC;
362 if (!(c->processor_id & 0x08))
363 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
364 c->tlbsize = 48;
365 break;
366 case PRID_IMP_R5000:
367 c->cputype = CPU_R5000;
368 c->isa_level = MIPS_CPU_ISA_IV;
369 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
370 MIPS_CPU_LLSC;
371 c->tlbsize = 48;
372 break;
373 case PRID_IMP_R5432:
374 c->cputype = CPU_R5432;
375 c->isa_level = MIPS_CPU_ISA_IV;
376 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
377 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
378 c->tlbsize = 48;
379 break;
380 case PRID_IMP_R5500:
381 c->cputype = CPU_R5500;
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_NEVADA:
388 c->cputype = CPU_NEVADA;
389 c->isa_level = MIPS_CPU_ISA_IV;
390 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
391 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
392 c->tlbsize = 48;
393 break;
394 case PRID_IMP_R6000:
395 c->cputype = CPU_R6000;
396 c->isa_level = MIPS_CPU_ISA_II;
397 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
398 MIPS_CPU_LLSC;
399 c->tlbsize = 32;
400 break;
401 case PRID_IMP_R6000A:
402 c->cputype = CPU_R6000A;
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_RM7000:
409 c->cputype = CPU_RM7000;
410 c->isa_level = MIPS_CPU_ISA_IV;
411 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
412 MIPS_CPU_LLSC;
413 /*
414 * Undocumented RM7000: Bit 29 in the info register of
415 * the RM7000 v2.0 indicates if the TLB has 48 or 64
416 * entries.
417 *
418 * 29 1 => 64 entry JTLB
419 * 0 => 48 entry JTLB
420 */
421 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
422 break;
423 case PRID_IMP_RM9000:
424 c->cputype = CPU_RM9000;
425 c->isa_level = MIPS_CPU_ISA_IV;
426 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
427 MIPS_CPU_LLSC;
428 /*
429 * Bit 29 in the info register of the RM9000
430 * indicates if the TLB has 48 or 64 entries.
431 *
432 * 29 1 => 64 entry JTLB
433 * 0 => 48 entry JTLB
434 */
435 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
436 break;
437 case PRID_IMP_R8000:
438 c->cputype = CPU_R8000;
439 c->isa_level = MIPS_CPU_ISA_IV;
440 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
441 MIPS_CPU_FPU | MIPS_CPU_32FPR |
442 MIPS_CPU_LLSC;
443 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
444 break;
445 case PRID_IMP_R10000:
446 c->cputype = CPU_R10000;
447 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000448 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449 MIPS_CPU_FPU | MIPS_CPU_32FPR |
450 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
451 MIPS_CPU_LLSC;
452 c->tlbsize = 64;
453 break;
454 case PRID_IMP_R12000:
455 c->cputype = CPU_R12000;
456 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000457 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700458 MIPS_CPU_FPU | MIPS_CPU_32FPR |
459 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
460 MIPS_CPU_LLSC;
461 c->tlbsize = 64;
462 break;
Kumba44d921b2006-05-16 22:23:59 -0400463 case PRID_IMP_R14000:
464 c->cputype = CPU_R14000;
465 c->isa_level = MIPS_CPU_ISA_IV;
466 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
467 MIPS_CPU_FPU | MIPS_CPU_32FPR |
468 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
469 MIPS_CPU_LLSC;
470 c->tlbsize = 64;
471 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 }
473}
474
Ralf Baechleb4672d32005-12-08 14:04:24 +0000475static char unknown_isa[] __initdata = KERN_ERR \
476 "Unsupported ISA type, c0.config0: %d.";
477
Ralf Baechle41943182005-05-05 16:45:59 +0000478static inline unsigned int decode_config0(struct cpuinfo_mips *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Ralf Baechle41943182005-05-05 16:45:59 +0000480 unsigned int config0;
481 int isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482
Ralf Baechle41943182005-05-05 16:45:59 +0000483 config0 = read_c0_config();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
Ralf Baechle41943182005-05-05 16:45:59 +0000485 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
Ralf Baechle02cf2112005-10-01 13:06:32 +0100486 c->options |= MIPS_CPU_TLB;
Ralf Baechle41943182005-05-05 16:45:59 +0000487 isa = (config0 & MIPS_CONF_AT) >> 13;
488 switch (isa) {
489 case 0:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100490 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000491 case 0:
492 c->isa_level = MIPS_CPU_ISA_M32R1;
493 break;
494 case 1:
495 c->isa_level = MIPS_CPU_ISA_M32R2;
496 break;
497 default:
498 goto unknown;
499 }
Ralf Baechle41943182005-05-05 16:45:59 +0000500 break;
501 case 2:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100502 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000503 case 0:
504 c->isa_level = MIPS_CPU_ISA_M64R1;
505 break;
506 case 1:
507 c->isa_level = MIPS_CPU_ISA_M64R2;
508 break;
509 default:
510 goto unknown;
511 }
Ralf Baechle41943182005-05-05 16:45:59 +0000512 break;
513 default:
Ralf Baechleb4672d32005-12-08 14:04:24 +0000514 goto unknown;
Ralf Baechle41943182005-05-05 16:45:59 +0000515 }
516
517 return config0 & MIPS_CONF_M;
Ralf Baechleb4672d32005-12-08 14:04:24 +0000518
519unknown:
520 panic(unknown_isa, config0);
Ralf Baechle41943182005-05-05 16:45:59 +0000521}
522
523static inline unsigned int decode_config1(struct cpuinfo_mips *c)
524{
525 unsigned int config1;
526
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527 config1 = read_c0_config1();
Ralf Baechle41943182005-05-05 16:45:59 +0000528
529 if (config1 & MIPS_CONF1_MD)
530 c->ases |= MIPS_ASE_MDMX;
531 if (config1 & MIPS_CONF1_WR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 c->options |= MIPS_CPU_WATCH;
Ralf Baechle41943182005-05-05 16:45:59 +0000533 if (config1 & MIPS_CONF1_CA)
534 c->ases |= MIPS_ASE_MIPS16;
535 if (config1 & MIPS_CONF1_EP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536 c->options |= MIPS_CPU_EJTAG;
Ralf Baechle41943182005-05-05 16:45:59 +0000537 if (config1 & MIPS_CONF1_FP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538 c->options |= MIPS_CPU_FPU;
539 c->options |= MIPS_CPU_32FPR;
540 }
Ralf Baechle41943182005-05-05 16:45:59 +0000541 if (cpu_has_tlb)
542 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
543
544 return config1 & MIPS_CONF_M;
545}
546
547static inline unsigned int decode_config2(struct cpuinfo_mips *c)
548{
549 unsigned int config2;
550
551 config2 = read_c0_config2();
552
553 if (config2 & MIPS_CONF2_SL)
554 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
555
556 return config2 & MIPS_CONF_M;
557}
558
559static inline unsigned int decode_config3(struct cpuinfo_mips *c)
560{
561 unsigned int config3;
562
563 config3 = read_c0_config3();
564
565 if (config3 & MIPS_CONF3_SM)
566 c->ases |= MIPS_ASE_SMARTMIPS;
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000567 if (config3 & MIPS_CONF3_DSP)
568 c->ases |= MIPS_ASE_DSP;
Ralf Baechle8f406112005-07-14 07:34:18 +0000569 if (config3 & MIPS_CONF3_VINT)
570 c->options |= MIPS_CPU_VINT;
571 if (config3 & MIPS_CONF3_VEIC)
572 c->options |= MIPS_CPU_VEIC;
573 if (config3 & MIPS_CONF3_MT)
574 c->ases |= MIPS_ASE_MIPSMT;
Ralf Baechle41943182005-05-05 16:45:59 +0000575
576 return config3 & MIPS_CONF_M;
577}
578
Thiemo Seuferc36cd4b2006-07-03 13:30:01 +0100579static void __init decode_configs(struct cpuinfo_mips *c)
Ralf Baechle41943182005-05-05 16:45:59 +0000580{
581 /* MIPS32 or MIPS64 compliant CPU. */
Ralf Baechle02cf2112005-10-01 13:06:32 +0100582 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
583 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
Ralf Baechle41943182005-05-05 16:45:59 +0000584
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
586
Ralf Baechle41943182005-05-05 16:45:59 +0000587 /* Read Config registers. */
588 if (!decode_config0(c))
589 return; /* actually worth a panic() */
590 if (!decode_config1(c))
591 return;
592 if (!decode_config2(c))
593 return;
594 if (!decode_config3(c))
595 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596}
597
598static inline void cpu_probe_mips(struct cpuinfo_mips *c)
599{
Ralf Baechle41943182005-05-05 16:45:59 +0000600 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 switch (c->processor_id & 0xff00) {
602 case PRID_IMP_4KC:
603 c->cputype = CPU_4KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700604 break;
605 case PRID_IMP_4KEC:
606 c->cputype = CPU_4KEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 break;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000608 case PRID_IMP_4KECR2:
609 c->cputype = CPU_4KEC;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000610 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 case PRID_IMP_4KSC:
Ralf Baechle8afcb5d2005-10-04 15:01:26 +0100612 case PRID_IMP_4KSD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700613 c->cputype = CPU_4KSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 break;
615 case PRID_IMP_5KC:
616 c->cputype = CPU_5KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 break;
618 case PRID_IMP_20KC:
619 c->cputype = CPU_20KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620 break;
621 case PRID_IMP_24K:
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000622 case PRID_IMP_24KE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 c->cputype = CPU_24K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624 break;
625 case PRID_IMP_25KF:
626 c->cputype = CPU_25KF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700627 break;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000628 case PRID_IMP_34K:
629 c->cputype = CPU_34K;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000630 break;
Chris Dearmanc6209532006-05-02 14:08:46 +0100631 case PRID_IMP_74K:
632 c->cputype = CPU_74K;
633 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 }
635}
636
637static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
638{
Ralf Baechle41943182005-05-05 16:45:59 +0000639 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 switch (c->processor_id & 0xff00) {
641 case PRID_IMP_AU1_REV1:
642 case PRID_IMP_AU1_REV2:
643 switch ((c->processor_id >> 24) & 0xff) {
644 case 0:
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000645 c->cputype = CPU_AU1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700646 break;
647 case 1:
648 c->cputype = CPU_AU1500;
649 break;
650 case 2:
651 c->cputype = CPU_AU1100;
652 break;
653 case 3:
654 c->cputype = CPU_AU1550;
655 break;
Pete Popove3ad1c22005-03-01 06:33:16 +0000656 case 4:
657 c->cputype = CPU_AU1200;
658 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700659 default:
660 panic("Unknown Au Core!");
661 break;
662 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663 break;
664 }
665}
666
667static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
668{
Ralf Baechle41943182005-05-05 16:45:59 +0000669 decode_configs(c);
Ralf Baechle02cf2112005-10-01 13:06:32 +0100670
671 /*
672 * For historical reasons the SB1 comes with it's own variant of
673 * cache code which eventually will be folded into c-r4k.c. Until
674 * then we pretend it's got it's own cache architecture.
675 */
Andrew Isaacsond121ced2005-10-19 23:54:43 -0700676 c->options &= ~MIPS_CPU_4K_CACHE;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100677 c->options |= MIPS_CPU_SB1_CACHE;
678
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 switch (c->processor_id & 0xff00) {
680 case PRID_IMP_SB1:
681 c->cputype = CPU_SB1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 /* FPU in pass1 is known to have issues. */
Ralf Baechleaa323742006-05-29 00:02:12 +0100683 if ((c->processor_id & 0xff) < 0x02)
Ralf Baechle010b8532006-01-29 18:42:08 +0000684 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 break;
Andrew Isaacson93ce2f522005-10-19 23:56:20 -0700686 case PRID_IMP_SB1A:
687 c->cputype = CPU_SB1A;
688 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 }
690}
691
692static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
693{
Ralf Baechle41943182005-05-05 16:45:59 +0000694 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 switch (c->processor_id & 0xff00) {
696 case PRID_IMP_SR71000:
697 c->cputype = CPU_SR71000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698 c->scache.ways = 8;
699 c->tlbsize = 64;
700 break;
701 }
702}
703
Pete Popovbdf21b12005-07-14 17:47:57 +0000704static inline void cpu_probe_philips(struct cpuinfo_mips *c)
705{
706 decode_configs(c);
707 switch (c->processor_id & 0xff00) {
708 case PRID_IMP_PR4450:
709 c->cputype = CPU_PR4450;
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000710 c->isa_level = MIPS_CPU_ISA_M32R1;
Pete Popovbdf21b12005-07-14 17:47:57 +0000711 break;
712 default:
713 panic("Unknown Philips Core!"); /* REVISIT: die? */
714 break;
715 }
716}
717
718
Linus Torvalds1da177e2005-04-16 15:20:36 -0700719__init void cpu_probe(void)
720{
721 struct cpuinfo_mips *c = &current_cpu_data;
722
723 c->processor_id = PRID_IMP_UNKNOWN;
724 c->fpu_id = FPIR_IMP_NONE;
725 c->cputype = CPU_UNKNOWN;
726
727 c->processor_id = read_c0_prid();
728 switch (c->processor_id & 0xff0000) {
729 case PRID_COMP_LEGACY:
730 cpu_probe_legacy(c);
731 break;
732 case PRID_COMP_MIPS:
733 cpu_probe_mips(c);
734 break;
735 case PRID_COMP_ALCHEMY:
736 cpu_probe_alchemy(c);
737 break;
738 case PRID_COMP_SIBYTE:
739 cpu_probe_sibyte(c);
740 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 case PRID_COMP_SANDCRAFT:
742 cpu_probe_sandcraft(c);
743 break;
Pete Popovbdf21b12005-07-14 17:47:57 +0000744 case PRID_COMP_PHILIPS:
745 cpu_probe_philips(c);
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000746 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747 default:
748 c->cputype = CPU_UNKNOWN;
749 }
Ralf Baechle41943182005-05-05 16:45:59 +0000750 if (c->options & MIPS_CPU_FPU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 c->fpu_id = cpu_get_fpu_id();
Ralf Baechle41943182005-05-05 16:45:59 +0000752
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000753 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
Ralf Baechleb4672d32005-12-08 14:04:24 +0000754 c->isa_level == MIPS_CPU_ISA_M32R2 ||
755 c->isa_level == MIPS_CPU_ISA_M64R1 ||
756 c->isa_level == MIPS_CPU_ISA_M64R2) {
Ralf Baechle41943182005-05-05 16:45:59 +0000757 if (c->fpu_id & MIPS_FPIR_3D)
758 c->ases |= MIPS_ASE_MIPS3D;
759 }
760 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700761}
762
763__init void cpu_report(void)
764{
765 struct cpuinfo_mips *c = &current_cpu_data;
766
767 printk("CPU revision is: %08x\n", c->processor_id);
768 if (c->options & MIPS_CPU_FPU)
769 printk("FPU revision is: %08x\n", c->fpu_id);
770}