cpu-probe.c 51 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068
  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. * Determine the IEEE 754 NaN encodings and ABS.fmt/NEG.fmt execution modes
  87. * supported by FPU hardware.
  88. */
  89. static void cpu_set_fpu_2008(struct cpuinfo_mips *c)
  90. {
  91. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  92. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  93. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  94. unsigned long sr, fir, fcsr, fcsr0, fcsr1;
  95. sr = read_c0_status();
  96. __enable_fpu(FPU_AS_IS);
  97. fir = read_32bit_cp1_register(CP1_REVISION);
  98. if (fir & MIPS_FPIR_HAS2008) {
  99. fcsr = read_32bit_cp1_register(CP1_STATUS);
  100. fcsr0 = fcsr & ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
  101. write_32bit_cp1_register(CP1_STATUS, fcsr0);
  102. fcsr0 = read_32bit_cp1_register(CP1_STATUS);
  103. fcsr1 = fcsr | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  104. write_32bit_cp1_register(CP1_STATUS, fcsr1);
  105. fcsr1 = read_32bit_cp1_register(CP1_STATUS);
  106. write_32bit_cp1_register(CP1_STATUS, fcsr);
  107. if (!(fcsr0 & FPU_CSR_NAN2008))
  108. c->options |= MIPS_CPU_NAN_LEGACY;
  109. if (fcsr1 & FPU_CSR_NAN2008)
  110. c->options |= MIPS_CPU_NAN_2008;
  111. if ((fcsr0 ^ fcsr1) & FPU_CSR_ABS2008)
  112. c->fpu_msk31 &= ~FPU_CSR_ABS2008;
  113. else
  114. c->fpu_csr31 |= fcsr & FPU_CSR_ABS2008;
  115. if ((fcsr0 ^ fcsr1) & FPU_CSR_NAN2008)
  116. c->fpu_msk31 &= ~FPU_CSR_NAN2008;
  117. else
  118. c->fpu_csr31 |= fcsr & FPU_CSR_NAN2008;
  119. } else {
  120. c->options |= MIPS_CPU_NAN_LEGACY;
  121. }
  122. write_c0_status(sr);
  123. } else {
  124. c->options |= MIPS_CPU_NAN_LEGACY;
  125. }
  126. }
  127. /*
  128. * IEEE 754 conformance mode to use. Affects the NaN encoding and the
  129. * ABS.fmt/NEG.fmt execution mode.
  130. */
  131. static enum { STRICT, LEGACY, STD2008, RELAXED } ieee754 = STRICT;
  132. /*
  133. * Set the IEEE 754 NaN encodings and the ABS.fmt/NEG.fmt execution modes
  134. * to support by the FPU emulator according to the IEEE 754 conformance
  135. * mode selected. Note that "relaxed" straps the emulator so that it
  136. * allows 2008-NaN binaries even for legacy processors.
  137. */
  138. static void cpu_set_nofpu_2008(struct cpuinfo_mips *c)
  139. {
  140. c->options &= ~(MIPS_CPU_NAN_2008 | MIPS_CPU_NAN_LEGACY);
  141. c->fpu_csr31 &= ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
  142. c->fpu_msk31 &= ~(FPU_CSR_ABS2008 | FPU_CSR_NAN2008);
  143. switch (ieee754) {
  144. case STRICT:
  145. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  146. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  147. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  148. c->options |= MIPS_CPU_NAN_2008 | MIPS_CPU_NAN_LEGACY;
  149. } else {
  150. c->options |= MIPS_CPU_NAN_LEGACY;
  151. c->fpu_msk31 |= FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  152. }
  153. break;
  154. case LEGACY:
  155. c->options |= MIPS_CPU_NAN_LEGACY;
  156. c->fpu_msk31 |= FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  157. break;
  158. case STD2008:
  159. c->options |= MIPS_CPU_NAN_2008;
  160. c->fpu_csr31 |= FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  161. c->fpu_msk31 |= FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  162. break;
  163. case RELAXED:
  164. c->options |= MIPS_CPU_NAN_2008 | MIPS_CPU_NAN_LEGACY;
  165. break;
  166. }
  167. }
  168. /*
  169. * Override the IEEE 754 NaN encoding and ABS.fmt/NEG.fmt execution mode
  170. * according to the "ieee754=" parameter.
  171. */
  172. static void cpu_set_nan_2008(struct cpuinfo_mips *c)
  173. {
  174. switch (ieee754) {
  175. case STRICT:
  176. mips_use_nan_legacy = !!cpu_has_nan_legacy;
  177. mips_use_nan_2008 = !!cpu_has_nan_2008;
  178. break;
  179. case LEGACY:
  180. mips_use_nan_legacy = !!cpu_has_nan_legacy;
  181. mips_use_nan_2008 = !cpu_has_nan_legacy;
  182. break;
  183. case STD2008:
  184. mips_use_nan_legacy = !cpu_has_nan_2008;
  185. mips_use_nan_2008 = !!cpu_has_nan_2008;
  186. break;
  187. case RELAXED:
  188. mips_use_nan_legacy = true;
  189. mips_use_nan_2008 = true;
  190. break;
  191. }
  192. }
  193. /*
  194. * IEEE 754 NaN encoding and ABS.fmt/NEG.fmt execution mode override
  195. * settings:
  196. *
  197. * strict: accept binaries that request a NaN encoding supported by the FPU
  198. * legacy: only accept legacy-NaN binaries
  199. * 2008: only accept 2008-NaN binaries
  200. * relaxed: accept any binaries regardless of whether supported by the FPU
  201. */
  202. static int __init ieee754_setup(char *s)
  203. {
  204. if (!s)
  205. return -1;
  206. else if (!strcmp(s, "strict"))
  207. ieee754 = STRICT;
  208. else if (!strcmp(s, "legacy"))
  209. ieee754 = LEGACY;
  210. else if (!strcmp(s, "2008"))
  211. ieee754 = STD2008;
  212. else if (!strcmp(s, "relaxed"))
  213. ieee754 = RELAXED;
  214. else
  215. return -1;
  216. if (!(boot_cpu_data.options & MIPS_CPU_FPU))
  217. cpu_set_nofpu_2008(&boot_cpu_data);
  218. cpu_set_nan_2008(&boot_cpu_data);
  219. return 0;
  220. }
  221. early_param("ieee754", ieee754_setup);
  222. /*
  223. * Set the FIR feature flags for the FPU emulator.
  224. */
  225. static void cpu_set_nofpu_id(struct cpuinfo_mips *c)
  226. {
  227. u32 value;
  228. value = 0;
  229. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  230. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  231. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6))
  232. value |= MIPS_FPIR_D | MIPS_FPIR_S;
  233. if (c->isa_level & (MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  234. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6))
  235. value |= MIPS_FPIR_F64 | MIPS_FPIR_L | MIPS_FPIR_W;
  236. if (c->options & MIPS_CPU_NAN_2008)
  237. value |= MIPS_FPIR_HAS2008;
  238. c->fpu_id = value;
  239. }
  240. /* Determined FPU emulator mask to use for the boot CPU with "nofpu". */
  241. static unsigned int mips_nofpu_msk31;
  242. /*
  243. * Set options for FPU hardware.
  244. */
  245. static void cpu_set_fpu_opts(struct cpuinfo_mips *c)
  246. {
  247. c->fpu_id = cpu_get_fpu_id();
  248. mips_nofpu_msk31 = c->fpu_msk31;
  249. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  250. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  251. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  252. if (c->fpu_id & MIPS_FPIR_3D)
  253. c->ases |= MIPS_ASE_MIPS3D;
  254. if (c->fpu_id & MIPS_FPIR_FREP)
  255. c->options |= MIPS_CPU_FRE;
  256. }
  257. cpu_set_fpu_fcsr_mask(c);
  258. cpu_set_fpu_2008(c);
  259. cpu_set_nan_2008(c);
  260. }
  261. /*
  262. * Set options for the FPU emulator.
  263. */
  264. static void cpu_set_nofpu_opts(struct cpuinfo_mips *c)
  265. {
  266. c->options &= ~MIPS_CPU_FPU;
  267. c->fpu_msk31 = mips_nofpu_msk31;
  268. cpu_set_nofpu_2008(c);
  269. cpu_set_nan_2008(c);
  270. cpu_set_nofpu_id(c);
  271. }
  272. static int mips_fpu_disabled;
  273. static int __init fpu_disable(char *s)
  274. {
  275. cpu_set_nofpu_opts(&boot_cpu_data);
  276. mips_fpu_disabled = 1;
  277. return 1;
  278. }
  279. __setup("nofpu", fpu_disable);
  280. int mips_dsp_disabled;
  281. static int __init dsp_disable(char *s)
  282. {
  283. cpu_data[0].ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  284. mips_dsp_disabled = 1;
  285. return 1;
  286. }
  287. __setup("nodsp", dsp_disable);
  288. static int mips_htw_disabled;
  289. static int __init htw_disable(char *s)
  290. {
  291. mips_htw_disabled = 1;
  292. cpu_data[0].options &= ~MIPS_CPU_HTW;
  293. write_c0_pwctl(read_c0_pwctl() &
  294. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  295. return 1;
  296. }
  297. __setup("nohtw", htw_disable);
  298. static int mips_ftlb_disabled;
  299. static int mips_has_ftlb_configured;
  300. static int set_ftlb_enable(struct cpuinfo_mips *c, int enable);
  301. static int __init ftlb_disable(char *s)
  302. {
  303. unsigned int config4, mmuextdef;
  304. /*
  305. * If the core hasn't done any FTLB configuration, there is nothing
  306. * for us to do here.
  307. */
  308. if (!mips_has_ftlb_configured)
  309. return 1;
  310. /* Disable it in the boot cpu */
  311. if (set_ftlb_enable(&cpu_data[0], 0)) {
  312. pr_warn("Can't turn FTLB off\n");
  313. return 1;
  314. }
  315. back_to_back_c0_hazard();
  316. config4 = read_c0_config4();
  317. /* Check that FTLB has been disabled */
  318. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  319. /* MMUSIZEEXT == VTLB ON, FTLB OFF */
  320. if (mmuextdef == MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT) {
  321. /* This should never happen */
  322. pr_warn("FTLB could not be disabled!\n");
  323. return 1;
  324. }
  325. mips_ftlb_disabled = 1;
  326. mips_has_ftlb_configured = 0;
  327. /*
  328. * noftlb is mainly used for debug purposes so print
  329. * an informative message instead of using pr_debug()
  330. */
  331. pr_info("FTLB has been disabled\n");
  332. /*
  333. * Some of these bits are duplicated in the decode_config4.
  334. * MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT is the only possible case
  335. * once FTLB has been disabled so undo what decode_config4 did.
  336. */
  337. cpu_data[0].tlbsize -= cpu_data[0].tlbsizeftlbways *
  338. cpu_data[0].tlbsizeftlbsets;
  339. cpu_data[0].tlbsizeftlbsets = 0;
  340. cpu_data[0].tlbsizeftlbways = 0;
  341. return 1;
  342. }
  343. __setup("noftlb", ftlb_disable);
  344. static inline void check_errata(void)
  345. {
  346. struct cpuinfo_mips *c = &current_cpu_data;
  347. switch (current_cpu_type()) {
  348. case CPU_34K:
  349. /*
  350. * Erratum "RPS May Cause Incorrect Instruction Execution"
  351. * This code only handles VPE0, any SMP/RTOS code
  352. * making use of VPE1 will be responsable for that VPE.
  353. */
  354. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  355. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  356. break;
  357. default:
  358. break;
  359. }
  360. }
  361. void __init check_bugs32(void)
  362. {
  363. check_errata();
  364. }
  365. /*
  366. * Probe whether cpu has config register by trying to play with
  367. * alternate cache bit and see whether it matters.
  368. * It's used by cpu_probe to distinguish between R3000A and R3081.
  369. */
  370. static inline int cpu_has_confreg(void)
  371. {
  372. #ifdef CONFIG_CPU_R3000
  373. extern unsigned long r3k_cache_size(unsigned long);
  374. unsigned long size1, size2;
  375. unsigned long cfg = read_c0_conf();
  376. size1 = r3k_cache_size(ST0_ISC);
  377. write_c0_conf(cfg ^ R30XX_CONF_AC);
  378. size2 = r3k_cache_size(ST0_ISC);
  379. write_c0_conf(cfg);
  380. return size1 != size2;
  381. #else
  382. return 0;
  383. #endif
  384. }
  385. static inline void set_elf_platform(int cpu, const char *plat)
  386. {
  387. if (cpu == 0)
  388. __elf_platform = plat;
  389. }
  390. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  391. {
  392. #ifdef __NEED_VMBITS_PROBE
  393. write_c0_entryhi(0x3fffffffffffe000ULL);
  394. back_to_back_c0_hazard();
  395. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  396. #endif
  397. }
  398. static void set_isa(struct cpuinfo_mips *c, unsigned int isa)
  399. {
  400. switch (isa) {
  401. case MIPS_CPU_ISA_M64R2:
  402. c->isa_level |= MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2;
  403. case MIPS_CPU_ISA_M64R1:
  404. c->isa_level |= MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1;
  405. case MIPS_CPU_ISA_V:
  406. c->isa_level |= MIPS_CPU_ISA_V;
  407. case MIPS_CPU_ISA_IV:
  408. c->isa_level |= MIPS_CPU_ISA_IV;
  409. case MIPS_CPU_ISA_III:
  410. c->isa_level |= MIPS_CPU_ISA_II | MIPS_CPU_ISA_III;
  411. break;
  412. /* R6 incompatible with everything else */
  413. case MIPS_CPU_ISA_M64R6:
  414. c->isa_level |= MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6;
  415. case MIPS_CPU_ISA_M32R6:
  416. c->isa_level |= MIPS_CPU_ISA_M32R6;
  417. /* Break here so we don't add incompatible ISAs */
  418. break;
  419. case MIPS_CPU_ISA_M32R2:
  420. c->isa_level |= MIPS_CPU_ISA_M32R2;
  421. case MIPS_CPU_ISA_M32R1:
  422. c->isa_level |= MIPS_CPU_ISA_M32R1;
  423. case MIPS_CPU_ISA_II:
  424. c->isa_level |= MIPS_CPU_ISA_II;
  425. break;
  426. }
  427. }
  428. static char unknown_isa[] = KERN_ERR \
  429. "Unsupported ISA type, c0.config0: %d.";
  430. static unsigned int calculate_ftlb_probability(struct cpuinfo_mips *c)
  431. {
  432. unsigned int probability = c->tlbsize / c->tlbsizevtlb;
  433. /*
  434. * 0 = All TLBWR instructions go to FTLB
  435. * 1 = 15:1: For every 16 TBLWR instructions, 15 go to the
  436. * FTLB and 1 goes to the VTLB.
  437. * 2 = 7:1: As above with 7:1 ratio.
  438. * 3 = 3:1: As above with 3:1 ratio.
  439. *
  440. * Use the linear midpoint as the probability threshold.
  441. */
  442. if (probability >= 12)
  443. return 1;
  444. else if (probability >= 6)
  445. return 2;
  446. else
  447. /*
  448. * So FTLB is less than 4 times bigger than VTLB.
  449. * A 3:1 ratio can still be useful though.
  450. */
  451. return 3;
  452. }
  453. static int set_ftlb_enable(struct cpuinfo_mips *c, int enable)
  454. {
  455. unsigned int config;
  456. /* It's implementation dependent how the FTLB can be enabled */
  457. switch (c->cputype) {
  458. case CPU_PROAPTIV:
  459. case CPU_P5600:
  460. case CPU_P6600:
  461. /* proAptiv & related cores use Config6 to enable the FTLB */
  462. config = read_c0_config6();
  463. /* Clear the old probability value */
  464. config &= ~(3 << MIPS_CONF6_FTLBP_SHIFT);
  465. if (enable)
  466. /* Enable FTLB */
  467. write_c0_config6(config |
  468. (calculate_ftlb_probability(c)
  469. << MIPS_CONF6_FTLBP_SHIFT)
  470. | MIPS_CONF6_FTLBEN);
  471. else
  472. /* Disable FTLB */
  473. write_c0_config6(config & ~MIPS_CONF6_FTLBEN);
  474. break;
  475. case CPU_I6400:
  476. /* I6400 & related cores use Config7 to configure FTLB */
  477. config = read_c0_config7();
  478. /* Clear the old probability value */
  479. config &= ~(3 << MIPS_CONF7_FTLBP_SHIFT);
  480. write_c0_config7(config | (calculate_ftlb_probability(c)
  481. << MIPS_CONF7_FTLBP_SHIFT));
  482. break;
  483. case CPU_LOONGSON3:
  484. /* Flush ITLB, DTLB, VTLB and FTLB */
  485. write_c0_diag(LOONGSON_DIAG_ITLB | LOONGSON_DIAG_DTLB |
  486. LOONGSON_DIAG_VTLB | LOONGSON_DIAG_FTLB);
  487. /* Loongson-3 cores use Config6 to enable the FTLB */
  488. config = read_c0_config6();
  489. if (enable)
  490. /* Enable FTLB */
  491. write_c0_config6(config & ~MIPS_CONF6_FTLBDIS);
  492. else
  493. /* Disable FTLB */
  494. write_c0_config6(config | MIPS_CONF6_FTLBDIS);
  495. break;
  496. default:
  497. return 1;
  498. }
  499. return 0;
  500. }
  501. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  502. {
  503. unsigned int config0;
  504. int isa, mt;
  505. config0 = read_c0_config();
  506. /*
  507. * Look for Standard TLB or Dual VTLB and FTLB
  508. */
  509. mt = config0 & MIPS_CONF_MT;
  510. if (mt == MIPS_CONF_MT_TLB)
  511. c->options |= MIPS_CPU_TLB;
  512. else if (mt == MIPS_CONF_MT_FTLB)
  513. c->options |= MIPS_CPU_TLB | MIPS_CPU_FTLB;
  514. isa = (config0 & MIPS_CONF_AT) >> 13;
  515. switch (isa) {
  516. case 0:
  517. switch ((config0 & MIPS_CONF_AR) >> 10) {
  518. case 0:
  519. set_isa(c, MIPS_CPU_ISA_M32R1);
  520. break;
  521. case 1:
  522. set_isa(c, MIPS_CPU_ISA_M32R2);
  523. break;
  524. case 2:
  525. set_isa(c, MIPS_CPU_ISA_M32R6);
  526. break;
  527. default:
  528. goto unknown;
  529. }
  530. break;
  531. case 2:
  532. switch ((config0 & MIPS_CONF_AR) >> 10) {
  533. case 0:
  534. set_isa(c, MIPS_CPU_ISA_M64R1);
  535. break;
  536. case 1:
  537. set_isa(c, MIPS_CPU_ISA_M64R2);
  538. break;
  539. case 2:
  540. set_isa(c, MIPS_CPU_ISA_M64R6);
  541. break;
  542. default:
  543. goto unknown;
  544. }
  545. break;
  546. default:
  547. goto unknown;
  548. }
  549. return config0 & MIPS_CONF_M;
  550. unknown:
  551. panic(unknown_isa, config0);
  552. }
  553. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  554. {
  555. unsigned int config1;
  556. config1 = read_c0_config1();
  557. if (config1 & MIPS_CONF1_MD)
  558. c->ases |= MIPS_ASE_MDMX;
  559. if (config1 & MIPS_CONF1_PC)
  560. c->options |= MIPS_CPU_PERF;
  561. if (config1 & MIPS_CONF1_WR)
  562. c->options |= MIPS_CPU_WATCH;
  563. if (config1 & MIPS_CONF1_CA)
  564. c->ases |= MIPS_ASE_MIPS16;
  565. if (config1 & MIPS_CONF1_EP)
  566. c->options |= MIPS_CPU_EJTAG;
  567. if (config1 & MIPS_CONF1_FP) {
  568. c->options |= MIPS_CPU_FPU;
  569. c->options |= MIPS_CPU_32FPR;
  570. }
  571. if (cpu_has_tlb) {
  572. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  573. c->tlbsizevtlb = c->tlbsize;
  574. c->tlbsizeftlbsets = 0;
  575. }
  576. return config1 & MIPS_CONF_M;
  577. }
  578. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  579. {
  580. unsigned int config2;
  581. config2 = read_c0_config2();
  582. if (config2 & MIPS_CONF2_SL)
  583. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  584. return config2 & MIPS_CONF_M;
  585. }
  586. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  587. {
  588. unsigned int config3;
  589. config3 = read_c0_config3();
  590. if (config3 & MIPS_CONF3_SM) {
  591. c->ases |= MIPS_ASE_SMARTMIPS;
  592. c->options |= MIPS_CPU_RIXI | MIPS_CPU_CTXTC;
  593. }
  594. if (config3 & MIPS_CONF3_RXI)
  595. c->options |= MIPS_CPU_RIXI;
  596. if (config3 & MIPS_CONF3_CTXTC)
  597. c->options |= MIPS_CPU_CTXTC;
  598. if (config3 & MIPS_CONF3_DSP)
  599. c->ases |= MIPS_ASE_DSP;
  600. if (config3 & MIPS_CONF3_DSP2P) {
  601. c->ases |= MIPS_ASE_DSP2P;
  602. if (cpu_has_mips_r6)
  603. c->ases |= MIPS_ASE_DSP3;
  604. }
  605. if (config3 & MIPS_CONF3_VINT)
  606. c->options |= MIPS_CPU_VINT;
  607. if (config3 & MIPS_CONF3_VEIC)
  608. c->options |= MIPS_CPU_VEIC;
  609. if (config3 & MIPS_CONF3_LPA)
  610. c->options |= MIPS_CPU_LPA;
  611. if (config3 & MIPS_CONF3_MT)
  612. c->ases |= MIPS_ASE_MIPSMT;
  613. if (config3 & MIPS_CONF3_ULRI)
  614. c->options |= MIPS_CPU_ULRI;
  615. if (config3 & MIPS_CONF3_ISA)
  616. c->options |= MIPS_CPU_MICROMIPS;
  617. if (config3 & MIPS_CONF3_VZ)
  618. c->ases |= MIPS_ASE_VZ;
  619. if (config3 & MIPS_CONF3_SC)
  620. c->options |= MIPS_CPU_SEGMENTS;
  621. if (config3 & MIPS_CONF3_BI)
  622. c->options |= MIPS_CPU_BADINSTR;
  623. if (config3 & MIPS_CONF3_BP)
  624. c->options |= MIPS_CPU_BADINSTRP;
  625. if (config3 & MIPS_CONF3_MSA)
  626. c->ases |= MIPS_ASE_MSA;
  627. if (config3 & MIPS_CONF3_PW) {
  628. c->htw_seq = 0;
  629. c->options |= MIPS_CPU_HTW;
  630. }
  631. if (config3 & MIPS_CONF3_CDMM)
  632. c->options |= MIPS_CPU_CDMM;
  633. if (config3 & MIPS_CONF3_SP)
  634. c->options |= MIPS_CPU_SP;
  635. return config3 & MIPS_CONF_M;
  636. }
  637. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  638. {
  639. unsigned int config4;
  640. unsigned int newcf4;
  641. unsigned int mmuextdef;
  642. unsigned int ftlb_page = MIPS_CONF4_FTLBPAGESIZE;
  643. unsigned long asid_mask;
  644. config4 = read_c0_config4();
  645. if (cpu_has_tlb) {
  646. if (((config4 & MIPS_CONF4_IE) >> 29) == 2)
  647. c->options |= MIPS_CPU_TLBINV;
  648. /*
  649. * R6 has dropped the MMUExtDef field from config4.
  650. * On R6 the fields always describe the FTLB, and only if it is
  651. * present according to Config.MT.
  652. */
  653. if (!cpu_has_mips_r6)
  654. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  655. else if (cpu_has_ftlb)
  656. mmuextdef = MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT;
  657. else
  658. mmuextdef = 0;
  659. switch (mmuextdef) {
  660. case MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT:
  661. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  662. c->tlbsizevtlb = c->tlbsize;
  663. break;
  664. case MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT:
  665. c->tlbsizevtlb +=
  666. ((config4 & MIPS_CONF4_VTLBSIZEEXT) >>
  667. MIPS_CONF4_VTLBSIZEEXT_SHIFT) * 0x40;
  668. c->tlbsize = c->tlbsizevtlb;
  669. ftlb_page = MIPS_CONF4_VFTLBPAGESIZE;
  670. /* fall through */
  671. case MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT:
  672. if (mips_ftlb_disabled)
  673. break;
  674. newcf4 = (config4 & ~ftlb_page) |
  675. (page_size_ftlb(mmuextdef) <<
  676. MIPS_CONF4_FTLBPAGESIZE_SHIFT);
  677. write_c0_config4(newcf4);
  678. back_to_back_c0_hazard();
  679. config4 = read_c0_config4();
  680. if (config4 != newcf4) {
  681. pr_err("PAGE_SIZE 0x%lx is not supported by FTLB (config4=0x%x)\n",
  682. PAGE_SIZE, config4);
  683. /* Switch FTLB off */
  684. set_ftlb_enable(c, 0);
  685. break;
  686. }
  687. c->tlbsizeftlbsets = 1 <<
  688. ((config4 & MIPS_CONF4_FTLBSETS) >>
  689. MIPS_CONF4_FTLBSETS_SHIFT);
  690. c->tlbsizeftlbways = ((config4 & MIPS_CONF4_FTLBWAYS) >>
  691. MIPS_CONF4_FTLBWAYS_SHIFT) + 2;
  692. c->tlbsize += c->tlbsizeftlbways * c->tlbsizeftlbsets;
  693. mips_has_ftlb_configured = 1;
  694. break;
  695. }
  696. }
  697. c->kscratch_mask = (config4 & MIPS_CONF4_KSCREXIST)
  698. >> MIPS_CONF4_KSCREXIST_SHIFT;
  699. asid_mask = MIPS_ENTRYHI_ASID;
  700. if (config4 & MIPS_CONF4_AE)
  701. asid_mask |= MIPS_ENTRYHI_ASIDX;
  702. set_cpu_asid_mask(c, asid_mask);
  703. /*
  704. * Warn if the computed ASID mask doesn't match the mask the kernel
  705. * is built for. This may indicate either a serious problem or an
  706. * easy optimisation opportunity, but either way should be addressed.
  707. */
  708. WARN_ON(asid_mask != cpu_asid_mask(c));
  709. return config4 & MIPS_CONF_M;
  710. }
  711. static inline unsigned int decode_config5(struct cpuinfo_mips *c)
  712. {
  713. unsigned int config5;
  714. config5 = read_c0_config5();
  715. config5 &= ~(MIPS_CONF5_UFR | MIPS_CONF5_UFE);
  716. write_c0_config5(config5);
  717. if (config5 & MIPS_CONF5_EVA)
  718. c->options |= MIPS_CPU_EVA;
  719. if (config5 & MIPS_CONF5_MRP)
  720. c->options |= MIPS_CPU_MAAR;
  721. if (config5 & MIPS_CONF5_LLB)
  722. c->options |= MIPS_CPU_RW_LLB;
  723. if (config5 & MIPS_CONF5_MVH)
  724. c->options |= MIPS_CPU_MVH;
  725. if (cpu_has_mips_r6 && (config5 & MIPS_CONF5_VP))
  726. c->options |= MIPS_CPU_VP;
  727. return config5 & MIPS_CONF_M;
  728. }
  729. static void decode_configs(struct cpuinfo_mips *c)
  730. {
  731. int ok;
  732. /* MIPS32 or MIPS64 compliant CPU. */
  733. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  734. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  735. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  736. /* Enable FTLB if present and not disabled */
  737. set_ftlb_enable(c, !mips_ftlb_disabled);
  738. ok = decode_config0(c); /* Read Config registers. */
  739. BUG_ON(!ok); /* Arch spec violation! */
  740. if (ok)
  741. ok = decode_config1(c);
  742. if (ok)
  743. ok = decode_config2(c);
  744. if (ok)
  745. ok = decode_config3(c);
  746. if (ok)
  747. ok = decode_config4(c);
  748. if (ok)
  749. ok = decode_config5(c);
  750. /* Probe the EBase.WG bit */
  751. if (cpu_has_mips_r2_r6) {
  752. u64 ebase;
  753. unsigned int status;
  754. /* {read,write}_c0_ebase_64() may be UNDEFINED prior to r6 */
  755. ebase = cpu_has_mips64r6 ? read_c0_ebase_64()
  756. : (s32)read_c0_ebase();
  757. if (ebase & MIPS_EBASE_WG) {
  758. /* WG bit already set, we can avoid the clumsy probe */
  759. c->options |= MIPS_CPU_EBASE_WG;
  760. } else {
  761. /* Its UNDEFINED to change EBase while BEV=0 */
  762. status = read_c0_status();
  763. write_c0_status(status | ST0_BEV);
  764. irq_enable_hazard();
  765. /*
  766. * On pre-r6 cores, this may well clobber the upper bits
  767. * of EBase. This is hard to avoid without potentially
  768. * hitting UNDEFINED dm*c0 behaviour if EBase is 32-bit.
  769. */
  770. if (cpu_has_mips64r6)
  771. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  772. else
  773. write_c0_ebase(ebase | MIPS_EBASE_WG);
  774. back_to_back_c0_hazard();
  775. /* Restore BEV */
  776. write_c0_status(status);
  777. if (read_c0_ebase() & MIPS_EBASE_WG) {
  778. c->options |= MIPS_CPU_EBASE_WG;
  779. write_c0_ebase(ebase);
  780. }
  781. }
  782. }
  783. mips_probe_watch_registers(c);
  784. #ifndef CONFIG_MIPS_CPS
  785. if (cpu_has_mips_r2_r6) {
  786. c->core = get_ebase_cpunum();
  787. if (cpu_has_mipsmt)
  788. c->core >>= fls(core_nvpes()) - 1;
  789. }
  790. #endif
  791. }
  792. /*
  793. * Probe for certain guest capabilities by writing config bits and reading back.
  794. * Finally write back the original value.
  795. */
  796. #define probe_gc0_config(name, maxconf, bits) \
  797. do { \
  798. unsigned int tmp; \
  799. tmp = read_gc0_##name(); \
  800. write_gc0_##name(tmp | (bits)); \
  801. back_to_back_c0_hazard(); \
  802. maxconf = read_gc0_##name(); \
  803. write_gc0_##name(tmp); \
  804. } while (0)
  805. /*
  806. * Probe for dynamic guest capabilities by changing certain config bits and
  807. * reading back to see if they change. Finally write back the original value.
  808. */
  809. #define probe_gc0_config_dyn(name, maxconf, dynconf, bits) \
  810. do { \
  811. maxconf = read_gc0_##name(); \
  812. write_gc0_##name(maxconf ^ (bits)); \
  813. back_to_back_c0_hazard(); \
  814. dynconf = maxconf ^ read_gc0_##name(); \
  815. write_gc0_##name(maxconf); \
  816. maxconf |= dynconf; \
  817. } while (0)
  818. static inline unsigned int decode_guest_config0(struct cpuinfo_mips *c)
  819. {
  820. unsigned int config0;
  821. probe_gc0_config(config, config0, MIPS_CONF_M);
  822. if (config0 & MIPS_CONF_M)
  823. c->guest.conf |= BIT(1);
  824. return config0 & MIPS_CONF_M;
  825. }
  826. static inline unsigned int decode_guest_config1(struct cpuinfo_mips *c)
  827. {
  828. unsigned int config1, config1_dyn;
  829. probe_gc0_config_dyn(config1, config1, config1_dyn,
  830. MIPS_CONF_M | MIPS_CONF1_PC | MIPS_CONF1_WR |
  831. MIPS_CONF1_FP);
  832. if (config1 & MIPS_CONF1_FP)
  833. c->guest.options |= MIPS_CPU_FPU;
  834. if (config1_dyn & MIPS_CONF1_FP)
  835. c->guest.options_dyn |= MIPS_CPU_FPU;
  836. if (config1 & MIPS_CONF1_WR)
  837. c->guest.options |= MIPS_CPU_WATCH;
  838. if (config1_dyn & MIPS_CONF1_WR)
  839. c->guest.options_dyn |= MIPS_CPU_WATCH;
  840. if (config1 & MIPS_CONF1_PC)
  841. c->guest.options |= MIPS_CPU_PERF;
  842. if (config1_dyn & MIPS_CONF1_PC)
  843. c->guest.options_dyn |= MIPS_CPU_PERF;
  844. if (config1 & MIPS_CONF_M)
  845. c->guest.conf |= BIT(2);
  846. return config1 & MIPS_CONF_M;
  847. }
  848. static inline unsigned int decode_guest_config2(struct cpuinfo_mips *c)
  849. {
  850. unsigned int config2;
  851. probe_gc0_config(config2, config2, MIPS_CONF_M);
  852. if (config2 & MIPS_CONF_M)
  853. c->guest.conf |= BIT(3);
  854. return config2 & MIPS_CONF_M;
  855. }
  856. static inline unsigned int decode_guest_config3(struct cpuinfo_mips *c)
  857. {
  858. unsigned int config3, config3_dyn;
  859. probe_gc0_config_dyn(config3, config3, config3_dyn,
  860. MIPS_CONF_M | MIPS_CONF3_MSA | MIPS_CONF3_CTXTC);
  861. if (config3 & MIPS_CONF3_CTXTC)
  862. c->guest.options |= MIPS_CPU_CTXTC;
  863. if (config3_dyn & MIPS_CONF3_CTXTC)
  864. c->guest.options_dyn |= MIPS_CPU_CTXTC;
  865. if (config3 & MIPS_CONF3_PW)
  866. c->guest.options |= MIPS_CPU_HTW;
  867. if (config3 & MIPS_CONF3_SC)
  868. c->guest.options |= MIPS_CPU_SEGMENTS;
  869. if (config3 & MIPS_CONF3_BI)
  870. c->guest.options |= MIPS_CPU_BADINSTR;
  871. if (config3 & MIPS_CONF3_BP)
  872. c->guest.options |= MIPS_CPU_BADINSTRP;
  873. if (config3 & MIPS_CONF3_MSA)
  874. c->guest.ases |= MIPS_ASE_MSA;
  875. if (config3_dyn & MIPS_CONF3_MSA)
  876. c->guest.ases_dyn |= MIPS_ASE_MSA;
  877. if (config3 & MIPS_CONF_M)
  878. c->guest.conf |= BIT(4);
  879. return config3 & MIPS_CONF_M;
  880. }
  881. static inline unsigned int decode_guest_config4(struct cpuinfo_mips *c)
  882. {
  883. unsigned int config4;
  884. probe_gc0_config(config4, config4,
  885. MIPS_CONF_M | MIPS_CONF4_KSCREXIST);
  886. c->guest.kscratch_mask = (config4 & MIPS_CONF4_KSCREXIST)
  887. >> MIPS_CONF4_KSCREXIST_SHIFT;
  888. if (config4 & MIPS_CONF_M)
  889. c->guest.conf |= BIT(5);
  890. return config4 & MIPS_CONF_M;
  891. }
  892. static inline unsigned int decode_guest_config5(struct cpuinfo_mips *c)
  893. {
  894. unsigned int config5, config5_dyn;
  895. probe_gc0_config_dyn(config5, config5, config5_dyn,
  896. MIPS_CONF_M | MIPS_CONF5_MRP);
  897. if (config5 & MIPS_CONF5_MRP)
  898. c->guest.options |= MIPS_CPU_MAAR;
  899. if (config5_dyn & MIPS_CONF5_MRP)
  900. c->guest.options_dyn |= MIPS_CPU_MAAR;
  901. if (config5 & MIPS_CONF5_LLB)
  902. c->guest.options |= MIPS_CPU_RW_LLB;
  903. if (config5 & MIPS_CONF_M)
  904. c->guest.conf |= BIT(6);
  905. return config5 & MIPS_CONF_M;
  906. }
  907. static inline void decode_guest_configs(struct cpuinfo_mips *c)
  908. {
  909. unsigned int ok;
  910. ok = decode_guest_config0(c);
  911. if (ok)
  912. ok = decode_guest_config1(c);
  913. if (ok)
  914. ok = decode_guest_config2(c);
  915. if (ok)
  916. ok = decode_guest_config3(c);
  917. if (ok)
  918. ok = decode_guest_config4(c);
  919. if (ok)
  920. decode_guest_config5(c);
  921. }
  922. static inline void cpu_probe_guestctl0(struct cpuinfo_mips *c)
  923. {
  924. unsigned int guestctl0, temp;
  925. guestctl0 = read_c0_guestctl0();
  926. if (guestctl0 & MIPS_GCTL0_G0E)
  927. c->options |= MIPS_CPU_GUESTCTL0EXT;
  928. if (guestctl0 & MIPS_GCTL0_G1)
  929. c->options |= MIPS_CPU_GUESTCTL1;
  930. if (guestctl0 & MIPS_GCTL0_G2)
  931. c->options |= MIPS_CPU_GUESTCTL2;
  932. if (!(guestctl0 & MIPS_GCTL0_RAD)) {
  933. c->options |= MIPS_CPU_GUESTID;
  934. /*
  935. * Probe for Direct Root to Guest (DRG). Set GuestCtl1.RID = 0
  936. * first, otherwise all data accesses will be fully virtualised
  937. * as if they were performed by guest mode.
  938. */
  939. write_c0_guestctl1(0);
  940. tlbw_use_hazard();
  941. write_c0_guestctl0(guestctl0 | MIPS_GCTL0_DRG);
  942. back_to_back_c0_hazard();
  943. temp = read_c0_guestctl0();
  944. if (temp & MIPS_GCTL0_DRG) {
  945. write_c0_guestctl0(guestctl0);
  946. c->options |= MIPS_CPU_DRG;
  947. }
  948. }
  949. }
  950. static inline void cpu_probe_guestctl1(struct cpuinfo_mips *c)
  951. {
  952. if (cpu_has_guestid) {
  953. /* determine the number of bits of GuestID available */
  954. write_c0_guestctl1(MIPS_GCTL1_ID);
  955. back_to_back_c0_hazard();
  956. c->guestid_mask = (read_c0_guestctl1() & MIPS_GCTL1_ID)
  957. >> MIPS_GCTL1_ID_SHIFT;
  958. write_c0_guestctl1(0);
  959. }
  960. }
  961. static inline void cpu_probe_gtoffset(struct cpuinfo_mips *c)
  962. {
  963. /* determine the number of bits of GTOffset available */
  964. write_c0_gtoffset(0xffffffff);
  965. back_to_back_c0_hazard();
  966. c->gtoffset_mask = read_c0_gtoffset();
  967. write_c0_gtoffset(0);
  968. }
  969. static inline void cpu_probe_vz(struct cpuinfo_mips *c)
  970. {
  971. cpu_probe_guestctl0(c);
  972. if (cpu_has_guestctl1)
  973. cpu_probe_guestctl1(c);
  974. cpu_probe_gtoffset(c);
  975. decode_guest_configs(c);
  976. }
  977. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  978. | MIPS_CPU_COUNTER)
  979. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  980. {
  981. switch (c->processor_id & PRID_IMP_MASK) {
  982. case PRID_IMP_R2000:
  983. c->cputype = CPU_R2000;
  984. __cpu_name[cpu] = "R2000";
  985. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  986. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  987. MIPS_CPU_NOFPUEX;
  988. if (__cpu_has_fpu())
  989. c->options |= MIPS_CPU_FPU;
  990. c->tlbsize = 64;
  991. break;
  992. case PRID_IMP_R3000:
  993. if ((c->processor_id & PRID_REV_MASK) == PRID_REV_R3000A) {
  994. if (cpu_has_confreg()) {
  995. c->cputype = CPU_R3081E;
  996. __cpu_name[cpu] = "R3081";
  997. } else {
  998. c->cputype = CPU_R3000A;
  999. __cpu_name[cpu] = "R3000A";
  1000. }
  1001. } else {
  1002. c->cputype = CPU_R3000;
  1003. __cpu_name[cpu] = "R3000";
  1004. }
  1005. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1006. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  1007. MIPS_CPU_NOFPUEX;
  1008. if (__cpu_has_fpu())
  1009. c->options |= MIPS_CPU_FPU;
  1010. c->tlbsize = 64;
  1011. break;
  1012. case PRID_IMP_R4000:
  1013. if (read_c0_config() & CONF_SC) {
  1014. if ((c->processor_id & PRID_REV_MASK) >=
  1015. PRID_REV_R4400) {
  1016. c->cputype = CPU_R4400PC;
  1017. __cpu_name[cpu] = "R4400PC";
  1018. } else {
  1019. c->cputype = CPU_R4000PC;
  1020. __cpu_name[cpu] = "R4000PC";
  1021. }
  1022. } else {
  1023. int cca = read_c0_config() & CONF_CM_CMASK;
  1024. int mc;
  1025. /*
  1026. * SC and MC versions can't be reliably told apart,
  1027. * but only the latter support coherent caching
  1028. * modes so assume the firmware has set the KSEG0
  1029. * coherency attribute reasonably (if uncached, we
  1030. * assume SC).
  1031. */
  1032. switch (cca) {
  1033. case CONF_CM_CACHABLE_CE:
  1034. case CONF_CM_CACHABLE_COW:
  1035. case CONF_CM_CACHABLE_CUW:
  1036. mc = 1;
  1037. break;
  1038. default:
  1039. mc = 0;
  1040. break;
  1041. }
  1042. if ((c->processor_id & PRID_REV_MASK) >=
  1043. PRID_REV_R4400) {
  1044. c->cputype = mc ? CPU_R4400MC : CPU_R4400SC;
  1045. __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC";
  1046. } else {
  1047. c->cputype = mc ? CPU_R4000MC : CPU_R4000SC;
  1048. __cpu_name[cpu] = mc ? "R4000MC" : "R4000SC";
  1049. }
  1050. }
  1051. set_isa(c, MIPS_CPU_ISA_III);
  1052. c->fpu_msk31 |= FPU_CSR_CONDX;
  1053. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1054. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  1055. MIPS_CPU_LLSC;
  1056. c->tlbsize = 48;
  1057. break;
  1058. case PRID_IMP_VR41XX:
  1059. set_isa(c, MIPS_CPU_ISA_III);
  1060. c->fpu_msk31 |= FPU_CSR_CONDX;
  1061. c->options = R4K_OPTS;
  1062. c->tlbsize = 32;
  1063. switch (c->processor_id & 0xf0) {
  1064. case PRID_REV_VR4111:
  1065. c->cputype = CPU_VR4111;
  1066. __cpu_name[cpu] = "NEC VR4111";
  1067. break;
  1068. case PRID_REV_VR4121:
  1069. c->cputype = CPU_VR4121;
  1070. __cpu_name[cpu] = "NEC VR4121";
  1071. break;
  1072. case PRID_REV_VR4122:
  1073. if ((c->processor_id & 0xf) < 0x3) {
  1074. c->cputype = CPU_VR4122;
  1075. __cpu_name[cpu] = "NEC VR4122";
  1076. } else {
  1077. c->cputype = CPU_VR4181A;
  1078. __cpu_name[cpu] = "NEC VR4181A";
  1079. }
  1080. break;
  1081. case PRID_REV_VR4130:
  1082. if ((c->processor_id & 0xf) < 0x4) {
  1083. c->cputype = CPU_VR4131;
  1084. __cpu_name[cpu] = "NEC VR4131";
  1085. } else {
  1086. c->cputype = CPU_VR4133;
  1087. c->options |= MIPS_CPU_LLSC;
  1088. __cpu_name[cpu] = "NEC VR4133";
  1089. }
  1090. break;
  1091. default:
  1092. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  1093. c->cputype = CPU_VR41XX;
  1094. __cpu_name[cpu] = "NEC Vr41xx";
  1095. break;
  1096. }
  1097. break;
  1098. case PRID_IMP_R4300:
  1099. c->cputype = CPU_R4300;
  1100. __cpu_name[cpu] = "R4300";
  1101. set_isa(c, MIPS_CPU_ISA_III);
  1102. c->fpu_msk31 |= FPU_CSR_CONDX;
  1103. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1104. MIPS_CPU_LLSC;
  1105. c->tlbsize = 32;
  1106. break;
  1107. case PRID_IMP_R4600:
  1108. c->cputype = CPU_R4600;
  1109. __cpu_name[cpu] = "R4600";
  1110. set_isa(c, MIPS_CPU_ISA_III);
  1111. c->fpu_msk31 |= FPU_CSR_CONDX;
  1112. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1113. MIPS_CPU_LLSC;
  1114. c->tlbsize = 48;
  1115. break;
  1116. #if 0
  1117. case PRID_IMP_R4650:
  1118. /*
  1119. * This processor doesn't have an MMU, so it's not
  1120. * "real easy" to run Linux on it. It is left purely
  1121. * for documentation. Commented out because it shares
  1122. * it's c0_prid id number with the TX3900.
  1123. */
  1124. c->cputype = CPU_R4650;
  1125. __cpu_name[cpu] = "R4650";
  1126. set_isa(c, MIPS_CPU_ISA_III);
  1127. c->fpu_msk31 |= FPU_CSR_CONDX;
  1128. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  1129. c->tlbsize = 48;
  1130. break;
  1131. #endif
  1132. case PRID_IMP_TX39:
  1133. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1134. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  1135. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  1136. c->cputype = CPU_TX3927;
  1137. __cpu_name[cpu] = "TX3927";
  1138. c->tlbsize = 64;
  1139. } else {
  1140. switch (c->processor_id & PRID_REV_MASK) {
  1141. case PRID_REV_TX3912:
  1142. c->cputype = CPU_TX3912;
  1143. __cpu_name[cpu] = "TX3912";
  1144. c->tlbsize = 32;
  1145. break;
  1146. case PRID_REV_TX3922:
  1147. c->cputype = CPU_TX3922;
  1148. __cpu_name[cpu] = "TX3922";
  1149. c->tlbsize = 64;
  1150. break;
  1151. }
  1152. }
  1153. break;
  1154. case PRID_IMP_R4700:
  1155. c->cputype = CPU_R4700;
  1156. __cpu_name[cpu] = "R4700";
  1157. set_isa(c, MIPS_CPU_ISA_III);
  1158. c->fpu_msk31 |= FPU_CSR_CONDX;
  1159. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1160. MIPS_CPU_LLSC;
  1161. c->tlbsize = 48;
  1162. break;
  1163. case PRID_IMP_TX49:
  1164. c->cputype = CPU_TX49XX;
  1165. __cpu_name[cpu] = "R49XX";
  1166. set_isa(c, MIPS_CPU_ISA_III);
  1167. c->fpu_msk31 |= FPU_CSR_CONDX;
  1168. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  1169. if (!(c->processor_id & 0x08))
  1170. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  1171. c->tlbsize = 48;
  1172. break;
  1173. case PRID_IMP_R5000:
  1174. c->cputype = CPU_R5000;
  1175. __cpu_name[cpu] = "R5000";
  1176. set_isa(c, MIPS_CPU_ISA_IV);
  1177. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1178. MIPS_CPU_LLSC;
  1179. c->tlbsize = 48;
  1180. break;
  1181. case PRID_IMP_R5432:
  1182. c->cputype = CPU_R5432;
  1183. __cpu_name[cpu] = "R5432";
  1184. set_isa(c, MIPS_CPU_ISA_IV);
  1185. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1186. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  1187. c->tlbsize = 48;
  1188. break;
  1189. case PRID_IMP_R5500:
  1190. c->cputype = CPU_R5500;
  1191. __cpu_name[cpu] = "R5500";
  1192. set_isa(c, MIPS_CPU_ISA_IV);
  1193. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1194. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  1195. c->tlbsize = 48;
  1196. break;
  1197. case PRID_IMP_NEVADA:
  1198. c->cputype = CPU_NEVADA;
  1199. __cpu_name[cpu] = "Nevada";
  1200. set_isa(c, MIPS_CPU_ISA_IV);
  1201. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1202. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  1203. c->tlbsize = 48;
  1204. break;
  1205. case PRID_IMP_R6000:
  1206. c->cputype = CPU_R6000;
  1207. __cpu_name[cpu] = "R6000";
  1208. set_isa(c, MIPS_CPU_ISA_II);
  1209. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1210. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  1211. MIPS_CPU_LLSC;
  1212. c->tlbsize = 32;
  1213. break;
  1214. case PRID_IMP_R6000A:
  1215. c->cputype = CPU_R6000A;
  1216. __cpu_name[cpu] = "R6000A";
  1217. set_isa(c, MIPS_CPU_ISA_II);
  1218. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1219. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  1220. MIPS_CPU_LLSC;
  1221. c->tlbsize = 32;
  1222. break;
  1223. case PRID_IMP_RM7000:
  1224. c->cputype = CPU_RM7000;
  1225. __cpu_name[cpu] = "RM7000";
  1226. set_isa(c, MIPS_CPU_ISA_IV);
  1227. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1228. MIPS_CPU_LLSC;
  1229. /*
  1230. * Undocumented RM7000: Bit 29 in the info register of
  1231. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  1232. * entries.
  1233. *
  1234. * 29 1 => 64 entry JTLB
  1235. * 0 => 48 entry JTLB
  1236. */
  1237. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  1238. break;
  1239. case PRID_IMP_R8000:
  1240. c->cputype = CPU_R8000;
  1241. __cpu_name[cpu] = "RM8000";
  1242. set_isa(c, MIPS_CPU_ISA_IV);
  1243. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  1244. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1245. MIPS_CPU_LLSC;
  1246. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  1247. break;
  1248. case PRID_IMP_R10000:
  1249. c->cputype = CPU_R10000;
  1250. __cpu_name[cpu] = "R10000";
  1251. set_isa(c, MIPS_CPU_ISA_IV);
  1252. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1253. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1254. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1255. MIPS_CPU_LLSC;
  1256. c->tlbsize = 64;
  1257. break;
  1258. case PRID_IMP_R12000:
  1259. c->cputype = CPU_R12000;
  1260. __cpu_name[cpu] = "R12000";
  1261. set_isa(c, MIPS_CPU_ISA_IV);
  1262. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1263. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1264. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1265. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  1266. c->tlbsize = 64;
  1267. break;
  1268. case PRID_IMP_R14000:
  1269. if (((c->processor_id >> 4) & 0x0f) > 2) {
  1270. c->cputype = CPU_R16000;
  1271. __cpu_name[cpu] = "R16000";
  1272. } else {
  1273. c->cputype = CPU_R14000;
  1274. __cpu_name[cpu] = "R14000";
  1275. }
  1276. set_isa(c, MIPS_CPU_ISA_IV);
  1277. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1278. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1279. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1280. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  1281. c->tlbsize = 64;
  1282. break;
  1283. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  1284. switch (c->processor_id & PRID_REV_MASK) {
  1285. case PRID_REV_LOONGSON2E:
  1286. c->cputype = CPU_LOONGSON2;
  1287. __cpu_name[cpu] = "ICT Loongson-2";
  1288. set_elf_platform(cpu, "loongson2e");
  1289. set_isa(c, MIPS_CPU_ISA_III);
  1290. c->fpu_msk31 |= FPU_CSR_CONDX;
  1291. break;
  1292. case PRID_REV_LOONGSON2F:
  1293. c->cputype = CPU_LOONGSON2;
  1294. __cpu_name[cpu] = "ICT Loongson-2";
  1295. set_elf_platform(cpu, "loongson2f");
  1296. set_isa(c, MIPS_CPU_ISA_III);
  1297. c->fpu_msk31 |= FPU_CSR_CONDX;
  1298. break;
  1299. case PRID_REV_LOONGSON3A_R1:
  1300. c->cputype = CPU_LOONGSON3;
  1301. __cpu_name[cpu] = "ICT Loongson-3";
  1302. set_elf_platform(cpu, "loongson3a");
  1303. set_isa(c, MIPS_CPU_ISA_M64R1);
  1304. break;
  1305. case PRID_REV_LOONGSON3B_R1:
  1306. case PRID_REV_LOONGSON3B_R2:
  1307. c->cputype = CPU_LOONGSON3;
  1308. __cpu_name[cpu] = "ICT Loongson-3";
  1309. set_elf_platform(cpu, "loongson3b");
  1310. set_isa(c, MIPS_CPU_ISA_M64R1);
  1311. break;
  1312. }
  1313. c->options = R4K_OPTS |
  1314. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  1315. MIPS_CPU_32FPR;
  1316. c->tlbsize = 64;
  1317. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1318. break;
  1319. case PRID_IMP_LOONGSON_32: /* Loongson-1 */
  1320. decode_configs(c);
  1321. c->cputype = CPU_LOONGSON1;
  1322. switch (c->processor_id & PRID_REV_MASK) {
  1323. case PRID_REV_LOONGSON1B:
  1324. __cpu_name[cpu] = "Loongson 1B";
  1325. break;
  1326. }
  1327. break;
  1328. }
  1329. }
  1330. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  1331. {
  1332. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1333. switch (c->processor_id & PRID_IMP_MASK) {
  1334. case PRID_IMP_QEMU_GENERIC:
  1335. c->writecombine = _CACHE_UNCACHED;
  1336. c->cputype = CPU_QEMU_GENERIC;
  1337. __cpu_name[cpu] = "MIPS GENERIC QEMU";
  1338. break;
  1339. case PRID_IMP_4KC:
  1340. c->cputype = CPU_4KC;
  1341. c->writecombine = _CACHE_UNCACHED;
  1342. __cpu_name[cpu] = "MIPS 4Kc";
  1343. break;
  1344. case PRID_IMP_4KEC:
  1345. case PRID_IMP_4KECR2:
  1346. c->cputype = CPU_4KEC;
  1347. c->writecombine = _CACHE_UNCACHED;
  1348. __cpu_name[cpu] = "MIPS 4KEc";
  1349. break;
  1350. case PRID_IMP_4KSC:
  1351. case PRID_IMP_4KSD:
  1352. c->cputype = CPU_4KSC;
  1353. c->writecombine = _CACHE_UNCACHED;
  1354. __cpu_name[cpu] = "MIPS 4KSc";
  1355. break;
  1356. case PRID_IMP_5KC:
  1357. c->cputype = CPU_5KC;
  1358. c->writecombine = _CACHE_UNCACHED;
  1359. __cpu_name[cpu] = "MIPS 5Kc";
  1360. break;
  1361. case PRID_IMP_5KE:
  1362. c->cputype = CPU_5KE;
  1363. c->writecombine = _CACHE_UNCACHED;
  1364. __cpu_name[cpu] = "MIPS 5KE";
  1365. break;
  1366. case PRID_IMP_20KC:
  1367. c->cputype = CPU_20KC;
  1368. c->writecombine = _CACHE_UNCACHED;
  1369. __cpu_name[cpu] = "MIPS 20Kc";
  1370. break;
  1371. case PRID_IMP_24K:
  1372. c->cputype = CPU_24K;
  1373. c->writecombine = _CACHE_UNCACHED;
  1374. __cpu_name[cpu] = "MIPS 24Kc";
  1375. break;
  1376. case PRID_IMP_24KE:
  1377. c->cputype = CPU_24K;
  1378. c->writecombine = _CACHE_UNCACHED;
  1379. __cpu_name[cpu] = "MIPS 24KEc";
  1380. break;
  1381. case PRID_IMP_25KF:
  1382. c->cputype = CPU_25KF;
  1383. c->writecombine = _CACHE_UNCACHED;
  1384. __cpu_name[cpu] = "MIPS 25Kc";
  1385. break;
  1386. case PRID_IMP_34K:
  1387. c->cputype = CPU_34K;
  1388. c->writecombine = _CACHE_UNCACHED;
  1389. __cpu_name[cpu] = "MIPS 34Kc";
  1390. break;
  1391. case PRID_IMP_74K:
  1392. c->cputype = CPU_74K;
  1393. c->writecombine = _CACHE_UNCACHED;
  1394. __cpu_name[cpu] = "MIPS 74Kc";
  1395. break;
  1396. case PRID_IMP_M14KC:
  1397. c->cputype = CPU_M14KC;
  1398. c->writecombine = _CACHE_UNCACHED;
  1399. __cpu_name[cpu] = "MIPS M14Kc";
  1400. break;
  1401. case PRID_IMP_M14KEC:
  1402. c->cputype = CPU_M14KEC;
  1403. c->writecombine = _CACHE_UNCACHED;
  1404. __cpu_name[cpu] = "MIPS M14KEc";
  1405. break;
  1406. case PRID_IMP_1004K:
  1407. c->cputype = CPU_1004K;
  1408. c->writecombine = _CACHE_UNCACHED;
  1409. __cpu_name[cpu] = "MIPS 1004Kc";
  1410. break;
  1411. case PRID_IMP_1074K:
  1412. c->cputype = CPU_1074K;
  1413. c->writecombine = _CACHE_UNCACHED;
  1414. __cpu_name[cpu] = "MIPS 1074Kc";
  1415. break;
  1416. case PRID_IMP_INTERAPTIV_UP:
  1417. c->cputype = CPU_INTERAPTIV;
  1418. __cpu_name[cpu] = "MIPS interAptiv";
  1419. break;
  1420. case PRID_IMP_INTERAPTIV_MP:
  1421. c->cputype = CPU_INTERAPTIV;
  1422. __cpu_name[cpu] = "MIPS interAptiv (multi)";
  1423. break;
  1424. case PRID_IMP_PROAPTIV_UP:
  1425. c->cputype = CPU_PROAPTIV;
  1426. __cpu_name[cpu] = "MIPS proAptiv";
  1427. break;
  1428. case PRID_IMP_PROAPTIV_MP:
  1429. c->cputype = CPU_PROAPTIV;
  1430. __cpu_name[cpu] = "MIPS proAptiv (multi)";
  1431. break;
  1432. case PRID_IMP_P5600:
  1433. c->cputype = CPU_P5600;
  1434. __cpu_name[cpu] = "MIPS P5600";
  1435. break;
  1436. case PRID_IMP_P6600:
  1437. c->cputype = CPU_P6600;
  1438. __cpu_name[cpu] = "MIPS P6600";
  1439. break;
  1440. case PRID_IMP_I6400:
  1441. c->cputype = CPU_I6400;
  1442. __cpu_name[cpu] = "MIPS I6400";
  1443. break;
  1444. case PRID_IMP_M5150:
  1445. c->cputype = CPU_M5150;
  1446. __cpu_name[cpu] = "MIPS M5150";
  1447. break;
  1448. case PRID_IMP_M6250:
  1449. c->cputype = CPU_M6250;
  1450. __cpu_name[cpu] = "MIPS M6250";
  1451. break;
  1452. }
  1453. decode_configs(c);
  1454. spram_config();
  1455. }
  1456. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  1457. {
  1458. decode_configs(c);
  1459. switch (c->processor_id & PRID_IMP_MASK) {
  1460. case PRID_IMP_AU1_REV1:
  1461. case PRID_IMP_AU1_REV2:
  1462. c->cputype = CPU_ALCHEMY;
  1463. switch ((c->processor_id >> 24) & 0xff) {
  1464. case 0:
  1465. __cpu_name[cpu] = "Au1000";
  1466. break;
  1467. case 1:
  1468. __cpu_name[cpu] = "Au1500";
  1469. break;
  1470. case 2:
  1471. __cpu_name[cpu] = "Au1100";
  1472. break;
  1473. case 3:
  1474. __cpu_name[cpu] = "Au1550";
  1475. break;
  1476. case 4:
  1477. __cpu_name[cpu] = "Au1200";
  1478. if ((c->processor_id & PRID_REV_MASK) == 2)
  1479. __cpu_name[cpu] = "Au1250";
  1480. break;
  1481. case 5:
  1482. __cpu_name[cpu] = "Au1210";
  1483. break;
  1484. default:
  1485. __cpu_name[cpu] = "Au1xxx";
  1486. break;
  1487. }
  1488. break;
  1489. }
  1490. }
  1491. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  1492. {
  1493. decode_configs(c);
  1494. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1495. switch (c->processor_id & PRID_IMP_MASK) {
  1496. case PRID_IMP_SB1:
  1497. c->cputype = CPU_SB1;
  1498. __cpu_name[cpu] = "SiByte SB1";
  1499. /* FPU in pass1 is known to have issues. */
  1500. if ((c->processor_id & PRID_REV_MASK) < 0x02)
  1501. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  1502. break;
  1503. case PRID_IMP_SB1A:
  1504. c->cputype = CPU_SB1A;
  1505. __cpu_name[cpu] = "SiByte SB1A";
  1506. break;
  1507. }
  1508. }
  1509. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  1510. {
  1511. decode_configs(c);
  1512. switch (c->processor_id & PRID_IMP_MASK) {
  1513. case PRID_IMP_SR71000:
  1514. c->cputype = CPU_SR71000;
  1515. __cpu_name[cpu] = "Sandcraft SR71000";
  1516. c->scache.ways = 8;
  1517. c->tlbsize = 64;
  1518. break;
  1519. }
  1520. }
  1521. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  1522. {
  1523. decode_configs(c);
  1524. switch (c->processor_id & PRID_IMP_MASK) {
  1525. case PRID_IMP_PR4450:
  1526. c->cputype = CPU_PR4450;
  1527. __cpu_name[cpu] = "Philips PR4450";
  1528. set_isa(c, MIPS_CPU_ISA_M32R1);
  1529. break;
  1530. }
  1531. }
  1532. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  1533. {
  1534. decode_configs(c);
  1535. switch (c->processor_id & PRID_IMP_MASK) {
  1536. case PRID_IMP_BMIPS32_REV4:
  1537. case PRID_IMP_BMIPS32_REV8:
  1538. c->cputype = CPU_BMIPS32;
  1539. __cpu_name[cpu] = "Broadcom BMIPS32";
  1540. set_elf_platform(cpu, "bmips32");
  1541. break;
  1542. case PRID_IMP_BMIPS3300:
  1543. case PRID_IMP_BMIPS3300_ALT:
  1544. case PRID_IMP_BMIPS3300_BUG:
  1545. c->cputype = CPU_BMIPS3300;
  1546. __cpu_name[cpu] = "Broadcom BMIPS3300";
  1547. set_elf_platform(cpu, "bmips3300");
  1548. break;
  1549. case PRID_IMP_BMIPS43XX: {
  1550. int rev = c->processor_id & PRID_REV_MASK;
  1551. if (rev >= PRID_REV_BMIPS4380_LO &&
  1552. rev <= PRID_REV_BMIPS4380_HI) {
  1553. c->cputype = CPU_BMIPS4380;
  1554. __cpu_name[cpu] = "Broadcom BMIPS4380";
  1555. set_elf_platform(cpu, "bmips4380");
  1556. c->options |= MIPS_CPU_RIXI;
  1557. } else {
  1558. c->cputype = CPU_BMIPS4350;
  1559. __cpu_name[cpu] = "Broadcom BMIPS4350";
  1560. set_elf_platform(cpu, "bmips4350");
  1561. }
  1562. break;
  1563. }
  1564. case PRID_IMP_BMIPS5000:
  1565. case PRID_IMP_BMIPS5200:
  1566. c->cputype = CPU_BMIPS5000;
  1567. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_BMIPS5200)
  1568. __cpu_name[cpu] = "Broadcom BMIPS5200";
  1569. else
  1570. __cpu_name[cpu] = "Broadcom BMIPS5000";
  1571. set_elf_platform(cpu, "bmips5000");
  1572. c->options |= MIPS_CPU_ULRI | MIPS_CPU_RIXI;
  1573. break;
  1574. }
  1575. }
  1576. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  1577. {
  1578. decode_configs(c);
  1579. switch (c->processor_id & PRID_IMP_MASK) {
  1580. case PRID_IMP_CAVIUM_CN38XX:
  1581. case PRID_IMP_CAVIUM_CN31XX:
  1582. case PRID_IMP_CAVIUM_CN30XX:
  1583. c->cputype = CPU_CAVIUM_OCTEON;
  1584. __cpu_name[cpu] = "Cavium Octeon";
  1585. goto platform;
  1586. case PRID_IMP_CAVIUM_CN58XX:
  1587. case PRID_IMP_CAVIUM_CN56XX:
  1588. case PRID_IMP_CAVIUM_CN50XX:
  1589. case PRID_IMP_CAVIUM_CN52XX:
  1590. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  1591. __cpu_name[cpu] = "Cavium Octeon+";
  1592. platform:
  1593. set_elf_platform(cpu, "octeon");
  1594. break;
  1595. case PRID_IMP_CAVIUM_CN61XX:
  1596. case PRID_IMP_CAVIUM_CN63XX:
  1597. case PRID_IMP_CAVIUM_CN66XX:
  1598. case PRID_IMP_CAVIUM_CN68XX:
  1599. case PRID_IMP_CAVIUM_CNF71XX:
  1600. c->cputype = CPU_CAVIUM_OCTEON2;
  1601. __cpu_name[cpu] = "Cavium Octeon II";
  1602. set_elf_platform(cpu, "octeon2");
  1603. break;
  1604. case PRID_IMP_CAVIUM_CN70XX:
  1605. case PRID_IMP_CAVIUM_CN73XX:
  1606. case PRID_IMP_CAVIUM_CNF75XX:
  1607. case PRID_IMP_CAVIUM_CN78XX:
  1608. c->cputype = CPU_CAVIUM_OCTEON3;
  1609. __cpu_name[cpu] = "Cavium Octeon III";
  1610. set_elf_platform(cpu, "octeon3");
  1611. break;
  1612. default:
  1613. printk(KERN_INFO "Unknown Octeon chip!\n");
  1614. c->cputype = CPU_UNKNOWN;
  1615. break;
  1616. }
  1617. }
  1618. static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)
  1619. {
  1620. switch (c->processor_id & PRID_IMP_MASK) {
  1621. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  1622. switch (c->processor_id & PRID_REV_MASK) {
  1623. case PRID_REV_LOONGSON3A_R2:
  1624. c->cputype = CPU_LOONGSON3;
  1625. __cpu_name[cpu] = "ICT Loongson-3";
  1626. set_elf_platform(cpu, "loongson3a");
  1627. set_isa(c, MIPS_CPU_ISA_M64R2);
  1628. break;
  1629. }
  1630. decode_configs(c);
  1631. c->options |= MIPS_CPU_TLBINV | MIPS_CPU_LDPTE;
  1632. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1633. break;
  1634. default:
  1635. panic("Unknown Loongson Processor ID!");
  1636. break;
  1637. }
  1638. }
  1639. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  1640. {
  1641. decode_configs(c);
  1642. /* JZRISC does not implement the CP0 counter. */
  1643. c->options &= ~MIPS_CPU_COUNTER;
  1644. BUG_ON(!__builtin_constant_p(cpu_has_counter) || cpu_has_counter);
  1645. switch (c->processor_id & PRID_IMP_MASK) {
  1646. case PRID_IMP_JZRISC:
  1647. c->cputype = CPU_JZRISC;
  1648. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1649. __cpu_name[cpu] = "Ingenic JZRISC";
  1650. break;
  1651. default:
  1652. panic("Unknown Ingenic Processor ID!");
  1653. break;
  1654. }
  1655. }
  1656. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  1657. {
  1658. decode_configs(c);
  1659. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_NETLOGIC_AU13XX) {
  1660. c->cputype = CPU_ALCHEMY;
  1661. __cpu_name[cpu] = "Au1300";
  1662. /* following stuff is not for Alchemy */
  1663. return;
  1664. }
  1665. c->options = (MIPS_CPU_TLB |
  1666. MIPS_CPU_4KEX |
  1667. MIPS_CPU_COUNTER |
  1668. MIPS_CPU_DIVEC |
  1669. MIPS_CPU_WATCH |
  1670. MIPS_CPU_EJTAG |
  1671. MIPS_CPU_LLSC);
  1672. switch (c->processor_id & PRID_IMP_MASK) {
  1673. case PRID_IMP_NETLOGIC_XLP2XX:
  1674. case PRID_IMP_NETLOGIC_XLP9XX:
  1675. case PRID_IMP_NETLOGIC_XLP5XX:
  1676. c->cputype = CPU_XLP;
  1677. __cpu_name[cpu] = "Broadcom XLPII";
  1678. break;
  1679. case PRID_IMP_NETLOGIC_XLP8XX:
  1680. case PRID_IMP_NETLOGIC_XLP3XX:
  1681. c->cputype = CPU_XLP;
  1682. __cpu_name[cpu] = "Netlogic XLP";
  1683. break;
  1684. case PRID_IMP_NETLOGIC_XLR732:
  1685. case PRID_IMP_NETLOGIC_XLR716:
  1686. case PRID_IMP_NETLOGIC_XLR532:
  1687. case PRID_IMP_NETLOGIC_XLR308:
  1688. case PRID_IMP_NETLOGIC_XLR532C:
  1689. case PRID_IMP_NETLOGIC_XLR516C:
  1690. case PRID_IMP_NETLOGIC_XLR508C:
  1691. case PRID_IMP_NETLOGIC_XLR308C:
  1692. c->cputype = CPU_XLR;
  1693. __cpu_name[cpu] = "Netlogic XLR";
  1694. break;
  1695. case PRID_IMP_NETLOGIC_XLS608:
  1696. case PRID_IMP_NETLOGIC_XLS408:
  1697. case PRID_IMP_NETLOGIC_XLS404:
  1698. case PRID_IMP_NETLOGIC_XLS208:
  1699. case PRID_IMP_NETLOGIC_XLS204:
  1700. case PRID_IMP_NETLOGIC_XLS108:
  1701. case PRID_IMP_NETLOGIC_XLS104:
  1702. case PRID_IMP_NETLOGIC_XLS616B:
  1703. case PRID_IMP_NETLOGIC_XLS608B:
  1704. case PRID_IMP_NETLOGIC_XLS416B:
  1705. case PRID_IMP_NETLOGIC_XLS412B:
  1706. case PRID_IMP_NETLOGIC_XLS408B:
  1707. case PRID_IMP_NETLOGIC_XLS404B:
  1708. c->cputype = CPU_XLR;
  1709. __cpu_name[cpu] = "Netlogic XLS";
  1710. break;
  1711. default:
  1712. pr_info("Unknown Netlogic chip id [%02x]!\n",
  1713. c->processor_id);
  1714. c->cputype = CPU_XLR;
  1715. break;
  1716. }
  1717. if (c->cputype == CPU_XLP) {
  1718. set_isa(c, MIPS_CPU_ISA_M64R2);
  1719. c->options |= (MIPS_CPU_FPU | MIPS_CPU_ULRI | MIPS_CPU_MCHECK);
  1720. /* This will be updated again after all threads are woken up */
  1721. c->tlbsize = ((read_c0_config6() >> 16) & 0xffff) + 1;
  1722. } else {
  1723. set_isa(c, MIPS_CPU_ISA_M64R1);
  1724. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  1725. }
  1726. c->kscratch_mask = 0xf;
  1727. }
  1728. #ifdef CONFIG_64BIT
  1729. /* For use by uaccess.h */
  1730. u64 __ua_limit;
  1731. EXPORT_SYMBOL(__ua_limit);
  1732. #endif
  1733. const char *__cpu_name[NR_CPUS];
  1734. const char *__elf_platform;
  1735. void cpu_probe(void)
  1736. {
  1737. struct cpuinfo_mips *c = &current_cpu_data;
  1738. unsigned int cpu = smp_processor_id();
  1739. c->processor_id = PRID_IMP_UNKNOWN;
  1740. c->fpu_id = FPIR_IMP_NONE;
  1741. c->cputype = CPU_UNKNOWN;
  1742. c->writecombine = _CACHE_UNCACHED;
  1743. c->fpu_csr31 = FPU_CSR_RN;
  1744. c->fpu_msk31 = FPU_CSR_RSVD | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  1745. c->processor_id = read_c0_prid();
  1746. switch (c->processor_id & PRID_COMP_MASK) {
  1747. case PRID_COMP_LEGACY:
  1748. cpu_probe_legacy(c, cpu);
  1749. break;
  1750. case PRID_COMP_MIPS:
  1751. cpu_probe_mips(c, cpu);
  1752. break;
  1753. case PRID_COMP_ALCHEMY:
  1754. cpu_probe_alchemy(c, cpu);
  1755. break;
  1756. case PRID_COMP_SIBYTE:
  1757. cpu_probe_sibyte(c, cpu);
  1758. break;
  1759. case PRID_COMP_BROADCOM:
  1760. cpu_probe_broadcom(c, cpu);
  1761. break;
  1762. case PRID_COMP_SANDCRAFT:
  1763. cpu_probe_sandcraft(c, cpu);
  1764. break;
  1765. case PRID_COMP_NXP:
  1766. cpu_probe_nxp(c, cpu);
  1767. break;
  1768. case PRID_COMP_CAVIUM:
  1769. cpu_probe_cavium(c, cpu);
  1770. break;
  1771. case PRID_COMP_LOONGSON:
  1772. cpu_probe_loongson(c, cpu);
  1773. break;
  1774. case PRID_COMP_INGENIC_D0:
  1775. case PRID_COMP_INGENIC_D1:
  1776. case PRID_COMP_INGENIC_E1:
  1777. cpu_probe_ingenic(c, cpu);
  1778. break;
  1779. case PRID_COMP_NETLOGIC:
  1780. cpu_probe_netlogic(c, cpu);
  1781. break;
  1782. }
  1783. BUG_ON(!__cpu_name[cpu]);
  1784. BUG_ON(c->cputype == CPU_UNKNOWN);
  1785. /*
  1786. * Platform code can force the cpu type to optimize code
  1787. * generation. In that case be sure the cpu type is correctly
  1788. * manually setup otherwise it could trigger some nasty bugs.
  1789. */
  1790. BUG_ON(current_cpu_type() != c->cputype);
  1791. if (cpu_has_rixi) {
  1792. /* Enable the RIXI exceptions */
  1793. set_c0_pagegrain(PG_IEC);
  1794. back_to_back_c0_hazard();
  1795. /* Verify the IEC bit is set */
  1796. if (read_c0_pagegrain() & PG_IEC)
  1797. c->options |= MIPS_CPU_RIXIEX;
  1798. }
  1799. if (mips_fpu_disabled)
  1800. c->options &= ~MIPS_CPU_FPU;
  1801. if (mips_dsp_disabled)
  1802. c->ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  1803. if (mips_htw_disabled) {
  1804. c->options &= ~MIPS_CPU_HTW;
  1805. write_c0_pwctl(read_c0_pwctl() &
  1806. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  1807. }
  1808. if (c->options & MIPS_CPU_FPU)
  1809. cpu_set_fpu_opts(c);
  1810. else
  1811. cpu_set_nofpu_opts(c);
  1812. if (cpu_has_bp_ghist)
  1813. write_c0_r10k_diag(read_c0_r10k_diag() |
  1814. R10K_DIAG_E_GHIST);
  1815. if (cpu_has_mips_r2_r6) {
  1816. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1817. /* R2 has Performance Counter Interrupt indicator */
  1818. c->options |= MIPS_CPU_PCI;
  1819. }
  1820. else
  1821. c->srsets = 1;
  1822. if (cpu_has_mips_r6)
  1823. elf_hwcap |= HWCAP_MIPS_R6;
  1824. if (cpu_has_msa) {
  1825. c->msa_id = cpu_get_msa_id();
  1826. WARN(c->msa_id & MSA_IR_WRPF,
  1827. "Vector register partitioning unimplemented!");
  1828. elf_hwcap |= HWCAP_MIPS_MSA;
  1829. }
  1830. if (cpu_has_vz)
  1831. cpu_probe_vz(c);
  1832. cpu_probe_vmbits(c);
  1833. #ifdef CONFIG_64BIT
  1834. if (cpu == 0)
  1835. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1836. #endif
  1837. }
  1838. void cpu_report(void)
  1839. {
  1840. struct cpuinfo_mips *c = &current_cpu_data;
  1841. pr_info("CPU%d revision is: %08x (%s)\n",
  1842. smp_processor_id(), c->processor_id, cpu_name_string());
  1843. if (c->options & MIPS_CPU_FPU)
  1844. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1845. if (cpu_has_msa)
  1846. pr_info("MSA revision is: %08x\n", c->msa_id);
  1847. }