blob: 388b0d425b507add656cca2aa7b48a346bf159ec [file] [log] [blame]
Jason Baronbf5438fc2010-09-17 11:09:00 -04001#ifndef _LINUX_JUMP_LABEL_H
2#define _LINUX_JUMP_LABEL_H
3
Jason Barond430d3d2011-03-16 17:29:47 -04004#include <linux/types.h>
5#include <linux/compiler.h>
6
Steven Rostedt45f81b12010-10-29 12:33:43 -04007#if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
Jason Barond430d3d2011-03-16 17:29:47 -04008
9struct 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 Baronbf5438fc2010-09-17 11:09:00 -040017# include <asm/jump_label.h>
18# define HAVE_JUMP_LABEL
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -070019#endif /* CC_HAVE_ASM_GOTO && CONFIG_JUMP_LABEL */
Jason Baronbf5438fc2010-09-17 11:09:00 -040020
21enum jump_label_type {
Jason Barond430d3d2011-03-16 17:29:47 -040022 JUMP_LABEL_DISABLE = 0,
Jason Baronbf5438fc2010-09-17 11:09:00 -040023 JUMP_LABEL_ENABLE,
Jason Baronbf5438fc2010-09-17 11:09:00 -040024};
25
26struct module;
27
28#ifdef HAVE_JUMP_LABEL
29
Jason Barond430d3d2011-03-16 17:29:47 -040030#ifdef CONFIG_MODULES
Jeremy Fitzhardinged5d9a3b2011-09-28 17:45:15 -070031#define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL, NULL}
Jason Barond430d3d2011-03-16 17:29:47 -040032#else
Jeremy Fitzhardinged5d9a3b2011-09-28 17:45:15 -070033#define JUMP_LABEL_INIT {ATOMIC_INIT(0), NULL}
Jason Barond430d3d2011-03-16 17:29:47 -040034#endif
35
36static __always_inline bool static_branch(struct jump_label_key *key)
37{
38 return arch_static_branch(key);
39}
40
Jason Baronbf5438fc2010-09-17 11:09:00 -040041extern struct jump_entry __start___jump_table[];
42extern struct jump_entry __stop___jump_table[];
43
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -070044extern void jump_label_init(void);
Jason Baron91bad2f82010-10-01 17:23:48 -040045extern void jump_label_lock(void);
46extern void jump_label_unlock(void);
Jason Baronbf5438fc2010-09-17 11:09:00 -040047extern void arch_jump_label_transform(struct jump_entry *entry,
Jeremy Fitzhardinge37348802011-09-29 11:10:05 -070048 enum jump_label_type type);
Jeremy Fitzhardinge20284aa2011-10-03 11:01:46 -070049extern void arch_jump_label_transform_static(struct jump_entry *entry,
50 enum jump_label_type type);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040051extern int jump_label_text_reserved(void *start, void *end);
Jason Barond430d3d2011-03-16 17:29:47 -040052extern void jump_label_inc(struct jump_label_key *key);
53extern void jump_label_dec(struct jump_label_key *key);
54extern bool jump_label_enabled(struct jump_label_key *key);
55extern void jump_label_apply_nops(struct module *mod);
Jason Baronbf5438fc2010-09-17 11:09:00 -040056
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -070057#else /* !HAVE_JUMP_LABEL */
Jason Baronbf5438fc2010-09-17 11:09:00 -040058
Arun Sharma60063492011-07-26 16:09:06 -070059#include <linux/atomic.h>
Jason Baronbf5438fc2010-09-17 11:09:00 -040060
Jason Barond430d3d2011-03-16 17:29:47 -040061#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
Jason Baronbf5438fc2010-09-17 11:09:00 -040062
Jason Barond430d3d2011-03-16 17:29:47 -040063struct jump_label_key {
64 atomic_t enabled;
65};
Jason Baronbf5438fc2010-09-17 11:09:00 -040066
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -070067static __always_inline void jump_label_init(void)
68{
69}
70
Jason Barond430d3d2011-03-16 17:29:47 -040071static __always_inline bool static_branch(struct jump_label_key *key)
Jason Baronbf5438fc2010-09-17 11:09:00 -040072{
Jason Barond430d3d2011-03-16 17:29:47 -040073 if (unlikely(atomic_read(&key->enabled)))
74 return true;
75 return false;
76}
77
78static inline void jump_label_inc(struct jump_label_key *key)
79{
80 atomic_inc(&key->enabled);
81}
82
83static inline void jump_label_dec(struct jump_label_key *key)
84{
85 atomic_dec(&key->enabled);
Jason Baronbf5438fc2010-09-17 11:09:00 -040086}
87
Jason Baron4c3ef6d2010-09-17 11:09:08 -040088static inline int jump_label_text_reserved(void *start, void *end)
89{
90 return 0;
91}
92
Jason Baron91bad2f82010-10-01 17:23:48 -040093static inline void jump_label_lock(void) {}
94static inline void jump_label_unlock(void) {}
95
Jason Barond430d3d2011-03-16 17:29:47 -040096static inline bool jump_label_enabled(struct jump_label_key *key)
97{
98 return !!atomic_read(&key->enabled);
99}
Jason Baronbf5438fc2010-09-17 11:09:00 -0400100
Jason Barond430d3d2011-03-16 17:29:47 -0400101static inline int jump_label_apply_nops(struct module *mod)
102{
103 return 0;
104}
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -0700105#endif /* HAVE_JUMP_LABEL */
Jason Barond430d3d2011-03-16 17:29:47 -0400106
Jeremy Fitzhardinge97ce2c82011-10-12 16:17:54 -0700107#endif /* _LINUX_JUMP_LABEL_H */