[v5,06/11] remoteproc: stm32: Properly set co-processor state when attaching
diff mbox series

Message ID 20200707213112.928383-7-mathieu.poirier@linaro.org
State New
Headers show
Series
  • remoteproc: stm32: Add support for attaching to M4
Related show

Commit Message

Mathieu Poirier July 7, 2020, 9:31 p.m. UTC
Introduce the required mechanic to set the state of the M4 in order
to properly deal with scenarios where the co-processor has been
started by another entity.

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

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

Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
---
 drivers/remoteproc/stm32_rproc.c | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

Comments

Arnaud Pouliquen July 9, 2020, 4:13 p.m. UTC | #1
Hi Mathieu,

On 7/7/20 11:31 PM, Mathieu Poirier wrote:
> Introduce the required mechanic to set the state of the M4 in order
> to properly deal with scenarios where the co-processor has been
> started by another entity.
> 
> Mainly based on the work published by Arnaud Pouliquen [1].
> 
> [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=239877
> 
> Signed-off-by: Mathieu Poirier <mathieu.poirier@linaro.org>
> Reviewed-by: Bjorn Andersson <bjorn.andersson@linaro.org>
> ---
>  drivers/remoteproc/stm32_rproc.c | 32 ++++++++++++++++++++++++++++++++
>  1 file changed, 32 insertions(+)
> 
> diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
> index 961a53f67ec5..cbeb5ceb15c5 100644
> --- a/drivers/remoteproc/stm32_rproc.c
> +++ b/drivers/remoteproc/stm32_rproc.c
> @@ -39,6 +39,13 @@
>  #define STM32_MBX_VQ1_ID	1
>  #define STM32_MBX_SHUTDOWN	"shutdown"
>  
> +#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;
> @@ -636,12 +643,30 @@ 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) {
> +		/*
> +		 * We couldn't get the coprocessor's state, assume
> +		 * it is not running.
> +		 */
> +		state = M4_STATE_OFF;
> +		return 0;
> +	}
> +
> +	return regmap_read(ddata->m4_state.map, ddata->m4_state.reg, state);
> +}
> +
> +
nitpicking:  multiple blank lines here

>  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;
>  	int ret;
>  
>  	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
> @@ -664,6 +689,13 @@ static int stm32_rproc_probe(struct platform_device *pdev)
>  	if (ret)
>  		goto free_rproc;
>  
> +	ret = stm32_rproc_get_m4_status(ddata, &state);
> +	if (ret)
> +		goto free_rproc;
> +
> +	if (state == M4_STATE_CRUN)
> +		rproc->state = RPROC_DETACHED;
> +
>  	rproc->has_iommu = false;
>  	ddata->workqueue = create_workqueue(dev_name(dev));
>  	if (!ddata->workqueue) {
>
kernel test robot July 14, 2020, 8:30 p.m. UTC | #2
Hi Mathieu,

I love your patch! Yet something to improve:

[auto build test ERROR on linux/master]
[also build test ERROR on linus/master v5.8-rc5 next-20200714]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use  as documented in
https://git-scm.com/docs/git-format-patch]

url:    https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-stm32-Add-support-for-attaching-to-M4/20200708-053515
base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9ebcfadb0610322ac537dd7aa5d9cbc2b2894c68
config: arm-randconfig-r011-20200714 (attached as .config)
compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)
reproduce (this is a W=1 build):
        wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
        chmod +x ~/bin/make.cross
        # install arm cross compiling tool for clang build
        # apt-get install binutils-arm-linux-gnueabi
        # save the attached .config to linux build tree
        COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm 

If you fix the issue, kindly add following tag as appropriate
Reported-by: kernel test robot <lkp@intel.com>

All errors (new ones prefixed by >>):

>> drivers/remoteproc/stm32_rproc.c:697:18: error: use of undeclared identifier 'RPROC_DETACHED'
                   rproc->state = RPROC_DETACHED;
                                  ^
   1 error generated.

