Browse Source
This patch adds the common API to save and restore FP and SVE. When SVE is enabled we save and restore SVE which automatically covers FP. If FP is enabled while SVE is not, then we save and restore FP only. The patch uses simd_ctx_t to save and restore both FP and SVE which means developers need not use fp or sve routines directly. Once all the calls to fpregs_context_* are replaced with simd_ctx_*, we can remove fp_regs_t data structure and macros (taken care in a following patch). simd_ctx_t is currently allocated in section of its own. This will go into BSS section by default but platform will have option of relocating it to a different section by overriding in plat.ld.S. Signed-off-by: Madhukar Pappireddy <madhukar.pappireddy@arm.com> Signed-off-by: Okash Khawaja <okash@google.com> Change-Id: I090f8b8fa3862e527b6c40385249adc69256bf24pull/2005/merge
Madhukar Pappireddy
5 months ago
5 changed files with 91 additions and 2 deletions
@ -0,0 +1,81 @@ |
|||
/*
|
|||
* Copyright (c) 2024, Arm Limited and Contributors. All rights reserved. |
|||
* Copyright (c) 2022, Google LLC. All rights reserved. |
|||
* |
|||
* SPDX-License-Identifier: BSD-3-Clause |
|||
*/ |
|||
|
|||
#include <stdint.h> |
|||
|
|||
#include <common/debug.h> |
|||
#include <lib/el3_runtime/aarch64/context.h> |
|||
#include <lib/el3_runtime/context_mgmt.h> |
|||
#include <lib/el3_runtime/cpu_data.h> |
|||
#include <lib/el3_runtime/simd_ctx.h> |
|||
#include <lib/extensions/sve.h> |
|||
#include <plat/common/platform.h> |
|||
|
|||
#if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS |
|||
|
|||
/* SIMD context managed for Secure and Normal Worlds. */ |
|||
#define SIMD_CTXT_COUNT 2 |
|||
|
|||
#if SEPARATE_SIMD_SECTION |
|||
__section(".simd_context") |
|||
#else |
|||
__section(".bss.simd_context") |
|||
#endif |
|||
static simd_regs_t simd_context[SIMD_CTXT_COUNT][PLATFORM_CORE_COUNT]; |
|||
|
|||
void simd_ctx_save(uint32_t security_state, bool hint_sve) |
|||
{ |
|||
simd_regs_t *regs; |
|||
|
|||
if (security_state != NON_SECURE && security_state != SECURE) { |
|||
ERROR("Unsupported security state specified for SIMD context: %u\n", |
|||
security_state); |
|||
panic(); |
|||
} |
|||
|
|||
regs = &simd_context[security_state][plat_my_core_pos()]; |
|||
|
|||
#if CTX_INCLUDE_SVE_REGS |
|||
regs->hint = hint_sve; |
|||
|
|||
if (hint_sve) { |
|||
/*
|
|||
* Hint bit denoting absence of SVE live state. Hence, only |
|||
* save FP context. |
|||
*/ |
|||
fpregs_context_save(regs); |
|||
} else { |
|||
sve_context_save(regs); |
|||
} |
|||
#elif CTX_INCLUDE_FPREGS |
|||
fpregs_context_save(regs); |
|||
#endif |
|||
} |
|||
|
|||
void simd_ctx_restore(uint32_t security_state) |
|||
{ |
|||
simd_regs_t *regs; |
|||
|
|||
if (security_state != NON_SECURE && security_state != SECURE) { |
|||
ERROR("Unsupported security state specified for SIMD context: %u\n", |
|||
security_state); |
|||
panic(); |
|||
} |
|||
|
|||
regs = &simd_context[security_state][plat_my_core_pos()]; |
|||
|
|||
#if CTX_INCLUDE_SVE_REGS |
|||
if (regs->hint) { |
|||
fpregs_context_restore(regs); |
|||
} else { |
|||
sve_context_restore(regs); |
|||
} |
|||
#elif CTX_INCLUDE_FPREGS |
|||
fpregs_context_restore(regs); |
|||
#endif |
|||
} |
|||
#endif /* CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS */ |
Loading…
Reference in new issue