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

Commit 6b8f1b71 authored by Patrick Daly's avatar Patrick Daly
Browse files

ion: ion_cma_heap: Add no-map detection



Some DMA heaps may not have a kernel mapping. Ensure buffers are marked as
non-cacheable to prevent cache-maintenance from failing.

Change-Id: Ia510bba239b33c1a819f2e17137b22bff8797611
Signed-off-by: default avatarPatrick Daly <pdaly@codeaurora.org>
parent 1323e41a
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -215,7 +215,6 @@ static struct ion_buffer *ion_buffer_create(struct ion_heap *heap,

	buffer->dev = dev;
	buffer->size = len;
	buffer->flags = flags;
	INIT_LIST_HEAD(&buffer->vmas);

	table = heap->ops->map_dma(heap, buffer);
+19 −0
Original line number Diff line number Diff line
@@ -23,6 +23,7 @@
#include <linux/err.h>
#include <linux/dma-mapping.h>
#include <linux/msm_ion.h>
#include <linux/of.h>

#include <asm/cacheflush.h>
#include <soc/qcom/secure_buffer.h>
@@ -59,6 +60,18 @@ static int ion_cma_get_sgtable(struct device *dev, struct sg_table *sgt,
	return 0;
}

static bool ion_cma_has_kernel_mapping(struct ion_heap *heap)
{
	struct device *dev = heap->priv;
	struct device_node *mem_region;

	mem_region = of_parse_phandle(dev->of_node, "memory-region", 0);
	if (IS_ERR(mem_region))
		return false;

	return !of_property_read_bool(mem_region, "no-map");
}

/* ION CMA heap operations functions */
static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
			    unsigned long len, unsigned long align,
@@ -73,6 +86,12 @@ static int ion_cma_allocate(struct ion_heap *heap, struct ion_buffer *buffer,
	if (!info)
		return ION_CMA_ALLOCATE_FAILED;

	/* Override flags if cached-mappings are not supported */
	if (!ion_cma_has_kernel_mapping(heap)) {
		flags &= ~((unsigned long)ION_FLAG_CACHED);
		buffer->flags = flags;
	}

	if (!ION_IS_CACHED(flags))
		info->cpu_addr = dma_alloc_writecombine(dev, len,
							&info->handle,