jump_label.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. #define arch_jump_label_transform_static arch_jump_label_transform
  11. #ifndef __ASSEMBLY__
  12. #include <linux/types.h>
  13. #include <asm/isa-rev.h>
  14. #define JUMP_LABEL_NOP_SIZE 4
  15. #ifdef CONFIG_64BIT
  16. #define WORD_INSN ".dword"
  17. #else
  18. #define WORD_INSN ".word"
  19. #endif
  20. #ifdef CONFIG_CPU_MICROMIPS
  21. # define B_INSN "b32"
  22. # define J_INSN "j32"
  23. #elif MIPS_ISA_REV >= 6
  24. # define B_INSN "bc"
  25. # define J_INSN "bc"
  26. #else
  27. # define B_INSN "b"
  28. # define J_INSN "j"
  29. #endif
  30. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  31. {
  32. asm_volatile_goto("1:\t" B_INSN " 2f\n\t"
  33. "2:\t.insn\n\t"
  34. ".pushsection __jump_table, \"aw\"\n\t"
  35. WORD_INSN " 1b, %l[l_yes], %0\n\t"
  36. ".popsection\n\t"
  37. : : "i" (&((char *)key)[branch]) : : l_yes);
  38. return false;
  39. l_yes:
  40. return true;
  41. }
  42. static __always_inline bool arch_static_branch_jump(struct static_key *key, bool branch)
  43. {
  44. asm_volatile_goto("1:\t" J_INSN " %l[l_yes]\n\t"
  45. ".pushsection __jump_table, \"aw\"\n\t"
  46. WORD_INSN " 1b, %l[l_yes], %0\n\t"
  47. ".popsection\n\t"
  48. : : "i" (&((char *)key)[branch]) : : l_yes);
  49. return false;
  50. l_yes:
  51. return true;
  52. }
  53. #ifdef CONFIG_64BIT
  54. typedef u64 jump_label_t;
  55. #else
  56. typedef u32 jump_label_t;
  57. #endif
  58. struct jump_entry {
  59. jump_label_t code;
  60. jump_label_t target;
  61. jump_label_t key;
  62. };
  63. #endif /* __ASSEMBLY__ */
  64. #endif /* _ASM_MIPS_JUMP_LABEL_H */