linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthias Brugger <matthias.bgg@gmail.com>
To: zhengnan chen <zhengnan.chen@mediatek.com>,
	Yong Wu <yong.wu@mediatek.com>, Joerg Roedel <joro@8bytes.org>,
	Will Deacon <will@kernel.org>,
	Robin Murphy <robin.murphy@arm.com>,
	Rob Herring <robh@kernel.org>,
	Krzysztof Kozlowski <krzk+dt@kernel.org>,
	Conor Dooley <conor+dt@kernel.org>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>
Cc: iommu@lists.linux.dev, linux-mediatek@lists.infradead.org,
	devicetree@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	Project_Global_Chrome_Upstream_Group@mediatek.com
Subject: Re: [PATCH 2/3] iommu/mediatek: Add a flag DL_WITH_MULTI_LARB
Date: Thu, 7 Aug 2025 17:24:28 +0200	[thread overview]
Message-ID: <2d179e08-c6f4-4e0d-8d2c-10c643e96d5e@gmail.com> (raw)
In-Reply-To: <20250807095756.11840-3-zhengnan.chen@mediatek.com>

On 07/08/2025 11:57, zhengnan chen wrote:
> From: "zhengnan chen" <zhengnan.chen@mediatek.com>
> 
> Add DL_WITH_MULTI_LARB flag to support the HW which connect with
> multiple larbs. Prepare for mt8189. In mt8189, the display connect
> with larb1 and larb2 at the same time. Thus, we should add link
> between disp-dev with these two larbs.
> 
> Signed-off-by: zhengnan chen <zhengnan.chen@mediatek.com>

Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com>

> ---
>   drivers/iommu/mtk_iommu.c | 56 ++++++++++++++++++++++++++++++---------
>   1 file changed, 43 insertions(+), 13 deletions(-)
> 
> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> index 0e0285348d2b..7af47c59b10b 100644
> --- a/drivers/iommu/mtk_iommu.c
> +++ b/drivers/iommu/mtk_iommu.c
> @@ -147,6 +147,7 @@
>   #define TF_PORT_TO_ADDR_MT8173		BIT(18)
>   #define INT_ID_PORT_WIDTH_6		BIT(19)
>   #define CFG_IFA_MASTER_IN_ATF		BIT(20)
> +#define DL_WITH_MULTI_LARB		BIT(21)
>   
>   #define MTK_IOMMU_HAS_FLAG_MASK(pdata, _x, mask)	\
>   				((((pdata)->flags) & (mask)) == (_x))
> @@ -865,6 +866,7 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
>   	struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
>   	struct device_link *link;
>   	struct device *larbdev;
> +	unsigned long larbid_msk = 0;
>   	unsigned int larbid, larbidx, i;
>   
>   	if (!MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM))
> @@ -872,30 +874,50 @@ static struct iommu_device *mtk_iommu_probe_device(struct device *dev)
>   
>   	/*
>   	 * Link the consumer device with the smi-larb device(supplier).
> -	 * The device that connects with each a larb is a independent HW.
> -	 * All the ports in each a device should be in the same larbs.
> +	 * w/DL_WITH_MULTI_LARB: the master may connect with multi larbs,
> +	 * we should create device link with each larb.
> +	 * w/o DL_WITH_MULTI_LARB: the master must connect with one larb,
> +	 * otherwise fail.
>   	 */
>   	larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
>   	if (larbid >= MTK_LARB_NR_MAX)
>   		return ERR_PTR(-EINVAL);
>   
> +	larbid_msk |= BIT(larbid);
> +
>   	for (i = 1; i < fwspec->num_ids; i++) {
>   		larbidx = MTK_M4U_TO_LARB(fwspec->ids[i]);
> -		if (larbid != larbidx) {
> +		if (MTK_IOMMU_HAS_FLAG(data->plat_data, DL_WITH_MULTI_LARB)) {
> +			larbid_msk |= BIT(larbidx);
> +		} else if (larbid != larbidx) {
>   			dev_err(dev, "Can only use one larb. Fail@larb%d-%d.\n",
>   				larbid, larbidx);
>   			return ERR_PTR(-EINVAL);
>   		}
>   	}
> -	larbdev = data->larb_imu[larbid].dev;
> -	if (!larbdev)
> -		return ERR_PTR(-EINVAL);
>   
> -	link = device_link_add(dev, larbdev,
> -			       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> -	if (!link)
> -		dev_err(dev, "Unable to link %s\n", dev_name(larbdev));
> +	for_each_set_bit(larbid, &larbid_msk, 32) {
> +		larbdev = data->larb_imu[larbid].dev;
> +		if (!larbdev)
> +			return ERR_PTR(-EINVAL);
> +
> +		link = device_link_add(dev, larbdev,
> +				       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> +		if (!link) {
> +			dev_err(dev, "Unable to link %s\n", dev_name(larbdev));
> +			goto link_remove;
> +		}
> +	}
> +
>   	return &data->iommu;
> +
> +link_remove:
> +	for_each_set_bit(i, &larbid_msk, larbid) {
> +		larbdev = data->larb_imu[i].dev;
> +		device_link_remove(dev, larbdev);
> +	}
> +
> +	return ERR_PTR(-ENODEV);
>   }
>   
>   static void mtk_iommu_release_device(struct device *dev)
> @@ -903,11 +925,19 @@ static void mtk_iommu_release_device(struct device *dev)
>   	struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
>   	struct mtk_iommu_data *data;
>   	struct device *larbdev;
> -	unsigned int larbid;
> +	unsigned int larbid, i;
> +	unsigned long larbid_msk = 0;
>   
>   	data = dev_iommu_priv_get(dev);
> -	if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) {
> -		larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
> +	if (!MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM))
> +		return;
> +
> +	for (i = 0; i < fwspec->num_ids; i++) {
> +		larbid = MTK_M4U_TO_LARB(fwspec->ids[i]);
> +		larbid_msk |= BIT(larbid);
> +	}
> +
> +	for_each_set_bit(larbid, &larbid_msk, 32) {
>   		larbdev = data->larb_imu[larbid].dev;
>   		device_link_remove(dev, larbdev);
>   	}


  reply	other threads:[~2025-08-07 15:24 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-07  9:57 [PATCH 0/3] MT8189 IOMMU SUPPORT zhengnan chen
2025-08-07  9:57 ` [PATCH 1/3] dt-bindings: mediatek: mt8189: Add bindings for MM & APU & INFRA IOMMU zhengnan chen
2025-08-07 15:23   ` Matthias Brugger
2025-08-07 16:12   ` Conor Dooley
2025-08-07  9:57 ` [PATCH 2/3] iommu/mediatek: Add a flag DL_WITH_MULTI_LARB zhengnan chen
2025-08-07 15:24   ` Matthias Brugger [this message]
2025-08-10  7:09   ` Yong Wu (吴勇)
2025-08-07  9:57 ` [PATCH 3/3] iommu/mediatek: Add support for mt8189 zhengnan chen
2025-08-10  7:09   ` Yong Wu (吴勇)

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2d179e08-c6f4-4e0d-8d2c-10c643e96d5e@gmail.com \
    --to=matthias.bgg@gmail.com \
    --cc=Project_Global_Chrome_Upstream_Group@mediatek.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=iommu@lists.linux.dev \
    --cc=joro@8bytes.org \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=robh@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=will@kernel.org \
    --cc=yong.wu@mediatek.com \
    --cc=zhengnan.chen@mediatek.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).