Skip to content

Commit 9a89051

Browse files
xuchengci24968joergroedel
authored andcommitted
iommu/mediatek: Adjust mtk_iommu_config flow
If there are many ports in a infra master, current flow will update the INFRA register many times. This patch saves all ports to portid_msk in the front of mtk_iommu_config(), then update only once for the IOMMU configure. After this, we could avoid send too many SMC calls to ATF in MT8188. Prepare for MT8188, also reduce the indention without functional change. Signed-off-by: Chengci.Xu <[email protected]> Signed-off-by: Yong Wu <[email protected]> Reviewed-by: AngeloGioacchino Del Regno <[email protected]> Reviewed-by: Alexandre Mergnat <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Joerg Roedel <[email protected]>
1 parent cf69ef4 commit 9a89051

File tree

1 file changed

+32
-26
lines changed

1 file changed

+32
-26
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -579,41 +579,47 @@ static int mtk_iommu_config(struct mtk_iommu_data *data, struct device *dev,
579579
unsigned int larbid, portid;
580580
struct iommu_fwspec *fwspec = dev_iommu_fwspec_get(dev);
581581
const struct mtk_iommu_iova_region *region;
582-
u32 peri_mmuen, peri_mmuen_msk;
582+
unsigned long portid_msk = 0;
583583
int i, ret = 0;
584584

585585
for (i = 0; i < fwspec->num_ids; ++i) {
586-
larbid = MTK_M4U_TO_LARB(fwspec->ids[i]);
587586
portid = MTK_M4U_TO_PORT(fwspec->ids[i]);
587+
portid_msk |= BIT(portid);
588+
}
588589

589-
if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) {
590-
larb_mmu = &data->larb_imu[larbid];
590+
if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_MM)) {
591+
/* All ports should be in the same larb. just use 0 here */
592+
larbid = MTK_M4U_TO_LARB(fwspec->ids[0]);
593+
larb_mmu = &data->larb_imu[larbid];
594+
region = data->plat_data->iova_region + regionid;
591595

592-
region = data->plat_data->iova_region + regionid;
596+
for_each_set_bit(portid, &portid_msk, 32)
593597
larb_mmu->bank[portid] = upper_32_bits(region->iova_base);
594598

595-
dev_dbg(dev, "%s iommu for larb(%s) port %d region %d rgn-bank %d.\n",
596-
enable ? "enable" : "disable", dev_name(larb_mmu->dev),
597-
portid, regionid, larb_mmu->bank[portid]);
598-
599-
if (enable)
600-
larb_mmu->mmu |= MTK_SMI_MMU_EN(portid);
601-
else
602-
larb_mmu->mmu &= ~MTK_SMI_MMU_EN(portid);
603-
} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
604-
peri_mmuen_msk = BIT(portid);
605-
/* PCI dev has only one output id, enable the next writing bit for PCIe */
606-
if (dev_is_pci(dev))
607-
peri_mmuen_msk |= BIT(portid + 1);
608-
609-
peri_mmuen = enable ? peri_mmuen_msk : 0;
610-
ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1,
611-
peri_mmuen_msk, peri_mmuen);
612-
if (ret)
613-
dev_err(dev, "%s iommu(%s) inframaster 0x%x fail(%d).\n",
614-
enable ? "enable" : "disable",
615-
dev_name(data->dev), peri_mmuen_msk, ret);
599+
dev_dbg(dev, "%s iommu for larb(%s) port 0x%lx region %d rgn-bank %d.\n",
600+
enable ? "enable" : "disable", dev_name(larb_mmu->dev),
601+
portid_msk, regionid, upper_32_bits(region->iova_base));
602+
603+
if (enable)
604+
larb_mmu->mmu |= portid_msk;
605+
else
606+
larb_mmu->mmu &= ~portid_msk;
607+
} else if (MTK_IOMMU_IS_TYPE(data->plat_data, MTK_IOMMU_TYPE_INFRA)) {
608+
/* PCI dev has only one output id, enable the next writing bit for PCIe */
609+
if (dev_is_pci(dev)) {
610+
if (fwspec->num_ids != 1) {
611+
dev_err(dev, "PCI dev can only have one port.\n");
612+
return -ENODEV;
613+
}
614+
portid_msk |= BIT(portid + 1);
616615
}
616+
617+
ret = regmap_update_bits(data->pericfg, PERICFG_IOMMU_1,
618+
(u32)portid_msk, enable ? (u32)portid_msk : 0);
619+
if (ret)
620+
dev_err(dev, "%s iommu(%s) inframaster 0x%lx fail(%d).\n",
621+
enable ? "enable" : "disable",
622+
dev_name(data->dev), portid_msk, ret);
617623
}
618624
return ret;
619625
}

0 commit comments

Comments
 (0)