1 /* 2 * Copyright 2024 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 #include "msr.h" 10 #include "sysregs.h" 11 arch_sme_disable_traps(void)12void arch_sme_disable_traps(void) 13 { 14 uint64_t cptr_el2_val; 15 16 /* Disable SME traps at EL2/1/0. */ 17 cptr_el2_val = read_msr(CPTR_EL2); 18 if (has_vhe_support()) { 19 cptr_el2_val |= CPTR_EL2_SME_VHE_SMEN; 20 } else { 21 cptr_el2_val &= ~CPTR_EL2_TSM; 22 } 23 24 write_msr(CPTR_EL2, cptr_el2_val); 25 isb(); 26 } 27 arch_sme_enable_traps(void)28void arch_sme_enable_traps(void) 29 { 30 uint64_t cptr_el2_val; 31 32 /* Enable SME traps at EL2/1/0. */ 33 cptr_el2_val = read_msr(CPTR_EL2); 34 if (has_vhe_support()) { 35 cptr_el2_val &= ~CPTR_EL2_SME_VHE_SMEN; 36 } else { 37 cptr_el2_val |= CPTR_EL2_TSM; 38 } 39 40 write_msr(CPTR_EL2, cptr_el2_val); 41 isb(); 42 } 43 arch_sme_configure_svl(void)44void arch_sme_configure_svl(void) 45 { 46 uint64_t smcr_el2_val; 47 48 /* 49 * SMCR_EL2.FA64=1 treating A64 instructions as legal in Streaming SVE. 50 * EZT0 cleared traps accesses to SME2 ZT0 register at EL2 and lower. 51 * Set SVL to the maximum permitted value. 52 */ 53 smcr_el2_val = (SMCR_EL2_LEN_MAX << SMCR_EL2_LEN_SHIFT); 54 if (is_arch_feat_sme_fa64_supported()) { 55 smcr_el2_val |= SMCR_EL2_FA64_BIT; 56 } 57 58 write_msr(MSR_SMCR_EL2, smcr_el2_val); 59 isb(); 60 } 61