blob: 442839e9578c3c21d4b3763c75a653c657d9757d [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
Ralf Baechle55d04df2005-07-13 19:22:45 +0000113 if (nowait) {
Ralf Baechlec2379232006-11-30 01:14:44 +0000114 printk("Wait instruction disabled.\n");
Ralf Baechle55d04df2005-07-13 19:22:45 +0000115 return;
116 }
117
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118 switch (c->cputype) {
119 case CPU_R3081:
120 case CPU_R3081E:
121 cpu_wait = r3081_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 break;
123 case CPU_TX3927:
124 cpu_wait = r39xx_wait;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125 break;
126 case CPU_R4200:
127/* case CPU_R4300: */
128 case CPU_R4600:
129 case CPU_R4640:
130 case CPU_R4650:
131 case CPU_R4700:
132 case CPU_R5000:
133 case CPU_NEVADA:
134 case CPU_RM7000:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135 case CPU_4KC:
136 case CPU_4KEC:
137 case CPU_4KSC:
138 case CPU_5KC:
139/* case CPU_20KC:*/
140 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 Baechle441ee342006-06-02 11:48:11 +0100158 case CPU_RM9000:
Ralf Baechlec2379232006-11-30 01:14:44 +0000159 if ((c->processor_id & 0x00ff) >= 0x40)
Ralf Baechle441ee342006-06-02 11:48:11 +0100160 cpu_wait = r4k_wait;
Ralf Baechle441ee342006-06-02 11:48:11 +0100161 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700162 default:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163 break;
164 }
165}
166
167void __init check_bugs32(void)
168{
169 check_wait();
170}
171
172/*
173 * Probe whether cpu has config register by trying to play with
174 * alternate cache bit and see whether it matters.
175 * It's used by cpu_probe to distinguish between R3000A and R3081.
176 */
177static inline int cpu_has_confreg(void)
178{
179#ifdef CONFIG_CPU_R3000
180 extern unsigned long r3k_cache_size(unsigned long);
181 unsigned long size1, size2;
182 unsigned long cfg = read_c0_conf();
183
184 size1 = r3k_cache_size(ST0_ISC);
185 write_c0_conf(cfg ^ R30XX_CONF_AC);
186 size2 = r3k_cache_size(ST0_ISC);
187 write_c0_conf(cfg);
188 return size1 != size2;
189#else
190 return 0;
191#endif
192}
193
194/*
195 * Get the FPU Implementation/Revision.
196 */
197static inline unsigned long cpu_get_fpu_id(void)
198{
199 unsigned long tmp, fpu_id;
200
201 tmp = read_c0_status();
202 __enable_fpu();
203 fpu_id = read_32bit_cp1_register(CP1_REVISION);
204 write_c0_status(tmp);
205 return fpu_id;
206}
207
208/*
209 * Check the CPU has an FPU the official way.
210 */
211static inline int __cpu_has_fpu(void)
212{
213 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
214}
215
Ralf Baechle02cf2112005-10-01 13:06:32 +0100216#define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
Linus Torvalds1da177e2005-04-16 15:20:36 -0700217 | MIPS_CPU_COUNTER)
218
219static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
220{
221 switch (c->processor_id & 0xff00) {
222 case PRID_IMP_R2000:
223 c->cputype = CPU_R2000;
224 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100225 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
226 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700227 if (__cpu_has_fpu())
228 c->options |= MIPS_CPU_FPU;
229 c->tlbsize = 64;
230 break;
231 case PRID_IMP_R3000:
232 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
233 if (cpu_has_confreg())
234 c->cputype = CPU_R3081E;
235 else
236 c->cputype = CPU_R3000A;
237 else
238 c->cputype = CPU_R3000;
239 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100240 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
241 MIPS_CPU_NOFPUEX;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 if (__cpu_has_fpu())
243 c->options |= MIPS_CPU_FPU;
244 c->tlbsize = 64;
245 break;
246 case PRID_IMP_R4000:
247 if (read_c0_config() & CONF_SC) {
248 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
249 c->cputype = CPU_R4400PC;
250 else
251 c->cputype = CPU_R4000PC;
252 } else {
253 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
254 c->cputype = CPU_R4400SC;
255 else
256 c->cputype = CPU_R4000SC;
257 }
258
259 c->isa_level = MIPS_CPU_ISA_III;
260 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
261 MIPS_CPU_WATCH | MIPS_CPU_VCE |
262 MIPS_CPU_LLSC;
263 c->tlbsize = 48;
264 break;
265 case PRID_IMP_VR41XX:
266 switch (c->processor_id & 0xf0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700267 case PRID_REV_VR4111:
268 c->cputype = CPU_VR4111;
269 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270 case PRID_REV_VR4121:
271 c->cputype = CPU_VR4121;
272 break;
273 case PRID_REV_VR4122:
274 if ((c->processor_id & 0xf) < 0x3)
275 c->cputype = CPU_VR4122;
276 else
277 c->cputype = CPU_VR4181A;
278 break;
279 case PRID_REV_VR4130:
280 if ((c->processor_id & 0xf) < 0x4)
281 c->cputype = CPU_VR4131;
282 else
283 c->cputype = CPU_VR4133;
284 break;
285 default:
286 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
287 c->cputype = CPU_VR41XX;
288 break;
289 }
290 c->isa_level = MIPS_CPU_ISA_III;
291 c->options = R4K_OPTS;
292 c->tlbsize = 32;
293 break;
294 case PRID_IMP_R4300:
295 c->cputype = CPU_R4300;
296 c->isa_level = MIPS_CPU_ISA_III;
297 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
298 MIPS_CPU_LLSC;
299 c->tlbsize = 32;
300 break;
301 case PRID_IMP_R4600:
302 c->cputype = CPU_R4600;
303 c->isa_level = MIPS_CPU_ISA_III;
Thiemo Seufer075e7502005-07-27 21:48:12 +0000304 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
305 MIPS_CPU_LLSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 c->tlbsize = 48;
307 break;
308 #if 0
309 case PRID_IMP_R4650:
310 /*
311 * This processor doesn't have an MMU, so it's not
312 * "real easy" to run Linux on it. It is left purely
313 * for documentation. Commented out because it shares
314 * it's c0_prid id number with the TX3900.
315 */
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000316 c->cputype = CPU_R4650;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700317 c->isa_level = MIPS_CPU_ISA_III;
318 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
319 c->tlbsize = 48;
320 break;
321 #endif
322 case PRID_IMP_TX39:
323 c->isa_level = MIPS_CPU_ISA_I;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100324 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
327 c->cputype = CPU_TX3927;
328 c->tlbsize = 64;
329 } else {
330 switch (c->processor_id & 0xff) {
331 case PRID_REV_TX3912:
332 c->cputype = CPU_TX3912;
333 c->tlbsize = 32;
334 break;
335 case PRID_REV_TX3922:
336 c->cputype = CPU_TX3922;
337 c->tlbsize = 64;
338 break;
339 default:
340 c->cputype = CPU_UNKNOWN;
341 break;
342 }
343 }
344 break;
345 case PRID_IMP_R4700:
346 c->cputype = CPU_R4700;
347 c->isa_level = MIPS_CPU_ISA_III;
348 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
349 MIPS_CPU_LLSC;
350 c->tlbsize = 48;
351 break;
352 case PRID_IMP_TX49:
353 c->cputype = CPU_TX49XX;
354 c->isa_level = MIPS_CPU_ISA_III;
355 c->options = R4K_OPTS | MIPS_CPU_LLSC;
356 if (!(c->processor_id & 0x08))
357 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
358 c->tlbsize = 48;
359 break;
360 case PRID_IMP_R5000:
361 c->cputype = CPU_R5000;
362 c->isa_level = MIPS_CPU_ISA_IV;
363 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
364 MIPS_CPU_LLSC;
365 c->tlbsize = 48;
366 break;
367 case PRID_IMP_R5432:
368 c->cputype = CPU_R5432;
369 c->isa_level = MIPS_CPU_ISA_IV;
370 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
371 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
372 c->tlbsize = 48;
373 break;
374 case PRID_IMP_R5500:
375 c->cputype = CPU_R5500;
376 c->isa_level = MIPS_CPU_ISA_IV;
377 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
378 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
379 c->tlbsize = 48;
380 break;
381 case PRID_IMP_NEVADA:
382 c->cputype = CPU_NEVADA;
383 c->isa_level = MIPS_CPU_ISA_IV;
384 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
385 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
386 c->tlbsize = 48;
387 break;
388 case PRID_IMP_R6000:
389 c->cputype = CPU_R6000;
390 c->isa_level = MIPS_CPU_ISA_II;
391 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
392 MIPS_CPU_LLSC;
393 c->tlbsize = 32;
394 break;
395 case PRID_IMP_R6000A:
396 c->cputype = CPU_R6000A;
397 c->isa_level = MIPS_CPU_ISA_II;
398 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
399 MIPS_CPU_LLSC;
400 c->tlbsize = 32;
401 break;
402 case PRID_IMP_RM7000:
403 c->cputype = CPU_RM7000;
404 c->isa_level = MIPS_CPU_ISA_IV;
405 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
406 MIPS_CPU_LLSC;
407 /*
408 * Undocumented RM7000: Bit 29 in the info register of
409 * the RM7000 v2.0 indicates if the TLB has 48 or 64
410 * entries.
411 *
412 * 29 1 => 64 entry JTLB
413 * 0 => 48 entry JTLB
414 */
415 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
416 break;
417 case PRID_IMP_RM9000:
418 c->cputype = CPU_RM9000;
419 c->isa_level = MIPS_CPU_ISA_IV;
420 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
421 MIPS_CPU_LLSC;
422 /*
423 * Bit 29 in the info register of the RM9000
424 * indicates if the TLB has 48 or 64 entries.
425 *
426 * 29 1 => 64 entry JTLB
427 * 0 => 48 entry JTLB
428 */
429 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
430 break;
431 case PRID_IMP_R8000:
432 c->cputype = CPU_R8000;
433 c->isa_level = MIPS_CPU_ISA_IV;
434 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
435 MIPS_CPU_FPU | MIPS_CPU_32FPR |
436 MIPS_CPU_LLSC;
437 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
438 break;
439 case PRID_IMP_R10000:
440 c->cputype = CPU_R10000;
441 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000442 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 MIPS_CPU_FPU | MIPS_CPU_32FPR |
444 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
445 MIPS_CPU_LLSC;
446 c->tlbsize = 64;
447 break;
448 case PRID_IMP_R12000:
449 c->cputype = CPU_R12000;
450 c->isa_level = MIPS_CPU_ISA_IV;
Ralf Baechle8b366122005-11-22 17:53:59 +0000451 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
Linus Torvalds1da177e2005-04-16 15:20:36 -0700452 MIPS_CPU_FPU | MIPS_CPU_32FPR |
453 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
454 MIPS_CPU_LLSC;
455 c->tlbsize = 64;
456 break;
Kumba44d921b2006-05-16 22:23:59 -0400457 case PRID_IMP_R14000:
458 c->cputype = CPU_R14000;
459 c->isa_level = MIPS_CPU_ISA_IV;
460 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
461 MIPS_CPU_FPU | MIPS_CPU_32FPR |
462 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
463 MIPS_CPU_LLSC;
464 c->tlbsize = 64;
465 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466 }
467}
468
Ralf Baechleb4672d32005-12-08 14:04:24 +0000469static char unknown_isa[] __initdata = KERN_ERR \
470 "Unsupported ISA type, c0.config0: %d.";
471
Ralf Baechle41943182005-05-05 16:45:59 +0000472static inline unsigned int decode_config0(struct cpuinfo_mips *c)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700473{
Ralf Baechle41943182005-05-05 16:45:59 +0000474 unsigned int config0;
475 int isa;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700476
Ralf Baechle41943182005-05-05 16:45:59 +0000477 config0 = read_c0_config();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478
Ralf Baechle41943182005-05-05 16:45:59 +0000479 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
Ralf Baechle02cf2112005-10-01 13:06:32 +0100480 c->options |= MIPS_CPU_TLB;
Ralf Baechle41943182005-05-05 16:45:59 +0000481 isa = (config0 & MIPS_CONF_AT) >> 13;
482 switch (isa) {
483 case 0:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100484 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000485 case 0:
486 c->isa_level = MIPS_CPU_ISA_M32R1;
487 break;
488 case 1:
489 c->isa_level = MIPS_CPU_ISA_M32R2;
490 break;
491 default:
492 goto unknown;
493 }
Ralf Baechle41943182005-05-05 16:45:59 +0000494 break;
495 case 2:
Thiemo Seufer3a01c492006-07-03 13:30:01 +0100496 switch ((config0 & MIPS_CONF_AR) >> 10) {
Ralf Baechleb4672d32005-12-08 14:04:24 +0000497 case 0:
498 c->isa_level = MIPS_CPU_ISA_M64R1;
499 break;
500 case 1:
501 c->isa_level = MIPS_CPU_ISA_M64R2;
502 break;
503 default:
504 goto unknown;
505 }
Ralf Baechle41943182005-05-05 16:45:59 +0000506 break;
507 default:
Ralf Baechleb4672d32005-12-08 14:04:24 +0000508 goto unknown;
Ralf Baechle41943182005-05-05 16:45:59 +0000509 }
510
511 return config0 & MIPS_CONF_M;
Ralf Baechleb4672d32005-12-08 14:04:24 +0000512
513unknown:
514 panic(unknown_isa, config0);
Ralf Baechle41943182005-05-05 16:45:59 +0000515}
516
517static inline unsigned int decode_config1(struct cpuinfo_mips *c)
518{
519 unsigned int config1;
520
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521 config1 = read_c0_config1();
Ralf Baechle41943182005-05-05 16:45:59 +0000522
523 if (config1 & MIPS_CONF1_MD)
524 c->ases |= MIPS_ASE_MDMX;
525 if (config1 & MIPS_CONF1_WR)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526 c->options |= MIPS_CPU_WATCH;
Ralf Baechle41943182005-05-05 16:45:59 +0000527 if (config1 & MIPS_CONF1_CA)
528 c->ases |= MIPS_ASE_MIPS16;
529 if (config1 & MIPS_CONF1_EP)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700530 c->options |= MIPS_CPU_EJTAG;
Ralf Baechle41943182005-05-05 16:45:59 +0000531 if (config1 & MIPS_CONF1_FP) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 c->options |= MIPS_CPU_FPU;
533 c->options |= MIPS_CPU_32FPR;
534 }
Ralf Baechle41943182005-05-05 16:45:59 +0000535 if (cpu_has_tlb)
536 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
537
538 return config1 & MIPS_CONF_M;
539}
540
541static inline unsigned int decode_config2(struct cpuinfo_mips *c)
542{
543 unsigned int config2;
544
545 config2 = read_c0_config2();
546
547 if (config2 & MIPS_CONF2_SL)
548 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
549
550 return config2 & MIPS_CONF_M;
551}
552
553static inline unsigned int decode_config3(struct cpuinfo_mips *c)
554{
555 unsigned int config3;
556
557 config3 = read_c0_config3();
558
559 if (config3 & MIPS_CONF3_SM)
560 c->ases |= MIPS_ASE_SMARTMIPS;
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000561 if (config3 & MIPS_CONF3_DSP)
562 c->ases |= MIPS_ASE_DSP;
Ralf Baechle8f406112005-07-14 07:34:18 +0000563 if (config3 & MIPS_CONF3_VINT)
564 c->options |= MIPS_CPU_VINT;
565 if (config3 & MIPS_CONF3_VEIC)
566 c->options |= MIPS_CPU_VEIC;
567 if (config3 & MIPS_CONF3_MT)
568 c->ases |= MIPS_ASE_MIPSMT;
Ralf Baechle41943182005-05-05 16:45:59 +0000569
570 return config3 & MIPS_CONF_M;
571}
572
Thiemo Seuferc36cd4b2006-07-03 13:30:01 +0100573static void __init decode_configs(struct cpuinfo_mips *c)
Ralf Baechle41943182005-05-05 16:45:59 +0000574{
575 /* MIPS32 or MIPS64 compliant CPU. */
Ralf Baechle02cf2112005-10-01 13:06:32 +0100576 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
577 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
Ralf Baechle41943182005-05-05 16:45:59 +0000578
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
580
Ralf Baechle41943182005-05-05 16:45:59 +0000581 /* Read Config registers. */
582 if (!decode_config0(c))
583 return; /* actually worth a panic() */
584 if (!decode_config1(c))
585 return;
586 if (!decode_config2(c))
587 return;
588 if (!decode_config3(c))
589 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590}
591
592static inline void cpu_probe_mips(struct cpuinfo_mips *c)
593{
Ralf Baechle41943182005-05-05 16:45:59 +0000594 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595 switch (c->processor_id & 0xff00) {
596 case PRID_IMP_4KC:
597 c->cputype = CPU_4KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598 break;
599 case PRID_IMP_4KEC:
600 c->cputype = CPU_4KEC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 break;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000602 case PRID_IMP_4KECR2:
603 c->cputype = CPU_4KEC;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000604 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700605 case PRID_IMP_4KSC:
Ralf Baechle8afcb5d2005-10-04 15:01:26 +0100606 case PRID_IMP_4KSD:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607 c->cputype = CPU_4KSC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700608 break;
609 case PRID_IMP_5KC:
610 c->cputype = CPU_5KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 break;
612 case PRID_IMP_20KC:
613 c->cputype = CPU_20KC;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700614 break;
615 case PRID_IMP_24K:
Ralf Baechlee50c0a8f2005-05-31 11:49:19 +0000616 case PRID_IMP_24KE:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617 c->cputype = CPU_24K;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618 break;
619 case PRID_IMP_25KF:
620 c->cputype = CPU_25KF;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700621 break;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000622 case PRID_IMP_34K:
623 c->cputype = CPU_34K;
Ralf Baechlebbc7f222005-07-12 16:12:05 +0000624 break;
Chris Dearmanc6209532006-05-02 14:08:46 +0100625 case PRID_IMP_74K:
626 c->cputype = CPU_74K;
627 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628 }
629}
630
631static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
632{
Ralf Baechle41943182005-05-05 16:45:59 +0000633 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 switch (c->processor_id & 0xff00) {
635 case PRID_IMP_AU1_REV1:
636 case PRID_IMP_AU1_REV2:
637 switch ((c->processor_id >> 24) & 0xff) {
638 case 0:
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000639 c->cputype = CPU_AU1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640 break;
641 case 1:
642 c->cputype = CPU_AU1500;
643 break;
644 case 2:
645 c->cputype = CPU_AU1100;
646 break;
647 case 3:
648 c->cputype = CPU_AU1550;
649 break;
Pete Popove3ad1c22005-03-01 06:33:16 +0000650 case 4:
651 c->cputype = CPU_AU1200;
652 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653 default:
654 panic("Unknown Au Core!");
655 break;
656 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 break;
658 }
659}
660
661static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
662{
Ralf Baechle41943182005-05-05 16:45:59 +0000663 decode_configs(c);
Ralf Baechle02cf2112005-10-01 13:06:32 +0100664
665 /*
666 * For historical reasons the SB1 comes with it's own variant of
667 * cache code which eventually will be folded into c-r4k.c. Until
668 * then we pretend it's got it's own cache architecture.
669 */
Andrew Isaacsond121ced2005-10-19 23:54:43 -0700670 c->options &= ~MIPS_CPU_4K_CACHE;
Ralf Baechle02cf2112005-10-01 13:06:32 +0100671 c->options |= MIPS_CPU_SB1_CACHE;
672
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673 switch (c->processor_id & 0xff00) {
674 case PRID_IMP_SB1:
675 c->cputype = CPU_SB1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700676 /* FPU in pass1 is known to have issues. */
Ralf Baechleaa323742006-05-29 00:02:12 +0100677 if ((c->processor_id & 0xff) < 0x02)
Ralf Baechle010b8532006-01-29 18:42:08 +0000678 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700679 break;
Andrew Isaacson93ce2f522005-10-19 23:56:20 -0700680 case PRID_IMP_SB1A:
681 c->cputype = CPU_SB1A;
682 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 }
684}
685
686static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
687{
Ralf Baechle41943182005-05-05 16:45:59 +0000688 decode_configs(c);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700689 switch (c->processor_id & 0xff00) {
690 case PRID_IMP_SR71000:
691 c->cputype = CPU_SR71000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700692 c->scache.ways = 8;
693 c->tlbsize = 64;
694 break;
695 }
696}
697
Pete Popovbdf21b12005-07-14 17:47:57 +0000698static inline void cpu_probe_philips(struct cpuinfo_mips *c)
699{
700 decode_configs(c);
701 switch (c->processor_id & 0xff00) {
702 case PRID_IMP_PR4450:
703 c->cputype = CPU_PR4450;
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000704 c->isa_level = MIPS_CPU_ISA_M32R1;
Pete Popovbdf21b12005-07-14 17:47:57 +0000705 break;
706 default:
707 panic("Unknown Philips Core!"); /* REVISIT: die? */
708 break;
709 }
710}
711
712
Linus Torvalds1da177e2005-04-16 15:20:36 -0700713__init void cpu_probe(void)
714{
715 struct cpuinfo_mips *c = &current_cpu_data;
716
717 c->processor_id = PRID_IMP_UNKNOWN;
718 c->fpu_id = FPIR_IMP_NONE;
719 c->cputype = CPU_UNKNOWN;
720
721 c->processor_id = read_c0_prid();
722 switch (c->processor_id & 0xff0000) {
723 case PRID_COMP_LEGACY:
724 cpu_probe_legacy(c);
725 break;
726 case PRID_COMP_MIPS:
727 cpu_probe_mips(c);
728 break;
729 case PRID_COMP_ALCHEMY:
730 cpu_probe_alchemy(c);
731 break;
732 case PRID_COMP_SIBYTE:
733 cpu_probe_sibyte(c);
734 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735 case PRID_COMP_SANDCRAFT:
736 cpu_probe_sandcraft(c);
737 break;
Pete Popovbdf21b12005-07-14 17:47:57 +0000738 case PRID_COMP_PHILIPS:
739 cpu_probe_philips(c);
Ralf Baechlea3dddd52006-03-11 08:18:41 +0000740 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700741 default:
742 c->cputype = CPU_UNKNOWN;
743 }
Ralf Baechle41943182005-05-05 16:45:59 +0000744 if (c->options & MIPS_CPU_FPU) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700745 c->fpu_id = cpu_get_fpu_id();
Ralf Baechle41943182005-05-05 16:45:59 +0000746
Ralf Baechlee7958bb2005-12-08 13:00:20 +0000747 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
Ralf Baechleb4672d32005-12-08 14:04:24 +0000748 c->isa_level == MIPS_CPU_ISA_M32R2 ||
749 c->isa_level == MIPS_CPU_ISA_M64R1 ||
750 c->isa_level == MIPS_CPU_ISA_M64R2) {
Ralf Baechle41943182005-05-05 16:45:59 +0000751 if (c->fpu_id & MIPS_FPIR_3D)
752 c->ases |= MIPS_ASE_MIPS3D;
753 }
754 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
757__init void cpu_report(void)
758{
759 struct cpuinfo_mips *c = &current_cpu_data;
760
761 printk("CPU revision is: %08x\n", c->processor_id);
762 if (c->options & MIPS_CPU_FPU)
763 printk("FPU revision is: %08x\n", c->fpu_id);
764}