Skip to contentSkip to conversation

remoteproc: stm32: Add support for synchronisation with MCU

PATCH Superseded Mathieu Poirier 2 participants 26 messages Mar 24, 2020 – Mar 30, 2020

Subsystems (2)

v1 of 6 Superseded Latest is v6 →

lore
Share & tools
lore

Mathieu Poirier

author maintainer
#0 lore raw

cover remoteproc: stm32: Add support for synchronisation with MCU

This patchset needs to be applied on top of this one [1].

It refactors the STM32 platform code in order to introduce support for synchronising with an MCU that would have been started by another entity.

Most of the code is taken from work that Arnaud has already published [2].

On top of making sure the classic case where the remoteproc core is in charge of the MCU's lifecyle is still functional, this set also tested that it can synchronise with the MCU on ST's mp157c board.

Thanks,
Mathieu

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=261069
[2]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

Mathieu Poirier (11):
remoteproc: stm32: Decouple rproc from memory translation
remoteproc: stm32: Request IRQ with platform device
remoteproc: stm32: Decouple rproc from DT parsing
remoteproc: stm32: Remove memory translation from DT parsing
remoteproc: stm32: Parse syscon that will manage M4 synchronisation
remoteproc: stm32: Get coprocessor state
remoteproc: stm32: Get loaded resource table for synchronisation
remoteproc: stm32: Introduce new start and stop ops for
synchronisation
remoteproc: stm32: Introduce new parse fw ops for synchronisation
remoteproc: stm32: Introduce new loaded rsc ops for synchronisation
remoteproc: stm32: Allocate rproc for synchronisation with MCU

 drivers/remoteproc/stm32_rproc.c | 285 ++++++++++++++++++++++++++++---
 1 file changed, 265 insertions(+), 20 deletions(-)
Signature · 1 line
2.20.1
author maintainer
#1 lore raw

PATCH 1/11 remoteproc: stm32: Decouple rproc from memory translation

Remove the remote processor from the process of parsing the memory ranges since there is no correlation between them.

---
 drivers/remoteproc/stm32_rproc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/remoteproc/stm32_rproc.c +4 -4
index a18f88044111..cde4b1a56381 100644
@@ -127,10 +127,10 @@ static int stm32_rproc_mem_release(struct rproc *rproc,
 	return 0;
 }
 
-static int stm32_rproc_of_memory_translations(struct rproc *rproc)
+static int stm32_rproc_of_memory_translations(struct platform_device *pdev,
+					      struct stm32_rproc *ddata)
 {
-	struct device *parent, *dev = rproc->dev.parent;
-	struct stm32_rproc *ddata = rproc->priv;
+	struct device *parent, *dev = &pdev->dev;
 	struct device_node *np;
 	struct stm32_rproc_mem *p_mems;
 	struct stm32_rproc_mem_ranges *mem_range;
@@ -606,7 +606,7 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev)
 
 	rproc->auto_boot = of_property_read_bool(np, "st,auto-boot");
 
-	return stm32_rproc_of_memory_translations(rproc);
+	return stm32_rproc_of_memory_translations(pdev, ddata);
 }
 
 static int stm32_rproc_probe(struct platform_device *pdev)
Signature · 1 line
2.20.1
Reviewed-by on v1 1/11
#2 lore raw

RE: [PATCH 01/11] remoteproc: stm32: Decouple rproc from memory translation

Quoted 14 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Mathieu Poirier
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 01/11] remoteproc: stm32: Decouple rproc from memory translation

Quoted 4 lines

Remove the remote processor from the process of parsing the memory ranges since there is no correlation between them.

Thanks Mathieu

Quoted 37 lines
---
 drivers/remoteproc/stm32_rproc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/remoteproc/stm32_rproc.c +3 -3
index a18f88044111..cde4b1a56381 100644
@@ -127,10 +127,10 @@ static int stm32_rproc_mem_release(struct rproc
 *rproc,
 	return 0;
 }
 
-static int stm32_rproc_of_memory_translations(struct rproc *rproc)
+static int stm32_rproc_of_memory_translations(struct platform_device
 *pdev,
+					      struct stm32_rproc *ddata)
 {
-	struct device *parent, *dev = rproc->dev.parent;
-	struct stm32_rproc *ddata = rproc->priv;
+	struct device *parent, *dev = &pdev->dev;
 	struct device_node *np;
drivers/remoteproc/stm32_rproc.c +1 -1
 	struct stm32_rproc_mem *p_mems;
 	struct stm32_rproc_mem_ranges *mem_range;
@@ -606,7 +606,7 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev)
 
 	rproc->auto_boot = of_property_read_bool(np, "st,auto-boot");
 
-	return stm32_rproc_of_memory_translations(rproc);
+	return stm32_rproc_of_memory_translations(pdev, ddata);
 }
 

static int stm32_rproc_probe(struct platform_device *pdev)
--
2.20.1

author maintainer
#3 lore raw

PATCH 2/11 remoteproc: stm32: Request IRQ with platform device

In reply to Mathieu Poirier

Request IRQ with platform device rather than remote proc in order to call stm32_rproc_parse_dt() before rproc_alloc(). That way we can know whether we need to synchronise with the MCU or not.

---
 drivers/remoteproc/stm32_rproc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +3 -2
index cde4b1a56381..0c1f0b84e057 100644
@@ -261,7 +261,8 @@ static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
 {
-	struct rproc *rproc = data;
+	struct platform_device *pdev = data;
+	struct rproc *rproc = platform_get_drvdata(pdev);
 
 	rproc_report_crash(rproc, RPROC_WATCHDOG);
 
@@ -553,7 +554,7 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev)
 
 	if (irq > 0) {
 		err = devm_request_irq(dev, irq, stm32_rproc_wdg, 0,
-				       dev_name(dev), rproc);
+				       dev_name(dev), pdev);
 		if (err) {
 			dev_err(dev, "failed to request wdg irq\n");
 			return err;
Signature · 1 line
2.20.1
Reviewed-by on v1 2/11
#4 lore raw

RE: [PATCH 02/11] remoteproc: stm32: Request IRQ with platform device

Quoted 13 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 02/11] remoteproc: stm32: Request IRQ with platform device

Quoted 5 lines

Request IRQ with platform device rather than remote proc in order to call stm32_rproc_parse_dt() before rproc_alloc(). That way we can know whether we need to synchronise with the MCU or not.

Thanks Mathieu

Quoted 32 lines
---
 drivers/remoteproc/stm32_rproc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/remoteproc/stm32_rproc.c +3 -2
