cpu-probe.c 38 KB

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