msa.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307
  1. /*
  2. * Copyright (C) 2013 Imagination Technologies
  3. * Author: Paul Burton <paul.burton@imgtec.com>
  4. *
  5. * This program is free software; you can redistribute it and/or modify it
  6. * under the terms of the GNU General Public License as published by the
  7. * Free Software Foundation; either version 2 of the License, or (at your
  8. * option) any later version.
  9. */
  10. #ifndef _ASM_MSA_H
  11. #define _ASM_MSA_H
  12. #include <asm/mipsregs.h>
  13. #ifndef __ASSEMBLY__
  14. #include <asm/inst.h>
  15. extern void _save_msa(struct task_struct *);
  16. extern void _restore_msa(struct task_struct *);
  17. extern void _init_msa_upper(void);
  18. extern void read_msa_wr_b(unsigned idx, union fpureg *to);
  19. extern void read_msa_wr_h(unsigned idx, union fpureg *to);
  20. extern void read_msa_wr_w(unsigned idx, union fpureg *to);
  21. extern void read_msa_wr_d(unsigned idx, union fpureg *to);
  22. /**
  23. * read_msa_wr() - Read a single MSA vector register
  24. * @idx: The index of the vector register to read
  25. * @to: The FPU register union to store the registers value in
  26. * @fmt: The format of the data in the vector register
  27. *
  28. * Read the value of MSA vector register idx into the FPU register
  29. * union to, using the format fmt.
  30. */
  31. static inline void read_msa_wr(unsigned idx, union fpureg *to,
  32. enum msa_2b_fmt fmt)
  33. {
  34. switch (fmt) {
  35. case msa_fmt_b:
  36. read_msa_wr_b(idx, to);
  37. break;
  38. case msa_fmt_h:
  39. read_msa_wr_h(idx, to);
  40. break;
  41. case msa_fmt_w:
  42. read_msa_wr_w(idx, to);
  43. break;
  44. case msa_fmt_d:
  45. read_msa_wr_d(idx, to);
  46. break;
  47. default:
  48. BUG();
  49. }
  50. }
  51. extern void write_msa_wr_b(unsigned idx, union fpureg *from);
  52. extern void write_msa_wr_h(unsigned idx, union fpureg *from);
  53. extern void write_msa_wr_w(unsigned idx, union fpureg *from);
  54. extern void write_msa_wr_d(unsigned idx, union fpureg *from);
  55. /**
  56. * write_msa_wr() - Write a single MSA vector register
  57. * @idx: The index of the vector register to write
  58. * @from: The FPU register union to take the registers value from
  59. * @fmt: The format of the data in the vector register
  60. *
  61. * Write the value from the FPU register union from into MSA vector
  62. * register idx, using the format fmt.
  63. */
  64. static inline void write_msa_wr(unsigned idx, union fpureg *from,
  65. enum msa_2b_fmt fmt)
  66. {
  67. switch (fmt) {
  68. case msa_fmt_b:
  69. write_msa_wr_b(idx, from);
  70. break;
  71. case msa_fmt_h:
  72. write_msa_wr_h(idx, from);
  73. break;
  74. case msa_fmt_w:
  75. write_msa_wr_w(idx, from);
  76. break;
  77. case msa_fmt_d:
  78. write_msa_wr_d(idx, from);
  79. break;
  80. default:
  81. BUG();
  82. }
  83. }
  84. static inline void enable_msa(void)
  85. {
  86. if (cpu_has_msa) {
  87. set_c0_config5(MIPS_CONF5_MSAEN);
  88. enable_fpu_hazard();
  89. }
  90. }
  91. static inline void disable_msa(void)
  92. {
  93. if (cpu_has_msa) {
  94. clear_c0_config5(MIPS_CONF5_MSAEN);
  95. disable_fpu_hazard();
  96. }
  97. }
  98. static inline int is_msa_enabled(void)
  99. {
  100. if (!cpu_has_msa)
  101. return 0;
  102. return read_c0_config5() & MIPS_CONF5_MSAEN;
  103. }
  104. static inline int thread_msa_context_live(void)
  105. {
  106. /*
  107. * Check cpu_has_msa only if it's a constant. This will allow the
  108. * compiler to optimise out code for CPUs without MSA without adding
  109. * an extra redundant check for CPUs with MSA.
  110. */
  111. if (__builtin_constant_p(cpu_has_msa) && !cpu_has_msa)
  112. return 0;
  113. return test_thread_flag(TIF_MSA_CTX_LIVE);
  114. }
  115. static inline void save_msa(struct task_struct *t)
  116. {
  117. if (cpu_has_msa)
  118. _save_msa(t);
  119. }
  120. static inline void restore_msa(struct task_struct *t)
  121. {
  122. if (cpu_has_msa)
  123. _restore_msa(t);
  124. }
  125. static inline void init_msa_upper(void)
  126. {
  127. /*
  128. * Check cpu_has_msa only if it's a constant. This will allow the
  129. * compiler to optimise out code for CPUs without MSA without adding
  130. * an extra redundant check for CPUs with MSA.
  131. */
  132. if (__builtin_constant_p(cpu_has_msa) && !cpu_has_msa)
  133. return;
  134. _init_msa_upper();
  135. }
  136. #ifdef TOOLCHAIN_SUPPORTS_MSA
  137. #define __BUILD_MSA_CTL_REG(name, cs) \
  138. static inline unsigned int read_msa_##name(void) \
  139. { \
  140. unsigned int reg; \
  141. __asm__ __volatile__( \
  142. " .set push\n" \
  143. " .set fp=64\n" \
  144. " .set msa\n" \
  145. " cfcmsa %0, $" #cs "\n" \
  146. " .set pop\n" \
  147. : "=r"(reg)); \
  148. return reg; \
  149. } \
  150. \
  151. static inline void write_msa_##name(unsigned int val) \
  152. { \
  153. __asm__ __volatile__( \
  154. " .set push\n" \
  155. " .set fp=64\n" \
  156. " .set msa\n" \
  157. " ctcmsa $" #cs ", %0\n" \
  158. " .set pop\n" \
  159. : : "r"(val)); \
  160. }
  161. #else /* !TOOLCHAIN_SUPPORTS_MSA */
  162. /*
  163. * Define functions using .word for the c[ft]cmsa instructions in order to
  164. * allow compilation with toolchains that do not support MSA. Once all
  165. * toolchains in use support MSA these can be removed.
  166. */
  167. #define __BUILD_MSA_CTL_REG(name, cs) \
  168. static inline unsigned int read_msa_##name(void) \
  169. { \
  170. unsigned int reg; \
  171. __asm__ __volatile__( \
  172. " .set push\n" \
  173. " .set noat\n" \
  174. " # cfcmsa $1, $%1\n" \
  175. _ASM_INSN_IF_MIPS(0x787e0059 | %1 << 11) \
  176. _ASM_INSN32_IF_MM(0x587e0056 | %1 << 11) \
  177. " move %0, $1\n" \
  178. " .set pop\n" \
  179. : "=r"(reg) : "i"(cs)); \
  180. return reg; \
  181. } \
  182. \
  183. static inline void write_msa_##name(unsigned int val) \
  184. { \
  185. __asm__ __volatile__( \
  186. " .set push\n" \
  187. " .set noat\n" \
  188. " move $1, %0\n" \
  189. " # ctcmsa $%1, $1\n" \
  190. _ASM_INSN_IF_MIPS(0x783e0819 | %1 << 6) \
  191. _ASM_INSN32_IF_MM(0x583e0816 | %1 << 6) \
  192. " .set pop\n" \
  193. : : "r"(val), "i"(cs)); \
  194. }
  195. #endif /* !TOOLCHAIN_SUPPORTS_MSA */
  196. __BUILD_MSA_CTL_REG(ir, 0)
  197. __BUILD_MSA_CTL_REG(csr, 1)
  198. __BUILD_MSA_CTL_REG(access, 2)
  199. __BUILD_MSA_CTL_REG(save, 3)
  200. __BUILD_MSA_CTL_REG(modify, 4)
  201. __BUILD_MSA_CTL_REG(request, 5)
  202. __BUILD_MSA_CTL_REG(map, 6)
  203. __BUILD_MSA_CTL_REG(unmap, 7)
  204. #endif /* !__ASSEMBLY__ */
  205. #define MSA_IR 0
  206. #define MSA_CSR 1
  207. #define MSA_ACCESS 2
  208. #define MSA_SAVE 3
  209. #define MSA_MODIFY 4
  210. #define MSA_REQUEST 5
  211. #define MSA_MAP 6
  212. #define MSA_UNMAP 7
  213. /* MSA Implementation Register (MSAIR) */
  214. #define MSA_IR_REVB 0
  215. #define MSA_IR_REVF (_ULCAST_(0xff) << MSA_IR_REVB)
  216. #define MSA_IR_PROCB 8
  217. #define MSA_IR_PROCF (_ULCAST_(0xff) << MSA_IR_PROCB)
  218. #define MSA_IR_WRPB 16
  219. #define MSA_IR_WRPF (_ULCAST_(0x1) << MSA_IR_WRPB)
  220. /* MSA Control & Status Register (MSACSR) */
  221. #define MSA_CSR_RMB 0
  222. #define MSA_CSR_RMF (_ULCAST_(0x3) << MSA_CSR_RMB)
  223. #define MSA_CSR_RM_NEAREST 0
  224. #define MSA_CSR_RM_TO_ZERO 1
  225. #define MSA_CSR_RM_TO_POS 2
  226. #define MSA_CSR_RM_TO_NEG 3
  227. #define MSA_CSR_FLAGSB 2
  228. #define MSA_CSR_FLAGSF (_ULCAST_(0x1f) << MSA_CSR_FLAGSB)
  229. #define MSA_CSR_FLAGS_IB 2
  230. #define MSA_CSR_FLAGS_IF (_ULCAST_(0x1) << MSA_CSR_FLAGS_IB)
  231. #define MSA_CSR_FLAGS_UB 3
  232. #define MSA_CSR_FLAGS_UF (_ULCAST_(0x1) << MSA_CSR_FLAGS_UB)
  233. #define MSA_CSR_FLAGS_OB 4
  234. #define MSA_CSR_FLAGS_OF (_ULCAST_(0x1) << MSA_CSR_FLAGS_OB)
  235. #define MSA_CSR_FLAGS_ZB 5
  236. #define MSA_CSR_FLAGS_ZF (_ULCAST_(0x1) << MSA_CSR_FLAGS_ZB)
  237. #define MSA_CSR_FLAGS_VB 6
  238. #define MSA_CSR_FLAGS_VF (_ULCAST_(0x1) << MSA_CSR_FLAGS_VB)
  239. #define MSA_CSR_ENABLESB 7
  240. #define MSA_CSR_ENABLESF (_ULCAST_(0x1f) << MSA_CSR_ENABLESB)
  241. #define MSA_CSR_ENABLES_IB 7
  242. #define MSA_CSR_ENABLES_IF (_ULCAST_(0x1) << MSA_CSR_ENABLES_IB)
  243. #define MSA_CSR_ENABLES_UB 8
  244. #define MSA_CSR_ENABLES_UF (_ULCAST_(0x1) << MSA_CSR_ENABLES_UB)
  245. #define MSA_CSR_ENABLES_OB 9
  246. #define MSA_CSR_ENABLES_OF (_ULCAST_(0x1) << MSA_CSR_ENABLES_OB)
  247. #define MSA_CSR_ENABLES_ZB 10
  248. #define MSA_CSR_ENABLES_ZF (_ULCAST_(0x1) << MSA_CSR_ENABLES_ZB)
  249. #define MSA_CSR_ENABLES_VB 11
  250. #define MSA_CSR_ENABLES_VF (_ULCAST_(0x1) << MSA_CSR_ENABLES_VB)
  251. #define MSA_CSR_CAUSEB 12
  252. #define MSA_CSR_CAUSEF (_ULCAST_(0x3f) << MSA_CSR_CAUSEB)
  253. #define MSA_CSR_CAUSE_IB 12
  254. #define MSA_CSR_CAUSE_IF (_ULCAST_(0x1) << MSA_CSR_CAUSE_IB)
  255. #define MSA_CSR_CAUSE_UB 13
  256. #define MSA_CSR_CAUSE_UF (_ULCAST_(0x1) << MSA_CSR_CAUSE_UB)
  257. #define MSA_CSR_CAUSE_OB 14
  258. #define MSA_CSR_CAUSE_OF (_ULCAST_(0x1) << MSA_CSR_CAUSE_OB)
  259. #define MSA_CSR_CAUSE_ZB 15
  260. #define MSA_CSR_CAUSE_ZF (_ULCAST_(0x1) << MSA_CSR_CAUSE_ZB)
  261. #define MSA_CSR_CAUSE_VB 16
  262. #define MSA_CSR_CAUSE_VF (_ULCAST_(0x1) << MSA_CSR_CAUSE_VB)
  263. #define MSA_CSR_CAUSE_EB 17
  264. #define MSA_CSR_CAUSE_EF (_ULCAST_(0x1) << MSA_CSR_CAUSE_EB)
  265. #define MSA_CSR_NXB 18
  266. #define MSA_CSR_NXF (_ULCAST_(0x1) << MSA_CSR_NXB)
  267. #define MSA_CSR_FSB 24
  268. #define MSA_CSR_FSF (_ULCAST_(0x1) << MSA_CSR_FSB)
  269. #endif /* _ASM_MSA_H */