cpu-probe.c 27 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174
  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/export.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/elf.h>
  27. #include <asm/spram.h>
  28. #include <asm/uaccess.h>
  29. /*
  30. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  31. * the implementation of the "wait" feature differs between CPU families. This
  32. * points to the function that implements CPU specific wait.
  33. * The wait instruction stops the pipeline and reduces the power consumption of
  34. * the CPU very much.
  35. */
  36. void (*cpu_wait)(void);
  37. EXPORT_SYMBOL(cpu_wait);
  38. static void r3081_wait(void)
  39. {
  40. unsigned long cfg = read_c0_conf();
  41. write_c0_conf(cfg | R30XX_CONF_HALT);
  42. }
  43. static void r39xx_wait(void)
  44. {
  45. local_irq_disable();
  46. if (!need_resched())
  47. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  48. local_irq_enable();
  49. }
  50. extern void r4k_wait(void);
  51. /*
  52. * This variant is preferable as it allows testing need_resched and going to
  53. * sleep depending on the outcome atomically. Unfortunately the "It is
  54. * implementation-dependent whether the pipeline restarts when a non-enabled
  55. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  56. * using this version a gamble.
  57. */
  58. void r4k_wait_irqoff(void)
  59. {
  60. local_irq_disable();
  61. if (!need_resched())
  62. __asm__(" .set push \n"
  63. " .set mips3 \n"
  64. " wait \n"
  65. " .set pop \n");
  66. local_irq_enable();
  67. __asm__(" .globl __pastwait \n"
  68. "__pastwait: \n");
  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. static inline void set_elf_platform(int cpu, const char *plat)
  261. {
  262. if (cpu == 0)
  263. __elf_platform = plat;
  264. }
  265. /*
  266. * Get the FPU Implementation/Revision.
  267. */
  268. static inline unsigned long cpu_get_fpu_id(void)
  269. {
  270. unsigned long tmp, fpu_id;
  271. tmp = read_c0_status();
  272. __enable_fpu();
  273. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  274. write_c0_status(tmp);
  275. return fpu_id;
  276. }
  277. /*
  278. * Check the CPU has an FPU the official way.
  279. */
  280. static inline int __cpu_has_fpu(void)
  281. {
  282. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  283. }
  284. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  285. {
  286. #ifdef __NEED_VMBITS_PROBE
  287. write_c0_entryhi(0x3fffffffffffe000ULL);
  288. back_to_back_c0_hazard();
  289. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  290. #endif
  291. }
  292. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  293. | MIPS_CPU_COUNTER)
  294. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  295. {
  296. switch (c->processor_id & 0xff00) {
  297. case PRID_IMP_R2000:
  298. c->cputype = CPU_R2000;
  299. __cpu_name[cpu] = "R2000";
  300. c->isa_level = MIPS_CPU_ISA_I;
  301. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  302. MIPS_CPU_NOFPUEX;
  303. if (__cpu_has_fpu())
  304. c->options |= MIPS_CPU_FPU;
  305. c->tlbsize = 64;
  306. break;
  307. case PRID_IMP_R3000:
  308. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  309. if (cpu_has_confreg()) {
  310. c->cputype = CPU_R3081E;
  311. __cpu_name[cpu] = "R3081";
  312. } else {
  313. c->cputype = CPU_R3000A;
  314. __cpu_name[cpu] = "R3000A";
  315. }
  316. break;
  317. } else {
  318. c->cputype = CPU_R3000;
  319. __cpu_name[cpu] = "R3000";
  320. }
  321. c->isa_level = MIPS_CPU_ISA_I;
  322. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  323. MIPS_CPU_NOFPUEX;
  324. if (__cpu_has_fpu())
  325. c->options |= MIPS_CPU_FPU;
  326. c->tlbsize = 64;
  327. break;
  328. case PRID_IMP_R4000:
  329. if (read_c0_config() & CONF_SC) {
  330. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  331. c->cputype = CPU_R4400PC;
  332. __cpu_name[cpu] = "R4400PC";
  333. } else {
  334. c->cputype = CPU_R4000PC;
  335. __cpu_name[cpu] = "R4000PC";
  336. }
  337. } else {
  338. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  339. c->cputype = CPU_R4400SC;
  340. __cpu_name[cpu] = "R4400SC";
  341. } else {
  342. c->cputype = CPU_R4000SC;
  343. __cpu_name[cpu] = "R4000SC";
  344. }
  345. }
  346. c->isa_level = MIPS_CPU_ISA_III;
  347. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  348. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  349. MIPS_CPU_LLSC;
  350. c->tlbsize = 48;
  351. break;
  352. case PRID_IMP_VR41XX:
  353. switch (c->processor_id & 0xf0) {
  354. case PRID_REV_VR4111:
  355. c->cputype = CPU_VR4111;
  356. __cpu_name[cpu] = "NEC VR4111";
  357. break;
  358. case PRID_REV_VR4121:
  359. c->cputype = CPU_VR4121;
  360. __cpu_name[cpu] = "NEC VR4121";
  361. break;
  362. case PRID_REV_VR4122:
  363. if ((c->processor_id & 0xf) < 0x3) {
  364. c->cputype = CPU_VR4122;
  365. __cpu_name[cpu] = "NEC VR4122";
  366. } else {
  367. c->cputype = CPU_VR4181A;
  368. __cpu_name[cpu] = "NEC VR4181A";
  369. }
  370. break;
  371. case PRID_REV_VR4130:
  372. if ((c->processor_id & 0xf) < 0x4) {
  373. c->cputype = CPU_VR4131;
  374. __cpu_name[cpu] = "NEC VR4131";
  375. } else {
  376. c->cputype = CPU_VR4133;
  377. __cpu_name[cpu] = "NEC VR4133";
  378. }
  379. break;
  380. default:
  381. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  382. c->cputype = CPU_VR41XX;
  383. __cpu_name[cpu] = "NEC Vr41xx";
  384. break;
  385. }
  386. c->isa_level = MIPS_CPU_ISA_III;
  387. c->options = R4K_OPTS;
  388. c->tlbsize = 32;
  389. break;
  390. case PRID_IMP_R4300:
  391. c->cputype = CPU_R4300;
  392. __cpu_name[cpu] = "R4300";
  393. c->isa_level = MIPS_CPU_ISA_III;
  394. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  395. MIPS_CPU_LLSC;
  396. c->tlbsize = 32;
  397. break;
  398. case PRID_IMP_R4600:
  399. c->cputype = CPU_R4600;
  400. __cpu_name[cpu] = "R4600";
  401. c->isa_level = MIPS_CPU_ISA_III;
  402. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  403. MIPS_CPU_LLSC;
  404. c->tlbsize = 48;
  405. break;
  406. #if 0
  407. case PRID_IMP_R4650:
  408. /*
  409. * This processor doesn't have an MMU, so it's not
  410. * "real easy" to run Linux on it. It is left purely
  411. * for documentation. Commented out because it shares
  412. * it's c0_prid id number with the TX3900.
  413. */
  414. c->cputype = CPU_R4650;
  415. __cpu_name[cpu] = "R4650";
  416. c->isa_level = MIPS_CPU_ISA_III;
  417. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  418. c->tlbsize = 48;
  419. break;
  420. #endif
  421. case PRID_IMP_TX39:
  422. c->isa_level = MIPS_CPU_ISA_I;
  423. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  424. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  425. c->cputype = CPU_TX3927;
  426. __cpu_name[cpu] = "TX3927";
  427. c->tlbsize = 64;
  428. } else {
  429. switch (c->processor_id & 0xff) {
  430. case PRID_REV_TX3912:
  431. c->cputype = CPU_TX3912;
  432. __cpu_name[cpu] = "TX3912";
  433. c->tlbsize = 32;
  434. break;
  435. case PRID_REV_TX3922:
  436. c->cputype = CPU_TX3922;
  437. __cpu_name[cpu] = "TX3922";
  438. c->tlbsize = 64;
  439. break;
  440. }
  441. }
  442. break;
  443. case PRID_IMP_R4700:
  444. c->cputype = CPU_R4700;
  445. __cpu_name[cpu] = "R4700";
  446. c->isa_level = MIPS_CPU_ISA_III;
  447. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  448. MIPS_CPU_LLSC;
  449. c->tlbsize = 48;
  450. break;
  451. case PRID_IMP_TX49:
  452. c->cputype = CPU_TX49XX;
  453. __cpu_name[cpu] = "R49XX";
  454. c->isa_level = MIPS_CPU_ISA_III;
  455. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  456. if (!(c->processor_id & 0x08))
  457. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  458. c->tlbsize = 48;
  459. break;
  460. case PRID_IMP_R5000:
  461. c->cputype = CPU_R5000;
  462. __cpu_name[cpu] = "R5000";
  463. c->isa_level = MIPS_CPU_ISA_IV;
  464. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  465. MIPS_CPU_LLSC;
  466. c->tlbsize = 48;
  467. break;
  468. case PRID_IMP_R5432:
  469. c->cputype = CPU_R5432;
  470. __cpu_name[cpu] = "R5432";
  471. c->isa_level = MIPS_CPU_ISA_IV;
  472. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  473. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  474. c->tlbsize = 48;
  475. break;
  476. case PRID_IMP_R5500:
  477. c->cputype = CPU_R5500;
  478. __cpu_name[cpu] = "R5500";
  479. c->isa_level = MIPS_CPU_ISA_IV;
  480. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  481. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  482. c->tlbsize = 48;
  483. break;
  484. case PRID_IMP_NEVADA:
  485. c->cputype = CPU_NEVADA;
  486. __cpu_name[cpu] = "Nevada";
  487. c->isa_level = MIPS_CPU_ISA_IV;
  488. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  489. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  490. c->tlbsize = 48;
  491. break;
  492. case PRID_IMP_R6000:
  493. c->cputype = CPU_R6000;
  494. __cpu_name[cpu] = "R6000";
  495. c->isa_level = MIPS_CPU_ISA_II;
  496. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  497. MIPS_CPU_LLSC;
  498. c->tlbsize = 32;
  499. break;
  500. case PRID_IMP_R6000A:
  501. c->cputype = CPU_R6000A;
  502. __cpu_name[cpu] = "R6000A";
  503. c->isa_level = MIPS_CPU_ISA_II;
  504. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  505. MIPS_CPU_LLSC;
  506. c->tlbsize = 32;
  507. break;
  508. case PRID_IMP_RM7000:
  509. c->cputype = CPU_RM7000;
  510. __cpu_name[cpu] = "RM7000";
  511. c->isa_level = MIPS_CPU_ISA_IV;
  512. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  513. MIPS_CPU_LLSC;
  514. /*
  515. * Undocumented RM7000: Bit 29 in the info register of
  516. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  517. * entries.
  518. *
  519. * 29 1 => 64 entry JTLB
  520. * 0 => 48 entry JTLB
  521. */
  522. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  523. break;
  524. case PRID_IMP_RM9000:
  525. c->cputype = CPU_RM9000;
  526. __cpu_name[cpu] = "RM9000";
  527. c->isa_level = MIPS_CPU_ISA_IV;
  528. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  529. MIPS_CPU_LLSC;
  530. /*
  531. * Bit 29 in the info register of the RM9000
  532. * indicates if the TLB has 48 or 64 entries.
  533. *
  534. * 29 1 => 64 entry JTLB
  535. * 0 => 48 entry JTLB
  536. */
  537. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  538. break;
  539. case PRID_IMP_R8000:
  540. c->cputype = CPU_R8000;
  541. __cpu_name[cpu] = "RM8000";
  542. c->isa_level = MIPS_CPU_ISA_IV;
  543. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  544. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  545. MIPS_CPU_LLSC;
  546. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  547. break;
  548. case PRID_IMP_R10000:
  549. c->cputype = CPU_R10000;
  550. __cpu_name[cpu] = "R10000";
  551. c->isa_level = MIPS_CPU_ISA_IV;
  552. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  553. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  554. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  555. MIPS_CPU_LLSC;
  556. c->tlbsize = 64;
  557. break;
  558. case PRID_IMP_R12000:
  559. c->cputype = CPU_R12000;
  560. __cpu_name[cpu] = "R12000";
  561. c->isa_level = MIPS_CPU_ISA_IV;
  562. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  563. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  564. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  565. MIPS_CPU_LLSC;
  566. c->tlbsize = 64;
  567. break;
  568. case PRID_IMP_R14000:
  569. c->cputype = CPU_R14000;
  570. __cpu_name[cpu] = "R14000";
  571. c->isa_level = MIPS_CPU_ISA_IV;
  572. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  573. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  574. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  575. MIPS_CPU_LLSC;
  576. c->tlbsize = 64;
  577. break;
  578. case PRID_IMP_LOONGSON2:
  579. c->cputype = CPU_LOONGSON2;
  580. __cpu_name[cpu] = "ICT Loongson-2";
  581. switch (c->processor_id & PRID_REV_MASK) {
  582. case PRID_REV_LOONGSON2E:
  583. set_elf_platform(cpu, "loongson2e");
  584. break;
  585. case PRID_REV_LOONGSON2F:
  586. set_elf_platform(cpu, "loongson2f");
  587. break;
  588. }
  589. c->isa_level = MIPS_CPU_ISA_III;
  590. c->options = R4K_OPTS |
  591. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  592. MIPS_CPU_32FPR;
  593. c->tlbsize = 64;
  594. break;
  595. }
  596. }
  597. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  598. "Unsupported ISA type, c0.config0: %d.";
  599. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  600. {
  601. unsigned int config0;
  602. int isa;
  603. config0 = read_c0_config();
  604. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  605. c->options |= MIPS_CPU_TLB;
  606. isa = (config0 & MIPS_CONF_AT) >> 13;
  607. switch (isa) {
  608. case 0:
  609. switch ((config0 & MIPS_CONF_AR) >> 10) {
  610. case 0:
  611. c->isa_level = MIPS_CPU_ISA_M32R1;
  612. break;
  613. case 1:
  614. c->isa_level = MIPS_CPU_ISA_M32R2;
  615. break;
  616. default:
  617. goto unknown;
  618. }
  619. break;
  620. case 2:
  621. switch ((config0 & MIPS_CONF_AR) >> 10) {
  622. case 0:
  623. c->isa_level = MIPS_CPU_ISA_M64R1;
  624. break;
  625. case 1:
  626. c->isa_level = MIPS_CPU_ISA_M64R2;
  627. break;
  628. default:
  629. goto unknown;
  630. }
  631. break;
  632. default:
  633. goto unknown;
  634. }
  635. return config0 & MIPS_CONF_M;
  636. unknown:
  637. panic(unknown_isa, config0);
  638. }
  639. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  640. {
  641. unsigned int config1;
  642. config1 = read_c0_config1();
  643. if (config1 & MIPS_CONF1_MD)
  644. c->ases |= MIPS_ASE_MDMX;
  645. if (config1 & MIPS_CONF1_WR)
  646. c->options |= MIPS_CPU_WATCH;
  647. if (config1 & MIPS_CONF1_CA)
  648. c->ases |= MIPS_ASE_MIPS16;
  649. if (config1 & MIPS_CONF1_EP)
  650. c->options |= MIPS_CPU_EJTAG;
  651. if (config1 & MIPS_CONF1_FP) {
  652. c->options |= MIPS_CPU_FPU;
  653. c->options |= MIPS_CPU_32FPR;
  654. }
  655. if (cpu_has_tlb)
  656. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  657. return config1 & MIPS_CONF_M;
  658. }
  659. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  660. {
  661. unsigned int config2;
  662. config2 = read_c0_config2();
  663. if (config2 & MIPS_CONF2_SL)
  664. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  665. return config2 & MIPS_CONF_M;
  666. }
  667. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  668. {
  669. unsigned int config3;
  670. config3 = read_c0_config3();
  671. if (config3 & MIPS_CONF3_SM)
  672. c->ases |= MIPS_ASE_SMARTMIPS;
  673. if (config3 & MIPS_CONF3_DSP)
  674. c->ases |= MIPS_ASE_DSP;
  675. if (config3 & MIPS_CONF3_VINT)
  676. c->options |= MIPS_CPU_VINT;
  677. if (config3 & MIPS_CONF3_VEIC)
  678. c->options |= MIPS_CPU_VEIC;
  679. if (config3 & MIPS_CONF3_MT)
  680. c->ases |= MIPS_ASE_MIPSMT;
  681. if (config3 & MIPS_CONF3_ULRI)
  682. c->options |= MIPS_CPU_ULRI;
  683. return config3 & MIPS_CONF_M;
  684. }
  685. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  686. {
  687. unsigned int config4;
  688. config4 = read_c0_config4();
  689. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  690. && cpu_has_tlb)
  691. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  692. c->kscratch_mask = (config4 >> 16) & 0xff;
  693. return config4 & MIPS_CONF_M;
  694. }
  695. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  696. {
  697. int ok;
  698. /* MIPS32 or MIPS64 compliant CPU. */
  699. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  700. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  701. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  702. ok = decode_config0(c); /* Read Config registers. */
  703. BUG_ON(!ok); /* Arch spec violation! */
  704. if (ok)
  705. ok = decode_config1(c);
  706. if (ok)
  707. ok = decode_config2(c);
  708. if (ok)
  709. ok = decode_config3(c);
  710. if (ok)
  711. ok = decode_config4(c);
  712. mips_probe_watch_registers(c);
  713. if (cpu_has_mips_r2)
  714. c->core = read_c0_ebase() & 0x3ff;
  715. }
  716. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  717. {
  718. decode_configs(c);
  719. switch (c->processor_id & 0xff00) {
  720. case PRID_IMP_4KC:
  721. c->cputype = CPU_4KC;
  722. __cpu_name[cpu] = "MIPS 4Kc";
  723. break;
  724. case PRID_IMP_4KEC:
  725. case PRID_IMP_4KECR2:
  726. c->cputype = CPU_4KEC;
  727. __cpu_name[cpu] = "MIPS 4KEc";
  728. break;
  729. case PRID_IMP_4KSC:
  730. case PRID_IMP_4KSD:
  731. c->cputype = CPU_4KSC;
  732. __cpu_name[cpu] = "MIPS 4KSc";
  733. break;
  734. case PRID_IMP_5KC:
  735. c->cputype = CPU_5KC;
  736. __cpu_name[cpu] = "MIPS 5Kc";
  737. break;
  738. case PRID_IMP_20KC:
  739. c->cputype = CPU_20KC;
  740. __cpu_name[cpu] = "MIPS 20Kc";
  741. break;
  742. case PRID_IMP_24K:
  743. case PRID_IMP_24KE:
  744. c->cputype = CPU_24K;
  745. __cpu_name[cpu] = "MIPS 24Kc";
  746. break;
  747. case PRID_IMP_25KF:
  748. c->cputype = CPU_25KF;
  749. __cpu_name[cpu] = "MIPS 25Kc";
  750. break;
  751. case PRID_IMP_34K:
  752. c->cputype = CPU_34K;
  753. __cpu_name[cpu] = "MIPS 34Kc";
  754. break;
  755. case PRID_IMP_74K:
  756. c->cputype = CPU_74K;
  757. __cpu_name[cpu] = "MIPS 74Kc";
  758. break;
  759. case PRID_IMP_1004K:
  760. c->cputype = CPU_1004K;
  761. __cpu_name[cpu] = "MIPS 1004Kc";
  762. break;
  763. }
  764. spram_config();
  765. }
  766. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  767. {
  768. decode_configs(c);
  769. switch (c->processor_id & 0xff00) {
  770. case PRID_IMP_AU1_REV1:
  771. case PRID_IMP_AU1_REV2:
  772. c->cputype = CPU_ALCHEMY;
  773. switch ((c->processor_id >> 24) & 0xff) {
  774. case 0:
  775. __cpu_name[cpu] = "Au1000";
  776. break;
  777. case 1:
  778. __cpu_name[cpu] = "Au1500";
  779. break;
  780. case 2:
  781. __cpu_name[cpu] = "Au1100";
  782. break;
  783. case 3:
  784. __cpu_name[cpu] = "Au1550";
  785. break;
  786. case 4:
  787. __cpu_name[cpu] = "Au1200";
  788. if ((c->processor_id & 0xff) == 2)
  789. __cpu_name[cpu] = "Au1250";
  790. break;
  791. case 5:
  792. __cpu_name[cpu] = "Au1210";
  793. break;
  794. default:
  795. __cpu_name[cpu] = "Au1xxx";
  796. break;
  797. }
  798. break;
  799. }
  800. }
  801. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  802. {
  803. decode_configs(c);
  804. switch (c->processor_id & 0xff00) {
  805. case PRID_IMP_SB1:
  806. c->cputype = CPU_SB1;
  807. __cpu_name[cpu] = "SiByte SB1";
  808. /* FPU in pass1 is known to have issues. */
  809. if ((c->processor_id & 0xff) < 0x02)
  810. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  811. break;
  812. case PRID_IMP_SB1A:
  813. c->cputype = CPU_SB1A;
  814. __cpu_name[cpu] = "SiByte SB1A";
  815. break;
  816. }
  817. }
  818. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  819. {
  820. decode_configs(c);
  821. switch (c->processor_id & 0xff00) {
  822. case PRID_IMP_SR71000:
  823. c->cputype = CPU_SR71000;
  824. __cpu_name[cpu] = "Sandcraft SR71000";
  825. c->scache.ways = 8;
  826. c->tlbsize = 64;
  827. break;
  828. }
  829. }
  830. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  831. {
  832. decode_configs(c);
  833. switch (c->processor_id & 0xff00) {
  834. case PRID_IMP_PR4450:
  835. c->cputype = CPU_PR4450;
  836. __cpu_name[cpu] = "Philips PR4450";
  837. c->isa_level = MIPS_CPU_ISA_M32R1;
  838. break;
  839. }
  840. }
  841. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  842. {
  843. decode_configs(c);
  844. switch (c->processor_id & 0xff00) {
  845. case PRID_IMP_BMIPS32_REV4:
  846. case PRID_IMP_BMIPS32_REV8:
  847. c->cputype = CPU_BMIPS32;
  848. __cpu_name[cpu] = "Broadcom BMIPS32";
  849. set_elf_platform(cpu, "bmips32");
  850. break;
  851. case PRID_IMP_BMIPS3300:
  852. case PRID_IMP_BMIPS3300_ALT:
  853. case PRID_IMP_BMIPS3300_BUG:
  854. c->cputype = CPU_BMIPS3300;
  855. __cpu_name[cpu] = "Broadcom BMIPS3300";
  856. set_elf_platform(cpu, "bmips3300");
  857. break;
  858. case PRID_IMP_BMIPS43XX: {
  859. int rev = c->processor_id & 0xff;
  860. if (rev >= PRID_REV_BMIPS4380_LO &&
  861. rev <= PRID_REV_BMIPS4380_HI) {
  862. c->cputype = CPU_BMIPS4380;
  863. __cpu_name[cpu] = "Broadcom BMIPS4380";
  864. set_elf_platform(cpu, "bmips4380");
  865. } else {
  866. c->cputype = CPU_BMIPS4350;
  867. __cpu_name[cpu] = "Broadcom BMIPS4350";
  868. set_elf_platform(cpu, "bmips4350");
  869. }
  870. break;
  871. }
  872. case PRID_IMP_BMIPS5000:
  873. c->cputype = CPU_BMIPS5000;
  874. __cpu_name[cpu] = "Broadcom BMIPS5000";
  875. set_elf_platform(cpu, "bmips5000");
  876. c->options |= MIPS_CPU_ULRI;
  877. break;
  878. }
  879. }
  880. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  881. {
  882. decode_configs(c);
  883. switch (c->processor_id & 0xff00) {
  884. case PRID_IMP_CAVIUM_CN38XX:
  885. case PRID_IMP_CAVIUM_CN31XX:
  886. case PRID_IMP_CAVIUM_CN30XX:
  887. c->cputype = CPU_CAVIUM_OCTEON;
  888. __cpu_name[cpu] = "Cavium Octeon";
  889. goto platform;
  890. case PRID_IMP_CAVIUM_CN58XX:
  891. case PRID_IMP_CAVIUM_CN56XX:
  892. case PRID_IMP_CAVIUM_CN50XX:
  893. case PRID_IMP_CAVIUM_CN52XX:
  894. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  895. __cpu_name[cpu] = "Cavium Octeon+";
  896. platform:
  897. set_elf_platform(cpu, "octeon");
  898. break;
  899. case PRID_IMP_CAVIUM_CN61XX:
  900. case PRID_IMP_CAVIUM_CN63XX:
  901. case PRID_IMP_CAVIUM_CN66XX:
  902. case PRID_IMP_CAVIUM_CN68XX:
  903. c->cputype = CPU_CAVIUM_OCTEON2;
  904. __cpu_name[cpu] = "Cavium Octeon II";
  905. set_elf_platform(cpu, "octeon2");
  906. break;
  907. default:
  908. printk(KERN_INFO "Unknown Octeon chip!\n");
  909. c->cputype = CPU_UNKNOWN;
  910. break;
  911. }
  912. }
  913. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  914. {
  915. decode_configs(c);
  916. /* JZRISC does not implement the CP0 counter. */
  917. c->options &= ~MIPS_CPU_COUNTER;
  918. switch (c->processor_id & 0xff00) {
  919. case PRID_IMP_JZRISC:
  920. c->cputype = CPU_JZRISC;
  921. __cpu_name[cpu] = "Ingenic JZRISC";
  922. break;
  923. default:
  924. panic("Unknown Ingenic Processor ID!");
  925. break;
  926. }
  927. }
  928. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  929. {
  930. decode_configs(c);
  931. if ((c->processor_id & 0xff00) == PRID_IMP_NETLOGIC_AU13XX) {
  932. c->cputype = CPU_ALCHEMY;
  933. __cpu_name[cpu] = "Au1300";
  934. /* following stuff is not for Alchemy */
  935. return;
  936. }
  937. c->options = (MIPS_CPU_TLB |
  938. MIPS_CPU_4KEX |
  939. MIPS_CPU_COUNTER |
  940. MIPS_CPU_DIVEC |
  941. MIPS_CPU_WATCH |
  942. MIPS_CPU_EJTAG |
  943. MIPS_CPU_LLSC);
  944. switch (c->processor_id & 0xff00) {
  945. case PRID_IMP_NETLOGIC_XLR732:
  946. case PRID_IMP_NETLOGIC_XLR716:
  947. case PRID_IMP_NETLOGIC_XLR532:
  948. case PRID_IMP_NETLOGIC_XLR308:
  949. case PRID_IMP_NETLOGIC_XLR532C:
  950. case PRID_IMP_NETLOGIC_XLR516C:
  951. case PRID_IMP_NETLOGIC_XLR508C:
  952. case PRID_IMP_NETLOGIC_XLR308C:
  953. c->cputype = CPU_XLR;
  954. __cpu_name[cpu] = "Netlogic XLR";
  955. break;
  956. case PRID_IMP_NETLOGIC_XLS608:
  957. case PRID_IMP_NETLOGIC_XLS408:
  958. case PRID_IMP_NETLOGIC_XLS404:
  959. case PRID_IMP_NETLOGIC_XLS208:
  960. case PRID_IMP_NETLOGIC_XLS204:
  961. case PRID_IMP_NETLOGIC_XLS108:
  962. case PRID_IMP_NETLOGIC_XLS104:
  963. case PRID_IMP_NETLOGIC_XLS616B:
  964. case PRID_IMP_NETLOGIC_XLS608B:
  965. case PRID_IMP_NETLOGIC_XLS416B:
  966. case PRID_IMP_NETLOGIC_XLS412B:
  967. case PRID_IMP_NETLOGIC_XLS408B:
  968. case PRID_IMP_NETLOGIC_XLS404B:
  969. c->cputype = CPU_XLR;
  970. __cpu_name[cpu] = "Netlogic XLS";
  971. break;
  972. default:
  973. printk(KERN_INFO "Unknown Netlogic chip id [%02x]!\n",
  974. c->processor_id);
  975. c->cputype = CPU_XLR;
  976. break;
  977. }
  978. c->isa_level = MIPS_CPU_ISA_M64R1;
  979. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  980. }
  981. #ifdef CONFIG_64BIT
  982. /* For use by uaccess.h */
  983. u64 __ua_limit;
  984. EXPORT_SYMBOL(__ua_limit);
  985. #endif
  986. const char *__cpu_name[NR_CPUS];
  987. const char *__elf_platform;
  988. __cpuinit void cpu_probe(void)
  989. {
  990. struct cpuinfo_mips *c = &current_cpu_data;
  991. unsigned int cpu = smp_processor_id();
  992. c->processor_id = PRID_IMP_UNKNOWN;
  993. c->fpu_id = FPIR_IMP_NONE;
  994. c->cputype = CPU_UNKNOWN;
  995. c->processor_id = read_c0_prid();
  996. switch (c->processor_id & 0xff0000) {
  997. case PRID_COMP_LEGACY:
  998. cpu_probe_legacy(c, cpu);
  999. break;
  1000. case PRID_COMP_MIPS:
  1001. cpu_probe_mips(c, cpu);
  1002. break;
  1003. case PRID_COMP_ALCHEMY:
  1004. cpu_probe_alchemy(c, cpu);
  1005. break;
  1006. case PRID_COMP_SIBYTE:
  1007. cpu_probe_sibyte(c, cpu);
  1008. break;
  1009. case PRID_COMP_BROADCOM:
  1010. cpu_probe_broadcom(c, cpu);
  1011. break;
  1012. case PRID_COMP_SANDCRAFT:
  1013. cpu_probe_sandcraft(c, cpu);
  1014. break;
  1015. case PRID_COMP_NXP:
  1016. cpu_probe_nxp(c, cpu);
  1017. break;
  1018. case PRID_COMP_CAVIUM:
  1019. cpu_probe_cavium(c, cpu);
  1020. break;
  1021. case PRID_COMP_INGENIC:
  1022. cpu_probe_ingenic(c, cpu);
  1023. break;
  1024. case PRID_COMP_NETLOGIC:
  1025. cpu_probe_netlogic(c, cpu);
  1026. break;
  1027. }
  1028. BUG_ON(!__cpu_name[cpu]);
  1029. BUG_ON(c->cputype == CPU_UNKNOWN);
  1030. /*
  1031. * Platform code can force the cpu type to optimize code
  1032. * generation. In that case be sure the cpu type is correctly
  1033. * manually setup otherwise it could trigger some nasty bugs.
  1034. */
  1035. BUG_ON(current_cpu_type() != c->cputype);
  1036. if (mips_fpu_disabled)
  1037. c->options &= ~MIPS_CPU_FPU;
  1038. if (mips_dsp_disabled)
  1039. c->ases &= ~MIPS_ASE_DSP;
  1040. if (c->options & MIPS_CPU_FPU) {
  1041. c->fpu_id = cpu_get_fpu_id();
  1042. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  1043. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  1044. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  1045. c->isa_level == MIPS_CPU_ISA_M64R2) {
  1046. if (c->fpu_id & MIPS_FPIR_3D)
  1047. c->ases |= MIPS_ASE_MIPS3D;
  1048. }
  1049. }
  1050. if (cpu_has_mips_r2)
  1051. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1052. else
  1053. c->srsets = 1;
  1054. cpu_probe_vmbits(c);
  1055. #ifdef CONFIG_64BIT
  1056. if (cpu == 0)
  1057. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1058. #endif
  1059. }
  1060. __cpuinit void cpu_report(void)
  1061. {
  1062. struct cpuinfo_mips *c = &current_cpu_data;
  1063. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  1064. c->processor_id, cpu_name_string());
  1065. if (c->options & MIPS_CPU_FPU)
  1066. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1067. }