Skip to contentSkip to conversation

remoteproc: st: add virtio_rpmsg support

PATCH Superseded Loic Pallardy 3 participants 11 messages Jan 31, 2017 – Feb 9, 2017

Subsystems (2)

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover remoteproc: st: add virtio_rpmsg support

Goal of this series is:
- to add vring based communication link (virtio_rpmsg)
- to add rproc_da_to_va translation function to allow firmware loading in pre-reserved carveout memory region

V2:
Only changes in patch 1 to:
- fix typos
- fix mailbox allocation per coprocessor

V3:
- Integrate Bjorn's comments about mailbox support simplification
- Add missing Signed-of-by
- Move st_rproc_probe error management correction in a dedicated patch
- Fix warnings reported by checkpatch --strict

Loic Pallardy (4):
remoteproc: st: correct probe error management
remoteproc: st: add virtio communication support
remoteproc: st: add da to va support
remoteproc: core: don't allocate carveout if pa or da are defined

 drivers/remoteproc/Kconfig           |   3 +
 drivers/remoteproc/remoteproc_core.c |   5 ++
 drivers/remoteproc/st_remoteproc.c   | 158 +++++++++++++++++++++++++++++++++--
 3 files changed, 158 insertions(+), 8 deletions(-)
Signature · 1 line
1.9.1
#1 lore raw

PATCH v3 1/4 remoteproc: st: correct probe error management

Associated clock is prepared in st_rproc_parse_dt function. it should be unprepared in case of error during probing.

---
Changes from V2:
New patch fixing st_rproc_probe error management

 drivers/remoteproc/st_remoteproc.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/remoteproc/st_remoteproc.c +4 -2
index da4e152..bdfab49 100644
@@ -247,7 +247,7 @@ static int st_rproc_probe(struct platform_device *pdev)
 	enabled = st_rproc_state(pdev);
 	if (enabled < 0) {
 		ret = enabled;
-		goto free_rproc;
+		goto free_clk;
 	}
 
 	if (enabled) {
@@ -259,10 +259,12 @@ static int st_rproc_probe(struct platform_device *pdev)
 
 	ret = rproc_add(rproc);
 	if (ret)
-		goto free_rproc;
+		goto free_clk;
 
 	return 0;
 
+free_clk:
+	clk_unprepare(ddata->clk);
 free_rproc:
 	rproc_free(rproc);
 	return ret;
Signature · 1 line
1.9.1
#2 lore raw

Re: [PATCH v3 1/4] remoteproc: st: correct probe error management

Quoted 4 lines · Loic Pallardy

Associated clock is prepared in st_rproc_parse_dt function. it should be unprepared in case of error during probing.

Applied patch 1 and 2.

Regards,
Bjorn

#3 lore raw

RE: [PATCH v3 1/4] remoteproc: st: correct probe error management

Quoted 12 lines

-----Original Message-----
From: Bjorn Andersson [mailto:[email protected]]
Sent: Monday, February 06, 2017 10:20 PM
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Patrice CHOTARD <[email protected]>; Hugues FRUCHET <[email protected]>; [email protected]
Subject: Re: [PATCH v3 1/4] remoteproc: st: correct probe error management

Quoted 8 lines
Quoted 4 lines · Loic Pallardy

Associated clock is prepared in st_rproc_parse_dt function. it should be unprepared in case of error during probing.

Applied patch 1 and 2.

Thanks Bjorn.
Did you have time to review patch 3 and 4?
Regards,
Loic

Quoted 3 lines

Regards,
Bjorn

#4 lore raw

PATCH v3 2/4 remoteproc: st: add virtio communication support

In reply to Loic Pallardy

This patch provides virtio communication support based on mailbox for ST co-processors.

---
Changes from V2:
- Flatten mailbox channel to simplify mailbox management
- Flip test condition to simplify code
- Move clk_unprepare in a dedicated fix patch
- Add missing Signed-off-by

Changes from V1:
- fix typos
- fix mailbox allocation per co-processor

---
 drivers/remoteproc/Kconfig         |   3 +
 drivers/remoteproc/st_remoteproc.c | 113 ++++++++++++++++++++++++++++++++++++-
 2 files changed, 114 insertions(+), 2 deletions(-)
drivers/remoteproc/Kconfig +3 -0
index 8f9cf0b..108add8 100644
@@ -111,6 +111,9 @@ config ST_REMOTEPROC
 	tristate "ST remoteproc support"
 	depends on ARCH_STI
 	depends on REMOTEPROC
+	select MAILBOX
+	select STI_MBOX
+	select RPMSG_VIRTIO
 	help
 	  Say y here to support ST's adjunct processors via the remote
 	  processor framework.
drivers/remoteproc/st_remoteproc.c +111 -2

169 lines not on this page · raw message

Signature · 1 line
1.9.1
#5 lore raw

PATCH v3 3/4 remoteproc: st: add da to va support

In reply to Loic Pallardy

ST remoteproc driver needs to provide information about carveout memory region to allow remoteproc core to load firmware and access trace buffer.

---
Changes since V2:
- fix checkpatch --strict warning

---
 drivers/remoteproc/st_remoteproc.c | 43 ++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)
