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 notifier_block head; 33 }; 34 35 #define NOTIFIER_INIT(name) { .head.chain = LIST_HEAD_INIT(name.head.chain) } 36 37 #define NOTIFIER_HEAD(name) \ 38 struct notifier_head name = NOTIFIER_INIT(name) 39 40 void notifier_chain_register( 41 struct notifier_head *nh, struct notifier_block *nb); 42 void notifier_chain_unregister( 43 struct notifier_head *nh, struct notifier_block *nb); 44 45 int notifier_call_chain( 46 struct notifier_head *nh, unsigned long val, void *v, 47 struct notifier_block **pcursor); 48 49 /* Notifier flag values: OR into @val passed to notifier_call_chain(). */ 50 #define NOTIFY_FORWARD 0x0000 /* Call chain highest-priority-first */ 51 #define NOTIFY_REVERSE 0x8000 /* Call chain lowest-priority-first */ 52 53 /* Handler completion values */ 54 #define NOTIFY_DONE 0x0000 55 #define NOTIFY_STOP_MASK 0x8000 56 #define NOTIFY_STOP (NOTIFY_STOP_MASK|NOTIFY_DONE) 57 #define NOTIFY_BAD (NOTIFY_STOP_MASK|EINVAL) 58 59 /* Encapsulate (negative) errno value. */ notifier_from_errno(int err)60static inline int notifier_from_errno(int err) 61 { 62 return NOTIFY_STOP_MASK | -err; 63 } 64 65 /* Restore (negative) errno value from notify return value. */ notifier_to_errno(int ret)66static inline int notifier_to_errno(int ret) 67 { 68 return -(ret & ~NOTIFY_STOP_MASK); 69 } 70 71 #endif /* __XEN_NOTIFIER_H__ */ 72