Browse Source

refactor(context-mgmt): move FEAT_HCX save/restore into C

At the moment we save and restore the HCRX_EL2 register in assembly, and
just depend on the build time flags.
To allow runtime checking, and to avoid too much code in assembly, move
that over to C, and use the new combined build/runtime feature check.

This also allows to drop the assert, since this should now be covered by
the different FEAT_STATE_x options.

Change-Id: I3e20b9ba17121d423cd08edc20bbf4e7ae7c0178
Signed-off-by: Andre Przywara <andre.przywara@arm.com>
pull/1993/head
Andre Przywara 2 years ago
parent
commit
c5a3ebbd3a
  1. 9
      bl31/bl31_main.c
  2. 4
      include/lib/el3_runtime/aarch64/context.h
  3. 17
      lib/el3_runtime/aarch64/context.S
  4. 18
      lib/el3_runtime/aarch64/context_mgmt.c

9
bl31/bl31_main.c

@ -93,15 +93,6 @@ void bl31_setup(u_register_t arg0, u_register_t arg1, u_register_t arg2,
/* Perform late platform-specific setup */ /* Perform late platform-specific setup */
bl31_plat_arch_setup(); bl31_plat_arch_setup();
#if ENABLE_FEAT_HCX
/*
* Assert that FEAT_HCX is supported on this system, without this check
* an exception would occur during context save/restore if enabled but
* not supported.
*/
assert(is_feat_hcx_supported());
#endif /* ENABLE_FEAT_HCX */
#if CTX_INCLUDE_PAUTH_REGS #if CTX_INCLUDE_PAUTH_REGS
/* /*
* Assert that the ARMv8.3-PAuth registers are present or an access * Assert that the ARMv8.3-PAuth registers are present or an access

4
include/lib/el3_runtime/aarch64/context.h

@ -547,10 +547,6 @@ void el2_sysregs_context_restore_trf(el2_sysregs_t *regs);
void el2_sysregs_context_save_csv2(el2_sysregs_t *regs); void el2_sysregs_context_save_csv2(el2_sysregs_t *regs);
void el2_sysregs_context_restore_csv2(el2_sysregs_t *regs); void el2_sysregs_context_restore_csv2(el2_sysregs_t *regs);
#endif /* ENABLE_FEAT_CSV2_2 */ #endif /* ENABLE_FEAT_CSV2_2 */
#if ENABLE_FEAT_HCX
void el2_sysregs_context_save_hcx(el2_sysregs_t *regs);
void el2_sysregs_context_restore_hcx(el2_sysregs_t *regs);
#endif /* ENABLE_FEAT_HCX */
#endif /* CTX_INCLUDE_EL2_REGS */ #endif /* CTX_INCLUDE_EL2_REGS */
#if CTX_INCLUDE_FPREGS #if CTX_INCLUDE_FPREGS

17
lib/el3_runtime/aarch64/context.S

@ -49,10 +49,6 @@
.global el2_sysregs_context_save_csv2 .global el2_sysregs_context_save_csv2
.global el2_sysregs_context_restore_csv2 .global el2_sysregs_context_restore_csv2
#endif /* ENABLE_FEAT_CSV2_2 */ #endif /* ENABLE_FEAT_CSV2_2 */
#if ENABLE_FEAT_HCX
.global el2_sysregs_context_save_hcx
.global el2_sysregs_context_restore_hcx
#endif /* ENABLE_FEAT_HCX */
#endif /* CTX_INCLUDE_EL2_REGS */ #endif /* CTX_INCLUDE_EL2_REGS */
.global el1_sysregs_context_save .global el1_sysregs_context_save
@ -432,19 +428,6 @@ func el2_sysregs_context_restore_csv2
endfunc el2_sysregs_context_restore_csv2 endfunc el2_sysregs_context_restore_csv2
#endif /* ENABLE_FEAT_CSV2_2 */ #endif /* ENABLE_FEAT_CSV2_2 */
#if ENABLE_FEAT_HCX
func el2_sysregs_context_save_hcx
mrs x14, hcrx_el2
str x14, [x0, #CTX_HCRX_EL2]
ret
endfunc el2_sysregs_context_save_hcx
func el2_sysregs_context_restore_hcx
ldr x14, [x0, #CTX_HCRX_EL2]
msr hcrx_el2, x14
ret
endfunc el2_sysregs_context_restore_hcx
#endif /* ENABLE_FEAT_HCX */
#endif /* CTX_INCLUDE_EL2_REGS */ #endif /* CTX_INCLUDE_EL2_REGS */
/* ------------------------------------------------------------------ /* ------------------------------------------------------------------

18
lib/el3_runtime/aarch64/context_mgmt.c

@ -320,9 +320,9 @@ static void setup_context_common(cpu_context_t *ctx, const entry_point_info_t *e
* If FEAT_HCX is enabled, enable access to HCRX_EL2 by setting * If FEAT_HCX is enabled, enable access to HCRX_EL2 by setting
* SCR_EL3.HXEn. * SCR_EL3.HXEn.
*/ */
#if ENABLE_FEAT_HCX if (is_feat_hcx_supported()) {
scr_el3 |= SCR_HXEn_BIT; scr_el3 |= SCR_HXEn_BIT;
#endif }
/* /*
* If FEAT_RNG_TRAP is enabled, all reads of the RNDR and RNDRRS * If FEAT_RNG_TRAP is enabled, all reads of the RNDR and RNDRRS
@ -873,9 +873,9 @@ void cm_el2_sysregs_context_save(uint32_t security_state)
#if ENABLE_FEAT_CSV2_2 #if ENABLE_FEAT_CSV2_2
el2_sysregs_context_save_csv2(el2_sysregs_ctx); el2_sysregs_context_save_csv2(el2_sysregs_ctx);
#endif #endif
#if ENABLE_FEAT_HCX if (is_feat_hcx_supported()) {
el2_sysregs_context_save_hcx(el2_sysregs_ctx); write_ctx_reg(el2_sysregs_ctx, CTX_HCRX_EL2, read_hcrx_el2());
#endif }
} }
} }
@ -931,9 +931,9 @@ void cm_el2_sysregs_context_restore(uint32_t security_state)
#if ENABLE_FEAT_CSV2_2 #if ENABLE_FEAT_CSV2_2
el2_sysregs_context_restore_csv2(el2_sysregs_ctx); el2_sysregs_context_restore_csv2(el2_sysregs_ctx);
#endif #endif
#if ENABLE_FEAT_HCX if (is_feat_hcx_supported()) {
el2_sysregs_context_restore_hcx(el2_sysregs_ctx); write_hcrx_el2(read_ctx_reg(el2_sysregs_ctx, CTX_HCRX_EL2));
#endif }
} }
} }
#endif /* CTX_INCLUDE_EL2_REGS */ #endif /* CTX_INCLUDE_EL2_REGS */

Loading…
Cancel
Save