index cde4b1a56381..0c1f0b84e057 100644
@@ -261,7 +261,8 @@ static int stm32_rproc_parse_fw(struct rproc *rproc,
 const struct firmware *fw)
 
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
 {
-	struct rproc *rproc = data;
+	struct platform_device *pdev = data;
+	struct rproc *rproc = platform_get_drvdata(pdev);
 
 	rproc_report_crash(rproc, RPROC_WATCHDOG);
@@ -553,7 +554,7 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev)
 
 	if (irq > 0) {
 		err = devm_request_irq(dev, irq, stm32_rproc_wdg, 0,
-				       dev_name(dev), rproc);
+				       dev_name(dev), pdev);
 		if (err) {
 			dev_err(dev, "failed to request wdg irq\n");

return err;
--
2.20.1

author maintainer
#5 lore raw

PATCH 3/11 remoteproc: stm32: Decouple rproc from DT parsing

In reply to Mathieu Poirier

Remove the remote processor from the process of parsing the device tree since (1) there is no correlation between them and (2) to use the information that was gathered to make a decision on whether to synchronise with the MCU or not.

---
 drivers/remoteproc/stm32_rproc.c | 38 +++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/remoteproc/stm32_rproc.c +25 -13
index 0c1f0b84e057..ca60c917e218 100644
@@ -538,12 +538,11 @@ static int stm32_rproc_get_syscon(struct device_node *np, const char *prop,
 	return err;
 }
 
-static int stm32_rproc_parse_dt(struct platform_device *pdev)
+static int stm32_rproc_parse_dt(struct platform_device *pdev,
+				struct stm32_rproc *ddata, bool *auto_boot)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct rproc *rproc = platform_get_drvdata(pdev);
-	struct stm32_rproc *ddata = rproc->priv;
 	struct stm32_syscon tz;
 	unsigned int tzen;
 	int err, irq;
@@ -589,7 +588,7 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev)
 
 	err = regmap_read(tz.map, tz.reg, &tzen);
 	if (err) {
-		dev_err(&rproc->dev, "failed to read tzen\n");
+		dev_err(dev, "failed to read tzen\n");
 		return err;
 	}
 	ddata->secured_soc = tzen & tz.mask;
@@ -605,7 +604,7 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev)
 	if (err)
 		dev_warn(dev, "failed to get pdds\n");
 
-	rproc->auto_boot = of_property_read_bool(np, "st,auto-boot");
+	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
 	return stm32_rproc_of_memory_translations(pdev, ddata);
 }
@@ -616,18 +615,29 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
 	struct rproc *rproc;
+	bool auto_boot = false;
 	int ret;
 
 	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
 	if (ret)
 		return ret;
 
-	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
-	if (!rproc)
+	ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
+	if (!ddata)
 		return -ENOMEM;
 
+	ret = stm32_rproc_parse_dt(pdev, ddata, &auto_boot);
+	if (ret)
+		goto free_ddata;
+
+	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
+	if (!rproc) {
+		ret = -ENOMEM;
+		goto free_ddata;
+	}
+
+	rproc->auto_boot = auto_boot;
 	rproc->has_iommu = false;
-	ddata = rproc->priv;
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {
 		dev_err(dev, "cannot create workqueue\n");
@@ -635,20 +645,20 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 		goto free_rproc;
 	}
 
-	platform_set_drvdata(pdev, rproc);
+	memcpy(rproc->priv, ddata, sizeof(*ddata));
 
-	ret = stm32_rproc_parse_dt(pdev);
-	if (ret)
-		goto free_wkq;
+	platform_set_drvdata(pdev, rproc);
 
 	ret = stm32_rproc_request_mbox(rproc);
 	if (ret)
-		goto free_rproc;
+		goto free_wkq;
 
 	ret = rproc_add(rproc);
 	if (ret)
 		goto free_mb;
 
+	kfree(ddata);
+
 	return 0;
 
 free_mb:
@@ -661,6 +671,8 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 		device_init_wakeup(dev, false);
 	}
 	rproc_free(rproc);
+free_ddata:
+	kfree(ddata);
 	return ret;
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 3/11
#6 lore raw

RE: [PATCH 03/11] remoteproc: stm32: Decouple rproc from DT parsing

Quoted 12 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 03/11] remoteproc: stm32: Decouple rproc from DT parsing

Quoted 6 lines

Remove the remote processor from the process of parsing the device tree since (1) there is no correlation between them and (2) to use the information that was gathered to make a decision on whether to synchronise with the MCU or not.

Thanks Mathieu

Quoted 120 lines
---
 drivers/remoteproc/stm32_rproc.c | 38 +++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 13 deletions(-)
drivers/remoteproc/stm32_rproc.c +2 -3
index 0c1f0b84e057..ca60c917e218 100644
@@ -538,12 +538,11 @@ static int stm32_rproc_get_syscon(struct
 device_node *np, const char *prop,
 	return err;
 }
 
-static int stm32_rproc_parse_dt(struct platform_device *pdev)
+static int stm32_rproc_parse_dt(struct platform_device *pdev,
+				struct stm32_rproc *ddata, bool *auto_boot)
 {
 	struct device *dev = &pdev->dev;
 	struct device_node *np = dev->of_node;
-	struct rproc *rproc = platform_get_drvdata(pdev);
-	struct stm32_rproc *ddata = rproc->priv;
 	struct stm32_syscon tz;
 	unsigned int tzen;
drivers/remoteproc/stm32_rproc.c +1 -1
 	int err, irq;
@@ -589,7 +588,7 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev)
 
 	err = regmap_read(tz.map, tz.reg, &tzen);
 	if (err) {
-		dev_err(&rproc->dev, "failed to read tzen\n");
+		dev_err(dev, "failed to read tzen\n");
 		return err;
 	}
drivers/remoteproc/stm32_rproc.c +1 -1
 	ddata->secured_soc = tzen & tz.mask;
@@ -605,7 +604,7 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev)
 	if (err)
 		dev_warn(dev, "failed to get pdds\n");
 
-	rproc->auto_boot = of_property_read_bool(np, "st,auto-boot");
+	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
 	return stm32_rproc_of_memory_translations(pdev, ddata);

}

drivers/remoteproc/stm32_rproc.c +14 -3
@@ -616,18 +615,29 @@ static int stm32_rproc_probe(struct
 platform_device *pdev)
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
 	struct rproc *rproc;
+	bool auto_boot = false;
 	int ret;
 
 	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
 	if (ret)
 		return ret;
 
-	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
-	if (!rproc)
+	ddata = kzalloc(sizeof(*ddata), GFP_KERNEL);
+	if (!ddata)
 		return -ENOMEM;
 
+	ret = stm32_rproc_parse_dt(pdev, ddata, &auto_boot);
+	if (ret)
+		goto free_ddata;
+
+	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
+	if (!rproc) {
+		ret = -ENOMEM;
+		goto free_ddata;
+	}
+
+	rproc->auto_boot = auto_boot;
 	rproc->has_iommu = false;
-	ddata = rproc->priv;
drivers/remoteproc/stm32_rproc.c +5 -5
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {
 		dev_err(dev, "cannot create workqueue\n");
@@ -635,20 +645,20 @@ static int stm32_rproc_probe(struct
 platform_device *pdev)
 		goto free_rproc;
 	}
 
-	platform_set_drvdata(pdev, rproc);
+	memcpy(rproc->priv, ddata, sizeof(*ddata));
 
-	ret = stm32_rproc_parse_dt(pdev);
-	if (ret)
-		goto free_wkq;
+	platform_set_drvdata(pdev, rproc);
 
 	ret = stm32_rproc_request_mbox(rproc);
 	if (ret)
-		goto free_rproc;
+		goto free_wkq;
 
 	ret = rproc_add(rproc);
 	if (ret)
 		goto free_mb;
 
+	kfree(ddata);
+
 	return 0;
 

free_mb:

drivers/remoteproc/stm32_rproc.c +2 -1
@@ -661,6 +671,8 @@ static int stm32_rproc_probe(struct platform_device
 *pdev)
 		device_init_wakeup(dev, false);
 	}
 	rproc_free(rproc);
+free_ddata:
+	kfree(ddata);
 	return ret;
 }
 
--

2.20.1

author maintainer
#7 lore raw

PATCH 4/11 remoteproc: stm32: Remove memory translation from DT parsing

In reply to Mathieu Poirier

