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

Commit 232a71e1 authored by Prakash Gupta's avatar Prakash Gupta Committed by Gerrit - the friendly Code Review server
Browse files

arm64: dma-mapping: alloc page order based on domain pgsize



Restrict higher-order allocation to pgsize preferce per domain and avoid
wasting any time or effort on other sizes which offer no benefit.

Change-Id: Ic0a7843917e7c6e2959e7b566c20fec6a96670f3
Signed-off-by: default avatarPrakash Gupta <guptap@codeaurora.org>
parent 38177a28
Loading
Loading
Loading
Loading
+13 −2
Original line number Diff line number Diff line
@@ -1256,6 +1256,9 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
	size_t array_size = count * sizeof(struct page *);
	int i = 0;
	bool is_coherent = is_dma_coherent(dev, attrs);
	struct dma_iommu_mapping *mapping = dev->archdata.mapping;
	unsigned int alloc_sizes = mapping->domain->pgsize_bitmap;
	unsigned long order_mask;

	if (array_size <= PAGE_SIZE)
		pages = kzalloc(array_size, gfp);
@@ -1284,14 +1287,22 @@ static struct page **__iommu_alloc_buffer(struct device *dev, size_t size,
	 * IOMMU can map any pages, so himem can also be used here
	 */
	gfp |= __GFP_NOWARN | __GFP_HIGHMEM;
	order_mask = alloc_sizes >> PAGE_SHIFT;
	order_mask &= (2U << MAX_ORDER) - 1;
	if (!order_mask)
		goto error;

	while (count) {
		int j, order = __fls(count);
		int j, order;

		order_mask &= (2U << __fls(count)) - 1;
		order = __fls(order_mask);

		pages[i] = alloc_pages(order ? (gfp | __GFP_NORETRY) &
					~__GFP_RECLAIM : gfp, order);
		while (!pages[i] && order) {
			order--;
			order_mask &= ~(1U << order);
			order = __fls(order_mask);
			pages[i] = alloc_pages(order ? (gfp | __GFP_NORETRY) &
					~__GFP_RECLAIM : gfp, order);
		}