cpu-probe.c 23 KB

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