cpu-probe.c 25 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073
  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. /*
  28. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  29. * the implementation of the "wait" feature differs between CPU families. This
  30. * points to the function that implements CPU specific wait.
  31. * The wait instruction stops the pipeline and reduces the power consumption of
  32. * the CPU very much.
  33. */
  34. void (*cpu_wait)(void);
  35. EXPORT_SYMBOL(cpu_wait);
  36. static void r3081_wait(void)
  37. {
  38. unsigned long cfg = read_c0_conf();
  39. write_c0_conf(cfg | R30XX_CONF_HALT);
  40. }
  41. static void r39xx_wait(void)
  42. {
  43. local_irq_disable();
  44. if (!need_resched())
  45. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  46. local_irq_enable();
  47. }
  48. extern void r4k_wait(void);
  49. /*
  50. * This variant is preferable as it allows testing need_resched and going to
  51. * sleep depending on the outcome atomically. Unfortunately the "It is
  52. * implementation-dependent whether the pipeline restarts when a non-enabled
  53. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  54. * using this version a gamble.
  55. */
  56. void r4k_wait_irqoff(void)
  57. {
  58. local_irq_disable();
  59. if (!need_resched())
  60. __asm__(" .set push \n"
  61. " .set mips3 \n"
  62. " wait \n"
  63. " .set pop \n");
  64. local_irq_enable();
  65. __asm__(" .globl __pastwait \n"
  66. "__pastwait: \n");
  67. return;
  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_BCM3302:
  163. case CPU_BCM6338:
  164. case CPU_BCM6348:
  165. case CPU_BCM6358:
  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. /*
  260. * Get the FPU Implementation/Revision.
  261. */
  262. static inline unsigned long cpu_get_fpu_id(void)
  263. {
  264. unsigned long tmp, fpu_id;
  265. tmp = read_c0_status();
  266. __enable_fpu();
  267. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  268. write_c0_status(tmp);
  269. return fpu_id;
  270. }
  271. /*
  272. * Check the CPU has an FPU the official way.
  273. */
  274. static inline int __cpu_has_fpu(void)
  275. {
  276. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  277. }
  278. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  279. {
  280. #ifdef __NEED_VMBITS_PROBE
  281. write_c0_entryhi(0x3fffffffffffe000ULL);
  282. back_to_back_c0_hazard();
  283. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  284. #endif
  285. }
  286. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  287. | MIPS_CPU_COUNTER)
  288. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  289. {
  290. switch (c->processor_id & 0xff00) {
  291. case PRID_IMP_R2000:
  292. c->cputype = CPU_R2000;
  293. __cpu_name[cpu] = "R2000";
  294. c->isa_level = MIPS_CPU_ISA_I;
  295. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  296. MIPS_CPU_NOFPUEX;
  297. if (__cpu_has_fpu())
  298. c->options |= MIPS_CPU_FPU;
  299. c->tlbsize = 64;
  300. break;
  301. case PRID_IMP_R3000:
  302. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  303. if (cpu_has_confreg()) {
  304. c->cputype = CPU_R3081E;
  305. __cpu_name[cpu] = "R3081";
  306. } else {
  307. c->cputype = CPU_R3000A;
  308. __cpu_name[cpu] = "R3000A";
  309. }
  310. break;
  311. } else {
  312. c->cputype = CPU_R3000;
  313. __cpu_name[cpu] = "R3000";
  314. }
  315. c->isa_level = MIPS_CPU_ISA_I;
  316. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  317. MIPS_CPU_NOFPUEX;
  318. if (__cpu_has_fpu())
  319. c->options |= MIPS_CPU_FPU;
  320. c->tlbsize = 64;
  321. break;
  322. case PRID_IMP_R4000:
  323. if (read_c0_config() & CONF_SC) {
  324. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  325. c->cputype = CPU_R4400PC;
  326. __cpu_name[cpu] = "R4400PC";
  327. } else {
  328. c->cputype = CPU_R4000PC;
  329. __cpu_name[cpu] = "R4000PC";
  330. }
  331. } else {
  332. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  333. c->cputype = CPU_R4400SC;
  334. __cpu_name[cpu] = "R4400SC";
  335. } else {
  336. c->cputype = CPU_R4000SC;
  337. __cpu_name[cpu] = "R4000SC";
  338. }
  339. }
  340. c->isa_level = MIPS_CPU_ISA_III;
  341. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  342. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  343. MIPS_CPU_LLSC;
  344. c->tlbsize = 48;
  345. break;
  346. case PRID_IMP_VR41XX:
  347. switch (c->processor_id & 0xf0) {
  348. case PRID_REV_VR4111:
  349. c->cputype = CPU_VR4111;
  350. __cpu_name[cpu] = "NEC VR4111";
  351. break;
  352. case PRID_REV_VR4121:
  353. c->cputype = CPU_VR4121;
  354. __cpu_name[cpu] = "NEC VR4121";
  355. break;
  356. case PRID_REV_VR4122:
  357. if ((c->processor_id & 0xf) < 0x3) {
  358. c->cputype = CPU_VR4122;
  359. __cpu_name[cpu] = "NEC VR4122";
  360. } else {
  361. c->cputype = CPU_VR4181A;
  362. __cpu_name[cpu] = "NEC VR4181A";
  363. }
  364. break;
  365. case PRID_REV_VR4130:
  366. if ((c->processor_id & 0xf) < 0x4) {
  367. c->cputype = CPU_VR4131;
  368. __cpu_name[cpu] = "NEC VR4131";
  369. } else {
  370. c->cputype = CPU_VR4133;
  371. __cpu_name[cpu] = "NEC VR4133";
  372. }
  373. break;
  374. default:
  375. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  376. c->cputype = CPU_VR41XX;
  377. __cpu_name[cpu] = "NEC Vr41xx";
  378. break;
  379. }
  380. c->isa_level = MIPS_CPU_ISA_III;
  381. c->options = R4K_OPTS;
  382. c->tlbsize = 32;
  383. break;
  384. case PRID_IMP_R4300:
  385. c->cputype = CPU_R4300;
  386. __cpu_name[cpu] = "R4300";
  387. c->isa_level = MIPS_CPU_ISA_III;
  388. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  389. MIPS_CPU_LLSC;
  390. c->tlbsize = 32;
  391. break;
  392. case PRID_IMP_R4600:
  393. c->cputype = CPU_R4600;
  394. __cpu_name[cpu] = "R4600";
  395. c->isa_level = MIPS_CPU_ISA_III;
  396. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  397. MIPS_CPU_LLSC;
  398. c->tlbsize = 48;
  399. break;
  400. #if 0
  401. case PRID_IMP_R4650:
  402. /*
  403. * This processor doesn't have an MMU, so it's not
  404. * "real easy" to run Linux on it. It is left purely
  405. * for documentation. Commented out because it shares
  406. * it's c0_prid id number with the TX3900.
  407. */
  408. c->cputype = CPU_R4650;
  409. __cpu_name[cpu] = "R4650";
  410. c->isa_level = MIPS_CPU_ISA_III;
  411. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  412. c->tlbsize = 48;
  413. break;
  414. #endif
  415. case PRID_IMP_TX39:
  416. c->isa_level = MIPS_CPU_ISA_I;
  417. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  418. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  419. c->cputype = CPU_TX3927;
  420. __cpu_name[cpu] = "TX3927";
  421. c->tlbsize = 64;
  422. } else {
  423. switch (c->processor_id & 0xff) {
  424. case PRID_REV_TX3912:
  425. c->cputype = CPU_TX3912;
  426. __cpu_name[cpu] = "TX3912";
  427. c->tlbsize = 32;
  428. break;
  429. case PRID_REV_TX3922:
  430. c->cputype = CPU_TX3922;
  431. __cpu_name[cpu] = "TX3922";
  432. c->tlbsize = 64;
  433. break;
  434. }
  435. }
  436. break;
  437. case PRID_IMP_R4700:
  438. c->cputype = CPU_R4700;
  439. __cpu_name[cpu] = "R4700";
  440. c->isa_level = MIPS_CPU_ISA_III;
  441. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  442. MIPS_CPU_LLSC;
  443. c->tlbsize = 48;
  444. break;
  445. case PRID_IMP_TX49:
  446. c->cputype = CPU_TX49XX;
  447. __cpu_name[cpu] = "R49XX";
  448. c->isa_level = MIPS_CPU_ISA_III;
  449. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  450. if (!(c->processor_id & 0x08))
  451. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  452. c->tlbsize = 48;
  453. break;
  454. case PRID_IMP_R5000:
  455. c->cputype = CPU_R5000;
  456. __cpu_name[cpu] = "R5000";
  457. c->isa_level = MIPS_CPU_ISA_IV;
  458. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  459. MIPS_CPU_LLSC;
  460. c->tlbsize = 48;
  461. break;
  462. case PRID_IMP_R5432:
  463. c->cputype = CPU_R5432;
  464. __cpu_name[cpu] = "R5432";
  465. c->isa_level = MIPS_CPU_ISA_IV;
  466. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  467. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  468. c->tlbsize = 48;
  469. break;
  470. case PRID_IMP_R5500:
  471. c->cputype = CPU_R5500;
  472. __cpu_name[cpu] = "R5500";
  473. c->isa_level = MIPS_CPU_ISA_IV;
  474. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  475. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  476. c->tlbsize = 48;
  477. break;
  478. case PRID_IMP_NEVADA:
  479. c->cputype = CPU_NEVADA;
  480. __cpu_name[cpu] = "Nevada";
  481. c->isa_level = MIPS_CPU_ISA_IV;
  482. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  483. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  484. c->tlbsize = 48;
  485. break;
  486. case PRID_IMP_R6000:
  487. c->cputype = CPU_R6000;
  488. __cpu_name[cpu] = "R6000";
  489. c->isa_level = MIPS_CPU_ISA_II;
  490. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  491. MIPS_CPU_LLSC;
  492. c->tlbsize = 32;
  493. break;
  494. case PRID_IMP_R6000A:
  495. c->cputype = CPU_R6000A;
  496. __cpu_name[cpu] = "R6000A";
  497. c->isa_level = MIPS_CPU_ISA_II;
  498. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  499. MIPS_CPU_LLSC;
  500. c->tlbsize = 32;
  501. break;
  502. case PRID_IMP_RM7000:
  503. c->cputype = CPU_RM7000;
  504. __cpu_name[cpu] = "RM7000";
  505. c->isa_level = MIPS_CPU_ISA_IV;
  506. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  507. MIPS_CPU_LLSC;
  508. /*
  509. * Undocumented RM7000: Bit 29 in the info register of
  510. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  511. * entries.
  512. *
  513. * 29 1 => 64 entry JTLB
  514. * 0 => 48 entry JTLB
  515. */
  516. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  517. break;
  518. case PRID_IMP_RM9000:
  519. c->cputype = CPU_RM9000;
  520. __cpu_name[cpu] = "RM9000";
  521. c->isa_level = MIPS_CPU_ISA_IV;
  522. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  523. MIPS_CPU_LLSC;
  524. /*
  525. * Bit 29 in the info register of the RM9000
  526. * indicates if the TLB has 48 or 64 entries.
  527. *
  528. * 29 1 => 64 entry JTLB
  529. * 0 => 48 entry JTLB
  530. */
  531. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  532. break;
  533. case PRID_IMP_R8000:
  534. c->cputype = CPU_R8000;
  535. __cpu_name[cpu] = "RM8000";
  536. c->isa_level = MIPS_CPU_ISA_IV;
  537. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  538. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  539. MIPS_CPU_LLSC;
  540. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  541. break;
  542. case PRID_IMP_R10000:
  543. c->cputype = CPU_R10000;
  544. __cpu_name[cpu] = "R10000";
  545. c->isa_level = MIPS_CPU_ISA_IV;
  546. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  547. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  548. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  549. MIPS_CPU_LLSC;
  550. c->tlbsize = 64;
  551. break;
  552. case PRID_IMP_R12000:
  553. c->cputype = CPU_R12000;
  554. __cpu_name[cpu] = "R12000";
  555. c->isa_level = MIPS_CPU_ISA_IV;
  556. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  557. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  558. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  559. MIPS_CPU_LLSC;
  560. c->tlbsize = 64;
  561. break;
  562. case PRID_IMP_R14000:
  563. c->cputype = CPU_R14000;
  564. __cpu_name[cpu] = "R14000";
  565. c->isa_level = MIPS_CPU_ISA_IV;
  566. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  567. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  568. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  569. MIPS_CPU_LLSC;
  570. c->tlbsize = 64;
  571. break;
  572. case PRID_IMP_LOONGSON2:
  573. c->cputype = CPU_LOONGSON2;
  574. __cpu_name[cpu] = "ICT Loongson-2";
  575. c->isa_level = MIPS_CPU_ISA_III;
  576. c->options = R4K_OPTS |
  577. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  578. MIPS_CPU_32FPR;
  579. c->tlbsize = 64;
  580. break;
  581. }
  582. }
  583. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  584. "Unsupported ISA type, c0.config0: %d.";
  585. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  586. {
  587. unsigned int config0;
  588. int isa;
  589. config0 = read_c0_config();
  590. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  591. c->options |= MIPS_CPU_TLB;
  592. isa = (config0 & MIPS_CONF_AT) >> 13;
  593. switch (isa) {
  594. case 0:
  595. switch ((config0 & MIPS_CONF_AR) >> 10) {
  596. case 0:
  597. c->isa_level = MIPS_CPU_ISA_M32R1;
  598. break;
  599. case 1:
  600. c->isa_level = MIPS_CPU_ISA_M32R2;
  601. break;
  602. default:
  603. goto unknown;
  604. }
  605. break;
  606. case 2:
  607. switch ((config0 & MIPS_CONF_AR) >> 10) {
  608. case 0:
  609. c->isa_level = MIPS_CPU_ISA_M64R1;
  610. break;
  611. case 1:
  612. c->isa_level = MIPS_CPU_ISA_M64R2;
  613. break;
  614. default:
  615. goto unknown;
  616. }
  617. break;
  618. default:
  619. goto unknown;
  620. }
  621. return config0 & MIPS_CONF_M;
  622. unknown:
  623. panic(unknown_isa, config0);
  624. }
  625. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  626. {
  627. unsigned int config1;
  628. config1 = read_c0_config1();
  629. if (config1 & MIPS_CONF1_MD)
  630. c->ases |= MIPS_ASE_MDMX;
  631. if (config1 & MIPS_CONF1_WR)
  632. c->options |= MIPS_CPU_WATCH;
  633. if (config1 & MIPS_CONF1_CA)
  634. c->ases |= MIPS_ASE_MIPS16;
  635. if (config1 & MIPS_CONF1_EP)
  636. c->options |= MIPS_CPU_EJTAG;
  637. if (config1 & MIPS_CONF1_FP) {
  638. c->options |= MIPS_CPU_FPU;
  639. c->options |= MIPS_CPU_32FPR;
  640. }
  641. if (cpu_has_tlb)
  642. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  643. return config1 & MIPS_CONF_M;
  644. }
  645. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  646. {
  647. unsigned int config2;
  648. config2 = read_c0_config2();
  649. if (config2 & MIPS_CONF2_SL)
  650. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  651. return config2 & MIPS_CONF_M;
  652. }
  653. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  654. {
  655. unsigned int config3;
  656. config3 = read_c0_config3();
  657. if (config3 & MIPS_CONF3_SM)
  658. c->ases |= MIPS_ASE_SMARTMIPS;
  659. if (config3 & MIPS_CONF3_DSP)
  660. c->ases |= MIPS_ASE_DSP;
  661. if (config3 & MIPS_CONF3_VINT)
  662. c->options |= MIPS_CPU_VINT;
  663. if (config3 & MIPS_CONF3_VEIC)
  664. c->options |= MIPS_CPU_VEIC;
  665. if (config3 & MIPS_CONF3_MT)
  666. c->ases |= MIPS_ASE_MIPSMT;
  667. if (config3 & MIPS_CONF3_ULRI)
  668. c->options |= MIPS_CPU_ULRI;
  669. return config3 & MIPS_CONF_M;
  670. }
  671. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  672. {
  673. unsigned int config4;
  674. config4 = read_c0_config4();
  675. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  676. && cpu_has_tlb)
  677. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  678. return config4 & MIPS_CONF_M;
  679. }
  680. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  681. {
  682. int ok;
  683. /* MIPS32 or MIPS64 compliant CPU. */
  684. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  685. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  686. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  687. ok = decode_config0(c); /* Read Config registers. */
  688. BUG_ON(!ok); /* Arch spec violation! */
  689. if (ok)
  690. ok = decode_config1(c);
  691. if (ok)
  692. ok = decode_config2(c);
  693. if (ok)
  694. ok = decode_config3(c);
  695. if (ok)
  696. ok = decode_config4(c);
  697. mips_probe_watch_registers(c);
  698. if (cpu_has_mips_r2)
  699. c->core = read_c0_ebase() & 0x3ff;
  700. }
  701. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  702. {
  703. decode_configs(c);
  704. switch (c->processor_id & 0xff00) {
  705. case PRID_IMP_4KC:
  706. c->cputype = CPU_4KC;
  707. __cpu_name[cpu] = "MIPS 4Kc";
  708. break;
  709. case PRID_IMP_4KEC:
  710. case PRID_IMP_4KECR2:
  711. c->cputype = CPU_4KEC;
  712. __cpu_name[cpu] = "MIPS 4KEc";
  713. break;
  714. case PRID_IMP_4KSC:
  715. case PRID_IMP_4KSD:
  716. c->cputype = CPU_4KSC;
  717. __cpu_name[cpu] = "MIPS 4KSc";
  718. break;
  719. case PRID_IMP_5KC:
  720. c->cputype = CPU_5KC;
  721. __cpu_name[cpu] = "MIPS 5Kc";
  722. break;
  723. case PRID_IMP_20KC:
  724. c->cputype = CPU_20KC;
  725. __cpu_name[cpu] = "MIPS 20Kc";
  726. break;
  727. case PRID_IMP_24K:
  728. case PRID_IMP_24KE:
  729. c->cputype = CPU_24K;
  730. __cpu_name[cpu] = "MIPS 24Kc";
  731. break;
  732. case PRID_IMP_25KF:
  733. c->cputype = CPU_25KF;
  734. __cpu_name[cpu] = "MIPS 25Kc";
  735. break;
  736. case PRID_IMP_34K:
  737. c->cputype = CPU_34K;
  738. __cpu_name[cpu] = "MIPS 34Kc";
  739. break;
  740. case PRID_IMP_74K:
  741. c->cputype = CPU_74K;
  742. __cpu_name[cpu] = "MIPS 74Kc";
  743. break;
  744. case PRID_IMP_1004K:
  745. c->cputype = CPU_1004K;
  746. __cpu_name[cpu] = "MIPS 1004Kc";
  747. break;
  748. }
  749. spram_config();
  750. }
  751. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  752. {
  753. decode_configs(c);
  754. switch (c->processor_id & 0xff00) {
  755. case PRID_IMP_AU1_REV1:
  756. case PRID_IMP_AU1_REV2:
  757. c->cputype = CPU_ALCHEMY;
  758. switch ((c->processor_id >> 24) & 0xff) {
  759. case 0:
  760. __cpu_name[cpu] = "Au1000";
  761. break;
  762. case 1:
  763. __cpu_name[cpu] = "Au1500";
  764. break;
  765. case 2:
  766. __cpu_name[cpu] = "Au1100";
  767. break;
  768. case 3:
  769. __cpu_name[cpu] = "Au1550";
  770. break;
  771. case 4:
  772. __cpu_name[cpu] = "Au1200";
  773. if ((c->processor_id & 0xff) == 2)
  774. __cpu_name[cpu] = "Au1250";
  775. break;
  776. case 5:
  777. __cpu_name[cpu] = "Au1210";
  778. break;
  779. default:
  780. __cpu_name[cpu] = "Au1xxx";
  781. break;
  782. }
  783. break;
  784. }
  785. }
  786. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  787. {
  788. decode_configs(c);
  789. switch (c->processor_id & 0xff00) {
  790. case PRID_IMP_SB1:
  791. c->cputype = CPU_SB1;
  792. __cpu_name[cpu] = "SiByte SB1";
  793. /* FPU in pass1 is known to have issues. */
  794. if ((c->processor_id & 0xff) < 0x02)
  795. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  796. break;
  797. case PRID_IMP_SB1A:
  798. c->cputype = CPU_SB1A;
  799. __cpu_name[cpu] = "SiByte SB1A";
  800. break;
  801. }
  802. }
  803. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  804. {
  805. decode_configs(c);
  806. switch (c->processor_id & 0xff00) {
  807. case PRID_IMP_SR71000:
  808. c->cputype = CPU_SR71000;
  809. __cpu_name[cpu] = "Sandcraft SR71000";
  810. c->scache.ways = 8;
  811. c->tlbsize = 64;
  812. break;
  813. }
  814. }
  815. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  816. {
  817. decode_configs(c);
  818. switch (c->processor_id & 0xff00) {
  819. case PRID_IMP_PR4450:
  820. c->cputype = CPU_PR4450;
  821. __cpu_name[cpu] = "Philips PR4450";
  822. c->isa_level = MIPS_CPU_ISA_M32R1;
  823. break;
  824. }
  825. }
  826. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  827. {
  828. decode_configs(c);
  829. switch (c->processor_id & 0xff00) {
  830. case PRID_IMP_BCM3302:
  831. /* same as PRID_IMP_BCM6338 */
  832. c->cputype = CPU_BCM3302;
  833. __cpu_name[cpu] = "Broadcom BCM3302";
  834. break;
  835. case PRID_IMP_BCM4710:
  836. c->cputype = CPU_BCM4710;
  837. __cpu_name[cpu] = "Broadcom BCM4710";
  838. break;
  839. case PRID_IMP_BCM6345:
  840. c->cputype = CPU_BCM6345;
  841. __cpu_name[cpu] = "Broadcom BCM6345";
  842. break;
  843. case PRID_IMP_BCM6348:
  844. c->cputype = CPU_BCM6348;
  845. __cpu_name[cpu] = "Broadcom BCM6348";
  846. break;
  847. case PRID_IMP_BCM4350:
  848. switch (c->processor_id & 0xf0) {
  849. case PRID_REV_BCM6358:
  850. c->cputype = CPU_BCM6358;
  851. __cpu_name[cpu] = "Broadcom BCM6358";
  852. break;
  853. default:
  854. c->cputype = CPU_UNKNOWN;
  855. break;
  856. }
  857. break;
  858. }
  859. }
  860. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  861. {
  862. decode_configs(c);
  863. switch (c->processor_id & 0xff00) {
  864. case PRID_IMP_CAVIUM_CN38XX:
  865. case PRID_IMP_CAVIUM_CN31XX:
  866. case PRID_IMP_CAVIUM_CN30XX:
  867. c->cputype = CPU_CAVIUM_OCTEON;
  868. __cpu_name[cpu] = "Cavium Octeon";
  869. goto platform;
  870. case PRID_IMP_CAVIUM_CN58XX:
  871. case PRID_IMP_CAVIUM_CN56XX:
  872. case PRID_IMP_CAVIUM_CN50XX:
  873. case PRID_IMP_CAVIUM_CN52XX:
  874. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  875. __cpu_name[cpu] = "Cavium Octeon+";
  876. platform:
  877. if (cpu == 0)
  878. __elf_platform = "octeon";
  879. break;
  880. case PRID_IMP_CAVIUM_CN63XX:
  881. c->cputype = CPU_CAVIUM_OCTEON2;
  882. __cpu_name[cpu] = "Cavium Octeon II";
  883. if (cpu == 0)
  884. __elf_platform = "octeon2";
  885. break;
  886. default:
  887. printk(KERN_INFO "Unknown Octeon chip!\n");
  888. c->cputype = CPU_UNKNOWN;
  889. break;
  890. }
  891. }
  892. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  893. {
  894. decode_configs(c);
  895. /* JZRISC does not implement the CP0 counter. */
  896. c->options &= ~MIPS_CPU_COUNTER;
  897. switch (c->processor_id & 0xff00) {
  898. case PRID_IMP_JZRISC:
  899. c->cputype = CPU_JZRISC;
  900. __cpu_name[cpu] = "Ingenic JZRISC";
  901. break;
  902. default:
  903. panic("Unknown Ingenic Processor ID!");
  904. break;
  905. }
  906. }
  907. const char *__cpu_name[NR_CPUS];
  908. const char *__elf_platform;
  909. __cpuinit void cpu_probe(void)
  910. {
  911. struct cpuinfo_mips *c = &current_cpu_data;
  912. unsigned int cpu = smp_processor_id();
  913. c->processor_id = PRID_IMP_UNKNOWN;
  914. c->fpu_id = FPIR_IMP_NONE;
  915. c->cputype = CPU_UNKNOWN;
  916. c->processor_id = read_c0_prid();
  917. switch (c->processor_id & 0xff0000) {
  918. case PRID_COMP_LEGACY:
  919. cpu_probe_legacy(c, cpu);
  920. break;
  921. case PRID_COMP_MIPS:
  922. cpu_probe_mips(c, cpu);
  923. break;
  924. case PRID_COMP_ALCHEMY:
  925. cpu_probe_alchemy(c, cpu);
  926. break;
  927. case PRID_COMP_SIBYTE:
  928. cpu_probe_sibyte(c, cpu);
  929. break;
  930. case PRID_COMP_BROADCOM:
  931. cpu_probe_broadcom(c, cpu);
  932. break;
  933. case PRID_COMP_SANDCRAFT:
  934. cpu_probe_sandcraft(c, cpu);
  935. break;
  936. case PRID_COMP_NXP:
  937. cpu_probe_nxp(c, cpu);
  938. break;
  939. case PRID_COMP_CAVIUM:
  940. cpu_probe_cavium(c, cpu);
  941. break;
  942. case PRID_COMP_INGENIC:
  943. cpu_probe_ingenic(c, cpu);
  944. break;
  945. }
  946. BUG_ON(!__cpu_name[cpu]);
  947. BUG_ON(c->cputype == CPU_UNKNOWN);
  948. /*
  949. * Platform code can force the cpu type to optimize code
  950. * generation. In that case be sure the cpu type is correctly
  951. * manually setup otherwise it could trigger some nasty bugs.
  952. */
  953. BUG_ON(current_cpu_type() != c->cputype);
  954. if (mips_fpu_disabled)
  955. c->options &= ~MIPS_CPU_FPU;
  956. if (mips_dsp_disabled)
  957. c->ases &= ~MIPS_ASE_DSP;
  958. if (c->options & MIPS_CPU_FPU) {
  959. c->fpu_id = cpu_get_fpu_id();
  960. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  961. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  962. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  963. c->isa_level == MIPS_CPU_ISA_M64R2) {
  964. if (c->fpu_id & MIPS_FPIR_3D)
  965. c->ases |= MIPS_ASE_MIPS3D;
  966. }
  967. }
  968. if (cpu_has_mips_r2)
  969. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  970. else
  971. c->srsets = 1;
  972. cpu_probe_vmbits(c);
  973. }
  974. __cpuinit void cpu_report(void)
  975. {
  976. struct cpuinfo_mips *c = &current_cpu_data;
  977. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  978. c->processor_id, cpu_name_string());
  979. if (c->options & MIPS_CPU_FPU)
  980. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  981. }