Linux-remoteproc Archive mirror
 help / color / mirror / Atom feed
From: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
To: Bjorn Andersson <andersson@kernel.org>,
	Mathieu Poirier <mathieu.poirier@linaro.org>,
	Jens Wiklander <jens.wiklander@linaro.org>,
	"Rob Herring" <robh+dt@kernel.org>,
	Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>,
	Conor Dooley <conor+dt@kernel.org>
Cc: <linux-stm32@st-md-mailman.stormreply.com>,
	<linux-arm-kernel@lists.infradead.org>,
	<linux-remoteproc@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>,
	<op-tee@lists.trustedfirmware.org>, <devicetree@vger.kernel.org>,
	Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
Subject: [PATCH v3 4/7] remoteproc: core: Implement the support of an alternative boot
Date: Wed, 14 Feb 2024 18:21:24 +0100	[thread overview]
Message-ID: <20240214172127.1022199-5-arnaud.pouliquen@foss.st.com> (raw)
In-Reply-To: <20240214172127.1022199-1-arnaud.pouliquen@foss.st.com>

Implement a new method to load a firmware and start the remote processor.
In this method the firmware is loaded first and then the loaded resource
table is obtained.

Signed-off-by: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>
---
 drivers/remoteproc/remoteproc_core.c | 86 +++++++++++++++++++++++++++-
 include/linux/remoteproc.h           |  2 +
 2 files changed, 87 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/remoteproc_core.c b/drivers/remoteproc/remoteproc_core.c
index 34b0093689da..47956e07365e 100644
--- a/drivers/remoteproc/remoteproc_core.c
+++ b/drivers/remoteproc/remoteproc_core.c
@@ -38,6 +38,7 @@
 #include <linux/virtio_ring.h>
 #include <asm/byteorder.h>
 #include <linux/platform_device.h>
+#include <linux/tee_remoteproc.h>
 
 #include "remoteproc_internal.h"
 
@@ -1493,6 +1494,86 @@ static int rproc_set_rsc_table(struct rproc *rproc)
 	return 0;
 }
 
+/*
+ * Alternative method to load a firmware and boot a remote processor with it.
+ * Similar to rproc_fw_boot but the resource table is obtained and parsed only after loading the
+ * firmware.
+ */
+static int rproc_alt_fw_boot(struct rproc *rproc, const struct firmware *fw)
+{
+	struct device *dev = &rproc->dev;
+	const char *name = rproc->firmware;
+	int ret;
+
+	dev_info(dev, "Booting a private format image %s, size %zd\n", name, fw->size);
+
+	/*
+	 * if enabling an IOMMU isn't relevant for this rproc, this is
+	 * just a nop
+	 */
+	ret = rproc_enable_iommu(rproc);
+	if (ret) {
+		dev_err(dev, "can't enable iommu: %d\n", ret);
+		return ret;
+	}
+
+	/* Prepare rproc for firmware loading if needed */
+	ret = rproc_prepare_device(rproc);
+	if (ret) {
+		dev_err(dev, "can't prepare rproc %s: %d\n", rproc->name, ret);
+		goto disable_iommu;
+	}
+
+	/* load the image to memory */
+	ret = rproc_load_segments(rproc, fw);
+	if (ret) {
+		dev_err(dev, "Failed to load firmware: %d\n", ret);
+		return ret;
+	}
+
+	ret = rproc_set_rsc_table(rproc);
+	if (ret) {
+		dev_err(dev, "can't load resource table: %d\n", ret);
+		goto unprepare_device;
+	}
+
+	/* reset max_notifyid */
+	rproc->max_notifyid = -1;
+
+	/* reset handled vdev */
+	rproc->nb_vdev = 0;
+
+	/* handle fw resources which are required to boot rproc */
+	ret = rproc_handle_resources(rproc, rproc_loading_handlers);
+	if (ret) {
+		dev_err(dev, "Failed to process resources: %d\n", ret);
+		goto clean_up_resources;
+	}
+
+	/* Allocate carveout resources associated to rproc */
+	ret = rproc_alloc_registered_carveouts(rproc);
+	if (ret) {
+		dev_err(dev, "Failed to allocate associated carveouts: %d\n",
+			ret);
+		goto clean_up_resources;
+	}
+
+	ret = rproc_start(rproc, fw);
+	if (ret)
+		goto clean_up_resources;
+
+	return 0;
+
+clean_up_resources:
+	rproc_resource_cleanup(rproc);
+unprepare_device:
+	/* release HW resources if needed */
+	rproc_unprepare_device(rproc);
+disable_iommu:
+	rproc_disable_iommu(rproc);
+	return ret;
+}
+
 static int rproc_reset_rsc_table_on_detach(struct rproc *rproc)
 {
 	struct resource_table *table_ptr;
@@ -1957,7 +2038,10 @@ int rproc_boot(struct rproc *rproc)
 			goto downref_rproc;
 		}
 
