cpu-probe.c 23 KB

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