Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5072231ybv; Tue, 11 Feb 2020 08:40:29 -0800 (PST) X-Google-Smtp-Source: APXvYqz/Qav5sRY/w2xl+xKIgX587APNOZXHSxlg2pYSQ0StVktkGJMx+HMCv7UfJ2r+1wJadhV+ X-Received: by 2002:a9d:3b09:: with SMTP id z9mr5970541otb.195.1581439229482; Tue, 11 Feb 2020 08:40:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581439229; cv=none; d=google.com; s=arc-20160816; b=VPo1S4nMwQlZZiSyLKFJcuHiQT2M/xn+LhSszdXjUvN/GtEA+JeUZIWZdIluqIyfDW XUU4vDr7k3YS1U5vs0X2CI1GhRWgKRy/Z+eyExFsl0oLJcxke7rjt2p//b3SaU+/SkBN 3voHpaROT38RwsO/Rbv/ujt1UpukJcvcEcMA6iJgBOzh8rrxURGAxsuWdpaOeCyE8az7 ajx8CjEwYbkVtwYzfJyPqXNVFb2rsG2bgTF+xZ7LeJ+7IGOQeGTnxsmBtTIfe2Yv5h+5 xcr4+Uis1o6OIJbixL1L0PjOjTeQNlxuczue5kBiaQAHVo7ptodtA4TltdStUDLS/4VD w4/g== 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=owSzTXcFUumlvCbrX+D8MqPMN4JcxxIBLcFb/OPdfLI=; b=pxqIAYyBtFECmu8RakL0R81rtOegaIZJb6MXh2pf+bzOxTZSY1FGUK1Buz48SGsvio ycw0rnvEPRt1/ZzUM3c8VeftnMzo/szFEzNThCYwunZOGKRjolXkn1W+vzUNzZOZOYKu lvv6v70cb7wovDvjmzAJyYImWf1k1e0cbvAS3xuxdaI8g+YgTYUaSfSPaFmxbfsio51J 5DI/HI4xhhp3f0eoaYGRhnlHambR+rZtKsQic/l7jfQSJn8YbxzBnxmkjag8GaPki0iw s3KwGgqTobqheeewfvLvcUzwXEry+RxVjVm3qvGmAGm4R0reCBGm7fCNFUwChZvzqjns yBNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@crapouillou.net header.s=mail header.b="LuPg/Ywc"; 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 n1si1919442oic.225.2020.02.11.08.40.17; Tue, 11 Feb 2020 08:40:29 -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="LuPg/Ywc"; 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 S1730195AbgBKO0n (ORCPT + 99 others); Tue, 11 Feb 2020 09:26:43 -0500 Received: from outils.crapouillou.net ([89.234.176.41]:44884 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730186AbgBKO0m (ORCPT ); Tue, 11 Feb 2020 09:26:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1581431191; 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=owSzTXcFUumlvCbrX+D8MqPMN4JcxxIBLcFb/OPdfLI=; b=LuPg/YwcH66qQIkbrJrDG5EHiYlkOueGrEPlvLwgJB0ilhhKRYRQqFVaqBiYfe9/Zvq9AD Ra0OmPldDW1mgDnTJ49+lw1vpkJ8Z4saWeEFr1WTgfWtRyBMaeeaOUcvDNCQ3nlk2cvak7 SyFNAqUCZuXQ5fjbwnVF/QJ44ZVPly4= 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 v5 3/5] remoteproc: Add prepare/unprepare callbacks Date: Tue, 11 Feb 2020 11:26:11 -0300 Message-Id: <20200211142614.13567-3-paul@crapouillou.net> In-Reply-To: <20200211142614.13567-1-paul@crapouillou.net> References: <20200211142614.13567-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 v5: Move calls to prepare/unprepare to rproc_fw_boot/rproc_shutdown 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 fe5c7a2f9767..022b927e176b 100644 --- a/drivers/remoteproc/remoteproc_core.c +++ b/drivers/remoteproc/remoteproc_core.c @@ -1373,6 +1373,14 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) dev_info(dev, "Booting fw image %s, size %zd\n", name, fw->size); + if (rproc->ops->prepare) { + ret = rproc->ops->prepare(rproc); + if (ret) { + dev_err(dev, "Failed to prepare rproc: %d\n", ret); + return ret; + } + } + /* * if enabling an IOMMU isn't relevant for this rproc, this is * just a nop @@ -1380,7 +1388,7 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) ret = rproc_enable_iommu(rproc); if (ret) { dev_err(dev, "can't enable iommu: %d\n", ret); - return ret; + goto unprepare_rproc; } rproc->bootaddr = rproc_get_boot_addr(rproc, fw); @@ -1424,6 +1432,9 @@ static int rproc_fw_boot(struct rproc *rproc, const struct firmware *fw) rproc->table_ptr = NULL; disable_iommu: rproc_disable_iommu(rproc); +unprepare_rproc: + if (rproc->ops->unprepare) + rproc->ops->unprepare(rproc); return ret; } @@ -1823,6 +1834,9 @@ void rproc_shutdown(struct rproc *rproc) rproc_disable_iommu(rproc); + if (rproc->ops->unprepare) + rproc->ops->unprepare(rproc); + /* Free the copy of the resource table */ kfree(rproc->cached_table); rproc->cached_table = NULL; 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.25.0