blob: 56594e45b0117f3ace5256f10c9bcf0a4dd5367e [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
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
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,
Jeremy Fitzhardinge37348802011-09-29 11:10:05 -070047 enum jump_label_type type);
Jeremy Fitzhardinge20284aa2011-10-03 11:01:46 -070048extern void arch_jump_label_transform_static(struct jump_entry *entry,
49 enum jump_label_type type);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040050extern int jump_label_text_reserved(void *start, void *end);
Jason Barond430d3d2011-03-16 17:29:47 -040051extern void jump_label_inc(struct jump_label_key *key);
52extern void jump_label_dec(struct jump_label_key *key);
53extern bool jump_label_enabled(struct jump_label_key *key);
54extern void jump_label_apply_nops(struct module *mod);
Jason Baronbf5438fc2010-09-17 11:09:00 -040055
56#else
57
Arun Sharma600634972011-07-26 16:09:06 -070058#include <linux/atomic.h>
Jason Baronbf5438fc2010-09-17 11:09:00 -040059
Jason Barond430d3d2011-03-16 17:29:47 -040060#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
Jason Baronbf5438fc2010-09-17 11:09:00 -040061
Jason Barond430d3d2011-03-16 17:29:47 -040062struct jump_label_key {
63 atomic_t enabled;
64};
Jason Baronbf5438fc2010-09-17 11:09:00 -040065
Jason Barond430d3d2011-03-16 17:29:47 -040066static __always_inline bool static_branch(struct jump_label_key *key)
Jason Baronbf5438fc2010-09-17 11:09:00 -040067{
Jason Barond430d3d2011-03-16 17:29:47 -040068 if (unlikely(atomic_read(&key->enabled)))
69 return true;
70 return false;
71}
72
73static inline void jump_label_inc(struct jump_label_key *key)
74{
75 atomic_inc(&key->enabled);
76}
77
78static inline void jump_label_dec(struct jump_label_key *key)
79{
80 atomic_dec(&key->enabled);
Jason Baronbf5438fc2010-09-17 11:09:00 -040081}
82
Jason Baron4c3ef6d2010-09-17 11:09:08 -040083static inline int jump_label_text_reserved(void *start, void *end)
84{
85 return 0;
86}
87
Jason Baron91bad2f2010-10-01 17:23:48 -040088static inline void jump_label_lock(void) {}
89static inline void jump_label_unlock(void) {}
90
Jason Barond430d3d2011-03-16 17:29:47 -040091static inline bool jump_label_enabled(struct jump_label_key *key)
92{
93 return !!atomic_read(&key->enabled);
94}
Jason Baronbf5438fc2010-09-17 11:09:00 -040095
Jason Barond430d3d2011-03-16 17:29:47 -040096static inline int jump_label_apply_nops(struct module *mod)
97{
98 return 0;
99}
100
101#endif
Peter Zijlstraebf31f52010-10-17 12:15:00 +0200102
Jason Baronbf5438fc2010-09-17 11:09:00 -0400103#endif