mipsmtregs.h 9.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  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. extern void mips_mt_regdump(void);
  135. static inline unsigned int dvpe(void)
  136. {
  137. int res = 0;
  138. __asm__ __volatile__(
  139. " .set push \n"
  140. " .set noreorder \n"
  141. " .set noat \n"
  142. " .set mips32r2 \n"
  143. " .word 0x41610001 # dvpe $1 \n"
  144. " move %0, $1 \n"
  145. " ehb \n"
  146. " .set pop \n"
  147. : "=r" (res));
  148. instruction_hazard();
  149. return res;
  150. }
  151. static inline void __raw_evpe(void)
  152. {
  153. __asm__ __volatile__(
  154. " .set push \n"
  155. " .set noreorder \n"
  156. " .set noat \n"
  157. " .set mips32r2 \n"
  158. " .word 0x41600021 # evpe \n"
  159. " ehb \n"
  160. " .set pop \n");
  161. }
  162. /* Enable multiMT if previous suggested it should be.
  163. EMT_ENABLE to force */
  164. #define EVPE_ENABLE MVPCONTROL_EVP
  165. static inline void evpe(int previous)
  166. {
  167. if ((previous & MVPCONTROL_EVP))
  168. __raw_evpe();
  169. }
  170. static inline unsigned int dmt(void)
  171. {
  172. int res;
  173. __asm__ __volatile__(
  174. " .set push \n"
  175. " .set mips32r2 \n"
  176. " .set noat \n"
  177. " .word 0x41610BC1 # dmt $1 \n"
  178. " ehb \n"
  179. " move %0, $1 \n"
  180. " .set pop \n"
  181. : "=r" (res));
  182. instruction_hazard();
  183. return res;
  184. }
  185. static inline void __raw_emt(void)
  186. {
  187. __asm__ __volatile__(
  188. " .set noreorder \n"
  189. " .set mips32r2 \n"
  190. " emt \n"
  191. " ehb \n"
  192. " .set mips0 \n"
  193. " .set reorder");
  194. }
  195. /* enable multiVPE if previous suggested it should be.
  196. EVPE_ENABLE to force */
  197. #define EMT_ENABLE VPECONTROL_TE
  198. static inline void emt(int previous)
  199. {
  200. if ((previous & EMT_ENABLE))
  201. __raw_emt();
  202. }
  203. static inline void ehb(void)
  204. {
  205. __asm__ __volatile__(
  206. " .set mips32r2 \n"
  207. " ehb \n"
  208. " .set mips0 \n");
  209. }
  210. #define mftc0(rt,sel) \
  211. ({ \
  212. unsigned long __res; \
  213. \
  214. __asm__ __volatile__( \
  215. " .set push \n" \
  216. " .set mips32r2 \n" \
  217. " .set noat \n" \
  218. " # mftc0 $1, $" #rt ", " #sel " \n" \
  219. " .word 0x41000800 | (" #rt " << 16) | " #sel " \n" \
  220. " move %0, $1 \n" \
  221. " .set pop \n" \
  222. : "=r" (__res)); \
  223. \
  224. __res; \
  225. })
  226. #define mftgpr(rt) \
  227. ({ \
  228. unsigned long __res; \
  229. \
  230. __asm__ __volatile__( \
  231. " .set push \n" \
  232. " .set mips32r2 \n" \
  233. " mftgpr %0," #rt " \n" \
  234. " .set pop \n" \
  235. : "=r" (__res)); \
  236. \
  237. __res; \
  238. })
  239. #define mftr(rt,u,sel) \
  240. ({ \
  241. unsigned long __res; \
  242. \
  243. __asm__ __volatile__( \
  244. ".set noat\n\t" \
  245. "mftr\t%0, " #rt ", " #u ", " #sel "\n\t" \
  246. ".set at\n\t" \
  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_status() mftc0(12, 0)
  293. #define write_vpe_c0_status(val) mttc0(12, 0, val)
  294. #define read_vpe_c0_cause() mftc0(13, 0)
  295. #define write_vpe_c0_cause(val) mttc0(13, 0, val)
  296. #define read_vpe_c0_config() mftc0(16, 0)
  297. #define write_vpe_c0_config(val) mttc0(16, 0, val)
  298. #define read_vpe_c0_config1() mftc0(16, 1)
  299. #define write_vpe_c0_config1(val) mttc0(16, 1, val)
  300. #define read_vpe_c0_config7() mftc0(16, 7)
  301. #define write_vpe_c0_config7(val) mttc0(16, 7, val)
  302. #define read_vpe_c0_ebase() mftc0(15,1)
  303. #define write_vpe_c0_ebase(val) mttc0(15, 1, val)
  304. #define write_vpe_c0_compare(val) mttc0(11, 0, val)
  305. /* TC */
  306. #define read_tc_c0_tcstatus() mftc0(2, 1)
  307. #define write_tc_c0_tcstatus(val) mttc0(2,1,val)
  308. #define read_tc_c0_tcbind() mftc0(2, 2)
  309. #define write_tc_c0_tcbind(val) mttc0(2,2,val)
  310. #define read_tc_c0_tcrestart() mftc0(2, 3)
  311. #define write_tc_c0_tcrestart(val) mttc0(2,3,val)
  312. #define read_tc_c0_tchalt() mftc0(2, 4)
  313. #define write_tc_c0_tchalt(val) mttc0(2,4,val)
  314. #define read_tc_c0_tccontext() mftc0(2, 5)
  315. #define write_tc_c0_tccontext(val) mttc0(2,5,val)
  316. /* GPR */
  317. #define read_tc_gpr_sp() mftgpr(29)
  318. #define write_tc_gpr_sp(val) mttgpr(29, val)
  319. #define read_tc_gpr_gp() mftgpr(28)
  320. #define write_tc_gpr_gp(val) mttgpr(28, val)
  321. __BUILD_SET_C0(mvpcontrol)
  322. #endif /* Not __ASSEMBLY__ */
  323. #endif