From patchwork Fri Jun 22 12:25:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jean-Jacques Hiblot X-Patchwork-Id: 933315 X-Patchwork-Delegate: lukma@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.denx.de (client-ip=81.169.180.215; helo=lists.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=quarantine dis=none) header.from=ti.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=ti.com header.i=@ti.com header.b="AuF3Dv9h"; dkim-atps=neutral Received: from lists.denx.de (dione.denx.de [81.169.180.215]) by ozlabs.org (Postfix) with ESMTP id 41ByZH4s3gz9s3C for ; Fri, 22 Jun 2018 22:29:59 +1000 (AEST) Received: by lists.denx.de (Postfix, from userid 105) id 5B17AC21E42; Fri, 22 Jun 2018 12:27:18 +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=T_DKIM_INVALID 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 E9DBBC21F7A; Fri, 22 Jun 2018 12:26:13 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id A7D96C22000; Fri, 22 Jun 2018 12:25:54 +0000 (UTC) Received: from fllnx209.ext.ti.com (fllnx209.ext.ti.com [198.47.19.16]) by lists.denx.de (Postfix) with ESMTPS id 7AA60C21FE7 for ; Fri, 22 Jun 2018 12:25:50 +0000 (UTC) Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by fllnx209.ext.ti.com (8.15.1/8.15.1) with ESMTP id w5MCPiuM013651; Fri, 22 Jun 2018 07:25:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1529670344; bh=p0RIuGQyS+MD6nq6gTFXvppdjzAblpI3U/kb9YFvYYQ=; h=From:To:CC:Subject:Date:In-Reply-To:References; b=AuF3Dv9hqmkIXDuYOR8q6VNbTLs6zF2bhULZhl7w0gIyQJR/JfrllzWokQdvN9zBB vkdt53wA0ovAUUpjga+WK4KGCyGV7+RTnj5tcmOqP4Uc30ptW/7aYH4DxGmrdmC4mJ Xq1fCl3NK/iazyIWBJ4hMrLQnGBaY4k/X4G8wyKw= Received: from DLEE100.ent.ti.com (dlee100.ent.ti.com [157.170.170.30]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id w5MCPi8O012214; Fri, 22 Jun 2018 07:25:44 -0500 Received: from DLEE111.ent.ti.com (157.170.170.22) by DLEE100.ent.ti.com (157.170.170.30) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1466.3; Fri, 22 Jun 2018 07:25:44 -0500 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE111.ent.ti.com (157.170.170.22) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1466.3 via Frontend Transport; Fri, 22 Jun 2018 07:25:44 -0500 Received: from localhost (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id w5MCPhZo004704; Fri, 22 Jun 2018 07:25:44 -0500 From: Jean-Jacques Hiblot To: Date: Fri, 22 Jun 2018 14:25:33 +0200 Message-ID: <1529670334-21974-7-git-send-email-jjhiblot@ti.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1529670334-21974-1-git-send-email-jjhiblot@ti.com> References: <1529670334-21974-1-git-send-email-jjhiblot@ti.com> MIME-Version: 1.0 X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Cc: trini@konsulko.com, u-boot@lists.denx.de, sr@denx.de Subject: [U-Boot] [PATCH v3 6/7] device: expose the functions used to remove and unbind children of a device 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: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" Also add a 'drv' parameter to filter the children to remove/unbind. Exporting those functions is a preparatory work for the addition of the bind/unbind commands. Signed-off-by: Jean-Jacques Hiblot Reviewed-by: Simon Glass --- Changes in v3: - New Changes in v2: None drivers/core/device-remove.c | 30 +++++++++++------------------- include/dm/device-internal.h | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 19 deletions(-) diff --git a/drivers/core/device-remove.c b/drivers/core/device-remove.c index 1cf2278..586fade 100644 --- a/drivers/core/device-remove.c +++ b/drivers/core/device-remove.c @@ -17,16 +17,7 @@ #include #include -/** - * device_chld_unbind() - Unbind all device's children from the device - * - * On error, the function continues to unbind all children, and reports the - * first error. - * - * @dev: The device that is to be stripped of its children - * @return 0 on success, -ve on error - */ -static int device_chld_unbind(struct udevice *dev) +int device_chld_unbind(struct udevice *dev, struct driver *drv) { struct udevice *pos, *n; int ret, saved_ret = 0; @@ -34,6 +25,9 @@ static int device_chld_unbind(struct udevice *dev) assert(dev); list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + if (drv && (pos->driver != drv)) + continue; + ret = device_unbind(pos); if (ret && !saved_ret) saved_ret = ret; @@ -42,13 +36,8 @@ static int device_chld_unbind(struct udevice *dev) return saved_ret; } -/** - * device_chld_remove() - Stop all device's children - * @dev: The device whose children are to be removed - * @pre_os_remove: Flag, if this functions is called in the pre-OS stage - * @return 0 on success, -ve on error - */ -static int device_chld_remove(struct udevice *dev, uint flags) +int device_chld_remove(struct udevice *dev, struct driver *drv, + uint flags) { struct udevice *pos, *n; int ret; @@ -56,6 +45,9 @@ static int device_chld_remove(struct udevice *dev, uint flags) assert(dev); list_for_each_entry_safe(pos, n, &dev->child_head, sibling_node) { + if (drv && (pos->driver != drv)) + continue; + ret = device_remove(pos, flags); if (ret) return ret; @@ -87,7 +79,7 @@ int device_unbind(struct udevice *dev) return ret; } - ret = device_chld_unbind(dev); + ret = device_chld_unbind(dev, NULL); if (ret) return ret; @@ -178,7 +170,7 @@ int device_remove(struct udevice *dev, uint flags) if (ret) return ret; - ret = device_chld_remove(dev, flags); + ret = device_chld_remove(dev, NULL, flags); if (ret) goto err; diff --git a/include/dm/device-internal.h b/include/dm/device-internal.h index 5a4d50c..14b5c1b 100644 --- a/include/dm/device-internal.h +++ b/include/dm/device-internal.h @@ -127,6 +127,44 @@ static inline void device_free(struct udevice *dev) {} #endif /** + * device_chld_unbind() - Unbind all device's children from the device if bound + * to drv + * + * On error, the function continues to unbind all children, and reports the + * first error. + * + * @dev: The device that is to be stripped of its children + * @drv: The targeted driver + * @return 0 on success, -ve on error + */ +#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) +int device_chld_unbind(struct udevice *dev, struct driver *drv); +#else +static inline int device_chld_unbind(struct udevice *dev, struct driver *drv) +{ + return 0; +} +#endif + +/** + * device_chld_remove() - Stop all device's children + * @dev: The device whose children are to be removed + * @drv: The targeted driver + * @flags: Flag, if this functions is called in the pre-OS stage + * @return 0 on success, -ve on error + */ +#if CONFIG_IS_ENABLED(DM_DEVICE_REMOVE) +int device_chld_remove(struct udevice *dev, struct driver *drv, + uint flags); +#else +static inline int device_chld_remove(struct udevice *dev, struct driver *drv, + uint flags) +{ + return 0; +} +#endif + +/** * simple_bus_translate() - translate a bus address to a system address * * This handles the 'ranges' property in a simple bus. It translates the