jump_label.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2013 Huawei Ltd.
  4. * Author: Jiang Liu <[email protected]>
  5. *
  6. * Based on arch/arm/include/asm/jump_label.h
  7. */
  8. #ifndef __ASM_JUMP_LABEL_H
  9. #define __ASM_JUMP_LABEL_H
  10. #ifndef __ASSEMBLY__
  11. #include <linux/types.h>
  12. #include <asm/insn.h>
  13. #define JUMP_LABEL_NOP_SIZE AARCH64_INSN_SIZE
  14. static __always_inline bool arch_static_branch(struct static_key *key,
  15. bool branch)
  16. {
  17. asm_volatile_goto(
  18. "1: nop \n\t"
  19. " .pushsection __jump_table, \"aw\" \n\t"
  20. " .align 3 \n\t"
  21. " .long 1b - ., %l[l_yes] - . \n\t"
  22. " .quad %c0 - . \n\t"
  23. " .popsection \n\t"
  24. : : "i"(&((char *)key)[branch]) : : l_yes);
  25. return false;
  26. l_yes:
  27. return true;
  28. }
  29. static __always_inline bool arch_static_branch_jump(struct static_key *key,
  30. bool branch)
  31. {
  32. asm_volatile_goto(
  33. "1: b %l[l_yes] \n\t"
  34. " .pushsection __jump_table, \"aw\" \n\t"
  35. " .align 3 \n\t"
  36. " .long 1b - ., %l[l_yes] - . \n\t"
  37. " .quad %c0 - . \n\t"
  38. " .popsection \n\t"
  39. : : "i"(&((char *)key)[branch]) : : l_yes);
  40. return false;
  41. l_yes:
  42. return true;
  43. }
  44. #endif /* __ASSEMBLY__ */
  45. #endif /* __ASM_JUMP_LABEL_H */