From patchwork Mon Mar 20 11:51:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Roese X-Patchwork-Id: 740977 X-Patchwork-Delegate: sjg@chromium.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 3vmvVp47gLz9s73 for ; Mon, 20 Mar 2017 22:54:10 +1100 (AEDT) Received: by lists.denx.de (Postfix, from userid 105) id 4C1A6C21CBD; Mon, 20 Mar 2017 11:52:32 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id 53E6FC21C9A; Mon, 20 Mar 2017 11:52:01 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 12261C21C36; Mon, 20 Mar 2017 11:51:58 +0000 (UTC) Received: from mx1.mailbox.org (mx1.mailbox.org [80.241.60.212]) by lists.denx.de (Postfix) with ESMTPS id BC286C21C2C for ; Mon, 20 Mar 2017 11:51:57 +0000 (UTC) Received: from smtp1.mailbox.org (smtp1.mailbox.org [80.241.60.240]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.mailbox.org (Postfix) with ESMTPS id AF40345D67 for ; Mon, 20 Mar 2017 12:51:57 +0100 (CET) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp1.mailbox.org ([80.241.60.240]) by spamfilter02.heinlein-hosting.de (spamfilter02.heinlein-hosting.de [80.241.56.116]) (amavisd-new, port 10030) with ESMTP id bSxmk9ZirO2z for ; Mon, 20 Mar 2017 12:51:52 +0100 (CET) From: Stefan Roese To: u-boot@lists.denx.de Date: Mon, 20 Mar 2017 12:51:49 +0100 Message-Id: <20170320115151.15155-2-sr@denx.de> In-Reply-To: <20170320115151.15155-1-sr@denx.de> References: <20170320115151.15155-1-sr@denx.de> Subject: [U-Boot] [PATCH 2/4 v2] dm: core: Add dm_remove_devices_flags() and hook it into device_remove() X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" 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. Signed-off-by: Stefan Roese Reviewed-by: Simon Glass --- v2: - Added Simons Reviewed-by drivers/core/device-remove.c | 15 +++++++++++---- drivers/core/root.c | 7 +++++++ include/dm/root.h | 12 ++++++++++++ 3 files changed, 30 insertions(+), 4 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index b80bf52320..ca4680f7c2 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -174,7 +174,12 @@ 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 the driver flags + */ + if (drv->remove && + ((flags & DM_REMOVE_NORMAL) || (flags & drv->flags))) { ret = drv->remove(dev); if (ret) goto err_remove; @@ -188,10 +193,12 @@ int device_remove(struct udevice *dev, uint flags) } } - device_free(dev); + if ((flags & DM_REMOVE_NORMAL) || (flags & drv->flags)) { + device_free(dev); - dev->seq = -1; - dev->flags &= ~DM_FLAG_ACTIVATED; + dev->seq = -1; + dev->flags &= ~DM_FLAG_ACTIVATED; + } return ret; diff --git a/drivers/core/root.c b/drivers/core/root.c index 6dafc6ecfc..4c4642a8a4 100644 --- a/drivers/core/root.c +++ b/drivers/core/root.c @@ -182,6 +182,13 @@ int dm_uninit(void) return 0; } +int dm_remove_devices_flags(uint flags) +{ + device_remove(dm_root(), flags); + + return 0; +} + int dm_scan_platdata(bool pre_reloc_only) { int ret; diff --git a/include/dm/root.h b/include/dm/root.h index 3cf730dcee..b13c005c17 100644 --- a/include/dm/root.h +++ b/include/dm/root.h @@ -115,4 +115,16 @@ int dm_init(void); */ int dm_uninit(void); +/** + * 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); + #endif