jump_label.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2020 Emil Renner Berthing
  4. *
  5. * Based on arch/arm64/include/asm/jump_label.h
  6. */
  7. #ifndef __ASM_JUMP_LABEL_H
  8. #define __ASM_JUMP_LABEL_H
  9. #ifndef __ASSEMBLY__
  10. #include <linux/types.h>
  11. #include <asm/asm.h>
  12. #define JUMP_LABEL_NOP_SIZE 4
  13. static __always_inline bool arch_static_branch(struct static_key * const key,
  14. const bool branch)
  15. {
  16. asm_volatile_goto(
  17. " .align 2 \n\t"
  18. " .option push \n\t"
  19. " .option norelax \n\t"
  20. " .option norvc \n\t"
  21. "1: nop \n\t"
  22. " .option pop \n\t"
  23. " .pushsection __jump_table, \"aw\" \n\t"
  24. " .align " RISCV_LGPTR " \n\t"
  25. " .long 1b - ., %l[label] - . \n\t"
  26. " " RISCV_PTR " %0 - . \n\t"
  27. " .popsection \n\t"
  28. : : "i"(&((char *)key)[branch]) : : label);
  29. return false;
  30. label:
  31. return true;
  32. }
  33. static __always_inline bool arch_static_branch_jump(struct static_key * const key,
  34. const bool branch)
  35. {
  36. asm_volatile_goto(
  37. " .align 2 \n\t"
  38. " .option push \n\t"
  39. " .option norelax \n\t"
  40. " .option norvc \n\t"
  41. "1: jal zero, %l[label] \n\t"
  42. " .option pop \n\t"
  43. " .pushsection __jump_table, \"aw\" \n\t"
  44. " .align " RISCV_LGPTR " \n\t"
  45. " .long 1b - ., %l[label] - . \n\t"
  46. " " RISCV_PTR " %0 - . \n\t"
  47. " .popsection \n\t"
  48. : : "i"(&((char *)key)[branch]) : : label);
  49. return false;
  50. label:
  51. return true;
  52. }
  53. #endif /* __ASSEMBLY__ */
  54. #endif /* __ASM_JUMP_LABEL_H */