cpu-probe.c 51 KB

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