cpu-probe.c 23 KB

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