Other than one has to be done after the other, there is no correlation between memory translation and DT parsing. As move function stm32_rproc_of_memory_translations() to stm32_rproc_probe() so that stm32_rproc_parse_dt() can be extended to look for synchronisation related binding in a clean way.

---
 drivers/remoteproc/stm32_rproc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/remoteproc/stm32_rproc.c +5 -1
index ca60c917e218..a3e278490bb4 100644
@@ -606,7 +606,7 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev,
 
 	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
-	return stm32_rproc_of_memory_translations(pdev, ddata);
+	return 0;
 }
 
 static int stm32_rproc_probe(struct platform_device *pdev)
@@ -630,6 +630,10 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_ddata;
 
+	ret = stm32_rproc_of_memory_translations(pdev, ddata);
+	if (ret)
+		goto free_ddata;
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
Signature · 1 line
2.20.1
Reviewed-by on v1 4/11
#8 lore raw

RE: [PATCH 04/11] remoteproc: stm32: Remove memory translation from DT parsing

Quoted 13 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 04/11] remoteproc: stm32: Remove memory translation from DT parsing

Quoted 7 lines

Other than one has to be done after the other, there is no correlation between memory translation and DT parsing. As move function stm32_rproc_of_memory_translations() to stm32_rproc_probe() so that stm32_rproc_parse_dt() can be extended to look for synchronisation related binding in a clean way.

Thanks Mathieu

Quoted 34 lines
---
 drivers/remoteproc/stm32_rproc.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/remoteproc/stm32_rproc.c +1 -1
index ca60c917e218..a3e278490bb4 100644
@@ -606,7 +606,7 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev,
 
 	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
-	return stm32_rproc_of_memory_translations(pdev, ddata);
+	return 0;
 }
 

static int stm32_rproc_probe(struct platform_device *pdev)

drivers/remoteproc/stm32_rproc.c +4 -0
@@ -630,6 +630,10 @@ static int stm32_rproc_probe(struct platform_device
 *pdev)
 	if (ret)
 		goto free_ddata;
 
+	ret = stm32_rproc_of_memory_translations(pdev, ddata);
+	if (ret)
+		goto free_ddata;
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
drivers/remoteproc/stm32_rproc.c +0 -1
 	if (!rproc) {
 		ret = -ENOMEM;
--

2.20.1

author maintainer
#9 lore raw

PATCH 5/11 remoteproc: stm32: Parse syscon that will manage M4 synchronisation

In reply to Mathieu Poirier

Get from the DT the syncon to probe the state of the remote processor and the location of the resource table.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/remoteproc/stm32_rproc.c +26 -0
index a3e278490bb4..7d5d4a7dbb04 100644
@@ -70,6 +70,8 @@ struct stm32_rproc {
 	struct reset_control *rst;
 	struct stm32_syscon hold_boot;
 	struct stm32_syscon pdds;
+	struct stm32_syscon m4_state;
+	struct stm32_syscon rsctbl;
 	int wdg_irq;
 	u32 nb_rmems;
 	struct stm32_rproc_mem *rmems;
@@ -606,6 +608,30 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev,
 
 	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
+	/*
+	 * See if we can check the M4 status, i.e if it was started
+	 * from the boot loader or not.
+	 */
+        err = stm32_rproc_get_syscon(np, "st,syscfg-m4-state",
+                                     &ddata->m4_state);
+        if (err) {
+		/* remember this */
+		ddata->m4_state.map = NULL;
+                /* no coprocessor state syscon (optional) */
+                dev_warn(dev, "m4 state not supported\n");
+
+		/* no need to go further */
+		return 0;
+        }
+
+	/* See if we can get the resource table */
+        err = stm32_rproc_get_syscon(np, "st,syscfg-rsc-tbl",
+                                     &ddata->rsctbl);
+	if (err) {
+		/* no rsc table syscon (optional) */
+		dev_warn(dev, "rsc tbl syscon not supported\n");
+	}
+
 	return 0;
 }
 
Signature · 1 line
2.20.1
Reviewed-by on v1 5/11
#10 lore raw

RE: [PATCH 05/11] remoteproc: stm32: Parse syscon that will manage M4 synchronisation

Quoted 16 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 05/11] remoteproc: stm32: Parse syscon that will manage M4 synchronisation

Get from the DT the syncon to probe the state of the remote processor and the location of the resource table.

Quoted 6 lines

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

Thanks Mathieu

Quoted 52 lines
---
 drivers/remoteproc/stm32_rproc.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)
drivers/remoteproc/stm32_rproc.c +26 -1
index a3e278490bb4..7d5d4a7dbb04 100644
@@ -70,6 +70,8 @@ struct stm32_rproc {
 	struct reset_control *rst;
 	struct stm32_syscon hold_boot;
 	struct stm32_syscon pdds;
+	struct stm32_syscon m4_state;
+	struct stm32_syscon rsctbl;
 	int wdg_irq;
 	u32 nb_rmems;
 	struct stm32_rproc_mem *rmems;
@@ -606,6 +608,30 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev,
 
 	*auto_boot = of_property_read_bool(np, "st,auto-boot");
 
+	/*
+	 * See if we can check the M4 status, i.e if it was started
+	 * from the boot loader or not.
+	 */
+        err = stm32_rproc_get_syscon(np, "st,syscfg-m4-state",
+                                     &ddata->m4_state);
+        if (err) {
+		/* remember this */
+		ddata->m4_state.map = NULL;
+                /* no coprocessor state syscon (optional) */
+                dev_warn(dev, "m4 state not supported\n");
+
+		/* no need to go further */
+		return 0;
+        }
+
+	/* See if we can get the resource table */
+        err = stm32_rproc_get_syscon(np, "st,syscfg-rsc-tbl",
+                                     &ddata->rsctbl);
+	if (err) {
+		/* no rsc table syscon (optional) */
+		dev_warn(dev, "rsc tbl syscon not supported\n");
+	}
+
 	return 0;
 }
 
--

2.20.1

author maintainer
#11 lore raw

PATCH 6/11 remoteproc: stm32: Get coprocessor state

In reply to Mathieu Poirier

Introduce the required mechanic to get the state of the M4 when the remoteproc core is initialising.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/remoteproc/stm32_rproc.c +29 -0
index 7d5d4a7dbb04..b8af15dd0510 100644
@@ -38,6 +38,15 @@
 #define STM32_MBX_VQ1_ID	1
 #define STM32_MBX_SHUTDOWN	"shutdown"
 
+#define RSC_TBL_SIZE		(1024)
+
+#define M4_STATE_OFF		0
+#define M4_STATE_INI		1
+#define M4_STATE_CRUN		2
+#define M4_STATE_CSTOP		3
+#define M4_STATE_STANDBY	4
+#define M4_STATE_CRASH		5
+
 struct stm32_syscon {
 	struct regmap *map;
 	u32 reg;
@@ -635,12 +644,23 @@ static int stm32_rproc_parse_dt(struct platform_device *pdev,
 	return 0;
 }
 
+static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata,
+				     unsigned int *state)
+{
+	/* See stm32_rproc_parse_dt() */
+	if (!ddata->m4_state.map)
+		return -EINVAL;
+
+	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state);
+}
+
 static int stm32_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
 	struct rproc *rproc;
+	unsigned int state;
 	bool auto_boot = false;
 	int ret;
 
@@ -660,6 +680,15 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_ddata;
 
+	ret = stm32_rproc_get_m4_status(ddata, &state);
+	if (ret) {
+		/*
+		 * We couldn't get the coprocessor's state, assume
+		 * it is not running.
+		 */
+		state = M4_STATE_OFF;
+	}
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
Signature · 1 line
2.20.1
Reviewed-by on v1 6/11
#12 lore raw

