From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.5 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 806D3C432C3 for ; Sat, 16 Nov 2019 17:09:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 568B7214E0 for ; Sat, 16 Nov 2019 17:09:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=crapouillou.net header.i=@crapouillou.net header.b="udqx2d5u" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727916AbfKPRJM (ORCPT ); Sat, 16 Nov 2019 12:09:12 -0500 Received: from outils.crapouillou.net ([89.234.176.41]:40006 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727568AbfKPRJL (ORCPT ); Sat, 16 Nov 2019 12:09:11 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1573924137; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vnG/len4PT7c6eVSHFujXGTnSMs9h8aEaUg47UXdaDc=; b=udqx2d5u9J9VJ0ouWaslpRb4NgUX6MFQEuYhcbAVVzWUHKKeNY+Hgz0HIGsh7Val3tiINg x/4nPh8p9X2qg3Cu44WgPhxVt2+FKU6N+zSQFo2QzSaVFJ8EKR9MiF+KXwN/IjM4IGqZ35 +KN1zRspYFAuFTVX6CK8PAuZSMUn88U= From: Paul Cercueil To: Ohad Ben-Cohen , Bjorn Andersson , Rob Herring , Mark Rutland Cc: od@zcrc.me, linux-remoteproc@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Paul Cercueil Subject: [PATCH v3 3/4] remoteproc: Add prepare/unprepare callbacks Date: Sat, 16 Nov 2019 18:08:45 +0100 Message-Id: <20191116170846.67220-3-paul@crapouillou.net> In-Reply-To: <20191116170846.67220-1-paul@crapouillou.net> References: <20191116170846.67220-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: devicetree-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The .prepare() callback is called before the firmware is loaded to memory. This is useful for instance in the case where some setup is required for the memory to be accessible. Signed-off-by: Paul Cercueil --- Notes: v2: No change v3: No change drivers/remoteproc/remoteproc_core.c | 16 +++++++++++++++- include/linux/remoteproc.h | 4 ++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c index d3787c94f451..7f61ab8b7da5 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1300,11 +1300,19 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) struct device *dev = &rproc->dev; int ret; + if (rproc->ops->prepare) { + ret = rproc->ops->prepare(rproc); + if (ret) { + dev_err(dev, "Failed to prepare rproc: %d\n", ret); + return ret; + } + } + /* load the ELF segments to memory */ ret = rproc_load_segments(rproc, fw); if (ret) { dev_err(dev, "Failed to load program segments: %d\n", ret); - return ret; + goto unprepare_rproc; } /* @@ -1355,6 +1363,9 @@ static int rproc_start(struct rproc *rproc, const struct firmware *fw) rproc_unprepare_subdevices(rproc); reset_table_ptr: rproc->table_ptr = rproc->cached_table; +unprepare_rproc: + if (rproc->ops->unprepare) + rproc->ops->unprepare(rproc); return ret; } @@ -1484,6 +1495,9 @@ static int rproc_stop(struct rproc *rproc, bool crashed) rproc->state = RPROC_OFFLINE; + if (rproc->ops->unprepare) + rproc->ops->unprepare(rproc); + dev_info(dev, "stopped remote processor %s\n", rproc->name); return 0; diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h index 5f201f0c86c3..a6272d1ba384 100644 --- a/include/linux/remoteproc.h +++ b/include/linux/remoteproc.h @@ -355,6 +355,8 @@ enum rsc_handling_status { /** * struct rproc_ops - platform-specific device handlers + * @prepare: prepare the device for power up (before the firmware is loaded) + * @unprepare: unprepare the device after it is stopped * @start: power on the device and boot it * @stop: power off the device * @kick: kick a virtqueue (virtqueue id given as a parameter) @@ -371,6 +373,8 @@ enum rsc_handling_status { * @get_boot_addr: get boot address to entry point specified in firmware */ struct rproc_ops { + int (*prepare)(struct rproc *rproc); + void (*unprepare)(struct rproc *rproc); int (*start)(struct rproc *rproc); int (*stop)(struct rproc *rproc); void (*kick)(struct rproc *rproc, int vqid); -- 2.24.0