cpu-probe.c 37 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513
  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, 2011, 2012 MIPS Technologies, 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/cpu-features.h>
  23. #include <asm/cpu-type.h>
  24. #include <asm/fpu.h>
  25. #include <asm/mipsregs.h>
  26. #include <asm/mipsmtregs.h>
  27. #include <asm/msa.h>
  28. #include <asm/watch.h>
  29. #include <asm/elf.h>
  30. #include <asm/pgtable-bits.h>
  31. #include <asm/spram.h>
  32. #include <asm/uaccess.h>
  33. /*
  34. * Get the FPU Implementation/Revision.
  35. */
  36. static inline unsigned long cpu_get_fpu_id(void)
  37. {
  38. unsigned long tmp, fpu_id;
  39. tmp = read_c0_status();
  40. __enable_fpu(FPU_AS_IS);
  41. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  42. write_c0_status(tmp);
  43. return fpu_id;
  44. }
  45. /*
  46. * Check if the CPU has an external FPU.
  47. */
  48. static inline int __cpu_has_fpu(void)
  49. {
  50. return (cpu_get_fpu_id() & FPIR_IMP_MASK) != FPIR_IMP_NONE;
  51. }
  52. static inline unsigned long cpu_get_msa_id(void)
  53. {
  54. unsigned long status, msa_id;
  55. status = read_c0_status();
  56. __enable_fpu(FPU_64BIT);
  57. enable_msa();
  58. msa_id = read_msa_ir();
  59. disable_msa();
  60. write_c0_status(status);
  61. return msa_id;
  62. }
  63. /*
  64. * Determine the FCSR mask for FPU hardware.
  65. */
  66. static inline void cpu_set_fpu_fcsr_mask(struct cpuinfo_mips *c)
  67. {
  68. unsigned long sr, mask, fcsr, fcsr0, fcsr1;
  69. fcsr = c->fpu_csr31;
  70. mask = FPU_CSR_ALL_X | FPU_CSR_ALL_E | FPU_CSR_ALL_S | FPU_CSR_RM;
  71. sr = read_c0_status();
  72. __enable_fpu(FPU_AS_IS);
  73. fcsr0 = fcsr & mask;
  74. write_32bit_cp1_register(CP1_STATUS, fcsr0);
  75. fcsr0 = read_32bit_cp1_register(CP1_STATUS);
  76. fcsr1 = fcsr | ~mask;
  77. write_32bit_cp1_register(CP1_STATUS, fcsr1);
  78. fcsr1 = read_32bit_cp1_register(CP1_STATUS);
  79. write_32bit_cp1_register(CP1_STATUS, fcsr);
  80. write_c0_status(sr);
  81. c->fpu_msk31 = ~(fcsr0 ^ fcsr1) & ~mask;
  82. }
  83. /*
  84. * Set the FIR feature flags for the FPU emulator.
  85. */
  86. static void cpu_set_nofpu_id(struct cpuinfo_mips *c)
  87. {
  88. u32 value;
  89. value = 0;
  90. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  91. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  92. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6))
  93. value |= MIPS_FPIR_D | MIPS_FPIR_S;
  94. if (c->isa_level & (MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  95. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6))
  96. value |= MIPS_FPIR_F64 | MIPS_FPIR_L | MIPS_FPIR_W;
  97. c->fpu_id = value;
  98. }
  99. /* Determined FPU emulator mask to use for the boot CPU with "nofpu". */
  100. static unsigned int mips_nofpu_msk31;
  101. /*
  102. * Set options for FPU hardware.
  103. */
  104. static void cpu_set_fpu_opts(struct cpuinfo_mips *c)
  105. {
  106. c->fpu_id = cpu_get_fpu_id();
  107. mips_nofpu_msk31 = c->fpu_msk31;
  108. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  109. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  110. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  111. if (c->fpu_id & MIPS_FPIR_3D)
  112. c->ases |= MIPS_ASE_MIPS3D;
  113. if (c->fpu_id & MIPS_FPIR_FREP)
  114. c->options |= MIPS_CPU_FRE;
  115. }
  116. cpu_set_fpu_fcsr_mask(c);
  117. }
  118. /*
  119. * Set options for the FPU emulator.
  120. */
  121. static void cpu_set_nofpu_opts(struct cpuinfo_mips *c)
  122. {
  123. c->options &= ~MIPS_CPU_FPU;
  124. c->fpu_msk31 = mips_nofpu_msk31;
  125. cpu_set_nofpu_id(c);
  126. }
  127. static int mips_fpu_disabled;
  128. static int __init fpu_disable(char *s)
  129. {
  130. cpu_set_nofpu_opts(&boot_cpu_data);
  131. mips_fpu_disabled = 1;
  132. return 1;
  133. }
  134. __setup("nofpu", fpu_disable);
  135. int mips_dsp_disabled;
  136. static int __init dsp_disable(char *s)
  137. {
  138. cpu_data[0].ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  139. mips_dsp_disabled = 1;
  140. return 1;
  141. }
  142. __setup("nodsp", dsp_disable);
  143. static int mips_htw_disabled;
  144. static int __init htw_disable(char *s)
  145. {
  146. mips_htw_disabled = 1;
  147. cpu_data[0].options &= ~MIPS_CPU_HTW;
  148. write_c0_pwctl(read_c0_pwctl() &
  149. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  150. return 1;
  151. }
  152. __setup("nohtw", htw_disable);
  153. static int mips_ftlb_disabled;
  154. static int mips_has_ftlb_configured;
  155. static void set_ftlb_enable(struct cpuinfo_mips *c, int enable);
  156. static int __init ftlb_disable(char *s)
  157. {
  158. unsigned int config4, mmuextdef;
  159. /*
  160. * If the core hasn't done any FTLB configuration, there is nothing
  161. * for us to do here.
  162. */
  163. if (!mips_has_ftlb_configured)
  164. return 1;
  165. /* Disable it in the boot cpu */
  166. set_ftlb_enable(&cpu_data[0], 0);
  167. back_to_back_c0_hazard();
  168. config4 = read_c0_config4();
  169. /* Check that FTLB has been disabled */
  170. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  171. /* MMUSIZEEXT == VTLB ON, FTLB OFF */
  172. if (mmuextdef == MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT) {
  173. /* This should never happen */
  174. pr_warn("FTLB could not be disabled!\n");
  175. return 1;
  176. }
  177. mips_ftlb_disabled = 1;
  178. mips_has_ftlb_configured = 0;
  179. /*
  180. * noftlb is mainly used for debug purposes so print
  181. * an informative message instead of using pr_debug()
  182. */
  183. pr_info("FTLB has been disabled\n");
  184. /*
  185. * Some of these bits are duplicated in the decode_config4.
  186. * MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT is the only possible case
  187. * once FTLB has been disabled so undo what decode_config4 did.
  188. */
  189. cpu_data[0].tlbsize -= cpu_data[0].tlbsizeftlbways *
  190. cpu_data[0].tlbsizeftlbsets;
  191. cpu_data[0].tlbsizeftlbsets = 0;
  192. cpu_data[0].tlbsizeftlbways = 0;
  193. return 1;
  194. }
  195. __setup("noftlb", ftlb_disable);
  196. static inline void check_errata(void)
  197. {
  198. struct cpuinfo_mips *c = &current_cpu_data;
  199. switch (current_cpu_type()) {
  200. case CPU_34K:
  201. /*
  202. * Erratum "RPS May Cause Incorrect Instruction Execution"
  203. * This code only handles VPE0, any SMP/RTOS code
  204. * making use of VPE1 will be responsable for that VPE.
  205. */
  206. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  207. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  208. break;
  209. default:
  210. break;
  211. }
  212. }
  213. void __init check_bugs32(void)
  214. {
  215. check_errata();
  216. }
  217. /*
  218. * Probe whether cpu has config register by trying to play with
  219. * alternate cache bit and see whether it matters.
  220. * It's used by cpu_probe to distinguish between R3000A and R3081.
  221. */
  222. static inline int cpu_has_confreg(void)
  223. {
  224. #ifdef CONFIG_CPU_R3000
  225. extern unsigned long r3k_cache_size(unsigned long);
  226. unsigned long size1, size2;
  227. unsigned long cfg = read_c0_conf();
  228. size1 = r3k_cache_size(ST0_ISC);
  229. write_c0_conf(cfg ^ R30XX_CONF_AC);
  230. size2 = r3k_cache_size(ST0_ISC);
  231. write_c0_conf(cfg);
  232. return size1 != size2;
  233. #else
  234. return 0;
  235. #endif
  236. }
  237. static inline void set_elf_platform(int cpu, const char *plat)
  238. {
  239. if (cpu == 0)
  240. __elf_platform = plat;
  241. }
  242. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  243. {
  244. #ifdef __NEED_VMBITS_PROBE
  245. write_c0_entryhi(0x3fffffffffffe000ULL);
  246. back_to_back_c0_hazard();
  247. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  248. #endif
  249. }
  250. static void set_isa(struct cpuinfo_mips *c, unsigned int isa)
  251. {
  252. switch (isa) {
  253. case MIPS_CPU_ISA_M64R2:
  254. c->isa_level |= MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2;
  255. case MIPS_CPU_ISA_M64R1:
  256. c->isa_level |= MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1;
  257. case MIPS_CPU_ISA_V:
  258. c->isa_level |= MIPS_CPU_ISA_V;
  259. case MIPS_CPU_ISA_IV:
  260. c->isa_level |= MIPS_CPU_ISA_IV;
  261. case MIPS_CPU_ISA_III:
  262. c->isa_level |= MIPS_CPU_ISA_II | MIPS_CPU_ISA_III;
  263. break;
  264. /* R6 incompatible with everything else */
  265. case MIPS_CPU_ISA_M64R6:
  266. c->isa_level |= MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6;
  267. case MIPS_CPU_ISA_M32R6:
  268. c->isa_level |= MIPS_CPU_ISA_M32R6;
  269. /* Break here so we don't add incompatible ISAs */
  270. break;
  271. case MIPS_CPU_ISA_M32R2:
  272. c->isa_level |= MIPS_CPU_ISA_M32R2;
  273. case MIPS_CPU_ISA_M32R1:
  274. c->isa_level |= MIPS_CPU_ISA_M32R1;
  275. case MIPS_CPU_ISA_II:
  276. c->isa_level |= MIPS_CPU_ISA_II;
  277. break;
  278. }
  279. }
  280. static char unknown_isa[] = KERN_ERR \
  281. "Unsupported ISA type, c0.config0: %d.";
  282. static unsigned int calculate_ftlb_probability(struct cpuinfo_mips *c)
  283. {
  284. unsigned int probability = c->tlbsize / c->tlbsizevtlb;
  285. /*
  286. * 0 = All TLBWR instructions go to FTLB
  287. * 1 = 15:1: For every 16 TBLWR instructions, 15 go to the
  288. * FTLB and 1 goes to the VTLB.
  289. * 2 = 7:1: As above with 7:1 ratio.
  290. * 3 = 3:1: As above with 3:1 ratio.
  291. *
  292. * Use the linear midpoint as the probability threshold.
  293. */
  294. if (probability >= 12)
  295. return 1;
  296. else if (probability >= 6)
  297. return 2;
  298. else
  299. /*
  300. * So FTLB is less than 4 times bigger than VTLB.
  301. * A 3:1 ratio can still be useful though.
  302. */
  303. return 3;
  304. }
  305. static void set_ftlb_enable(struct cpuinfo_mips *c, int enable)
  306. {
  307. unsigned int config6;
  308. /* It's implementation dependent how the FTLB can be enabled */
  309. switch (c->cputype) {
  310. case CPU_PROAPTIV:
  311. case CPU_P5600:
  312. /* proAptiv & related cores use Config6 to enable the FTLB */
  313. config6 = read_c0_config6();
  314. /* Clear the old probability value */
  315. config6 &= ~(3 << MIPS_CONF6_FTLBP_SHIFT);
  316. if (enable)
  317. /* Enable FTLB */
  318. write_c0_config6(config6 |
  319. (calculate_ftlb_probability(c)
  320. << MIPS_CONF6_FTLBP_SHIFT)
  321. | MIPS_CONF6_FTLBEN);
  322. else
  323. /* Disable FTLB */
  324. write_c0_config6(config6 & ~MIPS_CONF6_FTLBEN);
  325. back_to_back_c0_hazard();
  326. break;
  327. }
  328. }
  329. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  330. {
  331. unsigned int config0;
  332. int isa;
  333. config0 = read_c0_config();
  334. /*
  335. * Look for Standard TLB or Dual VTLB and FTLB
  336. */
  337. if ((((config0 & MIPS_CONF_MT) >> 7) == 1) ||
  338. (((config0 & MIPS_CONF_MT) >> 7) == 4))
  339. c->options |= MIPS_CPU_TLB;
  340. isa = (config0 & MIPS_CONF_AT) >> 13;
  341. switch (isa) {
  342. case 0:
  343. switch ((config0 & MIPS_CONF_AR) >> 10) {
  344. case 0:
  345. set_isa(c, MIPS_CPU_ISA_M32R1);
  346. break;
  347. case 1:
  348. set_isa(c, MIPS_CPU_ISA_M32R2);
  349. break;
  350. case 2:
  351. set_isa(c, MIPS_CPU_ISA_M32R6);
  352. break;
  353. default:
  354. goto unknown;
  355. }
  356. break;
  357. case 2:
  358. switch ((config0 & MIPS_CONF_AR) >> 10) {
  359. case 0:
  360. set_isa(c, MIPS_CPU_ISA_M64R1);
  361. break;
  362. case 1:
  363. set_isa(c, MIPS_CPU_ISA_M64R2);
  364. break;
  365. case 2:
  366. set_isa(c, MIPS_CPU_ISA_M64R6);
  367. break;
  368. default:
  369. goto unknown;
  370. }
  371. break;
  372. default:
  373. goto unknown;
  374. }
  375. return config0 & MIPS_CONF_M;
  376. unknown:
  377. panic(unknown_isa, config0);
  378. }
  379. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  380. {
  381. unsigned int config1;
  382. config1 = read_c0_config1();
  383. if (config1 & MIPS_CONF1_MD)
  384. c->ases |= MIPS_ASE_MDMX;
  385. if (config1 & MIPS_CONF1_WR)
  386. c->options |= MIPS_CPU_WATCH;
  387. if (config1 & MIPS_CONF1_CA)
  388. c->ases |= MIPS_ASE_MIPS16;
  389. if (config1 & MIPS_CONF1_EP)
  390. c->options |= MIPS_CPU_EJTAG;
  391. if (config1 & MIPS_CONF1_FP) {
  392. c->options |= MIPS_CPU_FPU;
  393. c->options |= MIPS_CPU_32FPR;
  394. }
  395. if (cpu_has_tlb) {
  396. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  397. c->tlbsizevtlb = c->tlbsize;
  398. c->tlbsizeftlbsets = 0;
  399. }
  400. return config1 & MIPS_CONF_M;
  401. }
  402. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  403. {
  404. unsigned int config2;
  405. config2 = read_c0_config2();
  406. if (config2 & MIPS_CONF2_SL)
  407. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  408. return config2 & MIPS_CONF_M;
  409. }
  410. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  411. {
  412. unsigned int config3;
  413. config3 = read_c0_config3();
  414. if (config3 & MIPS_CONF3_SM) {
  415. c->ases |= MIPS_ASE_SMARTMIPS;
  416. c->options |= MIPS_CPU_RIXI;
  417. }
  418. if (config3 & MIPS_CONF3_RXI)
  419. c->options |= MIPS_CPU_RIXI;
  420. if (config3 & MIPS_CONF3_DSP)
  421. c->ases |= MIPS_ASE_DSP;
  422. if (config3 & MIPS_CONF3_DSP2P)
  423. c->ases |= MIPS_ASE_DSP2P;
  424. if (config3 & MIPS_CONF3_VINT)
  425. c->options |= MIPS_CPU_VINT;
  426. if (config3 & MIPS_CONF3_VEIC)
  427. c->options |= MIPS_CPU_VEIC;
  428. if (config3 & MIPS_CONF3_MT)
  429. c->ases |= MIPS_ASE_MIPSMT;
  430. if (config3 & MIPS_CONF3_ULRI)
  431. c->options |= MIPS_CPU_ULRI;
  432. if (config3 & MIPS_CONF3_ISA)
  433. c->options |= MIPS_CPU_MICROMIPS;
  434. if (config3 & MIPS_CONF3_VZ)
  435. c->ases |= MIPS_ASE_VZ;
  436. if (config3 & MIPS_CONF3_SC)
  437. c->options |= MIPS_CPU_SEGMENTS;
  438. if (config3 & MIPS_CONF3_MSA)
  439. c->ases |= MIPS_ASE_MSA;
  440. /* Only tested on 32-bit cores */
  441. if ((config3 & MIPS_CONF3_PW) && config_enabled(CONFIG_32BIT)) {
  442. c->htw_seq = 0;
  443. c->options |= MIPS_CPU_HTW;
  444. }
  445. if (config3 & MIPS_CONF3_CDMM)
  446. c->options |= MIPS_CPU_CDMM;
  447. return config3 & MIPS_CONF_M;
  448. }
  449. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  450. {
  451. unsigned int config4;
  452. unsigned int newcf4;
  453. unsigned int mmuextdef;
  454. unsigned int ftlb_page = MIPS_CONF4_FTLBPAGESIZE;
  455. config4 = read_c0_config4();
  456. if (cpu_has_tlb) {
  457. if (((config4 & MIPS_CONF4_IE) >> 29) == 2)
  458. c->options |= MIPS_CPU_TLBINV;
  459. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  460. switch (mmuextdef) {
  461. case MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT:
  462. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  463. c->tlbsizevtlb = c->tlbsize;
  464. break;
  465. case MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT:
  466. c->tlbsizevtlb +=
  467. ((config4 & MIPS_CONF4_VTLBSIZEEXT) >>
  468. MIPS_CONF4_VTLBSIZEEXT_SHIFT) * 0x40;
  469. c->tlbsize = c->tlbsizevtlb;
  470. ftlb_page = MIPS_CONF4_VFTLBPAGESIZE;
  471. /* fall through */
  472. case MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT:
  473. if (mips_ftlb_disabled)
  474. break;
  475. newcf4 = (config4 & ~ftlb_page) |
  476. (page_size_ftlb(mmuextdef) <<
  477. MIPS_CONF4_FTLBPAGESIZE_SHIFT);
  478. write_c0_config4(newcf4);
  479. back_to_back_c0_hazard();
  480. config4 = read_c0_config4();
  481. if (config4 != newcf4) {
  482. pr_err("PAGE_SIZE 0x%lx is not supported by FTLB (config4=0x%x)\n",
  483. PAGE_SIZE, config4);
  484. /* Switch FTLB off */
  485. set_ftlb_enable(c, 0);
  486. break;
  487. }
  488. c->tlbsizeftlbsets = 1 <<
  489. ((config4 & MIPS_CONF4_FTLBSETS) >>
  490. MIPS_CONF4_FTLBSETS_SHIFT);
  491. c->tlbsizeftlbways = ((config4 & MIPS_CONF4_FTLBWAYS) >>
  492. MIPS_CONF4_FTLBWAYS_SHIFT) + 2;
  493. c->tlbsize += c->tlbsizeftlbways * c->tlbsizeftlbsets;
  494. mips_has_ftlb_configured = 1;
  495. break;
  496. }
  497. }
  498. c->kscratch_mask = (config4 >> 16) & 0xff;
  499. return config4 & MIPS_CONF_M;
  500. }
  501. static inline unsigned int decode_config5(struct cpuinfo_mips *c)
  502. {
  503. unsigned int config5;
  504. config5 = read_c0_config5();
  505. config5 &= ~(MIPS_CONF5_UFR | MIPS_CONF5_UFE);
  506. write_c0_config5(config5);
  507. if (config5 & MIPS_CONF5_EVA)
  508. c->options |= MIPS_CPU_EVA;
  509. if (config5 & MIPS_CONF5_MRP)
  510. c->options |= MIPS_CPU_MAAR;
  511. if (config5 & MIPS_CONF5_LLB)
  512. c->options |= MIPS_CPU_RW_LLB;
  513. #ifdef CONFIG_XPA
  514. if (config5 & MIPS_CONF5_MVH)
  515. c->options |= MIPS_CPU_XPA;
  516. #endif
  517. return config5 & MIPS_CONF_M;
  518. }
  519. static void decode_configs(struct cpuinfo_mips *c)
  520. {
  521. int ok;
  522. /* MIPS32 or MIPS64 compliant CPU. */
  523. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  524. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  525. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  526. /* Enable FTLB if present and not disabled */
  527. set_ftlb_enable(c, !mips_ftlb_disabled);
  528. ok = decode_config0(c); /* Read Config registers. */
  529. BUG_ON(!ok); /* Arch spec violation! */
  530. if (ok)
  531. ok = decode_config1(c);
  532. if (ok)
  533. ok = decode_config2(c);
  534. if (ok)
  535. ok = decode_config3(c);
  536. if (ok)
  537. ok = decode_config4(c);
  538. if (ok)
  539. ok = decode_config5(c);
  540. mips_probe_watch_registers(c);
  541. if (cpu_has_rixi) {
  542. /* Enable the RIXI exceptions */
  543. set_c0_pagegrain(PG_IEC);
  544. back_to_back_c0_hazard();
  545. /* Verify the IEC bit is set */
  546. if (read_c0_pagegrain() & PG_IEC)
  547. c->options |= MIPS_CPU_RIXIEX;
  548. }
  549. #ifndef CONFIG_MIPS_CPS
  550. if (cpu_has_mips_r2_r6) {
  551. c->core = get_ebase_cpunum();
  552. if (cpu_has_mipsmt)
  553. c->core >>= fls(core_nvpes()) - 1;
  554. }
  555. #endif
  556. }
  557. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  558. | MIPS_CPU_COUNTER)
  559. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  560. {
  561. switch (c->processor_id & PRID_IMP_MASK) {
  562. case PRID_IMP_R2000:
  563. c->cputype = CPU_R2000;
  564. __cpu_name[cpu] = "R2000";
  565. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  566. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  567. MIPS_CPU_NOFPUEX;
  568. if (__cpu_has_fpu())
  569. c->options |= MIPS_CPU_FPU;
  570. c->tlbsize = 64;
  571. break;
  572. case PRID_IMP_R3000:
  573. if ((c->processor_id & PRID_REV_MASK) == PRID_REV_R3000A) {
  574. if (cpu_has_confreg()) {
  575. c->cputype = CPU_R3081E;
  576. __cpu_name[cpu] = "R3081";
  577. } else {
  578. c->cputype = CPU_R3000A;
  579. __cpu_name[cpu] = "R3000A";
  580. }
  581. } else {
  582. c->cputype = CPU_R3000;
  583. __cpu_name[cpu] = "R3000";
  584. }
  585. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  586. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  587. MIPS_CPU_NOFPUEX;
  588. if (__cpu_has_fpu())
  589. c->options |= MIPS_CPU_FPU;
  590. c->tlbsize = 64;
  591. break;
  592. case PRID_IMP_R4000:
  593. if (read_c0_config() & CONF_SC) {
  594. if ((c->processor_id & PRID_REV_MASK) >=
  595. PRID_REV_R4400) {
  596. c->cputype = CPU_R4400PC;
  597. __cpu_name[cpu] = "R4400PC";
  598. } else {
  599. c->cputype = CPU_R4000PC;
  600. __cpu_name[cpu] = "R4000PC";
  601. }
  602. } else {
  603. int cca = read_c0_config() & CONF_CM_CMASK;
  604. int mc;
  605. /*
  606. * SC and MC versions can't be reliably told apart,
  607. * but only the latter support coherent caching
  608. * modes so assume the firmware has set the KSEG0
  609. * coherency attribute reasonably (if uncached, we
  610. * assume SC).
  611. */
  612. switch (cca) {
  613. case CONF_CM_CACHABLE_CE:
  614. case CONF_CM_CACHABLE_COW:
  615. case CONF_CM_CACHABLE_CUW:
  616. mc = 1;
  617. break;
  618. default:
  619. mc = 0;
  620. break;
  621. }
  622. if ((c->processor_id & PRID_REV_MASK) >=
  623. PRID_REV_R4400) {
  624. c->cputype = mc ? CPU_R4400MC : CPU_R4400SC;
  625. __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC";
  626. } else {
  627. c->cputype = mc ? CPU_R4000MC : CPU_R4000SC;
  628. __cpu_name[cpu] = mc ? "R4000MC" : "R4000SC";
  629. }
  630. }
  631. set_isa(c, MIPS_CPU_ISA_III);
  632. c->fpu_msk31 |= FPU_CSR_CONDX;
  633. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  634. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  635. MIPS_CPU_LLSC;
  636. c->tlbsize = 48;
  637. break;
  638. case PRID_IMP_VR41XX:
  639. set_isa(c, MIPS_CPU_ISA_III);
  640. c->fpu_msk31 |= FPU_CSR_CONDX;
  641. c->options = R4K_OPTS;
  642. c->tlbsize = 32;
  643. switch (c->processor_id & 0xf0) {
  644. case PRID_REV_VR4111:
  645. c->cputype = CPU_VR4111;
  646. __cpu_name[cpu] = "NEC VR4111";
  647. break;
  648. case PRID_REV_VR4121:
  649. c->cputype = CPU_VR4121;
  650. __cpu_name[cpu] = "NEC VR4121";
  651. break;
  652. case PRID_REV_VR4122:
  653. if ((c->processor_id & 0xf) < 0x3) {
  654. c->cputype = CPU_VR4122;
  655. __cpu_name[cpu] = "NEC VR4122";
  656. } else {
  657. c->cputype = CPU_VR4181A;
  658. __cpu_name[cpu] = "NEC VR4181A";
  659. }
  660. break;
  661. case PRID_REV_VR4130:
  662. if ((c->processor_id & 0xf) < 0x4) {
  663. c->cputype = CPU_VR4131;
  664. __cpu_name[cpu] = "NEC VR4131";
  665. } else {
  666. c->cputype = CPU_VR4133;
  667. c->options |= MIPS_CPU_LLSC;
  668. __cpu_name[cpu] = "NEC VR4133";
  669. }
  670. break;
  671. default:
  672. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  673. c->cputype = CPU_VR41XX;
  674. __cpu_name[cpu] = "NEC Vr41xx";
  675. break;
  676. }
  677. break;
  678. case PRID_IMP_R4300:
  679. c->cputype = CPU_R4300;
  680. __cpu_name[cpu] = "R4300";
  681. set_isa(c, MIPS_CPU_ISA_III);
  682. c->fpu_msk31 |= FPU_CSR_CONDX;
  683. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  684. MIPS_CPU_LLSC;
  685. c->tlbsize = 32;
  686. break;
  687. case PRID_IMP_R4600:
  688. c->cputype = CPU_R4600;
  689. __cpu_name[cpu] = "R4600";
  690. set_isa(c, MIPS_CPU_ISA_III);
  691. c->fpu_msk31 |= FPU_CSR_CONDX;
  692. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  693. MIPS_CPU_LLSC;
  694. c->tlbsize = 48;
  695. break;
  696. #if 0
  697. case PRID_IMP_R4650:
  698. /*
  699. * This processor doesn't have an MMU, so it's not
  700. * "real easy" to run Linux on it. It is left purely
  701. * for documentation. Commented out because it shares
  702. * it's c0_prid id number with the TX3900.
  703. */
  704. c->cputype = CPU_R4650;
  705. __cpu_name[cpu] = "R4650";
  706. set_isa(c, MIPS_CPU_ISA_III);
  707. c->fpu_msk31 |= FPU_CSR_CONDX;
  708. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  709. c->tlbsize = 48;
  710. break;
  711. #endif
  712. case PRID_IMP_TX39:
  713. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  714. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  715. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  716. c->cputype = CPU_TX3927;
  717. __cpu_name[cpu] = "TX3927";
  718. c->tlbsize = 64;
  719. } else {
  720. switch (c->processor_id & PRID_REV_MASK) {
  721. case PRID_REV_TX3912:
  722. c->cputype = CPU_TX3912;
  723. __cpu_name[cpu] = "TX3912";
  724. c->tlbsize = 32;
  725. break;
  726. case PRID_REV_TX3922:
  727. c->cputype = CPU_TX3922;
  728. __cpu_name[cpu] = "TX3922";
  729. c->tlbsize = 64;
  730. break;
  731. }
  732. }
  733. break;
  734. case PRID_IMP_R4700:
  735. c->cputype = CPU_R4700;
  736. __cpu_name[cpu] = "R4700";
  737. set_isa(c, MIPS_CPU_ISA_III);
  738. c->fpu_msk31 |= FPU_CSR_CONDX;
  739. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  740. MIPS_CPU_LLSC;
  741. c->tlbsize = 48;
  742. break;
  743. case PRID_IMP_TX49:
  744. c->cputype = CPU_TX49XX;
  745. __cpu_name[cpu] = "R49XX";
  746. set_isa(c, MIPS_CPU_ISA_III);
  747. c->fpu_msk31 |= FPU_CSR_CONDX;
  748. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  749. if (!(c->processor_id & 0x08))
  750. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  751. c->tlbsize = 48;
  752. break;
  753. case PRID_IMP_R5000:
  754. c->cputype = CPU_R5000;
  755. __cpu_name[cpu] = "R5000";
  756. set_isa(c, MIPS_CPU_ISA_IV);
  757. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  758. MIPS_CPU_LLSC;
  759. c->tlbsize = 48;
  760. break;
  761. case PRID_IMP_R5432:
  762. c->cputype = CPU_R5432;
  763. __cpu_name[cpu] = "R5432";
  764. set_isa(c, MIPS_CPU_ISA_IV);
  765. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  766. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  767. c->tlbsize = 48;
  768. break;
  769. case PRID_IMP_R5500:
  770. c->cputype = CPU_R5500;
  771. __cpu_name[cpu] = "R5500";
  772. set_isa(c, MIPS_CPU_ISA_IV);
  773. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  774. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  775. c->tlbsize = 48;
  776. break;
  777. case PRID_IMP_NEVADA:
  778. c->cputype = CPU_NEVADA;
  779. __cpu_name[cpu] = "Nevada";
  780. set_isa(c, MIPS_CPU_ISA_IV);
  781. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  782. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  783. c->tlbsize = 48;
  784. break;
  785. case PRID_IMP_R6000:
  786. c->cputype = CPU_R6000;
  787. __cpu_name[cpu] = "R6000";
  788. set_isa(c, MIPS_CPU_ISA_II);
  789. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  790. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  791. MIPS_CPU_LLSC;
  792. c->tlbsize = 32;
  793. break;
  794. case PRID_IMP_R6000A:
  795. c->cputype = CPU_R6000A;
  796. __cpu_name[cpu] = "R6000A";
  797. set_isa(c, MIPS_CPU_ISA_II);
  798. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  799. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  800. MIPS_CPU_LLSC;
  801. c->tlbsize = 32;
  802. break;
  803. case PRID_IMP_RM7000:
  804. c->cputype = CPU_RM7000;
  805. __cpu_name[cpu] = "RM7000";
  806. set_isa(c, MIPS_CPU_ISA_IV);
  807. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  808. MIPS_CPU_LLSC;
  809. /*
  810. * Undocumented RM7000: Bit 29 in the info register of
  811. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  812. * entries.
  813. *
  814. * 29 1 => 64 entry JTLB
  815. * 0 => 48 entry JTLB
  816. */
  817. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  818. break;
  819. case PRID_IMP_R8000:
  820. c->cputype = CPU_R8000;
  821. __cpu_name[cpu] = "RM8000";
  822. set_isa(c, MIPS_CPU_ISA_IV);
  823. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  824. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  825. MIPS_CPU_LLSC;
  826. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  827. break;
  828. case PRID_IMP_R10000:
  829. c->cputype = CPU_R10000;
  830. __cpu_name[cpu] = "R10000";
  831. set_isa(c, MIPS_CPU_ISA_IV);
  832. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  833. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  834. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  835. MIPS_CPU_LLSC;
  836. c->tlbsize = 64;
  837. break;
  838. case PRID_IMP_R12000:
  839. c->cputype = CPU_R12000;
  840. __cpu_name[cpu] = "R12000";
  841. set_isa(c, MIPS_CPU_ISA_IV);
  842. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  843. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  844. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  845. MIPS_CPU_LLSC;
  846. c->tlbsize = 64;
  847. break;
  848. case PRID_IMP_R14000:
  849. if (((c->processor_id >> 4) & 0x0f) > 2) {
  850. c->cputype = CPU_R16000;
  851. __cpu_name[cpu] = "R16000";
  852. } else {
  853. c->cputype = CPU_R14000;
  854. __cpu_name[cpu] = "R14000";
  855. }
  856. set_isa(c, MIPS_CPU_ISA_IV);
  857. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  858. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  859. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  860. MIPS_CPU_LLSC;
  861. c->tlbsize = 64;
  862. break;
  863. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  864. switch (c->processor_id & PRID_REV_MASK) {
  865. case PRID_REV_LOONGSON2E:
  866. c->cputype = CPU_LOONGSON2;
  867. __cpu_name[cpu] = "ICT Loongson-2";
  868. set_elf_platform(cpu, "loongson2e");
  869. set_isa(c, MIPS_CPU_ISA_III);
  870. c->fpu_msk31 |= FPU_CSR_CONDX;
  871. break;
  872. case PRID_REV_LOONGSON2F:
  873. c->cputype = CPU_LOONGSON2;
  874. __cpu_name[cpu] = "ICT Loongson-2";
  875. set_elf_platform(cpu, "loongson2f");
  876. set_isa(c, MIPS_CPU_ISA_III);
  877. c->fpu_msk31 |= FPU_CSR_CONDX;
  878. break;
  879. case PRID_REV_LOONGSON3A:
  880. c->cputype = CPU_LOONGSON3;
  881. __cpu_name[cpu] = "ICT Loongson-3";
  882. set_elf_platform(cpu, "loongson3a");
  883. set_isa(c, MIPS_CPU_ISA_M64R1);
  884. break;
  885. case PRID_REV_LOONGSON3B_R1:
  886. case PRID_REV_LOONGSON3B_R2:
  887. c->cputype = CPU_LOONGSON3;
  888. __cpu_name[cpu] = "ICT Loongson-3";
  889. set_elf_platform(cpu, "loongson3b");
  890. set_isa(c, MIPS_CPU_ISA_M64R1);
  891. break;
  892. }
  893. c->options = R4K_OPTS |
  894. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  895. MIPS_CPU_32FPR;
  896. c->tlbsize = 64;
  897. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  898. break;
  899. case PRID_IMP_LOONGSON_32: /* Loongson-1 */
  900. decode_configs(c);
  901. c->cputype = CPU_LOONGSON1;
  902. switch (c->processor_id & PRID_REV_MASK) {
  903. case PRID_REV_LOONGSON1B:
  904. __cpu_name[cpu] = "Loongson 1B";
  905. break;
  906. }
  907. break;
  908. }
  909. }
  910. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  911. {
  912. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  913. switch (c->processor_id & PRID_IMP_MASK) {
  914. case PRID_IMP_QEMU_GENERIC:
  915. c->writecombine = _CACHE_UNCACHED;
  916. c->cputype = CPU_QEMU_GENERIC;
  917. __cpu_name[cpu] = "MIPS GENERIC QEMU";
  918. break;
  919. case PRID_IMP_4KC:
  920. c->cputype = CPU_4KC;
  921. c->writecombine = _CACHE_UNCACHED;
  922. __cpu_name[cpu] = "MIPS 4Kc";
  923. break;
  924. case PRID_IMP_4KEC:
  925. case PRID_IMP_4KECR2:
  926. c->cputype = CPU_4KEC;
  927. c->writecombine = _CACHE_UNCACHED;
  928. __cpu_name[cpu] = "MIPS 4KEc";
  929. break;
  930. case PRID_IMP_4KSC:
  931. case PRID_IMP_4KSD:
  932. c->cputype = CPU_4KSC;
  933. c->writecombine = _CACHE_UNCACHED;
  934. __cpu_name[cpu] = "MIPS 4KSc";
  935. break;
  936. case PRID_IMP_5KC:
  937. c->cputype = CPU_5KC;
  938. c->writecombine = _CACHE_UNCACHED;
  939. __cpu_name[cpu] = "MIPS 5Kc";
  940. break;
  941. case PRID_IMP_5KE:
  942. c->cputype = CPU_5KE;
  943. c->writecombine = _CACHE_UNCACHED;
  944. __cpu_name[cpu] = "MIPS 5KE";
  945. break;
  946. case PRID_IMP_20KC:
  947. c->cputype = CPU_20KC;
  948. c->writecombine = _CACHE_UNCACHED;
  949. __cpu_name[cpu] = "MIPS 20Kc";
  950. break;
  951. case PRID_IMP_24K:
  952. c->cputype = CPU_24K;
  953. c->writecombine = _CACHE_UNCACHED;
  954. __cpu_name[cpu] = "MIPS 24Kc";
  955. break;
  956. case PRID_IMP_24KE:
  957. c->cputype = CPU_24K;
  958. c->writecombine = _CACHE_UNCACHED;
  959. __cpu_name[cpu] = "MIPS 24KEc";
  960. break;
  961. case PRID_IMP_25KF:
  962. c->cputype = CPU_25KF;
  963. c->writecombine = _CACHE_UNCACHED;
  964. __cpu_name[cpu] = "MIPS 25Kc";
  965. break;
  966. case PRID_IMP_34K:
  967. c->cputype = CPU_34K;
  968. c->writecombine = _CACHE_UNCACHED;
  969. __cpu_name[cpu] = "MIPS 34Kc";
  970. break;
  971. case PRID_IMP_74K:
  972. c->cputype = CPU_74K;
  973. c->writecombine = _CACHE_UNCACHED;
  974. __cpu_name[cpu] = "MIPS 74Kc";
  975. break;
  976. case PRID_IMP_M14KC:
  977. c->cputype = CPU_M14KC;
  978. c->writecombine = _CACHE_UNCACHED;
  979. __cpu_name[cpu] = "MIPS M14Kc";
  980. break;
  981. case PRID_IMP_M14KEC:
  982. c->cputype = CPU_M14KEC;
  983. c->writecombine = _CACHE_UNCACHED;
  984. __cpu_name[cpu] = "MIPS M14KEc";
  985. break;
  986. case PRID_IMP_1004K:
  987. c->cputype = CPU_1004K;
  988. c->writecombine = _CACHE_UNCACHED;
  989. __cpu_name[cpu] = "MIPS 1004Kc";
  990. break;
  991. case PRID_IMP_1074K:
  992. c->cputype = CPU_1074K;
  993. c->writecombine = _CACHE_UNCACHED;
  994. __cpu_name[cpu] = "MIPS 1074Kc";
  995. break;
  996. case PRID_IMP_INTERAPTIV_UP:
  997. c->cputype = CPU_INTERAPTIV;
  998. __cpu_name[cpu] = "MIPS interAptiv";
  999. break;
  1000. case PRID_IMP_INTERAPTIV_MP:
  1001. c->cputype = CPU_INTERAPTIV;
  1002. __cpu_name[cpu] = "MIPS interAptiv (multi)";
  1003. break;
  1004. case PRID_IMP_PROAPTIV_UP:
  1005. c->cputype = CPU_PROAPTIV;
  1006. __cpu_name[cpu] = "MIPS proAptiv";
  1007. break;
  1008. case PRID_IMP_PROAPTIV_MP:
  1009. c->cputype = CPU_PROAPTIV;
  1010. __cpu_name[cpu] = "MIPS proAptiv (multi)";
  1011. break;
  1012. case PRID_IMP_P5600:
  1013. c->cputype = CPU_P5600;
  1014. __cpu_name[cpu] = "MIPS P5600";
  1015. break;
  1016. case PRID_IMP_M5150:
  1017. c->cputype = CPU_M5150;
  1018. __cpu_name[cpu] = "MIPS M5150";
  1019. break;
  1020. }
  1021. decode_configs(c);
  1022. spram_config();
  1023. }
  1024. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  1025. {
  1026. decode_configs(c);
  1027. switch (c->processor_id & PRID_IMP_MASK) {
  1028. case PRID_IMP_AU1_REV1:
  1029. case PRID_IMP_AU1_REV2:
  1030. c->cputype = CPU_ALCHEMY;
  1031. switch ((c->processor_id >> 24) & 0xff) {
  1032. case 0:
  1033. __cpu_name[cpu] = "Au1000";
  1034. break;
  1035. case 1:
  1036. __cpu_name[cpu] = "Au1500";
  1037. break;
  1038. case 2:
  1039. __cpu_name[cpu] = "Au1100";
  1040. break;
  1041. case 3:
  1042. __cpu_name[cpu] = "Au1550";
  1043. break;
  1044. case 4:
  1045. __cpu_name[cpu] = "Au1200";
  1046. if ((c->processor_id & PRID_REV_MASK) == 2)
  1047. __cpu_name[cpu] = "Au1250";
  1048. break;
  1049. case 5:
  1050. __cpu_name[cpu] = "Au1210";
  1051. break;
  1052. default:
  1053. __cpu_name[cpu] = "Au1xxx";
  1054. break;
  1055. }
  1056. break;
  1057. }
  1058. }
  1059. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  1060. {
  1061. decode_configs(c);
  1062. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1063. switch (c->processor_id & PRID_IMP_MASK) {
  1064. case PRID_IMP_SB1:
  1065. c->cputype = CPU_SB1;
  1066. __cpu_name[cpu] = "SiByte SB1";
  1067. /* FPU in pass1 is known to have issues. */
  1068. if ((c->processor_id & PRID_REV_MASK) < 0x02)
  1069. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  1070. break;
  1071. case PRID_IMP_SB1A:
  1072. c->cputype = CPU_SB1A;
  1073. __cpu_name[cpu] = "SiByte SB1A";
  1074. break;
  1075. }
  1076. }
  1077. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  1078. {
  1079. decode_configs(c);
  1080. switch (c->processor_id & PRID_IMP_MASK) {
  1081. case PRID_IMP_SR71000:
  1082. c->cputype = CPU_SR71000;
  1083. __cpu_name[cpu] = "Sandcraft SR71000";
  1084. c->scache.ways = 8;
  1085. c->tlbsize = 64;
  1086. break;
  1087. }
  1088. }
  1089. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  1090. {
  1091. decode_configs(c);
  1092. switch (c->processor_id & PRID_IMP_MASK) {
  1093. case PRID_IMP_PR4450:
  1094. c->cputype = CPU_PR4450;
  1095. __cpu_name[cpu] = "Philips PR4450";
  1096. set_isa(c, MIPS_CPU_ISA_M32R1);
  1097. break;
  1098. }
  1099. }
  1100. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  1101. {
  1102. decode_configs(c);
  1103. switch (c->processor_id & PRID_IMP_MASK) {
  1104. case PRID_IMP_BMIPS32_REV4:
  1105. case PRID_IMP_BMIPS32_REV8:
  1106. c->cputype = CPU_BMIPS32;
  1107. __cpu_name[cpu] = "Broadcom BMIPS32";
  1108. set_elf_platform(cpu, "bmips32");
  1109. break;
  1110. case PRID_IMP_BMIPS3300:
  1111. case PRID_IMP_BMIPS3300_ALT:
  1112. case PRID_IMP_BMIPS3300_BUG:
  1113. c->cputype = CPU_BMIPS3300;
  1114. __cpu_name[cpu] = "Broadcom BMIPS3300";
  1115. set_elf_platform(cpu, "bmips3300");
  1116. break;
  1117. case PRID_IMP_BMIPS43XX: {
  1118. int rev = c->processor_id & PRID_REV_MASK;
  1119. if (rev >= PRID_REV_BMIPS4380_LO &&
  1120. rev <= PRID_REV_BMIPS4380_HI) {
  1121. c->cputype = CPU_BMIPS4380;
  1122. __cpu_name[cpu] = "Broadcom BMIPS4380";
  1123. set_elf_platform(cpu, "bmips4380");
  1124. } else {
  1125. c->cputype = CPU_BMIPS4350;
  1126. __cpu_name[cpu] = "Broadcom BMIPS4350";
  1127. set_elf_platform(cpu, "bmips4350");
  1128. }
  1129. break;
  1130. }
  1131. case PRID_IMP_BMIPS5000:
  1132. case PRID_IMP_BMIPS5200:
  1133. c->cputype = CPU_BMIPS5000;
  1134. __cpu_name[cpu] = "Broadcom BMIPS5000";
  1135. set_elf_platform(cpu, "bmips5000");
  1136. c->options |= MIPS_CPU_ULRI;
  1137. break;
  1138. }
  1139. }
  1140. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  1141. {
  1142. decode_configs(c);
  1143. switch (c->processor_id & PRID_IMP_MASK) {
  1144. case PRID_IMP_CAVIUM_CN38XX:
  1145. case PRID_IMP_CAVIUM_CN31XX:
  1146. case PRID_IMP_CAVIUM_CN30XX:
  1147. c->cputype = CPU_CAVIUM_OCTEON;
  1148. __cpu_name[cpu] = "Cavium Octeon";
  1149. goto platform;
  1150. case PRID_IMP_CAVIUM_CN58XX:
  1151. case PRID_IMP_CAVIUM_CN56XX:
  1152. case PRID_IMP_CAVIUM_CN50XX:
  1153. case PRID_IMP_CAVIUM_CN52XX:
  1154. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  1155. __cpu_name[cpu] = "Cavium Octeon+";
  1156. platform:
  1157. set_elf_platform(cpu, "octeon");
  1158. break;
  1159. case PRID_IMP_CAVIUM_CN61XX:
  1160. case PRID_IMP_CAVIUM_CN63XX:
  1161. case PRID_IMP_CAVIUM_CN66XX:
  1162. case PRID_IMP_CAVIUM_CN68XX:
  1163. case PRID_IMP_CAVIUM_CNF71XX:
  1164. c->cputype = CPU_CAVIUM_OCTEON2;
  1165. __cpu_name[cpu] = "Cavium Octeon II";
  1166. set_elf_platform(cpu, "octeon2");
  1167. break;
  1168. case PRID_IMP_CAVIUM_CN70XX:
  1169. case PRID_IMP_CAVIUM_CN78XX:
  1170. c->cputype = CPU_CAVIUM_OCTEON3;
  1171. __cpu_name[cpu] = "Cavium Octeon III";
  1172. set_elf_platform(cpu, "octeon3");
  1173. break;
  1174. default:
  1175. printk(KERN_INFO "Unknown Octeon chip!\n");
  1176. c->cputype = CPU_UNKNOWN;
  1177. break;
  1178. }
  1179. }
  1180. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  1181. {
  1182. decode_configs(c);
  1183. /* JZRISC does not implement the CP0 counter. */
  1184. c->options &= ~MIPS_CPU_COUNTER;
  1185. BUG_ON(!__builtin_constant_p(cpu_has_counter) || cpu_has_counter);
  1186. switch (c->processor_id & PRID_IMP_MASK) {
  1187. case PRID_IMP_JZRISC:
  1188. c->cputype = CPU_JZRISC;
  1189. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1190. __cpu_name[cpu] = "Ingenic JZRISC";
  1191. break;
  1192. default:
  1193. panic("Unknown Ingenic Processor ID!");
  1194. break;
  1195. }
  1196. }
  1197. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  1198. {
  1199. decode_configs(c);
  1200. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_NETLOGIC_AU13XX) {
  1201. c->cputype = CPU_ALCHEMY;
  1202. __cpu_name[cpu] = "Au1300";
  1203. /* following stuff is not for Alchemy */
  1204. return;
  1205. }
  1206. c->options = (MIPS_CPU_TLB |
  1207. MIPS_CPU_4KEX |
  1208. MIPS_CPU_COUNTER |
  1209. MIPS_CPU_DIVEC |
  1210. MIPS_CPU_WATCH |
  1211. MIPS_CPU_EJTAG |
  1212. MIPS_CPU_LLSC);
  1213. switch (c->processor_id & PRID_IMP_MASK) {
  1214. case PRID_IMP_NETLOGIC_XLP2XX:
  1215. case PRID_IMP_NETLOGIC_XLP9XX:
  1216. case PRID_IMP_NETLOGIC_XLP5XX:
  1217. c->cputype = CPU_XLP;
  1218. __cpu_name[cpu] = "Broadcom XLPII";
  1219. break;
  1220. case PRID_IMP_NETLOGIC_XLP8XX:
  1221. case PRID_IMP_NETLOGIC_XLP3XX:
  1222. c->cputype = CPU_XLP;
  1223. __cpu_name[cpu] = "Netlogic XLP";
  1224. break;
  1225. case PRID_IMP_NETLOGIC_XLR732:
  1226. case PRID_IMP_NETLOGIC_XLR716:
  1227. case PRID_IMP_NETLOGIC_XLR532:
  1228. case PRID_IMP_NETLOGIC_XLR308:
  1229. case PRID_IMP_NETLOGIC_XLR532C:
  1230. case PRID_IMP_NETLOGIC_XLR516C:
  1231. case PRID_IMP_NETLOGIC_XLR508C:
  1232. case PRID_IMP_NETLOGIC_XLR308C:
  1233. c->cputype = CPU_XLR;
  1234. __cpu_name[cpu] = "Netlogic XLR";
  1235. break;
  1236. case PRID_IMP_NETLOGIC_XLS608:
  1237. case PRID_IMP_NETLOGIC_XLS408:
  1238. case PRID_IMP_NETLOGIC_XLS404:
  1239. case PRID_IMP_NETLOGIC_XLS208:
  1240. case PRID_IMP_NETLOGIC_XLS204:
  1241. case PRID_IMP_NETLOGIC_XLS108:
  1242. case PRID_IMP_NETLOGIC_XLS104:
  1243. case PRID_IMP_NETLOGIC_XLS616B:
  1244. case PRID_IMP_NETLOGIC_XLS608B:
  1245. case PRID_IMP_NETLOGIC_XLS416B:
  1246. case PRID_IMP_NETLOGIC_XLS412B:
  1247. case PRID_IMP_NETLOGIC_XLS408B:
  1248. case PRID_IMP_NETLOGIC_XLS404B:
  1249. c->cputype = CPU_XLR;
  1250. __cpu_name[cpu] = "Netlogic XLS";
  1251. break;
  1252. default:
  1253. pr_info("Unknown Netlogic chip id [%02x]!\n",
  1254. c->processor_id);
  1255. c->cputype = CPU_XLR;
  1256. break;
  1257. }
  1258. if (c->cputype == CPU_XLP) {
  1259. set_isa(c, MIPS_CPU_ISA_M64R2);
  1260. c->options |= (MIPS_CPU_FPU | MIPS_CPU_ULRI | MIPS_CPU_MCHECK);
  1261. /* This will be updated again after all threads are woken up */
  1262. c->tlbsize = ((read_c0_config6() >> 16) & 0xffff) + 1;
  1263. } else {
  1264. set_isa(c, MIPS_CPU_ISA_M64R1);
  1265. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  1266. }
  1267. c->kscratch_mask = 0xf;
  1268. }
  1269. #ifdef CONFIG_64BIT
  1270. /* For use by uaccess.h */
  1271. u64 __ua_limit;
  1272. EXPORT_SYMBOL(__ua_limit);
  1273. #endif
  1274. const char *__cpu_name[NR_CPUS];
  1275. const char *__elf_platform;
  1276. void cpu_probe(void)
  1277. {
  1278. struct cpuinfo_mips *c = &current_cpu_data;
  1279. unsigned int cpu = smp_processor_id();
  1280. c->processor_id = PRID_IMP_UNKNOWN;
  1281. c->fpu_id = FPIR_IMP_NONE;
  1282. c->cputype = CPU_UNKNOWN;
  1283. c->writecombine = _CACHE_UNCACHED;
  1284. c->fpu_csr31 = FPU_CSR_RN;
  1285. c->fpu_msk31 = FPU_CSR_RSVD | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  1286. c->processor_id = read_c0_prid();
  1287. switch (c->processor_id & PRID_COMP_MASK) {
  1288. case PRID_COMP_LEGACY:
  1289. cpu_probe_legacy(c, cpu);
  1290. break;
  1291. case PRID_COMP_MIPS:
  1292. cpu_probe_mips(c, cpu);
  1293. break;
  1294. case PRID_COMP_ALCHEMY:
  1295. cpu_probe_alchemy(c, cpu);
  1296. break;
  1297. case PRID_COMP_SIBYTE:
  1298. cpu_probe_sibyte(c, cpu);
  1299. break;
  1300. case PRID_COMP_BROADCOM:
  1301. cpu_probe_broadcom(c, cpu);
  1302. break;
  1303. case PRID_COMP_SANDCRAFT:
  1304. cpu_probe_sandcraft(c, cpu);
  1305. break;
  1306. case PRID_COMP_NXP:
  1307. cpu_probe_nxp(c, cpu);
  1308. break;
  1309. case PRID_COMP_CAVIUM:
  1310. cpu_probe_cavium(c, cpu);
  1311. break;
  1312. case PRID_COMP_INGENIC:
  1313. cpu_probe_ingenic(c, cpu);
  1314. break;
  1315. case PRID_COMP_NETLOGIC:
  1316. cpu_probe_netlogic(c, cpu);
  1317. break;
  1318. }
  1319. BUG_ON(!__cpu_name[cpu]);
  1320. BUG_ON(c->cputype == CPU_UNKNOWN);
  1321. /*
  1322. * Platform code can force the cpu type to optimize code
  1323. * generation. In that case be sure the cpu type is correctly
  1324. * manually setup otherwise it could trigger some nasty bugs.
  1325. */
  1326. BUG_ON(current_cpu_type() != c->cputype);
  1327. if (mips_fpu_disabled)
  1328. c->options &= ~MIPS_CPU_FPU;
  1329. if (mips_dsp_disabled)
  1330. c->ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  1331. if (mips_htw_disabled) {
  1332. c->options &= ~MIPS_CPU_HTW;
  1333. write_c0_pwctl(read_c0_pwctl() &
  1334. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  1335. }
  1336. if (c->options & MIPS_CPU_FPU)
  1337. cpu_set_fpu_opts(c);
  1338. else
  1339. cpu_set_nofpu_opts(c);
  1340. if (cpu_has_mips_r2_r6) {
  1341. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1342. /* R2 has Performance Counter Interrupt indicator */
  1343. c->options |= MIPS_CPU_PCI;
  1344. }
  1345. else
  1346. c->srsets = 1;
  1347. if (cpu_has_msa) {
  1348. c->msa_id = cpu_get_msa_id();
  1349. WARN(c->msa_id & MSA_IR_WRPF,
  1350. "Vector register partitioning unimplemented!");
  1351. }
  1352. cpu_probe_vmbits(c);
  1353. #ifdef CONFIG_64BIT
  1354. if (cpu == 0)
  1355. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1356. #endif
  1357. }
  1358. void cpu_report(void)
  1359. {
  1360. struct cpuinfo_mips *c = &current_cpu_data;
  1361. pr_info("CPU%d revision is: %08x (%s)\n",
  1362. smp_processor_id(), c->processor_id, cpu_name_string());
  1363. if (c->options & MIPS_CPU_FPU)
  1364. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1365. if (cpu_has_msa)
  1366. pr_info("MSA revision is: %08x\n", c->msa_id);
  1367. }