RE: [PATCH 06/11] remoteproc: stm32: Get coprocessor state

Hi Mathieu,

Quoted 31 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Mathieu Poirier
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 06/11] remoteproc: stm32: Get coprocessor state

Introduce the required mechanic to get the state of the M4 when the remoteproc core is initialising.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 29
+++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/remoteproc/stm32_rproc.c +0 -0
index 7d5d4a7dbb04..b8af15dd0510 100644

drivers/remoteproc/stm32_rproc.c line 44

Quoted 7 lines
drivers/remoteproc/stm32_rproc.c +4 -0
@@ -38,6 +38,15 @@
 #define STM32_MBX_VQ1_ID	1
 #define STM32_MBX_SHUTDOWN	"shutdown"
 
+#define RSC_TBL_SIZE		(1024)
+
+#define M4_STATE_OFF		0
+#define M4_STATE_INI		1

Typo M4_STATE_INI -> M4_STATE_INIT

Else ok for me

Regards,
Loic

Quoted 54 lines
drivers/remoteproc/stm32_rproc.c +16 -0
+#define M4_STATE_CRUN		2
+#define M4_STATE_CSTOP		3
+#define M4_STATE_STANDBY	4
+#define M4_STATE_CRASH		5
+
 struct stm32_syscon {
 	struct regmap *map;
 	u32 reg;
@@ -635,12 +644,23 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev,
 	return 0;
 }
 
+static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata,
+				     unsigned int *state)
+{
+	/* See stm32_rproc_parse_dt() */
+	if (!ddata->m4_state.map)
+		return -EINVAL;
+
+	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg,
 state);
+}
+
 static int stm32_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
 	struct rproc *rproc;
+	unsigned int state;
 	bool auto_boot = false;
drivers/remoteproc/stm32_rproc.c +9 -0
 	int ret;
@@ -660,6 +680,15 @@ static int stm32_rproc_probe(struct platform_device
 *pdev)
 	if (ret)
 		goto free_ddata;
 
+	ret = stm32_rproc_get_m4_status(ddata, &state);
+	if (ret) {
+		/*
+		 * We couldn't get the coprocessor's state, assume
+		 * it is not running.
+		 */
+		state = M4_STATE_OFF;
+	}
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
drivers/remoteproc/stm32_rproc.c +0 -1
 	if (!rproc) {
 		ret = -ENOMEM;
--

2.20.1

author maintainer
#13 lore raw

Re: [PATCH 06/11] remoteproc: stm32: Get coprocessor state

Quoted 36 lines · Loic PALLARDY

Hi Mathieu,

Quoted 34 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Mathieu Poirier
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 06/11] remoteproc: stm32: Get coprocessor state

Introduce the required mechanic to get the state of the M4 when the remoteproc core is initialising.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 29
+++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)
drivers/remoteproc/stm32_rproc.c +0 -0
index 7d5d4a7dbb04..b8af15dd0510 100644
@@ -38,6 +38,15 @@
 #define STM32_MBX_VQ1_ID	1
 #define STM32_MBX_SHUTDOWN	"shutdown"
 
Quoted 5 lines

drivers/remoteproc/stm32_rproc.c line 44

Quoted 4 lines
drivers/remoteproc/stm32_rproc.c +4 -0
+#define RSC_TBL_SIZE		(1024)
+
+#define M4_STATE_OFF		0
+#define M4_STATE_INI		1

Typo M4_STATE_INI -> M4_STATE_INIT

Good catch

Quoted 62 lines

Else ok for me

Regards,
Loic

Quoted 54 lines
drivers/remoteproc/stm32_rproc.c +16 -0
+#define M4_STATE_CRUN		2
+#define M4_STATE_CSTOP		3
+#define M4_STATE_STANDBY	4
+#define M4_STATE_CRASH		5
+
 struct stm32_syscon {
 	struct regmap *map;
 	u32 reg;
@@ -635,12 +644,23 @@ static int stm32_rproc_parse_dt(struct
 platform_device *pdev,
 	return 0;
 }
 
+static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata,
+				     unsigned int *state)
+{
+	/* See stm32_rproc_parse_dt() */
+	if (!ddata->m4_state.map)
+		return -EINVAL;
+
+	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg,
 state);
+}
+
 static int stm32_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
 	struct stm32_rproc *ddata;
 	struct device_node *np = dev->of_node;
 	struct rproc *rproc;
+	unsigned int state;
 	bool auto_boot = false;
drivers/remoteproc/stm32_rproc.c +9 -0
 	int ret;
@@ -660,6 +680,15 @@ static int stm32_rproc_probe(struct platform_device
 *pdev)
 	if (ret)
 		goto free_ddata;
 
+	ret = stm32_rproc_get_m4_status(ddata, &state);
+	if (ret) {
+		/*
+		 * We couldn't get the coprocessor's state, assume
+		 * it is not running.
+		 */
+		state = M4_STATE_OFF;
+	}
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
drivers/remoteproc/stm32_rproc.c +0 -1
 	if (!rproc) {
 		ret = -ENOMEM;
--

2.20.1

author maintainer
#14 lore raw

PATCH 7/11 remoteproc: stm32: Get loaded resource table for synchronisation

In reply to Mathieu Poirier

Get the resource table location when synchronising with the M4 so that the remoteproc and rpmsg subsystem can be initialised properly.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 66 ++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/remoteproc/stm32_rproc.c +66 -0
index b8af15dd0510..5bac0baf8f4c 100644
@@ -87,6 +87,7 @@ struct stm32_rproc {
 	struct stm32_mbox mb[MBOX_NB_MBX];
 	struct workqueue_struct *workqueue;
 	bool secured_soc;
+	void __iomem *rsc_va;
 };
 
 static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64 *da)
@@ -654,6 +655,65 @@ static int stm32_rproc_get_m4_status(struct stm32_rproc *ddata,
 	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state);
 }
 
+static int stm32_rproc_da_to_pa(struct platform_device *pdev,
+				struct stm32_rproc *ddata,
+				u64 da, phys_addr_t *pa)
+{
+	struct device *dev = &pdev->dev;
+	struct stm32_rproc_mem *p_mem;
+	unsigned int i;
+
+	for (i = 0; i < ddata->nb_rmems; i++) {
+		p_mem = &ddata->rmems[i];
+
+		if (da < p_mem->dev_addr ||
+		    da >= p_mem->dev_addr + p_mem->size)
+			continue;
+
+		*pa = da - p_mem->dev_addr + p_mem->bus_addr;
+		dev_dbg(dev, "da %llx to pa %#x\n", da, *pa);
+
+		return 0;
+	}
+
+	dev_err(dev, "can't translate da %llx\n", da);
+
+	return -EINVAL;
+}
+
+static int stm32_rproc_get_loaded_rsc_table(struct platform_device *pdev,
+					    struct stm32_rproc *ddata)
+{
+	struct device *dev = &pdev->dev;
+	phys_addr_t rsc_pa;
+	u32 rsc_da;
+	int err;
+
+	err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da);
+	if (err) {
+		dev_err(dev, "failed to read rsc tbl addr\n");
+		return err;
+	}
+
+	if (!rsc_da)
+		/* no rsc table */
+		return 0;
+
+	err = stm32_rproc_da_to_pa(pdev, ddata, rsc_da, &rsc_pa);
+	if (err)
+		return err;
+
+	ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE);
+	if (IS_ERR_OR_NULL(ddata->rsc_va)) {
+		dev_err(dev, "Unable to map memory region: %pa+%zx\n",
+			&rsc_pa, RSC_TBL_SIZE);
+		ddata->rsc_va = NULL;
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+
 static int stm32_rproc_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -689,6 +749,12 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 		state = M4_STATE_OFF;
 	}
 
