Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 1 | #ifndef _LINUX_JUMP_LABEL_H |
| 2 | #define _LINUX_JUMP_LABEL_H |
| 3 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 4 | #include <linux/types.h> |
| 5 | #include <linux/compiler.h> |
| 6 | |
Steven Rostedt | 45f81b1 | 2010-10-29 12:33:43 -0400 | [diff] [blame] | 7 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 8 | |
| 9 | struct jump_label_key { |
| 10 | atomic_t enabled; |
| 11 | struct jump_entry *entries; |
| 12 | #ifdef CONFIG_MODULES |
| 13 | struct jump_label_mod *next; |
| 14 | #endif |
| 15 | }; |
| 16 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 17 | # include <asm/jump_label.h> |
| 18 | # define HAVE_JUMP_LABEL |
| 19 | #endif |
| 20 | |
| 21 | enum jump_label_type { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 22 | JUMP_LABEL_DISABLE = 0, |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 23 | JUMP_LABEL_ENABLE, |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 24 | }; |
| 25 | |
| 26 | struct module; |
| 27 | |
| 28 | #ifdef HAVE_JUMP_LABEL |
| 29 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 30 | #ifdef CONFIG_MODULES |
Jeremy Fitzhardinge | d5d9a3b | 2011-09-28 17:45:15 -0700 | [diff] [blame] | 31 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL} |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 32 | #else |
Jeremy Fitzhardinge | d5d9a3b | 2011-09-28 17:45:15 -0700 | [diff] [blame] | 33 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL} |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 34 | #endif |
| 35 | |
| 36 | static __always_inline bool static_branch(struct jump_label_key *key) |
| 37 | { |
| 38 | return arch_static_branch(key); |
| 39 | } |
| 40 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 41 | extern struct jump_entry __start___jump_table[]; |
| 42 | extern struct jump_entry __stop___jump_table[]; |
| 43 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 44 | extern void jump_label_lock(void); |
| 45 | extern void jump_label_unlock(void); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 46 | extern void arch_jump_label_transform(struct jump_entry *entry, |
Jeremy Fitzhardinge | 3734880 | 2011-09-29 11:10:05 -0700 | [diff] [blame] | 47 | enum jump_label_type type); |
Jeremy Fitzhardinge | 20284aa | 2011-10-03 11:01:46 -0700 | [diff] [blame^] | 48 | extern void arch_jump_label_transform_static(struct jump_entry *entry, |
| 49 | enum jump_label_type type); |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 50 | extern int jump_label_text_reserved(void *start, void *end); |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 51 | extern void jump_label_inc(struct jump_label_key *key); |
| 52 | extern void jump_label_dec(struct jump_label_key *key); |
| 53 | extern bool jump_label_enabled(struct jump_label_key *key); |
| 54 | extern void jump_label_apply_nops(struct module *mod); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 55 | |
| 56 | #else |
| 57 | |
Arun Sharma | 60063497 | 2011-07-26 16:09:06 -0700 | [diff] [blame] | 58 | #include <linux/atomic.h> |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 59 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 60 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0)} |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 61 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 62 | struct jump_label_key { |
| 63 | atomic_t enabled; |
| 64 | }; |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 65 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 66 | static __always_inline bool static_branch(struct jump_label_key *key) |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 67 | { |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 68 | if (unlikely(atomic_read(&key->enabled))) |
| 69 | return true; |
| 70 | return false; |
| 71 | } |
| 72 | |
| 73 | static inline void jump_label_inc(struct jump_label_key *key) |
| 74 | { |
| 75 | atomic_inc(&key->enabled); |
| 76 | } |
| 77 | |
| 78 | static inline void jump_label_dec(struct jump_label_key *key) |
| 79 | { |
| 80 | atomic_dec(&key->enabled); |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 81 | } |
| 82 | |
Jason Baron | 4c3ef6d | 2010-09-17 11:09:08 -0400 | [diff] [blame] | 83 | static inline int jump_label_text_reserved(void *start, void *end) |
| 84 | { |
| 85 | return 0; |
| 86 | } |
| 87 | |
Jason Baron | 91bad2f | 2010-10-01 17:23:48 -0400 | [diff] [blame] | 88 | static inline void jump_label_lock(void) {} |
| 89 | static inline void jump_label_unlock(void) {} |
| 90 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 91 | static inline bool jump_label_enabled(struct jump_label_key *key) |
| 92 | { |
| 93 | return !!atomic_read(&key->enabled); |
| 94 | } |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 95 | |
Jason Baron | d430d3d | 2011-03-16 17:29:47 -0400 | [diff] [blame] | 96 | static inline int jump_label_apply_nops(struct module *mod) |
| 97 | { |
| 98 | return 0; |
| 99 | } |
| 100 | |
| 101 | #endif |
Peter Zijlstra | ebf31f5 | 2010-10-17 12:15:00 +0200 | [diff] [blame] | 102 | |
Jason Baron | bf5438fc | 2010-09-17 11:09:00 -0400 | [diff] [blame] | 103 | #endif |