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. if (!allow_au1k_wait)
  91. return;
  92. /* using the wait instruction makes CP0 counter unusable */
  93. __asm__(" .set mips3 \n"
  94. " cache 0x14, 0(%0) \n"
  95. " cache 0x14, 32(%0) \n"
  96. " sync \n"
  97. " nop \n"
  98. " wait \n"
  99. " nop \n"
  100. " nop \n"
  101. " nop \n"
  102. " nop \n"
  103. " .set mips0 \n"
  104. : : "r" (au1k_wait));
  105. }
  106. static int __initdata nowait = 0;
  107. static int __init wait_disable(char *s)
  108. {
  109. nowait = 1;
  110. return 1;
  111. }
  112. __setup("nowait", wait_disable);
  113. void __init check_wait(void)
  114. {
  115. struct cpuinfo_mips *c = &current_cpu_data;
  116. if (nowait) {
  117. printk("Wait instruction disabled.\n");
  118. return;
  119. }
  120. switch (c->cputype) {
  121. case CPU_R3081:
  122. case CPU_R3081E:
  123. cpu_wait = r3081_wait;
  124. break;
  125. case CPU_TX3927:
  126. cpu_wait = r39xx_wait;
  127. break;
  128. case CPU_R4200:
  129. /* case CPU_R4300: */
  130. case CPU_R4600:
  131. case CPU_R4640:
  132. case CPU_R4650:
  133. case CPU_R4700:
  134. case CPU_R5000:
  135. case CPU_NEVADA:
  136. case CPU_4KC:
  137. case CPU_4KEC:
  138. case CPU_4KSC:
  139. case CPU_5KC:
  140. case CPU_25KF:
  141. case CPU_PR4450:
  142. case CPU_BCM3302:
  143. case CPU_CAVIUM_OCTEON:
  144. cpu_wait = r4k_wait;
  145. break;
  146. case CPU_RM7000:
  147. cpu_wait = rm7k_wait_irqoff;
  148. break;
  149. case CPU_24K:
  150. case CPU_34K:
  151. case CPU_1004K:
  152. cpu_wait = r4k_wait;
  153. if (read_c0_config7() & MIPS_CONF7_WII)
  154. cpu_wait = r4k_wait_irqoff;
  155. break;
  156. case CPU_74K:
  157. cpu_wait = r4k_wait;
  158. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  159. cpu_wait = r4k_wait_irqoff;
  160. break;
  161. case CPU_TX49XX:
  162. cpu_wait = r4k_wait_irqoff;
  163. break;
  164. case CPU_AU1000:
  165. case CPU_AU1100:
  166. case CPU_AU1500:
  167. case CPU_AU1550:
  168. case CPU_AU1200:
  169. case CPU_AU1210:
  170. case CPU_AU1250:
  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_errata();
  218. }
  219. /*
  220. * Probe whether cpu has config register by trying to play with
  221. * alternate cache bit and see whether it matters.
  222. * It's used by cpu_probe to distinguish between R3000A and R3081.
  223. */
  224. static inline int cpu_has_confreg(void)
  225. {
  226. #ifdef CONFIG_CPU_R3000
  227. extern unsigned long r3k_cache_size(unsigned long);
  228. unsigned long size1, size2;
  229. unsigned long cfg = read_c0_conf();
  230. size1 = r3k_cache_size(ST0_ISC);
  231. write_c0_conf(cfg ^ R30XX_CONF_AC);
  232. size2 = r3k_cache_size(ST0_ISC);
  233. write_c0_conf(cfg);
  234. return size1 != size2;
  235. #else
  236. return 0;
  237. #endif
  238. }
  239. /*
  240. * Get the FPU Implementation/Revision.
  241. */
  242. static inline unsigned long cpu_get_fpu_id(void)
  243. {
  244. unsigned long tmp, fpu_id;
  245. tmp = read_c0_status();
  246. __enable_fpu();
  247. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  248. write_c0_status(tmp);
  249. return fpu_id;
  250. }
  251. /*
  252. * Check the CPU has an FPU the official way.
  253. */
  254. static inline int __cpu_has_fpu(void)
  255. {
  256. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  257. }
  258. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  259. | MIPS_CPU_COUNTER)
  260. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  261. {
  262. switch (c->processor_id & 0xff00) {
  263. case PRID_IMP_R2000:
  264. c->cputype = CPU_R2000;
  265. __cpu_name[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. __cpu_name[cpu] = "R3081";
  278. } else {
  279. c->cputype = CPU_R3000A;
  280. __cpu_name[cpu] = "R3000A";
  281. }
  282. break;
  283. } else {
  284. c->cputype = CPU_R3000;
  285. __cpu_name[cpu] = "R3000";
  286. }
  287. c->isa_level = MIPS_CPU_ISA_I;
  288. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  289. MIPS_CPU_NOFPUEX;
  290. if (__cpu_has_fpu())
  291. c->options |= MIPS_CPU_FPU;
  292. c->tlbsize = 64;
  293. break;
  294. case PRID_IMP_R4000:
  295. if (read_c0_config() & CONF_SC) {
  296. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  297. c->cputype = CPU_R4400PC;
  298. __cpu_name[cpu] = "R4400PC";
  299. } else {
  300. c->cputype = CPU_R4000PC;
  301. __cpu_name[cpu] = "R4000PC";
  302. }
  303. } else {
  304. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  305. c->cputype = CPU_R4400SC;
  306. __cpu_name[cpu] = "R4400SC";
  307. } else {
  308. c->cputype = CPU_R4000SC;
  309. __cpu_name[cpu] = "R4000SC";
  310. }
  311. }
  312. c->isa_level = MIPS_CPU_ISA_III;
  313. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  314. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  315. MIPS_CPU_LLSC;
  316. c->tlbsize = 48;
  317. break;
  318. case PRID_IMP_VR41XX:
  319. switch (c->processor_id & 0xf0) {
  320. case PRID_REV_VR4111:
  321. c->cputype = CPU_VR4111;
  322. __cpu_name[cpu] = "NEC VR4111";
  323. break;
  324. case PRID_REV_VR4121:
  325. c->cputype = CPU_VR4121;
  326. __cpu_name[cpu] = "NEC VR4121";
  327. break;
  328. case PRID_REV_VR4122:
  329. if ((c->processor_id & 0xf) < 0x3) {
  330. c->cputype = CPU_VR4122;
  331. __cpu_name[cpu] = "NEC VR4122";
  332. } else {
  333. c->cputype = CPU_VR4181A;
  334. __cpu_name[cpu] = "NEC VR4181A";
  335. }
  336. break;
  337. case PRID_REV_VR4130:
  338. if ((c->processor_id & 0xf) < 0x4) {
  339. c->cputype = CPU_VR4131;
  340. __cpu_name[cpu] = "NEC VR4131";
  341. } else {
  342. c->cputype = CPU_VR4133;
  343. __cpu_name[cpu] = "NEC VR4133";
  344. }
  345. break;
  346. default:
  347. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  348. c->cputype = CPU_VR41XX;
  349. __cpu_name[cpu] = "NEC Vr41xx";
  350. break;
  351. }
  352. c->isa_level = MIPS_CPU_ISA_III;
  353. c->options = R4K_OPTS;
  354. c->tlbsize = 32;
  355. break;
  356. case PRID_IMP_R4300:
  357. c->cputype = CPU_R4300;
  358. __cpu_name[cpu] = "R4300";
  359. c->isa_level = MIPS_CPU_ISA_III;
  360. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  361. MIPS_CPU_LLSC;
  362. c->tlbsize = 32;
  363. break;
  364. case PRID_IMP_R4600:
  365. c->cputype = CPU_R4600;
  366. __cpu_name[cpu] = "R4600";
  367. c->isa_level = MIPS_CPU_ISA_III;
  368. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  369. MIPS_CPU_LLSC;
  370. c->tlbsize = 48;
  371. break;
  372. #if 0
  373. case PRID_IMP_R4650:
  374. /*
  375. * This processor doesn't have an MMU, so it's not
  376. * "real easy" to run Linux on it. It is left purely
  377. * for documentation. Commented out because it shares
  378. * it's c0_prid id number with the TX3900.
  379. */
  380. c->cputype = CPU_R4650;
  381. __cpu_name[cpu] = "R4650";
  382. c->isa_level = MIPS_CPU_ISA_III;
  383. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  384. c->tlbsize = 48;
  385. break;
  386. #endif
  387. case PRID_IMP_TX39:
  388. c->isa_level = MIPS_CPU_ISA_I;
  389. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  390. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  391. c->cputype = CPU_TX3927;
  392. __cpu_name[cpu] = "TX3927";
  393. c->tlbsize = 64;
  394. } else {
  395. switch (c->processor_id & 0xff) {
  396. case PRID_REV_TX3912:
  397. c->cputype = CPU_TX3912;
  398. __cpu_name[cpu] = "TX3912";
  399. c->tlbsize = 32;
  400. break;
  401. case PRID_REV_TX3922:
  402. c->cputype = CPU_TX3922;
  403. __cpu_name[cpu] = "TX3922";
  404. c->tlbsize = 64;
  405. break;
  406. }
  407. }
  408. break;
  409. case PRID_IMP_R4700:
  410. c->cputype = CPU_R4700;
  411. __cpu_name[cpu] = "R4700";
  412. c->isa_level = MIPS_CPU_ISA_III;
  413. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  414. MIPS_CPU_LLSC;
  415. c->tlbsize = 48;
  416. break;
  417. case PRID_IMP_TX49:
  418. c->cputype = CPU_TX49XX;
  419. __cpu_name[cpu] = "R49XX";
  420. c->isa_level = MIPS_CPU_ISA_III;
  421. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  422. if (!(c->processor_id & 0x08))
  423. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  424. c->tlbsize = 48;
  425. break;
  426. case PRID_IMP_R5000:
  427. c->cputype = CPU_R5000;
  428. __cpu_name[cpu] = "R5000";
  429. c->isa_level = MIPS_CPU_ISA_IV;
  430. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  431. MIPS_CPU_LLSC;
  432. c->tlbsize = 48;
  433. break;
  434. case PRID_IMP_R5432:
  435. c->cputype = CPU_R5432;
  436. __cpu_name[cpu] = "R5432";
  437. c->isa_level = MIPS_CPU_ISA_IV;
  438. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  439. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  440. c->tlbsize = 48;
  441. break;
  442. case PRID_IMP_R5500:
  443. c->cputype = CPU_R5500;
  444. __cpu_name[cpu] = "R5500";
  445. c->isa_level = MIPS_CPU_ISA_IV;
  446. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  447. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  448. c->tlbsize = 48;
  449. break;
  450. case PRID_IMP_NEVADA:
  451. c->cputype = CPU_NEVADA;
  452. __cpu_name[cpu] = "Nevada";
  453. c->isa_level = MIPS_CPU_ISA_IV;
  454. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  455. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  456. c->tlbsize = 48;
  457. break;
  458. case PRID_IMP_R6000:
  459. c->cputype = CPU_R6000;
  460. __cpu_name[cpu] = "R6000";
  461. c->isa_level = MIPS_CPU_ISA_II;
  462. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  463. MIPS_CPU_LLSC;
  464. c->tlbsize = 32;
  465. break;
  466. case PRID_IMP_R6000A:
  467. c->cputype = CPU_R6000A;
  468. __cpu_name[cpu] = "R6000A";
  469. c->isa_level = MIPS_CPU_ISA_II;
  470. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  471. MIPS_CPU_LLSC;
  472. c->tlbsize = 32;
  473. break;
  474. case PRID_IMP_RM7000:
  475. c->cputype = CPU_RM7000;
  476. __cpu_name[cpu] = "RM7000";
  477. c->isa_level = MIPS_CPU_ISA_IV;
  478. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  479. MIPS_CPU_LLSC;
  480. /*
  481. * Undocumented RM7000: Bit 29 in the info register of
  482. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  483. * entries.
  484. *
  485. * 29 1 => 64 entry JTLB
  486. * 0 => 48 entry JTLB
  487. */
  488. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  489. break;
  490. case PRID_IMP_RM9000:
  491. c->cputype = CPU_RM9000;
  492. __cpu_name[cpu] = "RM9000";
  493. c->isa_level = MIPS_CPU_ISA_IV;
  494. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  495. MIPS_CPU_LLSC;
  496. /*
  497. * Bit 29 in the info register of the RM9000
  498. * indicates if the TLB has 48 or 64 entries.
  499. *
  500. * 29 1 => 64 entry JTLB
  501. * 0 => 48 entry JTLB
  502. */
  503. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  504. break;
  505. case PRID_IMP_R8000:
  506. c->cputype = CPU_R8000;
  507. __cpu_name[cpu] = "RM8000";
  508. c->isa_level = MIPS_CPU_ISA_IV;
  509. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  510. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  511. MIPS_CPU_LLSC;
  512. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  513. break;
  514. case PRID_IMP_R10000:
  515. c->cputype = CPU_R10000;
  516. __cpu_name[cpu] = "R10000";
  517. c->isa_level = MIPS_CPU_ISA_IV;
  518. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  519. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  520. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  521. MIPS_CPU_LLSC;
  522. c->tlbsize = 64;
  523. break;
  524. case PRID_IMP_R12000:
  525. c->cputype = CPU_R12000;
  526. __cpu_name[cpu] = "R12000";
  527. c->isa_level = MIPS_CPU_ISA_IV;
  528. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  529. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  530. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  531. MIPS_CPU_LLSC;
  532. c->tlbsize = 64;
  533. break;
  534. case PRID_IMP_R14000:
  535. c->cputype = CPU_R14000;
  536. __cpu_name[cpu] = "R14000";
  537. c->isa_level = MIPS_CPU_ISA_IV;
  538. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  539. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  540. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  541. MIPS_CPU_LLSC;
  542. c->tlbsize = 64;
  543. break;
  544. case PRID_IMP_LOONGSON2:
  545. c->cputype = CPU_LOONGSON2;
  546. __cpu_name[cpu] = "ICT Loongson-2";
  547. c->isa_level = MIPS_CPU_ISA_III;
  548. c->options = R4K_OPTS |
  549. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  550. MIPS_CPU_32FPR;
  551. c->tlbsize = 64;
  552. break;
  553. }
  554. }
  555. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  556. "Unsupported ISA type, c0.config0: %d.";
  557. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  558. {
  559. unsigned int config0;
  560. int isa;
  561. config0 = read_c0_config();
  562. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  563. c->options |= MIPS_CPU_TLB;
  564. isa = (config0 & MIPS_CONF_AT) >> 13;
  565. switch (isa) {
  566. case 0:
  567. switch ((config0 & MIPS_CONF_AR) >> 10) {
  568. case 0:
  569. c->isa_level = MIPS_CPU_ISA_M32R1;
  570. break;
  571. case 1:
  572. c->isa_level = MIPS_CPU_ISA_M32R2;
  573. break;
  574. default:
  575. goto unknown;
  576. }
  577. break;
  578. case 2:
  579. switch ((config0 & MIPS_CONF_AR) >> 10) {
  580. case 0:
  581. c->isa_level = MIPS_CPU_ISA_M64R1;
  582. break;
  583. case 1:
  584. c->isa_level = MIPS_CPU_ISA_M64R2;
  585. break;
  586. default:
  587. goto unknown;
  588. }
  589. break;
  590. default:
  591. goto unknown;
  592. }
  593. return config0 & MIPS_CONF_M;
  594. unknown:
  595. panic(unknown_isa, config0);
  596. }
  597. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  598. {
  599. unsigned int config1;
  600. config1 = read_c0_config1();
  601. if (config1 & MIPS_CONF1_MD)
  602. c->ases |= MIPS_ASE_MDMX;
  603. if (config1 & MIPS_CONF1_WR)
  604. c->options |= MIPS_CPU_WATCH;
  605. if (config1 & MIPS_CONF1_CA)
  606. c->ases |= MIPS_ASE_MIPS16;
  607. if (config1 & MIPS_CONF1_EP)
  608. c->options |= MIPS_CPU_EJTAG;
  609. if (config1 & MIPS_CONF1_FP) {
  610. c->options |= MIPS_CPU_FPU;
  611. c->options |= MIPS_CPU_32FPR;
  612. }
  613. if (cpu_has_tlb)
  614. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  615. return config1 & MIPS_CONF_M;
  616. }
  617. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  618. {
  619. unsigned int config2;
  620. config2 = read_c0_config2();
  621. if (config2 & MIPS_CONF2_SL)
  622. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  623. return config2 & MIPS_CONF_M;
  624. }
  625. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  626. {
  627. unsigned int config3;
  628. config3 = read_c0_config3();
  629. if (config3 & MIPS_CONF3_SM)
  630. c->ases |= MIPS_ASE_SMARTMIPS;
  631. if (config3 & MIPS_CONF3_DSP)
  632. c->ases |= MIPS_ASE_DSP;
  633. if (config3 & MIPS_CONF3_VINT)
  634. c->options |= MIPS_CPU_VINT;
  635. if (config3 & MIPS_CONF3_VEIC)
  636. c->options |= MIPS_CPU_VEIC;
  637. if (config3 & MIPS_CONF3_MT)
  638. c->ases |= MIPS_ASE_MIPSMT;
  639. if (config3 & MIPS_CONF3_ULRI)
  640. c->options |= MIPS_CPU_ULRI;
  641. return config3 & MIPS_CONF_M;
  642. }
  643. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  644. {
  645. int ok;
  646. /* MIPS32 or MIPS64 compliant CPU. */
  647. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  648. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  649. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  650. ok = decode_config0(c); /* Read Config registers. */
  651. BUG_ON(!ok); /* Arch spec violation! */
  652. if (ok)
  653. ok = decode_config1(c);
  654. if (ok)
  655. ok = decode_config2(c);
  656. if (ok)
  657. ok = decode_config3(c);
  658. mips_probe_watch_registers(c);
  659. }
  660. #ifdef CONFIG_CPU_MIPSR2
  661. extern void spram_config(void);
  662. #else
  663. static inline void spram_config(void) {}
  664. #endif
  665. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  666. {
  667. decode_configs(c);
  668. switch (c->processor_id & 0xff00) {
  669. case PRID_IMP_4KC:
  670. c->cputype = CPU_4KC;
  671. __cpu_name[cpu] = "MIPS 4Kc";
  672. break;
  673. case PRID_IMP_4KEC:
  674. c->cputype = CPU_4KEC;
  675. __cpu_name[cpu] = "MIPS 4KEc";
  676. break;
  677. case PRID_IMP_4KECR2:
  678. c->cputype = CPU_4KEC;
  679. __cpu_name[cpu] = "MIPS 4KEc";
  680. break;
  681. case PRID_IMP_4KSC:
  682. case PRID_IMP_4KSD:
  683. c->cputype = CPU_4KSC;
  684. __cpu_name[cpu] = "MIPS 4KSc";
  685. break;
  686. case PRID_IMP_5KC:
  687. c->cputype = CPU_5KC;
  688. __cpu_name[cpu] = "MIPS 5Kc";
  689. break;
  690. case PRID_IMP_20KC:
  691. c->cputype = CPU_20KC;
  692. __cpu_name[cpu] = "MIPS 20Kc";
  693. break;
  694. case PRID_IMP_24K:
  695. case PRID_IMP_24KE:
  696. c->cputype = CPU_24K;
  697. __cpu_name[cpu] = "MIPS 24Kc";
  698. break;
  699. case PRID_IMP_25KF:
  700. c->cputype = CPU_25KF;
  701. __cpu_name[cpu] = "MIPS 25Kc";
  702. break;
  703. case PRID_IMP_34K:
  704. c->cputype = CPU_34K;
  705. __cpu_name[cpu] = "MIPS 34Kc";
  706. break;
  707. case PRID_IMP_74K:
  708. c->cputype = CPU_74K;
  709. __cpu_name[cpu] = "MIPS 74Kc";
  710. break;
  711. case PRID_IMP_1004K:
  712. c->cputype = CPU_1004K;
  713. __cpu_name[cpu] = "MIPS 1004Kc";
  714. break;
  715. }
  716. spram_config();
  717. }
  718. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  719. {
  720. decode_configs(c);
  721. switch (c->processor_id & 0xff00) {
  722. case PRID_IMP_AU1_REV1:
  723. case PRID_IMP_AU1_REV2:
  724. switch ((c->processor_id >> 24) & 0xff) {
  725. case 0:
  726. c->cputype = CPU_AU1000;
  727. __cpu_name[cpu] = "Au1000";
  728. break;
  729. case 1:
  730. c->cputype = CPU_AU1500;
  731. __cpu_name[cpu] = "Au1500";
  732. break;
  733. case 2:
  734. c->cputype = CPU_AU1100;
  735. __cpu_name[cpu] = "Au1100";
  736. break;
  737. case 3:
  738. c->cputype = CPU_AU1550;
  739. __cpu_name[cpu] = "Au1550";
  740. break;
  741. case 4:
  742. c->cputype = CPU_AU1200;
  743. __cpu_name[cpu] = "Au1200";
  744. if ((c->processor_id & 0xff) == 2) {
  745. c->cputype = CPU_AU1250;
  746. __cpu_name[cpu] = "Au1250";
  747. }
  748. break;
  749. case 5:
  750. c->cputype = CPU_AU1210;
  751. __cpu_name[cpu] = "Au1210";
  752. break;
  753. default:
  754. panic("Unknown Au Core!");
  755. break;
  756. }
  757. break;
  758. }
  759. }
  760. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  761. {
  762. decode_configs(c);
  763. switch (c->processor_id & 0xff00) {
  764. case PRID_IMP_SB1:
  765. c->cputype = CPU_SB1;
  766. __cpu_name[cpu] = "SiByte SB1";
  767. /* FPU in pass1 is known to have issues. */
  768. if ((c->processor_id & 0xff) < 0x02)
  769. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  770. break;
  771. case PRID_IMP_SB1A:
  772. c->cputype = CPU_SB1A;
  773. __cpu_name[cpu] = "SiByte SB1A";
  774. break;
  775. }
  776. }
  777. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  778. {
  779. decode_configs(c);
  780. switch (c->processor_id & 0xff00) {
  781. case PRID_IMP_SR71000:
  782. c->cputype = CPU_SR71000;
  783. __cpu_name[cpu] = "Sandcraft SR71000";
  784. c->scache.ways = 8;
  785. c->tlbsize = 64;
  786. break;
  787. }
  788. }
  789. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  790. {
  791. decode_configs(c);
  792. switch (c->processor_id & 0xff00) {
  793. case PRID_IMP_PR4450:
  794. c->cputype = CPU_PR4450;
  795. __cpu_name[cpu] = "Philips PR4450";
  796. c->isa_level = MIPS_CPU_ISA_M32R1;
  797. break;
  798. }
  799. }
  800. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  801. {
  802. decode_configs(c);
  803. switch (c->processor_id & 0xff00) {
  804. case PRID_IMP_BCM3302:
  805. c->cputype = CPU_BCM3302;
  806. __cpu_name[cpu] = "Broadcom BCM3302";
  807. break;
  808. case PRID_IMP_BCM4710:
  809. c->cputype = CPU_BCM4710;
  810. __cpu_name[cpu] = "Broadcom BCM4710";
  811. break;
  812. }
  813. }
  814. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  815. {
  816. decode_configs(c);
  817. switch (c->processor_id & 0xff00) {
  818. case PRID_IMP_CAVIUM_CN38XX:
  819. case PRID_IMP_CAVIUM_CN31XX:
  820. case PRID_IMP_CAVIUM_CN30XX:
  821. case PRID_IMP_CAVIUM_CN58XX:
  822. case PRID_IMP_CAVIUM_CN56XX:
  823. case PRID_IMP_CAVIUM_CN50XX:
  824. case PRID_IMP_CAVIUM_CN52XX:
  825. c->cputype = CPU_CAVIUM_OCTEON;
  826. __cpu_name[cpu] = "Cavium Octeon";
  827. break;
  828. default:
  829. printk(KERN_INFO "Unknown Octeon chip!\n");
  830. c->cputype = CPU_UNKNOWN;
  831. break;
  832. }
  833. }
  834. const char *__cpu_name[NR_CPUS];
  835. __cpuinit void cpu_probe(void)
  836. {
  837. struct cpuinfo_mips *c = &current_cpu_data;
  838. unsigned int cpu = smp_processor_id();
  839. c->processor_id = PRID_IMP_UNKNOWN;
  840. c->fpu_id = FPIR_IMP_NONE;
  841. c->cputype = CPU_UNKNOWN;
  842. c->processor_id = read_c0_prid();
  843. switch (c->processor_id & 0xff0000) {
  844. case PRID_COMP_LEGACY:
  845. cpu_probe_legacy(c, cpu);
  846. break;
  847. case PRID_COMP_MIPS:
  848. cpu_probe_mips(c, cpu);
  849. break;
  850. case PRID_COMP_ALCHEMY:
  851. cpu_probe_alchemy(c, cpu);
  852. break;
  853. case PRID_COMP_SIBYTE:
  854. cpu_probe_sibyte(c, cpu);
  855. break;
  856. case PRID_COMP_BROADCOM:
  857. cpu_probe_broadcom(c, cpu);
  858. break;
  859. case PRID_COMP_SANDCRAFT:
  860. cpu_probe_sandcraft(c, cpu);
  861. break;
  862. case PRID_COMP_NXP:
  863. cpu_probe_nxp(c, cpu);
  864. break;
  865. case PRID_COMP_CAVIUM:
  866. cpu_probe_cavium(c, cpu);
  867. break;
  868. }
  869. BUG_ON(!__cpu_name[cpu]);
  870. BUG_ON(c->cputype == CPU_UNKNOWN);
  871. /*
  872. * Platform code can force the cpu type to optimize code
  873. * generation. In that case be sure the cpu type is correctly
  874. * manually setup otherwise it could trigger some nasty bugs.
  875. */
  876. BUG_ON(current_cpu_type() != c->cputype);
  877. if (c->options & MIPS_CPU_FPU) {
  878. c->fpu_id = cpu_get_fpu_id();
  879. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  880. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  881. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  882. c->isa_level == MIPS_CPU_ISA_M64R2) {
  883. if (c->fpu_id & MIPS_FPIR_3D)
  884. c->ases |= MIPS_ASE_MIPS3D;
  885. }
  886. }
  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. }