cpu-probe.c 51 KB

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