Commit | Line | Data |
---|---|---|
bf5438fc JB |
1 | #ifndef _LINUX_JUMP_LABEL_H |
2 | #define _LINUX_JUMP_LABEL_H | |
3 | ||
d430d3d7 JB |
4 | #include <linux/types.h> |
5 | #include <linux/compiler.h> | |
6 | ||
45f81b1c | 7 | #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL) |
d430d3d7 JB |
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 | ||
bf5438fc JB |
17 | # include <asm/jump_label.h> |
18 | # define HAVE_JUMP_LABEL | |
19 | #endif | |
20 | ||
21 | enum jump_label_type { | |
d430d3d7 | 22 | JUMP_LABEL_DISABLE = 0, |
bf5438fc | 23 | JUMP_LABEL_ENABLE, |
bf5438fc JB |
24 | }; |
25 | ||
26 | struct module; | |
27 | ||
28 | #ifdef HAVE_JUMP_LABEL | |
29 | ||
d430d3d7 | 30 | #ifdef CONFIG_MODULES |
d5d9a3b1 | 31 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL} |
d430d3d7 | 32 | #else |
d5d9a3b1 | 33 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL} |
d430d3d7 JB |
34 | #endif |
35 | ||
36 | static __always_inline bool static_branch(struct jump_label_key *key) | |
37 | { | |
38 | return arch_static_branch(key); | |
39 | } | |
40 | ||
bf5438fc JB |
41 | extern struct jump_entry __start___jump_table[]; |
42 | extern struct jump_entry __stop___jump_table[]; | |
43 | ||
91bad2f8 JB |
44 | extern void jump_label_lock(void); |
45 | extern void jump_label_unlock(void); | |
bf5438fc | 46 | extern void arch_jump_label_transform(struct jump_entry *entry, |
37348804 | 47 | enum jump_label_type type); |
4c3ef6d7 | 48 | extern int jump_label_text_reserved(void *start, void *end); |
d430d3d7 JB |
49 | extern void jump_label_inc(struct jump_label_key *key); |
50 | extern void jump_label_dec(struct jump_label_key *key); | |
51 | extern bool jump_label_enabled(struct jump_label_key *key); | |
52 | extern void jump_label_apply_nops(struct module *mod); | |
bf5438fc | 53 | |
d430d3d7 | 54 | #else |
bf5438fc | 55 | |
60063497 | 56 | #include <linux/atomic.h> |
bf5438fc | 57 | |
d430d3d7 | 58 | #define JUMP_LABEL_INIT {ATOMIC_INIT(0)} |
bf5438fc | 59 | |
d430d3d7 JB |
60 | struct jump_label_key { |
61 | atomic_t enabled; | |
62 | }; | |
bf5438fc | 63 | |
d430d3d7 JB |
64 | static __always_inline bool static_branch(struct jump_label_key *key) |
65 | { | |
66 | if (unlikely(atomic_read(&key->enabled))) | |
67 | return true; | |
68 | return false; | |
69 | } | |
bf5438fc | 70 | |
d430d3d7 JB |
71 | static inline void jump_label_inc(struct jump_label_key *key) |
72 | { | |
73 | atomic_inc(&key->enabled); | |
74 | } | |
bf5438fc | 75 | |
d430d3d7 | 76 | static inline void jump_label_dec(struct jump_label_key *key) |
bf5438fc | 77 | { |
d430d3d7 | 78 | atomic_dec(&key->enabled); |
bf5438fc JB |
79 | } |
80 | ||
4c3ef6d7 JB |
81 | static inline int jump_label_text_reserved(void *start, void *end) |
82 | { | |
83 | return 0; | |
84 | } | |
85 | ||
91bad2f8 JB |
86 | static inline void jump_label_lock(void) {} |
87 | static inline void jump_label_unlock(void) {} | |
88 | ||
d430d3d7 JB |
89 | static inline bool jump_label_enabled(struct jump_label_key *key) |
90 | { | |
91 | return !!atomic_read(&key->enabled); | |
92 | } | |
bf5438fc | 93 | |
d430d3d7 JB |
94 | static inline int jump_label_apply_nops(struct module *mod) |
95 | { | |
96 | return 0; | |
97 | } | |
98 | ||
99 | #endif | |
ebf31f50 | 100 | |
bf5438fc | 101 | #endif |