[PATCH v13 07/11] remoteproc: mediatek: Add scp_boot_peers and scp_shutdown_peers operations

Mathieu Poirier mathieu.poirier at linaro.org
Mon Jun 12 10:54:54 PDT 2023


On Wed, Jun 07, 2023 at 03:22:18PM +0800, Tinghan Shen wrote:
> Due to that SCP core 0 controls the SCP clock and SRAM power, add two
> new mtk_scp_of_data operations, scp_boot_peers and scp_shutdown_peers,
> to manage the boot sequence and watchdog timeout handling of SCP core 1.
> It ensures that core 1 boots after or shuts down before core 0 for
> maintaining the proper control flow over SCP core 1.
> 
> Signed-off-by: Tinghan Shen <tinghan.shen at mediatek.com>
> ---
>  drivers/remoteproc/mtk_common.h |  3 ++
>  drivers/remoteproc/mtk_scp.c    | 55 +++++++++++++++++++++++++++++++++
>  2 files changed, 58 insertions(+)
> 
> diff --git a/drivers/remoteproc/mtk_common.h b/drivers/remoteproc/mtk_common.h
> index 56395e8664cb..0bfd242c41cc 100644
> --- a/drivers/remoteproc/mtk_common.h
> +++ b/drivers/remoteproc/mtk_common.h
> @@ -93,6 +93,8 @@ struct mtk_scp_of_data {
>  	void (*scp_reset_deassert)(struct mtk_scp *scp);
>  	void (*scp_stop)(struct mtk_scp *scp);
>  	void *(*scp_da_to_va)(struct mtk_scp *scp, u64 da, size_t len);
> +	void (*scp_boot_peers)(struct mtk_scp *scp);
> +	void (*scp_shutdown_peers)(struct mtk_scp *scp);

This isn't what I suggested in my previous email.  This solution will not work
if a user is looking to independently start/stop CPU1 from sysfs.

I will not go further with this revision.

Mathieu

>  
>  	u32 host_to_scp_reg;
>  	u32 host_to_scp_int_bit;
> @@ -130,6 +132,7 @@ struct mtk_scp {
>  	struct rproc_subdev *rpmsg_subdev;
>  
>  	struct list_head elem;
> +	struct list_head *cluster;
>  };
>  
>  /**
> diff --git a/drivers/remoteproc/mtk_scp.c b/drivers/remoteproc/mtk_scp.c
> index d644e232dfec..edbf71f4c21e 100644
> --- a/drivers/remoteproc/mtk_scp.c
> +++ b/drivers/remoteproc/mtk_scp.c
> @@ -74,8 +74,21 @@ void scp_put(struct mtk_scp *scp)
>  }
>  EXPORT_SYMBOL_GPL(scp_put);
>  
> +static void mt8195_scp_shutdown_peers(struct mtk_scp *scp)
> +{
> +	struct mtk_scp *next_scp;
> +
> +	next_scp = list_next_entry(scp, elem);
> +	list_for_each_entry_from(next_scp, scp->cluster, elem) {
> +		rproc_shutdown(next_scp->rproc);
> +	}
> +}
> +
>  static void scp_wdt_handler(struct mtk_scp *scp, u32 scp_to_host)
>  {
> +	if (scp->data->scp_shutdown_peers)
> +		scp->data->scp_shutdown_peers(scp);
> +
>  	dev_err(scp->dev, "SCP watchdog timeout! 0x%x", scp_to_host);
>  	rproc_report_crash(scp->rproc, RPROC_WATCHDOG);
>  }
> @@ -539,6 +552,18 @@ static int scp_parse_fw(struct rproc *rproc, const struct firmware *fw)
>  	return ret;
>  }
>  
> +static void mt8195_scp_boot_peers(struct mtk_scp *scp)
> +{
> +	struct mtk_scp *next_scp;
> +
> +	if (scp->cluster && !list_empty(scp->cluster)) {
> +		next_scp = list_next_entry(scp, elem);
> +		list_for_each_entry_from(next_scp, scp->cluster, elem) {
> +			rproc_boot(next_scp->rproc);
> +		}
> +	}
> +}
> +
>  static int scp_start(struct rproc *rproc)
>  {
>  	struct mtk_scp *scp = rproc->priv;
> @@ -574,6 +599,9 @@ static int scp_start(struct rproc *rproc)
>  	clk_disable_unprepare(scp->clk);
>  	dev_info(dev, "SCP is ready. FW version %s\n", run->fw_ver);
>  
> +	if (scp->data->scp_boot_peers)
> +		scp->data->scp_boot_peers(scp);
> +
>  	return 0;
>  
>  stop:
> @@ -977,6 +1005,8 @@ static int scp_add_single_core(struct platform_device *pdev)
>  	if (IS_ERR(scp))
>  		return PTR_ERR(scp);
>  
> +	scp->cluster = cluster;
> +
>  	ret = rproc_add(scp->rproc);
>  	if (ret) {
>  		dev_err(dev, "Failed to add rproc\n");
> @@ -989,6 +1019,15 @@ static int scp_add_single_core(struct platform_device *pdev)
>  	return 0;
>  }
>  
> +static void scp_rproc_boot_core0(const struct firmware *fw, void *context)
> +{
> +	struct rproc *rproc = context;
> +
> +	rproc_boot(rproc);
> +
> +	release_firmware(fw);
> +}
> +
>  static int scp_add_multi_core(struct platform_device *pdev)
>  {
>  	struct device *dev = &pdev->dev;
> @@ -1029,6 +1068,10 @@ static int scp_add_multi_core(struct platform_device *pdev)
>  			goto init_fail;
>  		}
>  
> +		/* boot after all cores are discovered */
> +		scp->rproc->auto_boot = false;
> +		scp->cluster = cluster;
> +
>  		ret = rproc_add(scp->rproc);
>  		if (ret) {
>  			dev_err(dev, "Failed to add rproc of core %d\n", core_id);
> @@ -1041,6 +1084,16 @@ static int scp_add_multi_core(struct platform_device *pdev)
>  		core_id++;
>  	}
>  
> +	/* boot core 0, and other cores are booted following core 0 */
> +	scp = list_first_entry(cluster, struct mtk_scp, elem);
> +	ret = request_firmware_nowait(THIS_MODULE, FW_ACTION_UEVENT,
> +				      scp->rproc->firmware, &scp->rproc->dev, GFP_KERNEL,
> +				      scp->rproc, scp_rproc_boot_core0);
> +	if (ret < 0) {
> +		dev_err(dev, "request_firmware_nowait err: %d\n", ret);
> +		goto init_fail;
> +	}
> +
>  	return 0;
>  
>  init_fail:
> @@ -1198,6 +1251,8 @@ static const struct mtk_scp_of_data mt8195_of_data = {
>  	.scp_reset_deassert = mt8192_scp_reset_deassert,
>  	.scp_stop = mt8195_scp_stop,
>  	.scp_da_to_va = mt8192_scp_da_to_va,
> +	.scp_boot_peers = mt8195_scp_boot_peers,
> +	.scp_shutdown_peers = mt8195_scp_shutdown_peers,
>  	.host_to_scp_reg = MT8192_GIPC_IN_SET,
>  	.host_to_scp_int_bit = MT8192_HOST_IPC_INT_BIT,
>  };
> -- 
> 2.18.0
> 



More information about the Linux-mediatek mailing list