cpu-probe.c 52 KB

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