mipsregs.h 45 KB

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