jump_label.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #ifndef _ASM_POWERPC_JUMP_LABEL_H
  2. #define _ASM_POWERPC_JUMP_LABEL_H
  3. /*
  4. * Copyright 2010 Michael Ellerman, IBM Corp.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version
  9. * 2 of the License, or (at your option) any later version.
  10. */
  11. #ifndef __ASSEMBLY__
  12. #include <linux/types.h>
  13. #include <asm/feature-fixups.h>
  14. #include <asm/asm-compat.h>
  15. #define JUMP_ENTRY_TYPE stringify_in_c(FTR_ENTRY_LONG)
  16. #define JUMP_LABEL_NOP_SIZE 4
  17. static __always_inline bool arch_static_branch(struct static_key *key, bool branch)
  18. {
  19. asm_volatile_goto("1:\n\t"
  20. "nop # arch_static_branch\n\t"
  21. ".pushsection __jump_table, \"aw\"\n\t"
  22. JUMP_ENTRY_TYPE "1b, %l[l_yes], %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, bool branch)
  30. {
  31. asm_volatile_goto("1:\n\t"
  32. "b %l[l_yes] # arch_static_branch_jump\n\t"
  33. ".pushsection __jump_table, \"aw\"\n\t"
  34. JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
  35. ".popsection \n\t"
  36. : : "i" (&((char *)key)[branch]) : : l_yes);
  37. return false;
  38. l_yes:
  39. return true;
  40. }
  41. #ifdef CONFIG_PPC64
  42. typedef u64 jump_label_t;
  43. #else
  44. typedef u32 jump_label_t;
  45. #endif
  46. struct jump_entry {
  47. jump_label_t code;
  48. jump_label_t target;
  49. jump_label_t key;
  50. };
  51. #else
  52. #define ARCH_STATIC_BRANCH(LABEL, KEY) \
  53. 1098: nop; \
  54. .pushsection __jump_table, "aw"; \
  55. FTR_ENTRY_LONG 1098b, LABEL, KEY; \
  56. .popsection
  57. #endif
  58. #endif /* _ASM_POWERPC_JUMP_LABEL_H */