simd_ctx.c 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. #include <stdint.h>
  8. #include <common/debug.h>
  9. #include <lib/el3_runtime/aarch64/context.h>
  10. #include <lib/el3_runtime/context_mgmt.h>
  11. #include <lib/el3_runtime/cpu_data.h>
  12. #include <lib/el3_runtime/simd_ctx.h>
  13. #include <lib/extensions/sve.h>
  14. #include <plat/common/platform.h>
  15. #if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS
  16. /* SIMD context managed for Secure and Normal Worlds. */
  17. #define SIMD_CTXT_COUNT 2
  18. #if SEPARATE_SIMD_SECTION
  19. __section(".simd_context")
  20. #else
  21. __section(".bss.simd_context")
  22. #endif
  23. static simd_regs_t simd_context[SIMD_CTXT_COUNT][PLATFORM_CORE_COUNT];
  24. void simd_ctx_save(uint32_t security_state, bool hint_sve)
  25. {
  26. simd_regs_t *regs;
  27. if (security_state != NON_SECURE && security_state != SECURE) {
  28. ERROR("Unsupported security state specified for SIMD context: %u\n",
  29. security_state);
  30. panic();
  31. }
  32. regs = &simd_context[security_state][plat_my_core_pos()];
  33. #if CTX_INCLUDE_SVE_REGS
  34. regs->hint = hint_sve;
  35. if (hint_sve) {
  36. /*
  37. * Hint bit denoting absence of SVE live state. Hence, only
  38. * save FP context.
  39. */
  40. fpregs_context_save(regs);
  41. } else {
  42. sve_context_save(regs);
  43. }
  44. #elif CTX_INCLUDE_FPREGS
  45. fpregs_context_save(regs);
  46. #endif
  47. }
  48. void simd_ctx_restore(uint32_t security_state)
  49. {
  50. simd_regs_t *regs;
  51. if (security_state != NON_SECURE && security_state != SECURE) {
  52. ERROR("Unsupported security state specified for SIMD context: %u\n",
  53. security_state);
  54. panic();
  55. }
  56. regs = &simd_context[security_state][plat_my_core_pos()];
  57. #if CTX_INCLUDE_SVE_REGS
  58. if (regs->hint) {
  59. fpregs_context_restore(regs);
  60. } else {
  61. sve_context_restore(regs);
  62. }
  63. #elif CTX_INCLUDE_FPREGS
  64. fpregs_context_restore(regs);
  65. #endif
  66. }
  67. #endif /* CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS */