cpu-probe.c 25 KB

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