+	if (state == M4_STATE_CRUN) {
+		ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata);
+		if (ret)
+			goto free_ddata;
+	}
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
Signature · 1 line
2.20.1
Reviewed-by on v1 7/11
#15 lore raw

RE: [PATCH 07/11] remoteproc: stm32: Get loaded resource table for synchronisation

Quoted 16 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 07/11] remoteproc: stm32: Get loaded resource table for synchronisation

Get the resource table location when synchronising with the M4 so that the remoteproc and rpmsg subsystem can be initialised properly.

Quoted 6 lines

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

Thanks Mathieu

Quoted 105 lines
---
 drivers/remoteproc/stm32_rproc.c | 66
++++++++++++++++++++++++++++++++
 1 file changed, 66 insertions(+)
drivers/remoteproc/stm32_rproc.c +1 -0
index b8af15dd0510..5bac0baf8f4c 100644
@@ -87,6 +87,7 @@ struct stm32_rproc {
 	struct stm32_mbox mb[MBOX_NB_MBX];
 	struct workqueue_struct *workqueue;
 	bool secured_soc;
+	void __iomem *rsc_va;
 };
 
 static int stm32_rproc_pa_to_da(struct rproc *rproc, phys_addr_t pa, u64

*da)

drivers/remoteproc/stm32_rproc.c +59 -0
@@ -654,6 +655,65 @@ static int stm32_rproc_get_m4_status(struct
 stm32_rproc *ddata,
 	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg,
 state);
 }
 
+static int stm32_rproc_da_to_pa(struct platform_device *pdev,
+				struct stm32_rproc *ddata,
+				u64 da, phys_addr_t *pa)
+{
+	struct device *dev = &pdev->dev;
+	struct stm32_rproc_mem *p_mem;
+	unsigned int i;
+
+	for (i = 0; i < ddata->nb_rmems; i++) {
+		p_mem = &ddata->rmems[i];
+
+		if (da < p_mem->dev_addr ||
+		    da >= p_mem->dev_addr + p_mem->size)
+			continue;
+
+		*pa = da - p_mem->dev_addr + p_mem->bus_addr;
+		dev_dbg(dev, "da %llx to pa %#x\n", da, *pa);
+
+		return 0;
+	}
+
+	dev_err(dev, "can't translate da %llx\n", da);
+
+	return -EINVAL;
+}
+
+static int stm32_rproc_get_loaded_rsc_table(struct platform_device
 *pdev,
+					    struct stm32_rproc *ddata)
+{
+	struct device *dev = &pdev->dev;
+	phys_addr_t rsc_pa;
+	u32 rsc_da;
+	int err;
+
+	err = regmap_read(ddata->rsctbl.map, ddata->rsctbl.reg, &rsc_da);
+	if (err) {
+		dev_err(dev, "failed to read rsc tbl addr\n");
+		return err;
+	}
+
+	if (!rsc_da)
+		/* no rsc table */
+		return 0;
+
+	err = stm32_rproc_da_to_pa(pdev, ddata, rsc_da, &rsc_pa);
+	if (err)
+		return err;
+
+	ddata->rsc_va = devm_ioremap_wc(dev, rsc_pa, RSC_TBL_SIZE);
+	if (IS_ERR_OR_NULL(ddata->rsc_va)) {
+		dev_err(dev, "Unable to map memory region: %pa+%zx\n",
+			&rsc_pa, RSC_TBL_SIZE);
+		ddata->rsc_va = NULL;
+		return -ENOMEM;
+	}
+
+	return 0;
+}
+

static int stm32_rproc_probe(struct platform_device *pdev) {

drivers/remoteproc/stm32_rproc.c +6 -0
 	struct device *dev = &pdev->dev;
@@ -689,6 +749,12 @@ static int stm32_rproc_probe(struct platform_device
 *pdev)
 		state = M4_STATE_OFF;
 	}
 
+	if (state == M4_STATE_CRUN) {
+		ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata);
+		if (ret)
+			goto free_ddata;
+	}
+
 	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
drivers/remoteproc/stm32_rproc.c +0 -1
 	if (!rproc) {
 		ret = -ENOMEM;
--

2.20.1

author maintainer
#16 lore raw

PATCH 8/11 remoteproc: stm32: Introduce new start and stop ops for synchronisation

In reply to Mathieu Poirier

Introduce new start and stop rproc_ops functions to be used when synchonising with an MCU.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 37 ++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/remoteproc/stm32_rproc.c +37 -0
index 5bac0baf8f4c..734605a9223e 100644
@@ -449,6 +449,13 @@ static int stm32_rproc_start(struct rproc *rproc)
 	return stm32_rproc_set_hold_boot(rproc, true);
 }
 
+static int stm32_rproc_sync_start(struct rproc *rproc)
+{
+	stm32_rproc_add_coredump_trace(rproc);
+
+	return stm32_rproc_set_hold_boot(rproc, true);
+}
+
 static int stm32_rproc_stop(struct rproc *rproc)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -489,6 +496,30 @@ static int stm32_rproc_stop(struct rproc *rproc)
 	return 0;
 }
 
+static int stm32_rproc_sync_stop(struct rproc *rproc)
+{
+	struct stm32_rproc *ddata = rproc->priv;
+	int err;
+
+	err = stm32_rproc_stop(rproc);
+	if (err)
+		return err;
+
+	/* update copro state to OFF */
+	if (ddata->m4_state.map) {
+		err = regmap_update_bits(ddata->m4_state.map,
+					 ddata->m4_state.reg,
+					 ddata->m4_state.mask,
+					 M4_STATE_OFF);
+		if (err) {
+			dev_err(&rproc->dev, "failed to set copro state\n");
+			return err;
+		}
+	}
+
+	return 0;
+}
+
 static void stm32_rproc_kick(struct rproc *rproc, int vqid)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -522,6 +553,12 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
+static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+	.start		= stm32_rproc_sync_start,
+	.stop		= stm32_rproc_sync_stop,
+	.kick		= stm32_rproc_kick,
+};
+
 static const struct of_device_id stm32_rproc_match[] = {
 	{ .compatible = "st,stm32mp1-m4" },
 	{},
Signature · 1 line
2.20.1
#17 lore raw

RE: [PATCH 08/11] remoteproc: stm32: Introduce new start and stop ops for synchronisation

Hi Mathieu,

Quoted 58 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 08/11] remoteproc: stm32: Introduce new start and stop ops for synchronisation

Introduce new start and stop rproc_ops functions to be used when synchonising with an MCU.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 37
++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/remoteproc/stm32_rproc.c +17 -0
index 5bac0baf8f4c..734605a9223e 100644
@@ -449,6 +449,13 @@ static int stm32_rproc_start(struct rproc *rproc)
 	return stm32_rproc_set_hold_boot(rproc, true);
 }
 
+static int stm32_rproc_sync_start(struct rproc *rproc)
+{
+	stm32_rproc_add_coredump_trace(rproc);
+
+	return stm32_rproc_set_hold_boot(rproc, true);
+}
+
 static int stm32_rproc_stop(struct rproc *rproc)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -489,6 +496,30 @@ static int stm32_rproc_stop(struct rproc *rproc)
 	return 0;
 }
 
