riscv_v_helpers.c 977 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (C) 2023 SiFive
  4. * Author: Andy Chiu <andy.chiu@sifive.com>
  5. */
  6. #include <linux/linkage.h>
  7. #include <asm/asm.h>
  8. #include <asm/vector.h>
  9. #include <asm/simd.h>
  10. #ifdef CONFIG_MMU
  11. #include <asm/asm-prototypes.h>
  12. #endif
  13. #ifdef CONFIG_MMU
  14. size_t riscv_v_usercopy_threshold = CONFIG_RISCV_ISA_V_UCOPY_THRESHOLD;
  15. int __asm_vector_usercopy(void *dst, void *src, size_t n);
  16. int fallback_scalar_usercopy(void *dst, void *src, size_t n);
  17. asmlinkage int enter_vector_usercopy(void *dst, void *src, size_t n)
  18. {
  19. size_t remain, copied;
  20. /* skip has_vector() check because it has been done by the asm */
  21. if (!may_use_simd())
  22. goto fallback;
  23. kernel_vector_begin();
  24. remain = __asm_vector_usercopy(dst, src, n);
  25. kernel_vector_end();
  26. if (remain) {
  27. copied = n - remain;
  28. dst += copied;
  29. src += copied;
  30. n = remain;
  31. goto fallback;
  32. }
  33. return remain;
  34. fallback:
  35. return fallback_scalar_usercopy(dst, src, n);
  36. }
  37. #endif