mipsmtregs.h 11 KB

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