blob: 83e745f3ead76b225d52a92608819c47d8a8c209 [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
19#endif
20
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
31#define JUMP_LABEL_INIT {{ 0 }, NULL, NULL}
32#else
33#define JUMP_LABEL_INIT {{ 0 }, NULL}
34#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
Jason Baron91bad2f2010-10-01 17:23:48 -040044extern void jump_label_lock(void);
45extern void jump_label_unlock(void);
Jason Baronbf5438fc2010-09-17 11:09:00 -040046extern void arch_jump_label_transform(struct jump_entry *entry,
47 enum jump_label_type type);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040048extern void arch_jump_label_text_poke_early(jump_label_t addr);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040049extern int jump_label_text_reserved(void *start, void *end);
Jason Barond430d3d2011-03-16 17:29:47 -040050extern void jump_label_inc(struct jump_label_key *key);
51extern void jump_label_dec(struct jump_label_key *key);
52extern bool jump_label_enabled(struct jump_label_key *key);
53extern void jump_label_apply_nops(struct module *mod);
Jason Baronbf5438fc2010-09-17 11:09:00 -040054
55#else
56
Jason Barond430d3d2011-03-16 17:29:47 -040057#include <asm/atomic.h>
Jason Baronbf5438fc2010-09-17 11:09:00 -040058
Jason Barond430d3d2011-03-16 17:29:47 -040059#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
Jason Baronbf5438fc2010-09-17 11:09:00 -040060
Jason Barond430d3d2011-03-16 17:29:47 -040061struct jump_label_key {
62 atomic_t enabled;
63};
Jason Baronbf5438fc2010-09-17 11:09:00 -040064
Jason Barond430d3d2011-03-16 17:29:47 -040065static __always_inline bool static_branch(struct jump_label_key *key)
Jason Baronbf5438fc2010-09-17 11:09:00 -040066{
Jason Barond430d3d2011-03-16 17:29:47 -040067 if (unlikely(atomic_read(&key->enabled)))
68 return true;
69 return false;
70}
71
72static inline void jump_label_inc(struct jump_label_key *key)
73{
74 atomic_inc(&key->enabled);
75}
76
77static inline void jump_label_dec(struct jump_label_key *key)
78{
79 atomic_dec(&key->enabled);
Jason Baronbf5438fc2010-09-17 11:09:00 -040080}
81
Jason Baron4c3ef6d2010-09-17 11:09:08 -040082static inline int jump_label_text_reserved(void *start, void *end)
83{
84 return 0;
85}
86
Jason Baron91bad2f2010-10-01 17:23:48 -040087static inline void jump_label_lock(void) {}
88static inline void jump_label_unlock(void) {}
89
Jason Barond430d3d2011-03-16 17:29:47 -040090static inline bool jump_label_enabled(struct jump_label_key *key)
91{
92 return !!atomic_read(&key->enabled);
93}
Jason Baronbf5438fc2010-09-17 11:09:00 -040094
Jason Barond430d3d2011-03-16 17:29:47 -040095static inline int jump_label_apply_nops(struct module *mod)
96{
97 return 0;
98}
99
100#endif
Peter Zijlstraebf31f52010-10-17 12:15:00 +0200101
Jason Baronbf5438fc2010-09-17 11:09:00 -0400102#endif