From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BEDCA7C for ; Tue, 20 Sep 2022 09:02:01 +0000 (UTC) Received: from [192.168.1.100] (2-237-20-237.ip236.fastwebnet.it [2.237.20.237]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: kholk11) by madras.collabora.co.uk (Postfix) with ESMTPSA id EFF556601F65; Tue, 20 Sep 2022 10:01:58 +0100 (BST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1663664519; bh=+3Eho6vznxN6lcZbJbVvkS5KJYsPvu5pctKzlZPKMUo=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=LJclHzWWXsCnozr4D6rWp6q57rPuakEPkNWPH4x5OppazabiA3wjTGmtPFWcgEgIj GR4sP0iuussi0aap1SwEamN3AIHInnQt4Y1crvC44KcN+0rKVSTNkt68tCFtcAFgHP HS3TRs3QGz4pde4u0r/jmuJIccKVgD1Y/4o3hls04T98y6fFdWjuThZAW7qN0rGcIc OkU750ey5Tj9vwjKlDYO//swC6zIN/iq6EUNiD3n5mCmT6OWvc4/WLatlhkVtbeK+s MqjnrDydHispgrfrj0N6PWPcfxJ5yGR6xzIIQIlFVoxfFGL1qS81oMdjy95Z24kSXU xwFUg1uwDjb7w== Message-ID: <3a0ac49f-2245-fb64-aa60-e3b1a1d4afcd@collabora.com> Date: Tue, 20 Sep 2022 11:01:56 +0200 Precedence: bulk X-Mailing-List: iommu@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.0 Subject: Re: [PATCH v3 2/3] iommu/mediatek: Add enable IOMMU SMC command for INFRA master Content-Language: en-US To: "Chengci.Xu" , Yong Wu , Joerg Roedel , Will Deacon , Robin Murphy , Rob Herring , Krzysztof Kozlowski , Matthias Brugger 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 References: <20220919082611.19824-1-chengci.xu@mediatek.com> <20220919082611.19824-3-chengci.xu@mediatek.com> From: AngeloGioacchino Del Regno In-Reply-To: <20220919082611.19824-3-chengci.xu@mediatek.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit 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 > --- > 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 > */ > +#include > #include > #include > #include > @@ -28,6 +29,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -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