Skip to content

Commit cf69ef4

Browse files
xuchengci24968joergroedel
authored andcommitted
iommu/mediatek: Fix two IOMMU share pagetable issue
Prepare for mt8188 to fix a two IOMMU HWs share pagetable issue. We have two MM IOMMU HWs in mt8188, one is VPP-IOMMU, the other is VDO-IOMMU. The 2 MM IOMMU HWs share pagetable don't work in this case: a) VPP-IOMMU probe firstly. b) VDO-IOMMU probe. c) The master for VDO-IOMMU probe (means frstdata is vpp-iommu). d) The master in another domain probe. No matter it is vdo or vpp. Then it still create a new pagetable in step d). The problem is "frstdata->bank[0]->m4u_dom" was not initialized. Then when d) enter, it still create a new one. In this patch, we create a new variable "share_dom" for this share pgtable case, it should be helpful for readable. and put all the share pgtable logic in the mtk_iommu_domain_finalise. In mt8195, the master of VPP-IOMMU probes before than VDO-IOMMU from its dtsi node sequence, we don't see this issue in it. Prepare for mt8188. Fixes: 645b87c ("iommu/mediatek: Fix 2 HW sharing pgtable issue") 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 d5cda14 commit cf69ef4

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,8 @@ struct mtk_iommu_data {
258258
struct device *smicomm_dev;
259259

260260
struct mtk_iommu_bank_data *bank;
261+
struct mtk_iommu_domain *share_dom; /* For 2 HWs share pgtable */
262+
261263
struct regmap *pericfg;
262264
struct mutex mutex; /* Protect m4u_group/m4u_dom above */
263265

@@ -620,15 +622,14 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
620622
struct mtk_iommu_data *data,
621623
unsigned int region_id)
622624
{
625+
struct mtk_iommu_domain *share_dom = data->share_dom;
623626
const struct mtk_iommu_iova_region *region;
624-
struct mtk_iommu_domain *m4u_dom;
625-
626-
/* Always use bank0 in sharing pgtable case */
627-
m4u_dom = data->bank[0].m4u_dom;
628-
if (m4u_dom) {
629-
dom->iop = m4u_dom->iop;
630-
dom->cfg = m4u_dom->cfg;
631-
dom->domain.pgsize_bitmap = m4u_dom->cfg.pgsize_bitmap;
627+
628+
/* Always use share domain in sharing pgtable case */
629+
if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE) && share_dom) {
630+
dom->iop = share_dom->iop;
631+
dom->cfg = share_dom->cfg;
632+
dom->domain.pgsize_bitmap = share_dom->cfg.pgsize_bitmap;
632633
goto update_iova_region;
633634
}
634635

@@ -658,6 +659,9 @@ static int mtk_iommu_domain_finalise(struct mtk_iommu_domain *dom,
658659
/* Update our support page sizes bitmap */
659660
dom->domain.pgsize_bitmap = dom->cfg.pgsize_bitmap;
660661

662+
if (MTK_IOMMU_HAS_FLAG(data->plat_data, SHARE_PGTABLE))
663+
data->share_dom = dom;
664+
661665
update_iova_region:
662666
/* Update the iova region for this domain */
663667
region = data->plat_data->iova_region + region_id;
@@ -708,7 +712,9 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
708712
/* Data is in the frstdata in sharing pgtable case. */
709713
frstdata = mtk_iommu_get_frst_data(hw_list);
710714

715+
mutex_lock(&frstdata->mutex);
711716
ret = mtk_iommu_domain_finalise(dom, frstdata, region_id);
717+
mutex_unlock(&frstdata->mutex);
712718
if (ret) {
713719
mutex_unlock(&dom->mutex);
714720
return ret;

0 commit comments

Comments
 (0)