+static int stm32_rproc_sync_stop(struct rproc *rproc)
+{
+	struct stm32_rproc *ddata = rproc->priv;
+	int err;
+
+	err = stm32_rproc_stop(rproc);
+	if (err)
+		return err;
+
+	/* update copro state to OFF */

drivers/remoteproc/stm32_rproc.c static int stm32_rproc_stop(struct rproc *rproc) · line 518

Quoted 10 lines
drivers/remoteproc/stm32_rproc.c +10 -0
+	if (ddata->m4_state.map) {
+		err = regmap_update_bits(ddata->m4_state.map,
+					 ddata->m4_state.reg,
+					 ddata->m4_state.mask,
+					 M4_STATE_OFF);
+		if (err) {
+			dev_err(&rproc->dev, "failed to set copro state\n");
+			return err;
+		}
+	}

In fact m4_state is updated in following way:
- it is set by Linux when M4 is guarantee, that means only when Linux is stopping the M4. in that case M4 is under reset and m4_state could be updated to M4_STATE_OFF
- for all other states, it is M4 responsibility to update m4_state when running That means the code above is common to both stm32_rproc_stop() and stm32_rproc_sync_stop(). Only one function is required.

Regards,
Loic

Quoted 22 lines
drivers/remoteproc/stm32_rproc.c +10 -1
+
+	return 0;
+}
+
 static void stm32_rproc_kick(struct rproc *rproc, int vqid)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -522,6 +553,12 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
+static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+	.start		= stm32_rproc_sync_start,
+	.stop		= stm32_rproc_sync_stop,
+	.kick		= stm32_rproc_kick,
+};
+
 static const struct of_device_id stm32_rproc_match[] = {
 	{ .compatible = "st,stm32mp1-m4" },
 	{},
--

2.20.1

author maintainer
#18 lore raw

Re: [PATCH 08/11] remoteproc: stm32: Introduce new start and stop ops for synchronisation

Quoted 68 lines · Loic PALLARDY

Hi Mathieu,

Quoted 66 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 08/11] remoteproc: stm32: Introduce new start and stop ops for synchronisation

Introduce new start and stop rproc_ops functions to be used when synchonising with an MCU.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 37
++++++++++++++++++++++++++++++++
 1 file changed, 37 insertions(+)
drivers/remoteproc/stm32_rproc.c +25 -0
index 5bac0baf8f4c..734605a9223e 100644
@@ -449,6 +449,13 @@ static int stm32_rproc_start(struct rproc *rproc)
 	return stm32_rproc_set_hold_boot(rproc, true);
 }
 
+static int stm32_rproc_sync_start(struct rproc *rproc)
+{
+	stm32_rproc_add_coredump_trace(rproc);
+
+	return stm32_rproc_set_hold_boot(rproc, true);
+}
+
 static int stm32_rproc_stop(struct rproc *rproc)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -489,6 +496,30 @@ static int stm32_rproc_stop(struct rproc *rproc)
 	return 0;
 }
 
+static int stm32_rproc_sync_stop(struct rproc *rproc)
+{
+	struct stm32_rproc *ddata = rproc->priv;
+	int err;
+
+	err = stm32_rproc_stop(rproc);
+	if (err)
+		return err;
+
+	/* update copro state to OFF */
+	if (ddata->m4_state.map) {
+		err = regmap_update_bits(ddata->m4_state.map,
+					 ddata->m4_state.reg,
+					 ddata->m4_state.mask,
+					 M4_STATE_OFF);
+		if (err) {
+			dev_err(&rproc->dev, "failed to set copro state\n");
+			return err;
Quoted 8 lines

drivers/remoteproc/stm32_rproc.c static int stm32_rproc_stop(struct rproc *rproc) · line 518

Quoted 2 lines
drivers/remoteproc/stm32_rproc.c +2 -0
+		}
+	}

In fact m4_state is updated in following way:
- it is set by Linux when M4 is guarantee, that means only when Linux is stopping the M4. in that case M4 is under reset and m4_state could be updated to M4_STATE_OFF
- for all other states, it is M4 responsibility to update m4_state when running That means the code above is common to both stm32_rproc_stop() and stm32_rproc_sync_stop(). Only one function is required.

Very well, I'll get it fixed.

Quoted 26 lines

Regards,
Loic

Quoted 22 lines
drivers/remoteproc/stm32_rproc.c +10 -1
+
+	return 0;
+}
+
 static void stm32_rproc_kick(struct rproc *rproc, int vqid)
 {
 	struct stm32_rproc *ddata = rproc->priv;
@@ -522,6 +553,12 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
+static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+	.start		= stm32_rproc_sync_start,
+	.stop		= stm32_rproc_sync_stop,
+	.kick		= stm32_rproc_kick,
+};
+
 static const struct of_device_id stm32_rproc_match[] = {
 	{ .compatible = "st,stm32mp1-m4" },
 	{},
--

2.20.1

author maintainer
#19 lore raw

PATCH 9/11 remoteproc: stm32: Introduce new parse fw ops for synchronisation

In reply to Mathieu Poirier

Introduce new parse firmware rproc_ops functions to be used when synchonising with an MCU.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 49 +++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/remoteproc/stm32_rproc.c +48 -1
index 734605a9223e..4268d71f191d 100644
@@ -215,7 +215,34 @@ static int stm32_rproc_elf_load_rsc_table(struct rproc *rproc,
 	return 0;
 }
 
-static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+static int stm32_rproc_sync_elf_load_rsc_table(struct rproc *rproc,
+					       const struct firmware *fw)
+{
+	struct resource_table *table = NULL;
+	struct stm32_rproc *ddata = rproc->priv;
+
+	if (ddata->rsc_va) {
+		table = (struct resource_table *)ddata->rsc_va;
+		/* Assuming that the resource table fits in 1kB is fair */
+		rproc->cached_table = kmemdup(table, RSC_TBL_SIZE, GFP_KERNEL);
+		if (!rproc->cached_table)
+			return -ENOMEM;
+
+		rproc->table_ptr = rproc->cached_table;
+		rproc->table_sz = RSC_TBL_SIZE;
+		return 0;
+	}
+
+	rproc->cached_table = NULL;
+	rproc->table_ptr = NULL;
+	rproc->table_sz = 0;
+
+	dev_warn(&rproc->dev, "no resource table found for this firmware\n");
+	return 0;
+}
+
+static int stm32_rproc_parse_memory_regions(struct rproc *rproc,
+					    const struct firmware *fw)
 {
 	struct device *dev = rproc->dev.parent;
 	struct device_node *np = dev->of_node;
@@ -268,9 +295,28 @@ static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
 		index++;
 	}
 
+	return 0;
+}
+
+static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware *fw)
+{
+	int ret = stm32_rproc_parse_memory_regions(rproc, fw);
+	if (ret)
+		return ret;
+
 	return stm32_rproc_elf_load_rsc_table(rproc, fw);
 }
 
+static int stm32_rproc_sync_parse_fw(struct rproc *rproc,
+				     const struct firmware *fw)
+{
+	int ret = stm32_rproc_parse_memory_regions(rproc, fw);
+	if (ret)
+		return ret;
+
+	return stm32_rproc_sync_elf_load_rsc_table(rproc, fw);
+}
+
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
 {
 	struct platform_device *pdev = data;
@@ -557,6 +603,7 @@ static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
 	.start		= stm32_rproc_sync_start,
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
+	.parse_fw	= stm32_rproc_sync_parse_fw,
 };
 
 static const struct of_device_id stm32_rproc_match[] = {
Signature · 1 line
2.20.1
Reviewed-by on v1 9/11
#20 lore raw

RE: [PATCH 09/11] remoteproc: stm32: Introduce new parse fw ops for synchronisation

Quoted 16 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 09/11] remoteproc: stm32: Introduce new parse fw ops for synchronisation

