cpu-probe.c 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164
  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/export.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/elf.h>
  27. #include <asm/spram.h>
  28. #include <asm/uaccess.h>
  29. /*
  30. * Not all of the MIPS CPUs have the "wait" instruction available. Moreover,
  31. * the implementation of the "wait" feature differs between CPU families. This
  32. * points to the function that implements CPU specific wait.
  33. * The wait instruction stops the pipeline and reduces the power consumption of
  34. * the CPU very much.
  35. */
  36. void (*cpu_wait)(void);
  37. EXPORT_SYMBOL(cpu_wait);
  38. static void r3081_wait(void)
  39. {
  40. unsigned long cfg = read_c0_conf();
  41. write_c0_conf(cfg | R30XX_CONF_HALT);
  42. }
  43. static void r39xx_wait(void)
  44. {
  45. local_irq_disable();
  46. if (!need_resched())
  47. write_c0_conf(read_c0_conf() | TX39_CONF_HALT);
  48. local_irq_enable();
  49. }
  50. extern void r4k_wait(void);
  51. /*
  52. * This variant is preferable as it allows testing need_resched and going to
  53. * sleep depending on the outcome atomically. Unfortunately the "It is
  54. * implementation-dependent whether the pipeline restarts when a non-enabled
  55. * interrupt is requested" restriction in the MIPS32/MIPS64 architecture makes
  56. * using this version a gamble.
  57. */
  58. void r4k_wait_irqoff(void)
  59. {
  60. local_irq_disable();
  61. if (!need_resched())
  62. __asm__(" .set push \n"
  63. " .set mips3 \n"
  64. " wait \n"
  65. " .set pop \n");
  66. local_irq_enable();
  67. __asm__(" .globl __pastwait \n"
  68. "__pastwait: \n");
  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. static inline void set_elf_platform(int cpu, const char *plat)
  261. {
  262. if (cpu == 0)
  263. __elf_platform = plat;
  264. }
  265. /*
  266. * Get the FPU Implementation/Revision.
  267. */
  268. static inline unsigned long cpu_get_fpu_id(void)
  269. {
  270. unsigned long tmp, fpu_id;
  271. tmp = read_c0_status();
  272. __enable_fpu();
  273. fpu_id = read_32bit_cp1_register(CP1_REVISION);
  274. write_c0_status(tmp);
  275. return fpu_id;
  276. }
  277. /*
  278. * Check the CPU has an FPU the official way.
  279. */
  280. static inline int __cpu_has_fpu(void)
  281. {
  282. return ((cpu_get_fpu_id() & 0xff00) != FPIR_IMP_NONE);
  283. }
  284. static inline void cpu_probe_vmbits(struct cpuinfo_mips *c)
  285. {
  286. #ifdef __NEED_VMBITS_PROBE
  287. write_c0_entryhi(0x3fffffffffffe000ULL);
  288. back_to_back_c0_hazard();
  289. c->vmbits = fls64(read_c0_entryhi() & 0x3fffffffffffe000ULL);
  290. #endif
  291. }
  292. #define R4K_OPTS (MIPS_CPU_TLB | MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE \
  293. | MIPS_CPU_COUNTER)
  294. static inline void cpu_probe_legacy(struct cpuinfo_mips *c, unsigned int cpu)
  295. {
  296. switch (c->processor_id & 0xff00) {
  297. case PRID_IMP_R2000:
  298. c->cputype = CPU_R2000;
  299. __cpu_name[cpu] = "R2000";
  300. c->isa_level = MIPS_CPU_ISA_I;
  301. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  302. MIPS_CPU_NOFPUEX;
  303. if (__cpu_has_fpu())
  304. c->options |= MIPS_CPU_FPU;
  305. c->tlbsize = 64;
  306. break;
  307. case PRID_IMP_R3000:
  308. if ((c->processor_id & 0xff) == PRID_REV_R3000A) {
  309. if (cpu_has_confreg()) {
  310. c->cputype = CPU_R3081E;
  311. __cpu_name[cpu] = "R3081";
  312. } else {
  313. c->cputype = CPU_R3000A;
  314. __cpu_name[cpu] = "R3000A";
  315. }
  316. break;
  317. } else {
  318. c->cputype = CPU_R3000;
  319. __cpu_name[cpu] = "R3000";
  320. }
  321. c->isa_level = MIPS_CPU_ISA_I;
  322. c->options = MIPS_CPU_TLB | MIPS_CPU_3K_CACHE |
  323. MIPS_CPU_NOFPUEX;
  324. if (__cpu_has_fpu())
  325. c->options |= MIPS_CPU_FPU;
  326. c->tlbsize = 64;
  327. break;
  328. case PRID_IMP_R4000:
  329. if (read_c0_config() & CONF_SC) {
  330. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  331. c->cputype = CPU_R4400PC;
  332. __cpu_name[cpu] = "R4400PC";
  333. } else {
  334. c->cputype = CPU_R4000PC;
  335. __cpu_name[cpu] = "R4000PC";
  336. }
  337. } else {
  338. if ((c->processor_id & 0xff) >= PRID_REV_R4400) {
  339. c->cputype = CPU_R4400SC;
  340. __cpu_name[cpu] = "R4400SC";
  341. } else {
  342. c->cputype = CPU_R4000SC;
  343. __cpu_name[cpu] = "R4000SC";
  344. }
  345. }
  346. c->isa_level = MIPS_CPU_ISA_III;
  347. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  348. MIPS_CPU_WATCH | MIPS_CPU_VCE |
  349. MIPS_CPU_LLSC;
  350. c->tlbsize = 48;
  351. break;
  352. case PRID_IMP_VR41XX:
  353. switch (c->processor_id & 0xf0) {
  354. case PRID_REV_VR4111:
  355. c->cputype = CPU_VR4111;
  356. __cpu_name[cpu] = "NEC VR4111";
  357. break;
  358. case PRID_REV_VR4121:
  359. c->cputype = CPU_VR4121;
  360. __cpu_name[cpu] = "NEC VR4121";
  361. break;
  362. case PRID_REV_VR4122:
  363. if ((c->processor_id & 0xf) < 0x3) {
  364. c->cputype = CPU_VR4122;
  365. __cpu_name[cpu] = "NEC VR4122";
  366. } else {
  367. c->cputype = CPU_VR4181A;
  368. __cpu_name[cpu] = "NEC VR4181A";
  369. }
  370. break;
  371. case PRID_REV_VR4130:
  372. if ((c->processor_id & 0xf) < 0x4) {
  373. c->cputype = CPU_VR4131;
  374. __cpu_name[cpu] = "NEC VR4131";
  375. } else {
  376. c->cputype = CPU_VR4133;
  377. __cpu_name[cpu] = "NEC VR4133";
  378. }
  379. break;
  380. default:
  381. printk(KERN_INFO "Unexpected CPU of NEC VR4100 series\n");
  382. c->cputype = CPU_VR41XX;
  383. __cpu_name[cpu] = "NEC Vr41xx";
  384. break;
  385. }
  386. c->isa_level = MIPS_CPU_ISA_III;
  387. c->options = R4K_OPTS;
  388. c->tlbsize = 32;
  389. break;
  390. case PRID_IMP_R4300:
  391. c->cputype = CPU_R4300;
  392. __cpu_name[cpu] = "R4300";
  393. c->isa_level = MIPS_CPU_ISA_III;
  394. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  395. MIPS_CPU_LLSC;
  396. c->tlbsize = 32;
  397. break;
  398. case PRID_IMP_R4600:
  399. c->cputype = CPU_R4600;
  400. __cpu_name[cpu] = "R4600";
  401. c->isa_level = MIPS_CPU_ISA_III;
  402. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  403. MIPS_CPU_LLSC;
  404. c->tlbsize = 48;
  405. break;
  406. #if 0
  407. case PRID_IMP_R4650:
  408. /*
  409. * This processor doesn't have an MMU, so it's not
  410. * "real easy" to run Linux on it. It is left purely
  411. * for documentation. Commented out because it shares
  412. * it's c0_prid id number with the TX3900.
  413. */
  414. c->cputype = CPU_R4650;
  415. __cpu_name[cpu] = "R4650";
  416. c->isa_level = MIPS_CPU_ISA_III;
  417. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_LLSC;
  418. c->tlbsize = 48;
  419. break;
  420. #endif
  421. case PRID_IMP_TX39:
  422. c->isa_level = MIPS_CPU_ISA_I;
  423. c->options = MIPS_CPU_TLB | MIPS_CPU_TX39_CACHE;
  424. if ((c->processor_id & 0xf0) == (PRID_REV_TX3927 & 0xf0)) {
  425. c->cputype = CPU_TX3927;
  426. __cpu_name[cpu] = "TX3927";
  427. c->tlbsize = 64;
  428. } else {
  429. switch (c->processor_id & 0xff) {
  430. case PRID_REV_TX3912:
  431. c->cputype = CPU_TX3912;
  432. __cpu_name[cpu] = "TX3912";
  433. c->tlbsize = 32;
  434. break;
  435. case PRID_REV_TX3922:
  436. c->cputype = CPU_TX3922;
  437. __cpu_name[cpu] = "TX3922";
  438. c->tlbsize = 64;
  439. break;
  440. }
  441. }
  442. break;
  443. case PRID_IMP_R4700:
  444. c->cputype = CPU_R4700;
  445. __cpu_name[cpu] = "R4700";
  446. c->isa_level = MIPS_CPU_ISA_III;
  447. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  448. MIPS_CPU_LLSC;
  449. c->tlbsize = 48;
  450. break;
  451. case PRID_IMP_TX49:
  452. c->cputype = CPU_TX49XX;
  453. __cpu_name[cpu] = "R49XX";
  454. c->isa_level = MIPS_CPU_ISA_III;
  455. c->options = R4K_OPTS | MIPS_CPU_LLSC;
  456. if (!(c->processor_id & 0x08))
  457. c->options |= MIPS_CPU_FPU | MIPS_CPU_32FPR;
  458. c->tlbsize = 48;
  459. break;
  460. case PRID_IMP_R5000:
  461. c->cputype = CPU_R5000;
  462. __cpu_name[cpu] = "R5000";
  463. c->isa_level = MIPS_CPU_ISA_IV;
  464. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  465. MIPS_CPU_LLSC;
  466. c->tlbsize = 48;
  467. break;
  468. case PRID_IMP_R5432:
  469. c->cputype = CPU_R5432;
  470. __cpu_name[cpu] = "R5432";
  471. c->isa_level = MIPS_CPU_ISA_IV;
  472. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  473. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  474. c->tlbsize = 48;
  475. break;
  476. case PRID_IMP_R5500:
  477. c->cputype = CPU_R5500;
  478. __cpu_name[cpu] = "R5500";
  479. c->isa_level = MIPS_CPU_ISA_IV;
  480. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  481. MIPS_CPU_WATCH | MIPS_CPU_LLSC;
  482. c->tlbsize = 48;
  483. break;
  484. case PRID_IMP_NEVADA:
  485. c->cputype = CPU_NEVADA;
  486. __cpu_name[cpu] = "Nevada";
  487. c->isa_level = MIPS_CPU_ISA_IV;
  488. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  489. MIPS_CPU_DIVEC | MIPS_CPU_LLSC;
  490. c->tlbsize = 48;
  491. break;
  492. case PRID_IMP_R6000:
  493. c->cputype = CPU_R6000;
  494. __cpu_name[cpu] = "R6000";
  495. c->isa_level = MIPS_CPU_ISA_II;
  496. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  497. MIPS_CPU_LLSC;
  498. c->tlbsize = 32;
  499. break;
  500. case PRID_IMP_R6000A:
  501. c->cputype = CPU_R6000A;
  502. __cpu_name[cpu] = "R6000A";
  503. c->isa_level = MIPS_CPU_ISA_II;
  504. c->options = MIPS_CPU_TLB | MIPS_CPU_FPU |
  505. MIPS_CPU_LLSC;
  506. c->tlbsize = 32;
  507. break;
  508. case PRID_IMP_RM7000:
  509. c->cputype = CPU_RM7000;
  510. __cpu_name[cpu] = "RM7000";
  511. c->isa_level = MIPS_CPU_ISA_IV;
  512. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  513. MIPS_CPU_LLSC;
  514. /*
  515. * Undocumented RM7000: Bit 29 in the info register of
  516. * the RM7000 v2.0 indicates if the TLB has 48 or 64
  517. * entries.
  518. *
  519. * 29 1 => 64 entry JTLB
  520. * 0 => 48 entry JTLB
  521. */
  522. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  523. break;
  524. case PRID_IMP_RM9000:
  525. c->cputype = CPU_RM9000;
  526. __cpu_name[cpu] = "RM9000";
  527. c->isa_level = MIPS_CPU_ISA_IV;
  528. c->options = R4K_OPTS | MIPS_CPU_FPU | MIPS_CPU_32FPR |
  529. MIPS_CPU_LLSC;
  530. /*
  531. * Bit 29 in the info register of the RM9000
  532. * indicates if the TLB has 48 or 64 entries.
  533. *
  534. * 29 1 => 64 entry JTLB
  535. * 0 => 48 entry JTLB
  536. */
  537. c->tlbsize = (read_c0_info() & (1 << 29)) ? 64 : 48;
  538. break;
  539. case PRID_IMP_R8000:
  540. c->cputype = CPU_R8000;
  541. __cpu_name[cpu] = "RM8000";
  542. c->isa_level = MIPS_CPU_ISA_IV;
  543. c->options = MIPS_CPU_TLB | MIPS_CPU_4KEX |
  544. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  545. MIPS_CPU_LLSC;
  546. c->tlbsize = 384; /* has weird TLB: 3-way x 128 */
  547. break;
  548. case PRID_IMP_R10000:
  549. c->cputype = CPU_R10000;
  550. __cpu_name[cpu] = "R10000";
  551. c->isa_level = MIPS_CPU_ISA_IV;
  552. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  553. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  554. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  555. MIPS_CPU_LLSC;
  556. c->tlbsize = 64;
  557. break;
  558. case PRID_IMP_R12000:
  559. c->cputype = CPU_R12000;
  560. __cpu_name[cpu] = "R12000";
  561. c->isa_level = MIPS_CPU_ISA_IV;
  562. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  563. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  564. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  565. MIPS_CPU_LLSC;
  566. c->tlbsize = 64;
  567. break;
  568. case PRID_IMP_R14000:
  569. c->cputype = CPU_R14000;
  570. __cpu_name[cpu] = "R14000";
  571. c->isa_level = MIPS_CPU_ISA_IV;
  572. c->options = MIPS_CPU_TLB | MIPS_CPU_4K_CACHE | MIPS_CPU_4KEX |
  573. MIPS_CPU_FPU | MIPS_CPU_32FPR |
  574. MIPS_CPU_COUNTER | MIPS_CPU_WATCH |
  575. MIPS_CPU_LLSC;
  576. c->tlbsize = 64;
  577. break;
  578. case PRID_IMP_LOONGSON2:
  579. c->cputype = CPU_LOONGSON2;
  580. __cpu_name[cpu] = "ICT Loongson-2";
  581. switch (c->processor_id & PRID_REV_MASK) {
  582. case PRID_REV_LOONGSON2E:
  583. set_elf_platform(cpu, "loongson2e");
  584. break;
  585. case PRID_REV_LOONGSON2F:
  586. set_elf_platform(cpu, "loongson2f");
  587. break;
  588. }
  589. c->isa_level = MIPS_CPU_ISA_III;
  590. c->options = R4K_OPTS |
  591. MIPS_CPU_FPU | MIPS_CPU_LLSC |
  592. MIPS_CPU_32FPR;
  593. c->tlbsize = 64;
  594. break;
  595. }
  596. }
  597. static char unknown_isa[] __cpuinitdata = KERN_ERR \
  598. "Unsupported ISA type, c0.config0: %d.";
  599. static inline unsigned int decode_config0(struct cpuinfo_mips *c)
  600. {
  601. unsigned int config0;
  602. int isa;
  603. config0 = read_c0_config();
  604. if (((config0 & MIPS_CONF_MT) >> 7) == 1)
  605. c->options |= MIPS_CPU_TLB;
  606. isa = (config0 & MIPS_CONF_AT) >> 13;
  607. switch (isa) {
  608. case 0:
  609. switch ((config0 & MIPS_CONF_AR) >> 10) {
  610. case 0:
  611. c->isa_level = MIPS_CPU_ISA_M32R1;
  612. break;
  613. case 1:
  614. c->isa_level = MIPS_CPU_ISA_M32R2;
  615. break;
  616. default:
  617. goto unknown;
  618. }
  619. break;
  620. case 2:
  621. switch ((config0 & MIPS_CONF_AR) >> 10) {
  622. case 0:
  623. c->isa_level = MIPS_CPU_ISA_M64R1;
  624. break;
  625. case 1:
  626. c->isa_level = MIPS_CPU_ISA_M64R2;
  627. break;
  628. default:
  629. goto unknown;
  630. }
  631. break;
  632. default:
  633. goto unknown;
  634. }
  635. return config0 & MIPS_CONF_M;
  636. unknown:
  637. panic(unknown_isa, config0);
  638. }
  639. static inline unsigned int decode_config1(struct cpuinfo_mips *c)
  640. {
  641. unsigned int config1;
  642. config1 = read_c0_config1();
  643. if (config1 & MIPS_CONF1_MD)
  644. c->ases |= MIPS_ASE_MDMX;
  645. if (config1 & MIPS_CONF1_WR)
  646. c->options |= MIPS_CPU_WATCH;
  647. if (config1 & MIPS_CONF1_CA)
  648. c->ases |= MIPS_ASE_MIPS16;
  649. if (config1 & MIPS_CONF1_EP)
  650. c->options |= MIPS_CPU_EJTAG;
  651. if (config1 & MIPS_CONF1_FP) {
  652. c->options |= MIPS_CPU_FPU;
  653. c->options |= MIPS_CPU_32FPR;
  654. }
  655. if (cpu_has_tlb)
  656. c->tlbsize = ((config1 & MIPS_CONF1_TLBS) >> 25) + 1;
  657. return config1 & MIPS_CONF_M;
  658. }
  659. static inline unsigned int decode_config2(struct cpuinfo_mips *c)
  660. {
  661. unsigned int config2;
  662. config2 = read_c0_config2();
  663. if (config2 & MIPS_CONF2_SL)
  664. c->scache.flags &= ~MIPS_CACHE_NOT_PRESENT;
  665. return config2 & MIPS_CONF_M;
  666. }
  667. static inline unsigned int decode_config3(struct cpuinfo_mips *c)
  668. {
  669. unsigned int config3;
  670. config3 = read_c0_config3();
  671. if (config3 & MIPS_CONF3_SM)
  672. c->ases |= MIPS_ASE_SMARTMIPS;
  673. if (config3 & MIPS_CONF3_DSP)
  674. c->ases |= MIPS_ASE_DSP;
  675. if (config3 & MIPS_CONF3_VINT)
  676. c->options |= MIPS_CPU_VINT;
  677. if (config3 & MIPS_CONF3_VEIC)
  678. c->options |= MIPS_CPU_VEIC;
  679. if (config3 & MIPS_CONF3_MT)
  680. c->ases |= MIPS_ASE_MIPSMT;
  681. if (config3 & MIPS_CONF3_ULRI)
  682. c->options |= MIPS_CPU_ULRI;
  683. return config3 & MIPS_CONF_M;
  684. }
  685. static inline unsigned int decode_config4(struct cpuinfo_mips *c)
  686. {
  687. unsigned int config4;
  688. config4 = read_c0_config4();
  689. if ((config4 & MIPS_CONF4_MMUEXTDEF) == MIPS_CONF4_MMUEXTDEF_MMUSIZEEXT
  690. && cpu_has_tlb)
  691. c->tlbsize += (config4 & MIPS_CONF4_MMUSIZEEXT) * 0x40;
  692. c->kscratch_mask = (config4 >> 16) & 0xff;
  693. return config4 & MIPS_CONF_M;
  694. }
  695. static void __cpuinit decode_configs(struct cpuinfo_mips *c)
  696. {
  697. int ok;
  698. /* MIPS32 or MIPS64 compliant CPU. */
  699. c->options = MIPS_CPU_4KEX | MIPS_CPU_4K_CACHE | MIPS_CPU_COUNTER |
  700. MIPS_CPU_DIVEC | MIPS_CPU_LLSC | MIPS_CPU_MCHECK;
  701. c->scache.flags = MIPS_CACHE_NOT_PRESENT;
  702. ok = decode_config0(c); /* Read Config registers. */
  703. BUG_ON(!ok); /* Arch spec violation! */
  704. if (ok)
  705. ok = decode_config1(c);
  706. if (ok)
  707. ok = decode_config2(c);
  708. if (ok)
  709. ok = decode_config3(c);
  710. if (ok)
  711. ok = decode_config4(c);
  712. mips_probe_watch_registers(c);
  713. if (cpu_has_mips_r2)
  714. c->core = read_c0_ebase() & 0x3ff;
  715. }
  716. static inline void cpu_probe_mips(struct cpuinfo_mips *c, unsigned int cpu)
  717. {
  718. decode_configs(c);
  719. switch (c->processor_id & 0xff00) {
  720. case PRID_IMP_4KC:
  721. c->cputype = CPU_4KC;
  722. __cpu_name[cpu] = "MIPS 4Kc";
  723. break;
  724. case PRID_IMP_4KEC:
  725. case PRID_IMP_4KECR2:
  726. c->cputype = CPU_4KEC;
  727. __cpu_name[cpu] = "MIPS 4KEc";
  728. break;
  729. case PRID_IMP_4KSC:
  730. case PRID_IMP_4KSD:
  731. c->cputype = CPU_4KSC;
  732. __cpu_name[cpu] = "MIPS 4KSc";
  733. break;
  734. case PRID_IMP_5KC:
  735. c->cputype = CPU_5KC;
  736. __cpu_name[cpu] = "MIPS 5Kc";
  737. break;
  738. case PRID_IMP_20KC:
  739. c->cputype = CPU_20KC;
  740. __cpu_name[cpu] = "MIPS 20Kc";
  741. break;
  742. case PRID_IMP_24K:
  743. case PRID_IMP_24KE:
  744. c->cputype = CPU_24K;
  745. __cpu_name[cpu] = "MIPS 24Kc";
  746. break;
  747. case PRID_IMP_25KF:
  748. c->cputype = CPU_25KF;
  749. __cpu_name[cpu] = "MIPS 25Kc";
  750. break;
  751. case PRID_IMP_34K:
  752. c->cputype = CPU_34K;
  753. __cpu_name[cpu] = "MIPS 34Kc";
  754. break;
  755. case PRID_IMP_74K:
  756. c->cputype = CPU_74K;
  757. __cpu_name[cpu] = "MIPS 74Kc";
  758. break;
  759. case PRID_IMP_1004K:
  760. c->cputype = CPU_1004K;
  761. __cpu_name[cpu] = "MIPS 1004Kc";
  762. break;
  763. }
  764. spram_config();
  765. }
  766. static inline void cpu_probe_alchemy(struct cpuinfo_mips *c, unsigned int cpu)
  767. {
  768. decode_configs(c);
  769. switch (c->processor_id & 0xff00) {
  770. case PRID_IMP_AU1_REV1:
  771. case PRID_IMP_AU1_REV2:
  772. c->cputype = CPU_ALCHEMY;
  773. switch ((c->processor_id >> 24) & 0xff) {
  774. case 0:
  775. __cpu_name[cpu] = "Au1000";
  776. break;
  777. case 1:
  778. __cpu_name[cpu] = "Au1500";
  779. break;
  780. case 2:
  781. __cpu_name[cpu] = "Au1100";
  782. break;
  783. case 3:
  784. __cpu_name[cpu] = "Au1550";
  785. break;
  786. case 4:
  787. __cpu_name[cpu] = "Au1200";
  788. if ((c->processor_id & 0xff) == 2)
  789. __cpu_name[cpu] = "Au1250";
  790. break;
  791. case 5:
  792. __cpu_name[cpu] = "Au1210";
  793. break;
  794. default:
  795. __cpu_name[cpu] = "Au1xxx";
  796. break;
  797. }
  798. break;
  799. }
  800. }
  801. static inline void cpu_probe_sibyte(struct cpuinfo_mips *c, unsigned int cpu)
  802. {
  803. decode_configs(c);
  804. switch (c->processor_id & 0xff00) {
  805. case PRID_IMP_SB1:
  806. c->cputype = CPU_SB1;
  807. __cpu_name[cpu] = "SiByte SB1";
  808. /* FPU in pass1 is known to have issues. */
  809. if ((c->processor_id & 0xff) < 0x02)
  810. c->options &= ~(MIPS_CPU_FPU | MIPS_CPU_32FPR);
  811. break;
  812. case PRID_IMP_SB1A:
  813. c->cputype = CPU_SB1A;
  814. __cpu_name[cpu] = "SiByte SB1A";
  815. break;
  816. }
  817. }
  818. static inline void cpu_probe_sandcraft(struct cpuinfo_mips *c, unsigned int cpu)
  819. {
  820. decode_configs(c);
  821. switch (c->processor_id & 0xff00) {
  822. case PRID_IMP_SR71000:
  823. c->cputype = CPU_SR71000;
  824. __cpu_name[cpu] = "Sandcraft SR71000";
  825. c->scache.ways = 8;
  826. c->tlbsize = 64;
  827. break;
  828. }
  829. }
  830. static inline void cpu_probe_nxp(struct cpuinfo_mips *c, unsigned int cpu)
  831. {
  832. decode_configs(c);
  833. switch (c->processor_id & 0xff00) {
  834. case PRID_IMP_PR4450:
  835. c->cputype = CPU_PR4450;
  836. __cpu_name[cpu] = "Philips PR4450";
  837. c->isa_level = MIPS_CPU_ISA_M32R1;
  838. break;
  839. }
  840. }
  841. static inline void cpu_probe_broadcom(struct cpuinfo_mips *c, unsigned int cpu)
  842. {
  843. decode_configs(c);
  844. switch (c->processor_id & 0xff00) {
  845. case PRID_IMP_BMIPS32_REV4:
  846. case PRID_IMP_BMIPS32_REV8:
  847. c->cputype = CPU_BMIPS32;
  848. __cpu_name[cpu] = "Broadcom BMIPS32";
  849. set_elf_platform(cpu, "bmips32");
  850. break;
  851. case PRID_IMP_BMIPS3300:
  852. case PRID_IMP_BMIPS3300_ALT:
  853. case PRID_IMP_BMIPS3300_BUG:
  854. c->cputype = CPU_BMIPS3300;
  855. __cpu_name[cpu] = "Broadcom BMIPS3300";
  856. set_elf_platform(cpu, "bmips3300");
  857. break;
  858. case PRID_IMP_BMIPS43XX: {
  859. int rev = c->processor_id & 0xff;
  860. if (rev >= PRID_REV_BMIPS4380_LO &&
  861. rev <= PRID_REV_BMIPS4380_HI) {
  862. c->cputype = CPU_BMIPS4380;
  863. __cpu_name[cpu] = "Broadcom BMIPS4380";
  864. set_elf_platform(cpu, "bmips4380");
  865. } else {
  866. c->cputype = CPU_BMIPS4350;
  867. __cpu_name[cpu] = "Broadcom BMIPS4350";
  868. set_elf_platform(cpu, "bmips4350");
  869. }
  870. break;
  871. }
  872. case PRID_IMP_BMIPS5000:
  873. c->cputype = CPU_BMIPS5000;
  874. __cpu_name[cpu] = "Broadcom BMIPS5000";
  875. set_elf_platform(cpu, "bmips5000");
  876. c->options |= MIPS_CPU_ULRI;
  877. break;
  878. }
  879. }
  880. static inline void cpu_probe_cavium(struct cpuinfo_mips *c, unsigned int cpu)
  881. {
  882. decode_configs(c);
  883. switch (c->processor_id & 0xff00) {
  884. case PRID_IMP_CAVIUM_CN38XX:
  885. case PRID_IMP_CAVIUM_CN31XX:
  886. case PRID_IMP_CAVIUM_CN30XX:
  887. c->cputype = CPU_CAVIUM_OCTEON;
  888. __cpu_name[cpu] = "Cavium Octeon";
  889. goto platform;
  890. case PRID_IMP_CAVIUM_CN58XX:
  891. case PRID_IMP_CAVIUM_CN56XX:
  892. case PRID_IMP_CAVIUM_CN50XX:
  893. case PRID_IMP_CAVIUM_CN52XX:
  894. c->cputype = CPU_CAVIUM_OCTEON_PLUS;
  895. __cpu_name[cpu] = "Cavium Octeon+";
  896. platform:
  897. set_elf_platform(cpu, "octeon");
  898. break;
  899. case PRID_IMP_CAVIUM_CN63XX:
  900. c->cputype = CPU_CAVIUM_OCTEON2;
  901. __cpu_name[cpu] = "Cavium Octeon II";
  902. set_elf_platform(cpu, "octeon2");
  903. break;
  904. default:
  905. printk(KERN_INFO "Unknown Octeon chip!\n");
  906. c->cputype = CPU_UNKNOWN;
  907. break;
  908. }
  909. }
  910. static inline void cpu_probe_ingenic(struct cpuinfo_mips *c, unsigned int cpu)
  911. {
  912. decode_configs(c);
  913. /* JZRISC does not implement the CP0 counter. */
  914. c->options &= ~MIPS_CPU_COUNTER;
  915. switch (c->processor_id & 0xff00) {
  916. case PRID_IMP_JZRISC:
  917. c->cputype = CPU_JZRISC;
  918. __cpu_name[cpu] = "Ingenic JZRISC";
  919. break;
  920. default:
  921. panic("Unknown Ingenic Processor ID!");
  922. break;
  923. }
  924. }
  925. static inline void cpu_probe_netlogic(struct cpuinfo_mips *c, int cpu)
  926. {
  927. decode_configs(c);
  928. c->options = (MIPS_CPU_TLB |
  929. MIPS_CPU_4KEX |
  930. MIPS_CPU_COUNTER |
  931. MIPS_CPU_DIVEC |
  932. MIPS_CPU_WATCH |
  933. MIPS_CPU_EJTAG |
  934. MIPS_CPU_LLSC);
  935. switch (c->processor_id & 0xff00) {
  936. case PRID_IMP_NETLOGIC_XLR732:
  937. case PRID_IMP_NETLOGIC_XLR716:
  938. case PRID_IMP_NETLOGIC_XLR532:
  939. case PRID_IMP_NETLOGIC_XLR308:
  940. case PRID_IMP_NETLOGIC_XLR532C:
  941. case PRID_IMP_NETLOGIC_XLR516C:
  942. case PRID_IMP_NETLOGIC_XLR508C:
  943. case PRID_IMP_NETLOGIC_XLR308C:
  944. c->cputype = CPU_XLR;
  945. __cpu_name[cpu] = "Netlogic XLR";
  946. break;
  947. case PRID_IMP_NETLOGIC_XLS608:
  948. case PRID_IMP_NETLOGIC_XLS408:
  949. case PRID_IMP_NETLOGIC_XLS404:
  950. case PRID_IMP_NETLOGIC_XLS208:
  951. case PRID_IMP_NETLOGIC_XLS204:
  952. case PRID_IMP_NETLOGIC_XLS108:
  953. case PRID_IMP_NETLOGIC_XLS104:
  954. case PRID_IMP_NETLOGIC_XLS616B:
  955. case PRID_IMP_NETLOGIC_XLS608B:
  956. case PRID_IMP_NETLOGIC_XLS416B:
  957. case PRID_IMP_NETLOGIC_XLS412B:
  958. case PRID_IMP_NETLOGIC_XLS408B:
  959. case PRID_IMP_NETLOGIC_XLS404B:
  960. c->cputype = CPU_XLR;
  961. __cpu_name[cpu] = "Netlogic XLS";
  962. break;
  963. default:
  964. printk(KERN_INFO "Unknown Netlogic chip id [%02x]!\n",
  965. c->processor_id);
  966. c->cputype = CPU_XLR;
  967. break;
  968. }
  969. c->isa_level = MIPS_CPU_ISA_M64R1;
  970. c->tlbsize = ((read_c0_config1() >> 25) & 0x3f) + 1;
  971. }
  972. #ifdef CONFIG_64BIT
  973. /* For use by uaccess.h */
  974. u64 __ua_limit;
  975. EXPORT_SYMBOL(__ua_limit);
  976. #endif
  977. const char *__cpu_name[NR_CPUS];
  978. const char *__elf_platform;
  979. __cpuinit void cpu_probe(void)
  980. {
  981. struct cpuinfo_mips *c = &current_cpu_data;
  982. unsigned int cpu = smp_processor_id();
  983. c->processor_id = PRID_IMP_UNKNOWN;
  984. c->fpu_id = FPIR_IMP_NONE;
  985. c->cputype = CPU_UNKNOWN;
  986. c->processor_id = read_c0_prid();
  987. switch (c->processor_id & 0xff0000) {
  988. case PRID_COMP_LEGACY:
  989. cpu_probe_legacy(c, cpu);
  990. break;
  991. case PRID_COMP_MIPS:
  992. cpu_probe_mips(c, cpu);
  993. break;
  994. case PRID_COMP_ALCHEMY:
  995. cpu_probe_alchemy(c, cpu);
  996. break;
  997. case PRID_COMP_SIBYTE:
  998. cpu_probe_sibyte(c, cpu);
  999. break;
  1000. case PRID_COMP_BROADCOM:
  1001. cpu_probe_broadcom(c, cpu);
  1002. break;
  1003. case PRID_COMP_SANDCRAFT:
  1004. cpu_probe_sandcraft(c, cpu);
  1005. break;
  1006. case PRID_COMP_NXP:
  1007. cpu_probe_nxp(c, cpu);
  1008. break;
  1009. case PRID_COMP_CAVIUM:
  1010. cpu_probe_cavium(c, cpu);
  1011. break;
  1012. case PRID_COMP_INGENIC:
  1013. cpu_probe_ingenic(c, cpu);
  1014. break;
  1015. case PRID_COMP_NETLOGIC:
  1016. cpu_probe_netlogic(c, cpu);
  1017. break;
  1018. }
  1019. BUG_ON(!__cpu_name[cpu]);
  1020. BUG_ON(c->cputype == CPU_UNKNOWN);
  1021. /*
  1022. * Platform code can force the cpu type to optimize code
  1023. * generation. In that case be sure the cpu type is correctly
  1024. * manually setup otherwise it could trigger some nasty bugs.
  1025. */
  1026. BUG_ON(current_cpu_type() != c->cputype);
  1027. if (mips_fpu_disabled)
  1028. c->options &= ~MIPS_CPU_FPU;
  1029. if (mips_dsp_disabled)
  1030. c->ases &= ~MIPS_ASE_DSP;
  1031. if (c->options & MIPS_CPU_FPU) {
  1032. c->fpu_id = cpu_get_fpu_id();
  1033. if (c->isa_level == MIPS_CPU_ISA_M32R1 ||
  1034. c->isa_level == MIPS_CPU_ISA_M32R2 ||
  1035. c->isa_level == MIPS_CPU_ISA_M64R1 ||
  1036. c->isa_level == MIPS_CPU_ISA_M64R2) {
  1037. if (c->fpu_id & MIPS_FPIR_3D)
  1038. c->ases |= MIPS_ASE_MIPS3D;
  1039. }
  1040. }
  1041. if (cpu_has_mips_r2)
  1042. c->srsets = ((read_c0_srsctl() >> 26) & 0x0f) + 1;
  1043. else
  1044. c->srsets = 1;
  1045. cpu_probe_vmbits(c);
  1046. #ifdef CONFIG_64BIT
  1047. if (cpu == 0)
  1048. __ua_limit = ~((1ull << cpu_vmbits) - 1);
  1049. #endif
  1050. }
  1051. __cpuinit void cpu_report(void)
  1052. {
  1053. struct cpuinfo_mips *c = &current_cpu_data;
  1054. printk(KERN_INFO "CPU revision is: %08x (%s)\n",
  1055. c->processor_id, cpu_name_string());
  1056. if (c->options & MIPS_CPU_FPU)
  1057. printk(KERN_INFO "FPU revision is: %08x\n", c->fpu_id);
  1058. }