cpu-probe.c 23 KB

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