vim +/RPROC_DETACHED +697 drivers/remoteproc/stm32_rproc.c

   661	
   662	
   663	static int stm32_rproc_probe(struct platform_device *pdev)
   664	{
   665		struct device *dev = &pdev->dev;
   666		struct stm32_rproc *ddata;
   667		struct device_node *np = dev->of_node;
   668		struct rproc *rproc;
   669		unsigned int state;
   670		int ret;
   671	
   672		ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
   673		if (ret)
   674			return ret;
   675	
   676		rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
   677		if (!rproc)
   678			return -ENOMEM;
   679	
   680		ddata = rproc->priv;
   681	
   682		rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
   683	
   684		ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot);
   685		if (ret)
   686			goto free_rproc;
   687	
   688		ret = stm32_rproc_of_memory_translations(pdev, ddata);
   689		if (ret)
   690			goto free_rproc;
   691	
   692		ret = stm32_rproc_get_m4_status(ddata, &state);
   693		if (ret)
   694			goto free_rproc;
   695	
   696		if (state == M4_STATE_CRUN)
 > 697			rproc->state = RPROC_DETACHED;
   698	
   699		rproc->has_iommu = false;
   700		ddata->workqueue = create_workqueue(dev_name(dev));
   701		if (!ddata->workqueue) {
   702			dev_err(dev, "cannot create workqueue\n");
   703			ret = -ENOMEM;
   704			goto free_rproc;
   705		}
   706	
   707		platform_set_drvdata(pdev, rproc);
   708	
   709		ret = stm32_rproc_request_mbox(rproc);
   710		if (ret)
   711			goto free_wkq;
   712	
   713		ret = rproc_add(rproc);
   714		if (ret)
   715			goto free_mb;
   716	
   717		return 0;
   718	
   719	free_mb:
   720		stm32_rproc_free_mbox(rproc);
   721	free_wkq:
   722		destroy_workqueue(ddata->workqueue);
   723	free_rproc:
   724		if (device_may_wakeup(dev)) {
   725			dev_pm_clear_wake_irq(dev);
   726			device_init_wakeup(dev, false);
   727		}
   728		rproc_free(rproc);
   729		return ret;
   730	}
   731	

---
0-DAY CI Kernel Test Service, Intel Corporation
https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
Mathieu Poirier July 15, 2020, 10:19 p.m. UTC | #3
Hi Robot,

On Tue, 14 Jul 2020 at 14:31, kernel test robot <lkp@intel.com> wrote:
>
> Hi Mathieu,
>
> I love your patch! Yet something to improve:
>
> [auto build test ERROR on linux/master]
> [also build test ERROR on linus/master v5.8-rc5 next-20200714]
> [If your patch is applied to the wrong git tree, kindly drop us a note.
> And when submitting patch, we suggest to use  as documented in
> https://git-scm.com/docs/git-format-patch]
>
> url:    https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-stm32-Add-support-for-attaching-to-M4/20200708-053515
> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9ebcfadb0610322ac537dd7aa5d9cbc2b2894c68
> config: arm-randconfig-r011-20200714 (attached as .config)
> compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)
> reproduce (this is a W=1 build):
>         wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>         chmod +x ~/bin/make.cross
>         # install arm cross compiling tool for clang build
>         # apt-get install binutils-arm-linux-gnueabi
>         # save the attached .config to linux build tree
>         COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
>
> If you fix the issue, kindly add following tag as appropriate
> Reported-by: kernel test robot <lkp@intel.com>
>
> All errors (new ones prefixed by >>):
>
> >> drivers/remoteproc/stm32_rproc.c:697:18: error: use of undeclared identifier 'RPROC_DETACHED'
>                    rproc->state = RPROC_DETACHED;
>                                   ^
>    1 error generated.

This patchset depends on this one [1], something that is clearly
stated in the cover letter.  Compiling this set on top of [1]
generates no error.

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

