mirror of
https://github.com/ARM-software/arm-trusted-firmware.git
synced 2025-04-18 02:24:18 +00:00
Merge "refactor(cm): move mpam registers into el2 context" into integration
This commit is contained in:
commit
55c7efc494
3 changed files with 53 additions and 79 deletions
|
@ -298,27 +298,6 @@
|
|||
#define CTX_PAUTH_REGS_END U(0)
|
||||
#endif /* CTX_INCLUDE_PAUTH_REGS */
|
||||
|
||||
/*******************************************************************************
|
||||
* Registers related to ARMv8.2-MPAM.
|
||||
******************************************************************************/
|
||||
#define CTX_MPAM_REGS_OFFSET (CTX_PAUTH_REGS_OFFSET + CTX_PAUTH_REGS_END)
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
#define CTX_MPAM2_EL2 U(0x0)
|
||||
#define CTX_MPAMHCR_EL2 U(0x8)
|
||||
#define CTX_MPAMVPM0_EL2 U(0x10)
|
||||
#define CTX_MPAMVPM1_EL2 U(0x18)
|
||||
#define CTX_MPAMVPM2_EL2 U(0x20)
|
||||
#define CTX_MPAMVPM3_EL2 U(0x28)
|
||||
#define CTX_MPAMVPM4_EL2 U(0x30)
|
||||
#define CTX_MPAMVPM5_EL2 U(0x38)
|
||||
#define CTX_MPAMVPM6_EL2 U(0x40)
|
||||
#define CTX_MPAMVPM7_EL2 U(0x48)
|
||||
#define CTX_MPAMVPMV_EL2 U(0x50)
|
||||
#define CTX_MPAM_REGS_END U(0x60)
|
||||
#else
|
||||
#define CTX_MPAM_REGS_END U(0x0)
|
||||
#endif /* CTX_INCLUDE_MPAM_REGS */
|
||||
|
||||
/*******************************************************************************
|
||||
* Registers initialised in a per-world context.
|
||||
******************************************************************************/
|
||||
|
@ -355,9 +334,6 @@
|
|||
#if CTX_INCLUDE_PAUTH_REGS
|
||||
# define CTX_PAUTH_REGS_ALL (CTX_PAUTH_REGS_END >> DWORD_SHIFT)
|
||||
#endif
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
# define CTX_MPAM_REGS_ALL (CTX_MPAM_REGS_END >> DWORD_SHIFT)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* AArch64 general purpose register context structure. Usually x0-x18,
|
||||
|
@ -397,11 +373,6 @@ DEFINE_REG_STRUCT(cve_2018_3639, CTX_CVE_2018_3639_ALL);
|
|||
DEFINE_REG_STRUCT(pauth, CTX_PAUTH_REGS_ALL);
|
||||
#endif
|
||||
|
||||
/* Registers associated to ARMv8.2 MPAM */
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
DEFINE_REG_STRUCT(mpam, CTX_MPAM_REGS_ALL);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Macros to access members of any of the above structures using their
|
||||
* offsets
|
||||
|
@ -432,10 +403,6 @@ typedef struct cpu_context {
|
|||
pauth_t pauth_ctx;
|
||||
#endif
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
mpam_t mpam_ctx;
|
||||
#endif
|
||||
|
||||
#if CTX_INCLUDE_EL2_REGS
|
||||
el2_sysregs_t el2_sysregs_ctx;
|
||||
#endif
|
||||
|
@ -468,9 +435,6 @@ extern per_world_context_t per_world_context[CPU_DATA_CONTEXT_NUM];
|
|||
#if CTX_INCLUDE_PAUTH_REGS
|
||||
# define get_pauth_ctx(h) (&((cpu_context_t *) h)->pauth_ctx)
|
||||
#endif
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
# define get_mpam_ctx(h) (&((cpu_context_t *) h)->mpam_ctx)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Compile time assertions related to the 'cpu_context' structure to
|
||||
|
@ -499,11 +463,6 @@ CASSERT(CTX_PAUTH_REGS_OFFSET == __builtin_offsetof(cpu_context_t, pauth_ctx),
|
|||
assert_core_context_pauth_offset_mismatch);
|
||||
#endif /* CTX_INCLUDE_PAUTH_REGS */
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
CASSERT(CTX_MPAM_REGS_OFFSET == __builtin_offsetof(cpu_context_t, mpam_ctx),
|
||||
assert_core_context_mpam_offset_mismatch);
|
||||
#endif /* CTX_INCLUDE_MPAM_REGS */
|
||||
|
||||
/*
|
||||
* Helper macro to set the general purpose registers that correspond to
|
||||
* parameters in an aapcs_64 call i.e. x0-x7
|
||||
|
|
|
@ -114,6 +114,20 @@ typedef struct el2_gcs_regs {
|
|||
uint64_t gcspr_el2;
|
||||
} el2_gcs_regs_t;
|
||||
|
||||
typedef struct el2_mpam_regs {
|
||||
uint64_t mpam2_el2;
|
||||
uint64_t mpamhcr_el2;
|
||||
uint64_t mpamvpm0_el2;
|
||||
uint64_t mpamvpm1_el2;
|
||||
uint64_t mpamvpm2_el2;
|
||||
uint64_t mpamvpm3_el2;
|
||||
uint64_t mpamvpm4_el2;
|
||||
uint64_t mpamvpm5_el2;
|
||||
uint64_t mpamvpm6_el2;
|
||||
uint64_t mpamvpm7_el2;
|
||||
uint64_t mpamvpmv_el2;
|
||||
} el2_mpam_regs_t;
|
||||
|
||||
typedef struct el2_sysregs {
|
||||
|
||||
el2_common_regs_t common;
|
||||
|
@ -174,6 +188,10 @@ typedef struct el2_sysregs {
|
|||
el2_gcs_regs_t gcs;
|
||||
#endif
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
el2_mpam_regs_t mpam;
|
||||
#endif
|
||||
|
||||
} el2_sysregs_t;
|
||||
|
||||
/*
|
||||
|
@ -311,6 +329,15 @@ typedef struct el2_sysregs {
|
|||
#define write_el2_ctx_gcs(ctx, reg, val)
|
||||
#endif /* ENABLE_FEAT_GCS */
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
#define read_el2_ctx_mpam(ctx, reg) (((ctx)->mpam).reg)
|
||||
#define write_el2_ctx_mpam(ctx, reg, val) ((((ctx)->mpam).reg) \
|
||||
= (uint64_t) (val))
|
||||
#else
|
||||
#define read_el2_ctx_mpam(ctx, reg) ULL(0)
|
||||
#define write_el2_ctx_mpam(ctx, reg, val)
|
||||
#endif /* CTX_INCLUDE_MPAM_REGS */
|
||||
|
||||
#endif /* CTX_INCLUDE_EL2_REGS */
|
||||
/******************************************************************************/
|
||||
|
||||
|
|
|
@ -1046,13 +1046,11 @@ static void el2_sysregs_context_restore_fgt(el2_sysregs_t *ctx)
|
|||
write_hfgwtr_el2(read_el2_ctx_fgt(ctx, hfgwtr_el2));
|
||||
}
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
|
||||
static void el2_sysregs_context_save_mpam(mpam_t *ctx)
|
||||
static void el2_sysregs_context_save_mpam(el2_sysregs_t *ctx)
|
||||
{
|
||||
u_register_t mpam_idr = read_mpamidr_el1();
|
||||
|
||||
write_ctx_reg(ctx, CTX_MPAM2_EL2, read_mpam2_el2());
|
||||
write_el2_ctx_mpam(ctx, mpam2_el2, read_mpam2_el2());
|
||||
|
||||
/*
|
||||
* The context registers that we intend to save would be part of the
|
||||
|
@ -1066,9 +1064,9 @@ static void el2_sysregs_context_save_mpam(mpam_t *ctx)
|
|||
* MPAMHCR_EL2, MPAMVPMV_EL2 and MPAMVPM0_EL2 are always present if
|
||||
* MPAMIDR_HAS_HCR_BIT == 1.
|
||||
*/
|
||||
write_ctx_reg(ctx, CTX_MPAMHCR_EL2, read_mpamhcr_el2());
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM0_EL2, read_mpamvpm0_el2());
|
||||
write_ctx_reg(ctx, CTX_MPAMVPMV_EL2, read_mpamvpmv_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamhcr_el2, read_mpamhcr_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm0_el2, read_mpamvpm0_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpmv_el2, read_mpamvpmv_el2());
|
||||
|
||||
/*
|
||||
* The number of MPAMVPM registers is implementation defined, their
|
||||
|
@ -1076,71 +1074,67 @@ static void el2_sysregs_context_save_mpam(mpam_t *ctx)
|
|||
*/
|
||||
switch ((mpam_idr >> MPAMIDR_EL1_VPMR_MAX_SHIFT) & MPAMIDR_EL1_VPMR_MAX_MASK) {
|
||||
case 7:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM7_EL2, read_mpamvpm7_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm7_el2, read_mpamvpm7_el2());
|
||||
__fallthrough;
|
||||
case 6:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM6_EL2, read_mpamvpm6_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm6_el2, read_mpamvpm6_el2());
|
||||
__fallthrough;
|
||||
case 5:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM5_EL2, read_mpamvpm5_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm5_el2, read_mpamvpm5_el2());
|
||||
__fallthrough;
|
||||
case 4:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM4_EL2, read_mpamvpm4_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm4_el2, read_mpamvpm4_el2());
|
||||
__fallthrough;
|
||||
case 3:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM3_EL2, read_mpamvpm3_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm3_el2, read_mpamvpm3_el2());
|
||||
__fallthrough;
|
||||
case 2:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM2_EL2, read_mpamvpm2_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm2_el2, read_mpamvpm2_el2());
|
||||
__fallthrough;
|
||||
case 1:
|
||||
write_ctx_reg(ctx, CTX_MPAMVPM1_EL2, read_mpamvpm1_el2());
|
||||
write_el2_ctx_mpam(ctx, mpamvpm1_el2, read_mpamvpm1_el2());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
#endif /* CTX_INCLUDE_MPAM_REGS */
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
static void el2_sysregs_context_restore_mpam(mpam_t *ctx)
|
||||
static void el2_sysregs_context_restore_mpam(el2_sysregs_t *ctx)
|
||||
{
|
||||
u_register_t mpam_idr = read_mpamidr_el1();
|
||||
|
||||
write_mpam2_el2(read_ctx_reg(ctx, CTX_MPAM2_EL2));
|
||||
write_mpam2_el2(read_el2_ctx_mpam(ctx, mpam2_el2));
|
||||
|
||||
if ((mpam_idr & MPAMIDR_HAS_HCR_BIT) == 0U) {
|
||||
return;
|
||||
}
|
||||
|
||||
write_mpamhcr_el2(read_ctx_reg(ctx, CTX_MPAMHCR_EL2));
|
||||
write_mpamvpm0_el2(read_ctx_reg(ctx, CTX_MPAMVPM0_EL2));
|
||||
write_mpamvpmv_el2(read_ctx_reg(ctx, CTX_MPAMVPMV_EL2));
|
||||
write_mpamhcr_el2(read_el2_ctx_mpam(ctx, mpamhcr_el2));
|
||||
write_mpamvpm0_el2(read_el2_ctx_mpam(ctx, mpamvpm0_el2));
|
||||
write_mpamvpmv_el2(read_el2_ctx_mpam(ctx, mpamvpmv_el2));
|
||||
|
||||
switch ((mpam_idr >> MPAMIDR_EL1_VPMR_MAX_SHIFT) & MPAMIDR_EL1_VPMR_MAX_MASK) {
|
||||
case 7:
|
||||
write_mpamvpm7_el2(read_ctx_reg(ctx, CTX_MPAMVPM7_EL2));
|
||||
write_mpamvpm7_el2(read_el2_ctx_mpam(ctx, mpamvpm7_el2));
|
||||
__fallthrough;
|
||||
case 6:
|
||||
write_mpamvpm6_el2(read_ctx_reg(ctx, CTX_MPAMVPM6_EL2));
|
||||
write_mpamvpm6_el2(read_el2_ctx_mpam(ctx, mpamvpm6_el2));
|
||||
__fallthrough;
|
||||
case 5:
|
||||
write_mpamvpm5_el2(read_ctx_reg(ctx, CTX_MPAMVPM5_EL2));
|
||||
write_mpamvpm5_el2(read_el2_ctx_mpam(ctx, mpamvpm5_el2));
|
||||
__fallthrough;
|
||||
case 4:
|
||||
write_mpamvpm4_el2(read_ctx_reg(ctx, CTX_MPAMVPM4_EL2));
|
||||
write_mpamvpm4_el2(read_el2_ctx_mpam(ctx, mpamvpm4_el2));
|
||||
__fallthrough;
|
||||
case 3:
|
||||
write_mpamvpm3_el2(read_ctx_reg(ctx, CTX_MPAMVPM3_EL2));
|
||||
write_mpamvpm3_el2(read_el2_ctx_mpam(ctx, mpamvpm3_el2));
|
||||
__fallthrough;
|
||||
case 2:
|
||||
write_mpamvpm2_el2(read_ctx_reg(ctx, CTX_MPAMVPM2_EL2));
|
||||
write_mpamvpm2_el2(read_el2_ctx_mpam(ctx, mpamvpm2_el2));
|
||||
__fallthrough;
|
||||
case 1:
|
||||
write_mpamvpm1_el2(read_ctx_reg(ctx, CTX_MPAMVPM1_EL2));
|
||||
write_mpamvpm1_el2(read_el2_ctx_mpam(ctx, mpamvpm1_el2));
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif /* CTX_INCLUDE_MPAM_REGS */
|
||||
|
||||
/* ---------------------------------------------------------------------------
|
||||
* The following registers are not added:
|
||||
|
@ -1283,12 +1277,9 @@ void cm_el2_sysregs_context_save(uint32_t security_state)
|
|||
write_el2_ctx_mte2(el2_sysregs_ctx, tfsr_el2, read_tfsr_el2());
|
||||
}
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
if (is_feat_mpam_supported()) {
|
||||
mpam_t *mpam_ctx = get_mpam_ctx(ctx);
|
||||
el2_sysregs_context_save_mpam(mpam_ctx);
|
||||
el2_sysregs_context_save_mpam(el2_sysregs_ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_feat_fgt_supported()) {
|
||||
el2_sysregs_context_save_fgt(el2_sysregs_ctx);
|
||||
|
@ -1369,12 +1360,9 @@ void cm_el2_sysregs_context_restore(uint32_t security_state)
|
|||
write_tfsr_el2(read_el2_ctx_mte2(el2_sysregs_ctx, tfsr_el2));
|
||||
}
|
||||
|
||||
#if CTX_INCLUDE_MPAM_REGS
|
||||
if (is_feat_mpam_supported()) {
|
||||
mpam_t *mpam_ctx = get_mpam_ctx(ctx);
|
||||
el2_sysregs_context_restore_mpam(mpam_ctx);
|
||||
el2_sysregs_context_restore_mpam(el2_sysregs_ctx);
|
||||
}
|
||||
#endif
|
||||
|
||||
if (is_feat_fgt_supported()) {
|
||||
el2_sysregs_context_restore_fgt(el2_sysregs_ctx);
|
||||
|
|
Loading…
Add table
Reference in a new issue