cpu-probe.c 51 KB

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