lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <aL7vR190pYBlnujg@lizhi-Precision-Tower-5810>
Date: Mon, 8 Sep 2025 10:59:19 -0400
From: Frank Li <Frank.li@....com>
To: Peng Fan <peng.fan@....com>
Cc: Bjorn Andersson <andersson@...nel.org>,
	Mathieu Poirier <mathieu.poirier@...aro.org>,
	Shawn Guo <shawnguo@...nel.org>,
	Sascha Hauer <s.hauer@...gutronix.de>,
	Pengutronix Kernel Team <kernel@...gutronix.de>,
	Fabio Estevam <festevam@...il.com>,
	Daniel Baluta <daniel.baluta@....com>,
	Hiago De Franco <hiago.franco@...adex.com>,
	linux-remoteproc@...r.kernel.org, imx@...ts.linux.dev,
	linux-arm-kernel@...ts.infradead.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH 4/6] remoteproc: imx_rproc: Simplify IMX_RPROC_SCU_API
 switch case

On Mon, Sep 08, 2025 at 09:07:37PM +0800, Peng Fan wrote:
> Introduce imx_rproc_scu_api_{start, stop, detect_mode}() helper functions
> for all i.MX variants using IMX_RPROC_SCU_API to manage remote processors.
>
> This allows the removal of the IMX_RPROC_SCU_API switch-case blocks from
> imx_rproc_start(), imx_rproc_stop(), and imx_rproc_detect_mode(), resulting
> in cleaner and more maintainable code.
>
> No functional changes.
>
> Signed-off-by: Peng Fan <peng.fan@....com>
> ---

Reviewed-by: Frank Li <Frank.Li@....com>

