jump_label.c 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * Copyright 2015 Tilera Corporation. All Rights Reserved.
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License
  6. * as published by the Free Software Foundation, version 2.
  7. *
  8. * This program is distributed in the hope that it will be useful, but
  9. * WITHOUT ANY WARRANTY; without even the implied warranty of
  10. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  11. * NON INFRINGEMENT. See the GNU General Public License for
  12. * more details.
  13. *
  14. * jump label TILE-Gx support
  15. */
  16. #include <linux/jump_label.h>
  17. #include <linux/memory.h>
  18. #include <linux/module.h>
  19. #include <linux/mutex.h>
  20. #include <linux/cpu.h>
  21. #include <asm/cacheflush.h>
  22. #include <asm/insn.h>
  23. #ifdef HAVE_JUMP_LABEL
  24. static void __jump_label_transform(struct jump_entry *e,
  25. enum jump_label_type type)
  26. {
  27. tilegx_bundle_bits opcode;
  28. /* Operate on writable kernel text mapping. */
  29. unsigned long pc_wr = ktext_writable_addr(e->code);
  30. if (type == JUMP_LABEL_JMP)
  31. opcode = tilegx_gen_branch(e->code, e->target, false);
  32. else
  33. opcode = NOP();
  34. *(tilegx_bundle_bits *)pc_wr = opcode;
  35. /* Make sure that above mem writes were issued towards the memory. */
  36. smp_wmb();
  37. }
  38. void arch_jump_label_transform(struct jump_entry *e,
  39. enum jump_label_type type)
  40. {
  41. get_online_cpus();
  42. mutex_lock(&text_mutex);
  43. __jump_label_transform(e, type);
  44. flush_icache_range(e->code, e->code + sizeof(tilegx_bundle_bits));
  45. mutex_unlock(&text_mutex);
  46. put_online_cpus();
  47. }
  48. __init_or_module void arch_jump_label_transform_static(struct jump_entry *e,
  49. enum jump_label_type type)
  50. {
  51. __jump_label_transform(e, type);
  52. }
  53. #endif /* HAVE_JUMP_LABEL */