mirror of
https://github.com/hardkernel/linux.git
synced 2026-06-08 20:07:46 +09:00
UPSTREAM: iommu/mediatek: Add mutex for m4u_group and m4u_dom in data
Add a mutex to protect the data in the structure mtk_iommu_data, like ->"m4u_group" ->"m4u_dom". For the internal data, we should protect it in ourselves driver. Add a mutex for this. This could be a fix for the multi-groups support. Bug: 254441685 Fixes:c3045f3924("iommu/mediatek: Support for multi domains") Signed-off-by: Yunfei Wang <yf.wang@mediatek.com> Signed-off-by: Yong Wu <yong.wu@mediatek.com> Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com> Reviewed-by: Matthias Brugger <matthias.bgg@gmail.com> Link: https://lore.kernel.org/r/20220503071427.2285-8-yong.wu@mediatek.com Signed-off-by: Joerg Roedel <jroedel@suse.de> (cherry picked from commit0e5a3f2e63) Signed-off-by: Lee Jones <joneslee@google.com> Change-Id: I66499dabeeb99583e266e0c24958114dc6b974bd
This commit is contained in:
committed by
Treehugger Robot
parent
b66bdceff1
commit
17d733d05b
@@ -476,15 +476,16 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
|
|||||||
dom->data = data;
|
dom->data = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mutex_lock(&data->mutex);
|
||||||
if (!data->m4u_dom) { /* Initialize the M4U HW */
|
if (!data->m4u_dom) { /* Initialize the M4U HW */
|
||||||
ret = pm_runtime_resume_and_get(m4udev);
|
ret = pm_runtime_resume_and_get(m4udev);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
return ret;
|
goto err_unlock;
|
||||||
|
|
||||||
ret = mtk_iommu_hw_init(data);
|
ret = mtk_iommu_hw_init(data);
|
||||||
if (ret) {
|
if (ret) {
|
||||||
pm_runtime_put(m4udev);
|
pm_runtime_put(m4udev);
|
||||||
return ret;
|
goto err_unlock;
|
||||||
}
|
}
|
||||||
data->m4u_dom = dom;
|
data->m4u_dom = dom;
|
||||||
writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK,
|
writel(dom->cfg.arm_v7s_cfg.ttbr & MMU_PT_ADDR_MASK,
|
||||||
@@ -492,9 +493,14 @@ static int mtk_iommu_attach_device(struct iommu_domain *domain,
|
|||||||
|
|
||||||
pm_runtime_put(m4udev);
|
pm_runtime_put(m4udev);
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
|
||||||
mtk_iommu_config(data, dev, true, domid);
|
mtk_iommu_config(data, dev, true, domid);
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
err_unlock:
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void mtk_iommu_detach_device(struct iommu_domain *domain,
|
static void mtk_iommu_detach_device(struct iommu_domain *domain,
|
||||||
@@ -606,6 +612,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev)
|
|||||||
if (domid < 0)
|
if (domid < 0)
|
||||||
return ERR_PTR(domid);
|
return ERR_PTR(domid);
|
||||||
|
|
||||||
|
mutex_lock(&data->mutex);
|
||||||
group = data->m4u_group[domid];
|
group = data->m4u_group[domid];
|
||||||
if (!group) {
|
if (!group) {
|
||||||
group = iommu_group_alloc();
|
group = iommu_group_alloc();
|
||||||
@@ -614,6 +621,7 @@ static struct iommu_group *mtk_iommu_device_group(struct device *dev)
|
|||||||
} else {
|
} else {
|
||||||
iommu_group_ref_get(group);
|
iommu_group_ref_get(group);
|
||||||
}
|
}
|
||||||
|
mutex_unlock(&data->mutex);
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -887,6 +895,7 @@ static int mtk_iommu_probe(struct platform_device *pdev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
platform_set_drvdata(pdev, data);
|
platform_set_drvdata(pdev, data);
|
||||||
|
mutex_init(&data->mutex);
|
||||||
|
|
||||||
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
|
ret = iommu_device_sysfs_add(&data->iommu, dev, NULL,
|
||||||
"mtk-iommu.%pa", &ioaddr);
|
"mtk-iommu.%pa", &ioaddr);
|
||||||
|
|||||||
@@ -80,6 +80,8 @@ struct mtk_iommu_data {
|
|||||||
|
|
||||||
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
|
struct dma_iommu_mapping *mapping; /* For mtk_iommu_v1.c */
|
||||||
|
|
||||||
|
struct mutex mutex; /* Protect m4u_group/m4u_dom above */
|
||||||
|
|
||||||
struct list_head list;
|
struct list_head list;
|
||||||
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
|
struct mtk_smi_larb_iommu larb_imu[MTK_LARB_NR_MAX];
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user