source: GPL/trunk/include/linux/notifier.h@ 703

Last change on this file since 703 was 679, checked in by David Azarewicz, 4 years ago

Merge changes from Paul's uniaud32next branch.

File size: 3.4 KB
Line 
1/*
2 * Routines to manage notifier chains for passing status changes to any
3 * interested routines. We need this instead of hard coded call lists so
4 * that modules can poke their nose into the innards. The network devices
5 * needed them so here they are for the rest of you.
6 *
7 * Alan Cox <Alan.Cox@linux.org>
8 */
9
10#ifndef _LINUX_NOTIFIER_H
11#define _LINUX_NOTIFIER_H
12#include <linux/errno.h>
13#include <linux/rwsem.h>
14
15typedef int (*notifier_fn_t)(struct notifier_block *nb,
16 unsigned long action, void *data);
17
18struct notifier_block
19{
20 int (*notifier_call)(struct notifier_block *self, unsigned long, void *);
21 struct notifier_block *next;
22 int priority;
23};
24
25struct atomic_notifier_head {
26 spinlock_t lock;
27 struct notifier_block *head;
28};
29
30struct blocking_notifier_head {
31 struct semaphore rwsem;
32 struct notifier_block *head;
33};
34
35
36
37#ifdef __KERNEL__
38
39#define NOTIFY_DONE 0x0000 /* Don't care */
40#define NOTIFY_OK 0x0001 /* Suits me */
41#define NOTIFY_STOP_MASK 0x8000 /* Don't call further */
42#define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002) /* Bad/Veto action */
43
44extern __inline__ int notifier_chain_register(struct notifier_block **list, struct notifier_block *n)
45{
46 while(*list)
47 {
48 if(n->priority > (*list)->priority)
49 break;
50 list= &((*list)->next);
51 }
52 n->next = *list;
53 *list=n;
54 return 0;
55}
56
57/*
58 * Warning to any non GPL module writers out there.. these functions are
59 * GPL'd
60 */
61
62extern __inline__ int notifier_chain_unregister(struct notifier_block **nl, struct notifier_block *n)
63{
64 while((*nl)!=NULL)
65 {
66 if((*nl)==n)
67 {
68 *nl=n->next;
69 return 0;
70 }
71 nl=&((*nl)->next);
72 }
73 return -ENOENT;
74}
75
76/*
77 * This is one of these things that is generally shorter inline
78 */
79
80extern __inline__ int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v)
81{
82 int ret=NOTIFY_DONE;
83 struct notifier_block *nb = *n;
84 while(nb)
85 {
86 ret=nb->notifier_call(nb,val,v);
87 if(ret&NOTIFY_STOP_MASK)
88 return ret;
89 nb=nb->next;
90 }
91 return ret;
92}
93
94
95/*
96 * Declared notifiers so far. I can imagine quite a few more chains
97 * over time (eg laptop power reset chains, reboot chain (to clean
98 * device units up), device [un]mount chain, module load/unload chain,
99 * low memory chain, screenblank chain (for plug in modular screenblankers)
100 * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
101 */
102
103/* netdevice notifier chain */
104#define NETDEV_UP 0x0001 /* For now you can't veto a device up/down */
105#define NETDEV_DOWN 0x0002
106#define NETDEV_REBOOT 0x0003 /* Tell a protocol stack a network interface
107 detected a hardware crash and restarted
108 - we can use this eg to kick tcp sessions
109 once done */
110#define NETDEV_CHANGE 0x0004 /* Notify device state change */
111#define NETDEV_REGISTER 0x0005
112#define NETDEV_UNREGISTER 0x0006
113#define NETDEV_CHANGEMTU 0x0007
114#define NETDEV_CHANGEADDR 0x0008
115#define NETDEV_GOING_DOWN 0x0009
116#define NETDEV_CHANGENAME 0x000A
117
118#define SYS_DOWN 0x0001 /* Notify of system down */
119#define SYS_RESTART SYS_DOWN
120#define SYS_HALT 0x0002 /* Notify of system halt */
121#define SYS_POWER_OFF 0x0003 /* Notify of system power off */
122
123/*
124 * Publically visible notifier objects
125 */
126
127extern struct notifier_block *boot_notifier_list;
128
129#endif
130#define BLOCKING_INIT_NOTIFIER_HEAD(name) do { \
131 init_rwsem(&(name)->rwsem); \
132 (name)->head = NULL; \
133 } while (0)
134#endif
Note: See TracBrowser for help on using the repository browser.