2 * Processor capabilities determination functions.
4 * Copyright (C) xxxx the Anonymous
5 * Copyright (C) 1994 - 2006 Ralf Baechle
6 * Copyright (C) 2003, 2004 Maciej W. Rozycki
7 * Copyright (C) 2001, 2004 MIPS Inc.
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.
14 #include <linux/init.h>
15 #include <linux/kernel.h>
16 #include <linux/ptrace.h>
17 #include <linux/stddef.h>
22 #include <asm/mipsregs.h>
23 #include <asm/system.h>
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
32 void (*cpu_wait)(void) = NULL;
34 static void r3081_wait(void)
36 unsigned long cfg = read_c0_conf();
37 write_c0_conf(cfg | R30XX_CONF_HALT);
40 static void r39xx_wait(void)
44 write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
49 * There is a race when WAIT instruction executed with interrupt
51 * But it is implementation-dependent wheter the pipelie restarts when
52 * a non-enabled interrupt is requested.
54 static void r4k_wait(void)
56 __asm__(" .set mips3 \n"
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.
68 static void r4k_wait_irqoff(void)
72 __asm__(" .set mips3 \n"
78 /* The Au1xxx wait is available only if using 32khz counter or
79 * external timer source, but specifically not CP0 Counter. */
82 static void au1k_wait(void)
84 /* using the wait instruction makes CP0 counter unusable */
85 __asm__(" .set mips3 \n"
86 " cache 0x14, 0(%0) \n"
87 " cache 0x14, 32(%0) \n"
99 static int __initdata nowait = 0;
101 static int __init wait_disable(char *s)
108 __setup("nowait", wait_disable);
110 static inline void check_wait(void)
112 struct cpuinfo_mips *c = ¤t_cpu_data;
115 printk("Wait instruction disabled.\n");
119 switch (c->cputype) {
122 cpu_wait = r3081_wait;
125 cpu_wait = r39xx_wait;
128 /* case CPU_R4300: */
149 cpu_wait = r4k_wait_irqoff;
157 cpu_wait = au1k_wait;
160 if ((c->processor_id & 0x00ff) >= 0x40)
168 void __init check_bugs32(void)
174 * Probe whether cpu has config register by trying to play with
175 * alternate cache bit and see whether it matters.
176 * It's used by cpu_probe to distinguish between R3000A and R3081.
178 static inline int cpu_has_confreg(void)
180 #ifdef CONFIG_CPU_R3000
181 extern unsigned long r3k_cache_size(unsigned long);
182 unsigned long size1, size2;
183 unsigned long cfg = read_c0_conf();
185 size1 = r3k_cache_size(ST0_ISC);
186 write_c0_conf(cfg ^ R30XX_CONF_AC);
187 size2 = r3k_cache_size(ST0_ISC);
189 return size1 != size2;
196 * Get the FPU Implementation/Revision.
198 static inline unsigned long cpu_get_fpu_id(void)
200 unsigned long tmp, fpu_id;
202 tmp = read_c0_status();
204 fpu_id = read_32bit_cp1_register(CP1_REVISION);
205 write_c0_status(tmp);
210 * Check the CPU has an FPU the official way.
212 static inline int __cpu_has_fpu(void)
214 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
217 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
220 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
222 switch (c->processor_id & 0xff00) {
224 c->cputype = CPU_R2000;
225 c->isa_level = MIPS_CPU_ISA_I;
226 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
229 c->options |= MIPS_CPU_FPU;
233 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
234 if (cpu_has_confreg())
235 c->cputype = CPU_R3081E;
237 c->cputype = CPU_R3000A;
239 c->cputype = CPU_R3000;
240 c->isa_level = MIPS_CPU_ISA_I;
241 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
244 c->options |= MIPS_CPU_FPU;
248 if (read_c0_config() & CONF_SC) {
249 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
250 c->cputype = CPU_R4400PC;
252 c->cputype = CPU_R4000PC;
254 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
255 c->cputype = CPU_R4400SC;
257 c->cputype = CPU_R4000SC;
260 c->isa_level = MIPS_CPU_ISA_III;
261 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
262 MIPS_CPU_WATCH | MIPS_CPU_VCE |
266 case PRID_IMP_VR41XX:
267 switch (c->processor_id & 0xf0) {
268 case PRID_REV_VR4111:
269 c->cputype = CPU_VR4111;
271 case PRID_REV_VR4121:
272 c->cputype = CPU_VR4121;
274 case PRID_REV_VR4122:
275 if ((c->processor_id & 0xf) < 0x3)
276 c->cputype = CPU_VR4122;
278 c->cputype = CPU_VR4181A;
280 case PRID_REV_VR4130:
281 if ((c->processor_id & 0xf) < 0x4)
282 c->cputype = CPU_VR4131;
284 c->cputype = CPU_VR4133;
287 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
288 c->cputype = CPU_VR41XX;
291 c->isa_level = MIPS_CPU_ISA_III;
292 c->options = R4K_OPTS;
296 c->cputype = CPU_R4300;
297 c->isa_level = MIPS_CPU_ISA_III;
298 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
303 c->cputype = CPU_R4600;
304 c->isa_level = MIPS_CPU_ISA_III;
305 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
312 * This processor doesn't have an MMU, so it's not
313 * "real easy" to run Linux on it. It is left purely
314 * for documentation. Commented out because it shares
315 * it's c0_prid id number with the TX3900.
317 c->cputype = CPU_R4650;
318 c->isa_level = MIPS_CPU_ISA_III;
319 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
324 c->isa_level = MIPS_CPU_ISA_I;
325 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
327 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
328 c->cputype = CPU_TX3927;
331 switch (c->processor_id & 0xff) {
332 case PRID_REV_TX3912:
333 c->cputype = CPU_TX3912;
336 case PRID_REV_TX3922:
337 c->cputype = CPU_TX3922;
341 c->cputype = CPU_UNKNOWN;
347 c->cputype = CPU_R4700;
348 c->isa_level = MIPS_CPU_ISA_III;
349 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
354 c->cputype = CPU_TX49XX;
355 c->isa_level = MIPS_CPU_ISA_III;
356 c->options = R4K_OPTS | MIPS_CPU_LLSC;
357 if (!(c->processor_id & 0x08))
358 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
362 c->cputype = CPU_R5000;
363 c->isa_level = MIPS_CPU_ISA_IV;
364 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
369 c->cputype = CPU_R5432;
370 c->isa_level = MIPS_CPU_ISA_IV;
371 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
372 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
376 c->cputype = CPU_R5500;
377 c->isa_level = MIPS_CPU_ISA_IV;
378 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
379 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
382 case PRID_IMP_NEVADA:
383 c->cputype = CPU_NEVADA;
384 c->isa_level = MIPS_CPU_ISA_IV;
385 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
386 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
390 c->cputype = CPU_R6000;
391 c->isa_level = MIPS_CPU_ISA_II;
392 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
396 case PRID_IMP_R6000A:
397 c->cputype = CPU_R6000A;
398 c->isa_level = MIPS_CPU_ISA_II;
399 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
403 case PRID_IMP_RM7000:
404 c->cputype = CPU_RM7000;
405 c->isa_level = MIPS_CPU_ISA_IV;
406 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
409 * Undocumented RM7000: Bit 29 in the info register of
410 * the RM7000 v2.0 indicates if the TLB has 48 or 64
413 * 29 1 => 64 entry JTLB
416 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
418 case PRID_IMP_RM9000:
419 c->cputype = CPU_RM9000;
420 c->isa_level = MIPS_CPU_ISA_IV;
421 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
424 * Bit 29 in the info register of the RM9000
425 * indicates if the TLB has 48 or 64 entries.
427 * 29 1 => 64 entry JTLB
430 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
433 c->cputype = CPU_R8000;
434 c->isa_level = MIPS_CPU_ISA_IV;
435 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
436 MIPS_CPU_FPU | MIPS_CPU_32FPR |
438 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
440 case PRID_IMP_R10000:
441 c->cputype = CPU_R10000;
442 c->isa_level = MIPS_CPU_ISA_IV;
443 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
444 MIPS_CPU_FPU | MIPS_CPU_32FPR |
445 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
449 case PRID_IMP_R12000:
450 c->cputype = CPU_R12000;
451 c->isa_level = MIPS_CPU_ISA_IV;
452 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
453 MIPS_CPU_FPU | MIPS_CPU_32FPR |
454 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
458 case PRID_IMP_R14000:
459 c->cputype = CPU_R14000;
460 c->isa_level = MIPS_CPU_ISA_IV;
461 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
462 MIPS_CPU_FPU | MIPS_CPU_32FPR |
463 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
470 static char unknown_isa[] __initdata = KERN_ERR \
471 "Unsupported ISA type, c0.config0: %d.";
473 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
475 unsigned int config0;
478 config0 = read_c0_config();
480 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
481 c->options |= MIPS_CPU_TLB;
482 isa = (config0 & MIPS_CONF_AT) >> 13;
485 switch ((config0 & MIPS_CONF_AR) >> 10) {
487 c->isa_level = MIPS_CPU_ISA_M32R1;
490 c->isa_level = MIPS_CPU_ISA_M32R2;
497 switch ((config0 & MIPS_CONF_AR) >> 10) {
499 c->isa_level = MIPS_CPU_ISA_M64R1;
502 c->isa_level = MIPS_CPU_ISA_M64R2;
512 return config0 & MIPS_CONF_M;
515 panic(unknown_isa, config0);
518 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
520 unsigned int config1;
522 config1 = read_c0_config1();
524 if (config1 & MIPS_CONF1_MD)
525 c->ases |= MIPS_ASE_MDMX;
526 if (config1 & MIPS_CONF1_WR)
527 c->options |= MIPS_CPU_WATCH;
528 if (config1 & MIPS_CONF1_CA)
529 c->ases |= MIPS_ASE_MIPS16;
530 if (config1 & MIPS_CONF1_EP)
531 c->options |= MIPS_CPU_EJTAG;
532 if (config1 & MIPS_CONF1_FP) {
533 c->options |= MIPS_CPU_FPU;
534 c->options |= MIPS_CPU_32FPR;
537 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
539 return config1 & MIPS_CONF_M;
542 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
544 unsigned int config2;
546 config2 = read_c0_config2();
548 if (config2 & MIPS_CONF2_SL)
549 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
551 return config2 & MIPS_CONF_M;
554 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
556 unsigned int config3;
558 config3 = read_c0_config3();
560 if (config3 & MIPS_CONF3_SM)
561 c->ases |= MIPS_ASE_SMARTMIPS;
562 if (config3 & MIPS_CONF3_DSP)
563 c->ases |= MIPS_ASE_DSP;
564 if (config3 & MIPS_CONF3_VINT)
565 c->options |= MIPS_CPU_VINT;
566 if (config3 & MIPS_CONF3_VEIC)
567 c->options |= MIPS_CPU_VEIC;
568 if (config3 & MIPS_CONF3_MT)
569 c->ases |= MIPS_ASE_MIPSMT;
571 return config3 & MIPS_CONF_M;
574 static void __init decode_configs(struct cpuinfo_mips *c)
576 /* MIPS32 or MIPS64 compliant CPU. */
577 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
578 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
580 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
582 /* Read Config registers. */
583 if (!decode_config0(c))
584 return; /* actually worth a panic() */
585 if (!decode_config1(c))
587 if (!decode_config2(c))
589 if (!decode_config3(c))
593 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
596 switch (c->processor_id & 0xff00) {
598 c->cputype = CPU_4KC;
601 c->cputype = CPU_4KEC;
603 case PRID_IMP_4KECR2:
604 c->cputype = CPU_4KEC;
608 c->cputype = CPU_4KSC;
611 c->cputype = CPU_5KC;
614 c->cputype = CPU_20KC;
618 c->cputype = CPU_24K;
621 c->cputype = CPU_25KF;
624 c->cputype = CPU_34K;
627 c->cputype = CPU_74K;
632 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
635 switch (c->processor_id & 0xff00) {
636 case PRID_IMP_AU1_REV1:
637 case PRID_IMP_AU1_REV2:
638 switch ((c->processor_id >> 24) & 0xff) {
640 c->cputype = CPU_AU1000;
643 c->cputype = CPU_AU1500;
646 c->cputype = CPU_AU1100;
649 c->cputype = CPU_AU1550;
652 c->cputype = CPU_AU1200;
655 panic("Unknown Au Core!");
662 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
667 * For historical reasons the SB1 comes with it's own variant of
668 * cache code which eventually will be folded into c-r4k.c. Until
669 * then we pretend it's got it's own cache architecture.
671 c->options &= ~MIPS_CPU_4K_CACHE;
672 c->options |= MIPS_CPU_SB1_CACHE;
674 switch (c->processor_id & 0xff00) {
676 c->cputype = CPU_SB1;
677 /* FPU in pass1 is known to have issues. */
678 if ((c->processor_id & 0xff) < 0x02)
679 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
682 c->cputype = CPU_SB1A;
687 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
690 switch (c->processor_id & 0xff00) {
691 case PRID_IMP_SR71000:
692 c->cputype = CPU_SR71000;
699 static inline void cpu_probe_philips(struct cpuinfo_mips *c)
702 switch (c->processor_id & 0xff00) {
703 case PRID_IMP_PR4450:
704 c->cputype = CPU_PR4450;
705 c->isa_level = MIPS_CPU_ISA_M32R1;
708 panic("Unknown Philips Core!"); /* REVISIT: die? */
714 __init void cpu_probe(void)
716 struct cpuinfo_mips *c = ¤t_cpu_data;
718 c->processor_id = PRID_IMP_UNKNOWN;
719 c->fpu_id = FPIR_IMP_NONE;
720 c->cputype = CPU_UNKNOWN;
722 c->processor_id = read_c0_prid();
723 switch (c->processor_id & 0xff0000) {
724 case PRID_COMP_LEGACY:
730 case PRID_COMP_ALCHEMY:
731 cpu_probe_alchemy(c);
733 case PRID_COMP_SIBYTE:
736 case PRID_COMP_SANDCRAFT:
737 cpu_probe_sandcraft(c);
739 case PRID_COMP_PHILIPS:
740 cpu_probe_philips(c);
743 c->cputype = CPU_UNKNOWN;
745 if (c->options & MIPS_CPU_FPU) {
746 c->fpu_id = cpu_get_fpu_id();
748 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
749 c->isa_level == MIPS_CPU_ISA_M32R2 ||
750 c->isa_level == MIPS_CPU_ISA_M64R1 ||
751 c->isa_level == MIPS_CPU_ISA_M64R2) {
752 if (c->fpu_id & MIPS_FPIR_3D)
753 c->ases |= MIPS_ASE_MIPS3D;
758 __init void cpu_report(void)
760 struct cpuinfo_mips *c = ¤t_cpu_data;
762 printk("CPU revision is: %08x\n", c->processor_id);
763 if (c->options & MIPS_CPU_FPU)
764 printk("FPU revision is: %08x\n", c->fpu_id);