cpu-probe.c 23 KB

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