Browse Source

feat(simd): introduce simd context helper APIs

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: I090f8b8fa3862e527b6c40385249adc69256bf24
pull/2005/merge
Madhukar Pappireddy 5 months ago
parent
commit
308ebfa188
  1. 2
      Makefile
  2. 1
      bl31/bl31.mk
  3. 5
      include/lib/el3_runtime/aarch64/context.h
  4. 81
      lib/el3_runtime/simd_ctx.c
  5. 4
      make_helpers/defaults.mk

2
Makefile

@ -1169,6 +1169,7 @@ $(eval $(call assert_booleans,\
SEPARATE_CODE_AND_RODATA \
SEPARATE_BL2_NOLOAD_REGION \
SEPARATE_NOBITS_REGION \
SEPARATE_SIMD_SECTION \
SPIN_ON_BL1_EXIT \
SPM_MM \
SPMC_AT_EL3 \
@ -1342,6 +1343,7 @@ $(eval $(call add_defines,\
SEPARATE_CODE_AND_RODATA \
SEPARATE_BL2_NOLOAD_REGION \
SEPARATE_NOBITS_REGION \
SEPARATE_SIMD_SECTION \
RECLAIM_INIT_CODE \
SPD_${SPD} \
SPIN_ON_BL1_EXIT \

1
bl31/bl31.mk

@ -46,6 +46,7 @@ BL31_SOURCES += bl31/bl31_main.c \
plat/common/aarch64/platform_mp_stack.S \
services/arm_arch_svc/arm_arch_svc_setup.c \
services/std_svc/std_svc_setup.c \
lib/el3_runtime/simd_ctx.c \
${PSCI_LIB_SOURCES} \
${SPMD_SOURCES} \
${SPM_MM_SOURCES} \

5
include/lib/el3_runtime/aarch64/context.h

@ -10,6 +10,7 @@
#include <lib/el3_runtime/context_el1.h>
#include <lib/el3_runtime/context_el2.h>
#include <lib/el3_runtime/cpu_data.h>
#include <lib/el3_runtime/simd_ctx.h>
#include <lib/utils_def.h>
/*******************************************************************************
@ -422,8 +423,8 @@ CASSERT(CTX_PAUTH_REGS_OFFSET == __builtin_offsetof(cpu_context_t, pauth_ctx),
* Function prototypes
******************************************************************************/
#if CTX_INCLUDE_FPREGS
void fpregs_context_save(fp_regs_t *regs);
void fpregs_context_restore(fp_regs_t *regs);
void fpregs_context_save(simd_regs_t *regs);
void fpregs_context_restore(simd_regs_t *regs);
#endif
#endif /* __ASSEMBLER__ */

81
lib/el3_runtime/simd_ctx.c

@ -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 */

4
make_helpers/defaults.mk

@ -240,6 +240,10 @@ SEPARATE_NOBITS_REGION := 0
# region, platform Makefile is free to override this value.
SEPARATE_BL2_NOLOAD_REGION := 0
# Put SIMD context data structures in a separate memory region. Platforms
# have the choice to put it outside of default BSS region of EL3 firmware.
SEPARATE_SIMD_SECTION := 0
# If the BL31 image initialisation code is recalimed after use for the secondary
# cores stack
RECLAIM_INIT_CODE := 0

Loading…
Cancel
Save