Introduce new parse firmware rproc_ops functions to be used when synchonising with an MCU.

Quoted 6 lines

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

Thanks Mathieu

Quoted 92 lines
---
 drivers/remoteproc/stm32_rproc.c | 49
+++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/remoteproc/stm32_rproc.c +23 -1
index 734605a9223e..4268d71f191d 100644
@@ -215,7 +215,34 @@ static int stm32_rproc_elf_load_rsc_table(struct
 rproc *rproc,
 	return 0;
 }
 
-static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware
 *fw)
+static int stm32_rproc_sync_elf_load_rsc_table(struct rproc *rproc,
+					       const struct firmware *fw)
+{
+	struct resource_table *table = NULL;
+	struct stm32_rproc *ddata = rproc->priv;
+
+	if (ddata->rsc_va) {
+		table = (struct resource_table *)ddata->rsc_va;
+		/* Assuming that the resource table fits in 1kB is fair */
+		rproc->cached_table = kmemdup(table, RSC_TBL_SIZE,
 GFP_KERNEL);
+		if (!rproc->cached_table)
+			return -ENOMEM;
+
+		rproc->table_ptr = rproc->cached_table;
+		rproc->table_sz = RSC_TBL_SIZE;
+		return 0;
+	}
+
+	rproc->cached_table = NULL;
+	rproc->table_ptr = NULL;
+	rproc->table_sz = 0;
+
+	dev_warn(&rproc->dev, "no resource table found for this

firmware\n");

drivers/remoteproc/stm32_rproc.c +24 -0
+	return 0;
+}
+
+static int stm32_rproc_parse_memory_regions(struct rproc *rproc,
+					    const struct firmware *fw)
 {
 	struct device *dev = rproc->dev.parent;
 	struct device_node *np = dev->of_node;
@@ -268,9 +295,28 @@ static int stm32_rproc_parse_fw(struct rproc *rproc,
 const struct firmware *fw)
 		index++;
 	}
 
+	return 0;
+}
+
+static int stm32_rproc_parse_fw(struct rproc *rproc, const struct firmware
 *fw)
+{
+	int ret = stm32_rproc_parse_memory_regions(rproc, fw);
+	if (ret)
+		return ret;
+
 	return stm32_rproc_elf_load_rsc_table(rproc, fw);
 }
 
+static int stm32_rproc_sync_parse_fw(struct rproc *rproc,
+				     const struct firmware *fw)
+{
+	int ret = stm32_rproc_parse_memory_regions(rproc, fw);
+	if (ret)
+		return ret;
+
+	return stm32_rproc_sync_elf_load_rsc_table(rproc, fw);
+}
+
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)

