Skip to contentSkip to conversation

dm: core: Add dm_remove_devices_flags() and hook it into device_remove()

PATCH New Stefan Roese 2 participants 2 messages Mar 27, 2017 – Apr 5, 2017

lore
Share & tools
lore
#0 lore raw

PATCH v4 2/4 dm: core: Add dm_remove_devices_flags() and hook it into device_remove()

The new function dm_remove_devices_flags() is intented for driver specific last-stage cleanup operations before the OS is started. This patch adds this functionality and hooks it into the common device_remove() function.

Drivers wanting to use this feature for some last-stage removal calls, need to add one of the DM_REMOVE_xx flags to their driver .flags.

---
v4:
- Make comparison of flags more explicit by masking the driver flags with the drivers "remove flags" before masking them with the device_remove() removal flags parameter

v3:
- Add conditional compilation to fix compilation breakage on platforms without DM and DM_DEVICE_REMOVE support. With this change, Travis compiles all targets without any error

v2:
- Added Simons Reviewed-by

drivers/core/device-remove.c | 17 +++++++++++++----

 drivers/core/root.c          |  9 +++++++++
 include/dm/root.h            | 16 ++++++++++++++++
 3 files changed, 38 insertions(+), 4 deletions(-)
drivers/core/device-remove.c +13 -4
index b80bf52320..cc0043b990 100644
@@ -174,7 +174,13 @@ int device_remove(struct udevice *dev, uint flags)
 	if (ret)
 		goto err;
 
-	if (drv->remove) {
+	/*
+	 * Remove the device if called with the "normal" remove flag set,
+	 * or if the remove flag matches any of the drivers remove flags
+	 */
+	if (drv->remove &&
+	    ((flags & DM_REMOVE_NORMAL) ||
+	     (flags & (drv->flags & DM_FLAG_ACTIVE_DMA)))) {
 		ret = drv->remove(dev);
 		if (ret)
 			goto err_remove;
@@ -188,10 +194,13 @@ int device_remove(struct udevice *dev, uint flags)
 		}
 	}
 
-	device_free(dev);
+	if ((flags & DM_REMOVE_NORMAL) ||
+	    (flags & (drv->flags & DM_FLAG_ACTIVE_DMA))) {
+		device_free(dev);
 
-	dev->seq = -1;
-	dev->flags &= ~DM_FLAG_ACTIVATED;
+		dev->seq = -1;
+		dev->flags &= ~DM_FLAG_ACTIVATED;
+	}
 
 	return ret;
 
drivers/core/root.c +9 -0
index d8c51fb496..42679d047c 100644
@@ -184,6 +184,15 @@ int dm_uninit(void)
 	return 0;
 }
 
+#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+int dm_remove_devices_flags(uint flags)
+{
+	device_remove(dm_root(), flags);
+
+	return 0;
+}
+#endif
+
 int dm_scan_platdata(bool pre_reloc_only)
 {
 	int ret;
include/dm/root.h +16 -0
index 3cf730dcee..058eb98923 100644
@@ -115,4 +115,20 @@ int dm_init(void);
  */
 int dm_uninit(void);
 
+#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE)
+/**
+ * dm_remove_devices_flags - Call remove function of all drivers with
+ *                           specific removal flags set to selectively
+ *                           remove drivers
+ *
+ * All devices with the matching flags set will be removed
+ *
+ * @flags: Flags for selective device removal
+ * @return 0 if OK, -ve on error
+ */
+int dm_remove_devices_flags(uint flags);
+#else
+static inline int dm_remove_devices_flags(uint flags) { return 0; }
+#endif
+
 #endif
Signature · 1 line
2.12.2
#1 lore raw

PATCH v4 2/4 dm: core: Add dm_remove_devices_flags() and hook it into device_remove()

Quoted 21 lines · Stefan Roese

The new function dm_remove_devices_flags() is intented for driver specific last-stage cleanup operations before the OS is started. This patch adds this functionality and hooks it into the common device_remove() function.

Drivers wanting to use this feature for some last-stage removal calls, need to add one of the DM_REMOVE_xx flags to their driver .flags.

---
v4:
- Make comparison of flags more explicit by masking the driver flags with the drivers "remove flags" before masking them with the device_remove() removal flags parameter

v3:
- Add conditional compilation to fix compilation breakage on platforms without DM and DM_DEVICE_REMOVE support. With this change, Travis compiles all targets without any error

Quoted 8 lines

v2:
- Added Simons Reviewed-by

drivers/core/device-remove.c | 17 +++++++++++++----

 drivers/core/root.c          |  9 +++++++++
 include/dm/root.h            | 16 ++++++++++++++++
 3 files changed, 38 insertions(+), 4 deletions(-)

Applied to u-boot-dm, thanks!