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 cpu_wait = r4k_wait_irqoff;
156 cpu_wait = au1k_wait;
160 * WAIT on Rev1.0 has E1, E2, E3 and E16.
161 * WAIT on Rev2.0 and Rev3.0 has E16.
162 * Rev3.1 WAIT is nop, why bother
164 if ((c->processor_id & 0xff) <= 0x64)
170 if ((c->processor_id & 0x00ff) >= 0x40)
178 void __init check_bugs32(void)
184 * Probe whether cpu has config register by trying to play with
185 * alternate cache bit and see whether it matters.
186 * It's used by cpu_probe to distinguish between R3000A and R3081.
188 static inline int cpu_has_confreg(void)
190 #ifdef CONFIG_CPU_R3000
191 extern unsigned long r3k_cache_size(unsigned long);
192 unsigned long size1, size2;
193 unsigned long cfg = read_c0_conf();
195 size1 = r3k_cache_size(ST0_ISC);
196 write_c0_conf(cfg ^ R30XX_CONF_AC);
197 size2 = r3k_cache_size(ST0_ISC);
199 return size1 != size2;
206 * Get the FPU Implementation/Revision.
208 static inline unsigned long cpu_get_fpu_id(void)
210 unsigned long tmp, fpu_id;
212 tmp = read_c0_status();
214 fpu_id = read_32bit_cp1_register(CP1_REVISION);
215 write_c0_status(tmp);
220 * Check the CPU has an FPU the official way.
222 static inline int __cpu_has_fpu(void)
224 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
227 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
230 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
232 switch (c->processor_id & 0xff00) {
234 c->cputype = CPU_R2000;
235 c->isa_level = MIPS_CPU_ISA_I;
236 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
239 c->options |= MIPS_CPU_FPU;
243 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
244 if (cpu_has_confreg())
245 c->cputype = CPU_R3081E;
247 c->cputype = CPU_R3000A;
249 c->cputype = CPU_R3000;
250 c->isa_level = MIPS_CPU_ISA_I;
251 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
254 c->options |= MIPS_CPU_FPU;
258 if (read_c0_config() & CONF_SC) {
259 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
260 c->cputype = CPU_R4400PC;
262 c->cputype = CPU_R4000PC;
264 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
265 c->cputype = CPU_R4400SC;
267 c->cputype = CPU_R4000SC;
270 c->isa_level = MIPS_CPU_ISA_III;
271 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
272 MIPS_CPU_WATCH | MIPS_CPU_VCE |
276 case PRID_IMP_VR41XX:
277 switch (c->processor_id & 0xf0) {
278 case PRID_REV_VR4111:
279 c->cputype = CPU_VR4111;
281 case PRID_REV_VR4121:
282 c->cputype = CPU_VR4121;
284 case PRID_REV_VR4122:
285 if ((c->processor_id & 0xf) < 0x3)
286 c->cputype = CPU_VR4122;
288 c->cputype = CPU_VR4181A;
290 case PRID_REV_VR4130:
291 if ((c->processor_id & 0xf) < 0x4)
292 c->cputype = CPU_VR4131;
294 c->cputype = CPU_VR4133;
297 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
298 c->cputype = CPU_VR41XX;
301 c->isa_level = MIPS_CPU_ISA_III;
302 c->options = R4K_OPTS;
306 c->cputype = CPU_R4300;
307 c->isa_level = MIPS_CPU_ISA_III;
308 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
313 c->cputype = CPU_R4600;
314 c->isa_level = MIPS_CPU_ISA_III;
315 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
322 * This processor doesn't have an MMU, so it's not
323 * "real easy" to run Linux on it. It is left purely
324 * for documentation. Commented out because it shares
325 * it's c0_prid id number with the TX3900.
327 c->cputype = CPU_R4650;
328 c->isa_level = MIPS_CPU_ISA_III;
329 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
334 c->isa_level = MIPS_CPU_ISA_I;
335 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
337 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
338 c->cputype = CPU_TX3927;
341 switch (c->processor_id & 0xff) {
342 case PRID_REV_TX3912:
343 c->cputype = CPU_TX3912;
346 case PRID_REV_TX3922:
347 c->cputype = CPU_TX3922;
351 c->cputype = CPU_UNKNOWN;
357 c->cputype = CPU_R4700;
358 c->isa_level = MIPS_CPU_ISA_III;
359 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
364 c->cputype = CPU_TX49XX;
365 c->isa_level = MIPS_CPU_ISA_III;
366 c->options = R4K_OPTS | MIPS_CPU_LLSC;
367 if (!(c->processor_id & 0x08))
368 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
372 c->cputype = CPU_R5000;
373 c->isa_level = MIPS_CPU_ISA_IV;
374 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
379 c->cputype = CPU_R5432;
380 c->isa_level = MIPS_CPU_ISA_IV;
381 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
382 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
386 c->cputype = CPU_R5500;
387 c->isa_level = MIPS_CPU_ISA_IV;
388 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
389 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
392 case PRID_IMP_NEVADA:
393 c->cputype = CPU_NEVADA;
394 c->isa_level = MIPS_CPU_ISA_IV;
395 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
396 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
400 c->cputype = CPU_R6000;
401 c->isa_level = MIPS_CPU_ISA_II;
402 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
406 case PRID_IMP_R6000A:
407 c->cputype = CPU_R6000A;
408 c->isa_level = MIPS_CPU_ISA_II;
409 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
413 case PRID_IMP_RM7000:
414 c->cputype = CPU_RM7000;
415 c->isa_level = MIPS_CPU_ISA_IV;
416 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
419 * Undocumented RM7000: Bit 29 in the info register of
420 * the RM7000 v2.0 indicates if the TLB has 48 or 64
423 * 29 1 => 64 entry JTLB
426 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
428 case PRID_IMP_RM9000:
429 c->cputype = CPU_RM9000;
430 c->isa_level = MIPS_CPU_ISA_IV;
431 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
434 * Bit 29 in the info register of the RM9000
435 * indicates if the TLB has 48 or 64 entries.
437 * 29 1 => 64 entry JTLB
440 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
443 c->cputype = CPU_R8000;
444 c->isa_level = MIPS_CPU_ISA_IV;
445 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
446 MIPS_CPU_FPU | MIPS_CPU_32FPR |
448 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
450 case PRID_IMP_R10000:
451 c->cputype = CPU_R10000;
452 c->isa_level = MIPS_CPU_ISA_IV;
453 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
454 MIPS_CPU_FPU | MIPS_CPU_32FPR |
455 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
459 case PRID_IMP_R12000:
460 c->cputype = CPU_R12000;
461 c->isa_level = MIPS_CPU_ISA_IV;
462 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
463 MIPS_CPU_FPU | MIPS_CPU_32FPR |
464 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
468 case PRID_IMP_R14000:
469 c->cputype = CPU_R14000;
470 c->isa_level = MIPS_CPU_ISA_IV;
471 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
472 MIPS_CPU_FPU | MIPS_CPU_32FPR |
473 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
480 static char unknown_isa[] __initdata = KERN_ERR \
481 "Unsupported ISA type, c0.config0: %d.";
483 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
485 unsigned int config0;
488 config0 = read_c0_config();
490 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
491 c->options |= MIPS_CPU_TLB;
492 isa = (config0 & MIPS_CONF_AT) >> 13;
495 switch ((config0 & MIPS_CONF_AR) >> 10) {
497 c->isa_level = MIPS_CPU_ISA_M32R1;
500 c->isa_level = MIPS_CPU_ISA_M32R2;
507 switch ((config0 & MIPS_CONF_AR) >> 10) {
509 c->isa_level = MIPS_CPU_ISA_M64R1;
512 c->isa_level = MIPS_CPU_ISA_M64R2;
522 return config0 & MIPS_CONF_M;
525 panic(unknown_isa, config0);
528 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
530 unsigned int config1;
532 config1 = read_c0_config1();
534 if (config1 & MIPS_CONF1_MD)
535 c->ases |= MIPS_ASE_MDMX;
536 if (config1 & MIPS_CONF1_WR)
537 c->options |= MIPS_CPU_WATCH;
538 if (config1 & MIPS_CONF1_CA)
539 c->ases |= MIPS_ASE_MIPS16;
540 if (config1 & MIPS_CONF1_EP)
541 c->options |= MIPS_CPU_EJTAG;
542 if (config1 & MIPS_CONF1_FP) {
543 c->options |= MIPS_CPU_FPU;
544 c->options |= MIPS_CPU_32FPR;
547 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
549 return config1 & MIPS_CONF_M;
552 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
554 unsigned int config2;
556 config2 = read_c0_config2();
558 if (config2 & MIPS_CONF2_SL)
559 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
561 return config2 & MIPS_CONF_M;
564 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
566 unsigned int config3;
568 config3 = read_c0_config3();
570 if (config3 & MIPS_CONF3_SM)
571 c->ases |= MIPS_ASE_SMARTMIPS;
572 if (config3 & MIPS_CONF3_DSP)
573 c->ases |= MIPS_ASE_DSP;
574 if (config3 & MIPS_CONF3_VINT)
575 c->options |= MIPS_CPU_VINT;
576 if (config3 & MIPS_CONF3_VEIC)
577 c->options |= MIPS_CPU_VEIC;
578 if (config3 & MIPS_CONF3_MT)
579 c->ases |= MIPS_ASE_MIPSMT;
581 return config3 & MIPS_CONF_M;
584 static void __init decode_configs(struct cpuinfo_mips *c)
586 /* MIPS32 or MIPS64 compliant CPU. */
587 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
588 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
590 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
592 /* Read Config registers. */
593 if (!decode_config0(c))
594 return; /* actually worth a panic() */
595 if (!decode_config1(c))
597 if (!decode_config2(c))
599 if (!decode_config3(c))
603 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
606 switch (c->processor_id & 0xff00) {
608 c->cputype = CPU_4KC;
611 c->cputype = CPU_4KEC;
613 case PRID_IMP_4KECR2:
614 c->cputype = CPU_4KEC;
618 c->cputype = CPU_4KSC;
621 c->cputype = CPU_5KC;
624 c->cputype = CPU_20KC;
628 c->cputype = CPU_24K;
631 c->cputype = CPU_25KF;
634 c->cputype = CPU_34K;
637 c->cputype = CPU_74K;
642 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
645 switch (c->processor_id & 0xff00) {
646 case PRID_IMP_AU1_REV1:
647 case PRID_IMP_AU1_REV2:
648 switch ((c->processor_id >> 24) & 0xff) {
650 c->cputype = CPU_AU1000;
653 c->cputype = CPU_AU1500;
656 c->cputype = CPU_AU1100;
659 c->cputype = CPU_AU1550;
662 c->cputype = CPU_AU1200;
665 panic("Unknown Au Core!");
672 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
677 * For historical reasons the SB1 comes with it's own variant of
678 * cache code which eventually will be folded into c-r4k.c. Until
679 * then we pretend it's got it's own cache architecture.
681 c->options &= ~MIPS_CPU_4K_CACHE;
682 c->options |= MIPS_CPU_SB1_CACHE;
684 switch (c->processor_id & 0xff00) {
686 c->cputype = CPU_SB1;
687 /* FPU in pass1 is known to have issues. */
688 if ((c->processor_id & 0xff) < 0x02)
689 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
692 c->cputype = CPU_SB1A;
697 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
700 switch (c->processor_id & 0xff00) {
701 case PRID_IMP_SR71000:
702 c->cputype = CPU_SR71000;
709 static inline void cpu_probe_philips(struct cpuinfo_mips *c)
712 switch (c->processor_id & 0xff00) {
713 case PRID_IMP_PR4450:
714 c->cputype = CPU_PR4450;
715 c->isa_level = MIPS_CPU_ISA_M32R1;
718 panic("Unknown Philips Core!"); /* REVISIT: die? */
724 __init void cpu_probe(void)
726 struct cpuinfo_mips *c = ¤t_cpu_data;
728 c->processor_id = PRID_IMP_UNKNOWN;
729 c->fpu_id = FPIR_IMP_NONE;
730 c->cputype = CPU_UNKNOWN;
732 c->processor_id = read_c0_prid();
733 switch (c->processor_id & 0xff0000) {
734 case PRID_COMP_LEGACY:
740 case PRID_COMP_ALCHEMY:
741 cpu_probe_alchemy(c);
743 case PRID_COMP_SIBYTE:
746 case PRID_COMP_SANDCRAFT:
747 cpu_probe_sandcraft(c);
749 case PRID_COMP_PHILIPS:
750 cpu_probe_philips(c);
753 c->cputype = CPU_UNKNOWN;
755 if (c->options & MIPS_CPU_FPU) {
756 c->fpu_id = cpu_get_fpu_id();
758 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
759 c->isa_level == MIPS_CPU_ISA_M32R2 ||
760 c->isa_level == MIPS_CPU_ISA_M64R1 ||
761 c->isa_level == MIPS_CPU_ISA_M64R2) {
762 if (c->fpu_id & MIPS_FPIR_3D)
763 c->ases |= MIPS_ASE_MIPS3D;
768 __init void cpu_report(void)
770 struct cpuinfo_mips *c = ¤t_cpu_data;
772 printk("CPU revision is: %08x\n", c->processor_id);
773 if (c->options & MIPS_CPU_FPU)
774 printk("FPU revision is: %08x\n", c->fpu_id);