{

drivers/remoteproc/stm32_rproc.c +1 -0
 	struct platform_device *pdev = data;
@@ -557,6 +603,7 @@ static __maybe_unused struct rproc_ops
 st_rproc_sync_ops = {
 	.start		= stm32_rproc_sync_start,
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
+	.parse_fw	= stm32_rproc_sync_parse_fw,
 };
 

static const struct of_device_id stm32_rproc_match[] = {
--
2.20.1

author maintainer
#21 lore raw

PATCH 10/11 remoteproc: stm32: Introduce new loaded rsc ops for synchronisation

In reply to Mathieu Poirier

Introduce new elf find loaded resource table rproc_ops functions to be used when synchonising with an MCU.

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877

---
 drivers/remoteproc/stm32_rproc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/remoteproc/stm32_rproc.c +10 -0
index 4268d71f191d..07be306c0fb1 100644
@@ -317,6 +317,15 @@ static int stm32_rproc_sync_parse_fw(struct rproc *rproc,
 	return stm32_rproc_sync_elf_load_rsc_table(rproc, fw);
 }
 
+static struct resource_table *
+stm32_rproc_sync_elf_find_loaded_rsc_table(struct rproc *rproc,
+					   const struct firmware *fw)
+{
+	struct stm32_rproc *ddata = rproc->priv;
+
+	return (struct resource_table *)ddata->rsc_va;
+}
+
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
 {
 	struct platform_device *pdev = data;
@@ -604,6 +613,7 @@ static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
 	.parse_fw	= stm32_rproc_sync_parse_fw,
+	.find_loaded_rsc_table = stm32_rproc_sync_elf_find_loaded_rsc_table,
 };
 
 static const struct of_device_id stm32_rproc_match[] = {
Signature · 1 line
2.20.1
Reviewed-by on v1 10/11
#22 lore raw

RE: [PATCH 10/11] remoteproc: stm32: Introduce new loaded rsc ops for synchronisation

Quoted 16 lines

-----Original Message-----
From: Mathieu Poirier <[email protected]>
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 10/11] remoteproc: stm32: Introduce new loaded rsc ops for synchronisation

Introduce new elf find loaded resource table rproc_ops functions to be used when synchonising with an MCU.

Quoted 6 lines

Mainly based on the work published by Arnaud Pouliquen [1].

[1]. https://patchwork.kernel.org/project/linux-
remoteproc/list/?series=239877

Thanks Mathieu

Quoted 38 lines
---
 drivers/remoteproc/stm32_rproc.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/remoteproc/stm32_rproc.c +9 -0
index 4268d71f191d..07be306c0fb1 100644
@@ -317,6 +317,15 @@ static int stm32_rproc_sync_parse_fw(struct rproc
 *rproc,
 	return stm32_rproc_sync_elf_load_rsc_table(rproc, fw);
 }
 
+static struct resource_table *
+stm32_rproc_sync_elf_find_loaded_rsc_table(struct rproc *rproc,
+					   const struct firmware *fw)
+{
+	struct stm32_rproc *ddata = rproc->priv;
+
+	return (struct resource_table *)ddata->rsc_va;
+}
+
 static irqreturn_t stm32_rproc_wdg(int irq, void *data)
 {
drivers/remoteproc/stm32_rproc.c +1 -0
 	struct platform_device *pdev = data;
@@ -604,6 +613,7 @@ static __maybe_unused struct rproc_ops
 st_rproc_sync_ops = {
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
 	.parse_fw	= stm32_rproc_sync_parse_fw,
+	.find_loaded_rsc_table =
 stm32_rproc_sync_elf_find_loaded_rsc_table,
 };

static const struct of_device_id stm32_rproc_match[] = {
--
2.20.1

author maintainer
#23 lore raw

PATCH 11/11 remoteproc: stm32: Allocate rproc for synchronisation with MCU

In reply to Mathieu Poirier

Allocate remote processor structure with state machine if the MCU has already been started by an external entity.

---
 drivers/remoteproc/stm32_rproc.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/remoteproc/stm32_rproc.c +16 -3
index 07be306c0fb1..f320ef9ee286 100644
@@ -608,7 +608,7 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
-static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+static struct rproc_ops st_rproc_sync_ops = {
 	.start		= stm32_rproc_sync_start,
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
@@ -616,6 +616,12 @@ static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
 	.find_loaded_rsc_table = stm32_rproc_sync_elf_find_loaded_rsc_table,
 };
 
+static struct rproc_sync_states st_sync_states = {
+	.on_init = true, /* sync with MCU when the kernel boots */
+	.after_stop = false, /* don't resync with MCU if stopped from sysfs */
+	.after_crash = false, /* don't resync with MCU after a crash */
+};
+
 static const struct of_device_id stm32_rproc_match[] = {
 	{ .compatible = "st,stm32mp1-m4" },
 	{},
@@ -847,15 +853,22 @@ static int stm32_rproc_probe(struct platform_device *pdev)
 		ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata);
 		if (ret)
 			goto free_ddata;
+
+		rproc = rproc_alloc_state_machine(dev, np->name, &st_rproc_ops,
+						  &st_rproc_sync_ops,
+						  &st_sync_states, NULL,
+						  sizeof(*ddata));
+	} else {
+		rproc = rproc_alloc(dev, np->name, &st_rproc_ops,
+				    NULL, sizeof(*ddata));
+		rproc->auto_boot = auto_boot;
 	}
 
-	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
 		goto free_ddata;
 	}
 
-	rproc->auto_boot = auto_boot;
 	rproc->has_iommu = false;
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {
Signature · 1 line
2.20.1
#24 lore raw

RE: [PATCH 11/11] remoteproc: stm32: Allocate rproc for synchronisation with MCU

Hi Mathieu,

Quoted 51 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Mathieu Poirier
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 11/11] remoteproc: stm32: Allocate rproc for synchronisation with MCU

Allocate remote processor structure with state machine if the MCU has already been started by an external entity.

---
 drivers/remoteproc/stm32_rproc.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/remoteproc/stm32_rproc.c +7 -1
index 07be306c0fb1..f320ef9ee286 100644
@@ -608,7 +608,7 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
-static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+static struct rproc_ops st_rproc_sync_ops = {
 	.start		= stm32_rproc_sync_start,
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
@@ -616,6 +616,12 @@ static __maybe_unused struct rproc_ops
 st_rproc_sync_ops = {
 	.find_loaded_rsc_table =
 stm32_rproc_sync_elf_find_loaded_rsc_table,
 };
 
+static struct rproc_sync_states st_sync_states = {
+	.on_init = true, /* sync with MCU when the kernel boots */
+	.after_stop = false, /* don't resync with MCU if stopped from sysfs
 */
+	.after_crash = false, /* don't resync with MCU after a crash */
+};
+

static const struct of_device_id stm32_rproc_match[] = {

drivers/remoteproc/stm32_rproc.c +0 -0
 	{ .compatible = "st,stm32mp1-m4" },
 	{},

drivers/remoteproc/stm32_rproc.c static int stm32_rproc_probe(struct · line 862

Quoted 10 lines
drivers/remoteproc/stm32_rproc.c +5 -0
@@ -847,15 +853,22 @@ static int stm32_rproc_probe(struct
 platform_device *pdev)
 		ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata);
 		if (ret)
 			goto free_ddata;
+
+		rproc = rproc_alloc_state_machine(dev, np->name,
 &st_rproc_ops,
+						  &st_rproc_sync_ops,
+						  &st_sync_states, NULL,
+						  sizeof(*ddata));

Could we have only one call to rproc_alloc_state_machine(), simply configuring st_sync_states according to m4_state and other DT properties?

Regards,
Loic

Quoted 19 lines
drivers/remoteproc/stm32_rproc.c +4 -2
+	} else {
+		rproc = rproc_alloc(dev, np->name, &st_rproc_ops,
+				    NULL, sizeof(*ddata));
+		rproc->auto_boot = auto_boot;
 	}
 
-	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
 		goto free_ddata;
 	}
 
-	rproc->auto_boot = auto_boot;
drivers/remoteproc/stm32_rproc.c +0 -1
 	rproc->has_iommu = false;
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {
--

2.20.1

author maintainer
#25 lore raw

Re: [PATCH 11/11] remoteproc: stm32: Allocate rproc for synchronisation with MCU

Quoted 57 lines · Loic PALLARDY

Hi Mathieu,

Quoted 55 lines

-----Original Message-----
From: [email protected] <linux-remoteproc- [email protected]> On Behalf Of Mathieu Poirier
Sent: mardi 24 mars 2020 23:03
To: [email protected]
Cc: [email protected]; Loic PALLARDY <[email protected]>; s- [email protected]; [email protected]; Arnaud POULIQUEN <[email protected]>; Fabien DESSENNE <[email protected]>; [email protected]
Subject: [PATCH 11/11] remoteproc: stm32: Allocate rproc for synchronisation with MCU

Allocate remote processor structure with state machine if the MCU has already been started by an external entity.

---
 drivers/remoteproc/stm32_rproc.c | 19 ++++++++++++++++---
 1 file changed, 16 insertions(+), 3 deletions(-)
drivers/remoteproc/stm32_rproc.c +7 -1
index 07be306c0fb1..f320ef9ee286 100644
@@ -608,7 +608,7 @@ static struct rproc_ops st_rproc_ops = {
 	.get_boot_addr	= rproc_elf_get_boot_addr,
 };
 
-static __maybe_unused struct rproc_ops st_rproc_sync_ops = {
+static struct rproc_ops st_rproc_sync_ops = {
 	.start		= stm32_rproc_sync_start,
 	.stop		= stm32_rproc_sync_stop,
 	.kick		= stm32_rproc_kick,
@@ -616,6 +616,12 @@ static __maybe_unused struct rproc_ops
 st_rproc_sync_ops = {
 	.find_loaded_rsc_table =
 stm32_rproc_sync_elf_find_loaded_rsc_table,
 };
 
+static struct rproc_sync_states st_sync_states = {
+	.on_init = true, /* sync with MCU when the kernel boots */
+	.after_stop = false, /* don't resync with MCU if stopped from sysfs
 */
+	.after_crash = false, /* don't resync with MCU after a crash */
+};
+

static const struct of_device_id stm32_rproc_match[] = {

drivers/remoteproc/stm32_rproc.c +0 -0
 	{ .compatible = "st,stm32mp1-m4" },
 	{},
@@ -847,15 +853,22 @@ static int stm32_rproc_probe(struct
 platform_device *pdev)
 		ret = stm32_rproc_get_loaded_rsc_table(pdev, ddata);
 		if (ret)
 			goto free_ddata;
Quoted 8 lines

drivers/remoteproc/stm32_rproc.c static int stm32_rproc_probe(struct platform_device *pdev) · line 860

Quoted 6 lines
drivers/remoteproc/stm32_rproc.c +5 -0
+
+		rproc = rproc_alloc_state_machine(dev, np->name,
 &st_rproc_ops,
+						  &st_rproc_sync_ops,
+						  &st_sync_states, NULL,
+						  sizeof(*ddata));

Could we have only one call to rproc_alloc_state_machine(), simply configuring st_sync_states according to m4_state and other DT properties?

Yes, very much so - I'll do that for V2.

Mathieu

Quoted 23 lines

Regards,
Loic

Quoted 19 lines
drivers/remoteproc/stm32_rproc.c +4 -2
+	} else {
+		rproc = rproc_alloc(dev, np->name, &st_rproc_ops,
+				    NULL, sizeof(*ddata));
+		rproc->auto_boot = auto_boot;
 	}
 
-	rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL,
 sizeof(*ddata));
 	if (!rproc) {
 		ret = -ENOMEM;
 		goto free_ddata;
 	}
 
-	rproc->auto_boot = auto_boot;
drivers/remoteproc/stm32_rproc.c +0 -1
 	rproc->has_iommu = false;
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {
--

2.20.1