cpu-probe.c 37 KB

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