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: */
148 if (read_c0_config7() & MIPS_CONF7_WII)
149 cpu_wait = r4k_wait_irqoff;
154 if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
155 cpu_wait = r4k_wait_irqoff;
159 cpu_wait = r4k_wait_irqoff;
167 cpu_wait = au1k_wait;
171 * WAIT on Rev1.0 has E1, E2, E3 and E16.
172 * WAIT on Rev2.0 and Rev3.0 has E16.
173 * Rev3.1 WAIT is nop, why bother
175 if ((c->processor_id & 0xff) <= 0x64)
181 if ((c->processor_id & 0x00ff) >= 0x40)
189 void __init check_bugs32(void)
195 * Probe whether cpu has config register by trying to play with
196 * alternate cache bit and see whether it matters.
197 * It's used by cpu_probe to distinguish between R3000A and R3081.
199 static inline int cpu_has_confreg(void)
201 #ifdef CONFIG_CPU_R3000
202 extern unsigned long r3k_cache_size(unsigned long);
203 unsigned long size1, size2;
204 unsigned long cfg = read_c0_conf();
206 size1 = r3k_cache_size(ST0_ISC);
207 write_c0_conf(cfg ^ R30XX_CONF_AC);
208 size2 = r3k_cache_size(ST0_ISC);
210 return size1 != size2;
217 * Get the FPU Implementation/Revision.
219 static inline unsigned long cpu_get_fpu_id(void)
221 unsigned long tmp, fpu_id;
223 tmp = read_c0_status();
225 fpu_id = read_32bit_cp1_register(CP1_REVISION);
226 write_c0_status(tmp);
231 * Check the CPU has an FPU the official way.
233 static inline int __cpu_has_fpu(void)
235 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
238 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
241 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
243 switch (c->processor_id & 0xff00) {
245 c->cputype = CPU_R2000;
246 c->isa_level = MIPS_CPU_ISA_I;
247 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
250 c->options |= MIPS_CPU_FPU;
254 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
255 if (cpu_has_confreg())
256 c->cputype = CPU_R3081E;
258 c->cputype = CPU_R3000A;
260 c->cputype = CPU_R3000;
261 c->isa_level = MIPS_CPU_ISA_I;
262 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
265 c->options |= MIPS_CPU_FPU;
269 if (read_c0_config() & CONF_SC) {
270 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
271 c->cputype = CPU_R4400PC;
273 c->cputype = CPU_R4000PC;
275 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
276 c->cputype = CPU_R4400SC;
278 c->cputype = CPU_R4000SC;
281 c->isa_level = MIPS_CPU_ISA_III;
282 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
283 MIPS_CPU_WATCH | MIPS_CPU_VCE |
287 case PRID_IMP_VR41XX:
288 switch (c->processor_id & 0xf0) {
289 case PRID_REV_VR4111:
290 c->cputype = CPU_VR4111;
292 case PRID_REV_VR4121:
293 c->cputype = CPU_VR4121;
295 case PRID_REV_VR4122:
296 if ((c->processor_id & 0xf) < 0x3)
297 c->cputype = CPU_VR4122;
299 c->cputype = CPU_VR4181A;
301 case PRID_REV_VR4130:
302 if ((c->processor_id & 0xf) < 0x4)
303 c->cputype = CPU_VR4131;
305 c->cputype = CPU_VR4133;
308 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
309 c->cputype = CPU_VR41XX;
312 c->isa_level = MIPS_CPU_ISA_III;
313 c->options = R4K_OPTS;
317 c->cputype = CPU_R4300;
318 c->isa_level = MIPS_CPU_ISA_III;
319 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
324 c->cputype = CPU_R4600;
325 c->isa_level = MIPS_CPU_ISA_III;
326 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
333 * This processor doesn't have an MMU, so it's not
334 * "real easy" to run Linux on it. It is left purely
335 * for documentation. Commented out because it shares
336 * it's c0_prid id number with the TX3900.
338 c->cputype = CPU_R4650;
339 c->isa_level = MIPS_CPU_ISA_III;
340 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
345 c->isa_level = MIPS_CPU_ISA_I;
346 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
348 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
349 c->cputype = CPU_TX3927;
352 switch (c->processor_id & 0xff) {
353 case PRID_REV_TX3912:
354 c->cputype = CPU_TX3912;
357 case PRID_REV_TX3922:
358 c->cputype = CPU_TX3922;
362 c->cputype = CPU_UNKNOWN;
368 c->cputype = CPU_R4700;
369 c->isa_level = MIPS_CPU_ISA_III;
370 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
375 c->cputype = CPU_TX49XX;
376 c->isa_level = MIPS_CPU_ISA_III;
377 c->options = R4K_OPTS | MIPS_CPU_LLSC;
378 if (!(c->processor_id & 0x08))
379 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
383 c->cputype = CPU_R5000;
384 c->isa_level = MIPS_CPU_ISA_IV;
385 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
390 c->cputype = CPU_R5432;
391 c->isa_level = MIPS_CPU_ISA_IV;
392 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
393 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
397 c->cputype = CPU_R5500;
398 c->isa_level = MIPS_CPU_ISA_IV;
399 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
400 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
403 case PRID_IMP_NEVADA:
404 c->cputype = CPU_NEVADA;
405 c->isa_level = MIPS_CPU_ISA_IV;
406 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
407 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
411 c->cputype = CPU_R6000;
412 c->isa_level = MIPS_CPU_ISA_II;
413 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
417 case PRID_IMP_R6000A:
418 c->cputype = CPU_R6000A;
419 c->isa_level = MIPS_CPU_ISA_II;
420 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
424 case PRID_IMP_RM7000:
425 c->cputype = CPU_RM7000;
426 c->isa_level = MIPS_CPU_ISA_IV;
427 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
430 * Undocumented RM7000: Bit 29 in the info register of
431 * the RM7000 v2.0 indicates if the TLB has 48 or 64
434 * 29 1 => 64 entry JTLB
437 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
439 case PRID_IMP_RM9000:
440 c->cputype = CPU_RM9000;
441 c->isa_level = MIPS_CPU_ISA_IV;
442 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
445 * Bit 29 in the info register of the RM9000
446 * indicates if the TLB has 48 or 64 entries.
448 * 29 1 => 64 entry JTLB
451 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
454 c->cputype = CPU_R8000;
455 c->isa_level = MIPS_CPU_ISA_IV;
456 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
457 MIPS_CPU_FPU | MIPS_CPU_32FPR |
459 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
461 case PRID_IMP_R10000:
462 c->cputype = CPU_R10000;
463 c->isa_level = MIPS_CPU_ISA_IV;
464 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
465 MIPS_CPU_FPU | MIPS_CPU_32FPR |
466 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
470 case PRID_IMP_R12000:
471 c->cputype = CPU_R12000;
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 |
479 case PRID_IMP_R14000:
480 c->cputype = CPU_R14000;
481 c->isa_level = MIPS_CPU_ISA_IV;
482 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
483 MIPS_CPU_FPU | MIPS_CPU_32FPR |
484 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
491 static char unknown_isa[] __initdata = KERN_ERR \
492 "Unsupported ISA type, c0.config0: %d.";
494 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
496 unsigned int config0;
499 config0 = read_c0_config();
501 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
502 c->options |= MIPS_CPU_TLB;
503 isa = (config0 & MIPS_CONF_AT) >> 13;
506 switch ((config0 & MIPS_CONF_AR) >> 10) {
508 c->isa_level = MIPS_CPU_ISA_M32R1;
511 c->isa_level = MIPS_CPU_ISA_M32R2;
518 switch ((config0 & MIPS_CONF_AR) >> 10) {
520 c->isa_level = MIPS_CPU_ISA_M64R1;
523 c->isa_level = MIPS_CPU_ISA_M64R2;
533 return config0 & MIPS_CONF_M;
536 panic(unknown_isa, config0);
539 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
541 unsigned int config1;
543 config1 = read_c0_config1();
545 if (config1 & MIPS_CONF1_MD)
546 c->ases |= MIPS_ASE_MDMX;
547 if (config1 & MIPS_CONF1_WR)
548 c->options |= MIPS_CPU_WATCH;
549 if (config1 & MIPS_CONF1_CA)
550 c->ases |= MIPS_ASE_MIPS16;
551 if (config1 & MIPS_CONF1_EP)
552 c->options |= MIPS_CPU_EJTAG;
553 if (config1 & MIPS_CONF1_FP) {
554 c->options |= MIPS_CPU_FPU;
555 c->options |= MIPS_CPU_32FPR;
558 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
560 return config1 & MIPS_CONF_M;
563 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
565 unsigned int config2;
567 config2 = read_c0_config2();
569 if (config2 & MIPS_CONF2_SL)
570 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
572 return config2 & MIPS_CONF_M;
575 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
577 unsigned int config3;
579 config3 = read_c0_config3();
581 if (config3 & MIPS_CONF3_SM)
582 c->ases |= MIPS_ASE_SMARTMIPS;
583 if (config3 & MIPS_CONF3_DSP)
584 c->ases |= MIPS_ASE_DSP;
585 if (config3 & MIPS_CONF3_VINT)
586 c->options |= MIPS_CPU_VINT;
587 if (config3 & MIPS_CONF3_VEIC)
588 c->options |= MIPS_CPU_VEIC;
589 if (config3 & MIPS_CONF3_MT)
590 c->ases |= MIPS_ASE_MIPSMT;
592 return config3 & MIPS_CONF_M;
595 static void __init decode_configs(struct cpuinfo_mips *c)
597 /* MIPS32 or MIPS64 compliant CPU. */
598 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
599 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
601 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
603 /* Read Config registers. */
604 if (!decode_config0(c))
605 return; /* actually worth a panic() */
606 if (!decode_config1(c))
608 if (!decode_config2(c))
610 if (!decode_config3(c))
614 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
617 switch (c->processor_id & 0xff00) {
619 c->cputype = CPU_4KC;
622 c->cputype = CPU_4KEC;
624 case PRID_IMP_4KECR2:
625 c->cputype = CPU_4KEC;
629 c->cputype = CPU_4KSC;
632 c->cputype = CPU_5KC;
635 c->cputype = CPU_20KC;
639 c->cputype = CPU_24K;
642 c->cputype = CPU_25KF;
645 c->cputype = CPU_34K;
648 c->cputype = CPU_74K;
653 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
656 switch (c->processor_id & 0xff00) {
657 case PRID_IMP_AU1_REV1:
658 case PRID_IMP_AU1_REV2:
659 switch ((c->processor_id >> 24) & 0xff) {
661 c->cputype = CPU_AU1000;
664 c->cputype = CPU_AU1500;
667 c->cputype = CPU_AU1100;
670 c->cputype = CPU_AU1550;
673 c->cputype = CPU_AU1200;
676 panic("Unknown Au Core!");
683 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
688 * For historical reasons the SB1 comes with it's own variant of
689 * cache code which eventually will be folded into c-r4k.c. Until
690 * then we pretend it's got it's own cache architecture.
692 c->options &= ~MIPS_CPU_4K_CACHE;
693 c->options |= MIPS_CPU_SB1_CACHE;
695 switch (c->processor_id & 0xff00) {
697 c->cputype = CPU_SB1;
698 /* FPU in pass1 is known to have issues. */
699 if ((c->processor_id & 0xff) < 0x02)
700 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
703 c->cputype = CPU_SB1A;
708 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
711 switch (c->processor_id & 0xff00) {
712 case PRID_IMP_SR71000:
713 c->cputype = CPU_SR71000;
720 static inline void cpu_probe_philips(struct cpuinfo_mips *c)
723 switch (c->processor_id & 0xff00) {
724 case PRID_IMP_PR4450:
725 c->cputype = CPU_PR4450;
726 c->isa_level = MIPS_CPU_ISA_M32R1;
729 panic("Unknown Philips Core!"); /* REVISIT: die? */
735 __init void cpu_probe(void)
737 struct cpuinfo_mips *c = ¤t_cpu_data;
739 c->processor_id = PRID_IMP_UNKNOWN;
740 c->fpu_id = FPIR_IMP_NONE;
741 c->cputype = CPU_UNKNOWN;
743 c->processor_id = read_c0_prid();
744 switch (c->processor_id & 0xff0000) {
745 case PRID_COMP_LEGACY:
751 case PRID_COMP_ALCHEMY:
752 cpu_probe_alchemy(c);
754 case PRID_COMP_SIBYTE:
757 case PRID_COMP_SANDCRAFT:
758 cpu_probe_sandcraft(c);
760 case PRID_COMP_PHILIPS:
761 cpu_probe_philips(c);
764 c->cputype = CPU_UNKNOWN;
766 if (c->options & MIPS_CPU_FPU) {
767 c->fpu_id = cpu_get_fpu_id();
769 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
770 c->isa_level == MIPS_CPU_ISA_M32R2 ||
771 c->isa_level == MIPS_CPU_ISA_M64R1 ||
772 c->isa_level == MIPS_CPU_ISA_M64R2) {
773 if (c->fpu_id & MIPS_FPIR_3D)
774 c->ases |= MIPS_ASE_MIPS3D;
779 __init void cpu_report(void)
781 struct cpuinfo_mips *c = ¤t_cpu_data;
783 printk("CPU revision is: %08x\n", c->processor_id);
784 if (c->options & MIPS_CPU_FPU)
785 printk("FPU revision is: %08x\n", c->fpu_id);