jump_label.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 *key,
  14. bool branch)
  15. {
  16. asm_volatile_goto(
  17. " .option push \n\t"
  18. " .option norelax \n\t"
  19. " .option norvc \n\t"
  20. "1: nop \n\t"
  21. " .option pop \n\t"
  22. " .pushsection __jump_table, \"aw\" \n\t"
  23. " .align " RISCV_LGPTR " \n\t"
  24. " .long 1b - ., %l[label] - . \n\t"
  25. " " RISCV_PTR " %0 - . \n\t"
  26. " .popsection \n\t"
  27. : : "i"(&((char *)key)[branch]) : : label);
  28. return false;
  29. label:
  30. return true;
  31. }
  32. static __always_inline bool arch_static_branch_jump(struct static_key *key,
  33. bool branch)
  34. {
  35. asm_volatile_goto(
  36. " .option push \n\t"
  37. " .option norelax \n\t"
  38. " .option norvc \n\t"
  39. "1: jal zero, %l[label] \n\t"
  40. " .option pop \n\t"
  41. " .pushsection __jump_table, \"aw\" \n\t"
  42. " .align " RISCV_LGPTR " \n\t"
  43. " .long 1b - ., %l[label] - . \n\t"
  44. " " RISCV_PTR " %0 - . \n\t"
  45. " .popsection \n\t"
  46. : : "i"(&((char *)key)[branch]) : : label);
  47. return false;
  48. label:
  49. return true;
  50. }
  51. #endif /* __ASSEMBLY__ */
  52. #endif /* __ASM_JUMP_LABEL_H */