xor.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /* SPDX-License-Identifier: GPL-2.0-or-later */
  2. /*
  3. * Copyright (C) 2021 SiFive
  4. */
  5. #include <linux/hardirq.h>
  6. #include <asm-generic/xor.h>
  7. #ifdef CONFIG_RISCV_ISA_V
  8. #include <asm/vector.h>
  9. #include <asm/switch_to.h>
  10. #include <asm/asm-prototypes.h>
  11. static void xor_vector_2(unsigned long bytes, unsigned long *__restrict p1,
  12. const unsigned long *__restrict p2)
  13. {
  14. kernel_vector_begin();
  15. xor_regs_2_(bytes, p1, p2);
  16. kernel_vector_end();
  17. }
  18. static void xor_vector_3(unsigned long bytes, unsigned long *__restrict p1,
  19. const unsigned long *__restrict p2,
  20. const unsigned long *__restrict p3)
  21. {
  22. kernel_vector_begin();
  23. xor_regs_3_(bytes, p1, p2, p3);
  24. kernel_vector_end();
  25. }
  26. static void xor_vector_4(unsigned long bytes, unsigned long *__restrict p1,
  27. const unsigned long *__restrict p2,
  28. const unsigned long *__restrict p3,
  29. const unsigned long *__restrict p4)
  30. {
  31. kernel_vector_begin();
  32. xor_regs_4_(bytes, p1, p2, p3, p4);
  33. kernel_vector_end();
  34. }
  35. static void xor_vector_5(unsigned long bytes, unsigned long *__restrict p1,
  36. const unsigned long *__restrict p2,
  37. const unsigned long *__restrict p3,
  38. const unsigned long *__restrict p4,
  39. const unsigned long *__restrict p5)
  40. {
  41. kernel_vector_begin();
  42. xor_regs_5_(bytes, p1, p2, p3, p4, p5);
  43. kernel_vector_end();
  44. }
  45. static struct xor_block_template xor_block_rvv = {
  46. .name = "rvv",
  47. .do_2 = xor_vector_2,
  48. .do_3 = xor_vector_3,
  49. .do_4 = xor_vector_4,
  50. .do_5 = xor_vector_5
  51. };
  52. #undef XOR_TRY_TEMPLATES
  53. #define XOR_TRY_TEMPLATES \
  54. do { \
  55. xor_speed(&xor_block_8regs); \
  56. xor_speed(&xor_block_32regs); \
  57. if (has_vector()) { \
  58. xor_speed(&xor_block_rvv);\
  59. } \
  60. } while (0)
  61. #endif