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/config.h>
15 #include <linux/init.h>
16 #include <linux/kernel.h>
17 #include <linux/ptrace.h>
18 #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)
42 unsigned long cfg = read_c0_conf();
43 write_c0_conf(cfg | TX39_CONF_HALT);
46 static void r4k_wait(void)
48 __asm__(".set\tmips3\n\t"
53 /* The Au1xxx wait is available only if using 32khz counter or
54 * external timer source, but specifically not CP0 Counter. */
57 static void au1k_wait(void)
59 /* using the wait instruction makes CP0 counter unusable */
60 __asm__(".set mips3\n\t"
61 "cache 0x14, 0(%0)\n\t"
62 "cache 0x14, 32(%0)\n\t"
74 static int __initdata nowait = 0;
76 int __init wait_disable(char *s)
83 __setup("nowait", wait_disable);
85 static inline void check_wait(void)
87 struct cpuinfo_mips *c = ¤t_cpu_data;
89 printk("Checking for 'wait' instruction... ");
91 printk (" disabled.\n");
98 cpu_wait = r3081_wait;
99 printk(" available.\n");
102 cpu_wait = r39xx_wait;
103 printk(" available.\n");
106 /* case CPU_R4300: */
127 printk(" available.\n");
134 if (allow_au1k_wait) {
135 cpu_wait = au1k_wait;
136 printk(" available.\n");
138 printk(" unavailable.\n");
141 printk(" unavailable.\n");
146 void __init check_bugs32(void)
152 * Probe whether cpu has config register by trying to play with
153 * alternate cache bit and see whether it matters.
154 * It's used by cpu_probe to distinguish between R3000A and R3081.
156 static inline int cpu_has_confreg(void)
158 #ifdef CONFIG_CPU_R3000
159 extern unsigned long r3k_cache_size(unsigned long);
160 unsigned long size1, size2;
161 unsigned long cfg = read_c0_conf();
163 size1 = r3k_cache_size(ST0_ISC);
164 write_c0_conf(cfg ^ R30XX_CONF_AC);
165 size2 = r3k_cache_size(ST0_ISC);
167 return size1 != size2;
174 * Get the FPU Implementation/Revision.
176 static inline unsigned long cpu_get_fpu_id(void)
178 unsigned long tmp, fpu_id;
180 tmp = read_c0_status();
182 fpu_id = read_32bit_cp1_register(CP1_REVISION);
183 write_c0_status(tmp);
188 * Check the CPU has an FPU the official way.
190 static inline int __cpu_has_fpu(void)
192 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
195 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
198 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
200 switch (c->processor_id & 0xff00) {
202 c->cputype = CPU_R2000;
203 c->isa_level = MIPS_CPU_ISA_I;
204 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
207 c->options |= MIPS_CPU_FPU;
211 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
212 if (cpu_has_confreg())
213 c->cputype = CPU_R3081E;
215 c->cputype = CPU_R3000A;
217 c->cputype = CPU_R3000;
218 c->isa_level = MIPS_CPU_ISA_I;
219 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
222 c->options |= MIPS_CPU_FPU;
226 if (read_c0_config() & CONF_SC) {
227 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
228 c->cputype = CPU_R4400PC;
230 c->cputype = CPU_R4000PC;
232 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
233 c->cputype = CPU_R4400SC;
235 c->cputype = CPU_R4000SC;
238 c->isa_level = MIPS_CPU_ISA_III;
239 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
240 MIPS_CPU_WATCH | MIPS_CPU_VCE |
244 case PRID_IMP_VR41XX:
245 switch (c->processor_id & 0xf0) {
246 case PRID_REV_VR4111:
247 c->cputype = CPU_VR4111;
249 case PRID_REV_VR4121:
250 c->cputype = CPU_VR4121;
252 case PRID_REV_VR4122:
253 if ((c->processor_id & 0xf) < 0x3)
254 c->cputype = CPU_VR4122;
256 c->cputype = CPU_VR4181A;
258 case PRID_REV_VR4130:
259 if ((c->processor_id & 0xf) < 0x4)
260 c->cputype = CPU_VR4131;
262 c->cputype = CPU_VR4133;
265 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
266 c->cputype = CPU_VR41XX;
269 c->isa_level = MIPS_CPU_ISA_III;
270 c->options = R4K_OPTS;
274 c->cputype = CPU_R4300;
275 c->isa_level = MIPS_CPU_ISA_III;
276 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
281 c->cputype = CPU_R4600;
282 c->isa_level = MIPS_CPU_ISA_III;
283 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
290 * This processor doesn't have an MMU, so it's not
291 * "real easy" to run Linux on it. It is left purely
292 * for documentation. Commented out because it shares
293 * it's c0_prid id number with the TX3900.
295 c->cputype = CPU_R4650;
296 c->isa_level = MIPS_CPU_ISA_III;
297 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
302 c->isa_level = MIPS_CPU_ISA_I;
303 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
305 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
306 c->cputype = CPU_TX3927;
309 switch (c->processor_id & 0xff) {
310 case PRID_REV_TX3912:
311 c->cputype = CPU_TX3912;
314 case PRID_REV_TX3922:
315 c->cputype = CPU_TX3922;
319 c->cputype = CPU_UNKNOWN;
325 c->cputype = CPU_R4700;
326 c->isa_level = MIPS_CPU_ISA_III;
327 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
332 c->cputype = CPU_TX49XX;
333 c->isa_level = MIPS_CPU_ISA_III;
334 c->options = R4K_OPTS | MIPS_CPU_LLSC;
335 if (!(c->processor_id & 0x08))
336 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
340 c->cputype = CPU_R5000;
341 c->isa_level = MIPS_CPU_ISA_IV;
342 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
347 c->cputype = CPU_R5432;
348 c->isa_level = MIPS_CPU_ISA_IV;
349 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
350 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
354 c->cputype = CPU_R5500;
355 c->isa_level = MIPS_CPU_ISA_IV;
356 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
357 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
360 case PRID_IMP_NEVADA:
361 c->cputype = CPU_NEVADA;
362 c->isa_level = MIPS_CPU_ISA_IV;
363 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
364 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
368 c->cputype = CPU_R6000;
369 c->isa_level = MIPS_CPU_ISA_II;
370 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
374 case PRID_IMP_R6000A:
375 c->cputype = CPU_R6000A;
376 c->isa_level = MIPS_CPU_ISA_II;
377 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
381 case PRID_IMP_RM7000:
382 c->cputype = CPU_RM7000;
383 c->isa_level = MIPS_CPU_ISA_IV;
384 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
387 * Undocumented RM7000: Bit 29 in the info register of
388 * the RM7000 v2.0 indicates if the TLB has 48 or 64
391 * 29 1 => 64 entry JTLB
394 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
396 case PRID_IMP_RM9000:
397 c->cputype = CPU_RM9000;
398 c->isa_level = MIPS_CPU_ISA_IV;
399 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
402 * Bit 29 in the info register of the RM9000
403 * indicates if the TLB has 48 or 64 entries.
405 * 29 1 => 64 entry JTLB
408 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
411 c->cputype = CPU_R8000;
412 c->isa_level = MIPS_CPU_ISA_IV;
413 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
414 MIPS_CPU_FPU | MIPS_CPU_32FPR |
416 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
418 case PRID_IMP_R10000:
419 c->cputype = CPU_R10000;
420 c->isa_level = MIPS_CPU_ISA_IV;
421 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
422 MIPS_CPU_FPU | MIPS_CPU_32FPR |
423 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
427 case PRID_IMP_R12000:
428 c->cputype = CPU_R12000;
429 c->isa_level = MIPS_CPU_ISA_IV;
430 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
431 MIPS_CPU_FPU | MIPS_CPU_32FPR |
432 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
436 case PRID_IMP_R14000:
437 c->cputype = CPU_R14000;
438 c->isa_level = MIPS_CPU_ISA_IV;
439 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
440 MIPS_CPU_FPU | MIPS_CPU_32FPR |
441 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
448 static char unknown_isa[] __initdata = KERN_ERR \
449 "Unsupported ISA type, c0.config0: %d.";
451 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
453 unsigned int config0;
456 config0 = read_c0_config();
458 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
459 c->options |= MIPS_CPU_TLB;
460 isa = (config0 & MIPS_CONF_AT) >> 13;
463 switch ((config0 >> 10) & 7) {
465 c->isa_level = MIPS_CPU_ISA_M32R1;
468 c->isa_level = MIPS_CPU_ISA_M32R2;
475 switch ((config0 >> 10) & 7) {
477 c->isa_level = MIPS_CPU_ISA_M64R1;
480 c->isa_level = MIPS_CPU_ISA_M64R2;
490 return config0 & MIPS_CONF_M;
493 panic(unknown_isa, config0);
496 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
498 unsigned int config1;
500 config1 = read_c0_config1();
502 if (config1 & MIPS_CONF1_MD)
503 c->ases |= MIPS_ASE_MDMX;
504 if (config1 & MIPS_CONF1_WR)
505 c->options |= MIPS_CPU_WATCH;
506 if (config1 & MIPS_CONF1_CA)
507 c->ases |= MIPS_ASE_MIPS16;
508 if (config1 & MIPS_CONF1_EP)
509 c->options |= MIPS_CPU_EJTAG;
510 if (config1 & MIPS_CONF1_FP) {
511 c->options |= MIPS_CPU_FPU;
512 c->options |= MIPS_CPU_32FPR;
515 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
517 return config1 & MIPS_CONF_M;
520 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
522 unsigned int config2;
524 config2 = read_c0_config2();
526 if (config2 & MIPS_CONF2_SL)
527 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
529 return config2 & MIPS_CONF_M;
532 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
534 unsigned int config3;
536 config3 = read_c0_config3();
538 if (config3 & MIPS_CONF3_SM)
539 c->ases |= MIPS_ASE_SMARTMIPS;
540 if (config3 & MIPS_CONF3_DSP)
541 c->ases |= MIPS_ASE_DSP;
542 if (config3 & MIPS_CONF3_VINT)
543 c->options |= MIPS_CPU_VINT;
544 if (config3 & MIPS_CONF3_VEIC)
545 c->options |= MIPS_CPU_VEIC;
546 if (config3 & MIPS_CONF3_MT)
547 c->ases |= MIPS_ASE_MIPSMT;
549 return config3 & MIPS_CONF_M;
552 static inline void decode_configs(struct cpuinfo_mips *c)
554 /* MIPS32 or MIPS64 compliant CPU. */
555 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
556 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
558 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
560 /* Read Config registers. */
561 if (!decode_config0(c))
562 return; /* actually worth a panic() */
563 if (!decode_config1(c))
565 if (!decode_config2(c))
567 if (!decode_config3(c))
571 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
574 switch (c->processor_id & 0xff00) {
576 c->cputype = CPU_4KC;
579 c->cputype = CPU_4KEC;
581 case PRID_IMP_4KECR2:
582 c->cputype = CPU_4KEC;
586 c->cputype = CPU_4KSC;
589 c->cputype = CPU_5KC;
592 c->cputype = CPU_20KC;
596 c->cputype = CPU_24K;
599 c->cputype = CPU_25KF;
600 /* Probe for L2 cache */
601 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
604 c->cputype = CPU_34K;
607 c->cputype = CPU_74K;
612 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
615 switch (c->processor_id & 0xff00) {
616 case PRID_IMP_AU1_REV1:
617 case PRID_IMP_AU1_REV2:
618 switch ((c->processor_id >> 24) & 0xff) {
620 c->cputype = CPU_AU1000;
623 c->cputype = CPU_AU1500;
626 c->cputype = CPU_AU1100;
629 c->cputype = CPU_AU1550;
632 c->cputype = CPU_AU1200;
635 panic("Unknown Au Core!");
642 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
647 * For historical reasons the SB1 comes with it's own variant of
648 * cache code which eventually will be folded into c-r4k.c. Until
649 * then we pretend it's got it's own cache architecture.
651 c->options &= ~MIPS_CPU_4K_CACHE;
652 c->options |= MIPS_CPU_SB1_CACHE;
654 switch (c->processor_id & 0xff00) {
656 c->cputype = CPU_SB1;
657 /* FPU in pass1 is known to have issues. */
658 if ((c->processor_id & 0xff) < 0x02)
659 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
662 c->cputype = CPU_SB1A;
667 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
670 switch (c->processor_id & 0xff00) {
671 case PRID_IMP_SR71000:
672 c->cputype = CPU_SR71000;
679 static inline void cpu_probe_philips(struct cpuinfo_mips *c)
682 switch (c->processor_id & 0xff00) {
683 case PRID_IMP_PR4450:
684 c->cputype = CPU_PR4450;
685 c->isa_level = MIPS_CPU_ISA_M32R1;
688 panic("Unknown Philips Core!"); /* REVISIT: die? */
694 __init void cpu_probe(void)
696 struct cpuinfo_mips *c = ¤t_cpu_data;
698 c->processor_id = PRID_IMP_UNKNOWN;
699 c->fpu_id = FPIR_IMP_NONE;
700 c->cputype = CPU_UNKNOWN;
702 c->processor_id = read_c0_prid();
703 switch (c->processor_id & 0xff0000) {
704 case PRID_COMP_LEGACY:
710 case PRID_COMP_ALCHEMY:
711 cpu_probe_alchemy(c);
713 case PRID_COMP_SIBYTE:
716 case PRID_COMP_SANDCRAFT:
717 cpu_probe_sandcraft(c);
719 case PRID_COMP_PHILIPS:
720 cpu_probe_philips(c);
723 c->cputype = CPU_UNKNOWN;
725 if (c->options & MIPS_CPU_FPU) {
726 c->fpu_id = cpu_get_fpu_id();
728 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
729 c->isa_level == MIPS_CPU_ISA_M32R2 ||
730 c->isa_level == MIPS_CPU_ISA_M64R1 ||
731 c->isa_level == MIPS_CPU_ISA_M64R2) {
732 if (c->fpu_id & MIPS_FPIR_3D)
733 c->ases |= MIPS_ASE_MIPS3D;
738 __init void cpu_report(void)
740 struct cpuinfo_mips *c = ¤t_cpu_data;
742 printk("CPU revision is: %08x\n", c->processor_id);
743 if (c->options & MIPS_CPU_FPU)
744 printk("FPU revision is: %08x\n", c->fpu_id);