mipsregs.h 44 KB

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