cpu-probe.c 25 KB

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