1 /****************************************************************************** 2 * include/xen/notifier.h 3 * 4 * Routines to manage notifier chains for passing status changes to any 5 * interested routines. 6 * 7 * Original code from Linux kernel 2.6.27 (Alan Cox <Alan.Cox@linux.org>) 8 */ 9 10 #ifndef __XEN_NOTIFIER_H__ 11 #define __XEN_NOTIFIER_H__ 12 13 #include <xen/types.h> 14 #include <xen/errno.h> 15 #include <xen/kernel.h> 16 #include <xen/list.h> 17 18 /* 19 * Xen includes only one type of notifier chains inherited from Linux: 20 * Raw notifier chains: There are no restrictions on callbacks, 21 * registration, or unregistration. All locking and protection 22 * must be provided by the caller. 23 */ 24 25 struct notifier_block { 26 int (*notifier_call)(struct notifier_block *, unsigned long, void *); 27 struct list_head chain; 28 int priority; 29 }; 30 31 struct notifier_head { 32 struct list_head head; 33 }; 34 35 #define NOTIFIER_HEAD(name) \ 36 struct notifier_head name = { .head = LIST_HEAD_INIT(name.head) } 37 38 39 void notifier_chain_register( 40 struct notifier_head *nh, struct notifier_block *nb); 41 void notifier_chain_unregister( 42 struct notifier_head *nh, struct notifier_block *nb); 43 44 int notifier_call_chain( 45 struct notifier_head *nh, unsigned long val, void *v, 46 struct notifier_block **pcursor); 47 48 /* Notifier flag values: OR into @val passed to notifier_call_chain(). */ 49 #define NOTIFY_FORWARD 0x0000 /* Call chain highest-priority-first */ 50 #define NOTIFY_REVERSE 0x8000 /* Call chain lowest-priority-first */ 51 52 /* Handler completion values */ 53 #define NOTIFY_DONE 0x0000 54 #define NOTIFY_STOP_MASK 0x8000 55 #define NOTIFY_STOP (NOTIFY_STOP_MASK|NOTIFY_DONE) 56 #define NOTIFY_BAD (NOTIFY_STOP_MASK|EINVAL) 57 58 /* Encapsulate (negative) errno value. */ notifier_from_errno(int err)59static inline int notifier_from_errno(int err) 60 { 61 return NOTIFY_STOP_MASK | -err; 62 } 63 64 /* Restore (negative) errno value from notify return value. */ notifier_to_errno(int ret)65static inline int notifier_to_errno(int ret) 66 { 67 return -(ret & ~NOTIFY_STOP_MASK); 68 } 69 70 #endif /* __XEN_NOTIFIER_H__ */ 71