arch_helpers.h 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /*
  2. * Copyright (c) 2013-2024, Arm Limited and Contributors. All rights reserved.
  3. *
  4. * SPDX-License-Identifier: BSD-3-Clause
  5. */
  6. #ifndef ARCH_HELPERS_H
  7. #define ARCH_HELPERS_H
  8. #include <cdefs.h>
  9. #include <stdbool.h>
  10. #include <stdint.h>
  11. #include <string.h>
  12. #include <arch.h>
  13. /**********************************************************************
  14. * Macros which create inline functions to read or write CPU system
  15. * registers
  16. *********************************************************************/
  17. #define _DEFINE_SYSREG_READ_FUNC(_name, _reg_name) \
  18. static inline u_register_t read_ ## _name(void) \
  19. { \
  20. u_register_t v; \
  21. __asm__ volatile ("mrs %0, " #_reg_name : "=r" (v)); \
  22. return v; \
  23. }
  24. #define _DEFINE_SYSREG_READ_FUNC_NV(_name, _reg_name) \
  25. static inline u_register_t read_ ## _name(void) \
  26. { \
  27. u_register_t v; \
  28. __asm__ ("mrs %0, " #_reg_name : "=r" (v)); \
  29. return v; \
  30. }
  31. #define _DEFINE_SYSREG_WRITE_FUNC(_name, _reg_name) \
  32. static inline void write_ ## _name(u_register_t v) \
  33. { \
  34. __asm__ volatile ("msr " #_reg_name ", %0" : : "r" (v)); \
  35. }
  36. #define SYSREG_WRITE_CONST(reg_name, v) \
  37. __asm__ volatile ("msr " #reg_name ", %0" : : "i" (v))
  38. /* Define read function for system register */
  39. #define DEFINE_SYSREG_READ_FUNC(_name) \
  40. _DEFINE_SYSREG_READ_FUNC(_name, _name)
  41. /* Define read & write function for system register */
  42. #define DEFINE_SYSREG_RW_FUNCS(_name) \
  43. _DEFINE_SYSREG_READ_FUNC(_name, _name) \
  44. _DEFINE_SYSREG_WRITE_FUNC(_name, _name)
  45. /* Define read & write function for renamed system register */
  46. #define DEFINE_RENAME_SYSREG_RW_FUNCS(_name, _reg_name) \
  47. _DEFINE_SYSREG_READ_FUNC(_name, _reg_name) \
  48. _DEFINE_SYSREG_WRITE_FUNC(_name, _reg_name)
  49. /* Define read function for renamed system register */
  50. #define DEFINE_RENAME_SYSREG_READ_FUNC(_name, _reg_name) \
  51. _DEFINE_SYSREG_READ_FUNC(_name, _reg_name)
  52. /* Define write function for renamed system register */
  53. #define DEFINE_RENAME_SYSREG_WRITE_FUNC(_name, _reg_name) \
  54. _DEFINE_SYSREG_WRITE_FUNC(_name, _reg_name)
  55. /* Define read function for ID register (w/o volatile qualifier) */
  56. #define DEFINE_IDREG_READ_FUNC(_name) \
  57. _DEFINE_SYSREG_READ_FUNC_NV(_name, _name)
  58. /* Define read function for renamed ID register (w/o volatile qualifier) */
  59. #define DEFINE_RENAME_IDREG_READ_FUNC(_name, _reg_name) \
  60. _DEFINE_SYSREG_READ_FUNC_NV(_name, _reg_name)
  61. /**********************************************************************
  62. * Macros to create inline functions for system instructions
  63. *********************************************************************/
  64. /* Define function for simple system instruction */
  65. #define DEFINE_SYSOP_FUNC(_op) \
  66. static inline void _op(void) \
  67. { \
  68. __asm__ (#_op); \
  69. }
  70. /* Define function for system instruction with register parameter */
  71. #define DEFINE_SYSOP_PARAM_FUNC(_op) \
  72. static inline void _op(uint64_t v) \
  73. { \
  74. __asm__ (#_op " %0" : : "r" (v)); \
  75. }
  76. /* Define function for system instruction with type specifier */
  77. #define DEFINE_SYSOP_TYPE_FUNC(_op, _type) \
  78. static inline void _op ## _type(void) \
  79. { \
  80. __asm__ (#_op " " #_type : : : "memory"); \
  81. }
  82. /* Define function for system instruction with register parameter */
  83. #define DEFINE_SYSOP_TYPE_PARAM_FUNC(_op, _type) \
  84. static inline void _op ## _type(uint64_t v) \
  85. { \
  86. __asm__ (#_op " " #_type ", %0" : : "r" (v)); \
  87. }
  88. /*******************************************************************************
  89. * TLB maintenance accessor prototypes
  90. ******************************************************************************/
  91. #if ERRATA_A57_813419 || ERRATA_A76_1286807
  92. /*
  93. * Define function for TLBI instruction with type specifier that implements
  94. * the workaround for errata 813419 of Cortex-A57 or errata 1286807 of
  95. * Cortex-A76.
  96. */
  97. #define DEFINE_TLBIOP_ERRATA_TYPE_FUNC(_type)\
  98. static inline void tlbi ## _type(void) \
  99. { \
  100. __asm__("tlbi " #_type "\n" \
  101. "dsb ish\n" \
  102. "tlbi " #_type); \
  103. }
  104. /*
  105. * Define function for TLBI instruction with register parameter that implements
  106. * the workaround for errata 813419 of Cortex-A57 or errata 1286807 of
  107. * Cortex-A76.
  108. */
  109. #define DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(_type) \
  110. static inline void tlbi ## _type(uint64_t v) \
  111. { \
  112. __asm__("tlbi " #_type ", %0\n" \
  113. "dsb ish\n" \
  114. "tlbi " #_type ", %0" : : "r" (v)); \
  115. }
  116. #endif /* ERRATA_A57_813419 */
  117. #if ERRATA_A53_819472 || ERRATA_A53_824069 || ERRATA_A53_827319
  118. /*
  119. * Define function for DC instruction with register parameter that enables
  120. * the workaround for errata 819472, 824069 and 827319 of Cortex-A53.
  121. */
  122. #define DEFINE_DCOP_ERRATA_A53_TYPE_PARAM_FUNC(_name, _type) \
  123. static inline void dc ## _name(uint64_t v) \
  124. { \
  125. __asm__("dc " #_type ", %0" : : "r" (v)); \
  126. }
  127. #endif /* ERRATA_A53_819472 || ERRATA_A53_824069 || ERRATA_A53_827319 */
  128. #if ERRATA_A57_813419
  129. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle1)
  130. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle1is)
  131. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle2)
  132. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle2is)
  133. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle3)
  134. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle3is)
  135. DEFINE_SYSOP_TYPE_FUNC(tlbi, vmalle1)
  136. #elif ERRATA_A76_1286807
  137. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle1)
  138. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle1is)
  139. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle2)
  140. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle2is)
  141. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle3)
  142. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(alle3is)
  143. DEFINE_TLBIOP_ERRATA_TYPE_FUNC(vmalle1)
  144. #else
  145. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle1)
  146. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle1is)
  147. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle2)
  148. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle2is)
  149. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle3)
  150. DEFINE_SYSOP_TYPE_FUNC(tlbi, alle3is)
  151. DEFINE_SYSOP_TYPE_FUNC(tlbi, vmalle1)
  152. #endif
  153. #if ERRATA_A57_813419
  154. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vaae1is)
  155. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vaale1is)
  156. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vae2is)
  157. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vale2is)
  158. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vae3is)
  159. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vale3is)
  160. #elif ERRATA_A76_1286807
  161. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vaae1is)
  162. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vaale1is)
  163. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vae2is)
  164. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vale2is)
  165. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vae3is)
  166. DEFINE_TLBIOP_ERRATA_TYPE_PARAM_FUNC(vale3is)
  167. #else
  168. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vaae1is)
  169. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vaale1is)
  170. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vae2is)
  171. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vale2is)
  172. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vae3is)
  173. DEFINE_SYSOP_TYPE_PARAM_FUNC(tlbi, vale3is)
  174. #endif
  175. /*******************************************************************************
  176. * Cache maintenance accessor prototypes
  177. ******************************************************************************/
  178. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, isw)
  179. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, cisw)
  180. #if ERRATA_A53_827319
  181. DEFINE_DCOP_ERRATA_A53_TYPE_PARAM_FUNC(csw, cisw)
  182. #else
  183. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, csw)
  184. #endif
  185. #if ERRATA_A53_819472 || ERRATA_A53_824069 || ERRATA_A53_827319
  186. DEFINE_DCOP_ERRATA_A53_TYPE_PARAM_FUNC(cvac, civac)
  187. #else
  188. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, cvac)
  189. #endif
  190. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, ivac)
  191. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, civac)
  192. #if ERRATA_A53_819472 || ERRATA_A53_824069 || ERRATA_A53_827319
  193. DEFINE_DCOP_ERRATA_A53_TYPE_PARAM_FUNC(cvau, civac)
  194. #else
  195. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, cvau)
  196. #endif
  197. DEFINE_SYSOP_TYPE_PARAM_FUNC(dc, zva)
  198. /*******************************************************************************
  199. * Address translation accessor prototypes
  200. ******************************************************************************/
  201. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s12e1r)
  202. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s12e1w)
  203. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s12e0r)
  204. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s12e0w)
  205. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s1e1r)
  206. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s1e2r)
  207. DEFINE_SYSOP_TYPE_PARAM_FUNC(at, s1e3r)
  208. /*******************************************************************************
  209. * Strip Pointer Authentication Code
  210. ******************************************************************************/
  211. DEFINE_SYSOP_PARAM_FUNC(xpaci)
  212. void flush_dcache_range(uintptr_t addr, size_t size);
  213. void flush_dcache_to_popa_range(uintptr_t addr, size_t size);
  214. void flush_dcache_to_popa_range_mte2(uintptr_t addr, size_t size);
  215. void clean_dcache_range(uintptr_t addr, size_t size);
  216. void inv_dcache_range(uintptr_t addr, size_t size);
  217. bool is_dcache_enabled(void);
  218. void dcsw_op_louis(u_register_t op_type);
  219. void dcsw_op_all(u_register_t op_type);
  220. void disable_mmu_el1(void);
  221. void disable_mmu_el3(void);
  222. void disable_mpu_el2(void);
  223. void disable_mmu_icache_el1(void);
  224. void disable_mmu_icache_el3(void);
  225. void disable_mpu_icache_el2(void);
  226. /*******************************************************************************
  227. * Misc. accessor prototypes
  228. ******************************************************************************/
  229. #define write_daifclr(val) SYSREG_WRITE_CONST(daifclr, val)
  230. #define write_daifset(val) SYSREG_WRITE_CONST(daifset, val)
  231. DEFINE_SYSREG_RW_FUNCS(par_el1)
  232. DEFINE_IDREG_READ_FUNC(id_pfr1_el1)
  233. DEFINE_IDREG_READ_FUNC(id_aa64isar0_el1)
  234. DEFINE_IDREG_READ_FUNC(id_aa64isar1_el1)
  235. DEFINE_RENAME_IDREG_READ_FUNC(id_aa64isar2_el1, ID_AA64ISAR2_EL1)
  236. DEFINE_IDREG_READ_FUNC(id_aa64pfr0_el1)
  237. DEFINE_IDREG_READ_FUNC(id_aa64pfr1_el1)
  238. DEFINE_RENAME_IDREG_READ_FUNC(id_aa64pfr2_el1, ID_AA64PFR2_EL1)
  239. DEFINE_IDREG_READ_FUNC(id_aa64dfr0_el1)
  240. DEFINE_IDREG_READ_FUNC(id_aa64dfr1_el1)
  241. DEFINE_IDREG_READ_FUNC(id_afr0_el1)
  242. DEFINE_SYSREG_READ_FUNC(CurrentEl)
  243. DEFINE_SYSREG_READ_FUNC(ctr_el0)
  244. DEFINE_SYSREG_RW_FUNCS(daif)
  245. DEFINE_SYSREG_RW_FUNCS(spsr_el1)
  246. DEFINE_SYSREG_RW_FUNCS(spsr_el2)
  247. DEFINE_SYSREG_RW_FUNCS(spsr_el3)
  248. DEFINE_SYSREG_RW_FUNCS(elr_el1)
  249. DEFINE_SYSREG_RW_FUNCS(elr_el2)
  250. DEFINE_SYSREG_RW_FUNCS(elr_el3)
  251. DEFINE_SYSREG_RW_FUNCS(mdccsr_el0)
  252. DEFINE_SYSREG_RW_FUNCS(mdccint_el1)
  253. DEFINE_SYSREG_RW_FUNCS(dbgdtrrx_el0)
  254. DEFINE_SYSREG_RW_FUNCS(dbgdtrtx_el0)
  255. DEFINE_SYSREG_RW_FUNCS(sp_el1)
  256. DEFINE_SYSREG_RW_FUNCS(sp_el2)
  257. DEFINE_SYSOP_FUNC(wfi)
  258. DEFINE_SYSOP_FUNC(wfe)
  259. DEFINE_SYSOP_FUNC(sev)
  260. DEFINE_SYSOP_TYPE_FUNC(dsb, sy)
  261. DEFINE_SYSOP_TYPE_FUNC(dmb, sy)
  262. DEFINE_SYSOP_TYPE_FUNC(dmb, st)
  263. DEFINE_SYSOP_TYPE_FUNC(dmb, ld)
  264. DEFINE_SYSOP_TYPE_FUNC(dsb, ish)
  265. DEFINE_SYSOP_TYPE_FUNC(dsb, osh)
  266. DEFINE_SYSOP_TYPE_FUNC(dsb, nsh)
  267. DEFINE_SYSOP_TYPE_FUNC(dsb, ishst)
  268. DEFINE_SYSOP_TYPE_FUNC(dsb, oshst)
  269. DEFINE_SYSOP_TYPE_FUNC(dmb, oshld)
  270. DEFINE_SYSOP_TYPE_FUNC(dmb, oshst)
  271. DEFINE_SYSOP_TYPE_FUNC(dmb, osh)
  272. DEFINE_SYSOP_TYPE_FUNC(dmb, nshld)
  273. DEFINE_SYSOP_TYPE_FUNC(dmb, nshst)
  274. DEFINE_SYSOP_TYPE_FUNC(dmb, nsh)
  275. DEFINE_SYSOP_TYPE_FUNC(dmb, ishld)
  276. DEFINE_SYSOP_TYPE_FUNC(dmb, ishst)
  277. DEFINE_SYSOP_TYPE_FUNC(dmb, ish)
  278. DEFINE_SYSOP_FUNC(isb)
  279. static inline void enable_irq(void)
  280. {
  281. /*
  282. * The compiler memory barrier will prevent the compiler from
  283. * scheduling non-volatile memory access after the write to the
  284. * register.
  285. *
  286. * This could happen if some initialization code issues non-volatile
  287. * accesses to an area used by an interrupt handler, in the assumption
  288. * that it is safe as the interrupts are disabled at the time it does
  289. * that (according to program order). However, non-volatile accesses
  290. * are not necessarily in program order relatively with volatile inline
  291. * assembly statements (and volatile accesses).
  292. */
  293. COMPILER_BARRIER();
  294. write_daifclr(DAIF_IRQ_BIT);
  295. isb();
  296. }
  297. static inline void enable_fiq(void)
  298. {
  299. COMPILER_BARRIER();
  300. write_daifclr(DAIF_FIQ_BIT);
  301. isb();
  302. }
  303. static inline void enable_serror(void)
  304. {
  305. COMPILER_BARRIER();
  306. write_daifclr(DAIF_ABT_BIT);
  307. isb();
  308. }
  309. static inline void enable_debug_exceptions(void)
  310. {
  311. COMPILER_BARRIER();
  312. write_daifclr(DAIF_DBG_BIT);
  313. isb();
  314. }
  315. static inline void disable_irq(void)
  316. {
  317. COMPILER_BARRIER();
  318. write_daifset(DAIF_IRQ_BIT);
  319. isb();
  320. }
  321. static inline void disable_fiq(void)
  322. {
  323. COMPILER_BARRIER();
  324. write_daifset(DAIF_FIQ_BIT);
  325. isb();
  326. }
  327. static inline void disable_serror(void)
  328. {
  329. COMPILER_BARRIER();
  330. write_daifset(DAIF_ABT_BIT);
  331. isb();
  332. }
  333. static inline void disable_debug_exceptions(void)
  334. {
  335. COMPILER_BARRIER();
  336. write_daifset(DAIF_DBG_BIT);
  337. isb();
  338. }
  339. void __dead2 smc(uint64_t x0, uint64_t x1, uint64_t x2, uint64_t x3,
  340. uint64_t x4, uint64_t x5, uint64_t x6, uint64_t x7);
  341. /*******************************************************************************
  342. * System register accessor prototypes
  343. ******************************************************************************/
  344. DEFINE_IDREG_READ_FUNC(midr_el1)
  345. DEFINE_SYSREG_READ_FUNC(mpidr_el1)
  346. DEFINE_IDREG_READ_FUNC(id_aa64mmfr0_el1)
  347. DEFINE_IDREG_READ_FUNC(id_aa64mmfr1_el1)
  348. DEFINE_SYSREG_RW_FUNCS(scr_el3)
  349. DEFINE_SYSREG_RW_FUNCS(hcr_el2)
  350. DEFINE_SYSREG_RW_FUNCS(vbar_el1)
  351. DEFINE_SYSREG_RW_FUNCS(vbar_el2)
  352. DEFINE_SYSREG_RW_FUNCS(vbar_el3)
  353. DEFINE_SYSREG_RW_FUNCS(sctlr_el1)
  354. DEFINE_SYSREG_RW_FUNCS(sctlr_el2)
  355. DEFINE_SYSREG_RW_FUNCS(sctlr_el3)
  356. DEFINE_SYSREG_RW_FUNCS(actlr_el1)
  357. DEFINE_SYSREG_RW_FUNCS(actlr_el2)
  358. DEFINE_SYSREG_RW_FUNCS(actlr_el3)
  359. DEFINE_SYSREG_RW_FUNCS(esr_el1)
  360. DEFINE_SYSREG_RW_FUNCS(esr_el2)
  361. DEFINE_SYSREG_RW_FUNCS(esr_el3)
  362. DEFINE_SYSREG_RW_FUNCS(afsr0_el1)
  363. DEFINE_SYSREG_RW_FUNCS(afsr0_el2)
  364. DEFINE_SYSREG_RW_FUNCS(afsr0_el3)
  365. DEFINE_SYSREG_RW_FUNCS(afsr1_el1)
  366. DEFINE_SYSREG_RW_FUNCS(afsr1_el2)
  367. DEFINE_SYSREG_RW_FUNCS(afsr1_el3)
  368. DEFINE_SYSREG_RW_FUNCS(far_el1)
  369. DEFINE_SYSREG_RW_FUNCS(far_el2)
  370. DEFINE_SYSREG_RW_FUNCS(far_el3)
  371. DEFINE_SYSREG_RW_FUNCS(mair_el1)
  372. DEFINE_SYSREG_RW_FUNCS(mair_el2)
  373. DEFINE_SYSREG_RW_FUNCS(mair_el3)
  374. DEFINE_SYSREG_RW_FUNCS(amair_el1)
  375. DEFINE_SYSREG_RW_FUNCS(amair_el2)
  376. DEFINE_SYSREG_RW_FUNCS(amair_el3)
  377. DEFINE_SYSREG_READ_FUNC(rvbar_el1)
  378. DEFINE_SYSREG_READ_FUNC(rvbar_el2)
  379. DEFINE_SYSREG_READ_FUNC(rvbar_el3)
  380. DEFINE_SYSREG_RW_FUNCS(rmr_el1)
  381. DEFINE_SYSREG_RW_FUNCS(rmr_el2)
  382. DEFINE_SYSREG_RW_FUNCS(rmr_el3)
  383. DEFINE_SYSREG_RW_FUNCS(tcr_el1)
  384. DEFINE_SYSREG_RW_FUNCS(tcr_el2)
  385. DEFINE_SYSREG_RW_FUNCS(tcr_el3)
  386. DEFINE_SYSREG_RW_FUNCS(ttbr0_el1)
  387. DEFINE_SYSREG_RW_FUNCS(ttbr0_el2)
  388. DEFINE_SYSREG_RW_FUNCS(ttbr0_el3)
  389. DEFINE_SYSREG_RW_FUNCS(ttbr1_el1)
  390. DEFINE_SYSREG_RW_FUNCS(vttbr_el2)
  391. DEFINE_SYSREG_RW_FUNCS(cptr_el2)
  392. DEFINE_SYSREG_RW_FUNCS(cptr_el3)
  393. DEFINE_SYSREG_RW_FUNCS(cpacr_el1)
  394. DEFINE_SYSREG_RW_FUNCS(cntfrq_el0)
  395. DEFINE_SYSREG_RW_FUNCS(cnthp_ctl_el2)
  396. DEFINE_SYSREG_RW_FUNCS(cnthp_tval_el2)
  397. DEFINE_SYSREG_RW_FUNCS(cnthp_cval_el2)
  398. DEFINE_SYSREG_RW_FUNCS(cntps_ctl_el1)
  399. DEFINE_SYSREG_RW_FUNCS(cntps_tval_el1)
  400. DEFINE_SYSREG_RW_FUNCS(cntps_cval_el1)
  401. DEFINE_SYSREG_RW_FUNCS(cntp_ctl_el0)
  402. DEFINE_SYSREG_RW_FUNCS(cntp_tval_el0)
  403. DEFINE_SYSREG_RW_FUNCS(cntp_cval_el0)
  404. DEFINE_SYSREG_READ_FUNC(cntpct_el0)
  405. DEFINE_SYSREG_RW_FUNCS(cnthctl_el2)
  406. DEFINE_SYSREG_RW_FUNCS(cntv_ctl_el0)
  407. DEFINE_SYSREG_RW_FUNCS(cntv_cval_el0)
  408. DEFINE_SYSREG_RW_FUNCS(cntkctl_el1)
  409. DEFINE_SYSREG_RW_FUNCS(vtcr_el2)
  410. #define get_cntp_ctl_enable(x) (((x) >> CNTP_CTL_ENABLE_SHIFT) & \
  411. CNTP_CTL_ENABLE_MASK)
  412. #define get_cntp_ctl_imask(x) (((x) >> CNTP_CTL_IMASK_SHIFT) & \
  413. CNTP_CTL_IMASK_MASK)
  414. #define get_cntp_ctl_istatus(x) (((x) >> CNTP_CTL_ISTATUS_SHIFT) & \
  415. CNTP_CTL_ISTATUS_MASK)
  416. #define set_cntp_ctl_enable(x) ((x) |= (U(1) << CNTP_CTL_ENABLE_SHIFT))
  417. #define set_cntp_ctl_imask(x) ((x) |= (U(1) << CNTP_CTL_IMASK_SHIFT))
  418. #define clr_cntp_ctl_enable(x) ((x) &= ~(U(1) << CNTP_CTL_ENABLE_SHIFT))
  419. #define clr_cntp_ctl_imask(x) ((x) &= ~(U(1) << CNTP_CTL_IMASK_SHIFT))
  420. DEFINE_SYSREG_RW_FUNCS(tpidr_el0)
  421. DEFINE_SYSREG_RW_FUNCS(tpidr_el1)
  422. DEFINE_SYSREG_RW_FUNCS(tpidr_el2)
  423. DEFINE_SYSREG_RW_FUNCS(tpidr_el3)
  424. DEFINE_SYSREG_RW_FUNCS(cntvoff_el2)
  425. DEFINE_SYSREG_RW_FUNCS(vpidr_el2)
  426. DEFINE_SYSREG_RW_FUNCS(vmpidr_el2)
  427. DEFINE_SYSREG_RW_FUNCS(hacr_el2)
  428. DEFINE_SYSREG_RW_FUNCS(hpfar_el2)
  429. DEFINE_SYSREG_RW_FUNCS(dbgvcr32_el2)
  430. DEFINE_RENAME_SYSREG_RW_FUNCS(ich_hcr_el2, ICH_HCR_EL2)
  431. DEFINE_RENAME_SYSREG_RW_FUNCS(ich_vmcr_el2, ICH_VMCR_EL2)
  432. DEFINE_SYSREG_READ_FUNC(isr_el1)
  433. DEFINE_SYSREG_RW_FUNCS(mdscr_el1)
  434. DEFINE_SYSREG_RW_FUNCS(mdcr_el2)
  435. DEFINE_SYSREG_RW_FUNCS(mdcr_el3)
  436. DEFINE_SYSREG_RW_FUNCS(hstr_el2)
  437. DEFINE_SYSREG_RW_FUNCS(pmcr_el0)
  438. DEFINE_SYSREG_RW_FUNCS(csselr_el1)
  439. DEFINE_SYSREG_RW_FUNCS(tpidrro_el0)
  440. DEFINE_SYSREG_RW_FUNCS(contextidr_el1)
  441. DEFINE_SYSREG_RW_FUNCS(spsr_abt)
  442. DEFINE_SYSREG_RW_FUNCS(spsr_und)
  443. DEFINE_SYSREG_RW_FUNCS(spsr_irq)
  444. DEFINE_SYSREG_RW_FUNCS(spsr_fiq)
  445. DEFINE_SYSREG_RW_FUNCS(dacr32_el2)
  446. DEFINE_SYSREG_RW_FUNCS(ifsr32_el2)
  447. /* GICv3 System Registers */
  448. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_sre_el1, ICC_SRE_EL1)
  449. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_sre_el2, ICC_SRE_EL2)
  450. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_sre_el3, ICC_SRE_EL3)
  451. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_pmr_el1, ICC_PMR_EL1)
  452. DEFINE_RENAME_SYSREG_READ_FUNC(icc_rpr_el1, ICC_RPR_EL1)
  453. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_igrpen1_el3, ICC_IGRPEN1_EL3)
  454. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_igrpen1_el1, ICC_IGRPEN1_EL1)
  455. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_igrpen0_el1, ICC_IGRPEN0_EL1)
  456. DEFINE_RENAME_SYSREG_READ_FUNC(icc_hppir0_el1, ICC_HPPIR0_EL1)
  457. DEFINE_RENAME_SYSREG_READ_FUNC(icc_hppir1_el1, ICC_HPPIR1_EL1)
  458. DEFINE_RENAME_SYSREG_READ_FUNC(icc_iar0_el1, ICC_IAR0_EL1)
  459. DEFINE_RENAME_SYSREG_READ_FUNC(icc_iar1_el1, ICC_IAR1_EL1)
  460. DEFINE_RENAME_SYSREG_WRITE_FUNC(icc_eoir0_el1, ICC_EOIR0_EL1)
  461. DEFINE_RENAME_SYSREG_WRITE_FUNC(icc_eoir1_el1, ICC_EOIR1_EL1)
  462. DEFINE_RENAME_SYSREG_WRITE_FUNC(icc_sgi0r_el1, ICC_SGI0R_EL1)
  463. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_sgi1r, ICC_SGI1R)
  464. DEFINE_RENAME_SYSREG_RW_FUNCS(icc_asgi1r, ICC_ASGI1R)
  465. DEFINE_RENAME_SYSREG_READ_FUNC(amcfgr_el0, AMCFGR_EL0)
  466. DEFINE_RENAME_SYSREG_READ_FUNC(amcgcr_el0, AMCGCR_EL0)
  467. DEFINE_RENAME_SYSREG_READ_FUNC(amcg1idr_el0, AMCG1IDR_EL0)
  468. DEFINE_RENAME_SYSREG_RW_FUNCS(amcr_el0, AMCR_EL0)
  469. DEFINE_RENAME_SYSREG_RW_FUNCS(amcntenclr0_el0, AMCNTENCLR0_EL0)
  470. DEFINE_RENAME_SYSREG_RW_FUNCS(amcntenset0_el0, AMCNTENSET0_EL0)
  471. DEFINE_RENAME_SYSREG_RW_FUNCS(amcntenclr1_el0, AMCNTENCLR1_EL0)
  472. DEFINE_RENAME_SYSREG_RW_FUNCS(amcntenset1_el0, AMCNTENSET1_EL0)
  473. DEFINE_RENAME_SYSREG_RW_FUNCS(pmblimitr_el1, PMBLIMITR_EL1)
  474. DEFINE_RENAME_SYSREG_WRITE_FUNC(zcr_el3, ZCR_EL3)
  475. DEFINE_RENAME_SYSREG_WRITE_FUNC(zcr_el2, ZCR_EL2)
  476. DEFINE_RENAME_IDREG_READ_FUNC(id_aa64smfr0_el1, ID_AA64SMFR0_EL1)
  477. DEFINE_RENAME_SYSREG_RW_FUNCS(smcr_el3, SMCR_EL3)
  478. DEFINE_RENAME_SYSREG_READ_FUNC(erridr_el1, ERRIDR_EL1)
  479. DEFINE_RENAME_SYSREG_WRITE_FUNC(errselr_el1, ERRSELR_EL1)
  480. DEFINE_RENAME_SYSREG_READ_FUNC(erxfr_el1, ERXFR_EL1)
  481. DEFINE_RENAME_SYSREG_RW_FUNCS(erxctlr_el1, ERXCTLR_EL1)
  482. DEFINE_RENAME_SYSREG_RW_FUNCS(erxstatus_el1, ERXSTATUS_EL1)
  483. DEFINE_RENAME_SYSREG_READ_FUNC(erxaddr_el1, ERXADDR_EL1)
  484. DEFINE_RENAME_SYSREG_READ_FUNC(erxmisc0_el1, ERXMISC0_EL1)
  485. DEFINE_RENAME_SYSREG_READ_FUNC(erxmisc1_el1, ERXMISC1_EL1)
  486. DEFINE_RENAME_SYSREG_RW_FUNCS(scxtnum_el2, SCXTNUM_EL2)
  487. DEFINE_RENAME_SYSREG_RW_FUNCS(scxtnum_el1, SCXTNUM_EL1)
  488. DEFINE_RENAME_SYSREG_RW_FUNCS(scxtnum_el0, SCXTNUM_EL0)
  489. /* Armv8.1 VHE Registers */
  490. DEFINE_RENAME_SYSREG_RW_FUNCS(contextidr_el2, CONTEXTIDR_EL2)
  491. DEFINE_RENAME_SYSREG_RW_FUNCS(ttbr1_el2, TTBR1_EL2)
  492. /* Armv8.2 ID Registers */
  493. DEFINE_RENAME_IDREG_READ_FUNC(id_aa64mmfr2_el1, ID_AA64MMFR2_EL1)
  494. /* Armv8.2 RAS Registers */
  495. DEFINE_RENAME_SYSREG_RW_FUNCS(disr_el1, DISR_EL1)
  496. DEFINE_RENAME_SYSREG_RW_FUNCS(vdisr_el2, VDISR_EL2)
  497. DEFINE_RENAME_SYSREG_RW_FUNCS(vsesr_el2, VSESR_EL2)
  498. /* Armv8.2 MPAM Registers */
  499. DEFINE_RENAME_SYSREG_READ_FUNC(mpamidr_el1, MPAMIDR_EL1)
  500. DEFINE_RENAME_SYSREG_RW_FUNCS(mpam3_el3, MPAM3_EL3)
  501. DEFINE_RENAME_SYSREG_RW_FUNCS(mpam2_el2, MPAM2_EL2)
  502. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamhcr_el2, MPAMHCR_EL2)
  503. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm0_el2, MPAMVPM0_EL2)
  504. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm1_el2, MPAMVPM1_EL2)
  505. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm2_el2, MPAMVPM2_EL2)
  506. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm3_el2, MPAMVPM3_EL2)
  507. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm4_el2, MPAMVPM4_EL2)
  508. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm5_el2, MPAMVPM5_EL2)
  509. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm6_el2, MPAMVPM6_EL2)
  510. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpm7_el2, MPAMVPM7_EL2)
  511. DEFINE_RENAME_SYSREG_RW_FUNCS(mpamvpmv_el2, MPAMVPMV_EL2)
  512. /* Armv8.3 Pointer Authentication Registers */
  513. DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeyhi_el1, APIAKeyHi_EL1)
  514. DEFINE_RENAME_SYSREG_RW_FUNCS(apiakeylo_el1, APIAKeyLo_EL1)
  515. /* Armv8.4 Data Independent Timing Register */
  516. DEFINE_RENAME_SYSREG_RW_FUNCS(dit, DIT)
  517. /* Armv8.4 FEAT_TRF Register */
  518. DEFINE_RENAME_SYSREG_RW_FUNCS(trfcr_el2, TRFCR_EL2)
  519. DEFINE_RENAME_SYSREG_RW_FUNCS(trfcr_el1, TRFCR_EL1)
  520. DEFINE_RENAME_SYSREG_RW_FUNCS(vncr_el2, VNCR_EL2)
  521. /* Armv8.5 MTE Registers */
  522. DEFINE_RENAME_SYSREG_RW_FUNCS(tfsre0_el1, TFSRE0_EL1)
  523. DEFINE_RENAME_SYSREG_RW_FUNCS(tfsr_el1, TFSR_EL1)
  524. DEFINE_RENAME_SYSREG_RW_FUNCS(rgsr_el1, RGSR_EL1)
  525. DEFINE_RENAME_SYSREG_RW_FUNCS(gcr_el1, GCR_EL1)
  526. DEFINE_RENAME_SYSREG_RW_FUNCS(tfsr_el2, TFSR_EL2)
  527. /* Armv8.5 FEAT_RNG Registers */
  528. DEFINE_RENAME_SYSREG_READ_FUNC(rndr, RNDR)
  529. DEFINE_RENAME_SYSREG_READ_FUNC(rndrrs, RNDRRS)
  530. /* Armv8.6 FEAT_FGT Registers */
  531. DEFINE_RENAME_SYSREG_RW_FUNCS(hdfgrtr_el2, HDFGRTR_EL2)
  532. DEFINE_RENAME_SYSREG_RW_FUNCS(hafgrtr_el2, HAFGRTR_EL2)
  533. DEFINE_RENAME_SYSREG_RW_FUNCS(hdfgwtr_el2, HDFGWTR_EL2)
  534. DEFINE_RENAME_SYSREG_RW_FUNCS(hfgitr_el2, HFGITR_EL2)
  535. DEFINE_RENAME_SYSREG_RW_FUNCS(hfgrtr_el2, HFGRTR_EL2)
  536. DEFINE_RENAME_SYSREG_RW_FUNCS(hfgwtr_el2, HFGWTR_EL2)
  537. /* ARMv8.6 FEAT_ECV Register */
  538. DEFINE_RENAME_SYSREG_RW_FUNCS(cntpoff_el2, CNTPOFF_EL2)
  539. /* FEAT_HCX Register */
  540. DEFINE_RENAME_SYSREG_RW_FUNCS(hcrx_el2, HCRX_EL2)
  541. /* Armv8.9 system registers */
  542. DEFINE_RENAME_IDREG_READ_FUNC(id_aa64mmfr3_el1, ID_AA64MMFR3_EL1)
  543. /* FEAT_TCR2 Register */
  544. DEFINE_RENAME_SYSREG_RW_FUNCS(tcr2_el1, TCR2_EL1)
  545. DEFINE_RENAME_SYSREG_RW_FUNCS(tcr2_el2, TCR2_EL2)
  546. /* FEAT_SxPIE Registers */
  547. DEFINE_RENAME_SYSREG_RW_FUNCS(pire0_el1, PIRE0_EL1)
  548. DEFINE_RENAME_SYSREG_RW_FUNCS(pire0_el2, PIRE0_EL2)
  549. DEFINE_RENAME_SYSREG_RW_FUNCS(pir_el1, PIR_EL1)
  550. DEFINE_RENAME_SYSREG_RW_FUNCS(pir_el2, PIR_EL2)
  551. DEFINE_RENAME_SYSREG_RW_FUNCS(s2pir_el2, S2PIR_EL2)
  552. /* FEAT_SxPOE Registers */
  553. DEFINE_RENAME_SYSREG_RW_FUNCS(por_el1, POR_EL1)
  554. DEFINE_RENAME_SYSREG_RW_FUNCS(por_el2, POR_EL2)
  555. DEFINE_RENAME_SYSREG_RW_FUNCS(s2por_el1, S2POR_EL1)
  556. /* FEAT_GCS Registers */
  557. DEFINE_RENAME_SYSREG_RW_FUNCS(gcscr_el2, GCSCR_EL2)
  558. DEFINE_RENAME_SYSREG_RW_FUNCS(gcspr_el2, GCSPR_EL2)
  559. DEFINE_RENAME_SYSREG_RW_FUNCS(gcscr_el1, GCSCR_EL1)
  560. DEFINE_RENAME_SYSREG_RW_FUNCS(gcscre0_el1, GCSCRE0_EL1)
  561. DEFINE_RENAME_SYSREG_RW_FUNCS(gcspr_el1, GCSPR_EL1)
  562. DEFINE_RENAME_SYSREG_RW_FUNCS(gcspr_el0, GCSPR_EL0)
  563. /* DynamIQ Control registers */
  564. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpwrdn_el1, CLUSTERPWRDN_EL1)
  565. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmcr_el1, CLUSTERPMCR_EL1)
  566. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmcntenset_el1, CLUSTERPMCNTENSET_EL1)
  567. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmccntr_el1, CLUSTERPMCCNTR_EL1)
  568. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmovsset_el1, CLUSTERPMOVSSET_EL1)
  569. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmovsclr_el1, CLUSTERPMOVSCLR_EL1)
  570. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmselr_el1, CLUSTERPMSELR_EL1)
  571. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmxevcntr_el1, CLUSTERPMXEVCNTR_EL1)
  572. DEFINE_RENAME_SYSREG_RW_FUNCS(clusterpmxevtyper_el1, CLUSTERPMXEVTYPER_EL1)
  573. /* CPU Power/Performance Management registers */
  574. DEFINE_RENAME_SYSREG_RW_FUNCS(cpuppmcr_el3, CPUPPMCR_EL3)
  575. DEFINE_RENAME_SYSREG_RW_FUNCS(cpumpmmcr_el3, CPUMPMMCR_EL3)
  576. /* Armv9.2 RME Registers */
  577. DEFINE_RENAME_SYSREG_RW_FUNCS(gptbr_el3, GPTBR_EL3)
  578. DEFINE_RENAME_SYSREG_RW_FUNCS(gpccr_el3, GPCCR_EL3)
  579. #define IS_IN_EL(x) \
  580. (GET_EL(read_CurrentEl()) == MODE_EL##x)
  581. #define IS_IN_EL1() IS_IN_EL(1)
  582. #define IS_IN_EL2() IS_IN_EL(2)
  583. #define IS_IN_EL3() IS_IN_EL(3)
  584. static inline unsigned int get_current_el(void)
  585. {
  586. return GET_EL(read_CurrentEl());
  587. }
  588. static inline unsigned int get_current_el_maybe_constant(void)
  589. {
  590. #if defined(IMAGE_AT_EL1)
  591. return 1;
  592. #elif defined(IMAGE_AT_EL2)
  593. return 2; /* no use-case in TF-A */
  594. #elif defined(IMAGE_AT_EL3)
  595. return 3;
  596. #else
  597. /*
  598. * If we do not know which exception level this is being built for
  599. * (e.g. built for library), fall back to run-time detection.
  600. */
  601. return get_current_el();
  602. #endif
  603. }
  604. /*
  605. * Check if an EL is implemented from AA64PFR0 register fields.
  606. */
  607. static inline uint64_t el_implemented(unsigned int el)
  608. {
  609. if (el > 3U) {
  610. return EL_IMPL_NONE;
  611. } else {
  612. unsigned int shift = ID_AA64PFR0_EL1_SHIFT * el;
  613. return (read_id_aa64pfr0_el1() >> shift) & ID_AA64PFR0_ELX_MASK;
  614. }
  615. }
  616. /*
  617. * TLBI PAALLOS instruction
  618. * (TLB Invalidate GPT Information by PA, All Entries, Outer Shareable)
  619. */
  620. static inline void tlbipaallos(void)
  621. {
  622. __asm__("sys #6, c8, c1, #4");
  623. }
  624. /*
  625. * TLBI RPALOS instructions
  626. * (TLB Range Invalidate GPT Information by PA, Last level, Outer Shareable)
  627. *
  628. * command SIZE, bits [47:44] field:
  629. * 0b0000 4KB
  630. * 0b0001 16KB
  631. * 0b0010 64KB
  632. * 0b0011 2MB
  633. * 0b0100 32MB
  634. * 0b0101 512MB
  635. * 0b0110 1GB
  636. * 0b0111 16GB
  637. * 0b1000 64GB
  638. * 0b1001 512GB
  639. */
  640. #define TLBI_SZ_4K 0UL
  641. #define TLBI_SZ_16K 1UL
  642. #define TLBI_SZ_64K 2UL
  643. #define TLBI_SZ_2M 3UL
  644. #define TLBI_SZ_32M 4UL
  645. #define TLBI_SZ_512M 5UL
  646. #define TLBI_SZ_1G 6UL
  647. #define TLBI_SZ_16G 7UL
  648. #define TLBI_SZ_64G 8UL
  649. #define TLBI_SZ_512G 9UL
  650. #define TLBI_ADDR_SHIFT U(12)
  651. #define TLBI_SIZE_SHIFT U(44)
  652. #define TLBIRPALOS(_addr, _size) \
  653. { \
  654. u_register_t arg = ((_addr) >> TLBI_ADDR_SHIFT) | \
  655. ((_size) << TLBI_SIZE_SHIFT); \
  656. __asm__("sys #6, c8, c4, #7, %0" : : "r" (arg)); \
  657. }
  658. /* Note: addr must be aligned to 4KB */
  659. static inline void tlbirpalos_4k(uintptr_t addr)
  660. {
  661. TLBIRPALOS(addr, TLBI_SZ_4K);
  662. }
  663. /* Note: addr must be aligned to 16KB */
  664. static inline void tlbirpalos_16k(uintptr_t addr)
  665. {
  666. TLBIRPALOS(addr, TLBI_SZ_16K);
  667. }
  668. /* Note: addr must be aligned to 64KB */
  669. static inline void tlbirpalos_64k(uintptr_t addr)
  670. {
  671. TLBIRPALOS(addr, TLBI_SZ_64K);
  672. }
  673. /* Note: addr must be aligned to 2MB */
  674. static inline void tlbirpalos_2m(uintptr_t addr)
  675. {
  676. TLBIRPALOS(addr, TLBI_SZ_2M);
  677. }
  678. /* Note: addr must be aligned to 32MB */
  679. static inline void tlbirpalos_32m(uintptr_t addr)
  680. {
  681. TLBIRPALOS(addr, TLBI_SZ_32M);
  682. }
  683. /* Note: addr must be aligned to 512MB */
  684. static inline void tlbirpalos_512m(uintptr_t addr)
  685. {
  686. TLBIRPALOS(addr, TLBI_SZ_512M);
  687. }
  688. /* Previously defined accessor functions with incomplete register names */
  689. #define read_current_el() read_CurrentEl()
  690. #define dsb() dsbsy()
  691. #define read_midr() read_midr_el1()
  692. #define read_mpidr() read_mpidr_el1()
  693. #define read_scr() read_scr_el3()
  694. #define write_scr(_v) write_scr_el3(_v)
  695. #define read_hcr() read_hcr_el2()
  696. #define write_hcr(_v) write_hcr_el2(_v)
  697. #define read_cpacr() read_cpacr_el1()
  698. #define write_cpacr(_v) write_cpacr_el1(_v)
  699. #define read_clusterpwrdn() read_clusterpwrdn_el1()
  700. #define write_clusterpwrdn(_v) write_clusterpwrdn_el1(_v)
  701. #define read_clusterpmcr() read_clusterpmcr_el1()
  702. #define write_clusterpmcr(_v) write_clusterpmcr_el1(_v)
  703. #define read_clusterpmcntenset() read_clusterpmcntenset_el1()
  704. #define write_clusterpmcntenset(_v) write_clusterpmcntenset_el1(_v)
  705. #define read_clusterpmccntr() read_clusterpmccntr_el1()
  706. #define write_clusterpmccntr(_v) write_clusterpmccntr_el1(_v)
  707. #define read_clusterpmovsset() read_clusterpmovsset_el1()
  708. #define write_clusterpmovsset(_v) write_clusterpmovsset_el1(_v)
  709. #define read_clusterpmovsclr() read_clusterpmovsclr_el1()
  710. #define write_clusterpmovsclr(_v) write_clusterpmovsclr_el1(_v)
  711. #define read_clusterpmselr() read_clusterpmselr_el1()
  712. #define write_clusterpmselr(_v) write_clusterpmselr_el1(_v)
  713. #define read_clusterpmxevcntr() read_clusterpmxevcntr_el1()
  714. #define write_clusterpmxevcntr(_v) write_clusterpmxevcntr_el1(_v)
  715. #define read_clusterpmxevtyper() read_clusterpmxevtyper_el1()
  716. #define write_clusterpmxevtyper(_v) write_clusterpmxevtyper_el1(_v)
  717. #if ERRATA_SPECULATIVE_AT
  718. /*
  719. * Assuming SCTLR.M bit is already enabled
  720. * 1. Enable page table walk by clearing TCR_EL1.EPDx bits
  721. * 2. Execute AT instruction for lower EL1/0
  722. * 3. Disable page table walk by setting TCR_EL1.EPDx bits
  723. */
  724. #define AT(_at_inst, _va) \
  725. { \
  726. assert((read_sctlr_el1() & SCTLR_M_BIT) != 0ULL); \
  727. write_tcr_el1(read_tcr_el1() & ~(TCR_EPD0_BIT | TCR_EPD1_BIT)); \
  728. isb(); \
  729. _at_inst(_va); \
  730. write_tcr_el1(read_tcr_el1() | (TCR_EPD0_BIT | TCR_EPD1_BIT)); \
  731. isb(); \
  732. }
  733. #else
  734. #define AT(_at_inst, _va) _at_inst(_va)
  735. #endif
  736. #endif /* ARCH_HELPERS_H */