2 * Processor capabilities determination functions.
4 * Copyright (C) xxxx the Anonymous
5 * Copyright (C) 2003, 2004 Maciej W. Rozycki
6 * Copyright (C) 1994 - 2003 Ralf Baechle
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: */
125 printk(" available.\n");
132 if (allow_au1k_wait) {
133 cpu_wait = au1k_wait;
134 printk(" available.\n");
136 printk(" unavailable.\n");
139 printk(" unavailable.\n");
144 void __init check_bugs32(void)
150 * Probe whether cpu has config register by trying to play with
151 * alternate cache bit and see whether it matters.
152 * It's used by cpu_probe to distinguish between R3000A and R3081.
154 static inline int cpu_has_confreg(void)
156 #ifdef CONFIG_CPU_R3000
157 extern unsigned long r3k_cache_size(unsigned long);
158 unsigned long size1, size2;
159 unsigned long cfg = read_c0_conf();
161 size1 = r3k_cache_size(ST0_ISC);
162 write_c0_conf(cfg ^ R30XX_CONF_AC);
163 size2 = r3k_cache_size(ST0_ISC);
165 return size1 != size2;
172 * Get the FPU Implementation/Revision.
174 static inline unsigned long cpu_get_fpu_id(void)
176 unsigned long tmp, fpu_id;
178 tmp = read_c0_status();
180 fpu_id = read_32bit_cp1_register(CP1_REVISION);
181 write_c0_status(tmp);
186 * Check the CPU has an FPU the official way.
188 static inline int __cpu_has_fpu(void)
190 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
193 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4KTLB \
196 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
198 switch (c->processor_id & 0xff00) {
200 c->cputype = CPU_R2000;
201 c->isa_level = MIPS_CPU_ISA_I;
202 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
204 c->options |= MIPS_CPU_FPU;
208 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
209 if (cpu_has_confreg())
210 c->cputype = CPU_R3081E;
212 c->cputype = CPU_R3000A;
214 c->cputype = CPU_R3000;
215 c->isa_level = MIPS_CPU_ISA_I;
216 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
218 c->options |= MIPS_CPU_FPU;
222 if (read_c0_config() & CONF_SC) {
223 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
224 c->cputype = CPU_R4400PC;
226 c->cputype = CPU_R4000PC;
228 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
229 c->cputype = CPU_R4400SC;
231 c->cputype = CPU_R4000SC;
234 c->isa_level = MIPS_CPU_ISA_III;
235 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
236 MIPS_CPU_WATCH | MIPS_CPU_VCE |
240 case PRID_IMP_VR41XX:
241 switch (c->processor_id & 0xf0) {
242 case PRID_REV_VR4111:
243 c->cputype = CPU_VR4111;
245 case PRID_REV_VR4121:
246 c->cputype = CPU_VR4121;
248 case PRID_REV_VR4122:
249 if ((c->processor_id & 0xf) < 0x3)
250 c->cputype = CPU_VR4122;
252 c->cputype = CPU_VR4181A;
254 case PRID_REV_VR4130:
255 if ((c->processor_id & 0xf) < 0x4)
256 c->cputype = CPU_VR4131;
258 c->cputype = CPU_VR4133;
261 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
262 c->cputype = CPU_VR41XX;
265 c->isa_level = MIPS_CPU_ISA_III;
266 c->options = R4K_OPTS;
270 c->cputype = CPU_R4300;
271 c->isa_level = MIPS_CPU_ISA_III;
272 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
277 c->cputype = CPU_R4600;
278 c->isa_level = MIPS_CPU_ISA_III;
279 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
285 * This processor doesn't have an MMU, so it's not
286 * "real easy" to run Linux on it. It is left purely
287 * for documentation. Commented out because it shares
288 * it's c0_prid id number with the TX3900.
290 c->cputype = CPU_R4650;
291 c->isa_level = MIPS_CPU_ISA_III;
292 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
297 c->isa_level = MIPS_CPU_ISA_I;
298 c->options = MIPS_CPU_TLB;
300 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
301 c->cputype = CPU_TX3927;
304 switch (c->processor_id & 0xff) {
305 case PRID_REV_TX3912:
306 c->cputype = CPU_TX3912;
309 case PRID_REV_TX3922:
310 c->cputype = CPU_TX3922;
314 c->cputype = CPU_UNKNOWN;
320 c->cputype = CPU_R4700;
321 c->isa_level = MIPS_CPU_ISA_III;
322 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
327 c->cputype = CPU_TX49XX;
328 c->isa_level = MIPS_CPU_ISA_III;
329 c->options = R4K_OPTS | MIPS_CPU_LLSC;
330 if (!(c->processor_id & 0x08))
331 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
335 c->cputype = CPU_R5000;
336 c->isa_level = MIPS_CPU_ISA_IV;
337 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
342 c->cputype = CPU_R5432;
343 c->isa_level = MIPS_CPU_ISA_IV;
344 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
345 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
349 c->cputype = CPU_R5500;
350 c->isa_level = MIPS_CPU_ISA_IV;
351 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
352 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
355 case PRID_IMP_NEVADA:
356 c->cputype = CPU_NEVADA;
357 c->isa_level = MIPS_CPU_ISA_IV;
358 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
359 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
363 c->cputype = CPU_R6000;
364 c->isa_level = MIPS_CPU_ISA_II;
365 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
369 case PRID_IMP_R6000A:
370 c->cputype = CPU_R6000A;
371 c->isa_level = MIPS_CPU_ISA_II;
372 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
376 case PRID_IMP_RM7000:
377 c->cputype = CPU_RM7000;
378 c->isa_level = MIPS_CPU_ISA_IV;
379 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
382 * Undocumented RM7000: Bit 29 in the info register of
383 * the RM7000 v2.0 indicates if the TLB has 48 or 64
386 * 29 1 => 64 entry JTLB
389 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
391 case PRID_IMP_RM9000:
392 c->cputype = CPU_RM9000;
393 c->isa_level = MIPS_CPU_ISA_IV;
394 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
397 * Bit 29 in the info register of the RM9000
398 * indicates if the TLB has 48 or 64 entries.
400 * 29 1 => 64 entry JTLB
403 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
406 c->cputype = CPU_R8000;
407 c->isa_level = MIPS_CPU_ISA_IV;
408 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
409 MIPS_CPU_FPU | MIPS_CPU_32FPR |
411 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
413 case PRID_IMP_R10000:
414 c->cputype = CPU_R10000;
415 c->isa_level = MIPS_CPU_ISA_IV;
416 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
417 MIPS_CPU_FPU | MIPS_CPU_32FPR |
418 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
422 case PRID_IMP_R12000:
423 c->cputype = CPU_R12000;
424 c->isa_level = MIPS_CPU_ISA_IV;
425 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
426 MIPS_CPU_FPU | MIPS_CPU_32FPR |
427 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
434 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
436 unsigned int config0;
439 config0 = read_c0_config();
441 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
442 c->options |= MIPS_CPU_TLB | MIPS_CPU_4KTLB;
443 isa = (config0 & MIPS_CONF_AT) >> 13;
446 c->isa_level = MIPS_CPU_ISA_M32;
449 c->isa_level = MIPS_CPU_ISA_M64;
452 panic("Unsupported ISA type, cp0.config0.at: %d.", isa);
455 return config0 & MIPS_CONF_M;
458 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
460 unsigned int config1;
462 config1 = read_c0_config1();
464 if (config1 & MIPS_CONF1_MD)
465 c->ases |= MIPS_ASE_MDMX;
466 if (config1 & MIPS_CONF1_WR)
467 c->options |= MIPS_CPU_WATCH;
468 if (config1 & MIPS_CONF1_CA)
469 c->ases |= MIPS_ASE_MIPS16;
470 if (config1 & MIPS_CONF1_EP)
471 c->options |= MIPS_CPU_EJTAG;
472 if (config1 & MIPS_CONF1_FP) {
473 c->options |= MIPS_CPU_FPU;
474 c->options |= MIPS_CPU_32FPR;
477 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
479 return config1 & MIPS_CONF_M;
482 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
484 unsigned int config2;
486 config2 = read_c0_config2();
488 if (config2 & MIPS_CONF2_SL)
489 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
491 return config2 & MIPS_CONF_M;
494 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
496 unsigned int config3;
498 config3 = read_c0_config3();
500 if (config3 & MIPS_CONF3_SM)
501 c->ases |= MIPS_ASE_SMARTMIPS;
502 if (config3 & MIPS_CONF3_DSP)
503 c->ases |= MIPS_ASE_DSP;
505 return config3 & MIPS_CONF_M;
508 static inline void decode_configs(struct cpuinfo_mips *c)
510 /* MIPS32 or MIPS64 compliant CPU. */
511 c->options = MIPS_CPU_4KEX | MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
512 MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
514 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
516 /* Read Config registers. */
517 if (!decode_config0(c))
518 return; /* actually worth a panic() */
519 if (!decode_config1(c))
521 if (!decode_config2(c))
523 if (!decode_config3(c))
527 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
530 switch (c->processor_id & 0xff00) {
532 c->cputype = CPU_4KC;
535 c->cputype = CPU_4KEC;
537 case PRID_IMP_4KECR2:
538 c->cputype = CPU_4KEC;
541 c->cputype = CPU_4KSC;
544 c->cputype = CPU_5KC;
547 c->cputype = CPU_20KC;
551 c->cputype = CPU_24K;
554 c->cputype = CPU_25KF;
555 /* Probe for L2 cache */
556 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
559 c->cputype = CPU_34K;
560 c->isa_level = MIPS_CPU_ISA_M32;
565 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
568 switch (c->processor_id & 0xff00) {
569 case PRID_IMP_AU1_REV1:
570 case PRID_IMP_AU1_REV2:
571 switch ((c->processor_id >> 24) & 0xff) {
573 c->cputype = CPU_AU1000;
576 c->cputype = CPU_AU1500;
579 c->cputype = CPU_AU1100;
582 c->cputype = CPU_AU1550;
585 c->cputype = CPU_AU1200;
588 panic("Unknown Au Core!");
595 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
598 switch (c->processor_id & 0xff00) {
600 c->cputype = CPU_SB1;
601 #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
602 /* FPU in pass1 is known to have issues. */
603 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
609 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
612 switch (c->processor_id & 0xff00) {
613 case PRID_IMP_SR71000:
614 c->cputype = CPU_SR71000;
621 __init void cpu_probe(void)
623 struct cpuinfo_mips *c = ¤t_cpu_data;
625 c->processor_id = PRID_IMP_UNKNOWN;
626 c->fpu_id = FPIR_IMP_NONE;
627 c->cputype = CPU_UNKNOWN;
629 c->processor_id = read_c0_prid();
630 switch (c->processor_id & 0xff0000) {
631 case PRID_COMP_LEGACY:
637 case PRID_COMP_ALCHEMY:
638 cpu_probe_alchemy(c);
640 case PRID_COMP_SIBYTE:
643 case PRID_COMP_SANDCRAFT:
644 cpu_probe_sandcraft(c);
647 c->cputype = CPU_UNKNOWN;
649 if (c->options & MIPS_CPU_FPU) {
650 c->fpu_id = cpu_get_fpu_id();
652 if (c->isa_level == MIPS_CPU_ISA_M32 ||
653 c->isa_level == MIPS_CPU_ISA_M64) {
654 if (c->fpu_id & MIPS_FPIR_3D)
655 c->ases |= MIPS_ASE_MIPS3D;
660 __init void cpu_report(void)
662 struct cpuinfo_mips *c = ¤t_cpu_data;
664 printk("CPU revision is: %08x\n", c->processor_id);
665 if (c->options & MIPS_CPU_FPU)
666 printk("FPU revision is: %08x\n", c->fpu_id);