Skip to content

Commit ab1d528

Browse files
YongWu-HFwilldeacon
authored andcommitted
iommu/mediatek: Add iova reserved function
For multiple iommu_domains, we need to reserve some iova regions. Take a example, If the default iova region is 0 ~ 4G, but the 0x4000_0000 ~ 0x43ff_ffff is only for the special CCU0 domain. Thus we should exclude this region for the default iova region. Signed-off-by: Anan sun <[email protected]> Signed-off-by: Chao Hao <[email protected]> Signed-off-by: Yong Wu <[email protected]> Reviewed-by: Tomasz Figa <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Will Deacon <[email protected]>
1 parent c3045f3 commit ab1d528

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

drivers/iommu/mtk_iommu.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,35 @@ static int mtk_iommu_of_xlate(struct device *dev, struct of_phandle_args *args)
626626
return iommu_fwspec_add_ids(dev, args->args, 1);
627627
}
628628

629+
static void mtk_iommu_get_resv_regions(struct device *dev,
630+
struct list_head *head)
631+
{
632+
struct mtk_iommu_data *data = dev_iommu_priv_get(dev);
633+
unsigned int domid = mtk_iommu_get_domain_id(dev, data->plat_data), i;
634+
const struct mtk_iommu_iova_region *resv, *curdom;
635+
struct iommu_resv_region *region;
636+
int prot = IOMMU_WRITE | IOMMU_READ;
637+
638+
if (domid < 0)
639+
return;
640+
curdom = data->plat_data->iova_region + domid;
641+
for (i = 0; i < data->plat_data->iova_region_nr; i++) {
642+
resv = data->plat_data->iova_region + i;
643+
644+
/* Only reserve when the region is inside the current domain */
645+
if (resv->iova_base <= curdom->iova_base ||
646+
resv->iova_base + resv->size >= curdom->iova_base + curdom->size)
647+
continue;
648+
649+
region = iommu_alloc_resv_region(resv->iova_base, resv->size,
650+
prot, IOMMU_RESV_RESERVED);
651+
if (!region)
652+
return;
653+
654+
list_add_tail(&region->list, head);
655+
}
656+
}
657+
629658
static const struct iommu_ops mtk_iommu_ops = {
630659
.domain_alloc = mtk_iommu_domain_alloc,
631660
.domain_free = mtk_iommu_domain_free,
@@ -641,6 +670,8 @@ static const struct iommu_ops mtk_iommu_ops = {
641670
.release_device = mtk_iommu_release_device,
642671
.device_group = mtk_iommu_device_group,
643672
.of_xlate = mtk_iommu_of_xlate,
673+
.get_resv_regions = mtk_iommu_get_resv_regions,
674+
.put_resv_regions = generic_iommu_put_resv_regions,
644675
.pgsize_bitmap = SZ_4K | SZ_64K | SZ_1M | SZ_16M,
645676
};
646677

0 commit comments

Comments
 (0)