cpu-probe.c 23 KB

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