blob: f7a87dfe1f1c57aad0f97b1e700c9b9f225d1b60 [file] [log] [blame]
Madhukar Pappireddy5c1b8d92024-06-17 15:26:00 -05001/*
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
28static simd_regs_t simd_context[SIMD_CTXT_COUNT][PLATFORM_CORE_COUNT];
29
30void 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
59void 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 */