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

Commit b737ca50 authored by Laura Abbott's avatar Laura Abbott Committed by Shiraz Hashim
Browse files

arm: Add option to skip buffer zeroing



The DMA framework currently zeros all buffers because it (righfully so)
assumes that drivers will soon need to pass the memory to a device.
Some devices/use case may not require zeroed memory and there can
be an increase in performance if we skip the zeroing. Add a DMA_ATTR
to allow skipping of DMA zeroing.

Change-Id: Ib78a19cb341c3c441f91d5b004c6375c80c10413
Signed-off-by: default avatarLaura Abbott <lauraa@codeaurora.org>
parent 2d0f0840
Loading
Loading
Loading
Loading
+11 −12
Original line number Diff line number Diff line
@@ -307,7 +307,7 @@ static void __dma_free_buffer(struct page *page, size_t size)
static void *__alloc_from_contiguous(struct device *dev, size_t size,
				     pgprot_t prot, struct page **ret_page,
				     const void *caller,
				     bool no_kernel_mapping);
				     struct dma_attrs *attrs);

static void *__alloc_remap_buffer(struct device *dev, size_t size, gfp_t gfp,
				 pgprot_t prot, struct page **ret_page,
@@ -375,7 +375,7 @@ static int __init atomic_pool_init(void)

	if (IS_ENABLED(CONFIG_DMA_CMA))
		ptr = __alloc_from_contiguous(NULL, atomic_pool_size, prot,
				&page, atomic_pool_init, false);
				&page, atomic_pool_init, NULL);
	else
		ptr = __alloc_remap_buffer(NULL, atomic_pool_size, gfp, prot,
					   &page, atomic_pool_init);
@@ -559,17 +559,20 @@ static int __free_from_pool(void *start, size_t size)
static void *__alloc_from_contiguous(struct device *dev, size_t size,
				     pgprot_t prot, struct page **ret_page,
				     const void *caller,
				     bool no_kernel_mapping)
				     struct dma_attrs *attrs)
{
	unsigned long order = get_order(size);
	size_t count = size >> PAGE_SHIFT;
	struct page *page;
	void *ptr;
	bool no_kernel_mapping = dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING,
							attrs);

	page = dma_alloc_from_contiguous(dev, count, order);
	if (!page)
		return NULL;

	if (!dma_get_attr(DMA_ATTR_SKIP_ZEROING, attrs))
		__dma_clear_buffer(page, size);

	if (PageHighMem(page)) {
@@ -655,7 +658,7 @@ static void *__alloc_simple_buffer(struct device *dev, size_t size, gfp_t gfp,

static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
			 gfp_t gfp, pgprot_t prot, bool is_coherent,
			 const void *caller, bool no_kernel_mapping)
			 const void *caller, struct dma_attrs *attrs)
{
	u64 mask = get_coherent_dma_mask(dev);
	struct page *page = NULL;
@@ -696,7 +699,7 @@ static void *__dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
		addr = __alloc_remap_buffer(dev, size, gfp, prot, &page, caller);
	else
		addr = __alloc_from_contiguous(dev, size, prot, &page, caller,
						no_kernel_mapping);
						attrs);

	if (addr)
		*handle = pfn_to_dma(dev, page_to_pfn(page));
@@ -713,14 +716,12 @@ void *arm_dma_alloc(struct device *dev, size_t size, dma_addr_t *handle,
{
	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
	void *memory;
	bool no_kernel_mapping = dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING,
					attrs);

	if (dma_alloc_from_coherent(dev, size, handle, &memory))
		return memory;

	return __dma_alloc(dev, size, handle, gfp, prot, false,
			   __builtin_return_address(0), no_kernel_mapping);
			   __builtin_return_address(0), attrs);
}

static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
@@ -728,14 +729,12 @@ static void *arm_coherent_dma_alloc(struct device *dev, size_t size,
{
	pgprot_t prot = __get_dma_pgprot(attrs, PAGE_KERNEL);
	void *memory;
	bool no_kernel_mapping = dma_get_attr(DMA_ATTR_NO_KERNEL_MAPPING,
					attrs);

	if (dma_alloc_from_coherent(dev, size, handle, &memory))
		return memory;

	return __dma_alloc(dev, size, handle, gfp, prot, true,
			   __builtin_return_address(0), no_kernel_mapping);
			   __builtin_return_address(0), attrs);
}

/*