cpu-probe.c 23 KB

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