1 /* 2 * Copyright 2019 The Hafnium Authors. 3 * 4 * Use of this source code is governed by a BSD-style 5 * license that can be found in the LICENSE file or at 6 * https://opensource.org/licenses/BSD-3-Clause. 7 */ 8 9 #pragma once 10 11 #include "hf/arch/barriers.h" 12 #include "hf/arch/types.h" 13 14 #include "msr.h" 15 #include "sysregs_defs.h" 16 17 /** HCR_EL2 */ 18 uintreg_t get_hcr_el2_value(ffa_vm_id_t vm_id, bool is_el0_partition); 19 20 /** MDCR_EL2 */ 21 uintreg_t get_mdcr_el2_value(void); 22 23 /** CPTR_EL2 */ 24 uintreg_t get_cptr_el2_value(void); 25 26 /** SCTLR_EL2 */ 27 uintreg_t get_sctlr_el2_value(bool is_el0_partition); 28 29 /** 30 * Branch Target Identification mechanism support in AArch64 state. 31 */ 32 bool is_arch_feat_bti_supported(void); 33 34 /** 35 * Returns true if the processor supports ARMv8.1 VHE. 36 */ has_vhe_support(void)37static inline bool has_vhe_support(void) 38 { 39 #if ENABLE_VHE == 1 40 return (((read_msr(ID_AA64MMFR1_EL1) >> ID_AA64MMFR1_EL1_VH_SHIFT) & 41 ID_AA64MMFR1_EL1_VH_MASK) == ID_AA64MMFR1_EL1_VH_SUPPORTED); 42 #else 43 return false; 44 #endif 45 } 46 vhe_switch_to_host_or_guest(bool guest)47static inline void vhe_switch_to_host_or_guest(bool guest) 48 { 49 if (has_vhe_support()) { 50 uint64_t hcr_el2 = read_msr(hcr_el2); 51 52 if (guest) { 53 hcr_el2 &= ~HCR_EL2_TGE; 54 } else { 55 hcr_el2 |= HCR_EL2_TGE; 56 } 57 write_msr(hcr_el2, hcr_el2); 58 isb(); 59 } 60 } 61 62 /** 63 * Returns true if the SVE feature is implemented. 64 */ 65 bool is_arch_feat_sve_supported(void); 66