cpu-probe.c 27 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163
  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 MIPS 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/module.h>
  20. #include <asm/bugs.h>
  21. #include <asm/cpu.h>
  22. #include <asm/fpu.h>
  23. #include <asm/mipsregs.h>
  24. #include <asm/system.h>
  25. #include <asm/watch.h>
  26. #include <asm/spram.h>
  27. #include <asm/uaccess.h>
  28. /*
  29. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  30. * the implementation of the "wait" feature differs between CPU families. This
  31. * points to the function that implements CPU specific wait.
  32. * The wait instruction stops the pipeline and reduces the power consumption of
  33. * the CPU very much.
  34. */
  35. void (*cpu_wait)(void);
  36. EXPORT_SYMBOL(cpu_wait);
  37. static void r3081_wait(void)
  38. {
  39. unsigned long cfg = read_c0_conf();
  40. write_c0_conf(cfg | R30XX_CONF_HALT);
  41. }
  42. static void r39xx_wait(void)
  43. {
  44. local_irq_disable();
  45. if (!need_resched())
  46. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  47. local_irq_enable();
  48. }
  49. extern void r4k_wait(void);
  50. /*
  51. * This variant is preferable as it allows testing need_resched and going to
  52. * sleep depending on the outcome atomically. Unfortunately the "It is
  53. * implementation-dependent whether the pipeline restarts when a non-enabled
  54. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  55. * using this version a gamble.
  56. */
  57. void r4k_wait_irqoff(void)
  58. {
  59. local_irq_disable();
  60. if (!need_resched())
  61. __asm__(" .set push \n"
  62. " .set mips3 \n"
  63. " wait \n"
  64. " .set pop \n");
  65. local_irq_enable();
  66. __asm__(" .globl __pastwait \n"
  67. "__pastwait: \n");
  68. }
  69. /*
  70. * The RM7000 variant has to handle erratum 38. The workaround is to not
  71. * have any pending stores when the WAIT instruction is executed.
  72. */
  73. static void rm7k_wait_irqoff(void)
  74. {
  75. local_irq_disable();
  76. if (!need_resched())
  77. __asm__(
  78. " .set push \n"
  79. " .set mips3 \n"
  80. " .set noat \n"
  81. " mfc0 $1, $12 \n"
  82. " sync \n"
  83. " mtc0 $1, $12 # stalls until W stage \n"
  84. " wait \n"
  85. " mtc0 $1, $12 # stalls until W stage \n"
  86. " .set pop \n");
  87. local_irq_enable();
  88. }
  89. /*
  90. * The Au1xxx wait is available only if using 32khz counter or
  91. * external timer source, but specifically not CP0 Counter.
  92. * alchemy/common/time.c may override cpu_wait!
  93. */
  94. static void au1k_wait(void)
  95. {
  96. __asm__(" .set mips3 \n"
  97. " cache 0x14, 0(%0) \n"
  98. " cache 0x14, 32(%0) \n"
  99. " sync \n"
  100. " nop \n"
  101. " wait \n"
  102. " nop \n"
  103. " nop \n"
  104. " nop \n"
  105. " nop \n"
  106. " .set mips0 \n"
  107. : : "r" (au1k_wait));
  108. }
  109. static int __initdata nowait;
  110. static int __init wait_disable(char *s)
  111. {
  112. nowait = 1;
  113. return 1;
  114. }
  115. __setup("nowait", wait_disable);
  116. static int __cpuinitdata mips_fpu_disabled;
  117. static int __init fpu_disable(char *s)
  118. {
  119. cpu_data[0].options &= ~MIPS_CPU_FPU;
  120. mips_fpu_disabled = 1;
  121. return 1;
  122. }
  123. __setup("nofpu", fpu_disable);
  124. int __cpuinitdata mips_dsp_disabled;
  125. static int __init dsp_disable(char *s)
  126. {
  127. cpu_data[0].ases &= ~MIPS_ASE_DSP;
  128. mips_dsp_disabled = 1;
  129. return 1;
  130. }
  131. __setup("nodsp", dsp_disable);
  132. void __init check_wait(void)
  133. {
  134. struct cpuinfo_mips *c = &current_cpu_data;
  135. if (nowait) {
  136. printk("Wait instruction disabled.\n");
  137. return;
  138. }
  139. switch (c->cputype) {
  140. case CPU_R3081:
  141. case CPU_R3081E:
  142. cpu_wait = r3081_wait;
  143. break;
  144. case CPU_TX3927:
  145. cpu_wait = r39xx_wait;
  146. break;
  147. case CPU_R4200:
  148. /* case CPU_R4300: */
  149. case CPU_R4600:
  150. case CPU_R4640:
  151. case CPU_R4650:
  152. case CPU_R4700:
  153. case CPU_R5000:
  154. case CPU_R5500:
  155. case CPU_NEVADA:
  156. case CPU_4KC:
  157. case CPU_4KEC:
  158. case CPU_4KSC:
  159. case CPU_5KC:
  160. case CPU_25KF:
  161. case CPU_PR4450:
  162. case CPU_BMIPS3300:
  163. case CPU_BMIPS4350:
  164. case CPU_BMIPS4380:
  165. case CPU_BMIPS5000:
  166. case CPU_CAVIUM_OCTEON:
  167. case CPU_CAVIUM_OCTEON_PLUS:
  168. case CPU_CAVIUM_OCTEON2:
  169. case CPU_JZRISC:
  170. cpu_wait = r4k_wait;
  171. break;
  172. case CPU_RM7000:
  173. cpu_wait = rm7k_wait_irqoff;
  174. break;
  175. case CPU_24K:
  176. case CPU_34K:
  177. case CPU_1004K:
  178. cpu_wait = r4k_wait;
  179. if (read_c0_config7() & MIPS_CONF7_WII)
  180. cpu_wait = r4k_wait_irqoff;
  181. break;
  182. case CPU_74K:
  183. cpu_wait = r4k_wait;
  184. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  185. cpu_wait = r4k_wait_irqoff;
  186. break;
  187. case CPU_TX49XX:
  188. cpu_wait = r4k_wait_irqoff;
  189. break;
  190. case CPU_ALCHEMY:
  191. cpu_wait = au1k_wait;
  192. break;
  193. case CPU_20KC:
  194. /*
  195. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  196. * WAIT on Rev2.0 and Rev3.0 has E16.
  197. * Rev3.1 WAIT is nop, why bother
  198. */
  199. if ((c->processor_id & 0xff) <= 0x64)
  200. break;
  201. /*
  202. * Another rev is incremeting c0_count at a reduced clock
  203. * rate while in WAIT mode. So we basically have the choice
  204. * between using the cp0 timer as clocksource or avoiding
  205. * the WAIT instruction. Until more details are known,
  206. * disable the use of WAIT for 20Kc entirely.
  207. cpu_wait = r4k_wait;
  208. */
  209. break;
  210. case CPU_RM9000:
  211. if ((c->processor_id & 0x00ff) >= 0x40)
  212. cpu_wait = r4k_wait;
  213. break;
  214. default:
  215. break;
  216. }
  217. }
  218. static inline void check_errata(void)
  219. {
  220. struct cpuinfo_mips *c = &current_cpu_data;
  221. switch (c->cputype) {
  222. case CPU_34K:
  223. /*
  224. * Erratum "RPS May Cause Incorrect Instruction Execution"
  225. * This code only handles VPE0, any SMP/SMTC/RTOS code
  226. * making use of VPE1 will be responsable for that VPE.
  227. */
  228. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  229. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  230. break;
  231. default:
  232. break;
  233. }
  234. }
  235. void __init check_bugs32(void)
  236. {
  237. check_errata();
  238. }
  239. /*
  240. * Probe whether cpu has config register by trying to play with
  241. * alternate cache bit and see whether it matters.
  242. * It's used by cpu_probe to distinguish between R3000A and R3081.
  243. */
  244. static inline int cpu_has_confreg(void)
  245. {
  246. #ifdef CONFIG_CPU_R3000
  247. extern unsigned long r3k_cache_size(unsigned long);
  248. unsigned long size1, size2;
  249. unsigned long cfg = read_c0_conf();
  250. size1 = r3k_cache_size(ST0_ISC);
  251. write_c0_conf(cfg ^ R30XX_CONF_AC);
  252. size2 = r3k_cache_size(ST0_ISC);
  253. write_c0_conf(cfg);
  254. return size1 != size2;
  255. #else
  256. return 0;
  257. #endif
  258. }
  259. static inline void set_elf_platform(int cpu, const char *plat)
  260. {
  261. if (cpu == 0)
  262. __elf_platform = plat;
  263. }
  264. /*
  265. * Get the FPU Implementation/Revision.
  266. */
  267. static inline unsigned long cpu_get_fpu_id(void)
  268. {
  269. unsigned long tmp, fpu_id;
  270. tmp = read_c0_status();
  271. __enable_fpu();
  272. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  273. write_c0_status(tmp);
  274. return fpu_id;
  275. }
  276. /*
  277. * Check the CPU has an FPU the official way.
  278. */
  279. static inline int __cpu_has_fpu(void)
  280. {
  281. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  282. }
  283. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  284. {
  285. #ifdef __NEED_VMBITS_PROBE
  286. write_c0_entryhi(0x3fffffffffffe000ULL);
  287. back_to_back_c0_hazard();
  288. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  289. #endif
  290. }
  291. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  292. | MIPS_CPU_COUNTER)
  293. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  294. {
  295. switch (c->processor_id & 0xff00) {
  296. case PRID_IMP_R2000:
  297. c->cputype = CPU_R2000;
  298. __cpu_name[cpu] = "R2000";
  299. c->isa_level = MIPS_CPU_ISA_I;
  300. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  301. MIPS_CPU_NOFPUEX;
  302. if (__cpu_has_fpu())
  303. c->options |= MIPS_CPU_FPU;
  304. c->tlbsize = 64;
  305. break;
  306. case PRID_IMP_R3000:
  307. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  308. if (cpu_has_confreg()) {
  309. c->cputype = CPU_R3081E;
  310. __cpu_name[cpu] = "R3081";
  311. } else {
  312. c->cputype = CPU_R3000A;
  313. __cpu_name[cpu] = "R3000A";
  314. }
  315. break;
  316. } else {
  317. c->cputype = CPU_R3000;
  318. __cpu_name[cpu] = "R3000";
  319. }
  320. c->isa_level = MIPS_CPU_ISA_I;
  321. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  322. MIPS_CPU_NOFPUEX;
  323. if (__cpu_has_fpu())
  324. c->options |= MIPS_CPU_FPU;
  325. c->tlbsize = 64;
  326. break;
  327. case PRID_IMP_R4000:
  328. if (read_c0_config() & CONF_SC) {
  329. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  330. c->cputype = CPU_R4400PC;
  331. __cpu_name[cpu] = "R4400PC";
  332. } else {
  333. c->cputype = CPU_R4000PC;
  334. __cpu_name[cpu] = "R4000PC";
  335. }
  336. } else {
  337. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  338. c->cputype = CPU_R4400SC;
  339. __cpu_name[cpu] = "R4400SC";
  340. } else {
  341. c->cputype = CPU_R4000SC;
  342. __cpu_name[cpu] = "R4000SC";
  343. }
  344. }
  345. c->isa_level = MIPS_CPU_ISA_III;
  346. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  347. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  348. MIPS_CPU_LLSC;
  349. c->tlbsize = 48;
  350. break;
  351. case PRID_IMP_VR41XX:
  352. switch (c->processor_id & 0xf0) {
  353. case PRID_REV_VR4111:
  354. c->cputype = CPU_VR4111;
  355. __cpu_name[cpu] = "NEC VR4111";
  356. break;
  357. case PRID_REV_VR4121:
  358. c->cputype = CPU_VR4121;
  359. __cpu_name[cpu] = "NEC VR4121";
  360. break;
  361. case PRID_REV_VR4122:
  362. if ((c->processor_id & 0xf) < 0x3) {
  363. c->cputype = CPU_VR4122;
  364. __cpu_name[cpu] = "NEC VR4122";
  365. } else {
  366. c->cputype = CPU_VR4181A;
  367. __cpu_name[cpu] = "NEC VR4181A";
  368. }
  369. break;
  370. case PRID_REV_VR4130:
  371. if ((c->processor_id & 0xf) < 0x4) {
  372. c->cputype = CPU_VR4131;
  373. __cpu_name[cpu] = "NEC VR4131";
  374. } else {
  375. c->cputype = CPU_VR4133;
  376. __cpu_name[cpu] = "NEC VR4133";
  377. }
  378. break;
  379. default:
  380. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  381. c->cputype = CPU_VR41XX;
  382. __cpu_name[cpu] = "NEC Vr41xx";
  383. break;
  384. }
  385. c->isa_level = MIPS_CPU_ISA_III;
  386. c->options = R4K_OPTS;
  387. c->tlbsize = 32;
  388. break;
  389. case PRID_IMP_R4300:
  390. c->cputype = CPU_R4300;
  391. __cpu_name[cpu] = "R4300";
  392. c->isa_level = MIPS_CPU_ISA_III;
  393. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  394. MIPS_CPU_LLSC;
  395. c->tlbsize = 32;
  396. break;
  397. case PRID_IMP_R4600:
  398. c->cputype = CPU_R4600;
  399. __cpu_name[cpu] = "R4600";
  400. c->isa_level = MIPS_CPU_ISA_III;
  401. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  402. MIPS_CPU_LLSC;
  403. c->tlbsize = 48;
  404. break;
  405. #if 0
  406. case PRID_IMP_R4650:
  407. /*
  408. * This processor doesn't have an MMU, so it's not
  409. * "real easy" to run Linux on it. It is left purely
  410. * for documentation. Commented out because it shares
  411. * it's c0_prid id number with the TX3900.
  412. */
  413. c->cputype = CPU_R4650;
  414. __cpu_name[cpu] = "R4650";
  415. c->isa_level = MIPS_CPU_ISA_III;
  416. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  417. c->tlbsize = 48;
  418. break;
  419. #endif
  420. case PRID_IMP_TX39:
  421. c->isa_level = MIPS_CPU_ISA_I;
  422. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  423. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  424. c->cputype = CPU_TX3927;
  425. __cpu_name[cpu] = "TX3927";
  426. c->tlbsize = 64;
  427. } else {
  428. switch (c->processor_id & 0xff) {
  429. case PRID_REV_TX3912:
  430. c->cputype = CPU_TX3912;
  431. __cpu_name[cpu] = "TX3912";
  432. c->tlbsize = 32;
  433. break;
  434. case PRID_REV_TX3922:
  435. c->cputype = CPU_TX3922;
  436. __cpu_name[cpu] = "TX3922";
  437. c->tlbsize = 64;
  438. break;
  439. }
  440. }
  441. break;
  442. case PRID_IMP_R4700:
  443. c->cputype = CPU_R4700;
  444. __cpu_name[cpu] = "R4700";
  445. c->isa_level = MIPS_CPU_ISA_III;
  446. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  447. MIPS_CPU_LLSC;
  448. c->tlbsize = 48;
  449. break;
  450. case PRID_IMP_TX49:
  451. c->cputype = CPU_TX49XX;
  452. __cpu_name[cpu] = "R49XX";
  453. c->isa_level = MIPS_CPU_ISA_III;
  454. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  455. if (!(c->processor_id & 0x08))
  456. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  457. c->tlbsize = 48;
  458. break;
  459. case PRID_IMP_R5000:
  460. c->cputype = CPU_R5000;
  461. __cpu_name[cpu] = "R5000";
  462. c->isa_level = MIPS_CPU_ISA_IV;
  463. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  464. MIPS_CPU_LLSC;
  465. c->tlbsize = 48;
  466. break;
  467. case PRID_IMP_R5432:
  468. c->cputype = CPU_R5432;
  469. __cpu_name[cpu] = "R5432";
  470. c->isa_level = MIPS_CPU_ISA_IV;
  471. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  472. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  473. c->tlbsize = 48;
  474. break;
  475. case PRID_IMP_R5500:
  476. c->cputype = CPU_R5500;
  477. __cpu_name[cpu] = "R5500";
  478. c->isa_level = MIPS_CPU_ISA_IV;
  479. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  480. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  481. c->tlbsize = 48;
  482. break;
  483. case PRID_IMP_NEVADA:
  484. c->cputype = CPU_NEVADA;
  485. __cpu_name[cpu] = "Nevada";
  486. c->isa_level = MIPS_CPU_ISA_IV;
  487. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  488. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  489. c->tlbsize = 48;
  490. break;
  491. case PRID_IMP_R6000:
  492. c->cputype = CPU_R6000;
  493. __cpu_name[cpu] = "R6000";
  494. c->isa_level = MIPS_CPU_ISA_II;
  495. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  496. MIPS_CPU_LLSC;
  497. c->tlbsize = 32;
  498. break;
  499. case PRID_IMP_R6000A:
  500. c->cputype = CPU_R6000A;
  501. __cpu_name[cpu] = "R6000A";
  502. c->isa_level = MIPS_CPU_ISA_II;
  503. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  504. MIPS_CPU_LLSC;
  505. c->tlbsize = 32;
  506. break;
  507. case PRID_IMP_RM7000:
  508. c->cputype = CPU_RM7000;
  509. __cpu_name[cpu] = "RM7000";
  510. c->isa_level = MIPS_CPU_ISA_IV;
  511. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  512. MIPS_CPU_LLSC;
  513. /*
  514. * Undocumented RM7000: Bit 29 in the info register of
  515. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  516. * entries.
  517. *
  518. * 29 1 => 64 entry JTLB
  519. * 0 => 48 entry JTLB
  520. */
  521. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  522. break;
  523. case PRID_IMP_RM9000:
  524. c->cputype = CPU_RM9000;
  525. __cpu_name[cpu] = "RM9000";
  526. c->isa_level = MIPS_CPU_ISA_IV;
  527. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  528. MIPS_CPU_LLSC;
  529. /*
  530. * Bit 29 in the info register of the RM9000
  531. * indicates if the TLB has 48 or 64 entries.
  532. *
  533. * 29 1 => 64 entry JTLB
  534. * 0 => 48 entry JTLB
  535. */
  536. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  537. break;
  538. case PRID_IMP_R8000:
  539. c->cputype = CPU_R8000;
  540. __cpu_name[cpu] = "RM8000";
  541. c->isa_level = MIPS_CPU_ISA_IV;
  542. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  543. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  544. MIPS_CPU_LLSC;
  545. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  546. break;
  547. case PRID_IMP_R10000:
  548. c->cputype = CPU_R10000;
  549. __cpu_name[cpu] = "R10000";
  550. c->isa_level = MIPS_CPU_ISA_IV;
  551. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  552. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  553. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  554. MIPS_CPU_LLSC;
  555. c->tlbsize = 64;
  556. break;
  557. case PRID_IMP_R12000:
  558. c->cputype = CPU_R12000;
  559. __cpu_name[cpu] = "R12000";
  560. c->isa_level = MIPS_CPU_ISA_IV;
  561. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  562. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  563. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  564. MIPS_CPU_LLSC;
  565. c->tlbsize = 64;
  566. break;
  567. case PRID_IMP_R14000:
  568. c->cputype = CPU_R14000;
  569. __cpu_name[cpu] = "R14000";
  570. c->isa_level = MIPS_CPU_ISA_IV;
  571. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  572. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  573. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  574. MIPS_CPU_LLSC;
  575. c->tlbsize = 64;
  576. break;
  577. case PRID_IMP_LOONGSON2:
  578. c->cputype = CPU_LOONGSON2;
  579. __cpu_name[cpu] = "ICT Loongson-2";
  580. switch (c->processor_id & PRID_REV_MASK) {
  581. case PRID_REV_LOONGSON2E:
  582. set_elf_platform(cpu, "loongson2e");
  583. break;
  584. case PRID_REV_LOONGSON2F:
  585. set_elf_platform(cpu, "loongson2f");
  586. break;
  587. }
  588. c->isa_level = MIPS_CPU_ISA_III;
  589. c->options = R4K_OPTS |
  590. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  591. MIPS_CPU_32FPR;
  592. c->tlbsize = 64;
  593. break;
  594. }
  595. }
  596. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  597. "Unsupported ISA type, c0.config0: %d.";
  598. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  599. {
  600. unsigned int config0;
  601. int isa;
  602. config0 = read_c0_config();
  603. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  604. c->options |= MIPS_CPU_TLB;
  605. isa = (config0 & MIPS_CONF_AT) >> 13;
  606. switch (isa) {
  607. case 0:
  608. switch ((config0 & MIPS_CONF_AR) >> 10) {
  609. case 0:
  610. c->isa_level = MIPS_CPU_ISA_M32R1;
  611. break;
  612. case 1:
  613. c->isa_level = MIPS_CPU_ISA_M32R2;
  614. break;
  615. default:
  616. goto unknown;
  617. }
  618. break;
  619. case 2:
  620. switch ((config0 & MIPS_CONF_AR) >> 10) {
  621. case 0:
  622. c->isa_level = MIPS_CPU_ISA_M64R1;
  623. break;
  624. case 1:
  625. c->isa_level = MIPS_CPU_ISA_M64R2;
  626. break;
  627. default:
  628. goto unknown;
  629. }
  630. break;
  631. default:
  632. goto unknown;
  633. }
  634. return config0 & MIPS_CONF_M;
  635. unknown:
  636. panic(unknown_isa, config0);
  637. }
  638. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  639. {
  640. unsigned int config1;
  641. config1 = read_c0_config1();
  642. if (config1 & MIPS_CONF1_MD)
  643. c->ases |= MIPS_ASE_MDMX;
  644. if (config1 & MIPS_CONF1_WR)
  645. c->options |= MIPS_CPU_WATCH;
  646. if (config1 & MIPS_CONF1_CA)
  647. c->ases |= MIPS_ASE_MIPS16;
  648. if (config1 & MIPS_CONF1_EP)
  649. c->options |= MIPS_CPU_EJTAG;
  650. if (config1 & MIPS_CONF1_FP) {
  651. c->options |= MIPS_CPU_FPU;
  652. c->options |= MIPS_CPU_32FPR;
  653. }
  654. if (cpu_has_tlb)
  655. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  656. return config1 & MIPS_CONF_M;
  657. }
  658. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  659. {
  660. unsigned int config2;
  661. config2 = read_c0_config2();
  662. if (config2 & MIPS_CONF2_SL)
  663. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  664. return config2 & MIPS_CONF_M;
  665. }
  666. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  667. {
  668. unsigned int config3;
  669. config3 = read_c0_config3();
  670. if (config3 & MIPS_CONF3_SM)
  671. c->ases |= MIPS_ASE_SMARTMIPS;
  672. if (config3 & MIPS_CONF3_DSP)
  673. c->ases |= MIPS_ASE_DSP;
  674. if (config3 & MIPS_CONF3_VINT)
  675. c->options |= MIPS_CPU_VINT;
  676. if (config3 & MIPS_CONF3_VEIC)
  677. c->options |= MIPS_CPU_VEIC;
  678. if (config3 & MIPS_CONF3_MT)
  679. c->ases |= MIPS_ASE_MIPSMT;
  680. if (config3 & MIPS_CONF3_ULRI)
  681. c->options |= MIPS_CPU_ULRI;
  682. return config3 & MIPS_CONF_M;
  683. }
  684. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  685. {
  686. unsigned int config4;
  687. config4 = read_c0_config4();
  688. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  689. && cpu_has_tlb)
  690. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  691. c->kscratch_mask = (config4 >> 16) & 0xff;
  692. return config4 & MIPS_CONF_M;
  693. }
  694. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  695. {
  696. int ok;
  697. /* MIPS32 or MIPS64 compliant CPU. */
  698. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  699. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  700. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  701. ok = decode_config0(c); /* Read Config registers. */
  702. BUG_ON(!ok); /* Arch spec violation! */
  703. if (ok)
  704. ok = decode_config1(c);
  705. if (ok)
  706. ok = decode_config2(c);
  707. if (ok)
  708. ok = decode_config3(c);
  709. if (ok)
  710. ok = decode_config4(c);
  711. mips_probe_watch_registers(c);
  712. if (cpu_has_mips_r2)
  713. c->core = read_c0_ebase() & 0x3ff;
  714. }
  715. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  716. {
  717. decode_configs(c);
  718. switch (c->processor_id & 0xff00) {
  719. case PRID_IMP_4KC:
  720. c->cputype = CPU_4KC;
  721. __cpu_name[cpu] = "MIPS 4Kc";
  722. break;
  723. case PRID_IMP_4KEC:
  724. case PRID_IMP_4KECR2:
  725. c->cputype = CPU_4KEC;
  726. __cpu_name[cpu] = "MIPS 4KEc";
  727. break;
  728. case PRID_IMP_4KSC:
  729. case PRID_IMP_4KSD:
  730. c->cputype = CPU_4KSC;
  731. __cpu_name[cpu] = "MIPS 4KSc";
  732. break;
  733. case PRID_IMP_5KC:
  734. c->cputype = CPU_5KC;
  735. __cpu_name[cpu] = "MIPS 5Kc";
  736. break;
  737. case PRID_IMP_20KC:
  738. c->cputype = CPU_20KC;
  739. __cpu_name[cpu] = "MIPS 20Kc";
  740. break;
  741. case PRID_IMP_24K:
  742. case PRID_IMP_24KE:
  743. c->cputype = CPU_24K;
  744. __cpu_name[cpu] = "MIPS 24Kc";
  745. break;
  746. case PRID_IMP_25KF:
  747. c->cputype = CPU_25KF;
  748. __cpu_name[cpu] = "MIPS 25Kc";
  749. break;
  750. case PRID_IMP_34K:
  751. c->cputype = CPU_34K;
  752. __cpu_name[cpu] = "MIPS 34Kc";
  753. break;
  754. case PRID_IMP_74K:
  755. c->cputype = CPU_74K;
  756. __cpu_name[cpu] = "MIPS 74Kc";
  757. break;
  758. case PRID_IMP_1004K:
  759. c->cputype = CPU_1004K;
  760. __cpu_name[cpu] = "MIPS 1004Kc";
  761. break;
  762. }
  763. spram_config();
  764. }
  765. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  766. {
  767. decode_configs(c);
  768. switch (c->processor_id & 0xff00) {
  769. case PRID_IMP_AU1_REV1:
  770. case PRID_IMP_AU1_REV2:
  771. c->cputype = CPU_ALCHEMY;
  772. switch ((c->processor_id >> 24) & 0xff) {
  773. case 0:
  774. __cpu_name[cpu] = "Au1000";
  775. break;
  776. case 1:
  777. __cpu_name[cpu] = "Au1500";
  778. break;
  779. case 2:
  780. __cpu_name[cpu] = "Au1100";
  781. break;
  782. case 3:
  783. __cpu_name[cpu] = "Au1550";
  784. break;
  785. case 4:
  786. __cpu_name[cpu] = "Au1200";
  787. if ((c->processor_id & 0xff) == 2)
  788. __cpu_name[cpu] = "Au1250";
  789. break;
  790. case 5:
  791. __cpu_name[cpu] = "Au1210";
  792. break;
  793. default:
  794. __cpu_name[cpu] = "Au1xxx";
  795. break;
  796. }
  797. break;
  798. }
  799. }
  800. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  801. {
  802. decode_configs(c);
  803. switch (c->processor_id & 0xff00) {
  804. case PRID_IMP_SB1:
  805. c->cputype = CPU_SB1;
  806. __cpu_name[cpu] = "SiByte SB1";
  807. /* FPU in pass1 is known to have issues. */
  808. if ((c->processor_id & 0xff) < 0x02)
  809. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  810. break;
  811. case PRID_IMP_SB1A:
  812. c->cputype = CPU_SB1A;
  813. __cpu_name[cpu] = "SiByte SB1A";
  814. break;
  815. }
  816. }
  817. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  818. {
  819. decode_configs(c);
  820. switch (c->processor_id & 0xff00) {
  821. case PRID_IMP_SR71000:
  822. c->cputype = CPU_SR71000;
  823. __cpu_name[cpu] = "Sandcraft SR71000";
  824. c->scache.ways = 8;
  825. c->tlbsize = 64;
  826. break;
  827. }
  828. }
  829. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  830. {
  831. decode_configs(c);
  832. switch (c->processor_id & 0xff00) {
  833. case PRID_IMP_PR4450:
  834. c->cputype = CPU_PR4450;
  835. __cpu_name[cpu] = "Philips PR4450";
  836. c->isa_level = MIPS_CPU_ISA_M32R1;
  837. break;
  838. }
  839. }
  840. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  841. {
  842. decode_configs(c);
  843. switch (c->processor_id & 0xff00) {
  844. case PRID_IMP_BMIPS32_REV4:
  845. case PRID_IMP_BMIPS32_REV8:
  846. c->cputype = CPU_BMIPS32;
  847. __cpu_name[cpu] = "Broadcom BMIPS32";
  848. set_elf_platform(cpu, "bmips32");
  849. break;
  850. case PRID_IMP_BMIPS3300:
  851. case PRID_IMP_BMIPS3300_ALT:
  852. case PRID_IMP_BMIPS3300_BUG:
  853. c->cputype = CPU_BMIPS3300;
  854. __cpu_name[cpu] = "Broadcom BMIPS3300";
  855. set_elf_platform(cpu, "bmips3300");
  856. break;
  857. case PRID_IMP_BMIPS43XX: {
  858. int rev = c->processor_id & 0xff;
  859. if (rev >= PRID_REV_BMIPS4380_LO &&
  860. rev <= PRID_REV_BMIPS4380_HI) {
  861. c->cputype = CPU_BMIPS4380;
  862. __cpu_name[cpu] = "Broadcom BMIPS4380";
  863. set_elf_platform(cpu, "bmips4380");
  864. } else {
  865. c->cputype = CPU_BMIPS4350;
  866. __cpu_name[cpu] = "Broadcom BMIPS4350";
  867. set_elf_platform(cpu, "bmips4350");
  868. }
  869. break;
  870. }
  871. case PRID_IMP_BMIPS5000:
  872. c->cputype = CPU_BMIPS5000;
  873. __cpu_name[cpu] = "Broadcom BMIPS5000";
  874. set_elf_platform(cpu, "bmips5000");
  875. c->options |= MIPS_CPU_ULRI;
  876. break;
  877. }
  878. }
  879. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  880. {
  881. decode_configs(c);
  882. switch (c->processor_id & 0xff00) {
  883. case PRID_IMP_CAVIUM_CN38XX:
  884. case PRID_IMP_CAVIUM_CN31XX:
  885. case PRID_IMP_CAVIUM_CN30XX:
  886. c->cputype = CPU_CAVIUM_OCTEON;
  887. __cpu_name[cpu] = "Cavium Octeon";
  888. goto platform;
  889. case PRID_IMP_CAVIUM_CN58XX:
  890. case PRID_IMP_CAVIUM_CN56XX:
  891. case PRID_IMP_CAVIUM_CN50XX:
  892. case PRID_IMP_CAVIUM_CN52XX:
  893. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  894. __cpu_name[cpu] = "Cavium Octeon+";
  895. platform:
  896. set_elf_platform(cpu, "octeon");
  897. break;
  898. case PRID_IMP_CAVIUM_CN63XX:
  899. c->cputype = CPU_CAVIUM_OCTEON2;
  900. __cpu_name[cpu] = "Cavium Octeon II";
  901. set_elf_platform(cpu, "octeon2");
  902. break;
  903. default:
  904. printk(KERN_INFO "Unknown Octeon chip!\n");
  905. c->cputype = CPU_UNKNOWN;
  906. break;
  907. }
  908. }
  909. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  910. {
  911. decode_configs(c);
  912. /* JZRISC does not implement the CP0 counter. */
  913. c->options &= ~MIPS_CPU_COUNTER;
  914. switch (c->processor_id & 0xff00) {
  915. case PRID_IMP_JZRISC:
  916. c->cputype = CPU_JZRISC;
  917. __cpu_name[cpu] = "Ingenic JZRISC";
  918. break;
  919. default:
  920. panic("Unknown Ingenic Processor ID!");
  921. break;
  922. }
  923. }
  924. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  925. {
  926. decode_configs(c);
  927. c->options = (MIPS_CPU_TLB |
  928. MIPS_CPU_4KEX |
  929. MIPS_CPU_COUNTER |
  930. MIPS_CPU_DIVEC |
  931. MIPS_CPU_WATCH |
  932. MIPS_CPU_EJTAG |
  933. MIPS_CPU_LLSC);
  934. switch (c->processor_id & 0xff00) {
  935. case PRID_IMP_NETLOGIC_XLR732:
  936. case PRID_IMP_NETLOGIC_XLR716:
  937. case PRID_IMP_NETLOGIC_XLR532:
  938. case PRID_IMP_NETLOGIC_XLR308:
  939. case PRID_IMP_NETLOGIC_XLR532C:
  940. case PRID_IMP_NETLOGIC_XLR516C:
  941. case PRID_IMP_NETLOGIC_XLR508C:
  942. case PRID_IMP_NETLOGIC_XLR308C:
  943. c->cputype = CPU_XLR;
  944. __cpu_name[cpu] = "Netlogic XLR";
  945. break;
  946. case PRID_IMP_NETLOGIC_XLS608:
  947. case PRID_IMP_NETLOGIC_XLS408:
  948. case PRID_IMP_NETLOGIC_XLS404:
  949. case PRID_IMP_NETLOGIC_XLS208:
  950. case PRID_IMP_NETLOGIC_XLS204:
  951. case PRID_IMP_NETLOGIC_XLS108:
  952. case PRID_IMP_NETLOGIC_XLS104:
  953. case PRID_IMP_NETLOGIC_XLS616B:
  954. case PRID_IMP_NETLOGIC_XLS608B:
  955. case PRID_IMP_NETLOGIC_XLS416B:
  956. case PRID_IMP_NETLOGIC_XLS412B:
  957. case PRID_IMP_NETLOGIC_XLS408B:
  958. case PRID_IMP_NETLOGIC_XLS404B:
  959. c->cputype = CPU_XLR;
  960. __cpu_name[cpu] = "Netlogic XLS";
  961. break;
  962. default:
  963. printk(KERN_INFO "Unknown Netlogic chip id [%02x]!\n",
  964. c->processor_id);
  965. c->cputype = CPU_XLR;
  966. break;
  967. }
  968. c->isa_level = MIPS_CPU_ISA_M64R1;
  969. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  970. }
  971. #ifdef CONFIG_64BIT
  972. /* For use by uaccess.h */
  973. u64 __ua_limit;
  974. EXPORT_SYMBOL(__ua_limit);
  975. #endif
  976. const char *__cpu_name[NR_CPUS];
  977. const char *__elf_platform;
  978. __cpuinit void cpu_probe(void)
  979. {
  980. struct cpuinfo_mips *c = &current_cpu_data;
  981. unsigned int cpu = smp_processor_id();
  982. c->processor_id = PRID_IMP_UNKNOWN;
  983. c->fpu_id = FPIR_IMP_NONE;
  984. c->cputype = CPU_UNKNOWN;
  985. c->processor_id = read_c0_prid();
  986. switch (c->processor_id & 0xff0000) {
  987. case PRID_COMP_LEGACY:
  988. cpu_probe_legacy(c, cpu);
  989. break;
  990. case PRID_COMP_MIPS:
  991. cpu_probe_mips(c, cpu);
  992. break;
  993. case PRID_COMP_ALCHEMY:
  994. cpu_probe_alchemy(c, cpu);
  995. break;
  996. case PRID_COMP_SIBYTE:
  997. cpu_probe_sibyte(c, cpu);
  998. break;
  999. case PRID_COMP_BROADCOM:
  1000. cpu_probe_broadcom(c, cpu);
  1001. break;
  1002. case PRID_COMP_SANDCRAFT:
  1003. cpu_probe_sandcraft(c, cpu);
  1004. break;
  1005. case PRID_COMP_NXP:
  1006. cpu_probe_nxp(c, cpu);
  1007. break;
  1008. case PRID_COMP_CAVIUM:
  1009. cpu_probe_cavium(c, cpu);
  1010. break;
  1011. case PRID_COMP_INGENIC:
  1012. cpu_probe_ingenic(c, cpu);
  1013. break;
  1014. case PRID_COMP_NETLOGIC:
  1015. cpu_probe_netlogic(c, cpu);
  1016. break;
  1017. }
  1018. BUG_ON(!__cpu_name[cpu]);
  1019. BUG_ON(c->cputype == CPU_UNKNOWN);
  1020. /*
  1021. * Platform code can force the cpu type to optimize code
  1022. * generation. In that case be sure the cpu type is correctly
  1023. * manually setup otherwise it could trigger some nasty bugs.
  1024. */
  1025. BUG_ON(current_cpu_type() != c->cputype);
  1026. if (mips_fpu_disabled)
  1027. c->options &= ~MIPS_CPU_FPU;
  1028. if (mips_dsp_disabled)
  1029. c->ases &= ~MIPS_ASE_DSP;
  1030. if (c->options & MIPS_CPU_FPU) {
  1031. c->fpu_id = cpu_get_fpu_id();
  1032. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  1033. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  1034. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  1035. c->isa_level == MIPS_CPU_ISA_M64R2) {
  1036. if (c->fpu_id & MIPS_FPIR_3D)
  1037. c->ases |= MIPS_ASE_MIPS3D;
  1038. }
  1039. }
  1040. if (cpu_has_mips_r2)
  1041. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1042. else
  1043. c->srsets = 1;
  1044. cpu_probe_vmbits(c);
  1045. #ifdef CONFIG_64BIT
  1046. if (cpu == 0)
  1047. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1048. #endif
  1049. }
  1050. __cpuinit void cpu_report(void)
  1051. {
  1052. struct cpuinfo_mips *c = &current_cpu_data;
  1053. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  1054. c->processor_id, cpu_name_string());
  1055. if (c->options & MIPS_CPU_FPU)
  1056. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1057. }