cpu-probe.c 23 KB

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