cpu-probe.c 24 KB

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