blob: 12e804ea32abd0e5c75d0b858b91ae00c28d4398 [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 Baron91bad2f82010-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);
Jason Baron4c3ef6d2010-09-17 11:09:08 -040048extern int jump_label_text_reserved(void *start, void *end);
Jason Barond430d3d2011-03-16 17:29:47 -040049extern void jump_label_inc(struct jump_label_key *key);
50extern void jump_label_dec(struct jump_label_key *key);
51extern bool jump_label_enabled(struct jump_label_key *key);
52extern void jump_label_apply_nops(struct module *mod);
Jason Baronbf5438fc2010-09-17 11:09:00 -040053
54#else
55
Arun Sharma60063492011-07-26 16:09:06 -070056#include <linux/atomic.h>
Jason Baronbf5438fc2010-09-17 11:09:00 -040057
Jason Barond430d3d2011-03-16 17:29:47 -040058#define JUMP_LABEL_INIT {ATOMIC_INIT(0)}
Jason Baronbf5438fc2010-09-17 11:09:00 -040059
Jason Barond430d3d2011-03-16 17:29:47 -040060struct jump_label_key {
61 atomic_t enabled;
62};
Jason Baronbf5438fc2010-09-17 11:09:00 -040063
Jason Barond430d3d2011-03-16 17:29:47 -040064static __always_inline bool static_branch(struct jump_label_key *key)
Jason Baronbf5438fc2010-09-17 11:09:00 -040065{
Jason Barond430d3d2011-03-16 17:29:47 -040066 if (unlikely(atomic_read(&key->enabled)))
67 return true;
68 return false;
69}
70
71static inline void jump_label_inc(struct jump_label_key *key)
72{
73 atomic_inc(&key->enabled);
74}
75
76static inline void jump_label_dec(struct jump_label_key *key)
77{
78 atomic_dec(&key->enabled);
Jason Baronbf5438fc2010-09-17 11:09:00 -040079}
80
Jason Baron4c3ef6d2010-09-17 11:09:08 -040081static inline int jump_label_text_reserved(void *start, void *end)
82{
83 return 0;
84}
85
Jason Baron91bad2f82010-10-01 17:23:48 -040086static inline void jump_label_lock(void) {}
87static inline void jump_label_unlock(void) {}
88
Jason Barond430d3d2011-03-16 17:29:47 -040089static inline bool jump_label_enabled(struct jump_label_key *key)
90{
91 return !!atomic_read(&key->enabled);
92}
Jason Baronbf5438fc2010-09-17 11:09:00 -040093
Jason Barond430d3d2011-03-16 17:29:47 -040094static inline int jump_label_apply_nops(struct module *mod)
95{
96 return 0;
97}
98
99#endif
Peter Zijlstraebf31f52010-10-17 12:15:00 +0200100
Jason Baronbf5438fc2010-09-17 11:09:00 -0400101#endif