cpu-probe.c 38 KB

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