jump_label.c 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. #include <linux/jump_label.h>
  9. #include <linux/kernel.h>
  10. #include <linux/memory.h>
  11. #include <linux/mutex.h>
  12. #include <linux/types.h>
  13. #include <linux/cpu.h>
  14. #include <asm/cacheflush.h>
  15. #include <asm/inst.h>
  16. #ifdef HAVE_JUMP_LABEL
  17. #define J_RANGE_MASK ((1ul << 28) - 1)
  18. void arch_jump_label_transform(struct jump_entry *e,
  19. enum jump_label_type type)
  20. {
  21. union mips_instruction insn;
  22. union mips_instruction *insn_p =
  23. (union mips_instruction *)(unsigned long)e->code;
  24. /* Jump only works within a 256MB aligned region. */
  25. BUG_ON((e->target & ~J_RANGE_MASK) != (e->code & ~J_RANGE_MASK));
  26. /* Target must have 4 byte alignment. */
  27. BUG_ON((e->target & 3) != 0);
  28. if (type == JUMP_LABEL_ENABLE) {
  29. insn.j_format.opcode = j_op;
  30. insn.j_format.target = (e->target & J_RANGE_MASK) >> 2;
  31. } else {
  32. insn.word = 0; /* nop */
  33. }
  34. get_online_cpus();
  35. mutex_lock(&text_mutex);
  36. *insn_p = insn;
  37. flush_icache_range((unsigned long)insn_p,
  38. (unsigned long)insn_p + sizeof(*insn_p));
  39. mutex_unlock(&text_mutex);
  40. put_online_cpus();
  41. }
  42. #endif /* HAVE_JUMP_LABEL */