aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/base/bus.c
diff options
context:
space:
mode:
authorBenjamin Herrenschmidt <benh@kernel.crashing.org>2006-10-24 23:44:59 -0400
committerGreg Kroah-Hartman <gregkh@suse.de>2006-12-01 17:51:58 -0500
commit116af378201ef793424cd10508ccf18b06d8a021 (patch)
tree2de792e7b9d8a122d88241d1ecfbe7bc92b9b8fe /drivers/base/bus.c
parent0215ffb08ce99e2bb59eca114a99499a4d06e704 (diff)
Driver core: add notification of bus events
I finally did as you suggested and added the notifier to the struct bus_type itself. There are still problems to be expected is something attaches to a bus type where the code can hook in different struct device sub-classes (which is imho a big bogosity but I won't even try to argue that case now) but it will solve nicely a number of issues I've had so far. That also means that clients interested in registering for such notifications have to do it before devices are added and after bus types are registered. Fortunately, most bus types that matter for the various usage scenarios I have in mind are registerd at postcore_initcall time, which means I have a really nice spot at arch_initcall time to add my notifiers. There are 4 notifications provided. Device being added (before hooked to the bus) and removed (failure of previous case or after being unhooked from the bus), along with driver being bound to a device and about to be unbound. The usage I have for these are: - The 2 first ones are used to maintain a struct device_ext that is hooked to struct device.firmware_data. This structure contains for now a pointer to the Open Firmware node related to the device (if any), the NUMA node ID (for quick access to it) and the DMA operations pointers & iommu table instance for DMA to/from this device. For bus types I own (like IBM VIO or EBUS), I just maintain that structure directly from the bus code when creating the devices. But for bus types managed by generic code like PCI or platform (actually, of_platform which is a variation of platform linked to Open Firmware device-tree), I need this notifier. - The other two ones have a completely different usage scenario. I have cases where multiple devices and their drivers depend on each other. For example, the IBM EMAC network driver needs to attach to a MAL DMA engine which is a separate device, and a PHY interface which is also a separate device. They are all of_platform_device's (well, about to be with my upcoming patches) but there is no say in what precise order the core will "probe" them and instanciate the various modules. The solution I found for that is to have the drivers for emac to use multithread_probe, and wait for a driver to be bound to the target MAL and PHY control devices (the device-tree contains reference to the MAL and PHY interface nodes, which I can then match to of_platform_devices). Right now, I've been polling, but with that notifier, I can more cleanly wait (with a timeout of course). Signed-off-by: Benjamin Herrenschmidt <benh@kernel.crashing.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/base/bus.c')
-rw-r--r--drivers/base/bus.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 7d8a7ce73fb3..ed3e8a2be64a 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -724,6 +724,8 @@ int bus_register(struct bus_type * bus)
724{ 724{
725 int retval; 725 int retval;
726 726
727 BLOCKING_INIT_NOTIFIER_HEAD(&bus->bus_notifier);
728
727 retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name); 729 retval = kobject_set_name(&bus->subsys.kset.kobj, "%s", bus->name);
728 if (retval) 730 if (retval)
729 goto out; 731 goto out;
@@ -782,6 +784,18 @@ void bus_unregister(struct bus_type * bus)
782 subsystem_unregister(&bus->subsys); 784 subsystem_unregister(&bus->subsys);
783} 785}
784 786
787int bus_register_notifier(struct bus_type *bus, struct notifier_block *nb)
788{
789 return blocking_notifier_chain_register(&bus->bus_notifier, nb);
790}
791EXPORT_SYMBOL_GPL(bus_register_notifier);
792
793int bus_unregister_notifier(struct bus_type *bus, struct notifier_block *nb)
794{
795 return blocking_notifier_chain_unregister(&bus->bus_notifier, nb);
796}
797EXPORT_SYMBOL_GPL(bus_unregister_notifier);
798
785int __init buses_init(void) 799int __init buses_init(void)
786{ 800{
787 return subsystem_register(&bus_subsys); 801 return subsystem_register(&bus_subsys);