cpu-probe.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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 <linux/module.h>
  20. #include <asm/bugs.h>
  21. #include <asm/cpu.h>
  22. #include <asm/fpu.h>
  23. #include <asm/mipsregs.h>
  24. #include <asm/system.h>
  25. #include <asm/watch.h>
  26. #include <asm/spram.h>
  27. /*
  28. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  29. * the implementation of the "wait" feature differs between CPU families. This
  30. * points to the function that implements CPU specific wait.
  31. * The wait instruction stops the pipeline and reduces the power consumption of
  32. * the CPU very much.
  33. */
  34. void (*cpu_wait)(void);
  35. EXPORT_SYMBOL(cpu_wait);
  36. static void r3081_wait(void)
  37. {
  38. unsigned long cfg = read_c0_conf();
  39. write_c0_conf(cfg | R30XX_CONF_HALT);
  40. }
  41. static void r39xx_wait(void)
  42. {
  43. local_irq_disable();
  44. if (!need_resched())
  45. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  46. local_irq_enable();
  47. }
  48. extern void r4k_wait(void);
  49. /*
  50. * This variant is preferable as it allows testing need_resched and going to
  51. * sleep depending on the outcome atomically. Unfortunately the "It is
  52. * implementation-dependent whether the pipeline restarts when a non-enabled
  53. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  54. * using this version a gamble.
  55. */
  56. void r4k_wait_irqoff(void)
  57. {
  58. local_irq_disable();
  59. if (!need_resched())
  60. __asm__(" .set push \n"
  61. " .set mips3 \n"
  62. " wait \n"
  63. " .set pop \n");
  64. local_irq_enable();
  65. __asm__(" .globl __pastwait \n"
  66. "__pastwait: \n");
  67. return;
  68. }
  69. /*
  70. * The RM7000 variant has to handle erratum 38. The workaround is to not
  71. * have any pending stores when the WAIT instruction is executed.
  72. */
  73. static void rm7k_wait_irqoff(void)
  74. {
  75. local_irq_disable();
  76. if (!need_resched())
  77. __asm__(
  78. " .set push \n"
  79. " .set mips3 \n"
  80. " .set noat \n"
  81. " mfc0 $1, $12 \n"
  82. " sync \n"
  83. " mtc0 $1, $12 # stalls until W stage \n"
  84. " wait \n"
  85. " mtc0 $1, $12 # stalls until W stage \n"
  86. " .set pop \n");
  87. local_irq_enable();
  88. }
  89. /*
  90. * The Au1xxx wait is available only if using 32khz counter or
  91. * external timer source, but specifically not CP0 Counter.
  92. * alchemy/common/time.c may override cpu_wait!
  93. */
  94. static void au1k_wait(void)
  95. {
  96. __asm__(" .set mips3 \n"
  97. " cache 0x14, 0(%0) \n"
  98. " cache 0x14, 32(%0) \n"
  99. " sync \n"
  100. " nop \n"
  101. " wait \n"
  102. " nop \n"
  103. " nop \n"
  104. " nop \n"
  105. " nop \n"
  106. " .set mips0 \n"
  107. : : "r" (au1k_wait));
  108. }
  109. static int __initdata nowait;
  110. static int __init wait_disable(char *s)
  111. {
  112. nowait = 1;
  113. return 1;
  114. }
  115. __setup("nowait", wait_disable);
  116. void __init check_wait(void)
  117. {
  118. struct cpuinfo_mips *c = &current_cpu_data;
  119. if (nowait) {
  120. printk("Wait instruction disabled.\n");
  121. return;
  122. }
  123. switch (c->cputype) {
  124. case CPU_R3081:
  125. case CPU_R3081E:
  126. cpu_wait = r3081_wait;
  127. break;
  128. case CPU_TX3927:
  129. cpu_wait = r39xx_wait;
  130. break;
  131. case CPU_R4200:
  132. /* case CPU_R4300: */
  133. case CPU_R4600:
  134. case CPU_R4640:
  135. case CPU_R4650:
  136. case CPU_R4700:
  137. case CPU_R5000:
  138. case CPU_R5500:
  139. case CPU_NEVADA:
  140. case CPU_4KC:
  141. case CPU_4KEC:
  142. case CPU_4KSC:
  143. case CPU_5KC:
  144. case CPU_25KF:
  145. case CPU_PR4450:
  146. case CPU_BCM3302:
  147. case CPU_BCM6338:
  148. case CPU_BCM6348:
  149. case CPU_BCM6358:
  150. case CPU_CAVIUM_OCTEON:
  151. cpu_wait = r4k_wait;
  152. break;
  153. case CPU_RM7000:
  154. cpu_wait = rm7k_wait_irqoff;
  155. break;
  156. case CPU_24K:
  157. case CPU_34K:
  158. case CPU_1004K:
  159. cpu_wait = r4k_wait;
  160. if (read_c0_config7() & MIPS_CONF7_WII)
  161. cpu_wait = r4k_wait_irqoff;
  162. break;
  163. case CPU_74K:
  164. cpu_wait = r4k_wait;
  165. if ((c->processor_id & 0xff) >= PRID_REV_ENCODE_332(2, 1, 0))
  166. cpu_wait = r4k_wait_irqoff;
  167. break;
  168. case CPU_TX49XX:
  169. cpu_wait = r4k_wait_irqoff;
  170. break;
  171. case CPU_ALCHEMY:
  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. 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. /* same as PRID_IMP_BCM6338 */
  795. c->cputype = CPU_BCM3302;
  796. __cpu_name[cpu] = "Broadcom BCM3302";
  797. break;
  798. case PRID_IMP_BCM4710:
  799. c->cputype = CPU_BCM4710;
  800. __cpu_name[cpu] = "Broadcom BCM4710";
  801. break;
  802. case PRID_IMP_BCM6345:
  803. c->cputype = CPU_BCM6345;
  804. __cpu_name[cpu] = "Broadcom BCM6345";
  805. break;
  806. case PRID_IMP_BCM6348:
  807. c->cputype = CPU_BCM6348;
  808. __cpu_name[cpu] = "Broadcom BCM6348";
  809. break;
  810. case PRID_IMP_BCM4350:
  811. switch (c->processor_id & 0xf0) {
  812. case PRID_REV_BCM6358:
  813. c->cputype = CPU_BCM6358;
  814. __cpu_name[cpu] = "Broadcom BCM6358";
  815. break;
  816. default:
  817. c->cputype = CPU_UNKNOWN;
  818. break;
  819. }
  820. break;
  821. }
  822. }
  823. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  824. {
  825. decode_configs(c);
  826. switch (c->processor_id & 0xff00) {
  827. case PRID_IMP_CAVIUM_CN38XX:
  828. case PRID_IMP_CAVIUM_CN31XX:
  829. case PRID_IMP_CAVIUM_CN30XX:
  830. case PRID_IMP_CAVIUM_CN58XX:
  831. case PRID_IMP_CAVIUM_CN56XX:
  832. case PRID_IMP_CAVIUM_CN50XX:
  833. case PRID_IMP_CAVIUM_CN52XX:
  834. c->cputype = CPU_CAVIUM_OCTEON;
  835. __cpu_name[cpu] = "Cavium Octeon";
  836. break;
  837. default:
  838. printk(KERN_INFO "Unknown Octeon chip!\n");
  839. c->cputype = CPU_UNKNOWN;
  840. break;
  841. }
  842. }
  843. const char *__cpu_name[NR_CPUS];
  844. __cpuinit void cpu_probe(void)
  845. {
  846. struct cpuinfo_mips *c = &current_cpu_data;
  847. unsigned int cpu = smp_processor_id();
  848. c->processor_id = PRID_IMP_UNKNOWN;
  849. c->fpu_id = FPIR_IMP_NONE;
  850. c->cputype = CPU_UNKNOWN;
  851. c->processor_id = read_c0_prid();
  852. switch (c->processor_id & 0xff0000) {
  853. case PRID_COMP_LEGACY:
  854. cpu_probe_legacy(c, cpu);
  855. break;
  856. case PRID_COMP_MIPS:
  857. cpu_probe_mips(c, cpu);
  858. break;
  859. case PRID_COMP_ALCHEMY:
  860. cpu_probe_alchemy(c, cpu);
  861. break;
  862. case PRID_COMP_SIBYTE:
  863. cpu_probe_sibyte(c, cpu);
  864. break;
  865. case PRID_COMP_BROADCOM:
  866. cpu_probe_broadcom(c, cpu);
  867. break;
  868. case PRID_COMP_SANDCRAFT:
  869. cpu_probe_sandcraft(c, cpu);
  870. break;
  871. case PRID_COMP_NXP:
  872. cpu_probe_nxp(c, cpu);
  873. break;
  874. case PRID_COMP_CAVIUM:
  875. cpu_probe_cavium(c, cpu);
  876. break;
  877. }
  878. BUG_ON(!__cpu_name[cpu]);
  879. BUG_ON(c->cputype == CPU_UNKNOWN);
  880. /*
  881. * Platform code can force the cpu type to optimize code
  882. * generation. In that case be sure the cpu type is correctly
  883. * manually setup otherwise it could trigger some nasty bugs.
  884. */
  885. BUG_ON(current_cpu_type() != c->cputype);
  886. if (c->options & MIPS_CPU_FPU) {
  887. c->fpu_id = cpu_get_fpu_id();
  888. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  889. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  890. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  891. c->isa_level == MIPS_CPU_ISA_M64R2) {
  892. if (c->fpu_id & MIPS_FPIR_3D)
  893. c->ases |= MIPS_ASE_MIPS3D;
  894. }
  895. }
  896. if (cpu_has_mips_r2)
  897. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  898. else
  899. c->srsets = 1;
  900. }
  901. __cpuinit void cpu_report(void)
  902. {
  903. struct cpuinfo_mips *c = &current_cpu_data;
  904. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  905. c->processor_id, cpu_name_string());
  906. if (c->options & MIPS_CPU_FPU)
  907. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  908. }