cpu-probe.c 25 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066
  1. /*
  2. * Processor capabilities determination functions.
  3. *
  4. * Copyright (C) xxxx the Anonymous
  5. * Copyright (C) 1994 - 2006 Ralf Baechle
  6. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  7. * Copyright (C) 2001, 2004 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/init.h>
  15. #include <linux/kernel.h>
  16. #include <linux/ptrace.h>
  17. #include <linux/smp.h>
  18. #include <linux/stddef.h>
  19. #include <linux/module.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>
  25. #include <asm/watch.h>
  26. #include <asm/spram.h>
  27. /*
  28. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  29. * the implementation of the "wait" feature differs between CPU families. This
  30. * points to the function that implements CPU specific wait.
  31. * The wait instruction stops the pipeline and reduces the power consumption of
  32. * the CPU very much.
  33. */
  34. void (*cpu_wait)(void);
  35. EXPORT_SYMBOL(cpu_wait);
  36. static void r3081_wait(void)
  37. {
  38. unsigned long cfg = read_c0_conf();
  39. write_c0_conf(cfg | R30XX_CONF_HALT);
  40. }
  41. static void r39xx_wait(void)
  42. {
  43. local_irq_disable();
  44. if (!need_resched())
  45. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  46. local_irq_enable();
  47. }
  48. extern void r4k_wait(void);
  49. /*
  50. * This variant is preferable as it allows testing need_resched and going to
  51. * sleep depending on the outcome atomically. Unfortunately the "It is
  52. * implementation-dependent whether the pipeline restarts when a non-enabled
  53. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  54. * using this version a gamble.
  55. */
  56. void r4k_wait_irqoff(void)
  57. {
  58. local_irq_disable();
  59. if (!need_resched())
  60. __asm__(" .set push \n"
  61. " .set mips3 \n"
  62. " wait \n"
  63. " .set pop \n");
  64. local_irq_enable();
  65. __asm__(" .globl __pastwait \n"
  66. "__pastwait: \n");
  67. return;
  68. }
  69. /*
  70. * The RM7000 variant has to handle erratum 38. The workaround is to not
  71. * have any pending stores when the WAIT instruction is executed.
  72. */
  73. static void rm7k_wait_irqoff(void)
  74. {
  75. local_irq_disable();
  76. if (!need_resched())
  77. __asm__(
  78. " .set push \n"
  79. " .set mips3 \n"
  80. " .set noat \n"
  81. " mfc0 $1, $12 \n"
  82. " sync \n"
  83. " mtc0 $1, $12 # stalls until W stage \n"
  84. " wait \n"
  85. " mtc0 $1, $12 # stalls until W stage \n"
  86. " .set pop \n");
  87. local_irq_enable();
  88. }
  89. /*
  90. * The Au1xxx wait is available only if using 32khz counter or
  91. * external timer source, but specifically not CP0 Counter.
  92. * alchemy/common/time.c may override cpu_wait!
  93. */
  94. static void au1k_wait(void)
  95. {
  96. __asm__(" .set mips3 \n"
  97. " cache 0x14, 0(%0) \n"
  98. " cache 0x14, 32(%0) \n"
  99. " sync \n"
  100. " nop \n"
  101. " wait \n"
  102. " nop \n"
  103. " nop \n"
  104. " nop \n"
  105. " nop \n"
  106. " .set mips0 \n"
  107. : : "r" (au1k_wait));
  108. }
  109. static int __initdata nowait;
  110. static int __init wait_disable(char *s)
  111. {
  112. nowait = 1;
  113. return 1;
  114. }
  115. __setup("nowait", wait_disable);
  116. static int __cpuinitdata mips_fpu_disabled;
  117. static int __init fpu_disable(char *s)
  118. {
  119. cpu_data[0].options &= ~MIPS_CPU_FPU;
  120. mips_fpu_disabled = 1;
  121. return 1;
  122. }
  123. __setup("nofpu", fpu_disable);
  124. int __cpuinitdata mips_dsp_disabled;
  125. static int __init dsp_disable(char *s)
  126. {
  127. cpu_data[0].ases &= ~MIPS_ASE_DSP;
  128. mips_dsp_disabled = 1;
  129. return 1;
  130. }
  131. __setup("nodsp", dsp_disable);
  132. void __init check_wait(void)
  133. {
  134. struct cpuinfo_mips *c = &current_cpu_data;
  135. if (nowait) {
  136. printk("Wait instruction disabled.\n");
  137. return;
  138. }
  139. switch (c->cputype) {
  140. case CPU_R3081:
  141. case CPU_R3081E:
  142. cpu_wait = r3081_wait;
  143. break;
  144. case CPU_TX3927:
  145. cpu_wait = r39xx_wait;
  146. break;
  147. case CPU_R4200:
  148. /* case CPU_R4300: */
  149. case CPU_R4600:
  150. case CPU_R4640:
  151. case CPU_R4650:
  152. case CPU_R4700:
  153. case CPU_R5000:
  154. case CPU_R5500:
  155. case CPU_NEVADA:
  156. case CPU_4KC:
  157. case CPU_4KEC:
  158. case CPU_4KSC:
  159. case CPU_5KC:
  160. case CPU_25KF:
  161. case CPU_PR4450:
  162. case CPU_BCM3302:
  163. case CPU_BCM6338:
  164. case CPU_BCM6348:
  165. case CPU_BCM6358:
  166. case CPU_CAVIUM_OCTEON:
  167. case CPU_CAVIUM_OCTEON_PLUS:
  168. case CPU_JZRISC:
  169. cpu_wait = r4k_wait;
  170. break;
  171. case CPU_RM7000:
  172. cpu_wait = rm7k_wait_irqoff;
  173. break;
  174. case CPU_24K:
  175. case CPU_34K:
  176. case CPU_1004K:
  177. cpu_wait = r4k_wait;
  178. if (read_c0_config7() & MIPS_CONF7_WII)
  179. cpu_wait = r4k_wait_irqoff;
  180. break;
  181. case CPU_74K:
  182. cpu_wait = r4k_wait;
  183. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  184. cpu_wait = r4k_wait_irqoff;
  185. break;
  186. case CPU_TX49XX:
  187. cpu_wait = r4k_wait_irqoff;
  188. break;
  189. case CPU_ALCHEMY:
  190. cpu_wait = au1k_wait;
  191. break;
  192. case CPU_20KC:
  193. /*
  194. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  195. * WAIT on Rev2.0 and Rev3.0 has E16.
  196. * Rev3.1 WAIT is nop, why bother
  197. */
  198. if ((c->processor_id & 0xff) <= 0x64)
  199. break;
  200. /*
  201. * Another rev is incremeting c0_count at a reduced clock
  202. * rate while in WAIT mode. So we basically have the choice
  203. * between using the cp0 timer as clocksource or avoiding
  204. * the WAIT instruction. Until more details are known,
  205. * disable the use of WAIT for 20Kc entirely.
  206. cpu_wait = r4k_wait;
  207. */
  208. break;
  209. case CPU_RM9000:
  210. if ((c->processor_id & 0x00ff) >= 0x40)
  211. cpu_wait = r4k_wait;
  212. break;
  213. default:
  214. break;
  215. }
  216. }
  217. static inline void check_errata(void)
  218. {
  219. struct cpuinfo_mips *c = &current_cpu_data;
  220. switch (c->cputype) {
  221. case CPU_34K:
  222. /*
  223. * Erratum "RPS May Cause Incorrect Instruction Execution"
  224. * This code only handles VPE0, any SMP/SMTC/RTOS code
  225. * making use of VPE1 will be responsable for that VPE.
  226. */
  227. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  228. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. void __init check_bugs32(void)
  235. {
  236. check_errata();
  237. }
  238. /*
  239. * Probe whether cpu has config register by trying to play with
  240. * alternate cache bit and see whether it matters.
  241. * It's used by cpu_probe to distinguish between R3000A and R3081.
  242. */
  243. static inline int cpu_has_confreg(void)
  244. {
  245. #ifdef CONFIG_CPU_R3000
  246. extern unsigned long r3k_cache_size(unsigned long);
  247. unsigned long size1, size2;
  248. unsigned long cfg = read_c0_conf();
  249. size1 = r3k_cache_size(ST0_ISC);
  250. write_c0_conf(cfg ^ R30XX_CONF_AC);
  251. size2 = r3k_cache_size(ST0_ISC);
  252. write_c0_conf(cfg);
  253. return size1 != size2;
  254. #else
  255. return 0;
  256. #endif
  257. }
  258. /*
  259. * Get the FPU Implementation/Revision.
  260. */
  261. static inline unsigned long cpu_get_fpu_id(void)
  262. {
  263. unsigned long tmp, fpu_id;
  264. tmp = read_c0_status();
  265. __enable_fpu();
  266. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  267. write_c0_status(tmp);
  268. return fpu_id;
  269. }
  270. /*
  271. * Check the CPU has an FPU the official way.
  272. */
  273. static inline int __cpu_has_fpu(void)
  274. {
  275. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  276. }
  277. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  278. {
  279. #ifdef __NEED_VMBITS_PROBE
  280. write_c0_entryhi(0x3fffffffffffe000ULL);
  281. back_to_back_c0_hazard();
  282. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  283. #endif
  284. }
  285. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  286. | MIPS_CPU_COUNTER)
  287. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  288. {
  289. switch (c->processor_id & 0xff00) {
  290. case PRID_IMP_R2000:
  291. c->cputype = CPU_R2000;
  292. __cpu_name[cpu] = "R2000";
  293. c->isa_level = MIPS_CPU_ISA_I;
  294. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  295. MIPS_CPU_NOFPUEX;
  296. if (__cpu_has_fpu())
  297. c->options |= MIPS_CPU_FPU;
  298. c->tlbsize = 64;
  299. break;
  300. case PRID_IMP_R3000:
  301. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  302. if (cpu_has_confreg()) {
  303. c->cputype = CPU_R3081E;
  304. __cpu_name[cpu] = "R3081";
  305. } else {
  306. c->cputype = CPU_R3000A;
  307. __cpu_name[cpu] = "R3000A";
  308. }
  309. break;
  310. } else {
  311. c->cputype = CPU_R3000;
  312. __cpu_name[cpu] = "R3000";
  313. }
  314. c->isa_level = MIPS_CPU_ISA_I;
  315. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  316. MIPS_CPU_NOFPUEX;
  317. if (__cpu_has_fpu())
  318. c->options |= MIPS_CPU_FPU;
  319. c->tlbsize = 64;
  320. break;
  321. case PRID_IMP_R4000:
  322. if (read_c0_config() & CONF_SC) {
  323. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  324. c->cputype = CPU_R4400PC;
  325. __cpu_name[cpu] = "R4400PC";
  326. } else {
  327. c->cputype = CPU_R4000PC;
  328. __cpu_name[cpu] = "R4000PC";
  329. }
  330. } else {
  331. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  332. c->cputype = CPU_R4400SC;
  333. __cpu_name[cpu] = "R4400SC";
  334. } else {
  335. c->cputype = CPU_R4000SC;
  336. __cpu_name[cpu] = "R4000SC";
  337. }
  338. }
  339. c->isa_level = MIPS_CPU_ISA_III;
  340. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  341. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  342. MIPS_CPU_LLSC;
  343. c->tlbsize = 48;
  344. break;
  345. case PRID_IMP_VR41XX:
  346. switch (c->processor_id & 0xf0) {
  347. case PRID_REV_VR4111:
  348. c->cputype = CPU_VR4111;
  349. __cpu_name[cpu] = "NEC VR4111";
  350. break;
  351. case PRID_REV_VR4121:
  352. c->cputype = CPU_VR4121;
  353. __cpu_name[cpu] = "NEC VR4121";
  354. break;
  355. case PRID_REV_VR4122:
  356. if ((c->processor_id & 0xf) < 0x3) {
  357. c->cputype = CPU_VR4122;
  358. __cpu_name[cpu] = "NEC VR4122";
  359. } else {
  360. c->cputype = CPU_VR4181A;
  361. __cpu_name[cpu] = "NEC VR4181A";
  362. }
  363. break;
  364. case PRID_REV_VR4130:
  365. if ((c->processor_id & 0xf) < 0x4) {
  366. c->cputype = CPU_VR4131;
  367. __cpu_name[cpu] = "NEC VR4131";
  368. } else {
  369. c->cputype = CPU_VR4133;
  370. __cpu_name[cpu] = "NEC VR4133";
  371. }
  372. break;
  373. default:
  374. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  375. c->cputype = CPU_VR41XX;
  376. __cpu_name[cpu] = "NEC Vr41xx";
  377. break;
  378. }
  379. c->isa_level = MIPS_CPU_ISA_III;
  380. c->options = R4K_OPTS;
  381. c->tlbsize = 32;
  382. break;
  383. case PRID_IMP_R4300:
  384. c->cputype = CPU_R4300;
  385. __cpu_name[cpu] = "R4300";
  386. c->isa_level = MIPS_CPU_ISA_III;
  387. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  388. MIPS_CPU_LLSC;
  389. c->tlbsize = 32;
  390. break;
  391. case PRID_IMP_R4600:
  392. c->cputype = CPU_R4600;
  393. __cpu_name[cpu] = "R4600";
  394. c->isa_level = MIPS_CPU_ISA_III;
  395. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  396. MIPS_CPU_LLSC;
  397. c->tlbsize = 48;
  398. break;
  399. #if 0
  400. case PRID_IMP_R4650:
  401. /*
  402. * This processor doesn't have an MMU, so it's not
  403. * "real easy" to run Linux on it. It is left purely
  404. * for documentation. Commented out because it shares
  405. * it's c0_prid id number with the TX3900.
  406. */
  407. c->cputype = CPU_R4650;
  408. __cpu_name[cpu] = "R4650";
  409. c->isa_level = MIPS_CPU_ISA_III;
  410. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  411. c->tlbsize = 48;
  412. break;
  413. #endif
  414. case PRID_IMP_TX39:
  415. c->isa_level = MIPS_CPU_ISA_I;
  416. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  417. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  418. c->cputype = CPU_TX3927;
  419. __cpu_name[cpu] = "TX3927";
  420. c->tlbsize = 64;
  421. } else {
  422. switch (c->processor_id & 0xff) {
  423. case PRID_REV_TX3912:
  424. c->cputype = CPU_TX3912;
  425. __cpu_name[cpu] = "TX3912";
  426. c->tlbsize = 32;
  427. break;
  428. case PRID_REV_TX3922:
  429. c->cputype = CPU_TX3922;
  430. __cpu_name[cpu] = "TX3922";
  431. c->tlbsize = 64;
  432. break;
  433. }
  434. }
  435. break;
  436. case PRID_IMP_R4700:
  437. c->cputype = CPU_R4700;
  438. __cpu_name[cpu] = "R4700";
  439. c->isa_level = MIPS_CPU_ISA_III;
  440. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  441. MIPS_CPU_LLSC;
  442. c->tlbsize = 48;
  443. break;
  444. case PRID_IMP_TX49:
  445. c->cputype = CPU_TX49XX;
  446. __cpu_name[cpu] = "R49XX";
  447. c->isa_level = MIPS_CPU_ISA_III;
  448. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  449. if (!(c->processor_id & 0x08))
  450. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  451. c->tlbsize = 48;
  452. break;
  453. case PRID_IMP_R5000:
  454. c->cputype = CPU_R5000;
  455. __cpu_name[cpu] = "R5000";
  456. c->isa_level = MIPS_CPU_ISA_IV;
  457. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  458. MIPS_CPU_LLSC;
  459. c->tlbsize = 48;
  460. break;
  461. case PRID_IMP_R5432:
  462. c->cputype = CPU_R5432;
  463. __cpu_name[cpu] = "R5432";
  464. c->isa_level = MIPS_CPU_ISA_IV;
  465. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  466. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  467. c->tlbsize = 48;
  468. break;
  469. case PRID_IMP_R5500:
  470. c->cputype = CPU_R5500;
  471. __cpu_name[cpu] = "R5500";
  472. c->isa_level = MIPS_CPU_ISA_IV;
  473. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  474. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  475. c->tlbsize = 48;
  476. break;
  477. case PRID_IMP_NEVADA:
  478. c->cputype = CPU_NEVADA;
  479. __cpu_name[cpu] = "Nevada";
  480. c->isa_level = MIPS_CPU_ISA_IV;
  481. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  482. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  483. c->tlbsize = 48;
  484. break;
  485. case PRID_IMP_R6000:
  486. c->cputype = CPU_R6000;
  487. __cpu_name[cpu] = "R6000";
  488. c->isa_level = MIPS_CPU_ISA_II;
  489. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  490. MIPS_CPU_LLSC;
  491. c->tlbsize = 32;
  492. break;
  493. case PRID_IMP_R6000A:
  494. c->cputype = CPU_R6000A;
  495. __cpu_name[cpu] = "R6000A";
  496. c->isa_level = MIPS_CPU_ISA_II;
  497. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  498. MIPS_CPU_LLSC;
  499. c->tlbsize = 32;
  500. break;
  501. case PRID_IMP_RM7000:
  502. c->cputype = CPU_RM7000;
  503. __cpu_name[cpu] = "RM7000";
  504. c->isa_level = MIPS_CPU_ISA_IV;
  505. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  506. MIPS_CPU_LLSC;
  507. /*
  508. * Undocumented RM7000: Bit 29 in the info register of
  509. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  510. * entries.
  511. *
  512. * 29 1 => 64 entry JTLB
  513. * 0 => 48 entry JTLB
  514. */
  515. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  516. break;
  517. case PRID_IMP_RM9000:
  518. c->cputype = CPU_RM9000;
  519. __cpu_name[cpu] = "RM9000";
  520. c->isa_level = MIPS_CPU_ISA_IV;
  521. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  522. MIPS_CPU_LLSC;
  523. /*
  524. * Bit 29 in the info register of the RM9000
  525. * indicates if the TLB has 48 or 64 entries.
  526. *
  527. * 29 1 => 64 entry JTLB
  528. * 0 => 48 entry JTLB
  529. */
  530. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  531. break;
  532. case PRID_IMP_R8000:
  533. c->cputype = CPU_R8000;
  534. __cpu_name[cpu] = "RM8000";
  535. c->isa_level = MIPS_CPU_ISA_IV;
  536. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  537. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  538. MIPS_CPU_LLSC;
  539. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  540. break;
  541. case PRID_IMP_R10000:
  542. c->cputype = CPU_R10000;
  543. __cpu_name[cpu] = "R10000";
  544. c->isa_level = MIPS_CPU_ISA_IV;
  545. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  546. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  547. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  548. MIPS_CPU_LLSC;
  549. c->tlbsize = 64;
  550. break;
  551. case PRID_IMP_R12000:
  552. c->cputype = CPU_R12000;
  553. __cpu_name[cpu] = "R12000";
  554. c->isa_level = MIPS_CPU_ISA_IV;
  555. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  556. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  557. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  558. MIPS_CPU_LLSC;
  559. c->tlbsize = 64;
  560. break;
  561. case PRID_IMP_R14000:
  562. c->cputype = CPU_R14000;
  563. __cpu_name[cpu] = "R14000";
  564. c->isa_level = MIPS_CPU_ISA_IV;
  565. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  566. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  567. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  568. MIPS_CPU_LLSC;
  569. c->tlbsize = 64;
  570. break;
  571. case PRID_IMP_LOONGSON2:
  572. c->cputype = CPU_LOONGSON2;
  573. __cpu_name[cpu] = "ICT Loongson-2";
  574. c->isa_level = MIPS_CPU_ISA_III;
  575. c->options = R4K_OPTS |
  576. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  577. MIPS_CPU_32FPR;
  578. c->tlbsize = 64;
  579. break;
  580. }
  581. }
  582. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  583. "Unsupported ISA type, c0.config0: %d.";
  584. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  585. {
  586. unsigned int config0;
  587. int isa;
  588. config0 = read_c0_config();
  589. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  590. c->options |= MIPS_CPU_TLB;
  591. isa = (config0 & MIPS_CONF_AT) >> 13;
  592. switch (isa) {
  593. case 0:
  594. switch ((config0 & MIPS_CONF_AR) >> 10) {
  595. case 0:
  596. c->isa_level = MIPS_CPU_ISA_M32R1;
  597. break;
  598. case 1:
  599. c->isa_level = MIPS_CPU_ISA_M32R2;
  600. break;
  601. default:
  602. goto unknown;
  603. }
  604. break;
  605. case 2:
  606. switch ((config0 & MIPS_CONF_AR) >> 10) {
  607. case 0:
  608. c->isa_level = MIPS_CPU_ISA_M64R1;
  609. break;
  610. case 1:
  611. c->isa_level = MIPS_CPU_ISA_M64R2;
  612. break;
  613. default:
  614. goto unknown;
  615. }
  616. break;
  617. default:
  618. goto unknown;
  619. }
  620. return config0 & MIPS_CONF_M;
  621. unknown:
  622. panic(unknown_isa, config0);
  623. }
  624. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  625. {
  626. unsigned int config1;
  627. config1 = read_c0_config1();
  628. if (config1 & MIPS_CONF1_MD)
  629. c->ases |= MIPS_ASE_MDMX;
  630. if (config1 & MIPS_CONF1_WR)
  631. c->options |= MIPS_CPU_WATCH;
  632. if (config1 & MIPS_CONF1_CA)
  633. c->ases |= MIPS_ASE_MIPS16;
  634. if (config1 & MIPS_CONF1_EP)
  635. c->options |= MIPS_CPU_EJTAG;
  636. if (config1 & MIPS_CONF1_FP) {
  637. c->options |= MIPS_CPU_FPU;
  638. c->options |= MIPS_CPU_32FPR;
  639. }
  640. if (cpu_has_tlb)
  641. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  642. return config1 & MIPS_CONF_M;
  643. }
  644. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  645. {
  646. unsigned int config2;
  647. config2 = read_c0_config2();
  648. if (config2 & MIPS_CONF2_SL)
  649. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  650. return config2 & MIPS_CONF_M;
  651. }
  652. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  653. {
  654. unsigned int config3;
  655. config3 = read_c0_config3();
  656. if (config3 & MIPS_CONF3_SM)
  657. c->ases |= MIPS_ASE_SMARTMIPS;
  658. if (config3 & MIPS_CONF3_DSP)
  659. c->ases |= MIPS_ASE_DSP;
  660. if (config3 & MIPS_CONF3_VINT)
  661. c->options |= MIPS_CPU_VINT;
  662. if (config3 & MIPS_CONF3_VEIC)
  663. c->options |= MIPS_CPU_VEIC;
  664. if (config3 & MIPS_CONF3_MT)
  665. c->ases |= MIPS_ASE_MIPSMT;
  666. if (config3 & MIPS_CONF3_ULRI)
  667. c->options |= MIPS_CPU_ULRI;
  668. return config3 & MIPS_CONF_M;
  669. }
  670. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  671. {
  672. unsigned int config4;
  673. config4 = read_c0_config4();
  674. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  675. && cpu_has_tlb)
  676. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  677. return config4 & MIPS_CONF_M;
  678. }
  679. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  680. {
  681. int ok;
  682. /* MIPS32 or MIPS64 compliant CPU. */
  683. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  684. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  685. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  686. ok = decode_config0(c); /* Read Config registers. */
  687. BUG_ON(!ok); /* Arch spec violation! */
  688. if (ok)
  689. ok = decode_config1(c);
  690. if (ok)
  691. ok = decode_config2(c);
  692. if (ok)
  693. ok = decode_config3(c);
  694. if (ok)
  695. ok = decode_config4(c);
  696. mips_probe_watch_registers(c);
  697. if (cpu_has_mips_r2)
  698. c->core = read_c0_ebase() & 0x3ff;
  699. }
  700. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  701. {
  702. decode_configs(c);
  703. switch (c->processor_id & 0xff00) {
  704. case PRID_IMP_4KC:
  705. c->cputype = CPU_4KC;
  706. __cpu_name[cpu] = "MIPS 4Kc";
  707. break;
  708. case PRID_IMP_4KEC:
  709. case PRID_IMP_4KECR2:
  710. c->cputype = CPU_4KEC;
  711. __cpu_name[cpu] = "MIPS 4KEc";
  712. break;
  713. case PRID_IMP_4KSC:
  714. case PRID_IMP_4KSD:
  715. c->cputype = CPU_4KSC;
  716. __cpu_name[cpu] = "MIPS 4KSc";
  717. break;
  718. case PRID_IMP_5KC:
  719. c->cputype = CPU_5KC;
  720. __cpu_name[cpu] = "MIPS 5Kc";
  721. break;
  722. case PRID_IMP_20KC:
  723. c->cputype = CPU_20KC;
  724. __cpu_name[cpu] = "MIPS 20Kc";
  725. break;
  726. case PRID_IMP_24K:
  727. case PRID_IMP_24KE:
  728. c->cputype = CPU_24K;
  729. __cpu_name[cpu] = "MIPS 24Kc";
  730. break;
  731. case PRID_IMP_25KF:
  732. c->cputype = CPU_25KF;
  733. __cpu_name[cpu] = "MIPS 25Kc";
  734. break;
  735. case PRID_IMP_34K:
  736. c->cputype = CPU_34K;
  737. __cpu_name[cpu] = "MIPS 34Kc";
  738. break;
  739. case PRID_IMP_74K:
  740. c->cputype = CPU_74K;
  741. __cpu_name[cpu] = "MIPS 74Kc";
  742. break;
  743. case PRID_IMP_1004K:
  744. c->cputype = CPU_1004K;
  745. __cpu_name[cpu] = "MIPS 1004Kc";
  746. break;
  747. }
  748. spram_config();
  749. }
  750. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  751. {
  752. decode_configs(c);
  753. switch (c->processor_id & 0xff00) {
  754. case PRID_IMP_AU1_REV1:
  755. case PRID_IMP_AU1_REV2:
  756. c->cputype = CPU_ALCHEMY;
  757. switch ((c->processor_id >> 24) & 0xff) {
  758. case 0:
  759. __cpu_name[cpu] = "Au1000";
  760. break;
  761. case 1:
  762. __cpu_name[cpu] = "Au1500";
  763. break;
  764. case 2:
  765. __cpu_name[cpu] = "Au1100";
  766. break;
  767. case 3:
  768. __cpu_name[cpu] = "Au1550";
  769. break;
  770. case 4:
  771. __cpu_name[cpu] = "Au1200";
  772. if ((c->processor_id & 0xff) == 2)
  773. __cpu_name[cpu] = "Au1250";
  774. break;
  775. case 5:
  776. __cpu_name[cpu] = "Au1210";
  777. break;
  778. default:
  779. __cpu_name[cpu] = "Au1xxx";
  780. break;
  781. }
  782. break;
  783. }
  784. }
  785. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  786. {
  787. decode_configs(c);
  788. switch (c->processor_id & 0xff00) {
  789. case PRID_IMP_SB1:
  790. c->cputype = CPU_SB1;
  791. __cpu_name[cpu] = "SiByte SB1";
  792. /* FPU in pass1 is known to have issues. */
  793. if ((c->processor_id & 0xff) < 0x02)
  794. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  795. break;
  796. case PRID_IMP_SB1A:
  797. c->cputype = CPU_SB1A;
  798. __cpu_name[cpu] = "SiByte SB1A";
  799. break;
  800. }
  801. }
  802. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  803. {
  804. decode_configs(c);
  805. switch (c->processor_id & 0xff00) {
  806. case PRID_IMP_SR71000:
  807. c->cputype = CPU_SR71000;
  808. __cpu_name[cpu] = "Sandcraft SR71000";
  809. c->scache.ways = 8;
  810. c->tlbsize = 64;
  811. break;
  812. }
  813. }
  814. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  815. {
  816. decode_configs(c);
  817. switch (c->processor_id & 0xff00) {
  818. case PRID_IMP_PR4450:
  819. c->cputype = CPU_PR4450;
  820. __cpu_name[cpu] = "Philips PR4450";
  821. c->isa_level = MIPS_CPU_ISA_M32R1;
  822. break;
  823. }
  824. }
  825. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  826. {
  827. decode_configs(c);
  828. switch (c->processor_id & 0xff00) {
  829. case PRID_IMP_BCM3302:
  830. /* same as PRID_IMP_BCM6338 */
  831. c->cputype = CPU_BCM3302;
  832. __cpu_name[cpu] = "Broadcom BCM3302";
  833. break;
  834. case PRID_IMP_BCM4710:
  835. c->cputype = CPU_BCM4710;
  836. __cpu_name[cpu] = "Broadcom BCM4710";
  837. break;
  838. case PRID_IMP_BCM6345:
  839. c->cputype = CPU_BCM6345;
  840. __cpu_name[cpu] = "Broadcom BCM6345";
  841. break;
  842. case PRID_IMP_BCM6348:
  843. c->cputype = CPU_BCM6348;
  844. __cpu_name[cpu] = "Broadcom BCM6348";
  845. break;
  846. case PRID_IMP_BCM4350:
  847. switch (c->processor_id & 0xf0) {
  848. case PRID_REV_BCM6358:
  849. c->cputype = CPU_BCM6358;
  850. __cpu_name[cpu] = "Broadcom BCM6358";
  851. break;
  852. default:
  853. c->cputype = CPU_UNKNOWN;
  854. break;
  855. }
  856. break;
  857. }
  858. }
  859. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  860. {
  861. decode_configs(c);
  862. switch (c->processor_id & 0xff00) {
  863. case PRID_IMP_CAVIUM_CN38XX:
  864. case PRID_IMP_CAVIUM_CN31XX:
  865. case PRID_IMP_CAVIUM_CN30XX:
  866. c->cputype = CPU_CAVIUM_OCTEON;
  867. __cpu_name[cpu] = "Cavium Octeon";
  868. goto platform;
  869. case PRID_IMP_CAVIUM_CN58XX:
  870. case PRID_IMP_CAVIUM_CN56XX:
  871. case PRID_IMP_CAVIUM_CN50XX:
  872. case PRID_IMP_CAVIUM_CN52XX:
  873. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  874. __cpu_name[cpu] = "Cavium Octeon+";
  875. platform:
  876. if (cpu == 0)
  877. __elf_platform = "octeon";
  878. break;
  879. default:
  880. printk(KERN_INFO "Unknown Octeon chip!\n");
  881. c->cputype = CPU_UNKNOWN;
  882. break;
  883. }
  884. }
  885. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  886. {
  887. decode_configs(c);
  888. /* JZRISC does not implement the CP0 counter. */
  889. c->options &= ~MIPS_CPU_COUNTER;
  890. switch (c->processor_id & 0xff00) {
  891. case PRID_IMP_JZRISC:
  892. c->cputype = CPU_JZRISC;
  893. __cpu_name[cpu] = "Ingenic JZRISC";
  894. break;
  895. default:
  896. panic("Unknown Ingenic Processor ID!");
  897. break;
  898. }
  899. }
  900. const char *__cpu_name[NR_CPUS];
  901. const char *__elf_platform;
  902. __cpuinit void cpu_probe(void)
  903. {
  904. struct cpuinfo_mips *c = &current_cpu_data;
  905. unsigned int cpu = smp_processor_id();
  906. c->processor_id = PRID_IMP_UNKNOWN;
  907. c->fpu_id = FPIR_IMP_NONE;
  908. c->cputype = CPU_UNKNOWN;
  909. c->processor_id = read_c0_prid();
  910. switch (c->processor_id & 0xff0000) {
  911. case PRID_COMP_LEGACY:
  912. cpu_probe_legacy(c, cpu);
  913. break;
  914. case PRID_COMP_MIPS:
  915. cpu_probe_mips(c, cpu);
  916. break;
  917. case PRID_COMP_ALCHEMY:
  918. cpu_probe_alchemy(c, cpu);
  919. break;
  920. case PRID_COMP_SIBYTE:
  921. cpu_probe_sibyte(c, cpu);
  922. break;
  923. case PRID_COMP_BROADCOM:
  924. cpu_probe_broadcom(c, cpu);
  925. break;
  926. case PRID_COMP_SANDCRAFT:
  927. cpu_probe_sandcraft(c, cpu);
  928. break;
  929. case PRID_COMP_NXP:
  930. cpu_probe_nxp(c, cpu);
  931. break;
  932. case PRID_COMP_CAVIUM:
  933. cpu_probe_cavium(c, cpu);
  934. break;
  935. case PRID_COMP_INGENIC:
  936. cpu_probe_ingenic(c, cpu);
  937. break;
  938. }
  939. BUG_ON(!__cpu_name[cpu]);
  940. BUG_ON(c->cputype == CPU_UNKNOWN);
  941. /*
  942. * Platform code can force the cpu type to optimize code
  943. * generation. In that case be sure the cpu type is correctly
  944. * manually setup otherwise it could trigger some nasty bugs.
  945. */
  946. BUG_ON(current_cpu_type() != c->cputype);
  947. if (mips_fpu_disabled)
  948. c->options &= ~MIPS_CPU_FPU;
  949. if (mips_dsp_disabled)
  950. c->ases &= ~MIPS_ASE_DSP;
  951. if (c->options & MIPS_CPU_FPU) {
  952. c->fpu_id = cpu_get_fpu_id();
  953. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  954. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  955. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  956. c->isa_level == MIPS_CPU_ISA_M64R2) {
  957. if (c->fpu_id & MIPS_FPIR_3D)
  958. c->ases |= MIPS_ASE_MIPS3D;
  959. }
  960. }
  961. if (cpu_has_mips_r2)
  962. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  963. else
  964. c->srsets = 1;
  965. cpu_probe_vmbits(c);
  966. }
  967. __cpuinit void cpu_report(void)
  968. {
  969. struct cpuinfo_mips *c = &current_cpu_data;
  970. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  971. c->processor_id, cpu_name_string());
  972. if (c->options & MIPS_CPU_FPU)
  973. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  974. }