2 * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved.
4 * SPDX-License-Identifier: BSD-3-Clause
10 #include <arch_helpers.h>
11 #include <lib/el3_runtime/pubsub.h>
12 #include <lib/extensions/sve.h>
14 bool sve_supported(void)
18 features
= read_id_aa64pfr0_el1() >> ID_AA64PFR0_SVE_SHIFT
;
19 return (features
& ID_AA64PFR0_SVE_MASK
) == 1U;
22 static void *disable_sve_hook(const void *arg
)
30 * Disable SVE, SIMD and FP access for the Secure world.
31 * As the SIMD/FP registers are part of the SVE Z-registers, any
32 * use of SIMD/FP functionality will corrupt the SVE registers.
33 * Therefore it is necessary to prevent use of SIMD/FP support
34 * in the Secure world as well as SVE functionality.
36 cptr
= read_cptr_el3();
37 cptr
= (cptr
| TFP_BIT
) & ~(CPTR_EZ_BIT
);
41 * No explicit ISB required here as ERET to switch to Secure
47 static void *enable_sve_hook(const void *arg
)
55 * Enable SVE, SIMD and FP access for the Non-secure world.
57 cptr
= read_cptr_el3();
58 cptr
= (cptr
| CPTR_EZ_BIT
) & ~(TFP_BIT
);
62 * No explicit ISB required here as ERET to switch to Non-secure
68 void sve_enable(bool el2_unused
)
75 #if CTX_INCLUDE_FPREGS
77 * CTX_INCLUDE_FPREGS is not supported on SVE enabled systems.
82 * Update CPTR_EL3 to enable access to SVE functionality for the
84 * NOTE - assumed that CPTR_EL3.TFP is set to allow access to
85 * the SIMD, floating-point and SVE support.
87 * CPTR_EL3.EZ: Set to 1 to enable access to SVE functionality
88 * in the Non-secure world.
90 cptr
= read_cptr_el3();
95 * Need explicit ISB here to guarantee that update to ZCR_ELx
96 * and CPTR_EL2.TZ do not result in trap to EL3.
101 * Ensure lower ELs have access to full vector length.
103 write_zcr_el3(ZCR_EL3_LEN_MASK
);
107 * Update CPTR_EL2 to enable access to SVE functionality
108 * for Non-secure world, EL2 and Non-secure EL1 and EL0.
109 * NOTE - assumed that CPTR_EL2.TFP is set to allow
110 * access to the SIMD, floating-point and SVE support.
112 * CPTR_EL2.TZ: Set to 0 to enable access to SVE support
113 * for EL2 and Non-secure EL1 and EL0.
115 cptr
= read_cptr_el2();
116 cptr
&= ~(CPTR_EL2_TZ_BIT
);
117 write_cptr_el2(cptr
);
120 * Ensure lower ELs have access to full vector length.
122 write_zcr_el2(ZCR_EL2_LEN_MASK
);
125 * No explicit ISB required here as ERET to switch to
126 * Non-secure world covers it.
130 SUBSCRIBE_TO_EVENT(cm_exited_normal_world
, disable_sve_hook
);
131 SUBSCRIBE_TO_EVENT(cm_entering_normal_world
, enable_sve_hook
);