target/arm: use arm_hcr_el2_eff() where applicable

This will simplify accessing HCR conditionally in secure state.

Backports e04a5752cb03e066d7b1e583e340c7982fcd5e4e
This commit is contained in:
Rémi Denis-Courmont 2021-03-04 13:53:28 -05:00 committed by Lioncash
parent 58af3e76e6
commit b657bfc59b

View file

@ -4125,16 +4125,16 @@ static CPAccessResult aa64_cacheop_pou_access(CPUARMState *env,
static int vae1_tlbmask(CPUARMState *env) static int vae1_tlbmask(CPUARMState *env)
{ {
/* Since we exclude secure first, we may read HCR_EL2 directly. */ uint64_t hcr = arm_hcr_el2_eff(env);
if (arm_is_secure_below_el3(env)) {
return ARMMMUIdxBit_SE10_1 | if ((hcr & (HCR_E2H | HCR_TGE)) == (HCR_E2H | HCR_TGE)) {
ARMMMUIdxBit_SE10_1_PAN |
ARMMMUIdxBit_SE10_0;
} else if ((env->cp15.hcr_el2 & (HCR_E2H | HCR_TGE))
== (HCR_E2H | HCR_TGE)) {
return ARMMMUIdxBit_E20_2 | return ARMMMUIdxBit_E20_2 |
ARMMMUIdxBit_E20_2_PAN | ARMMMUIdxBit_E20_2_PAN |
ARMMMUIdxBit_E20_0; ARMMMUIdxBit_E20_0;
} else if (arm_is_secure_below_el3(env)) {
return ARMMMUIdxBit_SE10_1 |
ARMMMUIdxBit_SE10_1_PAN |
ARMMMUIdxBit_SE10_0;
} else { } else {
return ARMMMUIdxBit_E10_1 | return ARMMMUIdxBit_E10_1 |
ARMMMUIdxBit_E10_1_PAN | ARMMMUIdxBit_E10_1_PAN |
@ -9680,6 +9680,8 @@ static inline uint64_t regime_sctlr(CPUARMState *env, ARMMMUIdx mmu_idx)
static inline bool regime_translation_disabled(CPUARMState *env, static inline bool regime_translation_disabled(CPUARMState *env,
ARMMMUIdx mmu_idx) ARMMMUIdx mmu_idx)
{ {
uint64_t hcr_el2;
if (arm_feature(env, ARM_FEATURE_M)) { if (arm_feature(env, ARM_FEATURE_M)) {
switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] & switch (env->v7m.mpu_ctrl[regime_is_secure(env, mmu_idx)] &
(R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) { (R_V7M_MPU_CTRL_ENABLE_MASK | R_V7M_MPU_CTRL_HFNMIENA_MASK)) {
@ -9699,19 +9701,21 @@ static inline bool regime_translation_disabled(CPUARMState *env,
} }
} }
hcr_el2 = arm_hcr_el2_eff(env);
if (mmu_idx == ARMMMUIdx_Stage2) { if (mmu_idx == ARMMMUIdx_Stage2) {
/* HCR.DC means HCR.VM behaves as 1 */ /* HCR.DC means HCR.VM behaves as 1 */
return (env->cp15.hcr_el2 & (HCR_DC | HCR_VM)) == 0; return (hcr_el2 & (HCR_DC | HCR_VM)) == 0;
} }
if (env->cp15.hcr_el2 & HCR_TGE) { if (hcr_el2 & HCR_TGE) {
/* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */ /* TGE means that NS EL0/1 act as if SCTLR_EL1.M is zero */
if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) == 1) { if (!regime_is_secure(env, mmu_idx) && regime_el(env, mmu_idx) == 1) {
return true; return true;
} }
} }
if ((env->cp15.hcr_el2 & HCR_DC) && arm_mmu_idx_is_stage1_of_2(mmu_idx)) { if ((hcr_el2 & HCR_DC) && arm_mmu_idx_is_stage1_of_2(mmu_idx)) {
/* HCR.DC means SCTLR_EL1.M behaves as 0 */ /* HCR.DC means SCTLR_EL1.M behaves as 0 */
return true; return true;
} }
@ -10072,7 +10076,8 @@ static hwaddr S1_ptw_translate(CPUARMState *env, ARMMMUIdx mmu_idx,
fi->s1ptw = true; fi->s1ptw = true;
return ~0; return ~0;
} }
if ((env->cp15.hcr_el2 & HCR_PTW) && (cacheattrs.attrs & 0xf0) == 0) { if ((arm_hcr_el2_eff(env) & HCR_PTW) &&
(cacheattrs.attrs & 0xf0) == 0) {
/* /*
* PTW set and S1 walk touched S2 Device memory: * PTW set and S1 walk touched S2 Device memory:
* generate Permission fault. * generate Permission fault.
@ -10509,7 +10514,7 @@ static uint8_t convert_stage2_attrs(CPUARMState *env, uint8_t s2attrs)
uint8_t hihint = 0, lohint = 0; uint8_t hihint = 0, lohint = 0;
if (hiattr != 0) { /* normal memory */ if (hiattr != 0) { /* normal memory */
if ((env->cp15.hcr_el2 & HCR_CD) != 0) { /* cache disabled */ if (arm_hcr_el2_eff(env) & HCR_CD) { /* cache disabled */
hiattr = loattr = 1; /* non-cacheable */ hiattr = loattr = 1; /* non-cacheable */
} else { } else {
if (hiattr != 1) { /* Write-through or write-back */ if (hiattr != 1) { /* Write-through or write-back */
@ -11835,7 +11840,7 @@ bool get_phys_addr(CPUARMState *env, target_ulong address,
} }
/* Combine the S1 and S2 cache attributes. */ /* Combine the S1 and S2 cache attributes. */
if (env->cp15.hcr_el2 & HCR_DC) { if (arm_hcr_el2_eff(env) & HCR_DC) {
/* /*
* HCR.DC forces the first stage attributes to * HCR.DC forces the first stage attributes to
* Normal Non-Shareable, * Normal Non-Shareable,