simd_ctx.h 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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. #ifndef SIMD_CTX_H
  8. #define SIMD_CTX_H
  9. /*******************************************************************************
  10. * Constants that allow assembler code to access members of and the 'simd_context'
  11. * structure at their correct offsets.
  12. ******************************************************************************/
  13. #if CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS
  14. #if CTX_INCLUDE_SVE_REGS
  15. #define SIMD_VECTOR_LEN_BYTES (SVE_VECTOR_LEN / 8) /* Length of vector in bytes */
  16. #elif CTX_INCLUDE_FPREGS
  17. #define SIMD_VECTOR_LEN_BYTES U(16) /* 128 bits fixed vector length for FPU */
  18. #endif /* CTX_INCLUDE_SVE_REGS */
  19. #define CTX_SIMD_VECTORS U(0)
  20. /* there are 32 vector registers, each of size SIMD_VECTOR_LEN_BYTES */
  21. #define CTX_SIMD_FPSR (CTX_SIMD_VECTORS + (32 * SIMD_VECTOR_LEN_BYTES))
  22. #define CTX_SIMD_FPCR (CTX_SIMD_FPSR + 8)
  23. #if CTX_INCLUDE_FPREGS && CTX_INCLUDE_AARCH32_REGS
  24. #define CTX_SIMD_FPEXC32 (CTX_SIMD_FPCR + 8)
  25. #define CTX_SIMD_PREDICATES (CTX_SIMD_FPEXC32 + 16)
  26. #else
  27. #define CTX_SIMD_PREDICATES (CTX_SIMD_FPCR + 8)
  28. #endif /* CTX_INCLUDE_FPREGS && CTX_INCLUDE_AARCH32_REGS */
  29. /*
  30. * Each predicate register is 1/8th the size of a vector register and there are 16
  31. * predicate registers
  32. */
  33. #define CTX_SIMD_FFR (CTX_SIMD_PREDICATES + (16 * (SIMD_VECTOR_LEN_BYTES / 8)))
  34. #ifndef __ASSEMBLER__
  35. #include <stdint.h>
  36. #include <lib/cassert.h>
  37. /*
  38. * Please don't change order of fields in this struct as that may violate
  39. * alignment requirements and affect how assembly code accesses members of this
  40. * struct.
  41. */
  42. typedef struct {
  43. uint8_t vectors[32][SIMD_VECTOR_LEN_BYTES];
  44. uint8_t fpsr[8];
  45. uint8_t fpcr[8];
  46. #if CTX_INCLUDE_FPREGS && CTX_INCLUDE_AARCH32_REGS
  47. /* 16 bytes to align to next 16 byte boundary when CTX_INCLUDE_SVE_REGS is 0 */
  48. uint8_t fpexc32_el2[16];
  49. #endif
  50. #if CTX_INCLUDE_SVE_REGS
  51. /* FFR and each of predicates is one-eigth of the SVE vector length */
  52. uint8_t predicates[16][SIMD_VECTOR_LEN_BYTES / 8];
  53. uint8_t ffr[SIMD_VECTOR_LEN_BYTES / 8];
  54. /* SMCCCv1.3 FID[16] hint bit state recorded on EL3 entry */
  55. bool hint;
  56. #endif /* CTX_INCLUDE_SVE_REGS */
  57. } __aligned(16) simd_regs_t;
  58. CASSERT(CTX_SIMD_VECTORS == __builtin_offsetof(simd_regs_t, vectors),
  59. assert_vectors_mismatch);
  60. CASSERT(CTX_SIMD_FPSR == __builtin_offsetof(simd_regs_t, fpsr),
  61. assert_fpsr_mismatch);
  62. CASSERT(CTX_SIMD_FPCR == __builtin_offsetof(simd_regs_t, fpcr),
  63. assert_fpcr_mismatch);
  64. #if CTX_INCLUDE_FPREGS && CTX_INCLUDE_AARCH32_REGS
  65. CASSERT(CTX_SIMD_FPEXC32 == __builtin_offsetof(simd_regs_t, fpexc32_el2),
  66. assert_fpex32_mismtatch);
  67. #endif
  68. #if CTX_INCLUDE_SVE_REGS
  69. CASSERT(CTX_SIMD_PREDICATES == __builtin_offsetof(simd_regs_t, predicates),
  70. assert_predicates_mismatch);
  71. CASSERT(CTX_SIMD_FFR == __builtin_offsetof(simd_regs_t, ffr),
  72. assert_ffr_mismatch);
  73. #endif
  74. void simd_ctx_save(uint32_t security_state, bool hint_sve);
  75. void simd_ctx_restore(uint32_t security_state);
  76. #endif /* __ASSEMBLER__ */
  77. #endif /* CTX_INCLUDE_FPREGS || CTX_INCLUDE_SVE_REGS */
  78. #endif /* SIMD_CTX_H */