-		ret = rproc_fw_boot(rproc, firmware_p);
+		if (rproc->alt_boot)
+			ret = rproc_alt_fw_boot(rproc, firmware_p);
+		else
+			ret = rproc_fw_boot(rproc, firmware_p);
 
 		release_firmware(firmware_p);
 	}
diff --git a/include/linux/remoteproc.h b/include/linux/remoteproc.h
index b4795698d8c2..ba219a77e055 100644
--- a/include/linux/remoteproc.h
+++ b/include/linux/remoteproc.h
@@ -544,6 +544,7 @@ enum rproc_features {
  * @elf_machine: firmware ELF machine
  * @cdev: character device of the rproc
  * @cdev_put_on_release: flag to indicate if remoteproc should be shutdown on @char_dev release
+ * @alt_boot flag to indicate if remoteproc should use the alternate boot method.
  * @features: indicate remoteproc features
  */
 struct rproc {
@@ -585,6 +586,7 @@ struct rproc {
 	u16 elf_machine;
 	struct cdev cdev;
 	bool cdev_put_on_release;
+	bool alt_boot;
 	DECLARE_BITMAP(features, RPROC_MAX_FEATURES);
 };
 
-- 
2.25.1


  parent reply	other threads:[~2024-02-14 17:22 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-14 17:21 [PATCH v3 0/7] Introduction of a remoteproc tee to load signed firmware Arnaud Pouliquen
2024-02-14 17:21 ` [PATCH v3 1/7] remoteproc: Add TEE support Arnaud Pouliquen
2024-02-20 18:58   ` Mathieu Poirier
2024-02-21  8:39     ` Arnaud POULIQUEN
2024-02-22  5:42   ` Naman Jain
2024-02-23 18:27   ` Mathieu Poirier
2024-02-28  8:20     ` Arnaud POULIQUEN
2024-02-29 16:19       ` Mathieu Poirier
2024-02-29 18:26         ` Arnaud POULIQUEN
2024-02-14 17:21 ` [PATCH v3 2/7] remoteproc: Extract the firmware load from the start Arnaud Pouliquen
2024-02-14 17:21 ` [PATCH v3 3/7] remoteproc: core: Add check on cached_table pointer Arnaud Pouliquen
2024-02-23 18:32   ` Mathieu Poirier
2024-02-14 17:21 ` Arnaud Pouliquen [this message]
2024-02-14 17:21 ` [PATCH v3 5/7] dt-bindings: remoteproc: Add compatibility for TEE support Arnaud Pouliquen
2024-02-22 18:24   ` Rob Herring
2024-02-14 17:21 ` [PATCH v3 6/7] remoteproc: stm32: Create sub-functions to request shutdown and release Arnaud Pouliquen
2024-02-14 17:21 ` [PATCH v3 7/7] remoteproc: stm32: Add support of an OP-TEE TA to load the firmware Arnaud Pouliquen
2024-02-22 19:02   ` Mathieu Poirier
2024-02-23 13:54     ` Arnaud POULIQUEN
2024-02-23 18:37       ` Mathieu Poirier
2024-02-29 18:16         ` Arnaud POULIQUEN
2024-02-22  5:43 ` [PATCH v3 0/7] Introduction of a remoteproc tee to load signed firmware Naman Jain
2024-02-22  8:47   ` Arnaud POULIQUEN
2024-02-22  9:55     ` Naman Jain
2024-02-23 14:10       ` Arnaud POULIQUEN

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240214172127.1022199-5-arnaud.pouliquen@foss.st.com \
    --to=arnaud.pouliquen@foss.st.com \
    --cc=andersson@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=jens.wiklander@linaro.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=mathieu.poirier@linaro.org \
    --cc=op-tee@lists.trustedfirmware.org \
    --cc=robh+dt@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).