jump_label.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2023 Loongson Technology Corporation Limited
  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 __ASSEMBLER__
  10. #include <linux/types.h>
  11. #include <linux/stringify.h>
  12. #include <asm/asm.h>
  13. #define JUMP_LABEL_NOP_SIZE 4
  14. #ifdef CONFIG_32BIT
  15. #define JUMP_LABEL_TYPE ".long "
  16. #else
  17. #define JUMP_LABEL_TYPE ".quad "
  18. #endif
  19. /* This macro is also expanded on the Rust side. */
  20. #define JUMP_TABLE_ENTRY(key, label) \
  21. ".pushsection __jump_table, \"aw\" \n\t" \
  22. ".align " __stringify(PTRLOG) " \n\t" \
  23. ".long 1b - ., " label " - . \n\t" \
  24. JUMP_LABEL_TYPE key " - . \n\t" \
  25. ".popsection \n\t"
  26. #define ARCH_STATIC_BRANCH_ASM(key, label) \
  27. "1: nop \n\t" \
  28. JUMP_TABLE_ENTRY(key, label)
  29. static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
  30. {
  31. asm goto(
  32. ARCH_STATIC_BRANCH_ASM("%0", "%l[l_yes]")
  33. : : "i"(&((char *)key)[branch]) : : l_yes);
  34. return false;
  35. l_yes:
  36. return true;
  37. }
  38. static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
  39. {
  40. asm goto(
  41. "1: b %l[l_yes] \n\t"
  42. JUMP_TABLE_ENTRY("%0", "%l[l_yes]")
  43. : : "i"(&((char *)key)[branch]) : : l_yes);
  44. return false;
  45. l_yes:
  46. return true;
  47. }
  48. #endif /* __ASSEMBLER__ */
  49. #endif /* __ASM_JUMP_LABEL_H */