Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 1 | /* |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 2 | * Copyright (c) 2016-2018, ARM Limited and Contributors. All rights reserved. |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 3 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 4 | * SPDX-License-Identifier: BSD-3-Clause |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 5 | */ |
| 6 | |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 7 | #ifndef ARCH_HELPERS_H |
| 8 | #define ARCH_HELPERS_H |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 9 | |
| 10 | #include <arch.h> /* for additional register definitions */ |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 11 | #include <cdefs.h> |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 12 | #include <stdint.h> |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 13 | #include <string.h> |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 14 | |
| 15 | /********************************************************************** |
| 16 | * Macros which create inline functions to read or write CPU system |
| 17 | * registers |
| 18 | *********************************************************************/ |
| 19 | |
| 20 | #define _DEFINE_COPROCR_WRITE_FUNC(_name, coproc, opc1, CRn, CRm, opc2) \ |
| 21 | static inline void write_## _name(u_register_t v) \ |
| 22 | { \ |
| 23 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 24 | } |
| 25 | |
| 26 | #define _DEFINE_COPROCR_READ_FUNC(_name, coproc, opc1, CRn, CRm, opc2) \ |
| 27 | static inline u_register_t read_ ## _name(void) \ |
| 28 | { \ |
| 29 | u_register_t v; \ |
| 30 | __asm__ volatile ("mrc "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : "=r" (v));\ |
| 31 | return v; \ |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * The undocumented %Q and %R extended asm are used to implemented the below |
| 36 | * 64 bit `mrrc` and `mcrr` instructions. It works only on Little Endian |
| 37 | * systems for GCC versions < 4.6. Above GCC 4.6, both Little Endian and |
| 38 | * Big Endian systems generate the right instruction encoding. |
| 39 | */ |
dp-arm | 320e844 | 2017-05-02 12:00:08 +0100 | [diff] [blame] | 40 | #if !(__clang__ || __GNUC__ > (4) || __GNUC__ == (4) && __GNUC_MINOR__ >= (6)) |
| 41 | #error "clang or GCC 4.6 or above is required to build AArch32 Trusted Firmware" |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 42 | #endif |
| 43 | |
| 44 | #define _DEFINE_COPROCR_WRITE_FUNC_64(_name, coproc, opc1, CRm) \ |
| 45 | static inline void write64_## _name(uint64_t v) \ |
| 46 | { \ |
| 47 | __asm__ volatile ("mcrr "#coproc","#opc1", %Q0, %R0,"#CRm : : "r" (v));\ |
| 48 | } |
| 49 | |
| 50 | #define _DEFINE_COPROCR_READ_FUNC_64(_name, coproc, opc1, CRm) \ |
| 51 | static inline uint64_t read64_## _name(void) \ |
| 52 | { uint64_t v; \ |
| 53 | __asm__ volatile ("mrrc "#coproc","#opc1", %Q0, %R0,"#CRm : "=r" (v));\ |
| 54 | return v; \ |
| 55 | } |
| 56 | |
| 57 | #define _DEFINE_SYSREG_READ_FUNC(_name, _reg_name) \ |
| 58 | static inline u_register_t read_ ## _name(void) \ |
| 59 | { \ |
| 60 | u_register_t v; \ |
| 61 | __asm__ volatile ("mrs %0, " #_reg_name : "=r" (v)); \ |
| 62 | return v; \ |
| 63 | } |
| 64 | |
| 65 | #define _DEFINE_SYSREG_WRITE_FUNC(_name, _reg_name) \ |
| 66 | static inline void write_ ## _name(u_register_t v) \ |
| 67 | { \ |
| 68 | __asm__ volatile ("msr " #_reg_name ", %0" : : "r" (v)); \ |
| 69 | } |
| 70 | |
| 71 | #define _DEFINE_SYSREG_WRITE_CONST_FUNC(_name, _reg_name) \ |
| 72 | static inline void write_ ## _name(const u_register_t v) \ |
| 73 | { \ |
| 74 | __asm__ volatile ("msr " #_reg_name ", %0" : : "i" (v)); \ |
| 75 | } |
| 76 | |
| 77 | /* Define read function for coproc register */ |
| 78 | #define DEFINE_COPROCR_READ_FUNC(_name, ...) \ |
| 79 | _DEFINE_COPROCR_READ_FUNC(_name, __VA_ARGS__) |
| 80 | |
| 81 | /* Define read & write function for coproc register */ |
| 82 | #define DEFINE_COPROCR_RW_FUNCS(_name, ...) \ |
| 83 | _DEFINE_COPROCR_READ_FUNC(_name, __VA_ARGS__) \ |
| 84 | _DEFINE_COPROCR_WRITE_FUNC(_name, __VA_ARGS__) |
| 85 | |
| 86 | /* Define 64 bit read function for coproc register */ |
| 87 | #define DEFINE_COPROCR_READ_FUNC_64(_name, ...) \ |
| 88 | _DEFINE_COPROCR_READ_FUNC_64(_name, __VA_ARGS__) |
| 89 | |
| 90 | /* Define 64 bit read & write function for coproc register */ |
| 91 | #define DEFINE_COPROCR_RW_FUNCS_64(_name, ...) \ |
| 92 | _DEFINE_COPROCR_READ_FUNC_64(_name, __VA_ARGS__) \ |
| 93 | _DEFINE_COPROCR_WRITE_FUNC_64(_name, __VA_ARGS__) |
| 94 | |
| 95 | /* Define read & write function for system register */ |
| 96 | #define DEFINE_SYSREG_RW_FUNCS(_name) \ |
| 97 | _DEFINE_SYSREG_READ_FUNC(_name, _name) \ |
| 98 | _DEFINE_SYSREG_WRITE_FUNC(_name, _name) |
| 99 | |
| 100 | /********************************************************************** |
| 101 | * Macros to create inline functions for tlbi operations |
| 102 | *********************************************************************/ |
| 103 | |
Dimitris Papastamos | 12f8be5 | 2017-06-20 09:25:10 +0100 | [diff] [blame] | 104 | #if ERRATA_A57_813419 |
| 105 | /* |
| 106 | * Define function for TLBI instruction with type specifier that |
| 107 | * implements the workaround for errata 813419 of Cortex-A57 |
| 108 | */ |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 109 | #define _DEFINE_TLBIOP_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 110 | static inline void tlbi##_op(void) \ |
| 111 | { \ |
| 112 | u_register_t v = 0; \ |
| 113 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
Dimitris Papastamos | 12f8be5 | 2017-06-20 09:25:10 +0100 | [diff] [blame] | 114 | __asm__ volatile ("dsb ish");\ |
| 115 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 116 | } |
| 117 | |
Dimitris Papastamos | 12f8be5 | 2017-06-20 09:25:10 +0100 | [diff] [blame] | 118 | #define _DEFINE_TLBIOP_PARAM_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 119 | static inline void tlbi##_op(u_register_t v) \ |
| 120 | { \ |
| 121 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 122 | __asm__ volatile ("dsb ish");\ |
| 123 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 124 | } |
| 125 | #else |
| 126 | #define _DEFINE_TLBIOP_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 127 | static inline void tlbi##_op(void) \ |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 128 | { \ |
| 129 | u_register_t v = 0; \ |
| 130 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 131 | } |
| 132 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 133 | #define _DEFINE_TLBIOP_PARAM_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 134 | static inline void tlbi##_op(u_register_t v) \ |
| 135 | { \ |
| 136 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 137 | } |
Dimitris Papastamos | 12f8be5 | 2017-06-20 09:25:10 +0100 | [diff] [blame] | 138 | #endif /* ERRATA_A57_813419 */ |
| 139 | |
| 140 | #define _DEFINE_BPIOP_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 141 | static inline void bpi##_op(void) \ |
| 142 | { \ |
| 143 | u_register_t v = 0; \ |
| 144 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 145 | } |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 146 | |
| 147 | /* Define function for simple TLBI operation */ |
| 148 | #define DEFINE_TLBIOP_FUNC(_op, ...) \ |
| 149 | _DEFINE_TLBIOP_FUNC(_op, __VA_ARGS__) |
| 150 | |
| 151 | /* Define function for TLBI operation with register parameter */ |
| 152 | #define DEFINE_TLBIOP_PARAM_FUNC(_op, ...) \ |
| 153 | _DEFINE_TLBIOP_PARAM_FUNC(_op, __VA_ARGS__) |
| 154 | |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 155 | /* Define function for simple BPI operation */ |
| 156 | #define DEFINE_BPIOP_FUNC(_op, ...) \ |
| 157 | _DEFINE_BPIOP_FUNC(_op, __VA_ARGS__) |
| 158 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 159 | /********************************************************************** |
| 160 | * Macros to create inline functions for DC operations |
| 161 | *********************************************************************/ |
| 162 | #define _DEFINE_DCOP_PARAM_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 163 | static inline void dc##_op(u_register_t v) \ |
| 164 | { \ |
| 165 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 166 | } |
| 167 | |
| 168 | /* Define function for DC operation with register parameter */ |
| 169 | #define DEFINE_DCOP_PARAM_FUNC(_op, ...) \ |
| 170 | _DEFINE_DCOP_PARAM_FUNC(_op, __VA_ARGS__) |
| 171 | |
| 172 | /********************************************************************** |
| 173 | * Macros to create inline functions for system instructions |
| 174 | *********************************************************************/ |
| 175 | /* Define function for simple system instruction */ |
| 176 | #define DEFINE_SYSOP_FUNC(_op) \ |
| 177 | static inline void _op(void) \ |
| 178 | { \ |
| 179 | __asm__ (#_op); \ |
| 180 | } |
| 181 | |
| 182 | |
| 183 | /* Define function for system instruction with type specifier */ |
| 184 | #define DEFINE_SYSOP_TYPE_FUNC(_op, _type) \ |
| 185 | static inline void _op ## _type(void) \ |
| 186 | { \ |
| 187 | __asm__ (#_op " " #_type); \ |
| 188 | } |
| 189 | |
| 190 | /* Define function for system instruction with register parameter */ |
| 191 | #define DEFINE_SYSOP_TYPE_PARAM_FUNC(_op, _type) \ |
| 192 | static inline void _op ## _type(u_register_t v) \ |
| 193 | { \ |
| 194 | __asm__ (#_op " " #_type ", %0" : : "r" (v)); \ |
| 195 | } |
| 196 | |
| 197 | void flush_dcache_range(uintptr_t addr, size_t size); |
| 198 | void clean_dcache_range(uintptr_t addr, size_t size); |
| 199 | void inv_dcache_range(uintptr_t addr, size_t size); |
| 200 | |
Antonio Nino Diaz | e40306b | 2017-01-13 15:03:07 +0000 | [diff] [blame] | 201 | void dcsw_op_louis(u_register_t op_type); |
| 202 | void dcsw_op_all(u_register_t op_type); |
| 203 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 204 | void disable_mmu_secure(void); |
| 205 | void disable_mmu_icache_secure(void); |
| 206 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 207 | DEFINE_SYSOP_FUNC(wfi) |
| 208 | DEFINE_SYSOP_FUNC(wfe) |
| 209 | DEFINE_SYSOP_FUNC(sev) |
| 210 | DEFINE_SYSOP_TYPE_FUNC(dsb, sy) |
| 211 | DEFINE_SYSOP_TYPE_FUNC(dmb, sy) |
Yatharth Kochar | 2694cba | 2016-11-14 12:00:41 +0000 | [diff] [blame] | 212 | DEFINE_SYSOP_TYPE_FUNC(dmb, st) |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 213 | |
| 214 | /* dmb ld is not valid for armv7/thumb machines */ |
| 215 | #if ARM_ARCH_MAJOR != 7 |
Yatharth Kochar | 2694cba | 2016-11-14 12:00:41 +0000 | [diff] [blame] | 216 | DEFINE_SYSOP_TYPE_FUNC(dmb, ld) |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 217 | #endif |
| 218 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 219 | DEFINE_SYSOP_TYPE_FUNC(dsb, ish) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 220 | DEFINE_SYSOP_TYPE_FUNC(dsb, ishst) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 221 | DEFINE_SYSOP_TYPE_FUNC(dmb, ish) |
Jeenu Viswambharan | 6250507 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 222 | DEFINE_SYSOP_TYPE_FUNC(dmb, ishst) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 223 | DEFINE_SYSOP_FUNC(isb) |
| 224 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 225 | void __dead2 smc(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3, |
| 226 | uint32_t r4, uint32_t r5, uint32_t r6, uint32_t r7); |
| 227 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 228 | DEFINE_SYSREG_RW_FUNCS(spsr) |
| 229 | DEFINE_SYSREG_RW_FUNCS(cpsr) |
| 230 | |
| 231 | /******************************************************************************* |
| 232 | * System register accessor prototypes |
| 233 | ******************************************************************************/ |
| 234 | DEFINE_COPROCR_READ_FUNC(mpidr, MPIDR) |
| 235 | DEFINE_COPROCR_READ_FUNC(midr, MIDR) |
Dimitris Papastamos | dda48b0 | 2017-10-17 14:03:14 +0100 | [diff] [blame] | 236 | DEFINE_COPROCR_READ_FUNC(id_pfr0, ID_PFR0) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 237 | DEFINE_COPROCR_READ_FUNC(id_pfr1, ID_PFR1) |
| 238 | DEFINE_COPROCR_READ_FUNC(isr, ISR) |
| 239 | DEFINE_COPROCR_READ_FUNC(clidr, CLIDR) |
| 240 | DEFINE_COPROCR_READ_FUNC_64(cntpct, CNTPCT_64) |
| 241 | |
| 242 | DEFINE_COPROCR_RW_FUNCS(scr, SCR) |
| 243 | DEFINE_COPROCR_RW_FUNCS(ctr, CTR) |
| 244 | DEFINE_COPROCR_RW_FUNCS(sctlr, SCTLR) |
Etienne Carriere | 70a004b | 2017-11-05 22:56:03 +0100 | [diff] [blame] | 245 | DEFINE_COPROCR_RW_FUNCS(actlr, ACTLR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 246 | DEFINE_COPROCR_RW_FUNCS(hsctlr, HSCTLR) |
| 247 | DEFINE_COPROCR_RW_FUNCS(hcr, HCR) |
| 248 | DEFINE_COPROCR_RW_FUNCS(hcptr, HCPTR) |
| 249 | DEFINE_COPROCR_RW_FUNCS(cntfrq, CNTFRQ) |
| 250 | DEFINE_COPROCR_RW_FUNCS(cnthctl, CNTHCTL) |
| 251 | DEFINE_COPROCR_RW_FUNCS(mair0, MAIR0) |
| 252 | DEFINE_COPROCR_RW_FUNCS(mair1, MAIR1) |
| 253 | DEFINE_COPROCR_RW_FUNCS(ttbcr, TTBCR) |
| 254 | DEFINE_COPROCR_RW_FUNCS(ttbr0, TTBR0) |
| 255 | DEFINE_COPROCR_RW_FUNCS_64(ttbr0, TTBR0_64) |
| 256 | DEFINE_COPROCR_RW_FUNCS(ttbr1, TTBR1) |
| 257 | DEFINE_COPROCR_RW_FUNCS(vpidr, VPIDR) |
| 258 | DEFINE_COPROCR_RW_FUNCS(vmpidr, VMPIDR) |
| 259 | DEFINE_COPROCR_RW_FUNCS_64(vttbr, VTTBR_64) |
| 260 | DEFINE_COPROCR_RW_FUNCS_64(ttbr1, TTBR1_64) |
| 261 | DEFINE_COPROCR_RW_FUNCS_64(cntvoff, CNTVOFF_64) |
| 262 | DEFINE_COPROCR_RW_FUNCS(csselr, CSSELR) |
David Cunado | fee8653 | 2017-04-13 22:38:29 +0100 | [diff] [blame] | 263 | DEFINE_COPROCR_RW_FUNCS(hstr, HSTR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 264 | |
| 265 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el1, ICC_SRE) |
| 266 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el2, ICC_HSRE) |
| 267 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el3, ICC_MSRE) |
| 268 | DEFINE_COPROCR_RW_FUNCS(icc_pmr_el1, ICC_PMR) |
Jeenu Viswambharan | b1e957e | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 269 | DEFINE_COPROCR_RW_FUNCS(icc_rpr_el1, ICC_RPR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 270 | DEFINE_COPROCR_RW_FUNCS(icc_igrpen1_el3, ICC_MGRPEN1) |
| 271 | DEFINE_COPROCR_RW_FUNCS(icc_igrpen0_el1, ICC_IGRPEN0) |
| 272 | DEFINE_COPROCR_RW_FUNCS(icc_hppir0_el1, ICC_HPPIR0) |
| 273 | DEFINE_COPROCR_RW_FUNCS(icc_hppir1_el1, ICC_HPPIR1) |
| 274 | DEFINE_COPROCR_RW_FUNCS(icc_iar0_el1, ICC_IAR0) |
| 275 | DEFINE_COPROCR_RW_FUNCS(icc_iar1_el1, ICC_IAR1) |
| 276 | DEFINE_COPROCR_RW_FUNCS(icc_eoir0_el1, ICC_EOIR0) |
| 277 | DEFINE_COPROCR_RW_FUNCS(icc_eoir1_el1, ICC_EOIR1) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 278 | DEFINE_COPROCR_RW_FUNCS_64(icc_sgi0r_el1, ICC_SGI0R_EL1_64) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 279 | |
David Cunado | 5f55e28 | 2016-10-31 17:37:34 +0000 | [diff] [blame] | 280 | DEFINE_COPROCR_RW_FUNCS(hdcr, HDCR) |
David Cunado | c14b08e | 2016-11-25 00:21:59 +0000 | [diff] [blame] | 281 | DEFINE_COPROCR_RW_FUNCS(cnthp_ctl, CNTHP_CTL) |
David Cunado | 5f55e28 | 2016-10-31 17:37:34 +0000 | [diff] [blame] | 282 | DEFINE_COPROCR_READ_FUNC(pmcr, PMCR) |
| 283 | |
Douglas Raillard | 7741463 | 2018-08-21 12:54:45 +0100 | [diff] [blame] | 284 | DEFINE_COPROCR_RW_FUNCS(ats1cpr, ATS1CPR) |
| 285 | DEFINE_COPROCR_RW_FUNCS(ats1hr, ATS1HR) |
| 286 | DEFINE_COPROCR_RW_FUNCS_64(par, PAR_64) |
| 287 | |
Etienne Carriere | 70a004b | 2017-11-05 22:56:03 +0100 | [diff] [blame] | 288 | DEFINE_COPROCR_RW_FUNCS(nsacr, NSACR) |
| 289 | |
| 290 | /* AArch32 coproc registers for 32bit MMU descriptor support */ |
| 291 | DEFINE_COPROCR_RW_FUNCS(prrr, PRRR) |
| 292 | DEFINE_COPROCR_RW_FUNCS(nmrr, NMRR) |
| 293 | DEFINE_COPROCR_RW_FUNCS(dacr, DACR) |
| 294 | |
Dimitris Papastamos | dda48b0 | 2017-10-17 14:03:14 +0100 | [diff] [blame] | 295 | DEFINE_COPROCR_RW_FUNCS(amcntenset0, AMCNTENSET0) |
| 296 | DEFINE_COPROCR_RW_FUNCS(amcntenset1, AMCNTENSET1) |
| 297 | DEFINE_COPROCR_RW_FUNCS(amcntenclr0, AMCNTENCLR0) |
| 298 | DEFINE_COPROCR_RW_FUNCS(amcntenclr1, AMCNTENCLR1) |
| 299 | |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 300 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr00, AMEVCNTR00) |
| 301 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr01, AMEVCNTR01) |
| 302 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr02, AMEVCNTR02) |
| 303 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr03, AMEVCNTR03) |
| 304 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 305 | /* |
| 306 | * TLBI operation prototypes |
| 307 | */ |
| 308 | DEFINE_TLBIOP_FUNC(all, TLBIALL) |
| 309 | DEFINE_TLBIOP_FUNC(allis, TLBIALLIS) |
| 310 | DEFINE_TLBIOP_PARAM_FUNC(mva, TLBIMVA) |
| 311 | DEFINE_TLBIOP_PARAM_FUNC(mvaa, TLBIMVAA) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 312 | DEFINE_TLBIOP_PARAM_FUNC(mvaais, TLBIMVAAIS) |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 313 | DEFINE_TLBIOP_PARAM_FUNC(mvahis, TLBIMVAHIS) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 314 | |
| 315 | /* |
| 316 | * BPI operation prototypes. |
| 317 | */ |
| 318 | DEFINE_BPIOP_FUNC(allis, BPIALLIS) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 319 | |
| 320 | /* |
| 321 | * DC operation prototypes |
| 322 | */ |
| 323 | DEFINE_DCOP_PARAM_FUNC(civac, DCCIMVAC) |
| 324 | DEFINE_DCOP_PARAM_FUNC(ivac, DCIMVAC) |
| 325 | DEFINE_DCOP_PARAM_FUNC(cvac, DCCMVAC) |
| 326 | |
| 327 | /* Previously defined accessor functions with incomplete register names */ |
| 328 | #define dsb() dsbsy() |
Etienne Carriere | a257986 | 2017-11-05 22:57:29 +0100 | [diff] [blame] | 329 | #define dmb() dmbsy() |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 330 | |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 331 | /* dmb ld is not valid for armv7/thumb machines, so alias it to dmb */ |
| 332 | #if ARM_ARCH_MAJOR == 7 |
| 333 | #define dmbld() dmb() |
| 334 | #endif |
| 335 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 336 | #define IS_IN_SECURE() \ |
| 337 | (GET_NS_BIT(read_scr()) == 0) |
| 338 | |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 339 | #define IS_IN_HYP() (GET_M32(read_cpsr()) == MODE32_hyp) |
| 340 | #define IS_IN_SVC() (GET_M32(read_cpsr()) == MODE32_svc) |
| 341 | #define IS_IN_MON() (GET_M32(read_cpsr()) == MODE32_mon) |
| 342 | #define IS_IN_EL2() IS_IN_HYP() |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 343 | /* |
| 344 | * If EL3 is AArch32, then secure PL1 and monitor mode correspond to EL3 |
| 345 | */ |
| 346 | #define IS_IN_EL3() \ |
| 347 | ((GET_M32(read_cpsr()) == MODE32_mon) || \ |
| 348 | (IS_IN_SECURE() && (GET_M32(read_cpsr()) != MODE32_usr))) |
| 349 | |
Douglas Raillard | 7741463 | 2018-08-21 12:54:45 +0100 | [diff] [blame] | 350 | static inline unsigned int get_current_el(void) |
| 351 | { |
| 352 | if (IS_IN_EL3()) { |
| 353 | return 3U; |
| 354 | } else if (IS_IN_EL2()) { |
| 355 | return 2U; |
| 356 | } else { |
| 357 | return 1U; |
| 358 | } |
| 359 | } |
| 360 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 361 | /* Macros for compatibility with AArch64 system registers */ |
| 362 | #define read_mpidr_el1() read_mpidr() |
| 363 | |
| 364 | #define read_scr_el3() read_scr() |
| 365 | #define write_scr_el3(_v) write_scr(_v) |
| 366 | |
| 367 | #define read_hcr_el2() read_hcr() |
| 368 | #define write_hcr_el2(_v) write_hcr(_v) |
| 369 | |
| 370 | #define read_cpacr_el1() read_cpacr() |
| 371 | #define write_cpacr_el1(_v) write_cpacr(_v) |
| 372 | |
| 373 | #define read_cntfrq_el0() read_cntfrq() |
| 374 | #define write_cntfrq_el0(_v) write_cntfrq(_v) |
| 375 | #define read_isr_el1() read_isr() |
| 376 | |
| 377 | #define read_cntpct_el0() read64_cntpct() |
| 378 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 379 | #define read_ctr_el0() read_ctr() |
| 380 | |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 381 | #define write_icc_sgi0r_el1(_v) \ |
| 382 | write64_icc_sgi0r_el1(_v) |
| 383 | |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 384 | #endif /* ARCH_HELPERS_H */ |