Skip to content

Commit 6077c7e

Browse files
YongWu-HFjoergroedel
authored andcommitted
iommu/mediatek: Add a PM_CLK_AO flag for infra iommu
The power/clock of infra iommu is always on, and it doesn't have the device link with the master devices, then the infra iommu device's PM status is not active, thus we add A PM_CLK_AO flag for infra iommu. The tlb operation is a bit not clear here, there are 2 special cases. Comment them in the code. 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-21-yong.wu@mediatek.com Signed-off-by: Joerg Roedel <jroedel@suse.de>
1 parent 32e1ccc commit 6077c7e

1 file changed

Lines changed: 26 additions & 3 deletions

File tree

drivers/iommu/mtk_iommu.c

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,8 @@
130130
#define MTK_IOMMU_TYPE_MM (0x0 << 13)
131131
#define MTK_IOMMU_TYPE_INFRA (0x1 << 13)
132132
#define MTK_IOMMU_TYPE_MASK (0x3 << 13)
133+
/* PM and clock always on. e.g. infra iommu */
134+
#define PM_CLK_AO BIT(15)
133135

134136
#define MTK_IOMMU_HAS_FLAG_MASK(pdata, _x, mask) \
135137
((((pdata)->flags) & (mask)) == (_x))
@@ -235,13 +237,33 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size,
235237
struct mtk_iommu_data *data)
236238
{
237239
struct list_head *head = data->hw_list;
240+
bool check_pm_status;
238241
unsigned long flags;
239242
int ret;
240243
u32 tmp;
241244

242245
for_each_m4u(data, head) {
243-
if (pm_runtime_get_if_in_use(data->dev) <= 0)
244-
continue;
246+
/*
247+
* To avoid resume the iommu device frequently when the iommu device
248+
* is not active, it doesn't always call pm_runtime_get here, then tlb
249+
* flush depends on the tlb flush all in the runtime resume.
250+
*
251+
* There are 2 special cases:
252+
*
253+
* Case1: The iommu dev doesn't have power domain but has bclk. This case
254+
* should also avoid the tlb flush while the dev is not active to mute
255+
* the tlb timeout log. like mt8173.
256+
*
257+
* Case2: The power/clock of infra iommu is always on, and it doesn't
258+
* have the device link with the master devices. This case should avoid
259+
* the PM status check.
260+
*/
261+
check_pm_status = !MTK_IOMMU_HAS_FLAG(data->plat_data, PM_CLK_AO);
262+
263+
if (check_pm_status) {
264+
if (pm_runtime_get_if_in_use(data->dev) <= 0)
265+
continue;
266+
}
245267

246268
spin_lock_irqsave(&data->tlb_lock, flags);
247269
writel_relaxed(F_INVLD_EN1 | F_INVLD_EN0,
@@ -268,7 +290,8 @@ static void mtk_iommu_tlb_flush_range_sync(unsigned long iova, size_t size,
268290
mtk_iommu_tlb_flush_all(data);
269291
}
270292

271-
pm_runtime_put(data->dev);
293+
if (check_pm_status)
294+
pm_runtime_put(data->dev);
272295
}
273296
}
274297

0 commit comments

Comments
 (0)