blob: 21ef82de8c5ba6b68dc007373c7cfeecd3c39d4d [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * Processor capabilities determination functions.
3 *
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.
8 *
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.
13 */
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>
19
Linus Torvalds1da177e2005-04-16 15:20:36 -070020#include <asm/cpu.h>
21#include <asm/fpu.h>
22#include <asm/mipsregs.h>
23#include <asm/system.h>
24
25/*
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
30 * the CPU very much.
31 */
32void (*cpu_wait)(void) = NULL;
33
34static void r3081_wait(void)
35{
36 unsigned long cfg = read_c0_conf();
37 write_c0_conf(cfg | R30XX_CONF_HALT);
38}
39
40static void r39xx_wait(void)
41{
42 unsigned long cfg = read_c0_conf();
43 write_c0_conf(cfg | TX39_CONF_HALT);
44}
45
46static void r4k_wait(void)
47{
48 __asm__(".set\tmips3\n\t"
49 "wait\n\t"
50 ".set\tmips0");
51}
52
Pete Popov494900a2005-04-07 00:42:10 +000053/* The Au1xxx wait is available only if using 32khz counter or
54 * external timer source, but specifically not CP0 Counter. */
Pete Popovfe359bf2005-04-08 08:34:43 +000055int allow_au1k_wait;
Pete Popov494900a2005-04-07 00:42:10 +000056static void au1k_wait(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070057{
Pete Popovfe359bf2005-04-08 08:34:43 +000058 unsigned long addr = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 /* using the wait instruction makes CP0 counter unusable */
Pete Popov494900a2005-04-07 00:42:10 +000060 __asm__("la %0,au1k_wait\n\t"
61 ".set mips3\n\t"
62 "cache 0x14,0(%0)\n\t"
63 "cache 0x14,32(%0)\n\t"
64 "sync\n\t"
65 "nop\n\t"
Linus Torvalds1da177e2005-04-16 15:20:36 -070066 "wait\n\t"
67 "nop\n\t"
68 "nop\n\t"
69 "nop\n\t"
70 "nop\n\t"
Pete Popov494900a2005-04-07 00:42:10 +000071 ".set mips0\n\t"
72 : : "r" (addr));
Linus Torvalds1da177e2005-04-16 15:20:36 -070073}
74
75static inline void check_wait(void)
76{
77 struct cpuinfo_mips *c = &current_cpu_data;
78
79 printk("Checking for 'wait' instruction... ");
80 switch (c->cputype) {
81 case CPU_R3081:
82 case CPU_R3081E:
83 cpu_wait = r3081_wait;
84 printk(" available.\n");
85 break;
86 case CPU_TX3927:
87 cpu_wait = r39xx_wait;
88 printk(" available.\n");
89 break;
90 case CPU_R4200:
91/* case CPU_R4300: */
92 case CPU_R4600:
93 case CPU_R4640:
94 case CPU_R4650:
95 case CPU_R4700:
96 case CPU_R5000:
97 case CPU_NEVADA:
98 case CPU_RM7000:
99 case CPU_RM9000:
100 case CPU_TX49XX:
101 case CPU_4KC:
102 case CPU_4KEC:
103 case CPU_4KSC:
104 case CPU_5KC:
105/* case CPU_20KC:*/
106 case CPU_24K:
107 case CPU_25KF:
108 cpu_wait = r4k_wait;
109 printk(" available.\n");
110 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700111 case CPU_AU1000:
112 case CPU_AU1100:
113 case CPU_AU1500:
Pete Popove3ad1c22005-03-01 06:33:16 +0000114 case CPU_AU1550:
115 case CPU_AU1200:
Pete Popovfe359bf2005-04-08 08:34:43 +0000116 if (allow_au1k_wait) {
117 cpu_wait = au1k_wait;
118 printk(" available.\n");
119 } else
120 printk(" unavailable.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700121 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122 default:
123 printk(" unavailable.\n");
124 break;
125 }
126}
127
128void __init check_bugs32(void)
129{
130 check_wait();
131}
132
133/*
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.
137 */
138static inline int cpu_has_confreg(void)
139{
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();
144
145 size1 = r3k_cache_size(ST0_ISC);
146 write_c0_conf(cfg ^ R30XX_CONF_AC);
147 size2 = r3k_cache_size(ST0_ISC);
148 write_c0_conf(cfg);
149 return size1 != size2;
150#else
151 return 0;
152#endif
153}
154
155/*
156 * Get the FPU Implementation/Revision.
157 */
158static inline unsigned long cpu_get_fpu_id(void)
159{
160 unsigned long tmp, fpu_id;
161
162 tmp = read_c0_status();
163 __enable_fpu();
164 fpu_id = read_32bit_cp1_register(CP1_REVISION);
165 write_c0_status(tmp);
166 return fpu_id;
167}
168
169/*
170 * Check the CPU has an FPU the official way.
171 */
172static inline int __cpu_has_fpu(void)
173{
174 return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
175}
176
177#define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4KTLB \
178 | MIPS_CPU_COUNTER)
179
180static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
181{
182 switch (c->processor_id & 0xff00) {
183 case PRID_IMP_R2000:
184 c->cputype = CPU_R2000;
185 c->isa_level = MIPS_CPU_ISA_I;
186 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
187 if (__cpu_has_fpu())
188 c->options |= MIPS_CPU_FPU;
189 c->tlbsize = 64;
190 break;
191 case PRID_IMP_R3000:
192 if ((c->processor_id & 0xff) == PRID_REV_R3000A)
193 if (cpu_has_confreg())
194 c->cputype = CPU_R3081E;
195 else
196 c->cputype = CPU_R3000A;
197 else
198 c->cputype = CPU_R3000;
199 c->isa_level = MIPS_CPU_ISA_I;
200 c->options = MIPS_CPU_TLB | MIPS_CPU_NOFPUEX;
201 if (__cpu_has_fpu())
202 c->options |= MIPS_CPU_FPU;
203 c->tlbsize = 64;
204 break;
205 case PRID_IMP_R4000:
206 if (read_c0_config() & CONF_SC) {
207 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
208 c->cputype = CPU_R4400PC;
209 else
210 c->cputype = CPU_R4000PC;
211 } else {
212 if ((c->processor_id & 0xff) >= PRID_REV_R4400)
213 c->cputype = CPU_R4400SC;
214 else
215 c->cputype = CPU_R4000SC;
216 }
217
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 |
221 MIPS_CPU_LLSC;
222 c->tlbsize = 48;
223 break;
224 case PRID_IMP_VR41XX:
225 switch (c->processor_id & 0xf0) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226 case PRID_REV_VR4111:
227 c->cputype = CPU_VR4111;
228 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700229 case PRID_REV_VR4121:
230 c->cputype = CPU_VR4121;
231 break;
232 case PRID_REV_VR4122:
233 if ((c->processor_id & 0xf) < 0x3)
234 c->cputype = CPU_VR4122;
235 else
236 c->cputype = CPU_VR4181A;
237 break;
238 case PRID_REV_VR4130:
239 if ((c->processor_id & 0xf) < 0x4)
240 c->cputype = CPU_VR4131;
241 else
242 c->cputype = CPU_VR4133;
243 break;
244 default:
245 printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
246 c->cputype = CPU_VR41XX;
247 break;
248 }
249 c->isa_level = MIPS_CPU_ISA_III;
250 c->options = R4K_OPTS;
251 c->tlbsize = 32;
252 break;
253 case PRID_IMP_R4300:
254 c->cputype = CPU_R4300;
255 c->isa_level = MIPS_CPU_ISA_III;
256 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
257 MIPS_CPU_LLSC;
258 c->tlbsize = 32;
259 break;
260 case PRID_IMP_R4600:
261 c->cputype = CPU_R4600;
262 c->isa_level = MIPS_CPU_ISA_III;
263 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
264 c->tlbsize = 48;
265 break;
266 #if 0
267 case PRID_IMP_R4650:
268 /*
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.
273 */
274 c->cputype = CPU_R4650;
275 c->isa_level = MIPS_CPU_ISA_III;
276 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
277 c->tlbsize = 48;
278 break;
279 #endif
280 case PRID_IMP_TX39:
281 c->isa_level = MIPS_CPU_ISA_I;
282 c->options = MIPS_CPU_TLB;
283
284 if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
285 c->cputype = CPU_TX3927;
286 c->tlbsize = 64;
287 } else {
288 switch (c->processor_id & 0xff) {
289 case PRID_REV_TX3912:
290 c->cputype = CPU_TX3912;
291 c->tlbsize = 32;
292 break;
293 case PRID_REV_TX3922:
294 c->cputype = CPU_TX3922;
295 c->tlbsize = 64;
296 break;
297 default:
298 c->cputype = CPU_UNKNOWN;
299 break;
300 }
301 }
302 break;
303 case PRID_IMP_R4700:
304 c->cputype = CPU_R4700;
305 c->isa_level = MIPS_CPU_ISA_III;
306 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
307 MIPS_CPU_LLSC;
308 c->tlbsize = 48;
309 break;
310 case PRID_IMP_TX49:
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;
316 c->tlbsize = 48;
317 break;
318 case PRID_IMP_R5000:
319 c->cputype = CPU_R5000;
320 c->isa_level = MIPS_CPU_ISA_IV;
321 c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
322 MIPS_CPU_LLSC;
323 c->tlbsize = 48;
324 break;
325 case PRID_IMP_R5432:
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;
330 c->tlbsize = 48;
331 break;
332 case PRID_IMP_R5500:
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;
337 c->tlbsize = 48;
338 break;
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;
344 c->tlbsize = 48;
345 break;
346 case PRID_IMP_R6000:
347 c->cputype = CPU_R6000;
348 c->isa_level = MIPS_CPU_ISA_II;
349 c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
350 MIPS_CPU_LLSC;
351 c->tlbsize = 32;
352 break;
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 |
357 MIPS_CPU_LLSC;
358 c->tlbsize = 32;
359 break;
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 |
364 MIPS_CPU_LLSC;
365 /*
366 * Undocumented RM7000: Bit 29 in the info register of
367 * the RM7000 v2.0 indicates if the TLB has 48 or 64
368 * entries.
369 *
370 * 29 1 => 64 entry JTLB
371 * 0 => 48 entry JTLB
372 */
373 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
374 break;
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 |
379 MIPS_CPU_LLSC;
380 /*
381 * Bit 29 in the info register of the RM9000
382 * indicates if the TLB has 48 or 64 entries.
383 *
384 * 29 1 => 64 entry JTLB
385 * 0 => 48 entry JTLB
386 */
387 c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
388 break;
389 case PRID_IMP_R8000:
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 |
394 MIPS_CPU_LLSC;
395 c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
396 break;
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 |
403 MIPS_CPU_LLSC;
404 c->tlbsize = 64;
405 break;
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 |
412 MIPS_CPU_LLSC;
413 c->tlbsize = 64;
414 break;
415 }
416}
417
418static inline void decode_config1(struct cpuinfo_mips *c)
419{
420 unsigned long config0 = read_c0_config();
421 unsigned long config1;
422
423 if ((config0 & (1 << 31)) == 0)
424 return; /* actually wort a panic() */
425
426 /* MIPS32 or MIPS64 compliant CPU. Read Config 1 register. */
427 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
428 MIPS_CPU_4KTLB | MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
429 MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
430 config1 = read_c0_config1();
431 if (config1 & (1 << 3))
432 c->options |= MIPS_CPU_WATCH;
433 if (config1 & (1 << 2))
434 c->options |= MIPS_CPU_MIPS16;
435 if (config1 & (1 << 1))
436 c->options |= MIPS_CPU_EJTAG;
437 if (config1 & 1) {
438 c->options |= MIPS_CPU_FPU;
439 c->options |= MIPS_CPU_32FPR;
440 }
441 c->scache.flags = MIPS_CACHE_NOT_PRESENT;
442
443 c->tlbsize = ((config1 >> 25) & 0x3f) + 1;
444}
445
446static inline void cpu_probe_mips(struct cpuinfo_mips *c)
447{
448 decode_config1(c);
449 switch (c->processor_id & 0xff00) {
450 case PRID_IMP_4KC:
451 c->cputype = CPU_4KC;
452 c->isa_level = MIPS_CPU_ISA_M32;
453 break;
454 case PRID_IMP_4KEC:
455 c->cputype = CPU_4KEC;
456 c->isa_level = MIPS_CPU_ISA_M32;
457 break;
Ralf Baechle2b07bd02005-04-08 20:36:05 +0000458 case PRID_IMP_4KECR2:
459 c->cputype = CPU_4KEC;
460 c->isa_level = MIPS_CPU_ISA_M32;
461 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 case PRID_IMP_4KSC:
463 c->cputype = CPU_4KSC;
464 c->isa_level = MIPS_CPU_ISA_M32;
465 break;
466 case PRID_IMP_5KC:
467 c->cputype = CPU_5KC;
468 c->isa_level = MIPS_CPU_ISA_M64;
469 break;
470 case PRID_IMP_20KC:
471 c->cputype = CPU_20KC;
472 c->isa_level = MIPS_CPU_ISA_M64;
473 break;
474 case PRID_IMP_24K:
475 c->cputype = CPU_24K;
476 c->isa_level = MIPS_CPU_ISA_M32;
477 break;
478 case PRID_IMP_25KF:
479 c->cputype = CPU_25KF;
480 c->isa_level = MIPS_CPU_ISA_M64;
481 /* Probe for L2 cache */
482 c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
483 break;
484 }
485}
486
487static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
488{
489 decode_config1(c);
490 switch (c->processor_id & 0xff00) {
491 case PRID_IMP_AU1_REV1:
492 case PRID_IMP_AU1_REV2:
493 switch ((c->processor_id >> 24) & 0xff) {
494 case 0:
495 c->cputype = CPU_AU1000;
496 break;
497 case 1:
498 c->cputype = CPU_AU1500;
499 break;
500 case 2:
501 c->cputype = CPU_AU1100;
502 break;
503 case 3:
504 c->cputype = CPU_AU1550;
505 break;
Pete Popove3ad1c22005-03-01 06:33:16 +0000506 case 4:
507 c->cputype = CPU_AU1200;
508 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509 default:
510 panic("Unknown Au Core!");
511 break;
512 }
513 c->isa_level = MIPS_CPU_ISA_M32;
514 break;
515 }
516}
517
518static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
519{
520 decode_config1(c);
521 switch (c->processor_id & 0xff00) {
522 case PRID_IMP_SB1:
523 c->cputype = CPU_SB1;
524 c->isa_level = MIPS_CPU_ISA_M64;
525 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
526 MIPS_CPU_COUNTER | MIPS_CPU_DIVEC |
527 MIPS_CPU_MCHECK | MIPS_CPU_EJTAG |
528 MIPS_CPU_WATCH | MIPS_CPU_LLSC;
529#ifndef CONFIG_SB1_PASS_1_WORKAROUNDS
530 /* FPU in pass1 is known to have issues. */
531 c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
532#endif
533 break;
534 }
535}
536
537static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
538{
539 decode_config1(c);
540 switch (c->processor_id & 0xff00) {
541 case PRID_IMP_SR71000:
542 c->cputype = CPU_SR71000;
543 c->isa_level = MIPS_CPU_ISA_M64;
544 c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
545 MIPS_CPU_4KTLB | MIPS_CPU_FPU |
546 MIPS_CPU_COUNTER | MIPS_CPU_MCHECK;
547 c->scache.ways = 8;
548 c->tlbsize = 64;
549 break;
550 }
551}
552
553__init void cpu_probe(void)
554{
555 struct cpuinfo_mips *c = &current_cpu_data;
556
557 c->processor_id = PRID_IMP_UNKNOWN;
558 c->fpu_id = FPIR_IMP_NONE;
559 c->cputype = CPU_UNKNOWN;
560
561 c->processor_id = read_c0_prid();
562 switch (c->processor_id & 0xff0000) {
563 case PRID_COMP_LEGACY:
564 cpu_probe_legacy(c);
565 break;
566 case PRID_COMP_MIPS:
567 cpu_probe_mips(c);
568 break;
569 case PRID_COMP_ALCHEMY:
570 cpu_probe_alchemy(c);
571 break;
572 case PRID_COMP_SIBYTE:
573 cpu_probe_sibyte(c);
574 break;
575
576 case PRID_COMP_SANDCRAFT:
577 cpu_probe_sandcraft(c);
578 break;
579 default:
580 c->cputype = CPU_UNKNOWN;
581 }
582 if (c->options & MIPS_CPU_FPU)
583 c->fpu_id = cpu_get_fpu_id();
584}
585
586__init void cpu_report(void)
587{
588 struct cpuinfo_mips *c = &current_cpu_data;
589
590 printk("CPU revision is: %08x\n", c->processor_id);
591 if (c->options & MIPS_CPU_FPU)
592 printk("FPU revision is: %08x\n", c->fpu_id);
593}