cpu-probe.c 37 KB

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