cpu-probe.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  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. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  260. {
  261. #ifdef __NEED_VMBITS_PROBE
  262. write_c0_entryhi(0x3fffffffffffe000ULL);
  263. back_to_back_c0_hazard();
  264. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  265. #endif
  266. }
  267. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  268. | MIPS_CPU_COUNTER)
  269. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  270. {
  271. switch (c->processor_id & 0xff00) {
  272. case PRID_IMP_R2000:
  273. c->cputype = CPU_R2000;
  274. __cpu_name[cpu] = "R2000";
  275. c->isa_level = MIPS_CPU_ISA_I;
  276. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  277. MIPS_CPU_NOFPUEX;
  278. if (__cpu_has_fpu())
  279. c->options |= MIPS_CPU_FPU;
  280. c->tlbsize = 64;
  281. break;
  282. case PRID_IMP_R3000:
  283. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  284. if (cpu_has_confreg()) {
  285. c->cputype = CPU_R3081E;
  286. __cpu_name[cpu] = "R3081";
  287. } else {
  288. c->cputype = CPU_R3000A;
  289. __cpu_name[cpu] = "R3000A";
  290. }
  291. break;
  292. } else {
  293. c->cputype = CPU_R3000;
  294. __cpu_name[cpu] = "R3000";
  295. }
  296. c->isa_level = MIPS_CPU_ISA_I;
  297. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  298. MIPS_CPU_NOFPUEX;
  299. if (__cpu_has_fpu())
  300. c->options |= MIPS_CPU_FPU;
  301. c->tlbsize = 64;
  302. break;
  303. case PRID_IMP_R4000:
  304. if (read_c0_config() & CONF_SC) {
  305. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  306. c->cputype = CPU_R4400PC;
  307. __cpu_name[cpu] = "R4400PC";
  308. } else {
  309. c->cputype = CPU_R4000PC;
  310. __cpu_name[cpu] = "R4000PC";
  311. }
  312. } else {
  313. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  314. c->cputype = CPU_R4400SC;
  315. __cpu_name[cpu] = "R4400SC";
  316. } else {
  317. c->cputype = CPU_R4000SC;
  318. __cpu_name[cpu] = "R4000SC";
  319. }
  320. }
  321. c->isa_level = MIPS_CPU_ISA_III;
  322. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  323. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  324. MIPS_CPU_LLSC;
  325. c->tlbsize = 48;
  326. break;
  327. case PRID_IMP_VR41XX:
  328. switch (c->processor_id & 0xf0) {
  329. case PRID_REV_VR4111:
  330. c->cputype = CPU_VR4111;
  331. __cpu_name[cpu] = "NEC VR4111";
  332. break;
  333. case PRID_REV_VR4121:
  334. c->cputype = CPU_VR4121;
  335. __cpu_name[cpu] = "NEC VR4121";
  336. break;
  337. case PRID_REV_VR4122:
  338. if ((c->processor_id & 0xf) < 0x3) {
  339. c->cputype = CPU_VR4122;
  340. __cpu_name[cpu] = "NEC VR4122";
  341. } else {
  342. c->cputype = CPU_VR4181A;
  343. __cpu_name[cpu] = "NEC VR4181A";
  344. }
  345. break;
  346. case PRID_REV_VR4130:
  347. if ((c->processor_id & 0xf) < 0x4) {
  348. c->cputype = CPU_VR4131;
  349. __cpu_name[cpu] = "NEC VR4131";
  350. } else {
  351. c->cputype = CPU_VR4133;
  352. __cpu_name[cpu] = "NEC VR4133";
  353. }
  354. break;
  355. default:
  356. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  357. c->cputype = CPU_VR41XX;
  358. __cpu_name[cpu] = "NEC Vr41xx";
  359. break;
  360. }
  361. c->isa_level = MIPS_CPU_ISA_III;
  362. c->options = R4K_OPTS;
  363. c->tlbsize = 32;
  364. break;
  365. case PRID_IMP_R4300:
  366. c->cputype = CPU_R4300;
  367. __cpu_name[cpu] = "R4300";
  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 = 32;
  372. break;
  373. case PRID_IMP_R4600:
  374. c->cputype = CPU_R4600;
  375. __cpu_name[cpu] = "R4600";
  376. c->isa_level = MIPS_CPU_ISA_III;
  377. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  378. MIPS_CPU_LLSC;
  379. c->tlbsize = 48;
  380. break;
  381. #if 0
  382. case PRID_IMP_R4650:
  383. /*
  384. * This processor doesn't have an MMU, so it's not
  385. * "real easy" to run Linux on it. It is left purely
  386. * for documentation. Commented out because it shares
  387. * it's c0_prid id number with the TX3900.
  388. */
  389. c->cputype = CPU_R4650;
  390. __cpu_name[cpu] = "R4650";
  391. c->isa_level = MIPS_CPU_ISA_III;
  392. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  393. c->tlbsize = 48;
  394. break;
  395. #endif
  396. case PRID_IMP_TX39:
  397. c->isa_level = MIPS_CPU_ISA_I;
  398. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  399. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  400. c->cputype = CPU_TX3927;
  401. __cpu_name[cpu] = "TX3927";
  402. c->tlbsize = 64;
  403. } else {
  404. switch (c->processor_id & 0xff) {
  405. case PRID_REV_TX3912:
  406. c->cputype = CPU_TX3912;
  407. __cpu_name[cpu] = "TX3912";
  408. c->tlbsize = 32;
  409. break;
  410. case PRID_REV_TX3922:
  411. c->cputype = CPU_TX3922;
  412. __cpu_name[cpu] = "TX3922";
  413. c->tlbsize = 64;
  414. break;
  415. }
  416. }
  417. break;
  418. case PRID_IMP_R4700:
  419. c->cputype = CPU_R4700;
  420. __cpu_name[cpu] = "R4700";
  421. c->isa_level = MIPS_CPU_ISA_III;
  422. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  423. MIPS_CPU_LLSC;
  424. c->tlbsize = 48;
  425. break;
  426. case PRID_IMP_TX49:
  427. c->cputype = CPU_TX49XX;
  428. __cpu_name[cpu] = "R49XX";
  429. c->isa_level = MIPS_CPU_ISA_III;
  430. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  431. if (!(c->processor_id & 0x08))
  432. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  433. c->tlbsize = 48;
  434. break;
  435. case PRID_IMP_R5000:
  436. c->cputype = CPU_R5000;
  437. __cpu_name[cpu] = "R5000";
  438. c->isa_level = MIPS_CPU_ISA_IV;
  439. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  440. MIPS_CPU_LLSC;
  441. c->tlbsize = 48;
  442. break;
  443. case PRID_IMP_R5432:
  444. c->cputype = CPU_R5432;
  445. __cpu_name[cpu] = "R5432";
  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_R5500:
  452. c->cputype = CPU_R5500;
  453. __cpu_name[cpu] = "R5500";
  454. c->isa_level = MIPS_CPU_ISA_IV;
  455. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  456. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  457. c->tlbsize = 48;
  458. break;
  459. case PRID_IMP_NEVADA:
  460. c->cputype = CPU_NEVADA;
  461. __cpu_name[cpu] = "Nevada";
  462. c->isa_level = MIPS_CPU_ISA_IV;
  463. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  464. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  465. c->tlbsize = 48;
  466. break;
  467. case PRID_IMP_R6000:
  468. c->cputype = CPU_R6000;
  469. __cpu_name[cpu] = "R6000";
  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_R6000A:
  476. c->cputype = CPU_R6000A;
  477. __cpu_name[cpu] = "R6000A";
  478. c->isa_level = MIPS_CPU_ISA_II;
  479. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  480. MIPS_CPU_LLSC;
  481. c->tlbsize = 32;
  482. break;
  483. case PRID_IMP_RM7000:
  484. c->cputype = CPU_RM7000;
  485. __cpu_name[cpu] = "RM7000";
  486. c->isa_level = MIPS_CPU_ISA_IV;
  487. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  488. MIPS_CPU_LLSC;
  489. /*
  490. * Undocumented RM7000: Bit 29 in the info register of
  491. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  492. * entries.
  493. *
  494. * 29 1 => 64 entry JTLB
  495. * 0 => 48 entry JTLB
  496. */
  497. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  498. break;
  499. case PRID_IMP_RM9000:
  500. c->cputype = CPU_RM9000;
  501. __cpu_name[cpu] = "RM9000";
  502. c->isa_level = MIPS_CPU_ISA_IV;
  503. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  504. MIPS_CPU_LLSC;
  505. /*
  506. * Bit 29 in the info register of the RM9000
  507. * indicates if the TLB has 48 or 64 entries.
  508. *
  509. * 29 1 => 64 entry JTLB
  510. * 0 => 48 entry JTLB
  511. */
  512. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  513. break;
  514. case PRID_IMP_R8000:
  515. c->cputype = CPU_R8000;
  516. __cpu_name[cpu] = "RM8000";
  517. c->isa_level = MIPS_CPU_ISA_IV;
  518. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  519. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  520. MIPS_CPU_LLSC;
  521. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  522. break;
  523. case PRID_IMP_R10000:
  524. c->cputype = CPU_R10000;
  525. __cpu_name[cpu] = "R10000";
  526. c->isa_level = MIPS_CPU_ISA_IV;
  527. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  528. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  529. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  530. MIPS_CPU_LLSC;
  531. c->tlbsize = 64;
  532. break;
  533. case PRID_IMP_R12000:
  534. c->cputype = CPU_R12000;
  535. __cpu_name[cpu] = "R12000";
  536. c->isa_level = MIPS_CPU_ISA_IV;
  537. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  538. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  539. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  540. MIPS_CPU_LLSC;
  541. c->tlbsize = 64;
  542. break;
  543. case PRID_IMP_R14000:
  544. c->cputype = CPU_R14000;
  545. __cpu_name[cpu] = "R14000";
  546. c->isa_level = MIPS_CPU_ISA_IV;
  547. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  548. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  549. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  550. MIPS_CPU_LLSC;
  551. c->tlbsize = 64;
  552. break;
  553. case PRID_IMP_LOONGSON2:
  554. c->cputype = CPU_LOONGSON2;
  555. __cpu_name[cpu] = "ICT Loongson-2";
  556. c->isa_level = MIPS_CPU_ISA_III;
  557. c->options = R4K_OPTS |
  558. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  559. MIPS_CPU_32FPR;
  560. c->tlbsize = 64;
  561. break;
  562. }
  563. }
  564. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  565. "Unsupported ISA type, c0.config0: %d.";
  566. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  567. {
  568. unsigned int config0;
  569. int isa;
  570. config0 = read_c0_config();
  571. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  572. c->options |= MIPS_CPU_TLB;
  573. isa = (config0 & MIPS_CONF_AT) >> 13;
  574. switch (isa) {
  575. case 0:
  576. switch ((config0 & MIPS_CONF_AR) >> 10) {
  577. case 0:
  578. c->isa_level = MIPS_CPU_ISA_M32R1;
  579. break;
  580. case 1:
  581. c->isa_level = MIPS_CPU_ISA_M32R2;
  582. break;
  583. default:
  584. goto unknown;
  585. }
  586. break;
  587. case 2:
  588. switch ((config0 & MIPS_CONF_AR) >> 10) {
  589. case 0:
  590. c->isa_level = MIPS_CPU_ISA_M64R1;
  591. break;
  592. case 1:
  593. c->isa_level = MIPS_CPU_ISA_M64R2;
  594. break;
  595. default:
  596. goto unknown;
  597. }
  598. break;
  599. default:
  600. goto unknown;
  601. }
  602. return config0 & MIPS_CONF_M;
  603. unknown:
  604. panic(unknown_isa, config0);
  605. }
  606. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  607. {
  608. unsigned int config1;
  609. config1 = read_c0_config1();
  610. if (config1 & MIPS_CONF1_MD)
  611. c->ases |= MIPS_ASE_MDMX;
  612. if (config1 & MIPS_CONF1_WR)
  613. c->options |= MIPS_CPU_WATCH;
  614. if (config1 & MIPS_CONF1_CA)
  615. c->ases |= MIPS_ASE_MIPS16;
  616. if (config1 & MIPS_CONF1_EP)
  617. c->options |= MIPS_CPU_EJTAG;
  618. if (config1 & MIPS_CONF1_FP) {
  619. c->options |= MIPS_CPU_FPU;
  620. c->options |= MIPS_CPU_32FPR;
  621. }
  622. if (cpu_has_tlb)
  623. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  624. return config1 & MIPS_CONF_M;
  625. }
  626. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  627. {
  628. unsigned int config2;
  629. config2 = read_c0_config2();
  630. if (config2 & MIPS_CONF2_SL)
  631. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  632. return config2 & MIPS_CONF_M;
  633. }
  634. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  635. {
  636. unsigned int config3;
  637. config3 = read_c0_config3();
  638. if (config3 & MIPS_CONF3_SM)
  639. c->ases |= MIPS_ASE_SMARTMIPS;
  640. if (config3 & MIPS_CONF3_DSP)
  641. c->ases |= MIPS_ASE_DSP;
  642. if (config3 & MIPS_CONF3_VINT)
  643. c->options |= MIPS_CPU_VINT;
  644. if (config3 & MIPS_CONF3_VEIC)
  645. c->options |= MIPS_CPU_VEIC;
  646. if (config3 & MIPS_CONF3_MT)
  647. c->ases |= MIPS_ASE_MIPSMT;
  648. if (config3 & MIPS_CONF3_ULRI)
  649. c->options |= MIPS_CPU_ULRI;
  650. return config3 & MIPS_CONF_M;
  651. }
  652. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  653. {
  654. int ok;
  655. /* MIPS32 or MIPS64 compliant CPU. */
  656. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  657. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  658. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  659. ok = decode_config0(c); /* Read Config registers. */
  660. BUG_ON(!ok); /* Arch spec violation! */
  661. if (ok)
  662. ok = decode_config1(c);
  663. if (ok)
  664. ok = decode_config2(c);
  665. if (ok)
  666. ok = decode_config3(c);
  667. mips_probe_watch_registers(c);
  668. }
  669. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  670. {
  671. decode_configs(c);
  672. switch (c->processor_id & 0xff00) {
  673. case PRID_IMP_4KC:
  674. c->cputype = CPU_4KC;
  675. __cpu_name[cpu] = "MIPS 4Kc";
  676. break;
  677. case PRID_IMP_4KEC:
  678. c->cputype = CPU_4KEC;
  679. __cpu_name[cpu] = "MIPS 4KEc";
  680. break;
  681. case PRID_IMP_4KECR2:
  682. c->cputype = CPU_4KEC;
  683. __cpu_name[cpu] = "MIPS 4KEc";
  684. break;
  685. case PRID_IMP_4KSC:
  686. case PRID_IMP_4KSD:
  687. c->cputype = CPU_4KSC;
  688. __cpu_name[cpu] = "MIPS 4KSc";
  689. break;
  690. case PRID_IMP_5KC:
  691. c->cputype = CPU_5KC;
  692. __cpu_name[cpu] = "MIPS 5Kc";
  693. break;
  694. case PRID_IMP_20KC:
  695. c->cputype = CPU_20KC;
  696. __cpu_name[cpu] = "MIPS 20Kc";
  697. break;
  698. case PRID_IMP_24K:
  699. case PRID_IMP_24KE:
  700. c->cputype = CPU_24K;
  701. __cpu_name[cpu] = "MIPS 24Kc";
  702. break;
  703. case PRID_IMP_25KF:
  704. c->cputype = CPU_25KF;
  705. __cpu_name[cpu] = "MIPS 25Kc";
  706. break;
  707. case PRID_IMP_34K:
  708. c->cputype = CPU_34K;
  709. __cpu_name[cpu] = "MIPS 34Kc";
  710. break;
  711. case PRID_IMP_74K:
  712. c->cputype = CPU_74K;
  713. __cpu_name[cpu] = "MIPS 74Kc";
  714. break;
  715. case PRID_IMP_1004K:
  716. c->cputype = CPU_1004K;
  717. __cpu_name[cpu] = "MIPS 1004Kc";
  718. break;
  719. }
  720. spram_config();
  721. }
  722. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  723. {
  724. decode_configs(c);
  725. switch (c->processor_id & 0xff00) {
  726. case PRID_IMP_AU1_REV1:
  727. case PRID_IMP_AU1_REV2:
  728. c->cputype = CPU_ALCHEMY;
  729. switch ((c->processor_id >> 24) & 0xff) {
  730. case 0:
  731. __cpu_name[cpu] = "Au1000";
  732. break;
  733. case 1:
  734. __cpu_name[cpu] = "Au1500";
  735. break;
  736. case 2:
  737. __cpu_name[cpu] = "Au1100";
  738. break;
  739. case 3:
  740. __cpu_name[cpu] = "Au1550";
  741. break;
  742. case 4:
  743. __cpu_name[cpu] = "Au1200";
  744. if ((c->processor_id & 0xff) == 2)
  745. __cpu_name[cpu] = "Au1250";
  746. break;
  747. case 5:
  748. __cpu_name[cpu] = "Au1210";
  749. break;
  750. default:
  751. __cpu_name[cpu] = "Au1xxx";
  752. break;
  753. }
  754. break;
  755. }
  756. }
  757. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  758. {
  759. decode_configs(c);
  760. switch (c->processor_id & 0xff00) {
  761. case PRID_IMP_SB1:
  762. c->cputype = CPU_SB1;
  763. __cpu_name[cpu] = "SiByte SB1";
  764. /* FPU in pass1 is known to have issues. */
  765. if ((c->processor_id & 0xff) < 0x02)
  766. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  767. break;
  768. case PRID_IMP_SB1A:
  769. c->cputype = CPU_SB1A;
  770. __cpu_name[cpu] = "SiByte SB1A";
  771. break;
  772. }
  773. }
  774. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  775. {
  776. decode_configs(c);
  777. switch (c->processor_id & 0xff00) {
  778. case PRID_IMP_SR71000:
  779. c->cputype = CPU_SR71000;
  780. __cpu_name[cpu] = "Sandcraft SR71000";
  781. c->scache.ways = 8;
  782. c->tlbsize = 64;
  783. break;
  784. }
  785. }
  786. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  787. {
  788. decode_configs(c);
  789. switch (c->processor_id & 0xff00) {
  790. case PRID_IMP_PR4450:
  791. c->cputype = CPU_PR4450;
  792. __cpu_name[cpu] = "Philips PR4450";
  793. c->isa_level = MIPS_CPU_ISA_M32R1;
  794. break;
  795. }
  796. }
  797. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  798. {
  799. decode_configs(c);
  800. switch (c->processor_id & 0xff00) {
  801. case PRID_IMP_BCM3302:
  802. /* same as PRID_IMP_BCM6338 */
  803. c->cputype = CPU_BCM3302;
  804. __cpu_name[cpu] = "Broadcom BCM3302";
  805. break;
  806. case PRID_IMP_BCM4710:
  807. c->cputype = CPU_BCM4710;
  808. __cpu_name[cpu] = "Broadcom BCM4710";
  809. break;
  810. case PRID_IMP_BCM6345:
  811. c->cputype = CPU_BCM6345;
  812. __cpu_name[cpu] = "Broadcom BCM6345";
  813. break;
  814. case PRID_IMP_BCM6348:
  815. c->cputype = CPU_BCM6348;
  816. __cpu_name[cpu] = "Broadcom BCM6348";
  817. break;
  818. case PRID_IMP_BCM4350:
  819. switch (c->processor_id & 0xf0) {
  820. case PRID_REV_BCM6358:
  821. c->cputype = CPU_BCM6358;
  822. __cpu_name[cpu] = "Broadcom BCM6358";
  823. break;
  824. default:
  825. c->cputype = CPU_UNKNOWN;
  826. break;
  827. }
  828. break;
  829. }
  830. }
  831. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  832. {
  833. decode_configs(c);
  834. switch (c->processor_id & 0xff00) {
  835. case PRID_IMP_CAVIUM_CN38XX:
  836. case PRID_IMP_CAVIUM_CN31XX:
  837. case PRID_IMP_CAVIUM_CN30XX:
  838. case PRID_IMP_CAVIUM_CN58XX:
  839. case PRID_IMP_CAVIUM_CN56XX:
  840. case PRID_IMP_CAVIUM_CN50XX:
  841. case PRID_IMP_CAVIUM_CN52XX:
  842. c->cputype = CPU_CAVIUM_OCTEON;
  843. __cpu_name[cpu] = "Cavium Octeon";
  844. break;
  845. default:
  846. printk(KERN_INFO "Unknown Octeon chip!\n");
  847. c->cputype = CPU_UNKNOWN;
  848. break;
  849. }
  850. }
  851. const char *__cpu_name[NR_CPUS];
  852. __cpuinit void cpu_probe(void)
  853. {
  854. struct cpuinfo_mips *c = &current_cpu_data;
  855. unsigned int cpu = smp_processor_id();
  856. c->processor_id = PRID_IMP_UNKNOWN;
  857. c->fpu_id = FPIR_IMP_NONE;
  858. c->cputype = CPU_UNKNOWN;
  859. c->processor_id = read_c0_prid();
  860. switch (c->processor_id & 0xff0000) {
  861. case PRID_COMP_LEGACY:
  862. cpu_probe_legacy(c, cpu);
  863. break;
  864. case PRID_COMP_MIPS:
  865. cpu_probe_mips(c, cpu);
  866. break;
  867. case PRID_COMP_ALCHEMY:
  868. cpu_probe_alchemy(c, cpu);
  869. break;
  870. case PRID_COMP_SIBYTE:
  871. cpu_probe_sibyte(c, cpu);
  872. break;
  873. case PRID_COMP_BROADCOM:
  874. cpu_probe_broadcom(c, cpu);
  875. break;
  876. case PRID_COMP_SANDCRAFT:
  877. cpu_probe_sandcraft(c, cpu);
  878. break;
  879. case PRID_COMP_NXP:
  880. cpu_probe_nxp(c, cpu);
  881. break;
  882. case PRID_COMP_CAVIUM:
  883. cpu_probe_cavium(c, cpu);
  884. break;
  885. }
  886. BUG_ON(!__cpu_name[cpu]);
  887. BUG_ON(c->cputype == CPU_UNKNOWN);
  888. /*
  889. * Platform code can force the cpu type to optimize code
  890. * generation. In that case be sure the cpu type is correctly
  891. * manually setup otherwise it could trigger some nasty bugs.
  892. */
  893. BUG_ON(current_cpu_type() != c->cputype);
  894. if (c->options & MIPS_CPU_FPU) {
  895. c->fpu_id = cpu_get_fpu_id();
  896. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  897. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  898. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  899. c->isa_level == MIPS_CPU_ISA_M64R2) {
  900. if (c->fpu_id & MIPS_FPIR_3D)
  901. c->ases |= MIPS_ASE_MIPS3D;
  902. }
  903. }
  904. if (cpu_has_mips_r2)
  905. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  906. else
  907. c->srsets = 1;
  908. cpu_probe_vmbits(c);
  909. }
  910. __cpuinit void cpu_report(void)
  911. {
  912. struct cpuinfo_mips *c = &current_cpu_data;
  913. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  914. c->processor_id, cpu_name_string());
  915. if (c->options & MIPS_CPU_FPU)
  916. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  917. }