mipsregs.h 43 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (C) 1994, 1995, 1996, 1997, 2000, 2001 by Ralf Baechle
  7. * Copyright (C) 2000 Silicon Graphics, Inc.
  8. * Modified for further R[236]000 support by Paul M. Antoine, 1996.
  9. * Kevin D. Kissell, kevink@mips.com and Carsten Langgaard, carstenl@mips.com
  10. * Copyright (C) 2000, 07 MIPS Technologies, Inc.
  11. * Copyright (C) 2003, 2004 Maciej W. Rozycki
  12. */
  13. #ifndef _ASM_MIPSREGS_H
  14. #define _ASM_MIPSREGS_H
  15. #include <linux/linkage.h>
  16. #include <asm/hazards.h>
  17. #include <asm/war.h>
  18. /*
  19. * The following macros are especially useful for __asm__
  20. * inline assembler.
  21. */
  22. #ifndef __STR
  23. #define __STR(x) #x
  24. #endif
  25. #ifndef STR
  26. #define STR(x) __STR(x)
  27. #endif
  28. /*
  29. * Configure language
  30. */
  31. #ifdef __ASSEMBLY__
  32. #define _ULCAST_
  33. #else
  34. #define _ULCAST_ (unsigned long)
  35. #endif
  36. /*
  37. * Coprocessor 0 register names
  38. */
  39. #define CP0_INDEX $0
  40. #define CP0_RANDOM $1
  41. #define CP0_ENTRYLO0 $2
  42. #define CP0_ENTRYLO1 $3
  43. #define CP0_CONF $3
  44. #define CP0_CONTEXT $4
  45. #define CP0_PAGEMASK $5
  46. #define CP0_WIRED $6
  47. #define CP0_INFO $7
  48. #define CP0_BADVADDR $8
  49. #define CP0_COUNT $9
  50. #define CP0_ENTRYHI $10
  51. #define CP0_COMPARE $11
  52. #define CP0_STATUS $12
  53. #define CP0_CAUSE $13
  54. #define CP0_EPC $14
  55. #define CP0_PRID $15
  56. #define CP0_CONFIG $16
  57. #define CP0_LLADDR $17
  58. #define CP0_WATCHLO $18
  59. #define CP0_WATCHHI $19
  60. #define CP0_XCONTEXT $20
  61. #define CP0_FRAMEMASK $21
  62. #define CP0_DIAGNOSTIC $22
  63. #define CP0_DEBUG $23
  64. #define CP0_DEPC $24
  65. #define CP0_PERFORMANCE $25
  66. #define CP0_ECC $26
  67. #define CP0_CACHEERR $27
  68. #define CP0_TAGLO $28
  69. #define CP0_TAGHI $29
  70. #define CP0_ERROREPC $30
  71. #define CP0_DESAVE $31
  72. /*
  73. * R4640/R4650 cp0 register names. These registers are listed
  74. * here only for completeness; without MMU these CPUs are not useable
  75. * by Linux. A future ELKS port might take make Linux run on them
  76. * though ...
  77. */
  78. #define CP0_IBASE $0
  79. #define CP0_IBOUND $1
  80. #define CP0_DBASE $2
  81. #define CP0_DBOUND $3
  82. #define CP0_CALG $17
  83. #define CP0_IWATCH $18
  84. #define CP0_DWATCH $19
  85. /*
  86. * Coprocessor 0 Set 1 register names
  87. */
  88. #define CP0_S1_DERRADDR0 $26
  89. #define CP0_S1_DERRADDR1 $27
  90. #define CP0_S1_INTCONTROL $20
  91. /*
  92. * Coprocessor 0 Set 2 register names
  93. */
  94. #define CP0_S2_SRSCTL $12 /* MIPSR2 */
  95. /*
  96. * Coprocessor 0 Set 3 register names
  97. */
  98. #define CP0_S3_SRSMAP $12 /* MIPSR2 */
  99. /*
  100. * TX39 Series
  101. */
  102. #define CP0_TX39_CACHE $7
  103. /*
  104. * Coprocessor 1 (FPU) register names
  105. */
  106. #define CP1_REVISION $0
  107. #define CP1_STATUS $31
  108. /*
  109. * FPU Status Register Values
  110. */
  111. /*
  112. * Status Register Values
  113. */
  114. #define FPU_CSR_FLUSH 0x01000000 /* flush denormalised results to 0 */
  115. #define FPU_CSR_COND 0x00800000 /* $fcc0 */
  116. #define FPU_CSR_COND0 0x00800000 /* $fcc0 */
  117. #define FPU_CSR_COND1 0x02000000 /* $fcc1 */
  118. #define FPU_CSR_COND2 0x04000000 /* $fcc2 */
  119. #define FPU_CSR_COND3 0x08000000 /* $fcc3 */
  120. #define FPU_CSR_COND4 0x10000000 /* $fcc4 */
  121. #define FPU_CSR_COND5 0x20000000 /* $fcc5 */
  122. #define FPU_CSR_COND6 0x40000000 /* $fcc6 */
  123. #define FPU_CSR_COND7 0x80000000 /* $fcc7 */
  124. /*
  125. * X the exception cause indicator
  126. * E the exception enable
  127. * S the sticky/flag bit
  128. */
  129. #define FPU_CSR_ALL_X 0x0003f000
  130. #define FPU_CSR_UNI_X 0x00020000
  131. #define FPU_CSR_INV_X 0x00010000
  132. #define FPU_CSR_DIV_X 0x00008000
  133. #define FPU_CSR_OVF_X 0x00004000
  134. #define FPU_CSR_UDF_X 0x00002000
  135. #define FPU_CSR_INE_X 0x00001000
  136. #define FPU_CSR_ALL_E 0x00000f80
  137. #define FPU_CSR_INV_E 0x00000800
  138. #define FPU_CSR_DIV_E 0x00000400
  139. #define FPU_CSR_OVF_E 0x00000200
  140. #define FPU_CSR_UDF_E 0x00000100
  141. #define FPU_CSR_INE_E 0x00000080
  142. #define FPU_CSR_ALL_S 0x0000007c
  143. #define FPU_CSR_INV_S 0x00000040
  144. #define FPU_CSR_DIV_S 0x00000020
  145. #define FPU_CSR_OVF_S 0x00000010
  146. #define FPU_CSR_UDF_S 0x00000008
  147. #define FPU_CSR_INE_S 0x00000004
  148. /* rounding mode */
  149. #define FPU_CSR_RN 0x0 /* nearest */
  150. #define FPU_CSR_RZ 0x1 /* towards zero */
  151. #define FPU_CSR_RU 0x2 /* towards +Infinity */
  152. #define FPU_CSR_RD 0x3 /* towards -Infinity */
  153. /*
  154. * Values for PageMask register
  155. */
  156. #ifdef CONFIG_CPU_VR41XX
  157. /* Why doesn't stupidity hurt ... */
  158. #define PM_1K 0x00000000
  159. #define PM_4K 0x00001800
  160. #define PM_16K 0x00007800
  161. #define PM_64K 0x0001f800
  162. #define PM_256K 0x0007f800
  163. #else
  164. #define PM_4K 0x00000000
  165. #define PM_16K 0x00006000
  166. #define PM_64K 0x0001e000
  167. #define PM_256K 0x0007e000
  168. #define PM_1M 0x001fe000
  169. #define PM_4M 0x007fe000
  170. #define PM_16M 0x01ffe000
  171. #define PM_64M 0x07ffe000
  172. #define PM_256M 0x1fffe000
  173. #define PM_1G 0x7fffe000
  174. #endif
  175. /*
  176. * Default page size for a given kernel configuration
  177. */
  178. #ifdef CONFIG_PAGE_SIZE_4KB
  179. #define PM_DEFAULT_MASK PM_4K
  180. #elif defined(CONFIG_PAGE_SIZE_16KB)
  181. #define PM_DEFAULT_MASK PM_16K
  182. #elif defined(CONFIG_PAGE_SIZE_64KB)
  183. #define PM_DEFAULT_MASK PM_64K
  184. #else
  185. #error Bad page size configuration!
  186. #endif
  187. /*
  188. * Values used for computation of new tlb entries
  189. */
  190. #define PL_4K 12
  191. #define PL_16K 14
  192. #define PL_64K 16
  193. #define PL_256K 18
  194. #define PL_1M 20
  195. #define PL_4M 22
  196. #define PL_16M 24
  197. #define PL_64M 26
  198. #define PL_256M 28
  199. /*
  200. * R4x00 interrupt enable / cause bits
  201. */
  202. #define IE_SW0 (_ULCAST_(1) << 8)
  203. #define IE_SW1 (_ULCAST_(1) << 9)
  204. #define IE_IRQ0 (_ULCAST_(1) << 10)
  205. #define IE_IRQ1 (_ULCAST_(1) << 11)
  206. #define IE_IRQ2 (_ULCAST_(1) << 12)
  207. #define IE_IRQ3 (_ULCAST_(1) << 13)
  208. #define IE_IRQ4 (_ULCAST_(1) << 14)
  209. #define IE_IRQ5 (_ULCAST_(1) << 15)
  210. /*
  211. * R4x00 interrupt cause bits
  212. */
  213. #define C_SW0 (_ULCAST_(1) << 8)
  214. #define C_SW1 (_ULCAST_(1) << 9)
  215. #define C_IRQ0 (_ULCAST_(1) << 10)
  216. #define C_IRQ1 (_ULCAST_(1) << 11)
  217. #define C_IRQ2 (_ULCAST_(1) << 12)
  218. #define C_IRQ3 (_ULCAST_(1) << 13)
  219. #define C_IRQ4 (_ULCAST_(1) << 14)
  220. #define C_IRQ5 (_ULCAST_(1) << 15)
  221. /*
  222. * Bitfields in the R4xx0 cp0 status register
  223. */
  224. #define ST0_IE 0x00000001
  225. #define ST0_EXL 0x00000002
  226. #define ST0_ERL 0x00000004
  227. #define ST0_KSU 0x00000018
  228. # define KSU_USER 0x00000010
  229. # define KSU_SUPERVISOR 0x00000008
  230. # define KSU_KERNEL 0x00000000
  231. #define ST0_UX 0x00000020
  232. #define ST0_SX 0x00000040
  233. #define ST0_KX 0x00000080
  234. #define ST0_DE 0x00010000
  235. #define ST0_CE 0x00020000
  236. /*
  237. * Setting c0_status.co enables Hit_Writeback and Hit_Writeback_Invalidate
  238. * cacheops in userspace. This bit exists only on RM7000 and RM9000
  239. * processors.
  240. */
  241. #define ST0_CO 0x08000000
  242. /*
  243. * Bitfields in the R[23]000 cp0 status register.
  244. */
  245. #define ST0_IEC 0x00000001
  246. #define ST0_KUC 0x00000002
  247. #define ST0_IEP 0x00000004
  248. #define ST0_KUP 0x00000008
  249. #define ST0_IEO 0x00000010
  250. #define ST0_KUO 0x00000020
  251. /* bits 6 & 7 are reserved on R[23]000 */
  252. #define ST0_ISC 0x00010000
  253. #define ST0_SWC 0x00020000
  254. #define ST0_CM 0x00080000
  255. /*
  256. * Bits specific to the R4640/R4650
  257. */
  258. #define ST0_UM (_ULCAST_(1) << 4)
  259. #define ST0_IL (_ULCAST_(1) << 23)
  260. #define ST0_DL (_ULCAST_(1) << 24)
  261. /*
  262. * Enable the MIPS MDMX and DSP ASEs
  263. */
  264. #define ST0_MX 0x01000000
  265. /*
  266. * Bitfields in the TX39 family CP0 Configuration Register 3
  267. */
  268. #define TX39_CONF_ICS_SHIFT 19
  269. #define TX39_CONF_ICS_MASK 0x00380000
  270. #define TX39_CONF_ICS_1KB 0x00000000
  271. #define TX39_CONF_ICS_2KB 0x00080000
  272. #define TX39_CONF_ICS_4KB 0x00100000
  273. #define TX39_CONF_ICS_8KB 0x00180000
  274. #define TX39_CONF_ICS_16KB 0x00200000
  275. #define TX39_CONF_DCS_SHIFT 16
  276. #define TX39_CONF_DCS_MASK 0x00070000
  277. #define TX39_CONF_DCS_1KB 0x00000000
  278. #define TX39_CONF_DCS_2KB 0x00010000
  279. #define TX39_CONF_DCS_4KB 0x00020000
  280. #define TX39_CONF_DCS_8KB 0x00030000
  281. #define TX39_CONF_DCS_16KB 0x00040000
  282. #define TX39_CONF_CWFON 0x00004000
  283. #define TX39_CONF_WBON 0x00002000
  284. #define TX39_CONF_RF_SHIFT 10
  285. #define TX39_CONF_RF_MASK 0x00000c00
  286. #define TX39_CONF_DOZE 0x00000200
  287. #define TX39_CONF_HALT 0x00000100
  288. #define TX39_CONF_LOCK 0x00000080
  289. #define TX39_CONF_ICE 0x00000020
  290. #define TX39_CONF_DCE 0x00000010
  291. #define TX39_CONF_IRSIZE_SHIFT 2
  292. #define TX39_CONF_IRSIZE_MASK 0x0000000c
  293. #define TX39_CONF_DRSIZE_SHIFT 0
  294. #define TX39_CONF_DRSIZE_MASK 0x00000003
  295. /*
  296. * Status register bits available in all MIPS CPUs.
  297. */
  298. #define ST0_IM 0x0000ff00
  299. #define STATUSB_IP0 8
  300. #define STATUSF_IP0 (_ULCAST_(1) << 8)
  301. #define STATUSB_IP1 9
  302. #define STATUSF_IP1 (_ULCAST_(1) << 9)
  303. #define STATUSB_IP2 10
  304. #define STATUSF_IP2 (_ULCAST_(1) << 10)
  305. #define STATUSB_IP3 11
  306. #define STATUSF_IP3 (_ULCAST_(1) << 11)
  307. #define STATUSB_IP4 12
  308. #define STATUSF_IP4 (_ULCAST_(1) << 12)
  309. #define STATUSB_IP5 13
  310. #define STATUSF_IP5 (_ULCAST_(1) << 13)
  311. #define STATUSB_IP6 14
  312. #define STATUSF_IP6 (_ULCAST_(1) << 14)
  313. #define STATUSB_IP7 15
  314. #define STATUSF_IP7 (_ULCAST_(1) << 15)
  315. #define STATUSB_IP8 0
  316. #define STATUSF_IP8 (_ULCAST_(1) << 0)
  317. #define STATUSB_IP9 1
  318. #define STATUSF_IP9 (_ULCAST_(1) << 1)
  319. #define STATUSB_IP10 2
  320. #define STATUSF_IP10 (_ULCAST_(1) << 2)
  321. #define STATUSB_IP11 3
  322. #define STATUSF_IP11 (_ULCAST_(1) << 3)
  323. #define STATUSB_IP12 4
  324. #define STATUSF_IP12 (_ULCAST_(1) << 4)
  325. #define STATUSB_IP13 5
  326. #define STATUSF_IP13 (_ULCAST_(1) << 5)
  327. #define STATUSB_IP14 6
  328. #define STATUSF_IP14 (_ULCAST_(1) << 6)
  329. #define STATUSB_IP15 7
  330. #define STATUSF_IP15 (_ULCAST_(1) << 7)
  331. #define ST0_CH 0x00040000
  332. #define ST0_SR 0x00100000
  333. #define ST0_TS 0x00200000
  334. #define ST0_BEV 0x00400000
  335. #define ST0_RE 0x02000000
  336. #define ST0_FR 0x04000000
  337. #define ST0_CU 0xf0000000
  338. #define ST0_CU0 0x10000000
  339. #define ST0_CU1 0x20000000
  340. #define ST0_CU2 0x40000000
  341. #define ST0_CU3 0x80000000
  342. #define ST0_XX 0x80000000 /* MIPS IV naming */
  343. /*
  344. * Bitfields and bit numbers in the coprocessor 0 cause register.
  345. *
  346. * Refer to your MIPS R4xx0 manual, chapter 5 for explanation.
  347. */
  348. #define CAUSEB_EXCCODE 2
  349. #define CAUSEF_EXCCODE (_ULCAST_(31) << 2)
  350. #define CAUSEB_IP 8
  351. #define CAUSEF_IP (_ULCAST_(255) << 8)
  352. #define CAUSEB_IP0 8
  353. #define CAUSEF_IP0 (_ULCAST_(1) << 8)
  354. #define CAUSEB_IP1 9
  355. #define CAUSEF_IP1 (_ULCAST_(1) << 9)
  356. #define CAUSEB_IP2 10
  357. #define CAUSEF_IP2 (_ULCAST_(1) << 10)
  358. #define CAUSEB_IP3 11
  359. #define CAUSEF_IP3 (_ULCAST_(1) << 11)
  360. #define CAUSEB_IP4 12
  361. #define CAUSEF_IP4 (_ULCAST_(1) << 12)
  362. #define CAUSEB_IP5 13
  363. #define CAUSEF_IP5 (_ULCAST_(1) << 13)
  364. #define CAUSEB_IP6 14
  365. #define CAUSEF_IP6 (_ULCAST_(1) << 14)
  366. #define CAUSEB_IP7 15
  367. #define CAUSEF_IP7 (_ULCAST_(1) << 15)
  368. #define CAUSEB_IV 23
  369. #define CAUSEF_IV (_ULCAST_(1) << 23)
  370. #define CAUSEB_CE 28
  371. #define CAUSEF_CE (_ULCAST_(3) << 28)
  372. #define CAUSEB_BD 31
  373. #define CAUSEF_BD (_ULCAST_(1) << 31)
  374. /*
  375. * Bits in the coprocessor 0 config register.
  376. */
  377. /* Generic bits. */
  378. #define CONF_CM_CACHABLE_NO_WA 0
  379. #define CONF_CM_CACHABLE_WA 1
  380. #define CONF_CM_UNCACHED 2
  381. #define CONF_CM_CACHABLE_NONCOHERENT 3
  382. #define CONF_CM_CACHABLE_CE 4
  383. #define CONF_CM_CACHABLE_COW 5
  384. #define CONF_CM_CACHABLE_CUW 6
  385. #define CONF_CM_CACHABLE_ACCELERATED 7
  386. #define CONF_CM_CMASK 7
  387. #define CONF_BE (_ULCAST_(1) << 15)
  388. /* Bits common to various processors. */
  389. #define CONF_CU (_ULCAST_(1) << 3)
  390. #define CONF_DB (_ULCAST_(1) << 4)
  391. #define CONF_IB (_ULCAST_(1) << 5)
  392. #define CONF_DC (_ULCAST_(7) << 6)
  393. #define CONF_IC (_ULCAST_(7) << 9)
  394. #define CONF_EB (_ULCAST_(1) << 13)
  395. #define CONF_EM (_ULCAST_(1) << 14)
  396. #define CONF_SM (_ULCAST_(1) << 16)
  397. #define CONF_SC (_ULCAST_(1) << 17)
  398. #define CONF_EW (_ULCAST_(3) << 18)
  399. #define CONF_EP (_ULCAST_(15)<< 24)
  400. #define CONF_EC (_ULCAST_(7) << 28)
  401. #define CONF_CM (_ULCAST_(1) << 31)
  402. /* Bits specific to the R4xx0. */
  403. #define R4K_CONF_SW (_ULCAST_(1) << 20)
  404. #define R4K_CONF_SS (_ULCAST_(1) << 21)
  405. #define R4K_CONF_SB (_ULCAST_(3) << 22)
  406. /* Bits specific to the R5000. */
  407. #define R5K_CONF_SE (_ULCAST_(1) << 12)
  408. #define R5K_CONF_SS (_ULCAST_(3) << 20)
  409. /* Bits specific to the RM7000. */
  410. #define RM7K_CONF_SE (_ULCAST_(1) << 3)
  411. #define RM7K_CONF_TE (_ULCAST_(1) << 12)
  412. #define RM7K_CONF_CLK (_ULCAST_(1) << 16)
  413. #define RM7K_CONF_TC (_ULCAST_(1) << 17)
  414. #define RM7K_CONF_SI (_ULCAST_(3) << 20)
  415. #define RM7K_CONF_SC (_ULCAST_(1) << 31)
  416. /* Bits specific to the R10000. */
  417. #define R10K_CONF_DN (_ULCAST_(3) << 3)
  418. #define R10K_CONF_CT (_ULCAST_(1) << 5)
  419. #define R10K_CONF_PE (_ULCAST_(1) << 6)
  420. #define R10K_CONF_PM (_ULCAST_(3) << 7)
  421. #define R10K_CONF_EC (_ULCAST_(15)<< 9)
  422. #define R10K_CONF_SB (_ULCAST_(1) << 13)
  423. #define R10K_CONF_SK (_ULCAST_(1) << 14)
  424. #define R10K_CONF_SS (_ULCAST_(7) << 16)
  425. #define R10K_CONF_SC (_ULCAST_(7) << 19)
  426. #define R10K_CONF_DC (_ULCAST_(7) << 26)
  427. #define R10K_CONF_IC (_ULCAST_(7) << 29)
  428. /* Bits specific to the VR41xx. */
  429. #define VR41_CONF_CS (_ULCAST_(1) << 12)
  430. #define VR41_CONF_P4K (_ULCAST_(1) << 13)
  431. #define VR41_CONF_BP (_ULCAST_(1) << 16)
  432. #define VR41_CONF_M16 (_ULCAST_(1) << 20)
  433. #define VR41_CONF_AD (_ULCAST_(1) << 23)
  434. /* Bits specific to the R30xx. */
  435. #define R30XX_CONF_FDM (_ULCAST_(1) << 19)
  436. #define R30XX_CONF_REV (_ULCAST_(1) << 22)
  437. #define R30XX_CONF_AC (_ULCAST_(1) << 23)
  438. #define R30XX_CONF_RF (_ULCAST_(1) << 24)
  439. #define R30XX_CONF_HALT (_ULCAST_(1) << 25)
  440. #define R30XX_CONF_FPINT (_ULCAST_(7) << 26)
  441. #define R30XX_CONF_DBR (_ULCAST_(1) << 29)
  442. #define R30XX_CONF_SB (_ULCAST_(1) << 30)
  443. #define R30XX_CONF_LOCK (_ULCAST_(1) << 31)
  444. /* Bits specific to the TX49. */
  445. #define TX49_CONF_DC (_ULCAST_(1) << 16)
  446. #define TX49_CONF_IC (_ULCAST_(1) << 17) /* conflict with CONF_SC */
  447. #define TX49_CONF_HALT (_ULCAST_(1) << 18)
  448. #define TX49_CONF_CWFON (_ULCAST_(1) << 27)
  449. /* Bits specific to the MIPS32/64 PRA. */
  450. #define MIPS_CONF_MT (_ULCAST_(7) << 7)
  451. #define MIPS_CONF_AR (_ULCAST_(7) << 10)
  452. #define MIPS_CONF_AT (_ULCAST_(3) << 13)
  453. #define MIPS_CONF_M (_ULCAST_(1) << 31)
  454. /*
  455. * Bits in the MIPS32/64 PRA coprocessor 0 config registers 1 and above.
  456. */
  457. #define MIPS_CONF1_FP (_ULCAST_(1) << 0)
  458. #define MIPS_CONF1_EP (_ULCAST_(1) << 1)
  459. #define MIPS_CONF1_CA (_ULCAST_(1) << 2)
  460. #define MIPS_CONF1_WR (_ULCAST_(1) << 3)
  461. #define MIPS_CONF1_PC (_ULCAST_(1) << 4)
  462. #define MIPS_CONF1_MD (_ULCAST_(1) << 5)
  463. #define MIPS_CONF1_C2 (_ULCAST_(1) << 6)
  464. #define MIPS_CONF1_DA (_ULCAST_(7) << 7)
  465. #define MIPS_CONF1_DL (_ULCAST_(7) << 10)
  466. #define MIPS_CONF1_DS (_ULCAST_(7) << 13)
  467. #define MIPS_CONF1_IA (_ULCAST_(7) << 16)
  468. #define MIPS_CONF1_IL (_ULCAST_(7) << 19)
  469. #define MIPS_CONF1_IS (_ULCAST_(7) << 22)
  470. #define MIPS_CONF1_TLBS (_ULCAST_(63)<< 25)
  471. #define MIPS_CONF2_SA (_ULCAST_(15)<< 0)
  472. #define MIPS_CONF2_SL (_ULCAST_(15)<< 4)
  473. #define MIPS_CONF2_SS (_ULCAST_(15)<< 8)
  474. #define MIPS_CONF2_SU (_ULCAST_(15)<< 12)
  475. #define MIPS_CONF2_TA (_ULCAST_(15)<< 16)
  476. #define MIPS_CONF2_TL (_ULCAST_(15)<< 20)
  477. #define MIPS_CONF2_TS (_ULCAST_(15)<< 24)
  478. #define MIPS_CONF2_TU (_ULCAST_(7) << 28)
  479. #define MIPS_CONF3_TL (_ULCAST_(1) << 0)
  480. #define MIPS_CONF3_SM (_ULCAST_(1) << 1)
  481. #define MIPS_CONF3_MT (_ULCAST_(1) << 2)
  482. #define MIPS_CONF3_SP (_ULCAST_(1) << 4)
  483. #define MIPS_CONF3_VINT (_ULCAST_(1) << 5)
  484. #define MIPS_CONF3_VEIC (_ULCAST_(1) << 6)
  485. #define MIPS_CONF3_LPA (_ULCAST_(1) << 7)
  486. #define MIPS_CONF3_DSP (_ULCAST_(1) << 10)
  487. #define MIPS_CONF3_ULRI (_ULCAST_(1) << 13)
  488. #define MIPS_CONF7_WII (_ULCAST_(1) << 31)
  489. #define MIPS_CONF7_RPS (_ULCAST_(1) << 2)
  490. /*
  491. * Bits in the MIPS32/64 coprocessor 1 (FPU) revision register.
  492. */
  493. #define MIPS_FPIR_S (_ULCAST_(1) << 16)
  494. #define MIPS_FPIR_D (_ULCAST_(1) << 17)
  495. #define MIPS_FPIR_PS (_ULCAST_(1) << 18)
  496. #define MIPS_FPIR_3D (_ULCAST_(1) << 19)
  497. #define MIPS_FPIR_W (_ULCAST_(1) << 20)
  498. #define MIPS_FPIR_L (_ULCAST_(1) << 21)
  499. #define MIPS_FPIR_F64 (_ULCAST_(1) << 22)
  500. #ifndef __ASSEMBLY__
  501. /*
  502. * Functions to access the R10000 performance counters. These are basically
  503. * mfc0 and mtc0 instructions from and to coprocessor register with a 5-bit
  504. * performance counter number encoded into bits 1 ... 5 of the instruction.
  505. * Only performance counters 0 to 1 actually exist, so for a non-R10000 aware
  506. * disassembler these will look like an access to sel 0 or 1.
  507. */
  508. #define read_r10k_perf_cntr(counter) \
  509. ({ \
  510. unsigned int __res; \
  511. __asm__ __volatile__( \
  512. "mfpc\t%0, %1" \
  513. : "=r" (__res) \
  514. : "i" (counter)); \
  515. \
  516. __res; \
  517. })
  518. #define write_r10k_perf_cntr(counter,val) \
  519. do { \
  520. __asm__ __volatile__( \
  521. "mtpc\t%0, %1" \
  522. : \
  523. : "r" (val), "i" (counter)); \
  524. } while (0)
  525. #define read_r10k_perf_event(counter) \
  526. ({ \
  527. unsigned int __res; \
  528. __asm__ __volatile__( \
  529. "mfps\t%0, %1" \
  530. : "=r" (__res) \
  531. : "i" (counter)); \
  532. \
  533. __res; \
  534. })
  535. #define write_r10k_perf_cntl(counter,val) \
  536. do { \
  537. __asm__ __volatile__( \
  538. "mtps\t%0, %1" \
  539. : \
  540. : "r" (val), "i" (counter)); \
  541. } while (0)
  542. /*
  543. * Macros to access the system control coprocessor
  544. */
  545. #define __read_32bit_c0_register(source, sel) \
  546. ({ int __res; \
  547. if (sel == 0) \
  548. __asm__ __volatile__( \
  549. "mfc0\t%0, " #source "\n\t" \
  550. : "=r" (__res)); \
  551. else \
  552. __asm__ __volatile__( \
  553. ".set\tmips32\n\t" \
  554. "mfc0\t%0, " #source ", " #sel "\n\t" \
  555. ".set\tmips0\n\t" \
  556. : "=r" (__res)); \
  557. __res; \
  558. })
  559. #define __read_64bit_c0_register(source, sel) \
  560. ({ unsigned long long __res; \
  561. if (sizeof(unsigned long) == 4) \
  562. __res = __read_64bit_c0_split(source, sel); \
  563. else if (sel == 0) \
  564. __asm__ __volatile__( \
  565. ".set\tmips3\n\t" \
  566. "dmfc0\t%0, " #source "\n\t" \
  567. ".set\tmips0" \
  568. : "=r" (__res)); \
  569. else \
  570. __asm__ __volatile__( \
  571. ".set\tmips64\n\t" \
  572. "dmfc0\t%0, " #source ", " #sel "\n\t" \
  573. ".set\tmips0" \
  574. : "=r" (__res)); \
  575. __res; \
  576. })
  577. #define __write_32bit_c0_register(register, sel, value) \
  578. do { \
  579. if (sel == 0) \
  580. __asm__ __volatile__( \
  581. "mtc0\t%z0, " #register "\n\t" \
  582. : : "Jr" ((unsigned int)(value))); \
  583. else \
  584. __asm__ __volatile__( \
  585. ".set\tmips32\n\t" \
  586. "mtc0\t%z0, " #register ", " #sel "\n\t" \
  587. ".set\tmips0" \
  588. : : "Jr" ((unsigned int)(value))); \
  589. } while (0)
  590. #define __write_64bit_c0_register(register, sel, value) \
  591. do { \
  592. if (sizeof(unsigned long) == 4) \
  593. __write_64bit_c0_split(register, sel, value); \
  594. else if (sel == 0) \
  595. __asm__ __volatile__( \
  596. ".set\tmips3\n\t" \
  597. "dmtc0\t%z0, " #register "\n\t" \
  598. ".set\tmips0" \
  599. : : "Jr" (value)); \
  600. else \
  601. __asm__ __volatile__( \
  602. ".set\tmips64\n\t" \
  603. "dmtc0\t%z0, " #register ", " #sel "\n\t" \
  604. ".set\tmips0" \
  605. : : "Jr" (value)); \
  606. } while (0)
  607. #define __read_ulong_c0_register(reg, sel) \
  608. ((sizeof(unsigned long) == 4) ? \
  609. (unsigned long) __read_32bit_c0_register(reg, sel) : \
  610. (unsigned long) __read_64bit_c0_register(reg, sel))
  611. #define __write_ulong_c0_register(reg, sel, val) \
  612. do { \
  613. if (sizeof(unsigned long) == 4) \
  614. __write_32bit_c0_register(reg, sel, val); \
  615. else \
  616. __write_64bit_c0_register(reg, sel, val); \
  617. } while (0)
  618. /*
  619. * On RM7000/RM9000 these are uses to access cop0 set 1 registers
  620. */
  621. #define __read_32bit_c0_ctrl_register(source) \
  622. ({ int __res; \
  623. __asm__ __volatile__( \
  624. "cfc0\t%0, " #source "\n\t" \
  625. : "=r" (__res)); \
  626. __res; \
  627. })
  628. #define __write_32bit_c0_ctrl_register(register, value) \
  629. do { \
  630. __asm__ __volatile__( \
  631. "ctc0\t%z0, " #register "\n\t" \
  632. : : "Jr" ((unsigned int)(value))); \
  633. } while (0)
  634. /*
  635. * These versions are only needed for systems with more than 38 bits of
  636. * physical address space running the 32-bit kernel. That's none atm :-)
  637. */
  638. #define __read_64bit_c0_split(source, sel) \
  639. ({ \
  640. unsigned long long __val; \
  641. unsigned long __flags; \
  642. \
  643. local_irq_save(__flags); \
  644. if (sel == 0) \
  645. __asm__ __volatile__( \
  646. ".set\tmips64\n\t" \
  647. "dmfc0\t%M0, " #source "\n\t" \
  648. "dsll\t%L0, %M0, 32\n\t" \
  649. "dsrl\t%M0, %M0, 32\n\t" \
  650. "dsrl\t%L0, %L0, 32\n\t" \
  651. ".set\tmips0" \
  652. : "=r" (__val)); \
  653. else \
  654. __asm__ __volatile__( \
  655. ".set\tmips64\n\t" \
  656. "dmfc0\t%M0, " #source ", " #sel "\n\t" \
  657. "dsll\t%L0, %M0, 32\n\t" \
  658. "dsrl\t%M0, %M0, 32\n\t" \
  659. "dsrl\t%L0, %L0, 32\n\t" \
  660. ".set\tmips0" \
  661. : "=r" (__val)); \
  662. local_irq_restore(__flags); \
  663. \
  664. __val; \
  665. })
  666. #define __write_64bit_c0_split(source, sel, val) \
  667. do { \
  668. unsigned long __flags; \
  669. \
  670. local_irq_save(__flags); \
  671. if (sel == 0) \
  672. __asm__ __volatile__( \
  673. ".set\tmips64\n\t" \
  674. "dsll\t%L0, %L0, 32\n\t" \
  675. "dsrl\t%L0, %L0, 32\n\t" \
  676. "dsll\t%M0, %M0, 32\n\t" \
  677. "or\t%L0, %L0, %M0\n\t" \
  678. "dmtc0\t%L0, " #source "\n\t" \
  679. ".set\tmips0" \
  680. : : "r" (val)); \
  681. else \
  682. __asm__ __volatile__( \
  683. ".set\tmips64\n\t" \
  684. "dsll\t%L0, %L0, 32\n\t" \
  685. "dsrl\t%L0, %L0, 32\n\t" \
  686. "dsll\t%M0, %M0, 32\n\t" \
  687. "or\t%L0, %L0, %M0\n\t" \
  688. "dmtc0\t%L0, " #source ", " #sel "\n\t" \
  689. ".set\tmips0" \
  690. : : "r" (val)); \
  691. local_irq_restore(__flags); \
  692. } while (0)
  693. #define read_c0_index() __read_32bit_c0_register($0, 0)
  694. #define write_c0_index(val) __write_32bit_c0_register($0, 0, val)
  695. #define read_c0_random() __read_32bit_c0_register($1, 0)
  696. #define write_c0_random(val) __write_32bit_c0_register($1, 0, val)
  697. #define read_c0_entrylo0() __read_ulong_c0_register($2, 0)
  698. #define write_c0_entrylo0(val) __write_ulong_c0_register($2, 0, val)
  699. #define read_c0_entrylo1() __read_ulong_c0_register($3, 0)
  700. #define write_c0_entrylo1(val) __write_ulong_c0_register($3, 0, val)
  701. #define read_c0_conf() __read_32bit_c0_register($3, 0)
  702. #define write_c0_conf(val) __write_32bit_c0_register($3, 0, val)
  703. #define read_c0_context() __read_ulong_c0_register($4, 0)
  704. #define write_c0_context(val) __write_ulong_c0_register($4, 0, val)
  705. #define read_c0_userlocal() __read_ulong_c0_register($4, 2)
  706. #define write_c0_userlocal(val) __write_ulong_c0_register($4, 2, val)
  707. #define read_c0_pagemask() __read_32bit_c0_register($5, 0)
  708. #define write_c0_pagemask(val) __write_32bit_c0_register($5, 0, val)
  709. #define read_c0_wired() __read_32bit_c0_register($6, 0)
  710. #define write_c0_wired(val) __write_32bit_c0_register($6, 0, val)
  711. #define read_c0_info() __read_32bit_c0_register($7, 0)
  712. #define read_c0_cache() __read_32bit_c0_register($7, 0) /* TX39xx */
  713. #define write_c0_cache(val) __write_32bit_c0_register($7, 0, val)
  714. #define read_c0_badvaddr() __read_ulong_c0_register($8, 0)
  715. #define write_c0_badvaddr(val) __write_ulong_c0_register($8, 0, val)
  716. #define read_c0_count() __read_32bit_c0_register($9, 0)
  717. #define write_c0_count(val) __write_32bit_c0_register($9, 0, val)
  718. #define read_c0_count2() __read_32bit_c0_register($9, 6) /* pnx8550 */
  719. #define write_c0_count2(val) __write_32bit_c0_register($9, 6, val)
  720. #define read_c0_count3() __read_32bit_c0_register($9, 7) /* pnx8550 */
  721. #define write_c0_count3(val) __write_32bit_c0_register($9, 7, val)
  722. #define read_c0_entryhi() __read_ulong_c0_register($10, 0)
  723. #define write_c0_entryhi(val) __write_ulong_c0_register($10, 0, val)
  724. #define read_c0_compare() __read_32bit_c0_register($11, 0)
  725. #define write_c0_compare(val) __write_32bit_c0_register($11, 0, val)
  726. #define read_c0_compare2() __read_32bit_c0_register($11, 6) /* pnx8550 */
  727. #define write_c0_compare2(val) __write_32bit_c0_register($11, 6, val)
  728. #define read_c0_compare3() __read_32bit_c0_register($11, 7) /* pnx8550 */
  729. #define write_c0_compare3(val) __write_32bit_c0_register($11, 7, val)
  730. #define read_c0_status() __read_32bit_c0_register($12, 0)
  731. #ifdef CONFIG_MIPS_MT_SMTC
  732. #define write_c0_status(val) \
  733. do { \
  734. __write_32bit_c0_register($12, 0, val); \
  735. __ehb(); \
  736. } while (0)
  737. #else
  738. /*
  739. * Legacy non-SMTC code, which may be hazardous
  740. * but which might not support EHB
  741. */
  742. #define write_c0_status(val) __write_32bit_c0_register($12, 0, val)
  743. #endif /* CONFIG_MIPS_MT_SMTC */
  744. #define read_c0_cause() __read_32bit_c0_register($13, 0)
  745. #define write_c0_cause(val) __write_32bit_c0_register($13, 0, val)
  746. #define read_c0_epc() __read_ulong_c0_register($14, 0)
  747. #define write_c0_epc(val) __write_ulong_c0_register($14, 0, val)
  748. #define read_c0_prid() __read_32bit_c0_register($15, 0)
  749. #define read_c0_config() __read_32bit_c0_register($16, 0)
  750. #define read_c0_config1() __read_32bit_c0_register($16, 1)
  751. #define read_c0_config2() __read_32bit_c0_register($16, 2)
  752. #define read_c0_config3() __read_32bit_c0_register($16, 3)
  753. #define read_c0_config4() __read_32bit_c0_register($16, 4)
  754. #define read_c0_config5() __read_32bit_c0_register($16, 5)
  755. #define read_c0_config6() __read_32bit_c0_register($16, 6)
  756. #define read_c0_config7() __read_32bit_c0_register($16, 7)
  757. #define write_c0_config(val) __write_32bit_c0_register($16, 0, val)
  758. #define write_c0_config1(val) __write_32bit_c0_register($16, 1, val)
  759. #define write_c0_config2(val) __write_32bit_c0_register($16, 2, val)
  760. #define write_c0_config3(val) __write_32bit_c0_register($16, 3, val)
  761. #define write_c0_config4(val) __write_32bit_c0_register($16, 4, val)
  762. #define write_c0_config5(val) __write_32bit_c0_register($16, 5, val)
  763. #define write_c0_config6(val) __write_32bit_c0_register($16, 6, val)
  764. #define write_c0_config7(val) __write_32bit_c0_register($16, 7, val)
  765. /*
  766. * The WatchLo register. There may be upto 8 of them.
  767. */
  768. #define read_c0_watchlo0() __read_ulong_c0_register($18, 0)
  769. #define read_c0_watchlo1() __read_ulong_c0_register($18, 1)
  770. #define read_c0_watchlo2() __read_ulong_c0_register($18, 2)
  771. #define read_c0_watchlo3() __read_ulong_c0_register($18, 3)
  772. #define read_c0_watchlo4() __read_ulong_c0_register($18, 4)
  773. #define read_c0_watchlo5() __read_ulong_c0_register($18, 5)
  774. #define read_c0_watchlo6() __read_ulong_c0_register($18, 6)
  775. #define read_c0_watchlo7() __read_ulong_c0_register($18, 7)
  776. #define write_c0_watchlo0(val) __write_ulong_c0_register($18, 0, val)
  777. #define write_c0_watchlo1(val) __write_ulong_c0_register($18, 1, val)
  778. #define write_c0_watchlo2(val) __write_ulong_c0_register($18, 2, val)
  779. #define write_c0_watchlo3(val) __write_ulong_c0_register($18, 3, val)
  780. #define write_c0_watchlo4(val) __write_ulong_c0_register($18, 4, val)
  781. #define write_c0_watchlo5(val) __write_ulong_c0_register($18, 5, val)
  782. #define write_c0_watchlo6(val) __write_ulong_c0_register($18, 6, val)
  783. #define write_c0_watchlo7(val) __write_ulong_c0_register($18, 7, val)
  784. /*
  785. * The WatchHi register. There may be upto 8 of them.
  786. */
  787. #define read_c0_watchhi0() __read_32bit_c0_register($19, 0)
  788. #define read_c0_watchhi1() __read_32bit_c0_register($19, 1)
  789. #define read_c0_watchhi2() __read_32bit_c0_register($19, 2)
  790. #define read_c0_watchhi3() __read_32bit_c0_register($19, 3)
  791. #define read_c0_watchhi4() __read_32bit_c0_register($19, 4)
  792. #define read_c0_watchhi5() __read_32bit_c0_register($19, 5)
  793. #define read_c0_watchhi6() __read_32bit_c0_register($19, 6)
  794. #define read_c0_watchhi7() __read_32bit_c0_register($19, 7)
  795. #define write_c0_watchhi0(val) __write_32bit_c0_register($19, 0, val)
  796. #define write_c0_watchhi1(val) __write_32bit_c0_register($19, 1, val)
  797. #define write_c0_watchhi2(val) __write_32bit_c0_register($19, 2, val)
  798. #define write_c0_watchhi3(val) __write_32bit_c0_register($19, 3, val)
  799. #define write_c0_watchhi4(val) __write_32bit_c0_register($19, 4, val)
  800. #define write_c0_watchhi5(val) __write_32bit_c0_register($19, 5, val)
  801. #define write_c0_watchhi6(val) __write_32bit_c0_register($19, 6, val)
  802. #define write_c0_watchhi7(val) __write_32bit_c0_register($19, 7, val)
  803. #define read_c0_xcontext() __read_ulong_c0_register($20, 0)
  804. #define write_c0_xcontext(val) __write_ulong_c0_register($20, 0, val)
  805. #define read_c0_intcontrol() __read_32bit_c0_ctrl_register($20)
  806. #define write_c0_intcontrol(val) __write_32bit_c0_ctrl_register($20, val)
  807. #define read_c0_framemask() __read_32bit_c0_register($21, 0)
  808. #define write_c0_framemask(val) __write_32bit_c0_register($21, 0, val)
  809. /* RM9000 PerfControl performance counter control register */
  810. #define read_c0_perfcontrol() __read_32bit_c0_register($22, 0)
  811. #define write_c0_perfcontrol(val) __write_32bit_c0_register($22, 0, val)
  812. #define read_c0_diag() __read_32bit_c0_register($22, 0)
  813. #define write_c0_diag(val) __write_32bit_c0_register($22, 0, val)
  814. #define read_c0_diag1() __read_32bit_c0_register($22, 1)
  815. #define write_c0_diag1(val) __write_32bit_c0_register($22, 1, val)
  816. #define read_c0_diag2() __read_32bit_c0_register($22, 2)
  817. #define write_c0_diag2(val) __write_32bit_c0_register($22, 2, val)
  818. #define read_c0_diag3() __read_32bit_c0_register($22, 3)
  819. #define write_c0_diag3(val) __write_32bit_c0_register($22, 3, val)
  820. #define read_c0_diag4() __read_32bit_c0_register($22, 4)
  821. #define write_c0_diag4(val) __write_32bit_c0_register($22, 4, val)
  822. #define read_c0_diag5() __read_32bit_c0_register($22, 5)
  823. #define write_c0_diag5(val) __write_32bit_c0_register($22, 5, val)
  824. #define read_c0_debug() __read_32bit_c0_register($23, 0)
  825. #define write_c0_debug(val) __write_32bit_c0_register($23, 0, val)
  826. #define read_c0_depc() __read_ulong_c0_register($24, 0)
  827. #define write_c0_depc(val) __write_ulong_c0_register($24, 0, val)
  828. /*
  829. * MIPS32 / MIPS64 performance counters
  830. */
  831. #define read_c0_perfctrl0() __read_32bit_c0_register($25, 0)
  832. #define write_c0_perfctrl0(val) __write_32bit_c0_register($25, 0, val)
  833. #define read_c0_perfcntr0() __read_32bit_c0_register($25, 1)
  834. #define write_c0_perfcntr0(val) __write_32bit_c0_register($25, 1, val)
  835. #define read_c0_perfctrl1() __read_32bit_c0_register($25, 2)
  836. #define write_c0_perfctrl1(val) __write_32bit_c0_register($25, 2, val)
  837. #define read_c0_perfcntr1() __read_32bit_c0_register($25, 3)
  838. #define write_c0_perfcntr1(val) __write_32bit_c0_register($25, 3, val)
  839. #define read_c0_perfctrl2() __read_32bit_c0_register($25, 4)
  840. #define write_c0_perfctrl2(val) __write_32bit_c0_register($25, 4, val)
  841. #define read_c0_perfcntr2() __read_32bit_c0_register($25, 5)
  842. #define write_c0_perfcntr2(val) __write_32bit_c0_register($25, 5, val)
  843. #define read_c0_perfctrl3() __read_32bit_c0_register($25, 6)
  844. #define write_c0_perfctrl3(val) __write_32bit_c0_register($25, 6, val)
  845. #define read_c0_perfcntr3() __read_32bit_c0_register($25, 7)
  846. #define write_c0_perfcntr3(val) __write_32bit_c0_register($25, 7, val)
  847. /* RM9000 PerfCount performance counter register */
  848. #define read_c0_perfcount() __read_64bit_c0_register($25, 0)
  849. #define write_c0_perfcount(val) __write_64bit_c0_register($25, 0, val)
  850. #define read_c0_ecc() __read_32bit_c0_register($26, 0)
  851. #define write_c0_ecc(val) __write_32bit_c0_register($26, 0, val)
  852. #define read_c0_derraddr0() __read_ulong_c0_register($26, 1)
  853. #define write_c0_derraddr0(val) __write_ulong_c0_register($26, 1, val)
  854. #define read_c0_cacheerr() __read_32bit_c0_register($27, 0)
  855. #define read_c0_derraddr1() __read_ulong_c0_register($27, 1)
  856. #define write_c0_derraddr1(val) __write_ulong_c0_register($27, 1, val)
  857. #define read_c0_taglo() __read_32bit_c0_register($28, 0)
  858. #define write_c0_taglo(val) __write_32bit_c0_register($28, 0, val)
  859. #define read_c0_dtaglo() __read_32bit_c0_register($28, 2)
  860. #define write_c0_dtaglo(val) __write_32bit_c0_register($28, 2, val)
  861. #define read_c0_taghi() __read_32bit_c0_register($29, 0)
  862. #define write_c0_taghi(val) __write_32bit_c0_register($29, 0, val)
  863. #define read_c0_errorepc() __read_ulong_c0_register($30, 0)
  864. #define write_c0_errorepc(val) __write_ulong_c0_register($30, 0, val)
  865. /* MIPSR2 */
  866. #define read_c0_hwrena() __read_32bit_c0_register($7, 0)
  867. #define write_c0_hwrena(val) __write_32bit_c0_register($7, 0, val)
  868. #define read_c0_intctl() __read_32bit_c0_register($12, 1)
  869. #define write_c0_intctl(val) __write_32bit_c0_register($12, 1, val)
  870. #define read_c0_srsctl() __read_32bit_c0_register($12, 2)
  871. #define write_c0_srsctl(val) __write_32bit_c0_register($12, 2, val)
  872. #define read_c0_srsmap() __read_32bit_c0_register($12, 3)
  873. #define write_c0_srsmap(val) __write_32bit_c0_register($12, 3, val)
  874. #define read_c0_ebase() __read_32bit_c0_register($15, 1)
  875. #define write_c0_ebase(val) __write_32bit_c0_register($15, 1, val)
  876. /*
  877. * Macros to access the floating point coprocessor control registers
  878. */
  879. #define read_32bit_cp1_register(source) \
  880. ({ int __res; \
  881. __asm__ __volatile__( \
  882. ".set\tpush\n\t" \
  883. ".set\treorder\n\t" \
  884. "cfc1\t%0,"STR(source)"\n\t" \
  885. ".set\tpop" \
  886. : "=r" (__res)); \
  887. __res;})
  888. #define rddsp(mask) \
  889. ({ \
  890. unsigned int __res; \
  891. \
  892. __asm__ __volatile__( \
  893. " .set push \n" \
  894. " .set noat \n" \
  895. " # rddsp $1, %x1 \n" \
  896. " .word 0x7c000cb8 | (%x1 << 16) \n" \
  897. " move %0, $1 \n" \
  898. " .set pop \n" \
  899. : "=r" (__res) \
  900. : "i" (mask)); \
  901. __res; \
  902. })
  903. #define wrdsp(val, mask) \
  904. do { \
  905. __asm__ __volatile__( \
  906. " .set push \n" \
  907. " .set noat \n" \
  908. " move $1, %0 \n" \
  909. " # wrdsp $1, %x1 \n" \
  910. " .word 0x7c2004f8 | (%x1 << 11) \n" \
  911. " .set pop \n" \
  912. : \
  913. : "r" (val), "i" (mask)); \
  914. } while (0)
  915. #if 0 /* Need DSP ASE capable assembler ... */
  916. #define mflo0() ({ long mflo0; __asm__("mflo %0, $ac0" : "=r" (mflo0)); mflo0;})
  917. #define mflo1() ({ long mflo1; __asm__("mflo %0, $ac1" : "=r" (mflo1)); mflo1;})
  918. #define mflo2() ({ long mflo2; __asm__("mflo %0, $ac2" : "=r" (mflo2)); mflo2;})
  919. #define mflo3() ({ long mflo3; __asm__("mflo %0, $ac3" : "=r" (mflo3)); mflo3;})
  920. #define mfhi0() ({ long mfhi0; __asm__("mfhi %0, $ac0" : "=r" (mfhi0)); mfhi0;})
  921. #define mfhi1() ({ long mfhi1; __asm__("mfhi %0, $ac1" : "=r" (mfhi1)); mfhi1;})
  922. #define mfhi2() ({ long mfhi2; __asm__("mfhi %0, $ac2" : "=r" (mfhi2)); mfhi2;})
  923. #define mfhi3() ({ long mfhi3; __asm__("mfhi %0, $ac3" : "=r" (mfhi3)); mfhi3;})
  924. #define mtlo0(x) __asm__("mtlo %0, $ac0" ::"r" (x))
  925. #define mtlo1(x) __asm__("mtlo %0, $ac1" ::"r" (x))
  926. #define mtlo2(x) __asm__("mtlo %0, $ac2" ::"r" (x))
  927. #define mtlo3(x) __asm__("mtlo %0, $ac3" ::"r" (x))
  928. #define mthi0(x) __asm__("mthi %0, $ac0" ::"r" (x))
  929. #define mthi1(x) __asm__("mthi %0, $ac1" ::"r" (x))
  930. #define mthi2(x) __asm__("mthi %0, $ac2" ::"r" (x))
  931. #define mthi3(x) __asm__("mthi %0, $ac3" ::"r" (x))
  932. #else
  933. #define mfhi0() \
  934. ({ \
  935. unsigned long __treg; \
  936. \
  937. __asm__ __volatile__( \
  938. " .set push \n" \
  939. " .set noat \n" \
  940. " # mfhi %0, $ac0 \n" \
  941. " .word 0x00000810 \n" \
  942. " move %0, $1 \n" \
  943. " .set pop \n" \
  944. : "=r" (__treg)); \
  945. __treg; \
  946. })
  947. #define mfhi1() \
  948. ({ \
  949. unsigned long __treg; \
  950. \
  951. __asm__ __volatile__( \
  952. " .set push \n" \
  953. " .set noat \n" \
  954. " # mfhi %0, $ac1 \n" \
  955. " .word 0x00200810 \n" \
  956. " move %0, $1 \n" \
  957. " .set pop \n" \
  958. : "=r" (__treg)); \
  959. __treg; \
  960. })
  961. #define mfhi2() \
  962. ({ \
  963. unsigned long __treg; \
  964. \
  965. __asm__ __volatile__( \
  966. " .set push \n" \
  967. " .set noat \n" \
  968. " # mfhi %0, $ac2 \n" \
  969. " .word 0x00400810 \n" \
  970. " move %0, $1 \n" \
  971. " .set pop \n" \
  972. : "=r" (__treg)); \
  973. __treg; \
  974. })
  975. #define mfhi3() \
  976. ({ \
  977. unsigned long __treg; \
  978. \
  979. __asm__ __volatile__( \
  980. " .set push \n" \
  981. " .set noat \n" \
  982. " # mfhi %0, $ac3 \n" \
  983. " .word 0x00600810 \n" \
  984. " move %0, $1 \n" \
  985. " .set pop \n" \
  986. : "=r" (__treg)); \
  987. __treg; \
  988. })
  989. #define mflo0() \
  990. ({ \
  991. unsigned long __treg; \
  992. \
  993. __asm__ __volatile__( \
  994. " .set push \n" \
  995. " .set noat \n" \
  996. " # mflo %0, $ac0 \n" \
  997. " .word 0x00000812 \n" \
  998. " move %0, $1 \n" \
  999. " .set pop \n" \
  1000. : "=r" (__treg)); \
  1001. __treg; \
  1002. })
  1003. #define mflo1() \
  1004. ({ \
  1005. unsigned long __treg; \
  1006. \
  1007. __asm__ __volatile__( \
  1008. " .set push \n" \
  1009. " .set noat \n" \
  1010. " # mflo %0, $ac1 \n" \
  1011. " .word 0x00200812 \n" \
  1012. " move %0, $1 \n" \
  1013. " .set pop \n" \
  1014. : "=r" (__treg)); \
  1015. __treg; \
  1016. })
  1017. #define mflo2() \
  1018. ({ \
  1019. unsigned long __treg; \
  1020. \
  1021. __asm__ __volatile__( \
  1022. " .set push \n" \
  1023. " .set noat \n" \
  1024. " # mflo %0, $ac2 \n" \
  1025. " .word 0x00400812 \n" \
  1026. " move %0, $1 \n" \
  1027. " .set pop \n" \
  1028. : "=r" (__treg)); \
  1029. __treg; \
  1030. })
  1031. #define mflo3() \
  1032. ({ \
  1033. unsigned long __treg; \
  1034. \
  1035. __asm__ __volatile__( \
  1036. " .set push \n" \
  1037. " .set noat \n" \
  1038. " # mflo %0, $ac3 \n" \
  1039. " .word 0x00600812 \n" \
  1040. " move %0, $1 \n" \
  1041. " .set pop \n" \
  1042. : "=r" (__treg)); \
  1043. __treg; \
  1044. })
  1045. #define mthi0(x) \
  1046. do { \
  1047. __asm__ __volatile__( \
  1048. " .set push \n" \
  1049. " .set noat \n" \
  1050. " move $1, %0 \n" \
  1051. " # mthi $1, $ac0 \n" \
  1052. " .word 0x00200011 \n" \
  1053. " .set pop \n" \
  1054. : \
  1055. : "r" (x)); \
  1056. } while (0)
  1057. #define mthi1(x) \
  1058. do { \
  1059. __asm__ __volatile__( \
  1060. " .set push \n" \
  1061. " .set noat \n" \
  1062. " move $1, %0 \n" \
  1063. " # mthi $1, $ac1 \n" \
  1064. " .word 0x00200811 \n" \
  1065. " .set pop \n" \
  1066. : \
  1067. : "r" (x)); \
  1068. } while (0)
  1069. #define mthi2(x) \
  1070. do { \
  1071. __asm__ __volatile__( \
  1072. " .set push \n" \
  1073. " .set noat \n" \
  1074. " move $1, %0 \n" \
  1075. " # mthi $1, $ac2 \n" \
  1076. " .word 0x00201011 \n" \
  1077. " .set pop \n" \
  1078. : \
  1079. : "r" (x)); \
  1080. } while (0)
  1081. #define mthi3(x) \
  1082. do { \
  1083. __asm__ __volatile__( \
  1084. " .set push \n" \
  1085. " .set noat \n" \
  1086. " move $1, %0 \n" \
  1087. " # mthi $1, $ac3 \n" \
  1088. " .word 0x00201811 \n" \
  1089. " .set pop \n" \
  1090. : \
  1091. : "r" (x)); \
  1092. } while (0)
  1093. #define mtlo0(x) \
  1094. do { \
  1095. __asm__ __volatile__( \
  1096. " .set push \n" \
  1097. " .set noat \n" \
  1098. " move $1, %0 \n" \
  1099. " # mtlo $1, $ac0 \n" \
  1100. " .word 0x00200013 \n" \
  1101. " .set pop \n" \
  1102. : \
  1103. : "r" (x)); \
  1104. } while (0)
  1105. #define mtlo1(x) \
  1106. do { \
  1107. __asm__ __volatile__( \
  1108. " .set push \n" \
  1109. " .set noat \n" \
  1110. " move $1, %0 \n" \
  1111. " # mtlo $1, $ac1 \n" \
  1112. " .word 0x00200813 \n" \
  1113. " .set pop \n" \
  1114. : \
  1115. : "r" (x)); \
  1116. } while (0)
  1117. #define mtlo2(x) \
  1118. do { \
  1119. __asm__ __volatile__( \
  1120. " .set push \n" \
  1121. " .set noat \n" \
  1122. " move $1, %0 \n" \
  1123. " # mtlo $1, $ac2 \n" \
  1124. " .word 0x00201013 \n" \
  1125. " .set pop \n" \
  1126. : \
  1127. : "r" (x)); \
  1128. } while (0)
  1129. #define mtlo3(x) \
  1130. do { \
  1131. __asm__ __volatile__( \
  1132. " .set push \n" \
  1133. " .set noat \n" \
  1134. " move $1, %0 \n" \
  1135. " # mtlo $1, $ac3 \n" \
  1136. " .word 0x00201813 \n" \
  1137. " .set pop \n" \
  1138. : \
  1139. : "r" (x)); \
  1140. } while (0)
  1141. #endif
  1142. /*
  1143. * TLB operations.
  1144. *
  1145. * It is responsibility of the caller to take care of any TLB hazards.
  1146. */
  1147. static inline void tlb_probe(void)
  1148. {
  1149. __asm__ __volatile__(
  1150. ".set noreorder\n\t"
  1151. "tlbp\n\t"
  1152. ".set reorder");
  1153. }
  1154. static inline void tlb_read(void)
  1155. {
  1156. #if MIPS34K_MISSED_ITLB_WAR
  1157. int res = 0;
  1158. __asm__ __volatile__(
  1159. " .set push \n"
  1160. " .set noreorder \n"
  1161. " .set noat \n"
  1162. " .set mips32r2 \n"
  1163. " .word 0x41610001 # dvpe $1 \n"
  1164. " move %0, $1 \n"
  1165. " ehb \n"
  1166. " .set pop \n"
  1167. : "=r" (res));
  1168. instruction_hazard();
  1169. #endif
  1170. __asm__ __volatile__(
  1171. ".set noreorder\n\t"
  1172. "tlbr\n\t"
  1173. ".set reorder");
  1174. #if MIPS34K_MISSED_ITLB_WAR
  1175. if ((res & _ULCAST_(1)))
  1176. __asm__ __volatile__(
  1177. " .set push \n"
  1178. " .set noreorder \n"
  1179. " .set noat \n"
  1180. " .set mips32r2 \n"
  1181. " .word 0x41600021 # evpe \n"
  1182. " ehb \n"
  1183. " .set pop \n");
  1184. #endif
  1185. }
  1186. static inline void tlb_write_indexed(void)
  1187. {
  1188. __asm__ __volatile__(
  1189. ".set noreorder\n\t"
  1190. "tlbwi\n\t"
  1191. ".set reorder");
  1192. }
  1193. static inline void tlb_write_random(void)
  1194. {
  1195. __asm__ __volatile__(
  1196. ".set noreorder\n\t"
  1197. "tlbwr\n\t"
  1198. ".set reorder");
  1199. }
  1200. /*
  1201. * Manipulate bits in a c0 register.
  1202. */
  1203. #ifndef CONFIG_MIPS_MT_SMTC
  1204. /*
  1205. * SMTC Linux requires shutting-down microthread scheduling
  1206. * during CP0 register read-modify-write sequences.
  1207. */
  1208. #define __BUILD_SET_C0(name) \
  1209. static inline unsigned int \
  1210. set_c0_##name(unsigned int set) \
  1211. { \
  1212. unsigned int res; \
  1213. \
  1214. res = read_c0_##name(); \
  1215. res |= set; \
  1216. write_c0_##name(res); \
  1217. \
  1218. return res; \
  1219. } \
  1220. \
  1221. static inline unsigned int \
  1222. clear_c0_##name(unsigned int clear) \
  1223. { \
  1224. unsigned int res; \
  1225. \
  1226. res = read_c0_##name(); \
  1227. res &= ~clear; \
  1228. write_c0_##name(res); \
  1229. \
  1230. return res; \
  1231. } \
  1232. \
  1233. static inline unsigned int \
  1234. change_c0_##name(unsigned int change, unsigned int new) \
  1235. { \
  1236. unsigned int res; \
  1237. \
  1238. res = read_c0_##name(); \
  1239. res &= ~change; \
  1240. res |= (new & change); \
  1241. write_c0_##name(res); \
  1242. \
  1243. return res; \
  1244. }
  1245. #else /* SMTC versions that manage MT scheduling */
  1246. #include <linux/irqflags.h>
  1247. /*
  1248. * This is a duplicate of dmt() in mipsmtregs.h to avoid problems with
  1249. * header file recursion.
  1250. */
  1251. static inline unsigned int __dmt(void)
  1252. {
  1253. int res;
  1254. __asm__ __volatile__(
  1255. " .set push \n"
  1256. " .set mips32r2 \n"
  1257. " .set noat \n"
  1258. " .word 0x41610BC1 # dmt $1 \n"
  1259. " ehb \n"
  1260. " move %0, $1 \n"
  1261. " .set pop \n"
  1262. : "=r" (res));
  1263. instruction_hazard();
  1264. return res;
  1265. }
  1266. #define __VPECONTROL_TE_SHIFT 15
  1267. #define __VPECONTROL_TE (1UL << __VPECONTROL_TE_SHIFT)
  1268. #define __EMT_ENABLE __VPECONTROL_TE
  1269. static inline void __emt(unsigned int previous)
  1270. {
  1271. if ((previous & __EMT_ENABLE))
  1272. __asm__ __volatile__(
  1273. " .set mips32r2 \n"
  1274. " .word 0x41600be1 # emt \n"
  1275. " ehb \n"
  1276. " .set mips0 \n");
  1277. }
  1278. static inline void __ehb(void)
  1279. {
  1280. __asm__ __volatile__(
  1281. " .set mips32r2 \n"
  1282. " ehb \n" " .set mips0 \n");
  1283. }
  1284. /*
  1285. * Note that local_irq_save/restore affect TC-specific IXMT state,
  1286. * not Status.IE as in non-SMTC kernel.
  1287. */
  1288. #define __BUILD_SET_C0(name) \
  1289. static inline unsigned int \
  1290. set_c0_##name(unsigned int set) \
  1291. { \
  1292. unsigned int res; \
  1293. unsigned int omt; \
  1294. unsigned long flags; \
  1295. \
  1296. local_irq_save(flags); \
  1297. omt = __dmt(); \
  1298. res = read_c0_##name(); \
  1299. res |= set; \
  1300. write_c0_##name(res); \
  1301. __emt(omt); \
  1302. local_irq_restore(flags); \
  1303. \
  1304. return res; \
  1305. } \
  1306. \
  1307. static inline unsigned int \
  1308. clear_c0_##name(unsigned int clear) \
  1309. { \
  1310. unsigned int res; \
  1311. unsigned int omt; \
  1312. unsigned long flags; \
  1313. \
  1314. local_irq_save(flags); \
  1315. omt = __dmt(); \
  1316. res = read_c0_##name(); \
  1317. res &= ~clear; \
  1318. write_c0_##name(res); \
  1319. __emt(omt); \
  1320. local_irq_restore(flags); \
  1321. \
  1322. return res; \
  1323. } \
  1324. \
  1325. static inline unsigned int \
  1326. change_c0_##name(unsigned int change, unsigned int new) \
  1327. { \
  1328. unsigned int res; \
  1329. unsigned int omt; \
  1330. unsigned long flags; \
  1331. \
  1332. local_irq_save(flags); \
  1333. \
  1334. omt = __dmt(); \
  1335. res = read_c0_##name(); \
  1336. res &= ~change; \
  1337. res |= (new & change); \
  1338. write_c0_##name(res); \
  1339. __emt(omt); \
  1340. local_irq_restore(flags); \
  1341. \
  1342. return res; \
  1343. }
  1344. #endif
  1345. __BUILD_SET_C0(status)
  1346. __BUILD_SET_C0(cause)
  1347. __BUILD_SET_C0(config)
  1348. __BUILD_SET_C0(intcontrol)
  1349. __BUILD_SET_C0(intctl)
  1350. __BUILD_SET_C0(srsmap)
  1351. #endif /* !__ASSEMBLY__ */
  1352. #endif /* _ASM_MIPSREGS_H */