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>
21 #include <asm/mipsregs.h>
22 #include <asm/system.h>
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
31 void (*cpu_wait)(void) = NULL;
33 static void r3081_wait(void)
35 unsigned long cfg = read_c0_conf();
36 write_c0_conf(cfg | R30XX_CONF_HALT);
39 static void r39xx_wait(void)
41 unsigned long cfg = read_c0_conf();
42 write_c0_conf(cfg | TX39_CONF_HALT);
45 static void r4k_wait(void)
47 __asm__(".set\tmips3\n\t"
52 /* The Au1xxx wait is available only if using 32khz counter or
53 * external timer source, but specifically not CP0 Counter. */
56 static void au1k_wait(void)
58 /* using the wait instruction makes CP0 counter unusable */
59 __asm__(".set mips3\n\t"
60 "cache 0x14, 0(%0)\n\t"
61 "cache 0x14, 32(%0)\n\t"
73 static int __initdata nowait = 0;
75 int __init wait_disable(char *s)
82 __setup("nowait", wait_disable);
84 static inline void check_wait(void)
86 struct cpuinfo_mips *c = ¤t_cpu_data;
88 printk("Checking for 'wait' instruction... ");
90 printk (" disabled.\n");
97 cpu_wait = r3081_wait;
98 printk(" available.\n");
101 cpu_wait = r39xx_wait;
102 printk(" available.\n");
105 /* case CPU_R4300: */
126 printk(" available.\n");
133 if (allow_au1k_wait) {
134 cpu_wait = au1k_wait;
135 printk(" available.\n");
137 printk(" unavailable.\n");
140 printk(" unavailable.\n");
145 void __init check_bugs32(void)
151 * Probe whether cpu has config register by trying to play with
152 * alternate cache bit and see whether it matters.
153 * It's used by cpu_probe to distinguish between R3000A and R3081.
155 static inline int cpu_has_confreg(void)
157 #ifdef CONFIG_CPU_R3000
158 extern unsigned long r3k_cache_size(unsigned long);
159 unsigned long size1, size2;
160 unsigned long cfg = read_c0_conf();
162 size1 = r3k_cache_size(ST0_ISC);
163 write_c0_conf(cfg ^ R30XX_CONF_AC);
164 size2 = r3k_cache_size(ST0_ISC);
166 return size1 != size2;
173 * Get the FPU Implementation/Revision.
175 static inline unsigned long cpu_get_fpu_id(void)
177 unsigned long tmp, fpu_id;
179 tmp = read_c0_status();
181 fpu_id = read_32bit_cp1_register(CP1_REVISION);
182 write_c0_status(tmp);
187 * Check the CPU has an FPU the official way.
189 static inline int __cpu_has_fpu(void)
191 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
194 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
197 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
199 switch (c->processor_id & 0xff00) {
201 c->cputype = CPU_R2000;
202 c->isa_level = MIPS_CPU_ISA_I;
203 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
206 c->options |= MIPS_CPU_FPU;
210 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
211 if (cpu_has_confreg())
212 c->cputype = CPU_R3081E;
214 c->cputype = CPU_R3000A;
216 c->cputype = CPU_R3000;
217 c->isa_level = MIPS_CPU_ISA_I;
218 c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
221 c->options |= MIPS_CPU_FPU;
225 if (read_c0_config() & CONF_SC) {
226 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
227 c->cputype = CPU_R4400PC;
229 c->cputype = CPU_R4000PC;
231 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
232 c->cputype = CPU_R4400SC;
234 c->cputype = CPU_R4000SC;
237 c->isa_level = MIPS_CPU_ISA_III;
238 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
239 MIPS_CPU_WATCH | MIPS_CPU_VCE |
243 case PRID_IMP_VR41XX:
244 switch (c->processor_id & 0xf0) {
245 case PRID_REV_VR4111:
246 c->cputype = CPU_VR4111;
248 case PRID_REV_VR4121:
249 c->cputype = CPU_VR4121;
251 case PRID_REV_VR4122:
252 if ((c->processor_id & 0xf) < 0x3)
253 c->cputype = CPU_VR4122;
255 c->cputype = CPU_VR4181A;
257 case PRID_REV_VR4130:
258 if ((c->processor_id & 0xf) < 0x4)
259 c->cputype = CPU_VR4131;
261 c->cputype = CPU_VR4133;
264 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
265 c->cputype = CPU_VR41XX;
268 c->isa_level = MIPS_CPU_ISA_III;
269 c->options = R4K_OPTS;
273 c->cputype = CPU_R4300;
274 c->isa_level = MIPS_CPU_ISA_III;
275 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
280 c->cputype = CPU_R4600;
281 c->isa_level = MIPS_CPU_ISA_III;
282 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
289 * This processor doesn't have an MMU, so it's not
290 * "real easy" to run Linux on it. It is left purely
291 * for documentation. Commented out because it shares
292 * it's c0_prid id number with the TX3900.
294 c->cputype = CPU_R4650;
295 c->isa_level = MIPS_CPU_ISA_III;
296 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
301 c->isa_level = MIPS_CPU_ISA_I;
302 c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
304 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
305 c->cputype = CPU_TX3927;
308 switch (c->processor_id & 0xff) {
309 case PRID_REV_TX3912:
310 c->cputype = CPU_TX3912;
313 case PRID_REV_TX3922:
314 c->cputype = CPU_TX3922;
318 c->cputype = CPU_UNKNOWN;
324 c->cputype = CPU_R4700;
325 c->isa_level = MIPS_CPU_ISA_III;
326 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
331 c->cputype = CPU_TX49XX;
332 c->isa_level = MIPS_CPU_ISA_III;
333 c->options = R4K_OPTS | MIPS_CPU_LLSC;
334 if (!(c->processor_id & 0x08))
335 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
339 c->cputype = CPU_R5000;
340 c->isa_level = MIPS_CPU_ISA_IV;
341 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
346 c->cputype = CPU_R5432;
347 c->isa_level = MIPS_CPU_ISA_IV;
348 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
349 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
353 c->cputype = CPU_R5500;
354 c->isa_level = MIPS_CPU_ISA_IV;
355 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
356 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
359 case PRID_IMP_NEVADA:
360 c->cputype = CPU_NEVADA;
361 c->isa_level = MIPS_CPU_ISA_IV;
362 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
363 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
367 c->cputype = CPU_R6000;
368 c->isa_level = MIPS_CPU_ISA_II;
369 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
373 case PRID_IMP_R6000A:
374 c->cputype = CPU_R6000A;
375 c->isa_level = MIPS_CPU_ISA_II;
376 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
380 case PRID_IMP_RM7000:
381 c->cputype = CPU_RM7000;
382 c->isa_level = MIPS_CPU_ISA_IV;
383 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
386 * Undocumented RM7000: Bit 29 in the info register of
387 * the RM7000 v2.0 indicates if the TLB has 48 or 64
390 * 29 1 => 64 entry JTLB
393 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
395 case PRID_IMP_RM9000:
396 c->cputype = CPU_RM9000;
397 c->isa_level = MIPS_CPU_ISA_IV;
398 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
401 * Bit 29 in the info register of the RM9000
402 * indicates if the TLB has 48 or 64 entries.
404 * 29 1 => 64 entry JTLB
407 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
410 c->cputype = CPU_R8000;
411 c->isa_level = MIPS_CPU_ISA_IV;
412 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
413 MIPS_CPU_FPU | MIPS_CPU_32FPR |
415 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
417 case PRID_IMP_R10000:
418 c->cputype = CPU_R10000;
419 c->isa_level = MIPS_CPU_ISA_IV;
420 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
421 MIPS_CPU_FPU | MIPS_CPU_32FPR |
422 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
426 case PRID_IMP_R12000:
427 c->cputype = CPU_R12000;
428 c->isa_level = MIPS_CPU_ISA_IV;
429 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
430 MIPS_CPU_FPU | MIPS_CPU_32FPR |
431 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
435 case PRID_IMP_R14000:
436 c->cputype = CPU_R14000;
437 c->isa_level = MIPS_CPU_ISA_IV;
438 c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
439 MIPS_CPU_FPU | MIPS_CPU_32FPR |
440 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
447 static char unknown_isa[] __initdata = KERN_ERR \
448 "Unsupported ISA type, c0.config0: %d.";
450 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
452 unsigned int config0;
455 config0 = read_c0_config();
457 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
458 c->options |= MIPS_CPU_TLB;
459 isa = (config0 & MIPS_CONF_AT) >> 13;
462 switch ((config0 >> 10) & 7) {
464 c->isa_level = MIPS_CPU_ISA_M32R1;
467 c->isa_level = MIPS_CPU_ISA_M32R2;
474 switch ((config0 >> 10) & 7) {
476 c->isa_level = MIPS_CPU_ISA_M64R1;
479 c->isa_level = MIPS_CPU_ISA_M64R2;
489 return config0 & MIPS_CONF_M;
492 panic(unknown_isa, config0);
495 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
497 unsigned int config1;
499 config1 = read_c0_config1();
501 if (config1 & MIPS_CONF1_MD)
502 c->ases |= MIPS_ASE_MDMX;
503 if (config1 & MIPS_CONF1_WR)
504 c->options |= MIPS_CPU_WATCH;
505 if (config1 & MIPS_CONF1_CA)
506 c->ases |= MIPS_ASE_MIPS16;
507 if (config1 & MIPS_CONF1_EP)
508 c->options |= MIPS_CPU_EJTAG;
509 if (config1 & MIPS_CONF1_FP) {
510 c->options |= MIPS_CPU_FPU;
511 c->options |= MIPS_CPU_32FPR;
514 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
516 return config1 & MIPS_CONF_M;
519 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
521 unsigned int config2;
523 config2 = read_c0_config2();
525 if (config2 & MIPS_CONF2_SL)
526 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
528 return config2 & MIPS_CONF_M;
531 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
533 unsigned int config3;
535 config3 = read_c0_config3();
537 if (config3 & MIPS_CONF3_SM)
538 c->ases |= MIPS_ASE_SMARTMIPS;
539 if (config3 & MIPS_CONF3_DSP)
540 c->ases |= MIPS_ASE_DSP;
541 if (config3 & MIPS_CONF3_VINT)
542 c->options |= MIPS_CPU_VINT;
543 if (config3 & MIPS_CONF3_VEIC)
544 c->options |= MIPS_CPU_VEIC;
545 if (config3 & MIPS_CONF3_MT)
546 c->ases |= MIPS_ASE_MIPSMT;
548 return config3 & MIPS_CONF_M;
551 static inline void decode_configs(struct cpuinfo_mips *c)
553 /* MIPS32 or MIPS64 compliant CPU. */
554 c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
555 MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
557 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
559 /* Read Config registers. */
560 if (!decode_config0(c))
561 return; /* actually worth a panic() */
562 if (!decode_config1(c))
564 if (!decode_config2(c))
566 if (!decode_config3(c))
570 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
573 switch (c->processor_id & 0xff00) {
575 c->cputype = CPU_4KC;
578 c->cputype = CPU_4KEC;
580 case PRID_IMP_4KECR2:
581 c->cputype = CPU_4KEC;
585 c->cputype = CPU_4KSC;
588 c->cputype = CPU_5KC;
591 c->cputype = CPU_20KC;
595 c->cputype = CPU_24K;
598 c->cputype = CPU_25KF;
601 c->cputype = CPU_34K;
604 c->cputype = CPU_74K;
609 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
612 switch (c->processor_id & 0xff00) {
613 case PRID_IMP_AU1_REV1:
614 case PRID_IMP_AU1_REV2:
615 switch ((c->processor_id >> 24) & 0xff) {
617 c->cputype = CPU_AU1000;
620 c->cputype = CPU_AU1500;
623 c->cputype = CPU_AU1100;
626 c->cputype = CPU_AU1550;
629 c->cputype = CPU_AU1200;
632 panic("Unknown Au Core!");
639 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
644 * For historical reasons the SB1 comes with it's own variant of
645 * cache code which eventually will be folded into c-r4k.c. Until
646 * then we pretend it's got it's own cache architecture.
648 c->options &= ~MIPS_CPU_4K_CACHE;
649 c->options |= MIPS_CPU_SB1_CACHE;
651 switch (c->processor_id & 0xff00) {
653 c->cputype = CPU_SB1;
654 /* FPU in pass1 is known to have issues. */
655 if ((c->processor_id & 0xff) < 0x02)
656 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
659 c->cputype = CPU_SB1A;
664 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
667 switch (c->processor_id & 0xff00) {
668 case PRID_IMP_SR71000:
669 c->cputype = CPU_SR71000;
676 static inline void cpu_probe_philips(struct cpuinfo_mips *c)
679 switch (c->processor_id & 0xff00) {
680 case PRID_IMP_PR4450:
681 c->cputype = CPU_PR4450;
682 c->isa_level = MIPS_CPU_ISA_M32R1;
685 panic("Unknown Philips Core!"); /* REVISIT: die? */
691 __init void cpu_probe(void)
693 struct cpuinfo_mips *c = ¤t_cpu_data;
695 c->processor_id = PRID_IMP_UNKNOWN;
696 c->fpu_id = FPIR_IMP_NONE;
697 c->cputype = CPU_UNKNOWN;
699 c->processor_id = read_c0_prid();
700 switch (c->processor_id & 0xff0000) {
701 case PRID_COMP_LEGACY:
707 case PRID_COMP_ALCHEMY:
708 cpu_probe_alchemy(c);
710 case PRID_COMP_SIBYTE:
713 case PRID_COMP_SANDCRAFT:
714 cpu_probe_sandcraft(c);
716 case PRID_COMP_PHILIPS:
717 cpu_probe_philips(c);
720 c->cputype = CPU_UNKNOWN;
722 if (c->options & MIPS_CPU_FPU) {
723 c->fpu_id = cpu_get_fpu_id();
725 if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
726 c->isa_level == MIPS_CPU_ISA_M32R2 ||
727 c->isa_level == MIPS_CPU_ISA_M64R1 ||
728 c->isa_level == MIPS_CPU_ISA_M64R2) {
729 if (c->fpu_id & MIPS_FPIR_3D)
730 c->ases |= MIPS_ASE_MIPS3D;
735 __init void cpu_report(void)
737 struct cpuinfo_mips *c = ¤t_cpu_data;
739 printk("CPU revision is: %08x\n", c->processor_id);
740 if (c->options & MIPS_CPU_FPU)
741 printk("FPU revision is: %08x\n", c->fpu_id);