fpsimd.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Copyright (C) 2012 ARM Ltd.
  3. *
  4. * This program is free software; you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License version 2 as
  6. * published by the Free Software Foundation.
  7. *
  8. * This program is distributed in the hope that it will be useful,
  9. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. *
  13. * You should have received a copy of the GNU General Public License
  14. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #ifndef __ASM_FP_H
  17. #define __ASM_FP_H
  18. #include <asm/errno.h>
  19. #include <asm/ptrace.h>
  20. #include <asm/processor.h>
  21. #include <asm/sigcontext.h>
  22. #include <asm/sysreg.h>
  23. #ifndef __ASSEMBLY__
  24. #include <linux/build_bug.h>
  25. #include <linux/cache.h>
  26. #include <linux/init.h>
  27. #include <linux/stddef.h>
  28. #if defined(__KERNEL__) && defined(CONFIG_COMPAT)
  29. /* Masks for extracting the FPSR and FPCR from the FPSCR */
  30. #define VFP_FPSCR_STAT_MASK 0xf800009f
  31. #define VFP_FPSCR_CTRL_MASK 0x07f79f00
  32. /*
  33. * The VFP state has 32x64-bit registers and a single 32-bit
  34. * control/status register.
  35. */
  36. #define VFP_STATE_SIZE ((32 * 8) + 4)
  37. #endif
  38. struct task_struct;
  39. extern void fpsimd_save_state(struct user_fpsimd_state *state);
  40. extern void fpsimd_load_state(struct user_fpsimd_state *state);
  41. extern void fpsimd_save(void);
  42. extern void fpsimd_thread_switch(struct task_struct *next);
  43. extern void fpsimd_flush_thread(void);
  44. extern void fpsimd_signal_preserve_current_state(void);
  45. extern void fpsimd_preserve_current_state(void);
  46. extern void fpsimd_restore_current_state(void);
  47. extern void fpsimd_update_current_state(struct user_fpsimd_state const *state);
  48. extern void fpsimd_bind_task_to_cpu(void);
  49. extern void fpsimd_bind_state_to_cpu(struct user_fpsimd_state *state);
  50. extern void fpsimd_flush_task_state(struct task_struct *target);
  51. extern void fpsimd_flush_cpu_state(void);
  52. extern void sve_flush_cpu_state(void);
  53. /* Maximum VL that SVE VL-agnostic software can transparently support */
  54. #define SVE_VL_ARCH_MAX 0x100
  55. /* Offset of FFR in the SVE register dump */
  56. static inline size_t sve_ffr_offset(int vl)
  57. {
  58. return SVE_SIG_FFR_OFFSET(sve_vq_from_vl(vl)) - SVE_SIG_REGS_OFFSET;
  59. }
  60. static inline void *sve_pffr(struct thread_struct *thread)
  61. {
  62. return (char *)thread->sve_state + sve_ffr_offset(thread->sve_vl);
  63. }
  64. extern void sve_save_state(void *state, u32 *pfpsr);
  65. extern void sve_load_state(void const *state, u32 const *pfpsr,
  66. unsigned long vq_minus_1);
  67. extern unsigned int sve_get_vl(void);
  68. struct arm64_cpu_capabilities;
  69. extern void sve_kernel_enable(const struct arm64_cpu_capabilities *__unused);
  70. extern u64 read_zcr_features(void);
  71. extern int __ro_after_init sve_max_vl;
  72. #ifdef CONFIG_ARM64_SVE
  73. extern size_t sve_state_size(struct task_struct const *task);
  74. extern void sve_alloc(struct task_struct *task);
  75. extern void fpsimd_release_task(struct task_struct *task);
  76. extern void fpsimd_sync_to_sve(struct task_struct *task);
  77. extern void sve_sync_to_fpsimd(struct task_struct *task);
  78. extern void sve_sync_from_fpsimd_zeropad(struct task_struct *task);
  79. extern int sve_set_vector_length(struct task_struct *task,
  80. unsigned long vl, unsigned long flags);
  81. extern int sve_set_current_vl(unsigned long arg);
  82. extern int sve_get_current_vl(void);
  83. static inline void sve_user_disable(void)
  84. {
  85. sysreg_clear_set(cpacr_el1, CPACR_EL1_ZEN_EL0EN, 0);
  86. }
  87. static inline void sve_user_enable(void)
  88. {
  89. sysreg_clear_set(cpacr_el1, 0, CPACR_EL1_ZEN_EL0EN);
  90. }
  91. /*
  92. * Probing and setup functions.
  93. * Calls to these functions must be serialised with one another.
  94. */
  95. extern void __init sve_init_vq_map(void);
  96. extern void sve_update_vq_map(void);
  97. extern int sve_verify_vq_map(void);
  98. extern void __init sve_setup(void);
  99. #else /* ! CONFIG_ARM64_SVE */
  100. static inline void sve_alloc(struct task_struct *task) { }
  101. static inline void fpsimd_release_task(struct task_struct *task) { }
  102. static inline void sve_sync_to_fpsimd(struct task_struct *task) { }
  103. static inline void sve_sync_from_fpsimd_zeropad(struct task_struct *task) { }
  104. static inline int sve_set_current_vl(unsigned long arg)
  105. {
  106. return -EINVAL;
  107. }
  108. static inline int sve_get_current_vl(void)
  109. {
  110. return -EINVAL;
  111. }
  112. static inline void sve_user_disable(void) { BUILD_BUG(); }
  113. static inline void sve_user_enable(void) { BUILD_BUG(); }
  114. static inline void sve_init_vq_map(void) { }
  115. static inline void sve_update_vq_map(void) { }
  116. static inline int sve_verify_vq_map(void) { return 0; }
  117. static inline void sve_setup(void) { }
  118. #endif /* ! CONFIG_ARM64_SVE */
  119. /* For use by EFI runtime services calls only */
  120. extern void __efi_fpsimd_begin(void);
  121. extern void __efi_fpsimd_end(void);
  122. #endif
  123. #endif