From: Joerg Roedel <jroedel@suse.de>
Date: Tue, 30 Sep 2014 13:02:02 +0200
Subject: driver core: Add BUS_NOTIFY_REMOVED_DEVICE event
Git-commit: 599bad38cf7163123af7c9efea0fcf228bc74fe1
Patch-mainline: v3.18 or v3.17-rc8 (next release)
References: bnc#920960

This event closes an important gap in the bus notifiers.
There is already the BUS_NOTIFY_DEL_DEVICE event, but that
is sent when the device is still bound to its device driver.

This is too early for the IOMMU code to destroy any mappings
for the device, as they might still be in use by the driver.

The new BUS_NOTIFY_REMOVED_DEVICE event introduced with this
patch closes this gap as it is sent when the device is
already unbound from its device driver and almost completly
removed from the driver core.

With this event the IOMMU code can safely destroy any
mappings and other data structures when a device is removed.

Signed-off-by: Joerg Roedel <jroedel@suse.de>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Tested-by: Jerry Hoemann <jerry.hoemann@hp.com>
---
 drivers/base/core.c    |  3 +++
 include/linux/device.h | 11 ++++++-----
 2 files changed, 9 insertions(+), 5 deletions(-)

Index: linux-3.0-SLE11-SP4/drivers/base/core.c
===================================================================
--- linux-3.0-SLE11-SP4.orig/drivers/base/core.c
+++ linux-3.0-SLE11-SP4/drivers/base/core.c
@@ -1134,6 +1134,9 @@ void device_del(struct device *dev)
 	 */
 	if (platform_notify_remove)
 		platform_notify_remove(dev);
+	if (dev->bus)
+		blocking_notifier_call_chain(&dev->bus->p->bus_notifier,
+					     BUS_NOTIFY_REMOVED_DEVICE, dev);
 	kobject_uevent(&dev->kobj, KOBJ_REMOVE);
 	cleanup_device_parent(dev);
 	kobject_del(&dev->kobj);
Index: linux-3.0-SLE11-SP4/include/linux/device.h
===================================================================
--- linux-3.0-SLE11-SP4.orig/include/linux/device.h
+++ linux-3.0-SLE11-SP4/include/linux/device.h
@@ -148,6 +148,7 @@ extern int bus_unregister_notifier(struc
 						      unbound */
 #define BUS_NOTIFY_UNBOUND_DRIVER	0x00000006 /* driver is unbound
 						      from the device */
+#define BUS_NOTIFY_REMOVED_DEVICE	0x00000007 /* device removed */
 
 extern struct kset *bus_get_kset(struct bus_type *bus);
 extern struct klist *bus_get_device_klist(struct bus_type *bus);
