simd.h 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2017 Linaro Ltd. <ard.biesheuvel@linaro.org>
  4. */
  5. #ifndef __ASM_SIMD_H
  6. #define __ASM_SIMD_H
  7. #include <linux/compiler.h>
  8. #include <linux/irqflags.h>
  9. #include <linux/percpu.h>
  10. #include <linux/preempt.h>
  11. #include <linux/types.h>
  12. #ifdef CONFIG_KERNEL_MODE_NEON
  13. /*
  14. * may_use_simd - whether it is allowable at this time to issue SIMD
  15. * instructions or access the SIMD register file
  16. *
  17. * Callers must not assume that the result remains true beyond the next
  18. * preempt_enable() or return from softirq context.
  19. */
  20. static __must_check inline bool may_use_simd(void)
  21. {
  22. /*
  23. * We must make sure that the SVE has been initialized properly
  24. * before using the SIMD in kernel.
  25. */
  26. return !WARN_ON(!system_capabilities_finalized()) &&
  27. system_supports_fpsimd() &&
  28. !in_hardirq() && !irqs_disabled() && !in_nmi();
  29. }
  30. #else /* ! CONFIG_KERNEL_MODE_NEON */
  31. static __must_check inline bool may_use_simd(void) {
  32. return false;
  33. }
  34. #endif /* ! CONFIG_KERNEL_MODE_NEON */
  35. #endif