Blame view
include/linux/notifier.h
7.98 KB
b24413180 License cleanup: ... |
1 |
/* SPDX-License-Identifier: GPL-2.0 */ |
1da177e4c Linux-2.6.12-rc2 |
2 3 4 5 6 7 8 9 10 11 12 13 |
/* * Routines to manage notifier chains for passing status changes to any * interested routines. We need this instead of hard coded call lists so * that modules can poke their nose into the innards. The network devices * needed them so here they are for the rest of you. * * Alan Cox <Alan.Cox@linux.org> */ #ifndef _LINUX_NOTIFIER_H #define _LINUX_NOTIFIER_H #include <linux/errno.h> |
e041c6834 [PATCH] Notifier ... |
14 15 |
#include <linux/mutex.h> #include <linux/rwsem.h> |
eabc06940 [PATCH] Add SRCU-... |
16 |
#include <linux/srcu.h> |
1da177e4c Linux-2.6.12-rc2 |
17 |
|
e041c6834 [PATCH] Notifier ... |
18 |
/* |
eabc06940 [PATCH] Add SRCU-... |
19 |
* Notifier chains are of four types: |
e041c6834 [PATCH] Notifier ... |
20 21 22 23 24 25 26 27 |
* * Atomic notifier chains: Chain callbacks run in interrupt/atomic * context. Callouts are not allowed to block. * Blocking notifier chains: Chain callbacks run in process context. * Callouts are allowed to block. * Raw notifier chains: There are no restrictions on callbacks, * registration, or unregistration. All locking and protection * must be provided by the caller. |
eabc06940 [PATCH] Add SRCU-... |
28 29 |
* SRCU notifier chains: A variant of blocking notifier chains, with * the same restrictions. |
e041c6834 [PATCH] Notifier ... |
30 31 |
* * atomic_notifier_chain_register() may be called from an atomic context, |
eabc06940 [PATCH] Add SRCU-... |
32 33 34 |
* but blocking_notifier_chain_register() and srcu_notifier_chain_register() * must be called from a process context. Ditto for the corresponding * _unregister() routines. |
e041c6834 [PATCH] Notifier ... |
35 |
* |
eabc06940 [PATCH] Add SRCU-... |
36 37 38 39 40 41 42 43 44 45 |
* atomic_notifier_chain_unregister(), blocking_notifier_chain_unregister(), * and srcu_notifier_chain_unregister() _must not_ be called from within * the call chain. * * SRCU notifier chains are an alternative form of blocking notifier chains. * They use SRCU (Sleepable Read-Copy Update) instead of rw-semaphores for * protection of the chain links. This means there is _very_ low overhead * in srcu_notifier_call_chain(): no cache bounces and no memory barriers. * As compensation, srcu_notifier_chain_unregister() is rather expensive. * SRCU notifier chains should be used when the chain will be called very |
9c80172b9 kernel/SRCU: prov... |
46 |
* often but notifier_blocks will seldom be removed. |
e041c6834 [PATCH] Notifier ... |
47 |
*/ |
27d50c7ee rcu: Make CPU_DYI... |
48 |
struct notifier_block; |
f02c69680 include/linux/mem... |
49 50 |
typedef int (*notifier_fn_t)(struct notifier_block *nb, unsigned long action, void *data); |
e041c6834 [PATCH] Notifier ... |
51 |
struct notifier_block { |
f02c69680 include/linux/mem... |
52 |
notifier_fn_t notifier_call; |
374a8e0dc notifiers: __rcu ... |
53 |
struct notifier_block __rcu *next; |
1da177e4c Linux-2.6.12-rc2 |
54 55 |
int priority; }; |
e041c6834 [PATCH] Notifier ... |
56 57 |
struct atomic_notifier_head { spinlock_t lock; |
374a8e0dc notifiers: __rcu ... |
58 |
struct notifier_block __rcu *head; |
e041c6834 [PATCH] Notifier ... |
59 60 61 62 |
}; struct blocking_notifier_head { struct rw_semaphore rwsem; |
374a8e0dc notifiers: __rcu ... |
63 |
struct notifier_block __rcu *head; |
e041c6834 [PATCH] Notifier ... |
64 65 66 |
}; struct raw_notifier_head { |
374a8e0dc notifiers: __rcu ... |
67 |
struct notifier_block __rcu *head; |
e041c6834 [PATCH] Notifier ... |
68 |
}; |
eabc06940 [PATCH] Add SRCU-... |
69 70 71 |
struct srcu_notifier_head { struct mutex mutex; struct srcu_struct srcu; |
374a8e0dc notifiers: __rcu ... |
72 |
struct notifier_block __rcu *head; |
eabc06940 [PATCH] Add SRCU-... |
73 |
}; |
e041c6834 [PATCH] Notifier ... |
74 75 76 77 78 79 80 81 82 83 84 |
#define ATOMIC_INIT_NOTIFIER_HEAD(name) do { \ spin_lock_init(&(name)->lock); \ (name)->head = NULL; \ } while (0) #define BLOCKING_INIT_NOTIFIER_HEAD(name) do { \ init_rwsem(&(name)->rwsem); \ (name)->head = NULL; \ } while (0) #define RAW_INIT_NOTIFIER_HEAD(name) do { \ (name)->head = NULL; \ } while (0) |
9c80172b9 kernel/SRCU: prov... |
85 |
/* srcu_notifier_heads must be cleaned up dynamically */ |
eabc06940 [PATCH] Add SRCU-... |
86 87 88 |
extern void srcu_init_notifier_head(struct srcu_notifier_head *nh); #define srcu_cleanup_notifier_head(name) \ cleanup_srcu_struct(&(name)->srcu); |
e041c6834 [PATCH] Notifier ... |
89 |
#define ATOMIC_NOTIFIER_INIT(name) { \ |
e4d919188 [PATCH] lockdep: ... |
90 |
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \ |
e041c6834 [PATCH] Notifier ... |
91 92 93 94 95 96 |
.head = NULL } #define BLOCKING_NOTIFIER_INIT(name) { \ .rwsem = __RWSEM_INITIALIZER((name).rwsem), \ .head = NULL } #define RAW_NOTIFIER_INIT(name) { \ .head = NULL } |
9c80172b9 kernel/SRCU: prov... |
97 98 99 100 101 102 103 |
#define SRCU_NOTIFIER_INIT(name, pcpu) \ { \ .mutex = __MUTEX_INITIALIZER(name.mutex), \ .head = NULL, \ .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \ } |
e041c6834 [PATCH] Notifier ... |
104 105 106 107 108 109 110 111 112 113 |
#define ATOMIC_NOTIFIER_HEAD(name) \ struct atomic_notifier_head name = \ ATOMIC_NOTIFIER_INIT(name) #define BLOCKING_NOTIFIER_HEAD(name) \ struct blocking_notifier_head name = \ BLOCKING_NOTIFIER_INIT(name) #define RAW_NOTIFIER_HEAD(name) \ struct raw_notifier_head name = \ RAW_NOTIFIER_INIT(name) |
1da177e4c Linux-2.6.12-rc2 |
114 |
|
9c80172b9 kernel/SRCU: prov... |
115 116 |
#ifdef CONFIG_TREE_SRCU #define _SRCU_NOTIFIER_HEAD(name, mod) \ |
94e297c50 include/linux/not... |
117 |
static DEFINE_PER_CPU(struct srcu_data, name##_head_srcu_data); \ |
9c80172b9 kernel/SRCU: prov... |
118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
mod struct srcu_notifier_head name = \ SRCU_NOTIFIER_INIT(name, name##_head_srcu_data) #else #define _SRCU_NOTIFIER_HEAD(name, mod) \ mod struct srcu_notifier_head name = \ SRCU_NOTIFIER_INIT(name, name) #endif #define SRCU_NOTIFIER_HEAD(name) \ _SRCU_NOTIFIER_HEAD(name, /* not static */) #define SRCU_NOTIFIER_HEAD_STATIC(name) \ _SRCU_NOTIFIER_HEAD(name, static) |
1da177e4c Linux-2.6.12-rc2 |
133 |
#ifdef __KERNEL__ |
6f7cc11aa Extend notifier_c... |
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh, struct notifier_block *nb); extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh, struct notifier_block *nb); extern int raw_notifier_chain_register(struct raw_notifier_head *nh, struct notifier_block *nb); extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh, struct notifier_block *nb); extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh, struct notifier_block *nb); extern int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh, struct notifier_block *nb); extern int raw_notifier_chain_unregister(struct raw_notifier_head *nh, struct notifier_block *nb); extern int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh, struct notifier_block *nb); extern int atomic_notifier_call_chain(struct atomic_notifier_head *nh, |
e041c6834 [PATCH] Notifier ... |
153 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
154 |
extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh, |
e041c6834 [PATCH] Notifier ... |
155 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
156 |
extern int raw_notifier_call_chain(struct raw_notifier_head *nh, |
e041c6834 [PATCH] Notifier ... |
157 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
158 |
extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh, |
eabc06940 [PATCH] Add SRCU-... |
159 |
unsigned long val, void *v); |
70d932985 notifier: Fix bro... |
160 161 162 163 164 165 166 |
extern int atomic_notifier_call_chain_robust(struct atomic_notifier_head *nh, unsigned long val_up, unsigned long val_down, void *v); extern int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh, unsigned long val_up, unsigned long val_down, void *v); extern int raw_notifier_call_chain_robust(struct raw_notifier_head *nh, unsigned long val_up, unsigned long val_down, void *v); |
1da177e4c Linux-2.6.12-rc2 |
167 168 169 170 |
#define NOTIFY_DONE 0x0000 /* Don't care */ #define NOTIFY_OK 0x0001 /* Suits me */ #define NOTIFY_STOP_MASK 0x8000 /* Don't call further */ |
e041c6834 [PATCH] Notifier ... |
171 172 |
#define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002) /* Bad/Veto action */ |
1da177e4c Linux-2.6.12-rc2 |
173 174 175 176 |
/* * Clean way to return from the notifier and stop further calls. */ #define NOTIFY_STOP (NOTIFY_OK|NOTIFY_STOP_MASK) |
fcc5a03ac [NET]: Allow netd... |
177 178 179 |
/* Encapsulate (negative) errno value (in particular, NOTIFY_BAD <=> EPERM). */ static inline int notifier_from_errno(int err) { |
b957e043e notifier: change ... |
180 181 182 183 |
if (err) return NOTIFY_STOP_MASK | (NOTIFY_OK - err); return NOTIFY_OK; |
fcc5a03ac [NET]: Allow netd... |
184 185 186 187 188 189 190 191 |
} /* Restore (negative) errno value from notify return value. */ static inline int notifier_to_errno(int ret) { ret &= ~NOTIFY_STOP_MASK; return ret > NOTIFY_OK ? NOTIFY_OK - ret : 0; } |
1da177e4c Linux-2.6.12-rc2 |
192 193 194 195 196 197 198 199 |
/* * Declared notifiers so far. I can imagine quite a few more chains * over time (eg laptop power reset chains, reboot chain (to clean * device units up), device [un]mount chain, module load/unload chain, * low memory chain, screenblank chain (for plug in modular screenblankers) * VC switch chains (for loadable kernel svgalib VC switch helpers) etc... */ |
80f1ff97d notifiers: cpu: m... |
200 |
/* CPU notfiers are defined in include/linux/cpu.h. */ |
dcfe1421c notifiers: net: m... |
201 |
/* netdevice notifiers are defined in include/linux/netdevice.h */ |
1da177e4c Linux-2.6.12-rc2 |
202 |
|
c5f41752f notifiers: sys: m... |
203 |
/* reboot notifiers are defined in include/linux/reboot.h. */ |
1da177e4c Linux-2.6.12-rc2 |
204 |
|
35eb6db11 notifiers: pm: mo... |
205 |
/* Hibernation and suspend events are defined in include/linux/suspend.h. */ |
1da177e4c Linux-2.6.12-rc2 |
206 |
|
a376d3d67 notifiers: vt: mo... |
207 |
/* Virtual Terminal events are defined in include/linux/vt.h. */ |
35eb6db11 notifiers: pm: mo... |
208 |
#define NETLINK_URELEASE 0x0001 /* Unicast netlink socket released */ |
b10d91174 PM: introduce hib... |
209 |
|
41ab4396e Console keyboard ... |
210 211 212 213 214 215 216 217 |
/* Console keyboard events. * Note: KBD_KEYCODE is always sent before KBD_UNBOUND_KEYCODE, KBD_UNICODE and * KBD_KEYSYM. */ #define KBD_KEYCODE 0x0001 /* Keyboard keycode, called before any other */ #define KBD_UNBOUND_KEYCODE 0x0002 /* Keyboard keycode which is not bound to any other */ #define KBD_UNICODE 0x0003 /* Keyboard unicode */ #define KBD_KEYSYM 0x0004 /* Keyboard keysym */ #define KBD_POST_KEYSYM 0x0005 /* Called after keyboard keysym interpretation */ |
fe9d4f576 Add kernel/notifi... |
218 |
extern struct blocking_notifier_head reboot_notifier_list; |
1da177e4c Linux-2.6.12-rc2 |
219 220 |
#endif /* __KERNEL__ */ #endif /* _LINUX_NOTIFIER_H */ |