linux-remoteproc.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: nikita.shubin@maquefel.me
To: nikita.shubin@maquefel.me
Cc: Nikita Shubin <NShubin@topcon.com>,
	Ohad Ben-Cohen <ohad@wizery.com>,
	Bjorn Andersson <bjorn.andersson@linaro.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	linux-remoteproc@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Subject: [PATCH v2 3/3] remoteproc: imx_rproc: memory regions
Date: Mon,  6 Apr 2020 14:33:10 +0300	[thread overview]
Message-ID: <20200406113310.3041-4-nikita.shubin@maquefel.me> (raw)
In-Reply-To: <20200406113310.3041-1-nikita.shubin@maquefel.me>

Add support for carveout memory regions required for vdev vring's and
buffer.

Search in device tree and allocate memory regions like for ocram:

vdev0vring0: vdev0vring0@00920000 {
	compatible = "shared-dma-pool";
        reg = <0x00920000 0x2000>;
        no-map;
};

vdev0vring1: vdev0vring1@00922000 {
	compatible = "shared-dma-pool";
	reg = <0x00922000 0x2000>;
	no-map;
};

vdev0buffer: vdev0buffer@00924000 {
	compatible = "shared-dma-pool";
	reg = <0x00924000 0x4000>;
	no-map;
};

imx7d-cm4 {
	compatible = "fsl,imx7d-cm4";
	memory-region = <&ocram>, <&vdev0vring0>, <&vdev0vring1>, \
		<&vdev0buffer>;
}

vdev0vring0, vdev0vring1, vdev0buffer are required for virtio
functioning.

Signed-off-by: Nikita Shubin <NShubin@topcon.com>
---
 drivers/remoteproc/imx_rproc.c | 119 ++++++++++++++++++++++++++++++++-
 1 file changed, 118 insertions(+), 1 deletion(-)

diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
index d2bede4ccb70..cdcff2bd2867 100644
--- a/drivers/remoteproc/imx_rproc.c
+++ b/drivers/remoteproc/imx_rproc.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/of_address.h>
 #include <linux/of_device.h>
+#include <linux/of_reserved_mem.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -238,6 +239,29 @@ static int imx_rproc_da_to_sys(struct imx_rproc *priv, u64 da,
 	return -ENOENT;
 }
 
+static int imx_rproc_sys_to_da(struct imx_rproc *priv, u64 sys,
+				int len, u64 *da)
+{
+	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
+	int i;
+
+	/* parse address translation table */
+	for (i = 0; i < dcfg->att_size; i++) {
+		const struct imx_rproc_att *att = &dcfg->att[i];
+
+		if (sys >= att->sa && sys + len <= att->sa + att->size) {
+			unsigned int offset = sys - att->sa;
+
+			*da = att->da + offset;
+			return 0;
+		}
+	}
+
+	dev_warn(priv->dev, "Translation failed: sys = 0x%llx len = 0x%x\n",
+			 sys, len);
+	return -ENOENT;
+}
+
 static void *imx_rproc_da_to_va(struct rproc *rproc, u64 da, int len)
 {
 	struct imx_rproc *priv = rproc->priv;
@@ -372,16 +396,109 @@ static void imx_rproc_kick(struct rproc *rproc, int vqid)
 		err = mbox_send_message(ddata->mb[i].chan, &vqid);
 		if (err < 0)
 			dev_err(&rproc->dev, "%s: failed (%s, err:%d)\n",
-					__func__, ddata->mb[i].name, err);
+				__func__, ddata->mb[i].name, err);
 			return;
 	}
 }
 