>
> vim +/RPROC_DETACHED +697 drivers/remoteproc/stm32_rproc.c
>
>    661
>    662
>    663  static int stm32_rproc_probe(struct platform_device *pdev)
>    664  {
>    665          struct device *dev = &pdev->dev;
>    666          struct stm32_rproc *ddata;
>    667          struct device_node *np = dev->of_node;
>    668          struct rproc *rproc;
>    669          unsigned int state;
>    670          int ret;
>    671
>    672          ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
>    673          if (ret)
>    674                  return ret;
>    675
>    676          rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
>    677          if (!rproc)
>    678                  return -ENOMEM;
>    679
>    680          ddata = rproc->priv;
>    681
>    682          rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
>    683
>    684          ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot);
>    685          if (ret)
>    686                  goto free_rproc;
>    687
>    688          ret = stm32_rproc_of_memory_translations(pdev, ddata);
>    689          if (ret)
>    690                  goto free_rproc;
>    691
>    692          ret = stm32_rproc_get_m4_status(ddata, &state);
>    693          if (ret)
>    694                  goto free_rproc;
>    695
>    696          if (state == M4_STATE_CRUN)
>  > 697                  rproc->state = RPROC_DETACHED;
>    698
>    699          rproc->has_iommu = false;
>    700          ddata->workqueue = create_workqueue(dev_name(dev));
>    701          if (!ddata->workqueue) {
>    702                  dev_err(dev, "cannot create workqueue\n");
>    703                  ret = -ENOMEM;
>    704                  goto free_rproc;
>    705          }
>    706
>    707          platform_set_drvdata(pdev, rproc);
>    708
>    709          ret = stm32_rproc_request_mbox(rproc);
>    710          if (ret)
>    711                  goto free_wkq;
>    712
>    713          ret = rproc_add(rproc);
>    714          if (ret)
>    715                  goto free_mb;
>    716
>    717          return 0;
>    718
>    719  free_mb:
>    720          stm32_rproc_free_mbox(rproc);
>    721  free_wkq:
>    722          destroy_workqueue(ddata->workqueue);
>    723  free_rproc:
>    724          if (device_may_wakeup(dev)) {
>    725                  dev_pm_clear_wake_irq(dev);
>    726                  device_init_wakeup(dev, false);
>    727          }
>    728          rproc_free(rproc);
>    729          return ret;
>    730  }
>    731
>
> ---
> 0-DAY CI Kernel Test Service, Intel Corporation
> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
kernel test robot July 16, 2020, 12:48 a.m. UTC | #4
On 7/16/20 6:19 AM, Mathieu Poirier wrote:
> Hi Robot,
>
> On Tue, 14 Jul 2020 at 14:31, kernel test robot <lkp@intel.com> wrote:
>> Hi Mathieu,
>>
>> I love your patch! Yet something to improve:
>>
>> [auto build test ERROR on linux/master]
>> [also build test ERROR on linus/master v5.8-rc5 next-20200714]
>> [If your patch is applied to the wrong git tree, kindly drop us a note.
>> And when submitting patch, we suggest to use  as documented in
>> https://git-scm.com/docs/git-format-patch]
>>
>> url:    https://github.com/0day-ci/linux/commits/Mathieu-Poirier/remoteproc-stm32-Add-support-for-attaching-to-M4/20200708-053515
>> base:   https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9ebcfadb0610322ac537dd7aa5d9cbc2b2894c68
>> config: arm-randconfig-r011-20200714 (attached as .config)
>> compiler: clang version 11.0.0 (https://github.com/llvm/llvm-project 02946de3802d3bc65bc9f2eb9b8d4969b5a7add8)
>> reproduce (this is a W=1 build):
>>          wget https://raw.githubusercontent.com/intel/lkp-tests/master/sbin/make.cross -O ~/bin/make.cross
>>          chmod +x ~/bin/make.cross
>>          # install arm cross compiling tool for clang build
>>          # apt-get install binutils-arm-linux-gnueabi
>>          # save the attached .config to linux build tree
>>          COMPILER_INSTALL_PATH=$HOME/0day COMPILER=clang make.cross ARCH=arm
>>
>> If you fix the issue, kindly add following tag as appropriate
>> Reported-by: kernel test robot <lkp@intel.com>
>>
>> All errors (new ones prefixed by >>):
>>
>>>> drivers/remoteproc/stm32_rproc.c:697:18: error: use of undeclared identifier 'RPROC_DETACHED'
>>                     rproc->state = RPROC_DETACHED;
>>                                    ^
>>     1 error generated.
> This patchset depends on this one [1], something that is clearly
> stated in the cover letter.  Compiling this set on top of [1]
> generates no error.
>
> [1]. https://patchwork.kernel.org/project/linux-remoteproc/list/?series=318275

Hi Mathieu,

Thanks for the feedback, the bot can't parse the base which links to another patchset,
and we can get the base commit if using 'git format-patch --base' to submit patch.

Best Regards,
Rong Chen

>
>> vim +/RPROC_DETACHED +697 drivers/remoteproc/stm32_rproc.c
>>
>>     661
>>     662
>>     663  static int stm32_rproc_probe(struct platform_device *pdev)
>>     664  {
>>     665          struct device *dev = &pdev->dev;
>>     666          struct stm32_rproc *ddata;
>>     667          struct device_node *np = dev->of_node;
>>     668          struct rproc *rproc;
>>     669          unsigned int state;
>>     670          int ret;
>>     671
>>     672          ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
>>     673          if (ret)
>>     674                  return ret;
>>     675
>>     676          rproc = rproc_alloc(dev, np->name, &st_rproc_ops, NULL, sizeof(*ddata));
>>     677          if (!rproc)
>>     678                  return -ENOMEM;
>>     679
>>     680          ddata = rproc->priv;
>>     681
>>     682          rproc_coredump_set_elf_info(rproc, ELFCLASS32, EM_NONE);
>>     683
>>     684          ret = stm32_rproc_parse_dt(pdev, ddata, &rproc->auto_boot);
>>     685          if (ret)
>>     686                  goto free_rproc;
>>     687
>>     688          ret = stm32_rproc_of_memory_translations(pdev, ddata);
>>     689          if (ret)
>>     690                  goto free_rproc;
>>     691
>>     692          ret = stm32_rproc_get_m4_status(ddata, &state);
>>     693          if (ret)
>>     694                  goto free_rproc;
>>     695
>>     696          if (state == M4_STATE_CRUN)
>>   > 697                  rproc->state = RPROC_DETACHED;
>>     698
>>     699          rproc->has_iommu = false;
>>     700          ddata->workqueue = create_workqueue(dev_name(dev));
>>     701          if (!ddata->workqueue) {
>>     702                  dev_err(dev, "cannot create workqueue\n");
>>     703                  ret = -ENOMEM;
>>     704                  goto free_rproc;
>>     705          }
>>     706
>>     707          platform_set_drvdata(pdev, rproc);
>>     708
>>     709          ret = stm32_rproc_request_mbox(rproc);
>>     710          if (ret)
>>     711                  goto free_wkq;
>>     712
>>     713          ret = rproc_add(rproc);
>>     714          if (ret)
>>     715                  goto free_mb;
>>     716
>>     717          return 0;
>>     718
>>     719  free_mb:
>>     720          stm32_rproc_free_mbox(rproc);
>>     721  free_wkq:
>>     722          destroy_workqueue(ddata->workqueue);
>>     723  free_rproc:
>>     724          if (device_may_wakeup(dev)) {
>>     725                  dev_pm_clear_wake_irq(dev);
>>     726                  device_init_wakeup(dev, false);
>>     727          }
>>     728          rproc_free(rproc);
>>     729          return ret;
>>     730  }
>>     731
>>
>> ---
>> 0-DAY CI Kernel Test Service, Intel Corporation
>> https://lists.01.org/hyperkitty/list/kbuild-all@lists.01.org
> _______________________________________________
> kbuild-all mailing list -- kbuild-all@lists.01.org
> To unsubscribe send an email to kbuild-all-leave@lists.01.org

Patch
diff mbox series

diff --git a/drivers/remoteproc/stm32_rproc.c b/drivers/remoteproc/stm32_rproc.c
index 961a53f67ec5..cbeb5ceb15c5 100644
--- a/drivers/remoteproc/stm32_rproc.c
+++ b/drivers/remoteproc/stm32_rproc.c
@@ -39,6 +39,13 @@ 
 #define STM32_MBX_VQ1_ID	1
 #define STM32_MBX_SHUTDOWN	"shutdown"
 
+#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;
@@ -636,12 +643,30 @@  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) {
+		/*
+		 * We couldn't get the coprocessor's state, assume
+		 * it is not running.
+		 */
+		state = M4_STATE_OFF;
+		return 0;
+	}
+
+	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;
 	int ret;
 
 	ret = dma_coerce_mask_and_coherent(dev, DMA_BIT_MASK(32));
@@ -664,6 +689,13 @@  static int stm32_rproc_probe(struct platform_device *pdev)
 	if (ret)
 		goto free_rproc;
 
+	ret = stm32_rproc_get_m4_status(ddata, &state);
+	if (ret)
+		goto free_rproc;
+
+	if (state == M4_STATE_CRUN)
+		rproc->state = RPROC_DETACHED;
+
 	rproc->has_iommu = false;
 	ddata->workqueue = create_workqueue(dev_name(dev));
 	if (!ddata->workqueue) {