mipsmtregs.h 11 KB

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