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

Commit 3459592f authored by Liam Mark's avatar Liam Mark Committed by Gerrit - the friendly Code Review server
Browse files

arm64: dma-mapping: make alloc_noncoherent more robust



Large allocations can result in the arm64_swiotlb_alloc_noncoherent
call not being able to succeed because it can't find enough
contiguous memory to setup the mapping.

Make arm64_swiotlb_alloc_noncoherent more robust by using vmalloc
as a fallback.

Change-Id: I00e8c3f634dc2280f3731c6042b9dd3dc644cb73
Signed-off-by: default avatarLiam Mark <lmark@codeaurora.org>
parent 0f0c42ba
Loading
Loading
Loading
Loading
+8 −4
Original line number Diff line number Diff line
@@ -294,16 +294,20 @@ static void *arm64_swiotlb_alloc_noncoherent(struct device *dev, size_t size,
			/* remove any dirty cache lines on the kernel alias */
			__dma_flush_range(ptr, ptr + size);

		map = kmalloc(sizeof(struct page *) << order, flags & ~GFP_DMA);
		map = kmalloc(sizeof(struct page *) << order,
			      (flags & ~GFP_DMA) | __GFP_NOWARN);
		if (!map) {
			map = vmalloc(sizeof(struct page *) << order);
			if (!map)
				goto no_map;
		}

		/* create a coherent mapping */
		page = virt_to_page(ptr);
		for (i = 0; i < (size >> PAGE_SHIFT); i++)
			map[i] = page + i;
		coherent_ptr = vmap(map, size >> PAGE_SHIFT, VM_MAP, prot);
		kfree(map);
		kvfree(map);
		if (!coherent_ptr)
			goto no_map;
	}