cpu-probe.c 53 KB

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