jump_label.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Copyright (c) 2010 Cavium Networks, Inc.
  7. */
  8. #ifndef _ASM_MIPS_JUMP_LABEL_H
  9. #define _ASM_MIPS_JUMP_LABEL_H
  10. #ifndef __ASSEMBLY__
  11. #include <linux/types.h>
  12. #define JUMP_LABEL_NOP_SIZE 4
  13. #ifdef CONFIG_64BIT
  14. #define WORD_INSN ".dword"
  15. #else
  16. #define WORD_INSN ".word"
  17. #endif
  18. #ifdef CONFIG_CPU_MICROMIPS
  19. #define NOP_INSN "nop32"
  20. #else
  21. #define NOP_INSN "nop"
  22. #endif
  23. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  24. {
  25. asm_volatile_goto("1:\t" NOP_INSN "\n\t"
  26. "nop\n\t"
  27. ".pushsection __jump_table, \"aw\"\n\t"
  28. WORD_INSN " 1b, %l[l_yes], %0\n\t"
  29. ".popsection\n\t"
  30. : : "i" (&((char *)key)[branch]) : : l_yes);
  31. return false;
  32. l_yes:
  33. return true;
  34. }
  35. static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  36. {
  37. asm_volatile_goto("1:\tj %l[l_yes]\n\t"
  38. "nop\n\t"
  39. ".pushsection __jump_table, \"aw\"\n\t"
  40. WORD_INSN " 1b, %l[l_yes], %0\n\t"
  41. ".popsection\n\t"
  42. : : "i" (&((char *)key)[branch]) : : l_yes);
  43. return false;
  44. l_yes:
  45. return true;
  46. }
  47. #ifdef CONFIG_64BIT
  48. typedef u64 jump_label_t;
  49. #else
  50. typedef u32 jump_label_t;
  51. #endif
  52. struct jump_entry {
  53. jump_label_t code;
  54. jump_label_t target;
  55. jump_label_t key;
  56. };
  57. #endif /* __ASSEMBLY__ */
  58. #endif /* _ASM_MIPS_JUMP_LABEL_H */