Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 1 | /* |
Masahiro Yamada | 019b4f8 | 2020-04-02 15:35:19 +0900 | [diff] [blame] | 2 | * Copyright (c) 2016-2020, 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 | |
Antonio Nino Diaz | 4b32e62 | 2018-08-16 16:52:57 +0100 | [diff] [blame] | 10 | #include <cdefs.h> |
Masahiro Yamada | 019b4f8 | 2020-04-02 15:35:19 +0900 | [diff] [blame] | 11 | #include <stdbool.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 | |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 15 | #include <arch.h> |
| 16 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 17 | /********************************************************************** |
| 18 | * Macros which create inline functions to read or write CPU system |
| 19 | * registers |
| 20 | *********************************************************************/ |
| 21 | |
| 22 | #define _DEFINE_COPROCR_WRITE_FUNC(_name, coproc, opc1, CRn, CRm, opc2) \ |
| 23 | static inline void write_## _name(u_register_t v) \ |
| 24 | { \ |
| 25 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 26 | } |
| 27 | |
| 28 | #define _DEFINE_COPROCR_READ_FUNC(_name, coproc, opc1, CRn, CRm, opc2) \ |
| 29 | static inline u_register_t read_ ## _name(void) \ |
| 30 | { \ |
| 31 | u_register_t v; \ |
| 32 | __asm__ volatile ("mrc "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : "=r" (v));\ |
| 33 | return v; \ |
| 34 | } |
| 35 | |
| 36 | /* |
| 37 | * The undocumented %Q and %R extended asm are used to implemented the below |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 38 | * 64 bit `mrrc` and `mcrr` instructions. |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 39 | */ |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 40 | |
| 41 | #define _DEFINE_COPROCR_WRITE_FUNC_64(_name, coproc, opc1, CRm) \ |
| 42 | static inline void write64_## _name(uint64_t v) \ |
| 43 | { \ |
| 44 | __asm__ volatile ("mcrr "#coproc","#opc1", %Q0, %R0,"#CRm : : "r" (v));\ |
| 45 | } |
| 46 | |
| 47 | #define _DEFINE_COPROCR_READ_FUNC_64(_name, coproc, opc1, CRm) \ |
| 48 | static inline uint64_t read64_## _name(void) \ |
| 49 | { uint64_t v; \ |
| 50 | __asm__ volatile ("mrrc "#coproc","#opc1", %Q0, %R0,"#CRm : "=r" (v));\ |
| 51 | return v; \ |
| 52 | } |
| 53 | |
| 54 | #define _DEFINE_SYSREG_READ_FUNC(_name, _reg_name) \ |
| 55 | static inline u_register_t read_ ## _name(void) \ |
| 56 | { \ |
| 57 | u_register_t v; \ |
| 58 | __asm__ volatile ("mrs %0, " #_reg_name : "=r" (v)); \ |
| 59 | return v; \ |
| 60 | } |
| 61 | |
| 62 | #define _DEFINE_SYSREG_WRITE_FUNC(_name, _reg_name) \ |
| 63 | static inline void write_ ## _name(u_register_t v) \ |
| 64 | { \ |
| 65 | __asm__ volatile ("msr " #_reg_name ", %0" : : "r" (v)); \ |
| 66 | } |
| 67 | |
| 68 | #define _DEFINE_SYSREG_WRITE_CONST_FUNC(_name, _reg_name) \ |
| 69 | static inline void write_ ## _name(const u_register_t v) \ |
| 70 | { \ |
| 71 | __asm__ volatile ("msr " #_reg_name ", %0" : : "i" (v)); \ |
| 72 | } |
| 73 | |
| 74 | /* Define read function for coproc register */ |
| 75 | #define DEFINE_COPROCR_READ_FUNC(_name, ...) \ |
| 76 | _DEFINE_COPROCR_READ_FUNC(_name, __VA_ARGS__) |
| 77 | |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 78 | /* Define write function for coproc register */ |
| 79 | #define DEFINE_COPROCR_WRITE_FUNC(_name, ...) \ |
| 80 | _DEFINE_COPROCR_WRITE_FUNC(_name, __VA_ARGS__) |
| 81 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 82 | /* Define read & write function for coproc register */ |
| 83 | #define DEFINE_COPROCR_RW_FUNCS(_name, ...) \ |
| 84 | _DEFINE_COPROCR_READ_FUNC(_name, __VA_ARGS__) \ |
| 85 | _DEFINE_COPROCR_WRITE_FUNC(_name, __VA_ARGS__) |
| 86 | |
| 87 | /* Define 64 bit read function for coproc register */ |
| 88 | #define DEFINE_COPROCR_READ_FUNC_64(_name, ...) \ |
| 89 | _DEFINE_COPROCR_READ_FUNC_64(_name, __VA_ARGS__) |
| 90 | |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 91 | /* Define 64 bit write function for coproc register */ |
| 92 | #define DEFINE_COPROCR_WRITE_FUNC_64(_name, ...) \ |
| 93 | _DEFINE_COPROCR_WRITE_FUNC_64(_name, __VA_ARGS__) |
| 94 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 95 | /* Define 64 bit read & write function for coproc register */ |
| 96 | #define DEFINE_COPROCR_RW_FUNCS_64(_name, ...) \ |
| 97 | _DEFINE_COPROCR_READ_FUNC_64(_name, __VA_ARGS__) \ |
| 98 | _DEFINE_COPROCR_WRITE_FUNC_64(_name, __VA_ARGS__) |
| 99 | |
| 100 | /* Define read & write function for system register */ |
| 101 | #define DEFINE_SYSREG_RW_FUNCS(_name) \ |
| 102 | _DEFINE_SYSREG_READ_FUNC(_name, _name) \ |
| 103 | _DEFINE_SYSREG_WRITE_FUNC(_name, _name) |
| 104 | |
| 105 | /********************************************************************** |
| 106 | * Macros to create inline functions for tlbi operations |
| 107 | *********************************************************************/ |
| 108 | |
| 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));\ |
| 114 | } |
| 115 | |
Antonio Nino Diaz | ab37d15 | 2018-11-22 15:38:05 +0000 | [diff] [blame] | 116 | #define _DEFINE_BPIOP_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 117 | static inline void bpi##_op(void) \ |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 118 | { \ |
| 119 | u_register_t v = 0; \ |
| 120 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 121 | } |
| 122 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 123 | #define _DEFINE_TLBIOP_PARAM_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 124 | static inline void tlbi##_op(u_register_t v) \ |
| 125 | { \ |
| 126 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 127 | } |
| 128 | |
| 129 | /* Define function for simple TLBI operation */ |
| 130 | #define DEFINE_TLBIOP_FUNC(_op, ...) \ |
| 131 | _DEFINE_TLBIOP_FUNC(_op, __VA_ARGS__) |
| 132 | |
| 133 | /* Define function for TLBI operation with register parameter */ |
| 134 | #define DEFINE_TLBIOP_PARAM_FUNC(_op, ...) \ |
| 135 | _DEFINE_TLBIOP_PARAM_FUNC(_op, __VA_ARGS__) |
| 136 | |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 137 | /* Define function for simple BPI operation */ |
| 138 | #define DEFINE_BPIOP_FUNC(_op, ...) \ |
| 139 | _DEFINE_BPIOP_FUNC(_op, __VA_ARGS__) |
| 140 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 141 | /********************************************************************** |
| 142 | * Macros to create inline functions for DC operations |
| 143 | *********************************************************************/ |
| 144 | #define _DEFINE_DCOP_PARAM_FUNC(_op, coproc, opc1, CRn, CRm, opc2) \ |
| 145 | static inline void dc##_op(u_register_t v) \ |
| 146 | { \ |
| 147 | __asm__ volatile ("mcr "#coproc","#opc1",%0,"#CRn","#CRm","#opc2 : : "r" (v));\ |
| 148 | } |
| 149 | |
| 150 | /* Define function for DC operation with register parameter */ |
| 151 | #define DEFINE_DCOP_PARAM_FUNC(_op, ...) \ |
| 152 | _DEFINE_DCOP_PARAM_FUNC(_op, __VA_ARGS__) |
| 153 | |
| 154 | /********************************************************************** |
| 155 | * Macros to create inline functions for system instructions |
| 156 | *********************************************************************/ |
| 157 | /* Define function for simple system instruction */ |
| 158 | #define DEFINE_SYSOP_FUNC(_op) \ |
| 159 | static inline void _op(void) \ |
| 160 | { \ |
| 161 | __asm__ (#_op); \ |
| 162 | } |
| 163 | |
| 164 | |
| 165 | /* Define function for system instruction with type specifier */ |
| 166 | #define DEFINE_SYSOP_TYPE_FUNC(_op, _type) \ |
| 167 | static inline void _op ## _type(void) \ |
| 168 | { \ |
| 169 | __asm__ (#_op " " #_type); \ |
| 170 | } |
| 171 | |
| 172 | /* Define function for system instruction with register parameter */ |
| 173 | #define DEFINE_SYSOP_TYPE_PARAM_FUNC(_op, _type) \ |
| 174 | static inline void _op ## _type(u_register_t v) \ |
| 175 | { \ |
| 176 | __asm__ (#_op " " #_type ", %0" : : "r" (v)); \ |
| 177 | } |
| 178 | |
| 179 | void flush_dcache_range(uintptr_t addr, size_t size); |
| 180 | void clean_dcache_range(uintptr_t addr, size_t size); |
| 181 | void inv_dcache_range(uintptr_t addr, size_t size); |
Masahiro Yamada | 019b4f8 | 2020-04-02 15:35:19 +0900 | [diff] [blame] | 182 | bool is_dcache_enabled(void); |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 183 | |
Antonio Nino Diaz | e40306b | 2017-01-13 15:03:07 +0000 | [diff] [blame] | 184 | void dcsw_op_louis(u_register_t op_type); |
| 185 | void dcsw_op_all(u_register_t op_type); |
| 186 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 187 | void disable_mmu_secure(void); |
| 188 | void disable_mmu_icache_secure(void); |
| 189 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 190 | DEFINE_SYSOP_FUNC(wfi) |
| 191 | DEFINE_SYSOP_FUNC(wfe) |
| 192 | DEFINE_SYSOP_FUNC(sev) |
| 193 | DEFINE_SYSOP_TYPE_FUNC(dsb, sy) |
| 194 | DEFINE_SYSOP_TYPE_FUNC(dmb, sy) |
Yatharth Kochar | 2694cba | 2016-11-14 12:00:41 +0000 | [diff] [blame] | 195 | DEFINE_SYSOP_TYPE_FUNC(dmb, st) |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 196 | |
| 197 | /* dmb ld is not valid for armv7/thumb machines */ |
| 198 | #if ARM_ARCH_MAJOR != 7 |
Yatharth Kochar | 2694cba | 2016-11-14 12:00:41 +0000 | [diff] [blame] | 199 | DEFINE_SYSOP_TYPE_FUNC(dmb, ld) |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 200 | #endif |
| 201 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 202 | DEFINE_SYSOP_TYPE_FUNC(dsb, ish) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 203 | DEFINE_SYSOP_TYPE_FUNC(dsb, ishst) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 204 | DEFINE_SYSOP_TYPE_FUNC(dmb, ish) |
Jeenu Viswambharan | 6250507 | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 205 | DEFINE_SYSOP_TYPE_FUNC(dmb, ishst) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 206 | DEFINE_SYSOP_FUNC(isb) |
| 207 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 208 | void __dead2 smc(uint32_t r0, uint32_t r1, uint32_t r2, uint32_t r3, |
| 209 | uint32_t r4, uint32_t r5, uint32_t r6, uint32_t r7); |
| 210 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 211 | DEFINE_SYSREG_RW_FUNCS(spsr) |
| 212 | DEFINE_SYSREG_RW_FUNCS(cpsr) |
| 213 | |
| 214 | /******************************************************************************* |
| 215 | * System register accessor prototypes |
| 216 | ******************************************************************************/ |
| 217 | DEFINE_COPROCR_READ_FUNC(mpidr, MPIDR) |
| 218 | DEFINE_COPROCR_READ_FUNC(midr, MIDR) |
Antonio Nino Diaz | c326c34 | 2019-01-11 11:20:10 +0000 | [diff] [blame] | 219 | DEFINE_COPROCR_READ_FUNC(id_mmfr4, ID_MMFR4) |
Dimitris Papastamos | dda48b0 | 2017-10-17 14:03:14 +0100 | [diff] [blame] | 220 | DEFINE_COPROCR_READ_FUNC(id_pfr0, ID_PFR0) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 221 | DEFINE_COPROCR_READ_FUNC(id_pfr1, ID_PFR1) |
| 222 | DEFINE_COPROCR_READ_FUNC(isr, ISR) |
| 223 | DEFINE_COPROCR_READ_FUNC(clidr, CLIDR) |
| 224 | DEFINE_COPROCR_READ_FUNC_64(cntpct, CNTPCT_64) |
| 225 | |
| 226 | DEFINE_COPROCR_RW_FUNCS(scr, SCR) |
| 227 | DEFINE_COPROCR_RW_FUNCS(ctr, CTR) |
| 228 | DEFINE_COPROCR_RW_FUNCS(sctlr, SCTLR) |
Etienne Carriere | 70a004b | 2017-11-05 22:56:03 +0100 | [diff] [blame] | 229 | DEFINE_COPROCR_RW_FUNCS(actlr, ACTLR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 230 | DEFINE_COPROCR_RW_FUNCS(hsctlr, HSCTLR) |
| 231 | DEFINE_COPROCR_RW_FUNCS(hcr, HCR) |
| 232 | DEFINE_COPROCR_RW_FUNCS(hcptr, HCPTR) |
| 233 | DEFINE_COPROCR_RW_FUNCS(cntfrq, CNTFRQ) |
| 234 | DEFINE_COPROCR_RW_FUNCS(cnthctl, CNTHCTL) |
| 235 | DEFINE_COPROCR_RW_FUNCS(mair0, MAIR0) |
| 236 | DEFINE_COPROCR_RW_FUNCS(mair1, MAIR1) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 237 | DEFINE_COPROCR_RW_FUNCS(hmair0, HMAIR0) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 238 | DEFINE_COPROCR_RW_FUNCS(ttbcr, TTBCR) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 239 | DEFINE_COPROCR_RW_FUNCS(htcr, HTCR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 240 | DEFINE_COPROCR_RW_FUNCS(ttbr0, TTBR0) |
| 241 | DEFINE_COPROCR_RW_FUNCS_64(ttbr0, TTBR0_64) |
| 242 | DEFINE_COPROCR_RW_FUNCS(ttbr1, TTBR1) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 243 | DEFINE_COPROCR_RW_FUNCS_64(httbr, HTTBR_64) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 244 | DEFINE_COPROCR_RW_FUNCS(vpidr, VPIDR) |
| 245 | DEFINE_COPROCR_RW_FUNCS(vmpidr, VMPIDR) |
| 246 | DEFINE_COPROCR_RW_FUNCS_64(vttbr, VTTBR_64) |
| 247 | DEFINE_COPROCR_RW_FUNCS_64(ttbr1, TTBR1_64) |
| 248 | DEFINE_COPROCR_RW_FUNCS_64(cntvoff, CNTVOFF_64) |
| 249 | DEFINE_COPROCR_RW_FUNCS(csselr, CSSELR) |
David Cunado | fee8653 | 2017-04-13 22:38:29 +0100 | [diff] [blame] | 250 | DEFINE_COPROCR_RW_FUNCS(hstr, HSTR) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 251 | DEFINE_COPROCR_RW_FUNCS(cnthp_ctl_el2, CNTHP_CTL) |
| 252 | DEFINE_COPROCR_RW_FUNCS(cnthp_tval_el2, CNTHP_TVAL) |
| 253 | DEFINE_COPROCR_RW_FUNCS_64(cnthp_cval_el2, CNTHP_CVAL_64) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 254 | |
Antonio Nino Diaz | dc4ed3d | 2018-11-23 13:54:00 +0000 | [diff] [blame] | 255 | #define get_cntp_ctl_enable(x) (((x) >> CNTP_CTL_ENABLE_SHIFT) & \ |
| 256 | CNTP_CTL_ENABLE_MASK) |
| 257 | #define get_cntp_ctl_imask(x) (((x) >> CNTP_CTL_IMASK_SHIFT) & \ |
| 258 | CNTP_CTL_IMASK_MASK) |
| 259 | #define get_cntp_ctl_istatus(x) (((x) >> CNTP_CTL_ISTATUS_SHIFT) & \ |
| 260 | CNTP_CTL_ISTATUS_MASK) |
| 261 | |
| 262 | #define set_cntp_ctl_enable(x) ((x) |= U(1) << CNTP_CTL_ENABLE_SHIFT) |
| 263 | #define set_cntp_ctl_imask(x) ((x) |= U(1) << CNTP_CTL_IMASK_SHIFT) |
| 264 | |
| 265 | #define clr_cntp_ctl_enable(x) ((x) &= ~(U(1) << CNTP_CTL_ENABLE_SHIFT)) |
| 266 | #define clr_cntp_ctl_imask(x) ((x) &= ~(U(1) << CNTP_CTL_IMASK_SHIFT)) |
| 267 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 268 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el1, ICC_SRE) |
| 269 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el2, ICC_HSRE) |
| 270 | DEFINE_COPROCR_RW_FUNCS(icc_sre_el3, ICC_MSRE) |
| 271 | DEFINE_COPROCR_RW_FUNCS(icc_pmr_el1, ICC_PMR) |
Jeenu Viswambharan | b1e957e | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 272 | DEFINE_COPROCR_RW_FUNCS(icc_rpr_el1, ICC_RPR) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 273 | DEFINE_COPROCR_RW_FUNCS(icc_igrpen1_el3, ICC_MGRPEN1) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 274 | DEFINE_COPROCR_RW_FUNCS(icc_igrpen1_el1, ICC_IGRPEN1) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 275 | DEFINE_COPROCR_RW_FUNCS(icc_igrpen0_el1, ICC_IGRPEN0) |
| 276 | DEFINE_COPROCR_RW_FUNCS(icc_hppir0_el1, ICC_HPPIR0) |
| 277 | DEFINE_COPROCR_RW_FUNCS(icc_hppir1_el1, ICC_HPPIR1) |
| 278 | DEFINE_COPROCR_RW_FUNCS(icc_iar0_el1, ICC_IAR0) |
| 279 | DEFINE_COPROCR_RW_FUNCS(icc_iar1_el1, ICC_IAR1) |
| 280 | DEFINE_COPROCR_RW_FUNCS(icc_eoir0_el1, ICC_EOIR0) |
| 281 | DEFINE_COPROCR_RW_FUNCS(icc_eoir1_el1, ICC_EOIR1) |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 282 | DEFINE_COPROCR_RW_FUNCS_64(icc_sgi0r_el1, ICC_SGI0R_EL1_64) |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 283 | DEFINE_COPROCR_WRITE_FUNC_64(icc_sgi1r, ICC_SGI1R_EL1_64) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 284 | |
David Cunado | 5f55e28 | 2016-10-31 17:37:34 +0000 | [diff] [blame] | 285 | DEFINE_COPROCR_RW_FUNCS(hdcr, HDCR) |
David Cunado | c14b08e | 2016-11-25 00:21:59 +0000 | [diff] [blame] | 286 | DEFINE_COPROCR_RW_FUNCS(cnthp_ctl, CNTHP_CTL) |
David Cunado | 5f55e28 | 2016-10-31 17:37:34 +0000 | [diff] [blame] | 287 | DEFINE_COPROCR_READ_FUNC(pmcr, PMCR) |
| 288 | |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 289 | /* |
| 290 | * Address translation |
| 291 | */ |
| 292 | DEFINE_COPROCR_WRITE_FUNC(ats1cpr, ATS1CPR) |
| 293 | DEFINE_COPROCR_WRITE_FUNC(ats1hr, ATS1HR) |
Douglas Raillard | 7741463 | 2018-08-21 12:54:45 +0100 | [diff] [blame] | 294 | DEFINE_COPROCR_RW_FUNCS_64(par, PAR_64) |
| 295 | |
Etienne Carriere | 70a004b | 2017-11-05 22:56:03 +0100 | [diff] [blame] | 296 | DEFINE_COPROCR_RW_FUNCS(nsacr, NSACR) |
| 297 | |
| 298 | /* AArch32 coproc registers for 32bit MMU descriptor support */ |
| 299 | DEFINE_COPROCR_RW_FUNCS(prrr, PRRR) |
| 300 | DEFINE_COPROCR_RW_FUNCS(nmrr, NMRR) |
| 301 | DEFINE_COPROCR_RW_FUNCS(dacr, DACR) |
| 302 | |
Dimitris Papastamos | dda48b0 | 2017-10-17 14:03:14 +0100 | [diff] [blame] | 303 | DEFINE_COPROCR_RW_FUNCS(amcntenset0, AMCNTENSET0) |
| 304 | DEFINE_COPROCR_RW_FUNCS(amcntenset1, AMCNTENSET1) |
| 305 | DEFINE_COPROCR_RW_FUNCS(amcntenclr0, AMCNTENCLR0) |
| 306 | DEFINE_COPROCR_RW_FUNCS(amcntenclr1, AMCNTENCLR1) |
| 307 | |
Dimitris Papastamos | eaf3e6d | 2017-11-28 13:47:06 +0000 | [diff] [blame] | 308 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr00, AMEVCNTR00) |
| 309 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr01, AMEVCNTR01) |
| 310 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr02, AMEVCNTR02) |
| 311 | DEFINE_COPROCR_RW_FUNCS_64(amevcntr03, AMEVCNTR03) |
| 312 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 313 | /* |
| 314 | * TLBI operation prototypes |
| 315 | */ |
| 316 | DEFINE_TLBIOP_FUNC(all, TLBIALL) |
| 317 | DEFINE_TLBIOP_FUNC(allis, TLBIALLIS) |
| 318 | DEFINE_TLBIOP_PARAM_FUNC(mva, TLBIMVA) |
| 319 | DEFINE_TLBIOP_PARAM_FUNC(mvaa, TLBIMVAA) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 320 | DEFINE_TLBIOP_PARAM_FUNC(mvaais, TLBIMVAAIS) |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 321 | DEFINE_TLBIOP_PARAM_FUNC(mvahis, TLBIMVAHIS) |
Antonio Nino Diaz | ac99803 | 2017-02-27 17:23:54 +0000 | [diff] [blame] | 322 | |
| 323 | /* |
| 324 | * BPI operation prototypes. |
| 325 | */ |
| 326 | DEFINE_BPIOP_FUNC(allis, BPIALLIS) |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 327 | |
| 328 | /* |
| 329 | * DC operation prototypes |
| 330 | */ |
| 331 | DEFINE_DCOP_PARAM_FUNC(civac, DCCIMVAC) |
| 332 | DEFINE_DCOP_PARAM_FUNC(ivac, DCIMVAC) |
Ambroise Vincent | f5fdfbc | 2019-02-21 14:16:24 +0000 | [diff] [blame] | 333 | #if ERRATA_A53_819472 || ERRATA_A53_824069 || ERRATA_A53_827319 |
| 334 | DEFINE_DCOP_PARAM_FUNC(cvac, DCCIMVAC) |
| 335 | #else |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 336 | DEFINE_DCOP_PARAM_FUNC(cvac, DCCMVAC) |
Ambroise Vincent | f5fdfbc | 2019-02-21 14:16:24 +0000 | [diff] [blame] | 337 | #endif |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 338 | |
Madhukar Pappireddy | 90d6532 | 2019-10-30 14:24:39 -0500 | [diff] [blame] | 339 | /* |
| 340 | * DynamIQ Shared Unit power management |
| 341 | */ |
| 342 | DEFINE_COPROCR_RW_FUNCS(clusterpwrdn, CLUSTERPWRDN) |
| 343 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 344 | /* Previously defined accessor functions with incomplete register names */ |
| 345 | #define dsb() dsbsy() |
Etienne Carriere | a257986 | 2017-11-05 22:57:29 +0100 | [diff] [blame] | 346 | #define dmb() dmbsy() |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 347 | |
Jeenu Viswambharan | 1aa2db3 | 2018-09-05 14:23:27 +0100 | [diff] [blame] | 348 | /* dmb ld is not valid for armv7/thumb machines, so alias it to dmb */ |
| 349 | #if ARM_ARCH_MAJOR == 7 |
| 350 | #define dmbld() dmb() |
| 351 | #endif |
| 352 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 353 | #define IS_IN_SECURE() \ |
| 354 | (GET_NS_BIT(read_scr()) == 0) |
| 355 | |
Antonio Nino Diaz | 128de8d | 2018-08-07 19:59:49 +0100 | [diff] [blame] | 356 | #define IS_IN_HYP() (GET_M32(read_cpsr()) == MODE32_hyp) |
| 357 | #define IS_IN_SVC() (GET_M32(read_cpsr()) == MODE32_svc) |
| 358 | #define IS_IN_MON() (GET_M32(read_cpsr()) == MODE32_mon) |
| 359 | #define IS_IN_EL2() IS_IN_HYP() |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 360 | /* If EL3 is AArch32, then secure PL1 and monitor mode correspond to EL3 */ |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 361 | #define IS_IN_EL3() \ |
| 362 | ((GET_M32(read_cpsr()) == MODE32_mon) || \ |
| 363 | (IS_IN_SECURE() && (GET_M32(read_cpsr()) != MODE32_usr))) |
| 364 | |
Douglas Raillard | 7741463 | 2018-08-21 12:54:45 +0100 | [diff] [blame] | 365 | static inline unsigned int get_current_el(void) |
| 366 | { |
| 367 | if (IS_IN_EL3()) { |
| 368 | return 3U; |
| 369 | } else if (IS_IN_EL2()) { |
| 370 | return 2U; |
| 371 | } else { |
| 372 | return 1U; |
| 373 | } |
| 374 | } |
| 375 | |
Soby Mathew | c6820d1 | 2016-05-09 17:49:55 +0100 | [diff] [blame] | 376 | /* Macros for compatibility with AArch64 system registers */ |
| 377 | #define read_mpidr_el1() read_mpidr() |
| 378 | |
| 379 | #define read_scr_el3() read_scr() |
| 380 | #define write_scr_el3(_v) write_scr(_v) |
| 381 | |
| 382 | #define read_hcr_el2() read_hcr() |
| 383 | #define write_hcr_el2(_v) write_hcr(_v) |
| 384 | |
| 385 | #define read_cpacr_el1() read_cpacr() |
| 386 | #define write_cpacr_el1(_v) write_cpacr(_v) |
| 387 | |
| 388 | #define read_cntfrq_el0() read_cntfrq() |
| 389 | #define write_cntfrq_el0(_v) write_cntfrq(_v) |
| 390 | #define read_isr_el1() read_isr() |
| 391 | |
| 392 | #define read_cntpct_el0() read64_cntpct() |
| 393 | |
Yatharth Kochar | f528faf | 2016-06-28 16:58:26 +0100 | [diff] [blame] | 394 | #define read_ctr_el0() read_ctr() |
| 395 | |
Antonio Nino Diaz | 8257f5b | 2018-11-22 15:53:17 +0000 | [diff] [blame] | 396 | #define write_icc_sgi0r_el1(_v) write64_icc_sgi0r_el1(_v) |
| 397 | |
| 398 | #define read_daif() read_cpsr() |
| 399 | #define write_daif(flags) write_cpsr(flags) |
| 400 | |
| 401 | #define read_cnthp_cval_el2() read64_cnthp_cval_el2() |
| 402 | #define write_cnthp_cval_el2(v) write64_cnthp_cval_el2(v) |
| 403 | |
| 404 | #define read_amcntenset0_el0() read_amcntenset0() |
| 405 | #define read_amcntenset1_el0() read_amcntenset1() |
Jeenu Viswambharan | ab14e9b | 2017-09-22 08:32:09 +0100 | [diff] [blame] | 406 | |
Antonio Nino Diaz | b4e3e4b | 2018-11-23 15:04:01 +0000 | [diff] [blame] | 407 | /* Helper functions to manipulate CPSR */ |
| 408 | static inline void enable_irq(void) |
| 409 | { |
| 410 | /* |
| 411 | * The compiler memory barrier will prevent the compiler from |
| 412 | * scheduling non-volatile memory access after the write to the |
| 413 | * register. |
| 414 | * |
| 415 | * This could happen if some initialization code issues non-volatile |
| 416 | * accesses to an area used by an interrupt handler, in the assumption |
| 417 | * that it is safe as the interrupts are disabled at the time it does |
| 418 | * that (according to program order). However, non-volatile accesses |
| 419 | * are not necessarily in program order relatively with volatile inline |
| 420 | * assembly statements (and volatile accesses). |
| 421 | */ |
| 422 | COMPILER_BARRIER(); |
| 423 | __asm__ volatile ("cpsie i"); |
| 424 | isb(); |
| 425 | } |
| 426 | |
| 427 | static inline void enable_serror(void) |
| 428 | { |
| 429 | COMPILER_BARRIER(); |
| 430 | __asm__ volatile ("cpsie a"); |
| 431 | isb(); |
| 432 | } |
| 433 | |
| 434 | static inline void enable_fiq(void) |
| 435 | { |
| 436 | COMPILER_BARRIER(); |
| 437 | __asm__ volatile ("cpsie f"); |
| 438 | isb(); |
| 439 | } |
| 440 | |
| 441 | static inline void disable_irq(void) |
| 442 | { |
| 443 | COMPILER_BARRIER(); |
| 444 | __asm__ volatile ("cpsid i"); |
| 445 | isb(); |
| 446 | } |
| 447 | |
| 448 | static inline void disable_serror(void) |
| 449 | { |
| 450 | COMPILER_BARRIER(); |
| 451 | __asm__ volatile ("cpsid a"); |
| 452 | isb(); |
| 453 | } |
| 454 | |
| 455 | static inline void disable_fiq(void) |
| 456 | { |
| 457 | COMPILER_BARRIER(); |
| 458 | __asm__ volatile ("cpsid f"); |
| 459 | isb(); |
| 460 | } |
| 461 | |
Antonio Nino Diaz | 864ca6f | 2018-10-31 15:25:35 +0000 | [diff] [blame] | 462 | #endif /* ARCH_HELPERS_H */ |