drivers/remoteproc/st_remoteproc.c +37 -6
index f1e9339..80f8118 100644
@@ -21,6 +21,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_reserved_mem.h>
+#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -53,6 +54,10 @@ struct st_rproc {
 	struct mbox_chan	*mbox_chan[ST_RPROC_MAX_VRING * MBOX_MAX];
 	struct mbox_client mbox_client_vq0;
 	struct mbox_client mbox_client_vq1;
+	phys_addr_t mem_phys;
+	phys_addr_t mem_reloc;
+	void *mem_region;
+	size_t mem_size;
 };
 
 static void st_rproc_mbox_callback(struct device *dev, u32 msg)
@@ -157,10 +162,23 @@ static int st_rproc_stop(struct rproc *rproc)
 	return sw_err ?: pwr_err;
 }
 
+static void *st_proc_da_to_va(struct rproc *rproc, u64 da, int len)
+{
+	struct st_rproc *ddata = rproc->priv;
+	int offset;
+
+	offset = da - ddata->mem_reloc;
+	if (offset < 0 || offset + len > ddata->mem_size)
+		return NULL;
+
+	return ddata->mem_region + offset;
+}
+
 static struct rproc_ops st_rproc_ops = {
 	.kick		= st_rproc_kick,
 	.start		= st_rproc_start,
 	.stop		= st_rproc_stop,
+	.da_to_va	= st_proc_da_to_va,
 };
 
 /*
@@ -208,7 +226,8 @@ static int st_rproc_parse_dt(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rproc *rproc = platform_get_drvdata(pdev);
 	struct st_rproc *ddata = rproc->priv;
-	struct device_node *np = dev->of_node;
+	struct device_node *np = dev->of_node, *node;
+	struct resource res;
 	int err;
 
 	if (ddata->config->sw_reset) {
@@ -252,10 +271,24 @@ static int st_rproc_parse_dt(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	err = of_reserved_mem_device_init(dev);
-	if (err) {
-		dev_err(dev, "Failed to obtain shared memory\n");
+	node = of_parse_phandle(np, "memory-region", 0);
+	if (!node) {
+		dev_err(dev, "No memory-region specified\n");
+		return -EINVAL;
+	}
+
+	err = of_address_to_resource(node, 0, &res);
+	if (err)
 		return err;
+
+	ddata->mem_phys = res.start;
+	ddata->mem_reloc = res.start;
+	ddata->mem_size = resource_size(&res);
+	ddata->mem_region = devm_ioremap_wc(dev, ddata->mem_phys, ddata->mem_size);
+	if (!ddata->mem_region) {
+		dev_err(dev, "Unable to map memory region: %pa+%zx\n",
+			&res.start, ddata->mem_size);
+		return -EBUSY;
 	}
 
 	err = clk_prepare(ddata->clk);
@@ -385,8 +418,6 @@ static int st_rproc_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(ddata->clk);
 
-	of_reserved_mem_device_release(&pdev->dev);
-
 	for (i = 0; i < ST_RPROC_MAX_VRING * MBOX_MAX; i++)
 		mbox_free_channel(ddata->mbox_chan[i]);
 
Signature · 1 line
1.9.1
#6 lore raw

Re: [v3,3/4] remoteproc: st: add da to va support

Quoted 5 lines · Loic PALLARDY

ST remoteproc driver needs to provide information about carveout memory region to allow remoteproc core to load firmware and access trace buffer.

Tested on B2260 ST Platform with st-delta video decoder V4L2 kernel driver
(http://www.mail-archive.com/[email protected]/msg107644.html).

Quoted 102 lines

---
Changes since V2:
- fix checkpatch --strict warning

---
 drivers/remoteproc/st_remoteproc.c | 43 ++++++++++++++++++++++++++++++++------
 1 file changed, 37 insertions(+), 6 deletions(-)
drivers/remoteproc/st_remoteproc.c +37 -6
index f1e9339..80f8118 100644
@@ -21,6 +21,7 @@
 #include <linux/of.h>
 #include <linux/of_device.h>
 #include <linux/of_reserved_mem.h>
+#include <linux/of_address.h>
 #include <linux/platform_device.h>
 #include <linux/regmap.h>
 #include <linux/remoteproc.h>
@@ -53,6 +54,10 @@ struct st_rproc {
 	struct mbox_chan	*mbox_chan[ST_RPROC_MAX_VRING * MBOX_MAX];
 	struct mbox_client mbox_client_vq0;
 	struct mbox_client mbox_client_vq1;
+	phys_addr_t mem_phys;
+	phys_addr_t mem_reloc;
+	void *mem_region;
+	size_t mem_size;
 };
 
 static void st_rproc_mbox_callback(struct device *dev, u32 msg)
@@ -157,10 +162,23 @@ static int st_rproc_stop(struct rproc *rproc)
 	return sw_err ?: pwr_err;
 }
 
+static void *st_proc_da_to_va(struct rproc *rproc, u64 da, int len)
+{
+	struct st_rproc *ddata = rproc->priv;
+	int offset;
+
+	offset = da - ddata->mem_reloc;
+	if (offset < 0 || offset + len > ddata->mem_size)
+		return NULL;
+
+	return ddata->mem_region + offset;
+}
+
 static struct rproc_ops st_rproc_ops = {
 	.kick		= st_rproc_kick,
 	.start		= st_rproc_start,
 	.stop		= st_rproc_stop,
+	.da_to_va	= st_proc_da_to_va,
 };
 
 /*
@@ -208,7 +226,8 @@ static int st_rproc_parse_dt(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct rproc *rproc = platform_get_drvdata(pdev);
 	struct st_rproc *ddata = rproc->priv;
-	struct device_node *np = dev->of_node;
+	struct device_node *np = dev->of_node, *node;
+	struct resource res;
 	int err;
 
 	if (ddata->config->sw_reset) {
@@ -252,10 +271,24 @@ static int st_rproc_parse_dt(struct platform_device *pdev)
 		return -EINVAL;
 	}
 
-	err = of_reserved_mem_device_init(dev);
-	if (err) {
-		dev_err(dev, "Failed to obtain shared memory\n");
+	node = of_parse_phandle(np, "memory-region", 0);
+	if (!node) {
+		dev_err(dev, "No memory-region specified\n");
+		return -EINVAL;
+	}
+
+	err = of_address_to_resource(node, 0, &res);
+	if (err)
 		return err;
+
+	ddata->mem_phys = res.start;
+	ddata->mem_reloc = res.start;
+	ddata->mem_size = resource_size(&res);
+	ddata->mem_region = devm_ioremap_wc(dev, ddata->mem_phys, ddata->mem_size);
+	if (!ddata->mem_region) {
+		dev_err(dev, "Unable to map memory region: %pa+%zx\n",
+			&res.start, ddata->mem_size);
+		return -EBUSY;
 	}
 
 	err = clk_prepare(ddata->clk);
@@ -385,8 +418,6 @@ static int st_rproc_remove(struct platform_device *pdev)
 
 	clk_disable_unprepare(ddata->clk);
 
-	of_reserved_mem_device_release(&pdev->dev);
-
 	for (i = 0; i < ST_RPROC_MAX_VRING * MBOX_MAX; i++)
 		mbox_free_channel(ddata->mbox_chan[i]);
 
#7 lore raw

PATCH v3 4/4 remoteproc: core: don't allocate carveout if pa or da are defined

In reply to Loic Pallardy

Remoteproc doesn't check if firmware requests fixed addresses for carveout regions.
Current assumption is that platform specific driver is in charge of coprocessor specific memory region allocation and remoteproc core doesn't have to handle them.
If a da or a pa is specified in firmware resource table, remoteproc core doesn't have to perform any allocation.
Access to carveout will be done thanks to rproc_da_to_pa function, which will provide virtual address on carveout region allocated by platform specific driver.

---
No change since V1

 drivers/remoteproc/remoteproc_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/remoteproc/remoteproc_core.c +5 -0
index 90b05c7..dd63ceed 100644
@@ -622,6 +622,11 @@ static int rproc_handle_carveout(struct rproc *rproc,
 	dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n",
 		rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
 
+	if (rsc->pa != FW_RSC_ADDR_ANY || rsc->da != FW_RSC_ADDR_ANY) {
+		dev_dbg(dev, "carveout already allocated by low level driver\n");
+		return 0;
+	}
+
 	carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
 	if (!carveout)
 		return -ENOMEM;
Signature · 1 line
1.9.1
#8 lore raw

Re: [v3, 4/4] remoteproc: core: don't allocate carveout if pa or da are defined

Quoted 11 lines · Loic PALLARDY

Remoteproc doesn't check if firmware requests fixed addresses for carveout regions.
Current assumption is that platform specific driver is in charge of coprocessor specific memory region allocation and remoteproc core doesn't have to handle them.
If a da or a pa is specified in firmware resource table, remoteproc core doesn't have to perform any allocation.
Access to carveout will be done thanks to rproc_da_to_pa function, which will provide virtual address on carveout region allocated by platform specific driver.

Quoted 1 line

Tested on B2260 ST Platform with st-delta video decoder V4L2 kernel driver
(http://www.mail-archive.com/[email protected]/msg107644.html).

Quoted 24 lines

---
No change since V1

 drivers/remoteproc/remoteproc_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/remoteproc/remoteproc_core.c +5 -0
index 90b05c7..dd63ceed 100644
@@ -622,6 +622,11 @@ static int rproc_handle_carveout(struct rproc *rproc,
 	dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n",
 		rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
 
+	if (rsc->pa != FW_RSC_ADDR_ANY || rsc->da != FW_RSC_ADDR_ANY) {
+		dev_dbg(dev, "carveout already allocated by low level driver\n");
+		return 0;
+	}
+
 	carveout = kzalloc(sizeof(*carveout), GFP_KERNEL);
 	if (!carveout)
 		return -ENOMEM;
#9 lore raw

Re: [PATCH v3 4/4] remoteproc: core: don't allocate carveout if pa or da are defined

In reply to Loic Pallardy
Quoted 23 lines · Loic Pallardy

Remoteproc doesn't check if firmware requests fixed addresses for carveout regions.
Current assumption is that platform specific driver is in charge of coprocessor specific memory region allocation and remoteproc core doesn't have to handle them.
If a da or a pa is specified in firmware resource table, remoteproc core doesn't have to perform any allocation.
Access to carveout will be done thanks to rproc_da_to_pa function, which will provide virtual address on carveout region allocated by platform specific driver.

---
No change since V1

 drivers/remoteproc/remoteproc_core.c | 5 +++++
 1 file changed, 5 insertions(+)
drivers/remoteproc/remoteproc_core.c +0 -0
index 90b05c7..dd63ceed 100644

drivers/remoteproc/remoteproc_core.c static int rproc_handle_carveout(struct rproc *rproc, · line 625

Quoted 4 lines
drivers/remoteproc/remoteproc_core.c +1 -0
@@ -622,6 +622,11 @@ static int rproc_handle_carveout(struct rproc *rproc,
 	dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x, flags 0x%x\n",
 		rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
 
+	if (rsc->pa != FW_RSC_ADDR_ANY || rsc->da != FW_RSC_ADDR_ANY) {

For devices with an IOMMU it's valid to specify "da" and have the allocated region mapped there. So this is not correct.

Regards,
Bjorn

#10 lore raw

RE: [PATCH v3 4/4] remoteproc: core: don't allocate carveout if pa or da are defined

Quoted 41 lines

-----Original Message-----
From: Bjorn Andersson [mailto:[email protected]]
Sent: Thursday, February 09, 2017 2:55 AM
To: Loic PALLARDY <[email protected]>
Cc: [email protected]; [email protected]; linux- [email protected]; [email protected]; [email protected]; Patrice CHOTARD <[email protected]>; Hugues FRUCHET <[email protected]>; [email protected]
Subject: Re: [PATCH v3 4/4] remoteproc: core: don't allocate carveout if pa or da are defined

Quoted 11 lines · Loic Pallardy

Remoteproc doesn't check if firmware requests fixed addresses for carveout regions.
Current assumption is that platform specific driver is in charge of coprocessor specific memory region allocation and remoteproc core doesn't have to handle them.
If a da or a pa is specified in firmware resource table, remoteproc core doesn't have to perform any allocation.
Access to carveout will be done thanks to rproc_da_to_pa function, which will provide virtual address on carveout region allocated by platform specific driver.

Review

Quoted 8 lines

---
No change since V1

 drivers/remoteproc/remoteproc_core.c | 5 +++++
 1 file changed, 5 insertions(+)
(quoted diff) +0 -0

b/drivers/remoteproc/remoteproc_core.c

drivers/remoteproc/remoteproc_core.c static int rproc_handle_carveout(struct rproc

Quoted 4 lines

index 90b05c7..dd63ceed 100644

drivers/remoteproc/remoteproc_core.c +0 -0
@@ -622,6 +622,11 @@ static int rproc_handle_carveout(struct rproc

*rproc,

drivers/remoteproc/remoteproc_core.c static int rproc_handle_carveout(struct rproc · line 622

Quoted 1 line
drivers/remoteproc/remoteproc_core.c +0 -0
 	dev_dbg(dev, "carveout rsc: name: %s, da 0x%x, pa 0x%x, len 0x%x,
Quoted 8 lines

flags 0x%x\n",

drivers/remoteproc/remoteproc_core.c static int rproc_handle_carveout(struct rproc *rproc,

Quoted 3 lines
drivers/remoteproc/remoteproc_core.c +1 -0
 		rsc->name, rsc->da, rsc->pa, rsc->len, rsc->flags);
 
+	if (rsc->pa != FW_RSC_ADDR_ANY || rsc->da !=

FW_RSC_ADDR_ANY) {

For devices with an IOMMU it's valid to specify "da" and have the allocated region mapped there. So this is not correct.

You're right, moreover patch series touch only to pa, so even if da behavior should be changed, should be done in a dedicated patch. I'll send a V4.

Regards,
Loic

Quoted 3 lines

Regards,
Bjorn