cpu-probe.c 53 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135
  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. if (config5 & MIPS_CONF5_CRCP)
  735. elf_hwcap |= HWCAP_MIPS_CRC32;
  736. return config5 & MIPS_CONF_M;
  737. }
  738. static void decode_configs(struct cpuinfo_mips *c)
  739. {
  740. int ok;
  741. /* MIPS32 or MIPS64 compliant CPU. */
  742. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  743. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  744. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  745. /* Enable FTLB if present and not disabled */
  746. set_ftlb_enable(c, mips_ftlb_disabled ? 0 : FTLB_EN);
  747. ok = decode_config0(c); /* Read Config registers. */
  748. BUG_ON(!ok); /* Arch spec violation! */
  749. if (ok)
  750. ok = decode_config1(c);
  751. if (ok)
  752. ok = decode_config2(c);
  753. if (ok)
  754. ok = decode_config3(c);
  755. if (ok)
  756. ok = decode_config4(c);
  757. if (ok)
  758. ok = decode_config5(c);
  759. /* Probe the EBase.WG bit */
  760. if (cpu_has_mips_r2_r6) {
  761. u64 ebase;
  762. unsigned int status;
  763. /* {read,write}_c0_ebase_64() may be UNDEFINED prior to r6 */
  764. ebase = cpu_has_mips64r6 ? read_c0_ebase_64()
  765. : (s32)read_c0_ebase();
  766. if (ebase & MIPS_EBASE_WG) {
  767. /* WG bit already set, we can avoid the clumsy probe */
  768. c->options |= MIPS_CPU_EBASE_WG;
  769. } else {
  770. /* Its UNDEFINED to change EBase while BEV=0 */
  771. status = read_c0_status();
  772. write_c0_status(status | ST0_BEV);
  773. irq_enable_hazard();
  774. /*
  775. * On pre-r6 cores, this may well clobber the upper bits
  776. * of EBase. This is hard to avoid without potentially
  777. * hitting UNDEFINED dm*c0 behaviour if EBase is 32-bit.
  778. */
  779. if (cpu_has_mips64r6)
  780. write_c0_ebase_64(ebase | MIPS_EBASE_WG);
  781. else
  782. write_c0_ebase(ebase | MIPS_EBASE_WG);
  783. back_to_back_c0_hazard();
  784. /* Restore BEV */
  785. write_c0_status(status);
  786. if (read_c0_ebase() & MIPS_EBASE_WG) {
  787. c->options |= MIPS_CPU_EBASE_WG;
  788. write_c0_ebase(ebase);
  789. }
  790. }
  791. }
  792. /* configure the FTLB write probability */
  793. set_ftlb_enable(c, (mips_ftlb_disabled ? 0 : FTLB_EN) | FTLB_SET_PROB);
  794. mips_probe_watch_registers(c);
  795. #ifndef CONFIG_MIPS_CPS
  796. if (cpu_has_mips_r2_r6) {
  797. unsigned int core;
  798. core = get_ebase_cpunum();
  799. if (cpu_has_mipsmt)
  800. core >>= fls(core_nvpes()) - 1;
  801. cpu_set_core(c, core);
  802. }
  803. #endif
  804. }
  805. /*
  806. * Probe for certain guest capabilities by writing config bits and reading back.
  807. * Finally write back the original value.
  808. */
  809. #define probe_gc0_config(name, maxconf, bits) \
  810. do { \
  811. unsigned int tmp; \
  812. tmp = read_gc0_##name(); \
  813. write_gc0_##name(tmp | (bits)); \
  814. back_to_back_c0_hazard(); \
  815. maxconf = read_gc0_##name(); \
  816. write_gc0_##name(tmp); \
  817. } while (0)
  818. /*
  819. * Probe for dynamic guest capabilities by changing certain config bits and
  820. * reading back to see if they change. Finally write back the original value.
  821. */
  822. #define probe_gc0_config_dyn(name, maxconf, dynconf, bits) \
  823. do { \
  824. maxconf = read_gc0_##name(); \
  825. write_gc0_##name(maxconf ^ (bits)); \
  826. back_to_back_c0_hazard(); \
  827. dynconf = maxconf ^ read_gc0_##name(); \
  828. write_gc0_##name(maxconf); \
  829. maxconf |= dynconf; \
  830. } while (0)
  831. static inline unsigned int decode_guest_config0(struct cpuinfo_mips *c)
  832. {
  833. unsigned int config0;
  834. probe_gc0_config(config, config0, MIPS_CONF_M);
  835. if (config0 & MIPS_CONF_M)
  836. c->guest.conf |= BIT(1);
  837. return config0 & MIPS_CONF_M;
  838. }
  839. static inline unsigned int decode_guest_config1(struct cpuinfo_mips *c)
  840. {
  841. unsigned int config1, config1_dyn;
  842. probe_gc0_config_dyn(config1, config1, config1_dyn,
  843. MIPS_CONF_M | MIPS_CONF1_PC | MIPS_CONF1_WR |
  844. MIPS_CONF1_FP);
  845. if (config1 & MIPS_CONF1_FP)
  846. c->guest.options |= MIPS_CPU_FPU;
  847. if (config1_dyn & MIPS_CONF1_FP)
  848. c->guest.options_dyn |= MIPS_CPU_FPU;
  849. if (config1 & MIPS_CONF1_WR)
  850. c->guest.options |= MIPS_CPU_WATCH;
  851. if (config1_dyn & MIPS_CONF1_WR)
  852. c->guest.options_dyn |= MIPS_CPU_WATCH;
  853. if (config1 & MIPS_CONF1_PC)
  854. c->guest.options |= MIPS_CPU_PERF;
  855. if (config1_dyn & MIPS_CONF1_PC)
  856. c->guest.options_dyn |= MIPS_CPU_PERF;
  857. if (config1 & MIPS_CONF_M)
  858. c->guest.conf |= BIT(2);
  859. return config1 & MIPS_CONF_M;
  860. }
  861. static inline unsigned int decode_guest_config2(struct cpuinfo_mips *c)
  862. {
  863. unsigned int config2;
  864. probe_gc0_config(config2, config2, MIPS_CONF_M);
  865. if (config2 & MIPS_CONF_M)
  866. c->guest.conf |= BIT(3);
  867. return config2 & MIPS_CONF_M;
  868. }
  869. static inline unsigned int decode_guest_config3(struct cpuinfo_mips *c)
  870. {
  871. unsigned int config3, config3_dyn;
  872. probe_gc0_config_dyn(config3, config3, config3_dyn,
  873. MIPS_CONF_M | MIPS_CONF3_MSA | MIPS_CONF3_ULRI |
  874. MIPS_CONF3_CTXTC);
  875. if (config3 & MIPS_CONF3_CTXTC)
  876. c->guest.options |= MIPS_CPU_CTXTC;
  877. if (config3_dyn & MIPS_CONF3_CTXTC)
  878. c->guest.options_dyn |= MIPS_CPU_CTXTC;
  879. if (config3 & MIPS_CONF3_PW)
  880. c->guest.options |= MIPS_CPU_HTW;
  881. if (config3 & MIPS_CONF3_ULRI)
  882. c->guest.options |= MIPS_CPU_ULRI;
  883. if (config3 & MIPS_CONF3_SC)
  884. c->guest.options |= MIPS_CPU_SEGMENTS;
  885. if (config3 & MIPS_CONF3_BI)
  886. c->guest.options |= MIPS_CPU_BADINSTR;
  887. if (config3 & MIPS_CONF3_BP)
  888. c->guest.options |= MIPS_CPU_BADINSTRP;
  889. if (config3 & MIPS_CONF3_MSA)
  890. c->guest.ases |= MIPS_ASE_MSA;
  891. if (config3_dyn & MIPS_CONF3_MSA)
  892. c->guest.ases_dyn |= MIPS_ASE_MSA;
  893. if (config3 & MIPS_CONF_M)
  894. c->guest.conf |= BIT(4);
  895. return config3 & MIPS_CONF_M;
  896. }
  897. static inline unsigned int decode_guest_config4(struct cpuinfo_mips *c)
  898. {
  899. unsigned int config4;
  900. probe_gc0_config(config4, config4,
  901. MIPS_CONF_M | MIPS_CONF4_KSCREXIST);
  902. c->guest.kscratch_mask = (config4 & MIPS_CONF4_KSCREXIST)
  903. >> MIPS_CONF4_KSCREXIST_SHIFT;
  904. if (config4 & MIPS_CONF_M)
  905. c->guest.conf |= BIT(5);
  906. return config4 & MIPS_CONF_M;
  907. }
  908. static inline unsigned int decode_guest_config5(struct cpuinfo_mips *c)
  909. {
  910. unsigned int config5, config5_dyn;
  911. probe_gc0_config_dyn(config5, config5, config5_dyn,
  912. MIPS_CONF_M | MIPS_CONF5_MVH | MIPS_CONF5_MRP);
  913. if (config5 & MIPS_CONF5_MRP)
  914. c->guest.options |= MIPS_CPU_MAAR;
  915. if (config5_dyn & MIPS_CONF5_MRP)
  916. c->guest.options_dyn |= MIPS_CPU_MAAR;
  917. if (config5 & MIPS_CONF5_LLB)
  918. c->guest.options |= MIPS_CPU_RW_LLB;
  919. if (config5 & MIPS_CONF5_MVH)
  920. c->guest.options |= MIPS_CPU_MVH;
  921. if (config5 & MIPS_CONF_M)
  922. c->guest.conf |= BIT(6);
  923. return config5 & MIPS_CONF_M;
  924. }
  925. static inline void decode_guest_configs(struct cpuinfo_mips *c)
  926. {
  927. unsigned int ok;
  928. ok = decode_guest_config0(c);
  929. if (ok)
  930. ok = decode_guest_config1(c);
  931. if (ok)
  932. ok = decode_guest_config2(c);
  933. if (ok)
  934. ok = decode_guest_config3(c);
  935. if (ok)
  936. ok = decode_guest_config4(c);
  937. if (ok)
  938. decode_guest_config5(c);
  939. }
  940. static inline void cpu_probe_guestctl0(struct cpuinfo_mips *c)
  941. {
  942. unsigned int guestctl0, temp;
  943. guestctl0 = read_c0_guestctl0();
  944. if (guestctl0 & MIPS_GCTL0_G0E)
  945. c->options |= MIPS_CPU_GUESTCTL0EXT;
  946. if (guestctl0 & MIPS_GCTL0_G1)
  947. c->options |= MIPS_CPU_GUESTCTL1;
  948. if (guestctl0 & MIPS_GCTL0_G2)
  949. c->options |= MIPS_CPU_GUESTCTL2;
  950. if (!(guestctl0 & MIPS_GCTL0_RAD)) {
  951. c->options |= MIPS_CPU_GUESTID;
  952. /*
  953. * Probe for Direct Root to Guest (DRG). Set GuestCtl1.RID = 0
  954. * first, otherwise all data accesses will be fully virtualised
  955. * as if they were performed by guest mode.
  956. */
  957. write_c0_guestctl1(0);
  958. tlbw_use_hazard();
  959. write_c0_guestctl0(guestctl0 | MIPS_GCTL0_DRG);
  960. back_to_back_c0_hazard();
  961. temp = read_c0_guestctl0();
  962. if (temp & MIPS_GCTL0_DRG) {
  963. write_c0_guestctl0(guestctl0);
  964. c->options |= MIPS_CPU_DRG;
  965. }
  966. }
  967. }
  968. static inline void cpu_probe_guestctl1(struct cpuinfo_mips *c)
  969. {
  970. if (cpu_has_guestid) {
  971. /* determine the number of bits of GuestID available */
  972. write_c0_guestctl1(MIPS_GCTL1_ID);
  973. back_to_back_c0_hazard();
  974. c->guestid_mask = (read_c0_guestctl1() & MIPS_GCTL1_ID)
  975. >> MIPS_GCTL1_ID_SHIFT;
  976. write_c0_guestctl1(0);
  977. }
  978. }
  979. static inline void cpu_probe_gtoffset(struct cpuinfo_mips *c)
  980. {
  981. /* determine the number of bits of GTOffset available */
  982. write_c0_gtoffset(0xffffffff);
  983. back_to_back_c0_hazard();
  984. c->gtoffset_mask = read_c0_gtoffset();
  985. write_c0_gtoffset(0);
  986. }
  987. static inline void cpu_probe_vz(struct cpuinfo_mips *c)
  988. {
  989. cpu_probe_guestctl0(c);
  990. if (cpu_has_guestctl1)
  991. cpu_probe_guestctl1(c);
  992. cpu_probe_gtoffset(c);
  993. decode_guest_configs(c);
  994. }
  995. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  996. | MIPS_CPU_COUNTER)
  997. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  998. {
  999. switch (c->processor_id & PRID_IMP_MASK) {
  1000. case PRID_IMP_R2000:
  1001. c->cputype = CPU_R2000;
  1002. __cpu_name[cpu] = "R2000";
  1003. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1004. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  1005. MIPS_CPU_NOFPUEX;
  1006. if (__cpu_has_fpu())
  1007. c->options |= MIPS_CPU_FPU;
  1008. c->tlbsize = 64;
  1009. break;
  1010. case PRID_IMP_R3000:
  1011. if ((c->processor_id & PRID_REV_MASK) == PRID_REV_R3000A) {
  1012. if (cpu_has_confreg()) {
  1013. c->cputype = CPU_R3081E;
  1014. __cpu_name[cpu] = "R3081";
  1015. } else {
  1016. c->cputype = CPU_R3000A;
  1017. __cpu_name[cpu] = "R3000A";
  1018. }
  1019. } else {
  1020. c->cputype = CPU_R3000;
  1021. __cpu_name[cpu] = "R3000";
  1022. }
  1023. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1024. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  1025. MIPS_CPU_NOFPUEX;
  1026. if (__cpu_has_fpu())
  1027. c->options |= MIPS_CPU_FPU;
  1028. c->tlbsize = 64;
  1029. break;
  1030. case PRID_IMP_R4000:
  1031. if (read_c0_config() & CONF_SC) {
  1032. if ((c->processor_id & PRID_REV_MASK) >=
  1033. PRID_REV_R4400) {
  1034. c->cputype = CPU_R4400PC;
  1035. __cpu_name[cpu] = "R4400PC";
  1036. } else {
  1037. c->cputype = CPU_R4000PC;
  1038. __cpu_name[cpu] = "R4000PC";
  1039. }
  1040. } else {
  1041. int cca = read_c0_config() & CONF_CM_CMASK;
  1042. int mc;
  1043. /*
  1044. * SC and MC versions can't be reliably told apart,
  1045. * but only the latter support coherent caching
  1046. * modes so assume the firmware has set the KSEG0
  1047. * coherency attribute reasonably (if uncached, we
  1048. * assume SC).
  1049. */
  1050. switch (cca) {
  1051. case CONF_CM_CACHABLE_CE:
  1052. case CONF_CM_CACHABLE_COW:
  1053. case CONF_CM_CACHABLE_CUW:
  1054. mc = 1;
  1055. break;
  1056. default:
  1057. mc = 0;
  1058. break;
  1059. }
  1060. if ((c->processor_id & PRID_REV_MASK) >=
  1061. PRID_REV_R4400) {
  1062. c->cputype = mc ? CPU_R4400MC : CPU_R4400SC;
  1063. __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC";
  1064. } else {
  1065. c->cputype = mc ? CPU_R4000MC : CPU_R4000SC;
  1066. __cpu_name[cpu] = mc ? "R4000MC" : "R4000SC";
  1067. }
  1068. }
  1069. set_isa(c, MIPS_CPU_ISA_III);
  1070. c->fpu_msk31 |= FPU_CSR_CONDX;
  1071. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1072. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  1073. MIPS_CPU_LLSC;
  1074. c->tlbsize = 48;
  1075. break;
  1076. case PRID_IMP_VR41XX:
  1077. set_isa(c, MIPS_CPU_ISA_III);
  1078. c->fpu_msk31 |= FPU_CSR_CONDX;
  1079. c->options = R4K_OPTS;
  1080. c->tlbsize = 32;
  1081. switch (c->processor_id & 0xf0) {
  1082. case PRID_REV_VR4111:
  1083. c->cputype = CPU_VR4111;
  1084. __cpu_name[cpu] = "NEC VR4111";
  1085. break;
  1086. case PRID_REV_VR4121:
  1087. c->cputype = CPU_VR4121;
  1088. __cpu_name[cpu] = "NEC VR4121";
  1089. break;
  1090. case PRID_REV_VR4122:
  1091. if ((c->processor_id & 0xf) < 0x3) {
  1092. c->cputype = CPU_VR4122;
  1093. __cpu_name[cpu] = "NEC VR4122";
  1094. } else {
  1095. c->cputype = CPU_VR4181A;
  1096. __cpu_name[cpu] = "NEC VR4181A";
  1097. }
  1098. break;
  1099. case PRID_REV_VR4130:
  1100. if ((c->processor_id & 0xf) < 0x4) {
  1101. c->cputype = CPU_VR4131;
  1102. __cpu_name[cpu] = "NEC VR4131";
  1103. } else {
  1104. c->cputype = CPU_VR4133;
  1105. c->options |= MIPS_CPU_LLSC;
  1106. __cpu_name[cpu] = "NEC VR4133";
  1107. }
  1108. break;
  1109. default:
  1110. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  1111. c->cputype = CPU_VR41XX;
  1112. __cpu_name[cpu] = "NEC Vr41xx";
  1113. break;
  1114. }
  1115. break;
  1116. case PRID_IMP_R4300:
  1117. c->cputype = CPU_R4300;
  1118. __cpu_name[cpu] = "R4300";
  1119. set_isa(c, MIPS_CPU_ISA_III);
  1120. c->fpu_msk31 |= FPU_CSR_CONDX;
  1121. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1122. MIPS_CPU_LLSC;
  1123. c->tlbsize = 32;
  1124. break;
  1125. case PRID_IMP_R4600:
  1126. c->cputype = CPU_R4600;
  1127. __cpu_name[cpu] = "R4600";
  1128. set_isa(c, MIPS_CPU_ISA_III);
  1129. c->fpu_msk31 |= FPU_CSR_CONDX;
  1130. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1131. MIPS_CPU_LLSC;
  1132. c->tlbsize = 48;
  1133. break;
  1134. #if 0
  1135. case PRID_IMP_R4650:
  1136. /*
  1137. * This processor doesn't have an MMU, so it's not
  1138. * "real easy" to run Linux on it. It is left purely
  1139. * for documentation. Commented out because it shares
  1140. * it's c0_prid id number with the TX3900.
  1141. */
  1142. c->cputype = CPU_R4650;
  1143. __cpu_name[cpu] = "R4650";
  1144. set_isa(c, MIPS_CPU_ISA_III);
  1145. c->fpu_msk31 |= FPU_CSR_CONDX;
  1146. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  1147. c->tlbsize = 48;
  1148. break;
  1149. #endif
  1150. case PRID_IMP_TX39:
  1151. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  1152. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  1153. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  1154. c->cputype = CPU_TX3927;
  1155. __cpu_name[cpu] = "TX3927";
  1156. c->tlbsize = 64;
  1157. } else {
  1158. switch (c->processor_id & PRID_REV_MASK) {
  1159. case PRID_REV_TX3912:
  1160. c->cputype = CPU_TX3912;
  1161. __cpu_name[cpu] = "TX3912";
  1162. c->tlbsize = 32;
  1163. break;
  1164. case PRID_REV_TX3922:
  1165. c->cputype = CPU_TX3922;
  1166. __cpu_name[cpu] = "TX3922";
  1167. c->tlbsize = 64;
  1168. break;
  1169. }
  1170. }
  1171. break;
  1172. case PRID_IMP_R4700:
  1173. c->cputype = CPU_R4700;
  1174. __cpu_name[cpu] = "R4700";
  1175. set_isa(c, MIPS_CPU_ISA_III);
  1176. c->fpu_msk31 |= FPU_CSR_CONDX;
  1177. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1178. MIPS_CPU_LLSC;
  1179. c->tlbsize = 48;
  1180. break;
  1181. case PRID_IMP_TX49:
  1182. c->cputype = CPU_TX49XX;
  1183. __cpu_name[cpu] = "R49XX";
  1184. set_isa(c, MIPS_CPU_ISA_III);
  1185. c->fpu_msk31 |= FPU_CSR_CONDX;
  1186. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  1187. if (!(c->processor_id & 0x08))
  1188. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  1189. c->tlbsize = 48;
  1190. break;
  1191. case PRID_IMP_R5000:
  1192. c->cputype = CPU_R5000;
  1193. __cpu_name[cpu] = "R5000";
  1194. set_isa(c, MIPS_CPU_ISA_IV);
  1195. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1196. MIPS_CPU_LLSC;
  1197. c->tlbsize = 48;
  1198. break;
  1199. case PRID_IMP_R5432:
  1200. c->cputype = CPU_R5432;
  1201. __cpu_name[cpu] = "R5432";
  1202. set_isa(c, MIPS_CPU_ISA_IV);
  1203. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1204. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  1205. c->tlbsize = 48;
  1206. break;
  1207. case PRID_IMP_R5500:
  1208. c->cputype = CPU_R5500;
  1209. __cpu_name[cpu] = "R5500";
  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_NEVADA:
  1216. c->cputype = CPU_NEVADA;
  1217. __cpu_name[cpu] = "Nevada";
  1218. set_isa(c, MIPS_CPU_ISA_IV);
  1219. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1220. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  1221. c->tlbsize = 48;
  1222. break;
  1223. case PRID_IMP_RM7000:
  1224. c->cputype = CPU_RM7000;
  1225. __cpu_name[cpu] = "RM7000";
  1226. set_isa(c, MIPS_CPU_ISA_IV);
  1227. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1228. MIPS_CPU_LLSC;
  1229. /*
  1230. * Undocumented RM7000: Bit 29 in the info register of
  1231. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  1232. * entries.
  1233. *
  1234. * 29 1 => 64 entry JTLB
  1235. * 0 => 48 entry JTLB
  1236. */
  1237. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  1238. break;
  1239. case PRID_IMP_R8000:
  1240. c->cputype = CPU_R8000;
  1241. __cpu_name[cpu] = "RM8000";
  1242. set_isa(c, MIPS_CPU_ISA_IV);
  1243. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  1244. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1245. MIPS_CPU_LLSC;
  1246. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  1247. break;
  1248. case PRID_IMP_R10000:
  1249. c->cputype = CPU_R10000;
  1250. __cpu_name[cpu] = "R10000";
  1251. set_isa(c, MIPS_CPU_ISA_IV);
  1252. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1253. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1254. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1255. MIPS_CPU_LLSC;
  1256. c->tlbsize = 64;
  1257. break;
  1258. case PRID_IMP_R12000:
  1259. c->cputype = CPU_R12000;
  1260. __cpu_name[cpu] = "R12000";
  1261. set_isa(c, MIPS_CPU_ISA_IV);
  1262. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1263. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1264. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1265. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  1266. c->tlbsize = 64;
  1267. break;
  1268. case PRID_IMP_R14000:
  1269. if (((c->processor_id >> 4) & 0x0f) > 2) {
  1270. c->cputype = CPU_R16000;
  1271. __cpu_name[cpu] = "R16000";
  1272. } else {
  1273. c->cputype = CPU_R14000;
  1274. __cpu_name[cpu] = "R14000";
  1275. }
  1276. set_isa(c, MIPS_CPU_ISA_IV);
  1277. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  1278. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  1279. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  1280. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  1281. c->tlbsize = 64;
  1282. break;
  1283. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  1284. switch (c->processor_id & PRID_REV_MASK) {
  1285. case PRID_REV_LOONGSON2E:
  1286. c->cputype = CPU_LOONGSON2;
  1287. __cpu_name[cpu] = "ICT Loongson-2";
  1288. set_elf_platform(cpu, "loongson2e");
  1289. set_isa(c, MIPS_CPU_ISA_III);
  1290. c->fpu_msk31 |= FPU_CSR_CONDX;
  1291. break;
  1292. case PRID_REV_LOONGSON2F:
  1293. c->cputype = CPU_LOONGSON2;
  1294. __cpu_name[cpu] = "ICT Loongson-2";
  1295. set_elf_platform(cpu, "loongson2f");
  1296. set_isa(c, MIPS_CPU_ISA_III);
  1297. c->fpu_msk31 |= FPU_CSR_CONDX;
  1298. break;
  1299. case PRID_REV_LOONGSON3A_R1:
  1300. c->cputype = CPU_LOONGSON3;
  1301. __cpu_name[cpu] = "ICT Loongson-3";
  1302. set_elf_platform(cpu, "loongson3a");
  1303. set_isa(c, MIPS_CPU_ISA_M64R1);
  1304. break;
  1305. case PRID_REV_LOONGSON3B_R1:
  1306. case PRID_REV_LOONGSON3B_R2:
  1307. c->cputype = CPU_LOONGSON3;
  1308. __cpu_name[cpu] = "ICT Loongson-3";
  1309. set_elf_platform(cpu, "loongson3b");
  1310. set_isa(c, MIPS_CPU_ISA_M64R1);
  1311. break;
  1312. }
  1313. c->options = R4K_OPTS |
  1314. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  1315. MIPS_CPU_32FPR;
  1316. c->tlbsize = 64;
  1317. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1318. break;
  1319. case PRID_IMP_LOONGSON_32: /* Loongson-1 */
  1320. decode_configs(c);
  1321. c->cputype = CPU_LOONGSON1;
  1322. switch (c->processor_id & PRID_REV_MASK) {
  1323. case PRID_REV_LOONGSON1B:
  1324. __cpu_name[cpu] = "Loongson 1B";
  1325. break;
  1326. }
  1327. break;
  1328. }
  1329. }
  1330. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  1331. {
  1332. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1333. switch (c->processor_id & PRID_IMP_MASK) {
  1334. case PRID_IMP_QEMU_GENERIC:
  1335. c->writecombine = _CACHE_UNCACHED;
  1336. c->cputype = CPU_QEMU_GENERIC;
  1337. __cpu_name[cpu] = "MIPS GENERIC QEMU";
  1338. break;
  1339. case PRID_IMP_4KC:
  1340. c->cputype = CPU_4KC;
  1341. c->writecombine = _CACHE_UNCACHED;
  1342. __cpu_name[cpu] = "MIPS 4Kc";
  1343. break;
  1344. case PRID_IMP_4KEC:
  1345. case PRID_IMP_4KECR2:
  1346. c->cputype = CPU_4KEC;
  1347. c->writecombine = _CACHE_UNCACHED;
  1348. __cpu_name[cpu] = "MIPS 4KEc";
  1349. break;
  1350. case PRID_IMP_4KSC:
  1351. case PRID_IMP_4KSD:
  1352. c->cputype = CPU_4KSC;
  1353. c->writecombine = _CACHE_UNCACHED;
  1354. __cpu_name[cpu] = "MIPS 4KSc";
  1355. break;
  1356. case PRID_IMP_5KC:
  1357. c->cputype = CPU_5KC;
  1358. c->writecombine = _CACHE_UNCACHED;
  1359. __cpu_name[cpu] = "MIPS 5Kc";
  1360. break;
  1361. case PRID_IMP_5KE:
  1362. c->cputype = CPU_5KE;
  1363. c->writecombine = _CACHE_UNCACHED;
  1364. __cpu_name[cpu] = "MIPS 5KE";
  1365. break;
  1366. case PRID_IMP_20KC:
  1367. c->cputype = CPU_20KC;
  1368. c->writecombine = _CACHE_UNCACHED;
  1369. __cpu_name[cpu] = "MIPS 20Kc";
  1370. break;
  1371. case PRID_IMP_24K:
  1372. c->cputype = CPU_24K;
  1373. c->writecombine = _CACHE_UNCACHED;
  1374. __cpu_name[cpu] = "MIPS 24Kc";
  1375. break;
  1376. case PRID_IMP_24KE:
  1377. c->cputype = CPU_24K;
  1378. c->writecombine = _CACHE_UNCACHED;
  1379. __cpu_name[cpu] = "MIPS 24KEc";
  1380. break;
  1381. case PRID_IMP_25KF:
  1382. c->cputype = CPU_25KF;
  1383. c->writecombine = _CACHE_UNCACHED;
  1384. __cpu_name[cpu] = "MIPS 25Kc";
  1385. break;
  1386. case PRID_IMP_34K:
  1387. c->cputype = CPU_34K;
  1388. c->writecombine = _CACHE_UNCACHED;
  1389. __cpu_name[cpu] = "MIPS 34Kc";
  1390. break;
  1391. case PRID_IMP_74K:
  1392. c->cputype = CPU_74K;
  1393. c->writecombine = _CACHE_UNCACHED;
  1394. __cpu_name[cpu] = "MIPS 74Kc";
  1395. break;
  1396. case PRID_IMP_M14KC:
  1397. c->cputype = CPU_M14KC;
  1398. c->writecombine = _CACHE_UNCACHED;
  1399. __cpu_name[cpu] = "MIPS M14Kc";
  1400. break;
  1401. case PRID_IMP_M14KEC:
  1402. c->cputype = CPU_M14KEC;
  1403. c->writecombine = _CACHE_UNCACHED;
  1404. __cpu_name[cpu] = "MIPS M14KEc";
  1405. break;
  1406. case PRID_IMP_1004K:
  1407. c->cputype = CPU_1004K;
  1408. c->writecombine = _CACHE_UNCACHED;
  1409. __cpu_name[cpu] = "MIPS 1004Kc";
  1410. break;
  1411. case PRID_IMP_1074K:
  1412. c->cputype = CPU_1074K;
  1413. c->writecombine = _CACHE_UNCACHED;
  1414. __cpu_name[cpu] = "MIPS 1074Kc";
  1415. break;
  1416. case PRID_IMP_INTERAPTIV_UP:
  1417. c->cputype = CPU_INTERAPTIV;
  1418. __cpu_name[cpu] = "MIPS interAptiv";
  1419. break;
  1420. case PRID_IMP_INTERAPTIV_MP:
  1421. c->cputype = CPU_INTERAPTIV;
  1422. __cpu_name[cpu] = "MIPS interAptiv (multi)";
  1423. break;
  1424. case PRID_IMP_PROAPTIV_UP:
  1425. c->cputype = CPU_PROAPTIV;
  1426. __cpu_name[cpu] = "MIPS proAptiv";
  1427. break;
  1428. case PRID_IMP_PROAPTIV_MP:
  1429. c->cputype = CPU_PROAPTIV;
  1430. __cpu_name[cpu] = "MIPS proAptiv (multi)";
  1431. break;
  1432. case PRID_IMP_P5600:
  1433. c->cputype = CPU_P5600;
  1434. __cpu_name[cpu] = "MIPS P5600";
  1435. break;
  1436. case PRID_IMP_P6600:
  1437. c->cputype = CPU_P6600;
  1438. __cpu_name[cpu] = "MIPS P6600";
  1439. break;
  1440. case PRID_IMP_I6400:
  1441. c->cputype = CPU_I6400;
  1442. __cpu_name[cpu] = "MIPS I6400";
  1443. break;
  1444. case PRID_IMP_I6500:
  1445. c->cputype = CPU_I6500;
  1446. __cpu_name[cpu] = "MIPS I6500";
  1447. break;
  1448. case PRID_IMP_M5150:
  1449. c->cputype = CPU_M5150;
  1450. __cpu_name[cpu] = "MIPS M5150";
  1451. break;
  1452. case PRID_IMP_M6250:
  1453. c->cputype = CPU_M6250;
  1454. __cpu_name[cpu] = "MIPS M6250";
  1455. break;
  1456. }
  1457. decode_configs(c);
  1458. spram_config();
  1459. switch (__get_cpu_type(c->cputype)) {
  1460. case CPU_I6500:
  1461. c->options |= MIPS_CPU_SHARED_FTLB_ENTRIES;
  1462. /* fall-through */
  1463. case CPU_I6400:
  1464. c->options |= MIPS_CPU_SHARED_FTLB_RAM;
  1465. /* fall-through */
  1466. default:
  1467. break;
  1468. }
  1469. }
  1470. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  1471. {
  1472. decode_configs(c);
  1473. switch (c->processor_id & PRID_IMP_MASK) {
  1474. case PRID_IMP_AU1_REV1:
  1475. case PRID_IMP_AU1_REV2:
  1476. c->cputype = CPU_ALCHEMY;
  1477. switch ((c->processor_id >> 24) & 0xff) {
  1478. case 0:
  1479. __cpu_name[cpu] = "Au1000";
  1480. break;
  1481. case 1:
  1482. __cpu_name[cpu] = "Au1500";
  1483. break;
  1484. case 2:
  1485. __cpu_name[cpu] = "Au1100";
  1486. break;
  1487. case 3:
  1488. __cpu_name[cpu] = "Au1550";
  1489. break;
  1490. case 4:
  1491. __cpu_name[cpu] = "Au1200";
  1492. if ((c->processor_id & PRID_REV_MASK) == 2)
  1493. __cpu_name[cpu] = "Au1250";
  1494. break;
  1495. case 5:
  1496. __cpu_name[cpu] = "Au1210";
  1497. break;
  1498. default:
  1499. __cpu_name[cpu] = "Au1xxx";
  1500. break;
  1501. }
  1502. break;
  1503. }
  1504. }
  1505. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  1506. {
  1507. decode_configs(c);
  1508. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1509. switch (c->processor_id & PRID_IMP_MASK) {
  1510. case PRID_IMP_SB1:
  1511. c->cputype = CPU_SB1;
  1512. __cpu_name[cpu] = "SiByte SB1";
  1513. /* FPU in pass1 is known to have issues. */
  1514. if ((c->processor_id & PRID_REV_MASK) < 0x02)
  1515. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  1516. break;
  1517. case PRID_IMP_SB1A:
  1518. c->cputype = CPU_SB1A;
  1519. __cpu_name[cpu] = "SiByte SB1A";
  1520. break;
  1521. }
  1522. }
  1523. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  1524. {
  1525. decode_configs(c);
  1526. switch (c->processor_id & PRID_IMP_MASK) {
  1527. case PRID_IMP_SR71000:
  1528. c->cputype = CPU_SR71000;
  1529. __cpu_name[cpu] = "Sandcraft SR71000";
  1530. c->scache.ways = 8;
  1531. c->tlbsize = 64;
  1532. break;
  1533. }
  1534. }
  1535. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  1536. {
  1537. decode_configs(c);
  1538. switch (c->processor_id & PRID_IMP_MASK) {
  1539. case PRID_IMP_PR4450:
  1540. c->cputype = CPU_PR4450;
  1541. __cpu_name[cpu] = "Philips PR4450";
  1542. set_isa(c, MIPS_CPU_ISA_M32R1);
  1543. break;
  1544. }
  1545. }
  1546. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  1547. {
  1548. decode_configs(c);
  1549. switch (c->processor_id & PRID_IMP_MASK) {
  1550. case PRID_IMP_BMIPS32_REV4:
  1551. case PRID_IMP_BMIPS32_REV8:
  1552. c->cputype = CPU_BMIPS32;
  1553. __cpu_name[cpu] = "Broadcom BMIPS32";
  1554. set_elf_platform(cpu, "bmips32");
  1555. break;
  1556. case PRID_IMP_BMIPS3300:
  1557. case PRID_IMP_BMIPS3300_ALT:
  1558. case PRID_IMP_BMIPS3300_BUG:
  1559. c->cputype = CPU_BMIPS3300;
  1560. __cpu_name[cpu] = "Broadcom BMIPS3300";
  1561. set_elf_platform(cpu, "bmips3300");
  1562. break;
  1563. case PRID_IMP_BMIPS43XX: {
  1564. int rev = c->processor_id & PRID_REV_MASK;
  1565. if (rev >= PRID_REV_BMIPS4380_LO &&
  1566. rev <= PRID_REV_BMIPS4380_HI) {
  1567. c->cputype = CPU_BMIPS4380;
  1568. __cpu_name[cpu] = "Broadcom BMIPS4380";
  1569. set_elf_platform(cpu, "bmips4380");
  1570. c->options |= MIPS_CPU_RIXI;
  1571. } else {
  1572. c->cputype = CPU_BMIPS4350;
  1573. __cpu_name[cpu] = "Broadcom BMIPS4350";
  1574. set_elf_platform(cpu, "bmips4350");
  1575. }
  1576. break;
  1577. }
  1578. case PRID_IMP_BMIPS5000:
  1579. case PRID_IMP_BMIPS5200:
  1580. c->cputype = CPU_BMIPS5000;
  1581. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_BMIPS5200)
  1582. __cpu_name[cpu] = "Broadcom BMIPS5200";
  1583. else
  1584. __cpu_name[cpu] = "Broadcom BMIPS5000";
  1585. set_elf_platform(cpu, "bmips5000");
  1586. c->options |= MIPS_CPU_ULRI | MIPS_CPU_RIXI;
  1587. break;
  1588. }
  1589. }
  1590. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  1591. {
  1592. decode_configs(c);
  1593. switch (c->processor_id & PRID_IMP_MASK) {
  1594. case PRID_IMP_CAVIUM_CN38XX:
  1595. case PRID_IMP_CAVIUM_CN31XX:
  1596. case PRID_IMP_CAVIUM_CN30XX:
  1597. c->cputype = CPU_CAVIUM_OCTEON;
  1598. __cpu_name[cpu] = "Cavium Octeon";
  1599. goto platform;
  1600. case PRID_IMP_CAVIUM_CN58XX:
  1601. case PRID_IMP_CAVIUM_CN56XX:
  1602. case PRID_IMP_CAVIUM_CN50XX:
  1603. case PRID_IMP_CAVIUM_CN52XX:
  1604. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  1605. __cpu_name[cpu] = "Cavium Octeon+";
  1606. platform:
  1607. set_elf_platform(cpu, "octeon");
  1608. break;
  1609. case PRID_IMP_CAVIUM_CN61XX:
  1610. case PRID_IMP_CAVIUM_CN63XX:
  1611. case PRID_IMP_CAVIUM_CN66XX:
  1612. case PRID_IMP_CAVIUM_CN68XX:
  1613. case PRID_IMP_CAVIUM_CNF71XX:
  1614. c->cputype = CPU_CAVIUM_OCTEON2;
  1615. __cpu_name[cpu] = "Cavium Octeon II";
  1616. set_elf_platform(cpu, "octeon2");
  1617. break;
  1618. case PRID_IMP_CAVIUM_CN70XX:
  1619. case PRID_IMP_CAVIUM_CN73XX:
  1620. case PRID_IMP_CAVIUM_CNF75XX:
  1621. case PRID_IMP_CAVIUM_CN78XX:
  1622. c->cputype = CPU_CAVIUM_OCTEON3;
  1623. __cpu_name[cpu] = "Cavium Octeon III";
  1624. set_elf_platform(cpu, "octeon3");
  1625. break;
  1626. default:
  1627. printk(KERN_INFO "Unknown Octeon chip!\n");
  1628. c->cputype = CPU_UNKNOWN;
  1629. break;
  1630. }
  1631. }
  1632. static inline void cpu_probe_loongson(struct cpuinfo_mips *c, unsigned int cpu)
  1633. {
  1634. switch (c->processor_id & PRID_IMP_MASK) {
  1635. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  1636. switch (c->processor_id & PRID_REV_MASK) {
  1637. case PRID_REV_LOONGSON3A_R2:
  1638. c->cputype = CPU_LOONGSON3;
  1639. __cpu_name[cpu] = "ICT Loongson-3";
  1640. set_elf_platform(cpu, "loongson3a");
  1641. set_isa(c, MIPS_CPU_ISA_M64R2);
  1642. break;
  1643. case PRID_REV_LOONGSON3A_R3:
  1644. c->cputype = CPU_LOONGSON3;
  1645. __cpu_name[cpu] = "ICT Loongson-3";
  1646. set_elf_platform(cpu, "loongson3a");
  1647. set_isa(c, MIPS_CPU_ISA_M64R2);
  1648. break;
  1649. }
  1650. decode_configs(c);
  1651. c->options |= MIPS_CPU_FTLB | MIPS_CPU_TLBINV | MIPS_CPU_LDPTE;
  1652. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1653. break;
  1654. default:
  1655. panic("Unknown Loongson Processor ID!");
  1656. break;
  1657. }
  1658. }
  1659. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  1660. {
  1661. decode_configs(c);
  1662. /* JZRISC does not implement the CP0 counter. */
  1663. c->options &= ~MIPS_CPU_COUNTER;
  1664. BUG_ON(!__builtin_constant_p(cpu_has_counter) || cpu_has_counter);
  1665. switch (c->processor_id & PRID_IMP_MASK) {
  1666. case PRID_IMP_JZRISC:
  1667. c->cputype = CPU_JZRISC;
  1668. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1669. __cpu_name[cpu] = "Ingenic JZRISC";
  1670. break;
  1671. default:
  1672. panic("Unknown Ingenic Processor ID!");
  1673. break;
  1674. }
  1675. }
  1676. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  1677. {
  1678. decode_configs(c);
  1679. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_NETLOGIC_AU13XX) {
  1680. c->cputype = CPU_ALCHEMY;
  1681. __cpu_name[cpu] = "Au1300";
  1682. /* following stuff is not for Alchemy */
  1683. return;
  1684. }
  1685. c->options = (MIPS_CPU_TLB |
  1686. MIPS_CPU_4KEX |
  1687. MIPS_CPU_COUNTER |
  1688. MIPS_CPU_DIVEC |
  1689. MIPS_CPU_WATCH |
  1690. MIPS_CPU_EJTAG |
  1691. MIPS_CPU_LLSC);
  1692. switch (c->processor_id & PRID_IMP_MASK) {
  1693. case PRID_IMP_NETLOGIC_XLP2XX:
  1694. case PRID_IMP_NETLOGIC_XLP9XX:
  1695. case PRID_IMP_NETLOGIC_XLP5XX:
  1696. c->cputype = CPU_XLP;
  1697. __cpu_name[cpu] = "Broadcom XLPII";
  1698. break;
  1699. case PRID_IMP_NETLOGIC_XLP8XX:
  1700. case PRID_IMP_NETLOGIC_XLP3XX:
  1701. c->cputype = CPU_XLP;
  1702. __cpu_name[cpu] = "Netlogic XLP";
  1703. break;
  1704. case PRID_IMP_NETLOGIC_XLR732:
  1705. case PRID_IMP_NETLOGIC_XLR716:
  1706. case PRID_IMP_NETLOGIC_XLR532:
  1707. case PRID_IMP_NETLOGIC_XLR308:
  1708. case PRID_IMP_NETLOGIC_XLR532C:
  1709. case PRID_IMP_NETLOGIC_XLR516C:
  1710. case PRID_IMP_NETLOGIC_XLR508C:
  1711. case PRID_IMP_NETLOGIC_XLR308C:
  1712. c->cputype = CPU_XLR;
  1713. __cpu_name[cpu] = "Netlogic XLR";
  1714. break;
  1715. case PRID_IMP_NETLOGIC_XLS608:
  1716. case PRID_IMP_NETLOGIC_XLS408:
  1717. case PRID_IMP_NETLOGIC_XLS404:
  1718. case PRID_IMP_NETLOGIC_XLS208:
  1719. case PRID_IMP_NETLOGIC_XLS204:
  1720. case PRID_IMP_NETLOGIC_XLS108:
  1721. case PRID_IMP_NETLOGIC_XLS104:
  1722. case PRID_IMP_NETLOGIC_XLS616B:
  1723. case PRID_IMP_NETLOGIC_XLS608B:
  1724. case PRID_IMP_NETLOGIC_XLS416B:
  1725. case PRID_IMP_NETLOGIC_XLS412B:
  1726. case PRID_IMP_NETLOGIC_XLS408B:
  1727. case PRID_IMP_NETLOGIC_XLS404B:
  1728. c->cputype = CPU_XLR;
  1729. __cpu_name[cpu] = "Netlogic XLS";
  1730. break;
  1731. default:
  1732. pr_info("Unknown Netlogic chip id [%02x]!\n",
  1733. c->processor_id);
  1734. c->cputype = CPU_XLR;
  1735. break;
  1736. }
  1737. if (c->cputype == CPU_XLP) {
  1738. set_isa(c, MIPS_CPU_ISA_M64R2);
  1739. c->options |= (MIPS_CPU_FPU | MIPS_CPU_ULRI | MIPS_CPU_MCHECK);
  1740. /* This will be updated again after all threads are woken up */
  1741. c->tlbsize = ((read_c0_config6() >> 16) & 0xffff) + 1;
  1742. } else {
  1743. set_isa(c, MIPS_CPU_ISA_M64R1);
  1744. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  1745. }
  1746. c->kscratch_mask = 0xf;
  1747. }
  1748. #ifdef CONFIG_64BIT
  1749. /* For use by uaccess.h */
  1750. u64 __ua_limit;
  1751. EXPORT_SYMBOL(__ua_limit);
  1752. #endif
  1753. const char *__cpu_name[NR_CPUS];
  1754. const char *__elf_platform;
  1755. void cpu_probe(void)
  1756. {
  1757. struct cpuinfo_mips *c = &current_cpu_data;
  1758. unsigned int cpu = smp_processor_id();
  1759. /*
  1760. * Set a default elf platform, cpu probe may later
  1761. * overwrite it with a more precise value
  1762. */
  1763. set_elf_platform(cpu, "mips");
  1764. c->processor_id = PRID_IMP_UNKNOWN;
  1765. c->fpu_id = FPIR_IMP_NONE;
  1766. c->cputype = CPU_UNKNOWN;
  1767. c->writecombine = _CACHE_UNCACHED;
  1768. c->fpu_csr31 = FPU_CSR_RN;
  1769. c->fpu_msk31 = FPU_CSR_RSVD | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  1770. c->processor_id = read_c0_prid();
  1771. switch (c->processor_id & PRID_COMP_MASK) {
  1772. case PRID_COMP_LEGACY:
  1773. cpu_probe_legacy(c, cpu);
  1774. break;
  1775. case PRID_COMP_MIPS:
  1776. cpu_probe_mips(c, cpu);
  1777. break;
  1778. case PRID_COMP_ALCHEMY:
  1779. cpu_probe_alchemy(c, cpu);
  1780. break;
  1781. case PRID_COMP_SIBYTE:
  1782. cpu_probe_sibyte(c, cpu);
  1783. break;
  1784. case PRID_COMP_BROADCOM:
  1785. cpu_probe_broadcom(c, cpu);
  1786. break;
  1787. case PRID_COMP_SANDCRAFT:
  1788. cpu_probe_sandcraft(c, cpu);
  1789. break;
  1790. case PRID_COMP_NXP:
  1791. cpu_probe_nxp(c, cpu);
  1792. break;
  1793. case PRID_COMP_CAVIUM:
  1794. cpu_probe_cavium(c, cpu);
  1795. break;
  1796. case PRID_COMP_LOONGSON:
  1797. cpu_probe_loongson(c, cpu);
  1798. break;
  1799. case PRID_COMP_INGENIC_D0:
  1800. case PRID_COMP_INGENIC_D1:
  1801. case PRID_COMP_INGENIC_E1:
  1802. cpu_probe_ingenic(c, cpu);
  1803. break;
  1804. case PRID_COMP_NETLOGIC:
  1805. cpu_probe_netlogic(c, cpu);
  1806. break;
  1807. }
  1808. BUG_ON(!__cpu_name[cpu]);
  1809. BUG_ON(c->cputype == CPU_UNKNOWN);
  1810. /*
  1811. * Platform code can force the cpu type to optimize code
  1812. * generation. In that case be sure the cpu type is correctly
  1813. * manually setup otherwise it could trigger some nasty bugs.
  1814. */
  1815. BUG_ON(current_cpu_type() != c->cputype);
  1816. if (cpu_has_rixi) {
  1817. /* Enable the RIXI exceptions */
  1818. set_c0_pagegrain(PG_IEC);
  1819. back_to_back_c0_hazard();
  1820. /* Verify the IEC bit is set */
  1821. if (read_c0_pagegrain() & PG_IEC)
  1822. c->options |= MIPS_CPU_RIXIEX;
  1823. }
  1824. if (mips_fpu_disabled)
  1825. c->options &= ~MIPS_CPU_FPU;
  1826. if (mips_dsp_disabled)
  1827. c->ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  1828. if (mips_htw_disabled) {
  1829. c->options &= ~MIPS_CPU_HTW;
  1830. write_c0_pwctl(read_c0_pwctl() &
  1831. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  1832. }
  1833. if (c->options & MIPS_CPU_FPU)
  1834. cpu_set_fpu_opts(c);
  1835. else
  1836. cpu_set_nofpu_opts(c);
  1837. if (cpu_has_bp_ghist)
  1838. write_c0_r10k_diag(read_c0_r10k_diag() |
  1839. R10K_DIAG_E_GHIST);
  1840. if (cpu_has_mips_r2_r6) {
  1841. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1842. /* R2 has Performance Counter Interrupt indicator */
  1843. c->options |= MIPS_CPU_PCI;
  1844. }
  1845. else
  1846. c->srsets = 1;
  1847. if (cpu_has_mips_r6)
  1848. elf_hwcap |= HWCAP_MIPS_R6;
  1849. if (cpu_has_msa) {
  1850. c->msa_id = cpu_get_msa_id();
  1851. WARN(c->msa_id & MSA_IR_WRPF,
  1852. "Vector register partitioning unimplemented!");
  1853. elf_hwcap |= HWCAP_MIPS_MSA;
  1854. }
  1855. if (cpu_has_vz)
  1856. cpu_probe_vz(c);
  1857. cpu_probe_vmbits(c);
  1858. #ifdef CONFIG_64BIT
  1859. if (cpu == 0)
  1860. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1861. #endif
  1862. }
  1863. void cpu_report(void)
  1864. {
  1865. struct cpuinfo_mips *c = &current_cpu_data;
  1866. pr_info("CPU%d revision is: %08x (%s)\n",
  1867. smp_processor_id(), c->processor_id, cpu_name_string());
  1868. if (c->options & MIPS_CPU_FPU)
  1869. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1870. if (cpu_has_msa)
  1871. pr_info("MSA revision is: %08x\n", c->msa_id);
  1872. }
  1873. void cpu_set_cluster(struct cpuinfo_mips *cpuinfo, unsigned int cluster)
  1874. {
  1875. /* Ensure the core number fits in the field */
  1876. WARN_ON(cluster > (MIPS_GLOBALNUMBER_CLUSTER >>
  1877. MIPS_GLOBALNUMBER_CLUSTER_SHF));
  1878. cpuinfo->globalnumber &= ~MIPS_GLOBALNUMBER_CLUSTER;
  1879. cpuinfo->globalnumber |= cluster << MIPS_GLOBALNUMBER_CLUSTER_SHF;
  1880. }
  1881. void cpu_set_core(struct cpuinfo_mips *cpuinfo, unsigned int core)
  1882. {
  1883. /* Ensure the core number fits in the field */
  1884. WARN_ON(core > (MIPS_GLOBALNUMBER_CORE >> MIPS_GLOBALNUMBER_CORE_SHF));
  1885. cpuinfo->globalnumber &= ~MIPS_GLOBALNUMBER_CORE;
  1886. cpuinfo->globalnumber |= core << MIPS_GLOBALNUMBER_CORE_SHF;
  1887. }
  1888. void cpu_set_vpe_id(struct cpuinfo_mips *cpuinfo, unsigned int vpe)
  1889. {
  1890. /* Ensure the VP(E) ID fits in the field */
  1891. WARN_ON(vpe > (MIPS_GLOBALNUMBER_VP >> MIPS_GLOBALNUMBER_VP_SHF));
  1892. /* Ensure we're not using VP(E)s without support */
  1893. WARN_ON(vpe && !IS_ENABLED(CONFIG_MIPS_MT_SMP) &&
  1894. !IS_ENABLED(CONFIG_CPU_MIPSR6));
  1895. cpuinfo->globalnumber &= ~MIPS_GLOBALNUMBER_VP;
  1896. cpuinfo->globalnumber |= vpe << MIPS_GLOBALNUMBER_VP_SHF;
  1897. }