initial commit with v2.6.9
[linux-2.6.9-moxart.git] / arch / mips / kernel / cpu-probe.c
blob36777476dae176011f9669230b761c2f74105019
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");
55 * The Au1xxx wait is available only if we run CONFIG_PM and
56 * the timer setup found we had a 32KHz counter available.
57 * There are still problems with functions that may call au1k_wait
58 * directly, but that will be discovered pretty quickly.
60 extern void (*au1k_wait_ptr)(void);
62 void au1k_wait(void)
64 #ifdef CONFIG_PM
65 /* using the wait instruction makes CP0 counter unusable */
66 __asm__(".set\tmips3\n\t"
67 "wait\n\t"
68 "nop\n\t"
69 "nop\n\t"
70 "nop\n\t"
71 "nop\n\t"
72 ".set\tmips0");
73 #else
74 __asm__("nop\n\t"
75 "nop");
76 #endif
79 static inline void check_wait(void)
81 struct cpuinfo_mips *c = &current_cpu_data;
83 printk("Checking for 'wait' instruction... ");
84 switch (c->cputype) {
85 case CPU_R3081:
86 case CPU_R3081E:
87 cpu_wait = r3081_wait;
88 printk(" available.\n");
89 break;
90 case CPU_TX3927:
91 cpu_wait = r39xx_wait;
92 printk(" available.\n");
93 break;
94 case CPU_R4200:
95 /* case CPU_R4300: */
96 case CPU_R4600:
97 case CPU_R4640:
98 case CPU_R4650:
99 case CPU_R4700:
100 case CPU_R5000:
101 case CPU_NEVADA:
102 case CPU_RM7000:
103 case CPU_TX49XX:
104 case CPU_4KC:
105 case CPU_4KEC:
106 case CPU_4KSC:
107 case CPU_5KC:
108 /* case CPU_20KC:*/
109 case CPU_24K:
110 case CPU_25KF:
111 cpu_wait = r4k_wait;
112 printk(" available.\n");
113 break;
114 #ifdef CONFIG_PM
115 case CPU_AU1000:
116 case CPU_AU1100:
117 case CPU_AU1500:
118 if (au1k_wait_ptr != NULL) {
119 cpu_wait = au1k_wait_ptr;
120 printk(" available.\n");
122 else {
123 printk(" unavailable.\n");
125 break;
126 #endif
127 default:
128 printk(" unavailable.\n");
129 break;
133 void __init check_bugs32(void)
135 check_wait();
139 * Probe whether cpu has config register by trying to play with
140 * alternate cache bit and see whether it matters.
141 * It's used by cpu_probe to distinguish between R3000A and R3081.
143 static inline int cpu_has_confreg(void)
145 #ifdef CONFIG_CPU_R3000
146 extern unsigned long r3k_cache_size(unsigned long);
147 unsigned long size1, size2;
148 unsigned long cfg = read_c0_conf();
150 size1 = r3k_cache_size(ST0_ISC);
151 write_c0_conf(cfg ^ R30XX_CONF_AC);
152 size2 = r3k_cache_size(ST0_ISC);
153 write_c0_conf(cfg);
154 return size1 != size2;
155 #else
156 return 0;
157 #endif
161 * Get the FPU Implementation/Revision.
163 static inline unsigned long cpu_get_fpu_id(void)
165 unsigned long tmp, fpu_id;
167 tmp = read_c0_status();
168 __enable_fpu();
169 fpu_id = read_32bit_cp1_register(CP1_REVISION);
170 write_c0_status(tmp);
171 return fpu_id;
175 * Check the CPU has an FPU the official way.
177 static inline int __cpu_has_fpu(void)
179 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
182 #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4KTLB \
183 | MIPS_CPU_COUNTER)
185 static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
187 switch (c->processor_id & 0xff00) {
188 case PRID_IMP_R2000:
189 c->cputype = CPU_R2000;
190 c->isa_level = MIPS_CPU_ISA_I;
191 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
192 if (__cpu_has_fpu())
193 c->options |= MIPS_CPU_FPU;
194 c->tlbsize = 64;
195 break;
196 case PRID_IMP_R3000:
197 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
198 if (cpu_has_confreg())
199 c->cputype = CPU_R3081E;
200 else
201 c->cputype = CPU_R3000A;
202 else
203 c->cputype = CPU_R3000;
204 c->isa_level = MIPS_CPU_ISA_I;
205 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
206 if (__cpu_has_fpu())
207 c->options |= MIPS_CPU_FPU;
208 c->tlbsize = 64;
209 break;
210 case PRID_IMP_R4000:
211 if (read_c0_config() & CONF_SC) {
212 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
213 c->cputype = CPU_R4400PC;
214 else
215 c->cputype = CPU_R4000PC;
216 } else {
217 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
218 c->cputype = CPU_R4400SC;
219 else
220 c->cputype = CPU_R4000SC;
223 c->isa_level = MIPS_CPU_ISA_III;
224 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
225 MIPS_CPU_WATCH | MIPS_CPU_VCE |
226 MIPS_CPU_LLSC;
227 c->tlbsize = 48;
228 break;
229 case PRID_IMP_VR41XX:
230 switch (c->processor_id & 0xf0) {
231 #ifndef CONFIG_VR4181
232 case PRID_REV_VR4111:
233 c->cputype = CPU_VR4111;
234 break;
235 #else
236 case PRID_REV_VR4181:
237 c->cputype = CPU_VR4181;
238 break;
239 #endif
240 case PRID_REV_VR4121:
241 c->cputype = CPU_VR4121;
242 break;
243 case PRID_REV_VR4122:
244 if ((c->processor_id & 0xf) < 0x3)
245 c->cputype = CPU_VR4122;
246 else
247 c->cputype = CPU_VR4181A;
248 break;
249 case PRID_REV_VR4130:
250 if ((c->processor_id & 0xf) < 0x4)
251 c->cputype = CPU_VR4131;
252 else
253 c->cputype = CPU_VR4133;
254 break;
255 default:
256 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
257 c->cputype = CPU_VR41XX;
258 break;
260 c->isa_level = MIPS_CPU_ISA_III;
261 c->options = R4K_OPTS;
262 c->tlbsize = 32;
263 break;
264 case PRID_IMP_R4300:
265 c->cputype = CPU_R4300;
266 c->isa_level = MIPS_CPU_ISA_III;
267 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
268 MIPS_CPU_LLSC;
269 c->tlbsize = 32;
270 break;
271 case PRID_IMP_R4600:
272 c->cputype = CPU_R4600;
273 c->isa_level = MIPS_CPU_ISA_III;
274 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
275 c->tlbsize = 48;
276 break;
277 #if 0
278 case PRID_IMP_R4650:
280 * This processor doesn't have an MMU, so it's not
281 * "real easy" to run Linux on it. It is left purely
282 * for documentation. Commented out because it shares
283 * it's c0_prid id number with the TX3900.
285 c->cputype = CPU_R4650;
286 c->isa_level = MIPS_CPU_ISA_III;
287 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
288 c->tlbsize = 48;
289 break;
290 #endif
291 case PRID_IMP_TX39:
292 c->isa_level = MIPS_CPU_ISA_I;
293 c->options = MIPS_CPU_TLB;
295 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
296 c->cputype = CPU_TX3927;
297 c->tlbsize = 64;
298 } else {
299 switch (c->processor_id & 0xff) {
300 case PRID_REV_TX3912:
301 c->cputype = CPU_TX3912;
302 c->tlbsize = 32;
303 break;
304 case PRID_REV_TX3922:
305 c->cputype = CPU_TX3922;
306 c->tlbsize = 64;
307 break;
308 default:
309 c->cputype = CPU_UNKNOWN;
310 break;
313 break;
314 case PRID_IMP_R4700:
315 c->cputype = CPU_R4700;
316 c->isa_level = MIPS_CPU_ISA_III;
317 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
318 MIPS_CPU_LLSC;
319 c->tlbsize = 48;
320 break;
321 case PRID_IMP_TX49:
322 c->cputype = CPU_TX49XX;
323 c->isa_level = MIPS_CPU_ISA_III;
324 c->options = R4K_OPTS | MIPS_CPU_LLSC;
325 if (!(c->processor_id & 0x08))
326 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
327 c->tlbsize = 48;
328 break;
329 case PRID_IMP_R5000:
330 c->cputype = CPU_R5000;
331 c->isa_level = MIPS_CPU_ISA_IV;
332 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
333 MIPS_CPU_LLSC;
334 c->tlbsize = 48;
335 break;
336 case PRID_IMP_R5432:
337 c->cputype = CPU_R5432;
338 c->isa_level = MIPS_CPU_ISA_IV;
339 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
340 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
341 c->tlbsize = 48;
342 break;
343 case PRID_IMP_R5500:
344 c->cputype = CPU_R5500;
345 c->isa_level = MIPS_CPU_ISA_IV;
346 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
347 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
348 c->tlbsize = 48;
349 break;
350 case PRID_IMP_NEVADA:
351 c->cputype = CPU_NEVADA;
352 c->isa_level = MIPS_CPU_ISA_IV;
353 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
354 MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
355 c->tlbsize = 48;
356 break;
357 case PRID_IMP_R6000:
358 c->cputype = CPU_R6000;
359 c->isa_level = MIPS_CPU_ISA_II;
360 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
361 MIPS_CPU_LLSC;
362 c->tlbsize = 32;
363 break;
364 case PRID_IMP_R6000A:
365 c->cputype = CPU_R6000A;
366 c->isa_level = MIPS_CPU_ISA_II;
367 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
368 MIPS_CPU_LLSC;
369 c->tlbsize = 32;
370 break;
371 case PRID_IMP_RM7000:
372 c->cputype = CPU_RM7000;
373 c->isa_level = MIPS_CPU_ISA_IV;
374 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
375 MIPS_CPU_LLSC;
377 * Undocumented RM7000: Bit 29 in the info register of
378 * the RM7000 v2.0 indicates if the TLB has 48 or 64
379 * entries.
381 * 29 1 => 64 entry JTLB
382 * 0 => 48 entry JTLB
384 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
385 break;
386 case PRID_IMP_RM9000:
387 c->cputype = CPU_RM9000;
388 c->isa_level = MIPS_CPU_ISA_IV;
389 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
390 MIPS_CPU_LLSC;
392 * Bit 29 in the info register of the RM9000
393 * indicates if the TLB has 48 or 64 entries.
395 * 29 1 => 64 entry JTLB
396 * 0 => 48 entry JTLB
398 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
399 break;
400 case PRID_IMP_R8000:
401 c->cputype = CPU_R8000;
402 c->isa_level = MIPS_CPU_ISA_IV;
403 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
404 MIPS_CPU_FPU | MIPS_CPU_32FPR |
405 MIPS_CPU_LLSC;
406 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
407 break;
408 case PRID_IMP_R10000:
409 c->cputype = CPU_R10000;
410 c->isa_level = MIPS_CPU_ISA_IV;
411 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
412 MIPS_CPU_FPU | MIPS_CPU_32FPR |
413 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
414 MIPS_CPU_LLSC;
415 c->tlbsize = 64;
416 break;
417 case PRID_IMP_R12000:
418 c->cputype = CPU_R12000;
419 c->isa_level = MIPS_CPU_ISA_IV;
420 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
421 MIPS_CPU_FPU | MIPS_CPU_32FPR |
422 MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
423 MIPS_CPU_LLSC;
424 c->tlbsize = 64;
425 break;
429 static inline void decode_config1(struct cpuinfo_mips *c)
431 unsigned long config0 = read_c0_config();
432 unsigned long config1;
434 if ((config0 & (1 << 31)) == 0)
435 return; /* actually wort a panic() */
437 /* MIPS32 or MIPS64 compliant CPU. Read Config 1 register. */
438 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
439 MIPS_CPU_4KTLB | MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
440 MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
441 config1 = read_c0_config1();
442 if (config1 & (1 << 3))
443 c->options |= MIPS_CPU_WATCH;
444 if (config1 & (1 << 2))
445 c->options |= MIPS_CPU_MIPS16;
446 if (config1 & (1 << 1))
447 c->options |= MIPS_CPU_EJTAG;
448 if (config1 & 1) {
449 c->options |= MIPS_CPU_FPU;
450 c->options |= MIPS_CPU_32FPR;
452 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
454 c->tlbsize = ((config1 >> 25) & 0x3f) + 1;
457 static inline void cpu_probe_mips(struct cpuinfo_mips *c)
459 decode_config1(c);
460 switch (c->processor_id & 0xff00) {
461 case PRID_IMP_4KC:
462 c->cputype = CPU_4KC;
463 c->isa_level = MIPS_CPU_ISA_M32;
464 break;
465 case PRID_IMP_4KEC:
466 c->cputype = CPU_4KEC;
467 c->isa_level = MIPS_CPU_ISA_M32;
468 break;
469 case PRID_IMP_4KSC:
470 c->cputype = CPU_4KSC;
471 c->isa_level = MIPS_CPU_ISA_M32;
472 break;
473 case PRID_IMP_5KC:
474 c->cputype = CPU_5KC;
475 c->isa_level = MIPS_CPU_ISA_M64;
476 break;
477 case PRID_IMP_20KC:
478 c->cputype = CPU_20KC;
479 c->isa_level = MIPS_CPU_ISA_M64;
480 break;
481 case PRID_IMP_24K:
482 c->cputype = CPU_24K;
483 c->isa_level = MIPS_CPU_ISA_M32;
484 break;
485 case PRID_IMP_25KF:
486 c->cputype = CPU_25KF;
487 c->isa_level = MIPS_CPU_ISA_M64;
488 /* Probe for L2 cache */
489 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
490 break;
494 static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
496 decode_config1(c);
497 switch (c->processor_id & 0xff00) {
498 case PRID_IMP_AU1_REV1:
499 case PRID_IMP_AU1_REV2:
500 switch ((c->processor_id >> 24) & 0xff) {
501 case 0:
502 c->cputype = CPU_AU1000;
503 break;
504 case 1:
505 c->cputype = CPU_AU1500;
506 break;
507 case 2:
508 c->cputype = CPU_AU1100;
509 break;
510 case 3:
511 c->cputype = CPU_AU1550;
512 break;
513 default:
514 panic("Unknown Au Core!");
515 break;
517 c->isa_level = MIPS_CPU_ISA_M32;
518 break;
522 static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
524 decode_config1(c);
525 switch (c->processor_id & 0xff00) {
526 case PRID_IMP_SB1:
527 c->cputype = CPU_SB1;
528 c->isa_level = MIPS_CPU_ISA_M64;
529 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
530 MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
531 MIPS_CPU_MCHECK | MIPS_CPU_EJTAG |
532 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
533 #ifndef CONFIG_SB1_PASS_1_WORKAROUNDS
534 /* FPU in pass1 is known to have issues. */
535 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
536 #endif
537 break;
541 static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
543 decode_config1(c);
544 switch (c->processor_id & 0xff00) {
545 case PRID_IMP_SR71000:
546 c->cputype = CPU_SR71000;
547 c->isa_level = MIPS_CPU_ISA_M64;
548 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
549 MIPS_CPU_4KTLB | MIPS_CPU_FPU |
550 MIPS_CPU_COUNTER | MIPS_CPU_MCHECK;
551 c->scache.ways = 8;
552 c->tlbsize = 64;
553 break;
557 __init void cpu_probe(void)
559 struct cpuinfo_mips *c = &current_cpu_data;
561 c->processor_id = PRID_IMP_UNKNOWN;
562 c->fpu_id = FPIR_IMP_NONE;
563 c->cputype = CPU_UNKNOWN;
565 c->processor_id = read_c0_prid();
566 switch (c->processor_id & 0xff0000) {
567 case PRID_COMP_LEGACY:
568 cpu_probe_legacy(c);
569 break;
570 case PRID_COMP_MIPS:
571 cpu_probe_mips(c);
572 break;
573 case PRID_COMP_ALCHEMY:
574 cpu_probe_alchemy(c);
575 break;
576 case PRID_COMP_SIBYTE:
577 cpu_probe_sibyte(c);
578 break;
580 case PRID_COMP_SANDCRAFT:
581 cpu_probe_sandcraft(c);
582 break;
583 default:
584 c->cputype = CPU_UNKNOWN;
586 if (c->options & MIPS_CPU_FPU)
587 c->fpu_id = cpu_get_fpu_id();
590 __init void cpu_report(void)
592 struct cpuinfo_mips *c = &current_cpu_data;
594 printk("CPU revision is: %08x\n", c->processor_id);
595 if (c->options & MIPS_CPU_FPU)
596 printk("FPU revision is: %08x\n", c->fpu_id);