+static int imx_rproc_mem_alloc(struct rproc *rproc,
+				struct rproc_mem_entry *mem)
+{
+	struct device *dev = rproc->dev.parent;
+	void *va;
+
+	dev_dbg(dev, "map memory: %pa+%x\n", &mem->dma, mem->len);
+	va = ioremap_wc(mem->dma, mem->len);
+	if (IS_ERR_OR_NULL(va)) {
+		dev_err(dev, "Unable to map memory region: %pa+%x\n",
+				&mem->dma, mem->len);
+		return -ENOMEM;
+	}
+
+	/* Update memory entry va */
+	mem->va = va;
+
+	return 0;
+}
+
+static int imx_rproc_mem_release(struct rproc *rproc,
+				struct rproc_mem_entry *mem)
+{
+	dev_dbg(rproc->dev.parent, "unmap memory: %pa\n", &mem->dma);
+	iounmap(mem->va);
+
+	return 0;
+}
+
+static int imx_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+	struct imx_rproc *priv = rproc->priv;
+	struct device *dev = rproc->dev.parent;
+	struct device_node *np = dev->of_node;
+	struct of_phandle_iterator it;
+	struct rproc_mem_entry *mem = 0;
+	struct reserved_mem *rmem;
+	u64 da;
+	int index = 0;
+
+	/* Register associated reserved memory regions */
+	of_phandle_iterator_init(&it, np, "memory-region", NULL, 0);
+	while (of_phandle_iterator_next(&it) == 0) {
+		rmem = of_reserved_mem_lookup(it.node);
+		if (!rmem) {
+			dev_err(dev, "unable to acquire memory-region\n");
+			return -EINVAL;
+		}
+
+		/*
+		 * Let's assume all data in device tree is from
+		 * CPU A7 point of view then we should translate
+		 * rmem->base into M4 da
+		 */
+		if (imx_rproc_sys_to_da(priv, rmem->base, rmem->size, &da)) {
+			dev_err(dev, "memory region not valid %pa\n",
+				&rmem->base);
+			return -EINVAL;
+		}
+
+		if (strcmp(it.node->name, "vdev0buffer")) {
+			/* Register memory region */
+			mem = rproc_mem_entry_init(dev, NULL,
+						(dma_addr_t)rmem->base,
+						rmem->size, da,
+						imx_rproc_mem_alloc,
+						imx_rproc_mem_release,
+						it.node->name);
+
+			if (mem)
+				rproc_coredump_add_segment(rproc, da,
+							rmem->size);
+		} else {
+			mem = rproc_of_resm_mem_entry_init(dev, index,
+							rmem->size,
+							rmem->base,
+							it.node->name);
+		}
+
+		if (!mem)
+			return -ENOMEM;
+
+		rproc_add_carveout(rproc, mem);
+		index++;
+	}
+
+	return rproc_elf_load_rsc_table(rproc, fw);
+}
+
 static const struct rproc_ops imx_rproc_ops = {
 	.start		= imx_rproc_start,
 	.stop		= imx_rproc_stop,
 	.da_to_va	= imx_rproc_da_to_va,
 	.kick		= imx_rproc_kick,
+	.load		= rproc_elf_load_segments,
+	.parse_fw	= imx_rproc_parse_fw,
+	.find_loaded_rsc_table = rproc_elf_find_loaded_rsc_table,
+	.sanity_check	= rproc_elf_sanity_check,
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
-- 
2.25.1

  parent reply	other threads:[~2020-04-06 11:33 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-03-04 14:26 [PATCH 1/2] remoteproc: imx_rproc: dummy kick method Nikita Shubin
2020-03-04 14:26 ` [PATCH 2/2] remoteproc: imx_rproc: set pc on start Nikita Shubin
2020-03-05 16:16 ` [PATCH 1/2] remoteproc: imx_rproc: dummy kick method Mathieu Poirier
2020-03-05 17:29   ` nikita.shubin
2020-03-05 17:54     ` Mathieu Poirier
2020-03-05 18:07       ` nikita.shubin
2020-03-05 18:36         ` Mathieu Poirier
2020-03-05 18:46           ` nikita.shubin
2020-04-06 11:33 ` [PATCH v2 0/3] remoteproc: imx_rproc: add virtio support nikita.shubin
2020-04-06 11:33   ` nikita.shubin
2020-04-06 11:33   ` [PATCH v2 1/3] remoteproc: imx_rproc: set pc on start nikita.shubin
2020-04-06 11:33     ` nikita.shubin
2020-04-14 16:45     ` Mathieu Poirier
2020-04-14 16:45       ` Mathieu Poirier
2020-04-17  5:40       ` nikita.shubin
2020-04-17 17:01         ` Mathieu Poirier
2020-04-17 17:01           ` Mathieu Poirier
2020-04-17 17:26           ` Nikita Shubin
2020-04-17 17:26             ` Nikita Shubin
2020-04-17 22:24             ` Mathieu Poirier
2020-04-17 22:24               ` Mathieu Poirier
2020-04-22  7:35               ` Nikita Shubin
2020-04-22  7:35                 ` Nikita Shubin
2020-04-17 12:11       ` Nikita Shubin
2020-04-17 12:11         ` Nikita Shubin
2020-04-17 15:37         ` Mathieu Poirier
2020-04-17 15:37           ` Mathieu Poirier
2020-04-17 15:46           ` Nikita Shubin
2020-04-17 15:46             ` Nikita Shubin
2020-04-06 11:33   ` [PATCH v2 2/3] remoteproc: imx_rproc: mailbox support nikita.shubin
2020-04-06 11:33     ` nikita.shubin
2020-04-07  1:07     ` kbuild test robot
2020-04-07  1:07       ` kbuild test robot
2020-04-14 17:20     ` Mathieu Poirier
2020-04-14 17:20       ` Mathieu Poirier
2020-04-17  8:37       ` Nikita Shubin
2020-04-17  8:37         ` Nikita Shubin
2020-04-17 16:02         ` Mathieu Poirier
2020-04-17 16:02           ` Mathieu Poirier
2020-04-14 17:36     ` Mathieu Poirier
2020-04-14 17:36       ` Mathieu Poirier
2020-04-06 11:33   ` nikita.shubin [this message]
2020-04-06 11:33     ` [PATCH v2 3/3] remoteproc: imx_rproc: memory regions nikita.shubin
2020-04-14 17:46     ` Mathieu Poirier
2020-04-14 17:46       ` Mathieu Poirier
2020-04-15  2:42   ` [PATCH v2 0/3] remoteproc: imx_rproc: add virtio support Peng Fan
2020-04-15  2:42     ` Peng Fan
2020-04-15 16:26     ` Mathieu Poirier
2020-04-15 16:26       ` Mathieu Poirier
2020-04-17  8:57     ` Nikita Shubin
2020-04-17  8:57       ` Nikita Shubin

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=20200406113310.3041-4-nikita.shubin@maquefel.me \
    --to=nikita.shubin@maquefel.me \
    --cc=NShubin@topcon.com \
    --cc=bjorn.andersson@linaro.org \
    --cc=festevam@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=ohad@wizery.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@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 NNTP newsgroup(s).