mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* Re: [PATCH v3 1/3] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU
       [not found] ` <20220919082611.19824-2-chengci.xu@mediatek.com>
@ 2022-09-19 11:05   ` Krzysztof Kozlowski
  0 siblings, 0 replies; 3+ messages in thread
From: Krzysztof Kozlowski @ 2022-09-19 11:05 UTC (permalink / raw)
  To: Chengci.Xu, Yong Wu, Joerg Roedel, Will Deacon, Robin Murphy,
	Rob Herring, Krzysztof Kozlowski, Matthias Brugger
  Cc: iommu, linux-mediatek, devicetree, linux-kernel,
	linux-arm-kernel, Project_Global_Chrome_Upstream_Group

On 19/09/2022 10:26, Chengci.Xu wrote:
> Adds descriptions for mt8188 IOMMU which also use ARM Short-Descriptor
> translation table format.
> 
> In mt8188, there are two smi-common HW and IOMMU, one is for vdo(video
> output), the other is for vpp(video processing pipe). They connects
> with different smi-larbs, then some setting(larbid_remap) is different.
> Differentiate them with the compatible string.
> 
> Something like this:
> 
>   IOMMU(VDO)          IOMMU(VPP)
>       |                   |
> SMI_COMMON_VDO      SMI_COMMON_VPP
> ---------------     ----------------
>   |     |    ...      |     |    ...
> larb0 larb2  ...    larb1 larb3  ...
> 
> We also have an IOMMU that is for infra master like PCIe.
> And infra master don't have the larb and ports.
> 
> Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com>


Acked-by: Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org>


Best regards,
Krzysztof

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3 2/3] iommu/mediatek: Add enable IOMMU SMC command for INFRA master
       [not found] ` <20220919082611.19824-3-chengci.xu@mediatek.com>
@ 2022-09-20  9:01   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-09-20  9:01 UTC (permalink / raw)
  To: Chengci.Xu, Yong Wu, Joerg Roedel, Will Deacon, Robin Murphy,
	Rob Herring, Krzysztof Kozlowski, Matthias Brugger
  Cc: iommu, linux-mediatek, devicetree, linux-kernel,
	linux-arm-kernel, Project_Global_Chrome_Upstream_Group

Il 19/09/22 10:26, Chengci.Xu ha scritto:
> The register which can enable IOMMU for INFRA master should be setted
> in secure world for security concerns. Therefore, we add a SMC command
> for INFRA master to enable/disable INFRA IOMMU in ATF. This function is
> prepared for MT8188.
> 
> Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com>
> ---
>   drivers/iommu/mtk_iommu.c  | 21 +++++++++++++++++++--
>   include/soc/mediatek/smi.h |  1 +
>   2 files changed, 20 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/mtk_iommu.c b/drivers/iommu/mtk_iommu.c
> index 552e4eb8c610..8b8a289bab2c 100644
> --- a/drivers/iommu/mtk_iommu.c
> +++ b/drivers/iommu/mtk_iommu.c
> @@ -3,6 +3,7 @@
>    * Copyright (c) 2015-2016 MediaTek Inc.
>    * Author: Yong Wu <yong.wu@mediatek.com>
>    */
> +#include <linux/arm-smccc.h>
>   #include <linux/bitfield.h>
>   #include <linux/bug.h>
>   #include <linux/clk.h>
> @@ -28,6 +29,7 @@
>   #include <linux/slab.h>
>   #include <linux/spinlock.h>
>   #include <linux/soc/mediatek/infracfg.h>
> +#include <linux/soc/mediatek/mtk_sip_svc.h>
>   #include <asm/barrier.h>
>   #include <soc/mediatek/smi.h>
>   
> @@ -138,6 +140,7 @@
>   #define PM_CLK_AO			BIT(15)
>   #define IFA_IOMMU_PCIE_SUPPORT		BIT(16)
>   #define PGTABLE_PA_35_EN		BIT(17)
> +#define CFG_IFA_MASTER_IN_ATF		BIT(18)
>   
>   #define MTK_IOMMU_HAS_FLAG_MASK(pdata, _x, mask)	\
>   				((((pdata)->flags) & (mask)) == (_x))
> @@ -553,7 +556,20 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,
>   				larb_mmu->mmu |= MTK_SMI_MMU_EN(portid);
>   			else
>   				larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid);
> -		} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
> +		} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA) &&
> +			   MTK_IOMMU_HAS_FLAG(data->plat_data, CFG_IFA_MASTER_IN_ATF)) {
> +			struct arm_smccc_res res;
> +
> +			arm_smccc_smc(MTK_SIP_KERNEL_IOMMU_CONTROL,
> +				      IOMMU_ATF_CMD_CONFIG_INFRA_IOMMU,
> +				      portid, enable, 0, 0, 0, 0, &res);
> +			if (res.a0 != 0) {
> +				dev_err(dev, "%s iommu(%s) inframaster %d fail(%ld).\n",
> +					enable ? "enable" : "disable",
> +					dev_name(data->dev), portid, res.a0);
> +				ret = -EINVAL;
> +			}
> +		} else {

This one is opening a big window for future mistakes.

I think that the only way that you have to do this is...

	} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
		if (MTK_IOMMU_HAS_FLAG(data->plat_data, CFG_IFA_MASTER_IN_ATF)) {
			arm_smcc_smc ....
		} else {
			peri_mmuen_msk ....
		}
	}

Otherwise, to reduce indentation, you'd have to do something like...

static int mtk_iommu_config_one(struct mtk_iommu_data *data, struct device *dev,
				bool enable, u32 regionid, u32 larbid, u32 portid)
{
	struct mtk_smi_larb_iommu *larb_mmu;
	............
}

static int mtk_iommu_config(struct .............)
{
	vars, etc....

	for (i = 0; i < fwspec->num_ids; ++i)
		mtk_iommu_config_one(data, dev, enable, regionid,
				     MTK_M4U_TO_LARB(...), MTK_M4U_TO_PORT(...));
}


or....

static int mtk_iommu_config_one_infra(struct ....)
{
	if (is atf) ....
	else ....
}

Your choice.

Regards,
Angelo



^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH v3 3/3] iommu/mediatek: Add MT8188 IOMMU Support
       [not found] ` <20220919082611.19824-4-chengci.xu@mediatek.com>
