Saturday, November 26, 2011

Notifiers in Linux kernel

Adding new notifiers and calling the notifier call chain.
Assume that are two drivers and one driver will have to notify the other.
Driver-1
/* atomic notifier initialization */
ATOMIC_NOTIFIER_HEAD(simple_notifier_list);

unsigned long val;
struct device_info *di;
/* later in some part of the driver call the notifier call chain */
atomic_notifier_call_chain(&simple_notifier_list, val, (void *)di);
Driver-2
static int notify_call_handler(notifier_block *n, unsigned long event, void *data)
{
}
static struct notifier_block simple_nb = {
.notifier_call = simple_notify_handler;
}
atomic_notifier_chain_register(&simple_notifier_list, &simple_nb)