>  drivers/remoteproc/imx_rproc.c | 149 +++++++++++++++++++++++------------------
>  1 file changed, 85 insertions(+), 64 deletions(-)
>
> diff --git a/drivers/remoteproc/imx_rproc.c b/drivers/remoteproc/imx_rproc.c
> index c37dd67595960f08fd85c0b516d0d03855cec9fc..ea34080970c6a5a9b035ef0d389014b8268660a9 100644
> --- a/drivers/remoteproc/imx_rproc.c
> +++ b/drivers/remoteproc/imx_rproc.c
> @@ -296,6 +296,13 @@ static int imx_rproc_mmio_start(struct rproc *rproc)
>  	return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_start);
>  }
>
> +static int imx_rproc_scu_api_start(struct rproc *rproc)
> +{
> +	struct imx_rproc *priv = rproc->priv;
> +
> +	return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
> +}
> +
>  static int imx_rproc_start(struct rproc *rproc)
>  {
>  	struct imx_rproc *priv = rproc->priv;
> @@ -318,9 +325,6 @@ static int imx_rproc_start(struct rproc *rproc)
>  		arm_smccc_smc(IMX_SIP_RPROC, IMX_SIP_RPROC_START, 0, 0, 0, 0, 0, 0, &res);
>  		ret = res.a0;
>  		break;
> -	case IMX_RPROC_SCU_API:
> -		ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, true, priv->entry);
> -		break;
>  	default:
>  		return -EOPNOTSUPP;
>  	}
> @@ -349,6 +353,13 @@ static int imx_rproc_mmio_stop(struct rproc *rproc)
>  	return regmap_update_bits(priv->regmap, dcfg->src_reg, dcfg->src_mask, dcfg->src_stop);
>  }
>
> +static int imx_rproc_scu_api_stop(struct rproc *rproc)
> +{
> +	struct imx_rproc *priv = rproc->priv;
> +
> +	return imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
> +}
> +
>  static int imx_rproc_stop(struct rproc *rproc)
>  {
>  	struct imx_rproc *priv = rproc->priv;
> @@ -369,9 +380,6 @@ static int imx_rproc_stop(struct rproc *rproc)
>  		if (res.a1)
>  			dev_info(dev, "Not in wfi, force stopped\n");
>  		break;
> -	case IMX_RPROC_SCU_API:
> -		ret = imx_sc_pm_cpu_start(priv->ipc_handle, priv->rsrc_id, false, priv->entry);
> -		break;
>  	default:
>  		return -EOPNOTSUPP;
>  	}
> @@ -907,14 +915,74 @@ static int imx_rproc_mmio_detect_mode(struct rproc *rproc)
>  	return 0;
>  }
>
> -static int imx_rproc_detect_mode(struct imx_rproc *priv)
> +static int imx_rproc_scu_api_detect_mode(struct rproc *rproc)
>  {
> -	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> +	struct imx_rproc *priv = rproc->priv;
>  	struct device *dev = priv->dev;
> -	struct arm_smccc_res res;
>  	int ret;
>  	u8 pt;
>
> +	ret = imx_scu_get_handle(&priv->ipc_handle);
> +	if (ret)
> +		return ret;
> +	ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id);
> +	if (ret) {
> +		dev_err(dev, "No fsl,resource-id property\n");
> +		return ret;
> +	}
> +
> +	if (priv->rsrc_id == IMX_SC_R_M4_1_PID0)
> +		priv->core_index = 1;
> +	else
> +		priv->core_index = 0;
> +
> +	/*
> +	 * If Mcore resource is not owned by Acore partition, It is kicked by ROM,
> +	 * and Linux could only do IPC with Mcore and nothing else.
> +	 */
> +	if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) {
> +		if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry))
> +			return -EINVAL;
> +
> +		return imx_rproc_attach_pd(priv);
> +	}
> +
> +	priv->rproc->state = RPROC_DETACHED;
> +	priv->rproc->recovery_disabled = false;
> +	rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
> +
> +	/* Get partition id and enable irq in SCFW */
> +	ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
> +	if (ret) {
> +		dev_err(dev, "not able to get resource owner\n");
> +		return ret;
> +	}
> +
> +	priv->rproc_pt = pt;
> +	priv->rproc_nb.notifier_call = imx_rproc_partition_notify;
> +
> +	ret = imx_scu_irq_register_notifier(&priv->rproc_nb);
> +	if (ret) {
> +		dev_err(dev, "register scu notifier failed, %d\n", ret);
> +		return ret;
> +	}
> +
> +	ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt),
> +				       true);
> +	if (ret) {
> +		imx_scu_irq_unregister_notifier(&priv->rproc_nb);
> +		dev_err(dev, "Enable irq failed, %d\n", ret);
> +		return ret;
> +	}
> +
> +	return 0;
> +}
> +
> +static int imx_rproc_detect_mode(struct imx_rproc *priv)
> +{
> +	const struct imx_rproc_dcfg *dcfg = priv->dcfg;
> +	struct arm_smccc_res res;
> +
>  	if (dcfg->ops && dcfg->ops->detect_mode)
>  		return dcfg->ops->detect_mode(priv->rproc);
>
> @@ -927,61 +995,6 @@ static int imx_rproc_detect_mode(struct imx_rproc *priv)
>  		if (res.a0)
>  			priv->rproc->state = RPROC_DETACHED;
>  		return 0;
> -	case IMX_RPROC_SCU_API:
> -		ret = imx_scu_get_handle(&priv->ipc_handle);
> -		if (ret)
> -			return ret;
> -		ret = of_property_read_u32(dev->of_node, "fsl,resource-id", &priv->rsrc_id);
> -		if (ret) {
> -			dev_err(dev, "No fsl,resource-id property\n");
> -			return ret;
> -		}
> -
> -		if (priv->rsrc_id == IMX_SC_R_M4_1_PID0)
> -			priv->core_index = 1;
> -		else
> -			priv->core_index = 0;
> -
> -		/*
> -		 * If Mcore resource is not owned by Acore partition, It is kicked by ROM,
> -		 * and Linux could only do IPC with Mcore and nothing else.
> -		 */
> -		if (imx_sc_rm_is_resource_owned(priv->ipc_handle, priv->rsrc_id)) {
> -			if (of_property_read_u32(dev->of_node, "fsl,entry-address", &priv->entry))
> -				return -EINVAL;
> -
> -			return imx_rproc_attach_pd(priv);
> -		}
> -
> -		priv->rproc->state = RPROC_DETACHED;
> -		priv->rproc->recovery_disabled = false;
> -		rproc_set_feature(priv->rproc, RPROC_FEAT_ATTACH_ON_RECOVERY);
> -
> -		/* Get partition id and enable irq in SCFW */
> -		ret = imx_sc_rm_get_resource_owner(priv->ipc_handle, priv->rsrc_id, &pt);
> -		if (ret) {
> -			dev_err(dev, "not able to get resource owner\n");
> -			return ret;
> -		}
> -
> -		priv->rproc_pt = pt;
> -		priv->rproc_nb.notifier_call = imx_rproc_partition_notify;
> -
> -		ret = imx_scu_irq_register_notifier(&priv->rproc_nb);
> -		if (ret) {
> -			dev_err(dev, "register scu notifier failed, %d\n", ret);
> -			return ret;
> -		}
> -
> -		ret = imx_scu_irq_group_enable(IMX_SC_IRQ_GROUP_REBOOTED, BIT(priv->rproc_pt),
> -					       true);
> -		if (ret) {
> -			imx_scu_irq_unregister_notifier(&priv->rproc_nb);
> -			dev_err(dev, "Enable irq failed, %d\n", ret);
> -			return ret;
> -		}
> -
> -		return 0;
>  	default:
>  		break;
>  	}
> @@ -1163,6 +1176,12 @@ static const struct imx_rproc_plat_ops imx_rproc_ops_mmio = {
>  	.detect_mode	= imx_rproc_mmio_detect_mode,
>  };
>
> +static const struct imx_rproc_plat_ops imx_rproc_ops_scu_api = {
> +	.start		= imx_rproc_scu_api_start,
> +	.stop		= imx_rproc_scu_api_stop,
> +	.detect_mode	= imx_rproc_scu_api_detect_mode,
> +};
> +
>  static const struct imx_rproc_dcfg imx_rproc_cfg_imx8mn_mmio = {
>  	.src_reg	= IMX7D_SRC_SCR,
>  	.src_mask	= IMX7D_M4_RST_MASK,
> @@ -1197,12 +1216,14 @@ static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qm = {
>  	.att            = imx_rproc_att_imx8qm,
>  	.att_size       = ARRAY_SIZE(imx_rproc_att_imx8qm),
>  	.method         = IMX_RPROC_SCU_API,
> +	.ops		= &imx_rproc_ops_scu_api,
>  };
>
>  static const struct imx_rproc_dcfg imx_rproc_cfg_imx8qxp = {
>  	.att		= imx_rproc_att_imx8qxp,
>  	.att_size	= ARRAY_SIZE(imx_rproc_att_imx8qxp),
>  	.method		= IMX_RPROC_SCU_API,
> +	.ops		= &imx_rproc_ops_scu_api,
>  };
>
>  static const struct imx_rproc_dcfg imx_rproc_cfg_imx8ulp = {
>
> --
> 2.37.1
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