Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit fe5cca37 authored by Patrick Daly's avatar Patrick Daly
Browse files

iommu/iova: Limit IOVA alignment using CONFIG_ARM64_DMA_IOMMU_ALIGNMENT



Currently IOVAs are aligned to the next power of two of the size of the
allocation. This can result in unnecessary fragmentation of the IOVA
space.

If defined use CONFIG_ARM64_DMA_IOMMU_ALIGNMENT to limit the maximum IOVA
alignment.

Change-Id: Ica7f6382237e37acac2d35972a564ca1e1f5e84f
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 7bc951b1
Loading
Loading
Loading
Loading
+19 −1
Original line number Original line Diff line number Diff line
@@ -175,6 +175,24 @@ iova_insert_rbtree(struct rb_root *root, struct iova *iova,
	rb_insert_color(&iova->node, root);
	rb_insert_color(&iova->node, root);
}
}


#ifdef CONFIG_ARM64_DMA_IOMMU_ALIGNMENT
static unsigned long limit_align(struct iova_domain *iovad,
					unsigned long shift)
{
	unsigned long max;

	max = CONFIG_ARM64_DMA_IOMMU_ALIGNMENT + PAGE_SHIFT
		- iova_shift(iovad);
	return min(shift, max);
}
#else
static unsigned long limit_align(struct iova_domain *iovad,
					unsigned long shift)
{
	return shift;
}
#endif

static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
		unsigned long size, unsigned long limit_pfn,
		unsigned long size, unsigned long limit_pfn,
			struct iova *new, bool size_aligned)
			struct iova *new, bool size_aligned)
@@ -186,7 +204,7 @@ static int __alloc_and_insert_iova_range(struct iova_domain *iovad,
	unsigned long align_mask = ~0UL;
	unsigned long align_mask = ~0UL;


	if (size_aligned)
	if (size_aligned)
		align_mask <<= fls_long(size - 1);
		align_mask <<= limit_align(iovad, fls_long(size - 1));


	/* Walk the tree backwards */
	/* Walk the tree backwards */
	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);
	spin_lock_irqsave(&iovad->iova_rbtree_lock, flags);