cpu-probe.c 19 KB

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