0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011 #ifndef _LINUX_NOTIFIER_H
0012 #define _LINUX_NOTIFIER_H
0013 #include <linux/errno.h>
0014 #include <linux/mutex.h>
0015 #include <linux/rwsem.h>
0016 #include <linux/srcu.h>
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048
0049 struct notifier_block;
0050
0051 typedef int (*notifier_fn_t)(struct notifier_block *nb,
0052 unsigned long action, void *data);
0053
0054 struct notifier_block {
0055 notifier_fn_t notifier_call;
0056 struct notifier_block __rcu *next;
0057 int priority;
0058 };
0059
0060 struct atomic_notifier_head {
0061 spinlock_t lock;
0062 struct notifier_block __rcu *head;
0063 };
0064
0065 struct blocking_notifier_head {
0066 struct rw_semaphore rwsem;
0067 struct notifier_block __rcu *head;
0068 };
0069
0070 struct raw_notifier_head {
0071 struct notifier_block __rcu *head;
0072 };
0073
0074 struct srcu_notifier_head {
0075 struct mutex mutex;
0076 struct srcu_struct srcu;
0077 struct notifier_block __rcu *head;
0078 };
0079
0080 #define ATOMIC_INIT_NOTIFIER_HEAD(name) do { \
0081 spin_lock_init(&(name)->lock); \
0082 (name)->head = NULL; \
0083 } while (0)
0084 #define BLOCKING_INIT_NOTIFIER_HEAD(name) do { \
0085 init_rwsem(&(name)->rwsem); \
0086 (name)->head = NULL; \
0087 } while (0)
0088 #define RAW_INIT_NOTIFIER_HEAD(name) do { \
0089 (name)->head = NULL; \
0090 } while (0)
0091
0092
0093 extern void srcu_init_notifier_head(struct srcu_notifier_head *nh);
0094 #define srcu_cleanup_notifier_head(name) \
0095 cleanup_srcu_struct(&(name)->srcu);
0096
0097 #define ATOMIC_NOTIFIER_INIT(name) { \
0098 .lock = __SPIN_LOCK_UNLOCKED(name.lock), \
0099 .head = NULL }
0100 #define BLOCKING_NOTIFIER_INIT(name) { \
0101 .rwsem = __RWSEM_INITIALIZER((name).rwsem), \
0102 .head = NULL }
0103 #define RAW_NOTIFIER_INIT(name) { \
0104 .head = NULL }
0105
0106 #define SRCU_NOTIFIER_INIT(name, pcpu) \
0107 { \
0108 .mutex = __MUTEX_INITIALIZER(name.mutex), \
0109 .head = NULL, \
0110 .srcu = __SRCU_STRUCT_INIT(name.srcu, pcpu), \
0111 }
0112
0113 #define ATOMIC_NOTIFIER_HEAD(name) \
0114 struct atomic_notifier_head name = \
0115 ATOMIC_NOTIFIER_INIT(name)
0116 #define BLOCKING_NOTIFIER_HEAD(name) \
0117 struct blocking_notifier_head name = \
0118 BLOCKING_NOTIFIER_INIT(name)
0119 #define RAW_NOTIFIER_HEAD(name) \
0120 struct raw_notifier_head name = \
0121 RAW_NOTIFIER_INIT(name)
0122
0123 #ifdef CONFIG_TREE_SRCU
0124 #define _SRCU_NOTIFIER_HEAD(name, mod) \
0125 static DEFINE_PER_CPU(struct srcu_data, name##_head_srcu_data); \
0126 mod struct srcu_notifier_head name = \
0127 SRCU_NOTIFIER_INIT(name, name##_head_srcu_data)
0128
0129 #else
0130 #define _SRCU_NOTIFIER_HEAD(name, mod) \
0131 mod struct srcu_notifier_head name = \
0132 SRCU_NOTIFIER_INIT(name, name)
0133
0134 #endif
0135
0136 #define SRCU_NOTIFIER_HEAD(name) \
0137 _SRCU_NOTIFIER_HEAD(name, )
0138
0139 #define SRCU_NOTIFIER_HEAD_STATIC(name) \
0140 _SRCU_NOTIFIER_HEAD(name, static)
0141
0142 #ifdef __KERNEL__
0143
0144 extern int atomic_notifier_chain_register(struct atomic_notifier_head *nh,
0145 struct notifier_block *nb);
0146 extern int blocking_notifier_chain_register(struct blocking_notifier_head *nh,
0147 struct notifier_block *nb);
0148 extern int raw_notifier_chain_register(struct raw_notifier_head *nh,
0149 struct notifier_block *nb);
0150 extern int srcu_notifier_chain_register(struct srcu_notifier_head *nh,
0151 struct notifier_block *nb);
0152
0153 extern int atomic_notifier_chain_register_unique_prio(
0154 struct atomic_notifier_head *nh, struct notifier_block *nb);
0155 extern int blocking_notifier_chain_register_unique_prio(
0156 struct blocking_notifier_head *nh, struct notifier_block *nb);
0157
0158 extern int atomic_notifier_chain_unregister(struct atomic_notifier_head *nh,
0159 struct notifier_block *nb);
0160 extern int blocking_notifier_chain_unregister(struct blocking_notifier_head *nh,
0161 struct notifier_block *nb);
0162 extern int raw_notifier_chain_unregister(struct raw_notifier_head *nh,
0163 struct notifier_block *nb);
0164 extern int srcu_notifier_chain_unregister(struct srcu_notifier_head *nh,
0165 struct notifier_block *nb);
0166
0167 extern int atomic_notifier_call_chain(struct atomic_notifier_head *nh,
0168 unsigned long val, void *v);
0169 extern int blocking_notifier_call_chain(struct blocking_notifier_head *nh,
0170 unsigned long val, void *v);
0171 extern int raw_notifier_call_chain(struct raw_notifier_head *nh,
0172 unsigned long val, void *v);
0173 extern int srcu_notifier_call_chain(struct srcu_notifier_head *nh,
0174 unsigned long val, void *v);
0175
0176 extern int blocking_notifier_call_chain_robust(struct blocking_notifier_head *nh,
0177 unsigned long val_up, unsigned long val_down, void *v);
0178 extern int raw_notifier_call_chain_robust(struct raw_notifier_head *nh,
0179 unsigned long val_up, unsigned long val_down, void *v);
0180
0181 extern bool atomic_notifier_call_chain_is_empty(struct atomic_notifier_head *nh);
0182
0183 #define NOTIFY_DONE 0x0000
0184 #define NOTIFY_OK 0x0001
0185 #define NOTIFY_STOP_MASK 0x8000
0186 #define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002)
0187
0188
0189
0190
0191 #define NOTIFY_STOP (NOTIFY_OK|NOTIFY_STOP_MASK)
0192
0193
0194 static inline int notifier_from_errno(int err)
0195 {
0196 if (err)
0197 return NOTIFY_STOP_MASK | (NOTIFY_OK - err);
0198
0199 return NOTIFY_OK;
0200 }
0201
0202
0203 static inline int notifier_to_errno(int ret)
0204 {
0205 ret &= ~NOTIFY_STOP_MASK;
0206 return ret > NOTIFY_OK ? NOTIFY_OK - ret : 0;
0207 }
0208
0209
0210
0211
0212
0213
0214
0215
0216
0217
0218
0219
0220
0221
0222
0223
0224
0225
0226
0227 #define NETLINK_URELEASE 0x0001
0228
0229
0230
0231
0232 #define KBD_KEYCODE 0x0001
0233 #define KBD_UNBOUND_KEYCODE 0x0002
0234 #define KBD_UNICODE 0x0003
0235 #define KBD_KEYSYM 0x0004
0236 #define KBD_POST_KEYSYM 0x0005
0237
0238 extern struct blocking_notifier_head reboot_notifier_list;
0239
0240 #endif
0241 #endif