Fixed buglet with previous patch that broke non au1x builds.
[linux-2.6/linux-mips.git] / arch / mips / kernel / cpu-probe.c
blobf3cad174ebd3aad3083aa65ab29fdbabd7b3e6fc
1 /*
2 * Processor capabilities determination functions.
4 * Copyright (C) xxxx the Anonymous
5 * Copyright (C) 2003 Maciej W. Rozycki
6 * Copyright (C) 1994 - 2003 Ralf Baechle
7 * Copyright (C) 2001 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>
20 #include <asm/bugs.h>
21 #include <asm/cpu.h>
22 #include <asm/fpu.h>
23 #include <asm/mipsregs.h>
24 #include <asm/system.h>
27 * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
28 * the implementation of the "wait" feature differs between CPU families. This
29 * points to the function that implements CPU specific wait.
30 * The wait instruction stops the pipeline and reduces the power consumption of
31 * the CPU very much.
33 void (*cpu_wait)(void) = NULL;
35 static void r3081_wait(void)
37 unsigned long cfg = read_c0_conf();
38 write_c0_conf(cfg | R30XX_CONF_HALT);
41 static void r39xx_wait(void)
43 unsigned long cfg = read_c0_conf();
44 write_c0_conf(cfg | TX39_CONF_HALT);
47 static void r4k_wait(void)
49 __asm__(".set\tmips3\n\t"
50 "wait\n\t"
51 ".set\tmips0");
54 /* The Au1xxx wait is available only if using 32khz counter or
55 * external timer source, but specifically not CP0 Counter. */
56 int allow_au1k_wait;
57 static void au1k_wait(void)
59 unsigned long addr = 0;
60 /* using the wait instruction makes CP0 counter unusable */
61 __asm__("la %0,au1k_wait\n\t"
62 ".set mips3\n\t"
63 "cache 0x14,0(%0)\n\t"
64 "cache 0x14,32(%0)\n\t"
65 "sync\n\t"
66 "nop\n\t"
67 "wait\n\t"
68 "nop\n\t"
69 "nop\n\t"
70 "nop\n\t"
71 "nop\n\t"
72 ".set mips0\n\t"
73 : : "r" (addr));
76 static inline void check_wait(void)
78 struct cpuinfo_mips *c = &current_cpu_data;
80 printk("Checking for 'wait' instruction... ");
81 switch (c->cputype) {
82 case CPU_R3081:
83 case CPU_R3081E:
84 cpu_wait = r3081_wait;
85 printk(" available.\n");
86 break;
87 case CPU_TX3927:
88 cpu_wait = r39xx_wait;
89 printk(" available.\n");
90 break;
91 case CPU_R4200:
92 /* case CPU_R4300: */
93 case CPU_R4600:
94 case CPU_R4640:
95 case CPU_R4650:
96 case CPU_R4700:
97 case CPU_R5000:
98 case CPU_NEVADA:
99 case CPU_RM7000:
100 case CPU_RM9000:
101 case CPU_TX49XX:
102 case CPU_4KC:
103 case CPU_4KEC:
104 case CPU_4KSC:
105 case CPU_5KC:
106 /* case CPU_20KC:*/
107 case CPU_24K:
108 case CPU_25KF:
109 cpu_wait = r4k_wait;
110 printk(" available.\n");
111 break;
112 case CPU_AU1000:
113 case CPU_AU1100:
114 case CPU_AU1500:
115 case CPU_AU1550:
116 case CPU_AU1200:
117 if (allow_au1k_wait) {
118 cpu_wait = au1k_wait;
119 printk(" available.\n");
120 } else
121 printk(" unavailable.\n");
122 break;
123 default:
124 printk(" unavailable.\n");
125 break;
129 void __init check_bugs32(void)
131 check_wait();
135 * Probe whether cpu has config register by trying to play with
136 * alternate cache bit and see whether it matters.
137 * It's used by cpu_probe to distinguish between R3000A and R3081.
139 static inline int cpu_has_confreg(void)
141 #ifdef CONFIG_CPU_R3000
142 extern unsigned long r3k_cache_size(unsigned long);
143 unsigned long size1, size2;
144 unsigned long cfg = read_c0_conf();
146 size1 = r3k_cache_size(ST0_ISC);
147 write_c0_conf(cfg ^ R30XX_CONF_AC);
148 size2 = r3k_cache_size(ST0_ISC);
149 write_c0_conf(cfg);
150 return size1 != size2;
151 #else
152 return 0;
153 #endif
157 * Get the FPU Implementation/Revision.
159 static inline unsigned long cpu_get_fpu_id(void)
161 unsigned long tmp, fpu_id;
163 tmp = read_c0_status();
164 __enable_fpu();
165 fpu_id = read_32bit_cp1_register(CP1_REVISION);
166 write_c0_status(tmp);
167 return fpu_id;
171 * Check the CPU has an FPU the official way.
173 static inline int __cpu_has_fpu(void)
175 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
178 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4KTLB \
179 | MIPS_CPU_COUNTER)
181 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
183 switch (c->processor_id & 0xff00) {
184 case PRID_IMP_R2000:
185 c->cputype = CPU_R2000;
186 c->isa_level = MIPS_CPU_ISA_I;
187 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
188 if (__cpu_has_fpu())
189 c->options |= MIPS_CPU_FPU;
190 c->tlbsize = 64;
191 break;
192 case PRID_IMP_R3000:
193 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
194 if (cpu_has_confreg())
195 c->cputype = CPU_R3081E;
196 else
197 c->cputype = CPU_R3000A;
198 else
199 c->cputype = CPU_R3000;
200 c->isa_level = MIPS_CPU_ISA_I;
201 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
202 if (__cpu_has_fpu())
203 c->options |= MIPS_CPU_FPU;
204 c->tlbsize = 64;
205 break;
206 case PRID_IMP_R4000:
207 if (read_c0_config() & CONF_SC) {
208 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
209 c->cputype = CPU_R4400PC;
210 else
211 c->cputype = CPU_R4000PC;
212 } else {
213 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
214 c->cputype = CPU_R4400SC;
215 else
216 c->cputype = CPU_R4000SC;
219 c->isa_level = MIPS_CPU_ISA_III;
220 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
221 MIPS_CPU_WATCH | MIPS_CPU_VCE |
222 MIPS_CPU_LLSC;
223 c->tlbsize = 48;
224 break;
225 case PRID_IMP_VR41XX:
226 switch (c->processor_id & 0xf0) {
227 #ifndef CONFIG_VR4181
228 case PRID_REV_VR4111:
229 c->cputype = CPU_VR4111;
230 break;
231 #else
232 case PRID_REV_VR4181:
233 c->cputype = CPU_VR4181;
234 break;
235 #endif
236 case PRID_REV_VR4121:
237 c->cputype = CPU_VR4121;
238 break;
239 case PRID_REV_VR4122:
240 if ((c->processor_id & 0xf) < 0x3)
241 c->cputype = CPU_VR4122;
242 else
243 c->cputype = CPU_VR4181A;
244 break;
245 case PRID_REV_VR4130:
246 if ((c->processor_id & 0xf) < 0x4)
247 c->cputype = CPU_VR4131;
248 else
249 c->cputype = CPU_VR4133;
250 break;
251 default:
252 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
253 c->cputype = CPU_VR41XX;
254 break;
256 c->isa_level = MIPS_CPU_ISA_III;
257 c->options = R4K_OPTS;
258 c->tlbsize = 32;
259 break;
260 case PRID_IMP_R4300:
261 c->cputype = CPU_R4300;
262 c->isa_level = MIPS_CPU_ISA_III;
263 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
264 MIPS_CPU_LLSC;
265 c->tlbsize = 32;
266 break;
267 case PRID_IMP_R4600:
268 c->cputype = CPU_R4600;
269 c->isa_level = MIPS_CPU_ISA_III;
270 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
271 c->tlbsize = 48;
272 break;
273 #if 0
274 case PRID_IMP_R4650:
276 * This processor doesn't have an MMU, so it's not
277 * "real easy" to run Linux on it. It is left purely
278 * for documentation. Commented out because it shares
279 * it's c0_prid id number with the TX3900.
281 c->cputype = CPU_R4650;
282 c->isa_level = MIPS_CPU_ISA_III;
283 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
284 c->tlbsize = 48;
285 break;
286 #endif
287 case PRID_IMP_TX39:
288 c->isa_level = MIPS_CPU_ISA_I;
289 c->options = MIPS_CPU_TLB;
291 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
292 c->cputype = CPU_TX3927;
293 c->tlbsize = 64;
294 } else {
295 switch (c->processor_id & 0xff) {
296 case PRID_REV_TX3912:
297 c->cputype = CPU_TX3912;
298 c->tlbsize = 32;
299 break;
300 case PRID_REV_TX3922:
301 c->cputype = CPU_TX3922;
302 c->tlbsize = 64;
303 break;
304 default:
305 c->cputype = CPU_UNKNOWN;
306 break;
309 break;
310 case PRID_IMP_R4700:
311 c->cputype = CPU_R4700;
312 c->isa_level = MIPS_CPU_ISA_III;
313 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
314 MIPS_CPU_LLSC;
315 c->tlbsize = 48;
316 break;
317 case PRID_IMP_TX49:
318 c->cputype = CPU_TX49XX;
319 c->isa_level = MIPS_CPU_ISA_III;
320 c->options = R4K_OPTS | MIPS_CPU_LLSC;
321 if (!(c->processor_id & 0x08))
322 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
323 c->tlbsize = 48;
324 break;
325 case PRID_IMP_R5000:
326 c->cputype = CPU_R5000;
327 c->isa_level = MIPS_CPU_ISA_IV;
328 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
329 MIPS_CPU_LLSC;
330 c->tlbsize = 48;
331 break;
332 case PRID_IMP_R5432:
333 c->cputype = CPU_R5432;
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;
337 c->tlbsize = 48;
338 break;
339 case PRID_IMP_R5500:
340 c->cputype = CPU_R5500;
341 c->isa_level = MIPS_CPU_ISA_IV;
342 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
343 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
344 c->tlbsize = 48;
345 break;
346 case PRID_IMP_NEVADA:
347 c->cputype = CPU_NEVADA;
348 c->isa_level = MIPS_CPU_ISA_IV;
349 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
350 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
351 c->tlbsize = 48;
352 break;
353 case PRID_IMP_R6000:
354 c->cputype = CPU_R6000;
355 c->isa_level = MIPS_CPU_ISA_II;
356 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
357 MIPS_CPU_LLSC;
358 c->tlbsize = 32;
359 break;
360 case PRID_IMP_R6000A:
361 c->cputype = CPU_R6000A;
362 c->isa_level = MIPS_CPU_ISA_II;
363 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
364 MIPS_CPU_LLSC;
365 c->tlbsize = 32;
366 break;
367 case PRID_IMP_RM7000:
368 c->cputype = CPU_RM7000;
369 c->isa_level = MIPS_CPU_ISA_IV;
370 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
371 MIPS_CPU_LLSC;
373 * Undocumented RM7000: Bit 29 in the info register of
374 * the RM7000 v2.0 indicates if the TLB has 48 or 64
375 * entries.
377 * 29 1 => 64 entry JTLB
378 * 0 => 48 entry JTLB
380 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
381 break;
382 case PRID_IMP_RM9000:
383 c->cputype = CPU_RM9000;
384 c->isa_level = MIPS_CPU_ISA_IV;
385 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
386 MIPS_CPU_LLSC;
388 * Bit 29 in the info register of the RM9000
389 * indicates if the TLB has 48 or 64 entries.
391 * 29 1 => 64 entry JTLB
392 * 0 => 48 entry JTLB
394 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
395 break;
396 case PRID_IMP_R8000:
397 c->cputype = CPU_R8000;
398 c->isa_level = MIPS_CPU_ISA_IV;
399 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
400 MIPS_CPU_FPU | MIPS_CPU_32FPR |
401 MIPS_CPU_LLSC;
402 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
403 break;
404 case PRID_IMP_R10000:
405 c->cputype = CPU_R10000;
406 c->isa_level = MIPS_CPU_ISA_IV;
407 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
408 MIPS_CPU_FPU | MIPS_CPU_32FPR |
409 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
410 MIPS_CPU_LLSC;
411 c->tlbsize = 64;
412 break;
413 case PRID_IMP_R12000:
414 c->cputype = CPU_R12000;
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 |
419 MIPS_CPU_LLSC;
420 c->tlbsize = 64;
421 break;
425 static inline void decode_config1(struct cpuinfo_mips *c)
427 unsigned long config0 = read_c0_config();
428 unsigned long config1;
430 if ((config0 & (1 << 31)) == 0)
431 return; /* actually wort a panic() */
433 /* MIPS32 or MIPS64 compliant CPU. Read Config 1 register. */
434 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
435 MIPS_CPU_4KTLB | MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
436 MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
437 config1 = read_c0_config1();
438 if (config1 & (1 << 3))
439 c->options |= MIPS_CPU_WATCH;
440 if (config1 & (1 << 2))
441 c->options |= MIPS_CPU_MIPS16;
442 if (config1 & (1 << 1))
443 c->options |= MIPS_CPU_EJTAG;
444 if (config1 & 1) {
445 c->options |= MIPS_CPU_FPU;
446 c->options |= MIPS_CPU_32FPR;
448 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
450 c->tlbsize = ((config1 >> 25) & 0x3f) + 1;
453 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
455 decode_config1(c);
456 switch (c->processor_id & 0xff00) {
457 case PRID_IMP_4KC:
458 c->cputype = CPU_4KC;
459 c->isa_level = MIPS_CPU_ISA_M32;
460 break;
461 case PRID_IMP_4KEC:
462 c->cputype = CPU_4KEC;
463 c->isa_level = MIPS_CPU_ISA_M32;
464 break;
465 case PRID_IMP_4KSC:
466 c->cputype = CPU_4KSC;
467 c->isa_level = MIPS_CPU_ISA_M32;
468 break;
469 case PRID_IMP_5KC:
470 c->cputype = CPU_5KC;
471 c->isa_level = MIPS_CPU_ISA_M64;
472 break;
473 case PRID_IMP_20KC:
474 c->cputype = CPU_20KC;
475 c->isa_level = MIPS_CPU_ISA_M64;
476 break;
477 case PRID_IMP_24K:
478 c->cputype = CPU_24K;
479 c->isa_level = MIPS_CPU_ISA_M32;
480 break;
481 case PRID_IMP_25KF:
482 c->cputype = CPU_25KF;
483 c->isa_level = MIPS_CPU_ISA_M64;
484 /* Probe for L2 cache */
485 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
486 break;
490 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
492 decode_config1(c);
493 switch (c->processor_id & 0xff00) {
494 case PRID_IMP_AU1_REV1:
495 case PRID_IMP_AU1_REV2:
496 switch ((c->processor_id >> 24) & 0xff) {
497 case 0:
498 c->cputype = CPU_AU1000;
499 break;
500 case 1:
501 c->cputype = CPU_AU1500;
502 break;
503 case 2:
504 c->cputype = CPU_AU1100;
505 break;
506 case 3:
507 c->cputype = CPU_AU1550;
508 break;
509 case 4:
510 c->cputype = CPU_AU1200;
511 break;
512 default:
513 panic("Unknown Au Core!");
514 break;
516 c->isa_level = MIPS_CPU_ISA_M32;
517 break;
521 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
523 decode_config1(c);
524 switch (c->processor_id & 0xff00) {
525 case PRID_IMP_SB1:
526 c->cputype = CPU_SB1;
527 c->isa_level = MIPS_CPU_ISA_M64;
528 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
529 MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
530 MIPS_CPU_MCHECK | MIPS_CPU_EJTAG |
531 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
532 #ifndef CONFIG_SB1_PASS_1_WORKAROUNDS
533 /* FPU in pass1 is known to have issues. */
534 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
535 #endif
536 break;
540 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
542 decode_config1(c);
543 switch (c->processor_id & 0xff00) {
544 case PRID_IMP_SR71000:
545 c->cputype = CPU_SR71000;
546 c->isa_level = MIPS_CPU_ISA_M64;
547 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
548 MIPS_CPU_4KTLB | MIPS_CPU_FPU |
549 MIPS_CPU_COUNTER | MIPS_CPU_MCHECK;
550 c->scache.ways = 8;
551 c->tlbsize = 64;
552 break;
556 __init void cpu_probe(void)
558 struct cpuinfo_mips *c = &current_cpu_data;
560 c->processor_id = PRID_IMP_UNKNOWN;
561 c->fpu_id = FPIR_IMP_NONE;
562 c->cputype = CPU_UNKNOWN;
564 c->processor_id = read_c0_prid();
565 switch (c->processor_id & 0xff0000) {
566 case PRID_COMP_LEGACY:
567 cpu_probe_legacy(c);
568 break;
569 case PRID_COMP_MIPS:
570 cpu_probe_mips(c);
571 break;
572 case PRID_COMP_ALCHEMY:
573 cpu_probe_alchemy(c);
574 break;
575 case PRID_COMP_SIBYTE:
576 cpu_probe_sibyte(c);
577 break;
579 case PRID_COMP_SANDCRAFT:
580 cpu_probe_sandcraft(c);
581 break;
582 default:
583 c->cputype = CPU_UNKNOWN;
585 if (c->options & MIPS_CPU_FPU)
586 c->fpu_id = cpu_get_fpu_id();
589 __init void cpu_report(void)
591 struct cpuinfo_mips *c = &current_cpu_data;
593 printk("CPU revision is: %08x\n", c->processor_id);
594 if (c->options & MIPS_CPU_FPU)
595 printk("FPU revision is: %08x\n", c->fpu_id);