cpu-probe.c 24 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043
  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. cpu_wait = r4k_wait;
  169. break;
  170. case CPU_RM7000:
  171. cpu_wait = rm7k_wait_irqoff;
  172. break;
  173. case CPU_24K:
  174. case CPU_34K:
  175. case CPU_1004K:
  176. cpu_wait = r4k_wait;
  177. if (read_c0_config7() & MIPS_CONF7_WII)
  178. cpu_wait = r4k_wait_irqoff;
  179. break;
  180. case CPU_74K:
  181. cpu_wait = r4k_wait;
  182. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  183. cpu_wait = r4k_wait_irqoff;
  184. break;
  185. case CPU_TX49XX:
  186. cpu_wait = r4k_wait_irqoff;
  187. break;
  188. case CPU_ALCHEMY:
  189. cpu_wait = au1k_wait;
  190. break;
  191. case CPU_20KC:
  192. /*
  193. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  194. * WAIT on Rev2.0 and Rev3.0 has E16.
  195. * Rev3.1 WAIT is nop, why bother
  196. */
  197. if ((c->processor_id & 0xff) <= 0x64)
  198. break;
  199. /*
  200. * Another rev is incremeting c0_count at a reduced clock
  201. * rate while in WAIT mode. So we basically have the choice
  202. * between using the cp0 timer as clocksource or avoiding
  203. * the WAIT instruction. Until more details are known,
  204. * disable the use of WAIT for 20Kc entirely.
  205. cpu_wait = r4k_wait;
  206. */
  207. break;
  208. case CPU_RM9000:
  209. if ((c->processor_id & 0x00ff) >= 0x40)
  210. cpu_wait = r4k_wait;
  211. break;
  212. default:
  213. break;
  214. }
  215. }
  216. static inline void check_errata(void)
  217. {
  218. struct cpuinfo_mips *c = &current_cpu_data;
  219. switch (c->cputype) {
  220. case CPU_34K:
  221. /*
  222. * Erratum "RPS May Cause Incorrect Instruction Execution"
  223. * This code only handles VPE0, any SMP/SMTC/RTOS code
  224. * making use of VPE1 will be responsable for that VPE.
  225. */
  226. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  227. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  228. break;
  229. default:
  230. break;
  231. }
  232. }
  233. void __init check_bugs32(void)
  234. {
  235. check_errata();
  236. }
  237. /*
  238. * Probe whether cpu has config register by trying to play with
  239. * alternate cache bit and see whether it matters.
  240. * It's used by cpu_probe to distinguish between R3000A and R3081.
  241. */
  242. static inline int cpu_has_confreg(void)
  243. {
  244. #ifdef CONFIG_CPU_R3000
  245. extern unsigned long r3k_cache_size(unsigned long);
  246. unsigned long size1, size2;
  247. unsigned long cfg = read_c0_conf();
  248. size1 = r3k_cache_size(ST0_ISC);
  249. write_c0_conf(cfg ^ R30XX_CONF_AC);
  250. size2 = r3k_cache_size(ST0_ISC);
  251. write_c0_conf(cfg);
  252. return size1 != size2;
  253. #else
  254. return 0;
  255. #endif
  256. }
  257. /*
  258. * Get the FPU Implementation/Revision.
  259. */
  260. static inline unsigned long cpu_get_fpu_id(void)
  261. {
  262. unsigned long tmp, fpu_id;
  263. tmp = read_c0_status();
  264. __enable_fpu();
  265. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  266. write_c0_status(tmp);
  267. return fpu_id;
  268. }
  269. /*
  270. * Check the CPU has an FPU the official way.
  271. */
  272. static inline int __cpu_has_fpu(void)
  273. {
  274. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  275. }
  276. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  277. {
  278. #ifdef __NEED_VMBITS_PROBE
  279. write_c0_entryhi(0x3fffffffffffe000ULL);
  280. back_to_back_c0_hazard();
  281. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  282. #endif
  283. }
  284. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  285. | MIPS_CPU_COUNTER)
  286. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  287. {
  288. switch (c->processor_id & 0xff00) {
  289. case PRID_IMP_R2000:
  290. c->cputype = CPU_R2000;
  291. __cpu_name[cpu] = "R2000";
  292. c->isa_level = MIPS_CPU_ISA_I;
  293. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  294. MIPS_CPU_NOFPUEX;
  295. if (__cpu_has_fpu())
  296. c->options |= MIPS_CPU_FPU;
  297. c->tlbsize = 64;
  298. break;
  299. case PRID_IMP_R3000:
  300. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  301. if (cpu_has_confreg()) {
  302. c->cputype = CPU_R3081E;
  303. __cpu_name[cpu] = "R3081";
  304. } else {
  305. c->cputype = CPU_R3000A;
  306. __cpu_name[cpu] = "R3000A";
  307. }
  308. break;
  309. } else {
  310. c->cputype = CPU_R3000;
  311. __cpu_name[cpu] = "R3000";
  312. }
  313. c->isa_level = MIPS_CPU_ISA_I;
  314. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  315. MIPS_CPU_NOFPUEX;
  316. if (__cpu_has_fpu())
  317. c->options |= MIPS_CPU_FPU;
  318. c->tlbsize = 64;
  319. break;
  320. case PRID_IMP_R4000:
  321. if (read_c0_config() & CONF_SC) {
  322. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  323. c->cputype = CPU_R4400PC;
  324. __cpu_name[cpu] = "R4400PC";
  325. } else {
  326. c->cputype = CPU_R4000PC;
  327. __cpu_name[cpu] = "R4000PC";
  328. }
  329. } else {
  330. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  331. c->cputype = CPU_R4400SC;
  332. __cpu_name[cpu] = "R4400SC";
  333. } else {
  334. c->cputype = CPU_R4000SC;
  335. __cpu_name[cpu] = "R4000SC";
  336. }
  337. }
  338. c->isa_level = MIPS_CPU_ISA_III;
  339. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  340. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  341. MIPS_CPU_LLSC;
  342. c->tlbsize = 48;
  343. break;
  344. case PRID_IMP_VR41XX:
  345. switch (c->processor_id & 0xf0) {
  346. case PRID_REV_VR4111:
  347. c->cputype = CPU_VR4111;
  348. __cpu_name[cpu] = "NEC VR4111";
  349. break;
  350. case PRID_REV_VR4121:
  351. c->cputype = CPU_VR4121;
  352. __cpu_name[cpu] = "NEC VR4121";
  353. break;
  354. case PRID_REV_VR4122:
  355. if ((c->processor_id & 0xf) < 0x3) {
  356. c->cputype = CPU_VR4122;
  357. __cpu_name[cpu] = "NEC VR4122";
  358. } else {
  359. c->cputype = CPU_VR4181A;
  360. __cpu_name[cpu] = "NEC VR4181A";
  361. }
  362. break;
  363. case PRID_REV_VR4130:
  364. if ((c->processor_id & 0xf) < 0x4) {
  365. c->cputype = CPU_VR4131;
  366. __cpu_name[cpu] = "NEC VR4131";
  367. } else {
  368. c->cputype = CPU_VR4133;
  369. __cpu_name[cpu] = "NEC VR4133";
  370. }
  371. break;
  372. default:
  373. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  374. c->cputype = CPU_VR41XX;
  375. __cpu_name[cpu] = "NEC Vr41xx";
  376. break;
  377. }
  378. c->isa_level = MIPS_CPU_ISA_III;
  379. c->options = R4K_OPTS;
  380. c->tlbsize = 32;
  381. break;
  382. case PRID_IMP_R4300:
  383. c->cputype = CPU_R4300;
  384. __cpu_name[cpu] = "R4300";
  385. c->isa_level = MIPS_CPU_ISA_III;
  386. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  387. MIPS_CPU_LLSC;
  388. c->tlbsize = 32;
  389. break;
  390. case PRID_IMP_R4600:
  391. c->cputype = CPU_R4600;
  392. __cpu_name[cpu] = "R4600";
  393. c->isa_level = MIPS_CPU_ISA_III;
  394. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  395. MIPS_CPU_LLSC;
  396. c->tlbsize = 48;
  397. break;
  398. #if 0
  399. case PRID_IMP_R4650:
  400. /*
  401. * This processor doesn't have an MMU, so it's not
  402. * "real easy" to run Linux on it. It is left purely
  403. * for documentation. Commented out because it shares
  404. * it's c0_prid id number with the TX3900.
  405. */
  406. c->cputype = CPU_R4650;
  407. __cpu_name[cpu] = "R4650";
  408. c->isa_level = MIPS_CPU_ISA_III;
  409. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  410. c->tlbsize = 48;
  411. break;
  412. #endif
  413. case PRID_IMP_TX39:
  414. c->isa_level = MIPS_CPU_ISA_I;
  415. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  416. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  417. c->cputype = CPU_TX3927;
  418. __cpu_name[cpu] = "TX3927";
  419. c->tlbsize = 64;
  420. } else {
  421. switch (c->processor_id & 0xff) {
  422. case PRID_REV_TX3912:
  423. c->cputype = CPU_TX3912;
  424. __cpu_name[cpu] = "TX3912";
  425. c->tlbsize = 32;
  426. break;
  427. case PRID_REV_TX3922:
  428. c->cputype = CPU_TX3922;
  429. __cpu_name[cpu] = "TX3922";
  430. c->tlbsize = 64;
  431. break;
  432. }
  433. }
  434. break;
  435. case PRID_IMP_R4700:
  436. c->cputype = CPU_R4700;
  437. __cpu_name[cpu] = "R4700";
  438. c->isa_level = MIPS_CPU_ISA_III;
  439. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  440. MIPS_CPU_LLSC;
  441. c->tlbsize = 48;
  442. break;
  443. case PRID_IMP_TX49:
  444. c->cputype = CPU_TX49XX;
  445. __cpu_name[cpu] = "R49XX";
  446. c->isa_level = MIPS_CPU_ISA_III;
  447. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  448. if (!(c->processor_id & 0x08))
  449. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  450. c->tlbsize = 48;
  451. break;
  452. case PRID_IMP_R5000:
  453. c->cputype = CPU_R5000;
  454. __cpu_name[cpu] = "R5000";
  455. c->isa_level = MIPS_CPU_ISA_IV;
  456. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  457. MIPS_CPU_LLSC;
  458. c->tlbsize = 48;
  459. break;
  460. case PRID_IMP_R5432:
  461. c->cputype = CPU_R5432;
  462. __cpu_name[cpu] = "R5432";
  463. c->isa_level = MIPS_CPU_ISA_IV;
  464. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  465. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  466. c->tlbsize = 48;
  467. break;
  468. case PRID_IMP_R5500:
  469. c->cputype = CPU_R5500;
  470. __cpu_name[cpu] = "R5500";
  471. c->isa_level = MIPS_CPU_ISA_IV;
  472. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  473. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  474. c->tlbsize = 48;
  475. break;
  476. case PRID_IMP_NEVADA:
  477. c->cputype = CPU_NEVADA;
  478. __cpu_name[cpu] = "Nevada";
  479. c->isa_level = MIPS_CPU_ISA_IV;
  480. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  481. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  482. c->tlbsize = 48;
  483. break;
  484. case PRID_IMP_R6000:
  485. c->cputype = CPU_R6000;
  486. __cpu_name[cpu] = "R6000";
  487. c->isa_level = MIPS_CPU_ISA_II;
  488. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  489. MIPS_CPU_LLSC;
  490. c->tlbsize = 32;
  491. break;
  492. case PRID_IMP_R6000A:
  493. c->cputype = CPU_R6000A;
  494. __cpu_name[cpu] = "R6000A";
  495. c->isa_level = MIPS_CPU_ISA_II;
  496. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  497. MIPS_CPU_LLSC;
  498. c->tlbsize = 32;
  499. break;
  500. case PRID_IMP_RM7000:
  501. c->cputype = CPU_RM7000;
  502. __cpu_name[cpu] = "RM7000";
  503. c->isa_level = MIPS_CPU_ISA_IV;
  504. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  505. MIPS_CPU_LLSC;
  506. /*
  507. * Undocumented RM7000: Bit 29 in the info register of
  508. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  509. * entries.
  510. *
  511. * 29 1 => 64 entry JTLB
  512. * 0 => 48 entry JTLB
  513. */
  514. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  515. break;
  516. case PRID_IMP_RM9000:
  517. c->cputype = CPU_RM9000;
  518. __cpu_name[cpu] = "RM9000";
  519. c->isa_level = MIPS_CPU_ISA_IV;
  520. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  521. MIPS_CPU_LLSC;
  522. /*
  523. * Bit 29 in the info register of the RM9000
  524. * indicates if the TLB has 48 or 64 entries.
  525. *
  526. * 29 1 => 64 entry JTLB
  527. * 0 => 48 entry JTLB
  528. */
  529. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  530. break;
  531. case PRID_IMP_R8000:
  532. c->cputype = CPU_R8000;
  533. __cpu_name[cpu] = "RM8000";
  534. c->isa_level = MIPS_CPU_ISA_IV;
  535. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  536. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  537. MIPS_CPU_LLSC;
  538. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  539. break;
  540. case PRID_IMP_R10000:
  541. c->cputype = CPU_R10000;
  542. __cpu_name[cpu] = "R10000";
  543. c->isa_level = MIPS_CPU_ISA_IV;
  544. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  545. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  546. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  547. MIPS_CPU_LLSC;
  548. c->tlbsize = 64;
  549. break;
  550. case PRID_IMP_R12000:
  551. c->cputype = CPU_R12000;
  552. __cpu_name[cpu] = "R12000";
  553. c->isa_level = MIPS_CPU_ISA_IV;
  554. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  555. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  556. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  557. MIPS_CPU_LLSC;
  558. c->tlbsize = 64;
  559. break;
  560. case PRID_IMP_R14000:
  561. c->cputype = CPU_R14000;
  562. __cpu_name[cpu] = "R14000";
  563. c->isa_level = MIPS_CPU_ISA_IV;
  564. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  565. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  566. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  567. MIPS_CPU_LLSC;
  568. c->tlbsize = 64;
  569. break;
  570. case PRID_IMP_LOONGSON2:
  571. c->cputype = CPU_LOONGSON2;
  572. __cpu_name[cpu] = "ICT Loongson-2";
  573. c->isa_level = MIPS_CPU_ISA_III;
  574. c->options = R4K_OPTS |
  575. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  576. MIPS_CPU_32FPR;
  577. c->tlbsize = 64;
  578. break;
  579. }
  580. }
  581. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  582. "Unsupported ISA type, c0.config0: %d.";
  583. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  584. {
  585. unsigned int config0;
  586. int isa;
  587. config0 = read_c0_config();
  588. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  589. c->options |= MIPS_CPU_TLB;
  590. isa = (config0 & MIPS_CONF_AT) >> 13;
  591. switch (isa) {
  592. case 0:
  593. switch ((config0 & MIPS_CONF_AR) >> 10) {
  594. case 0:
  595. c->isa_level = MIPS_CPU_ISA_M32R1;
  596. break;
  597. case 1:
  598. c->isa_level = MIPS_CPU_ISA_M32R2;
  599. break;
  600. default:
  601. goto unknown;
  602. }
  603. break;
  604. case 2:
  605. switch ((config0 & MIPS_CONF_AR) >> 10) {
  606. case 0:
  607. c->isa_level = MIPS_CPU_ISA_M64R1;
  608. break;
  609. case 1:
  610. c->isa_level = MIPS_CPU_ISA_M64R2;
  611. break;
  612. default:
  613. goto unknown;
  614. }
  615. break;
  616. default:
  617. goto unknown;
  618. }
  619. return config0 & MIPS_CONF_M;
  620. unknown:
  621. panic(unknown_isa, config0);
  622. }
  623. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  624. {
  625. unsigned int config1;
  626. config1 = read_c0_config1();
  627. if (config1 & MIPS_CONF1_MD)
  628. c->ases |= MIPS_ASE_MDMX;
  629. if (config1 & MIPS_CONF1_WR)
  630. c->options |= MIPS_CPU_WATCH;
  631. if (config1 & MIPS_CONF1_CA)
  632. c->ases |= MIPS_ASE_MIPS16;
  633. if (config1 & MIPS_CONF1_EP)
  634. c->options |= MIPS_CPU_EJTAG;
  635. if (config1 & MIPS_CONF1_FP) {
  636. c->options |= MIPS_CPU_FPU;
  637. c->options |= MIPS_CPU_32FPR;
  638. }
  639. if (cpu_has_tlb)
  640. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  641. return config1 & MIPS_CONF_M;
  642. }
  643. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  644. {
  645. unsigned int config2;
  646. config2 = read_c0_config2();
  647. if (config2 & MIPS_CONF2_SL)
  648. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  649. return config2 & MIPS_CONF_M;
  650. }
  651. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  652. {
  653. unsigned int config3;
  654. config3 = read_c0_config3();
  655. if (config3 & MIPS_CONF3_SM)
  656. c->ases |= MIPS_ASE_SMARTMIPS;
  657. if (config3 & MIPS_CONF3_DSP)
  658. c->ases |= MIPS_ASE_DSP;
  659. if (config3 & MIPS_CONF3_VINT)
  660. c->options |= MIPS_CPU_VINT;
  661. if (config3 & MIPS_CONF3_VEIC)
  662. c->options |= MIPS_CPU_VEIC;
  663. if (config3 & MIPS_CONF3_MT)
  664. c->ases |= MIPS_ASE_MIPSMT;
  665. if (config3 & MIPS_CONF3_ULRI)
  666. c->options |= MIPS_CPU_ULRI;
  667. return config3 & MIPS_CONF_M;
  668. }
  669. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  670. {
  671. unsigned int config4;
  672. config4 = read_c0_config4();
  673. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  674. && cpu_has_tlb)
  675. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  676. return config4 & MIPS_CONF_M;
  677. }
  678. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  679. {
  680. int ok;
  681. /* MIPS32 or MIPS64 compliant CPU. */
  682. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  683. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  684. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  685. ok = decode_config0(c); /* Read Config registers. */
  686. BUG_ON(!ok); /* Arch spec violation! */
  687. if (ok)
  688. ok = decode_config1(c);
  689. if (ok)
  690. ok = decode_config2(c);
  691. if (ok)
  692. ok = decode_config3(c);
  693. if (ok)
  694. ok = decode_config4(c);
  695. mips_probe_watch_registers(c);
  696. }
  697. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  698. {
  699. decode_configs(c);
  700. switch (c->processor_id & 0xff00) {
  701. case PRID_IMP_4KC:
  702. c->cputype = CPU_4KC;
  703. __cpu_name[cpu] = "MIPS 4Kc";
  704. break;
  705. case PRID_IMP_4KEC:
  706. case PRID_IMP_4KECR2:
  707. c->cputype = CPU_4KEC;
  708. __cpu_name[cpu] = "MIPS 4KEc";
  709. break;
  710. case PRID_IMP_4KSC:
  711. case PRID_IMP_4KSD:
  712. c->cputype = CPU_4KSC;
  713. __cpu_name[cpu] = "MIPS 4KSc";
  714. break;
  715. case PRID_IMP_5KC:
  716. c->cputype = CPU_5KC;
  717. __cpu_name[cpu] = "MIPS 5Kc";
  718. break;
  719. case PRID_IMP_20KC:
  720. c->cputype = CPU_20KC;
  721. __cpu_name[cpu] = "MIPS 20Kc";
  722. break;
  723. case PRID_IMP_24K:
  724. case PRID_IMP_24KE:
  725. c->cputype = CPU_24K;
  726. __cpu_name[cpu] = "MIPS 24Kc";
  727. break;
  728. case PRID_IMP_25KF:
  729. c->cputype = CPU_25KF;
  730. __cpu_name[cpu] = "MIPS 25Kc";
  731. break;
  732. case PRID_IMP_34K:
  733. c->cputype = CPU_34K;
  734. __cpu_name[cpu] = "MIPS 34Kc";
  735. break;
  736. case PRID_IMP_74K:
  737. c->cputype = CPU_74K;
  738. __cpu_name[cpu] = "MIPS 74Kc";
  739. break;
  740. case PRID_IMP_1004K:
  741. c->cputype = CPU_1004K;
  742. __cpu_name[cpu] = "MIPS 1004Kc";
  743. break;
  744. }
  745. spram_config();
  746. }
  747. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  748. {
  749. decode_configs(c);
  750. switch (c->processor_id & 0xff00) {
  751. case PRID_IMP_AU1_REV1:
  752. case PRID_IMP_AU1_REV2:
  753. c->cputype = CPU_ALCHEMY;
  754. switch ((c->processor_id >> 24) & 0xff) {
  755. case 0:
  756. __cpu_name[cpu] = "Au1000";
  757. break;
  758. case 1:
  759. __cpu_name[cpu] = "Au1500";
  760. break;
  761. case 2:
  762. __cpu_name[cpu] = "Au1100";
  763. break;
  764. case 3:
  765. __cpu_name[cpu] = "Au1550";
  766. break;
  767. case 4:
  768. __cpu_name[cpu] = "Au1200";
  769. if ((c->processor_id & 0xff) == 2)
  770. __cpu_name[cpu] = "Au1250";
  771. break;
  772. case 5:
  773. __cpu_name[cpu] = "Au1210";
  774. break;
  775. default:
  776. __cpu_name[cpu] = "Au1xxx";
  777. break;
  778. }
  779. break;
  780. }
  781. }
  782. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  783. {
  784. decode_configs(c);
  785. switch (c->processor_id & 0xff00) {
  786. case PRID_IMP_SB1:
  787. c->cputype = CPU_SB1;
  788. __cpu_name[cpu] = "SiByte SB1";
  789. /* FPU in pass1 is known to have issues. */
  790. if ((c->processor_id & 0xff) < 0x02)
  791. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  792. break;
  793. case PRID_IMP_SB1A:
  794. c->cputype = CPU_SB1A;
  795. __cpu_name[cpu] = "SiByte SB1A";
  796. break;
  797. }
  798. }
  799. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  800. {
  801. decode_configs(c);
  802. switch (c->processor_id & 0xff00) {
  803. case PRID_IMP_SR71000:
  804. c->cputype = CPU_SR71000;
  805. __cpu_name[cpu] = "Sandcraft SR71000";
  806. c->scache.ways = 8;
  807. c->tlbsize = 64;
  808. break;
  809. }
  810. }
  811. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  812. {
  813. decode_configs(c);
  814. switch (c->processor_id & 0xff00) {
  815. case PRID_IMP_PR4450:
  816. c->cputype = CPU_PR4450;
  817. __cpu_name[cpu] = "Philips PR4450";
  818. c->isa_level = MIPS_CPU_ISA_M32R1;
  819. break;
  820. }
  821. }
  822. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  823. {
  824. decode_configs(c);
  825. switch (c->processor_id & 0xff00) {
  826. case PRID_IMP_BCM3302:
  827. /* same as PRID_IMP_BCM6338 */
  828. c->cputype = CPU_BCM3302;
  829. __cpu_name[cpu] = "Broadcom BCM3302";
  830. break;
  831. case PRID_IMP_BCM4710:
  832. c->cputype = CPU_BCM4710;
  833. __cpu_name[cpu] = "Broadcom BCM4710";
  834. break;
  835. case PRID_IMP_BCM6345:
  836. c->cputype = CPU_BCM6345;
  837. __cpu_name[cpu] = "Broadcom BCM6345";
  838. break;
  839. case PRID_IMP_BCM6348:
  840. c->cputype = CPU_BCM6348;
  841. __cpu_name[cpu] = "Broadcom BCM6348";
  842. break;
  843. case PRID_IMP_BCM4350:
  844. switch (c->processor_id & 0xf0) {
  845. case PRID_REV_BCM6358:
  846. c->cputype = CPU_BCM6358;
  847. __cpu_name[cpu] = "Broadcom BCM6358";
  848. break;
  849. default:
  850. c->cputype = CPU_UNKNOWN;
  851. break;
  852. }
  853. break;
  854. }
  855. }
  856. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  857. {
  858. decode_configs(c);
  859. switch (c->processor_id & 0xff00) {
  860. case PRID_IMP_CAVIUM_CN38XX:
  861. case PRID_IMP_CAVIUM_CN31XX:
  862. case PRID_IMP_CAVIUM_CN30XX:
  863. c->cputype = CPU_CAVIUM_OCTEON;
  864. __cpu_name[cpu] = "Cavium Octeon";
  865. goto platform;
  866. case PRID_IMP_CAVIUM_CN58XX:
  867. case PRID_IMP_CAVIUM_CN56XX:
  868. case PRID_IMP_CAVIUM_CN50XX:
  869. case PRID_IMP_CAVIUM_CN52XX:
  870. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  871. __cpu_name[cpu] = "Cavium Octeon+";
  872. platform:
  873. if (cpu == 0)
  874. __elf_platform = "octeon";
  875. break;
  876. default:
  877. printk(KERN_INFO "Unknown Octeon chip!\n");
  878. c->cputype = CPU_UNKNOWN;
  879. break;
  880. }
  881. }
  882. const char *__cpu_name[NR_CPUS];
  883. const char *__elf_platform;
  884. __cpuinit void cpu_probe(void)
  885. {
  886. struct cpuinfo_mips *c = &current_cpu_data;
  887. unsigned int cpu = smp_processor_id();
  888. c->processor_id = PRID_IMP_UNKNOWN;
  889. c->fpu_id = FPIR_IMP_NONE;
  890. c->cputype = CPU_UNKNOWN;
  891. c->processor_id = read_c0_prid();
  892. switch (c->processor_id & 0xff0000) {
  893. case PRID_COMP_LEGACY:
  894. cpu_probe_legacy(c, cpu);
  895. break;
  896. case PRID_COMP_MIPS:
  897. cpu_probe_mips(c, cpu);
  898. break;
  899. case PRID_COMP_ALCHEMY:
  900. cpu_probe_alchemy(c, cpu);
  901. break;
  902. case PRID_COMP_SIBYTE:
  903. cpu_probe_sibyte(c, cpu);
  904. break;
  905. case PRID_COMP_BROADCOM:
  906. cpu_probe_broadcom(c, cpu);
  907. break;
  908. case PRID_COMP_SANDCRAFT:
  909. cpu_probe_sandcraft(c, cpu);
  910. break;
  911. case PRID_COMP_NXP:
  912. cpu_probe_nxp(c, cpu);
  913. break;
  914. case PRID_COMP_CAVIUM:
  915. cpu_probe_cavium(c, cpu);
  916. break;
  917. }
  918. BUG_ON(!__cpu_name[cpu]);
  919. BUG_ON(c->cputype == CPU_UNKNOWN);
  920. /*
  921. * Platform code can force the cpu type to optimize code
  922. * generation. In that case be sure the cpu type is correctly
  923. * manually setup otherwise it could trigger some nasty bugs.
  924. */
  925. BUG_ON(current_cpu_type() != c->cputype);
  926. if (mips_fpu_disabled)
  927. c->options &= ~MIPS_CPU_FPU;
  928. if (mips_dsp_disabled)
  929. c->ases &= ~MIPS_ASE_DSP;
  930. if (c->options & MIPS_CPU_FPU) {
  931. c->fpu_id = cpu_get_fpu_id();
  932. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  933. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  934. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  935. c->isa_level == MIPS_CPU_ISA_M64R2) {
  936. if (c->fpu_id & MIPS_FPIR_3D)
  937. c->ases |= MIPS_ASE_MIPS3D;
  938. }
  939. }
  940. if (cpu_has_mips_r2)
  941. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  942. else
  943. c->srsets = 1;
  944. cpu_probe_vmbits(c);
  945. }
  946. __cpuinit void cpu_report(void)
  947. {
  948. struct cpuinfo_mips *c = &current_cpu_data;
  949. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  950. c->processor_id, cpu_name_string());
  951. if (c->options & MIPS_CPU_FPU)
  952. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  953. }