mipsmtregs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396
  1. /*
  2. * MT regs definitions, follows on from mipsregs.h
  3. * Copyright (C) 2004 - 2005 MIPS Technologies, Inc. All rights reserved.
  4. * Elizabeth Clarke et. al.
  5. *
  6. */
  7. #ifndef _ASM_MIPSMTREGS_H
  8. #define _ASM_MIPSMTREGS_H
  9. #include <asm/mipsregs.h>
  10. #include <asm/war.h>
  11. #ifndef __ASSEMBLY__
  12. /*
  13. * C macros
  14. */
  15. #define read_c0_mvpcontrol() __read_32bit_c0_register($0, 1)
  16. #define write_c0_mvpcontrol(val) __write_32bit_c0_register($0, 1, val)
  17. #define read_c0_mvpconf0() __read_32bit_c0_register($0, 2)
  18. #define read_c0_mvpconf1() __read_32bit_c0_register($0, 3)
  19. #define read_c0_vpecontrol() __read_32bit_c0_register($1, 1)
  20. #define write_c0_vpecontrol(val) __write_32bit_c0_register($1, 1, val)
  21. #define read_c0_vpeconf0() __read_32bit_c0_register($1, 2)
  22. #define write_c0_vpeconf0(val) __write_32bit_c0_register($1, 2, val)
  23. #define read_c0_tcstatus() __read_32bit_c0_register($2, 1)
  24. #define write_c0_tcstatus(val) __write_32bit_c0_register($2, 1, val)
  25. #define read_c0_tcbind() __read_32bit_c0_register($2, 2)
  26. #define read_c0_tccontext() __read_32bit_c0_register($2, 5)
  27. #define write_c0_tccontext(val) __write_32bit_c0_register($2, 5, val)
  28. #else /* Assembly */
  29. /*
  30. * Macros for use in assembly language code
  31. */
  32. #define CP0_MVPCONTROL $0, 1
  33. #define CP0_MVPCONF0 $0, 2
  34. #define CP0_MVPCONF1 $0, 3
  35. #define CP0_VPECONTROL $1, 1
  36. #define CP0_VPECONF0 $1, 2
  37. #define CP0_VPECONF1 $1, 3
  38. #define CP0_YQMASK $1, 4
  39. #define CP0_VPESCHEDULE $1, 5
  40. #define CP0_VPESCHEFBK $1, 6
  41. #define CP0_TCSTATUS $2, 1
  42. #define CP0_TCBIND $2, 2
  43. #define CP0_TCRESTART $2, 3
  44. #define CP0_TCHALT $2, 4
  45. #define CP0_TCCONTEXT $2, 5
  46. #define CP0_TCSCHEDULE $2, 6
  47. #define CP0_TCSCHEFBK $2, 7
  48. #define CP0_SRSCONF0 $6, 1
  49. #define CP0_SRSCONF1 $6, 2
  50. #define CP0_SRSCONF2 $6, 3
  51. #define CP0_SRSCONF3 $6, 4
  52. #define CP0_SRSCONF4 $6, 5
  53. #endif
  54. /* MVPControl fields */
  55. #define MVPCONTROL_EVP (_ULCAST_(1))
  56. #define MVPCONTROL_VPC_SHIFT 1
  57. #define MVPCONTROL_VPC (_ULCAST_(1) << MVPCONTROL_VPC_SHIFT)
  58. #define MVPCONTROL_STLB_SHIFT 2
  59. #define MVPCONTROL_STLB (_ULCAST_(1) << MVPCONTROL_STLB_SHIFT)
  60. /* MVPConf0 fields */
  61. #define MVPCONF0_PTC_SHIFT 0
  62. #define MVPCONF0_PTC ( _ULCAST_(0xff))
  63. #define MVPCONF0_PVPE_SHIFT 10
  64. #define MVPCONF0_PVPE ( _ULCAST_(0xf) << MVPCONF0_PVPE_SHIFT)
  65. #define MVPCONF0_TCA_SHIFT 15
  66. #define MVPCONF0_TCA ( _ULCAST_(1) << MVPCONF0_TCA_SHIFT)
  67. #define MVPCONF0_PTLBE_SHIFT 16
  68. #define MVPCONF0_PTLBE (_ULCAST_(0x3ff) << MVPCONF0_PTLBE_SHIFT)
  69. #define MVPCONF0_TLBS_SHIFT 29
  70. #define MVPCONF0_TLBS (_ULCAST_(1) << MVPCONF0_TLBS_SHIFT)
  71. #define MVPCONF0_M_SHIFT 31
  72. #define MVPCONF0_M (_ULCAST_(0x1) << MVPCONF0_M_SHIFT)
  73. /* config3 fields */
  74. #define CONFIG3_MT_SHIFT 2
  75. #define CONFIG3_MT (_ULCAST_(1) << CONFIG3_MT_SHIFT)
  76. /* VPEControl fields (per VPE) */
  77. #define VPECONTROL_TARGTC (_ULCAST_(0xff))
  78. #define VPECONTROL_TE_SHIFT 15
  79. #define VPECONTROL_TE (_ULCAST_(1) << VPECONTROL_TE_SHIFT)
  80. #define VPECONTROL_EXCPT_SHIFT 16
  81. #define VPECONTROL_EXCPT (_ULCAST_(0x7) << VPECONTROL_EXCPT_SHIFT)
  82. /* Thread Exception Codes for EXCPT field */
  83. #define THREX_TU 0
  84. #define THREX_TO 1
  85. #define THREX_IYQ 2
  86. #define THREX_GSX 3
  87. #define THREX_YSCH 4
  88. #define THREX_GSSCH 5
  89. #define VPECONTROL_GSI_SHIFT 20
  90. #define VPECONTROL_GSI (_ULCAST_(1) << VPECONTROL_GSI_SHIFT)
  91. #define VPECONTROL_YSI_SHIFT 21
  92. #define VPECONTROL_YSI (_ULCAST_(1) << VPECONTROL_YSI_SHIFT)
  93. /* VPEConf0 fields (per VPE) */
  94. #define VPECONF0_VPA_SHIFT 0
  95. #define VPECONF0_VPA (_ULCAST_(1) << VPECONF0_VPA_SHIFT)
  96. #define VPECONF0_MVP_SHIFT 1
  97. #define VPECONF0_MVP (_ULCAST_(1) << VPECONF0_MVP_SHIFT)
  98. #define VPECONF0_XTC_SHIFT 21
  99. #define VPECONF0_XTC (_ULCAST_(0xff) << VPECONF0_XTC_SHIFT)
  100. /* TCStatus fields (per TC) */
  101. #define TCSTATUS_TASID (_ULCAST_(0xff))
  102. #define TCSTATUS_IXMT_SHIFT 10
  103. #define TCSTATUS_IXMT (_ULCAST_(1) << TCSTATUS_IXMT_SHIFT)
  104. #define TCSTATUS_TKSU_SHIFT 11
  105. #define TCSTATUS_TKSU (_ULCAST_(3) << TCSTATUS_TKSU_SHIFT)
  106. #define TCSTATUS_A_SHIFT 13
  107. #define TCSTATUS_A (_ULCAST_(1) << TCSTATUS_A_SHIFT)
  108. #define TCSTATUS_DA_SHIFT 15
  109. #define TCSTATUS_DA (_ULCAST_(1) << TCSTATUS_DA_SHIFT)
  110. #define TCSTATUS_DT_SHIFT 20
  111. #define TCSTATUS_DT (_ULCAST_(1) << TCSTATUS_DT_SHIFT)
  112. #define TCSTATUS_TDS_SHIFT 21
  113. #define TCSTATUS_TDS (_ULCAST_(1) << TCSTATUS_TDS_SHIFT)
  114. #define TCSTATUS_TSST_SHIFT 22
  115. #define TCSTATUS_TSST (_ULCAST_(1) << TCSTATUS_TSST_SHIFT)
  116. #define TCSTATUS_RNST_SHIFT 23
  117. #define TCSTATUS_RNST (_ULCAST_(3) << TCSTATUS_RNST_SHIFT)
  118. /* Codes for RNST */
  119. #define TC_RUNNING 0
  120. #define TC_WAITING 1
  121. #define TC_YIELDING 2
  122. #define TC_GATED 3
  123. #define TCSTATUS_TMX_SHIFT 27
  124. #define TCSTATUS_TMX (_ULCAST_(1) << TCSTATUS_TMX_SHIFT)
  125. /* TCStatus TCU bits can use same definitions/offsets as CU bits in Status */
  126. /* TCBind */
  127. #define TCBIND_CURVPE_SHIFT 0
  128. #define TCBIND_CURVPE (_ULCAST_(0xf))
  129. #define TCBIND_CURTC_SHIFT 21
  130. #define TCBIND_CURTC (_ULCAST_(0xff) << TCBIND_CURTC_SHIFT)
  131. /* TCHalt */
  132. #define TCHALT_H (_ULCAST_(1))
  133. #ifndef __ASSEMBLY__
  134. static inline unsigned int dvpe(void)
  135. {
  136. int res = 0;
  137. __asm__ __volatile__(
  138. " .set push \n"
  139. " .set noreorder \n"
  140. " .set noat \n"
  141. " .set mips32r2 \n"
  142. " .word 0x41610001 # dvpe $1 \n"
  143. " move %0, $1 \n"
  144. " ehb \n"
  145. " .set pop \n"
  146. : "=r" (res));
  147. instruction_hazard();
  148. return res;
  149. }
  150. static inline void __raw_evpe(void)
  151. {
  152. __asm__ __volatile__(
  153. " .set push \n"
  154. " .set noreorder \n"
  155. " .set noat \n"
  156. " .set mips32r2 \n"
  157. " .word 0x41600021 # evpe \n"
  158. " ehb \n"
  159. " .set pop \n");
  160. }
  161. /* Enable virtual processor execution if previous suggested it should be.
  162. EVPE_ENABLE to force */
  163. #define EVPE_ENABLE MVPCONTROL_EVP
  164. static inline void evpe(int previous)
  165. {
  166. if ((previous & MVPCONTROL_EVP))
  167. __raw_evpe();
  168. }
  169. static inline unsigned int dmt(void)
  170. {
  171. int res;
  172. __asm__ __volatile__(
  173. " .set push \n"
  174. " .set mips32r2 \n"
  175. " .set noat \n"
  176. " .word 0x41610BC1 # dmt $1 \n"
  177. " ehb \n"
  178. " move %0, $1 \n"
  179. " .set pop \n"
  180. : "=r" (res));
  181. instruction_hazard();
  182. return res;
  183. }
  184. static inline void __raw_emt(void)
  185. {
  186. __asm__ __volatile__(
  187. " .set noreorder \n"
  188. " .set mips32r2 \n"
  189. " .word 0x41600be1 # emt \n"
  190. " ehb \n"
  191. " .set mips0 \n"
  192. " .set reorder");
  193. }
  194. /* enable multi-threaded execution if previous suggested it should be.
  195. EMT_ENABLE to force */
  196. #define EMT_ENABLE VPECONTROL_TE
  197. static inline void emt(int previous)
  198. {
  199. if ((previous & EMT_ENABLE))
  200. __raw_emt();
  201. }
  202. static inline void ehb(void)
  203. {
  204. __asm__ __volatile__(
  205. " .set mips32r2 \n"
  206. " ehb \n"
  207. " .set mips0 \n");
  208. }
  209. #define mftc0(rt,sel) \
  210. ({ \
  211. unsigned long __res; \
  212. \
  213. __asm__ __volatile__( \
  214. " .set push \n" \
  215. " .set mips32r2 \n" \
  216. " .set noat \n" \
  217. " # mftc0 $1, $" #rt ", " #sel " \n" \
  218. " .word 0x41000800 | (" #rt " << 16) | " #sel " \n" \
  219. " move %0, $1 \n" \
  220. " .set pop \n" \
  221. : "=r" (__res)); \
  222. \
  223. __res; \
  224. })
  225. #define mftgpr(rt) \
  226. ({ \
  227. unsigned long __res; \
  228. \
  229. __asm__ __volatile__( \
  230. " .set push \n" \
  231. " .set noat \n" \
  232. " .set mips32r2 \n" \
  233. " # mftgpr $1," #rt " \n" \
  234. " .word 0x41000820 | (" #rt " << 16) \n" \
  235. " move %0, $1 \n" \
  236. " .set pop \n" \
  237. : "=r" (__res)); \
  238. \
  239. __res; \
  240. })
  241. #define mftr(rt, u, sel) \
  242. ({ \
  243. unsigned long __res; \
  244. \
  245. __asm__ __volatile__( \
  246. " mftr %0, " #rt ", " #u ", " #sel " \n" \
  247. : "=r" (__res)); \
  248. \
  249. __res; \
  250. })
  251. #define mttgpr(rd,v) \
  252. do { \
  253. __asm__ __volatile__( \
  254. " .set push \n" \
  255. " .set mips32r2 \n" \
  256. " .set noat \n" \
  257. " move $1, %0 \n" \
  258. " # mttgpr $1, " #rd " \n" \
  259. " .word 0x41810020 | (" #rd " << 11) \n" \
  260. " .set pop \n" \
  261. : : "r" (v)); \
  262. } while (0)
  263. #define mttc0(rd, sel, v) \
  264. ({ \
  265. __asm__ __volatile__( \
  266. " .set push \n" \
  267. " .set mips32r2 \n" \
  268. " .set noat \n" \
  269. " move $1, %0 \n" \
  270. " # mttc0 %0," #rd ", " #sel " \n" \
  271. " .word 0x41810000 | (" #rd " << 11) | " #sel " \n" \
  272. " .set pop \n" \
  273. : \
  274. : "r" (v)); \
  275. })
  276. #define mttr(rd, u, sel, v) \
  277. ({ \
  278. __asm__ __volatile__( \
  279. "mttr %0," #rd ", " #u ", " #sel \
  280. : : "r" (v)); \
  281. })
  282. #define settc(tc) \
  283. do { \
  284. write_c0_vpecontrol((read_c0_vpecontrol()&~VPECONTROL_TARGTC) | (tc)); \
  285. ehb(); \
  286. } while (0)
  287. /* you *must* set the target tc (settc) before trying to use these */
  288. #define read_vpe_c0_vpecontrol() mftc0(1, 1)
  289. #define write_vpe_c0_vpecontrol(val) mttc0(1, 1, val)
  290. #define read_vpe_c0_vpeconf0() mftc0(1, 2)
  291. #define write_vpe_c0_vpeconf0(val) mttc0(1, 2, val)
  292. #define read_vpe_c0_count() mftc0(9, 0)
  293. #define write_vpe_c0_count(val) mttc0(9, 0, val)
  294. #define read_vpe_c0_status() mftc0(12, 0)
  295. #define write_vpe_c0_status(val) mttc0(12, 0, val)
  296. #define read_vpe_c0_cause() mftc0(13, 0)
  297. #define write_vpe_c0_cause(val) mttc0(13, 0, val)
  298. #define read_vpe_c0_config() mftc0(16, 0)
  299. #define write_vpe_c0_config(val) mttc0(16, 0, val)
  300. #define read_vpe_c0_config1() mftc0(16, 1)
  301. #define write_vpe_c0_config1(val) mttc0(16, 1, val)
  302. #define read_vpe_c0_config7() mftc0(16, 7)
  303. #define write_vpe_c0_config7(val) mttc0(16, 7, val)
  304. #define read_vpe_c0_ebase() mftc0(15, 1)
  305. #define write_vpe_c0_ebase(val) mttc0(15, 1, val)
  306. #define write_vpe_c0_compare(val) mttc0(11, 0, val)
  307. #define read_vpe_c0_badvaddr() mftc0(8, 0)
  308. #define read_vpe_c0_epc() mftc0(14, 0)
  309. #define write_vpe_c0_epc(val) mttc0(14, 0, val)
  310. /* TC */
  311. #define read_tc_c0_tcstatus() mftc0(2, 1)
  312. #define write_tc_c0_tcstatus(val) mttc0(2, 1, val)
  313. #define read_tc_c0_tcbind() mftc0(2, 2)
  314. #define write_tc_c0_tcbind(val) mttc0(2, 2, val)
  315. #define read_tc_c0_tcrestart() mftc0(2, 3)
  316. #define write_tc_c0_tcrestart(val) mttc0(2, 3, val)
  317. #define read_tc_c0_tchalt() mftc0(2, 4)
  318. #define write_tc_c0_tchalt(val) mttc0(2, 4, val)
  319. #define read_tc_c0_tccontext() mftc0(2, 5)
  320. #define write_tc_c0_tccontext(val) mttc0(2, 5, val)
  321. /* GPR */
  322. #define read_tc_gpr_sp() mftgpr(29)
  323. #define write_tc_gpr_sp(val) mttgpr(29, val)
  324. #define read_tc_gpr_gp() mftgpr(28)
  325. #define write_tc_gpr_gp(val) mttgpr(28, val)
  326. __BUILD_SET_C0(mvpcontrol)
  327. #endif /* Not __ASSEMBLY__ */
  328. #endif