Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp5610338ybl; Tue, 10 Dec 2019 08:41:28 -0800 (PST) X-Google-Smtp-Source: APXvYqzcFWtVroSVsAdsjt6LMekn5nnMR0Dlwq/Q+4hIY5yXR2jUj1Xk8nD6zNsDEk++P6uDFgTw X-Received: by 2002:a9d:7483:: with SMTP id t3mr26566204otk.262.1575996088379; Tue, 10 Dec 2019 08:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575996088; cv=none; d=google.com; s=arc-20160816; b=xbHfx63fAIyAtWBF4P5XPDHHHwbpmePYYIVGALmg9Ss7UImaF+yN0b5yD+5+TA+Eui 5EHHxwhnkIHh7KKSEz2398p0B1R48Gng0WVrHP8P3essRE3qJVpUMdRjrbxhsO9XRxzb ff9qj2BUntrFPFth71hbqUP2YEOdg2hZLYdxteInUwcJ0XeusTqONCBdHOUypQMH9VaF LsMw6vLvIRHPvUU5u5g1fac+CxBNwfidpo7ZWWKMYlSP/5dLA+lF8hUCpansufkbjj5o g4s4+V8jKKjrPVrnb3Gx6IHtrcOa50TPZq4rH9/e/iMtvZ/rcx5SILZj/yJHsF7WKD1D yqsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=pCEbnFSw2JtJHUoCMM5IIt5gSFX+3SfW9opge7HY8DU=; b=mh4sLxass9Y1d+u90mWwTPAcrVEIWn1kjPJIY7beYNjCHQeCNyewP86dc3Kwzqwn1p /HG4juRCeVav66jRWqXcYzHXJQrShNWgiUkeOTRgLJOeG2k1HOf4DxmBiOTzztiAzKUG Ikvy7bOsQwtfeLuSwDg3M3WF1o0ky5gcdVDoPoomeFZ5FX3KarkEuD21Uk9UG0bTP0XU y42MaSggKr21KU6IA8Rs5p9Nck7qo3uHJkVFhuSsfQWpV3hIdWBUppEp1k9OPb/Nbqkq iVyuaxLDB5O8mwgVlk4HCy5h897PCFrZwvnoqqRXiIGVaLlVOBY0aw14fhUSojSTaHeR dIzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=JuDbPKWH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id m19si2090966otk.84.2019.12.10.08.41.15; Tue, 10 Dec 2019 08:41:28 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b=JuDbPKWH; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727683AbfLJQkf (ORCPT + 99 others); Tue, 10 Dec 2019 11:40:35 -0500 Received: from outils.crapouillou.net ([89.234.176.41]:39890 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727505AbfLJQkf (ORCPT ); Tue, 10 Dec 2019 11:40:35 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1575996021; 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=pCEbnFSw2JtJHUoCMM5IIt5gSFX+3SfW9opge7HY8DU=; b=JuDbPKWH2waC4uDRlbfdlZKpPAYjXScPfDy/JAuqDL7BS+mqIJkZ7K1i3J99bGfkgHiLCT PIXS4FJLB7VYUbaJsKcpymVN6+O5/+oTRQQbEvg6y94kSYScZaRtetcQP2wPHYqCfJxNYo ks7RqLhbwcqDVUJCyZG/aGffG6mePY4= 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 v4 3/5] remoteproc: Add prepare/unprepare callbacks Date: Tue, 10 Dec 2019 17:40:12 +0100 Message-Id: <20191210164014.50739-3-paul@crapouillou.net> In-Reply-To: <20191210164014.50739-1-paul@crapouillou.net> References: <20191210164014.50739-1-paul@crapouillou.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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-v4: 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 0a9fc7fdd1c3..3ea5f675a148 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1299,11 +1299,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; } /* @@ -1354,6 +1362,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; } @@ -1483,6 +1494,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