cpu-probe.c 24 KB

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