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. */
56 static void au1k_wait(void)
58 unsigned long addr = 0;
59 /* using the wait instruction makes CP0 counter unusable */
60 __asm__("la %0,au1k_wait\n\t"
62 "cache 0x14,0(%0)\n\t"
63 "cache 0x14,32(%0)\n\t"
75 static inline void check_wait(void)
77 struct cpuinfo_mips *c = ¤t_cpu_data;
79 printk("Checking for 'wait' instruction... ");
83 cpu_wait = r3081_wait;
84 printk(" available.\n");
87 cpu_wait = r39xx_wait;
88 printk(" available.\n");
109 printk(" available.\n");
116 if (allow_au1k_wait) {
117 cpu_wait = au1k_wait;
118 printk(" available.\n");
120 printk(" unavailable.\n");
123 printk(" unavailable.\n");
128 void __init check_bugs32(void)
134 * Probe whether cpu has config register by trying to play with
135 * alternate cache bit and see whether it matters.
136 * It's used by cpu_probe to distinguish between R3000A and R3081.
138 static inline int cpu_has_confreg(void)
140 #ifdef CONFIG_CPU_R3000
141 extern unsigned long r3k_cache_size(unsigned long);
142 unsigned long size1, size2;
143 unsigned long cfg = read_c0_conf();
145 size1 = r3k_cache_size(ST0_ISC);
146 write_c0_conf(cfg ^ R30XX_CONF_AC);
147 size2 = r3k_cache_size(ST0_ISC);
149 return size1 != size2;
156 * Get the FPU Implementation/Revision.
158 static inline unsigned long cpu_get_fpu_id(void)
160 unsigned long tmp, fpu_id;
162 tmp = read_c0_status();
164 fpu_id = read_32bit_cp1_register(CP1_REVISION);
165 write_c0_status(tmp);
170 * Check the CPU has an FPU the official way.
172 static inline int __cpu_has_fpu(void)
174 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
177 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4KTLB \
180 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
182 switch (c->processor_id & 0xff00) {
184 c->cputype = CPU_R2000;
185 c->isa_level = MIPS_CPU_ISA_I;
186 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
188 c->options |= MIPS_CPU_FPU;
192 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
193 if (cpu_has_confreg())
194 c->cputype = CPU_R3081E;
196 c->cputype = CPU_R3000A;
198 c->cputype = CPU_R3000;
199 c->isa_level = MIPS_CPU_ISA_I;
200 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
202 c->options |= MIPS_CPU_FPU;
206 if (read_c0_config() & CONF_SC) {
207 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
208 c->cputype = CPU_R4400PC;
210 c->cputype = CPU_R4000PC;
212 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
213 c->cputype = CPU_R4400SC;
215 c->cputype = CPU_R4000SC;
218 c->isa_level = MIPS_CPU_ISA_III;
219 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
220 MIPS_CPU_WATCH | MIPS_CPU_VCE |
224 case PRID_IMP_VR41XX:
225 switch (c->processor_id & 0xf0) {
226 case PRID_REV_VR4111:
227 c->cputype = CPU_VR4111;
229 case PRID_REV_VR4121:
230 c->cputype = CPU_VR4121;
232 case PRID_REV_VR4122:
233 if ((c->processor_id & 0xf) < 0x3)
234 c->cputype = CPU_VR4122;
236 c->cputype = CPU_VR4181A;
238 case PRID_REV_VR4130:
239 if ((c->processor_id & 0xf) < 0x4)
240 c->cputype = CPU_VR4131;
242 c->cputype = CPU_VR4133;
245 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
246 c->cputype = CPU_VR41XX;
249 c->isa_level = MIPS_CPU_ISA_III;
250 c->options = R4K_OPTS;
254 c->cputype = CPU_R4300;
255 c->isa_level = MIPS_CPU_ISA_III;
256 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
261 c->cputype = CPU_R4600;
262 c->isa_level = MIPS_CPU_ISA_III;
263 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
269 * This processor doesn't have an MMU, so it's not
270 * "real easy" to run Linux on it. It is left purely
271 * for documentation. Commented out because it shares
272 * it's c0_prid id number with the TX3900.
274 c->cputype = CPU_R4650;
275 c->isa_level = MIPS_CPU_ISA_III;
276 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
281 c->isa_level = MIPS_CPU_ISA_I;
282 c->options = MIPS_CPU_TLB;
284 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
285 c->cputype = CPU_TX3927;
288 switch (c->processor_id & 0xff) {
289 case PRID_REV_TX3912:
290 c->cputype = CPU_TX3912;
293 case PRID_REV_TX3922:
294 c->cputype = CPU_TX3922;
298 c->cputype = CPU_UNKNOWN;
304 c->cputype = CPU_R4700;
305 c->isa_level = MIPS_CPU_ISA_III;
306 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
311 c->cputype = CPU_TX49XX;
312 c->isa_level = MIPS_CPU_ISA_III;
313 c->options = R4K_OPTS | MIPS_CPU_LLSC;
314 if (!(c->processor_id & 0x08))
315 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
319 c->cputype = CPU_R5000;
320 c->isa_level = MIPS_CPU_ISA_IV;
321 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
326 c->cputype = CPU_R5432;
327 c->isa_level = MIPS_CPU_ISA_IV;
328 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
329 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
333 c->cputype = CPU_R5500;
334 c->isa_level = MIPS_CPU_ISA_IV;
335 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
336 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
339 case PRID_IMP_NEVADA:
340 c->cputype = CPU_NEVADA;
341 c->isa_level = MIPS_CPU_ISA_IV;
342 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
343 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
347 c->cputype = CPU_R6000;
348 c->isa_level = MIPS_CPU_ISA_II;
349 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
353 case PRID_IMP_R6000A:
354 c->cputype = CPU_R6000A;
355 c->isa_level = MIPS_CPU_ISA_II;
356 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
360 case PRID_IMP_RM7000:
361 c->cputype = CPU_RM7000;
362 c->isa_level = MIPS_CPU_ISA_IV;
363 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
366 * Undocumented RM7000: Bit 29 in the info register of
367 * the RM7000 v2.0 indicates if the TLB has 48 or 64
370 * 29 1 => 64 entry JTLB
373 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
375 case PRID_IMP_RM9000:
376 c->cputype = CPU_RM9000;
377 c->isa_level = MIPS_CPU_ISA_IV;
378 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
381 * Bit 29 in the info register of the RM9000
382 * indicates if the TLB has 48 or 64 entries.
384 * 29 1 => 64 entry JTLB
387 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
390 c->cputype = CPU_R8000;
391 c->isa_level = MIPS_CPU_ISA_IV;
392 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
393 MIPS_CPU_FPU | MIPS_CPU_32FPR |
395 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
397 case PRID_IMP_R10000:
398 c->cputype = CPU_R10000;
399 c->isa_level = MIPS_CPU_ISA_IV;
400 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
401 MIPS_CPU_FPU | MIPS_CPU_32FPR |
402 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
406 case PRID_IMP_R12000:
407 c->cputype = CPU_R12000;
408 c->isa_level = MIPS_CPU_ISA_IV;
409 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
410 MIPS_CPU_FPU | MIPS_CPU_32FPR |
411 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
418 static inline unsigned int decode_config0(struct cpuinfo_mips *c)
420 unsigned int config0;
423 config0 = read_c0_config();
425 if (((config0 & MIPS_CONF_MT) >> 7) == 1)
426 c->options |= MIPS_CPU_TLB;
427 isa = (config0 & MIPS_CONF_AT) >> 13;
430 c->isa_level = MIPS_CPU_ISA_M32;
433 c->isa_level = MIPS_CPU_ISA_M64;
436 panic("Unsupported ISA type, cp0.config0.at: %d.", isa);
439 return config0 & MIPS_CONF_M;
442 static inline unsigned int decode_config1(struct cpuinfo_mips *c)
444 unsigned int config1;
446 config1 = read_c0_config1();
448 if (config1 & MIPS_CONF1_MD)
449 c->ases |= MIPS_ASE_MDMX;
450 if (config1 & MIPS_CONF1_WR)
451 c->options |= MIPS_CPU_WATCH;
452 if (config1 & MIPS_CONF1_CA)
453 c->ases |= MIPS_ASE_MIPS16;
454 if (config1 & MIPS_CONF1_EP)
455 c->options |= MIPS_CPU_EJTAG;
456 if (config1 & MIPS_CONF1_FP) {
457 c->options |= MIPS_CPU_FPU;
458 c->options |= MIPS_CPU_32FPR;
461 c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
463 return config1 & MIPS_CONF_M;
466 static inline unsigned int decode_config2(struct cpuinfo_mips *c)
468 unsigned int config2;
470 config2 = read_c0_config2();
472 if (config2 & MIPS_CONF2_SL)
473 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
475 return config2 & MIPS_CONF_M;
478 static inline unsigned int decode_config3(struct cpuinfo_mips *c)
480 unsigned int config3;
482 config3 = read_c0_config3();
484 if (config3 & MIPS_CONF3_SM)
485 c->ases |= MIPS_ASE_SMARTMIPS;
487 return config3 & MIPS_CONF_M;
490 static inline void decode_configs(struct cpuinfo_mips *c)
492 /* MIPS32 or MIPS64 compliant CPU. */
493 c->options = MIPS_CPU_4KEX | MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
494 MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
496 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
498 /* Read Config registers. */
499 if (!decode_config0(c))
500 return; /* actually worth a panic() */
501 if (!decode_config1(c))
503 if (!decode_config2(c))
505 if (!decode_config3(c))
509 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
513 c->options |= MIPS_CPU_4KTLB;
514 switch (c->processor_id & 0xff00) {
516 c->cputype = CPU_4KC;
519 c->cputype = CPU_4KEC;
521 case PRID_IMP_4KECR2:
522 c->cputype = CPU_4KEC;
525 c->cputype = CPU_4KSC;
528 c->cputype = CPU_5KC;
531 c->cputype = CPU_20KC;
534 c->cputype = CPU_24K;
537 c->cputype = CPU_25KF;
538 /* Probe for L2 cache */
539 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
544 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
547 switch (c->processor_id & 0xff00) {
548 case PRID_IMP_AU1_REV1:
549 case PRID_IMP_AU1_REV2:
550 switch ((c->processor_id >> 24) & 0xff) {
552 c->cputype = CPU_AU1000;
555 c->cputype = CPU_AU1500;
558 c->cputype = CPU_AU1100;
561 c->cputype = CPU_AU1550;
564 c->cputype = CPU_AU1200;
567 panic("Unknown Au Core!");
574 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
577 switch (c->processor_id & 0xff00) {
579 c->cputype = CPU_SB1;
580 #ifdef CONFIG_SB1_PASS_1_WORKAROUNDS
581 /* FPU in pass1 is known to have issues. */
582 c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
588 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
592 c->options |= MIPS_CPU_4KTLB;
593 switch (c->processor_id & 0xff00) {
594 case PRID_IMP_SR71000:
595 c->cputype = CPU_SR71000;
602 __init void cpu_probe(void)
604 struct cpuinfo_mips *c = ¤t_cpu_data;
606 c->processor_id = PRID_IMP_UNKNOWN;
607 c->fpu_id = FPIR_IMP_NONE;
608 c->cputype = CPU_UNKNOWN;
610 c->processor_id = read_c0_prid();
611 switch (c->processor_id & 0xff0000) {
612 case PRID_COMP_LEGACY:
618 case PRID_COMP_ALCHEMY:
619 cpu_probe_alchemy(c);
621 case PRID_COMP_SIBYTE:
624 case PRID_COMP_SANDCRAFT:
625 cpu_probe_sandcraft(c);
628 c->cputype = CPU_UNKNOWN;
630 if (c->options & MIPS_CPU_FPU) {
631 c->fpu_id = cpu_get_fpu_id();
633 if (c->isa_level == MIPS_CPU_ISA_M32 ||
634 c->isa_level == MIPS_CPU_ISA_M64) {
635 if (c->fpu_id & MIPS_FPIR_3D)
636 c->ases |= MIPS_ASE_MIPS3D;
641 __init void cpu_report(void)
643 struct cpuinfo_mips *c = ¤t_cpu_data;
645 printk("CPU revision is: %08x\n", c->processor_id);
646 if (c->options & MIPS_CPU_FPU)
647 printk("FPU revision is: %08x\n", c->fpu_id);