• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2024, Arm Limited and Contributors. All rights reserved.
3  * Copyright (c) 2022, Google LLC. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #include <stdint.h>
9 
10 #include <common/debug.h>
11 #include <lib/el3_runtime/aarch64/context.h>
12 #include <lib/el3_runtime/context_mgmt.h>
13 #include <lib/el3_runtime/cpu_data.h>
14 #include <lib/el3_runtime/simd_ctx.h>
15 #include <lib/extensions/sve.h>
16 #include <plat/common/platform.h>
17 
18 #if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS
19 
20 /* SIMD context managed for Secure and Normal Worlds. */
21 #define SIMD_CTXT_COUNT	2
22 
23 #if SEPARATE_SIMD_SECTION
24 __section(".simd_context")
25 #else
26 __section(".bss.simd_context")
27 #endif
28 static simd_regs_t simd_context[SIMD_CTXT_COUNT][PLATFORM_CORE_COUNT];
29 
simd_ctx_save(uint32_t security_state,bool hint_sve)30 void simd_ctx_save(uint32_t security_state, bool hint_sve)
31 {
32 	simd_regs_t *regs;
33 
34 	if (security_state != NON_SECURE && security_state != SECURE) {
35 		ERROR("Unsupported security state specified for SIMD context: %u\n",
36 		      security_state);
37 		panic();
38 	}
39 
40 	regs = &simd_context[security_state][plat_my_core_pos()];
41 
42 #if CTX_INCLUDE_SVE_REGS
43 	regs->hint = hint_sve;
44 
45 	if (hint_sve) {
46 		/*
47 		 * Hint bit denoting absence of SVE live state. Hence, only
48 		 * save FP context.
49 		 */
50 		fpregs_context_save(regs);
51 	} else {
52 		sve_context_save(regs);
53 	}
54 #elif CTX_INCLUDE_FPREGS
55 	fpregs_context_save(regs);
56 #endif
57 }
58 
simd_ctx_restore(uint32_t security_state)59 void simd_ctx_restore(uint32_t security_state)
60 {
61 	simd_regs_t *regs;
62 
63 	if (security_state != NON_SECURE && security_state != SECURE) {
64 		ERROR("Unsupported security state specified for SIMD context: %u\n",
65 		      security_state);
66 		panic();
67 	}
68 
69 	regs = &simd_context[security_state][plat_my_core_pos()];
70 
71 #if CTX_INCLUDE_SVE_REGS
72 	if (regs->hint) {
73 		fpregs_context_restore(regs);
74 	} else {
75 		sve_context_restore(regs);
76 	}
77 #elif CTX_INCLUDE_FPREGS
78 	fpregs_context_restore(regs);
79 #endif
80 }
81 #endif /* CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS */
82