diff options
author | Masahiro Yamada <yamada.masahiro@socionext.com> | 2020-03-26 13:18:48 +0900 |
---|---|---|
committer | Masahiro Yamada <yamada.masahiro@socionext.com> | 2020-03-31 11:51:56 +0900 |
commit | fd092be23982c160a3855f1e396b7311b5225bf9 (patch) | |
tree | ccb25a69b9729692c67157705c6ff0f430803c6e /include/arch | |
parent | d5e97a1d2c79121a68ed1c68bd079e80a5f4540a (diff) | |
download | arm-trusted-firmware-fd092be23982c160a3855f1e396b7311b5225bf9.tar.gz |
Add get_current_el_maybe_constant()
There are some cases where we want to run EL-dependent code in the
shared code.
We could use #ifdef, but it leaves slight possibility where we do not
know the exception level at the build-time (e.g. library code).
The counter approach is to use get_current_el(), but it is run-time
detection, so all EL code is linked, some of which might be unneeded.
This commit adds get_current_el_maybe_constant(). This is a static
inline function that returns a constant value if we know the exception
level at build-time. This is mostly the case.
if (get_current_el_maybe_constant() == 1) {
/* do something for EL1 */
} else if (get_current_el_maybe_constant() == 3) {
/* do something for EL3 */
}
If get_current_el_maybe_constant() is build-time constant, the compiler
will optimize out the unreachable code.
If such code is included from the library code, it is not built-time
constant. In this case, it falls back to get_current_el(), so it still
works.
Change-Id: Idb03c20342a5b5173fe2d6b40e1fac7998675ad3
Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com>
Diffstat (limited to 'include/arch')
-rw-r--r-- | include/arch/aarch64/arch_helpers.h | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/include/arch/aarch64/arch_helpers.h b/include/arch/aarch64/arch_helpers.h index 240c1fbda..7c30758d0 100644 --- a/include/arch/aarch64/arch_helpers.h +++ b/include/arch/aarch64/arch_helpers.h @@ -531,6 +531,23 @@ static inline unsigned int get_current_el(void) return GET_EL(read_CurrentEl()); } +static inline unsigned int get_current_el_maybe_constant(void) +{ +#if defined(IMAGE_AT_EL1) + return 1; +#elif defined(IMAGE_AT_EL2) + return 2; /* no use-case in TF-A */ +#elif defined(IMAGE_AT_EL3) + return 3; +#else + /* + * If we do not know which exception level this is being built for + * (e.g. built for library), fall back to run-time detection. + */ + return get_current_el(); +#endif +} + /* * Check if an EL is implemented from AA64PFR0 register fields. */ |