Blame view
include/linux/notifier.h
8.47 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 8 9 10 11 12 |
/* * 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 ... |
13 14 |
#include <linux/mutex.h> #include <linux/rwsem.h> |
eabc06940 [PATCH] Add SRCU-... |
15 |
#include <linux/srcu.h> |
1da177e4c Linux-2.6.12-rc2 |
16 |
|
e041c6834 [PATCH] Notifier ... |
17 |
/* |
eabc06940 [PATCH] Add SRCU-... |
18 |
* Notifier chains are of four types: |
e041c6834 [PATCH] Notifier ... |
19 20 21 22 23 24 25 26 |
* * 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-... |
27 28 |
* SRCU notifier chains: A variant of blocking notifier chains, with * the same restrictions. |
e041c6834 [PATCH] Notifier ... |
29 30 |
* * atomic_notifier_chain_register() may be called from an atomic context, |
eabc06940 [PATCH] Add SRCU-... |
31 32 33 |
* 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 ... |
34 |
* |
eabc06940 [PATCH] Add SRCU-... |
35 36 37 38 39 40 41 42 43 44 45 46 47 |
* 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 * often but notifier_blocks will seldom be removed. Also, SRCU notifier * chains are slightly more difficult to use because they require special * runtime initialization. |
e041c6834 [PATCH] Notifier ... |
48 49 50 51 |
*/ struct notifier_block { int (*notifier_call)(struct notifier_block *, unsigned long, void *); |
1da177e4c Linux-2.6.12-rc2 |
52 53 54 |
struct notifier_block *next; int priority; }; |
e041c6834 [PATCH] Notifier ... |
55 56 57 58 59 60 61 62 63 64 65 66 67 |
struct atomic_notifier_head { spinlock_t lock; struct notifier_block *head; }; struct blocking_notifier_head { struct rw_semaphore rwsem; struct notifier_block *head; }; struct raw_notifier_head { struct notifier_block *head; }; |
eabc06940 [PATCH] Add SRCU-... |
68 69 70 71 72 |
struct srcu_notifier_head { struct mutex mutex; struct srcu_struct srcu; struct notifier_block *head; }; |
e041c6834 [PATCH] Notifier ... |
73 74 75 76 77 78 79 80 81 82 83 |
#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) |
eabc06940 [PATCH] Add SRCU-... |
84 85 86 87 |
/* srcu_notifier_heads must be initialized and cleaned up dynamically */ 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 ... |
88 |
#define ATOMIC_NOTIFIER_INIT(name) { \ |
e4d919188 [PATCH] lockdep: ... |
89 |
.lock = __SPIN_LOCK_UNLOCKED(name.lock), \ |
e041c6834 [PATCH] Notifier ... |
90 91 92 93 94 95 |
.head = NULL } #define BLOCKING_NOTIFIER_INIT(name) { \ .rwsem = __RWSEM_INITIALIZER((name).rwsem), \ .head = NULL } #define RAW_NOTIFIER_INIT(name) { \ .head = NULL } |
eabc06940 [PATCH] Add SRCU-... |
96 |
/* srcu_notifier_heads cannot be initialized statically */ |
e041c6834 [PATCH] Notifier ... |
97 98 99 100 101 102 103 104 105 106 |
#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 |
107 108 |
#ifdef __KERNEL__ |
6f7cc11aa Extend notifier_c... |
109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
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 ... |
128 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
129 130 131 |
extern int __atomic_notifier_call_chain(struct atomic_notifier_head *nh, unsigned long val, void *v, int nr_to_call, int *nr_calls); extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh, |
e041c6834 [PATCH] Notifier ... |
132 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
133 134 135 |
extern int __blocking_notifier_call_chain(struct blocking_notifier_head *nh, unsigned long val, void *v, int nr_to_call, int *nr_calls); extern int raw_notifier_call_chain(struct raw_notifier_head *nh, |
e041c6834 [PATCH] Notifier ... |
136 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
137 138 139 |
extern int __raw_notifier_call_chain(struct raw_notifier_head *nh, unsigned long val, void *v, int nr_to_call, int *nr_calls); extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh, |
eabc06940 [PATCH] Add SRCU-... |
140 |
unsigned long val, void *v); |
6f7cc11aa Extend notifier_c... |
141 142 |
extern int __srcu_notifier_call_chain(struct srcu_notifier_head *nh, unsigned long val, void *v, int nr_to_call, int *nr_calls); |
1da177e4c Linux-2.6.12-rc2 |
143 144 145 146 |
#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 ... |
147 148 |
#define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002) /* Bad/Veto action */ |
1da177e4c Linux-2.6.12-rc2 |
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 |
/* * Clean way to return from the notifier and stop further calls. */ #define NOTIFY_STOP (NOTIFY_OK|NOTIFY_STOP_MASK) /* * 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... */ /* netdevice notifier chain */ #define NETDEV_UP 0x0001 /* For now you can't veto a device up/down */ #define NETDEV_DOWN 0x0002 #define NETDEV_REBOOT 0x0003 /* Tell a protocol stack a network interface detected a hardware crash and restarted - we can use this eg to kick tcp sessions once done */ #define NETDEV_CHANGE 0x0004 /* Notify device state change */ #define NETDEV_REGISTER 0x0005 #define NETDEV_UNREGISTER 0x0006 #define NETDEV_CHANGEMTU 0x0007 #define NETDEV_CHANGEADDR 0x0008 #define NETDEV_GOING_DOWN 0x0009 #define NETDEV_CHANGENAME 0x000A |
d8a33ac43 [BRIDGE]: feature... |
176 |
#define NETDEV_FEAT_CHANGE 0x000B |
1da177e4c Linux-2.6.12-rc2 |
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
#define SYS_DOWN 0x0001 /* Notify of system down */ #define SYS_RESTART SYS_DOWN #define SYS_HALT 0x0002 /* Notify of system halt */ #define SYS_POWER_OFF 0x0003 /* Notify of system power off */ #define NETLINK_URELEASE 0x0001 /* Unicast netlink socket released */ #define CPU_ONLINE 0x0002 /* CPU (unsigned)v is up */ #define CPU_UP_PREPARE 0x0003 /* CPU (unsigned)v coming up */ #define CPU_UP_CANCELED 0x0004 /* CPU (unsigned)v NOT coming up */ #define CPU_DOWN_PREPARE 0x0005 /* CPU (unsigned)v going down */ #define CPU_DOWN_FAILED 0x0006 /* CPU (unsigned)v NOT going down */ #define CPU_DEAD 0x0007 /* CPU (unsigned)v dead */ |
baaca49f4 Define and use ne... |
191 192 |
#define CPU_LOCK_ACQUIRE 0x0008 /* Acquire all hotcpu locks */ #define CPU_LOCK_RELEASE 0x0009 /* Release all hotcpu locks */ |
db912f963 HOTPLUG: Add CPU_... |
193 194 |
#define CPU_DYING 0x000A /* CPU (unsigned)v not running any task, * not handling interrupts, soon dead */ |
1da177e4c Linux-2.6.12-rc2 |
195 |
|
8bb784428 Add suspend-relat... |
196 197 198 199 200 201 202 203 204 205 206 |
/* Used for CPU hotplug events occuring while tasks are frozen due to a suspend * operation in progress */ #define CPU_TASKS_FROZEN 0x0010 #define CPU_ONLINE_FROZEN (CPU_ONLINE | CPU_TASKS_FROZEN) #define CPU_UP_PREPARE_FROZEN (CPU_UP_PREPARE | CPU_TASKS_FROZEN) #define CPU_UP_CANCELED_FROZEN (CPU_UP_CANCELED | CPU_TASKS_FROZEN) #define CPU_DOWN_PREPARE_FROZEN (CPU_DOWN_PREPARE | CPU_TASKS_FROZEN) #define CPU_DOWN_FAILED_FROZEN (CPU_DOWN_FAILED | CPU_TASKS_FROZEN) #define CPU_DEAD_FROZEN (CPU_DEAD | CPU_TASKS_FROZEN) |
db912f963 HOTPLUG: Add CPU_... |
207 |
#define CPU_DYING_FROZEN (CPU_DYING | CPU_TASKS_FROZEN) |
8bb784428 Add suspend-relat... |
208 |
|
b10d91174 PM: introduce hib... |
209 210 211 212 213 |
/* Hibernation and suspend events */ #define PM_HIBERNATION_PREPARE 0x0001 /* Going to hibernate */ #define PM_POST_HIBERNATION 0x0002 /* Hibernation finished */ #define PM_SUSPEND_PREPARE 0x0003 /* Going to suspend the system */ #define PM_POST_SUSPEND 0x0004 /* Suspend finished */ |
1da177e4c Linux-2.6.12-rc2 |
214 215 |
#endif /* __KERNEL__ */ #endif /* _LINUX_NOTIFIER_H */ |