cpu-probe.c 23 KB

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