cpu-probe.c 55 KB

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