cpu-probe.c 51 KB

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