@ 2022-09-20  9:02   ` AngeloGioacchino Del Regno
  0 siblings, 0 replies; 3+ messages in thread
From: AngeloGioacchino Del Regno @ 2022-09-20  9:02 UTC (permalink / raw)
  To: Chengci.Xu, Yong Wu, Joerg Roedel, Will Deacon, Robin Murphy,
	Rob Herring, Krzysztof Kozlowski, Matthias Brugger
  Cc: iommu, linux-mediatek, devicetree, linux-kernel,
	linux-arm-kernel, Project_Global_Chrome_Upstream_Group

Il 19/09/22 10:26, Chengci.Xu ha scritto:
> MT8188 has 3 IOMMU, containing 2 MM IOMMUs, one is for vdo, the other
> is for vpp. and 1 INFRA IOMMU.
> 
> Signed-off-by: Chengci.Xu <chengci.xu@mediatek.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-09-20  9:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20220919082611.19824-1-chengci.xu@mediatek.com>
     [not found] ` <20220919082611.19824-2-chengci.xu@mediatek.com>
2022-09-19 11:05   ` [PATCH v3 1/3] dt-bindings: mediatek: mt8188: Add binding for MM & INFRA IOMMU Krzysztof Kozlowski
     [not found] ` <20220919082611.19824-3-chengci.xu@mediatek.com>
2022-09-20  9:01   ` [PATCH v3 2/3] iommu/mediatek: Add enable IOMMU SMC command for INFRA master AngeloGioacchino Del Regno
     [not found] ` <20220919082611.19824-4-chengci.xu@mediatek.com>
2022-09-20  9:02   ` [PATCH v3 3/3] iommu/mediatek: Add MT8188 IOMMU Support AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®