cpu-probe.c 52 KB

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