context_el1.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  1. /*
  2. * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef CONTEXT_EL1_H
  7. #define CONTEXT_EL1_H
  8. #include <lib/extensions/sysreg128.h>
  9. #ifndef __ASSEMBLER__
  10. /*******************************************************************************
  11. * EL1 Registers:
  12. * AArch64 EL1 system register context structure for preserving the
  13. * architectural state during world switches.
  14. ******************************************************************************/
  15. typedef struct el1_common_regs {
  16. uint64_t spsr_el1;
  17. uint64_t elr_el1;
  18. #if (!ERRATA_SPECULATIVE_AT)
  19. uint64_t sctlr_el1;
  20. uint64_t tcr_el1;
  21. #endif /* ERRATA_SPECULATIVE_AT=0 */
  22. uint64_t cpacr_el1;
  23. uint64_t csselr_el1;
  24. uint64_t sp_el1;
  25. uint64_t esr_el1;
  26. uint64_t mair_el1;
  27. uint64_t amair_el1;
  28. uint64_t actlr_el1;
  29. uint64_t tpidr_el1;
  30. uint64_t tpidr_el0;
  31. uint64_t tpidrro_el0;
  32. uint64_t far_el1;
  33. uint64_t afsr0_el1;
  34. uint64_t afsr1_el1;
  35. uint64_t contextidr_el1;
  36. uint64_t vbar_el1;
  37. uint64_t mdccint_el1;
  38. uint64_t mdscr_el1;
  39. sysreg_t par_el1;
  40. sysreg_t ttbr0_el1;
  41. sysreg_t ttbr1_el1;
  42. } el1_common_regs_t;
  43. typedef struct el1_aarch32_regs {
  44. uint64_t spsr_abt;
  45. uint64_t spsr_und;
  46. uint64_t spsr_irq;
  47. uint64_t spsr_fiq;
  48. uint64_t dacr32_el2;
  49. uint64_t ifsr32_el2;
  50. } el1_aarch32_regs_t;
  51. typedef struct el1_arch_timer_regs {
  52. uint64_t cntp_ctl_el0;
  53. uint64_t cntp_cval_el0;
  54. uint64_t cntv_ctl_el0;
  55. uint64_t cntv_cval_el0;
  56. uint64_t cntkctl_el1;
  57. } el1_arch_timer_regs_t;
  58. typedef struct el1_mte2_regs {
  59. uint64_t tfsre0_el1;
  60. uint64_t tfsr_el1;
  61. uint64_t rgsr_el1;
  62. uint64_t gcr_el1;
  63. } el1_mte2_regs_t;
  64. typedef struct el1_ras_regs {
  65. uint64_t disr_el1;
  66. } el1_ras_regs_t;
  67. typedef struct el1_s1pie_regs {
  68. uint64_t pire0_el1;
  69. uint64_t pir_el1;
  70. } el1_s1pie_regs_t;
  71. typedef struct el1_s1poe_regs {
  72. uint64_t por_el1;
  73. } el1_s1poe_regs_t;
  74. typedef struct el1_s2poe_regs {
  75. uint64_t s2por_el1;
  76. } el1_s2poe_regs_t;
  77. typedef struct el1_tcr2_regs {
  78. uint64_t tcr2_el1;
  79. } el1_tcr2_regs_t;
  80. typedef struct el1_trf_regs {
  81. uint64_t trfcr_el1;
  82. } el1_trf_regs_t;
  83. typedef struct el1_csv2_2_regs {
  84. uint64_t scxtnum_el0;
  85. uint64_t scxtnum_el1;
  86. } el1_csv2_2_regs_t;
  87. typedef struct el1_gcs_regs {
  88. uint64_t gcscr_el1;
  89. uint64_t gcscre0_el1;
  90. uint64_t gcspr_el1;
  91. uint64_t gcspr_el0;
  92. } el1_gcs_regs_t;
  93. typedef struct el1_the_regs {
  94. sysreg_t rcwmask_el1;
  95. sysreg_t rcwsmask_el1;
  96. } el1_the_regs_t;
  97. typedef struct el1_sctlr2_regs {
  98. uint64_t sctlr2_el1;
  99. } el1_sctlr2_regs_t;
  100. typedef struct el1_ls64_regs {
  101. uint64_t accdata_el1;
  102. } el1_ls64_regs_t;
  103. typedef struct el1_sysregs {
  104. el1_common_regs_t common;
  105. #if CTX_INCLUDE_AARCH32_REGS
  106. el1_aarch32_regs_t el1_aarch32;
  107. #endif
  108. #if NS_TIMER_SWITCH
  109. el1_arch_timer_regs_t arch_timer;
  110. #endif
  111. #if ENABLE_FEAT_MTE2
  112. el1_mte2_regs_t mte2;
  113. #endif
  114. #if ENABLE_FEAT_RAS
  115. el1_ras_regs_t ras;
  116. #endif
  117. #if ENABLE_FEAT_S1PIE
  118. el1_s1pie_regs_t s1pie;
  119. #endif
  120. #if ENABLE_FEAT_S1POE
  121. el1_s1poe_regs_t s1poe;
  122. #endif
  123. #if ENABLE_FEAT_S2POE
  124. el1_s2poe_regs_t s2poe;
  125. #endif
  126. #if ENABLE_FEAT_TCR2
  127. el1_tcr2_regs_t tcr2;
  128. #endif
  129. #if ENABLE_TRF_FOR_NS
  130. el1_trf_regs_t trf;
  131. #endif
  132. #if ENABLE_FEAT_CSV2_2
  133. el1_csv2_2_regs_t csv2_2;
  134. #endif
  135. #if ENABLE_FEAT_GCS
  136. el1_gcs_regs_t gcs;
  137. #endif
  138. #if ENABLE_FEAT_THE
  139. el1_the_regs_t the;
  140. #endif
  141. #if ENABLE_FEAT_SCTLR2
  142. el1_sctlr2_regs_t sctlr2;
  143. #endif
  144. #if ENABLE_FEAT_LS64_ACCDATA
  145. el1_ls64_regs_t ls64;
  146. #endif
  147. } el1_sysregs_t;
  148. /*
  149. * Macros to access members related to individual features of the el1_sysregs_t
  150. * structures.
  151. */
  152. #define read_el1_ctx_common(ctx, reg) (((ctx)->common).reg)
  153. #define write_el1_ctx_common(ctx, reg, val) ((((ctx)->common).reg) \
  154. = (uint64_t) (val))
  155. #if NS_TIMER_SWITCH
  156. #define read_el1_ctx_arch_timer(ctx, reg) (((ctx)->arch_timer).reg)
  157. #define write_el1_ctx_arch_timer(ctx, reg, val) ((((ctx)->arch_timer).reg) \
  158. = (uint64_t) (val))
  159. #else
  160. #define read_el1_ctx_arch_timer(ctx, reg) ULL(0)
  161. #define write_el1_ctx_arch_timer(ctx, reg, val)
  162. #endif /* NS_TIMER_SWITCH */
  163. #if CTX_INCLUDE_AARCH32_REGS
  164. #define read_el1_ctx_aarch32(ctx, reg) (((ctx)->el1_aarch32).reg)
  165. #define write_el1_ctx_aarch32(ctx, reg, val) ((((ctx)->el1_aarch32).reg) \
  166. = (uint64_t) (val))
  167. #else
  168. #define read_el1_ctx_aarch32(ctx, reg) ULL(0)
  169. #define write_el1_ctx_aarch32(ctx, reg, val)
  170. #endif /* CTX_INCLUDE_AARCH32_REGS */
  171. #if ENABLE_FEAT_MTE2
  172. #define read_el1_ctx_mte2(ctx, reg) (((ctx)->mte2).reg)
  173. #define write_el1_ctx_mte2(ctx, reg, val) ((((ctx)->mte2).reg) \
  174. = (uint64_t) (val))
  175. #else
  176. #define read_el1_ctx_mte2(ctx, reg) ULL(0)
  177. #define write_el1_ctx_mte2(ctx, reg, val)
  178. #endif /* ENABLE_FEAT_MTE2 */
  179. #if ENABLE_FEAT_RAS
  180. #define read_el1_ctx_ras(ctx, reg) (((ctx)->ras).reg)
  181. #define write_el1_ctx_ras(ctx, reg, val) ((((ctx)->ras).reg) \
  182. = (uint64_t) (val))
  183. #else
  184. #define read_el1_ctx_ras(ctx, reg) ULL(0)
  185. #define write_el1_ctx_ras(ctx, reg, val)
  186. #endif /* ENABLE_FEAT_RAS */
  187. #if ENABLE_FEAT_S1PIE
  188. #define read_el1_ctx_s1pie(ctx, reg) (((ctx)->s1pie).reg)
  189. #define write_el1_ctx_s1pie(ctx, reg, val) ((((ctx)->s1pie).reg) \
  190. = (uint64_t) (val))
  191. #else
  192. #define read_el1_ctx_s1pie(ctx, reg) ULL(0)
  193. #define write_el1_ctx_s1pie(ctx, reg, val)
  194. #endif /* ENABLE_FEAT_S1PIE */
  195. #if ENABLE_FEAT_S1POE
  196. #define read_el1_ctx_s1poe(ctx, reg) (((ctx)->s1poe).reg)
  197. #define write_el1_ctx_s1poe(ctx, reg, val) ((((ctx)->s1poe).reg) \
  198. = (uint64_t) (val))
  199. #else
  200. #define read_el1_ctx_s1poe(ctx, reg) ULL(0)
  201. #define write_el1_ctx_s1poe(ctx, reg, val)
  202. #endif /* ENABLE_FEAT_S1POE */
  203. #if ENABLE_FEAT_S2POE
  204. #define read_el1_ctx_s2poe(ctx, reg) (((ctx)->s2poe).reg)
  205. #define write_el1_ctx_s2poe(ctx, reg, val) ((((ctx)->s2poe).reg) \
  206. = (uint64_t) (val))
  207. #else
  208. #define read_el1_ctx_s2poe(ctx, reg) ULL(0)
  209. #define write_el1_ctx_s2poe(ctx, reg, val)
  210. #endif /* ENABLE_FEAT_S2POE */
  211. #if ENABLE_FEAT_TCR2
  212. #define read_el1_ctx_tcr2(ctx, reg) (((ctx)->tcr2).reg)
  213. #define write_el1_ctx_tcr2(ctx, reg, val) ((((ctx)->tcr2).reg) \
  214. = (uint64_t) (val))
  215. #else
  216. #define read_el1_ctx_tcr2(ctx, reg) ULL(0)
  217. #define write_el1_ctx_tcr2(ctx, reg, val)
  218. #endif /* ENABLE_FEAT_TCR2 */
  219. #if ENABLE_TRF_FOR_NS
  220. #define read_el1_ctx_trf(ctx, reg) (((ctx)->trf).reg)
  221. #define write_el1_ctx_trf(ctx, reg, val) ((((ctx)->trf).reg) \
  222. = (uint64_t) (val))
  223. #else
  224. #define read_el1_ctx_trf(ctx, reg) ULL(0)
  225. #define write_el1_ctx_trf(ctx, reg, val)
  226. #endif /* ENABLE_TRF_FOR_NS */
  227. #if ENABLE_FEAT_CSV2_2
  228. #define read_el1_ctx_csv2_2(ctx, reg) (((ctx)->csv2_2).reg)
  229. #define write_el1_ctx_csv2_2(ctx, reg, val) ((((ctx)->csv2_2).reg) \
  230. = (uint64_t) (val))
  231. #else
  232. #define read_el1_ctx_csv2_2(ctx, reg) ULL(0)
  233. #define write_el1_ctx_csv2_2(ctx, reg, val)
  234. #endif /* ENABLE_FEAT_CSV2_2 */
  235. #if ENABLE_FEAT_GCS
  236. #define read_el1_ctx_gcs(ctx, reg) (((ctx)->gcs).reg)
  237. #define write_el1_ctx_gcs(ctx, reg, val) ((((ctx)->gcs).reg) \
  238. = (uint64_t) (val))
  239. #else
  240. #define read_el1_ctx_gcs(ctx, reg) ULL(0)
  241. #define write_el1_ctx_gcs(ctx, reg, val)
  242. #endif /* ENABLE_FEAT_GCS */
  243. #if ENABLE_FEAT_THE
  244. #define read_el1_ctx_the(ctx, reg) (((ctx)->the).reg)
  245. #define write_el1_ctx_the(ctx, reg, val) ((((ctx)->the).reg) \
  246. = (uint64_t) (val))
  247. #else
  248. #define read_el1_ctx_the(ctx, reg) ULL(0)
  249. #define write_el1_ctx_the(ctx, reg, val)
  250. #endif /* ENABLE_FEAT_THE */
  251. #if ENABLE_FEAT_SCTLR2
  252. #define read_el1_ctx_sctlr2(ctx, reg) (((ctx)->sctlr2).reg)
  253. #define write_el1_ctx_sctlr2(ctx, reg, val) ((((ctx)->sctlr2).reg) \
  254. = (uint64_t) (val))
  255. #else
  256. #define read_el1_ctx_sctlr2(ctx, reg) ULL(0)
  257. #define write_el1_ctx_sctlr2(ctx, reg, val)
  258. #endif /* ENABLE_FEAT_SCTLR2 */
  259. #if ENABLE_FEAT_LS64_ACCDATA
  260. #define read_el1_ctx_ls64(ctx, reg) (((ctx)->ls64).reg)
  261. #define write_el1_ctx_ls64(ctx, reg, val) ((((ctx)->ls64).reg) \
  262. = (uint64_t) (val))
  263. #else
  264. #define read_el1_ctx_ls64(ctx, reg) ULL(0)
  265. #define write_el1_ctx_ls64(ctx, reg, val)
  266. #endif /* ENABLE_FEAT_LS64_ACCDATA */
  267. /******************************************************************************/
  268. #endif /* __ASSEMBLER__ */
  269. #endif /* CONTEXT_EL1_H */