cpu-probe.c 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847
  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. cpu_wait = r4k_wait;
  147. break;
  148. case CPU_RM7000:
  149. cpu_wait = rm7k_wait_irqoff;
  150. break;
  151. case CPU_24K:
  152. case CPU_34K:
  153. cpu_wait = r4k_wait;
  154. if (read_c0_config7() & MIPS_CONF7_WII)
  155. cpu_wait = r4k_wait_irqoff;
  156. break;
  157. case CPU_74K:
  158. cpu_wait = r4k_wait;
  159. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  160. cpu_wait = r4k_wait_irqoff;
  161. break;
  162. case CPU_TX49XX:
  163. cpu_wait = r4k_wait_irqoff;
  164. break;
  165. case CPU_AU1000:
  166. case CPU_AU1100:
  167. case CPU_AU1500:
  168. case CPU_AU1550:
  169. case CPU_AU1200:
  170. if (allow_au1k_wait)
  171. cpu_wait = au1k_wait;
  172. break;
  173. case CPU_20KC:
  174. /*
  175. * WAIT on Rev1.0 has E1, E2, E3 and E16.
  176. * WAIT on Rev2.0 and Rev3.0 has E16.
  177. * Rev3.1 WAIT is nop, why bother
  178. */
  179. if ((c->processor_id & 0xff) <= 0x64)
  180. break;
  181. /*
  182. * Another rev is incremeting c0_count at a reduced clock
  183. * rate while in WAIT mode. So we basically have the choice
  184. * between using the cp0 timer as clocksource or avoiding
  185. * the WAIT instruction. Until more details are known,
  186. * disable the use of WAIT for 20Kc entirely.
  187. cpu_wait = r4k_wait;
  188. */
  189. break;
  190. case CPU_RM9000:
  191. if ((c->processor_id & 0x00ff) >= 0x40)
  192. cpu_wait = r4k_wait;
  193. break;
  194. default:
  195. break;
  196. }
  197. }
  198. static inline void check_errata(void)
  199. {
  200. struct cpuinfo_mips *c = &current_cpu_data;
  201. switch (c->cputype) {
  202. case CPU_34K:
  203. /*
  204. * Erratum "RPS May Cause Incorrect Instruction Execution"
  205. * This code only handles VPE0, any SMP/SMTC/RTOS code
  206. * making use of VPE1 will be responsable for that VPE.
  207. */
  208. if ((c->processor_id & PRID_REV_MASK) <= PRID_REV_34K_V1_0_2)
  209. write_c0_config7(read_c0_config7() | MIPS_CONF7_RPS);
  210. break;
  211. default:
  212. break;
  213. }
  214. }
  215. void __init check_bugs32(void)
  216. {
  217. check_wait();
  218. check_errata();
  219. }
  220. /*
  221. * Probe whether cpu has config register by trying to play with
  222. * alternate cache bit and see whether it matters.
  223. * It's used by cpu_probe to distinguish between R3000A and R3081.
  224. */
  225. static inline int cpu_has_confreg(void)
  226. {
  227. #ifdef CONFIG_CPU_R3000
  228. extern unsigned long r3k_cache_size(unsigned long);
  229. unsigned long size1, size2;
  230. unsigned long cfg = read_c0_conf();
  231. size1 = r3k_cache_size(ST0_ISC);
  232. write_c0_conf(cfg ^ R30XX_CONF_AC);
  233. size2 = r3k_cache_size(ST0_ISC);
  234. write_c0_conf(cfg);
  235. return size1 != size2;
  236. #else
  237. return 0;
  238. #endif
  239. }
  240. /*
  241. * Get the FPU Implementation/Revision.
  242. */
  243. static inline unsigned long cpu_get_fpu_id(void)
  244. {
  245. unsigned long tmp, fpu_id;
  246. tmp = read_c0_status();
  247. __enable_fpu();
  248. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  249. write_c0_status(tmp);
  250. return fpu_id;
  251. }
  252. /*
  253. * Check the CPU has an FPU the official way.
  254. */
  255. static inline int __cpu_has_fpu(void)
  256. {
  257. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  258. }
  259. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  260. | MIPS_CPU_COUNTER)
  261. static inline void cpu_probe_legacy(struct cpuinfo_mips *c)
  262. {
  263. switch (c->processor_id & 0xff00) {
  264. case PRID_IMP_R2000:
  265. c->cputype = CPU_R2000;
  266. c->isa_level = MIPS_CPU_ISA_I;
  267. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  268. MIPS_CPU_NOFPUEX;
  269. if (__cpu_has_fpu())
  270. c->options |= MIPS_CPU_FPU;
  271. c->tlbsize = 64;
  272. break;
  273. case PRID_IMP_R3000:
  274. if ((c->processor_id & 0xff) == PRID_REV_R3000A)
  275. if (cpu_has_confreg())
  276. c->cputype = CPU_R3081E;
  277. else
  278. c->cputype = CPU_R3000A;
  279. else
  280. c->cputype = CPU_R3000;
  281. c->isa_level = MIPS_CPU_ISA_I;
  282. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  283. MIPS_CPU_NOFPUEX;
  284. if (__cpu_has_fpu())
  285. c->options |= MIPS_CPU_FPU;
  286. c->tlbsize = 64;
  287. break;
  288. case PRID_IMP_R4000:
  289. if (read_c0_config() & CONF_SC) {
  290. if ((c->processor_id & 0xff) >= PRID_REV_R4400)
  291. c->cputype = CPU_R4400PC;
  292. else
  293. c->cputype = CPU_R4000PC;
  294. } else {
  295. if ((c->processor_id & 0xff) >= PRID_REV_R4400)
  296. c->cputype = CPU_R4400SC;
  297. else
  298. c->cputype = CPU_R4000SC;
  299. }
  300. c->isa_level = MIPS_CPU_ISA_III;
  301. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  302. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  303. MIPS_CPU_LLSC;
  304. c->tlbsize = 48;
  305. break;
  306. case PRID_IMP_VR41XX:
  307. switch (c->processor_id & 0xf0) {
  308. case PRID_REV_VR4111:
  309. c->cputype = CPU_VR4111;
  310. break;
  311. case PRID_REV_VR4121:
  312. c->cputype = CPU_VR4121;
  313. break;
  314. case PRID_REV_VR4122:
  315. if ((c->processor_id & 0xf) < 0x3)
  316. c->cputype = CPU_VR4122;
  317. else
  318. c->cputype = CPU_VR4181A;
  319. break;
  320. case PRID_REV_VR4130:
  321. if ((c->processor_id & 0xf) < 0x4)
  322. c->cputype = CPU_VR4131;
  323. else
  324. c->cputype = CPU_VR4133;
  325. break;
  326. default:
  327. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  328. c->cputype = CPU_VR41XX;
  329. break;
  330. }
  331. c->isa_level = MIPS_CPU_ISA_III;
  332. c->options = R4K_OPTS;
  333. c->tlbsize = 32;
  334. break;
  335. case PRID_IMP_R4300:
  336. c->cputype = CPU_R4300;
  337. c->isa_level = MIPS_CPU_ISA_III;
  338. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  339. MIPS_CPU_LLSC;
  340. c->tlbsize = 32;
  341. break;
  342. case PRID_IMP_R4600:
  343. c->cputype = CPU_R4600;
  344. c->isa_level = MIPS_CPU_ISA_III;
  345. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  346. MIPS_CPU_LLSC;
  347. c->tlbsize = 48;
  348. break;
  349. #if 0
  350. case PRID_IMP_R4650:
  351. /*
  352. * This processor doesn't have an MMU, so it's not
  353. * "real easy" to run Linux on it. It is left purely
  354. * for documentation. Commented out because it shares
  355. * it's c0_prid id number with the TX3900.
  356. */
  357. c->cputype = CPU_R4650;
  358. c->isa_level = MIPS_CPU_ISA_III;
  359. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  360. c->tlbsize = 48;
  361. break;
  362. #endif
  363. case PRID_IMP_TX39:
  364. c->isa_level = MIPS_CPU_ISA_I;
  365. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  366. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  367. c->cputype = CPU_TX3927;
  368. c->tlbsize = 64;
  369. } else {
  370. switch (c->processor_id & 0xff) {
  371. case PRID_REV_TX3912:
  372. c->cputype = CPU_TX3912;
  373. c->tlbsize = 32;
  374. break;
  375. case PRID_REV_TX3922:
  376. c->cputype = CPU_TX3922;
  377. c->tlbsize = 64;
  378. break;
  379. default:
  380. c->cputype = CPU_UNKNOWN;
  381. break;
  382. }
  383. }
  384. break;
  385. case PRID_IMP_R4700:
  386. c->cputype = CPU_R4700;
  387. c->isa_level = MIPS_CPU_ISA_III;
  388. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  389. MIPS_CPU_LLSC;
  390. c->tlbsize = 48;
  391. break;
  392. case PRID_IMP_TX49:
  393. c->cputype = CPU_TX49XX;
  394. c->isa_level = MIPS_CPU_ISA_III;
  395. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  396. if (!(c->processor_id & 0x08))
  397. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  398. c->tlbsize = 48;
  399. break;
  400. case PRID_IMP_R5000:
  401. c->cputype = CPU_R5000;
  402. c->isa_level = MIPS_CPU_ISA_IV;
  403. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  404. MIPS_CPU_LLSC;
  405. c->tlbsize = 48;
  406. break;
  407. case PRID_IMP_R5432:
  408. c->cputype = CPU_R5432;
  409. c->isa_level = MIPS_CPU_ISA_IV;
  410. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  411. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  412. c->tlbsize = 48;
  413. break;
  414. case PRID_IMP_R5500:
  415. c->cputype = CPU_R5500;
  416. c->isa_level = MIPS_CPU_ISA_IV;
  417. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  418. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  419. c->tlbsize = 48;
  420. break;
  421. case PRID_IMP_NEVADA:
  422. c->cputype = CPU_NEVADA;
  423. c->isa_level = MIPS_CPU_ISA_IV;
  424. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  425. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  426. c->tlbsize = 48;
  427. break;
  428. case PRID_IMP_R6000:
  429. c->cputype = CPU_R6000;
  430. c->isa_level = MIPS_CPU_ISA_II;
  431. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  432. MIPS_CPU_LLSC;
  433. c->tlbsize = 32;
  434. break;
  435. case PRID_IMP_R6000A:
  436. c->cputype = CPU_R6000A;
  437. c->isa_level = MIPS_CPU_ISA_II;
  438. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  439. MIPS_CPU_LLSC;
  440. c->tlbsize = 32;
  441. break;
  442. case PRID_IMP_RM7000:
  443. c->cputype = CPU_RM7000;
  444. c->isa_level = MIPS_CPU_ISA_IV;
  445. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  446. MIPS_CPU_LLSC;
  447. /*
  448. * Undocumented RM7000: Bit 29 in the info register of
  449. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  450. * entries.
  451. *
  452. * 29 1 => 64 entry JTLB
  453. * 0 => 48 entry JTLB
  454. */
  455. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  456. break;
  457. case PRID_IMP_RM9000:
  458. c->cputype = CPU_RM9000;
  459. c->isa_level = MIPS_CPU_ISA_IV;
  460. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  461. MIPS_CPU_LLSC;
  462. /*
  463. * Bit 29 in the info register of the RM9000
  464. * indicates if the TLB has 48 or 64 entries.
  465. *
  466. * 29 1 => 64 entry JTLB
  467. * 0 => 48 entry JTLB
  468. */
  469. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  470. break;
  471. case PRID_IMP_R8000:
  472. c->cputype = CPU_R8000;
  473. c->isa_level = MIPS_CPU_ISA_IV;
  474. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  475. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  476. MIPS_CPU_LLSC;
  477. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  478. break;
  479. case PRID_IMP_R10000:
  480. c->cputype = CPU_R10000;
  481. c->isa_level = MIPS_CPU_ISA_IV;
  482. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  483. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  484. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  485. MIPS_CPU_LLSC;
  486. c->tlbsize = 64;
  487. break;
  488. case PRID_IMP_R12000:
  489. c->cputype = CPU_R12000;
  490. c->isa_level = MIPS_CPU_ISA_IV;
  491. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  492. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  493. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  494. MIPS_CPU_LLSC;
  495. c->tlbsize = 64;
  496. break;
  497. case PRID_IMP_R14000:
  498. c->cputype = CPU_R14000;
  499. c->isa_level = MIPS_CPU_ISA_IV;
  500. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  501. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  502. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  503. MIPS_CPU_LLSC;
  504. c->tlbsize = 64;
  505. break;
  506. case PRID_IMP_LOONGSON2:
  507. c->cputype = CPU_LOONGSON2;
  508. c->isa_level = MIPS_CPU_ISA_III;
  509. c->options = R4K_OPTS |
  510. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  511. MIPS_CPU_32FPR;
  512. c->tlbsize = 64;
  513. break;
  514. }
  515. }
  516. static char unknown_isa[] __initdata = KERN_ERR \
  517. "Unsupported ISA type, c0.config0: %d.";
  518. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  519. {
  520. unsigned int config0;
  521. int isa;
  522. config0 = read_c0_config();
  523. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  524. c->options |= MIPS_CPU_TLB;
  525. isa = (config0 & MIPS_CONF_AT) >> 13;
  526. switch (isa) {
  527. case 0:
  528. switch ((config0 & MIPS_CONF_AR) >> 10) {
  529. case 0:
  530. c->isa_level = MIPS_CPU_ISA_M32R1;
  531. break;
  532. case 1:
  533. c->isa_level = MIPS_CPU_ISA_M32R2;
  534. break;
  535. default:
  536. goto unknown;
  537. }
  538. break;
  539. case 2:
  540. switch ((config0 & MIPS_CONF_AR) >> 10) {
  541. case 0:
  542. c->isa_level = MIPS_CPU_ISA_M64R1;
  543. break;
  544. case 1:
  545. c->isa_level = MIPS_CPU_ISA_M64R2;
  546. break;
  547. default:
  548. goto unknown;
  549. }
  550. break;
  551. default:
  552. goto unknown;
  553. }
  554. return config0 & MIPS_CONF_M;
  555. unknown:
  556. panic(unknown_isa, config0);
  557. }
  558. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  559. {
  560. unsigned int config1;
  561. config1 = read_c0_config1();
  562. if (config1 & MIPS_CONF1_MD)
  563. c->ases |= MIPS_ASE_MDMX;
  564. if (config1 & MIPS_CONF1_WR)
  565. c->options |= MIPS_CPU_WATCH;
  566. if (config1 & MIPS_CONF1_CA)
  567. c->ases |= MIPS_ASE_MIPS16;
  568. if (config1 & MIPS_CONF1_EP)
  569. c->options |= MIPS_CPU_EJTAG;
  570. if (config1 & MIPS_CONF1_FP) {
  571. c->options |= MIPS_CPU_FPU;
  572. c->options |= MIPS_CPU_32FPR;
  573. }
  574. if (cpu_has_tlb)
  575. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  576. return config1 & MIPS_CONF_M;
  577. }
  578. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  579. {
  580. unsigned int config2;
  581. config2 = read_c0_config2();
  582. if (config2 & MIPS_CONF2_SL)
  583. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  584. return config2 & MIPS_CONF_M;
  585. }
  586. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  587. {
  588. unsigned int config3;
  589. config3 = read_c0_config3();
  590. if (config3 & MIPS_CONF3_SM)
  591. c->ases |= MIPS_ASE_SMARTMIPS;
  592. if (config3 & MIPS_CONF3_DSP)
  593. c->ases |= MIPS_ASE_DSP;
  594. if (config3 & MIPS_CONF3_VINT)
  595. c->options |= MIPS_CPU_VINT;
  596. if (config3 & MIPS_CONF3_VEIC)
  597. c->options |= MIPS_CPU_VEIC;
  598. if (config3 & MIPS_CONF3_MT)
  599. c->ases |= MIPS_ASE_MIPSMT;
  600. if (config3 & MIPS_CONF3_ULRI)
  601. c->options |= MIPS_CPU_ULRI;
  602. return config3 & MIPS_CONF_M;
  603. }
  604. static void __init decode_configs(struct cpuinfo_mips *c)
  605. {
  606. /* MIPS32 or MIPS64 compliant CPU. */
  607. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  608. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  609. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  610. /* Read Config registers. */
  611. if (!decode_config0(c))
  612. return; /* actually worth a panic() */
  613. if (!decode_config1(c))
  614. return;
  615. if (!decode_config2(c))
  616. return;
  617. if (!decode_config3(c))
  618. return;
  619. }
  620. static inline void cpu_probe_mips(struct cpuinfo_mips *c)
  621. {
  622. decode_configs(c);
  623. switch (c->processor_id & 0xff00) {
  624. case PRID_IMP_4KC:
  625. c->cputype = CPU_4KC;
  626. break;
  627. case PRID_IMP_4KEC:
  628. c->cputype = CPU_4KEC;
  629. break;
  630. case PRID_IMP_4KECR2:
  631. c->cputype = CPU_4KEC;
  632. break;
  633. case PRID_IMP_4KSC:
  634. case PRID_IMP_4KSD:
  635. c->cputype = CPU_4KSC;
  636. break;
  637. case PRID_IMP_5KC:
  638. c->cputype = CPU_5KC;
  639. break;
  640. case PRID_IMP_20KC:
  641. c->cputype = CPU_20KC;
  642. break;
  643. case PRID_IMP_24K:
  644. case PRID_IMP_24KE:
  645. c->cputype = CPU_24K;
  646. break;
  647. case PRID_IMP_25KF:
  648. c->cputype = CPU_25KF;
  649. break;
  650. case PRID_IMP_34K:
  651. c->cputype = CPU_34K;
  652. break;
  653. case PRID_IMP_74K:
  654. c->cputype = CPU_74K;
  655. break;
  656. }
  657. }
  658. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c)
  659. {
  660. decode_configs(c);
  661. switch (c->processor_id & 0xff00) {
  662. case PRID_IMP_AU1_REV1:
  663. case PRID_IMP_AU1_REV2:
  664. switch ((c->processor_id >> 24) & 0xff) {
  665. case 0:
  666. c->cputype = CPU_AU1000;
  667. break;
  668. case 1:
  669. c->cputype = CPU_AU1500;
  670. break;
  671. case 2:
  672. c->cputype = CPU_AU1100;
  673. break;
  674. case 3:
  675. c->cputype = CPU_AU1550;
  676. break;
  677. case 4:
  678. c->cputype = CPU_AU1200;
  679. break;
  680. default:
  681. panic("Unknown Au Core!");
  682. break;
  683. }
  684. break;
  685. }
  686. }
  687. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c)
  688. {
  689. decode_configs(c);
  690. /*
  691. * For historical reasons the SB1 comes with it's own variant of
  692. * cache code which eventually will be folded into c-r4k.c. Until
  693. * then we pretend it's got it's own cache architecture.
  694. */
  695. c->options &= ~MIPS_CPU_4K_CACHE;
  696. c->options |= MIPS_CPU_SB1_CACHE;
  697. switch (c->processor_id & 0xff00) {
  698. case PRID_IMP_SB1:
  699. c->cputype = CPU_SB1;
  700. /* FPU in pass1 is known to have issues. */
  701. if ((c->processor_id & 0xff) < 0x02)
  702. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  703. break;
  704. case PRID_IMP_SB1A:
  705. c->cputype = CPU_SB1A;
  706. break;
  707. }
  708. }
  709. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c)
  710. {
  711. decode_configs(c);
  712. switch (c->processor_id & 0xff00) {
  713. case PRID_IMP_SR71000:
  714. c->cputype = CPU_SR71000;
  715. c->scache.ways = 8;
  716. c->tlbsize = 64;
  717. break;
  718. }
  719. }
  720. static inline void cpu_probe_philips(struct cpuinfo_mips *c)
  721. {
  722. decode_configs(c);
  723. switch (c->processor_id & 0xff00) {
  724. case PRID_IMP_PR4450:
  725. c->cputype = CPU_PR4450;
  726. c->isa_level = MIPS_CPU_ISA_M32R1;
  727. break;
  728. default:
  729. panic("Unknown Philips Core!"); /* REVISIT: die? */
  730. break;
  731. }
  732. }
  733. __init void cpu_probe(void)
  734. {
  735. struct cpuinfo_mips *c = &current_cpu_data;
  736. c->processor_id = PRID_IMP_UNKNOWN;
  737. c->fpu_id = FPIR_IMP_NONE;
  738. c->cputype = CPU_UNKNOWN;
  739. c->processor_id = read_c0_prid();
  740. switch (c->processor_id & 0xff0000) {
  741. case PRID_COMP_LEGACY:
  742. cpu_probe_legacy(c);
  743. break;
  744. case PRID_COMP_MIPS:
  745. cpu_probe_mips(c);
  746. break;
  747. case PRID_COMP_ALCHEMY:
  748. cpu_probe_alchemy(c);
  749. break;
  750. case PRID_COMP_SIBYTE:
  751. cpu_probe_sibyte(c);
  752. break;
  753. case PRID_COMP_SANDCRAFT:
  754. cpu_probe_sandcraft(c);
  755. break;
  756. case PRID_COMP_PHILIPS:
  757. cpu_probe_philips(c);
  758. break;
  759. default:
  760. c->cputype = CPU_UNKNOWN;
  761. }
  762. if (c->options & MIPS_CPU_FPU) {
  763. c->fpu_id = cpu_get_fpu_id();
  764. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  765. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  766. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  767. c->isa_level == MIPS_CPU_ISA_M64R2) {
  768. if (c->fpu_id & MIPS_FPIR_3D)
  769. c->ases |= MIPS_ASE_MIPS3D;
  770. }
  771. }
  772. }
  773. __init void cpu_report(void)
  774. {
  775. struct cpuinfo_mips *c = &current_cpu_data;
  776. printk("CPU revision is: %08x\n", c->processor_id);
  777. if (c->options & MIPS_CPU_FPU)
  778. printk("FPU revision is: %08x\n", c->fpu_id);
  779. }