cpu-probe.c 19 KB

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