cpu-probe.c 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560
  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. * Set the FIR feature flags for the FPU emulator.
  87. */
  88. static void cpu_set_nofpu_id(struct cpuinfo_mips *c)
  89. {
  90. u32 value;
  91. value = 0;
  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. value |= MIPS_FPIR_D | MIPS_FPIR_S;
  96. if (c->isa_level & (MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  97. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6))
  98. value |= MIPS_FPIR_F64 | MIPS_FPIR_L | MIPS_FPIR_W;
  99. c->fpu_id = value;
  100. }
  101. /* Determined FPU emulator mask to use for the boot CPU with "nofpu". */
  102. static unsigned int mips_nofpu_msk31;
  103. /*
  104. * Set options for FPU hardware.
  105. */
  106. static void cpu_set_fpu_opts(struct cpuinfo_mips *c)
  107. {
  108. c->fpu_id = cpu_get_fpu_id();
  109. mips_nofpu_msk31 = c->fpu_msk31;
  110. if (c->isa_level & (MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1 |
  111. MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2 |
  112. MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6)) {
  113. if (c->fpu_id & MIPS_FPIR_3D)
  114. c->ases |= MIPS_ASE_MIPS3D;
  115. if (c->fpu_id & MIPS_FPIR_FREP)
  116. c->options |= MIPS_CPU_FRE;
  117. }
  118. cpu_set_fpu_fcsr_mask(c);
  119. }
  120. /*
  121. * Set options for the FPU emulator.
  122. */
  123. static void cpu_set_nofpu_opts(struct cpuinfo_mips *c)
  124. {
  125. c->options &= ~MIPS_CPU_FPU;
  126. c->fpu_msk31 = mips_nofpu_msk31;
  127. cpu_set_nofpu_id(c);
  128. }
  129. static int mips_fpu_disabled;
  130. static int __init fpu_disable(char *s)
  131. {
  132. cpu_set_nofpu_opts(&boot_cpu_data);
  133. mips_fpu_disabled = 1;
  134. return 1;
  135. }
  136. __setup("nofpu", fpu_disable);
  137. int mips_dsp_disabled;
  138. static int __init dsp_disable(char *s)
  139. {
  140. cpu_data[0].ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  141. mips_dsp_disabled = 1;
  142. return 1;
  143. }
  144. __setup("nodsp", dsp_disable);
  145. static int mips_htw_disabled;
  146. static int __init htw_disable(char *s)
  147. {
  148. mips_htw_disabled = 1;
  149. cpu_data[0].options &= ~MIPS_CPU_HTW;
  150. write_c0_pwctl(read_c0_pwctl() &
  151. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  152. return 1;
  153. }
  154. __setup("nohtw", htw_disable);
  155. static int mips_ftlb_disabled;
  156. static int mips_has_ftlb_configured;
  157. static int set_ftlb_enable(struct cpuinfo_mips *c, int enable);
  158. static int __init ftlb_disable(char *s)
  159. {
  160. unsigned int config4, mmuextdef;
  161. /*
  162. * If the core hasn't done any FTLB configuration, there is nothing
  163. * for us to do here.
  164. */
  165. if (!mips_has_ftlb_configured)
  166. return 1;
  167. /* Disable it in the boot cpu */
  168. if (set_ftlb_enable(&cpu_data[0], 0)) {
  169. pr_warn("Can't turn FTLB off\n");
  170. return 1;
  171. }
  172. back_to_back_c0_hazard();
  173. config4 = read_c0_config4();
  174. /* Check that FTLB has been disabled */
  175. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  176. /* MMUSIZEEXT == VTLB ON, FTLB OFF */
  177. if (mmuextdef == MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT) {
  178. /* This should never happen */
  179. pr_warn("FTLB could not be disabled!\n");
  180. return 1;
  181. }
  182. mips_ftlb_disabled = 1;
  183. mips_has_ftlb_configured = 0;
  184. /*
  185. * noftlb is mainly used for debug purposes so print
  186. * an informative message instead of using pr_debug()
  187. */
  188. pr_info("FTLB has been disabled\n");
  189. /*
  190. * Some of these bits are duplicated in the decode_config4.
  191. * MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT is the only possible case
  192. * once FTLB has been disabled so undo what decode_config4 did.
  193. */
  194. cpu_data[0].tlbsize -= cpu_data[0].tlbsizeftlbways *
  195. cpu_data[0].tlbsizeftlbsets;
  196. cpu_data[0].tlbsizeftlbsets = 0;
  197. cpu_data[0].tlbsizeftlbways = 0;
  198. return 1;
  199. }
  200. __setup("noftlb", ftlb_disable);
  201. static inline void check_errata(void)
  202. {
  203. struct cpuinfo_mips *c = &current_cpu_data;
  204. switch (current_cpu_type()) {
  205. case CPU_34K:
  206. /*
  207. * Erratum "RPS May Cause Incorrect Instruction Execution"
  208. * This code only handles VPE0, any SMP/RTOS code
  209. * making use of VPE1 will be responsable for that VPE.
  210. */
  211. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  212. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. void __init check_bugs32(void)
  219. {
  220. check_errata();
  221. }
  222. /*
  223. * Probe whether cpu has config register by trying to play with
  224. * alternate cache bit and see whether it matters.
  225. * It's used by cpu_probe to distinguish between R3000A and R3081.
  226. */
  227. static inline int cpu_has_confreg(void)
  228. {
  229. #ifdef CONFIG_CPU_R3000
  230. extern unsigned long r3k_cache_size(unsigned long);
  231. unsigned long size1, size2;
  232. unsigned long cfg = read_c0_conf();
  233. size1 = r3k_cache_size(ST0_ISC);
  234. write_c0_conf(cfg ^ R30XX_CONF_AC);
  235. size2 = r3k_cache_size(ST0_ISC);
  236. write_c0_conf(cfg);
  237. return size1 != size2;
  238. #else
  239. return 0;
  240. #endif
  241. }
  242. static inline void set_elf_platform(int cpu, const char *plat)
  243. {
  244. if (cpu == 0)
  245. __elf_platform = plat;
  246. }
  247. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  248. {
  249. #ifdef __NEED_VMBITS_PROBE
  250. write_c0_entryhi(0x3fffffffffffe000ULL);
  251. back_to_back_c0_hazard();
  252. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  253. #endif
  254. }
  255. static void set_isa(struct cpuinfo_mips *c, unsigned int isa)
  256. {
  257. switch (isa) {
  258. case MIPS_CPU_ISA_M64R2:
  259. c->isa_level |= MIPS_CPU_ISA_M32R2 | MIPS_CPU_ISA_M64R2;
  260. case MIPS_CPU_ISA_M64R1:
  261. c->isa_level |= MIPS_CPU_ISA_M32R1 | MIPS_CPU_ISA_M64R1;
  262. case MIPS_CPU_ISA_V:
  263. c->isa_level |= MIPS_CPU_ISA_V;
  264. case MIPS_CPU_ISA_IV:
  265. c->isa_level |= MIPS_CPU_ISA_IV;
  266. case MIPS_CPU_ISA_III:
  267. c->isa_level |= MIPS_CPU_ISA_II | MIPS_CPU_ISA_III;
  268. break;
  269. /* R6 incompatible with everything else */
  270. case MIPS_CPU_ISA_M64R6:
  271. c->isa_level |= MIPS_CPU_ISA_M32R6 | MIPS_CPU_ISA_M64R6;
  272. case MIPS_CPU_ISA_M32R6:
  273. c->isa_level |= MIPS_CPU_ISA_M32R6;
  274. /* Break here so we don't add incompatible ISAs */
  275. break;
  276. case MIPS_CPU_ISA_M32R2:
  277. c->isa_level |= MIPS_CPU_ISA_M32R2;
  278. case MIPS_CPU_ISA_M32R1:
  279. c->isa_level |= MIPS_CPU_ISA_M32R1;
  280. case MIPS_CPU_ISA_II:
  281. c->isa_level |= MIPS_CPU_ISA_II;
  282. break;
  283. }
  284. }
  285. static char unknown_isa[] = KERN_ERR \
  286. "Unsupported ISA type, c0.config0: %d.";
  287. static unsigned int calculate_ftlb_probability(struct cpuinfo_mips *c)
  288. {
  289. unsigned int probability = c->tlbsize / c->tlbsizevtlb;
  290. /*
  291. * 0 = All TLBWR instructions go to FTLB
  292. * 1 = 15:1: For every 16 TBLWR instructions, 15 go to the
  293. * FTLB and 1 goes to the VTLB.
  294. * 2 = 7:1: As above with 7:1 ratio.
  295. * 3 = 3:1: As above with 3:1 ratio.
  296. *
  297. * Use the linear midpoint as the probability threshold.
  298. */
  299. if (probability >= 12)
  300. return 1;
  301. else if (probability >= 6)
  302. return 2;
  303. else
  304. /*
  305. * So FTLB is less than 4 times bigger than VTLB.
  306. * A 3:1 ratio can still be useful though.
  307. */
  308. return 3;
  309. }
  310. static int set_ftlb_enable(struct cpuinfo_mips *c, int enable)
  311. {
  312. unsigned int config;
  313. /* It's implementation dependent how the FTLB can be enabled */
  314. switch (c->cputype) {
  315. case CPU_PROAPTIV:
  316. case CPU_P5600:
  317. /* proAptiv & related cores use Config6 to enable the FTLB */
  318. config = read_c0_config6();
  319. /* Clear the old probability value */
  320. config &= ~(3 << MIPS_CONF6_FTLBP_SHIFT);
  321. if (enable)
  322. /* Enable FTLB */
  323. write_c0_config6(config |
  324. (calculate_ftlb_probability(c)
  325. << MIPS_CONF6_FTLBP_SHIFT)
  326. | MIPS_CONF6_FTLBEN);
  327. else
  328. /* Disable FTLB */
  329. write_c0_config6(config & ~MIPS_CONF6_FTLBEN);
  330. break;
  331. case CPU_I6400:
  332. /* I6400 & related cores use Config7 to configure FTLB */
  333. config = read_c0_config7();
  334. /* Clear the old probability value */
  335. config &= ~(3 << MIPS_CONF7_FTLBP_SHIFT);
  336. write_c0_config7(config | (calculate_ftlb_probability(c)
  337. << MIPS_CONF7_FTLBP_SHIFT));
  338. break;
  339. default:
  340. return 1;
  341. }
  342. return 0;
  343. }
  344. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  345. {
  346. unsigned int config0;
  347. int isa, mt;
  348. config0 = read_c0_config();
  349. /*
  350. * Look for Standard TLB or Dual VTLB and FTLB
  351. */
  352. mt = config0 & MIPS_CONF_MT;
  353. if (mt == MIPS_CONF_MT_TLB)
  354. c->options |= MIPS_CPU_TLB;
  355. else if (mt == MIPS_CONF_MT_FTLB)
  356. c->options |= MIPS_CPU_TLB | MIPS_CPU_FTLB;
  357. isa = (config0 & MIPS_CONF_AT) >> 13;
  358. switch (isa) {
  359. case 0:
  360. switch ((config0 & MIPS_CONF_AR) >> 10) {
  361. case 0:
  362. set_isa(c, MIPS_CPU_ISA_M32R1);
  363. break;
  364. case 1:
  365. set_isa(c, MIPS_CPU_ISA_M32R2);
  366. break;
  367. case 2:
  368. set_isa(c, MIPS_CPU_ISA_M32R6);
  369. break;
  370. default:
  371. goto unknown;
  372. }
  373. break;
  374. case 2:
  375. switch ((config0 & MIPS_CONF_AR) >> 10) {
  376. case 0:
  377. set_isa(c, MIPS_CPU_ISA_M64R1);
  378. break;
  379. case 1:
  380. set_isa(c, MIPS_CPU_ISA_M64R2);
  381. break;
  382. case 2:
  383. set_isa(c, MIPS_CPU_ISA_M64R6);
  384. break;
  385. default:
  386. goto unknown;
  387. }
  388. break;
  389. default:
  390. goto unknown;
  391. }
  392. return config0 & MIPS_CONF_M;
  393. unknown:
  394. panic(unknown_isa, config0);
  395. }
  396. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  397. {
  398. unsigned int config1;
  399. config1 = read_c0_config1();
  400. if (config1 & MIPS_CONF1_MD)
  401. c->ases |= MIPS_ASE_MDMX;
  402. if (config1 & MIPS_CONF1_WR)
  403. c->options |= MIPS_CPU_WATCH;
  404. if (config1 & MIPS_CONF1_CA)
  405. c->ases |= MIPS_ASE_MIPS16;
  406. if (config1 & MIPS_CONF1_EP)
  407. c->options |= MIPS_CPU_EJTAG;
  408. if (config1 & MIPS_CONF1_FP) {
  409. c->options |= MIPS_CPU_FPU;
  410. c->options |= MIPS_CPU_32FPR;
  411. }
  412. if (cpu_has_tlb) {
  413. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  414. c->tlbsizevtlb = c->tlbsize;
  415. c->tlbsizeftlbsets = 0;
  416. }
  417. return config1 & MIPS_CONF_M;
  418. }
  419. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  420. {
  421. unsigned int config2;
  422. config2 = read_c0_config2();
  423. if (config2 & MIPS_CONF2_SL)
  424. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  425. return config2 & MIPS_CONF_M;
  426. }
  427. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  428. {
  429. unsigned int config3;
  430. config3 = read_c0_config3();
  431. if (config3 & MIPS_CONF3_SM) {
  432. c->ases |= MIPS_ASE_SMARTMIPS;
  433. c->options |= MIPS_CPU_RIXI;
  434. }
  435. if (config3 & MIPS_CONF3_RXI)
  436. c->options |= MIPS_CPU_RIXI;
  437. if (config3 & MIPS_CONF3_DSP)
  438. c->ases |= MIPS_ASE_DSP;
  439. if (config3 & MIPS_CONF3_DSP2P)
  440. c->ases |= MIPS_ASE_DSP2P;
  441. if (config3 & MIPS_CONF3_VINT)
  442. c->options |= MIPS_CPU_VINT;
  443. if (config3 & MIPS_CONF3_VEIC)
  444. c->options |= MIPS_CPU_VEIC;
  445. if (config3 & MIPS_CONF3_MT)
  446. c->ases |= MIPS_ASE_MIPSMT;
  447. if (config3 & MIPS_CONF3_ULRI)
  448. c->options |= MIPS_CPU_ULRI;
  449. if (config3 & MIPS_CONF3_ISA)
  450. c->options |= MIPS_CPU_MICROMIPS;
  451. if (config3 & MIPS_CONF3_VZ)
  452. c->ases |= MIPS_ASE_VZ;
  453. if (config3 & MIPS_CONF3_SC)
  454. c->options |= MIPS_CPU_SEGMENTS;
  455. if (config3 & MIPS_CONF3_MSA)
  456. c->ases |= MIPS_ASE_MSA;
  457. /* Only tested on 32-bit cores */
  458. if ((config3 & MIPS_CONF3_PW) && config_enabled(CONFIG_32BIT)) {
  459. c->htw_seq = 0;
  460. c->options |= MIPS_CPU_HTW;
  461. }
  462. if (config3 & MIPS_CONF3_CDMM)
  463. c->options |= MIPS_CPU_CDMM;
  464. if (config3 & MIPS_CONF3_SP)
  465. c->options |= MIPS_CPU_SP;
  466. return config3 & MIPS_CONF_M;
  467. }
  468. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  469. {
  470. unsigned int config4;
  471. unsigned int newcf4;
  472. unsigned int mmuextdef;
  473. unsigned int ftlb_page = MIPS_CONF4_FTLBPAGESIZE;
  474. config4 = read_c0_config4();
  475. if (cpu_has_tlb) {
  476. if (((config4 & MIPS_CONF4_IE) >> 29) == 2)
  477. c->options |= MIPS_CPU_TLBINV;
  478. /*
  479. * R6 has dropped the MMUExtDef field from config4.
  480. * On R6 the fields always describe the FTLB, and only if it is
  481. * present according to Config.MT.
  482. */
  483. if (!cpu_has_mips_r6)
  484. mmuextdef = config4 & MIPS_CONF4_MMUEXTDEF;
  485. else if (cpu_has_ftlb)
  486. mmuextdef = MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT;
  487. else
  488. mmuextdef = 0;
  489. switch (mmuextdef) {
  490. case MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT:
  491. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  492. c->tlbsizevtlb = c->tlbsize;
  493. break;
  494. case MIPS_CONF4_MMUEXTDEF_VTLBSIZEEXT:
  495. c->tlbsizevtlb +=
  496. ((config4 & MIPS_CONF4_VTLBSIZEEXT) >>
  497. MIPS_CONF4_VTLBSIZEEXT_SHIFT) * 0x40;
  498. c->tlbsize = c->tlbsizevtlb;
  499. ftlb_page = MIPS_CONF4_VFTLBPAGESIZE;
  500. /* fall through */
  501. case MIPS_CONF4_MMUEXTDEF_FTLBSIZEEXT:
  502. if (mips_ftlb_disabled)
  503. break;
  504. newcf4 = (config4 & ~ftlb_page) |
  505. (page_size_ftlb(mmuextdef) <<
  506. MIPS_CONF4_FTLBPAGESIZE_SHIFT);
  507. write_c0_config4(newcf4);
  508. back_to_back_c0_hazard();
  509. config4 = read_c0_config4();
  510. if (config4 != newcf4) {
  511. pr_err("PAGE_SIZE 0x%lx is not supported by FTLB (config4=0x%x)\n",
  512. PAGE_SIZE, config4);
  513. /* Switch FTLB off */
  514. set_ftlb_enable(c, 0);
  515. break;
  516. }
  517. c->tlbsizeftlbsets = 1 <<
  518. ((config4 & MIPS_CONF4_FTLBSETS) >>
  519. MIPS_CONF4_FTLBSETS_SHIFT);
  520. c->tlbsizeftlbways = ((config4 & MIPS_CONF4_FTLBWAYS) >>
  521. MIPS_CONF4_FTLBWAYS_SHIFT) + 2;
  522. c->tlbsize += c->tlbsizeftlbways * c->tlbsizeftlbsets;
  523. mips_has_ftlb_configured = 1;
  524. break;
  525. }
  526. }
  527. c->kscratch_mask = (config4 >> 16) & 0xff;
  528. return config4 & MIPS_CONF_M;
  529. }
  530. static inline unsigned int decode_config5(struct cpuinfo_mips *c)
  531. {
  532. unsigned int config5;
  533. config5 = read_c0_config5();
  534. config5 &= ~(MIPS_CONF5_UFR | MIPS_CONF5_UFE);
  535. write_c0_config5(config5);
  536. if (config5 & MIPS_CONF5_EVA)
  537. c->options |= MIPS_CPU_EVA;
  538. if (config5 & MIPS_CONF5_MRP)
  539. c->options |= MIPS_CPU_MAAR;
  540. if (config5 & MIPS_CONF5_LLB)
  541. c->options |= MIPS_CPU_RW_LLB;
  542. #ifdef CONFIG_XPA
  543. if (config5 & MIPS_CONF5_MVH)
  544. c->options |= MIPS_CPU_XPA;
  545. #endif
  546. return config5 & MIPS_CONF_M;
  547. }
  548. static void decode_configs(struct cpuinfo_mips *c)
  549. {
  550. int ok;
  551. /* MIPS32 or MIPS64 compliant CPU. */
  552. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  553. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  554. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  555. /* Enable FTLB if present and not disabled */
  556. set_ftlb_enable(c, !mips_ftlb_disabled);
  557. ok = decode_config0(c); /* Read Config registers. */
  558. BUG_ON(!ok); /* Arch spec violation! */
  559. if (ok)
  560. ok = decode_config1(c);
  561. if (ok)
  562. ok = decode_config2(c);
  563. if (ok)
  564. ok = decode_config3(c);
  565. if (ok)
  566. ok = decode_config4(c);
  567. if (ok)
  568. ok = decode_config5(c);
  569. mips_probe_watch_registers(c);
  570. if (cpu_has_rixi) {
  571. /* Enable the RIXI exceptions */
  572. set_c0_pagegrain(PG_IEC);
  573. back_to_back_c0_hazard();
  574. /* Verify the IEC bit is set */
  575. if (read_c0_pagegrain() & PG_IEC)
  576. c->options |= MIPS_CPU_RIXIEX;
  577. }
  578. #ifndef CONFIG_MIPS_CPS
  579. if (cpu_has_mips_r2_r6) {
  580. c->core = get_ebase_cpunum();
  581. if (cpu_has_mipsmt)
  582. c->core >>= fls(core_nvpes()) - 1;
  583. }
  584. #endif
  585. }
  586. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  587. | MIPS_CPU_COUNTER)
  588. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  589. {
  590. switch (c->processor_id & PRID_IMP_MASK) {
  591. case PRID_IMP_R2000:
  592. c->cputype = CPU_R2000;
  593. __cpu_name[cpu] = "R2000";
  594. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  595. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  596. MIPS_CPU_NOFPUEX;
  597. if (__cpu_has_fpu())
  598. c->options |= MIPS_CPU_FPU;
  599. c->tlbsize = 64;
  600. break;
  601. case PRID_IMP_R3000:
  602. if ((c->processor_id & PRID_REV_MASK) == PRID_REV_R3000A) {
  603. if (cpu_has_confreg()) {
  604. c->cputype = CPU_R3081E;
  605. __cpu_name[cpu] = "R3081";
  606. } else {
  607. c->cputype = CPU_R3000A;
  608. __cpu_name[cpu] = "R3000A";
  609. }
  610. } else {
  611. c->cputype = CPU_R3000;
  612. __cpu_name[cpu] = "R3000";
  613. }
  614. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  615. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  616. MIPS_CPU_NOFPUEX;
  617. if (__cpu_has_fpu())
  618. c->options |= MIPS_CPU_FPU;
  619. c->tlbsize = 64;
  620. break;
  621. case PRID_IMP_R4000:
  622. if (read_c0_config() & CONF_SC) {
  623. if ((c->processor_id & PRID_REV_MASK) >=
  624. PRID_REV_R4400) {
  625. c->cputype = CPU_R4400PC;
  626. __cpu_name[cpu] = "R4400PC";
  627. } else {
  628. c->cputype = CPU_R4000PC;
  629. __cpu_name[cpu] = "R4000PC";
  630. }
  631. } else {
  632. int cca = read_c0_config() & CONF_CM_CMASK;
  633. int mc;
  634. /*
  635. * SC and MC versions can't be reliably told apart,
  636. * but only the latter support coherent caching
  637. * modes so assume the firmware has set the KSEG0
  638. * coherency attribute reasonably (if uncached, we
  639. * assume SC).
  640. */
  641. switch (cca) {
  642. case CONF_CM_CACHABLE_CE:
  643. case CONF_CM_CACHABLE_COW:
  644. case CONF_CM_CACHABLE_CUW:
  645. mc = 1;
  646. break;
  647. default:
  648. mc = 0;
  649. break;
  650. }
  651. if ((c->processor_id & PRID_REV_MASK) >=
  652. PRID_REV_R4400) {
  653. c->cputype = mc ? CPU_R4400MC : CPU_R4400SC;
  654. __cpu_name[cpu] = mc ? "R4400MC" : "R4400SC";
  655. } else {
  656. c->cputype = mc ? CPU_R4000MC : CPU_R4000SC;
  657. __cpu_name[cpu] = mc ? "R4000MC" : "R4000SC";
  658. }
  659. }
  660. set_isa(c, MIPS_CPU_ISA_III);
  661. c->fpu_msk31 |= FPU_CSR_CONDX;
  662. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  663. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  664. MIPS_CPU_LLSC;
  665. c->tlbsize = 48;
  666. break;
  667. case PRID_IMP_VR41XX:
  668. set_isa(c, MIPS_CPU_ISA_III);
  669. c->fpu_msk31 |= FPU_CSR_CONDX;
  670. c->options = R4K_OPTS;
  671. c->tlbsize = 32;
  672. switch (c->processor_id & 0xf0) {
  673. case PRID_REV_VR4111:
  674. c->cputype = CPU_VR4111;
  675. __cpu_name[cpu] = "NEC VR4111";
  676. break;
  677. case PRID_REV_VR4121:
  678. c->cputype = CPU_VR4121;
  679. __cpu_name[cpu] = "NEC VR4121";
  680. break;
  681. case PRID_REV_VR4122:
  682. if ((c->processor_id & 0xf) < 0x3) {
  683. c->cputype = CPU_VR4122;
  684. __cpu_name[cpu] = "NEC VR4122";
  685. } else {
  686. c->cputype = CPU_VR4181A;
  687. __cpu_name[cpu] = "NEC VR4181A";
  688. }
  689. break;
  690. case PRID_REV_VR4130:
  691. if ((c->processor_id & 0xf) < 0x4) {
  692. c->cputype = CPU_VR4131;
  693. __cpu_name[cpu] = "NEC VR4131";
  694. } else {
  695. c->cputype = CPU_VR4133;
  696. c->options |= MIPS_CPU_LLSC;
  697. __cpu_name[cpu] = "NEC VR4133";
  698. }
  699. break;
  700. default:
  701. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  702. c->cputype = CPU_VR41XX;
  703. __cpu_name[cpu] = "NEC Vr41xx";
  704. break;
  705. }
  706. break;
  707. case PRID_IMP_R4300:
  708. c->cputype = CPU_R4300;
  709. __cpu_name[cpu] = "R4300";
  710. set_isa(c, MIPS_CPU_ISA_III);
  711. c->fpu_msk31 |= FPU_CSR_CONDX;
  712. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  713. MIPS_CPU_LLSC;
  714. c->tlbsize = 32;
  715. break;
  716. case PRID_IMP_R4600:
  717. c->cputype = CPU_R4600;
  718. __cpu_name[cpu] = "R4600";
  719. set_isa(c, MIPS_CPU_ISA_III);
  720. c->fpu_msk31 |= FPU_CSR_CONDX;
  721. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  722. MIPS_CPU_LLSC;
  723. c->tlbsize = 48;
  724. break;
  725. #if 0
  726. case PRID_IMP_R4650:
  727. /*
  728. * This processor doesn't have an MMU, so it's not
  729. * "real easy" to run Linux on it. It is left purely
  730. * for documentation. Commented out because it shares
  731. * it's c0_prid id number with the TX3900.
  732. */
  733. c->cputype = CPU_R4650;
  734. __cpu_name[cpu] = "R4650";
  735. set_isa(c, MIPS_CPU_ISA_III);
  736. c->fpu_msk31 |= FPU_CSR_CONDX;
  737. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  738. c->tlbsize = 48;
  739. break;
  740. #endif
  741. case PRID_IMP_TX39:
  742. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  743. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  744. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  745. c->cputype = CPU_TX3927;
  746. __cpu_name[cpu] = "TX3927";
  747. c->tlbsize = 64;
  748. } else {
  749. switch (c->processor_id & PRID_REV_MASK) {
  750. case PRID_REV_TX3912:
  751. c->cputype = CPU_TX3912;
  752. __cpu_name[cpu] = "TX3912";
  753. c->tlbsize = 32;
  754. break;
  755. case PRID_REV_TX3922:
  756. c->cputype = CPU_TX3922;
  757. __cpu_name[cpu] = "TX3922";
  758. c->tlbsize = 64;
  759. break;
  760. }
  761. }
  762. break;
  763. case PRID_IMP_R4700:
  764. c->cputype = CPU_R4700;
  765. __cpu_name[cpu] = "R4700";
  766. set_isa(c, MIPS_CPU_ISA_III);
  767. c->fpu_msk31 |= FPU_CSR_CONDX;
  768. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  769. MIPS_CPU_LLSC;
  770. c->tlbsize = 48;
  771. break;
  772. case PRID_IMP_TX49:
  773. c->cputype = CPU_TX49XX;
  774. __cpu_name[cpu] = "R49XX";
  775. set_isa(c, MIPS_CPU_ISA_III);
  776. c->fpu_msk31 |= FPU_CSR_CONDX;
  777. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  778. if (!(c->processor_id & 0x08))
  779. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  780. c->tlbsize = 48;
  781. break;
  782. case PRID_IMP_R5000:
  783. c->cputype = CPU_R5000;
  784. __cpu_name[cpu] = "R5000";
  785. set_isa(c, MIPS_CPU_ISA_IV);
  786. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  787. MIPS_CPU_LLSC;
  788. c->tlbsize = 48;
  789. break;
  790. case PRID_IMP_R5432:
  791. c->cputype = CPU_R5432;
  792. __cpu_name[cpu] = "R5432";
  793. set_isa(c, MIPS_CPU_ISA_IV);
  794. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  795. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  796. c->tlbsize = 48;
  797. break;
  798. case PRID_IMP_R5500:
  799. c->cputype = CPU_R5500;
  800. __cpu_name[cpu] = "R5500";
  801. set_isa(c, MIPS_CPU_ISA_IV);
  802. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  803. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  804. c->tlbsize = 48;
  805. break;
  806. case PRID_IMP_NEVADA:
  807. c->cputype = CPU_NEVADA;
  808. __cpu_name[cpu] = "Nevada";
  809. set_isa(c, MIPS_CPU_ISA_IV);
  810. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  811. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  812. c->tlbsize = 48;
  813. break;
  814. case PRID_IMP_R6000:
  815. c->cputype = CPU_R6000;
  816. __cpu_name[cpu] = "R6000";
  817. set_isa(c, MIPS_CPU_ISA_II);
  818. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  819. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  820. MIPS_CPU_LLSC;
  821. c->tlbsize = 32;
  822. break;
  823. case PRID_IMP_R6000A:
  824. c->cputype = CPU_R6000A;
  825. __cpu_name[cpu] = "R6000A";
  826. set_isa(c, MIPS_CPU_ISA_II);
  827. c->fpu_msk31 |= FPU_CSR_CONDX | FPU_CSR_FS;
  828. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  829. MIPS_CPU_LLSC;
  830. c->tlbsize = 32;
  831. break;
  832. case PRID_IMP_RM7000:
  833. c->cputype = CPU_RM7000;
  834. __cpu_name[cpu] = "RM7000";
  835. set_isa(c, MIPS_CPU_ISA_IV);
  836. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  837. MIPS_CPU_LLSC;
  838. /*
  839. * Undocumented RM7000: Bit 29 in the info register of
  840. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  841. * entries.
  842. *
  843. * 29 1 => 64 entry JTLB
  844. * 0 => 48 entry JTLB
  845. */
  846. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  847. break;
  848. case PRID_IMP_R8000:
  849. c->cputype = CPU_R8000;
  850. __cpu_name[cpu] = "RM8000";
  851. set_isa(c, MIPS_CPU_ISA_IV);
  852. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  853. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  854. MIPS_CPU_LLSC;
  855. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  856. break;
  857. case PRID_IMP_R10000:
  858. c->cputype = CPU_R10000;
  859. __cpu_name[cpu] = "R10000";
  860. set_isa(c, MIPS_CPU_ISA_IV);
  861. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  862. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  863. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  864. MIPS_CPU_LLSC;
  865. c->tlbsize = 64;
  866. break;
  867. case PRID_IMP_R12000:
  868. c->cputype = CPU_R12000;
  869. __cpu_name[cpu] = "R12000";
  870. set_isa(c, MIPS_CPU_ISA_IV);
  871. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  872. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  873. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  874. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  875. c->tlbsize = 64;
  876. break;
  877. case PRID_IMP_R14000:
  878. if (((c->processor_id >> 4) & 0x0f) > 2) {
  879. c->cputype = CPU_R16000;
  880. __cpu_name[cpu] = "R16000";
  881. } else {
  882. c->cputype = CPU_R14000;
  883. __cpu_name[cpu] = "R14000";
  884. }
  885. set_isa(c, MIPS_CPU_ISA_IV);
  886. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  887. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  888. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  889. MIPS_CPU_LLSC | MIPS_CPU_BP_GHIST;
  890. c->tlbsize = 64;
  891. break;
  892. case PRID_IMP_LOONGSON_64: /* Loongson-2/3 */
  893. switch (c->processor_id & PRID_REV_MASK) {
  894. case PRID_REV_LOONGSON2E:
  895. c->cputype = CPU_LOONGSON2;
  896. __cpu_name[cpu] = "ICT Loongson-2";
  897. set_elf_platform(cpu, "loongson2e");
  898. set_isa(c, MIPS_CPU_ISA_III);
  899. c->fpu_msk31 |= FPU_CSR_CONDX;
  900. break;
  901. case PRID_REV_LOONGSON2F:
  902. c->cputype = CPU_LOONGSON2;
  903. __cpu_name[cpu] = "ICT Loongson-2";
  904. set_elf_platform(cpu, "loongson2f");
  905. set_isa(c, MIPS_CPU_ISA_III);
  906. c->fpu_msk31 |= FPU_CSR_CONDX;
  907. break;
  908. case PRID_REV_LOONGSON3A:
  909. c->cputype = CPU_LOONGSON3;
  910. __cpu_name[cpu] = "ICT Loongson-3";
  911. set_elf_platform(cpu, "loongson3a");
  912. set_isa(c, MIPS_CPU_ISA_M64R1);
  913. break;
  914. case PRID_REV_LOONGSON3B_R1:
  915. case PRID_REV_LOONGSON3B_R2:
  916. c->cputype = CPU_LOONGSON3;
  917. __cpu_name[cpu] = "ICT Loongson-3";
  918. set_elf_platform(cpu, "loongson3b");
  919. set_isa(c, MIPS_CPU_ISA_M64R1);
  920. break;
  921. }
  922. c->options = R4K_OPTS |
  923. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  924. MIPS_CPU_32FPR;
  925. c->tlbsize = 64;
  926. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  927. break;
  928. case PRID_IMP_LOONGSON_32: /* Loongson-1 */
  929. decode_configs(c);
  930. c->cputype = CPU_LOONGSON1;
  931. switch (c->processor_id & PRID_REV_MASK) {
  932. case PRID_REV_LOONGSON1B:
  933. __cpu_name[cpu] = "Loongson 1B";
  934. break;
  935. }
  936. break;
  937. }
  938. }
  939. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  940. {
  941. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  942. switch (c->processor_id & PRID_IMP_MASK) {
  943. case PRID_IMP_QEMU_GENERIC:
  944. c->writecombine = _CACHE_UNCACHED;
  945. c->cputype = CPU_QEMU_GENERIC;
  946. __cpu_name[cpu] = "MIPS GENERIC QEMU";
  947. break;
  948. case PRID_IMP_4KC:
  949. c->cputype = CPU_4KC;
  950. c->writecombine = _CACHE_UNCACHED;
  951. __cpu_name[cpu] = "MIPS 4Kc";
  952. break;
  953. case PRID_IMP_4KEC:
  954. case PRID_IMP_4KECR2:
  955. c->cputype = CPU_4KEC;
  956. c->writecombine = _CACHE_UNCACHED;
  957. __cpu_name[cpu] = "MIPS 4KEc";
  958. break;
  959. case PRID_IMP_4KSC:
  960. case PRID_IMP_4KSD:
  961. c->cputype = CPU_4KSC;
  962. c->writecombine = _CACHE_UNCACHED;
  963. __cpu_name[cpu] = "MIPS 4KSc";
  964. break;
  965. case PRID_IMP_5KC:
  966. c->cputype = CPU_5KC;
  967. c->writecombine = _CACHE_UNCACHED;
  968. __cpu_name[cpu] = "MIPS 5Kc";
  969. break;
  970. case PRID_IMP_5KE:
  971. c->cputype = CPU_5KE;
  972. c->writecombine = _CACHE_UNCACHED;
  973. __cpu_name[cpu] = "MIPS 5KE";
  974. break;
  975. case PRID_IMP_20KC:
  976. c->cputype = CPU_20KC;
  977. c->writecombine = _CACHE_UNCACHED;
  978. __cpu_name[cpu] = "MIPS 20Kc";
  979. break;
  980. case PRID_IMP_24K:
  981. c->cputype = CPU_24K;
  982. c->writecombine = _CACHE_UNCACHED;
  983. __cpu_name[cpu] = "MIPS 24Kc";
  984. break;
  985. case PRID_IMP_24KE:
  986. c->cputype = CPU_24K;
  987. c->writecombine = _CACHE_UNCACHED;
  988. __cpu_name[cpu] = "MIPS 24KEc";
  989. break;
  990. case PRID_IMP_25KF:
  991. c->cputype = CPU_25KF;
  992. c->writecombine = _CACHE_UNCACHED;
  993. __cpu_name[cpu] = "MIPS 25Kc";
  994. break;
  995. case PRID_IMP_34K:
  996. c->cputype = CPU_34K;
  997. c->writecombine = _CACHE_UNCACHED;
  998. __cpu_name[cpu] = "MIPS 34Kc";
  999. break;
  1000. case PRID_IMP_74K:
  1001. c->cputype = CPU_74K;
  1002. c->writecombine = _CACHE_UNCACHED;
  1003. __cpu_name[cpu] = "MIPS 74Kc";
  1004. break;
  1005. case PRID_IMP_M14KC:
  1006. c->cputype = CPU_M14KC;
  1007. c->writecombine = _CACHE_UNCACHED;
  1008. __cpu_name[cpu] = "MIPS M14Kc";
  1009. break;
  1010. case PRID_IMP_M14KEC:
  1011. c->cputype = CPU_M14KEC;
  1012. c->writecombine = _CACHE_UNCACHED;
  1013. __cpu_name[cpu] = "MIPS M14KEc";
  1014. break;
  1015. case PRID_IMP_1004K:
  1016. c->cputype = CPU_1004K;
  1017. c->writecombine = _CACHE_UNCACHED;
  1018. __cpu_name[cpu] = "MIPS 1004Kc";
  1019. break;
  1020. case PRID_IMP_1074K:
  1021. c->cputype = CPU_1074K;
  1022. c->writecombine = _CACHE_UNCACHED;
  1023. __cpu_name[cpu] = "MIPS 1074Kc";
  1024. break;
  1025. case PRID_IMP_INTERAPTIV_UP:
  1026. c->cputype = CPU_INTERAPTIV;
  1027. __cpu_name[cpu] = "MIPS interAptiv";
  1028. break;
  1029. case PRID_IMP_INTERAPTIV_MP:
  1030. c->cputype = CPU_INTERAPTIV;
  1031. __cpu_name[cpu] = "MIPS interAptiv (multi)";
  1032. break;
  1033. case PRID_IMP_PROAPTIV_UP:
  1034. c->cputype = CPU_PROAPTIV;
  1035. __cpu_name[cpu] = "MIPS proAptiv";
  1036. break;
  1037. case PRID_IMP_PROAPTIV_MP:
  1038. c->cputype = CPU_PROAPTIV;
  1039. __cpu_name[cpu] = "MIPS proAptiv (multi)";
  1040. break;
  1041. case PRID_IMP_P5600:
  1042. c->cputype = CPU_P5600;
  1043. __cpu_name[cpu] = "MIPS P5600";
  1044. break;
  1045. case PRID_IMP_I6400:
  1046. c->cputype = CPU_I6400;
  1047. __cpu_name[cpu] = "MIPS I6400";
  1048. break;
  1049. case PRID_IMP_M5150:
  1050. c->cputype = CPU_M5150;
  1051. __cpu_name[cpu] = "MIPS M5150";
  1052. break;
  1053. }
  1054. decode_configs(c);
  1055. spram_config();
  1056. }
  1057. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  1058. {
  1059. decode_configs(c);
  1060. switch (c->processor_id & PRID_IMP_MASK) {
  1061. case PRID_IMP_AU1_REV1:
  1062. case PRID_IMP_AU1_REV2:
  1063. c->cputype = CPU_ALCHEMY;
  1064. switch ((c->processor_id >> 24) & 0xff) {
  1065. case 0:
  1066. __cpu_name[cpu] = "Au1000";
  1067. break;
  1068. case 1:
  1069. __cpu_name[cpu] = "Au1500";
  1070. break;
  1071. case 2:
  1072. __cpu_name[cpu] = "Au1100";
  1073. break;
  1074. case 3:
  1075. __cpu_name[cpu] = "Au1550";
  1076. break;
  1077. case 4:
  1078. __cpu_name[cpu] = "Au1200";
  1079. if ((c->processor_id & PRID_REV_MASK) == 2)
  1080. __cpu_name[cpu] = "Au1250";
  1081. break;
  1082. case 5:
  1083. __cpu_name[cpu] = "Au1210";
  1084. break;
  1085. default:
  1086. __cpu_name[cpu] = "Au1xxx";
  1087. break;
  1088. }
  1089. break;
  1090. }
  1091. }
  1092. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  1093. {
  1094. decode_configs(c);
  1095. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1096. switch (c->processor_id & PRID_IMP_MASK) {
  1097. case PRID_IMP_SB1:
  1098. c->cputype = CPU_SB1;
  1099. __cpu_name[cpu] = "SiByte SB1";
  1100. /* FPU in pass1 is known to have issues. */
  1101. if ((c->processor_id & PRID_REV_MASK) < 0x02)
  1102. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  1103. break;
  1104. case PRID_IMP_SB1A:
  1105. c->cputype = CPU_SB1A;
  1106. __cpu_name[cpu] = "SiByte SB1A";
  1107. break;
  1108. }
  1109. }
  1110. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  1111. {
  1112. decode_configs(c);
  1113. switch (c->processor_id & PRID_IMP_MASK) {
  1114. case PRID_IMP_SR71000:
  1115. c->cputype = CPU_SR71000;
  1116. __cpu_name[cpu] = "Sandcraft SR71000";
  1117. c->scache.ways = 8;
  1118. c->tlbsize = 64;
  1119. break;
  1120. }
  1121. }
  1122. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  1123. {
  1124. decode_configs(c);
  1125. switch (c->processor_id & PRID_IMP_MASK) {
  1126. case PRID_IMP_PR4450:
  1127. c->cputype = CPU_PR4450;
  1128. __cpu_name[cpu] = "Philips PR4450";
  1129. set_isa(c, MIPS_CPU_ISA_M32R1);
  1130. break;
  1131. }
  1132. }
  1133. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  1134. {
  1135. decode_configs(c);
  1136. switch (c->processor_id & PRID_IMP_MASK) {
  1137. case PRID_IMP_BMIPS32_REV4:
  1138. case PRID_IMP_BMIPS32_REV8:
  1139. c->cputype = CPU_BMIPS32;
  1140. __cpu_name[cpu] = "Broadcom BMIPS32";
  1141. set_elf_platform(cpu, "bmips32");
  1142. break;
  1143. case PRID_IMP_BMIPS3300:
  1144. case PRID_IMP_BMIPS3300_ALT:
  1145. case PRID_IMP_BMIPS3300_BUG:
  1146. c->cputype = CPU_BMIPS3300;
  1147. __cpu_name[cpu] = "Broadcom BMIPS3300";
  1148. set_elf_platform(cpu, "bmips3300");
  1149. break;
  1150. case PRID_IMP_BMIPS43XX: {
  1151. int rev = c->processor_id & PRID_REV_MASK;
  1152. if (rev >= PRID_REV_BMIPS4380_LO &&
  1153. rev <= PRID_REV_BMIPS4380_HI) {
  1154. c->cputype = CPU_BMIPS4380;
  1155. __cpu_name[cpu] = "Broadcom BMIPS4380";
  1156. set_elf_platform(cpu, "bmips4380");
  1157. } else {
  1158. c->cputype = CPU_BMIPS4350;
  1159. __cpu_name[cpu] = "Broadcom BMIPS4350";
  1160. set_elf_platform(cpu, "bmips4350");
  1161. }
  1162. break;
  1163. }
  1164. case PRID_IMP_BMIPS5000:
  1165. case PRID_IMP_BMIPS5200:
  1166. c->cputype = CPU_BMIPS5000;
  1167. __cpu_name[cpu] = "Broadcom BMIPS5000";
  1168. set_elf_platform(cpu, "bmips5000");
  1169. c->options |= MIPS_CPU_ULRI;
  1170. break;
  1171. }
  1172. }
  1173. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  1174. {
  1175. decode_configs(c);
  1176. switch (c->processor_id & PRID_IMP_MASK) {
  1177. case PRID_IMP_CAVIUM_CN38XX:
  1178. case PRID_IMP_CAVIUM_CN31XX:
  1179. case PRID_IMP_CAVIUM_CN30XX:
  1180. c->cputype = CPU_CAVIUM_OCTEON;
  1181. __cpu_name[cpu] = "Cavium Octeon";
  1182. goto platform;
  1183. case PRID_IMP_CAVIUM_CN58XX:
  1184. case PRID_IMP_CAVIUM_CN56XX:
  1185. case PRID_IMP_CAVIUM_CN50XX:
  1186. case PRID_IMP_CAVIUM_CN52XX:
  1187. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  1188. __cpu_name[cpu] = "Cavium Octeon+";
  1189. platform:
  1190. set_elf_platform(cpu, "octeon");
  1191. break;
  1192. case PRID_IMP_CAVIUM_CN61XX:
  1193. case PRID_IMP_CAVIUM_CN63XX:
  1194. case PRID_IMP_CAVIUM_CN66XX:
  1195. case PRID_IMP_CAVIUM_CN68XX:
  1196. case PRID_IMP_CAVIUM_CNF71XX:
  1197. c->cputype = CPU_CAVIUM_OCTEON2;
  1198. __cpu_name[cpu] = "Cavium Octeon II";
  1199. set_elf_platform(cpu, "octeon2");
  1200. break;
  1201. case PRID_IMP_CAVIUM_CN70XX:
  1202. case PRID_IMP_CAVIUM_CN78XX:
  1203. c->cputype = CPU_CAVIUM_OCTEON3;
  1204. __cpu_name[cpu] = "Cavium Octeon III";
  1205. set_elf_platform(cpu, "octeon3");
  1206. break;
  1207. default:
  1208. printk(KERN_INFO "Unknown Octeon chip!\n");
  1209. c->cputype = CPU_UNKNOWN;
  1210. break;
  1211. }
  1212. }
  1213. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  1214. {
  1215. decode_configs(c);
  1216. /* JZRISC does not implement the CP0 counter. */
  1217. c->options &= ~MIPS_CPU_COUNTER;
  1218. BUG_ON(!__builtin_constant_p(cpu_has_counter) || cpu_has_counter);
  1219. switch (c->processor_id & PRID_IMP_MASK) {
  1220. case PRID_IMP_JZRISC:
  1221. c->cputype = CPU_JZRISC;
  1222. c->writecombine = _CACHE_UNCACHED_ACCELERATED;
  1223. __cpu_name[cpu] = "Ingenic JZRISC";
  1224. break;
  1225. default:
  1226. panic("Unknown Ingenic Processor ID!");
  1227. break;
  1228. }
  1229. }
  1230. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  1231. {
  1232. decode_configs(c);
  1233. if ((c->processor_id & PRID_IMP_MASK) == PRID_IMP_NETLOGIC_AU13XX) {
  1234. c->cputype = CPU_ALCHEMY;
  1235. __cpu_name[cpu] = "Au1300";
  1236. /* following stuff is not for Alchemy */
  1237. return;
  1238. }
  1239. c->options = (MIPS_CPU_TLB |
  1240. MIPS_CPU_4KEX |
  1241. MIPS_CPU_COUNTER |
  1242. MIPS_CPU_DIVEC |
  1243. MIPS_CPU_WATCH |
  1244. MIPS_CPU_EJTAG |
  1245. MIPS_CPU_LLSC);
  1246. switch (c->processor_id & PRID_IMP_MASK) {
  1247. case PRID_IMP_NETLOGIC_XLP2XX:
  1248. case PRID_IMP_NETLOGIC_XLP9XX:
  1249. case PRID_IMP_NETLOGIC_XLP5XX:
  1250. c->cputype = CPU_XLP;
  1251. __cpu_name[cpu] = "Broadcom XLPII";
  1252. break;
  1253. case PRID_IMP_NETLOGIC_XLP8XX:
  1254. case PRID_IMP_NETLOGIC_XLP3XX:
  1255. c->cputype = CPU_XLP;
  1256. __cpu_name[cpu] = "Netlogic XLP";
  1257. break;
  1258. case PRID_IMP_NETLOGIC_XLR732:
  1259. case PRID_IMP_NETLOGIC_XLR716:
  1260. case PRID_IMP_NETLOGIC_XLR532:
  1261. case PRID_IMP_NETLOGIC_XLR308:
  1262. case PRID_IMP_NETLOGIC_XLR532C:
  1263. case PRID_IMP_NETLOGIC_XLR516C:
  1264. case PRID_IMP_NETLOGIC_XLR508C:
  1265. case PRID_IMP_NETLOGIC_XLR308C:
  1266. c->cputype = CPU_XLR;
  1267. __cpu_name[cpu] = "Netlogic XLR";
  1268. break;
  1269. case PRID_IMP_NETLOGIC_XLS608:
  1270. case PRID_IMP_NETLOGIC_XLS408:
  1271. case PRID_IMP_NETLOGIC_XLS404:
  1272. case PRID_IMP_NETLOGIC_XLS208:
  1273. case PRID_IMP_NETLOGIC_XLS204:
  1274. case PRID_IMP_NETLOGIC_XLS108:
  1275. case PRID_IMP_NETLOGIC_XLS104:
  1276. case PRID_IMP_NETLOGIC_XLS616B:
  1277. case PRID_IMP_NETLOGIC_XLS608B:
  1278. case PRID_IMP_NETLOGIC_XLS416B:
  1279. case PRID_IMP_NETLOGIC_XLS412B:
  1280. case PRID_IMP_NETLOGIC_XLS408B:
  1281. case PRID_IMP_NETLOGIC_XLS404B:
  1282. c->cputype = CPU_XLR;
  1283. __cpu_name[cpu] = "Netlogic XLS";
  1284. break;
  1285. default:
  1286. pr_info("Unknown Netlogic chip id [%02x]!\n",
  1287. c->processor_id);
  1288. c->cputype = CPU_XLR;
  1289. break;
  1290. }
  1291. if (c->cputype == CPU_XLP) {
  1292. set_isa(c, MIPS_CPU_ISA_M64R2);
  1293. c->options |= (MIPS_CPU_FPU | MIPS_CPU_ULRI | MIPS_CPU_MCHECK);
  1294. /* This will be updated again after all threads are woken up */
  1295. c->tlbsize = ((read_c0_config6() >> 16) & 0xffff) + 1;
  1296. } else {
  1297. set_isa(c, MIPS_CPU_ISA_M64R1);
  1298. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  1299. }
  1300. c->kscratch_mask = 0xf;
  1301. }
  1302. #ifdef CONFIG_64BIT
  1303. /* For use by uaccess.h */
  1304. u64 __ua_limit;
  1305. EXPORT_SYMBOL(__ua_limit);
  1306. #endif
  1307. const char *__cpu_name[NR_CPUS];
  1308. const char *__elf_platform;
  1309. void cpu_probe(void)
  1310. {
  1311. struct cpuinfo_mips *c = &current_cpu_data;
  1312. unsigned int cpu = smp_processor_id();
  1313. c->processor_id = PRID_IMP_UNKNOWN;
  1314. c->fpu_id = FPIR_IMP_NONE;
  1315. c->cputype = CPU_UNKNOWN;
  1316. c->writecombine = _CACHE_UNCACHED;
  1317. c->fpu_csr31 = FPU_CSR_RN;
  1318. c->fpu_msk31 = FPU_CSR_RSVD | FPU_CSR_ABS2008 | FPU_CSR_NAN2008;
  1319. c->processor_id = read_c0_prid();
  1320. switch (c->processor_id & PRID_COMP_MASK) {
  1321. case PRID_COMP_LEGACY:
  1322. cpu_probe_legacy(c, cpu);
  1323. break;
  1324. case PRID_COMP_MIPS:
  1325. cpu_probe_mips(c, cpu);
  1326. break;
  1327. case PRID_COMP_ALCHEMY:
  1328. cpu_probe_alchemy(c, cpu);
  1329. break;
  1330. case PRID_COMP_SIBYTE:
  1331. cpu_probe_sibyte(c, cpu);
  1332. break;
  1333. case PRID_COMP_BROADCOM:
  1334. cpu_probe_broadcom(c, cpu);
  1335. break;
  1336. case PRID_COMP_SANDCRAFT:
  1337. cpu_probe_sandcraft(c, cpu);
  1338. break;
  1339. case PRID_COMP_NXP:
  1340. cpu_probe_nxp(c, cpu);
  1341. break;
  1342. case PRID_COMP_CAVIUM:
  1343. cpu_probe_cavium(c, cpu);
  1344. break;
  1345. case PRID_COMP_INGENIC_D0:
  1346. case PRID_COMP_INGENIC_D1:
  1347. case PRID_COMP_INGENIC_E1:
  1348. cpu_probe_ingenic(c, cpu);
  1349. break;
  1350. case PRID_COMP_NETLOGIC:
  1351. cpu_probe_netlogic(c, cpu);
  1352. break;
  1353. }
  1354. BUG_ON(!__cpu_name[cpu]);
  1355. BUG_ON(c->cputype == CPU_UNKNOWN);
  1356. /*
  1357. * Platform code can force the cpu type to optimize code
  1358. * generation. In that case be sure the cpu type is correctly
  1359. * manually setup otherwise it could trigger some nasty bugs.
  1360. */
  1361. BUG_ON(current_cpu_type() != c->cputype);
  1362. if (mips_fpu_disabled)
  1363. c->options &= ~MIPS_CPU_FPU;
  1364. if (mips_dsp_disabled)
  1365. c->ases &= ~(MIPS_ASE_DSP | MIPS_ASE_DSP2P);
  1366. if (mips_htw_disabled) {
  1367. c->options &= ~MIPS_CPU_HTW;
  1368. write_c0_pwctl(read_c0_pwctl() &
  1369. ~(1 << MIPS_PWCTL_PWEN_SHIFT));
  1370. }
  1371. if (c->options & MIPS_CPU_FPU)
  1372. cpu_set_fpu_opts(c);
  1373. else
  1374. cpu_set_nofpu_opts(c);
  1375. if (cpu_has_bp_ghist)
  1376. write_c0_r10k_diag(read_c0_r10k_diag() |
  1377. R10K_DIAG_E_GHIST);
  1378. if (cpu_has_mips_r2_r6) {
  1379. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1380. /* R2 has Performance Counter Interrupt indicator */
  1381. c->options |= MIPS_CPU_PCI;
  1382. }
  1383. else
  1384. c->srsets = 1;
  1385. if (cpu_has_mips_r6)
  1386. elf_hwcap |= HWCAP_MIPS_R6;
  1387. if (cpu_has_msa) {
  1388. c->msa_id = cpu_get_msa_id();
  1389. WARN(c->msa_id & MSA_IR_WRPF,
  1390. "Vector register partitioning unimplemented!");
  1391. elf_hwcap |= HWCAP_MIPS_MSA;
  1392. }
  1393. cpu_probe_vmbits(c);
  1394. #ifdef CONFIG_64BIT
  1395. if (cpu == 0)
  1396. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1397. #endif
  1398. }
  1399. void cpu_report(void)
  1400. {
  1401. struct cpuinfo_mips *c = &current_cpu_data;
  1402. pr_info("CPU%d revision is: %08x (%s)\n",
  1403. smp_processor_id(), c->processor_id, cpu_name_string());
  1404. if (c->options & MIPS_CPU_FPU)
  1405. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1406. if (cpu_has_msa)
  1407. pr_info("MSA revision is: %08x\n", c->msa_id);
  1408. }